lib/glesv2: fix ordering and compatibility in uses of glGetActive
[nit.git] / lib / glesv2 / glesv2.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2014 Alexis Laferrière <alexis.laf@xymus.net>
4 #
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
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
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.
16
17 # OpenGL graphics rendering library for embedded systems, version 2.0
18 #
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`.
22 #
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/
27 #
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/
32 module glesv2 is
33 pkgconfig
34 new_annotation glsl_vertex_shader
35 new_annotation glsl_fragment_shader
36 end
37
38
39 in "C Header" `{
40 #include <GLES2/gl2.h>
41 `}
42
43 # OpenGL ES program to which we attach shaders
44 extern class GLProgram `{GLuint`}
45 # Create a new program
46 #
47 # The newly created instance should be checked using `is_ok`.
48 new `{ return glCreateProgram(); `}
49
50 # Is this a valid program?
51 fun is_ok: Bool `{ return glIsProgram(recv); `}
52
53 # Attach a `shader` to this program
54 fun attach_shader(shader: GLShader) `{ glAttachShader(recv, shader); `}
55
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);
60 `}
61
62 # Get the location of the attribute by `name`
63 #
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);
68 `}
69
70 # Get the location of the uniform by `name`
71 #
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);
76 `}
77
78 # Query information on this program
79 fun query(pname: Int): Int `{
80 int val;
81 glGetProgramiv(recv, pname, &val);
82 return val;
83 `}
84
85 # Try to link this program
86 #
87 # Check result using `in_linked` and `info_log`.
88 fun link `{ glLinkProgram(recv); `}
89
90 # Is this program linked?
91 fun is_linked: Bool do return query(0x8B82) != 0
92
93 # Use this program for the following operations
94 fun use `{ glUseProgram(recv); `}
95
96 # Delete this program
97 fun delete `{ glDeleteProgram(recv); `}
98
99 # Has this program been deleted?
100 fun is_deleted: Bool do return query(0x8B80) != 0
101
102 # Validate whether this program can be executed in the current OpenGL state
103 #
104 # Check results using `is_validated` and `info_log`.
105 fun validate `{ glValidateProgram(recv); `}
106
107 # Boolean result of `validate`, must be called after `validate`
108 fun is_validated: Bool do return query(0x8B83) != 0
109
110 # Retrieve the information log of this program
111 #
112 # Useful with `link` and `validate`
113 fun info_log: String import NativeString.to_s `{
114 int size;
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);
119 `}
120
121 # Number of active uniform in this program
122 #
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)
126
127 # Length of the longest uniform name in this program, including `\n`
128 fun active_uniform_max_length: Int do return query(0x8B87)
129
130 # Number of active attributes in this program
131 #
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)
135
136 # Length of the longest uniform name in this program, including `\n`
137 fun active_attribute_max_length: Int do return query(0x8B8A)
138
139 # Number of shaders attached to this program
140 fun n_attached_shaders: Int do return query(0x8B85)
141
142 # Name of the active attribute at `index`
143 fun active_attrib_name(index: Int): String
144 do
145 var max_size = active_attribute_max_length
146 return active_attrib_name_native(index, max_size).to_s
147 end
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.
151
152 char *name = malloc(max_size);
153 int size;
154 GLenum type;
155 glGetActiveAttrib(recv, index, max_size, NULL, &size, &type, name);
156 return name;
157 `}
158
159 # Size of the active attribute at `index`
160 fun active_attrib_size(index: Int): Int `{
161 int size;
162 GLenum type;
163 glGetActiveAttrib(recv, index, 0, NULL, &size, &type, NULL);
164 return size;
165 `}
166
167 # Type of the active attribute at `index`
168 #
169 # May only be float related data types (single float, vectors and matrix).
170 fun active_attrib_type(index: Int): GLFloatDataType `{
171 int size;
172 GLenum type;
173 glGetActiveAttrib(recv, index, 0, NULL, &size, &type, NULL);
174 return type;
175 `}
176
177 # Name of the active uniform at `index`
178 fun active_uniform_name(index: Int): String
179 do
180 var max_size = active_attribute_max_length
181 return active_uniform_name_native(index, max_size).to_s
182 end
183 private fun active_uniform_name_native(index, max_size: Int): NativeString `{
184 char *name = malloc(max_size);
185 int size;
186 GLenum type;
187 glGetActiveUniform(recv, index, max_size, NULL, &size, &type, name);
188 return name;
189 `}
190
191 # Size of the active uniform at `index`
192 fun active_uniform_size(index: Int): Int `{
193 int size;
194 GLenum type;
195 glGetActiveUniform(recv, index, 0, NULL, &size, &type, NULL);
196 return size;
197 `}
198
199 # Type of the active uniform at `index`
200 #
201 # May be any data type supported by OpenGL ES 2.0 shaders.
202 fun active_uniform_type(index: Int): GLDataType `{
203 int size;
204 GLenum type = 0;
205 glGetActiveUniform(recv, index, 0, NULL, &size, &type, NULL);
206 return type;
207 `}
208 end
209
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);
215 `}
216
217 # Source of the shader, if available
218 #
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
222 do
223 var size = query(0x8B88)
224 if size == 0 then return null
225 return source_native(size).to_s
226 end
227
228 private fun source_native(size: Int): NativeString `{
229 GLchar *code = malloc(size);
230 glGetShaderSource(recv, size, NULL, code);
231 return code;
232 `}
233
234 # Query information on this shader
235 protected fun query(pname: Int): Int `{
236 int val;
237 glGetShaderiv(recv, pname, &val);
238 return val;
239 `}
240
241 # Try to compile `source` into a binary GPU program
242 #
243 # Check the result using `is_compiled` and `info_log`
244 fun compile `{ glCompileShader(recv); `}
245
246 # Has this shader been compiled?
247 fun is_compiled: Bool do return query(0x8B81) != 0
248
249 # Delete this shader
250 fun delete `{ glDeleteShader(recv); `}
251
252 # Has this shader been deleted?
253 fun is_deleted: Bool do return query(0x8B80) != 0
254
255 # Is this a valid shader?
256 fun is_ok: Bool `{ return glIsShader(recv); `}
257
258 # Retrieve the information log of this shader
259 #
260 # Useful with `link` and `validate`
261 fun info_log: String import NativeString.to_s `{
262 int size;
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);
267 `}
268 end
269
270 # An OpenGL ES 2.0 fragment shader
271 extern class GLFragmentShader
272 super GLShader
273
274 # Create a new fragment shader
275 #
276 # The newly created instance should be checked using `is_ok`.
277 new `{ return glCreateShader(GL_FRAGMENT_SHADER); `}
278 end
279
280 # An OpenGL ES 2.0 vertex shader
281 extern class GLVertexShader
282 super GLShader
283
284 # Create a new fragment shader
285 #
286 # The newly created instance should be checked using `is_ok`.
287 new `{ return glCreateShader(GL_VERTEX_SHADER); `}
288 end
289
290 # An array of `Float` associated to a program variable
291 class VertexArray
292 var index: Int
293
294 # Number of data per vertex
295 var count: Int
296
297 protected var glfloat_array: GLfloatArray
298
299 init(index, count: Int, array: Array[Float])
300 do
301 self.index = index
302 self.count = count
303 self.glfloat_array = new GLfloatArray(array)
304 end
305
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);
309 `}
310
311 fun enable do enable_intern(index)
312 private fun enable_intern(index: Int) `{ glEnableVertexAttribArray(index); `}
313
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);
317 `}
318 end
319
320 # Low level array of `Float`
321 extern class GLfloatArray `{GLfloat *`}
322 new (array: Array[Float]) import Array[Float].length, Array[Float].[] `{
323 int i;
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);
327 return vertex_array;
328 `}
329 end
330
331 # General type for OpenGL enumerations
332 extern class GLEnum `{ GLenum `}
333
334 redef fun hash `{ return recv; `}
335
336 redef fun ==(o) do return o != null and is_same_type(o) and o.hash == self.hash
337 end
338
339 # An OpenGL ES 2.0 error code
340 extern class GLError
341 super GLEnum
342
343 # Is there no error?
344 fun is_ok: Bool do return is_no_error
345
346 # Is this not an error?
347 fun is_no_error: Bool `{ return recv == GL_NO_ERROR; `}
348
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; `}
354
355 redef fun to_s
356 do
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"
364 end
365 end
366
367 protected fun assert_no_gl_error
368 do
369 var error = gl.error
370 if not error.is_ok then
371 print "GL error: {error}"
372 abort
373 end
374 end
375
376 # Texture minifying function
377 #
378 # Used by: `GLES::tex_parameter_min_filter`
379 extern class GLTextureMinFilter
380 super GLEnum
381
382 new nearest `{ return GL_NEAREST; `}
383 new linear `{ return GL_LINEAR; `}
384 end
385
386 # Texture magnification function
387 #
388 # Used by: `GLES::tex_parameter_mag_filter`
389 extern class GLTextureMagFilter
390 super GLEnum
391
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; `}
398 end
399
400 # Wrap parameter of a texture
401 #
402 # Used by: `tex_parameter_wrap_*`
403 extern class GLTextureWrap
404 super GLEnum
405
406 new clamp_to_edge `{ return GL_CLAMP_TO_EDGE; `}
407 new mirrored_repeat `{ return GL_MIRRORED_REPEAT; `}
408 new repeat `{ return GL_REPEAT; `}
409 end
410
411 # Target texture
412 #
413 # Used by: `tex_parameter_*`
414 extern class GLTextureTarget
415 super GLEnum
416
417 new flat `{ return GL_TEXTURE_2D; `}
418 new cube_map `{ return GL_TEXTURE_CUBE_MAP; `}
419 end
420
421 # A server-side capability
422 class GLCap
423
424 # TODO private init
425
426 # Internal OpenGL integer for this capability
427 private var val: Int
428
429 # Enable this server-side capability
430 fun enable do enable_native(val)
431 private fun enable_native(cap: Int) `{ glEnable(cap); `}
432
433 # Disable this server-side capability
434 fun disable do disable_native(val)
435 private fun disable_native(cap: Int) `{ glDisable(cap); `}
436
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
439 end
440 redef class Sys
441 private var gles = new GLES is lazy
442 end
443
444 # Entry points to OpenGL ES 2.0 services
445 fun gl: GLES do return sys.gles
446
447 # OpenGL ES 2.0 services
448 class GLES
449
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);
453 `}
454
455 # Set the viewport
456 fun viewport(x, y, width, height: Int) `{ glViewport(x, y, width, height); `}
457
458 # Specify mapping of depth values from normalized device coordinates to window coordinates
459 #
460 # Default at `gl_depth_range(0.0, 1.0)`
461 fun depth_range(near, far: Float) `{ glDepthRangef(near, far); `}
462
463 # Define front- and back-facing polygons
464 #
465 # Front-facing polygons are clockwise if `value`, counter-clockwise otherwise.
466 fun front_face=(value: Bool) `{ glFrontFace(value? GL_CW: GL_CCW); `}
467
468 # Specify whether front- or back-facing polygons can be culled, default is `back` only
469 #
470 # One or both of `front` or `back` must be `true`. If you want to deactivate culling
471 # use `(new GLCap.cull_face).disable`.
472 #
473 # Require: `front or back`
474 fun cull_face(front, back: Bool)
475 do
476 assert not (front or back)
477 cull_face_native(front, back)
478 end
479
480 private fun cull_face_native(front, back: Bool) `{
481 glCullFace(front? back? GL_FRONT_AND_BACK: GL_BACK: GL_FRONT);
482 `}
483
484 # Clear the `buffer`
485 fun clear(buffer: GLBuffer) `{ glClear(buffer); `}
486
487 # Last error from OpenGL ES 2.0
488 fun error: GLError `{ return glGetError(); `}
489
490 # Query the boolean value at `key`
491 private fun get_bool(key: Int): Bool `{
492 GLboolean val;
493 glGetBooleanv(key, &val);
494 return val == GL_TRUE;
495 `}
496
497 # Query the floating point value at `key`
498 private fun get_float(key: Int): Float `{
499 GLfloat val;
500 glGetFloatv(key, &val);
501 return val;
502 `}
503
504 # Query the integer value at `key`
505 private fun get_int(key: Int): Int `{
506 GLint val;
507 glGetIntegerv(key, &val);
508 return val;
509 `}
510
511 # Does this driver support shader compilation?
512 #
513 # Should always return `true` in OpenGL ES 2.0 and 3.0.
514 fun shader_compiler: Bool do return get_bool(0x8DFA)
515
516 # Enable or disable writing into the depth buffer
517 fun depth_mask(value: Bool) `{ glDepthMask(value); `}
518
519 # Set the scale and units used to calculate depth values
520 fun polygon_offset(factor, units: Float) `{ glPolygonOffset(factor, units); `}
521
522 # Specify the width of rasterized lines
523 fun line_width(width: Float) `{ glLineWidth(width); `}
524
525 # Set the pixel arithmetic for the blending operations
526 #
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);
532 `}
533
534 # Specify the value used for depth buffer comparisons
535 #
536 # Default value is `GLDepthFunc::less`
537 #
538 # Foreign: glDepthFunc
539 fun depth_func(func: GLDepthFunc) `{ glDepthFunc(func); `}
540
541 # Copy a block of pixels from the framebuffer of `fomat` and `typ` at `data`
542 #
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);
546 `}
547
548 # Set the texture minifying function
549 #
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);
553 `}
554
555 # Set the texture magnification function
556 #
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);
560 `}
561
562 # Set the texture wrap parameter for coordinates _s_
563 #
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);
567 `}
568
569 # Set the texture wrap parameter for coordinates _t_
570 #
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);
574 `}
575
576 # Render primitives from array data
577 #
578 # Foreign: glDrawArrays
579 fun draw_arrays(mode: GLDrawMode, from, count: Int) `{ glDrawArrays(mode, from, count); `}
580
581 # OpenGL server-side capabilities
582 var capabilities = new GLCapabilities is lazy
583 end
584
585 # Entry point to OpenGL server-side capabilities
586 class GLCapabilities
587
588 # GL capability: blend the computed fragment color values
589 #
590 # Foreign: GL_BLEND
591 fun blend: GLCap is lazy do return new GLCap(0x0BE2)
592
593 # GL capability: cull polygons based of their winding in window coordinates
594 #
595 # Foreign: GL_CULL_FACE
596 fun cull_face: GLCap is lazy do return new GLCap(0x0B44)
597
598 # GL capability: do depth comparisons and update the depth buffer
599 #
600 # Foreign: GL_DEPTH_TEST
601 fun depth_test: GLCap is lazy do return new GLCap(0x0B71)
602
603 # GL capability: dither color components or indices before they are written to the color buffer
604 #
605 # Foreign: GL_DITHER
606 fun dither: GLCap is lazy do return new GLCap(0x0BE2)
607
608 # GL capability: add an offset to depth values of a polygon fragment before depth test
609 #
610 # Foreign: GL_POLYGON_OFFSET_FILL
611 fun polygon_offset_fill: GLCap is lazy do return new GLCap(0x8037)
612
613 # GL capability: compute a temporary coverage value where each bit is determined by the alpha value at the corresponding location
614 #
615 # Foreign: GL_SAMPLE_ALPHA_TO_COVERAGE
616 fun sample_alpha_to_coverage: GLCap is lazy do return new GLCap(0x809E)
617
618 # GL capability: AND the fragment coverage with the temporary coverage value
619 #
620 # Foreign: GL_SAMPLE_COVERAGE
621 fun sample_coverage: GLCap is lazy do return new GLCap(0x80A0)
622
623 # GL capability: discard fragments that are outside the scissor rectangle
624 #
625 # Foreign: GL_SCISSOR_TEST
626 fun scissor_test: GLCap is lazy do return new GLCap(0x0C11)
627
628 # GL capability: do stencil testing and update the stencil buffer
629 #
630 # Foreign: GL_STENCIL_TEST
631 fun stencil_test: GLCap is lazy do return new GLCap(0x0B90)
632 end
633
634 # Float related data types of OpenGL ES 2.0 shaders
635 #
636 # Only data types supported by shader attributes, as seen with
637 # `GLProgram::active_attrib_type`.
638 extern class GLFloatDataType
639 super GLEnum
640
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; `}
648
649 # Instances of `GLFloatDataType` can be equal to instances of `GLDataType`
650 redef fun ==(o)
651 do
652 return o != null and o isa GLFloatDataType and o.hash == self.hash
653 end
654 end
655
656 # All data types of OpenGL ES 2.0 shaders
657 #
658 # These types can be used by shader uniforms, as seen with
659 # `GLProgram::active_uniform_type`.
660 extern class GLDataType
661 super GLFloatDataType
662
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; `}
673 end
674
675 # Kind of primitives to render with `GLES::draw_arrays`
676 extern class GLDrawMode
677 super GLEnum
678
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; `}
686 end
687
688 # Pixel arithmetic for blending operations
689 #
690 # Used by `GLES::blend_func`
691 extern class GLBlendFactor
692 super GLEnum
693
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; `}
708
709 # Used for destination only
710 new src_alpha_saturate `{ return GL_SRC_ALPHA_SATURATE; `}
711 end
712
713 # Condition under which a pixel will be drawn
714 #
715 # Used by `GLES::depth_func`
716 extern class GLDepthFunc
717 super GLEnum
718
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; `}
727 end
728
729 # Format of pixel data
730 #
731 # Used by `GLES::read_pixels`
732 extern class GLPixelFormat
733 super GLEnum
734
735 new alpha `{ return GL_ALPHA; `}
736 new rgb `{ return GL_RGB; `}
737 new rgba `{ return GL_RGBA; `}
738 end
739
740 # Data type of pixel data
741 #
742 # Used by `GLES::read_pixels`
743 extern class GLPixelType
744 super GLEnum
745
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; `}
750 end
751
752 # Set of buffers as a bitwise OR mask, used by `GLES::clear`
753 #
754 # ~~~
755 # var buffers = (new GLBuffer).color.depth
756 # gl.clear buffers
757 # ~~~
758 extern class GLBuffer `{ GLbitfield `}
759 # Get an empty set of buffers
760 new `{ return 0; `}
761
762 # Add the color buffer to the returned buffer set
763 fun color: GLBuffer `{ return recv | GL_COLOR_BUFFER_BIT; `}
764
765 # Add the depth buffer to the returned buffer set
766 fun depth: GLBuffer `{ return recv | GL_DEPTH_BUFFER_BIT; `}
767
768 # Add the stencil buffer to the returned buffer set
769 fun stencil: GLBuffer `{ return recv | GL_STENCIL_BUFFER_BIT; `}
770 end