You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
117 lines
4.1 KiB
117 lines
4.1 KiB
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.InteropServices;
|
|
using UnityEngine;
|
|
|
|
namespace UltraCombos.Utility
|
|
{
|
|
public class D3D
|
|
{
|
|
const string dllName = "UnityUtilityNativePlugin";
|
|
|
|
[DllImport(dllName, EntryPoint = "GetDevice")]
|
|
public static extern IntPtr GetDevice();
|
|
|
|
[DllImport(dllName, EntryPoint = "GetContext")]
|
|
public static extern IntPtr GetContext();
|
|
|
|
[DllImport(dllName, EntryPoint = "ReleaseContext")]
|
|
public static extern void ReleaseContext(IntPtr context);
|
|
}
|
|
|
|
public class Buffer
|
|
{
|
|
const string dllName = "UnityUtilityNativePlugin";
|
|
|
|
[DllImport(dllName, EntryPoint = "CreateBuffer")]
|
|
public static extern IntPtr Create(IntPtr bufferHandle);
|
|
|
|
[DllImport(dllName, EntryPoint = "SetBufferData")]
|
|
public static extern bool SetData(IntPtr bufferHandle, IntPtr data, int dataSize);
|
|
|
|
[DllImport(dllName, EntryPoint = "GetBufferData")]
|
|
public static extern bool GetData(IntPtr bufferHandle, IntPtr data, int dataSize);
|
|
|
|
[DllImport(dllName, EntryPoint = "CopyResource")]
|
|
public static extern void Copy(IntPtr dstHandle, IntPtr srcHandle);
|
|
|
|
[DllImport(dllName, EntryPoint = "ReleaseBuffer")]
|
|
public static extern void Release(IntPtr bufferHandle);
|
|
|
|
[DllImport(dllName, EntryPoint = "GetBufferSize")]
|
|
public static extern int GetSize(IntPtr bufferHandle);
|
|
|
|
[DllImport(dllName, EntryPoint = "GetBufferStride")]
|
|
public static extern int GetStride(IntPtr bufferHandle);
|
|
|
|
public static void GetDataImpl(IntPtr bufferHandle, IntPtr data, int dataSize)
|
|
{
|
|
IntPtr handle = NativeBufferPool.Instance.GetReference(bufferHandle);
|
|
Copy(handle, bufferHandle);
|
|
if (GetData(handle, data, dataSize) == false)
|
|
Debug.Log("GetDataImpl fail");
|
|
}
|
|
|
|
public static void SetDataImpl(IntPtr bufferHandle, IntPtr data, int dataSize)
|
|
{
|
|
IntPtr handle = NativeBufferPool.Instance.GetReference(bufferHandle);
|
|
if (SetData(handle, data, dataSize))
|
|
Copy(bufferHandle, handle);
|
|
else Debug.Log("SetDataImpl fail");
|
|
}
|
|
}
|
|
|
|
public class Texture
|
|
{
|
|
const string dllName = "UnityUtilityNativePlugin";
|
|
|
|
[DllImport(dllName, EntryPoint = "CreateTexture")]
|
|
public static extern IntPtr Create(IntPtr textureHandle, ref int height, ref int width);
|
|
|
|
[DllImport(dllName, EntryPoint = "SetTextureData")]
|
|
public static extern void SetData(IntPtr textureHandle, IntPtr data, int height, int width);
|
|
|
|
[DllImport(dllName, EntryPoint = "GetTextureData")]
|
|
public static extern void GetData(IntPtr textureHandle, IntPtr data, int height, int width);
|
|
|
|
[DllImport(dllName, EntryPoint = "CopyResource")]
|
|
public static extern void Copy(IntPtr dstHandle, IntPtr srcHandle);
|
|
|
|
[DllImport(dllName, EntryPoint = "ReleaseTexture")]
|
|
public static extern void Release(IntPtr textureHandle);
|
|
/*
|
|
public static void SetDataImpl(IntPtr bufferHandle, IntPtr data, int dataSize)
|
|
{
|
|
IntPtr handle = NativeBufferPool.Instance.GetReference(bufferHandle);
|
|
SetData(handle, data, dataSize);
|
|
Copy(bufferHandle, handle);
|
|
}
|
|
*/
|
|
}
|
|
|
|
public class Flatbuffers
|
|
{
|
|
const string dllName = "UnityUtilityNativePlugin";
|
|
|
|
[DllImport(dllName, EntryPoint = "FlatbuffersParse")]
|
|
public static extern IntPtr Parse([MarshalAs(UnmanagedType.LPStr)]string schemafile, IntPtr flatbuffer);
|
|
}
|
|
|
|
public class Memory
|
|
{
|
|
[DllImport("msvcrt.dll", EntryPoint = "memcpy")]
|
|
public static extern void Copy(IntPtr dst, IntPtr src, int size);
|
|
|
|
[DllImport("msvcrt.dll", EntryPoint = "memset")]
|
|
public static extern void Set(IntPtr dst, int val, int size);
|
|
|
|
public static void Swap<T>(ref T lhs, ref T rhs)
|
|
{
|
|
T temp = lhs;
|
|
lhs = rhs;
|
|
rhs = temp;
|
|
}
|
|
}
|
|
}
|
|
|
|
|