+# Specify a two-dimensional texture subimage
+fun glTexSubImage2D(target: GLTextureTarget,
+ level, xoffset, yoffset, width, height, border: Int,
+ format: GLPixelFormat, typ: GLDataType, data: Pointer) `{
+ glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, typ, data);
+`}
+
+# Copy pixels into a 2D texture image
+fun glCopyTexImage2D(target: GLTextureTarget, level: Int, internalformat: GLPixelFormat,
+ x, y, width, height, border: Int) `{
+ glCopyTexImage2D(target, level, internalformat, x, y, width, height, border);
+`}
+
+# Copy a two-dimensional texture subimage
+fun glCopyTexSubImage2D(target: GLTextureTarget, level, xoffset, yoffset, x, y, width, height: Int) `{
+ glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
+`}
+
+# Copy a block of pixels from the framebuffer of `fomat` and `typ` at `data`
+fun glReadPixels(x, y, width, height: Int, format: GLPixelFormat, typ: GLDataType, data: Pointer) `{
+ glReadPixels(x, y, width, height, format, typ, data);
+`}
+
+# Texture minifying and magnifying function
+extern class GLTexParameteri
+ super GLEnum
+end
+
+fun gl_NEAREST: GLTexParameteri `{ return GL_NEAREST; `}
+fun gl_LINEAR: GLTexParameteri `{ return GL_LINEAR; `}
+fun gl_NEAREST_MIPMAP_NEAREST: GLTexParameteri `{ return GL_NEAREST_MIPMAP_NEAREST; `}
+fun gl_LINEAR_MIPMAP_NEAREST: GLTexParameteri `{ return GL_LINEAR_MIPMAP_NEAREST; `}
+fun gl_NEAREST_MIPMAP_NINEAR: GLTexParameteri `{ return GL_NEAREST_MIPMAP_LINEAR; `}
+fun gl_LINEAR_MIPMAP_LINEAR: GLTexParameteri `{ return GL_LINEAR_MIPMAP_LINEAR; `}
+fun gl_CLAMP_TO_EDGE: GLTexParameteri `{ return GL_CLAMP_TO_EDGE; `}
+fun gl_MIRRORED_REPEAT: GLTexParameteri `{ return GL_MIRRORED_REPEAT; `}
+fun gl_REPEAT: GLTexParameteri `{ return GL_REPEAT; `}
+
+# Target texture
+extern class GLTextureTarget
+ super GLEnum
+end
+
+# Two-dimensional texture
+fun gl_TEXTURE_2D: GLTextureTarget `{ return GL_TEXTURE_2D; `}
+
+# Cube map texture
+fun gl_TEXTURE_CUBE_MAP: GLTextureTarget `{ return GL_TEXTURE_CUBE_MAP; `}
+
+# TODO GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
+# GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
+
+# A server-side capability
+class GLCap
+
+ # TODO private init
+
+ # Internal OpenGL integer for this capability
+ private var val: Int
+
+ # Enable this server-side capability
+ fun enable do enable_native(val)
+ private fun enable_native(cap: Int) `{ glEnable(cap); `}
+
+ # Disable this server-side capability
+ fun disable do disable_native(val)
+ private fun disable_native(cap: Int) `{ glDisable(cap); `}
+
+ redef fun hash do return val
+ redef fun ==(o) do return o != null and is_same_type(o) and o.hash == self.hash
+end
+
+# Generate `n` renderbuffer object names
+fun glGenRenderbuffers(n: Int): Array[Int]
+do
+ var array = new CIntArray(n)
+ native_glGenRenderbuffers(n, array.native_array)
+ var a = array.to_a
+ array.destroy
+ return a
+end
+
+private fun native_glGenRenderbuffers(n: Int, renderbuffers: NativeCIntArray) `{
+ glGenRenderbuffers(n, (GLuint *)renderbuffers);
+`}
+
+# Does `name` corresponds to a renderbuffer object?
+fun glIsRenderbuffer(name: Int): Bool `{
+ return glIsRenderbuffer(name);
+`}
+
+# Delete named renderbuffer objects
+fun glDeleteRenderbuffers(renderbuffers: SequenceRead[Int])
+do
+ var n = renderbuffers.length
+ var array = new CIntArray.from(renderbuffers)
+ native_glDeleteRenderbuffers(n, array.native_array)
+ array.destroy
+end
+
+private fun native_glDeleteRenderbuffers(n: Int, renderbuffers: NativeCIntArray) `{
+ return glDeleteRenderbuffers(n, (const GLuint *)renderbuffers);
+`}
+
+# Attach a renderbuffer object to a framebuffer object
+fun glFramebufferRenderbuffer(target: GLFramebufferTarget, attachment: GLAttachment,
+ renderbuffertarget: GLRenderbufferTarget, renderbuffer: Int) `{
+ glFramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer);
+`}
+
+# Establish data storage, `format` and dimensions of the `target` renderbuffer object's image
+fun glRenderbufferStorage(target: GLRenderbufferTarget, format: GLRenderbufferFormat, width, height: Int) `{
+ glRenderbufferStorage(GL_RENDERBUFFER, format, width, height);
+`}
+
+# Format for a renderbuffer
+extern class GLRenderbufferFormat
+ super GLEnum
+end
+
+# 4 red, 4 green, 4 blue, 4 alpha bits format
+fun gl_RGBA4: GLRenderbufferFormat `{ return GL_RGBA4; `}
+
+# 5 red, 6 green, 5 blue bits format
+fun gl_RGB565: GLRenderbufferFormat `{ return GL_RGB565; `}
+
+# 5 red, 5 green, 5 blue, 1 alpha bits format
+fun gl_RGB5_A1: GLRenderbufferFormat `{ return GL_RGB5_A1; `}
+
+# 16 depth bits format
+fun gl_DEPTH_COMPONENT16: GLRenderbufferFormat `{ return GL_DEPTH_COMPONENT16; `}
+
+# 8 stencil bits format
+fun gl_STENCIL_INDEX8: GLRenderbufferFormat `{ return GL_STENCIL_INDEX8; `}
+
+# Renderbuffer attachment point to a framebuffer
+extern class GLAttachment
+ super GLEnum
+end
+
+# First color attachment point
+fun gl_COLOR_ATTACHMENT0: GLAttachment `{ return GL_COLOR_ATTACHMENT0; `}
+
+# Depth attachment point
+fun gl_DEPTH_ATTACHMENT: GLAttachment `{ return GL_DEPTH_ATTACHMENT; `}
+
+# Stencil attachment
+fun gl_STENCIL_ATTACHMENT: GLAttachment `{ return GL_STENCIL_ATTACHMENT; `}
+
+redef class Sys
+ private var gles = new GLES is lazy
+end
+
+# Entry points to OpenGL ES 2.0 services
+fun gl: GLES do return sys.gles
+
+# OpenGL ES 2.0 services
+class GLES
+
+ # Query the boolean value at `key`
+ private fun get_bool(key: Int): Bool `{
+ GLboolean val;
+ glGetBooleanv(key, &val);
+ return val == GL_TRUE;
+ `}
+
+ # Query the floating point value at `key`
+ private fun get_float(key: Int): Float `{
+ GLfloat val;
+ glGetFloatv(key, &val);
+ return val;
+ `}
+
+ # Query the integer value at `key`
+ private fun get_int(key: Int): Int `{
+ GLint val;
+ glGetIntegerv(key, &val);
+ return val;
+ `}
+
+ # Does this driver support shader compilation?
+ #
+ # Should always return `true` in OpenGL ES 2.0 and 3.0.
+ fun shader_compiler: Bool do return get_bool(0x8DFA)
+
+ # OpenGL server-side capabilities
+ var capabilities = new GLCapabilities is lazy
+end
+
+# Specify the clear values for the color buffer, default values are at 0.0
+fun glClearColor(red, green, blue, alpha: Float) `{
+ glClearColor(red, green, blue, alpha);
+`}
+
+# Specify the clear `value` for the depth buffer, default at 1.0
+fun glClearDepthf(value: Float) `{ glClearDepthf(value); `}
+
+# Specify the clear `value` for the stencil buffer, default at 0
+fun glClearStencil(value: Int) `{ glClearStencil(value); `}
+
+# Clear the `buffer`
+fun glClear(buffer: GLBuffer) `{ glClear(buffer); `}
+
+# Enable and disable writing of frame buffer color components
+fun glColorMask(red, green, blue, alpha: Bool) `{ glColorMask(red, green, blue, alpha); `}
+
+# Set the viewport
+fun glViewport(x, y, width, height: Int) `{ glViewport(x, y, width, height); `}
+
+# Block until all GL execution is complete
+fun glFinish `{ glFinish(); `}
+
+# Force execution of GL commands in finite time
+fun glFlush `{ glFlush(); `}
+
+# Set texture parameters
+fun glTexParameteri(target: GLTextureTarget, pname: GLTexParameteriName, param: GLTexParameteri) `{
+ glTexParameteri(target, pname, param);