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
40 #include <GLES2/gl2.h>
43 # OpenGL ES program to which we attach shaders
44 extern class GLProgram `{GLuint`}
45 # Create a new program
47 # The newly created instance should be checked using `is_ok
`.
48 new `{ return glCreateProgram(); `}
50 # Is this a valid program?
51 fun is_ok
: Bool `{ return glIsProgram(recv); `}
53 # Attach a `shader
` to this program
54 fun attach_shader(shader: GLShader) `{ glAttachShader(recv, shader); `}
56 # Set the location for the attribute by `name`
57 fun bind_attrib_location
(index
: Int, name
: String) import String.to_cstring
`{
58 GLchar *c_name = String_to_cstring(name);
59 glBindAttribLocation(recv, index, c_name);
62 # Get the location of the attribute by `name`
64 # Returns `-1` if there is no active attribute named `name`.
65 fun attrib_location
(name
: String): Int import String.to_cstring
`{
66 GLchar *c_name = String_to_cstring(name);
67 return glGetAttribLocation(recv, c_name);
70 # Get the location of the uniform by `name`
72 # Returns `-1` if there is no active uniform named `name`.
73 fun uniform_location
(name
: String): Int import String.to_cstring
`{
74 GLchar *c_name = String_to_cstring(name);
75 return glGetUniformLocation(recv, c_name);
78 # Query information on this program
79 fun query
(pname
: Int): Int `{
81 glGetProgramiv(recv, pname, &val);
85 # Try to link this program
87 # Check result using `in_linked` and `info_log`.
88 fun link
`{ glLinkProgram(recv); `}
90 # Is this program linked?
91 fun is_linked: Bool do return query(0x8B82) != 0
93 # Use this program for the following operations
94 fun use `{ glUseProgram(recv); `}
97 fun delete
`{ glDeleteProgram(recv); `}
99 # Has this program been deleted?
100 fun is_deleted: Bool do return query(0x8B80) != 0
102 # Validate whether this program can be executed in the current OpenGL state
104 # Check results using `is_validated
` and `info_log
`.
105 fun validate `{ glValidateProgram(recv); `}
107 # Boolean result of `validate`, must be called after `validate`
108 fun is_validated
: Bool do return query
(0x8B83) != 0
110 # Retrieve the information log of this program
112 # Useful with `link` and `validate`
113 fun info_log
: String import NativeString.to_s
`{
115 glGetProgramiv(recv, GL_INFO_LOG_LENGTH, &size);
116 GLchar *msg = malloc(size);
117 glGetProgramInfoLog(recv, size, NULL, msg);
118 return NativeString_to_s(msg);
121 # Number of active uniform in this program
123 # This should be the number of uniforms declared in all shader, except
124 # unused uniforms which may have been optimized out.
125 fun n_active_uniforms
: Int do return query
(0x8B86)
127 # Length of the longest uniform name in this program, including `\n`
128 fun active_uniform_max_length
: Int do return query
(0x8B87)
130 # Number of active attributes in this program
132 # This should be the number of uniforms declared in all shader, except
133 # unused uniforms which may have been optimized out.
134 fun n_active_attributes
: Int do return query
(0x8B89)
136 # Length of the longest uniform name in this program, including `\n`
137 fun active_attribute_max_length
: Int do return query
(0x8B8A)
139 # Number of shaders attached to this program
140 fun n_attached_shaders
: Int do return query
(0x8B85)
142 # Name of the active attribute at `index`
143 fun active_attrib_name
(index
: Int): String
145 var max_size
= active_attribute_max_length
146 return active_attrib_name_native
(index
, max_size
).to_s
148 private fun active_attrib_name_native
(index
, max_size
: Int): NativeString `{
149 // We get more values than we need, for compatibility. At least the
150 // NVidia driver tries to fill them even if NULL.
152 char *name = malloc(max_size);
155 glGetActiveAttrib(recv, index, max_size, NULL, &size, &type, name);
159 # Size of the active attribute at `index`
160 fun active_attrib_size
(index
: Int): Int `{
163 glGetActiveAttrib(recv, index, 0, NULL, &size, &type, NULL);
167 # Type of the active attribute at `index`
169 # May only be float related data types (single float, vectors and matrix).
170 fun active_attrib_type
(index
: Int): GLFloatDataType `{
173 glGetActiveAttrib(recv, index, 0, NULL, &size, &type, NULL);
177 # Name of the active uniform at `index`
178 fun active_uniform_name
(index
: Int): String
180 var max_size
= active_attribute_max_length
181 return active_uniform_name_native
(index
, max_size
).to_s
183 private fun active_uniform_name_native
(index
, max_size
: Int): NativeString `{
184 char *name = malloc(max_size);
187 glGetActiveUniform(recv, index, max_size, NULL, &size, &type, name);
191 # Size of the active uniform at `index`
192 fun active_uniform_size
(index
: Int): Int `{
195 glGetActiveUniform(recv, index, 0, NULL, &size, &type, NULL);
199 # Type of the active uniform at `index`
201 # May be any data type supported by OpenGL ES 2.0 shaders.
202 fun active_uniform_type
(index
: Int): GLDataType `{
205 glGetActiveUniform(recv, index, 0, NULL, &size, &type, NULL);
210 # Abstract OpenGL ES shader object, implemented by `GLFragmentShader` and `GLVertexShader`
211 extern class GLShader `{GLuint`}
212 # Set the source of the shader
213 fun source=(code: NativeString) `{
214 glShaderSource
(recv
, 1, (GLchar const
**)&code
, NULL);
217 # Source of the shader, if available
219 # Returns `null` if the source is not available, usually when the shader
220 # was created from a binary file.
221 fun source: nullable String
223 var size = query(0x8B88)
224 if size == 0 then return null
225 return source_native(size).to_s
228 private fun source_native(size: Int): NativeString `{
229 GLchar *code
= malloc
(size
);
230 glGetShaderSource
(recv
, size
, NULL, code
);
234 # Query information on this shader
235 protected fun query(pname: Int): Int `{
237 glGetShaderiv
(recv
, pname
, &val
);
241 # Try to compile `source
` into a binary GPU program
243 # Check the result using `is_compiled
` and `info_log
`
244 fun compile `{ glCompileShader(recv); `}
246 # Has this shader been compiled?
247 fun is_compiled
: Bool do return query
(0x8B81) != 0
250 fun delete
`{ glDeleteShader(recv); `}
252 # Has this shader been deleted?
253 fun is_deleted: Bool do return query(0x8B80) != 0
255 # Is this a valid shader?
256 fun is_ok: Bool `{ return glIsShader(recv); `}
258 # Retrieve the information log of this shader
260 # Useful with `link` and `validate`
261 fun info_log
: String import NativeString.to_s
`{
263 glGetShaderiv(recv, GL_INFO_LOG_LENGTH, &size);
264 GLchar *msg = malloc(size);
265 glGetShaderInfoLog(recv, size, NULL, msg);
266 return NativeString_to_s(msg);
270 # An OpenGL ES 2.0 fragment shader
271 extern class GLFragmentShader
274 # Create a new fragment shader
276 # The newly created instance should be checked using `is_ok`.
277 new `{ return glCreateShader(GL_FRAGMENT_SHADER); `}
280 # An OpenGL ES 2.0 vertex shader
281 extern class GLVertexShader
284 # Create a new fragment shader
286 # The newly created instance should be checked using `is_ok
`.
287 new `{ return glCreateShader(GL_VERTEX_SHADER); `}
290 # An array of `Float` associated to a program variable
294 # Number of data per vertex
297 protected var glfloat_array
: GLfloatArray
299 init(index
, count
: Int, array
: Array[Float])
303 self.glfloat_array
= new GLfloatArray(array
)
306 fun attrib_pointer
do attrib_pointer_intern
(index
, count
, glfloat_array
)
307 private fun attrib_pointer_intern
(index
, count
: Int, array
: GLfloatArray) `{
308 glVertexAttribPointer(index, count, GL_FLOAT, GL_FALSE, 0, array);
311 fun enable
do enable_intern
(index
)
312 private fun enable_intern
(index
: Int) `{ glEnableVertexAttribArray(index); `}
314 fun draw_arrays_triangles do draw_arrays_triangles_intern(index, count)
315 private fun draw_arrays_triangles_intern(index, count: Int) `{
316 glDrawArrays
(GL_TRIANGLES, index
, count
);
320 # Low level array of `Float`
321 extern class GLfloatArray `{GLfloat *`}
322 new (array
: Array[Float]) import Array[Float].length
, Array[Float].[] `{
324 int len = Array_of_Float_length(array);
325 GLfloat *vertex_array = malloc(sizeof(GLfloat)*len);
326 for (i = 0; i < len; i ++) vertex_array[i] = Array_of_Float__index(array, i);
331 # General type for OpenGL enumerations
332 extern class GLEnum `{ GLenum `}
334 redef fun hash `{ return recv; `}
336 redef fun ==(o
) do return o
!= null and is_same_type
(o
) and o
.hash
== self.hash
339 # An OpenGL ES 2.0 error code
344 fun is_ok
: Bool do return is_no_error
346 # Is this not an error?
347 fun is_no_error
: Bool `{ return recv == GL_NO_ERROR; `}
349 fun is_invalid_enum: Bool `{ return recv == GL_INVALID_ENUM; `}
350 fun is_invalid_value
: Bool `{ return recv == GL_INVALID_VALUE; `}
351 fun is_invalid_operation: Bool `{ return recv == GL_INVALID_OPERATION; `}
352 fun is_invalid_framebuffer_operation
: Bool `{ return recv == GL_INVALID_FRAMEBUFFER_OPERATION; `}
353 fun is_out_of_memory: Bool `{ return recv == GL_OUT_OF_MEMORY; `}
357 if is_no_error
then return "No error"
358 if is_invalid_enum
then return "Invalid enum"
359 if is_invalid_value
then return "Invalid value"
360 if is_invalid_operation
then return "Invalid operation"
361 if is_invalid_framebuffer_operation
then return "invalid framebuffer operation"
362 if is_out_of_memory
then return "Out of memory"
363 return "Truely unknown error"
367 protected fun assert_no_gl_error
370 if not error
.is_ok
then
371 print
"GL error: {error}"
376 # Texture minifying function
378 # Used by: `GLES::tex_parameter_min_filter`
379 extern class GLTextureMinFilter
382 new nearest
`{ return GL_NEAREST; `}
383 new linear `{ return GL_LINEAR; `}
386 # Texture magnification function
388 # Used by: `GLES::tex_parameter_mag_filter`
389 extern class GLTextureMagFilter
392 new nearest
`{ return GL_NEAREST; `}
393 new linear `{ return GL_LINEAR; `}
394 new nearest_mipmap_nearest
`{ return GL_NEAREST_MIPMAP_NEAREST; `}
395 new linear_mipmap_nearest `{ return GL_LINEAR_MIPMAP_NEAREST; `}
396 new nearest_mipmap_linear
`{ return GL_NEAREST_MIPMAP_LINEAR; `}
397 new linear_mipmap_linear `{ return GL_LINEAR_MIPMAP_LINEAR; `}
400 # Wrap parameter of a texture
402 # Used by: `tex_parameter_wrap_*`
403 extern class GLTextureWrap
406 new clamp_to_edge
`{ return GL_CLAMP_TO_EDGE; `}
407 new mirrored_repeat `{ return GL_MIRRORED_REPEAT; `}
408 new repeat
`{ return GL_REPEAT; `}
413 # Used by: `tex_parameter_
*`
414 extern class GLTextureTarget
417 new flat `{ return GL_TEXTURE_2D; `}
418 new cube_map
`{ return GL_TEXTURE_CUBE_MAP; `}
421 # A server-side capability
426 # Internal OpenGL integer for this capability
429 # Enable this server-side capability
430 fun enable do enable_native(val)
431 private fun enable_native(cap: Int) `{ glEnable(cap); `}
433 # Disable this server-side capability
434 fun disable
do disable_native
(val
)
435 private fun disable_native
(cap
: Int) `{ glDisable(cap); `}
437 redef fun hash do return val
438 redef fun ==(o) do return o != null and is_same_type(o) and o.hash == self.hash
441 private var gles = new GLES is lazy
444 # Entry points to OpenGL ES 2.0 services
445 fun gl: GLES do return sys.gles
447 # OpenGL ES 2.0 services
450 # Clear the color buffer to `red
`, `green
`, `blue
` and `alpha
`
451 fun clear_color(red, green, blue, alpha: Float) `{
452 glClearColor
(red
, green
, blue
, alpha
);
456 fun viewport(x, y, width, height: Int) `{ glViewport(x, y, width, height); `}
458 # Specify mapping of depth values from normalized device coordinates to window coordinates
460 # Default at `gl_depth_range(0.0, 1.0)`
461 fun depth_range
(near
, far
: Float) `{ glDepthRangef(near, far); `}
463 # Define front- and back-facing polygons
465 # Front-facing polygons are clockwise if `value
`, counter-clockwise otherwise.
466 fun front_face=(value: Bool) `{ glFrontFace(value? GL_CW: GL_CCW); `}
468 # Specify whether front- or back-facing polygons can be culled, default is `back` only
470 # One or both of `front` or `back` must be `true`. If you want to deactivate culling
471 # use `(new GLCap.cull_face).disable`.
473 # Require: `front or back`
474 fun cull_face
(front
, back
: Bool)
476 assert not (front
or back
)
477 cull_face_native
(front
, back
)
480 private fun cull_face_native
(front
, back
: Bool) `{
481 glCullFace(front? back? GL_FRONT_AND_BACK: GL_BACK: GL_FRONT);
485 fun clear
(buffer
: GLBuffer) `{ glClear(buffer); `}
487 # Last error from OpenGL ES 2.0
488 fun error: GLError `{ return glGetError(); `}
490 # Query the boolean value at `key`
491 private fun get_bool
(key
: Int): Bool `{
493 glGetBooleanv(key, &val);
494 return val == GL_TRUE;
497 # Query the floating point value at `key`
498 private fun get_float
(key
: Int): Float `{
500 glGetFloatv(key, &val);
504 # Query the integer value at `key`
505 private fun get_int
(key
: Int): Int `{
507 glGetIntegerv(key, &val);
511 # Does this driver support shader compilation?
513 # Should always return `true` in OpenGL ES 2.0 and 3.0.
514 fun shader_compiler
: Bool do return get_bool
(0x8DFA)
516 # Enable or disable writing into the depth buffer
517 fun depth_mask
(value
: Bool) `{ glDepthMask(value); `}
519 # Set the scale and units used to calculate depth values
520 fun polygon_offset(factor, units: Float) `{ glPolygonOffset(factor, units); `}
522 # Specify the width of rasterized lines
523 fun line_width
(width
: Float) `{ glLineWidth(width); `}
525 # Set the pixel arithmetic for the blending operations
527 # Defaultvalues before assignation:
528 # * `src_factor
`: `GLBlendFactor::one
`
529 # * `dst_factor
`: `GLBlendFactor::zero
`
530 fun blend_func(src_factor, dst_factor: GLBlendFactor) `{
531 glBlendFunc
(src_factor
, dst_factor
);
534 # Specify the value used for depth buffer comparisons
536 # Default value is `GLDepthFunc::less
`
538 # Foreign: glDepthFunc
539 fun depth_func(func: GLDepthFunc) `{ glDepthFunc(func); `}
541 # Copy a block of pixels from the framebuffer of `fomat` and `typ` at `data`
543 # Foreign: glReadPixel
544 fun read_pixels
(x
, y
, width
, height
: Int, format
: GLPixelFormat, typ
: GLPixelType, data
: Pointer) `{
545 glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
548 # Set the texture minifying function
550 # Foreign: glTexParameter with GL_TEXTURE_MIN_FILTER
551 fun tex_parameter_min_filter
(target
: GLTextureTarget, value
: GLTextureMinFilter) `{
552 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, value);
555 # Set the texture magnification function
557 # Foreign: glTexParameter with GL_TEXTURE_MAG_FILTER
558 fun tex_parameter_mag_filter
(target
: GLTextureTarget, value
: GLTextureMagFilter) `{
559 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, value);
562 # Set the texture wrap parameter for coordinates _s_
564 # Foreign: glTexParameter with GL_TEXTURE_WRAP_S
565 fun tex_parameter_wrap_s
(target
: GLTextureTarget, value
: GLTextureWrap) `{
566 glTexParameteri(target, GL_TEXTURE_WRAP_S, value);
569 # Set the texture wrap parameter for coordinates _t_
571 # Foreign: glTexParameter with GL_TEXTURE_WRAP_T
572 fun tex_parameter_wrap_t
(target
: GLTextureTarget, value
: GLTextureWrap) `{
573 glTexParameteri(target, GL_TEXTURE_WRAP_T, value);
576 # Render primitives from array data
578 # Foreign: glDrawArrays
579 fun draw_arrays
(mode
: GLDrawMode, from
, count
: Int) `{ glDrawArrays(mode, from, count); `}
581 # OpenGL server-side capabilities
582 var capabilities = new GLCapabilities is lazy
585 # Entry point to OpenGL server-side capabilities
588 # GL capability: blend the computed fragment color values
591 fun blend: GLCap is lazy do return new GLCap(0x0BE2)
593 # GL capability: cull polygons based of their winding in window coordinates
595 # Foreign: GL_CULL_FACE
596 fun cull_face: GLCap is lazy do return new GLCap(0x0B44)
598 # GL capability: do depth comparisons and update the depth buffer
600 # Foreign: GL_DEPTH_TEST
601 fun depth_test: GLCap is lazy do return new GLCap(0x0B71)
603 # GL capability: dither color components or indices before they are written to the color buffer
606 fun dither: GLCap is lazy do return new GLCap(0x0BE2)
608 # GL capability: add an offset to depth values of a polygon fragment before depth test
610 # Foreign: GL_POLYGON_OFFSET_FILL
611 fun polygon_offset_fill: GLCap is lazy do return new GLCap(0x8037)
613 # GL capability: compute a temporary coverage value where each bit is determined by the alpha value at the corresponding location
615 # Foreign: GL_SAMPLE_ALPHA_TO_COVERAGE
616 fun sample_alpha_to_coverage: GLCap is lazy do return new GLCap(0x809E)
618 # GL capability: AND the fragment coverage with the temporary coverage value
620 # Foreign: GL_SAMPLE_COVERAGE
621 fun sample_coverage: GLCap is lazy do return new GLCap(0x80A0)
623 # GL capability: discard fragments that are outside the scissor rectangle
625 # Foreign: GL_SCISSOR_TEST
626 fun scissor_test: GLCap is lazy do return new GLCap(0x0C11)
628 # GL capability: do stencil testing and update the stencil buffer
630 # Foreign: GL_STENCIL_TEST
631 fun stencil_test: GLCap is lazy do return new GLCap(0x0B90)
634 # Float related data types of OpenGL ES 2.0 shaders
636 # Only data types supported by shader attributes, as seen with
637 # `GLProgram::active_attrib_type
`.
638 extern class GLFloatDataType
641 fun is_float: Bool `{ return recv == GL_FLOAT; `}
642 fun is_float_vec2
: Bool `{ return recv == GL_FLOAT_VEC2; `}
643 fun is_float_vec3: Bool `{ return recv == GL_FLOAT_VEC3; `}
644 fun is_float_vec4
: Bool `{ return recv == GL_FLOAT_VEC4; `}
645 fun is_float_mat2: Bool `{ return recv == GL_FLOAT_MAT2; `}
646 fun is_float_mat3
: Bool `{ return recv == GL_FLOAT_MAT3; `}
647 fun is_float_mat4: Bool `{ return recv == GL_FLOAT_MAT4; `}
649 # Instances of `GLFloatDataType` can be equal to instances of `GLDataType`
652 return o
!= null and o
isa GLFloatDataType and o
.hash
== self.hash
656 # All data types of OpenGL ES 2.0 shaders
658 # These types can be used by shader uniforms, as seen with
659 # `GLProgram::active_uniform_type`.
660 extern class GLDataType
661 super GLFloatDataType
663 fun is_int
: Bool `{ return recv == GL_INT; `}
664 fun is_int_vec2: Bool `{ return recv == GL_INT_VEC2; `}
665 fun is_int_vec3
: Bool `{ return recv == GL_INT_VEC3; `}
666 fun is_int_vec4: Bool `{ return recv == GL_INT_VEC4; `}
667 fun is_bool
: Bool `{ return recv == GL_BOOL; `}
668 fun is_bool_vec2: Bool `{ return recv == GL_BOOL_VEC2; `}
669 fun is_bool_vec3
: Bool `{ return recv == GL_BOOL_VEC3; `}
670 fun is_bool_vec4: Bool `{ return recv == GL_BOOL_VEC4; `}
671 fun is_sampler_2d
: Bool `{ return recv == GL_SAMPLER_2D; `}
672 fun is_sampler_cube: Bool `{ return recv == GL_SAMPLER_CUBE; `}
675 # Kind of primitives to render with `GLES::draw_arrays`
676 extern class GLDrawMode
679 new points
`{ return GL_POINTS; `}
680 new line_strip `{ return GL_LINE_STRIP; `}
681 new line_loop
`{ return GL_LINE_LOOP; `}
682 new lines `{ return GL_LINES; `}
683 new triangle_strip
`{ return GL_TRIANGLE_STRIP; `}
684 new triangle_fan `{ return GL_TRIANGLE_FAN; `}
685 new triangles
`{ return GL_TRIANGLES; `}
688 # Pixel arithmetic for blending operations
690 # Used by `GLES::blend_func
`
691 extern class GLBlendFactor
694 new zero `{ return GL_ZERO; `}
695 new one
`{ return GL_ONE; `}
696 new src_color `{ return GL_SRC_COLOR; `}
697 new one_minus_src_color
`{ return GL_ONE_MINUS_SRC_COLOR; `}
698 new dst_color `{ return GL_DST_COLOR; `}
699 new one_minus_dst_color
`{ return GL_ONE_MINUS_DST_COLOR; `}
700 new src_alpha `{ return GL_SRC_ALPHA; `}
701 new one_minus_src_alpha
`{ return GL_ONE_MINUS_SRC_ALPHA; `}
702 new dst_alpha `{ return GL_DST_ALPHA; `}
703 new one_minus_dst_alpha
`{ return GL_ONE_MINUS_DST_ALPHA; `}
704 new constant_color `{ return GL_CONSTANT_COLOR; `}
705 new one_minus_constant_color
`{ return GL_ONE_MINUS_CONSTANT_COLOR; `}
706 new constant_alpha `{ return GL_CONSTANT_ALPHA; `}
707 new one_minus_constant_alpha
`{ return GL_ONE_MINUS_CONSTANT_ALPHA; `}
709 # Used for destination only
710 new src_alpha_saturate `{ return GL_SRC_ALPHA_SATURATE; `}
713 # Condition under which a pixel will be drawn
715 # Used by `GLES::depth_func`
716 extern class GLDepthFunc
719 new never
`{ return GL_NEVER; `}
720 new less `{ return GL_LESS; `}
721 new equal
`{ return GL_EQUAL; `}
722 new lequal `{ return GL_LEQUAL; `}
723 new greater
`{ return GL_GREATER; `}
724 new not_equal `{ return GL_NOTEQUAL; `}
725 new gequal
`{ return GL_GEQUAL; `}
726 new always `{ return GL_ALWAYS; `}
729 # Format of pixel data
731 # Used by `GLES::read_pixels`
732 extern class GLPixelFormat
735 new alpha
`{ return GL_ALPHA; `}
736 new rgb `{ return GL_RGB; `}
737 new rgba
`{ return GL_RGBA; `}
740 # Data type of pixel data
742 # Used by `GLES::read_pixels
`
743 extern class GLPixelType
746 new unsigned_byte `{ return GL_UNSIGNED_BYTE; `}
747 new unsigned_short_5_6_5
`{ return GL_UNSIGNED_SHORT_5_6_5; `}
748 new unsigned_short_4_4_4_4 `{ return GL_UNSIGNED_SHORT_4_4_4_4; `}
749 new unsigned_short_5_5_5_1
`{ return GL_UNSIGNED_SHORT_5_5_5_1; `}
752 # Set of buffers as a bitwise OR mask, used by `GLES::clear
`
755 # var buffers = (new GLBuffer).color.depth
758 extern class GLBuffer `{ GLbitfield `}
759 # Get an empty set of buffers
762 # Add the color buffer to the returned buffer set
763 fun color: GLBuffer `{ return recv | GL_COLOR_BUFFER_BIT; `}
765 # Add the depth buffer to the returned buffer set
766 fun depth
: GLBuffer `{ return recv | GL_DEPTH_BUFFER_BIT; `}
768 # Add the stencil buffer to the returned buffer set
769 fun stencil: GLBuffer `{ return recv | GL_STENCIL_BUFFER_BIT; `}