forked from 3DRadSpace/3D_Rad_Space
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEffect.cs
More file actions
108 lines (81 loc) · 3.28 KB
/
Copy pathEffect.cs
File metadata and controls
108 lines (81 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System.Runtime.InteropServices;
namespace Engine3DRadSpace.Graphics;
public class Effect : NatPtrWrapper
{
[DllImport("3DRadSpace.FFI.dll", EntryPoint = "E3DRSP_Effect_Create")]
extern static IntPtr _create(IntPtr device, IntPtr ppShaders, ulong numShaders);
[DllImport("3DRadSpace.FFI.dll", EntryPoint = "E3DRSP_Effect_SetAll")]
extern static void _setAll(IntPtr effect);
[DllImport("3DRadSpace.FFI.dll", EntryPoint = "E3DRSP_Effect_Set")]
extern static void _set(IntPtr effect, int idx);
[DllImport("3DRadSpace.FFI.dll", EntryPoint = "E3DRSP_Effect_SetData")]
extern static void _setData(IntPtr effect, IntPtr data, ulong dataSize, int cBufferID, int shaderID);
[DllImport("3DRadSpace.FFI.dll", EntryPoint = "E3DRSP_Effect_SetData2")]
extern static void _setData2(IntPtr effect, IntPtr data, ulong dataSize, int cBufferID);
[DllImport("3DRadSpace.FFI.dll", EntryPoint = "E3DRSP_Effect_SetTexture")]
extern static void _setTex(IntPtr effect, IntPtr texture, int idTexture);
[DllImport("3DRadSpace.FFI.dll", EntryPoint = "E3DRSP_Effect_SetTexture2")]
extern static void _setText2(IntPtr effect, IntPtr texture, int idTexture, int shaderID);
[DllImport("3DRadSpace.FFI.dll", EntryPoint = "E3DRSP_Effect_SetSampler")]
extern static void _setSamp(IntPtr effect, IntPtr sampler, int idTexture);
[DllImport("3DRadSpace.FFI.dll", EntryPoint = "E3DRSP_Effect_SetSampler2")]
extern static void _setSamp2(IntPtr effect, IntPtr sampler, int idTexture, int shaderID);
[DllImport("3DRadSpace.FFI.dll", EntryPoint = "E3DRSP_Effect_GetShader")]
extern static IntPtr _getShader(IntPtr effect, int id);
[DllImport("3DRadSpace.FFI.dll", EntryPoint = "E3DRSP_Effect_Destroy")]
extern static void _destroy(IntPtr effect);
static unsafe IntPtr _createInstance(IGraphicsDevice device, IShader[] shaders, int numShaders)
{
IntPtr* ppShaders = stackalloc IntPtr[numShaders];
for(int i = 0; i < shaders.Length; i++)
{
ppShaders[i] = shaders[i].Handle;
}
return _create(device.Handle, ppShaders[0], (ulong)numShaders);
}
public Effect(IGraphicsDevice device, IShader[] shaders, int numShaders ) : base(_createInstance(device, shaders, numShaders), _destroy)
{
}
public Effect(IntPtr handle) : base(handle, _destroy)
{
}
internal Effect(IntPtr handle, bool ownsHandle) : base(handle, ownsHandle ? _destroy : null)
{
}
public void SetAll()
{
_setAll(_handle);
}
public void Set(int shaderID)
{
_set(_handle, shaderID);
}
public void SetData(IntPtr data, ulong size, int cBufferID, int shaderID)
{
_setData(_handle, data, size, cBufferID, shaderID);
}
public void SetData(IntPtr data, ulong size, int cBufferID)
{
_setData2(_handle, data, size, cBufferID);
}
public void SetTexture(ITexture2D texture, int textureID)
{
_setTex(_handle, texture.Handle, textureID);
}
public void SetTexture(ITexture2D texture, int textureID, int shaderID)
{
_setText2(_handle, texture.Handle, textureID, shaderID);
}
public void SetSampler(ISamplerState samplerState, int idx)
{
_setSamp(_handle, samplerState.Handle, idx);
}
public void SetSampler(ISamplerState samplerState, int idx, int shaderID)
{
_setSamp2(_handle, samplerState.Handle, idx, shaderID);
}
public IShader GetShader(int shaderID)
{
return new InstIShader(_getShader(_handle, shaderID), ownsHandle: false);
}
}