This repository has been archived by the owner on Oct 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathHelper.cs
484 lines (378 loc) · 13.7 KB
/
Helper.cs
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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
#region License
//
// The Open Toolkit Library License
//
// Copyright (c) 2006 - 2009 the Open Toolkit library.
// Copyright 2013 Xamarin Inc
//
// 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.
//
#endregion
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenTK.Graphics.ES20
{
/// <summary>
/// Provides access to OpenGL ES 2.0 methods.
/// </summary>
public sealed partial class GL : GraphicsBindingsBase
{
public const string Library = "libGLESv2";
static readonly object sync_root = new object();
#region --- Protected Members ---
/// <summary>
/// Returns a synchronization token unique for the GL class.
/// </summary>
protected override object SyncRoot
{
get { return sync_root; }
}
#endregion
#region Helper Overloads
#pragma warning disable 3019
#pragma warning disable 1591
#pragma warning disable 1572
#pragma warning disable 1573
// Note: Mono 1.9.1 truncates StringBuilder results (for 'out string' parameters).
// We work around this issue by doubling the StringBuilder capacity.
#region public static void ClearColor() overloads
public static void ClearColor(System.Drawing.Color color)
{
GL.ClearColor(color.R / 255.0f, color.G / 255.0f, color.B / 255.0f, color.A / 255.0f);
}
public static void ClearColor(Color4 color)
{
GL.ClearColor(color.R, color.G, color.B, color.A);
}
#endregion
#region public static void BlendColor() overloads
public static void BlendColor(System.Drawing.Color color)
{
GL.BlendColor(color.R / 255.0f, color.G / 255.0f, color.B / 255.0f, color.A / 255.0f);
}
public static void BlendColor(Color4 color)
{
GL.BlendColor(color.R, color.G, color.B, color.A);
}
#endregion
#region Uniform
[CLSCompliant(false)]
public static void Uniform2(int location, ref Vector2 vector)
{
GL.Uniform2(location, vector.X, vector.Y);
}
[CLSCompliant(false)]
public static void Uniform3(int location, ref Vector3 vector)
{
GL.Uniform3(location, vector.X, vector.Y, vector.Z);
}
[CLSCompliant(false)]
public static void Uniform4(int location, ref Vector4 vector)
{
GL.Uniform4(location, vector.X, vector.Y, vector.Z, vector.W);
}
public static void Uniform2(int location, Vector2 vector)
{
GL.Uniform2(location, vector.X, vector.Y);
}
public static void Uniform3(int location, Vector3 vector)
{
GL.Uniform3(location, vector.X, vector.Y, vector.Z);
}
public static void Uniform4(int location, Vector4 vector)
{
GL.Uniform4(location, vector.X, vector.Y, vector.Z, vector.W);
}
public static void Uniform4(int location, Color4 color)
{
GL.Uniform4(location, color.R, color.G, color.B, color.A);
}
public static void Uniform4(int location, Quaternion quaternion)
{
GL.Uniform4(location, quaternion.X, quaternion.Y, quaternion.Z, quaternion.W);
}
public static void UniformMatrix2(int location, bool transpose, ref Matrix2 matrix)
{
unsafe
{
fixed (float* matrix_ptr = &matrix.R0C0)
{
GL.UniformMatrix2(location, 1, transpose, matrix_ptr);
}
}
}
public static void UniformMatrix3(int location, bool transpose, ref Matrix3 matrix)
{
unsafe
{
fixed (float* matrix_ptr = &matrix.R0C0)
{
GL.UniformMatrix3(location, 1, transpose, matrix_ptr);
}
}
}
public static void UniformMatrix4(int location, bool transpose, ref Matrix4 matrix)
{
unsafe
{
fixed (float* matrix_ptr = &matrix.Row0.X)
{
GL.UniformMatrix4(location, 1, transpose, matrix_ptr);
}
}
}
#endregion
#region Shaders
#region GetActiveAttrib
public static string GetActiveAttrib(int program, int index, out int size, out ActiveAttribType type)
{
int length;
GetProgram(program, ProgramParameter.ActiveAttributeMaxLength, out length);
StringBuilder sb = new StringBuilder(length == 0 ? 1 : length * 2);
GetActiveAttrib(program, index, sb.Capacity, out length, out size, out type, sb);
return sb.ToString();
}
[Obsolete]
public static string GetActiveAttrib(int program, int index, out int size, out All type)
{
ActiveAttribType t;
string str = GetActiveAttrib(program, index, out size, out t);
type = (All)(int) t;
return str;
}
#endregion
#region GetActiveUniform
public static string GetActiveUniform(int program, int uniformIndex, out int size, out ActiveUniformType type)
{
int length;
GetProgram(program, ProgramParameter.ActiveUniformMaxLength, out length);
StringBuilder sb = new StringBuilder(length == 0 ? 1 : length);
GetActiveUniform(program, uniformIndex, sb.Capacity, out length, out size, out type, sb);
return sb.ToString();
}
#endregion
#region public static void ShaderSource(Int32 shader, System.String @string)
public static void ShaderSource(Int32 shader, System.String @string)
{
unsafe
{
int length = @string.Length;
GL.ShaderSource((UInt32)shader, 1, new string[] { @string }, &length);
}
}
#endregion
#region public static string GetShaderInfoLog(Int32 shader)
public static string GetShaderInfoLog(Int32 shader)
{
string info;
GetShaderInfoLog(shader, out info);
return info;
}
#endregion
#region public static void GetShaderInfoLog(Int32 shader, out string info)
public static void GetShaderInfoLog(Int32 shader, out string info)
{
unsafe
{
int length;
GL.GetShader(shader, ShaderParameter.InfoLogLength, out length);
if (length == 0)
{
info = String.Empty;
return;
}
StringBuilder sb = new StringBuilder(length * 2);
GL.GetShaderInfoLog((UInt32)shader, sb.Capacity, &length, sb);
info = sb.ToString();
}
}
#endregion
#region public static string GetProgramInfoLog(Int32 program)
public static string GetProgramInfoLog(Int32 program)
{
string info;
GetProgramInfoLog(program, out info);
return info;
}
#endregion
#region public static void GetProgramInfoLog(Int32 program, out string info)
public static void GetProgramInfoLog(Int32 program, out string info)
{
unsafe
{
int length;
GL.GetProgram(program, ProgramParameter.InfoLogLength, out length); if (length == 0)
{
info = String.Empty;
return;
}
StringBuilder sb = new StringBuilder(length * 2);
GL.GetProgramInfoLog((UInt32)program, sb.Capacity, &length, sb);
info = sb.ToString();
}
}
#endregion
#endregion
#region public static void VertexAttrib2(Int32 index, ref Vector2 v)
[CLSCompliant(false)]
public static void VertexAttrib2(Int32 index, ref Vector2 v)
{
GL.VertexAttrib2(index, v.X, v.Y);
}
#endregion
#region public static void VertexAttrib3(Int32 index, ref Vector3 v)
[CLSCompliant(false)]
public static void VertexAttrib3(Int32 index, ref Vector3 v)
{
GL.VertexAttrib3(index, v.X, v.Y, v.Z);
}
#endregion
#region public static void VertexAttrib4(Int32 index, ref Vector4 v)
[CLSCompliant(false)]
public static void VertexAttrib4(Int32 index, ref Vector4 v)
{
GL.VertexAttrib4(index, v.X, v.Y, v.Z, v.W);
}
#endregion
#region public static void VertexAttrib2(Int32 index, Vector2 v)
public static void VertexAttrib2(Int32 index, Vector2 v)
{
GL.VertexAttrib2(index, v.X, v.Y);
}
#endregion
#region public static void VertexAttrib3(Int32 index, Vector3 v)
public static void VertexAttrib3(Int32 index, Vector3 v)
{
GL.VertexAttrib3(index, v.X, v.Y, v.Z);
}
#endregion
#region public static void VertexAttrib4(Int32 index, Vector4 v)
public static void VertexAttrib4(Int32 index, Vector4 v)
{
GL.VertexAttrib4(index, v.X, v.Y, v.Z, v.W);
}
#endregion
#region VertexAttribPointer
public static void VertexAttribPointer(int index, int size, VertexAttribPointerType type, bool normalized, int stride, int offset)
{
VertexAttribPointer(index, size, type, normalized, stride, (IntPtr)offset);
}
[CLSCompliant(false)]
public static void VertexAttribPointer(uint index, int size, VertexAttribPointerType type, bool normalized, int stride, int offset)
{
VertexAttribPointer(index, size, type, normalized, stride, (IntPtr)offset);
}
#endregion
#region DrawElements
public static void DrawElements(BeginMode mode, int count, DrawElementsType type, int offset)
{
DrawElements(mode, count, type, offset);
}
#endregion
#region public static int GenTexture()
public static int GenTexture()
{
int id;
GenTextures(1, out id);
return id;
}
#endregion
#region public static void DeleteTexture(int id)
public static void DeleteTexture(int id)
{
DeleteTextures(1, ref id);
}
[CLSCompliant(false)]
public static void DeleteTexture(uint id)
{
DeleteTextures(1, ref id);
}
#endregion
#region Get[Float|Double]
public static void GetFloat(GetPName pname, out Vector2 vector)
{
unsafe
{
fixed (Vector2* ptr = &vector)
GetFloat(pname, (float*)ptr);
}
}
public static void GetFloat(GetPName pname, out Vector3 vector)
{
unsafe
{
fixed (Vector3* ptr = &vector)
GetFloat(pname, (float*)ptr);
}
}
public static void GetFloat(GetPName pname, out Vector4 vector)
{
unsafe
{
fixed (Vector4* ptr = &vector)
GetFloat(pname, (float*)ptr);
}
}
public static void GetFloat(GetPName pname, out Matrix4 matrix)
{
unsafe
{
fixed (Matrix4* ptr = &matrix)
GetFloat(pname, (float*)ptr);
}
}
#endregion
#region Viewport
public static void Viewport(System.Drawing.Size size)
{
GL.Viewport(0, 0, size.Width, size.Height);
}
public static void Viewport(System.Drawing.Point location, System.Drawing.Size size)
{
GL.Viewport(location.X, location.Y, size.Width, size.Height);
}
public static void Viewport(System.Drawing.Rectangle rectangle)
{
GL.Viewport(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
}
#if NO_SYSDRAWING
public static void Viewport(OpenTK.Point location, OpenTK.Size size)
{
GL.Viewport(location.X, location.Y, size.Width, size.Height);
}
public static void Viewport(OpenTK.Rectangle rectangle)
{
GL.Viewport(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
}
#endif
#endregion
public static
OpenTK.Graphics.ES20.ErrorCode GetErrorCode()
{
return (ErrorCode) Core.GetError();
}
#pragma warning restore 3019
#pragma warning restore 1591
#pragma warning restore 1572
#pragma warning restore 1573
#endregion
}
}