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