1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2014 Alexis Laferrière <alexis.laf@xymus.net>
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 # OpenGL graphics rendering library for embedded systems, version 2.0
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`.
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/
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/
34 no_warning
"missing-doc"
35 new_annotation glsl_vertex_shader
36 new_annotation glsl_fragment_shader
37 ldflags
("-lGLESv2")@android
45 #include <OpenGLES/ES2/gl.h>
47 #include <GLES2/gl2.h>
51 # OpenGL ES program to which we attach shaders
52 extern class GLProgram `{GLuint`}
53 # Create a new program
55 # The newly created instance should be checked using `is_ok
`.
56 new `{ return glCreateProgram(); `}
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);
64 # Get the location of the attribute by `name`
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);
72 # Get the location of the uniform by `name`
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);
80 # Is this program linked?
81 fun is_linked
: Bool do return glGetProgramiv
(self, gl_LINK_STATUS
) != 0
83 # Has this program been deleted?
84 fun is_deleted
: Bool do return glGetProgramiv
(self, gl_DELETE_STATUS
) != 0
86 # Boolean result of `validate`, must be called after `validate`
87 fun is_validated
: Bool do return glGetProgramiv
(self, gl_VALIDATE_STATUS
) != 0
89 # Number of active uniform in this program
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
)
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
)
98 # Number of active attributes in this program
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
)
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
)
107 # Number of shaders attached to this program
108 fun n_attached_shaders
: Int do return glGetProgramiv
(self, gl_ATTACHED_SHADERS
)
110 # Name of the active attribute at `index`
111 fun active_attrib_name
(index
: Int): String
113 var max_size
= active_attribute_max_length
114 var cname
= new CString(max_size
)
115 active_attrib_name_native
(index
, max_size
, cname
)
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.
125 glGetActiveAttrib(self, index, max_size, NULL, &size, &type, name);
128 # Size of the active attribute at `index`
129 fun active_attrib_size
(index
: Int): Int `{
132 glGetActiveAttrib(self, index, 0, NULL, &size, &type, NULL);
136 # Type of the active attribute at `index`
138 # May only be float related data types (single float, vectors and matrix).
139 fun active_attrib_type
(index
: Int): GLDataType `{
142 glGetActiveAttrib(self, index, 0, NULL, &size, &type, NULL);
146 # Name of the active uniform at `index`
147 fun active_uniform_name
(index
: Int): String
149 var max_size
= active_uniform_max_length
150 var cname
= new CString(max_size
)
151 active_uniform_name_native
(index
, max_size
, cname
)
155 private fun active_uniform_name_native
(index
, max_size
: Int, name
: CString) `{
158 glGetActiveUniform(self, index, max_size, NULL, &size, &type, name);
161 # Size of the active uniform at `index`
162 fun active_uniform_size
(index
: Int): Int `{
165 glGetActiveUniform(self, index, 0, NULL, &size, &type, NULL);
169 # Type of the active uniform at `index`
171 # May be any data type supported by OpenGL ES 2.0 shaders.
172 fun active_uniform_type
(index
: Int): GLDataType `{
175 glGetActiveUniform(self, index, 0, NULL, &size, &type, NULL);
180 # Create a program object
181 fun glCreateProgram
: GLProgram `{ return glCreateProgram(); `}
183 # Install the `program
` as part of current rendering state
184 fun glUseProgram(program: GLProgram) `{ glUseProgram(program); `}
186 # Link the `program` object
187 fun glLinkProgram
(program
: GLProgram) `{ glLinkProgram(program); `}
189 # Validate the `program
` object
190 fun glValidateProgram(program: GLProgram) `{ glValidateProgram(program); `}
192 # Delete the `program` object
193 fun glDeleteProgram
(program
: GLProgram) `{ glDeleteProgram(program); `}
195 # Does `name
` corresponds to a program object?
196 fun glIsProgram(name: GLProgram): Bool `{ return glIsProgram(name); `}
198 # Attach a `shader` to `program`
199 fun glAttachShader
(program
: GLProgram, shader
: GLShader) `{ glAttachShader(program, shader); `}
201 # Detach `shader
` from `program
`
202 fun glDetachShader(program: GLProgram, shader: GLShader) `{ glDetachShader(program, shader); `}
204 # Parameter value from a `program` object
205 fun glGetProgramiv
(program
: GLProgram, pname
: GLGetParameterName): Int `{
207 glGetProgramiv(program, pname, &value);
211 # The information log for the `program` object
212 fun glGetProgramInfoLog
(program
: GLProgram): String
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
)
220 # Return the program information log in `buf`
221 private fun native_glGetProgramInfoLog
(program
: GLProgram, buf_size
: Int, buf
: CString): Int `{
223 glGetProgramInfoLog(program, buf_size, &length, buf);
227 # Abstract OpenGL ES shader object, implemented by `GLFragmentShader` and `GLVertexShader`
228 extern class GLShader `{GLuint`}
230 # Source of the shader, if available
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
236 var size = glGetShaderiv(self, gl_SHADER_SOURCE_LENGTH)
237 if size == 0 then return null
238 return source_native(size).to_s
241 private fun source_native(size: Int): CString `{
242 GLchar *code
= malloc
(size
);
243 glGetShaderSource
(self, size
, NULL, code
);
247 # Has this shader been compiled?
248 fun is_compiled: Bool do return glGetShaderiv(self, gl_COMPILE_STATUS) != 0
250 # Has this shader been deleted?
251 fun is_deleted: Bool do return glGetShaderiv(self, gl_DELETE_STATUS) != 0
254 # Get a parameter value from a `shader
` object
255 fun glGetShaderiv(shader: GLShader, pname: GLGetParameterName): Int `{
257 glGetShaderiv
(shader
, pname
, &val
);
262 extern class GLGetParameterName
266 fun gl_INFO_LOG_LENGTH: GLGetParameterName `{ return GL_INFO_LOG_LENGTH; `}
267 fun gl_DELETE_STATUS
: GLGetParameterName `{ return GL_DELETE_STATUS; `}
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; `}
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; `}
281 # The information log for the `shader
` object
282 fun glGetShaderInfoLog(shader: GLShader): String
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)
290 private fun native_glGetShaderInfoLog(shader: GLShader, buf_size: Int, buffer: CString): Int `{
292 glGetShaderInfoLog
(shader
, buf_size
, &length
, buffer
);
297 extern class GLShaderType
301 fun gl_VERTEX_SHADER: GLShaderType `{ return GL_VERTEX_SHADER; `}
302 fun gl_FRAGMENT_SHADER
: GLShaderType `{ return GL_FRAGMENT_SHADER; `}
304 # Create a shader object of the `shader_type
`
305 fun glCreateShader(shader_type: GLShaderType): GLShader `{
306 return glCreateShader
(shader_type
);
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);
314 # Compile the `shader
` object
315 fun glCompileShader(shader: GLShader) `{ glCompileShader(shader); `}
317 # Delete the `shader` object
318 fun glDeleteShader
(shader
: GLShader) `{ glDeleteShader(shader); `}
320 # Does `name
` corresponds to a shader object?
321 fun glIsShader(name: GLShader): Bool `{ return glIsShader(name); `}
323 # An OpenGL ES 2.0 fragment shader
324 extern class GLFragmentShader
327 # Create a new fragment shader
329 # The newly created instance should be checked using `is_ok`.
330 new `{ return glCreateShader(GL_FRAGMENT_SHADER); `}
333 # An OpenGL ES 2.0 vertex shader
334 extern class GLVertexShader
337 # Create a new fragment shader
339 # The newly created instance should be checked using `is_ok
`.
340 new `{ return glCreateShader(GL_VERTEX_SHADER); `}
343 # An array of `Float` associated to a program variable
347 # Number of data per vertex
350 protected var glfloat_array
: NativeGLfloatArray
352 init(index
, count
: Int, array
: Array[Float])
356 self.glfloat_array
= new NativeGLfloatArray(array
.length
)
357 for k
in [0..array
.length
[ do
358 glfloat_array
[k
] = array
[k
]
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);
367 # Enable this vertex attribute array
368 fun enable
do glEnableVertexAttribArray
(index
)
370 # Disable this vertex attribute array
371 fun disable
do glDisableVertexAttribArray
(index
)
374 # Enable the generic vertex attribute array at `index`
375 fun glEnableVertexAttribArray
(index
: Int) `{ glEnableVertexAttribArray(index); `}
377 # Disable the generic vertex attribute array at `index
`
378 fun glDisableVertexAttribArray(index: Int) `{ glDisableVertexAttribArray(index); `}
380 # Render primitives from array data
381 fun glDrawArrays
(mode
: GLDrawMode, from
, count
: Int) `{ glDrawArrays(mode, from, count); `}
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
);
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
);
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
);
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
);
403 # Specify the value of a generic vertex attribute
404 fun glVertexAttrib1f(index: Int, x: Float) `{ glVertexAttrib1f(index, x); `}
406 # Specify the value of a generic vertex attribute
407 fun glVertexAttrib2f
(index
: Int, x
, y
: Float) `{ glVertexAttrib2f(index, x, y); `}
409 # Specify the value of a generic vertex attribute
410 fun glVertexAttrib3f(index: Int, x, y, z: Float) `{ glVertexAttrib3f(index, x, y, z); `}
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); `}
415 # Specify the value of a uniform variable for the current program object
416 fun glUniform1i(index, x: Int) `{ glUniform1i(index, x); `}
418 # Specify the value of a uniform variable for the current program object
419 fun glUniform2i
(index
, x
, y
: Int) `{ glUniform2i(index, x, y); `}
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); `}
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); `}
427 # Specify the value of a uniform variable for the current program object
428 fun glUniform1f(index: Int, x: Float) `{ glUniform1f(index, x); `}
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); `}
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); `}
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); `}
439 # Low level array of `Float`
441 super FinalizableOnce
445 var native_array = new NativeGLfloatArray(length) is lateinit
447 fun [](index: Int): Float do return native_array[index]
449 fun []=(index: Int, val: Float) do native_array[index] = val
453 fun reset_add do add_index = 0
455 # Require: `add_index
< length
`
456 fun add(value: Float)
458 var index = add_index
459 assert index < length
460 native_array[index] = value
461 self.add_index = index + 1
464 # Create with the content of `array
`
465 new from(array: Array[Float])
467 var arr = new GLfloatArray(array.length)
472 # Fill with the content of `array
`
474 # If `dst_offset
` is set, the data is copied to the index `dst_offset
`,
475 # otherwise, it is copied the beginning of `self`.
477 # Require: `length
>= array
.length
+ dst_offset
or else 0`
478 fun fill_from(array: Array[Float], dst_offset: nullable Int)
480 dst_offset = dst_offset or else add_index
482 assert length >= array.length + dst_offset
483 for k in [0..array.length[ do
484 self[dst_offset+k] = array[k]
488 redef fun finalize_once do native_array.free
491 # An array of `GLfloat` in C (`GLfloat*`)
492 extern class NativeGLfloatArray `{ GLfloat* `}
494 new(size
: Int) `{ return calloc(size, sizeof(GLfloat)); `}
496 fun [](index: Int): Float `{ return self[index]; `}
498 fun []=(index
: Int, val
: Float) `{ self[index] = val; `}
500 fun +(offset: Int): NativeGLfloatArray `{ return self + offset; `}
503 # General type for OpenGL enumerations
504 extern class GLEnum `{ GLenum `}
506 redef fun hash `{ return self; `}
508 redef fun ==(o
) do return o
!= null and is_same_type
(o
) and o
.hash
== self.hash
512 fun glGetError
: GLError `{ return glGetError(); `}
514 # An OpenGL ES 2.0 error code
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"
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; `}
537 fun assert_no_gl_error
539 var error = glGetError
540 if not error == gl_NO_ERROR then
541 print "GL error: {error}"
546 # Texture unit, the number of texture units is implementation dependent
547 extern class GLTextureUnit
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; `}
584 # Texture unit at `offset
` after `gl_TEXTURE0
`
585 fun gl_TEXTURE(offset: Int): GLTextureUnit `{ return GL_TEXTURE0 + offset; `}
587 # Generate `n` texture names
588 fun glGenTextures
(n
: Int): Array[Int]
590 var array
= new CIntArray(n
)
591 native_glGenTextures
(n
, array
.native_array
)
597 private fun native_glGenTextures
(n
: Int, textures
: NativeCIntArray) `{
598 glGenTextures(n, (GLuint*)textures);
601 # Select server-side active texture unit
602 fun glActiveTexture
(texture
: GLTextureUnit) `{ glActiveTexture(texture); `}
604 # Bind the named `texture
` to a `target
`
605 fun glBindTexture(target: GLTextureTarget, texture: Int) `{
606 glBindTexture
(target
, texture
);
609 # Delete named textures
610 fun glDeleteTextures(textures: SequenceRead[Int])
612 var n = textures.length
613 var array = new CIntArray.from(textures)
614 native_glDeleteTextures(n, array.native_array)
618 private fun native_glDeleteTextures(n: Int, textures: NativeCIntArray) `{
619 glDeleteTextures
(n
, (const
GLuint *)textures
);
622 # Does `name
` corresponds to a texture?
623 fun glIsTexture(name: Int): Bool `{ return glIsTexture(name); `}
625 # Set pixel storage modes
626 fun glPixelStorei
(parameter
: GLPack, val
: Int) `{ glPixelStorei(parameter, val); `}
628 # Symbolic name of the parameter to be set with `glPixelStorei
`
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; `}
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; `}
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
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
);
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
);
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
);
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
);
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
);
672 # Texture minifying and magnifying function
673 extern class GLTexParameteri
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; `}
688 extern class GLTextureTarget
692 # Two-dimensional texture
693 fun gl_TEXTURE_2D
: GLTextureTarget `{ return GL_TEXTURE_2D; `}
696 fun gl_TEXTURE_CUBE_MAP: GLTextureTarget `{ return GL_TEXTURE_CUBE_MAP; `}
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
701 # A server-side capability
706 # Internal OpenGL integer for this capability
709 # Enable this server-side capability
710 fun enable
do enable_native
(val
)
711 private fun enable_native
(cap
: Int) `{ glEnable(cap); `}
713 # Disable this server-side capability
714 fun disable do disable_native(val)
715 private fun disable_native(cap: Int) `{ glDisable(cap); `}
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
721 # Generate `n` renderbuffer object names
722 fun glGenRenderbuffers
(n
: Int): Array[Int]
724 var array
= new CIntArray(n
)
725 native_glGenRenderbuffers
(n
, array
.native_array
)
731 private fun native_glGenRenderbuffers
(n
: Int, renderbuffers
: NativeCIntArray) `{
732 glGenRenderbuffers(n, (GLuint *)renderbuffers);
735 # Does `name` corresponds to a renderbuffer object?
736 fun glIsRenderbuffer
(name
: Int): Bool `{
737 return glIsRenderbuffer(name);
740 # Delete named renderbuffer objects
741 fun glDeleteRenderbuffers
(renderbuffers
: SequenceRead[Int])
743 var n
= renderbuffers
.length
744 var array
= new CIntArray.from
(renderbuffers
)
745 native_glDeleteRenderbuffers
(n
, array
.native_array
)
749 private fun native_glDeleteRenderbuffers
(n
: Int, renderbuffers
: NativeCIntArray) `{
750 return glDeleteRenderbuffers(n, (const GLuint *)renderbuffers);
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);
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);
764 # Format for a renderbuffer
765 extern class GLRenderbufferFormat
769 # 4 red, 4 green, 4 blue, 4 alpha bits format
770 fun gl_RGBA4
: GLRenderbufferFormat `{ return GL_RGBA4; `}
772 # 5 red, 6 green, 5 blue bits format
773 fun gl_RGB565: GLRenderbufferFormat `{ return GL_RGB565; `}
775 # 5 red, 5 green, 5 blue, 1 alpha bits format
776 fun gl_RGB5_A1
: GLRenderbufferFormat `{ return GL_RGB5_A1; `}
778 # 16 depth bits format
779 fun gl_DEPTH_COMPONENT16: GLRenderbufferFormat `{ return GL_DEPTH_COMPONENT16; `}
781 # 8 stencil bits format
782 fun gl_STENCIL_INDEX8
: GLRenderbufferFormat `{ return GL_STENCIL_INDEX8; `}
784 # Renderbuffer attachment point to a framebuffer
785 extern class GLAttachment
789 # First color attachment point
790 fun gl_COLOR_ATTACHMENT0: GLAttachment `{ return GL_COLOR_ATTACHMENT0; `}
792 # Depth attachment point
793 fun gl_DEPTH_ATTACHMENT
: GLAttachment `{ return GL_DEPTH_ATTACHMENT; `}
796 fun gl_STENCIL_ATTACHMENT: GLAttachment `{ return GL_STENCIL_ATTACHMENT; `}
799 private var gles
= new GLES is lazy
802 # Entry points to OpenGL ES 2.0 services
803 fun gl
: GLES do return sys
.gles
805 # OpenGL ES 2.0 services
808 # Query the boolean value at `key`
809 private fun get_bool
(key
: Int): Bool `{
811 glGetBooleanv(key, &val);
812 return val == GL_TRUE;
815 # Query the floating point value at `key`
816 private fun get_float
(key
: Int): Float `{
818 glGetFloatv(key, &val);
822 # Query the integer value at `key`
823 private fun get_int
(key
: Int): Int `{
825 glGetIntegerv(key, &val);
829 # Does this driver support shader compilation?
831 # Should always return `true` in OpenGL ES 2.0 and 3.0.
832 fun shader_compiler
: Bool do return get_bool
(0x8DFA)
834 # OpenGL server-side capabilities
835 var capabilities
= new GLCapabilities is lazy
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);
843 # Specify the clear `value` for the depth buffer, default at 1.0
844 fun glClearDepthf
(value
: Float) `{ glClearDepthf(value); `}
846 # Specify the clear `value
` for the stencil buffer, default at 0
847 fun glClearStencil(value: Int) `{ glClearStencil(value); `}
850 fun glClear
(buffer
: GLBuffer) `{ glClear(buffer); `}
852 # Enable and disable writing of frame buffer color components
853 fun glColorMask(red, green, blue, alpha: Bool) `{ glColorMask(red, green, blue, alpha); `}
856 fun glViewport
(x
, y
, width
, height
: Int) `{ glViewport(x, y, width, height); `}
858 # Block until all GL execution is complete
859 fun glFinish `{ glFinish(); `}
861 # Force execution of GL commands in finite time
862 fun glFlush
`{ glFlush(); `}
864 # Set texture parameters
865 fun glTexParameteri(target: GLTextureTarget, pname: GLTexParameteriName, param: GLTexParameteri) `{
866 glTexParameteri
(target
, pname
, param
);
869 # Name of parameters of textures
870 extern class GLTexParameteriName
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; `}
879 # Bind `framebuffer
` to a framebuffer target
881 # In OpenGL ES 2.0, `target
` must be `gl_FRAMEBUFFER
`.
882 fun glBindFramebuffer(target: GLFramebufferTarget, framebuffer: Int) `{
883 glBindFramebuffer
(target
, framebuffer
);
886 # Target of `glBindFramebuffer
`
887 extern class GLFramebufferTarget
891 # Target both reading and writing on the framebuffer with `glBindFramebuffer
`
892 fun gl_FRAMEBUFFER: GLFramebufferTarget `{ return GL_FRAMEBUFFER; `}
894 # Bind `renderbuffer` to a renderbuffer target
896 # In OpenGL ES 2.0, `target` must be `gl_RENDERBUFFER`.
897 fun glBindRenderbuffer
(target
: GLRenderbufferTarget, renderbuffer
: Int) `{
898 glBindRenderbuffer(target, renderbuffer);
901 # Target of `glBindRenderbuffer`
902 extern class GLRenderbufferTarget
906 # Target a renderbuffer with `glBindRenderbuffer`
907 fun gl_RENDERBUFFER
: GLRenderbufferTarget `{ return GL_RENDERBUFFER; `}
909 # Specify implementation specific hints
910 fun glHint(target: GLHintTarget, mode: GLHintMode) `{
911 glHint
(target
, mode
);
914 # Generate and fill set of mipmaps for the texture object `target
`
915 fun glGenerateMipmap(target: GLTextureTarget) `{ glGenerateMipmap(target); `}
917 # Generate `n` buffer names
918 fun glGenBuffers
(n
: Int): Array[Int]
920 var array
= new CIntArray(n
)
921 native_glGenBuffers
(n
, array
.native_array
)
927 private fun native_glGenBuffers
(n
: Int, buffers
: NativeCIntArray) `{
928 glGenBuffers(n, (GLuint *)buffers);
931 # Does `name` corresponds to a buffer object?
932 fun glIsBuffer
(name
: Int): Bool `{
933 return glIsBuffer(name);
936 # Delete named buffer objects
937 fun glDeleteBuffers
(buffers
: SequenceRead[Int])
939 var n
= buffers
.length
940 var array
= new CIntArray.from
(buffers
)
941 native_glDeleteBuffers
(n
, array
.native_array
)
945 private fun native_glDeleteBuffers
(n
: Int, buffers
: NativeCIntArray) `{
946 return glDeleteBuffers(n, (const GLuint *)buffers);
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);
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);
959 # Expected usage of a buffer
960 extern class GLBufferUsage
964 # Data will be modified once and used a few times
965 fun gl_STREAM_DRAW
: GLBufferUsage `{ return GL_STREAM_DRAW; `}
967 # Data will be modified once and used many times
968 fun gl_STATIC_DRAW: GLBufferUsage `{ return GL_STATIC_DRAW; `}
970 # Data will be modified repeatedly and used many times
971 fun gl_DYNAMIC_DRAW
: GLBufferUsage `{ return GL_DYNAMIC_DRAW; `}
973 # Bind the named `buffer
` object
974 fun glBindBuffer(target: GLArrayBuffer, buffer: Int) `{ glBindBuffer(target, buffer); `}
976 # Target to which bind the buffer with `glBindBuffer`
977 extern class GLArrayBuffer
981 # Array buffer target
982 fun gl_ARRAY_BUFFER
: GLArrayBuffer `{ return GL_ARRAY_BUFFER; `}
984 # Element array buffer
985 fun gl_ELEMENT_ARRAY_BUFFER: GLArrayBuffer `{ return GL_ELEMENT_ARRAY_BUFFER; `}
987 # Completeness status of a framebuffer object
988 fun glCheckFramebufferStatus
(target
: GLFramebufferTarget): GLFramebufferStatus `{
989 return glCheckFramebufferStatus(target);
992 # Return value of `glCheckFramebufferStatus`
993 extern class GLFramebufferStatus
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"
1007 # The framebuffer is complete
1008 fun gl_FRAMEBUFFER_COMPLETE
: GLFramebufferStatus `{
1009 return GL_FRAMEBUFFER_COMPLETE;
1012 # Not all framebuffer attachment points are framebuffer attachment complete
1013 fun gl_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
: GLFramebufferStatus `{
1014 return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
1017 # Not all attached images have the same width and height
1018 fun gl_FRAMEBUFFER_INCOMPLETE_DIMENSIONS
: GLFramebufferStatus `{
1019 return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS;
1022 # No images are attached to the framebuffer
1023 fun gl_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
: GLFramebufferStatus `{
1024 return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
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;
1032 # Hint target for `glHint`
1033 extern class GLHintTarget
1037 # Indicates the quality of filtering when generating mipmap images
1038 fun gl_GENERATE_MIPMAP_HINT
: GLHintTarget `{ return GL_GENERATE_MIPMAP_HINT; `}
1040 # Hint mode for `glHint
`
1041 extern class GLHintMode
1045 # The most efficient option should be chosen
1046 fun gl_FASTEST: GLHintMode `{ return GL_FASTEST; `}
1048 # The most correct, or highest quality, option should be chosen
1049 fun gl_NICEST
: GLHintMode `{ return GL_NICEST; `}
1052 fun gl_DONT_CARE: GLHintMode `{ return GL_DONT_CARE; `}
1054 # Generate `n` framebuffer object names
1055 fun glGenFramebuffers
(n
: Int): Array[Int]
1057 var array
= new CIntArray(n
)
1058 native_glGenFramebuffers
(n
, array
.native_array
)
1064 private fun native_glGenFramebuffers
(n
: Int, framebuffers
: NativeCIntArray) `{
1065 glGenFramebuffers(n, (GLuint *)framebuffers);
1068 # Does `name` corresponds to a framebuffer object?
1069 fun glIsFramebuffer
(name
: Int): Bool `{
1070 return glIsFramebuffer(name);
1073 # Delete named framebuffer objects
1074 fun glDeleteFramebuffers
(framebuffers
: SequenceRead[Int])
1076 var n
= framebuffers
.length
1077 var array
= new CIntArray.from
(framebuffers
)
1078 native_glDeleteFramebuffers
(n
, array
.native_array
)
1082 private fun native_glDeleteFramebuffers
(n
: Int, framebuffers
: NativeCIntArray) `{
1083 return glDeleteFramebuffers(n, (const GLuint *)framebuffers);
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);
1092 # Entry point to OpenGL server-side capabilities
1093 class GLCapabilities
1095 # GL capability: blend the computed fragment color values
1098 var blend
: GLCap is lazy
do return new GLCap(0x0BE2)
1100 # GL capability: cull polygons based of their winding in window coordinates
1102 # Foreign: GL_CULL_FACE
1103 var cull_face
: GLCap is lazy
do return new GLCap(0x0B44)
1105 # GL capability: do depth comparisons and update the depth buffer
1107 # Foreign: GL_DEPTH_TEST
1108 var depth_test
: GLCap is lazy
do return new GLCap(0x0B71)
1110 # GL capability: dither color components or indices before they are written to the color buffer
1112 # Foreign: GL_DITHER
1113 var dither
: GLCap is lazy
do return new GLCap(0x0BE2)
1115 # GL capability: add an offset to depth values of a polygon fragment before depth test
1117 # Foreign: GL_POLYGON_OFFSET_FILL
1118 var polygon_offset_fill
: GLCap is lazy
do return new GLCap(0x8037)
1120 # GL capability: compute a temporary coverage value where each bit is determined by the alpha value at the corresponding location
1122 # Foreign: GL_SAMPLE_ALPHA_TO_COVERAGE
1123 var sample_alpha_to_coverage
: GLCap is lazy
do return new GLCap(0x809E)
1125 # GL capability: AND the fragment coverage with the temporary coverage value
1127 # Foreign: GL_SAMPLE_COVERAGE
1128 var sample_coverage
: GLCap is lazy
do return new GLCap(0x80A0)
1130 # GL capability: discard fragments that are outside the scissor rectangle
1132 # Foreign: GL_SCISSOR_TEST
1133 var scissor_test
: GLCap is lazy
do return new GLCap(0x0C11)
1135 # GL capability: do stencil testing and update the stencil buffer
1137 # Foreign: GL_STENCIL_TEST
1138 var stencil_test
: GLCap is lazy
do return new GLCap(0x0B90)
1141 # All data types of OpenGL ES 2.0 shaders
1143 # These types can be used by shader uniforms, as seen with
1144 # `GLProgram::active_uniform_type`.
1145 extern class GLDataType
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; `}
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; `}
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; `}
1178 # Kind of primitives to render
1179 extern class GLDrawMode
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; `}
1191 # Pixel arithmetic for blending operations
1192 extern class GLBlendFactor
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; `}
1208 # Condition under which a pixel will be drawn
1209 extern class GLDepthFunc
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; `}
1222 # Format of pixel data
1223 extern class GLPixelFormat
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; `}
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; `}
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; `}
1242 # Define front- and back-facing polygons, `gc_CCW
` by default
1243 fun glFrontFace(mode: GLFrontFaceMode) `{ glFrontFace(mode); `}
1245 # Orientation of front-facing polygons
1246 extern class GLFrontFaceMode
1250 fun gl_CW
: GLFrontFaceMode `{ return GL_CW; `}
1251 fun gl_CCW: GLFrontFaceMode `{ return GL_CCW; `}
1253 # Specify whether front- or back-facing polygons can be culled, default is `back` only
1254 fun glCullFace
(mode
: GLCullFaceMode) `{ glCullFace(mode); `}
1256 # Candidates for culling
1257 extern class GLCullFaceMode
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; `}
1265 # Specify mapping of depth values from normalized device coordinates to window coordinates
1267 # Default at 0.0, 1.0.
1268 fun glDepthRangef
(near
, far
: Float) `{ glDepthRangef(near, far); `}
1270 # Enable or disable writing into the depth buffer
1271 fun glDepthMask(value: Bool) `{ glDepthMask(value); `}
1273 # Specify the value used for depth buffer comparisons
1275 # Default value is `gl_LESS`
1276 fun glDepthFunc
(func
: GLDepthFunc) `{ glDepthFunc(func); `}
1278 # Set the pixel arithmetic for the blending operations
1281 # * `src_factor
`: `gl_ONE
`
1282 # * `dst_factor
`: `gl_ZERO
`
1283 fun glBlendFunc(src_factor, dst_factor: GLBlendFactor) `{
1284 glBlendFunc
(src_factor
, dst_factor
);
1287 # Set the scale and units used to calculate depth values
1288 fun glPolygonOffset(factor, units: Float) `{ glPolygonOffset(factor, units); `}
1290 # Specify the width of rasterized lines
1291 fun glLineWidth
(width
: Float) `{ glLineWidth(width); `}
1293 # Get the value of the parameter `pname
` at `offset
`
1294 fun glGetBooleanv(pname: GLGetParameterName, offset: Int): Bool `{
1296 glGetBooleanv
(pname
, v
);
1300 # Get the value of the parameter `pname
` at `offset
`
1301 fun glGetFloatv(pname: GLGetParameterName, offset: Int): Float `{
1303 glGetFloatv
(pname
, v
);
1307 # Get the value of the parameter `pname
` at `offset
`
1308 fun glGetIntegerv(pname: GLGetParameterName, offset: Int): Int `{
1310 glGetIntegerv
(pname
, v
);
1314 fun gl_COLOR_CLEAR_VALUE: GLGetParameterName `{ return GL_COLOR_CLEAR_VALUE; `}
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; `}
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; `}
1334 # Return a string describing the current GL configuration
1335 fun glGetString
(name
: GLEnum): String
1337 var cstr
= glGetString_native
(name
)
1338 assert not cstr
.address_is_null
1342 private fun glGetString_native
(name
: GLEnum): CString `{ return (char*)glGetString(name); `}
1344 # Company responsible for this GL implementation
1345 fun gl_VENDOR: GLEnum `{ return GL_VENDOR; `}
1347 # Name of the renderer, typically specific to a particular configuration of the hardware platform
1348 fun gl_RENDERER
: GLEnum `{ return GL_RENDERER; `}
1350 # Version or release number
1351 fun gl_VERSION: GLEnum `{ return GL_VERSION; `}
1353 # Version or release number for the shading language of the form
1354 fun gl_SHADING_LANGUAGE_VERSION
: GLEnum `{ return GL_SHADING_LANGUAGE_VERSION; `}
1356 # Space-separated list of supported extensions to GL
1357 fun gl_EXTENSIONS: GLEnum `{ return GL_EXTENSIONS; `}