01ca43ce82bddce85d04864a4a29f3832492c461
[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 char *name = malloc(max_size);
150 glGetActiveAttrib(recv, index, max_size, NULL, NULL, NULL, name);
151 return name;
152 `}
153
154 # Size of the active attribute at `index`
155 fun active_attrib_size(index: Int): Int `{
156 int size;
157 glGetActiveAttrib(recv, index, 0, NULL, NULL, &size, NULL);
158 return size;
159 `}
160
161 # Type of the active attribute at `index`
162 #
163 # May only be float related data types (single float, vectors and matrix).
164 fun active_attrib_type(index: Int): GLFloatDataType `{
165 GLenum type;
166 glGetActiveAttrib(recv, index, 0, NULL, &type, NULL, NULL);
167 return type;
168 `}
169
170 # Name of the active uniform at `index`
171 fun active_uniform_name(index: Int): String
172 do
173 var max_size = active_attribute_max_length
174 return active_uniform_name_native(index, max_size).to_s
175 end
176 private fun active_uniform_name_native(index, max_size: Int): NativeString `{
177 char *name = malloc(max_size);
178 glGetActiveUniform(recv, index, max_size, NULL, NULL, NULL, name);
179 return name;
180 `}
181
182 # Size of the active uniform at `index`
183 fun active_uniform_size(index: Int): Int `{
184 int size;
185 glGetActiveUniform(recv, index, 0, NULL, NULL, &size, NULL);
186 return size;
187 `}
188
189 # Type of the active uniform at `index`
190 #
191 # May be any data type supported by OpenGL ES 2.0 shaders.
192 fun active_uniform_type(index: Int): GLDataType `{
193 GLenum type;
194 glGetActiveUniform(recv, index, 0, NULL, &type, NULL, NULL);
195 return type;
196 `}
197 end
198
199 # Abstract OpenGL ES shader object, implemented by `GLFragmentShader` and `GLVertexShader`
200 extern class GLShader `{GLuint`}
201 # Set the source of the shader
202 fun source=(code: NativeString) `{
203 glShaderSource(recv, 1, (GLchar const **)&code, NULL);
204 `}
205
206 # Source of the shader, if available
207 #
208 # Returns `null` if the source is not available, usually when the shader
209 # was created from a binary file.
210 fun source: nullable String
211 do
212 var size = query(0x8B88)
213 if size == 0 then return null
214 return source_native(size).to_s
215 end
216
217 private fun source_native(size: Int): NativeString `{
218 GLchar *code = malloc(size);
219 glGetShaderSource(recv, size, NULL, code);
220 return code;
221 `}
222
223 # Query information on this shader
224 protected fun query(pname: Int): Int `{
225 int val;
226 glGetShaderiv(recv, pname, &val);
227 return val;
228 `}
229
230 # Try to compile `source` into a binary GPU program
231 #
232 # Check the result using `is_compiled` and `info_log`
233 fun compile `{ glCompileShader(recv); `}
234
235 # Has this shader been compiled?
236 fun is_compiled: Bool do return query(0x8B81) != 0
237
238 # Delete this shader
239 fun delete `{ glDeleteShader(recv); `}
240
241 # Has this shader been deleted?
242 fun is_deleted: Bool do return query(0x8B80) != 0
243
244 # Is this a valid shader?
245 fun is_ok: Bool `{ return glIsShader(recv); `}
246
247 # Retrieve the information log of this shader
248 #
249 # Useful with `link` and `validate`
250 fun info_log: String import NativeString.to_s `{
251 int size;
252 glGetShaderiv(recv, GL_INFO_LOG_LENGTH, &size);
253 GLchar *msg = malloc(size);
254 glGetShaderInfoLog(recv, size, NULL, msg);
255 return NativeString_to_s(msg);
256 `}
257 end
258
259 # An OpenGL ES 2.0 fragment shader
260 extern class GLFragmentShader
261 super GLShader
262
263 # Create a new fragment shader
264 #
265 # The newly created instance should be checked using `is_ok`.
266 new `{ return glCreateShader(GL_FRAGMENT_SHADER); `}
267 end
268
269 # An OpenGL ES 2.0 vertex shader
270 extern class GLVertexShader
271 super GLShader
272
273 # Create a new fragment shader
274 #
275 # The newly created instance should be checked using `is_ok`.
276 new `{ return glCreateShader(GL_VERTEX_SHADER); `}
277 end
278
279 # An array of `Float` associated to a program variable
280 class VertexArray
281 var index: Int
282
283 # Number of data per vertex
284 var count: Int
285
286 protected var glfloat_array: GLfloatArray
287
288 init(index, count: Int, array: Array[Float])
289 do
290 self.index = index
291 self.count = count
292 self.glfloat_array = new GLfloatArray(array)
293 end
294
295 fun attrib_pointer do attrib_pointer_intern(index, count, glfloat_array)
296 private fun attrib_pointer_intern(index, count: Int, array: GLfloatArray) `{
297 glVertexAttribPointer(index, count, GL_FLOAT, GL_FALSE, 0, array);
298 `}
299
300 fun enable do enable_intern(index)
301 private fun enable_intern(index: Int) `{ glEnableVertexAttribArray(index); `}
302
303 fun draw_arrays_triangles do draw_arrays_triangles_intern(index, count)
304 private fun draw_arrays_triangles_intern(index, count: Int) `{
305 glDrawArrays(GL_TRIANGLES, index, count);
306 `}
307 end
308
309 # Low level array of `Float`
310 extern class GLfloatArray `{GLfloat *`}
311 new (array: Array[Float]) import Array[Float].length, Array[Float].[] `{
312 int i;
313 int len = Array_of_Float_length(array);
314 GLfloat *vertex_array = malloc(sizeof(GLfloat)*len);
315 for (i = 0; i < len; i ++) vertex_array[i] = Array_of_Float__index(array, i);
316 return vertex_array;
317 `}
318 end
319
320 # General type for OpenGL enumerations
321 extern class GLEnum `{ GLenum `}
322
323 redef fun hash `{ return recv; `}
324
325 redef fun ==(o) do return o != null and is_same_type(o) and o.hash == self.hash
326 end
327
328 # An OpenGL ES 2.0 error code
329 extern class GLError
330 super GLEnum
331
332 # Is there no error?
333 fun is_ok: Bool do return is_no_error
334
335 # Is this not an error?
336 fun is_no_error: Bool `{ return recv == GL_NO_ERROR; `}
337
338 fun is_invalid_enum: Bool `{ return recv == GL_INVALID_ENUM; `}
339 fun is_invalid_value: Bool `{ return recv == GL_INVALID_VALUE; `}
340 fun is_invalid_operation: Bool `{ return recv == GL_INVALID_OPERATION; `}
341 fun is_invalid_framebuffer_operation: Bool `{ return recv == GL_INVALID_FRAMEBUFFER_OPERATION; `}
342 fun is_out_of_memory: Bool `{ return recv == GL_OUT_OF_MEMORY; `}
343
344 redef fun to_s
345 do
346 if is_no_error then return "No error"
347 if is_invalid_enum then return "Invalid enum"
348 if is_invalid_value then return "Invalid value"
349 if is_invalid_operation then return "Invalid operation"
350 if is_invalid_framebuffer_operation then return "invalid framebuffer operation"
351 if is_out_of_memory then return "Out of memory"
352 return "Truely unknown error"
353 end
354 end
355
356 protected fun assert_no_gl_error
357 do
358 var error = gl.error
359 if not error.is_ok then
360 print "GL error: {error}"
361 abort
362 end
363 end
364
365 # Texture minifying function
366 #
367 # Used by: `GLES::tex_parameter_min_filter`
368 extern class GLTextureMinFilter
369 super GLEnum
370
371 new nearest `{ return GL_NEAREST; `}
372 new linear `{ return GL_LINEAR; `}
373 end
374
375 # Texture magnification function
376 #
377 # Used by: `GLES::tex_parameter_mag_filter`
378 extern class GLTextureMagFilter
379 super GLEnum
380
381 new nearest `{ return GL_NEAREST; `}
382 new linear `{ return GL_LINEAR; `}
383 new nearest_mipmap_nearest `{ return GL_NEAREST_MIPMAP_NEAREST; `}
384 new linear_mipmap_nearest `{ return GL_LINEAR_MIPMAP_NEAREST; `}
385 new nearest_mipmap_linear `{ return GL_NEAREST_MIPMAP_LINEAR; `}
386 new linear_mipmap_linear `{ return GL_LINEAR_MIPMAP_LINEAR; `}
387 end
388
389 # Wrap parameter of a texture
390 #
391 # Used by: `tex_parameter_wrap_*`
392 extern class GLTextureWrap
393 super GLEnum
394
395 new clamp_to_edge `{ return GL_CLAMP_TO_EDGE; `}
396 new mirrored_repeat `{ return GL_MIRRORED_REPEAT; `}
397 new repeat `{ return GL_REPEAT; `}
398 end
399
400 # Target texture
401 #
402 # Used by: `tex_parameter_*`
403 extern class GLTextureTarget
404 super GLEnum
405
406 new flat `{ return GL_TEXTURE_2D; `}
407 new cube_map `{ return GL_TEXTURE_CUBE_MAP; `}
408 end
409
410 # A server-side capability
411 class GLCap
412
413 # TODO private init
414
415 # Internal OpenGL integer for this capability
416 private var val: Int
417
418 # Enable this server-side capability
419 fun enable do enable_native(val)
420 private fun enable_native(cap: Int) `{ glEnable(cap); `}
421
422 # Disable this server-side capability
423 fun disable do disable_native(val)
424 private fun disable_native(cap: Int) `{ glDisable(cap); `}
425
426 redef fun hash do return val
427 redef fun ==(o) do return o != null and is_same_type(o) and o.hash == self.hash
428 end
429 redef class Sys
430 private var gles = new GLES is lazy
431 end
432
433 # Entry points to OpenGL ES 2.0 services
434 fun gl: GLES do return sys.gles
435
436 # OpenGL ES 2.0 services
437 class GLES
438
439 # Clear the color buffer to `red`, `green`, `blue` and `alpha`
440 fun clear_color(red, green, blue, alpha: Float) `{
441 glClearColor(red, green, blue, alpha);
442 `}
443
444 # Set the viewport
445 fun viewport(x, y, width, height: Int) `{ glViewport(x, y, width, height); `}
446
447 # Specify mapping of depth values from normalized device coordinates to window coordinates
448 #
449 # Default at `gl_depth_range(0.0, 1.0)`
450 fun depth_range(near, far: Float) `{ glDepthRangef(near, far); `}
451
452 # Define front- and back-facing polygons
453 #
454 # Front-facing polygons are clockwise if `value`, counter-clockwise otherwise.
455 fun front_face=(value: Bool) `{ glFrontFace(value? GL_CW: GL_CCW); `}
456
457 # Specify whether front- or back-facing polygons can be culled, default is `back` only
458 #
459 # One or both of `front` or `back` must be `true`. If you want to deactivate culling
460 # use `(new GLCap.cull_face).disable`.
461 #
462 # Require: `front or back`
463 fun cull_face(front, back: Bool)
464 do
465 assert not (front or back)
466 cull_face_native(front, back)
467 end
468
469 private fun cull_face_native(front, back: Bool) `{
470 glCullFace(front? back? GL_FRONT_AND_BACK: GL_BACK: GL_FRONT);
471 `}
472
473 # Clear the `buffer`
474 fun clear(buffer: GLBuffer) `{ glClear(buffer); `}
475
476 # Last error from OpenGL ES 2.0
477 fun error: GLError `{ return glGetError(); `}
478
479 # Query the boolean value at `key`
480 private fun get_bool(key: Int): Bool `{
481 GLboolean val;
482 glGetBooleanv(key, &val);
483 return val == GL_TRUE;
484 `}
485
486 # Query the floating point value at `key`
487 private fun get_float(key: Int): Float `{
488 GLfloat val;
489 glGetFloatv(key, &val);
490 return val;
491 `}
492
493 # Query the integer value at `key`
494 private fun get_int(key: Int): Int `{
495 GLint val;
496 glGetIntegerv(key, &val);
497 return val;
498 `}
499
500 # Does this driver support shader compilation?
501 #
502 # Should always return `true` in OpenGL ES 2.0 and 3.0.
503 fun shader_compiler: Bool do return get_bool(0x8DFA)
504
505 # Enable or disable writing into the depth buffer
506 fun depth_mask(value: Bool) `{ glDepthMask(value); `}
507
508 # Set the scale and units used to calculate depth values
509 fun polygon_offset(factor, units: Float) `{ glPolygonOffset(factor, units); `}
510
511 # Specify the width of rasterized lines
512 fun line_width(width: Float) `{ glLineWidth(width); `}
513
514 # Set the pixel arithmetic for the blending operations
515 #
516 # Defaultvalues before assignation:
517 # * `src_factor`: `GLBlendFactor::one`
518 # * `dst_factor`: `GLBlendFactor::zero`
519 fun blend_func(src_factor, dst_factor: GLBlendFactor) `{
520 glBlendFunc(src_factor, dst_factor);
521 `}
522
523 # Specify the value used for depth buffer comparisons
524 #
525 # Default value is `GLDepthFunc::less`
526 #
527 # Foreign: glDepthFunc
528 fun depth_func(func: GLDepthFunc) `{ glDepthFunc(func); `}
529
530 # Copy a block of pixels from the framebuffer of `fomat` and `typ` at `data`
531 #
532 # Foreign: glReadPixel
533 fun read_pixels(x, y, width, height: Int, format: GLPixelFormat, typ: GLPixelType, data: Pointer) `{
534 glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
535 `}
536
537 # Set the texture minifying function
538 #
539 # Foreign: glTexParameter with GL_TEXTURE_MIN_FILTER
540 fun tex_parameter_min_filter(target: GLTextureTarget, value: GLTextureMinFilter) `{
541 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, value);
542 `}
543
544 # Set the texture magnification function
545 #
546 # Foreign: glTexParameter with GL_TEXTURE_MAG_FILTER
547 fun tex_parameter_mag_filter(target: GLTextureTarget, value: GLTextureMagFilter) `{
548 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, value);
549 `}
550
551 # Set the texture wrap parameter for coordinates _s_
552 #
553 # Foreign: glTexParameter with GL_TEXTURE_WRAP_S
554 fun tex_parameter_wrap_s(target: GLTextureTarget, value: GLTextureWrap) `{
555 glTexParameteri(target, GL_TEXTURE_WRAP_S, value);
556 `}
557
558 # Set the texture wrap parameter for coordinates _t_
559 #
560 # Foreign: glTexParameter with GL_TEXTURE_WRAP_T
561 fun tex_parameter_wrap_t(target: GLTextureTarget, value: GLTextureWrap) `{
562 glTexParameteri(target, GL_TEXTURE_WRAP_T, value);
563 `}
564
565 # Render primitives from array data
566 #
567 # Foreign: glDrawArrays
568 fun draw_arrays(mode: GLDrawMode, from, count: Int) `{ glDrawArrays(mode, from, count); `}
569
570 # OpenGL server-side capabilities
571 var capabilities = new GLCapabilities is lazy
572 end
573
574 # Entry point to OpenGL server-side capabilities
575 class GLCapabilities
576
577 # GL capability: blend the computed fragment color values
578 #
579 # Foreign: GL_BLEND
580 fun blend: GLCap is lazy do return new GLCap(0x0BE2)
581
582 # GL capability: cull polygons based of their winding in window coordinates
583 #
584 # Foreign: GL_CULL_FACE
585 fun cull_face: GLCap is lazy do return new GLCap(0x0B44)
586
587 # GL capability: do depth comparisons and update the depth buffer
588 #
589 # Foreign: GL_DEPTH_TEST
590 fun depth_test: GLCap is lazy do return new GLCap(0x0B71)
591
592 # GL capability: dither color components or indices before they are written to the color buffer
593 #
594 # Foreign: GL_DITHER
595 fun dither: GLCap is lazy do return new GLCap(0x0BE2)
596
597 # GL capability: add an offset to depth values of a polygon fragment before depth test
598 #
599 # Foreign: GL_POLYGON_OFFSET_FILL
600 fun polygon_offset_fill: GLCap is lazy do return new GLCap(0x8037)
601
602 # GL capability: compute a temporary coverage value where each bit is determined by the alpha value at the corresponding location
603 #
604 # Foreign: GL_SAMPLE_ALPHA_TO_COVERAGE
605 fun sample_alpha_to_coverage: GLCap is lazy do return new GLCap(0x809E)
606
607 # GL capability: AND the fragment coverage with the temporary coverage value
608 #
609 # Foreign: GL_SAMPLE_COVERAGE
610 fun sample_coverage: GLCap is lazy do return new GLCap(0x80A0)
611
612 # GL capability: discard fragments that are outside the scissor rectangle
613 #
614 # Foreign: GL_SCISSOR_TEST
615 fun scissor_test: GLCap is lazy do return new GLCap(0x0C11)
616
617 # GL capability: do stencil testing and update the stencil buffer
618 #
619 # Foreign: GL_STENCIL_TEST
620 fun stencil_test: GLCap is lazy do return new GLCap(0x0B90)
621 end
622
623 # Float related data types of OpenGL ES 2.0 shaders
624 #
625 # Only data types supported by shader attributes, as seen with
626 # `GLProgram::active_attrib_type`.
627 extern class GLFloatDataType
628 super GLEnum
629
630 fun is_float: Bool `{ return recv == GL_FLOAT; `}
631 fun is_float_vec2: Bool `{ return recv == GL_FLOAT_VEC2; `}
632 fun is_float_vec3: Bool `{ return recv == GL_FLOAT_VEC3; `}
633 fun is_float_vec4: Bool `{ return recv == GL_FLOAT_VEC4; `}
634 fun is_float_mat2: Bool `{ return recv == GL_FLOAT_MAT2; `}
635 fun is_float_mat3: Bool `{ return recv == GL_FLOAT_MAT3; `}
636 fun is_float_mat4: Bool `{ return recv == GL_FLOAT_MAT4; `}
637
638 # Instances of `GLFloatDataType` can be equal to instances of `GLDataType`
639 redef fun ==(o)
640 do
641 return o != null and o isa GLFloatDataType and o.hash == self.hash
642 end
643 end
644
645 # All data types of OpenGL ES 2.0 shaders
646 #
647 # These types can be used by shader uniforms, as seen with
648 # `GLProgram::active_uniform_type`.
649 extern class GLDataType
650 super GLFloatDataType
651
652 fun is_int: Bool `{ return recv == GL_INT; `}
653 fun is_int_vec2: Bool `{ return recv == GL_INT_VEC2; `}
654 fun is_int_vec3: Bool `{ return recv == GL_INT_VEC3; `}
655 fun is_int_vec4: Bool `{ return recv == GL_INT_VEC4; `}
656 fun is_bool: Bool `{ return recv == GL_BOOL; `}
657 fun is_bool_vec2: Bool `{ return recv == GL_BOOL_VEC2; `}
658 fun is_bool_vec3: Bool `{ return recv == GL_BOOL_VEC3; `}
659 fun is_bool_vec4: Bool `{ return recv == GL_BOOL_VEC4; `}
660 fun is_sampler_2d: Bool `{ return recv == GL_SAMPLER_2D; `}
661 fun is_sampler_cube: Bool `{ return recv == GL_SAMPLER_CUBE; `}
662 end
663
664 # Kind of primitives to render with `GLES::draw_arrays`
665 extern class GLDrawMode
666 super GLEnum
667
668 new points `{ return GL_POINTS; `}
669 new line_strip `{ return GL_LINE_STRIP; `}
670 new line_loop `{ return GL_LINE_LOOP; `}
671 new lines `{ return GL_LINES; `}
672 new triangle_strip `{ return GL_TRIANGLE_STRIP; `}
673 new triangle_fan `{ return GL_TRIANGLE_FAN; `}
674 new triangles `{ return GL_TRIANGLES; `}
675 end
676
677 # Pixel arithmetic for blending operations
678 #
679 # Used by `GLES::blend_func`
680 extern class GLBlendFactor
681 super GLEnum
682
683 new zero `{ return GL_ZERO; `}
684 new one `{ return GL_ONE; `}
685 new src_color `{ return GL_SRC_COLOR; `}
686 new one_minus_src_color `{ return GL_ONE_MINUS_SRC_COLOR; `}
687 new dst_color `{ return GL_DST_COLOR; `}
688 new one_minus_dst_color `{ return GL_ONE_MINUS_DST_COLOR; `}
689 new src_alpha `{ return GL_SRC_ALPHA; `}
690 new one_minus_src_alpha `{ return GL_ONE_MINUS_SRC_ALPHA; `}
691 new dst_alpha `{ return GL_DST_ALPHA; `}
692 new one_minus_dst_alpha `{ return GL_ONE_MINUS_DST_ALPHA; `}
693 new constant_color `{ return GL_CONSTANT_COLOR; `}
694 new one_minus_constant_color `{ return GL_ONE_MINUS_CONSTANT_COLOR; `}
695 new constant_alpha `{ return GL_CONSTANT_ALPHA; `}
696 new one_minus_constant_alpha `{ return GL_ONE_MINUS_CONSTANT_ALPHA; `}
697
698 # Used for destination only
699 new src_alpha_saturate `{ return GL_SRC_ALPHA_SATURATE; `}
700 end
701
702 # Condition under which a pixel will be drawn
703 #
704 # Used by `GLES::depth_func`
705 extern class GLDepthFunc
706 super GLEnum
707
708 new never `{ return GL_NEVER; `}
709 new less `{ return GL_LESS; `}
710 new equal `{ return GL_EQUAL; `}
711 new lequal `{ return GL_LEQUAL; `}
712 new greater `{ return GL_GREATER; `}
713 new not_equal `{ return GL_NOTEQUAL; `}
714 new gequal `{ return GL_GEQUAL; `}
715 new always `{ return GL_ALWAYS; `}
716 end
717
718 # Format of pixel data
719 #
720 # Used by `GLES::read_pixels`
721 extern class GLPixelFormat
722 super GLEnum
723
724 new alpha `{ return GL_ALPHA; `}
725 new rgb `{ return GL_RGB; `}
726 new rgba `{ return GL_RGBA; `}
727 end
728
729 # Data type of pixel data
730 #
731 # Used by `GLES::read_pixels`
732 extern class GLPixelType
733 super GLEnum
734
735 new unsigned_byte `{ return GL_UNSIGNED_BYTE; `}
736 new unsigned_short_5_6_5 `{ return GL_UNSIGNED_SHORT_5_6_5; `}
737 new unsigned_short_4_4_4_4 `{ return GL_UNSIGNED_SHORT_4_4_4_4; `}
738 new unsigned_short_5_5_5_1 `{ return GL_UNSIGNED_SHORT_5_5_5_1; `}
739 end
740
741 # Set of buffers as a bitwise OR mask, used by `GLES::clear`
742 #
743 # ~~~
744 # var buffers = (new GLBuffer).color.depth
745 # gl.clear buffers
746 # ~~~
747 extern class GLBuffer `{ GLbitfield `}
748 # Get an empty set of buffers
749 new `{ return 0; `}
750
751 # Add the color buffer to the returned buffer set
752 fun color: GLBuffer `{ return recv | GL_COLOR_BUFFER_BIT; `}
753
754 # Add the depth buffer to the returned buffer set
755 fun depth: GLBuffer `{ return recv | GL_DEPTH_BUFFER_BIT; `}
756
757 # Add the stencil buffer to the returned buffer set
758 fun stencil: GLBuffer `{ return recv | GL_STENCIL_BUFFER_BIT; `}
759 end