lib/glesv2: intro services to synchronize operations on the server
[nit.git] / lib / glesv2 / glesv2.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2014 Alexis Laferrière <alexis.laf@xymus.net>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # OpenGL graphics rendering library for embedded systems, version 2.0
18 #
19 # This is a low-level wrapper, it can be useful for developers already familiar
20 # with the C API of OpenGL. Most developers will prefer to use higher level
21 # wrappers such as `mnit` and `gammit`.
22 #
23 # Defines the annotations `glsl_vertex_shader` and `glsl_fragment_shader`
24 # applicable on string literals to check shader code using `glslangValidator`.
25 # The tool must be in PATH. It can be downloaded from
26 # https://www.khronos.org/opengles/sdk/tools/Reference-Compiler/
27 #
28 # Most services of this module are a direct wrapper of the underlying
29 # C library. If a method or class is not documented in Nit, refer to
30 # the official documentation by the Khronos Group at:
31 # http://www.khronos.org/opengles/sdk/docs/man/
32 module glesv2 is
33 pkgconfig
34 new_annotation glsl_vertex_shader
35 new_annotation glsl_fragment_shader
36 ldflags("-lGLESv2")@android
37 end
38
39 import android::aware
40 intrude import c
41
42 in "C Header" `{
43 #include <GLES2/gl2.h>
44 `}
45
46 # OpenGL ES program to which we attach shaders
47 extern class GLProgram `{GLuint`}
48 # Create a new program
49 #
50 # The newly created instance should be checked using `is_ok`.
51 new `{ return glCreateProgram(); `}
52
53 # Set the location for the attribute by `name`
54 fun bind_attrib_location(index: Int, name: String) import String.to_cstring `{
55 GLchar *c_name = String_to_cstring(name);
56 glBindAttribLocation(self, index, c_name);
57 `}
58
59 # Get the location of the attribute by `name`
60 #
61 # Returns `-1` if there is no active attribute named `name`.
62 fun attrib_location(name: String): Int import String.to_cstring `{
63 GLchar *c_name = String_to_cstring(name);
64 return glGetAttribLocation(self, c_name);
65 `}
66
67 # Get the location of the uniform by `name`
68 #
69 # Returns `-1` if there is no active uniform named `name`.
70 fun uniform_location(name: String): Int import String.to_cstring `{
71 GLchar *c_name = String_to_cstring(name);
72 return glGetUniformLocation(self, c_name);
73 `}
74
75 # Query information on this program
76 fun query(pname: Int): Int `{
77 int val;
78 glGetProgramiv(self, pname, &val);
79 return val;
80 `}
81
82 # Is this program linked?
83 fun is_linked: Bool do return query(0x8B82) != 0
84
85 # Has this program been deleted?
86 fun is_deleted: Bool do return query(0x8B80) != 0
87
88 # Boolean result of `validate`, must be called after `validate`
89 fun is_validated: Bool do return query(0x8B83) != 0
90
91 # Retrieve the information log of this program
92 #
93 # Useful with `link` and `validate`
94 fun info_log: String import NativeString.to_s `{
95 int size;
96 glGetProgramiv(self, GL_INFO_LOG_LENGTH, &size);
97 GLchar *msg = malloc(size);
98 glGetProgramInfoLog(self, size, NULL, msg);
99 return NativeString_to_s(msg);
100 `}
101
102 # Number of active uniform in this program
103 #
104 # This should be the number of uniforms declared in all shader, except
105 # unused uniforms which may have been optimized out.
106 fun n_active_uniforms: Int do return query(0x8B86)
107
108 # Length of the longest uniform name in this program, including `\n`
109 fun active_uniform_max_length: Int do return query(0x8B87)
110
111 # Number of active attributes in this program
112 #
113 # This should be the number of uniforms declared in all shader, except
114 # unused uniforms which may have been optimized out.
115 fun n_active_attributes: Int do return query(0x8B89)
116
117 # Length of the longest uniform name in this program, including `\n`
118 fun active_attribute_max_length: Int do return query(0x8B8A)
119
120 # Number of shaders attached to this program
121 fun n_attached_shaders: Int do return query(0x8B85)
122
123 # Name of the active attribute at `index`
124 fun active_attrib_name(index: Int): String
125 do
126 var max_size = active_attribute_max_length
127 return active_attrib_name_native(index, max_size).to_s
128 end
129 private fun active_attrib_name_native(index, max_size: Int): NativeString `{
130 // We get more values than we need, for compatibility. At least the
131 // NVidia driver tries to fill them even if NULL.
132
133 char *name = malloc(max_size);
134 int size;
135 GLenum type;
136 glGetActiveAttrib(self, index, max_size, NULL, &size, &type, name);
137 return name;
138 `}
139
140 # Size of the active attribute at `index`
141 fun active_attrib_size(index: Int): Int `{
142 int size;
143 GLenum type;
144 glGetActiveAttrib(self, index, 0, NULL, &size, &type, NULL);
145 return size;
146 `}
147
148 # Type of the active attribute at `index`
149 #
150 # May only be float related data types (single float, vectors and matrix).
151 fun active_attrib_type(index: Int): GLFloatDataType `{
152 int size;
153 GLenum type;
154 glGetActiveAttrib(self, index, 0, NULL, &size, &type, NULL);
155 return type;
156 `}
157
158 # Name of the active uniform at `index`
159 fun active_uniform_name(index: Int): String
160 do
161 var max_size = active_attribute_max_length
162 return active_uniform_name_native(index, max_size).to_s
163 end
164 private fun active_uniform_name_native(index, max_size: Int): NativeString `{
165 char *name = malloc(max_size);
166 int size;
167 GLenum type;
168 glGetActiveUniform(self, index, max_size, NULL, &size, &type, name);
169 return name;
170 `}
171
172 # Size of the active uniform at `index`
173 fun active_uniform_size(index: Int): Int `{
174 int size;
175 GLenum type;
176 glGetActiveUniform(self, index, 0, NULL, &size, &type, NULL);
177 return size;
178 `}
179
180 # Type of the active uniform at `index`
181 #
182 # May be any data type supported by OpenGL ES 2.0 shaders.
183 fun active_uniform_type(index: Int): GLDataType `{
184 int size;
185 GLenum type = 0;
186 glGetActiveUniform(self, index, 0, NULL, &size, &type, NULL);
187 return type;
188 `}
189 end
190
191 # Create a program object
192 fun glCreateProgram: GLProgram `{ return glCreateProgram(); `}
193
194 # Install the `program` as part of current rendering state
195 fun glUseProgram(program: GLProgram) `{ glUseProgram(program); `}
196
197 # Link the `program` object
198 fun glLinkProgram(program: GLProgram) `{ glLinkProgram(program); `}
199
200 # Validate the `program` object
201 fun glValidateProgram(program: GLProgram) `{ glValidateProgram(program); `}
202
203 # Delete the `program` object
204 fun glDeleteProgram(program: GLProgram) `{ glDeleteProgram(program); `}
205
206 # Determine if `name` corresponds to a program object
207 fun glIsProgram(name: GLProgram): Bool `{ return glIsProgram(name); `}
208
209 # Attach a `shader` to `program`
210 fun glAttachShader(program: GLProgram, shader: GLShader) `{ glAttachShader(program, shader); `}
211
212 # Detach `shader` from `program`
213 fun glDetachShader(program: GLProgram, shader: GLShader) `{ glDetachShader(program, shader); `}
214
215 # Abstract OpenGL ES shader object, implemented by `GLFragmentShader` and `GLVertexShader`
216 extern class GLShader `{GLuint`}
217
218 # Source of the shader, if available
219 #
220 # Returns `null` if the source is not available, usually when the shader
221 # was created from a binary file.
222 fun source: nullable String
223 do
224 var size = query(0x8B88)
225 if size == 0 then return null
226 return source_native(size).to_s
227 end
228
229 private fun source_native(size: Int): NativeString `{
230 GLchar *code = malloc(size);
231 glGetShaderSource(self, size, NULL, code);
232 return code;
233 `}
234
235 # Query information on this shader
236 protected fun query(pname: Int): Int `{
237 int val;
238 glGetShaderiv(self, pname, &val);
239 return val;
240 `}
241
242 # Has this shader been compiled?
243 fun is_compiled: Bool do return query(0x8B81) != 0
244
245 # Has this shader been deleted?
246 fun is_deleted: Bool do return query(0x8B80) != 0
247
248 # Retrieve the information log of this shader
249 #
250 # Useful with `link` and `validate`
251 fun info_log: String import NativeString.to_s `{
252 int size;
253 glGetShaderiv(self, GL_INFO_LOG_LENGTH, &size);
254 GLchar *msg = malloc(size);
255 glGetShaderInfoLog(self, size, NULL, msg);
256 return NativeString_to_s(msg);
257 `}
258 end
259
260 # Shader type
261 extern class GLShaderType
262 super GLEnum
263 end
264
265 fun gl_VERTEX_SHADER: GLShaderType `{ return GL_VERTEX_SHADER; `}
266 fun gl_FRAGMENT_SHADER: GLShaderType `{ return GL_FRAGMENT_SHADER; `}
267
268 # Create a shader object of the `shader_type`
269 fun glCreateShader(shader_type: GLShaderType): GLShader `{
270 return glCreateShader(shader_type);
271 `}
272
273 # Replace the source code in the `shader` object with `code`
274 fun glShaderSource(shader: GLShader, code: NativeString) `{
275 glShaderSource(shader, 1, (GLchar const **)&code, NULL);
276 `}
277
278 # Compile the `shader` object
279 fun glCompileShader(shader: GLShader) `{ glCompileShader(shader); `}
280
281 # Delete the `shader` object
282 fun glDeleteShader(shader: GLShader) `{ glDeleteShader(shader); `}
283
284 # Determine if `name` corresponds to a shader object
285 fun glIsShader(name: GLShader): Bool `{ return glIsShader(name); `}
286
287 # An OpenGL ES 2.0 fragment shader
288 extern class GLFragmentShader
289 super GLShader
290
291 # Create a new fragment shader
292 #
293 # The newly created instance should be checked using `is_ok`.
294 new `{ return glCreateShader(GL_FRAGMENT_SHADER); `}
295 end
296
297 # An OpenGL ES 2.0 vertex shader
298 extern class GLVertexShader
299 super GLShader
300
301 # Create a new fragment shader
302 #
303 # The newly created instance should be checked using `is_ok`.
304 new `{ return glCreateShader(GL_VERTEX_SHADER); `}
305 end
306
307 # An array of `Float` associated to a program variable
308 class VertexArray
309 var index: Int
310
311 # Number of data per vertex
312 var count: Int
313
314 protected var glfloat_array: NativeGLfloatArray
315
316 init(index, count: Int, array: Array[Float])
317 do
318 self.index = index
319 self.count = count
320 self.glfloat_array = new NativeGLfloatArray(array.length)
321 for k in [0..array.length[ do
322 glfloat_array[k] = array[k]
323 end
324 end
325
326 fun attrib_pointer do attrib_pointer_intern(index, count, glfloat_array)
327 private fun attrib_pointer_intern(index, count: Int, array: NativeGLfloatArray) `{
328 glVertexAttribPointer(index, count, GL_FLOAT, GL_FALSE, 0, array);
329 `}
330
331 # Enable this vertex attribute array
332 fun enable do glEnableVertexAttribArray(index)
333
334 # Disable this vertex attribute array
335 fun disable do glDisableVertexAttribArray(index)
336 end
337
338 # Enable the generic vertex attribute array at `index`
339 fun glEnableVertexAttribArray(index: Int) `{ glEnableVertexAttribArray(index); `}
340
341 # Disable the generic vertex attribute array at `index`
342 fun glDisableVertexAttribArray(index: Int) `{ glDisableVertexAttribArray(index); `}
343
344 # Render primitives from array data
345 fun glDrawArrays(mode: GLDrawMode, from, count: Int) `{ glDrawArrays(mode, from, count); `}
346
347 # Define an array of generic vertex attribute data
348 fun glVertexAttribPointer(index, size: Int, typ: GLDataType, normalized: Bool, stride: Int, array: NativeGLfloatArray) `{
349 glVertexAttribPointer(index, size, typ, normalized, stride, array);
350 `}
351
352 # Specify the value of a generic vertex attribute
353 fun glVertexAttrib1f(index: Int, x: Float) `{ glVertexAttrib1f(index, x); `}
354
355 # Specify the value of a generic vertex attribute
356 fun glVertexAttrib2f(index: Int, x, y: Float) `{ glVertexAttrib2f(index, x, y); `}
357
358 # Specify the value of a generic vertex attribute
359 fun glVertexAttrib3f(index: Int, x, y, z: Float) `{ glVertexAttrib3f(index, x, y, z); `}
360
361 # Specify the value of a generic vertex attribute
362 fun glVertexAttrib4f(index: Int, x, y, z, w: Float) `{ glVertexAttrib4f(index, x, y, z, w); `}
363
364 # Specify the value of a uniform variable for the current program object
365 fun glUniform1i(index, x: Int) `{ glUniform1i(index, x); `}
366
367 # Specify the value of a uniform variable for the current program object
368 fun glUniform2i(index, x, y: Int) `{ glUniform2i(index, x, y); `}
369
370 # Specify the value of a uniform variable for the current program object
371 fun glUniform3i(index, x, y, z: Int) `{ glUniform3i(index, x, y, z); `}
372
373 # Specify the value of a uniform variable for the current program object
374 fun glUniform4i(index, x, y, z, w: Int) `{ glUniform4i(index, x, y, z, w); `}
375
376 # TODO glUniform*f
377
378 # Low level array of `Float`
379 class GLfloatArray
380 super CArray[Float]
381 redef type NATIVE: NativeGLfloatArray
382
383 init do native_array = new NativeGLfloatArray(length)
384
385 # Create with the content of `array`
386 new from(array: Array[Float])
387 do
388 var arr = new GLfloatArray(array.length)
389 arr.fill_from array
390 return arr
391 end
392
393 # Fill with the content of `array`
394 fun fill_from(array: Array[Float])
395 do
396 assert length >= array.length
397 for k in [0..array.length[ do
398 self[k] = array[k]
399 end
400 end
401 end
402
403 # An array of `GLfloat` in C (`GLfloat*`)
404 extern class NativeGLfloatArray `{ GLfloat* `}
405 super NativeCArray
406 redef type E: Float
407
408 new(size: Int) `{ return calloc(size, sizeof(GLfloat)); `}
409
410 redef fun [](index) `{ return self[index]; `}
411 redef fun []=(index, val) `{ self[index] = val; `}
412
413 redef fun +(offset) `{ return self + offset; `}
414 end
415
416 # General type for OpenGL enumerations
417 extern class GLEnum `{ GLenum `}
418
419 redef fun hash `{ return self; `}
420
421 redef fun ==(o) do return o != null and is_same_type(o) and o.hash == self.hash
422 end
423
424 # An OpenGL ES 2.0 error code
425 extern class GLError
426 super GLEnum
427
428 # Is there no error?
429 fun is_ok: Bool do return is_no_error
430
431 # Is this not an error?
432 fun is_no_error: Bool `{ return self == GL_NO_ERROR; `}
433
434 fun is_invalid_enum: Bool `{ return self == GL_INVALID_ENUM; `}
435 fun is_invalid_value: Bool `{ return self == GL_INVALID_VALUE; `}
436 fun is_invalid_operation: Bool `{ return self == GL_INVALID_OPERATION; `}
437 fun is_invalid_framebuffer_operation: Bool `{ return self == GL_INVALID_FRAMEBUFFER_OPERATION; `}
438 fun is_out_of_memory: Bool `{ return self == GL_OUT_OF_MEMORY; `}
439
440 redef fun to_s
441 do
442 if is_no_error then return "No error"
443 if is_invalid_enum then return "Invalid enum"
444 if is_invalid_value then return "Invalid value"
445 if is_invalid_operation then return "Invalid operation"
446 if is_invalid_framebuffer_operation then return "invalid framebuffer operation"
447 if is_out_of_memory then return "Out of memory"
448 return "Truely unknown error"
449 end
450 end
451
452 fun assert_no_gl_error
453 do
454 var error = gl.error
455 if not error.is_ok then
456 print "GL error: {error}"
457 abort
458 end
459 end
460
461 # Texture unit, the number of texture units is implementation dependent
462 extern class GLTextureUnit
463 super GLEnum
464 end
465
466 fun gl_TEXTURE0: GLTextureUnit `{ return GL_TEXTURE0; `}
467 fun gl_TEXTURE1: GLTextureUnit `{ return GL_TEXTURE1; `}
468 fun gl_TEXTURE2: GLTextureUnit `{ return GL_TEXTURE2; `}
469 fun gl_TEXTURE3: GLTextureUnit `{ return GL_TEXTURE3; `}
470 fun gl_TEXTURE4: GLTextureUnit `{ return GL_TEXTURE4; `}
471 fun gl_TEXTURE5: GLTextureUnit `{ return GL_TEXTURE5; `}
472 fun gl_TEXTURE6: GLTextureUnit `{ return GL_TEXTURE6; `}
473 fun gl_TEXTURE7: GLTextureUnit `{ return GL_TEXTURE7; `}
474 fun gl_TEXTURE8: GLTextureUnit `{ return GL_TEXTURE8; `}
475 fun gl_TEXTURE9: GLTextureUnit `{ return GL_TEXTURE9; `}
476 fun gl_TEXTURE10: GLTextureUnit `{ return GL_TEXTURE10; `}
477 fun gl_TEXTURE11: GLTextureUnit `{ return GL_TEXTURE11; `}
478 fun gl_TEXTURE12: GLTextureUnit `{ return GL_TEXTURE12; `}
479 fun gl_TEXTURE13: GLTextureUnit `{ return GL_TEXTURE13; `}
480 fun gl_TEXTURE14: GLTextureUnit `{ return GL_TEXTURE14; `}
481 fun gl_TEXTURE15: GLTextureUnit `{ return GL_TEXTURE15; `}
482 fun gl_TEXTURE16: GLTextureUnit `{ return GL_TEXTURE16; `}
483 fun gl_TEXTURE17: GLTextureUnit `{ return GL_TEXTURE17; `}
484 fun gl_TEXTURE18: GLTextureUnit `{ return GL_TEXTURE18; `}
485 fun gl_TEXTURE19: GLTextureUnit `{ return GL_TEXTURE19; `}
486 fun gl_TEXTURE20: GLTextureUnit `{ return GL_TEXTURE20; `}
487 fun gl_TEXTURE21: GLTextureUnit `{ return GL_TEXTURE21; `}
488 fun gl_TEXTURE22: GLTextureUnit `{ return GL_TEXTURE22; `}
489 fun gl_TEXTURE23: GLTextureUnit `{ return GL_TEXTURE23; `}
490 fun gl_TEXTURE24: GLTextureUnit `{ return GL_TEXTURE24; `}
491 fun gl_TEXTURE25: GLTextureUnit `{ return GL_TEXTURE25; `}
492 fun gl_TEXTURE26: GLTextureUnit `{ return GL_TEXTURE26; `}
493 fun gl_TEXTURE27: GLTextureUnit `{ return GL_TEXTURE27; `}
494 fun gl_TEXTURE28: GLTextureUnit `{ return GL_TEXTURE28; `}
495 fun gl_TEXTURE29: GLTextureUnit `{ return GL_TEXTURE29; `}
496 fun gl_TEXTURE30: GLTextureUnit `{ return GL_TEXTURE30; `}
497 fun gl_TEXTURE31: GLTextureUnit `{ return GL_TEXTURE31; `}
498
499 # Texture unit at `offset` after `gl_TEXTURE0`
500 fun gl_TEXTURE(offset: Int): GLTextureUnit `{ return GL_TEXTURE0 + offset; `}
501
502 # Generate `n` texture names
503 fun glGenTextures(n: Int): Array[Int]
504 do
505 var array = new CIntArray(n)
506 native_glGenTextures(n, array.native_array)
507 var a = array.to_a
508 array.destroy
509 return a
510 end
511
512 private fun native_glGenTextures(n: Int, textures: NativeCIntArray) `{
513 glGenTextures(n, (GLuint*)textures);
514 `}
515
516 # Select server-side active texture unit
517 fun glActiveTexture(texture: GLTextureUnit) `{ glActiveTexture(texture); `}
518
519 # Bind the named `texture` to a `target`
520 fun glBindTexture(target: GLTextureTarget, texture: Int) `{
521 glBindTexture(target, texture);
522 `}
523
524 # Delete named textures
525 fun glDeleteTextures(textures: SequenceRead[Int])
526 do
527 var n = textures.length
528 var array = new CIntArray.from(textures)
529 native_glDeleteTextures(n, array.native_array)
530 array.destroy
531 end
532
533 private fun native_glDeleteTextures(n: Int, textures: NativeCIntArray) `{
534 glDeleteTextures(n, (const GLuint *)textures);
535 `}
536
537 # Does `name` corresponds to a texture?
538 fun glIsTexture(name: Int): Bool `{ return glIsTexture(name); `}
539
540 # Set pixel storage modes
541 fun glPixelStorei(parameter: GLPack, val: Int) `{ glPixelStorei(parameter, val); `}
542
543 # Symbolic name of the parameter to be set with `glPixelStorei`
544 extern class GLPack
545 super GLEnum
546 end
547
548 # Parameter to specify the alignment requirements for the start of each pixel row in memory
549 fun gl_PACK_ALIGNEMENT: GLPack `{ return GL_PACK_ALIGNMENT; `}
550
551 # Parameter to specify the alignment requirements for the start of each pixel row in memory
552 fun gl_UNPACK_ALIGNEMENT: GLPack `{ return GL_UNPACK_ALIGNMENT; `}
553
554 # TODO GL_PACK_ROW_LENGTH, GL_PACK_IMAGE_HEIGHT, GL_PACK_SKIP_PIXELS, GL_PACK_SKIP_ROWS, GL_PACK_SKIP_IMAGES
555 # GL_UNPACK_ROW_LENGTH, GL_UNPACK_IMAGE_HEIGHT, GL_UNPACK_SKIP_PIXELS, GL_UNPACK_SKIP_ROWS, GL_UNPACK_SKIP_IMAGES
556
557 # Specify a two-dimensional texture image
558 fun glTexImage2D(target: GLTextureTarget, level: Int, internalformat: GLPixelFormat,
559 width, height, border: Int,
560 format: GLPixelFormat, typ: GLPixelType, data: Pointer) `{
561 glTexImage2D(target, level, internalformat, width, height, border, format, typ, data);
562 `}
563
564 # Specify a two-dimensional texture subimage
565 fun glTexSubImage2D(target: GLTextureTarget,
566 level, xoffset, yoffset, width, height, border: Int,
567 format: GLPixelFormat, typ: GLPixelType, data: Pointer) `{
568 glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, typ, data);
569 `}
570
571 # Copy pixels into a 2D texture image
572 fun glCopyTexImage2D(target: GLTextureTarget, level: Int, internalformat: GLPixelFormat,
573 x, y, width, height, border: Int) `{
574 glCopyTexImage2D(target, level, internalformat, x, y, width, height, border);
575 `}
576
577 # Copy a two-dimensional texture subimage
578 fun glCopyTexSubImage2D(target: GLTextureTarget, level, xoffset, yoffset, x, y, width, height: Int) `{
579 glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
580 `}
581
582 # Texture minifying and magnifying function
583 extern class GLTexParameteri
584 super GLEnum
585 end
586
587 fun gl_NEAREST: GLTexParameteri `{ return GL_NEAREST; `}
588 fun gl_LINEAR: GLTexParameteri `{ return GL_LINEAR; `}
589 fun gl_NEAREST_MIPMAP_NEAREST: GLTexParameteri `{ return GL_NEAREST_MIPMAP_NEAREST; `}
590 fun gl_LINEAR_MIPMAP_NEAREST: GLTexParameteri `{ return GL_LINEAR_MIPMAP_NEAREST; `}
591 fun gl_NEAREST_MIPMAP_NINEAR: GLTexParameteri `{ return GL_NEAREST_MIPMAP_LINEAR; `}
592 fun gl_LINEAR_MIPMAP_LINEAR: GLTexParameteri `{ return GL_LINEAR_MIPMAP_LINEAR; `}
593 fun gl_CLAMP_TO_EDGE: GLTexParameteri `{ return GL_CLAMP_TO_EDGE; `}
594 fun gl_MIRRORED_REPEAT: GLTexParameteri `{ return GL_MIRRORED_REPEAT; `}
595 fun gl_REPEAT: GLTexParameteri `{ return GL_REPEAT; `}
596
597 # Target texture
598 extern class GLTextureTarget
599 super GLEnum
600 end
601
602 # Two-dimensional texture
603 fun gl_TEXTURE_2D: GLTextureTarget `{ return GL_TEXTURE_2D; `}
604
605 # Cube map texture
606 fun gl_TEXTURE_CUBE_MAP: GLTextureTarget `{ return GL_TEXTURE_CUBE_MAP; `}
607
608 # TODO GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
609 # GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
610
611 # A server-side capability
612 class GLCap
613
614 # TODO private init
615
616 # Internal OpenGL integer for this capability
617 private var val: Int
618
619 # Enable this server-side capability
620 fun enable do enable_native(val)
621 private fun enable_native(cap: Int) `{ glEnable(cap); `}
622
623 # Disable this server-side capability
624 fun disable do disable_native(val)
625 private fun disable_native(cap: Int) `{ glDisable(cap); `}
626
627 redef fun hash do return val
628 redef fun ==(o) do return o != null and is_same_type(o) and o.hash == self.hash
629 end
630
631 # Generate `n` renderbuffer object names
632 fun glGenRenderbuffers(n: Int): Array[Int]
633 do
634 var array = new CIntArray(n)
635 native_glGenRenderbuffers(n, array.native_array)
636 var a = array.to_a
637 array.destroy
638 return a
639 end
640
641 private fun native_glGenRenderbuffers(n: Int, renderbuffers: NativeCIntArray) `{
642 glGenRenderbuffers(n, (GLuint *)renderbuffers);
643 `}
644
645 # Determine if `name` corresponds to a renderbuffer object
646 fun glIsRenderbuffer(name: Int): Bool `{
647 return glIsRenderbuffer(name);
648 `}
649
650 # Delete named renderbuffer objects
651 fun glDeleteRenderbuffers(renderbuffers: SequenceRead[Int])
652 do
653 var n = renderbuffers.length
654 var array = new CIntArray.from(renderbuffers)
655 native_glDeleteRenderbuffers(n, array.native_array)
656 array.destroy
657 end
658
659 private fun native_glDeleteRenderbuffers(n: Int, renderbuffers: NativeCIntArray) `{
660 return glDeleteRenderbuffers(n, (const GLuint *)renderbuffers);
661 `}
662
663 # Attach a renderbuffer object to a framebuffer object
664 fun glFramebufferRenderbuffer(target: GLFramebufferTarget, attachment: GLAttachment,
665 renderbuffertarget: GLRenderbufferTarget, renderbuffer: Int) `{
666 glFramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer);
667 `}
668
669 # Establish data storage, `format` and dimensions of the `target` renderbuffer object's image
670 fun glRenderbufferStorage(target: GLRenderbufferTarget, format: GLRenderbufferFormat, width, height: Int) `{
671 glRenderbufferStorage(GL_RENDERBUFFER, format, width, height);
672 `}
673
674 # Format for a renderbuffer
675 extern class GLRenderbufferFormat
676 super GLEnum
677 end
678
679 # 4 red, 4 green, 4 blue, 4 alpha bits format
680 fun gl_RGBA4: GLRenderbufferFormat `{ return GL_RGBA4; `}
681
682 # 5 red, 6 green, 5 blue bits format
683 fun gl_RGB565: GLRenderbufferFormat `{ return GL_RGB565; `}
684
685 # 5 red, 5 green, 5 blue, 1 alpha bits format
686 fun gl_RGB_A1: GLRenderbufferFormat `{ return GL_RGB5_A1; `}
687
688 # 16 depth bits format
689 fun gl_DEPTH_COMPNENT16: GLRenderbufferFormat `{ return GL_DEPTH_COMPONENT16; `}
690
691 # 8 stencil bits format
692 fun gl_STENCIL_INDEX8: GLRenderbufferFormat `{ return GL_STENCIL_INDEX8; `}
693
694 # Renderbuffer attachment point to a framebuffer
695 extern class GLAttachment
696 super GLEnum
697 end
698
699 # First color attachment point
700 fun gl_COLOR_ATTACHMENT0: GLAttachment `{ return GL_COLOR_ATTACHMENT0; `}
701
702 # Depth attachment point
703 fun gl_DEPTH_ATTACHMENT: GLAttachment `{ return GL_DEPTH_ATTACHMENT; `}
704
705 # Stencil attachment
706 fun gl_STENCIL_ATTACHMENT: GLAttachment `{ return GL_STENCIL_ATTACHMENT; `}
707
708 redef class Sys
709 private var gles = new GLES is lazy
710 end
711
712 # Entry points to OpenGL ES 2.0 services
713 fun gl: GLES do return sys.gles
714
715 # OpenGL ES 2.0 services
716 class GLES
717
718 # Specify mapping of depth values from normalized device coordinates to window coordinates
719 #
720 # Default at `gl_depth_range(0.0, 1.0)`
721 fun depth_range(near, far: Float) `{ glDepthRangef(near, far); `}
722
723 # Define front- and back-facing polygons
724 #
725 # Front-facing polygons are clockwise if `value`, counter-clockwise otherwise.
726 fun front_face=(value: Bool) `{ glFrontFace(value? GL_CW: GL_CCW); `}
727
728 # Specify whether front- or back-facing polygons can be culled, default is `back` only
729 #
730 # One or both of `front` or `back` must be `true`. If you want to deactivate culling
731 # use `(new GLCap.cull_face).disable`.
732 #
733 # Require: `front or back`
734 fun cull_face(front, back: Bool)
735 do
736 assert not (front or back)
737 cull_face_native(front, back)
738 end
739
740 private fun cull_face_native(front, back: Bool) `{
741 glCullFace(front? back? GL_FRONT_AND_BACK: GL_BACK: GL_FRONT);
742 `}
743
744 # Last error from OpenGL ES 2.0
745 fun error: GLError `{ return glGetError(); `}
746
747 # Query the boolean value at `key`
748 private fun get_bool(key: Int): Bool `{
749 GLboolean val;
750 glGetBooleanv(key, &val);
751 return val == GL_TRUE;
752 `}
753
754 # Query the floating point value at `key`
755 private fun get_float(key: Int): Float `{
756 GLfloat val;
757 glGetFloatv(key, &val);
758 return val;
759 `}
760
761 # Query the integer value at `key`
762 private fun get_int(key: Int): Int `{
763 GLint val;
764 glGetIntegerv(key, &val);
765 return val;
766 `}
767
768 # Does this driver support shader compilation?
769 #
770 # Should always return `true` in OpenGL ES 2.0 and 3.0.
771 fun shader_compiler: Bool do return get_bool(0x8DFA)
772
773 # Enable or disable writing into the depth buffer
774 fun depth_mask(value: Bool) `{ glDepthMask(value); `}
775
776 # Set the scale and units used to calculate depth values
777 fun polygon_offset(factor, units: Float) `{ glPolygonOffset(factor, units); `}
778
779 # Specify the width of rasterized lines
780 fun line_width(width: Float) `{ glLineWidth(width); `}
781
782 # Set the pixel arithmetic for the blending operations
783 #
784 # Defaultvalues before assignation:
785 # * `src_factor`: `GLBlendFactor::one`
786 # * `dst_factor`: `GLBlendFactor::zero`
787 fun blend_func(src_factor, dst_factor: GLBlendFactor) `{
788 glBlendFunc(src_factor, dst_factor);
789 `}
790
791 # Specify the value used for depth buffer comparisons
792 #
793 # Default value is `GLDepthFunc::less`
794 #
795 # Foreign: glDepthFunc
796 fun depth_func(func: GLDepthFunc) `{ glDepthFunc(func); `}
797
798 # Copy a block of pixels from the framebuffer of `fomat` and `typ` at `data`
799 #
800 # Foreign: glReadPixel
801 fun read_pixels(x, y, width, height: Int, format: GLPixelFormat, typ: GLPixelType, data: Pointer) `{
802 glReadPixels(x, y, width, height, format, typ, data);
803 `}
804
805 # Render primitives from array data
806 #
807 # Foreign: glDrawArrays
808 fun draw_arrays(mode: GLDrawMode, from, count: Int) `{ glDrawArrays(mode, from, count); `}
809
810 # OpenGL server-side capabilities
811 var capabilities = new GLCapabilities is lazy
812 end
813
814 # Specify the clear values for the color buffer, default values are at 0.0
815 fun glClearColor(red, green, blue, alpha: Float) `{
816 glClearColor(red, green, blue, alpha);
817 `}
818
819 # Specify the clear `value` for the depth buffer, default at 1.0
820 fun glClearDepthf(value: Float) `{ glClearDepthf(value); `}
821
822 # Specify the clear `value` for the stencil buffer, default at 0
823 fun glClearStencil(value: Int) `{ glClearStencil(value); `}
824
825 # Clear the `buffer`
826 fun glClear(buffer: GLBuffer) `{ glClear(buffer); `}
827
828 # Enable and disable writing of frame buffer color components
829 fun glColorMask(red, green, blue, alpha: Bool) `{ glColorMask(red, green, blue, alpha); `}
830
831 # Set the viewport
832 fun glViewport(x, y, width, height: Int) `{ glViewport(x, y, width, height); `}
833
834 # Block until all GL execution is complete
835 fun glFinish `{ glFinish(); `}
836
837 # Force execution of GL commands in finite time
838 fun glFlush `{ glFlush(); `}
839
840 # Set texture parameters
841 fun glTexParameteri(target: GLTextureTarget, pname: GLTexParameteriName, param: GLTexParameteri) `{
842 glTexParameteri(target, pname, param);
843 `}
844
845 # Name of parameters of textures
846 extern class GLTexParameteriName
847 super GLEnum
848 end
849
850 fun gl_TEXTURE_MIN_FILTER: GLTexParameteriName `{ return GL_TEXTURE_MIN_FILTER; `}
851 fun gl_TEXTURE_MAG_FILTER: GLTexParameteriName `{ return GL_TEXTURE_MAG_FILTER; `}
852 fun gl_TEXTURE_WRAP_S: GLTexParameteriName `{ return GL_TEXTURE_WRAP_S; `}
853 fun gl_TEXTURE_WRAP_T: GLTexParameteriName `{ return GL_TEXTURE_WRAP_T; `}
854
855 # Bind `framebuffer` to a framebuffer target
856 #
857 # In OpenGL ES 2.0, `target` must be `gl_FRAMEBUFFER`.
858 fun glBindFramebuffer(target: GLFramebufferTarget, framebuffer: Int) `{
859 glBindFramebuffer(target, framebuffer);
860 `}
861
862 # Target of `glBindFramebuffer`
863 extern class GLFramebufferTarget
864 super GLEnum
865 end
866
867 # Target both reading and writing on the framebuffer with `glBindFramebuffer`
868 fun gl_FRAMEBUFFER: GLFramebufferTarget `{ return GL_FRAMEBUFFER; `}
869
870 # Bind `renderbuffer` to a renderbuffer target
871 #
872 # In OpenGL ES 2.0, `target` must be `gl_RENDERBUFFER`.
873 fun glBindRenderbuffer(target: GLRenderbufferTarget, renderbuffer: Int) `{
874 glBindRenderbuffer(target, renderbuffer);
875 `}
876
877 # Target of `glBindRenderbuffer`
878 extern class GLRenderbufferTarget
879 super GLEnum
880 end
881
882 # Target a renderbuffer with `glBindRenderbuffer`
883 fun gl_RENDERBUFFER: GLRenderbufferTarget `{ return GL_RENDERBUFFER; `}
884
885 # Specify implementation specific hints
886 fun glHint(target: GLHintTarget, mode: GLHintMode) `{
887 glHint(target, mode);
888 `}
889
890 # Generate and fill set of mipmaps for the texture object `target`
891 fun glGenerateMipmap(target: GLTextureTarget) `{ glGenerateMipmap(target); `}
892
893 # Bind the named `buffer` object
894 fun glBindBuffer(target: GLArrayBuffer, buffer: Int) `{ glBindBuffer(target, buffer); `}
895
896 # Target to which bind the buffer with `glBindBuffer`
897 extern class GLArrayBuffer
898 super GLEnum
899 end
900
901 # Array buffer target
902 fun gl_ARRAY_BUFFER: GLArrayBuffer `{ return GL_ARRAY_BUFFER; `}
903
904 # Element array buffer
905 fun gl_ELEMENT_ARRAY_BUFFER: GLArrayBuffer `{ return GL_ELEMENT_ARRAY_BUFFER; `}
906
907 # Completeness status of a framebuffer object
908 fun glCheckFramebufferStatus(target: GLFramebufferTarget): GLFramebufferStatus `{
909 return glCheckFramebufferStatus(target);
910 `}
911
912 # Return value of `glCheckFramebufferStatus`
913 extern class GLFramebufferStatus
914 super GLEnum
915
916 redef fun to_s
917 do
918 if self == gl_FRAMEBUFFER_COMPLETE then return "complete"
919 if self == gl_FRAMEBUFFER_INCOMPLETE_ATTACHMENT then return "incomplete attachment"
920 if self == gl_FRAMEBUFFER_INCOMPLETE_DIMENSIONS then return "incomplete dimension"
921 if self == gl_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT then return "incomplete missing attachment"
922 if self == gl_FRAMEBUFFER_UNSUPPORTED then return "unsupported"
923 return "unknown"
924 end
925 end
926
927 # The framebuffer is complete
928 fun gl_FRAMEBUFFER_COMPLETE: GLFramebufferStatus `{
929 return GL_FRAMEBUFFER_COMPLETE;
930 `}
931
932 # Not all framebuffer attachment points are framebuffer attachment complete
933 fun gl_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: GLFramebufferStatus `{
934 return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
935 `}
936
937 # Not all attached images have the same width and height
938 fun gl_FRAMEBUFFER_INCOMPLETE_DIMENSIONS: GLFramebufferStatus `{
939 return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS;
940 `}
941
942 # No images are attached to the framebuffer
943 fun gl_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: GLFramebufferStatus `{
944 return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
945 `}
946
947 # The combination of internal formats of the attached images violates an implementation-dependent set of restrictions
948 fun gl_FRAMEBUFFER_UNSUPPORTED: GLFramebufferStatus `{
949 return GL_FRAMEBUFFER_UNSUPPORTED;
950 `}
951
952 # Hint target for `glHint`
953 extern class GLHintTarget
954 super GLEnum
955 end
956
957 # Indicates the quality of filtering when generating mipmap images
958 fun gl_GENERATE_MIPMAP_HINT: GLHintTarget `{ return GL_GENERATE_MIPMAP_HINT; `}
959
960 # Hint mode for `glHint`
961 extern class GLHintMode
962 super GLEnum
963 end
964
965 # The most efficient option should be chosen
966 fun gl_FASTEST: GLHintMode `{ return GL_FASTEST; `}
967
968 # The most correct, or highest quality, option should be chosen
969 fun gl_NICEST: GLHintMode `{ return GL_NICEST; `}
970
971 # No preference
972 fun gl_DONT_CARE: GLHintMode `{ return GL_DONT_CARE; `}
973
974 # Generate `n` framebuffer object names
975 fun glGenFramebuffers(n: Int): Array[Int]
976 do
977 var array = new CIntArray(n)
978 native_glGenFramebuffers(n, array.native_array)
979 var a = array.to_a
980 array.destroy
981 return a
982 end
983
984 private fun native_glGenFramebuffers(n: Int, textures: NativeCIntArray) `{
985 glGenFramebuffers(n, (GLuint *)textures);
986 `}
987
988 # Determine if `name` corresponds to a framebuffer object
989 fun glIsFramebuffer(name: Int): Bool `{
990 return glIsFramebuffer(name);
991 `}
992
993 # Delete named framebuffer objects
994 fun glDeleteFramebuffers(framebuffers: SequenceRead[Int])
995 do
996 var n = framebuffers.length
997 var array = new CIntArray.from(framebuffers)
998 native_glDeleteFramebuffers(n, array.native_array)
999 array.destroy
1000 end
1001
1002 private fun native_glDeleteFramebuffers(n: Int, framebuffers: NativeCIntArray) `{
1003 return glDeleteFramebuffers(n, (const GLuint *)framebuffers);
1004 `}
1005
1006 # Attach a level of a texture object as a logical buffer to the currently bound framebuffer object
1007 fun glFramebufferTexture2D(target: GLFramebufferTarget, attachment: GLAttachment,
1008 texture_target: GLTextureTarget, texture, level: Int) `{
1009 glFramebufferTexture2D(target, attachment, texture_target, texture, level);
1010 `}
1011
1012 # Entry point to OpenGL server-side capabilities
1013 class GLCapabilities
1014
1015 # GL capability: blend the computed fragment color values
1016 #
1017 # Foreign: GL_BLEND
1018 var blend: GLCap is lazy do return new GLCap(0x0BE2)
1019
1020 # GL capability: cull polygons based of their winding in window coordinates
1021 #
1022 # Foreign: GL_CULL_FACE
1023 var cull_face: GLCap is lazy do return new GLCap(0x0B44)
1024
1025 # GL capability: do depth comparisons and update the depth buffer
1026 #
1027 # Foreign: GL_DEPTH_TEST
1028 var depth_test: GLCap is lazy do return new GLCap(0x0B71)
1029
1030 # GL capability: dither color components or indices before they are written to the color buffer
1031 #
1032 # Foreign: GL_DITHER
1033 var dither: GLCap is lazy do return new GLCap(0x0BE2)
1034
1035 # GL capability: add an offset to depth values of a polygon fragment before depth test
1036 #
1037 # Foreign: GL_POLYGON_OFFSET_FILL
1038 var polygon_offset_fill: GLCap is lazy do return new GLCap(0x8037)
1039
1040 # GL capability: compute a temporary coverage value where each bit is determined by the alpha value at the corresponding location
1041 #
1042 # Foreign: GL_SAMPLE_ALPHA_TO_COVERAGE
1043 var sample_alpha_to_coverage: GLCap is lazy do return new GLCap(0x809E)
1044
1045 # GL capability: AND the fragment coverage with the temporary coverage value
1046 #
1047 # Foreign: GL_SAMPLE_COVERAGE
1048 var sample_coverage: GLCap is lazy do return new GLCap(0x80A0)
1049
1050 # GL capability: discard fragments that are outside the scissor rectangle
1051 #
1052 # Foreign: GL_SCISSOR_TEST
1053 var scissor_test: GLCap is lazy do return new GLCap(0x0C11)
1054
1055 # GL capability: do stencil testing and update the stencil buffer
1056 #
1057 # Foreign: GL_STENCIL_TEST
1058 var stencil_test: GLCap is lazy do return new GLCap(0x0B90)
1059 end
1060
1061 # Float related data types of OpenGL ES 2.0 shaders
1062 #
1063 # Only data types supported by shader attributes, as seen with
1064 # `GLProgram::active_attrib_type`.
1065 extern class GLFloatDataType
1066 super GLEnum
1067
1068 fun is_float: Bool `{ return self == GL_FLOAT; `}
1069 fun is_float_vec2: Bool `{ return self == GL_FLOAT_VEC2; `}
1070 fun is_float_vec3: Bool `{ return self == GL_FLOAT_VEC3; `}
1071 fun is_float_vec4: Bool `{ return self == GL_FLOAT_VEC4; `}
1072 fun is_float_mat2: Bool `{ return self == GL_FLOAT_MAT2; `}
1073 fun is_float_mat3: Bool `{ return self == GL_FLOAT_MAT3; `}
1074 fun is_float_mat4: Bool `{ return self == GL_FLOAT_MAT4; `}
1075
1076 # Instances of `GLFloatDataType` can be equal to instances of `GLDataType`
1077 redef fun ==(o)
1078 do
1079 return o != null and o isa GLFloatDataType and o.hash == self.hash
1080 end
1081 end
1082
1083 # All data types of OpenGL ES 2.0 shaders
1084 #
1085 # These types can be used by shader uniforms, as seen with
1086 # `GLProgram::active_uniform_type`.
1087 extern class GLDataType
1088 super GLFloatDataType
1089
1090 fun is_int: Bool `{ return self == GL_INT; `}
1091 fun is_int_vec2: Bool `{ return self == GL_INT_VEC2; `}
1092 fun is_int_vec3: Bool `{ return self == GL_INT_VEC3; `}
1093 fun is_int_vec4: Bool `{ return self == GL_INT_VEC4; `}
1094 fun is_bool: Bool `{ return self == GL_BOOL; `}
1095 fun is_bool_vec2: Bool `{ return self == GL_BOOL_VEC2; `}
1096 fun is_bool_vec3: Bool `{ return self == GL_BOOL_VEC3; `}
1097 fun is_bool_vec4: Bool `{ return self == GL_BOOL_VEC4; `}
1098 fun is_sampler_2d: Bool `{ return self == GL_SAMPLER_2D; `}
1099 fun is_sampler_cube: Bool `{ return self == GL_SAMPLER_CUBE; `}
1100 end
1101
1102 # Kind of primitives to render
1103 extern class GLDrawMode
1104 super GLEnum
1105 end
1106
1107 fun gl_POINTS: GLDrawMode `{ return GL_POINTS; `}
1108 fun gl_LINES: GLDrawMode `{ return GL_LINES; `}
1109 fun gl_LINE_LOOP: GLDrawMode `{ return GL_LINE_LOOP; `}
1110 fun gl_LINE_STRIP: GLDrawMode `{ return GL_LINE_STRIP; `}
1111 fun gl_TRIANGLES: GLDrawMode `{ return GL_TRIANGLES; `}
1112 fun gl_TRIANGLE_STRIP: GLDrawMode `{ return GL_TRIANGLE_STRIP; `}
1113 fun gl_TRIANGLE_FAN: GLDrawMode `{ return GL_TRIANGLE_FAN; `}
1114
1115 # Pixel arithmetic for blending operations
1116 extern class GLBlendFactor
1117 super GLEnum
1118 end
1119
1120 fun gl_ZERO: GLBlendFactor `{ return GL_ZERO; `}
1121 fun gl_ONE: GLBlendFactor `{ return GL_ONE; `}
1122 fun gl_SRC_COLOR: GLBlendFactor `{ return GL_SRC_COLOR; `}
1123 fun gl_ONE_MINUS_SRC_COLOR: GLBlendFactor `{ return GL_ONE_MINUS_SRC_COLOR; `}
1124 fun gl_SRC_ALPHA: GLBlendFactor `{ return GL_SRC_ALPHA; `}
1125 fun gl_ONE_MINUS_SRC_ALPHA: GLBlendFactor `{ return GL_ONE_MINUS_SRC_ALPHA; `}
1126 fun gl_DST_ALPHA: GLBlendFactor `{ return GL_DST_ALPHA; `}
1127 fun gl_ONE_MINUS_DST_ALPHA: GLBlendFactor `{ return GL_ONE_MINUS_DST_ALPHA; `}
1128 fun gl_DST_COLOR: GLBlendFactor `{ return GL_DST_COLOR; `}
1129 fun gl_ONE_MINUS_DST_COLOR: GLBlendFactor `{ return GL_ONE_MINUS_DST_COLOR; `}
1130 fun gl_SRC_ALPHA_SATURATE: GLBlendFactor `{ return GL_SRC_ALPHA_SATURATE; `}
1131
1132 # Condition under which a pixel will be drawn
1133 extern class GLDepthFunc
1134 super GLEnum
1135 end
1136
1137 fun gl_NEVER: GLDepthFunc `{ return GL_NEVER; `}
1138 fun gl_LESS: GLDepthFunc `{ return GL_LESS; `}
1139 fun gl_EQUAL: GLDepthFunc `{ return GL_EQUAL; `}
1140 fun gl_LEQUAL: GLDepthFunc `{ return GL_LEQUAL; `}
1141 fun gl_GREATER: GLDepthFunc `{ return GL_GREATER; `}
1142 fun gl_NOTEQUAL: GLDepthFunc `{ return GL_NOTEQUAL; `}
1143 fun gl_GEQUAL: GLDepthFunc `{ return GL_GEQUAL; `}
1144 fun gl_ALWAYS: GLDepthFunc `{ return GL_ALWAYS; `}
1145
1146 # Format of pixel data
1147 extern class GLPixelFormat
1148 super GLEnum
1149 end
1150
1151 fun gl_ALPHA: GLPixelFormat `{ return GL_ALPHA; `}
1152 fun gl_RGB: GLPixelFormat `{ return GL_RGB; `}
1153 fun gl_RGBA: GLPixelFormat `{ return GL_RGBA; `}
1154
1155 # Data type of pixel data
1156 extern class GLPixelType
1157 super GLEnum
1158 end
1159
1160 fun gl_UNSIGNED_BYTE: GLPixelType `{ return GL_UNSIGNED_BYTE; `}
1161 fun gl_UNSIGNED_SHORT_5_6_5: GLPixelType `{ return GL_UNSIGNED_SHORT_5_6_5; `}
1162 fun gl_UNSIGNED_SHORT_4_4_4_4: GLPixelType `{ return GL_UNSIGNED_SHORT_4_4_4_4; `}
1163 fun gl_UNSIGNED_SHORT_5_5_5_1: GLPixelType `{ return GL_UNSIGNED_SHORT_5_5_5_1; `}
1164
1165 # Set of buffers as a bitwise OR mask
1166 extern class GLBuffer `{ GLbitfield `}
1167 # Bitwise OR with `other`
1168 fun |(other: GLBuffer): GLBuffer `{ return self | other; `}
1169 end
1170
1171 fun gl_DEPTH_BUFFER_BIT: GLBuffer `{ return GL_DEPTH_BUFFER_BIT; `}
1172 fun gl_STENCIL_BUFFER_BIT: GLBuffer `{ return GL_STENCIL_BUFFER_BIT; `}
1173 fun gl_COLOR_BUFFER_BIT: GLBuffer `{ return GL_COLOR_BUFFER_BIT; `}