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