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