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 # Enable this vertex attribute array
314 fun enable
do glEnableVertexAttribArray
(index
)
316 # Disable this vertex attribute array
317 fun disable
do glDisableVertexAttribArray
(index
)
320 # Enable the generic vertex attribute array at `index`
321 fun glEnableVertexAttribArray
(index
: Int) `{ glEnableVertexAttribArray(index); `}
323 # Disable the generic vertex attribute array at `index
`
324 fun glDisableVertexAttribArray(index: Int) `{ glDisableVertexAttribArray(index); `}
326 # Render primitives from array data
327 fun glDrawArrays
(mode
: GLDrawMode, from
, count
: Int) `{ glDrawArrays(mode, from, count); `}
329 # Low level array of `Float`
330 extern class GLfloatArray `{GLfloat *`}
331 new (array
: Array[Float]) import Array[Float].length
, Array[Float].[] `{
333 int len = Array_of_Float_length(array);
334 GLfloat *vertex_array = malloc(sizeof(GLfloat)*len);
335 for (i = 0; i < len; i ++) vertex_array[i] = Array_of_Float__index(array, i);
340 # General type for OpenGL enumerations
341 extern class GLEnum `{ GLenum `}
343 redef fun hash `{ return self; `}
345 redef fun ==(o
) do return o
!= null and is_same_type
(o
) and o
.hash
== self.hash
348 # An OpenGL ES 2.0 error code
353 fun is_ok
: Bool do return is_no_error
355 # Is this not an error?
356 fun is_no_error
: Bool `{ return self == GL_NO_ERROR; `}
358 fun is_invalid_enum: Bool `{ return self == GL_INVALID_ENUM; `}
359 fun is_invalid_value
: Bool `{ return self == GL_INVALID_VALUE; `}
360 fun is_invalid_operation: Bool `{ return self == GL_INVALID_OPERATION; `}
361 fun is_invalid_framebuffer_operation
: Bool `{ return self == GL_INVALID_FRAMEBUFFER_OPERATION; `}
362 fun is_out_of_memory: Bool `{ return self == GL_OUT_OF_MEMORY; `}
366 if is_no_error
then return "No error"
367 if is_invalid_enum
then return "Invalid enum"
368 if is_invalid_value
then return "Invalid value"
369 if is_invalid_operation
then return "Invalid operation"
370 if is_invalid_framebuffer_operation
then return "invalid framebuffer operation"
371 if is_out_of_memory
then return "Out of memory"
372 return "Truely unknown error"
376 fun assert_no_gl_error
379 if not error
.is_ok
then
380 print
"GL error: {error}"
385 # Texture minifying function
387 # Used by: `GLES::tex_parameter_min_filter`
388 extern class GLTextureMinFilter
391 new nearest
`{ return GL_NEAREST; `}
392 new linear `{ return GL_LINEAR; `}
395 # Texture magnification function
397 # Used by: `GLES::tex_parameter_mag_filter`
398 extern class GLTextureMagFilter
401 new nearest
`{ return GL_NEAREST; `}
402 new linear `{ return GL_LINEAR; `}
403 new nearest_mipmap_nearest
`{ return GL_NEAREST_MIPMAP_NEAREST; `}
404 new linear_mipmap_nearest `{ return GL_LINEAR_MIPMAP_NEAREST; `}
405 new nearest_mipmap_linear
`{ return GL_NEAREST_MIPMAP_LINEAR; `}
406 new linear_mipmap_linear `{ return GL_LINEAR_MIPMAP_LINEAR; `}
409 # Wrap parameter of a texture
411 # Used by: `tex_parameter_wrap_*`
412 extern class GLTextureWrap
415 new clamp_to_edge
`{ return GL_CLAMP_TO_EDGE; `}
416 new mirrored_repeat `{ return GL_MIRRORED_REPEAT; `}
417 new repeat
`{ return GL_REPEAT; `}
422 # Used by: `tex_parameter_
*`
423 extern class GLTextureTarget
426 new flat `{ return GL_TEXTURE_2D; `}
427 new cube_map
`{ return GL_TEXTURE_CUBE_MAP; `}
430 # A server-side capability
435 # Internal OpenGL integer for this capability
438 # Enable this server-side capability
439 fun enable do enable_native(val)
440 private fun enable_native(cap: Int) `{ glEnable(cap); `}
442 # Disable this server-side capability
443 fun disable
do disable_native
(val
)
444 private fun disable_native
(cap
: Int) `{ glDisable(cap); `}
446 redef fun hash do return val
447 redef fun ==(o) do return o != null and is_same_type(o) and o.hash == self.hash
450 private var gles = new GLES is lazy
453 # Entry points to OpenGL ES 2.0 services
454 fun gl: GLES do return sys.gles
456 # OpenGL ES 2.0 services
459 # Clear the color buffer to `red
`, `green
`, `blue
` and `alpha
`
460 fun clear_color(red, green, blue, alpha: Float) `{
461 glClearColor
(red
, green
, blue
, alpha
);
465 fun viewport(x, y, width, height: Int) `{ glViewport(x, y, width, height); `}
467 # Specify mapping of depth values from normalized device coordinates to window coordinates
469 # Default at `gl_depth_range(0.0, 1.0)`
470 fun depth_range
(near
, far
: Float) `{ glDepthRangef(near, far); `}
472 # Define front- and back-facing polygons
474 # Front-facing polygons are clockwise if `value
`, counter-clockwise otherwise.
475 fun front_face=(value: Bool) `{ glFrontFace(value? GL_CW: GL_CCW); `}
477 # Specify whether front- or back-facing polygons can be culled, default is `back` only
479 # One or both of `front` or `back` must be `true`. If you want to deactivate culling
480 # use `(new GLCap.cull_face).disable`.
482 # Require: `front or back`
483 fun cull_face
(front
, back
: Bool)
485 assert not (front
or back
)
486 cull_face_native
(front
, back
)
489 private fun cull_face_native
(front
, back
: Bool) `{
490 glCullFace(front? back? GL_FRONT_AND_BACK: GL_BACK: GL_FRONT);
494 fun clear
(buffer
: GLBuffer) `{ glClear(buffer); `}
496 # Last error from OpenGL ES 2.0
497 fun error: GLError `{ return glGetError(); `}
499 # Query the boolean value at `key`
500 private fun get_bool
(key
: Int): Bool `{
502 glGetBooleanv(key, &val);
503 return val == GL_TRUE;
506 # Query the floating point value at `key`
507 private fun get_float
(key
: Int): Float `{
509 glGetFloatv(key, &val);
513 # Query the integer value at `key`
514 private fun get_int
(key
: Int): Int `{
516 glGetIntegerv(key, &val);
520 # Does this driver support shader compilation?
522 # Should always return `true` in OpenGL ES 2.0 and 3.0.
523 fun shader_compiler
: Bool do return get_bool
(0x8DFA)
525 # Enable or disable writing into the depth buffer
526 fun depth_mask
(value
: Bool) `{ glDepthMask(value); `}
528 # Set the scale and units used to calculate depth values
529 fun polygon_offset(factor, units: Float) `{ glPolygonOffset(factor, units); `}
531 # Specify the width of rasterized lines
532 fun line_width
(width
: Float) `{ glLineWidth(width); `}
534 # Set the pixel arithmetic for the blending operations
536 # Defaultvalues before assignation:
537 # * `src_factor
`: `GLBlendFactor::one
`
538 # * `dst_factor
`: `GLBlendFactor::zero
`
539 fun blend_func(src_factor, dst_factor: GLBlendFactor) `{
540 glBlendFunc
(src_factor
, dst_factor
);
543 # Specify the value used for depth buffer comparisons
545 # Default value is `GLDepthFunc::less
`
547 # Foreign: glDepthFunc
548 fun depth_func(func: GLDepthFunc) `{ glDepthFunc(func); `}
550 # Copy a block of pixels from the framebuffer of `fomat` and `typ` at `data`
552 # Foreign: glReadPixel
553 fun read_pixels
(x
, y
, width
, height
: Int, format
: GLPixelFormat, typ
: GLPixelType, data
: Pointer) `{
554 glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
557 # Set the texture minifying function
559 # Foreign: glTexParameter with GL_TEXTURE_MIN_FILTER
560 fun tex_parameter_min_filter
(target
: GLTextureTarget, value
: GLTextureMinFilter) `{
561 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, value);
564 # Set the texture magnification function
566 # Foreign: glTexParameter with GL_TEXTURE_MAG_FILTER
567 fun tex_parameter_mag_filter
(target
: GLTextureTarget, value
: GLTextureMagFilter) `{
568 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, value);
571 # Set the texture wrap parameter for coordinates _s_
573 # Foreign: glTexParameter with GL_TEXTURE_WRAP_S
574 fun tex_parameter_wrap_s
(target
: GLTextureTarget, value
: GLTextureWrap) `{
575 glTexParameteri(target, GL_TEXTURE_WRAP_S, value);
578 # Set the texture wrap parameter for coordinates _t_
580 # Foreign: glTexParameter with GL_TEXTURE_WRAP_T
581 fun tex_parameter_wrap_t
(target
: GLTextureTarget, value
: GLTextureWrap) `{
582 glTexParameteri(target, GL_TEXTURE_WRAP_T, value);
585 # Render primitives from array data
587 # Foreign: glDrawArrays
588 fun draw_arrays
(mode
: GLDrawMode, from
, count
: Int) `{ glDrawArrays(mode, from, count); `}
590 # OpenGL server-side capabilities
591 var capabilities = new GLCapabilities is lazy
594 # Bind `framebuffer
` to a framebuffer target
596 # In OpenGL ES 2.0, `target
` must be `gl_FRAMEBUFFER
`.
597 fun glBindFramebuffer(target: GLFramebufferTarget, framebuffer: Int) `{
598 glBindFramebuffer
(target
, framebuffer
);
601 # Target of `glBindFramebuffer
`
602 extern class GLFramebufferTarget
606 # Target both reading and writing on the framebuffer with `glBindFramebuffer
`
607 fun gl_FRAMEBUFFER: GLFramebufferTarget `{ return GL_FRAMEBUFFER; `}
609 # Bind `renderbuffer` to a renderbuffer target
611 # In OpenGL ES 2.0, `target` must be `gl_RENDERBUFFER`.
612 fun glBindRenderbuffer
(target
: GLRenderbufferTarget, renderbuffer
: Int) `{
613 glBindRenderbuffer(target, renderbuffer);
616 # Target of `glBindRenderbuffer`
617 extern class GLRenderbufferTarget
621 # Target a renderbuffer with `glBindRenderbuffer`
622 fun gl_RENDERBUFFER
: GLRenderbufferTarget `{ return GL_RENDERBUFFER; `}
624 # Specify implementation specific hints
625 fun glHint(target: GLHintTarget, mode: GLHintMode) `{
626 glHint
(target
, mode
);
629 # Completeness status of a framebuffer object
630 fun glCheckFramebufferStatus(target: GLFramebufferTarget): GLFramebufferStatus `{
631 return glCheckFramebufferStatus
(target
);
634 # Return value of `glCheckFramebufferStatus
`
635 extern class GLFramebufferStatus
640 if self == gl_FRAMEBUFFER_COMPLETE then return "complete"
641 if self == gl_FRAMEBUFFER_INCOMPLETE_ATTACHMENT then return "incomplete attachment"
642 if self == gl_FRAMEBUFFER_INCOMPLETE_DIMENSIONS then return "incomplete dimension"
643 if self == gl_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT then return "incomplete missing attachment"
644 if self == gl_FRAMEBUFFER_UNSUPPORTED then return "unsupported"
649 # The framebuffer is complete
650 fun gl_FRAMEBUFFER_COMPLETE: GLFramebufferStatus `{
651 return GL_FRAMEBUFFER_COMPLETE;
654 # Not all framebuffer attachment points are framebuffer attachment complete
655 fun gl_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: GLFramebufferStatus `{
656 return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
659 # Not all attached images have the same width and height
660 fun gl_FRAMEBUFFER_INCOMPLETE_DIMENSIONS: GLFramebufferStatus `{
661 return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS;
664 # No images are attached to the framebuffer
665 fun gl_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: GLFramebufferStatus `{
666 return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
669 # The combination of internal formats of the attached images violates an implementation-dependent set of restrictions
670 fun gl_FRAMEBUFFER_UNSUPPORTED: GLFramebufferStatus `{
671 return GL_FRAMEBUFFER_UNSUPPORTED;
674 # Hint target for `glHint
`
675 extern class GLHintTarget
679 # Indicates the quality of filtering when generating mipmap images
680 fun gl_GENERATE_MIPMAP_HINT: GLHintTarget `{ return GL_GENERATE_MIPMAP_HINT; `}
682 # Hint mode for `glHint`
683 extern class GLHintMode
687 # The most efficient option should be chosen
688 fun gl_FASTEST
: GLHintMode `{ return GL_FASTEST; `}
690 # The most correct, or highest quality, option should be chosen
691 fun gl_NICEST: GLHintMode `{ return GL_NICEST; `}
694 fun gl_DONT_CARE
: GLHintMode `{ return GL_DONT_CARE; `}
696 # Entry point to OpenGL server-side capabilities
699 # GL capability: blend the computed fragment color values
702 var blend: GLCap is lazy do return new GLCap(0x0BE2)
704 # GL capability: cull polygons based of their winding in window coordinates
706 # Foreign: GL_CULL_FACE
707 var cull_face: GLCap is lazy do return new GLCap(0x0B44)
709 # GL capability: do depth comparisons and update the depth buffer
711 # Foreign: GL_DEPTH_TEST
712 var depth_test: GLCap is lazy do return new GLCap(0x0B71)
714 # GL capability: dither color components or indices before they are written to the color buffer
717 var dither: GLCap is lazy do return new GLCap(0x0BE2)
719 # GL capability: add an offset to depth values of a polygon fragment before depth test
721 # Foreign: GL_POLYGON_OFFSET_FILL
722 var polygon_offset_fill: GLCap is lazy do return new GLCap(0x8037)
724 # GL capability: compute a temporary coverage value where each bit is determined by the alpha value at the corresponding location
726 # Foreign: GL_SAMPLE_ALPHA_TO_COVERAGE
727 var sample_alpha_to_coverage: GLCap is lazy do return new GLCap(0x809E)
729 # GL capability: AND the fragment coverage with the temporary coverage value
731 # Foreign: GL_SAMPLE_COVERAGE
732 var sample_coverage: GLCap is lazy do return new GLCap(0x80A0)
734 # GL capability: discard fragments that are outside the scissor rectangle
736 # Foreign: GL_SCISSOR_TEST
737 var scissor_test: GLCap is lazy do return new GLCap(0x0C11)
739 # GL capability: do stencil testing and update the stencil buffer
741 # Foreign: GL_STENCIL_TEST
742 var stencil_test: GLCap is lazy do return new GLCap(0x0B90)
745 # Float related data types of OpenGL ES 2.0 shaders
747 # Only data types supported by shader attributes, as seen with
748 # `GLProgram::active_attrib_type
`.
749 extern class GLFloatDataType
752 fun is_float: Bool `{ return self == GL_FLOAT; `}
753 fun is_float_vec2
: Bool `{ return self == GL_FLOAT_VEC2; `}
754 fun is_float_vec3: Bool `{ return self == GL_FLOAT_VEC3; `}
755 fun is_float_vec4
: Bool `{ return self == GL_FLOAT_VEC4; `}
756 fun is_float_mat2: Bool `{ return self == GL_FLOAT_MAT2; `}
757 fun is_float_mat3
: Bool `{ return self == GL_FLOAT_MAT3; `}
758 fun is_float_mat4: Bool `{ return self == GL_FLOAT_MAT4; `}
760 # Instances of `GLFloatDataType` can be equal to instances of `GLDataType`
763 return o
!= null and o
isa GLFloatDataType and o
.hash
== self.hash
767 # All data types of OpenGL ES 2.0 shaders
769 # These types can be used by shader uniforms, as seen with
770 # `GLProgram::active_uniform_type`.
771 extern class GLDataType
772 super GLFloatDataType
774 fun is_int
: Bool `{ return self == GL_INT; `}
775 fun is_int_vec2: Bool `{ return self == GL_INT_VEC2; `}
776 fun is_int_vec3
: Bool `{ return self == GL_INT_VEC3; `}
777 fun is_int_vec4: Bool `{ return self == GL_INT_VEC4; `}
778 fun is_bool
: Bool `{ return self == GL_BOOL; `}
779 fun is_bool_vec2: Bool `{ return self == GL_BOOL_VEC2; `}
780 fun is_bool_vec3
: Bool `{ return self == GL_BOOL_VEC3; `}
781 fun is_bool_vec4: Bool `{ return self == GL_BOOL_VEC4; `}
782 fun is_sampler_2d
: Bool `{ return self == GL_SAMPLER_2D; `}
783 fun is_sampler_cube: Bool `{ return self == GL_SAMPLER_CUBE; `}
786 # Kind of primitives to render with `GLES::draw_arrays`
787 extern class GLDrawMode
790 new points
`{ return GL_POINTS; `}
791 new line_strip `{ return GL_LINE_STRIP; `}
792 new line_loop
`{ return GL_LINE_LOOP; `}
793 new lines `{ return GL_LINES; `}
794 new triangle_strip
`{ return GL_TRIANGLE_STRIP; `}
795 new triangle_fan `{ return GL_TRIANGLE_FAN; `}
796 new triangles
`{ return GL_TRIANGLES; `}
799 # Pixel arithmetic for blending operations
801 # Used by `GLES::blend_func
`
802 extern class GLBlendFactor
805 new zero `{ return GL_ZERO; `}
806 new one
`{ return GL_ONE; `}
807 new src_color `{ return GL_SRC_COLOR; `}
808 new one_minus_src_color
`{ return GL_ONE_MINUS_SRC_COLOR; `}
809 new dst_color `{ return GL_DST_COLOR; `}
810 new one_minus_dst_color
`{ return GL_ONE_MINUS_DST_COLOR; `}
811 new src_alpha `{ return GL_SRC_ALPHA; `}
812 new one_minus_src_alpha
`{ return GL_ONE_MINUS_SRC_ALPHA; `}
813 new dst_alpha `{ return GL_DST_ALPHA; `}
814 new one_minus_dst_alpha
`{ return GL_ONE_MINUS_DST_ALPHA; `}
815 new constant_color `{ return GL_CONSTANT_COLOR; `}
816 new one_minus_constant_color
`{ return GL_ONE_MINUS_CONSTANT_COLOR; `}
817 new constant_alpha `{ return GL_CONSTANT_ALPHA; `}
818 new one_minus_constant_alpha
`{ return GL_ONE_MINUS_CONSTANT_ALPHA; `}
820 # Used for destination only
821 new src_alpha_saturate `{ return GL_SRC_ALPHA_SATURATE; `}
824 # Condition under which a pixel will be drawn
826 # Used by `GLES::depth_func`
827 extern class GLDepthFunc
830 new never
`{ return GL_NEVER; `}
831 new less `{ return GL_LESS; `}
832 new equal
`{ return GL_EQUAL; `}
833 new lequal `{ return GL_LEQUAL; `}
834 new greater
`{ return GL_GREATER; `}
835 new not_equal `{ return GL_NOTEQUAL; `}
836 new gequal
`{ return GL_GEQUAL; `}
837 new always `{ return GL_ALWAYS; `}
840 # Format of pixel data
842 # Used by `GLES::read_pixels`
843 extern class GLPixelFormat
846 new alpha
`{ return GL_ALPHA; `}
847 new rgb `{ return GL_RGB; `}
848 new rgba
`{ return GL_RGBA; `}
851 # Data type of pixel data
853 # Used by `GLES::read_pixels
`
854 extern class GLPixelType
857 new unsigned_byte `{ return GL_UNSIGNED_BYTE; `}
858 new unsigned_short_5_6_5
`{ return GL_UNSIGNED_SHORT_5_6_5; `}
859 new unsigned_short_4_4_4_4 `{ return GL_UNSIGNED_SHORT_4_4_4_4; `}
860 new unsigned_short_5_5_5_1
`{ return GL_UNSIGNED_SHORT_5_5_5_1; `}
863 # Set of buffers as a bitwise OR mask, used by `GLES::clear
`
866 # var buffers = (new GLBuffer).color.depth
869 extern class GLBuffer `{ GLbitfield `}
870 # Get an empty set of buffers
873 # Add the color buffer to the returned buffer set
874 fun color: GLBuffer `{ return self | GL_COLOR_BUFFER_BIT; `}
876 # Add the depth buffer to the returned buffer set
877 fun depth
: GLBuffer `{ return self | GL_DEPTH_BUFFER_BIT; `}
879 # Add the stencil buffer to the returned buffer set
880 fun stencil: GLBuffer `{ return self | GL_STENCIL_BUFFER_BIT; `}