forked from sharpdx/SharpDX
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEffectFile.cs
More file actions
373 lines (364 loc) · 12.9 KB
/
EffectFile.cs
File metadata and controls
373 lines (364 loc) · 12.9 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
// Copyright (c) 2010-2014 SharpDX - Alexandre Mutel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Runtime.InteropServices;
namespace SharpDX.DirectInput
{
public partial class EffectFile
{
/// <summary>
/// Initializes a new instance of the <see cref="EffectFile"/> class.
/// </summary>
public EffectFile()
{
unsafe
{
Size = sizeof(__Native);
}
}
/// <summary>
/// Gets or sets the parameters.
/// </summary>
/// <value>The parameters.</value>
public EffectParameters Parameters { get; set; }
internal static __Native __NewNative()
{
unsafe
{
__Native temp = default(__Native);
temp.Size = sizeof(__Native);
return temp;
}
}
// Internal native struct used for marshalling
[StructLayout(LayoutKind.Sequential, Pack = 0)]
internal partial struct __Native
{
public int Size;
public System.Guid Guid;
public System.IntPtr EffectParametersPointer;
public byte Name;
public byte _Name2;
public byte _Name3;
public byte _Name4;
public byte _Name5;
public byte _Name6;
public byte _Name7;
public byte _Name8;
public byte _Name9;
public byte _Name10;
public byte _Name11;
public byte _Name12;
public byte _Name13;
public byte _Name14;
public byte _Name15;
public byte _Name16;
public byte _Name17;
public byte _Name18;
public byte _Name19;
public byte _Name20;
public byte _Name21;
public byte _Name22;
public byte _Name23;
public byte _Name24;
public byte _Name25;
public byte _Name26;
public byte _Name27;
public byte _Name28;
public byte _Name29;
public byte _Name30;
public byte _Name31;
public byte _Name32;
public byte _Name33;
public byte _Name34;
public byte _Name35;
public byte _Name36;
public byte _Name37;
public byte _Name38;
public byte _Name39;
public byte _Name40;
public byte _Name41;
public byte _Name42;
public byte _Name43;
public byte _Name44;
public byte _Name45;
public byte _Name46;
public byte _Name47;
public byte _Name48;
public byte _Name49;
public byte _Name50;
public byte _Name51;
public byte _Name52;
public byte _Name53;
public byte _Name54;
public byte _Name55;
public byte _Name56;
public byte _Name57;
public byte _Name58;
public byte _Name59;
public byte _Name60;
public byte _Name61;
public byte _Name62;
public byte _Name63;
public byte _Name64;
public byte _Name65;
public byte _Name66;
public byte _Name67;
public byte _Name68;
public byte _Name69;
public byte _Name70;
public byte _Name71;
public byte _Name72;
public byte _Name73;
public byte _Name74;
public byte _Name75;
public byte _Name76;
public byte _Name77;
public byte _Name78;
public byte _Name79;
public byte _Name80;
public byte _Name81;
public byte _Name82;
public byte _Name83;
public byte _Name84;
public byte _Name85;
public byte _Name86;
public byte _Name87;
public byte _Name88;
public byte _Name89;
public byte _Name90;
public byte _Name91;
public byte _Name92;
public byte _Name93;
public byte _Name94;
public byte _Name95;
public byte _Name96;
public byte _Name97;
public byte _Name98;
public byte _Name99;
public byte _Name100;
public byte _Name101;
public byte _Name102;
public byte _Name103;
public byte _Name104;
public byte _Name105;
public byte _Name106;
public byte _Name107;
public byte _Name108;
public byte _Name109;
public byte _Name110;
public byte _Name111;
public byte _Name112;
public byte _Name113;
public byte _Name114;
public byte _Name115;
public byte _Name116;
public byte _Name117;
public byte _Name118;
public byte _Name119;
public byte _Name120;
public byte _Name121;
public byte _Name122;
public byte _Name123;
public byte _Name124;
public byte _Name125;
public byte _Name126;
public byte _Name127;
public byte _Name128;
public byte _Name129;
public byte _Name130;
public byte _Name131;
public byte _Name132;
public byte _Name133;
public byte _Name134;
public byte _Name135;
public byte _Name136;
public byte _Name137;
public byte _Name138;
public byte _Name139;
public byte _Name140;
public byte _Name141;
public byte _Name142;
public byte _Name143;
public byte _Name144;
public byte _Name145;
public byte _Name146;
public byte _Name147;
public byte _Name148;
public byte _Name149;
public byte _Name150;
public byte _Name151;
public byte _Name152;
public byte _Name153;
public byte _Name154;
public byte _Name155;
public byte _Name156;
public byte _Name157;
public byte _Name158;
public byte _Name159;
public byte _Name160;
public byte _Name161;
public byte _Name162;
public byte _Name163;
public byte _Name164;
public byte _Name165;
public byte _Name166;
public byte _Name167;
public byte _Name168;
public byte _Name169;
public byte _Name170;
public byte _Name171;
public byte _Name172;
public byte _Name173;
public byte _Name174;
public byte _Name175;
public byte _Name176;
public byte _Name177;
public byte _Name178;
public byte _Name179;
public byte _Name180;
public byte _Name181;
public byte _Name182;
public byte _Name183;
public byte _Name184;
public byte _Name185;
public byte _Name186;
public byte _Name187;
public byte _Name188;
public byte _Name189;
public byte _Name190;
public byte _Name191;
public byte _Name192;
public byte _Name193;
public byte _Name194;
public byte _Name195;
public byte _Name196;
public byte _Name197;
public byte _Name198;
public byte _Name199;
public byte _Name200;
public byte _Name201;
public byte _Name202;
public byte _Name203;
public byte _Name204;
public byte _Name205;
public byte _Name206;
public byte _Name207;
public byte _Name208;
public byte _Name209;
public byte _Name210;
public byte _Name211;
public byte _Name212;
public byte _Name213;
public byte _Name214;
public byte _Name215;
public byte _Name216;
public byte _Name217;
public byte _Name218;
public byte _Name219;
public byte _Name220;
public byte _Name221;
public byte _Name222;
public byte _Name223;
public byte _Name224;
public byte _Name225;
public byte _Name226;
public byte _Name227;
public byte _Name228;
public byte _Name229;
public byte _Name230;
public byte _Name231;
public byte _Name232;
public byte _Name233;
public byte _Name234;
public byte _Name235;
public byte _Name236;
public byte _Name237;
public byte _Name238;
public byte _Name239;
public byte _Name240;
public byte _Name241;
public byte _Name242;
public byte _Name243;
public byte _Name244;
public byte _Name245;
public byte _Name246;
public byte _Name247;
public byte _Name248;
public byte _Name249;
public byte _Name250;
public byte _Name251;
public byte _Name252;
public byte _Name253;
public byte _Name254;
public byte _Name255;
public byte _Name256;
public byte _Name257;
public byte _Name258;
public byte _Name259;
public byte _Name260;
// Method to free native struct
internal unsafe void __MarshalFree()
{
if (EffectParametersPointer != IntPtr.Zero)
Marshal.FreeHGlobal(EffectParametersPointer);
}
}
internal unsafe void __MarshalFree(ref __Native @ref)
{
// Free Parameters
if (Parameters != null && @ref.EffectParametersPointer != IntPtr.Zero)
Parameters.__MarshalFree(ref *((EffectParameters.__Native*)@ref.EffectParametersPointer));
@ref.__MarshalFree();
}
// Method to marshal from native to managed struct
internal unsafe void __MarshalFrom(ref __Native @ref)
{
this.Size = @ref.Size;
this.Guid = @ref.Guid;
this.EffectParametersPointer = @ref.EffectParametersPointer;
fixed (void* __ptr = &@ref.Name) this.Name = Utilities.PtrToStringAnsi((IntPtr)__ptr, 260);
if (this.EffectParametersPointer != IntPtr.Zero)
{
Parameters = new EffectParameters();
Parameters.__MarshalFrom(ref *(EffectParameters.__Native*)EffectParametersPointer);
EffectParametersPointer = IntPtr.Zero;
}
}
// Method to marshal from managed struct tot native
internal unsafe void __MarshalTo(ref __Native @ref)
{
@ref.Size = this.Size;
@ref.Guid = this.Guid;
IntPtr effectParameters = IntPtr.Zero;
if ( Parameters != null)
{
effectParameters = Marshal.AllocHGlobal(sizeof (EffectParameters.__Native));
var nativeParameters = default(EffectParameters.__Native);
Parameters.__MarshalTo(ref nativeParameters);
*((EffectParameters.__Native*) effectParameters) = nativeParameters;
}
@ref.EffectParametersPointer = effectParameters;
IntPtr Name_ = Marshal.StringToHGlobalAnsi(this.Name);
fixed (void* __ptr = &@ref.Name) Utilities.CopyMemory((IntPtr)__ptr, Name_, this.Name.Length);
Marshal.FreeHGlobal(Name_);
}
}
}