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