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