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 # Is this a valid program?
54 fun is_ok
: Bool `{ return glIsProgram(self); `}
56 # Attach a `shader
` to this program
57 fun attach_shader(shader: GLShader) `{ glAttachShader(self, shader); `}
59 # Set the location for the attribute by `name`
60 fun bind_attrib_location
(index
: Int, name
: String) import String.to_cstring
`{
61 GLchar *c_name = String_to_cstring(name);
62 glBindAttribLocation(self, index, c_name);
65 # Get the location of the attribute by `name`
67 # Returns `-1` if there is no active attribute named `name`.
68 fun attrib_location
(name
: String): Int import String.to_cstring
`{
69 GLchar *c_name = String_to_cstring(name);
70 return glGetAttribLocation(self, c_name);
73 # Get the location of the uniform by `name`
75 # Returns `-1` if there is no active uniform named `name`.
76 fun uniform_location
(name
: String): Int import String.to_cstring
`{
77 GLchar *c_name = String_to_cstring(name);
78 return glGetUniformLocation(self, c_name);
81 # Query information on this program
82 fun query
(pname
: Int): Int `{
84 glGetProgramiv(self, pname, &val);
88 # Try to link this program
90 # Check result using `in_linked` and `info_log`.
91 fun link
`{ glLinkProgram(self); `}
93 # Is this program linked?
94 fun is_linked: Bool do return query(0x8B82) != 0
96 # Use this program for the following operations
97 fun use `{ glUseProgram(self); `}
100 fun delete
`{ glDeleteProgram(self); `}
102 # Has this program been deleted?
103 fun is_deleted: Bool do return query(0x8B80) != 0
105 # Validate whether this program can be executed in the current OpenGL state
107 # Check results using `is_validated
` and `info_log
`.
108 fun validate `{ glValidateProgram(self); `}
110 # Boolean result of `validate`, must be called after `validate`
111 fun is_validated
: Bool do return query
(0x8B83) != 0
113 # Retrieve the information log of this program
115 # Useful with `link` and `validate`
116 fun info_log
: String import NativeString.to_s
`{
118 glGetProgramiv(self, GL_INFO_LOG_LENGTH, &size);
119 GLchar *msg = malloc(size);
120 glGetProgramInfoLog(self, size, NULL, msg);
121 return NativeString_to_s(msg);
124 # Number of active uniform in this program
126 # This should be the number of uniforms declared in all shader, except
127 # unused uniforms which may have been optimized out.
128 fun n_active_uniforms
: Int do return query
(0x8B86)
130 # Length of the longest uniform name in this program, including `\n`
131 fun active_uniform_max_length
: Int do return query
(0x8B87)
133 # Number of active attributes in this program
135 # This should be the number of uniforms declared in all shader, except
136 # unused uniforms which may have been optimized out.
137 fun n_active_attributes
: Int do return query
(0x8B89)
139 # Length of the longest uniform name in this program, including `\n`
140 fun active_attribute_max_length
: Int do return query
(0x8B8A)
142 # Number of shaders attached to this program
143 fun n_attached_shaders
: Int do return query
(0x8B85)
145 # Name of the active attribute at `index`
146 fun active_attrib_name
(index
: Int): String
148 var max_size
= active_attribute_max_length
149 return active_attrib_name_native
(index
, max_size
).to_s
151 private fun active_attrib_name_native
(index
, max_size
: Int): NativeString `{
152 // We get more values than we need, for compatibility. At least the
153 // NVidia driver tries to fill them even if NULL.
155 char *name = malloc(max_size);
158 glGetActiveAttrib(self, index, max_size, NULL, &size, &type, name);
162 # Size of the active attribute at `index`
163 fun active_attrib_size
(index
: Int): Int `{
166 glGetActiveAttrib(self, index, 0, NULL, &size, &type, NULL);
170 # Type of the active attribute at `index`
172 # May only be float related data types (single float, vectors and matrix).
173 fun active_attrib_type
(index
: Int): GLFloatDataType `{
176 glGetActiveAttrib(self, index, 0, NULL, &size, &type, NULL);
180 # Name of the active uniform at `index`
181 fun active_uniform_name
(index
: Int): String
183 var max_size
= active_attribute_max_length
184 return active_uniform_name_native
(index
, max_size
).to_s
186 private fun active_uniform_name_native
(index
, max_size
: Int): NativeString `{
187 char *name = malloc(max_size);
190 glGetActiveUniform(self, index, max_size, NULL, &size, &type, name);
194 # Size of the active uniform at `index`
195 fun active_uniform_size
(index
: Int): Int `{
198 glGetActiveUniform(self, index, 0, NULL, &size, &type, NULL);
202 # Type of the active uniform at `index`
204 # May be any data type supported by OpenGL ES 2.0 shaders.
205 fun active_uniform_type
(index
: Int): GLDataType `{
208 glGetActiveUniform(self, index, 0, NULL, &size, &type, NULL);
213 # Abstract OpenGL ES shader object, implemented by `GLFragmentShader` and `GLVertexShader`
214 extern class GLShader `{GLuint`}
215 # Set the source of the shader
216 fun source=(code: NativeString) `{
217 glShaderSource
(self, 1, (GLchar const
**)&code
, NULL);
220 # Source of the shader, if available
222 # Returns `null` if the source is not available, usually when the shader
223 # was created from a binary file.
224 fun source: nullable String
226 var size = query(0x8B88)
227 if size == 0 then return null
228 return source_native(size).to_s
231 private fun source_native(size: Int): NativeString `{
232 GLchar *code
= malloc
(size
);
233 glGetShaderSource
(self, size
, NULL, code
);
237 # Query information on this shader
238 protected fun query(pname: Int): Int `{
240 glGetShaderiv
(self, pname
, &val
);
244 # Try to compile `source
` into a binary GPU program
246 # Check the result using `is_compiled
` and `info_log
`
247 fun compile `{ glCompileShader(self); `}
249 # Has this shader been compiled?
250 fun is_compiled
: Bool do return query
(0x8B81) != 0
253 fun delete
`{ glDeleteShader(self); `}
255 # Has this shader been deleted?
256 fun is_deleted: Bool do return query(0x8B80) != 0
258 # Is this a valid shader?
259 fun is_ok: Bool `{ return glIsShader(self); `}
261 # Retrieve the information log of this shader
263 # Useful with `link` and `validate`
264 fun info_log
: String import NativeString.to_s
`{
266 glGetShaderiv(self, GL_INFO_LOG_LENGTH, &size);
267 GLchar *msg = malloc(size);
268 glGetShaderInfoLog(self, size, NULL, msg);
269 return NativeString_to_s(msg);
273 # An OpenGL ES 2.0 fragment shader
274 extern class GLFragmentShader
277 # Create a new fragment shader
279 # The newly created instance should be checked using `is_ok`.
280 new `{ return glCreateShader(GL_FRAGMENT_SHADER); `}
283 # An OpenGL ES 2.0 vertex shader
284 extern class GLVertexShader
287 # Create a new fragment shader
289 # The newly created instance should be checked using `is_ok
`.
290 new `{ return glCreateShader(GL_VERTEX_SHADER); `}
293 # An array of `Float` associated to a program variable
297 # Number of data per vertex
300 protected var glfloat_array
: NativeGLfloatArray
302 init(index
, count
: Int, array
: Array[Float])
306 self.glfloat_array
= new NativeGLfloatArray(array
.length
)
307 for k
in [0..array
.length
[ do
308 glfloat_array
[k
] = array
[k
]
312 fun attrib_pointer
do attrib_pointer_intern
(index
, count
, glfloat_array
)
313 private fun attrib_pointer_intern
(index
, count
: Int, array
: NativeGLfloatArray) `{
314 glVertexAttribPointer(index, count, GL_FLOAT, GL_FALSE, 0, array);
317 # Enable this vertex attribute array
318 fun enable
do glEnableVertexAttribArray
(index
)
320 # Disable this vertex attribute array
321 fun disable
do glDisableVertexAttribArray
(index
)
324 # Enable the generic vertex attribute array at `index`
325 fun glEnableVertexAttribArray
(index
: Int) `{ glEnableVertexAttribArray(index); `}
327 # Disable the generic vertex attribute array at `index
`
328 fun glDisableVertexAttribArray(index: Int) `{ glDisableVertexAttribArray(index); `}
330 # Render primitives from array data
331 fun glDrawArrays
(mode
: GLDrawMode, from
, count
: Int) `{ glDrawArrays(mode, from, count); `}
333 # Specify the value of a generic vertex attribute
334 fun glVertexAttrib1f(index: Int, x: Float) `{ glVertexAttrib1f(index, x); `}
336 # Specify the value of a generic vertex attribute
337 fun glVertexAttrib2f
(index
: Int, x
, y
: Float) `{ glVertexAttrib2f(index, x, y); `}
339 # Specify the value of a generic vertex attribute
340 fun glVertexAttrib3f(index: Int, x, y, z: Float) `{ glVertexAttrib3f(index, x, y, z); `}
342 # Specify the value of a generic vertex attribute
343 fun glVertexAttrib4f
(index
: Int, x
, y
, z
, w
: Float) `{ glVertexAttrib4f(index, x, y, z, w); `}
345 # Specify the value of a uniform variable for the current program object
346 fun glUniform1i(index, x: Int) `{ glUniform1i(index, x); `}
348 # Specify the value of a uniform variable for the current program object
349 fun glUniform2i
(index
, x
, y
: Int) `{ glUniform2i(index, x, y); `}
351 # Specify the value of a uniform variable for the current program object
352 fun glUniform3i(index, x, y, z: Int) `{ glUniform3i(index, x, y, z); `}
354 # Specify the value of a uniform variable for the current program object
355 fun glUniform4i
(index
, x
, y
, z
, w
: Int) `{ glUniform4i(index, x, y, z, w); `}
359 # Low level array of `Float`
362 redef type NATIVE: NativeGLfloatArray
364 init do native_array = new NativeGLfloatArray(length)
366 # Create with the content of `array
`
367 new from(array: Array[Float])
369 var arr = new GLfloatArray(array.length)
374 # Fill with the content of `array
`
375 fun fill_from(array: Array[Float])
377 assert length >= array.length
378 for k in [0..array.length[ do
384 # An array of `GLfloat` in C (`GLfloat*`)
385 extern class NativeGLfloatArray `{ GLfloat* `}
389 new(size
: Int) `{ return calloc(size, sizeof(GLfloat)); `}
391 redef fun [](index) `{ return self[index]; `}
392 redef fun []=(index
, val
) `{ self[index] = val; `}
394 redef fun +(offset) `{ return self + offset; `}
397 # General type for OpenGL enumerations
398 extern class GLEnum `{ GLenum `}
400 redef fun hash `{ return self; `}
402 redef fun ==(o
) do return o
!= null and is_same_type
(o
) and o
.hash
== self.hash
405 # An OpenGL ES 2.0 error code
410 fun is_ok
: Bool do return is_no_error
412 # Is this not an error?
413 fun is_no_error
: Bool `{ return self == GL_NO_ERROR; `}
415 fun is_invalid_enum: Bool `{ return self == GL_INVALID_ENUM; `}
416 fun is_invalid_value
: Bool `{ return self == GL_INVALID_VALUE; `}
417 fun is_invalid_operation: Bool `{ return self == GL_INVALID_OPERATION; `}
418 fun is_invalid_framebuffer_operation
: Bool `{ return self == GL_INVALID_FRAMEBUFFER_OPERATION; `}
419 fun is_out_of_memory: Bool `{ return self == GL_OUT_OF_MEMORY; `}
423 if is_no_error
then return "No error"
424 if is_invalid_enum
then return "Invalid enum"
425 if is_invalid_value
then return "Invalid value"
426 if is_invalid_operation
then return "Invalid operation"
427 if is_invalid_framebuffer_operation
then return "invalid framebuffer operation"
428 if is_out_of_memory
then return "Out of memory"
429 return "Truely unknown error"
433 fun assert_no_gl_error
436 if not error
.is_ok
then
437 print
"GL error: {error}"
442 # Does `name` corresponds to a texture?
443 fun glIsTexture
(name
: Int): Bool `{ return glIsTexture(name); `}
445 # Bind the named `texture
` to a `target
`
446 fun glBindTexture(target: GLTextureTarget, texture: Int) `{ glBindTexture(target, texture); `}
448 # Set pixel storage modes
449 fun glPixelStorei
(parameter
: GLPack, val
: Int) `{ glPixelStorei(parameter, val); `}
451 # Symbolic name of the parameter to be set with `glPixelStorei
`
456 # Parameter to specify the alignment requirements for the start of each pixel row in memory
457 fun gl_PACK_ALIGNEMENT: GLPack `{ return GL_PACK_ALIGNMENT; `}
459 # Parameter to specify the alignment requirements for the start of each pixel row in memory
460 fun gl_UNPACK_ALIGNEMENT
: GLPack `{ return GL_UNPACK_ALIGNMENT; `}
462 # TODO GL_PACK_ROW_LENGTH, GL_PACK_IMAGE_HEIGHT, GL_PACK_SKIP_PIXELS, GL_PACK_SKIP_ROWS, GL_PACK_SKIP_IMAGES
463 # GL_UNPACK_ROW_LENGTH, GL_UNPACK_IMAGE_HEIGHT, GL_UNPACK_SKIP_PIXELS, GL_UNPACK_SKIP_ROWS, GL_UNPACK_SKIP_IMAGES
465 # Specify a two-dimensional texture image
466 fun glTexImage2D(target: GLTextureTarget, level, internalformat, width, height, border: Int,
467 format: GLPixelFormat, typ: GLPixelType, data: NativeCByteArray) `{
468 glTexImage2D
(target
, level
, internalformat
, width
, height
, border
, format
, typ
, data
);
471 # Texture minifying and magnifying function
472 extern class GLTextureFilter
476 fun gl_NEAREST: GLTextureFilter `{ return GL_NEAREST; `}
477 fun gl_LINEAR
: GLTextureFilter `{ return GL_LINEAR; `}
478 fun gl_NEAREST_MIPMAP_NEAREST: GLTextureFilter `{ return GL_NEAREST_MIPMAP_NEAREST; `}
479 fun gl_LINEAR_MIPMAP_NEAREST
: GLTextureFilter `{ return GL_LINEAR_MIPMAP_NEAREST; `}
480 fun gl_NEAREST_MIPMAP_NINEAR: GLTextureFilter `{ return GL_NEAREST_MIPMAP_LINEAR; `}
481 fun gl_LINEAR_MIPMAP_LINEAR
: GLTextureFilter `{ return GL_LINEAR_MIPMAP_LINEAR; `}
483 # Wrap parameter of a texture
485 # Used by: `tex_parameter_wrap_
*`
486 extern class GLTextureWrap
489 new clamp_to_edge `{ return GL_CLAMP_TO_EDGE; `}
490 new mirrored_repeat
`{ return GL_MIRRORED_REPEAT; `}
491 new repeat `{ return GL_REPEAT; `}
495 extern class GLTextureTarget
499 # Two-dimensional texture
500 fun gl_TEXTURE_2D
: GLTextureTarget `{ return GL_TEXTURE_2D; `}
503 fun gl_TEXTURE_CUBE_MAP: GLTextureTarget `{ return GL_TEXTURE_CUBE_MAP; `}
505 # TODO GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
506 # GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
508 # A server-side capability
513 # Internal OpenGL integer for this capability
516 # Enable this server-side capability
517 fun enable
do enable_native
(val
)
518 private fun enable_native
(cap
: Int) `{ glEnable(cap); `}
520 # Disable this server-side capability
521 fun disable do disable_native(val)
522 private fun disable_native(cap: Int) `{ glDisable(cap); `}
524 redef fun hash
do return val
525 redef fun ==(o
) do return o
!= null and is_same_type
(o
) and o
.hash
== self.hash
528 # Attach a renderbuffer object to a framebuffer object
529 fun glFramebufferRenderbuffer
(target
: GLFramebufferTarget, attachment
: GLAttachment,
530 renderbuffertarget
: GLRenderbufferTarget, renderbuffer
: Int) `{
531 glFramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer);
534 # Establish data storage, `format` and dimensions of the `target` renderbuffer object's image
535 fun glRenderbufferStorage
(target
: GLRenderbufferTarget, format
: GLRenderbufferFormat, width
, height
: Int) `{
536 glRenderbufferStorage(GL_RENDERBUFFER, format, width, height);
539 # Format for a renderbuffer
540 extern class GLRenderbufferFormat
544 # 4 red, 4 green, 4 blue, 4 alpha bits format
545 fun gl_RGBA4
: GLRenderbufferFormat `{ return GL_RGBA4; `}
547 # 5 red, 6 green, 5 blue bits format
548 fun gl_RGB565: GLRenderbufferFormat `{ return GL_RGB565; `}
550 # 5 red, 5 green, 5 blue, 1 alpha bits format
551 fun gl_RGB_A1
: GLRenderbufferFormat `{ return GL_RGB5_A1; `}
553 # 16 depth bits format
554 fun gl_DEPTH_COMPNENT16: GLRenderbufferFormat `{ return GL_DEPTH_COMPONENT16; `}
556 # 8 stencil bits format
557 fun gl_STENCIL_INDEX8
: GLRenderbufferFormat `{ return GL_STENCIL_INDEX8; `}
559 # Renderbuffer attachment point to a framebuffer
560 extern class GLAttachment
564 # First color attachment point
565 fun gl_COLOR_ATTACHMENT0: GLAttachment `{ return GL_COLOR_ATTACHMENT0; `}
567 # Depth attachment point
568 fun gl_DEPTH_ATTACHMENT
: GLAttachment `{ return GL_DEPTH_ATTACHMENT; `}
571 fun gl_STENCIL_ATTACHMENT: GLAttachment `{ return GL_STENCIL_ATTACHMENT; `}
574 private var gles
= new GLES is lazy
577 # Entry points to OpenGL ES 2.0 services
578 fun gl
: GLES do return sys
.gles
580 # OpenGL ES 2.0 services
583 # Clear the color buffer to `red`, `green`, `blue` and `alpha`
584 fun clear_color
(red
, green
, blue
, alpha
: Float) `{
585 glClearColor(red, green, blue, alpha);
589 fun viewport
(x
, y
, width
, height
: Int) `{ glViewport(x, y, width, height); `}
591 # Specify mapping of depth values from normalized device coordinates to window coordinates
593 # Default at `gl_depth_range
(0.0, 1.0)`
594 fun depth_range(near, far: Float) `{ glDepthRangef(near, far); `}
596 # Define front- and back-facing polygons
598 # Front-facing polygons are clockwise if `value`, counter-clockwise otherwise.
599 fun front_face
=(value
: Bool) `{ glFrontFace(value? GL_CW: GL_CCW); `}
601 # Specify whether front- or back-facing polygons can be culled, default is `back
` only
603 # One or both of `front
` or `back
` must be `true`. If you want to deactivate culling
604 # use `(new GLCap.cull_face
).disable
`.
606 # Require: `front
or back
`
607 fun cull_face(front, back: Bool)
609 assert not (front or back)
610 cull_face_native(front, back)
613 private fun cull_face_native(front, back: Bool) `{
614 glCullFace
(front
? back
? GL_FRONT_AND_BACK: GL_BACK: GL_FRONT);
618 fun clear(buffer: GLBuffer) `{ glClear(buffer); `}
620 # Last error from OpenGL ES 2.0
621 fun error
: GLError `{ return glGetError(); `}
623 # Query the boolean value at `key
`
624 private fun get_bool(key: Int): Bool `{
626 glGetBooleanv
(key
, &val
);
627 return val
== GL_TRUE;
630 # Query the floating point value at `key
`
631 private fun get_float(key: Int): Float `{
633 glGetFloatv
(key
, &val
);
637 # Query the integer value at `key
`
638 private fun get_int(key: Int): Int `{
640 glGetIntegerv
(key
, &val
);
644 # Does this driver support shader compilation?
646 # Should always return `true` in OpenGL ES 2.0 and 3.0.
647 fun shader_compiler: Bool do return get_bool(0x8DFA)
649 # Enable or disable writing into the depth buffer
650 fun depth_mask(value: Bool) `{ glDepthMask(value); `}
652 # Set the scale and units used to calculate depth values
653 fun polygon_offset
(factor
, units
: Float) `{ glPolygonOffset(factor, units); `}
655 # Specify the width of rasterized lines
656 fun line_width(width: Float) `{ glLineWidth(width); `}
658 # Set the pixel arithmetic for the blending operations
660 # Defaultvalues before assignation:
661 # * `src_factor`: `GLBlendFactor::one`
662 # * `dst_factor`: `GLBlendFactor::zero`
663 fun blend_func
(src_factor
, dst_factor
: GLBlendFactor) `{
664 glBlendFunc(src_factor, dst_factor);
667 # Specify the value used for depth buffer comparisons
669 # Default value is `GLDepthFunc::less`
671 # Foreign: glDepthFunc
672 fun depth_func
(func
: GLDepthFunc) `{ glDepthFunc(func); `}
674 # Copy a block of pixels from the framebuffer of `fomat
` and `typ
` at `data
`
676 # Foreign: glReadPixel
677 fun read_pixels(x, y, width, height: Int, format: GLPixelFormat, typ: GLPixelType, data: Pointer) `{
678 glReadPixels
(x
, y
, width
, height
, format
, typ
, data
);
681 # Set the texture minifying function
683 # Foreign: glTexParameter with GL_TEXTURE_MIN_FILTER
684 fun tex_parameter_min_filter(target: GLTextureTarget, value: GLTextureFilter) `{
685 glTexParameteri
(target
, GL_TEXTURE_MIN_FILTER, value
);
688 # Set the texture magnification function
690 # Foreign: glTexParameter with GL_TEXTURE_MAG_FILTER
691 fun tex_parameter_mag_filter(target: GLTextureTarget, value: GLTextureFilter) `{
692 glTexParameteri
(target
, GL_TEXTURE_MAG_FILTER, value
);
695 # Set the texture wrap parameter for coordinates _s_
697 # Foreign: glTexParameter with GL_TEXTURE_WRAP_S
698 fun tex_parameter_wrap_s(target: GLTextureTarget, value: GLTextureWrap) `{
699 glTexParameteri
(target
, GL_TEXTURE_WRAP_S, value
);
702 # Set the texture wrap parameter for coordinates _t_
704 # Foreign: glTexParameter with GL_TEXTURE_WRAP_T
705 fun tex_parameter_wrap_t(target: GLTextureTarget, value: GLTextureWrap) `{
706 glTexParameteri
(target
, GL_TEXTURE_WRAP_T, value
);
709 # Render primitives from array data
711 # Foreign: glDrawArrays
712 fun draw_arrays(mode: GLDrawMode, from, count: Int) `{ glDrawArrays(mode, from, count); `}
714 # OpenGL server-side capabilities
715 var capabilities
= new GLCapabilities is lazy
718 # Bind `framebuffer` to a framebuffer target
720 # In OpenGL ES 2.0, `target` must be `gl_FRAMEBUFFER`.
721 fun glBindFramebuffer
(target
: GLFramebufferTarget, framebuffer
: Int) `{
722 glBindFramebuffer(target, framebuffer);
725 # Target of `glBindFramebuffer`
726 extern class GLFramebufferTarget
730 # Target both reading and writing on the framebuffer with `glBindFramebuffer`
731 fun gl_FRAMEBUFFER
: GLFramebufferTarget `{ return GL_FRAMEBUFFER; `}
733 # Bind `renderbuffer
` to a renderbuffer target
735 # In OpenGL ES 2.0, `target
` must be `gl_RENDERBUFFER
`.
736 fun glBindRenderbuffer(target: GLRenderbufferTarget, renderbuffer: Int) `{
737 glBindRenderbuffer
(target
, renderbuffer
);
740 # Target of `glBindRenderbuffer
`
741 extern class GLRenderbufferTarget
745 # Target a renderbuffer with `glBindRenderbuffer
`
746 fun gl_RENDERBUFFER: GLRenderbufferTarget `{ return GL_RENDERBUFFER; `}
748 # Specify implementation specific hints
749 fun glHint
(target
: GLHintTarget, mode
: GLHintMode) `{
750 glHint(target, mode);
753 # Generate and fill set of mipmaps for the texture object `target`
754 fun glGenerateMipmap
(target
: GLTextureTarget) `{ glGenerateMipmap(target); `}
756 # Bind the named `buffer
` object
757 fun glBindBuffer(target: GLArrayBuffer, buffer: Int) `{ glBindBuffer(target, buffer); `}
759 # Target to which bind the buffer with `glBindBuffer`
760 extern class GLArrayBuffer
764 # Array buffer target
765 fun gl_ARRAY_BUFFER
: GLArrayBuffer `{ return GL_ARRAY_BUFFER; `}
767 # Element array buffer
768 fun gl_ELEMENT_ARRAY_BUFFER: GLArrayBuffer `{ return GL_ELEMENT_ARRAY_BUFFER; `}
770 # Completeness status of a framebuffer object
771 fun glCheckFramebufferStatus
(target
: GLFramebufferTarget): GLFramebufferStatus `{
772 return glCheckFramebufferStatus(target);
775 # Return value of `glCheckFramebufferStatus`
776 extern class GLFramebufferStatus
781 if self == gl_FRAMEBUFFER_COMPLETE
then return "complete"
782 if self == gl_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
then return "incomplete attachment"
783 if self == gl_FRAMEBUFFER_INCOMPLETE_DIMENSIONS
then return "incomplete dimension"
784 if self == gl_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
then return "incomplete missing attachment"
785 if self == gl_FRAMEBUFFER_UNSUPPORTED
then return "unsupported"
790 # The framebuffer is complete
791 fun gl_FRAMEBUFFER_COMPLETE
: GLFramebufferStatus `{
792 return GL_FRAMEBUFFER_COMPLETE;
795 # Not all framebuffer attachment points are framebuffer attachment complete
796 fun gl_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
: GLFramebufferStatus `{
797 return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
800 # Not all attached images have the same width and height
801 fun gl_FRAMEBUFFER_INCOMPLETE_DIMENSIONS
: GLFramebufferStatus `{
802 return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS;
805 # No images are attached to the framebuffer
806 fun gl_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
: GLFramebufferStatus `{
807 return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
810 # The combination of internal formats of the attached images violates an implementation-dependent set of restrictions
811 fun gl_FRAMEBUFFER_UNSUPPORTED
: GLFramebufferStatus `{
812 return GL_FRAMEBUFFER_UNSUPPORTED;
815 # Hint target for `glHint`
816 extern class GLHintTarget
820 # Indicates the quality of filtering when generating mipmap images
821 fun gl_GENERATE_MIPMAP_HINT
: GLHintTarget `{ return GL_GENERATE_MIPMAP_HINT; `}
823 # Hint mode for `glHint
`
824 extern class GLHintMode
828 # The most efficient option should be chosen
829 fun gl_FASTEST: GLHintMode `{ return GL_FASTEST; `}
831 # The most correct, or highest quality, option should be chosen
832 fun gl_NICEST
: GLHintMode `{ return GL_NICEST; `}
835 fun gl_DONT_CARE: GLHintMode `{ return GL_DONT_CARE; `}
837 # Attach a level of a texture object as a logical buffer to the currently bound framebuffer object
838 fun glFramebufferTexture2D
(target
: GLFramebufferTarget, attachment
: GLAttachment,
839 texture_target
: GLTextureTarget, texture
, level
: Int) `{
840 glFramebufferTexture2D(target, attachment, texture_target, texture, level);
843 # Entry point to OpenGL server-side capabilities
846 # GL capability: blend the computed fragment color values
849 var blend
: GLCap is lazy
do return new GLCap(0x0BE2)
851 # GL capability: cull polygons based of their winding in window coordinates
853 # Foreign: GL_CULL_FACE
854 var cull_face
: GLCap is lazy
do return new GLCap(0x0B44)
856 # GL capability: do depth comparisons and update the depth buffer
858 # Foreign: GL_DEPTH_TEST
859 var depth_test
: GLCap is lazy
do return new GLCap(0x0B71)
861 # GL capability: dither color components or indices before they are written to the color buffer
864 var dither
: GLCap is lazy
do return new GLCap(0x0BE2)
866 # GL capability: add an offset to depth values of a polygon fragment before depth test
868 # Foreign: GL_POLYGON_OFFSET_FILL
869 var polygon_offset_fill
: GLCap is lazy
do return new GLCap(0x8037)
871 # GL capability: compute a temporary coverage value where each bit is determined by the alpha value at the corresponding location
873 # Foreign: GL_SAMPLE_ALPHA_TO_COVERAGE
874 var sample_alpha_to_coverage
: GLCap is lazy
do return new GLCap(0x809E)
876 # GL capability: AND the fragment coverage with the temporary coverage value
878 # Foreign: GL_SAMPLE_COVERAGE
879 var sample_coverage
: GLCap is lazy
do return new GLCap(0x80A0)
881 # GL capability: discard fragments that are outside the scissor rectangle
883 # Foreign: GL_SCISSOR_TEST
884 var scissor_test
: GLCap is lazy
do return new GLCap(0x0C11)
886 # GL capability: do stencil testing and update the stencil buffer
888 # Foreign: GL_STENCIL_TEST
889 var stencil_test
: GLCap is lazy
do return new GLCap(0x0B90)
892 # Float related data types of OpenGL ES 2.0 shaders
894 # Only data types supported by shader attributes, as seen with
895 # `GLProgram::active_attrib_type`.
896 extern class GLFloatDataType
899 fun is_float
: Bool `{ return self == GL_FLOAT; `}
900 fun is_float_vec2: Bool `{ return self == GL_FLOAT_VEC2; `}
901 fun is_float_vec3
: Bool `{ return self == GL_FLOAT_VEC3; `}
902 fun is_float_vec4: Bool `{ return self == GL_FLOAT_VEC4; `}
903 fun is_float_mat2
: Bool `{ return self == GL_FLOAT_MAT2; `}
904 fun is_float_mat3: Bool `{ return self == GL_FLOAT_MAT3; `}
905 fun is_float_mat4
: Bool `{ return self == GL_FLOAT_MAT4; `}
907 # Instances of `GLFloatDataType` can be equal to instances of `GLDataType`
910 return o != null and o isa GLFloatDataType and o.hash == self.hash
914 # All data types of OpenGL ES 2.0 shaders
916 # These types can be used by shader uniforms, as seen with
917 # `GLProgram::active_uniform_type
`.
918 extern class GLDataType
919 super GLFloatDataType
921 fun is_int: Bool `{ return self == GL_INT; `}
922 fun is_int_vec2
: Bool `{ return self == GL_INT_VEC2; `}
923 fun is_int_vec3: Bool `{ return self == GL_INT_VEC3; `}
924 fun is_int_vec4
: Bool `{ return self == GL_INT_VEC4; `}
925 fun is_bool: Bool `{ return self == GL_BOOL; `}
926 fun is_bool_vec2
: Bool `{ return self == GL_BOOL_VEC2; `}
927 fun is_bool_vec3: Bool `{ return self == GL_BOOL_VEC3; `}
928 fun is_bool_vec4
: Bool `{ return self == GL_BOOL_VEC4; `}
929 fun is_sampler_2d: Bool `{ return self == GL_SAMPLER_2D; `}
930 fun is_sampler_cube
: Bool `{ return self == GL_SAMPLER_CUBE; `}
933 # Kind of primitives to render with `GLES::draw_arrays
`
934 extern class GLDrawMode
937 new points `{ return GL_POINTS; `}
938 new line_strip
`{ return GL_LINE_STRIP; `}
939 new line_loop `{ return GL_LINE_LOOP; `}
940 new lines
`{ return GL_LINES; `}
941 new triangle_strip `{ return GL_TRIANGLE_STRIP; `}
942 new triangle_fan
`{ return GL_TRIANGLE_FAN; `}
943 new triangles `{ return GL_TRIANGLES; `}
946 # Pixel arithmetic for blending operations
948 # Used by `GLES::blend_func`
949 extern class GLBlendFactor
952 new zero
`{ return GL_ZERO; `}
953 new one `{ return GL_ONE; `}
954 new src_color
`{ return GL_SRC_COLOR; `}
955 new one_minus_src_color `{ return GL_ONE_MINUS_SRC_COLOR; `}
956 new dst_color
`{ return GL_DST_COLOR; `}
957 new one_minus_dst_color `{ return GL_ONE_MINUS_DST_COLOR; `}
958 new src_alpha
`{ return GL_SRC_ALPHA; `}
959 new one_minus_src_alpha `{ return GL_ONE_MINUS_SRC_ALPHA; `}
960 new dst_alpha
`{ return GL_DST_ALPHA; `}
961 new one_minus_dst_alpha `{ return GL_ONE_MINUS_DST_ALPHA; `}
962 new constant_color
`{ return GL_CONSTANT_COLOR; `}
963 new one_minus_constant_color `{ return GL_ONE_MINUS_CONSTANT_COLOR; `}
964 new constant_alpha
`{ return GL_CONSTANT_ALPHA; `}
965 new one_minus_constant_alpha `{ return GL_ONE_MINUS_CONSTANT_ALPHA; `}
967 # Used for destination only
968 new src_alpha_saturate
`{ return GL_SRC_ALPHA_SATURATE; `}
971 # Condition under which a pixel will be drawn
973 # Used by `GLES::depth_func
`
974 extern class GLDepthFunc
977 new never `{ return GL_NEVER; `}
978 new less
`{ return GL_LESS; `}
979 new equal `{ return GL_EQUAL; `}
980 new lequal
`{ return GL_LEQUAL; `}
981 new greater `{ return GL_GREATER; `}
982 new not_equal
`{ return GL_NOTEQUAL; `}
983 new gequal `{ return GL_GEQUAL; `}
984 new always
`{ return GL_ALWAYS; `}
987 # Format of pixel data
989 # Used by `GLES::read_pixels
`
990 extern class GLPixelFormat
993 new alpha `{ return GL_ALPHA; `}
994 new rgb
`{ return GL_RGB; `}
995 new rgba `{ return GL_RGBA; `}
998 # Data type of pixel data
1000 # Used by `GLES::read_pixels`
1001 extern class GLPixelType
1004 new unsigned_byte
`{ return GL_UNSIGNED_BYTE; `}
1005 new unsigned_short_5_6_5 `{ return GL_UNSIGNED_SHORT_5_6_5; `}
1006 new unsigned_short_4_4_4_4
`{ return GL_UNSIGNED_SHORT_4_4_4_4; `}
1007 new unsigned_short_5_5_5_1 `{ return GL_UNSIGNED_SHORT_5_5_5_1; `}
1010 # Set of buffers as a bitwise OR mask, used by `GLES::clear`
1013 # var buffers = (new GLBuffer).color.depth
1016 extern class GLBuffer `{ GLbitfield `}
1017 # Get an empty set of buffers
1020 # Add the color buffer to the returned buffer set
1021 fun color
: GLBuffer `{ return self | GL_COLOR_BUFFER_BIT; `}
1023 # Add the depth buffer to the returned buffer set
1024 fun depth: GLBuffer `{ return self | GL_DEPTH_BUFFER_BIT; `}
1026 # Add the stencil buffer to the returned buffer set
1027 fun stencil
: GLBuffer `{ return self | GL_STENCIL_BUFFER_BIT; `}