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
42 #include <GLES2/gl2.h>
45 # OpenGL ES program to which we attach shaders
46 extern class GLProgram `{GLuint`}
47 # Create a new program
49 # The newly created instance should be checked using `is_ok
`.
50 new `{ return glCreateProgram(); `}
52 # Is this a valid program?
53 fun is_ok
: Bool `{ return glIsProgram(self); `}
55 # Attach a `shader
` to this program
56 fun attach_shader(shader: GLShader) `{ glAttachShader(self, shader); `}
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 # Query information on this program
81 fun query
(pname
: Int): Int `{
83 glGetProgramiv(self, pname, &val);
87 # Try to link this program
89 # Check result using `in_linked` and `info_log`.
90 fun link
`{ glLinkProgram(self); `}
92 # Is this program linked?
93 fun is_linked: Bool do return query(0x8B82) != 0
95 # Use this program for the following operations
96 fun use `{ glUseProgram(self); `}
99 fun delete
`{ glDeleteProgram(self); `}
101 # Has this program been deleted?
102 fun is_deleted: Bool do return query(0x8B80) != 0
104 # Validate whether this program can be executed in the current OpenGL state
106 # Check results using `is_validated
` and `info_log
`.
107 fun validate `{ glValidateProgram(self); `}
109 # Boolean result of `validate`, must be called after `validate`
110 fun is_validated
: Bool do return query
(0x8B83) != 0
112 # Retrieve the information log of this program
114 # Useful with `link` and `validate`
115 fun info_log
: String import NativeString.to_s
`{
117 glGetProgramiv(self, GL_INFO_LOG_LENGTH, &size);
118 GLchar *msg = malloc(size);
119 glGetProgramInfoLog(self, size, NULL, msg);
120 return NativeString_to_s(msg);
123 # Number of active uniform in this program
125 # This should be the number of uniforms declared in all shader, except
126 # unused uniforms which may have been optimized out.
127 fun n_active_uniforms
: Int do return query
(0x8B86)
129 # Length of the longest uniform name in this program, including `\n`
130 fun active_uniform_max_length
: Int do return query
(0x8B87)
132 # Number of active attributes in this program
134 # This should be the number of uniforms declared in all shader, except
135 # unused uniforms which may have been optimized out.
136 fun n_active_attributes
: Int do return query
(0x8B89)
138 # Length of the longest uniform name in this program, including `\n`
139 fun active_attribute_max_length
: Int do return query
(0x8B8A)
141 # Number of shaders attached to this program
142 fun n_attached_shaders
: Int do return query
(0x8B85)
144 # Name of the active attribute at `index`
145 fun active_attrib_name
(index
: Int): String
147 var max_size
= active_attribute_max_length
148 return active_attrib_name_native
(index
, max_size
).to_s
150 private fun active_attrib_name_native
(index
, max_size
: Int): NativeString `{
151 // We get more values than we need, for compatibility. At least the
152 // NVidia driver tries to fill them even if NULL.
154 char *name = malloc(max_size);
157 glGetActiveAttrib(self, index, max_size, NULL, &size, &type, name);
161 # Size of the active attribute at `index`
162 fun active_attrib_size
(index
: Int): Int `{
165 glGetActiveAttrib(self, index, 0, NULL, &size, &type, NULL);
169 # Type of the active attribute at `index`
171 # May only be float related data types (single float, vectors and matrix).
172 fun active_attrib_type
(index
: Int): GLFloatDataType `{
175 glGetActiveAttrib(self, index, 0, NULL, &size, &type, NULL);
179 # Name of the active uniform at `index`
180 fun active_uniform_name
(index
: Int): String
182 var max_size
= active_attribute_max_length
183 return active_uniform_name_native
(index
, max_size
).to_s
185 private fun active_uniform_name_native
(index
, max_size
: Int): NativeString `{
186 char *name = malloc(max_size);
189 glGetActiveUniform(self, index, max_size, NULL, &size, &type, name);
193 # Size of the active uniform at `index`
194 fun active_uniform_size
(index
: Int): Int `{
197 glGetActiveUniform(self, index, 0, NULL, &size, &type, NULL);
201 # Type of the active uniform at `index`
203 # May be any data type supported by OpenGL ES 2.0 shaders.
204 fun active_uniform_type
(index
: Int): GLDataType `{
207 glGetActiveUniform(self, index, 0, NULL, &size, &type, NULL);
212 # Abstract OpenGL ES shader object, implemented by `GLFragmentShader` and `GLVertexShader`
213 extern class GLShader `{GLuint`}
214 # Set the source of the shader
215 fun source=(code: NativeString) `{
216 glShaderSource
(self, 1, (GLchar const
**)&code
, NULL);
219 # Source of the shader, if available
221 # Returns `null` if the source is not available, usually when the shader
222 # was created from a binary file.
223 fun source: nullable String
225 var size = query(0x8B88)
226 if size == 0 then return null
227 return source_native(size).to_s
230 private fun source_native(size: Int): NativeString `{
231 GLchar *code
= malloc
(size
);
232 glGetShaderSource
(self, size
, NULL, code
);
236 # Query information on this shader
237 protected fun query(pname: Int): Int `{
239 glGetShaderiv
(self, pname
, &val
);
243 # Try to compile `source
` into a binary GPU program
245 # Check the result using `is_compiled
` and `info_log
`
246 fun compile `{ glCompileShader(self); `}
248 # Has this shader been compiled?
249 fun is_compiled
: Bool do return query
(0x8B81) != 0
252 fun delete
`{ glDeleteShader(self); `}
254 # Has this shader been deleted?
255 fun is_deleted: Bool do return query(0x8B80) != 0
257 # Is this a valid shader?
258 fun is_ok: Bool `{ return glIsShader(self); `}
260 # Retrieve the information log of this shader
262 # Useful with `link` and `validate`
263 fun info_log
: String import NativeString.to_s
`{
265 glGetShaderiv(self, GL_INFO_LOG_LENGTH, &size);
266 GLchar *msg = malloc(size);
267 glGetShaderInfoLog(self, size, NULL, msg);
268 return NativeString_to_s(msg);
272 # An OpenGL ES 2.0 fragment shader
273 extern class GLFragmentShader
276 # Create a new fragment shader
278 # The newly created instance should be checked using `is_ok`.
279 new `{ return glCreateShader(GL_FRAGMENT_SHADER); `}
282 # An OpenGL ES 2.0 vertex shader
283 extern class GLVertexShader
286 # Create a new fragment shader
288 # The newly created instance should be checked using `is_ok
`.
289 new `{ return glCreateShader(GL_VERTEX_SHADER); `}
292 # An array of `Float` associated to a program variable
296 # Number of data per vertex
299 protected var glfloat_array
: GLfloatArray
301 init(index
, count
: Int, array
: Array[Float])
305 self.glfloat_array
= new GLfloatArray(array
)
308 fun attrib_pointer
do attrib_pointer_intern
(index
, count
, glfloat_array
)
309 private fun attrib_pointer_intern
(index
, count
: Int, array
: GLfloatArray) `{
310 glVertexAttribPointer(index, count, GL_FLOAT, GL_FALSE, 0, array);
313 fun enable
do enable_intern
(index
)
314 private fun enable_intern
(index
: Int) `{ glEnableVertexAttribArray(index); `}
316 fun draw_arrays_triangles do draw_arrays_triangles_intern(index, count)
317 private fun draw_arrays_triangles_intern(index, count: Int) `{
318 glDrawArrays
(GL_TRIANGLES, index
, count
);
322 # Low level array of `Float`
323 extern class GLfloatArray `{GLfloat *`}
324 new (array
: Array[Float]) import Array[Float].length
, Array[Float].[] `{
326 int len = Array_of_Float_length(array);
327 GLfloat *vertex_array = malloc(sizeof(GLfloat)*len);
328 for (i = 0; i < len; i ++) vertex_array[i] = Array_of_Float__index(array, i);
333 # General type for OpenGL enumerations
334 extern class GLEnum `{ GLenum `}
336 redef fun hash `{ return self; `}
338 redef fun ==(o
) do return o
!= null and is_same_type
(o
) and o
.hash
== self.hash
341 # An OpenGL ES 2.0 error code
346 fun is_ok
: Bool do return is_no_error
348 # Is this not an error?
349 fun is_no_error
: Bool `{ return self == GL_NO_ERROR; `}
351 fun is_invalid_enum: Bool `{ return self == GL_INVALID_ENUM; `}
352 fun is_invalid_value
: Bool `{ return self == GL_INVALID_VALUE; `}
353 fun is_invalid_operation: Bool `{ return self == GL_INVALID_OPERATION; `}
354 fun is_invalid_framebuffer_operation
: Bool `{ return self == GL_INVALID_FRAMEBUFFER_OPERATION; `}
355 fun is_out_of_memory: Bool `{ return self == GL_OUT_OF_MEMORY; `}
359 if is_no_error
then return "No error"
360 if is_invalid_enum
then return "Invalid enum"
361 if is_invalid_value
then return "Invalid value"
362 if is_invalid_operation
then return "Invalid operation"
363 if is_invalid_framebuffer_operation
then return "invalid framebuffer operation"
364 if is_out_of_memory
then return "Out of memory"
365 return "Truely unknown error"
369 fun assert_no_gl_error
372 if not error
.is_ok
then
373 print
"GL error: {error}"
378 # Texture minifying function
380 # Used by: `GLES::tex_parameter_min_filter`
381 extern class GLTextureMinFilter
384 new nearest
`{ return GL_NEAREST; `}
385 new linear `{ return GL_LINEAR; `}
388 # Texture magnification function
390 # Used by: `GLES::tex_parameter_mag_filter`
391 extern class GLTextureMagFilter
394 new nearest
`{ return GL_NEAREST; `}
395 new linear `{ return GL_LINEAR; `}
396 new nearest_mipmap_nearest
`{ return GL_NEAREST_MIPMAP_NEAREST; `}
397 new linear_mipmap_nearest `{ return GL_LINEAR_MIPMAP_NEAREST; `}
398 new nearest_mipmap_linear
`{ return GL_NEAREST_MIPMAP_LINEAR; `}
399 new linear_mipmap_linear `{ return GL_LINEAR_MIPMAP_LINEAR; `}
402 # Wrap parameter of a texture
404 # Used by: `tex_parameter_wrap_*`
405 extern class GLTextureWrap
408 new clamp_to_edge
`{ return GL_CLAMP_TO_EDGE; `}
409 new mirrored_repeat `{ return GL_MIRRORED_REPEAT; `}
410 new repeat
`{ return GL_REPEAT; `}
415 # Used by: `tex_parameter_
*`
416 extern class GLTextureTarget
419 new flat `{ return GL_TEXTURE_2D; `}
420 new cube_map
`{ return GL_TEXTURE_CUBE_MAP; `}
423 # A server-side capability
428 # Internal OpenGL integer for this capability
431 # Enable this server-side capability
432 fun enable do enable_native(val)
433 private fun enable_native(cap: Int) `{ glEnable(cap); `}
435 # Disable this server-side capability
436 fun disable
do disable_native
(val
)
437 private fun disable_native
(cap
: Int) `{ glDisable(cap); `}
439 redef fun hash do return val
440 redef fun ==(o) do return o != null and is_same_type(o) and o.hash == self.hash
443 private var gles = new GLES is lazy
446 # Entry points to OpenGL ES 2.0 services
447 fun gl: GLES do return sys.gles
449 # OpenGL ES 2.0 services
452 # Clear the color buffer to `red
`, `green
`, `blue
` and `alpha
`
453 fun clear_color(red, green, blue, alpha: Float) `{
454 glClearColor
(red
, green
, blue
, alpha
);
458 fun viewport(x, y, width, height: Int) `{ glViewport(x, y, width, height); `}
460 # Specify mapping of depth values from normalized device coordinates to window coordinates
462 # Default at `gl_depth_range(0.0, 1.0)`
463 fun depth_range
(near
, far
: Float) `{ glDepthRangef(near, far); `}
465 # Define front- and back-facing polygons
467 # Front-facing polygons are clockwise if `value
`, counter-clockwise otherwise.
468 fun front_face=(value: Bool) `{ glFrontFace(value? GL_CW: GL_CCW); `}
470 # Specify whether front- or back-facing polygons can be culled, default is `back` only
472 # One or both of `front` or `back` must be `true`. If you want to deactivate culling
473 # use `(new GLCap.cull_face).disable`.
475 # Require: `front or back`
476 fun cull_face
(front
, back
: Bool)
478 assert not (front
or back
)
479 cull_face_native
(front
, back
)
482 private fun cull_face_native
(front
, back
: Bool) `{
483 glCullFace(front? back? GL_FRONT_AND_BACK: GL_BACK: GL_FRONT);
487 fun clear
(buffer
: GLBuffer) `{ glClear(buffer); `}
489 # Last error from OpenGL ES 2.0
490 fun error: GLError `{ return glGetError(); `}
492 # Query the boolean value at `key`
493 private fun get_bool
(key
: Int): Bool `{
495 glGetBooleanv(key, &val);
496 return val == GL_TRUE;
499 # Query the floating point value at `key`
500 private fun get_float
(key
: Int): Float `{
502 glGetFloatv(key, &val);
506 # Query the integer value at `key`
507 private fun get_int
(key
: Int): Int `{
509 glGetIntegerv(key, &val);
513 # Does this driver support shader compilation?
515 # Should always return `true` in OpenGL ES 2.0 and 3.0.
516 fun shader_compiler
: Bool do return get_bool
(0x8DFA)
518 # Enable or disable writing into the depth buffer
519 fun depth_mask
(value
: Bool) `{ glDepthMask(value); `}
521 # Set the scale and units used to calculate depth values
522 fun polygon_offset(factor, units: Float) `{ glPolygonOffset(factor, units); `}
524 # Specify the width of rasterized lines
525 fun line_width
(width
: Float) `{ glLineWidth(width); `}
527 # Set the pixel arithmetic for the blending operations
529 # Defaultvalues before assignation:
530 # * `src_factor
`: `GLBlendFactor::one
`
531 # * `dst_factor
`: `GLBlendFactor::zero
`
532 fun blend_func(src_factor, dst_factor: GLBlendFactor) `{
533 glBlendFunc
(src_factor
, dst_factor
);
536 # Specify the value used for depth buffer comparisons
538 # Default value is `GLDepthFunc::less
`
540 # Foreign: glDepthFunc
541 fun depth_func(func: GLDepthFunc) `{ glDepthFunc(func); `}
543 # Copy a block of pixels from the framebuffer of `fomat` and `typ` at `data`
545 # Foreign: glReadPixel
546 fun read_pixels
(x
, y
, width
, height
: Int, format
: GLPixelFormat, typ
: GLPixelType, data
: Pointer) `{
547 glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
550 # Set the texture minifying function
552 # Foreign: glTexParameter with GL_TEXTURE_MIN_FILTER
553 fun tex_parameter_min_filter
(target
: GLTextureTarget, value
: GLTextureMinFilter) `{
554 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, value);
557 # Set the texture magnification function
559 # Foreign: glTexParameter with GL_TEXTURE_MAG_FILTER
560 fun tex_parameter_mag_filter
(target
: GLTextureTarget, value
: GLTextureMagFilter) `{
561 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, value);
564 # Set the texture wrap parameter for coordinates _s_
566 # Foreign: glTexParameter with GL_TEXTURE_WRAP_S
567 fun tex_parameter_wrap_s
(target
: GLTextureTarget, value
: GLTextureWrap) `{
568 glTexParameteri(target, GL_TEXTURE_WRAP_S, value);
571 # Set the texture wrap parameter for coordinates _t_
573 # Foreign: glTexParameter with GL_TEXTURE_WRAP_T
574 fun tex_parameter_wrap_t
(target
: GLTextureTarget, value
: GLTextureWrap) `{
575 glTexParameteri(target, GL_TEXTURE_WRAP_T, value);
578 # Render primitives from array data
580 # Foreign: glDrawArrays
581 fun draw_arrays
(mode
: GLDrawMode, from
, count
: Int) `{ glDrawArrays(mode, from, count); `}
583 # OpenGL server-side capabilities
584 var capabilities = new GLCapabilities is lazy
587 # Bind `framebuffer
` to a framebuffer target
589 # In OpenGL ES 2.0, `target
` must be `gl_FRAMEBUFFER
`.
590 fun glBindFramebuffer(target: GLFramebufferTarget, framebuffer: Int) `{
591 glBindFramebuffer
(target
, framebuffer
);
594 # Target of `glBindFramebuffer
`
595 extern class GLFramebufferTarget
599 # Target both reading and writing on the framebuffer with `glBindFramebuffer
`
600 fun gl_FRAMEBUFFER: GLFramebufferTarget `{ return GL_FRAMEBUFFER; `}
602 # Bind `renderbuffer` to a renderbuffer target
604 # In OpenGL ES 2.0, `target` must be `gl_RENDERBUFFER`.
605 fun glBindRenderbuffer
(target
: GLRenderbufferTarget, renderbuffer
: Int) `{
606 glBindRenderbuffer(target, renderbuffer);
609 # Target of `glBindRenderbuffer`
610 extern class GLRenderbufferTarget
614 # Target a renderbuffer with `glBindRenderbuffer`
615 fun gl_RENDERBUFFER
: GLRenderbufferTarget `{ return GL_RENDERBUFFER; `}
617 # Specify implementation specific hints
618 fun glHint(target: GLHintTarget, mode: GLHintMode) `{
619 glHint
(target
, mode
);
622 # Completeness status of a framebuffer object
623 fun glCheckFramebufferStatus(target: GLFramebufferTarget): GLFramebufferStatus `{
624 return glCheckFramebufferStatus
(target
);
627 # Return value of `glCheckFramebufferStatus
`
628 extern class GLFramebufferStatus
633 if self == gl_FRAMEBUFFER_COMPLETE then return "complete"
634 if self == gl_FRAMEBUFFER_INCOMPLETE_ATTACHMENT then return "incomplete attachment"
635 if self == gl_FRAMEBUFFER_INCOMPLETE_DIMENSIONS then return "incomplete dimension"
636 if self == gl_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT then return "incomplete missing attachment"
637 if self == gl_FRAMEBUFFER_UNSUPPORTED then return "unsupported"
642 # The framebuffer is complete
643 fun gl_FRAMEBUFFER_COMPLETE: GLFramebufferStatus `{
644 return GL_FRAMEBUFFER_COMPLETE;
647 # Not all framebuffer attachment points are framebuffer attachment complete
648 fun gl_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: GLFramebufferStatus `{
649 return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
652 # Not all attached images have the same width and height
653 fun gl_FRAMEBUFFER_INCOMPLETE_DIMENSIONS: GLFramebufferStatus `{
654 return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS;
657 # No images are attached to the framebuffer
658 fun gl_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: GLFramebufferStatus `{
659 return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
662 # The combination of internal formats of the attached images violates an implementation-dependent set of restrictions
663 fun gl_FRAMEBUFFER_UNSUPPORTED: GLFramebufferStatus `{
664 return GL_FRAMEBUFFER_UNSUPPORTED;
667 # Hint target for `glHint
`
668 extern class GLHintTarget
672 # Indicates the quality of filtering when generating mipmap images
673 fun gl_GENERATE_MIPMAP_HINT: GLHintTarget `{ return GL_GENERATE_MIPMAP_HINT; `}
675 # Hint mode for `glHint`
676 extern class GLHintMode
680 # The most efficient option should be chosen
681 fun gl_FASTEST
: GLHintMode `{ return GL_FASTEST; `}
683 # The most correct, or highest quality, option should be chosen
684 fun gl_NICEST: GLHintMode `{ return GL_NICEST; `}
687 fun gl_DONT_CARE
: GLHintMode `{ return GL_DONT_CARE; `}
689 # Entry point to OpenGL server-side capabilities
692 # GL capability: blend the computed fragment color values
695 var blend: GLCap is lazy do return new GLCap(0x0BE2)
697 # GL capability: cull polygons based of their winding in window coordinates
699 # Foreign: GL_CULL_FACE
700 var cull_face: GLCap is lazy do return new GLCap(0x0B44)
702 # GL capability: do depth comparisons and update the depth buffer
704 # Foreign: GL_DEPTH_TEST
705 var depth_test: GLCap is lazy do return new GLCap(0x0B71)
707 # GL capability: dither color components or indices before they are written to the color buffer
710 var dither: GLCap is lazy do return new GLCap(0x0BE2)
712 # GL capability: add an offset to depth values of a polygon fragment before depth test
714 # Foreign: GL_POLYGON_OFFSET_FILL
715 var polygon_offset_fill: GLCap is lazy do return new GLCap(0x8037)
717 # GL capability: compute a temporary coverage value where each bit is determined by the alpha value at the corresponding location
719 # Foreign: GL_SAMPLE_ALPHA_TO_COVERAGE
720 var sample_alpha_to_coverage: GLCap is lazy do return new GLCap(0x809E)
722 # GL capability: AND the fragment coverage with the temporary coverage value
724 # Foreign: GL_SAMPLE_COVERAGE
725 var sample_coverage: GLCap is lazy do return new GLCap(0x80A0)
727 # GL capability: discard fragments that are outside the scissor rectangle
729 # Foreign: GL_SCISSOR_TEST
730 var scissor_test: GLCap is lazy do return new GLCap(0x0C11)
732 # GL capability: do stencil testing and update the stencil buffer
734 # Foreign: GL_STENCIL_TEST
735 var stencil_test: GLCap is lazy do return new GLCap(0x0B90)
738 # Float related data types of OpenGL ES 2.0 shaders
740 # Only data types supported by shader attributes, as seen with
741 # `GLProgram::active_attrib_type
`.
742 extern class GLFloatDataType
745 fun is_float: Bool `{ return self == GL_FLOAT; `}
746 fun is_float_vec2
: Bool `{ return self == GL_FLOAT_VEC2; `}
747 fun is_float_vec3: Bool `{ return self == GL_FLOAT_VEC3; `}
748 fun is_float_vec4
: Bool `{ return self == GL_FLOAT_VEC4; `}
749 fun is_float_mat2: Bool `{ return self == GL_FLOAT_MAT2; `}
750 fun is_float_mat3
: Bool `{ return self == GL_FLOAT_MAT3; `}
751 fun is_float_mat4: Bool `{ return self == GL_FLOAT_MAT4; `}
753 # Instances of `GLFloatDataType` can be equal to instances of `GLDataType`
756 return o
!= null and o
isa GLFloatDataType and o
.hash
== self.hash
760 # All data types of OpenGL ES 2.0 shaders
762 # These types can be used by shader uniforms, as seen with
763 # `GLProgram::active_uniform_type`.
764 extern class GLDataType
765 super GLFloatDataType
767 fun is_int
: Bool `{ return self == GL_INT; `}
768 fun is_int_vec2: Bool `{ return self == GL_INT_VEC2; `}
769 fun is_int_vec3
: Bool `{ return self == GL_INT_VEC3; `}
770 fun is_int_vec4: Bool `{ return self == GL_INT_VEC4; `}
771 fun is_bool
: Bool `{ return self == GL_BOOL; `}
772 fun is_bool_vec2: Bool `{ return self == GL_BOOL_VEC2; `}
773 fun is_bool_vec3
: Bool `{ return self == GL_BOOL_VEC3; `}
774 fun is_bool_vec4: Bool `{ return self == GL_BOOL_VEC4; `}
775 fun is_sampler_2d
: Bool `{ return self == GL_SAMPLER_2D; `}
776 fun is_sampler_cube: Bool `{ return self == GL_SAMPLER_CUBE; `}
779 # Kind of primitives to render with `GLES::draw_arrays`
780 extern class GLDrawMode
783 new points
`{ return GL_POINTS; `}
784 new line_strip `{ return GL_LINE_STRIP; `}
785 new line_loop
`{ return GL_LINE_LOOP; `}
786 new lines `{ return GL_LINES; `}
787 new triangle_strip
`{ return GL_TRIANGLE_STRIP; `}
788 new triangle_fan `{ return GL_TRIANGLE_FAN; `}
789 new triangles
`{ return GL_TRIANGLES; `}
792 # Pixel arithmetic for blending operations
794 # Used by `GLES::blend_func
`
795 extern class GLBlendFactor
798 new zero `{ return GL_ZERO; `}
799 new one
`{ return GL_ONE; `}
800 new src_color `{ return GL_SRC_COLOR; `}
801 new one_minus_src_color
`{ return GL_ONE_MINUS_SRC_COLOR; `}
802 new dst_color `{ return GL_DST_COLOR; `}
803 new one_minus_dst_color
`{ return GL_ONE_MINUS_DST_COLOR; `}
804 new src_alpha `{ return GL_SRC_ALPHA; `}
805 new one_minus_src_alpha
`{ return GL_ONE_MINUS_SRC_ALPHA; `}
806 new dst_alpha `{ return GL_DST_ALPHA; `}
807 new one_minus_dst_alpha
`{ return GL_ONE_MINUS_DST_ALPHA; `}
808 new constant_color `{ return GL_CONSTANT_COLOR; `}
809 new one_minus_constant_color
`{ return GL_ONE_MINUS_CONSTANT_COLOR; `}
810 new constant_alpha `{ return GL_CONSTANT_ALPHA; `}
811 new one_minus_constant_alpha
`{ return GL_ONE_MINUS_CONSTANT_ALPHA; `}
813 # Used for destination only
814 new src_alpha_saturate `{ return GL_SRC_ALPHA_SATURATE; `}
817 # Condition under which a pixel will be drawn
819 # Used by `GLES::depth_func`
820 extern class GLDepthFunc
823 new never
`{ return GL_NEVER; `}
824 new less `{ return GL_LESS; `}
825 new equal
`{ return GL_EQUAL; `}
826 new lequal `{ return GL_LEQUAL; `}
827 new greater
`{ return GL_GREATER; `}
828 new not_equal `{ return GL_NOTEQUAL; `}
829 new gequal
`{ return GL_GEQUAL; `}
830 new always `{ return GL_ALWAYS; `}
833 # Format of pixel data
835 # Used by `GLES::read_pixels`
836 extern class GLPixelFormat
839 new alpha
`{ return GL_ALPHA; `}
840 new rgb `{ return GL_RGB; `}
841 new rgba
`{ return GL_RGBA; `}
844 # Data type of pixel data
846 # Used by `GLES::read_pixels
`
847 extern class GLPixelType
850 new unsigned_byte `{ return GL_UNSIGNED_BYTE; `}
851 new unsigned_short_5_6_5
`{ return GL_UNSIGNED_SHORT_5_6_5; `}
852 new unsigned_short_4_4_4_4 `{ return GL_UNSIGNED_SHORT_4_4_4_4; `}
853 new unsigned_short_5_5_5_1
`{ return GL_UNSIGNED_SHORT_5_5_5_1; `}
856 # Set of buffers as a bitwise OR mask, used by `GLES::clear
`
859 # var buffers = (new GLBuffer).color.depth
862 extern class GLBuffer `{ GLbitfield `}
863 # Get an empty set of buffers
866 # Add the color buffer to the returned buffer set
867 fun color: GLBuffer `{ return self | GL_COLOR_BUFFER_BIT; `}
869 # Add the depth buffer to the returned buffer set
870 fun depth
: GLBuffer `{ return self | GL_DEPTH_BUFFER_BIT; `}
872 # Add the stencil buffer to the returned buffer set
873 fun stencil: GLBuffer `{ return self | GL_STENCIL_BUFFER_BIT; `}