6c520833ccbb6a7c0162ac6f861fedc7b8f26e3f
[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 FinalizableOnce
438
439 var length: Int
440
441 var native_array = new NativeGLfloatArray(length) is lateinit
442
443 fun [](index: Int): Float do return native_array[index]
444
445 fun []=(index: Int, val: Float) do native_array[index] = val
446
447 var add_index = 0
448
449 fun reset_add do add_index = 0
450
451 # Require: `add_index < length`
452 fun add(value: Float)
453 do
454 var index = add_index
455 assert index < length
456 native_array[index] = value
457 self.add_index = index + 1
458 end
459
460 # Create with the content of `array`
461 new from(array: Array[Float])
462 do
463 var arr = new GLfloatArray(array.length)
464 arr.fill_from array
465 return arr
466 end
467
468 # Fill with the content of `array`
469 #
470 # If `dst_offset` is set, the data is copied to the index `dst_offset`,
471 # otherwise, it is copied the beginning of `self`.
472 #
473 # Require: `length >= array.length + dst_offset or else 0`
474 fun fill_from(array: Array[Float], dst_offset: nullable Int)
475 do
476 dst_offset = dst_offset or else add_index
477
478 assert length >= array.length + dst_offset
479 for k in [0..array.length[ do
480 self[dst_offset+k] = array[k]
481 end
482 end
483
484 redef fun finalize_once do native_array.free
485 end
486
487 # An array of `GLfloat` in C (`GLfloat*`)
488 extern class NativeGLfloatArray `{ GLfloat* `}
489
490 new(size: Int) `{ return calloc(size, sizeof(GLfloat)); `}
491
492 fun [](index: Int): Float `{ return self[index]; `}
493
494 fun []=(index: Int, val: Float) `{ self[index] = val; `}
495
496 fun +(offset: Int): NativeGLfloatArray `{ return self + offset; `}
497 end
498
499 # General type for OpenGL enumerations
500 extern class GLEnum `{ GLenum `}
501
502 redef fun hash `{ return self; `}
503
504 redef fun ==(o) do return o != null and is_same_type(o) and o.hash == self.hash
505 end
506
507 # Error information
508 fun glGetError: GLError `{ return glGetError(); `}
509
510 # An OpenGL ES 2.0 error code
511 extern class GLError
512 super GLEnum
513
514 redef fun to_s
515 do
516 if self == gl_NO_ERROR then return "No error"
517 if self == gl_INVALID_ENUM then return "Invalid enum"
518 if self == gl_INVALID_VALUE then return "Invalid value"
519 if self == gl_INVALID_OPERATION then return "Invalid operation"
520 if self == gl_INVALID_FRAMEBUFFER_OPERATION then return "invalid framebuffer operation"
521 if self == gl_OUT_OF_MEMORY then return "Out of memory"
522 return "Unknown error"
523 end
524 end
525
526 fun gl_NO_ERROR: GLError `{ return GL_NO_ERROR; `}
527 fun gl_INVALID_ENUM: GLError `{ return GL_INVALID_ENUM; `}
528 fun gl_INVALID_VALUE: GLError `{ return GL_INVALID_VALUE; `}
529 fun gl_INVALID_OPERATION: GLError `{ return GL_INVALID_OPERATION; `}
530 fun gl_INVALID_FRAMEBUFFER_OPERATION: GLError `{ return GL_INVALID_FRAMEBUFFER_OPERATION; `}
531 fun gl_OUT_OF_MEMORY: GLError `{ return GL_OUT_OF_MEMORY; `}
532
533 fun assert_no_gl_error
534 do
535 var error = glGetError
536 if not error == gl_NO_ERROR then
537 print "GL error: {error}"
538 abort
539 end
540 end
541
542 # Texture unit, the number of texture units is implementation dependent
543 extern class GLTextureUnit
544 super GLEnum
545 end
546
547 fun gl_TEXTURE0: GLTextureUnit `{ return GL_TEXTURE0; `}
548 fun gl_TEXTURE1: GLTextureUnit `{ return GL_TEXTURE1; `}
549 fun gl_TEXTURE2: GLTextureUnit `{ return GL_TEXTURE2; `}
550 fun gl_TEXTURE3: GLTextureUnit `{ return GL_TEXTURE3; `}
551 fun gl_TEXTURE4: GLTextureUnit `{ return GL_TEXTURE4; `}
552 fun gl_TEXTURE5: GLTextureUnit `{ return GL_TEXTURE5; `}
553 fun gl_TEXTURE6: GLTextureUnit `{ return GL_TEXTURE6; `}
554 fun gl_TEXTURE7: GLTextureUnit `{ return GL_TEXTURE7; `}
555 fun gl_TEXTURE8: GLTextureUnit `{ return GL_TEXTURE8; `}
556 fun gl_TEXTURE9: GLTextureUnit `{ return GL_TEXTURE9; `}
557 fun gl_TEXTURE10: GLTextureUnit `{ return GL_TEXTURE10; `}
558 fun gl_TEXTURE11: GLTextureUnit `{ return GL_TEXTURE11; `}
559 fun gl_TEXTURE12: GLTextureUnit `{ return GL_TEXTURE12; `}
560 fun gl_TEXTURE13: GLTextureUnit `{ return GL_TEXTURE13; `}
561 fun gl_TEXTURE14: GLTextureUnit `{ return GL_TEXTURE14; `}
562 fun gl_TEXTURE15: GLTextureUnit `{ return GL_TEXTURE15; `}
563 fun gl_TEXTURE16: GLTextureUnit `{ return GL_TEXTURE16; `}
564 fun gl_TEXTURE17: GLTextureUnit `{ return GL_TEXTURE17; `}
565 fun gl_TEXTURE18: GLTextureUnit `{ return GL_TEXTURE18; `}
566 fun gl_TEXTURE19: GLTextureUnit `{ return GL_TEXTURE19; `}
567 fun gl_TEXTURE20: GLTextureUnit `{ return GL_TEXTURE20; `}
568 fun gl_TEXTURE21: GLTextureUnit `{ return GL_TEXTURE21; `}
569 fun gl_TEXTURE22: GLTextureUnit `{ return GL_TEXTURE22; `}
570 fun gl_TEXTURE23: GLTextureUnit `{ return GL_TEXTURE23; `}
571 fun gl_TEXTURE24: GLTextureUnit `{ return GL_TEXTURE24; `}
572 fun gl_TEXTURE25: GLTextureUnit `{ return GL_TEXTURE25; `}
573 fun gl_TEXTURE26: GLTextureUnit `{ return GL_TEXTURE26; `}
574 fun gl_TEXTURE27: GLTextureUnit `{ return GL_TEXTURE27; `}
575 fun gl_TEXTURE28: GLTextureUnit `{ return GL_TEXTURE28; `}
576 fun gl_TEXTURE29: GLTextureUnit `{ return GL_TEXTURE29; `}
577 fun gl_TEXTURE30: GLTextureUnit `{ return GL_TEXTURE30; `}
578 fun gl_TEXTURE31: GLTextureUnit `{ return GL_TEXTURE31; `}
579
580 # Texture unit at `offset` after `gl_TEXTURE0`
581 fun gl_TEXTURE(offset: Int): GLTextureUnit `{ return GL_TEXTURE0 + offset; `}
582
583 # Generate `n` texture names
584 fun glGenTextures(n: Int): Array[Int]
585 do
586 var array = new CIntArray(n)
587 native_glGenTextures(n, array.native_array)
588 var a = array.to_a
589 array.destroy
590 return a
591 end
592
593 private fun native_glGenTextures(n: Int, textures: NativeCIntArray) `{
594 glGenTextures(n, (GLuint*)textures);
595 `}
596
597 # Select server-side active texture unit
598 fun glActiveTexture(texture: GLTextureUnit) `{ glActiveTexture(texture); `}
599
600 # Bind the named `texture` to a `target`
601 fun glBindTexture(target: GLTextureTarget, texture: Int) `{
602 glBindTexture(target, texture);
603 `}
604
605 # Delete named textures
606 fun glDeleteTextures(textures: SequenceRead[Int])
607 do
608 var n = textures.length
609 var array = new CIntArray.from(textures)
610 native_glDeleteTextures(n, array.native_array)
611 array.destroy
612 end
613
614 private fun native_glDeleteTextures(n: Int, textures: NativeCIntArray) `{
615 glDeleteTextures(n, (const GLuint *)textures);
616 `}
617
618 # Does `name` corresponds to a texture?
619 fun glIsTexture(name: Int): Bool `{ return glIsTexture(name); `}
620
621 # Set pixel storage modes
622 fun glPixelStorei(parameter: GLPack, val: Int) `{ glPixelStorei(parameter, val); `}
623
624 # Symbolic name of the parameter to be set with `glPixelStorei`
625 extern class GLPack
626 super GLEnum
627 end
628
629 # Parameter to specify the alignment requirements for the start of each pixel row in memory
630 fun gl_PACK_ALIGNEMENT: GLPack `{ return GL_PACK_ALIGNMENT; `}
631
632 # Parameter to specify the alignment requirements for the start of each pixel row in memory
633 fun gl_UNPACK_ALIGNEMENT: GLPack `{ return GL_UNPACK_ALIGNMENT; `}
634
635 # TODO GL_PACK_ROW_LENGTH, GL_PACK_IMAGE_HEIGHT, GL_PACK_SKIP_PIXELS, GL_PACK_SKIP_ROWS, GL_PACK_SKIP_IMAGES
636 # GL_UNPACK_ROW_LENGTH, GL_UNPACK_IMAGE_HEIGHT, GL_UNPACK_SKIP_PIXELS, GL_UNPACK_SKIP_ROWS, GL_UNPACK_SKIP_IMAGES
637
638 # Specify a two-dimensional texture image
639 fun glTexImage2D(target: GLTextureTarget, level: Int, internalformat: GLPixelFormat,
640 width, height, border: Int,
641 format: GLPixelFormat, typ: GLDataType, data: Pointer) `{
642 glTexImage2D(target, level, internalformat, width, height, border, format, typ, data);
643 `}
644
645 # Specify a two-dimensional texture subimage
646 fun glTexSubImage2D(target: GLTextureTarget,
647 level, xoffset, yoffset, width, height, border: Int,
648 format: GLPixelFormat, typ: GLDataType, data: Pointer) `{
649 glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, typ, data);
650 `}
651
652 # Copy pixels into a 2D texture image
653 fun glCopyTexImage2D(target: GLTextureTarget, level: Int, internalformat: GLPixelFormat,
654 x, y, width, height, border: Int) `{
655 glCopyTexImage2D(target, level, internalformat, x, y, width, height, border);
656 `}
657
658 # Copy a two-dimensional texture subimage
659 fun glCopyTexSubImage2D(target: GLTextureTarget, level, xoffset, yoffset, x, y, width, height: Int) `{
660 glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
661 `}
662
663 # Copy a block of pixels from the framebuffer of `fomat` and `typ` at `data`
664 fun glReadPixels(x, y, width, height: Int, format: GLPixelFormat, typ: GLDataType, data: Pointer) `{
665 glReadPixels(x, y, width, height, format, typ, data);
666 `}
667
668 # Texture minifying and magnifying function
669 extern class GLTexParameteri
670 super GLEnum
671 end
672
673 fun gl_NEAREST: GLTexParameteri `{ return GL_NEAREST; `}
674 fun gl_LINEAR: GLTexParameteri `{ return GL_LINEAR; `}
675 fun gl_NEAREST_MIPMAP_NEAREST: GLTexParameteri `{ return GL_NEAREST_MIPMAP_NEAREST; `}
676 fun gl_LINEAR_MIPMAP_NEAREST: GLTexParameteri `{ return GL_LINEAR_MIPMAP_NEAREST; `}
677 fun gl_NEAREST_MIPMAP_NINEAR: GLTexParameteri `{ return GL_NEAREST_MIPMAP_LINEAR; `}
678 fun gl_LINEAR_MIPMAP_LINEAR: GLTexParameteri `{ return GL_LINEAR_MIPMAP_LINEAR; `}
679 fun gl_CLAMP_TO_EDGE: GLTexParameteri `{ return GL_CLAMP_TO_EDGE; `}
680 fun gl_MIRRORED_REPEAT: GLTexParameteri `{ return GL_MIRRORED_REPEAT; `}
681 fun gl_REPEAT: GLTexParameteri `{ return GL_REPEAT; `}
682
683 # Target texture
684 extern class GLTextureTarget
685 super GLEnum
686 end
687
688 # Two-dimensional texture
689 fun gl_TEXTURE_2D: GLTextureTarget `{ return GL_TEXTURE_2D; `}
690
691 # Cube map texture
692 fun gl_TEXTURE_CUBE_MAP: GLTextureTarget `{ return GL_TEXTURE_CUBE_MAP; `}
693
694 # TODO GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
695 # GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
696
697 # A server-side capability
698 class GLCap
699
700 # TODO private init
701
702 # Internal OpenGL integer for this capability
703 private var val: Int
704
705 # Enable this server-side capability
706 fun enable do enable_native(val)
707 private fun enable_native(cap: Int) `{ glEnable(cap); `}
708
709 # Disable this server-side capability
710 fun disable do disable_native(val)
711 private fun disable_native(cap: Int) `{ glDisable(cap); `}
712
713 redef fun hash do return val
714 redef fun ==(o) do return o != null and is_same_type(o) and o.hash == self.hash
715 end
716
717 # Generate `n` renderbuffer object names
718 fun glGenRenderbuffers(n: Int): Array[Int]
719 do
720 var array = new CIntArray(n)
721 native_glGenRenderbuffers(n, array.native_array)
722 var a = array.to_a
723 array.destroy
724 return a
725 end
726
727 private fun native_glGenRenderbuffers(n: Int, renderbuffers: NativeCIntArray) `{
728 glGenRenderbuffers(n, (GLuint *)renderbuffers);
729 `}
730
731 # Does `name` corresponds to a renderbuffer object?
732 fun glIsRenderbuffer(name: Int): Bool `{
733 return glIsRenderbuffer(name);
734 `}
735
736 # Delete named renderbuffer objects
737 fun glDeleteRenderbuffers(renderbuffers: SequenceRead[Int])
738 do
739 var n = renderbuffers.length
740 var array = new CIntArray.from(renderbuffers)
741 native_glDeleteRenderbuffers(n, array.native_array)
742 array.destroy
743 end
744
745 private fun native_glDeleteRenderbuffers(n: Int, renderbuffers: NativeCIntArray) `{
746 return glDeleteRenderbuffers(n, (const GLuint *)renderbuffers);
747 `}
748
749 # Attach a renderbuffer object to a framebuffer object
750 fun glFramebufferRenderbuffer(target: GLFramebufferTarget, attachment: GLAttachment,
751 renderbuffertarget: GLRenderbufferTarget, renderbuffer: Int) `{
752 glFramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer);
753 `}
754
755 # Establish data storage, `format` and dimensions of the `target` renderbuffer object's image
756 fun glRenderbufferStorage(target: GLRenderbufferTarget, format: GLRenderbufferFormat, width, height: Int) `{
757 glRenderbufferStorage(GL_RENDERBUFFER, format, width, height);
758 `}
759
760 # Format for a renderbuffer
761 extern class GLRenderbufferFormat
762 super GLEnum
763 end
764
765 # 4 red, 4 green, 4 blue, 4 alpha bits format
766 fun gl_RGBA4: GLRenderbufferFormat `{ return GL_RGBA4; `}
767
768 # 5 red, 6 green, 5 blue bits format
769 fun gl_RGB565: GLRenderbufferFormat `{ return GL_RGB565; `}
770
771 # 5 red, 5 green, 5 blue, 1 alpha bits format
772 fun gl_RGB5_A1: GLRenderbufferFormat `{ return GL_RGB5_A1; `}
773
774 # 16 depth bits format
775 fun gl_DEPTH_COMPONENT16: GLRenderbufferFormat `{ return GL_DEPTH_COMPONENT16; `}
776
777 # 8 stencil bits format
778 fun gl_STENCIL_INDEX8: GLRenderbufferFormat `{ return GL_STENCIL_INDEX8; `}
779
780 # Renderbuffer attachment point to a framebuffer
781 extern class GLAttachment
782 super GLEnum
783 end
784
785 # First color attachment point
786 fun gl_COLOR_ATTACHMENT0: GLAttachment `{ return GL_COLOR_ATTACHMENT0; `}
787
788 # Depth attachment point
789 fun gl_DEPTH_ATTACHMENT: GLAttachment `{ return GL_DEPTH_ATTACHMENT; `}
790
791 # Stencil attachment
792 fun gl_STENCIL_ATTACHMENT: GLAttachment `{ return GL_STENCIL_ATTACHMENT; `}
793
794 redef class Sys
795 private var gles = new GLES is lazy
796 end
797
798 # Entry points to OpenGL ES 2.0 services
799 fun gl: GLES do return sys.gles
800
801 # OpenGL ES 2.0 services
802 class GLES
803
804 # Query the boolean value at `key`
805 private fun get_bool(key: Int): Bool `{
806 GLboolean val;
807 glGetBooleanv(key, &val);
808 return val == GL_TRUE;
809 `}
810
811 # Query the floating point value at `key`
812 private fun get_float(key: Int): Float `{
813 GLfloat val;
814 glGetFloatv(key, &val);
815 return val;
816 `}
817
818 # Query the integer value at `key`
819 private fun get_int(key: Int): Int `{
820 GLint val;
821 glGetIntegerv(key, &val);
822 return val;
823 `}
824
825 # Does this driver support shader compilation?
826 #
827 # Should always return `true` in OpenGL ES 2.0 and 3.0.
828 fun shader_compiler: Bool do return get_bool(0x8DFA)
829
830 # OpenGL server-side capabilities
831 var capabilities = new GLCapabilities is lazy
832 end
833
834 # Specify the clear values for the color buffer, default values are at 0.0
835 fun glClearColor(red, green, blue, alpha: Float) `{
836 glClearColor(red, green, blue, alpha);
837 `}
838
839 # Specify the clear `value` for the depth buffer, default at 1.0
840 fun glClearDepthf(value: Float) `{ glClearDepthf(value); `}
841
842 # Specify the clear `value` for the stencil buffer, default at 0
843 fun glClearStencil(value: Int) `{ glClearStencil(value); `}
844
845 # Clear the `buffer`
846 fun glClear(buffer: GLBuffer) `{ glClear(buffer); `}
847
848 # Enable and disable writing of frame buffer color components
849 fun glColorMask(red, green, blue, alpha: Bool) `{ glColorMask(red, green, blue, alpha); `}
850
851 # Set the viewport
852 fun glViewport(x, y, width, height: Int) `{ glViewport(x, y, width, height); `}
853
854 # Block until all GL execution is complete
855 fun glFinish `{ glFinish(); `}
856
857 # Force execution of GL commands in finite time
858 fun glFlush `{ glFlush(); `}
859
860 # Set texture parameters
861 fun glTexParameteri(target: GLTextureTarget, pname: GLTexParameteriName, param: GLTexParameteri) `{
862 glTexParameteri(target, pname, param);
863 `}
864
865 # Name of parameters of textures
866 extern class GLTexParameteriName
867 super GLEnum
868 end
869
870 fun gl_TEXTURE_MIN_FILTER: GLTexParameteriName `{ return GL_TEXTURE_MIN_FILTER; `}
871 fun gl_TEXTURE_MAG_FILTER: GLTexParameteriName `{ return GL_TEXTURE_MAG_FILTER; `}
872 fun gl_TEXTURE_WRAP_S: GLTexParameteriName `{ return GL_TEXTURE_WRAP_S; `}
873 fun gl_TEXTURE_WRAP_T: GLTexParameteriName `{ return GL_TEXTURE_WRAP_T; `}
874
875 # Bind `framebuffer` to a framebuffer target
876 #
877 # In OpenGL ES 2.0, `target` must be `gl_FRAMEBUFFER`.
878 fun glBindFramebuffer(target: GLFramebufferTarget, framebuffer: Int) `{
879 glBindFramebuffer(target, framebuffer);
880 `}
881
882 # Target of `glBindFramebuffer`
883 extern class GLFramebufferTarget
884 super GLEnum
885 end
886
887 # Target both reading and writing on the framebuffer with `glBindFramebuffer`
888 fun gl_FRAMEBUFFER: GLFramebufferTarget `{ return GL_FRAMEBUFFER; `}
889
890 # Bind `renderbuffer` to a renderbuffer target
891 #
892 # In OpenGL ES 2.0, `target` must be `gl_RENDERBUFFER`.
893 fun glBindRenderbuffer(target: GLRenderbufferTarget, renderbuffer: Int) `{
894 glBindRenderbuffer(target, renderbuffer);
895 `}
896
897 # Target of `glBindRenderbuffer`
898 extern class GLRenderbufferTarget
899 super GLEnum
900 end
901
902 # Target a renderbuffer with `glBindRenderbuffer`
903 fun gl_RENDERBUFFER: GLRenderbufferTarget `{ return GL_RENDERBUFFER; `}
904
905 # Specify implementation specific hints
906 fun glHint(target: GLHintTarget, mode: GLHintMode) `{
907 glHint(target, mode);
908 `}
909
910 # Generate and fill set of mipmaps for the texture object `target`
911 fun glGenerateMipmap(target: GLTextureTarget) `{ glGenerateMipmap(target); `}
912
913 # Generate `n` buffer names
914 fun glGenBuffers(n: Int): Array[Int]
915 do
916 var array = new CIntArray(n)
917 native_glGenBuffers(n, array.native_array)
918 var a = array.to_a
919 array.destroy
920 return a
921 end
922
923 private fun native_glGenBuffers(n: Int, buffers: NativeCIntArray) `{
924 glGenBuffers(n, (GLuint *)buffers);
925 `}
926
927 # Does `name` corresponds to a buffer object?
928 fun glIsBuffer(name: Int): Bool `{
929 return glIsBuffer(name);
930 `}
931
932 # Delete named buffer objects
933 fun glDeleteBuffers(buffers: SequenceRead[Int])
934 do
935 var n = buffers.length
936 var array = new CIntArray.from(buffers)
937 native_glDeleteBuffers(n, array.native_array)
938 array.destroy
939 end
940
941 private fun native_glDeleteBuffers(n: Int, buffers: NativeCIntArray) `{
942 return glDeleteBuffers(n, (const GLuint *)buffers);
943 `}
944
945 # Create and initialize a buffer object's data store
946 fun glBufferData(target: GLArrayBuffer, size: Int, data: Pointer, usage: GLBufferUsage) `{
947 glBufferData(target, size, data, usage);
948 `}
949
950 # Update a subset of a buffer object's data store
951 fun glBufferSubData(target: GLArrayBuffer, offset, size: Int, data: Pointer) `{
952 glBufferSubData(target, offset, size, data);
953 `}
954
955 # Expected usage of a buffer
956 extern class GLBufferUsage
957 super GLEnum
958 end
959
960 # Data will be modified once and used a few times
961 fun gl_STREAM_DRAW: GLBufferUsage `{ return GL_STREAM_DRAW; `}
962
963 # Data will be modified once and used many times
964 fun gl_STATIC_DRAW: GLBufferUsage `{ return GL_STATIC_DRAW; `}
965
966 # Data will be modified repeatedly and used many times
967 fun gl_DYNAMIC_DRAW: GLBufferUsage `{ return GL_DYNAMIC_DRAW; `}
968
969 # Bind the named `buffer` object
970 fun glBindBuffer(target: GLArrayBuffer, buffer: Int) `{ glBindBuffer(target, buffer); `}
971
972 # Target to which bind the buffer with `glBindBuffer`
973 extern class GLArrayBuffer
974 super GLEnum
975 end
976
977 # Array buffer target
978 fun gl_ARRAY_BUFFER: GLArrayBuffer `{ return GL_ARRAY_BUFFER; `}
979
980 # Element array buffer
981 fun gl_ELEMENT_ARRAY_BUFFER: GLArrayBuffer `{ return GL_ELEMENT_ARRAY_BUFFER; `}
982
983 # Completeness status of a framebuffer object
984 fun glCheckFramebufferStatus(target: GLFramebufferTarget): GLFramebufferStatus `{
985 return glCheckFramebufferStatus(target);
986 `}
987
988 # Return value of `glCheckFramebufferStatus`
989 extern class GLFramebufferStatus
990 super GLEnum
991
992 redef fun to_s
993 do
994 if self == gl_FRAMEBUFFER_COMPLETE then return "complete"
995 if self == gl_FRAMEBUFFER_INCOMPLETE_ATTACHMENT then return "incomplete attachment"
996 if self == gl_FRAMEBUFFER_INCOMPLETE_DIMENSIONS then return "incomplete dimension"
997 if self == gl_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT then return "incomplete missing attachment"
998 if self == gl_FRAMEBUFFER_UNSUPPORTED then return "unsupported"
999 return "unknown"
1000 end
1001 end
1002
1003 # The framebuffer is complete
1004 fun gl_FRAMEBUFFER_COMPLETE: GLFramebufferStatus `{
1005 return GL_FRAMEBUFFER_COMPLETE;
1006 `}
1007
1008 # Not all framebuffer attachment points are framebuffer attachment complete
1009 fun gl_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: GLFramebufferStatus `{
1010 return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
1011 `}
1012
1013 # Not all attached images have the same width and height
1014 fun gl_FRAMEBUFFER_INCOMPLETE_DIMENSIONS: GLFramebufferStatus `{
1015 return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS;
1016 `}
1017
1018 # No images are attached to the framebuffer
1019 fun gl_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: GLFramebufferStatus `{
1020 return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
1021 `}
1022
1023 # The combination of internal formats of the attached images violates an implementation-dependent set of restrictions
1024 fun gl_FRAMEBUFFER_UNSUPPORTED: GLFramebufferStatus `{
1025 return GL_FRAMEBUFFER_UNSUPPORTED;
1026 `}
1027
1028 # Hint target for `glHint`
1029 extern class GLHintTarget
1030 super GLEnum
1031 end
1032
1033 # Indicates the quality of filtering when generating mipmap images
1034 fun gl_GENERATE_MIPMAP_HINT: GLHintTarget `{ return GL_GENERATE_MIPMAP_HINT; `}
1035
1036 # Hint mode for `glHint`
1037 extern class GLHintMode
1038 super GLEnum
1039 end
1040
1041 # The most efficient option should be chosen
1042 fun gl_FASTEST: GLHintMode `{ return GL_FASTEST; `}
1043
1044 # The most correct, or highest quality, option should be chosen
1045 fun gl_NICEST: GLHintMode `{ return GL_NICEST; `}
1046
1047 # No preference
1048 fun gl_DONT_CARE: GLHintMode `{ return GL_DONT_CARE; `}
1049
1050 # Generate `n` framebuffer object names
1051 fun glGenFramebuffers(n: Int): Array[Int]
1052 do
1053 var array = new CIntArray(n)
1054 native_glGenFramebuffers(n, array.native_array)
1055 var a = array.to_a
1056 array.destroy
1057 return a
1058 end
1059
1060 private fun native_glGenFramebuffers(n: Int, framebuffers: NativeCIntArray) `{
1061 glGenFramebuffers(n, (GLuint *)framebuffers);
1062 `}
1063
1064 # Does `name` corresponds to a framebuffer object?
1065 fun glIsFramebuffer(name: Int): Bool `{
1066 return glIsFramebuffer(name);
1067 `}
1068
1069 # Delete named framebuffer objects
1070 fun glDeleteFramebuffers(framebuffers: SequenceRead[Int])
1071 do
1072 var n = framebuffers.length
1073 var array = new CIntArray.from(framebuffers)
1074 native_glDeleteFramebuffers(n, array.native_array)
1075 array.destroy
1076 end
1077
1078 private fun native_glDeleteFramebuffers(n: Int, framebuffers: NativeCIntArray) `{
1079 return glDeleteFramebuffers(n, (const GLuint *)framebuffers);
1080 `}
1081
1082 # Attach a level of a texture object as a logical buffer to the currently bound framebuffer object
1083 fun glFramebufferTexture2D(target: GLFramebufferTarget, attachment: GLAttachment,
1084 texture_target: GLTextureTarget, texture, level: Int) `{
1085 glFramebufferTexture2D(target, attachment, texture_target, texture, level);
1086 `}
1087
1088 # Entry point to OpenGL server-side capabilities
1089 class GLCapabilities
1090
1091 # GL capability: blend the computed fragment color values
1092 #
1093 # Foreign: GL_BLEND
1094 var blend: GLCap is lazy do return new GLCap(0x0BE2)
1095
1096 # GL capability: cull polygons based of their winding in window coordinates
1097 #
1098 # Foreign: GL_CULL_FACE
1099 var cull_face: GLCap is lazy do return new GLCap(0x0B44)
1100
1101 # GL capability: do depth comparisons and update the depth buffer
1102 #
1103 # Foreign: GL_DEPTH_TEST
1104 var depth_test: GLCap is lazy do return new GLCap(0x0B71)
1105
1106 # GL capability: dither color components or indices before they are written to the color buffer
1107 #
1108 # Foreign: GL_DITHER
1109 var dither: GLCap is lazy do return new GLCap(0x0BE2)
1110
1111 # GL capability: add an offset to depth values of a polygon fragment before depth test
1112 #
1113 # Foreign: GL_POLYGON_OFFSET_FILL
1114 var polygon_offset_fill: GLCap is lazy do return new GLCap(0x8037)
1115
1116 # GL capability: compute a temporary coverage value where each bit is determined by the alpha value at the corresponding location
1117 #
1118 # Foreign: GL_SAMPLE_ALPHA_TO_COVERAGE
1119 var sample_alpha_to_coverage: GLCap is lazy do return new GLCap(0x809E)
1120
1121 # GL capability: AND the fragment coverage with the temporary coverage value
1122 #
1123 # Foreign: GL_SAMPLE_COVERAGE
1124 var sample_coverage: GLCap is lazy do return new GLCap(0x80A0)
1125
1126 # GL capability: discard fragments that are outside the scissor rectangle
1127 #
1128 # Foreign: GL_SCISSOR_TEST
1129 var scissor_test: GLCap is lazy do return new GLCap(0x0C11)
1130
1131 # GL capability: do stencil testing and update the stencil buffer
1132 #
1133 # Foreign: GL_STENCIL_TEST
1134 var stencil_test: GLCap is lazy do return new GLCap(0x0B90)
1135 end
1136
1137 # All data types of OpenGL ES 2.0 shaders
1138 #
1139 # These types can be used by shader uniforms, as seen with
1140 # `GLProgram::active_uniform_type`.
1141 extern class GLDataType
1142 super GLEnum
1143 end
1144
1145 fun gl_FLOAT: GLDataType `{ return GL_FLOAT; `}
1146 fun gl_FLOAT_VEC2: GLDataType `{ return GL_FLOAT_VEC2; `}
1147 fun gl_FLOAT_VEC3: GLDataType `{ return GL_FLOAT_VEC3; `}
1148 fun gl_FLOAT_VEC4: GLDataType `{ return GL_FLOAT_VEC4; `}
1149 fun gl_FLOAT_MAT2: GLDataType `{ return GL_FLOAT_MAT2; `}
1150 fun gl_FLOAT_MAT3: GLDataType `{ return GL_FLOAT_MAT3; `}
1151 fun gl_FLOAT_MAT4: GLDataType `{ return GL_FLOAT_MAT4; `}
1152
1153 fun gl_BYTE: GLDataType `{ return GL_BYTE; `}
1154 fun gl_UNSIGNED_BYTE: GLDataType `{ return GL_UNSIGNED_BYTE; `}
1155 fun gl_SHORT: GLDataType `{ return GL_SHORT; `}
1156 fun gl_UNSIGNED_SHORT: GLDataType `{ return GL_UNSIGNED_SHORT; `}
1157 fun gl_INT: GLDataType `{ return GL_INT; `}
1158 fun gl_UNSIGNED_INT: GLDataType `{ return GL_UNSIGNED_INT; `}
1159 fun gl_FIXED: GLDataType `{ return GL_FIXED; `}
1160 fun gl_INT_VEC2: GLDataType `{ return GL_INT_VEC2; `}
1161 fun gl_INT_VEC3: GLDataType `{ return GL_INT_VEC3; `}
1162 fun gl_INT_VEC4: GLDataType `{ return GL_INT_VEC4; `}
1163 fun gl_BOOL: GLDataType `{ return GL_BOOL; `}
1164 fun gl_BOOL_VEC2: GLDataType `{ return GL_BOOL_VEC2; `}
1165 fun gl_BOOL_VEC3: GLDataType `{ return GL_BOOL_VEC3; `}
1166 fun gl_BOOL_VEC4: GLDataType `{ return GL_BOOL_VEC4; `}
1167 fun gl_SAMPLER_2D: GLDataType `{ return GL_SAMPLER_2D; `}
1168 fun gl_SAMPLER_CUBE: GLDataType `{ return GL_SAMPLER_CUBE; `}
1169
1170 fun gl_UNSIGNED_SHORT_5_6_5: GLDataType `{ return GL_UNSIGNED_SHORT_5_6_5; `}
1171 fun gl_UNSIGNED_SHORT_4_4_4_4: GLDataType `{ return GL_UNSIGNED_SHORT_4_4_4_4; `}
1172 fun gl_UNSIGNED_SHORT_5_5_5_1: GLDataType `{ return GL_UNSIGNED_SHORT_5_5_5_1; `}
1173
1174 # Kind of primitives to render
1175 extern class GLDrawMode
1176 super GLEnum
1177 end
1178
1179 fun gl_POINTS: GLDrawMode `{ return GL_POINTS; `}
1180 fun gl_LINES: GLDrawMode `{ return GL_LINES; `}
1181 fun gl_LINE_LOOP: GLDrawMode `{ return GL_LINE_LOOP; `}
1182 fun gl_LINE_STRIP: GLDrawMode `{ return GL_LINE_STRIP; `}
1183 fun gl_TRIANGLES: GLDrawMode `{ return GL_TRIANGLES; `}
1184 fun gl_TRIANGLE_STRIP: GLDrawMode `{ return GL_TRIANGLE_STRIP; `}
1185 fun gl_TRIANGLE_FAN: GLDrawMode `{ return GL_TRIANGLE_FAN; `}
1186
1187 # Pixel arithmetic for blending operations
1188 extern class GLBlendFactor
1189 super GLEnum
1190 end
1191
1192 fun gl_ZERO: GLBlendFactor `{ return GL_ZERO; `}
1193 fun gl_ONE: GLBlendFactor `{ return GL_ONE; `}
1194 fun gl_SRC_COLOR: GLBlendFactor `{ return GL_SRC_COLOR; `}
1195 fun gl_ONE_MINUS_SRC_COLOR: GLBlendFactor `{ return GL_ONE_MINUS_SRC_COLOR; `}
1196 fun gl_SRC_ALPHA: GLBlendFactor `{ return GL_SRC_ALPHA; `}
1197 fun gl_ONE_MINUS_SRC_ALPHA: GLBlendFactor `{ return GL_ONE_MINUS_SRC_ALPHA; `}
1198 fun gl_DST_ALPHA: GLBlendFactor `{ return GL_DST_ALPHA; `}
1199 fun gl_ONE_MINUS_DST_ALPHA: GLBlendFactor `{ return GL_ONE_MINUS_DST_ALPHA; `}
1200 fun gl_DST_COLOR: GLBlendFactor `{ return GL_DST_COLOR; `}
1201 fun gl_ONE_MINUS_DST_COLOR: GLBlendFactor `{ return GL_ONE_MINUS_DST_COLOR; `}
1202 fun gl_SRC_ALPHA_SATURATE: GLBlendFactor `{ return GL_SRC_ALPHA_SATURATE; `}
1203
1204 # Condition under which a pixel will be drawn
1205 extern class GLDepthFunc
1206 super GLEnum
1207 end
1208
1209 fun gl_NEVER: GLDepthFunc `{ return GL_NEVER; `}
1210 fun gl_LESS: GLDepthFunc `{ return GL_LESS; `}
1211 fun gl_EQUAL: GLDepthFunc `{ return GL_EQUAL; `}
1212 fun gl_LEQUAL: GLDepthFunc `{ return GL_LEQUAL; `}
1213 fun gl_GREATER: GLDepthFunc `{ return GL_GREATER; `}
1214 fun gl_NOTEQUAL: GLDepthFunc `{ return GL_NOTEQUAL; `}
1215 fun gl_GEQUAL: GLDepthFunc `{ return GL_GEQUAL; `}
1216 fun gl_ALWAYS: GLDepthFunc `{ return GL_ALWAYS; `}
1217
1218 # Format of pixel data
1219 extern class GLPixelFormat
1220 super GLEnum
1221 end
1222
1223 fun gl_ALPHA: GLPixelFormat `{ return GL_ALPHA; `}
1224 fun gl_RGB: GLPixelFormat `{ return GL_RGB; `}
1225 fun gl_RGBA: GLPixelFormat `{ return GL_RGBA; `}
1226 fun gl_DEPTH_COMPONENT: GLPixelFormat `{ return GL_DEPTH_COMPONENT; `}
1227
1228 # Set of buffers as a bitwise OR mask
1229 extern class GLBuffer `{ GLbitfield `}
1230 # Bitwise OR with `other`
1231 fun |(other: GLBuffer): GLBuffer `{ return self | other; `}
1232 end
1233
1234 fun gl_DEPTH_BUFFER_BIT: GLBuffer `{ return GL_DEPTH_BUFFER_BIT; `}
1235 fun gl_STENCIL_BUFFER_BIT: GLBuffer `{ return GL_STENCIL_BUFFER_BIT; `}
1236 fun gl_COLOR_BUFFER_BIT: GLBuffer `{ return GL_COLOR_BUFFER_BIT; `}
1237
1238 # Define front- and back-facing polygons, `gc_CCW` by default
1239 fun glFrontFace(mode: GLFrontFaceMode) `{ glFrontFace(mode); `}
1240
1241 # Orientation of front-facing polygons
1242 extern class GLFrontFaceMode
1243 super GLEnum
1244 end
1245
1246 fun gl_CW: GLFrontFaceMode `{ return GL_CW; `}
1247 fun gl_CCW: GLFrontFaceMode `{ return GL_CCW; `}
1248
1249 # Specify whether front- or back-facing polygons can be culled, default is `back` only
1250 fun glCullFace(mode: GLCullFaceMode) `{ glCullFace(mode); `}
1251
1252 # Candidates for culling
1253 extern class GLCullFaceMode
1254 super GLEnum
1255 end
1256
1257 fun gl_FRONT: GLCullFaceMode `{ return GL_FRONT; `}
1258 fun gl_BACK: GLCullFaceMode `{ return GL_BACK; `}
1259 fun gl_FRONT_AND_BACK: GLCullFaceMode `{ return GL_FRONT_AND_BACK; `}
1260
1261 # Specify mapping of depth values from normalized device coordinates to window coordinates
1262 #
1263 # Default at 0.0, 1.0.
1264 fun glDepthRangef(near, far: Float) `{ glDepthRangef(near, far); `}
1265
1266 # Enable or disable writing into the depth buffer
1267 fun glDepthMask(value: Bool) `{ glDepthMask(value); `}
1268
1269 # Specify the value used for depth buffer comparisons
1270 #
1271 # Default value is `gl_LESS`
1272 fun glDepthFunc(func: GLDepthFunc) `{ glDepthFunc(func); `}
1273
1274 # Set the pixel arithmetic for the blending operations
1275 #
1276 # Default values:
1277 # * `src_factor`: `gl_ONE`
1278 # * `dst_factor`: `gl_ZERO`
1279 fun glBlendFunc(src_factor, dst_factor: GLBlendFactor) `{
1280 glBlendFunc(src_factor, dst_factor);
1281 `}
1282
1283 # Set the scale and units used to calculate depth values
1284 fun glPolygonOffset(factor, units: Float) `{ glPolygonOffset(factor, units); `}
1285
1286 # Specify the width of rasterized lines
1287 fun glLineWidth(width: Float) `{ glLineWidth(width); `}
1288
1289 # Get the value of the parameter `pname` at `offset`
1290 fun glGetBooleanv(pname: GLGetParameterName, offset: Int): Bool `{
1291 GLboolean v[4];
1292 glGetBooleanv(pname, v);
1293 return v[offset];
1294 `}
1295
1296 # Get the value of the parameter `pname` at `offset`
1297 fun glGetFloatv(pname: GLGetParameterName, offset: Int): Float `{
1298 GLfloat v[4];
1299 glGetFloatv(pname, v);
1300 return v[offset];
1301 `}
1302
1303 # Get the value of the parameter `pname` at `offset`
1304 fun glGetIntegerv(pname: GLGetParameterName, offset: Int): Int `{
1305 GLint v[4];
1306 glGetIntegerv(pname, v);
1307 return v[offset];
1308 `}
1309
1310 fun gl_COLOR_CLEAR_VALUE: GLGetParameterName `{ return GL_COLOR_CLEAR_VALUE; `}
1311
1312 fun gl_MAX_TEXTURE_SIZE: GLGetParameterName `{ return GL_MAX_TEXTURE_SIZE; `}
1313 fun gl_MAX_VIEWPORT_DIMS: GLGetParameterName `{ return GL_MAX_VIEWPORT_DIMS; `}
1314 fun gl_MAX_VERTEX_ATTRIBS: GLGetParameterName `{ return GL_MAX_VERTEX_ATTRIBS; `}
1315 fun gl_MAX_VERTEX_UNIFORM_VECTORS: GLGetParameterName `{ return GL_MAX_VERTEX_UNIFORM_VECTORS; `}
1316 fun gl_MAX_VARYING_VECTORS: GLGetParameterName `{ return GL_MAX_VARYING_VECTORS; `}
1317 fun gl_MAX_COMBINED_TEXTURE_IMAGE_UNITS: GLGetParameterName `{ return GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS; `}
1318 fun gl_MAX_VERTEX_TEXTURE_IMAGE_UNITS: GLGetParameterName `{ return GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS; `}
1319 fun gl_MAX_TEXTURE_IMAGE_UNITS: GLGetParameterName `{ return GL_MAX_TEXTURE_IMAGE_UNITS; `}
1320 fun gl_MAX_FRAGMENT_UNIFORM_VECTORS: GLGetParameterName `{ return GL_MAX_FRAGMENT_UNIFORM_VECTORS; `}
1321
1322 fun gl_ARRAY_BUFFER_BINDING: GLGetParameterName `{ return GL_ARRAY_BUFFER_BINDING; `}
1323 fun gl_ELEMENT_ARRAY_BUFFER_BINDING: GLGetParameterName `{ return GL_ELEMENT_ARRAY_BUFFER_BINDING; `}
1324 fun gl_TEXTURE_BINDING_2D: GLGetParameterName `{ return GL_TEXTURE_BINDING_2D; `}
1325 fun gl_TEXTURE_BINDING_CUBE_MAP: GLGetParameterName `{ return GL_TEXTURE_BINDING_CUBE_MAP; `}
1326 fun gl_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: GLGetParameterName `{ return GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING; `}
1327 fun gl_FRAMEBUFFER_BINDING: GLGetParameterName `{ return GL_FRAMEBUFFER_BINDING; `}
1328 fun gl_RENDERBUFFER_BINDING: GLGetParameterName `{ return GL_RENDERBUFFER_BINDING; `}
1329
1330 # Return a string describing the current GL configuration
1331 fun glGetString(name: GLEnum): String
1332 do
1333 var cstr = glGetString_native(name)
1334 assert not cstr.address_is_null
1335 return cstr.to_s
1336 end
1337
1338 private fun glGetString_native(name: GLEnum): CString `{ return (char*)glGetString(name); `}
1339
1340 # Company responsible for this GL implementation
1341 fun gl_VENDOR: GLEnum `{ return GL_VENDOR; `}
1342
1343 # Name of the renderer, typically specific to a particular configuration of the hardware platform
1344 fun gl_RENDERER: GLEnum `{ return GL_RENDERER; `}
1345
1346 # Version or release number
1347 fun gl_VERSION: GLEnum `{ return GL_VERSION; `}
1348
1349 # Version or release number for the shading language of the form
1350 fun gl_SHADING_LANGUAGE_VERSION: GLEnum `{ return GL_SHADING_LANGUAGE_VERSION; `}
1351
1352 # Space-separated list of supported extensions to GL
1353 fun gl_EXTENSIONS: GLEnum `{ return GL_EXTENSIONS; `}