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 higher level
21 # wrappers such as `mnit` and `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 new_annotation glsl_vertex_shader
35 new_annotation glsl_fragment_shader
36 ldflags
("-lGLESv2")@android
43 #include <GLES2/gl2.h>
46 # OpenGL ES program to which we attach shaders
47 extern class GLProgram `{GLuint`}
48 # Create a new program
50 # The newly created instance should be checked using `is_ok
`.
51 new `{ return glCreateProgram(); `}
53 # Set the location for the attribute by `name`
54 fun bind_attrib_location
(index
: Int, name
: String) import String.to_cstring
`{
55 GLchar *c_name = String_to_cstring(name);
56 glBindAttribLocation(self, index, c_name);
59 # Get the location of the attribute by `name`
61 # Returns `-1` if there is no active attribute named `name`.
62 fun attrib_location
(name
: String): Int import String.to_cstring
`{
63 GLchar *c_name = String_to_cstring(name);
64 return glGetAttribLocation(self, c_name);
67 # Get the location of the uniform by `name`
69 # Returns `-1` if there is no active uniform named `name`.
70 fun uniform_location
(name
: String): Int import String.to_cstring
`{
71 GLchar *c_name = String_to_cstring(name);
72 return glGetUniformLocation(self, c_name);
75 # Is this program linked?
76 fun is_linked
: Bool do return glGetProgramiv
(self, gl_LINK_STATUS
) != 0
78 # Has this program been deleted?
79 fun is_deleted
: Bool do return glGetProgramiv
(self, gl_DELETE_STATUS
) != 0
81 # Boolean result of `validate`, must be called after `validate`
82 fun is_validated
: Bool do return glGetProgramiv
(self, gl_VALIDATE_STATUS
) != 0
84 # Number of active uniform in this program
86 # This should be the number of uniforms declared in all shader, except
87 # unused uniforms which may have been optimized out.
88 fun n_active_uniforms
: Int do return glGetProgramiv
(self, gl_ACTIVE_UNIFORMS
)
90 # Length of the longest uniform name in this program, including the null byte
91 fun active_uniform_max_length
: Int do return glGetProgramiv
(self, gl_ACTIVE_UNIFORM_MAX_LENGTH
)
93 # Number of active attributes in this program
95 # This should be the number of uniforms declared in all shader, except
96 # unused uniforms which may have been optimized out.
97 fun n_active_attributes
: Int do return glGetProgramiv
(self, gl_ACTIVE_ATTRIBUTES
)
99 # Length of the longest attribute name in this program, including the null byte
100 fun active_attribute_max_length
: Int do return glGetProgramiv
(self, gl_ACTIVE_ATTRIBUTE_MAX_LENGTH
)
102 # Number of shaders attached to this program
103 fun n_attached_shaders
: Int do return glGetProgramiv
(self, gl_ATTACHED_SHADERS
)
105 # Name of the active attribute at `index`
106 fun active_attrib_name
(index
: Int): String
108 var max_size
= active_attribute_max_length
109 var cname
= new CString(max_size
)
110 active_attrib_name_native
(index
, max_size
, cname
)
114 private fun active_attrib_name_native
(index
, max_size
: Int, name
: CString) `{
115 // We get more values than we need, for compatibility. At least the
116 // NVidia driver tries to fill them even if NULL.
120 glGetActiveAttrib(self, index, max_size, NULL, &size, &type, name);
123 # Size of the active attribute at `index`
124 fun active_attrib_size
(index
: Int): Int `{
127 glGetActiveAttrib(self, index, 0, NULL, &size, &type, NULL);
131 # Type of the active attribute at `index`
133 # May only be float related data types (single float, vectors and matrix).
134 fun active_attrib_type
(index
: Int): GLDataType `{
137 glGetActiveAttrib(self, index, 0, NULL, &size, &type, NULL);
141 # Name of the active uniform at `index`
142 fun active_uniform_name
(index
: Int): String
144 var max_size
= active_uniform_max_length
145 var cname
= new CString(max_size
)
146 active_uniform_name_native
(index
, max_size
, cname
)
150 private fun active_uniform_name_native
(index
, max_size
: Int, name
: CString) `{
153 glGetActiveUniform(self, index, max_size, NULL, &size, &type, name);
156 # Size of the active uniform at `index`
157 fun active_uniform_size
(index
: Int): Int `{
160 glGetActiveUniform(self, index, 0, NULL, &size, &type, NULL);
164 # Type of the active uniform at `index`
166 # May be any data type supported by OpenGL ES 2.0 shaders.
167 fun active_uniform_type
(index
: Int): GLDataType `{
170 glGetActiveUniform(self, index, 0, NULL, &size, &type, NULL);
175 # Create a program object
176 fun glCreateProgram
: GLProgram `{ return glCreateProgram(); `}
178 # Install the `program
` as part of current rendering state
179 fun glUseProgram(program: GLProgram) `{ glUseProgram(program); `}
181 # Link the `program` object
182 fun glLinkProgram
(program
: GLProgram) `{ glLinkProgram(program); `}
184 # Validate the `program
` object
185 fun glValidateProgram(program: GLProgram) `{ glValidateProgram(program); `}
187 # Delete the `program` object
188 fun glDeleteProgram
(program
: GLProgram) `{ glDeleteProgram(program); `}
190 # Does `name
` corresponds to a program object?
191 fun glIsProgram(name: GLProgram): Bool `{ return glIsProgram(name); `}
193 # Attach a `shader` to `program`
194 fun glAttachShader
(program
: GLProgram, shader
: GLShader) `{ glAttachShader(program, shader); `}
196 # Detach `shader
` from `program
`
197 fun glDetachShader(program: GLProgram, shader: GLShader) `{ glDetachShader(program, shader); `}
199 # Parameter value from a `program` object
200 fun glGetProgramiv
(program
: GLProgram, pname
: GLGetParameterName): Int `{
202 glGetProgramiv(program, pname, &value);
206 # The information log for the `program` object
207 fun glGetProgramInfoLog
(program
: GLProgram): String
209 var size
= glGetProgramiv
(program
, gl_INFO_LOG_LENGTH
)
210 var buf
= new CString(size
)
211 native_glGetProgramInfoLog
(program
, size
, buf
)
212 return buf
.to_s_with_length
(size
)
215 # Return the program information log in `buf`
216 private fun native_glGetProgramInfoLog
(program
: GLProgram, buf_size
: Int, buf
: CString): Int `{
218 glGetProgramInfoLog(program, buf_size, &length, buf);
222 # Abstract OpenGL ES shader object, implemented by `GLFragmentShader` and `GLVertexShader`
223 extern class GLShader `{GLuint`}
225 # Source of the shader, if available
227 # Returns `null` if the source is not available, usually when the shader
228 # was created from a binary file.
229 fun source: nullable String
231 var size = glGetShaderiv(self, gl_SHADER_SOURCE_LENGTH)
232 if size == 0 then return null
233 return source_native(size).to_s
236 private fun source_native(size: Int): CString `{
237 GLchar *code
= malloc
(size
);
238 glGetShaderSource
(self, size
, NULL, code
);
242 # Has this shader been compiled?
243 fun is_compiled: Bool do return glGetShaderiv(self, gl_COMPILE_STATUS) != 0
245 # Has this shader been deleted?
246 fun is_deleted: Bool do return glGetShaderiv(self, gl_DELETE_STATUS) != 0
249 # Get a parameter value from a `shader
` object
250 fun glGetShaderiv(shader: GLShader, pname: GLGetParameterName): Int `{
252 glGetShaderiv
(shader
, pname
, &val
);
257 extern class GLGetParameterName
261 fun gl_INFO_LOG_LENGTH: GLGetParameterName `{ return GL_INFO_LOG_LENGTH; `}
262 fun gl_DELETE_STATUS
: GLGetParameterName `{ return GL_DELETE_STATUS; `}
264 fun gl_SHADER_TYPE: GLGetParameterName `{ return GL_SHADER_TYPE; `}
265 fun gl_COMPILE_STATUS
: GLGetParameterName `{ return GL_COMPILE_STATUS; `}
266 fun gl_SHADER_SOURCE_LENGTH: GLGetParameterName `{ return GL_SHADER_SOURCE_LENGTH; `}
268 fun gl_ACTIVE_ATTRIBUTES
: GLGetParameterName `{ return GL_ACTIVE_ATTRIBUTES; `}
269 fun gl_ACTIVE_ATTRIBUTE_MAX_LENGTH: GLGetParameterName `{ return GL_ACTIVE_ATTRIBUTE_MAX_LENGTH; `}
270 fun gl_ACTIVE_UNIFORMS
: GLGetParameterName `{ return GL_ACTIVE_UNIFORMS; `}
271 fun gl_ACTIVE_UNIFORM_MAX_LENGTH: GLGetParameterName `{ return GL_ACTIVE_UNIFORM_MAX_LENGTH; `}
272 fun gl_ATTACHED_SHADERS
: GLGetParameterName `{ return GL_ATTACHED_SHADERS; `}
273 fun gl_LINK_STATUS: GLGetParameterName `{ return GL_LINK_STATUS; `}
274 fun gl_VALIDATE_STATUS
: GLGetParameterName `{ return GL_VALIDATE_STATUS; `}
276 # The information log for the `shader
` object
277 fun glGetShaderInfoLog(shader: GLShader): String
279 var size = glGetShaderiv(shader, gl_INFO_LOG_LENGTH)
280 var buf = new CString(size)
281 native_glGetShaderInfoLog(shader, size, buf)
282 return buf.to_s_with_length(size)
285 private fun native_glGetShaderInfoLog(shader: GLShader, buf_size: Int, buffer: CString): Int `{
287 glGetShaderInfoLog
(shader
, buf_size
, &length
, buffer
);
292 extern class GLShaderType
296 fun gl_VERTEX_SHADER: GLShaderType `{ return GL_VERTEX_SHADER; `}
297 fun gl_FRAGMENT_SHADER
: GLShaderType `{ return GL_FRAGMENT_SHADER; `}
299 # Create a shader object of the `shader_type
`
300 fun glCreateShader(shader_type: GLShaderType): GLShader `{
301 return glCreateShader
(shader_type
);
304 # Replace the source code in the `shader
` object with `code
`
305 fun glShaderSource(shader: GLShader, code: CString) `{
306 glShaderSource
(shader
, 1, (GLchar const
**)&code
, NULL);
309 # Compile the `shader
` object
310 fun glCompileShader(shader: GLShader) `{ glCompileShader(shader); `}
312 # Delete the `shader` object
313 fun glDeleteShader
(shader
: GLShader) `{ glDeleteShader(shader); `}
315 # Does `name
` corresponds to a shader object?
316 fun glIsShader(name: GLShader): Bool `{ return glIsShader(name); `}
318 # An OpenGL ES 2.0 fragment shader
319 extern class GLFragmentShader
322 # Create a new fragment shader
324 # The newly created instance should be checked using `is_ok`.
325 new `{ return glCreateShader(GL_FRAGMENT_SHADER); `}
328 # An OpenGL ES 2.0 vertex shader
329 extern class GLVertexShader
332 # Create a new fragment shader
334 # The newly created instance should be checked using `is_ok
`.
335 new `{ return glCreateShader(GL_VERTEX_SHADER); `}
338 # An array of `Float` associated to a program variable
342 # Number of data per vertex
345 protected var glfloat_array
: NativeGLfloatArray
347 init(index
, count
: Int, array
: Array[Float])
351 self.glfloat_array
= new NativeGLfloatArray(array
.length
)
352 for k
in [0..array
.length
[ do
353 glfloat_array
[k
] = array
[k
]
357 fun attrib_pointer
do attrib_pointer_intern
(index
, count
, glfloat_array
)
358 private fun attrib_pointer_intern
(index
, count
: Int, array
: NativeGLfloatArray) `{
359 glVertexAttribPointer(index, count, GL_FLOAT, GL_FALSE, 0, array);
362 # Enable this vertex attribute array
363 fun enable
do glEnableVertexAttribArray
(index
)
365 # Disable this vertex attribute array
366 fun disable
do glDisableVertexAttribArray
(index
)
369 # Enable the generic vertex attribute array at `index`
370 fun glEnableVertexAttribArray
(index
: Int) `{ glEnableVertexAttribArray(index); `}
372 # Disable the generic vertex attribute array at `index
`
373 fun glDisableVertexAttribArray(index: Int) `{ glDisableVertexAttribArray(index); `}
375 # Render primitives from array data
376 fun glDrawArrays
(mode
: GLDrawMode, from
, count
: Int) `{ glDrawArrays(mode, from, count); `}
378 # Render primitives from array data by their index listed in `indices
`
379 fun glDrawElements(mode: GLDrawMode, count: Int, typ: GLDataType, indices: Pointer) `{
380 glDrawElements
(mode
, count
, typ
, indices
);
383 # Render primitives from array data, at `offset
` in the element buffer
384 fun glDrawElementsi(mode: GLDrawMode, count: Int, typ: GLDataType, offset: Int) `{
385 glDrawElements
(mode
, count
, typ
, (const
GLvoid*)offset
);
388 # Define an array of generic vertex attribute data
389 fun glVertexAttribPointer(index, size: Int, typ: GLDataType, normalized: Bool, stride: Int, array: NativeGLfloatArray) `{
390 glVertexAttribPointer
(index
, size
, typ
, normalized
, stride
, array
);
393 # Define an array of generic vertex attribute data, at `offset
` in the array buffer
394 fun glVertexAttribPointeri(index, size: Int, typ: GLDataType, normalized: Bool, stride: Int, offset: Int) `{
395 glVertexAttribPointer
(index
, size
, typ
, normalized
, stride
, (const
GLvoid*)offset
);
398 # Specify the value of a generic vertex attribute
399 fun glVertexAttrib1f(index: Int, x: Float) `{ glVertexAttrib1f(index, x); `}
401 # Specify the value of a generic vertex attribute
402 fun glVertexAttrib2f
(index
: Int, x
, y
: Float) `{ glVertexAttrib2f(index, x, y); `}
404 # Specify the value of a generic vertex attribute
405 fun glVertexAttrib3f(index: Int, x, y, z: Float) `{ glVertexAttrib3f(index, x, y, z); `}
407 # Specify the value of a generic vertex attribute
408 fun glVertexAttrib4f
(index
: Int, x
, y
, z
, w
: Float) `{ glVertexAttrib4f(index, x, y, z, w); `}
410 # Specify the value of a uniform variable for the current program object
411 fun glUniform1i(index, x: Int) `{ glUniform1i(index, x); `}
413 # Specify the value of a uniform variable for the current program object
414 fun glUniform2i
(index
, x
, y
: Int) `{ glUniform2i(index, x, y); `}
416 # Specify the value of a uniform variable for the current program object
417 fun glUniform3i(index, x, y, z: Int) `{ glUniform3i(index, x, y, z); `}
419 # Specify the value of a uniform variable for the current program object
420 fun glUniform4i
(index
, x
, y
, z
, w
: Int) `{ glUniform4i(index, x, y, z, w); `}
422 # Specify the value of a uniform variable for the current program object
423 fun glUniform1f(index: Int, x: Float) `{ glUniform1f(index, x); `}
425 # Specify the value of a uniform variable for the current program object
426 fun glUniform2f
(index
: Int, x
, y
: Float) `{ glUniform2f(index, x, y); `}
428 # Specify the value of a uniform variable for the current program object
429 fun glUniform3f(index: Int, x, y, z: Float) `{ glUniform3f(index, x, y, z); `}
431 # Specify the value of a uniform variable for the current program object
432 fun glUniform4f
(index
: Int, x
, y
, z
, w
: Float) `{ glUniform4f(index, x, y, z, w); `}
434 # Low level array of `Float`
437 redef type NATIVE: NativeGLfloatArray
441 native_array = new NativeGLfloatArray(length)
444 # Create with the content of `array
`
445 new from(array: Array[Float])
447 var arr = new GLfloatArray(array.length)
452 # Fill with the content of `array
`
453 fun fill_from(array: Array[Float])
455 assert length >= array.length
456 for k in [0..array.length[ do
462 # An array of `GLfloat` in C (`GLfloat*`)
463 extern class NativeGLfloatArray `{ GLfloat* `}
467 new(size
: Int) `{ return calloc(size, sizeof(GLfloat)); `}
469 redef fun [](index) `{ return self[index]; `}
470 redef fun []=(index
, val
) `{ self[index] = val; `}
472 redef fun +(offset) `{ return self + offset; `}
475 # General type for OpenGL enumerations
476 extern class GLEnum `{ GLenum `}
478 redef fun hash `{ return self; `}
480 redef fun ==(o
) do return o
!= null and is_same_type
(o
) and o
.hash
== self.hash
484 fun glGetError
: GLError `{ return glGetError(); `}
486 # An OpenGL ES 2.0 error code
492 if self == gl_NO_ERROR then return "No error"
493 if self == gl_INVALID_ENUM then return "Invalid enum"
494 if self == gl_INVALID_VALUE then return "Invalid value"
495 if self == gl_INVALID_OPERATION then return "Invalid operation"
496 if self == gl_INVALID_FRAMEBUFFER_OPERATION then return "invalid framebuffer operation"
497 if self == gl_OUT_OF_MEMORY then return "Out of memory"
498 return "Unknown error"
502 fun gl_NO_ERROR: GLError `{ return GL_NO_ERROR; `}
503 fun gl_INVALID_ENUM
: GLError `{ return GL_INVALID_ENUM; `}
504 fun gl_INVALID_VALUE: GLError `{ return GL_INVALID_VALUE; `}
505 fun gl_INVALID_OPERATION
: GLError `{ return GL_INVALID_OPERATION; `}
506 fun gl_INVALID_FRAMEBUFFER_OPERATION: GLError `{ return GL_INVALID_FRAMEBUFFER_OPERATION; `}
507 fun gl_OUT_OF_MEMORY
: GLError `{ return GL_OUT_OF_MEMORY; `}
509 fun assert_no_gl_error
511 var error = glGetError
512 if not error == gl_NO_ERROR then
513 print "GL error: {error}"
518 # Texture unit, the number of texture units is implementation dependent
519 extern class GLTextureUnit
523 fun gl_TEXTURE0: GLTextureUnit `{ return GL_TEXTURE0; `}
524 fun gl_TEXTURE1
: GLTextureUnit `{ return GL_TEXTURE1; `}
525 fun gl_TEXTURE2: GLTextureUnit `{ return GL_TEXTURE2; `}
526 fun gl_TEXTURE3
: GLTextureUnit `{ return GL_TEXTURE3; `}
527 fun gl_TEXTURE4: GLTextureUnit `{ return GL_TEXTURE4; `}
528 fun gl_TEXTURE5
: GLTextureUnit `{ return GL_TEXTURE5; `}
529 fun gl_TEXTURE6: GLTextureUnit `{ return GL_TEXTURE6; `}
530 fun gl_TEXTURE7
: GLTextureUnit `{ return GL_TEXTURE7; `}
531 fun gl_TEXTURE8: GLTextureUnit `{ return GL_TEXTURE8; `}
532 fun gl_TEXTURE9
: GLTextureUnit `{ return GL_TEXTURE9; `}
533 fun gl_TEXTURE10: GLTextureUnit `{ return GL_TEXTURE10; `}
534 fun gl_TEXTURE11
: GLTextureUnit `{ return GL_TEXTURE11; `}
535 fun gl_TEXTURE12: GLTextureUnit `{ return GL_TEXTURE12; `}
536 fun gl_TEXTURE13
: GLTextureUnit `{ return GL_TEXTURE13; `}
537 fun gl_TEXTURE14: GLTextureUnit `{ return GL_TEXTURE14; `}
538 fun gl_TEXTURE15
: GLTextureUnit `{ return GL_TEXTURE15; `}
539 fun gl_TEXTURE16: GLTextureUnit `{ return GL_TEXTURE16; `}
540 fun gl_TEXTURE17
: GLTextureUnit `{ return GL_TEXTURE17; `}
541 fun gl_TEXTURE18: GLTextureUnit `{ return GL_TEXTURE18; `}
542 fun gl_TEXTURE19
: GLTextureUnit `{ return GL_TEXTURE19; `}
543 fun gl_TEXTURE20: GLTextureUnit `{ return GL_TEXTURE20; `}
544 fun gl_TEXTURE21
: GLTextureUnit `{ return GL_TEXTURE21; `}
545 fun gl_TEXTURE22: GLTextureUnit `{ return GL_TEXTURE22; `}
546 fun gl_TEXTURE23
: GLTextureUnit `{ return GL_TEXTURE23; `}
547 fun gl_TEXTURE24: GLTextureUnit `{ return GL_TEXTURE24; `}
548 fun gl_TEXTURE25
: GLTextureUnit `{ return GL_TEXTURE25; `}
549 fun gl_TEXTURE26: GLTextureUnit `{ return GL_TEXTURE26; `}
550 fun gl_TEXTURE27
: GLTextureUnit `{ return GL_TEXTURE27; `}
551 fun gl_TEXTURE28: GLTextureUnit `{ return GL_TEXTURE28; `}
552 fun gl_TEXTURE29
: GLTextureUnit `{ return GL_TEXTURE29; `}
553 fun gl_TEXTURE30: GLTextureUnit `{ return GL_TEXTURE30; `}
554 fun gl_TEXTURE31
: GLTextureUnit `{ return GL_TEXTURE31; `}
556 # Texture unit at `offset
` after `gl_TEXTURE0
`
557 fun gl_TEXTURE(offset: Int): GLTextureUnit `{ return GL_TEXTURE0 + offset; `}
559 # Generate `n` texture names
560 fun glGenTextures
(n
: Int): Array[Int]
562 var array
= new CIntArray(n
)
563 native_glGenTextures
(n
, array
.native_array
)
569 private fun native_glGenTextures
(n
: Int, textures
: NativeCIntArray) `{
570 glGenTextures(n, (GLuint*)textures);
573 # Select server-side active texture unit
574 fun glActiveTexture
(texture
: GLTextureUnit) `{ glActiveTexture(texture); `}
576 # Bind the named `texture
` to a `target
`
577 fun glBindTexture(target: GLTextureTarget, texture: Int) `{
578 glBindTexture
(target
, texture
);
581 # Delete named textures
582 fun glDeleteTextures(textures: SequenceRead[Int])
584 var n = textures.length
585 var array = new CIntArray.from(textures)
586 native_glDeleteTextures(n, array.native_array)
590 private fun native_glDeleteTextures(n: Int, textures: NativeCIntArray) `{
591 glDeleteTextures
(n
, (const
GLuint *)textures
);
594 # Does `name
` corresponds to a texture?
595 fun glIsTexture(name: Int): Bool `{ return glIsTexture(name); `}
597 # Set pixel storage modes
598 fun glPixelStorei
(parameter
: GLPack, val
: Int) `{ glPixelStorei(parameter, val); `}
600 # Symbolic name of the parameter to be set with `glPixelStorei
`
605 # Parameter to specify the alignment requirements for the start of each pixel row in memory
606 fun gl_PACK_ALIGNEMENT: GLPack `{ return GL_PACK_ALIGNMENT; `}
608 # Parameter to specify the alignment requirements for the start of each pixel row in memory
609 fun gl_UNPACK_ALIGNEMENT
: GLPack `{ return GL_UNPACK_ALIGNMENT; `}
611 # TODO GL_PACK_ROW_LENGTH, GL_PACK_IMAGE_HEIGHT, GL_PACK_SKIP_PIXELS, GL_PACK_SKIP_ROWS, GL_PACK_SKIP_IMAGES
612 # GL_UNPACK_ROW_LENGTH, GL_UNPACK_IMAGE_HEIGHT, GL_UNPACK_SKIP_PIXELS, GL_UNPACK_SKIP_ROWS, GL_UNPACK_SKIP_IMAGES
614 # Specify a two-dimensional texture image
615 fun glTexImage2D(target: GLTextureTarget, level: Int, internalformat: GLPixelFormat,
616 width, height, border: Int,
617 format: GLPixelFormat, typ: GLDataType, data: Pointer) `{
618 glTexImage2D
(target
, level
, internalformat
, width
, height
, border
, format
, typ
, data
);
621 # Specify a two-dimensional texture subimage
622 fun glTexSubImage2D(target: GLTextureTarget,
623 level, xoffset, yoffset, width, height, border: Int,
624 format: GLPixelFormat, typ: GLDataType, data: Pointer) `{
625 glTexSubImage2D
(target
, level
, xoffset
, yoffset
, width
, height
, format
, typ
, data
);
628 # Copy pixels into a 2D texture image
629 fun glCopyTexImage2D(target: GLTextureTarget, level: Int, internalformat: GLPixelFormat,
630 x, y, width, height, border: Int) `{
631 glCopyTexImage2D
(target
, level
, internalformat
, x
, y
, width
, height
, border
);
634 # Copy a two-dimensional texture subimage
635 fun glCopyTexSubImage2D(target: GLTextureTarget, level, xoffset, yoffset, x, y, width, height: Int) `{
636 glCopyTexSubImage2D
(target
, level
, xoffset
, yoffset
, x
, y
, width
, height
);
639 # Copy a block of pixels from the framebuffer of `fomat
` and `typ
` at `data
`
640 fun glReadPixels(x, y, width, height: Int, format: GLPixelFormat, typ: GLDataType, data: Pointer) `{
641 glReadPixels
(x
, y
, width
, height
, format
, typ
, data
);
644 # Texture minifying and magnifying function
645 extern class GLTexParameteri
649 fun gl_NEAREST: GLTexParameteri `{ return GL_NEAREST; `}
650 fun gl_LINEAR
: GLTexParameteri `{ return GL_LINEAR; `}
651 fun gl_NEAREST_MIPMAP_NEAREST: GLTexParameteri `{ return GL_NEAREST_MIPMAP_NEAREST; `}
652 fun gl_LINEAR_MIPMAP_NEAREST
: GLTexParameteri `{ return GL_LINEAR_MIPMAP_NEAREST; `}
653 fun gl_NEAREST_MIPMAP_NINEAR: GLTexParameteri `{ return GL_NEAREST_MIPMAP_LINEAR; `}
654 fun gl_LINEAR_MIPMAP_LINEAR
: GLTexParameteri `{ return GL_LINEAR_MIPMAP_LINEAR; `}
655 fun gl_CLAMP_TO_EDGE: GLTexParameteri `{ return GL_CLAMP_TO_EDGE; `}
656 fun gl_MIRRORED_REPEAT
: GLTexParameteri `{ return GL_MIRRORED_REPEAT; `}
657 fun gl_REPEAT: GLTexParameteri `{ return GL_REPEAT; `}
660 extern class GLTextureTarget
664 # Two-dimensional texture
665 fun gl_TEXTURE_2D
: GLTextureTarget `{ return GL_TEXTURE_2D; `}
668 fun gl_TEXTURE_CUBE_MAP: GLTextureTarget `{ return GL_TEXTURE_CUBE_MAP; `}
670 # TODO GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
671 # GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
673 # A server-side capability
678 # Internal OpenGL integer for this capability
681 # Enable this server-side capability
682 fun enable
do enable_native
(val
)
683 private fun enable_native
(cap
: Int) `{ glEnable(cap); `}
685 # Disable this server-side capability
686 fun disable do disable_native(val)
687 private fun disable_native(cap: Int) `{ glDisable(cap); `}
689 redef fun hash
do return val
690 redef fun ==(o
) do return o
!= null and is_same_type
(o
) and o
.hash
== self.hash
693 # Generate `n` renderbuffer object names
694 fun glGenRenderbuffers
(n
: Int): Array[Int]
696 var array
= new CIntArray(n
)
697 native_glGenRenderbuffers
(n
, array
.native_array
)
703 private fun native_glGenRenderbuffers
(n
: Int, renderbuffers
: NativeCIntArray) `{
704 glGenRenderbuffers(n, (GLuint *)renderbuffers);
707 # Does `name` corresponds to a renderbuffer object?
708 fun glIsRenderbuffer
(name
: Int): Bool `{
709 return glIsRenderbuffer(name);
712 # Delete named renderbuffer objects
713 fun glDeleteRenderbuffers
(renderbuffers
: SequenceRead[Int])
715 var n
= renderbuffers
.length
716 var array
= new CIntArray.from
(renderbuffers
)
717 native_glDeleteRenderbuffers
(n
, array
.native_array
)
721 private fun native_glDeleteRenderbuffers
(n
: Int, renderbuffers
: NativeCIntArray) `{
722 return glDeleteRenderbuffers(n, (const GLuint *)renderbuffers);
725 # Attach a renderbuffer object to a framebuffer object
726 fun glFramebufferRenderbuffer
(target
: GLFramebufferTarget, attachment
: GLAttachment,
727 renderbuffertarget
: GLRenderbufferTarget, renderbuffer
: Int) `{
728 glFramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer);
731 # Establish data storage, `format` and dimensions of the `target` renderbuffer object's image
732 fun glRenderbufferStorage
(target
: GLRenderbufferTarget, format
: GLRenderbufferFormat, width
, height
: Int) `{
733 glRenderbufferStorage(GL_RENDERBUFFER, format, width, height);
736 # Format for a renderbuffer
737 extern class GLRenderbufferFormat
741 # 4 red, 4 green, 4 blue, 4 alpha bits format
742 fun gl_RGBA4
: GLRenderbufferFormat `{ return GL_RGBA4; `}
744 # 5 red, 6 green, 5 blue bits format
745 fun gl_RGB565: GLRenderbufferFormat `{ return GL_RGB565; `}
747 # 5 red, 5 green, 5 blue, 1 alpha bits format
748 fun gl_RGB_A1
: GLRenderbufferFormat `{ return GL_RGB5_A1; `}
750 # 16 depth bits format
751 fun gl_DEPTH_COMPNENT16: GLRenderbufferFormat `{ return GL_DEPTH_COMPONENT16; `}
753 # 8 stencil bits format
754 fun gl_STENCIL_INDEX8
: GLRenderbufferFormat `{ return GL_STENCIL_INDEX8; `}
756 # Renderbuffer attachment point to a framebuffer
757 extern class GLAttachment
761 # First color attachment point
762 fun gl_COLOR_ATTACHMENT0: GLAttachment `{ return GL_COLOR_ATTACHMENT0; `}
764 # Depth attachment point
765 fun gl_DEPTH_ATTACHMENT
: GLAttachment `{ return GL_DEPTH_ATTACHMENT; `}
768 fun gl_STENCIL_ATTACHMENT: GLAttachment `{ return GL_STENCIL_ATTACHMENT; `}
771 private var gles
= new GLES is lazy
774 # Entry points to OpenGL ES 2.0 services
775 fun gl
: GLES do return sys
.gles
777 # OpenGL ES 2.0 services
780 # Query the boolean value at `key`
781 private fun get_bool
(key
: Int): Bool `{
783 glGetBooleanv(key, &val);
784 return val == GL_TRUE;
787 # Query the floating point value at `key`
788 private fun get_float
(key
: Int): Float `{
790 glGetFloatv(key, &val);
794 # Query the integer value at `key`
795 private fun get_int
(key
: Int): Int `{
797 glGetIntegerv(key, &val);
801 # Does this driver support shader compilation?
803 # Should always return `true` in OpenGL ES 2.0 and 3.0.
804 fun shader_compiler
: Bool do return get_bool
(0x8DFA)
806 # OpenGL server-side capabilities
807 var capabilities
= new GLCapabilities is lazy
810 # Specify the clear values for the color buffer, default values are at 0.0
811 fun glClearColor
(red
, green
, blue
, alpha
: Float) `{
812 glClearColor(red, green, blue, alpha);
815 # Specify the clear `value` for the depth buffer, default at 1.0
816 fun glClearDepthf
(value
: Float) `{ glClearDepthf(value); `}
818 # Specify the clear `value
` for the stencil buffer, default at 0
819 fun glClearStencil(value: Int) `{ glClearStencil(value); `}
822 fun glClear
(buffer
: GLBuffer) `{ glClear(buffer); `}
824 # Enable and disable writing of frame buffer color components
825 fun glColorMask(red, green, blue, alpha: Bool) `{ glColorMask(red, green, blue, alpha); `}
828 fun glViewport
(x
, y
, width
, height
: Int) `{ glViewport(x, y, width, height); `}
830 # Block until all GL execution is complete
831 fun glFinish `{ glFinish(); `}
833 # Force execution of GL commands in finite time
834 fun glFlush
`{ glFlush(); `}
836 # Set texture parameters
837 fun glTexParameteri(target: GLTextureTarget, pname: GLTexParameteriName, param: GLTexParameteri) `{
838 glTexParameteri
(target
, pname
, param
);
841 # Name of parameters of textures
842 extern class GLTexParameteriName
846 fun gl_TEXTURE_MIN_FILTER: GLTexParameteriName `{ return GL_TEXTURE_MIN_FILTER; `}
847 fun gl_TEXTURE_MAG_FILTER
: GLTexParameteriName `{ return GL_TEXTURE_MAG_FILTER; `}
848 fun gl_TEXTURE_WRAP_S: GLTexParameteriName `{ return GL_TEXTURE_WRAP_S; `}
849 fun gl_TEXTURE_WRAP_T
: GLTexParameteriName `{ return GL_TEXTURE_WRAP_T; `}
851 # Bind `framebuffer
` to a framebuffer target
853 # In OpenGL ES 2.0, `target
` must be `gl_FRAMEBUFFER
`.
854 fun glBindFramebuffer(target: GLFramebufferTarget, framebuffer: Int) `{
855 glBindFramebuffer
(target
, framebuffer
);
858 # Target of `glBindFramebuffer
`
859 extern class GLFramebufferTarget
863 # Target both reading and writing on the framebuffer with `glBindFramebuffer
`
864 fun gl_FRAMEBUFFER: GLFramebufferTarget `{ return GL_FRAMEBUFFER; `}
866 # Bind `renderbuffer` to a renderbuffer target
868 # In OpenGL ES 2.0, `target` must be `gl_RENDERBUFFER`.
869 fun glBindRenderbuffer
(target
: GLRenderbufferTarget, renderbuffer
: Int) `{
870 glBindRenderbuffer(target, renderbuffer);
873 # Target of `glBindRenderbuffer`
874 extern class GLRenderbufferTarget
878 # Target a renderbuffer with `glBindRenderbuffer`
879 fun gl_RENDERBUFFER
: GLRenderbufferTarget `{ return GL_RENDERBUFFER; `}
881 # Specify implementation specific hints
882 fun glHint(target: GLHintTarget, mode: GLHintMode) `{
883 glHint
(target
, mode
);
886 # Generate and fill set of mipmaps for the texture object `target
`
887 fun glGenerateMipmap(target: GLTextureTarget) `{ glGenerateMipmap(target); `}
889 # Generate `n` buffer names
890 fun glGenBuffers
(n
: Int): Array[Int]
892 var array
= new CIntArray(n
)
893 native_glGenBuffers
(n
, array
.native_array
)
899 private fun native_glGenBuffers
(n
: Int, buffers
: NativeCIntArray) `{
900 glGenBuffers(n, (GLuint *)buffers);
903 # Does `name` corresponds to a buffer object?
904 fun glIsBuffer
(name
: Int): Bool `{
905 return glIsBuffer(name);
908 # Delete named buffer objects
909 fun glDeleteBuffers
(buffers
: SequenceRead[Int])
911 var n
= buffers
.length
912 var array
= new CIntArray.from
(buffers
)
913 native_glDeleteFramebuffers
(n
, array
.native_array
)
917 private fun native_glDeleteBuffers
(n
: Int, buffers
: NativeCIntArray) `{
918 return glDeleteBuffers(n, (const GLuint *)buffers);
921 # Create and initialize a buffer object's data store
922 fun glBufferData
(target
: GLArrayBuffer, size
: Int, data
: Pointer, usage
: GLBufferUsage) `{
923 glBufferData(target, size, data, usage);
926 # Update a subset of a buffer object's data store
927 fun glBufferSubData
(target
: GLArrayBuffer, offset
, size
: Int, data
: Pointer) `{
928 glBufferSubData(target, offset, size, data);
931 # Expected usage of a buffer
932 extern class GLBufferUsage
936 # Data will be modified once and used a few times
937 fun gl_STREAM_DRAW
: GLBufferUsage `{ return GL_STREAM_DRAW; `}
939 # Data will be modified once and used many times
940 fun gl_STATIC_DRAW: GLBufferUsage `{ return GL_STATIC_DRAW; `}
942 # Data will be modified repeatedly and used many times
943 fun gl_DYNAMIC_DRAW
: GLBufferUsage `{ return GL_DYNAMIC_DRAW; `}
945 # Bind the named `buffer
` object
946 fun glBindBuffer(target: GLArrayBuffer, buffer: Int) `{ glBindBuffer(target, buffer); `}
948 # Target to which bind the buffer with `glBindBuffer`
949 extern class GLArrayBuffer
953 # Array buffer target
954 fun gl_ARRAY_BUFFER
: GLArrayBuffer `{ return GL_ARRAY_BUFFER; `}
956 # Element array buffer
957 fun gl_ELEMENT_ARRAY_BUFFER: GLArrayBuffer `{ return GL_ELEMENT_ARRAY_BUFFER; `}
959 # Completeness status of a framebuffer object
960 fun glCheckFramebufferStatus
(target
: GLFramebufferTarget): GLFramebufferStatus `{
961 return glCheckFramebufferStatus(target);
964 # Return value of `glCheckFramebufferStatus`
965 extern class GLFramebufferStatus
970 if self == gl_FRAMEBUFFER_COMPLETE
then return "complete"
971 if self == gl_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
then return "incomplete attachment"
972 if self == gl_FRAMEBUFFER_INCOMPLETE_DIMENSIONS
then return "incomplete dimension"
973 if self == gl_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
then return "incomplete missing attachment"
974 if self == gl_FRAMEBUFFER_UNSUPPORTED
then return "unsupported"
979 # The framebuffer is complete
980 fun gl_FRAMEBUFFER_COMPLETE
: GLFramebufferStatus `{
981 return GL_FRAMEBUFFER_COMPLETE;
984 # Not all framebuffer attachment points are framebuffer attachment complete
985 fun gl_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
: GLFramebufferStatus `{
986 return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
989 # Not all attached images have the same width and height
990 fun gl_FRAMEBUFFER_INCOMPLETE_DIMENSIONS
: GLFramebufferStatus `{
991 return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS;
994 # No images are attached to the framebuffer
995 fun gl_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
: GLFramebufferStatus `{
996 return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
999 # The combination of internal formats of the attached images violates an implementation-dependent set of restrictions
1000 fun gl_FRAMEBUFFER_UNSUPPORTED
: GLFramebufferStatus `{
1001 return GL_FRAMEBUFFER_UNSUPPORTED;
1004 # Hint target for `glHint`
1005 extern class GLHintTarget
1009 # Indicates the quality of filtering when generating mipmap images
1010 fun gl_GENERATE_MIPMAP_HINT
: GLHintTarget `{ return GL_GENERATE_MIPMAP_HINT; `}
1012 # Hint mode for `glHint
`
1013 extern class GLHintMode
1017 # The most efficient option should be chosen
1018 fun gl_FASTEST: GLHintMode `{ return GL_FASTEST; `}
1020 # The most correct, or highest quality, option should be chosen
1021 fun gl_NICEST
: GLHintMode `{ return GL_NICEST; `}
1024 fun gl_DONT_CARE: GLHintMode `{ return GL_DONT_CARE; `}
1026 # Generate `n` framebuffer object names
1027 fun glGenFramebuffers
(n
: Int): Array[Int]
1029 var array
= new CIntArray(n
)
1030 native_glGenFramebuffers
(n
, array
.native_array
)
1036 private fun native_glGenFramebuffers
(n
: Int, framebuffers
: NativeCIntArray) `{
1037 glGenFramebuffers(n, (GLuint *)framebuffers);
1040 # Does `name` corresponds to a framebuffer object?
1041 fun glIsFramebuffer
(name
: Int): Bool `{
1042 return glIsFramebuffer(name);
1045 # Delete named framebuffer objects
1046 fun glDeleteFramebuffers
(framebuffers
: SequenceRead[Int])
1048 var n
= framebuffers
.length
1049 var array
= new CIntArray.from
(framebuffers
)
1050 native_glDeleteFramebuffers
(n
, array
.native_array
)
1054 private fun native_glDeleteFramebuffers
(n
: Int, framebuffers
: NativeCIntArray) `{
1055 return glDeleteFramebuffers(n, (const GLuint *)framebuffers);
1058 # Attach a level of a texture object as a logical buffer to the currently bound framebuffer object
1059 fun glFramebufferTexture2D
(target
: GLFramebufferTarget, attachment
: GLAttachment,
1060 texture_target
: GLTextureTarget, texture
, level
: Int) `{
1061 glFramebufferTexture2D(target, attachment, texture_target, texture, level);
1064 # Entry point to OpenGL server-side capabilities
1065 class GLCapabilities
1067 # GL capability: blend the computed fragment color values
1070 var blend
: GLCap is lazy
do return new GLCap(0x0BE2)
1072 # GL capability: cull polygons based of their winding in window coordinates
1074 # Foreign: GL_CULL_FACE
1075 var cull_face
: GLCap is lazy
do return new GLCap(0x0B44)
1077 # GL capability: do depth comparisons and update the depth buffer
1079 # Foreign: GL_DEPTH_TEST
1080 var depth_test
: GLCap is lazy
do return new GLCap(0x0B71)
1082 # GL capability: dither color components or indices before they are written to the color buffer
1084 # Foreign: GL_DITHER
1085 var dither
: GLCap is lazy
do return new GLCap(0x0BE2)
1087 # GL capability: add an offset to depth values of a polygon fragment before depth test
1089 # Foreign: GL_POLYGON_OFFSET_FILL
1090 var polygon_offset_fill
: GLCap is lazy
do return new GLCap(0x8037)
1092 # GL capability: compute a temporary coverage value where each bit is determined by the alpha value at the corresponding location
1094 # Foreign: GL_SAMPLE_ALPHA_TO_COVERAGE
1095 var sample_alpha_to_coverage
: GLCap is lazy
do return new GLCap(0x809E)
1097 # GL capability: AND the fragment coverage with the temporary coverage value
1099 # Foreign: GL_SAMPLE_COVERAGE
1100 var sample_coverage
: GLCap is lazy
do return new GLCap(0x80A0)
1102 # GL capability: discard fragments that are outside the scissor rectangle
1104 # Foreign: GL_SCISSOR_TEST
1105 var scissor_test
: GLCap is lazy
do return new GLCap(0x0C11)
1107 # GL capability: do stencil testing and update the stencil buffer
1109 # Foreign: GL_STENCIL_TEST
1110 var stencil_test
: GLCap is lazy
do return new GLCap(0x0B90)
1113 # All data types of OpenGL ES 2.0 shaders
1115 # These types can be used by shader uniforms, as seen with
1116 # `GLProgram::active_uniform_type`.
1117 extern class GLDataType
1121 fun gl_FLOAT
: GLDataType `{ return GL_FLOAT; `}
1122 fun gl_FLOAT_VEC2: GLDataType `{ return GL_FLOAT_VEC2; `}
1123 fun gl_FLOAT_VEC3
: GLDataType `{ return GL_FLOAT_VEC3; `}
1124 fun gl_FLOAT_VEC4: GLDataType `{ return GL_FLOAT_VEC4; `}
1125 fun gl_FLOAT_MAT2
: GLDataType `{ return GL_FLOAT_MAT2; `}
1126 fun gl_FLOAT_MAT3: GLDataType `{ return GL_FLOAT_MAT3; `}
1127 fun gl_FLOAT_MAT4
: GLDataType `{ return GL_FLOAT_MAT4; `}
1129 fun gl_BYTE: GLDataType `{ return GL_BYTE; `}
1130 fun gl_UNSIGNED_BYTE
: GLDataType `{ return GL_UNSIGNED_BYTE; `}
1131 fun gl_SHORT: GLDataType `{ return GL_SHORT; `}
1132 fun gl_UNSIGNED_SHORT
: GLDataType `{ return GL_UNSIGNED_SHORT; `}
1133 fun gl_INT: GLDataType `{ return GL_INT; `}
1134 fun gl_UNSIGNED_INT
: GLDataType `{ return GL_UNSIGNED_INT; `}
1135 fun gl_FIXED: GLDataType `{ return GL_FIXED; `}
1136 fun gl_INT_VEC2
: GLDataType `{ return GL_INT_VEC2; `}
1137 fun gl_INT_VEC3: GLDataType `{ return GL_INT_VEC3; `}
1138 fun gl_INT_VEC4
: GLDataType `{ return GL_INT_VEC4; `}
1139 fun gl_BOOL: GLDataType `{ return GL_BOOL; `}
1140 fun gl_BOOL_VEC2
: GLDataType `{ return GL_BOOL_VEC2; `}
1141 fun gl_BOOL_VEC3: GLDataType `{ return GL_BOOL_VEC3; `}
1142 fun gl_BOOL_VEC4
: GLDataType `{ return GL_BOOL_VEC4; `}
1143 fun gl_SAMPLER_2D: GLDataType `{ return GL_SAMPLER_2D; `}
1144 fun gl_SAMPLER_CUBE
: GLDataType `{ return GL_SAMPLER_CUBE; `}
1146 fun gl_UNSIGNED_SHORT_5_6_5: GLDataType `{ return GL_UNSIGNED_SHORT_5_6_5; `}
1147 fun gl_UNSIGNED_SHORT_4_4_4_4
: GLDataType `{ return GL_UNSIGNED_SHORT_4_4_4_4; `}
1148 fun gl_UNSIGNED_SHORT_5_5_5_1: GLDataType `{ return GL_UNSIGNED_SHORT_5_5_5_1; `}
1150 # Kind of primitives to render
1151 extern class GLDrawMode
1155 fun gl_POINTS
: GLDrawMode `{ return GL_POINTS; `}
1156 fun gl_LINES: GLDrawMode `{ return GL_LINES; `}
1157 fun gl_LINE_LOOP
: GLDrawMode `{ return GL_LINE_LOOP; `}
1158 fun gl_LINE_STRIP: GLDrawMode `{ return GL_LINE_STRIP; `}
1159 fun gl_TRIANGLES
: GLDrawMode `{ return GL_TRIANGLES; `}
1160 fun gl_TRIANGLE_STRIP: GLDrawMode `{ return GL_TRIANGLE_STRIP; `}
1161 fun gl_TRIANGLE_FAN
: GLDrawMode `{ return GL_TRIANGLE_FAN; `}
1163 # Pixel arithmetic for blending operations
1164 extern class GLBlendFactor
1168 fun gl_ZERO: GLBlendFactor `{ return GL_ZERO; `}
1169 fun gl_ONE
: GLBlendFactor `{ return GL_ONE; `}
1170 fun gl_SRC_COLOR: GLBlendFactor `{ return GL_SRC_COLOR; `}
1171 fun gl_ONE_MINUS_SRC_COLOR
: GLBlendFactor `{ return GL_ONE_MINUS_SRC_COLOR; `}
1172 fun gl_SRC_ALPHA: GLBlendFactor `{ return GL_SRC_ALPHA; `}
1173 fun gl_ONE_MINUS_SRC_ALPHA
: GLBlendFactor `{ return GL_ONE_MINUS_SRC_ALPHA; `}
1174 fun gl_DST_ALPHA: GLBlendFactor `{ return GL_DST_ALPHA; `}
1175 fun gl_ONE_MINUS_DST_ALPHA
: GLBlendFactor `{ return GL_ONE_MINUS_DST_ALPHA; `}
1176 fun gl_DST_COLOR: GLBlendFactor `{ return GL_DST_COLOR; `}
1177 fun gl_ONE_MINUS_DST_COLOR
: GLBlendFactor `{ return GL_ONE_MINUS_DST_COLOR; `}
1178 fun gl_SRC_ALPHA_SATURATE: GLBlendFactor `{ return GL_SRC_ALPHA_SATURATE; `}
1180 # Condition under which a pixel will be drawn
1181 extern class GLDepthFunc
1185 fun gl_NEVER
: GLDepthFunc `{ return GL_NEVER; `}
1186 fun gl_LESS: GLDepthFunc `{ return GL_LESS; `}
1187 fun gl_EQUAL
: GLDepthFunc `{ return GL_EQUAL; `}
1188 fun gl_LEQUAL: GLDepthFunc `{ return GL_LEQUAL; `}
1189 fun gl_GREATER
: GLDepthFunc `{ return GL_GREATER; `}
1190 fun gl_NOTEQUAL: GLDepthFunc `{ return GL_NOTEQUAL; `}
1191 fun gl_GEQUAL
: GLDepthFunc `{ return GL_GEQUAL; `}
1192 fun gl_ALWAYS: GLDepthFunc `{ return GL_ALWAYS; `}
1194 # Format of pixel data
1195 extern class GLPixelFormat
1199 fun gl_ALPHA
: GLPixelFormat `{ return GL_ALPHA; `}
1200 fun gl_RGB: GLPixelFormat `{ return GL_RGB; `}
1201 fun gl_RGBA
: GLPixelFormat `{ return GL_RGBA; `}
1203 # Set of buffers as a bitwise OR mask
1204 extern class GLBuffer `{ GLbitfield `}
1205 # Bitwise OR with `other`
1206 fun |(other
: GLBuffer): GLBuffer `{ return self | other; `}
1209 fun gl_DEPTH_BUFFER_BIT: GLBuffer `{ return GL_DEPTH_BUFFER_BIT; `}
1210 fun gl_STENCIL_BUFFER_BIT
: GLBuffer `{ return GL_STENCIL_BUFFER_BIT; `}
1211 fun gl_COLOR_BUFFER_BIT: GLBuffer `{ return GL_COLOR_BUFFER_BIT; `}
1213 # Define front- and back-facing polygons, `gc_CCW` by default
1214 fun glFrontFace
(mode
: GLFrontFaceMode) `{ glFrontFace(mode); `}
1216 # Orientation of front-facing polygons
1217 extern class GLFrontFaceMode
1221 fun gl_CW: GLFrontFaceMode `{ return GL_CW; `}
1222 fun gl_CCW
: GLFrontFaceMode `{ return GL_CCW; `}
1224 # Specify whether front- or back-facing polygons can be culled, default is `back
` only
1225 fun glCullFace(mode: GLCullFaceMode) `{ glCullFace(mode); `}
1227 # Candidates for culling
1228 extern class GLCullFaceMode
1232 fun gl_FRONT
: GLCullFaceMode `{ return GL_FRONT; `}
1233 fun gl_BACK: GLCullFaceMode `{ return GL_BACK; `}
1234 fun gl_FRONT_AND_BACK
: GLCullFaceMode `{ return GL_FRONT_AND_BACK; `}
1236 # Specify mapping of depth values from normalized device coordinates to window coordinates
1238 # Default at 0.0, 1.0.
1239 fun glDepthRangef(near, far: Float) `{ glDepthRangef(near, far); `}
1241 # Enable or disable writing into the depth buffer
1242 fun glDepthMask
(value
: Bool) `{ glDepthMask(value); `}
1244 # Specify the value used for depth buffer comparisons
1246 # Default value is `gl_LESS
`
1247 fun glDepthFunc(func: GLDepthFunc) `{ glDepthFunc(func); `}
1249 # Set the pixel arithmetic for the blending operations
1252 # * `src_factor`: `gl_ONE`
1253 # * `dst_factor`: `gl_ZERO`
1254 fun glBlendFunc
(src_factor
, dst_factor
: GLBlendFactor) `{
1255 glBlendFunc(src_factor, dst_factor);
1258 # Set the scale and units used to calculate depth values
1259 fun glPolygonOffset
(factor
, units
: Float) `{ glPolygonOffset(factor, units); `}
1261 # Specify the width of rasterized lines
1262 fun glLineWidth(width: Float) `{ glLineWidth(width); `}
1264 # Get the value of the parameter `pname` at `offset`
1265 fun glGetBooleanv
(pname
: GLGetParameterName, offset
: Int): Bool `{
1267 glGetBooleanv(pname, v);
1271 # Get the value of the parameter `pname` at `offset`
1272 fun glGetFloatv
(pname
: GLGetParameterName, offset
: Int): Float `{
1274 glGetFloatv(pname, v);
1278 # Get the value of the parameter `pname` at `offset`
1279 fun glGetIntegerv
(pname
: GLGetParameterName, offset
: Int): Int `{
1281 glGetIntegerv(pname, v);
1285 fun gl_COLOR_CLEAR_VALUE
: GLGetParameterName `{ return GL_COLOR_CLEAR_VALUE; `}
1287 fun gl_MAX_TEXTURE_SIZE: GLGetParameterName `{ return GL_MAX_TEXTURE_SIZE; `}
1288 fun gl_MAX_VIEWPORT_DIMS
: GLGetParameterName `{ return GL_MAX_VIEWPORT_DIMS; `}
1289 fun gl_MAX_VERTEX_ATTRIBS: GLGetParameterName `{ return GL_MAX_VERTEX_ATTRIBS; `}
1290 fun gl_MAX_VERTEX_UNIFORM_VECTORS
: GLGetParameterName `{ return GL_MAX_VERTEX_UNIFORM_VECTORS; `}
1291 fun gl_MAX_VARYING_VECTORS: GLGetParameterName `{ return GL_MAX_VARYING_VECTORS; `}
1292 fun gl_MAX_COMBINED_TEXTURE_IMAGE_UNITS
: GLGetParameterName `{ return GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS; `}
1293 fun gl_MAX_VERTEX_TEXTURE_IMAGE_UNITS: GLGetParameterName `{ return GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS; `}
1294 fun gl_MAX_TEXTURE_IMAGE_UNITS
: GLGetParameterName `{ return GL_MAX_TEXTURE_IMAGE_UNITS; `}
1295 fun gl_MAX_FRAGMENT_UNIFORM_VECTORS: GLGetParameterName `{ return GL_MAX_FRAGMENT_UNIFORM_VECTORS; `}