end
import android::aware
+intrude import c
in "C Header" `{
#include <GLES2/gl2.h>
# Number of data per vertex
var count: Int
- protected var glfloat_array: GLfloatArray
+ protected var glfloat_array: NativeGLfloatArray
init(index, count: Int, array: Array[Float])
do
self.index = index
self.count = count
- self.glfloat_array = new GLfloatArray(array)
+ self.glfloat_array = new NativeGLfloatArray(array.length)
+ for k in [0..array.length[ do
+ glfloat_array[k] = array[k]
+ end
end
fun attrib_pointer do attrib_pointer_intern(index, count, glfloat_array)
- private fun attrib_pointer_intern(index, count: Int, array: GLfloatArray) `{
+ private fun attrib_pointer_intern(index, count: Int, array: NativeGLfloatArray) `{
glVertexAttribPointer(index, count, GL_FLOAT, GL_FALSE, 0, array);
`}
end
# Low level array of `Float`
-extern class GLfloatArray `{GLfloat *`}
- new (array: Array[Float]) import Array[Float].length, Array[Float].[] `{
- int i;
- int len = Array_of_Float_length(array);
- GLfloat *vertex_array = malloc(sizeof(GLfloat)*len);
- for (i = 0; i < len; i ++) vertex_array[i] = Array_of_Float__index(array, i);
- return vertex_array;
- `}
+class GLfloatArray
+ super CArray[Float]
+ redef type NATIVE: NativeGLfloatArray
+
+ init do native_array = new NativeGLfloatArray(length)
+
+ # Create with the content of `array`
+ new from(array: Array[Float])
+ do
+ var arr = new GLfloatArray(array.length)
+ arr.fill_from array
+ return arr
+ end
+
+ # Fill with the content of `array`
+ fun fill_from(array: Array[Float])
+ do
+ assert length >= array.length
+ for k in [0..array.length[ do
+ self[k] = array[k]
+ end
+ end
+end
+
+# An array of `GLfloat` in C (`GLfloat*`)
+extern class NativeGLfloatArray `{ GLfloat* `}
+ super NativeCArray
+ redef type E: Float
+
+ new(size: Int) `{ return calloc(size, sizeof(GLfloat)); `}
+
+ redef fun [](index) `{ return self[index]; `}
+ redef fun []=(index, val) `{ self[index] = val; `}
+
+ redef fun +(offset) `{ return self + offset; `}
end
# General type for OpenGL enumerations
end
end
-# Texture minifying function
-#
-# Used by: `GLES::tex_parameter_min_filter`
-extern class GLTextureMinFilter
- super GLEnum
+# Does `name` corresponds to a texture?
+fun glIsTexture(name: Int): Bool `{ return glIsTexture(name); `}
- new nearest `{ return GL_NEAREST; `}
- new linear `{ return GL_LINEAR; `}
-end
+# Bind the named `texture` to a `target`
+fun glBindTexture(target: GLTextureTarget, texture: Int) `{ glBindTexture(target, texture); `}
-# Texture magnification function
-#
-# Used by: `GLES::tex_parameter_mag_filter`
-extern class GLTextureMagFilter
+# Texture minifying and magnifying function
+extern class GLTextureFilter
super GLEnum
-
- new nearest `{ return GL_NEAREST; `}
- new linear `{ return GL_LINEAR; `}
- new nearest_mipmap_nearest `{ return GL_NEAREST_MIPMAP_NEAREST; `}
- new linear_mipmap_nearest `{ return GL_LINEAR_MIPMAP_NEAREST; `}
- new nearest_mipmap_linear `{ return GL_NEAREST_MIPMAP_LINEAR; `}
- new linear_mipmap_linear `{ return GL_LINEAR_MIPMAP_LINEAR; `}
end
+fun gl_NEAREST: GLTextureFilter `{ return GL_NEAREST; `}
+fun gl_LINEAR: GLTextureFilter `{ return GL_LINEAR; `}
+fun gl_NEAREST_MIPMAP_NEAREST: GLTextureFilter `{ return GL_NEAREST_MIPMAP_NEAREST; `}
+fun gl_LINEAR_MIPMAP_NEAREST: GLTextureFilter `{ return GL_LINEAR_MIPMAP_NEAREST; `}
+fun gl_NEAREST_MIPMAP_NINEAR: GLTextureFilter `{ return GL_NEAREST_MIPMAP_LINEAR; `}
+fun gl_LINEAR_MIPMAP_LINEAR: GLTextureFilter `{ return GL_LINEAR_MIPMAP_LINEAR; `}
+
# Wrap parameter of a texture
#
# Used by: `tex_parameter_wrap_*`
redef fun hash do return val
redef fun ==(o) do return o != null and is_same_type(o) and o.hash == self.hash
end
+
+# Attach a renderbuffer object to a framebuffer object
+fun glFramebufferRenderbuffer(target: GLFramebufferTarget, attachment: GLAttachment,
+ renderbuffertarget: GLRenderbufferTarget, renderbuffer: Int) `{
+ glFramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer);
+`}
+
+# 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
#
# Foreign: glReadPixel
fun read_pixels(x, y, width, height: Int, format: GLPixelFormat, typ: GLPixelType, data: Pointer) `{
- glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
+ glReadPixels(x, y, width, height, format, typ, data);
`}
# Set the texture minifying function
#
# Foreign: glTexParameter with GL_TEXTURE_MIN_FILTER
- fun tex_parameter_min_filter(target: GLTextureTarget, value: GLTextureMinFilter) `{
+ fun tex_parameter_min_filter(target: GLTextureTarget, value: GLTextureFilter) `{
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, value);
`}
# Set the texture magnification function
#
# Foreign: glTexParameter with GL_TEXTURE_MAG_FILTER
- fun tex_parameter_mag_filter(target: GLTextureTarget, value: GLTextureMagFilter) `{
+ fun tex_parameter_mag_filter(target: GLTextureTarget, value: GLTextureFilter) `{
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, value);
`}
glHint(target, mode);
`}
+# Generate and fill set of mipmaps for the texture object `target`
+fun glGenerateMipmap(target: GLTextureTarget) `{ glGenerateMipmap(target); `}
+
+# Bind the named `buffer` object
+fun glBindBuffer(target: GLArrayBuffer, buffer: Int) `{ glBindBuffer(target, buffer); `}
+
+# Target to which bind the buffer with `glBindBuffer`
+extern class GLArrayBuffer
+ super GLEnum
+end
+
+# Array buffer target
+fun gl_ARRAY_BUFFER: GLArrayBuffer `{ return GL_ARRAY_BUFFER; `}
+
+# Element array buffer
+fun gl_ELEMENT_ARRAY_BUFFER: GLArrayBuffer `{ return GL_ELEMENT_ARRAY_BUFFER; `}
+
# Completeness status of a framebuffer object
fun glCheckFramebufferStatus(target: GLFramebufferTarget): GLFramebufferStatus `{
return glCheckFramebufferStatus(target);