00001 #region License
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #endregion
00027
00028 using System;
00029 using System.Collections.Generic;
00030 using System.Text;
00031
00032 namespace OpenTK.Graphics.ES20
00033 {
00037 public sealed partial class GL : GraphicsBindingsBase
00038 {
00039 const string Library = "libGLESv2.dll";
00040 static readonly object sync_root = new object();
00041
00042 #region --- Protected Members ---
00043
00047 protected override object SyncRoot
00048 {
00049 get { return sync_root; }
00050 }
00051
00052 #endregion
00053
00054 #region Helper Overloads
00055
00056 #pragma warning disable 3019
00057 #pragma warning disable 1591
00058 #pragma warning disable 1572
00059 #pragma warning disable 1573
00060
00061
00062
00063
00064 #region public static void ClearColor() overloads
00065
00066 public static void ClearColor(System.Drawing.Color color)
00067 {
00068 GL.ClearColor(color.R / 255.0f, color.G / 255.0f, color.B / 255.0f, color.A / 255.0f);
00069 }
00070
00071 public static void ClearColor(Color4 color)
00072 {
00073 GL.ClearColor(color.R, color.G, color.B, color.A);
00074 }
00075
00076 #endregion
00077
00078 #region public static void BlendColor() overloads
00079
00080 public static void BlendColor(System.Drawing.Color color)
00081 {
00082 GL.BlendColor(color.R / 255.0f, color.G / 255.0f, color.B / 255.0f, color.A / 255.0f);
00083 }
00084
00085 public static void BlendColor(Color4 color)
00086 {
00087 GL.BlendColor(color.R, color.G, color.B, color.A);
00088 }
00089
00090 #endregion
00091
00092 #region Uniform
00093
00094 [CLSCompliant(false)]
00095 public static void Uniform2(int location, ref Vector2 vector)
00096 {
00097 GL.Uniform2(location, vector.X, vector.Y);
00098 }
00099
00100 [CLSCompliant(false)]
00101 public static void Uniform3(int location, ref Vector3 vector)
00102 {
00103 GL.Uniform3(location, vector.X, vector.Y, vector.Z);
00104 }
00105
00106 [CLSCompliant(false)]
00107 public static void Uniform4(int location, ref Vector4 vector)
00108 {
00109 GL.Uniform4(location, vector.X, vector.Y, vector.Z, vector.W);
00110 }
00111
00112 public static void Uniform2(int location, Vector2 vector)
00113 {
00114 GL.Uniform2(location, vector.X, vector.Y);
00115 }
00116
00117 public static void Uniform3(int location, Vector3 vector)
00118 {
00119 GL.Uniform3(location, vector.X, vector.Y, vector.Z);
00120 }
00121
00122 public static void Uniform4(int location, Vector4 vector)
00123 {
00124 GL.Uniform4(location, vector.X, vector.Y, vector.Z, vector.W);
00125 }
00126
00127 public static void Uniform4(int location, Color4 color)
00128 {
00129 GL.Uniform4(location, color.R, color.G, color.B, color.A);
00130 }
00131
00132 public static void Uniform4(int location, Quaternion quaternion)
00133 {
00134 GL.Uniform4(location, quaternion.X, quaternion.Y, quaternion.Z, quaternion.W);
00135 }
00136
00137 public static void UniformMatrix4(int location, bool transpose, ref Matrix4 matrix)
00138 {
00139 unsafe
00140 {
00141 fixed (float* matrix_ptr = &matrix.Row0.X)
00142 {
00143 GL.UniformMatrix4(location, 1, transpose, matrix_ptr);
00144 }
00145 }
00146 }
00147
00148
00149 #endregion
00150
00151 #region Shaders
00152
00153 #region GetActiveAttrib
00154
00155 public static string GetActiveAttrib(int program, int index, out int size, out ActiveAttribType type)
00156 {
00157 int length;
00158 GetProgram(program, ProgramParameter.ActiveAttributeMaxLength, out length);
00159 StringBuilder sb = new StringBuilder(length == 0 ? 1 : length * 2);
00160
00161 GetActiveAttrib(program, index, sb.Capacity, out length, out size, out type, sb);
00162 return sb.ToString();
00163 }
00164
00165 #endregion
00166
00167 #region GetActiveUniform
00168
00169 public static string GetActiveUniform(int program, int uniformIndex, out int size, out ActiveUniformType type)
00170 {
00171 int length;
00172 GetProgram(program, ProgramParameter.ActiveUniformMaxLength, out length);
00173
00174 StringBuilder sb = new StringBuilder(length == 0 ? 1 : length);
00175 GetActiveUniform(program, uniformIndex, sb.Capacity, out length, out size, out type, sb);
00176 return sb.ToString();
00177 }
00178
00179 #endregion
00180
00181 #region public static void ShaderSource(Int32 shader, System.String @string)
00182
00183 public static void ShaderSource(Int32 shader, System.String @string)
00184 {
00185 unsafe
00186 {
00187 int length = @string.Length;
00188 GL.ShaderSource((UInt32)shader, 1, new string[] { @string }, &length);
00189 }
00190 }
00191
00192 #endregion
00193
00194 #region public static string GetShaderInfoLog(Int32 shader)
00195
00196 public static string GetShaderInfoLog(Int32 shader)
00197 {
00198 string info;
00199 GetShaderInfoLog(shader, out info);
00200 return info;
00201 }
00202
00203 #endregion
00204
00205 #region public static void GetShaderInfoLog(Int32 shader, out string info)
00206
00207 public static void GetShaderInfoLog(Int32 shader, out string info)
00208 {
00209 unsafe
00210 {
00211 int length;
00212 GL.GetShader(shader, ShaderParameter.InfoLogLength, out length);
00213 if (length == 0)
00214 {
00215 info = String.Empty;
00216 return;
00217 }
00218 StringBuilder sb = new StringBuilder(length * 2);
00219 GL.GetShaderInfoLog((UInt32)shader, sb.Capacity, &length, sb);
00220 info = sb.ToString();
00221 }
00222 }
00223
00224 #endregion
00225
00226 #region public static string GetProgramInfoLog(Int32 program)
00227
00228 public static string GetProgramInfoLog(Int32 program)
00229 {
00230 string info;
00231 GetProgramInfoLog(program, out info);
00232 return info;
00233 }
00234
00235 #endregion
00236
00237 #region public static void GetProgramInfoLog(Int32 program, out string info)
00238
00239 public static void GetProgramInfoLog(Int32 program, out string info)
00240 {
00241 unsafe
00242 {
00243 int length;
00244 GL.GetProgram(program, ProgramParameter.InfoLogLength, out length); if (length == 0)
00245 {
00246 info = String.Empty;
00247 return;
00248 }
00249 StringBuilder sb = new StringBuilder(length * 2);
00250 GL.GetProgramInfoLog((UInt32)program, sb.Capacity, &length, sb);
00251 info = sb.ToString();
00252 }
00253 }
00254
00255 #endregion
00256
00257 #endregion
00258
00259 #region public static void VertexAttrib2(Int32 index, ref Vector2 v)
00260
00261 [CLSCompliant(false)]
00262 public static void VertexAttrib2(Int32 index, ref Vector2 v)
00263 {
00264 GL.VertexAttrib2(index, v.X, v.Y);
00265 }
00266
00267 #endregion
00268
00269 #region public static void VertexAttrib3(Int32 index, ref Vector3 v)
00270
00271 [CLSCompliant(false)]
00272 public static void VertexAttrib3(Int32 index, ref Vector3 v)
00273 {
00274 GL.VertexAttrib3(index, v.X, v.Y, v.Z);
00275 }
00276
00277 #endregion
00278
00279 #region public static void VertexAttrib4(Int32 index, ref Vector4 v)
00280
00281 [CLSCompliant(false)]
00282 public static void VertexAttrib4(Int32 index, ref Vector4 v)
00283 {
00284 GL.VertexAttrib4(index, v.X, v.Y, v.Z, v.W);
00285 }
00286
00287 #endregion
00288
00289 #region public static void VertexAttrib2(Int32 index, Vector2 v)
00290
00291 public static void VertexAttrib2(Int32 index, Vector2 v)
00292 {
00293 GL.VertexAttrib2(index, v.X, v.Y);
00294 }
00295
00296 #endregion
00297
00298 #region public static void VertexAttrib3(Int32 index, Vector3 v)
00299
00300 public static void VertexAttrib3(Int32 index, Vector3 v)
00301 {
00302 GL.VertexAttrib3(index, v.X, v.Y, v.Z);
00303 }
00304
00305 #endregion
00306
00307 #region public static void VertexAttrib4(Int32 index, Vector4 v)
00308
00309 public static void VertexAttrib4(Int32 index, Vector4 v)
00310 {
00311 GL.VertexAttrib4(index, v.X, v.Y, v.Z, v.W);
00312 }
00313
00314 #endregion
00315
00316 #region VertexAttribPointer
00317
00318 public static void VertexAttribPointer(int index, int size, VertexAttribPointerType type, bool normalized, int stride, int offset)
00319 {
00320 VertexAttribPointer(index, size, type, normalized, stride, (IntPtr)offset);
00321 }
00322
00323 [CLSCompliant(false)]
00324 public static void VertexAttribPointer(uint index, int size, VertexAttribPointerType type, bool normalized, int stride, int offset)
00325 {
00326 VertexAttribPointer(index, size, type, normalized, stride, (IntPtr)offset);
00327 }
00328
00329 #endregion
00330
00331 #region DrawElements
00332
00333 public static void DrawElements(BeginMode mode, int count, DrawElementsType type, int offset)
00334 {
00335 DrawElements(mode, count, type, new IntPtr(offset));
00336 }
00337
00338 #endregion
00339
00340 #region public static int GenTexture()
00341
00342 public static int GenTexture()
00343 {
00344 int id;
00345 GenTextures(1, out id);
00346 return id;
00347 }
00348
00349 #endregion
00350
00351 #region public static void DeleteTexture(int id)
00352
00353 public static void DeleteTexture(int id)
00354 {
00355 DeleteTextures(1, ref id);
00356 }
00357
00358 #endregion
00359
00360 #region Get[Float|Double]
00361
00362 public static void GetFloat(GetPName pname, out Vector2 vector)
00363 {
00364 unsafe
00365 {
00366 fixed (Vector2* ptr = &vector)
00367 GetFloat(pname, (float*)ptr);
00368 }
00369 }
00370
00371 public static void GetFloat(GetPName pname, out Vector3 vector)
00372 {
00373 unsafe
00374 {
00375 fixed (Vector3* ptr = &vector)
00376 GetFloat(pname, (float*)ptr);
00377 }
00378 }
00379
00380 public static void GetFloat(GetPName pname, out Vector4 vector)
00381 {
00382 unsafe
00383 {
00384 fixed (Vector4* ptr = &vector)
00385 GetFloat(pname, (float*)ptr);
00386 }
00387 }
00388
00389 public static void GetFloat(GetPName pname, out Matrix4 matrix)
00390 {
00391 unsafe
00392 {
00393 fixed (Matrix4* ptr = &matrix)
00394 GetFloat(pname, (float*)ptr);
00395 }
00396 }
00397
00398 #endregion
00399
00400 #region Viewport
00401
00402 public static void Viewport(System.Drawing.Size size)
00403 {
00404 GL.Viewport(0, 0, size.Width, size.Height);
00405 }
00406
00407 public static void Viewport(System.Drawing.Point location, System.Drawing.Size size)
00408 {
00409 GL.Viewport(location.X, location.Y, size.Width, size.Height);
00410 }
00411
00412 public static void Viewport(System.Drawing.Rectangle rectangle)
00413 {
00414 GL.Viewport(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
00415 }
00416 #if NO_SYSDRAWING
00417 public static void Viewport(OpenTK.Point location, OpenTK.Size size)
00418 {
00419 GL.Viewport(location.X, location.Y, size.Width, size.Height);
00420 }
00421
00422 public static void Viewport(OpenTK.Rectangle rectangle)
00423 {
00424 GL.Viewport(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
00425 }
00426 #endif
00427 #endregion
00428
00429 #pragma warning restore 3019
00430 #pragma warning restore 1591
00431 #pragma warning restore 1572
00432 #pragma warning restore 1573
00433
00434 #endregion
00435 }
00436 }