diff --git a/bld.inf b/bld.inf new file mode 100644 index 0000000..dc888a8 --- /dev/null +++ b/bld.inf @@ -0,0 +1,4 @@ +PRJ_PLATFORMS +DEFAULT -ARM4 -THUMB +PRJ_MMPFILES +gles.mmp diff --git a/debian/README.Debian b/debian/README.Debian new file mode 100644 index 0000000..b1f17bc --- /dev/null +++ b/debian/README.Debian @@ -0,0 +1,6 @@ +python-opengles for Debian +-------------------------- + + + + -- unknown , Mon, 4 Jun 2007 23:33:28 +0300 diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..1f651aa --- /dev/null +++ b/debian/changelog @@ -0,0 +1,6 @@ +python-opengles (0.1-1) unstable; urgency=low + + * Initial Release. + + -- unknown Mon, 4 Jun 2007 23:33:28 +0300 + diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..b8626c4 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +4 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..995578b --- /dev/null +++ b/debian/control @@ -0,0 +1,12 @@ +Source: python-opengles +Section: unknown +Priority: optional +Maintainer: unknown +Build-Depends: debhelper (>= 4.0.0), libgles1-dev +Standards-Version: 3.6.1 + +Package: python-opengles +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, libgles1 +Description: + diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..21e4929 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,12 @@ +This package was debianized by unknown on +Mon, 4 Jun 2007 23:33:28 +0300. + +It was downloaded from + +Copyright: + +Upstream Author(s): + +License: + + diff --git a/debian/dirs b/debian/dirs new file mode 100644 index 0000000..ca882bb --- /dev/null +++ b/debian/dirs @@ -0,0 +1,2 @@ +usr/bin +usr/sbin diff --git a/debian/docs b/debian/docs new file mode 100644 index 0000000..e69de29 diff --git a/debian/files b/debian/files new file mode 100644 index 0000000..b19bba7 --- /dev/null +++ b/debian/files @@ -0,0 +1 @@ +python-opengles_0.1-1_armel.deb unknown optional diff --git a/debian/python-opengles.substvars b/debian/python-opengles.substvars new file mode 100644 index 0000000..75ed21c --- /dev/null +++ b/debian/python-opengles.substvars @@ -0,0 +1,2 @@ +python:Depends=python (>= 2.3), python (<< 2.4) +shlibs:Depends=libc6 (>= 2.3.5-1), python2.5 diff --git a/debian/rules b/debian/rules new file mode 100644 index 0000000..ca0e6f8 --- /dev/null +++ b/debian/rules @@ -0,0 +1,98 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + + + +PYTHON = python2.5 +CFLAGS = -Wall -g + +ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) + CFLAGS += -O0 +else + CFLAGS += -O2 +endif + +configure: configure-stamp +configure-stamp: + dh_testdir + # Add here commands to configure the package. + + touch configure-stamp + + +build: build-stamp + +build-stamp: configure-stamp + dh_testdir + + # Add here commands to compile the package. + $(PYTHON) setup.py build + #docbook-to-man debian/python-opengles.sgml > python-opengles.1 + + touch build-stamp + +clean: + dh_testdir + dh_testroot + rm -f build-stamp configure-stamp + + # Add here commands to clean up after the build process. + -$(PYTHON) setup.py clean + + dh_clean + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + # Add here commands to install the package into debian/python-opengles. + $(PYTHON) setup.py install --prefix=$(CURDIR)/debian/python-opengles/usr + + +# Build architecture-independent files here. +binary-indep: build install +# We have nothing to do by default. + +# Build architecture-dependent files here. +binary-arch: build install + dh_testdir + dh_testroot + dh_installchangelogs + dh_installdocs + dh_installexamples +# dh_install +# dh_installmenu +# dh_installdebconf +# dh_installlogrotate +# dh_installemacsen +# dh_installpam +# dh_installmime +# dh_installinit +# dh_installcron +# dh_installinfo + dh_installman + dh_link + dh_strip + dh_compress + dh_fixperms +# dh_perl + dh_python +# dh_makeshlibs + dh_installdeb + dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install configure diff --git a/gles_util.c b/gles_util.c new file mode 100644 index 0000000..52d180e --- /dev/null +++ b/gles_util.c @@ -0,0 +1,728 @@ +/** + * ==================================================================== + * gles_util.h + * + * Copyright (c) 2006 Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "glesmodule.h" + +static GLES_Arrays *arrayData; + +int gles_PySequence_Dimension(PyObject *seq) { + assert(PySequence_Check(seq)); + PyObject *item = PySequence_GetItem(seq, 0); + if( !PySequence_Check(item) ) { + return -1; + } + // The dimension is determined from the lenght of the first element + int dimension = PySequence_Length(item); + return dimension; +} + +/** + * Convert a freely structured sequence into a flat sequence + * Also converts data to the given type. + * + * @param type Can be one of: GL_FLOAT, GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT, GL_FIXED. + * @param source A Python sequence where the data is read from. + * @param target A pointer to an existing target sequence. If NULL, a new sequence is created. + * @return A collapsed sequence. + */ +PyObject *gles_PySequence_Collapse(GLenum type, PyObject *source, PyObject *target) +{ + int count; + int i; + PyObject *k; + + // We need a sequence to operate. + if(!PySequence_Check(source)) { + PyErr_SetString(PyExc_TypeError, "Expecting a sequence"); + return NULL; + } + + // Make a new list if not supplied by caller. + if(target == NULL) { + target = PyList_New(0); + if(!target) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + } + + count = PySequence_Length(source); + for(i=0; i < count; i++) { + k = PySequence_GetItem(source, i); + // See if its a sequence. Strings are sequences too, but we should ignore them here. + if(PySequence_Check(k) && !PyString_Check(k)) { + // Call a new function go get the contents of the sequence. + if(gles_PySequence_Collapse(type, k, target) == NULL) { + // There should be an exception + assert(PyErr_Occurred() != NULL); + return NULL; + } + } else { + assert(k != NULL); + if(!PyNumber_Check(k)) { + PyErr_SetString(PyExc_TypeError, "Expecting a number"); + return NULL; + } + + // Try to convert the object into desired type. + // Using the number interface we can handle all + // types that can be converted into a number. + PyObject *t=NULL; + switch(type) { + case GL_FLOAT: + k = PyNumber_Float(k); + if(k==NULL) { + // Something went wrong with the conversion. + assert(PyErr_Occurred() != NULL); + return NULL; + } + t = Py_BuildValue("f", PyFloat_AsDouble(k)); + break; + case GL_SHORT: + k = PyNumber_Int(k); + if(k==NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + t = Py_BuildValue("h", PyInt_AsLong(k)); + break; + case GL_UNSIGNED_SHORT: + k = PyNumber_Int(k); + if(k==NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + t = Py_BuildValue("H", PyInt_AsLong(k)); + break; + case GL_BYTE: + k = PyNumber_Int(k); + if(k==NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + t = Py_BuildValue("b", PyInt_AsLong(k)); + break; + case GL_UNSIGNED_BYTE: + k = PyNumber_Int(k); + if(k==NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + t = Py_BuildValue("B", PyInt_AsLong(k)); + break; + case GL_FIXED: + k = PyNumber_Int(k); + if(k==NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + t = Py_BuildValue("i", PyInt_AsLong(k)); + break; + default: + PyErr_SetString(PyExc_TypeError, "Invalid type for conversion"); + return NULL; + } + if(t == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + // Add item to target. + PyList_Append(target, t); + } + } + + return target; +} + +/** + * Place given array into internal memory structure + * + * If there already is something in memory, it will be freed, + * if the memory does not belong to an array object + * + * @param targetarr Specifies where the given array should be placed in internal memory. Can be one of: GL_VERTEX_ARRAY, GL_NORMAL_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY. + * @param *ptr Pointer to an array. + * @param object Python object of type gles.array. Can be NULL, in which case the memory will be freed when the next array is placed in the same location. + * @return The given pointer +*/ +void *gles_assign_array(GLenum targetarr, void *ptr, array_object *object) { + //GLES_Arrays *arrays = (GLES_Arrays*)Dll::Tls(); + gles_array_t *arrptr; + + assert(arrayData!=NULL); + + // Get the array from internal struct. + switch(targetarr) { + case GL_VERTEX_ARRAY: + arrptr = &(arrayData->vertex); +#ifdef DEBUG_GLES + DEBUGMSG("Assigning GL_VERTEX_ARRAY\n"); +#endif + break; + case GL_NORMAL_ARRAY: + arrptr = &(arrayData->normal); +#ifdef DEBUG_GLES + DEBUGMSG("Assigning GL_NORMAL_ARRAY\n"); +#endif + break; + case GL_COLOR_ARRAY: + arrptr = &(arrayData->color); +#ifdef DEBUG_GLES + DEBUGMSG("Assigning GL_COLOR_ARRAY\n"); +#endif + break; + case GL_TEXTURE_COORD_ARRAY: + arrptr = &(arrayData->texcoord); +#ifdef DEBUG_GLES + DEBUGMSG("Assigning GL_TEXTURE_COORD_ARRAY\n"); +#endif + break; +#ifdef GL_OES_VERSION_1_1 + case GL_MATRIX_INDEX_ARRAY_OES: + arrptr = &(arrayData->matrix); +#ifdef DEBUG_GLES + DEBUGMSG("Assigning GL_MATRIX_INDEX_ARRAY_OES\n"); +#endif + break; + case GL_POINT_SIZE_ARRAY_OES: + arrptr = &(arrayData->pointsize); +#ifdef DEBUG_GLES + DEBUGMSG("Assigning GL_POINT_SIZE_ARRAY_OES\n"); +#endif + break; + case GL_WEIGHT_ARRAY_OES: + arrptr = &(arrayData->weight); +#ifdef DEBUG_GLES + DEBUGMSG("Assigning GL_WEIGHT_ARRAY_OES\n"); +#endif + break; +#endif + default: + return NULL; + } + // Set the previous array free + gles_free_array(targetarr); + + // See if we got a new object + if(object != NULL) { + arrptr->obj = (PyObject*)object; + Py_XINCREF(object); + arrptr->ptr = object->arrdata; + } // Otherwise just take the pointer into custody + else { + arrptr->obj = NULL; + arrptr->ptr = ptr; + } + + return arrptr->ptr; +} + +/** + * Convert a Python sequence to a float array + * + * @param seq A Python sequence object + * @return A pointer to a C array of GLfloat values + */ +GLfloat *gles_PySequence_AsGLfloatArray(PyObject *seq) { + int count; + GLfloat *dataptr; + int i; + PyObject *item; + + if(! PySequence_Check(seq)) { + PyErr_SetString(PyExc_TypeError, "Invalid type"); + return NULL; + } + + count = PySequence_Length(seq); + dataptr = (GLfloat*)gles_alloc( sizeof(GLfloat)*count); + if(dataptr == NULL) { + return (GLfloat*)PyErr_NoMemory(); + } + + for( i = 0; i < count; i++ ) { + item = PySequence_GetItem(seq, i); + if( !PyFloat_Check(item) ) { + PyErr_SetString(PyExc_TypeError, "Expecting a float"); + return NULL; + } + dataptr[i] = (GLfloat)PyFloat_AsDouble(item); + } + + return dataptr; +} + +/** + * Convert a Python sequence into unsigned short array + * + * @param seq A Python sequence object + * @return A pointer to a C array of GLushort values + */ +GLushort *gles_PySequence_AsGLushortArray(PyObject *seq) { + int count; + GLushort *dataptr; + int i; + PyObject *item; + + if(! PySequence_Check(seq)) { + PyErr_SetString(PyExc_TypeError, "Expecting a sequence"); + return NULL; + } + + count = PySequence_Length(seq); + dataptr = (GLushort*)gles_alloc( sizeof(GLushort)*count); + if(dataptr == NULL) { + return (GLushort*)PyErr_NoMemory(); + } + + for( i = 0; i < count; i++ ) { + item = PySequence_GetItem(seq, i); + if( !PyInt_Check(item) ) { + gles_free(dataptr); + PyErr_SetString(PyExc_TypeError, "Expecting an integer"); + return NULL; + } + dataptr[i] = (GLushort)PyInt_AsLong(item); + } + + return dataptr; +} + +/** + * Convert a Python sequence into short array + * + * @param seq A Python sequence object + * @return A pointer to a C array of GLshort values + */ +GLshort *gles_PySequence_AsGLshortArray(PyObject *seq) { + int count; + GLshort *dataptr; + int i; + PyObject *item; + + if(! PySequence_Check(seq)) { + PyErr_SetString(PyExc_TypeError, "Expecting a sequence"); + return NULL; + } + + count = PySequence_Length(seq); + dataptr = (GLshort*)gles_alloc( sizeof(GLshort)*count); + if(dataptr == NULL) { + return (GLshort*)PyErr_NoMemory(); + } + + for( i = 0; i < count; i++ ) { + item = PySequence_GetItem(seq, i); + if( !PyInt_Check(item) ) { + gles_free(dataptr); + PyErr_SetString(PyExc_TypeError, "Expecting an integer"); + return NULL; + } + dataptr[i] = (GLshort)PyInt_AsLong(item); + } + + return dataptr; +} + +/** + * Convert a Python sequence into a byte array + * + * @param seq A Python sequence object + * @return A pointer to a C array of GLbyte values + */ +GLbyte *gles_PySequence_AsGLbyteArray(PyObject *seq) { + int count; + GLbyte *dataptr; + int i; + PyObject *item; + + if(! PySequence_Check(seq)) { + PyErr_SetString(PyExc_TypeError, "Invalid type"); + return NULL; + } + + count = PySequence_Length(seq); + dataptr = (GLbyte*)gles_alloc( sizeof(GLbyte)*count); + if(dataptr == NULL) { + return (GLbyte*)PyErr_NoMemory(); + } + + for( i = 0; i < count; i++ ) { + item = PySequence_GetItem(seq, i); + if( !PyInt_Check(item) ) { + // Free the indices. + gles_free(dataptr); + PyErr_SetString(PyExc_TypeError, "Expecting an integer"); + return NULL; + } + dataptr[i] = (GLbyte)PyInt_AsLong(item); + } + + return dataptr; +} + +/** + * Converts a Python sequence into unsigned byte array + * + * @param seq A Python sequence object + * @return A pointer to a C array of GLubyte values + */ +GLubyte *gles_PySequence_AsGLubyteArray(PyObject *seq) { + int count; + GLubyte *dataptr; + int i; + PyObject *item; + + if(! PySequence_Check(seq)) { + PyErr_SetString(PyExc_TypeError, "Invalid type"); + return NULL; + } + + count = PySequence_Length(seq); + dataptr = (GLubyte*)gles_alloc( sizeof(GLubyte)*count); + if(dataptr == NULL) { + return (GLubyte*)PyErr_NoMemory(); + } + + for( i = 0; i < count; i++ ) { + item = PySequence_GetItem(seq, i); + if( !PyInt_Check(item) ) { + // Free the indices + gles_free(dataptr); + PyErr_SetString(PyExc_TypeError, "Expecting an integer"); + return NULL; + } + dataptr[i] = (GLubyte)PyInt_AsLong(item); + } + + return dataptr; +} + +/** + * Converts a Python sequence into int array + * + * @param seq A Python sequence object + * @return A pointer to a C array of GLint values + */ +GLint *gles_PySequence_AsGLintArray(PyObject *seq) { + int count; + GLint *dataptr; + int i; + PyObject *item; + + if(! PySequence_Check(seq)) { + PyErr_SetString(PyExc_TypeError, "Invalid type"); + return NULL; + } + + count = PySequence_Length(seq); + dataptr = (GLint*)gles_alloc( sizeof(GLint)*count); + if(dataptr == NULL) { + return (GLint*)PyErr_NoMemory(); + } + + for( i = 0; i < count; i++ ) { + item = PySequence_GetItem(seq, i); + if( !PyInt_Check(item) ) { + // Free the indices + gles_free(dataptr); + PyErr_SetString(PyExc_TypeError, "Expecting an integer"); + return NULL; + } + dataptr[i] = (GLint)PyInt_AsLong(item); + } + + return dataptr; +} + +/** + * Converts a Python sequence into unsigned int array + * + * @param seq A Python sequence object + * @return A pointer to a C array of GLuint values + */ +GLuint *gles_PySequence_AsGLuintArray(PyObject *seq) { + int count; + GLuint *dataptr; + int i; + PyObject *item; + + if(! PySequence_Check(seq)) { + PyErr_SetString(PyExc_TypeError, "Invalid type"); + return NULL; + } + + count = PySequence_Length(seq); + dataptr = (GLuint*)gles_alloc( sizeof(GLuint)*count); + if(dataptr == NULL) { + return (GLuint*)PyErr_NoMemory(); + } + + for( i = 0; i < count; i++ ) { + item = PySequence_GetItem(seq, i); + if( !PyInt_Check(item) ) { + // Free the indices + gles_free(dataptr); + PyErr_SetString(PyExc_TypeError, "Expecting an integer"); + return NULL; + } + dataptr[i] = (GLuint)PyInt_AsLong(item); + } + + return dataptr; +} + +/** + * Converts a Python sequence into fixed array + * + * @param seq A Python sequence object + * @return A pointer to a C array of GLfixed values + */ +GLfixed *gles_PySequence_AsGLfixedArray(PyObject *seq) { + int count; + GLfixed *dataptr; + int i; + PyObject *item; + + if(! PySequence_Check(seq)) { + PyErr_SetString(PyExc_TypeError, "Invalid type"); + return NULL; + } + + count = PySequence_Length(seq); + dataptr = (GLfixed*)gles_alloc( sizeof(GLfixed)*count); + if(dataptr == NULL) { + return (GLfixed*)PyErr_NoMemory(); + } + + for( i = 0; i < count; i++ ) { + item = PySequence_GetItem(seq, i); + if( !PyInt_Check(item) ) { + // Free the indices + gles_free(dataptr); + PyErr_SetString(PyExc_TypeError, "Expecting an integer"); + return NULL; + } + dataptr[i] = (GLfixed)PyInt_AsLong(item); + } + + return dataptr; +} + +/** + * Frees all the internally used array memory + * + */ +void gles_uninit_arrays() { + //GLES_Arrays *arrayData; + //arrayData = (GLES_Arrays*)Dll::Tls(); + if(arrayData != NULL) { + gles_free_array(GL_VERTEX_ARRAY); + gles_free_array(GL_NORMAL_ARRAY); + gles_free_array(GL_COLOR_ARRAY); + gles_free_array(GL_TEXTURE_COORD_ARRAY); +#ifdef GL_OES_VERSION_1_1 + gles_free_array(GL_MATRIX_INDEX_ARRAY_OES); + gles_free_array(GL_POINT_SIZE_ARRAY_OES); + gles_free_array(GL_WEIGHT_ARRAY_OES); +#endif + gles_free(arrayData); + } +} + +/** + * Initializes internal arrays used for glXXXPointer data + * + */ +void gles_init_arrays() { + + + arrayData = (GLES_Arrays*)gles_alloc( sizeof(GLES_Arrays) ); + if(arrayData == NULL) { + PyErr_NoMemory(); + return; + } + + // Reset array pointers + arrayData->vertex.ptr = NULL; + arrayData->vertex.obj = NULL; + + arrayData->color.ptr = NULL; + arrayData->color.obj = NULL; + + arrayData->normal.ptr = NULL; + arrayData->normal.obj = NULL; + + arrayData->texcoord.ptr = NULL; + arrayData->texcoord.obj = NULL; + +#ifdef GL_OES_VERSION_1_1 + arrayData->matrix.ptr = NULL; + arrayData->matrix.obj = NULL; + + arrayData->pointsize.ptr = NULL; + arrayData->pointsize.obj = NULL; + + arrayData->weight.ptr = NULL; + arrayData->weight.obj = NULL; +#endif +} + +/** + * Frees a specified array from internal memory + * + * @param arrtype Which array to free. Can be one of: GL_VERTEX_ARRAY, GL_NORMAL_ARRAY, GL_COLOR_ARRAY or GL_TEXTURE_COORD_ARRAY. +*/ +void gles_free_array(GLenum arrtype) { + gles_array_t *arr=NULL; + switch(arrtype) { + case GL_VERTEX_ARRAY: + arr = &(arrayData->vertex); +#ifdef DEBUG_GLES + DEBUGMSG("gles_free_array() (VERTEX)"); +#endif + break; + case GL_NORMAL_ARRAY: + arr = &(arrayData->normal); +#ifdef DEBUG_GLES + DEBUGMSG("gles_free_array() (NORMAL)"); +#endif + break; + case GL_COLOR_ARRAY: + arr = &(arrayData->color); +#ifdef DEBUG_GLES + DEBUGMSG("gles_free_array() (COLOR)"); +#endif + break; + case GL_TEXTURE_COORD_ARRAY: + arr = &(arrayData->texcoord); +#ifdef DEBUG_GLES + DEBUGMSG("gles_free_array() (TEXTURE_COORD)"); +#endif + break; +#ifdef GL_OES_VERSION_1_1 + case GL_MATRIX_INDEX_ARRAY_OES: + arr = &(arrayData->matrix); +#ifdef DEBUG_GLES + DEBUGMSG("gles_free_array() (GL_MATRIX_INDEX_ARRAY_OES)"); +#endif + break; + case GL_POINT_SIZE_ARRAY_OES: + arr = &(arrayData->pointsize); +#ifdef DEBUG_GLES + DEBUGMSG("gles_free_array() (GL_POINT_SIZE_ARRAY_OES)"); +#endif + break; + case GL_WEIGHT_ARRAY_OES: + arr = &(arrayData->weight); +#ifdef DEBUG_GLES + DEBUGMSG("gles_free_array() (GL_WEIGHT_ARRAY_OES)"); +#endif + break; +#endif + default: + return; + } + + if(arr->obj != NULL) { + Py_XDECREF(arr->obj); + } else if(arr->ptr != NULL) { + gles_free(arr->ptr); + } + arr->ptr=NULL; +} + +/** + * Checks if an OpenGL error has occurred, and sets an exception if necessary. + * + * @return 1 if an OpenGL error has occurred, 0 otherwise + */ +unsigned int gles_check_error() { + GLenum error = GL_NO_ERROR; + + error = glGetError(); + if(error != GL_NO_ERROR) { + PyObject *exc; + exc = PyErr_NewException("gles.GLerror", NULL, NULL); + switch(error) { + case GL_INVALID_ENUM: + PyErr_Format(exc, "Invalid enum [Errno %x]", error); +#ifdef DEBUG_GLES + DEBUGMSG1("gles_check_error(): Invalid enum [Errno %x]", error); +#endif + break; + case GL_INVALID_VALUE: + PyErr_Format(exc, "Invalid value [Errno %x]", error); +#ifdef DEBUG_GLES + DEBUGMSG1("gles_check_error(): Invalid value [Errno %x]", error); +#endif + break; + case GL_INVALID_OPERATION: + PyErr_Format(exc, "Invalid operation [Errno %x]", error); +#ifdef DEBUG_GLES + DEBUGMSG1("gles_check_error(): Invalid operation [Errno %x]", error); +#endif + break; + case GL_STACK_OVERFLOW: + PyErr_Format(exc, "Stack overflow [Errno %x]", error); +#ifdef DEBUG_GLES + DEBUGMSG1("gles_check_error(): Stack overflow [Errno %x]", error); +#endif + break; + case GL_STACK_UNDERFLOW: + PyErr_Format(exc, "Stack underflow [Errno %x]", error); +#ifdef DEBUG_GLES + DEBUGMSG1("gles_check_error(): Stack underflow [Errno %x]", error); +#endif + break; + case GL_OUT_OF_MEMORY: + PyErr_NoMemory(); +#ifdef DEBUG_GLES + DEBUGMSG("gles_check_error(): Out of memory"); +#endif + break; + default: + PyErr_Format(PyExc_Exception, "Unknown error: %x", error ); +#ifdef DEBUG_GLES + DEBUGMSG1("gles_check_error(): Unknown error: %x", error); +#endif + break; + } + return 1; + } + return 0; +} + +/** + * Helper function for allocating memory + * + * @param size Size of desired memory block + * @return A pointer to a newly allocated block of memory + */ +void *gles_alloc(size_t size) { + return malloc(size); +} + +/** + * Helper function for freeing allocated memory + * + * @param ptr A pointer to a block of memory to be freed + */ +void gles_free(void *ptr) { + free(ptr); +} diff --git a/gles_utils.py b/gles_utils.py new file mode 100644 index 0000000..7a4e10e --- /dev/null +++ b/gles_utils.py @@ -0,0 +1,519 @@ +# +# ==================================================================== +# gles_utils.py - Utility functions for OpenGL ES +# +# Ported from the C++ utils +# +# Copyright (c) 2006 Nokia Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from gles import * +from math import * +import types + +try: + radians +except NameError: + def radians(degrees): + """Convert degrees to radians""" + return degrees * (pi/180) + +try: + degrees +except NameError: + def degrees(radians): + """Convert radians to degrees""" + return radians * (180/pi) + +def int2fixed(i): + """Convert an integer to fixed point""" + return i << 16 + +def float2fixed(v): + """Convert a float to fixed point""" + print "float2fixed" + print type(v) + print "v = %x" % (v) + ret = v*pow(2,16) + print "ret = %x" % (ret) + return int(ret) + +def fixed2float(v): + """Convert fixed to float""" + return v * (1/65536.0) + +def floats2fixed(values): + """Convert a sequence of floats to fixed point""" + return [float2fixed(v) for v in values] + +def fixed_mul(a, b): + """Multiply fixed values""" + return (a >> 8) * (b >> 8) +def fixed_div(a,b): + return ((a * (1/b)) * 65536.0) + +class TVector: + """A 3D vector that is represented by single-precision floating point x,y,z coordinates.""" + def __init__(self, aX=0.0, aY=0.0, aZ=0.0): + self.iX = aX + self.iY = aY + self.iZ = aZ + + def __add__(self, other): + # + operator + return TVector(self.iX + other.iX, self.iY + other.iY, self.iZ + other.iZ) + + def __iadd__(self, other): + # += operator + ret = self + other + self.iX = ret.aX + self.iY = ret.aY + self.iZ = ret.aZ + return ret + + def __sub__(self, other): + # - operator + return (self + (other * -1)) + + def __neg__(self): + # -self operator + return (self * -1) + + def __mul__(self, other): + # * operator + if isinstance(other, TVector): + return (self.iX * other.iX + self.iY * other.iY + self.iZ * other.iZ) + if type(other) in (types.FloatType,types.IntType): + return TVector(self.iX * other, self.iY * other, self.iZ * other) + + + def Magnitude(self): + # Calculate the magnitude of this vector. Standard trigonometric calculation: + # sqrt(x**2 + y**2 + z**2) + return sqrt(self * self) + + def Normalize(self): + # Normalizes this vector, Panics if this vector = (0, 0, 0) + magnitude = self.Magnitude() + if magnitude == 0: + return + self = self * (1 / magnitude) + + def CrossProduct(aVector1, aVector2): + # Computes the crossproduct of vector aVector1 and vector aVector2. + iX = aVector1.iY * aVector2.iZ - aVector1.iZ * aVector2.iY + iY = aVector1.iZ * aVector2.iX - aVector1.iX * aVector2.iZ + iZ = aVector1.iX * aVector2.iY - aVector1.iY * aVector2.iX + + return TVector(iX, iY, iZ) + +class TVectorx: + """A 3D vector that is represented by fixed-point x,y,z coordinates.""" + def __init__(self, aX=0, aY=0, aZ=0): + self.iX = int2fixed(int(aX)) + self.iY = int2fixed(int(aY)) + self.iZ = int2fixed(int(aZ)) + + def __add__(self, other): + # + operator + return TVectorx(self.iX + other.iX, self.iY + other.iY, self.iZ + other.iZ) + + def __iadd__(self, other): + # += operator + ret = self + other + self.iX = ret.aX + self.iY = ret.aY + self.iZ = ret.aZ + return ret + + def __sub__(self, other): + # - operator + return (self + (other * int2fixed(-1))) + + def __neg__(self): + # -self operator + return (self * int2fixed(-1)) + + def __mul__(self, other): + # * operator + if isinstance(other, TVectorx): + return (fixed_mul(self.iX, other.iX) + fixed_mul(self.iY, other.iY) + fixed_mul(self.iZ, other.iZ)) + if type(other) in (types.FloatType, types.IntType): + return TVectorx(fixed_mul(self.iX, other), fixed_mul(self.iY, other), fixed_mul(self.iZ, other)) + else: + raise TypeError("Unsupported type") + + def Magnitude(self): + # Calculate the magnitude of this vector. Standard trigonometric calculation: + # sqrt(x**2 + y**2 + z**2) + src = fixed2float(self * self) + #print src + return float2fixed(sqrt(src)) + + def Normalize(self): + # Normalizes the vector by dividing each component with the length of the vector. + magnitude = self.Magnitude() + #print magnitude + if magnitude == 0: + return + ret = self * float2fixed(1 / fixed2float(magnitude)) + self.iX = ret.aX + self.iY = ret.aY + self.iZ = ret.aZ + + def CrossProduct(aVector1, aVector2): + # Computes the crossproduct of vector aVector1 and vector aVector2. + iX = fixed_mul(aVector1.iY, aVector2.iZ) - fixed_mul(aVector1.iZ, aVector2.iY) + iY = fixed_mul(aVector1.iZ, aVector2.iX) - fixed_mul(aVector1.iX, aVector2.iZ) + iZ = fixed_mul(aVector1.iX, aVector2.iY) - fixed_mul(aVector1.iY, aVector2.iX) + return TVectorx(iX, iY, iZ) + +class FiniteStateMachine: + # An abstraction of a finite state machine + def __init__(self): + self.iState = None + self.iPrevState = None + def SetState(self, aNewState ): + # Set the current state and trigger OnEnterState. + if aNewState != -1: + if aNewState != self.iState: + if self.iPrevState != -1: + self.OnLeaveState( self.iState ) + self.iPrevState = self.iState + self.iState = aNewState + self.OnEnterState( self.iState ) + + def OnLeaveState( self, aState ): + # Empty implementation + pass + + def OnEnterState( self, iState ): + # Empty implementation + pass + +class TFlareConfig: + # Index of the texture used by this element. + #iIndex + # Length scaling. + #iLengthScale + # Texture scaling. + #iImageScale; + pass + +class CLensFlareEffect: + # An abstraction of a lens flare effect. + def __init__(self, aTextureNames, aFlareConfigs, aTextureManager, aScreenWidth, aScreenHeight): + self.iTextures = TTexture(len(aTextureNames)) + + self.iFlareConfigs = aFlareConfigs + #self.iFlareConfigCount = aFlareConfigCount + + self.iTextureManager = aTextureManager + + self.iCenterX = aScreenWidth>>1 + self.iCenterY = aScreenHeight>>1 + + def DrawAt(self, aLightX, aLightY): + # Renders the lens flare effect at a given screen coordinates. + # Uses the CTextureManager::Blit, which in turn draws two triangles (forming + # a single quad) + + # Computing the lens flare vector. + DirX = aLightX - iCenterX + DirY = aLightY - iCenterY + + #TReal Scale; + #TReal BlitCenterX, BlitCenterY; + #TReal BlitWidth_div_2, BlitHeight_div_2; + + glEnable( GL_BLEND ) + glBlendFunc(GL_ONE, GL_ONE) + glEnable( GL_TEXTURE_2D ) + + for i in range(len(self.iFlareConfigs)): + TextureIndex = self.iFlareConfigs[i].iIndex + Scale = self.iFlareConfigs[i].iLengthScale + + BlitCenterX = DirX*Scale+self.iCenterX + BlitCenterY = DirY*Scale+self.iCenterY + BlitWidth_div_2 = (self.iTextures[TextureIndex].iTextureWidth * self.iFlareConfigs[i].iImageScale) / 4 + BlitHeight_div_2 = (self.iTextures[TextureIndex].iTextureHeight * self.iFlareConfigs[i].iImageScale) / 4 + + iTextureManager.Blit(self.iTextures[TextureIndex], + (BlitCenterX - BlitWidth_div_2), + (BlitCenterY - BlitHeight_div_2), + (BlitCenterX + BlitWidth_div_2), + (BlitCenterY + BlitHeight_div_2)) + glDisable( GL_TEXTURE_2D ) + glDisable( GL_BLEND ) + +class T3DModel: + # Abstraction of a 3D model, represented by a position vector and single-precision floating point Yaw, Pitch, Roll orientation + def __init__(self, aPosition, aYaw, aPitch, aRoll): + self.position = aPosition + self.yaw = aYaw + self.pitch = aPitch + self.roll = aRoll + + def MakeWorldViewMatrix(aCamera, aPosition, aYaw=0, aPitch=0, aRoll=0): + # Sets up a world + a view matrix. + + glMultMatrixf(aCamera.iViewMatrix) + + glTranslatef(aPosition.iX-aCamera.iPosition.iX, aPosition.iY-aCamera.iPosition.iY, aPosition.iZ-aCamera.iPosition.iZ) + if aRoll: + glRotatef( aRoll , 0, 0, 1) + if aYaw: + glRotatef( aYaw , 0, 1, 0) + if aPitch: + glRotatef( aPitch, 1, 0, 0) + MakeWorldViewMatrix = staticmethod(MakeWorldViewMatrix) + def MakeBillboardWorldViewMatrix(aCamera, aPosition): + # Sets up a billboard matrix, which is a matrix that rotates objects in such a + # way that they always face the camera. + # Refer to the billboard example to see how this method is used. + + # Set up a rotation matrix to orient the billboard towards the camera. + Dir = aCamera.iLookAt - aCamera.iPosition; + + #TReal Angle, SrcT, SrcB; + + SrcT = Dir.iZ; + SrcB = Dir.iX; + Angle = atan2( SrcT, SrcB) + # The Yaw angle is computed in such a way that the object always faces the + # camera. + Angle = -(degrees( Angle ) + 90) + T3DModel.MakeWorldViewMatrix(aCamera, aPosition, Angle) + MakeBillboardWorldViewMatrix = staticmethod(MakeBillboardWorldViewMatrix) + +class T3DModelx: + # Abstraction of a 3D model, represented by a position vector and fixed-point Yaw, Pitch, Roll orientation + def __init__(self, aPosition=TVectorx(int2fixed(0),int2fixed(0),int2fixed(0)), aYaw=int2fixed(0), aPitch=int2fixed(0), aRoll=int2fixed(0)): + # Constructs and initializes a T3DModelx to position aPosition, with + # orientation [aYaw, aPitch, aRoll]. + self.position = aPosition + self.yaw = aYaw + self.pitch = aPitch + self.roll = aRoll + def MakeWorldViewMatrix(aCamera, aPosition, aYaw=0, aPitch=0, aRoll=0): + # Sets up a world + a view matrix. + + glMultMatrixx(aCamera.iViewMatrix) + + glTranslatex(aPosition.iX-aCamera.iPosition.iX, aPosition.iY-aCamera.iPosition.iY, aPosition.iZ-aCamera.iPosition.iZ) + if aRoll != int2fixed(0): + glRotatex( aRoll , int2fixed(0), int2fixed(0), int2fixed(1)) + if aYaw != int2fixed(0): + glRotatex( aYaw , int2fixed(0), int2fixed(1), int2fixed(0)) + if aPitch != int2fixed(0): + glRotatex( aPitch, int2fixed(1), int2fixed(0), int2fixed(0)) + MakeWorldViewMatrix = staticmethod(MakeWorldViewMatrix) + + def MakeBillboardWorldViewMatrix(aCamera, aPosition): + # Sets up a billboard matrix, which is a matrix that rotates objects in such a + # way that they always face the camera. + # Refer to the billboard example to see how this method is used. + + #if not aPosition: + # aPosition = self.position + + # Set up a rotation matrix to orient the billboard towards the camera. + Dir = aCamera.iLookAt - aCamera.iPosition + + #TReal Angle, SrcT, SrcB; + #return + SrcT = fixed2float(Dir.iZ) + SrcB = fixed2float(Dir.iX) + print "SrcT: %x" % (SrcT) + print "SrcB: %x" % (SrcB) + angle = atan2( SrcT, SrcB) + print "Angle = %f" % (angle) + # The Yaw angle is computed in such a way that the object always faces the camera. + angle = -(degrees( angle ) + 90) + print "Angle = %f" % (angle) + T3DModelx.MakeWorldViewMatrix(aCamera, aPosition, float2fixed(angle)) + MakeBillboardWorldViewMatrix = staticmethod(MakeBillboardWorldViewMatrix) + +class TCamera: + # Abstraction of a Camera in 3D space. + # + # The camera is represented by the eye point, the reference point, and the up vector. + # This class is very useful since it provides an implementation of the gluLookAt method + # which is not part of the OpenGL ES specification. + def __init__(self, aPosition=TVector(0, 0, 0), aLookAt=TVector(0, 0, -1), aUp=TVector(0, 1, 0)): + self.iViewMatrix = [] + self.LookAt(aPosition, aLookAt, aUp) + + def LookAt(self, aPosition, aLookAt, aUp): + #Initializes a TCamera to aPosition, aLookAt, aUp. + #TVector XAxis, YAxis, ZAxis; + + self.iPosition = aPosition + self.iLookAt = aLookAt + self.iUp = aUp + + # Get the z basis vector, which points straight ahead; the + # difference from the position (eye point) to the look-at point. + # This is the direction of the gaze (+z). + ZAxis = (self.iLookAt - self.iPosition) + + # Normalize the z basis vector. + ZAxis.Normalize() + + # Compute the orthogonal axes from the cross product of the gaze + # and the Up vector. + #print ZAxis + #print self.iUp + if isinstance(ZAxis, TVectorx): + XAxis = TVectorx.CrossProduct(ZAxis, self.iUp) + elif isinstance(ZAxis, TVector): + XAxis = TVector.CrossProduct(ZAxis, self.iUp) + XAxis.Normalize() + if isinstance(ZAxis, TVectorx): + YAxis = TVectorx.CrossProduct(XAxis, ZAxis) + if isinstance(ZAxis, TVector): + YAxis = TVector.CrossProduct(XAxis, ZAxis) + # Start building the matrix. The first three rows contain the + # basis vectors used to rotate the view to point at the look-at point. + self.MakeIdentity() + + self.iViewMatrix[0][0] = XAxis.iX; + self.iViewMatrix[1][0] = XAxis.iY; + self.iViewMatrix[2][0] = XAxis.iZ; + + self.iViewMatrix[0][1] = YAxis.iX; + self.iViewMatrix[1][1] = YAxis.iY; + self.iViewMatrix[2][1] = YAxis.iZ; + + self.iViewMatrix[0][2] = -ZAxis.iX; + self.iViewMatrix[1][2] = -ZAxis.iY; + self.iViewMatrix[2][2] = -ZAxis.iZ; + + def MakeIdentity(self): + self.iViewMatrix = [ + [1.0, 0.0, 0.0, 0.0], + [0.0, 1.0, 0.0, 0.0], + [0.0, 0.0, 1.0, 0.0], + [0.0, 0.0, 0.0, 1.0] + ] + +class TCameraX: + # Abstraction of a Camera in 3D space using fixed-point arithmetic. + # + # The camera is represented by the eye point, the reference point, and the up vector. + # + # This class is very useful since it provides an implementation of the gluLookAt method + # which is not part of the OpenGL ES specification. + def __init__(self, aPosition=TVectorx(0, 0, 0), aLookAt=TVectorx(0, 0, -1), aUp=TVectorx(0, 1, 0)): + self.LookAt(aPosition, aLookAt, aUp) + self.iViewMatrix = [] + + def LookAt(self, aPosition, aLookAt, aUp): + # Initializes a TCamera to aPosition, aLookAt, aUp. + #TVectorx XAxis, YAxis, ZAxis; + + self.iPosition = aPosition + self.iLookAt = aLookAt + self.iUp = aUp + + # Get the z basis vector, which points straight ahead; the + # difference from the position (eye point) to the look-at point. + # This is the direction of the gaze (+z). + ZAxis = (iLookAt - iPosition) + + # Normalize the z basis vector. + ZAxis.Normalize(); + + # Compute the orthogonal axes from the cross product of the gaze + # and the Up vector. + XAxis = TVectorx.CrossProduct(ZAxis, iUp) + XAxis.Normalize() + YAxis = TVectorx.CrossProduct(XAxis, ZAxis) + + # Start building the matrix. The first three rows contain the + # basis vectors used to rotate the view to point at the look-at point. + self.iViewMatrix = self.MakeIdentity(self.iViewMatrix) + + iViewMatrix[0][0] = XAxis.iX + iViewMatrix[1][0] = XAxis.iY + iViewMatrix[2][0] = XAxis.iZ + + iViewMatrix[0][1] = YAxis.iX + iViewMatrix[1][1] = YAxis.iY + iViewMatrix[2][1] = YAxis.iZ + + iViewMatrix[0][2] = -ZAxis.iX + iViewMatrix[1][2] = -ZAxis.iY + iViewMatrix[2][2] = -ZAxis.iZ + + def MakeIdentity(self, aMatrix): + self.iViewMatrix = [ + [1.0, 0.0, 0.0, 0.0], + [0.0, 1.0, 0.0, 0.0], + [0.0, 0.0, 1.0, 0.0], + [0.0, 0.0, 0.0, 1.0] + ] + aMatrix[0 + 4 * 0] = int2fixed(1); aMatrix[0 + 4 * 1] = int2fixed(0) + aMatrix[0 + 4 * 2] = int2fixed(0); aMatrix[0 + 4 * 3] = int2fixed(0) + + aMatrix[1 + 4 * 0] = int2fixed(0); aMatrix[1 + 4 * 1] = int2fixed(1) + aMatrix[1 + 4 * 2] = int2fixed(0); aMatrix[1 + 4 * 3] = int2fixed(0) + + aMatrix[2 + 4 * 0] = int2fixed(0); aMatrix[2 + 4 * 1] = int2fixed(0) + aMatrix[2 + 4 * 2] = int2fixed(1); aMatrix[2 + 4 * 3] = int2fixed(0) + + aMatrix[3 + 4 * 0] = int2fixed(0); aMatrix[3 + 4 * 1] = int2fixed(0) + aMatrix[3 + 4 * 2] = int2fixed(0); aMatrix[3 + 4 * 3] = int2fixed(1) + return aMatrix + +class TParticle: + # This structure is used by the class CParticleEngine. + # It is an abstraction of a particle. + # Position + #TVector iPosition + # Velocity + #TVector iVelocity + # Acceleration + #TVector iAcceleration + # Empty implementation + pass + +class CParticleEngine: + # Abstraction of a particle engine. + # Particles engines are used to create special effects like Rain, Smoke, Snow, Sparks, etc... + def __init__(self, aParticlesCount, aPosition): + # Constructs a CParticleEngine object with aParticlesCount particles at + # position aPosition. + self.iParticlesCount = aParticlesCount + self.iParticles = [TParticle() for x in xrange(self.iParticlesCount)] + + self.position = aPosition + + def ResetEngine(self): + # Resets the particle engine + for p in self.iParticles: + self.ResetParticle(p) + def ResetParticle(self, aIndex): + # Resets the particle at index aIndex + pass + def UpdateEngine(self, aElapsedTime): + # Updates the engine. + pass + def RenderEngine(self, aCamera): + # Renders the system. + pass +class Utils: + # A set of useful functions. + pass diff --git a/glesmodule.c b/glesmodule.c new file mode 100644 index 0000000..7556111 --- /dev/null +++ b/glesmodule.c @@ -0,0 +1,5506 @@ +/** + * ==================================================================== + * glesmodule.cpp + * + * Copyright (c) 2006 Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "glesmodule.h" + +PyTypeObject *array_type; +#define GLES_ARRAY_TYPE array_type + +PyObject *new_array_object(PyObject *self, PyObject *args) +{ + array_object *op = NULL; + PyObject *sequence; + void *arrdata = NULL; + int type; + int dimension; + +#ifdef DEBUG_GLES + DEBUGMSG("new_array_object()"); +#endif + if (!PyArg_ParseTuple(args, "iiO:array", &type, &dimension, &sequence)) { + return NULL; + } + + if (!PySequence_Check(sequence) ) { + PyErr_SetString(PyExc_TypeError, "Expecting a sequence"); + return NULL; + } + + op = PyObject_New(array_object, GLES_ARRAY_TYPE); + if (!op) { + return PyErr_NoMemory(); + } + + sequence = gles_PySequence_Collapse(type, sequence, NULL); + if(sequence==NULL) { + // There should be an exception + assert(PyErr_Occurred() != NULL); + // Delete the object since we're not going to use it anymore anyways + PyObject_Del(op); + return NULL; + } + + switch(type) { + case GL_FLOAT: + arrdata = gles_PySequence_AsGLfloatArray(sequence); + op->item_size = sizeof(GLfloat); + break; + case GL_BYTE: + arrdata = gles_PySequence_AsGLbyteArray(sequence); + op->item_size = sizeof(GLbyte); + break; + case GL_UNSIGNED_BYTE: + arrdata = gles_PySequence_AsGLubyteArray(sequence); + op->item_size = sizeof(GLubyte); + break; + case GL_SHORT: + arrdata = gles_PySequence_AsGLshortArray(sequence); + op->item_size = sizeof(GLshort); + break; + case GL_UNSIGNED_SHORT: + arrdata = gles_PySequence_AsGLushortArray(sequence); + op->item_size = sizeof(GLushort); + break; + case GL_FIXED: + arrdata = gles_PySequence_AsGLfixedArray(sequence); + op->item_size = sizeof(GLfixed); + break; + default: + PyErr_SetString(PyExc_ValueError, "Invalid array type specified"); + return NULL; + } + + // We should have an exception from the previous functions if arrdata==NULL + if(arrdata == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + + op->arrdata = arrdata; + op->len = PySequence_Length(sequence); + // Calculate the length in memory + op->real_len = op->item_size * op->len; + op->arrtype = type; + op->dimension = dimension; + + if (!op->arrdata) { + PyObject_Del(op); + return PyErr_NoMemory(); + } + return (PyObject*)op; +} + +int array_length(PyObject *self) { + array_object *op = (array_object*)self; + + return op->len; +} + +PyObject *array_getitem(PyObject *self, int idx) { + array_object *op = (array_object*)self; + PyObject *ret = NULL; + + if(idx > op->len-1 ) { + PyErr_SetString(PyExc_IndexError, "list index out of range"); + return NULL; + } + + switch(op->arrtype) { + case GL_FLOAT: + ret = PyFloat_FromDouble(*((GLfloat*)op->arrdata+idx)); + break; + case GL_BYTE: + ret = PyInt_FromLong(*((GLbyte*)op->arrdata+idx)); + break; + case GL_UNSIGNED_BYTE: + /// Python 2.2.2 does not have PyInt_FromUnsignedLong() + ret = PyLong_FromUnsignedLong(*((GLubyte*)op->arrdata+idx)); + break; + case GL_SHORT: + ret = PyInt_FromLong(*((GLshort*)op->arrdata+idx)); + break; + case GL_UNSIGNED_SHORT: + ret = PyLong_FromUnsignedLong(*((GLushort*)op->arrdata+idx)); + break; + case GL_FIXED: + ret = PyInt_FromLong(*((GLfixed*)op->arrdata+idx)); + break; + default: + // This should never happen, but it's never too safe not to check + PyErr_SetString(PyExc_RuntimeError, "Unknown type of array"); + return NULL; + } + return ret; +} + +int array_setitem(PyObject *self, int idx, PyObject *v) { + array_object *op = (array_object*)self; + + if(idx > op->len-1 ) { + PyErr_SetString(PyExc_IndexError, "list index out of range"); + return -1; + } + + if(!PyNumber_Check(v)) { + PyErr_SetString(PyExc_TypeError, "Expecting a number"); + return -1; + } + + switch(op->arrtype) { + case GL_FLOAT: + *((GLfloat*)op->arrdata+idx) = (GLfloat)PyFloat_AsDouble(v); + break; + case GL_BYTE: + *((GLbyte*)op->arrdata+idx) = (GLbyte)PyInt_AsLong(v); + break; + case GL_UNSIGNED_BYTE: + *((GLubyte*)op->arrdata+idx) = (GLubyte)PyInt_AsLong(v); + break; + case GL_SHORT: + *((GLshort*)op->arrdata+idx) = (GLshort)PyInt_AsLong(v); + break; + case GL_UNSIGNED_SHORT: + *((GLushort*)op->arrdata+idx) = (GLushort)PyInt_AsLong(v); + break; + case GL_FIXED: + *((GLfixed*)op->arrdata+idx) = (GLfixed)PyInt_AsLong(v); + break; + default: + // This should never happen, but it's never too safe not to check + PyErr_SetString(PyExc_RuntimeError, "Unknown type of array"); + return 0; + } + return 0; +} + + +//{ + static void + array_dealloc(array_object *op) + { +#ifdef DEBUG_GLES + DEBUGMSG("array_dealloc\n"); +#endif + if(op->arrdata) { + gles_free(op->arrdata); + } + PyObject_Del(op); + } + + PyMethodDef array_methods[] = { + {NULL, NULL} // sentinel + }; + + PySequenceMethods array_as_sequence = { + (inquiry)array_length, /* sq_length */ + /*(binaryfunc)*/0, /* sq_concat */ + /*(intargfunc)*/0, /* sq_repeat */ + (intargfunc)array_getitem, /* sq_item */ + /*(intintargfunc)*/0, /* sq_slice */ + (intobjargproc)array_setitem, /* sq_ass_item */ + 0, /* sq_ass_slice */ + /*(objobjproc)*/0, /* sq_contains */ + }; + + static PyObject * + array_getattr(array_object *op, char *name) + { + PyObject *ret; + if (!strcmp(name,"len")) { + ret = PyInt_FromLong(op->len); + return ret; + } + return Py_FindMethod((PyMethodDef*)array_methods, + (PyObject*)op, name); + } + + static int + array_setattr(array_object *op, char *name, PyObject *v ) + { + PyErr_SetString(PyExc_AttributeError, "no such attribute"); + return -1; + } + + static PyTypeObject c_array_type = { + PyObject_HEAD_INIT(NULL) + 0, /*ob_size*/ + "GLESArray", /*tp_name*/ + sizeof(array_object), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor)array_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + (getattrfunc)array_getattr, /*tp_getattr*/ + (setattrfunc)array_setattr, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + &array_as_sequence, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + }; + + + +//} // extern "C" + +/*********************************************** + * The bindings code starts here * + ***********************************************/ + +PyObject *gles_glActiveTexture(PyObject *self, PyObject *args) { + GLenum texture; + + if( !PyArg_ParseTuple(args, "i:glActiveTexture", &texture) ) { + return NULL; + } + + glActiveTexture(texture); + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glAlphaFunc(PyObject *self, PyObject *args) { + GLenum func; + GLclampf ref; + + if( !PyArg_ParseTuple(args, "if:glAlphaFunc", &func, &ref) ) { + return NULL; + } + + glAlphaFunc(func, ref); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glAlphaFuncx(PyObject *self, PyObject *args) { + GLenum func; + GLclampx ref; + + if( !PyArg_ParseTuple(args, "ii:glAlphaFuncx", &func, &ref) ) { + return NULL; + } + + glAlphaFuncx(func, ref); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glBindTexture(PyObject *self, PyObject *args) { + GLenum target; + GLuint texture; + + if( !PyArg_ParseTuple(args, "ii:glBindTexture", &target, &texture)) { + return NULL; + } + + glBindTexture(target, texture); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glBlendFunc(PyObject *self, PyObject *args) { + GLenum sfactor; + GLenum dfactor; + + if( !PyArg_ParseTuple(args, "ii:glBlendFunc", &sfactor, &dfactor) ) { + return NULL; + } + + glBlendFunc(sfactor, dfactor); + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glClear (PyObject *self, PyObject *args) { + unsigned int mask; + + if ( !PyArg_ParseTuple(args, "i:glClear", &mask) ) { + return NULL; + } + glClear(mask); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glClearColor (PyObject *self, PyObject *args) { + GLclampf red; + GLclampf green; + GLclampf blue; + GLclampf alpha; + + if ( !PyArg_ParseTuple(args, "ffff:glClearColor", &red, &green, &blue, &alpha ) ) { + return NULL; + } + glClearColor(red, green, blue, alpha); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glClearColorx(PyObject *self, PyObject *args) { + GLclampx red; + GLclampx green; + GLclampx blue; + GLclampx alpha; + + if ( !PyArg_ParseTuple(args, "iiii:glClearColorx", &red, &green, &blue, &alpha ) ) { + return NULL; + } + glClearColorx(red, green, blue, alpha); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glClearDepthf(PyObject *self, PyObject *args) { + GLclampf depth; + + if ( !PyArg_ParseTuple(args, "f:glClearDepthf", &depth) ) { + return NULL; + } + glClearDepthf(depth); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glClearDepthx(PyObject *self, PyObject *args) { + GLclampx depth; + + if ( !PyArg_ParseTuple(args, "i:glClearDepthx", &depth) ) { + return NULL; + } + glClearDepthx(depth); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glClearStencil(PyObject *self, PyObject *args) { + GLint s; + + if ( !PyArg_ParseTuple(args, "i:glClearStencil", &s) ) { + return NULL; + } + glClearStencil(s); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glClientActiveTexture(PyObject *self, PyObject *args) { + GLenum texture; + + if ( !PyArg_ParseTuple(args, "i:glClientActiveTexture", &texture) ) { + return NULL; + } + glClientActiveTexture(texture); + + RETURN_IF_GLERROR; + RETURN_PYNONE; + +} + +PyObject *gles_glColor4f(PyObject *self, PyObject *args) { + GLfloat red; + GLfloat green; + GLfloat blue; + GLfloat alpha; + + if ( !PyArg_ParseTuple(args, "ffff:glColor4f", &red, &green, &blue, &alpha) ) { + return NULL; + } + glColor4f(red, green, blue, alpha); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glColor4x(PyObject *self, PyObject *args) { + GLfixed red; + GLfixed green; + GLfixed blue; + GLfixed alpha; + + if ( !PyArg_ParseTuple(args, "iiii:glColor4x", &red, &green, &blue, &alpha) ) { + return NULL; + } + glColor4x(red, green, blue, alpha); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glColorMask(PyObject *self, PyObject *args) { + GLboolean red; + GLboolean green; + GLboolean blue; + GLboolean alpha; + + if ( !PyArg_ParseTuple(args, "iiii:glColorMask", &red, &green, &blue, &alpha) ) { + return NULL; + } + glColorMask(red, green, blue, alpha); + + RETURN_IF_GLERROR; + RETURN_PYNONE; + +} + +PyObject *gles_wrap_glColorPointer(GLint size, GLenum type, GLsizei stride, PyObject *pointerPy) { + void *cptr = NULL; + array_object *arrobj=NULL; + + // We can use either the array type or a sequence + // Check the array type first + if(PyObject_TypeCheck(pointerPy, GLES_ARRAY_TYPE) ) { + arrobj = (array_object*)pointerPy; + cptr = arrobj->arrdata; + } +#ifdef GL_OES_VERSION_1_1 + else if(pointerPy == Py_None) { + cptr = NULL; + } +#endif + // Try to convert it as a sequence + else { + pointerPy = gles_PySequence_Collapse(type, pointerPy, NULL); + if(pointerPy == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + // glColorPointer accepts only GL_UNSIGNED_BYTE, GL_FLOAT or GL_FIXED types + switch(type) { + case GL_UNSIGNED_BYTE: + cptr = gles_PySequence_AsGLubyteArray(pointerPy); + break; + case GL_FLOAT: + cptr = gles_PySequence_AsGLfloatArray(pointerPy); + break; + case GL_FIXED: + cptr = gles_PySequence_AsGLfixedArray(pointerPy); + break; + default: + PyErr_SetString(PyExc_ValueError, "Unsupported array type"); + return NULL; + } + if(cptr == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + } +#ifndef GL_OES_VERSION_1_1 + if(cptr == NULL) { + // Something went horribly wrong + // However, we should have an exception already + assert(PyErr_Occurred() != NULL); + return NULL; + } +#endif + gles_assign_array(GL_COLOR_ARRAY, cptr, arrobj); + glColorPointer(size, type, stride, cptr); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glColorPointer(PyObject *self, PyObject *args) { + GLint size; + GLenum type; + GLsizei stride; + + PyObject * pointerPy; + if ( !PyArg_ParseTuple(args, "iiiO:glColorPointer", &size, &type, &stride, &pointerPy) ) { + return NULL; + } + + return gles_wrap_glColorPointer(size, type, stride, pointerPy); +} + +PyObject *gles_glColorPointerub(PyObject *self, PyObject *args) { + GLint size; + + PyObject * pointerPy; + if ( !PyArg_ParseTuple(args, "O:glColorPointerub", &pointerPy) ) { + return NULL; + } + + if(pointerPy == Py_None) { + gles_free_array(GL_COLOR_ARRAY); + RETURN_PYNONE; + } + + if( PyObject_TypeCheck(pointerPy, GLES_ARRAY_TYPE) ) { + size = ((array_object*)pointerPy)->dimension; + } else { + size = gles_PySequence_Dimension(pointerPy); + } + + return gles_wrap_glColorPointer(size, /*type*/ GL_UNSIGNED_BYTE, /*stride*/ 0, pointerPy); +} + +PyObject *gles_glColorPointerf(PyObject *self, PyObject *args) { + GLint size; + + PyObject * pointerPy; + if ( !PyArg_ParseTuple(args, "O:glColorPointerf", &pointerPy) ) { + return NULL; + } + + if(pointerPy == Py_None) { + gles_free_array(GL_COLOR_ARRAY); + RETURN_PYNONE; + } + + if( PyObject_TypeCheck(pointerPy, GLES_ARRAY_TYPE) ) { + size = ((array_object*)pointerPy)->dimension; + } else { + size = gles_PySequence_Dimension(pointerPy); + } + + return gles_wrap_glColorPointer(size, /*type*/ GL_FLOAT, /*stride*/ 0, pointerPy); +} + +PyObject *gles_glColorPointerx(PyObject *self, PyObject *args) { + GLint size; + + PyObject * pointerPy; + if ( !PyArg_ParseTuple(args, "O:glColorPointerx", &pointerPy) ) { + return NULL; + } + + if(pointerPy == Py_None) { + gles_free_array(GL_COLOR_ARRAY); + RETURN_PYNONE; + } + + if( PyObject_TypeCheck(pointerPy, GLES_ARRAY_TYPE) ) { + size = ((array_object*)pointerPy)->dimension; + } else { + size = gles_PySequence_Dimension(pointerPy); + } + + return gles_wrap_glColorPointer(size, /*type*/ GL_FIXED, /*stride*/ 0, pointerPy); +} + +PyObject *gles_glCompressedTexImage2D(PyObject *self, PyObject *args) { + GLenum target; + GLint level; + GLenum internalformat; + GLsizei width; + GLsizei height; + GLint border; + GLsizei imageSize; + GLvoid *data; + + PyObject *pixelsPy; + + if( !PyArg_ParseTuple(args, "iiiiiiiO:glCompressedTexImage2D", &target, &level, &internalformat, &width, &height, &border, &imageSize, &pixelsPy) ) { + return NULL; + } + + // Only accepting array or string objects + if( PyObject_TypeCheck(pixelsPy, GLES_ARRAY_TYPE) ) { + array_object *arr = (array_object*)pixelsPy; + data = arr->arrdata; + } else if( PyString_Check(pixelsPy) ) { + // "Convert" the string object into an array. + // The returned pointer points to the raw C string + // data held by the object, so no actual conversion needed. + data = PyString_AsString(pixelsPy); + if(data == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + } else { + PyErr_SetString(PyExc_TypeError,"Only strings and gles.array objects supported"); + return NULL; + } + + glCompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data); + + RETURN_PYNONE; +} + +PyObject *gles_glCompressedTexSubImage2D(PyObject *self, PyObject *args) { + GLenum target; + GLint level; + GLint xoffset; + GLint yoffset; + GLsizei width; + GLsizei height; + GLenum format; + GLsizei imageSize; + GLvoid *data; + + PyObject *pixelsPy; + + if( !PyArg_ParseTuple(args, "iiiiiiiiO:glCompressedTexSubImage2D", &target, &level, &xoffset, &yoffset, &width, &height, &format, &imageSize, &pixelsPy) ) { + return NULL; + } + + if( PyObject_TypeCheck(pixelsPy, GLES_ARRAY_TYPE) ) { + array_object *arr = (array_object*)pixelsPy; + data = arr->arrdata; + } else if( PyString_Check(pixelsPy) ) { + // "Convert" the string object into an array. + // The returned pointer points to the raw C string + // data held by the object, so no actual conversion needed. + data = PyString_AsString(pixelsPy); + if(data == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + } // The last resort is to check if the given object is an Image object + else { + PyErr_SetString(PyExc_TypeError,"Only strings and gles.array objects supported"); + return NULL; + } + + glCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data); + + RETURN_PYNONE; +} + +PyObject *gles_glCopyTexImage2D(PyObject *self, PyObject *args) { + GLenum target; + GLint level; + GLenum internalformat; + GLint x; + GLint y; + GLsizei width; + GLsizei height; + GLint border; + + if ( !PyArg_ParseTuple(args, "iiiiiiii:glCopyTexImage2D", &target, &level, &internalformat, &x, &y, &width, &height, &border) ) { + return NULL; + } + glCopyTexImage2D(target, level, internalformat, x, y, width, height, border); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glCopyTexSubImage2D(PyObject *self, PyObject *args) { + GLenum target; + GLint level; + GLint xoffset; + GLint yoffset; + GLint x; + GLint y; + GLsizei width; + GLsizei height; + + if ( !PyArg_ParseTuple(args, "iiiiiiii:glCopyTexSubImage2D", &target, &level, &xoffset, &yoffset, &x, &y, &width, &height) ) { + return NULL; + } + glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glCullFace(PyObject *self, PyObject *args) { + GLenum mode; + + if ( !PyArg_ParseTuple(args, "i:glCullFace", &mode) ) { + return NULL; + } + glCullFace(mode); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glDeleteTextures(PyObject *self, PyObject *args) { + GLsizei n; + GLuint *textures = NULL; + PyObject *texturesPy = NULL; + + if( !PyArg_ParseTuple(args, "O:glDeleteTextures", &texturesPy) ) { + return NULL; + } + + if(! PySequence_Check(texturesPy) ) { + PyErr_SetString(PyExc_TypeError, "Expecting a sequence"); + return NULL; + } + + + textures = gles_PySequence_AsGLuintArray(texturesPy); + if( textures == NULL ) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + + n = PySequence_Length(texturesPy); + glDeleteTextures(n, textures); + gles_free(textures); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glDepthFunc(PyObject *self, PyObject *args) { + GLenum func; + + if ( !PyArg_ParseTuple(args, "i:glDepthFunc", &func) ) { + return NULL; + } + glDepthFunc(func); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glDepthMask(PyObject *self, PyObject *args) { + GLboolean flag; + + if ( !PyArg_ParseTuple(args, "i:glDepthMask", &flag) ) { + return NULL; + } + glDepthMask(flag); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glDepthRangef(PyObject *self, PyObject *args) { + GLclampf zNear; + GLclampf zFar; + + if ( !PyArg_ParseTuple(args, "ff:glDepthRangef", &zNear, &zFar) ) { + return NULL; + } + glDepthRangef(zNear, zFar); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glDepthRangex(PyObject *self, PyObject *args) { + GLclampx zNear; + GLclampx zFar; + + if ( !PyArg_ParseTuple(args, "ii:glDepthRangex", &zNear, &zFar) ) { + return NULL; + } + glDepthRangex(zNear, zFar); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glDisable(PyObject *self, PyObject *args) { + GLenum cap; + if ( !PyArg_ParseTuple(args, "i:glDisable", &cap) ) { + return NULL; + } + glDisable(cap); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glDisableClientState(PyObject *self, PyObject *args) { + GLenum array; + + if ( !PyArg_ParseTuple(args, "i:glDisableClientState", &array) ) { + return NULL; + } + glDisableClientState(array); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glDrawArrays(PyObject *self, PyObject *args) { + GLenum mode; + GLint first; + GLsizei count; + + if ( !PyArg_ParseTuple(args, "iii:glDrawArrays", &mode, &first, &count) ) { + return NULL; + } + glDrawArrays(mode, first, count); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glDrawElements(PyObject *self, PyObject *args) { + GLenum mode; + GLsizei count = 0; + GLenum type; + void *eptr = NULL; + array_object *arrobj = NULL; + PyObject *indicesPy; + + if ( !PyArg_ParseTuple(args, "iiiO:glDrawElements", &mode, &count, &type, &indicesPy) ) { + return NULL; + } + + // We can use either the array type or a sequence. + // Check for gles.array type first. + if(PyObject_TypeCheck(indicesPy, GLES_ARRAY_TYPE) ) { + arrobj=(array_object*)indicesPy; + eptr = (GLubyte*)arrobj->arrdata; + } // We can also use None as an argument. + else if(indicesPy == Py_None) { + eptr = NULL; + } // Try to feed the object as a sequence. + else { + indicesPy = gles_PySequence_Collapse(type, indicesPy, NULL); + if(indicesPy == NULL) { + // We should have an exception from PySequence_Collapse if something went wrong + assert(PyErr_Occurred() != NULL); + return NULL; + } + + // glDrawElements accepts only GL_UNSIGNED_BYTE or GL_UNSIGNED_SHORT types + switch(type) { + case GL_UNSIGNED_BYTE: + eptr = gles_PySequence_AsGLubyteArray(indicesPy); + break; + case GL_UNSIGNED_SHORT: + eptr = gles_PySequence_AsGLushortArray(indicesPy); + break; + default: + PyErr_SetString(PyExc_ValueError, "Invalid array type"); + return NULL; + } + if(eptr == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + } + + glDrawElements(mode, count, type, eptr); + if(arrobj == NULL && eptr != NULL) { + gles_free(eptr); + } + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glDrawElementsub(PyObject *self, PyObject *args) { + GLenum mode; + GLsizei count = 0; + GLenum type = GL_UNSIGNED_BYTE; + GLubyte *eptr; + array_object *arrobj = NULL; + PyObject *indicesPy; + + if ( !PyArg_ParseTuple(args, "iO:glDrawElementsub", &mode, &indicesPy) ) { + return NULL; + } + + // We can use either the array type or a sequence. + // Check for gles.array type first. + if(PyObject_TypeCheck(indicesPy, GLES_ARRAY_TYPE) ) { + arrobj=(array_object*)indicesPy; + if(arrobj->arrtype != type) { + PyErr_SetString(PyExc_TypeError, "Invalid type; expected GL_UNSIGNED_BYTE"); + return NULL; + } + eptr = (GLubyte*)arrobj->arrdata; + count = arrobj->len; + } // We can also use None as an argument. + else if(indicesPy == Py_None) { + eptr = NULL; + } // Try to feed the object as a sequence. + else { + indicesPy = gles_PySequence_Collapse(type, indicesPy, NULL); + if(indicesPy == NULL) { + // We should have an exception from PySequence_Collapse if something went wrong + assert(PyErr_Occurred() != NULL); + return NULL; + } + + eptr = gles_PySequence_AsGLubyteArray(indicesPy); + if(eptr == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + count = PySequence_Length(indicesPy); + } + + glDrawElements(mode, count, type, eptr); + if(arrobj == NULL && eptr != NULL) { + gles_free(eptr); + } + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glDrawElementsus (PyObject *self, PyObject *args) { + GLenum mode; + GLsizei count = 0; + GLenum type = GL_UNSIGNED_SHORT; + GLushort *eptr; + array_object *arrobj = NULL; + PyObject *indicesPy; + + if ( !PyArg_ParseTuple(args, "iO:glDrawElementsus", &mode, &indicesPy) ) { + return NULL; + } + + // We can use either the array type or a sequence. + // Check for gles.array type first. + if(PyObject_TypeCheck(indicesPy, GLES_ARRAY_TYPE) ) { + arrobj = (array_object*)indicesPy; + if(arrobj->arrtype != type) { + PyErr_SetString(PyExc_TypeError, "Invalid type; expected GL_UNSIGNED_SHORT"); + return NULL; + } + eptr = (GLushort*)arrobj->arrdata; + count = arrobj->len; + } // We can also use None as an argument. + else if(indicesPy == Py_None) { + eptr = NULL; + } // Try to feed the object as a sequence. + else { + indicesPy = gles_PySequence_Collapse(type, indicesPy, NULL); + if(indicesPy == NULL) { + // We should have an exception from PySequence_Collapse if something went wrong + assert(PyErr_Occurred() != NULL); + return NULL; + } + eptr = gles_PySequence_AsGLushortArray(indicesPy); + if(eptr == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + count = PySequence_Length(indicesPy); + } + + glDrawElements(mode, count, type, eptr); + if(arrobj == NULL && eptr != NULL) { + gles_free(eptr); + } + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glEnable (PyObject *self, PyObject *args) { + GLenum cap; + if ( !PyArg_ParseTuple(args, "i:glEnable", &cap) ) { + return NULL; + } + glEnable(cap); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glEnableClientState(PyObject *self, PyObject *args) { + GLenum array; + + if ( !PyArg_ParseTuple(args, "i:glEnableClientState", &array) ) { + return NULL; + } + glEnableClientState(array); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glFinish(PyObject *self, PyObject *args) { + glFinish(); + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glFlush(PyObject *self, PyObject *args) { + glFlush(); + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glFogf(PyObject *self, PyObject *args) { + GLenum pname; + GLfloat param; + + if ( !PyArg_ParseTuple(args, "if:glFogf", &pname, ¶m) ) { + return NULL; + } + glFogf(pname, param); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glFogfv(PyObject *self, PyObject *args) { + GLenum pname; + GLfloat *params; + + PyObject *paramsPy; + if ( !PyArg_ParseTuple(args, "iO:glFogfv", &pname, ¶msPy) ) { + return NULL; + } + params = gles_PySequence_AsGLfloatArray(paramsPy); + if(params == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + glFogfv(pname, params); + gles_free(params); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glFogx(PyObject *self, PyObject *args) { + GLenum pname; + GLfixed param; + + if ( !PyArg_ParseTuple(args, "ii:glFogx", &pname, ¶m) ) { + return NULL; + } + glFogx(pname, param); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glFogxv(PyObject *self, PyObject *args) { + GLenum pname; + GLfixed *params; + + PyObject *paramsPy; + if ( !PyArg_ParseTuple(args, "iO:glFogxv", &pname, ¶msPy) ) { + return NULL; + } + params = gles_PySequence_AsGLfixedArray(paramsPy); + if(params == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + glFogxv(pname, params); + gles_free(params); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glFrontFace(PyObject *self, PyObject *args) { + GLenum mode; + + if ( !PyArg_ParseTuple(args, "i:glFrontFace", &mode) ) { + return NULL; + } + glFrontFace(mode); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glFrustumf(PyObject *self, PyObject *args) { + GLfloat left; + GLfloat right; + GLfloat bottom; + GLfloat top; + GLfloat zNear; + GLfloat zFar; + + if ( !PyArg_ParseTuple(args, "ffffff:glFrustumf", &left, &right, &bottom, &top, &zNear, &zFar) ) { + return NULL; + } + glFrustumf(left, right, bottom, top, zNear, zFar); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glFrustumx(PyObject *self, PyObject *args) { + GLfixed left; + GLfixed right; + GLfixed bottom; + GLfixed top; + GLfixed zNear; + GLfixed zFar; + + if ( !PyArg_ParseTuple(args, "iiiiii:glFrustumx", &left, &right, &bottom, &top, &zNear, &zFar) ) { + return NULL; + } + glFrustumx(left, right, bottom, top, zNear, zFar); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glGenTextures(PyObject *self, PyObject *args) { + GLuint *textures = NULL; + GLuint n; + unsigned int i; + PyObject *ret; + + if( !PyArg_ParseTuple(args, "i:glGenTextures", &n) ) { + return NULL; + } + + if(n < 1) { + PyErr_SetString(PyExc_ValueError, "Value must be positive"); + return NULL; + } + + textures = (GLuint*)gles_alloc( sizeof(GLuint)*n ); + + glGenTextures( n, textures); + if(n > 1) { + ret = PyTuple_New(n); + + for(i=0;iarrdata; + } +#ifdef GL_OES_VERSION_1_1 + else if(pointerPy == Py_None) { + nptr = NULL; + } +#endif + // Try to convert it as a sequence + else { + pointerPy = gles_PySequence_Collapse(type, pointerPy, NULL); + if( pointerPy == NULL ) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + // glNormalPointer accepts only GL_BYTE, GL_SHORT, GL_FIXED or GL_FLOAT types + switch(type) { + case GL_BYTE: + nptr = gles_PySequence_AsGLbyteArray(pointerPy); + break; + case GL_SHORT: + nptr = gles_PySequence_AsGLshortArray(pointerPy); + break; + case GL_FIXED: + nptr = gles_PySequence_AsGLfixedArray(pointerPy); + break; + case GL_FLOAT: + nptr = gles_PySequence_AsGLfloatArray(pointerPy); + break; + default: + PyErr_SetString(PyExc_ValueError, "Invalid array type"); + return NULL; + } + if(nptr == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + } +#ifndef GL_OES_VERSION_1_1 + if(nptr == NULL) { + // Something went horribly wrong + // However, we should have an exception already + assert(PyErr_Occurred() != NULL); + return NULL; + } +#endif + gles_assign_array(GL_NORMAL_ARRAY, nptr, arrobj); + glNormalPointer(type, stride, nptr); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glNormalPointer(PyObject *self, PyObject *args) { + GLenum type; + GLsizei stride; + PyObject *pointerPy; + + if ( !PyArg_ParseTuple(args, "iiO:glNormalPointer", &type, &stride, &pointerPy) ) { + return NULL; + } + + if(pointerPy == Py_None) { + gles_free_array(GL_NORMAL_ARRAY); + RETURN_PYNONE; + } + + return gles_wrap_glNormalPointer(type, stride, pointerPy); +} + +PyObject *gles_glNormalPointerb(PyObject *self, PyObject *args) { + PyObject *pointerPy; + + if ( !PyArg_ParseTuple(args, "O:glNormalPointerb", &pointerPy) ) { + return NULL; + } + + if(pointerPy == Py_None) { + gles_free_array(GL_NORMAL_ARRAY); + RETURN_PYNONE; + } + + return gles_wrap_glNormalPointer(/*type*/GL_BYTE, /*stride*/0, pointerPy); +} + +PyObject *gles_glNormalPointers(PyObject *self, PyObject *args) { + PyObject *pointerPy; + + if ( !PyArg_ParseTuple(args, "O:glNormalPointers", &pointerPy) ) { + return NULL; + } + + if(pointerPy == Py_None) { + gles_free_array(GL_NORMAL_ARRAY); + RETURN_PYNONE; + } + + return gles_wrap_glNormalPointer(/*type*/GL_SHORT, /*stride*/0, pointerPy); +} + +PyObject *gles_glNormalPointerf(PyObject *self, PyObject *args) { + PyObject *pointerPy; + + if ( !PyArg_ParseTuple(args, "O:glNormalPointerf", &pointerPy) ) { + return NULL; + } + + if(pointerPy == Py_None) { + gles_free_array(GL_NORMAL_ARRAY); + RETURN_PYNONE; + } + + return gles_wrap_glNormalPointer(/*type*/GL_FLOAT, /*stride*/0, pointerPy); +} + +PyObject *gles_glNormalPointerx(PyObject *self, PyObject *args) { + PyObject *pointerPy; + + if ( !PyArg_ParseTuple(args, "O:glNormalPointerx", &pointerPy) ) { + return NULL; + } + + if(pointerPy == Py_None) { + gles_free_array(GL_NORMAL_ARRAY); + RETURN_PYNONE; + } + + return gles_wrap_glNormalPointer(/*type*/GL_FIXED, /*stride*/0, pointerPy); +} + +PyObject *gles_glOrthof(PyObject *self, PyObject *args) { + GLfloat left; + GLfloat right; + GLfloat bottom; + GLfloat top; + GLfloat zNear; + GLfloat zFar; + + if ( !PyArg_ParseTuple(args, "ffffff:glOrthof", &left, &right, &bottom, &top, &zNear, &zFar) ) { + return NULL; + } + glOrthof(left, right, bottom, top, zNear, zFar); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glOrthox(PyObject *self, PyObject *args) { + GLfixed left; + GLfixed right; + GLfixed bottom; + GLfixed top; + GLfixed zNear; + GLfixed zFar; + + if ( !PyArg_ParseTuple(args, "iiiiii:glOrthox", &left, &right, &bottom, &top, &zNear, &zFar) ) { + return NULL; + } + glOrthox(left, right, bottom, top, zNear, zFar); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glPixelStorei(PyObject *self, PyObject *args) { + GLenum pname; + GLint param; + + if ( !PyArg_ParseTuple(args, "ii:glPixelStorei", &pname, ¶m) ) { + return NULL; + } + glPixelStorei(pname, param); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glPointSize(PyObject *self, PyObject *args) { + GLfloat size; + + if ( !PyArg_ParseTuple(args, "f:glPointSize", &size) ) { + return NULL; + } + glPointSize(size); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glPointSizex(PyObject *self, PyObject *args) { + GLfixed size; + + if ( !PyArg_ParseTuple(args, "i:glPointSizex", &size) ) { + return NULL; + } + glPointSizex(size); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glPolygonOffset(PyObject *self, PyObject *args) { + GLfloat factor; + GLfloat units; + + if ( !PyArg_ParseTuple(args, "ff:glPolygonOffset", &factor, &units) ) { + return NULL; + } + glPolygonOffset(factor, units); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glPolygonOffsetx(PyObject *self, PyObject *args) { + GLfixed factor; + GLfixed units; + + if ( !PyArg_ParseTuple(args, "ii:glPolygonOffsetx", &factor, &units) ) { + return NULL; + } + glPolygonOffsetx(factor, units); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glPopMatrix(PyObject *self, PyObject *args) { + glPopMatrix(); + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glPushMatrix(PyObject *self, PyObject *args) { + glPushMatrix(); + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glReadPixels(PyObject *self, PyObject *args) { + GLint x; + GLint y; + GLsizei width; + GLsizei height; + GLenum format; + GLenum type; + GLvoid *pixels; + + int len=0; + PyObject *pixelsPy=NULL; + if ( !PyArg_ParseTuple(args, "iiiiii:glReadPixels", &x, &y, &width, &height, &format, &type) ) { + return NULL; + } + + // Determine the size of the result + switch(format) { + case GL_RGBA: + len = width*height*4; + break; + case GL_RGB: + len = width*height*3; + break; + case GL_LUMINANCE: + len = width*height; + break; + case GL_LUMINANCE_ALPHA: + len = width*height*2; + break; + case GL_ALPHA: + len = width*height; + break; + default: + PyErr_SetString(PyExc_ValueError, "Unsupported format"); + return NULL; + } + + pixels = gles_alloc( len*sizeof(GLubyte) ); + if( pixels == NULL ) { + return PyErr_NoMemory(); + } + + glReadPixels(x, y, width, height, format, type, pixels); + + // Make a string object out of the data + pixelsPy = PyString_FromStringAndSize( (char*)pixels, len); + gles_free(pixels); + + RETURN_IF_GLERROR; + Py_INCREF(pixelsPy); + return pixelsPy; +} + +PyObject *gles_glRotatef(PyObject *self, PyObject *args) { + GLfloat angle; + GLfloat x; + GLfloat y; + GLfloat z; + + if ( !PyArg_ParseTuple(args, "ffff:glRotatef", &angle, &x, &y, &z) ) { + return NULL; + } + glRotatef(angle, x, y, z); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glRotatex (PyObject *self, PyObject *args) { + GLfixed angle; + GLfixed x; + GLfixed y; + GLfixed z; + + if ( !PyArg_ParseTuple(args, "iiii:glRotatex", &angle, &x, &y, &z) ) { + return NULL; + } + glRotatex(angle, x, y, z); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glSampleCoverage(PyObject *self, PyObject *args) { + GLclampf value; + GLboolean invert; + + if ( !PyArg_ParseTuple(args, "fi:glSampleCoverage", &value, &invert) ) { + return NULL; + } + + if(invert) { + invert = GL_TRUE; + } else { + invert = GL_FALSE; + } + + glSampleCoverage(value, invert); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glSampleCoveragex(PyObject *self, PyObject *args) { + GLclampx value; + GLboolean invert; + + if ( !PyArg_ParseTuple(args, "ii:glSampleCoverage", &value, &invert) ) { + return NULL; + } + + if(invert) { + invert = GL_TRUE; + } else { + invert = GL_FALSE; + } + + glSampleCoveragex(value, invert); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glScalef (PyObject *self, PyObject *args) { + GLfloat x; + GLfloat y; + GLfloat z; + + if ( !PyArg_ParseTuple(args, "fff:glScalef", &x, &y, &z) ) { + return NULL; + } + glScalef(x, y, z); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glScalex(PyObject *self, PyObject *args) { + GLfixed x; + GLfixed y; + GLfixed z; + + if ( !PyArg_ParseTuple(args, "iii:glScalex", &x, &y, &z) ) { + return NULL; + } + glScalex(x, y, z); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glScissor(PyObject *self, PyObject *args) { + GLint x; + GLint y; + GLsizei width; + GLsizei height; + + if ( !PyArg_ParseTuple(args, "iiii:glScissor", &x, &y, &width, &height) ) { + return NULL; + } + glScissor(x, y, width, height); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glShadeModel(PyObject *self, PyObject *args) { + GLenum mode; + + if ( !PyArg_ParseTuple(args, "i:glShadeModel", &mode) ) { + return NULL; + } + glShadeModel(mode); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glStencilFunc(PyObject *self, PyObject *args) { + GLenum func; + GLint ref; + GLuint mask; + + if ( !PyArg_ParseTuple(args, "iii:glStencilFunc", &func, &ref, &mask) ) { + return NULL; + } + glStencilFunc(func, ref, mask); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glStencilMask(PyObject *self, PyObject *args) { + GLuint mask; + + if ( !PyArg_ParseTuple(args, "i:glStencilMask", &mask) ) { + return NULL; + } + glStencilMask(mask); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glStencilOp(PyObject *self, PyObject *args) { + GLenum fail; + GLenum zfail; + GLenum zpass; + + if ( !PyArg_ParseTuple(args, "iii:glStencilOp", &fail, &zfail, &zpass) ) { + return NULL; + } + glStencilOp(fail, zfail, zpass); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_wrap_glTexCoordPointer(GLint size, GLenum type, GLsizei stride, PyObject *pointerPy) { + void *tcptr = NULL; + array_object *arrobj=NULL; + + // We can use either the array type or a sequence + // Check the array type first + if(PyObject_TypeCheck(pointerPy, GLES_ARRAY_TYPE) ) { + arrobj = (array_object*)pointerPy; + tcptr = arrobj->arrdata; + } +#ifdef GL_OES_VERSION_1_1 + else if(pointerPy == Py_None) { + tcptr = NULL; + } +#endif + // Try to convert it as a sequence + else { + pointerPy = gles_PySequence_Collapse(type, pointerPy, NULL); + if(pointerPy == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + // glTexCoordPointer accepts only GL_BYTE, GL_SHORT, GL_FIXED or GL_FLOAT types + switch(type) { + case GL_BYTE: + tcptr = gles_PySequence_AsGLbyteArray(pointerPy); + break; + case GL_SHORT: + tcptr = gles_PySequence_AsGLshortArray(pointerPy); + break; + case GL_FIXED: + tcptr = gles_PySequence_AsGLfixedArray(pointerPy); + break; + case GL_FLOAT: + tcptr = gles_PySequence_AsGLfloatArray(pointerPy); + break; + default: + PyErr_SetString(PyExc_ValueError, "Invalid array type"); + return NULL; + } + if(tcptr == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + } + +#ifndef GL_OES_VERSION_1_1 + if(tcptr == NULL) { + // Something went horribly wrong + // However, we should have an exception already + assert(PyErr_Occurred() != NULL); + return NULL; + } +#endif + gles_assign_array(GL_TEXTURE_COORD_ARRAY, tcptr, arrobj); + glTexCoordPointer(size, type, stride, tcptr); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glTexCoordPointer(PyObject *self, PyObject *args) { + GLint size; + GLenum type; + GLsizei stride = 0; + + PyObject *pointerPy; + if ( !PyArg_ParseTuple(args, "iiiO:glTexCoordPointer", &size, &type, &stride, &pointerPy) ) { + return NULL; + } + + if(pointerPy == Py_None) { + gles_free_array(GL_TEXTURE_COORD_ARRAY); + RETURN_PYNONE; + } + + return gles_wrap_glTexCoordPointer(size, type, stride, pointerPy); +} + +PyObject *gles_glTexCoordPointerb(PyObject *self, PyObject *args) { + GLint size; + PyObject *pointerPy; + + if ( !PyArg_ParseTuple(args, "O:glTexCoordPointerb", &pointerPy) ) { + return NULL; + } + + if(pointerPy == Py_None) { + gles_free_array(GL_TEXTURE_COORD_ARRAY); + RETURN_PYNONE; + } + + if(PyObject_TypeCheck(pointerPy, GLES_ARRAY_TYPE) ) { + size = ((array_object*)pointerPy)->dimension; + } else { + size = gles_PySequence_Dimension(pointerPy); + } + return gles_wrap_glTexCoordPointer(size, /*type*/GL_BYTE, /*stride*/0, pointerPy); +} + +PyObject *gles_glTexCoordPointers(PyObject *self, PyObject *args) { + GLint size; + PyObject *pointerPy; + + if ( !PyArg_ParseTuple(args, "O:glTexCoordPointers", &pointerPy) ) { + return NULL; + } + + if(pointerPy == Py_None) { + gles_free_array(GL_TEXTURE_COORD_ARRAY); + RETURN_PYNONE; + } + + if(PyObject_TypeCheck(pointerPy, GLES_ARRAY_TYPE) ) { + size = ((array_object*)pointerPy)->dimension; + } else { + size = gles_PySequence_Dimension(pointerPy); + } + return gles_wrap_glTexCoordPointer(size, /*type*/GL_SHORT, /*stride*/0, pointerPy); +} + +PyObject *gles_glTexCoordPointerf(PyObject *self, PyObject *args) { + GLint size; + PyObject *pointerPy; + + if ( !PyArg_ParseTuple(args, "O:glTexCoordPointerf", &pointerPy) ) { + return NULL; + } + + if(pointerPy == Py_None) { + gles_free_array(GL_TEXTURE_COORD_ARRAY); + RETURN_PYNONE; + } + + if(PyObject_TypeCheck(pointerPy, GLES_ARRAY_TYPE) ) { + size = ((array_object*)pointerPy)->dimension; + } else { + size = gles_PySequence_Dimension(pointerPy); + } + return gles_wrap_glTexCoordPointer(size, /*type*/GL_FLOAT, /*stride*/0, pointerPy); +} + +PyObject *gles_glTexCoordPointerx(PyObject *self, PyObject *args) { + GLint size; + PyObject *pointerPy; + + if ( !PyArg_ParseTuple(args, "O:glTexCoordPointerx", &pointerPy) ) { + return NULL; + } + + if(pointerPy == Py_None) { + gles_free_array(GL_TEXTURE_COORD_ARRAY); + RETURN_PYNONE; + } + + if(PyObject_TypeCheck(pointerPy, GLES_ARRAY_TYPE) ) { + size = ((array_object*)pointerPy)->dimension; + } else { + size = gles_PySequence_Dimension(pointerPy); + } + return gles_wrap_glTexCoordPointer(size, /*type*/GL_FIXED, /*stride*/0, pointerPy); +} + +PyObject *gles_glTexEnvf(PyObject *self, PyObject *args) { + GLenum target; + GLenum pname; + GLfloat param; + + if( !PyArg_ParseTuple(args, "iif:glTexEnvf", &target, &pname, ¶m)) { + return NULL; + } + glTexEnvf(target, pname, param); + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glTexEnvfv (PyObject *self, PyObject *args) { + GLenum face; + GLenum pname; + GLfloat *params; + + PyObject *paramsPy; + if ( !PyArg_ParseTuple(args, "iiO:glTexEnvfv", &face, &pname, ¶msPy) ) { + return NULL; + } + + params = (GLfloat*)gles_PySequence_AsGLfloatArray(paramsPy); + if(params == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + glTexEnvfv(face, pname, params); + gles_free(params); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glTexEnvx(PyObject *self, PyObject *args) { + GLenum target; + GLenum pname; + GLfixed param; + + if( !PyArg_ParseTuple(args, "iii:glTexEnvx", &target, &pname, ¶m)) { + return NULL; + } + glTexEnvx(target, pname, param); + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glTexEnvxv (PyObject *self, PyObject *args) { + GLenum face; + GLenum pname; + GLfixed *params; + + PyObject *paramsPy; + if ( !PyArg_ParseTuple(args, "iiO:glTexEnvfv", &face, &pname, ¶msPy) ) { + return NULL; + } + + params = (GLfixed*)gles_PySequence_AsGLfixedArray(paramsPy); + if(params == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + glTexEnvxv(face, pname, params); + gles_free(params); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_wrap_glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, PyObject *pixelsPy) { + GLvoid *pixels; + + // Indicates if the pixel data should be freed after the call to glTexImage2D. + int free_pixels = 0; + + if( PyObject_TypeCheck(pixelsPy, GLES_ARRAY_TYPE) ) { + array_object *arr = (array_object*)pixelsPy; + pixels = arr->arrdata; + } else if( PyString_Check(pixelsPy) ) { + // "Convert" the string object into an array. + // The returned pointer points to the raw C string + // data held by the object, so no actual conversion needed. + pixels = PyString_AsString(pixelsPy); + if(pixels == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + } +/* // The last resort is to check if the given object is an Image object + else { + CFbsBitmap *bitmap=Bitmap_AsFbsBitmap(pixelsPy); +#ifdef DEBUG_GLES + DEBUGMSG1("Image: %x", bitmap); +#endif + if(bitmap == NULL) { + PyErr_SetString(PyExc_TypeError, "Unsupported object type"); + return NULL; + } + free_pixels = 1; + pixels = gles_convert_fbsbitmap(bitmap, format, type, NULL); + if(pixels == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + } + */ + glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels ); + if(free_pixels == 1) { + gles_free(pixels); + } + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glTexImage2D(PyObject *self, PyObject *args) { + GLenum target; + GLint level; + GLint internalformat; + GLsizei width; + GLsizei height; + GLint border; + GLenum format; + GLenum type; + + PyObject *pixelsPy = NULL; + + if( !PyArg_ParseTuple(args, "iiiiiiiiO:glTexImage2D", &target, &level, &internalformat, &width, &height, &border, &format, &type, &pixelsPy) ) { + return NULL; + } + + return gles_wrap_glTexImage2D(target, level, internalformat, width, height, border, format, type, pixelsPy); +} +/* +PyObject *gles_glTexImage2DIO(PyObject *self, PyObject *args) { + GLenum target; + GLint level; + GLsizei width; + GLsizei height; + GLint border; + GLenum format; + GLenum type; + PyObject *image_object; + TSize imgsize; + + if( !PyArg_ParseTuple(args, "iiiiiO:glTexImage2DIO", &target, &level, &format, &border, &type, &image_object) ) { + return NULL; + } + + CFbsBitmap *bitmap=Bitmap_AsFbsBitmap(image_object); + if(bitmap == NULL) { + PyErr_SetString(PyExc_TypeError, "Expecting a graphics.Image object"); + return NULL; + } + + imgsize = bitmap->SizeInPixels(); + width = imgsize.iWidth; + height = imgsize.iHeight; + + return gles_wrap_glTexImage2D(target, level, / * internalformat * /format, width, height, border, format, type, image_object); +} +*/ + +PyObject *gles_glTexParameterf(PyObject *self, PyObject *args) { + GLenum target; + GLenum pname; + GLfloat param; + + if ( !PyArg_ParseTuple(args, "iif:glTexParameterf", &target, &pname, ¶m) ) { + return NULL; + } + glTexParameterf(target, pname, param); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glTexParameterx(PyObject *self, PyObject *args) { + GLenum target; + GLenum pname; + GLfixed param; + + if ( !PyArg_ParseTuple(args, "iii:glTexParameterx", &target, &pname, ¶m) ) { + return NULL; + } + glTexParameterx(target, pname, param); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_wrap_glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, PyObject *pixelsPy) { + GLvoid *pixels; + + // Indicates if the pixel data should be freed after the call to glTexSubImage2D. + int free_pixels = 0; + + if( PyObject_TypeCheck(pixelsPy, GLES_ARRAY_TYPE) ) { + array_object *arr = (array_object*)pixelsPy; + pixels = arr->arrdata; + } else if( PyString_Check(pixelsPy) ) { + // "Convert" the string object into an array. + // The returned pointer points to the raw C string + // data held by the object, so no actual conversion needed. + pixels = PyString_AsString(pixelsPy); + if(pixels == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + } +/* // The last resort is to check if the given object is an Image object + else { + CFbsBitmap *bitmap=Bitmap_AsFbsBitmap(pixelsPy); +#ifdef DEBUG_GLES + DEBUGMSG1("Image: %x", bitmap); +#endif + if(bitmap == NULL) { + PyErr_SetString(PyExc_TypeError, "Unsupported object type"); + return NULL; + } + free_pixels = 1; + pixels = gles_convert_fbsbitmap(bitmap, format, type, NULL); + if(pixels == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + } + */ + glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels ); + if(free_pixels == 1) { + gles_free(pixels); + } + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glTexSubImage2D(PyObject *self, PyObject *args) { + GLenum target; + GLint level; + GLint xoffset; + GLint yoffset; + GLsizei width; + GLsizei height; + GLenum format; + GLenum type; + PyObject *pixelsPy; + + if( !PyArg_ParseTuple(args, "iiiiiiiiO:glTexSubImage2D", &target, &level, &xoffset, &yoffset, &width, &height, &format, &type, &pixelsPy) ) { + return NULL; + } + + return gles_wrap_glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixelsPy); +} + +/*PyObject *gles_glTexSubImage2DIO(PyObject *self, PyObject *args) { + GLenum target; + GLint level; + GLint xoffset; + GLint yoffset; + GLsizei width; + GLsizei height; + GLenum format; + GLenum type; + PyObject *image_object; + TSize imgsize; + + if( !PyArg_ParseTuple(args, "iiiiiiO:glTexSubImage2D", &target, &level, &xoffset, &yoffset, &format, &type, &image_object) ) { + return NULL; + } + + CFbsBitmap *bitmap=Bitmap_AsFbsBitmap(image_object); + if(bitmap == NULL) { + PyErr_SetString(PyExc_TypeError, "Expecting a graphics.Image object"); + return NULL; + } + + imgsize = bitmap->SizeInPixels(); + width = imgsize.iWidth; + height = imgsize.iHeight; + + return gles_wrap_glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, image_object); +} +*/ +PyObject *gles_glTranslatex (PyObject *self, PyObject *args) { + GLfixed x; + GLfixed y; + GLfixed z; + + if ( !PyArg_ParseTuple(args, "iii:glTranslatex", &x, &y, &z) ) { + return NULL; + } + glTranslatex(x, y, z); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glTranslatef(PyObject *self, PyObject *args) { + GLfloat x; + GLfloat y; + GLfloat z; + + if ( !PyArg_ParseTuple(args, "fff:glTranslatef", &x, &y, &z) ) { + return NULL; + } + glTranslatef(x, y, z); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glViewport (PyObject *self, PyObject *args) { + GLint x; + GLint y; + GLsizei width; + GLsizei height; + + if ( !PyArg_ParseTuple(args, "iiii:glViewport", &x, &y, &width, &height) ) { + return NULL; + } + glViewport(x, y, width, height); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_wrap_glVertexPointer(GLint size, GLenum type, GLsizei stride, PyObject *pointerPy) { + void *vptr = NULL; + array_object *arrobj=NULL; + + // We can use either the array type or a sequence + // Check the array type first + if(PyObject_TypeCheck(pointerPy, GLES_ARRAY_TYPE) ) { + arrobj = (array_object*)pointerPy; + vptr = arrobj->arrdata; + } +#ifdef GL_OES_VERSION_1_1 + else if(pointerPy == Py_None) { + vptr = NULL; + } +#endif + // Try to convert it as a sequence + else { + pointerPy = gles_PySequence_Collapse(type, pointerPy, NULL); + // glVertexPointer accepts only GL_BYTE, GL_SHORT, GL_FIXED or GL_FLOAT types + switch(type) { + case GL_BYTE: + vptr = gles_PySequence_AsGLbyteArray(pointerPy); + break; + case GL_SHORT: + vptr = gles_PySequence_AsGLshortArray(pointerPy); + break; + case GL_FIXED: + vptr = gles_PySequence_AsGLfixedArray(pointerPy); + break; + case GL_FLOAT: + vptr = gles_PySequence_AsGLfloatArray(pointerPy); + break; + default: + PyErr_SetString(PyExc_ValueError, "Invalid array type"); + return NULL; + } + if(vptr == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + } +#ifndef GL_OES_VERSION_1_1 + if(vptr == NULL) { + // Something went horribly wrong + // However, we should have an exception already + assert(PyErr_Occurred() != NULL); + return NULL; + } +#endif + gles_assign_array(GL_VERTEX_ARRAY, vptr, arrobj); + glVertexPointer(size, type, stride, vptr); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glVertexPointer(PyObject *self, PyObject *args) { + GLint size; + GLenum type; + GLsizei stride; + PyObject *pointerPy; + + if ( !PyArg_ParseTuple(args, "iiiO:glVertexPointer", &size, &type, &stride, &pointerPy) ) { + return NULL; + } + + return gles_wrap_glVertexPointer(size, type, stride, pointerPy); +} + +PyObject *gles_glVertexPointerb(PyObject *self, PyObject *args) { + GLint size; + PyObject *pointerPy; + + if ( !PyArg_ParseTuple(args, "O:glVertexPointerb", &pointerPy) ) { + return NULL; + } + + if(pointerPy == Py_None) { + gles_free_array(GL_VERTEX_ARRAY); + RETURN_PYNONE; + } + + // We can use either the array type or a sequence. + // Check the array type first. + if(PyObject_TypeCheck(pointerPy, GLES_ARRAY_TYPE) ) { + size = ((array_object*)pointerPy)->dimension; + } // Try to feed the object as a sequence. + else { + size = gles_PySequence_Dimension(pointerPy); + } + + return gles_wrap_glVertexPointer(size, /*type*/GL_BYTE, /*stride*/0, pointerPy); +} + +PyObject *gles_glVertexPointers(PyObject *self, PyObject *args) { + GLint size; + PyObject *pointerPy; + + if ( !PyArg_ParseTuple(args, "O:glVertexPointers", &pointerPy) ) { + return NULL; + } + + if(pointerPy == Py_None) { + gles_free_array(GL_VERTEX_ARRAY); + RETURN_PYNONE; + } + + // We can use either the array type or a sequence. + // Check the array type first. + if(PyObject_TypeCheck(pointerPy, GLES_ARRAY_TYPE) ) { + size = ((array_object*)pointerPy)->dimension; + } // Try to feed the object as a sequence. + else { + size = gles_PySequence_Dimension(pointerPy); + } + + return gles_wrap_glVertexPointer(size, /*type*/GL_SHORT, /*stride*/0, pointerPy); +} + +PyObject *gles_glVertexPointerx(PyObject *self, PyObject *args) { + GLint size; + PyObject *pointerPy; + + if ( !PyArg_ParseTuple(args, "O:glVertexPointerx", &pointerPy) ) { + return NULL; + } + + if(pointerPy == Py_None) { + gles_free_array(GL_VERTEX_ARRAY); + RETURN_PYNONE; + } + + // We can use either the array type or a sequence. + // Check the array type first. + if(PyObject_TypeCheck(pointerPy, GLES_ARRAY_TYPE) ) { + size = ((array_object*)pointerPy)->dimension; + } // Try to feed the object as a sequence. + else { + size = gles_PySequence_Dimension(pointerPy); + } + + return gles_wrap_glVertexPointer(size, /*type*/GL_FIXED, /*stride*/0, pointerPy); +} + +PyObject *gles_glVertexPointerf(PyObject *self, PyObject *args) { + GLint size; + PyObject *pointerPy; + + if ( !PyArg_ParseTuple(args, "O:glVertexPointerf", &pointerPy) ) { + return NULL; + } + + if(pointerPy == Py_None) { + gles_free_array(GL_VERTEX_ARRAY); + RETURN_PYNONE; + } + + // We can use either the array type or a sequence. + // Check the array type first. + if(PyObject_TypeCheck(pointerPy, GLES_ARRAY_TYPE) ) { + size = ((array_object*)pointerPy)->dimension; + } // Try to feed the object as a sequence. + else { + size = gles_PySequence_Dimension(pointerPy); + } + + return gles_wrap_glVertexPointer(size, /*type*/GL_FLOAT, /*stride*/0, pointerPy); +} + +// Functions which belong only to OpenGL ES 1.1 should go here +#ifdef GL_OES_VERSION_1_1 +PyObject *gles_glBindBuffer(PyObject *self, PyObject *args) { + GLenum target; + GLuint buffer; + + if( !PyArg_ParseTuple(args,"ii:glBindBuffer", &target, &buffer)) { + return NULL; + } + + glBindBuffer(target, buffer); + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_wrap_glBufferData(GLenum type, GLenum target, GLsizeiptr size, PyObject *dataPy, GLenum usage) { + GLvoid *data = NULL; + array_object *arrobj = NULL; + + if(PyObject_TypeCheck(dataPy, GLES_ARRAY_TYPE) ) { + arrobj = (array_object*)dataPy; + data = arrobj->arrdata; + + assert(data != NULL); + + if(size == -1) { + size = arrobj->real_len; + } + } // Try to convert it as a sequence + else { + if(type == 0) { + // Type not specified and cannot be determined + PyErr_SetString(PyExc_RuntimeError, "Cannot determine data type"); + return NULL; + } + GLsizeiptr size2=0; + dataPy = gles_PySequence_Collapse(type, dataPy, NULL); + switch(type) { + case GL_BYTE: + size2 = PySequence_Length(dataPy) * sizeof(GLbyte); + data = gles_PySequence_AsGLbyteArray(dataPy); + break; + case GL_UNSIGNED_BYTE: + size2 = PySequence_Length(dataPy) * sizeof(GLubyte); + data = gles_PySequence_AsGLubyteArray(dataPy); + break; + case GL_SHORT: + size2 = PySequence_Length(dataPy) * sizeof(GLshort); + data = gles_PySequence_AsGLshortArray(dataPy); + break; + case GL_UNSIGNED_SHORT: + size2 = PySequence_Length(dataPy) * sizeof(GLushort); + data = gles_PySequence_AsGLushortArray(dataPy); + break; + case GL_FIXED: + size2 = PySequence_Length(dataPy) * sizeof(GLfixed); + data = gles_PySequence_AsGLfixedArray(dataPy); + break; + case GL_FLOAT: + size2 = PySequence_Length(dataPy) * sizeof(GLfloat); + data = gles_PySequence_AsGLfloatArray(dataPy); + break; + default: + PyErr_SetString(PyExc_ValueError, "Invalid array type"); + return NULL; + break; + } + if(size == -1) { + size = size2; + } + } + + glBufferData(target, size, data, usage); + if(arrobj == NULL) { + gles_free(data); + } + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glBufferData(PyObject *self, PyObject *args) { + GLenum target; + GLsizeiptr size; + //GLvoid *data; + GLenum usage; + PyObject *dataPy; + + if ( !PyArg_ParseTuple(args, "iiOi:glBufferData", &target, &size, &dataPy, &usage)) { + return NULL; + } + + if( !PyObject_TypeCheck(dataPy, GLES_ARRAY_TYPE) ) { + PyErr_SetString(PyExc_TypeError, "Expecting a gles.array type"); + return NULL; + } + + return gles_wrap_glBufferData((GLenum)NULL, target, size, dataPy, usage); +} + +PyObject *gles_glBufferDatab(PyObject *self, PyObject *args) { + GLenum target; + GLsizeiptr size; + //GLvoid *data; + GLenum usage; + PyObject *dataPy; + + if ( !PyArg_ParseTuple(args, "iOi:glBufferDatab", &target, &dataPy, &usage)) { + return NULL; + } + + // Only array objects or sequences here + if(PyObject_TypeCheck(dataPy, GLES_ARRAY_TYPE) ) { + size = ((array_object*)dataPy)->real_len; + } // Try to feed the object as a sequence. + else { + // Expecting a 1D sequence + dataPy = gles_PySequence_Collapse(GL_BYTE, dataPy, NULL); + if(dataPy == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + size = PySequence_Length(dataPy)*sizeof(GLbyte); + } + + return gles_wrap_glBufferData(GL_BYTE, target, size, dataPy, usage); +} + +PyObject *gles_glBufferDataub(PyObject *self, PyObject *args) { + GLenum target; + GLsizeiptr size; + //GLvoid *data; + GLenum usage; + PyObject *dataPy; + + if ( !PyArg_ParseTuple(args, "iOi:glBufferDataub", &target, &dataPy, &usage)) { + return NULL; + } + + if(PyObject_TypeCheck(dataPy, GLES_ARRAY_TYPE) ) { + size = ((array_object*)dataPy)->real_len; + } // Try to feed the object as a sequence. + else { + // Expecting a 1D sequence + dataPy = gles_PySequence_Collapse(GL_UNSIGNED_BYTE, dataPy, NULL); + if(dataPy == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + size = PySequence_Length(dataPy)*sizeof(GLubyte); + } + + return gles_wrap_glBufferData(GL_UNSIGNED_BYTE, target, size, dataPy, usage); +} + +PyObject *gles_glBufferDatas(PyObject *self, PyObject *args) { + GLenum target; + GLsizeiptr size; + //GLvoid *data; + GLenum usage; + PyObject *dataPy; + + if ( !PyArg_ParseTuple(args, "iOi:glBufferDatas", &target, &dataPy, &usage)) { + return NULL; + } + + if(PyObject_TypeCheck(dataPy, GLES_ARRAY_TYPE) ) { + size = ((array_object*)dataPy)->real_len; + } // Try to feed the object as a sequence. + else { + // Expecting a 1D sequence + dataPy = gles_PySequence_Collapse(GL_SHORT, dataPy, NULL); + if(dataPy == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + size = PySequence_Length(dataPy)*sizeof(GLshort); + } + + return gles_wrap_glBufferData(GL_SHORT, target, size, dataPy, usage); +} + +PyObject *gles_glBufferDataus(PyObject *self, PyObject *args) { + GLenum target; + GLsizeiptr size; + //GLvoid *data; + GLenum usage; + PyObject *dataPy; + + if ( !PyArg_ParseTuple(args, "iOi:glBufferDataus", &target, &dataPy, &usage)) { + return NULL; + } + + if(PyObject_TypeCheck(dataPy, GLES_ARRAY_TYPE) ) { + size = ((array_object*)dataPy)->real_len; + } // Try to feed the object as a sequence. + else { + // Expecting a 1D sequence + dataPy = gles_PySequence_Collapse(GL_UNSIGNED_SHORT, dataPy, NULL); + if(dataPy == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + size = PySequence_Length(dataPy)*sizeof(GLushort); + } + + return gles_wrap_glBufferData(GL_UNSIGNED_SHORT, target, size, dataPy, usage); +} + + + +PyObject *gles_glBufferDataf(PyObject *self, PyObject *args) { + GLenum target; + GLsizeiptr size; + //GLvoid *data; + GLenum usage; + PyObject *dataPy; + + if ( !PyArg_ParseTuple(args, "iOi:glBufferDataf", &target, &dataPy, &usage)) { + return NULL; + } + + if(PyObject_TypeCheck(dataPy, GLES_ARRAY_TYPE) ) { + size = ((array_object*)dataPy)->real_len; + } // Try to feed the object as a sequence. + else { + // Expecting a 1D sequence + dataPy = gles_PySequence_Collapse(GL_FLOAT, dataPy, NULL); + if(dataPy == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + size = PySequence_Length(dataPy)*sizeof(GLfloat); + } + + return gles_wrap_glBufferData(GL_FLOAT, target, size, dataPy, usage); +} + +PyObject *gles_glBufferDatax(PyObject *self, PyObject *args) { + GLenum target; + GLsizeiptr size; + //GLvoid *data; + GLenum usage; + PyObject *dataPy; + + if ( !PyArg_ParseTuple(args, "iOi:glBufferDatax", &target, &dataPy, &usage)) { + return NULL; + } + + if(PyObject_TypeCheck(dataPy, GLES_ARRAY_TYPE) ) { + size = ((array_object*)dataPy)->real_len; + } // Try to feed the object as a sequence. + else { + // Expecting a 1D sequence + dataPy = gles_PySequence_Collapse(GL_FIXED, dataPy, NULL); + if(dataPy == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + size = PySequence_Length(dataPy)*sizeof(GLfixed); + } + + + + return gles_wrap_glBufferData(GL_FIXED, target, size, dataPy, usage); +} + +PyObject *gles_wrap_glBufferSubData(GLenum type, GLenum target, GLintptr offset, GLsizeiptr size, PyObject *dataPy) { + GLvoid *data = NULL; + array_object *arrobj = NULL; + + if(PyObject_TypeCheck(dataPy, GLES_ARRAY_TYPE) ) { + arrobj = (array_object*)dataPy; + data = arrobj->arrdata; + + assert(data != NULL); + + if(size == -1) { + size = arrobj->real_len; + } + } // Try to convert it as a sequence + else { + if(type == 0) { + // Type not specified and cannot be determined + PyErr_SetString(PyExc_RuntimeError, "Cannot determine data type"); + return NULL; + } + GLsizeiptr size2=0; + dataPy = gles_PySequence_Collapse(type, dataPy, NULL); + switch(type) { + case GL_BYTE: + size2 = PySequence_Length(dataPy) * sizeof(GLbyte); + data = gles_PySequence_AsGLbyteArray(dataPy); + break; + case GL_UNSIGNED_BYTE: + size2 = PySequence_Length(dataPy) * sizeof(GLubyte); + data = gles_PySequence_AsGLubyteArray(dataPy); + break; + case GL_SHORT: + size2 = PySequence_Length(dataPy) * sizeof(GLshort); + data = gles_PySequence_AsGLshortArray(dataPy); + break; + case GL_UNSIGNED_SHORT: + size2 = PySequence_Length(dataPy) * sizeof(GLushort); + data = gles_PySequence_AsGLushortArray(dataPy); + break; + case GL_FIXED: + size2 = PySequence_Length(dataPy) * sizeof(GLfixed); + data = gles_PySequence_AsGLfixedArray(dataPy); + break; + case GL_FLOAT: + size2 = PySequence_Length(dataPy) * sizeof(GLfloat); + data = gles_PySequence_AsGLfloatArray(dataPy); + break; + default: + PyErr_SetString(PyExc_ValueError, "Invalid array type"); + return NULL; + break; + } + if(size == -1) { + size = size2; + } + } + + glBufferSubData(target, offset, size, data); + if(arrobj == NULL) { + gles_free(data); + } + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glBufferSubData(PyObject *self, PyObject *args) { + GLenum target; + GLintptr offset; + GLsizeiptr size; + PyObject *dataPy; + + if ( !PyArg_ParseTuple(args, "iiO:glBufferSubData", &target, &offset, &size, &dataPy)) { + return NULL; + } + + if( !PyObject_TypeCheck(dataPy, GLES_ARRAY_TYPE) ) { + PyErr_SetString(PyExc_TypeError, "Expecting a gles.array type"); + return NULL; + } + + return gles_wrap_glBufferSubData((GLenum)NULL, target, offset, size, dataPy); +} + +PyObject *gles_glBufferSubDatab(PyObject *self, PyObject *args) { + GLenum target; + GLintptr offset; + GLsizeiptr size; + PyObject *dataPy; + + if ( !PyArg_ParseTuple(args, "iiO:glBufferSubDatab", &target, &offset, &dataPy)) { + return NULL; + } + + if(PyObject_TypeCheck(dataPy, GLES_ARRAY_TYPE) ) { + size = ((array_object*)dataPy)->real_len; + } // Try to feed the object as a sequence. + else { + // Expecting a 1D sequence + dataPy = gles_PySequence_Collapse(GL_BYTE, dataPy, NULL); + if(dataPy == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + size = PySequence_Length(dataPy)*sizeof(GLbyte); + } + + + + return gles_wrap_glBufferSubData(GL_BYTE, target, offset, size, dataPy); +} + +PyObject *gles_glBufferSubDataub(PyObject *self, PyObject *args) { + GLenum target; + GLintptr offset; + GLsizeiptr size; + PyObject *dataPy; + + if ( !PyArg_ParseTuple(args, "iiO:glBufferSubDataub", &target, &offset, &dataPy)) { + return NULL; + } + + if(PyObject_TypeCheck(dataPy, GLES_ARRAY_TYPE) ) { + size = ((array_object*)dataPy)->real_len; + } // Try to feed the object as a sequence. + else { + // Expecting a 1D sequence + dataPy = gles_PySequence_Collapse(GL_UNSIGNED_BYTE, dataPy, NULL); + if(dataPy == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + size = PySequence_Length(dataPy)*sizeof(GLubyte); + } + + return gles_wrap_glBufferSubData(GL_UNSIGNED_BYTE, target, offset, size, dataPy); +} + +PyObject *gles_glBufferSubDatas(PyObject *self, PyObject *args) { + GLenum target; + GLintptr offset; + GLsizeiptr size; + PyObject *dataPy; + + if ( !PyArg_ParseTuple(args, "iiO:glBufferSubDatas", &target, &offset, &dataPy)) { + return NULL; + } + + if(PyObject_TypeCheck(dataPy, GLES_ARRAY_TYPE) ) { + size = ((array_object*)dataPy)->real_len; + } // Try to feed the object as a sequence. + else { + // Expecting a 1D sequence + dataPy = gles_PySequence_Collapse(GL_SHORT, dataPy, NULL); + if(dataPy == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + size = PySequence_Length(dataPy)*sizeof(GLshort); + } + + + + return gles_wrap_glBufferSubData(GL_SHORT, target, offset, size, dataPy); +} + +PyObject *gles_glBufferSubDataus(PyObject *self, PyObject *args) { + GLenum target; + GLintptr offset; + GLsizeiptr size; + PyObject *dataPy; + + if ( !PyArg_ParseTuple(args, "iiO:glBufferSubDataus", &target, &offset, &dataPy)) { + return NULL; + } + + if(PyObject_TypeCheck(dataPy, GLES_ARRAY_TYPE) ) { + size = ((array_object*)dataPy)->real_len; + } // Try to feed the object as a sequence. + else { + // Expecting a 1D sequence + dataPy = gles_PySequence_Collapse(GL_UNSIGNED_SHORT, dataPy, NULL); + if(dataPy == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + size = PySequence_Length(dataPy)*sizeof(GLushort); + } + + + + return gles_wrap_glBufferSubData(GL_UNSIGNED_SHORT, target, offset, size, dataPy); +} + +PyObject *gles_glBufferSubDataf(PyObject *self, PyObject *args) { + GLenum target; + GLintptr offset; + GLsizeiptr size; + PyObject *dataPy; + + if ( !PyArg_ParseTuple(args, "iiO:glBufferSubDataf", &target, &offset, &dataPy)) { + return NULL; + } + + if(PyObject_TypeCheck(dataPy, GLES_ARRAY_TYPE) ) { + size = ((array_object*)dataPy)->real_len; + } // Try to feed the object as a sequence. + else { + // Expecting a 1D sequence + dataPy = gles_PySequence_Collapse(GL_FLOAT, dataPy, NULL); + if(dataPy == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + size = PySequence_Length(dataPy)*sizeof(GLfloat); + } + + + + return gles_wrap_glBufferSubData(GL_FLOAT, target, offset, size, dataPy); +} + +PyObject *gles_glBufferSubDatax(PyObject *self, PyObject *args) { + GLenum target; + GLintptr offset; + GLsizeiptr size; + PyObject *dataPy = NULL; + + if ( !PyArg_ParseTuple(args, "iiO:glBufferSubDatax", &target, &offset, &dataPy)) { + return NULL; + } + + if(PyObject_TypeCheck(dataPy, GLES_ARRAY_TYPE) ) { + size = ((array_object*)dataPy)->real_len; + } // Try to feed the object as a sequence. + else { + // Expecting a 1D sequence + dataPy = gles_PySequence_Collapse(GL_FIXED, dataPy, NULL); + if(dataPy == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + size = PySequence_Length(dataPy)*sizeof(GLfixed); + } + + return gles_wrap_glBufferSubData(GL_FIXED, target, offset, size, dataPy); +} + +PyObject *gles_glClipPlanef(PyObject *self, PyObject *args) { + GLenum plane; + GLfloat *equation = NULL; + PyObject *equationPy = NULL; + + if( !PyArg_ParseTuple(args, "iO:glClipPlanef", &plane, equationPy)) { + return NULL; + } + + if(! PySequence_Check(equationPy) || PySequence_Length(equationPy) != 4) { + PyErr_SetString(PyExc_ValueError,"Expecting a sequence of 4 values"); + return NULL; + } + + equation = gles_PySequence_AsGLfloatArray(equationPy); + if(equation == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + + glClipPlanef(plane, equation); + gles_free(equation); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glClipPlanex(PyObject *self, PyObject *args) { + GLenum plane; + GLfixed *equation = NULL; + PyObject *equationPy = NULL; + + if( !PyArg_ParseTuple(args, "iO:glClipPlanex", &plane, equationPy)) { + return NULL; + } + + if(! PySequence_Check(equationPy) || PySequence_Length(equationPy) != 4) { + PyErr_SetString(PyExc_ValueError,"Expecting a sequence of 4 values"); + return NULL; + } + + equation = gles_PySequence_AsGLfixedArray(equationPy); + if(equation == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + + glClipPlanex(plane, equation); + gles_free(equation); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +/*PyObject *gles_glCurrentPaletteMatrixOES(PyObject *self, PyObject *args) { + GLuint index; + + if( !PyArg_ParseTuple(args, "i:glCurrentPaletteMatrixOES", &index)) { + return NULL; + } + + void (*func)(...) = NULL; + func = eglGetProcAddress("glCurrentPaletteMatrixOES"); + if(func) { + func(index); + } else { + PyErr_SetString(PyExc_NotImplementedError, "Extension not found"); + return NULL; + } + RETURN_IF_GLERROR; + RETURN_PYNONE; +}*/ + +PyObject *gles_glDeleteBuffers(PyObject *self, PyObject *args) { + GLsizei n; + GLuint *buffers = NULL; + PyObject *buffersPy; + + if( !PyArg_ParseTuple(args, "O:glDeleteBuffers", &buffersPy)) { + return NULL; + } + + n = PySequence_Length(buffersPy); + buffers = gles_PySequence_AsGLuintArray(buffersPy); + if(buffers == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + + glDeleteBuffers(n, buffers); + gles_free(buffers); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glDrawTexsOES(PyObject *self, PyObject *args) { + GLshort x; + GLshort y; + GLshort z; + GLshort width; + GLshort height; + + if( !PyArg_ParseTuple(args, "iiiii:glDrawTexsOES", &x, &y, &z, &width, &height)) { + return NULL; + } + + void (*func)(GLshort, GLshort, GLshort, GLshort, GLshort) = NULL; + func = eglGetProcAddress("glDrawTexsOES"); + if(func) { + func(x,y,z,width,height); + } else { + PyErr_SetString(PyExc_NotImplementedError, "Extension not found"); + return NULL; + } + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glDrawTexiOES(PyObject *self, PyObject *args) { + GLint x; + GLint y; + GLint z; + GLint width; + GLint height; + + if( !PyArg_ParseTuple(args, "iiiii:glDrawTexiOES", &x, &y, &z, &width, &height)) { + return NULL; + } + + void (*func)(GLint, GLint, GLint, GLint, GLint) = NULL; + func = eglGetProcAddress("glDrawTexiOES"); + if(func) { + func(x,y,z,width,height); + } else { + PyErr_SetString(PyExc_NotImplementedError, "Extension not found"); + return NULL; + } + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glDrawTexfOES(PyObject *self, PyObject *args) { + GLfloat x; + GLfloat y; + GLfloat z; + GLfloat width; + GLfloat height; + + if( !PyArg_ParseTuple(args, "fffff:glDrawTexfOES", &x, &y, &z, &width, &height)) { + return NULL; + } + + void (*func)(GLfloat, GLfloat, GLfloat, GLfloat, GLfloat) = NULL; + func = eglGetProcAddress("glDrawTexfOES"); + if(func) { + func(x,y,z,width,height); + } else { + PyErr_SetString(PyExc_NotImplementedError, "Extension not found"); + return NULL; + } + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glDrawTexxOES(PyObject *self, PyObject *args) { + GLfixed x; + GLfixed y; + GLfixed z; + GLfixed width; + GLfixed height; + + if( !PyArg_ParseTuple(args, "iiiii:glDrawTexxOES", &x, &y, &z, &width, &height)) { + return NULL; + } + + void (*func)(GLfixed, GLfixed, GLfixed, GLfixed, GLfixed) = NULL; + func = eglGetProcAddress("glDrawTexxOES"); + if(func) { + func(x,y,z,width,height); + } else { + PyErr_SetString(PyExc_NotImplementedError, "Extension not found"); + return NULL; + } + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glDrawTexsvOES(PyObject *self, PyObject *args) { + GLshort *coords; + PyObject *coordsPy; + + if( !PyArg_ParseTuple(args, "O", &coordsPy)) { + return NULL; + } + + coordsPy = gles_PySequence_Collapse(GL_SHORT, coordsPy, NULL); + if(coordsPy == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + + coords = gles_PySequence_AsGLshortArray(coordsPy); + if(coords == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + + void (*func)(GLshort*) = NULL; + func = eglGetProcAddress("glDrawTexsvOES"); + if(func) { + func(coords); + } else { + gles_free(coords); + PyErr_SetString(PyExc_NotImplementedError, "Extension not found"); + return NULL; + } + gles_free(coords); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glDrawTexivOES(PyObject *self, PyObject *args) { + GLint *coords = NULL; + PyObject *coordsPy = NULL; + + if( !PyArg_ParseTuple(args, "O", &coordsPy)) { + return NULL; + } + + coordsPy = gles_PySequence_Collapse(GL_SHORT, coordsPy, NULL); + if(coordsPy == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + + coords = gles_PySequence_AsGLintArray(coordsPy); + if(coords == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + + void (*func)(GLint*) = NULL; + func = eglGetProcAddress("glDrawTexivOES"); + if(func) { + func(coords); + } else { + gles_free(coords); + PyErr_SetString(PyExc_NotImplementedError, "Extension not found"); + return NULL; + } + gles_free(coords); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glDrawTexfvOES(PyObject *self, PyObject *args) { + GLfloat *coords; + PyObject *coordsPy; + + if( !PyArg_ParseTuple(args, "O", &coordsPy)) { + return NULL; + } + + coordsPy = gles_PySequence_Collapse(GL_FLOAT, coordsPy, NULL); + if(coordsPy == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + + coords = gles_PySequence_AsGLfloatArray(coordsPy); + if(coords == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + + void (*func)(GLfloat*) = NULL; + func = eglGetProcAddress("glDrawTexfvOES"); + if(func) { + func(coords); + } else { + gles_free(coords); + PyErr_SetString(PyExc_NotImplementedError, "Extension not found"); + return NULL; + } + gles_free(coords); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glDrawTexxvOES(PyObject *self, PyObject *args) { + GLfixed *coords; + PyObject *coordsPy; + + if( !PyArg_ParseTuple(args, "O", &coordsPy)) { + return NULL; + } + + coordsPy = gles_PySequence_Collapse(GL_FIXED, coordsPy, NULL); + if(coordsPy == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + + coords = gles_PySequence_AsGLfixedArray(coordsPy); + if(coords == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + + void (*func)(GLfixed*) = NULL; + func = eglGetProcAddress("glDrawTexxvOES"); + if(func) { + func(coords); + } else { + gles_free(coords); + PyErr_SetString(PyExc_NotImplementedError, "Extension not found"); + return NULL; + } + gles_free(coords); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glGenBuffers(PyObject *self, PyObject *args) { + GLuint *buffers = NULL; + GLuint n; + unsigned int i; + PyObject *ret; + + if( !PyArg_ParseTuple(args, "i:glGenBuffers", &n) ) { + return NULL; + } + + if(n < 1) { + PyErr_SetString(PyExc_ValueError, "Value must be positive"); + return NULL; + } + + buffers = (GLuint*)gles_alloc( sizeof(GLuint)*n ); + + glGenBuffers( n, buffers); + ret = PyTuple_New(n); + + if(n > 1) { + ret = PyTuple_New(n); + + for(i=0;iarrdata; + } else if(pointerPy == Py_None) { + mptr = NULL; + } // Try to convert it as a sequence + else { + pointerPy = gles_PySequence_Collapse(type, pointerPy, NULL); + if(pointerPy == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + switch(type) { + case GL_UNSIGNED_BYTE: + mptr = gles_PySequence_AsGLubyteArray(pointerPy); + break; + default: + PyErr_SetString(PyExc_ValueError, "Unsupported array type"); + return NULL; + break; + } + if(mptr == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + } + + gles_assign_array(GL_MATRIX_INDEX_ARRAY_OES, mptr, arrobj); + func(size, type, stride, mptr); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glMatrixIndexPointerOES(PyObject *self, PyObject *args) { + GLint size; + GLenum type; + GLsizei stride; + + PyObject * pointerPy; + if ( !PyArg_ParseTuple(args, "iiiO:glMatrixIndexPointerOES", &size, &type, &stride, &pointerPy) ) { + return NULL; + } + + return gles_wrap_glMatrixIndexPointerOES(size, type, stride, pointerPy); +} + +PyObject *gles_glMatrixIndexPointerOESub(PyObject *self, PyObject *args) { + GLint size; + + PyObject * pointerPy; + if ( !PyArg_ParseTuple(args, "O:glMatrixIndexPointerOESub", &pointerPy) ) { + return NULL; + } + + if(pointerPy == Py_None) { + gles_free_array(GL_MATRIX_INDEX_ARRAY_OES); + RETURN_PYNONE; + } + + if( PyObject_TypeCheck(pointerPy, GLES_ARRAY_TYPE) ) { + size = ((array_object*)pointerPy)->dimension; + } else { + size = gles_PySequence_Dimension(pointerPy); + } + + return gles_wrap_glMatrixIndexPointerOES(size, /*type*/ GL_UNSIGNED_BYTE, /*stride*/ 0, pointerPy); +} + +PyObject * gles_glPointParameterf(PyObject *self, PyObject *args) { + GLenum pname; + GLfloat param; + + if( !PyArg_ParseTuple(args, "if:glPointParameterf", &pname, ¶m)) { + return NULL; + } + + glPointParameterf(pname, param); + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject * gles_glPointParameterx(PyObject *self, PyObject *args) { + GLenum pname; + GLfixed param; + + if( !PyArg_ParseTuple(args, "ii:glPointParameterx", &pname, ¶m)) { + return NULL; + } + + glPointParameterx(pname, param); + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glPointParameterfv(PyObject *self, PyObject *args) { + GLenum pname; + GLfloat *params = NULL; + PyObject *paramsPy; + + if( !PyArg_ParseTuple(args, "iO:glPointParameterfv", &pname, ¶msPy)) { + return NULL; + } + + params = gles_PySequence_AsGLfloatArray(paramsPy); + if(params == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + + glPointParameterfv(pname, params); + gles_free(params); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glPointParameterxv(PyObject *self, PyObject *args) { + GLenum pname; + GLfixed *params = NULL; + PyObject *paramsPy; + + if( !PyArg_ParseTuple(args, "iO:glPointParameterfv", &pname, ¶msPy)) { + return NULL; + } + + params = gles_PySequence_AsGLfixedArray(paramsPy); + if(params == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + + glPointParameterxv(pname, params); + gles_free(params); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_wrap_glPointSizePointerOES(GLenum type, GLsizei stride, PyObject *pointerPy) { + void *psptr = NULL; + array_object *arrobj=NULL; + void (*func)(GLenum, GLsizei, void*) = NULL; + + func = eglGetProcAddress("glPointSizePointerOES"); + if(!func) { + PyErr_SetString(PyExc_NotImplementedError, "Extension not found"); + return NULL; + } + + // We can use either the array type or a sequence + // Check the array type first + if(PyObject_TypeCheck(pointerPy, GLES_ARRAY_TYPE) ) { + arrobj = (array_object*)pointerPy; + psptr = arrobj->arrdata; + } else if(pointerPy == Py_None) { + psptr = NULL; + } // Try to convert it as a sequence + else { + pointerPy = gles_PySequence_Collapse(type, pointerPy, NULL); + if(pointerPy == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + switch(type) { + case GL_FLOAT: + psptr = gles_PySequence_AsGLfloatArray(pointerPy); + break; + case GL_FIXED: + psptr = gles_PySequence_AsGLfixedArray(pointerPy); + break; + default: + PyErr_SetString(PyExc_ValueError, "Unsupported array type"); + return NULL; + break; + } + if(psptr == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + } + + gles_assign_array(GL_POINT_SIZE_ARRAY_OES, psptr, arrobj); + func(type, stride, psptr); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glPointSizePointerOES(PyObject *self, PyObject *args) { + GLenum type; + GLsizei stride; + + PyObject * pointerPy; + if ( !PyArg_ParseTuple(args, "iiiO:glPointSizePointerOES", &type, &stride, &pointerPy) ) { + return NULL; + } + + return gles_wrap_glPointSizePointerOES(type, stride, pointerPy); +} + +PyObject *gles_glPointSizePointerOESf(PyObject *self, PyObject *args) { + PyObject * pointerPy; + if ( !PyArg_ParseTuple(args, "O:glPointSizePointerOESf", &pointerPy) ) { + return NULL; + } + + if(pointerPy == Py_None) { + gles_free_array(GL_POINT_SIZE_ARRAY_OES); + RETURN_PYNONE; + } + + return gles_wrap_glPointSizePointerOES(/*type*/ GL_FLOAT, /*stride*/ 0, pointerPy); +} + +PyObject *gles_glPointSizePointerOESx(PyObject *self, PyObject *args) { + PyObject * pointerPy; + if ( !PyArg_ParseTuple(args, "O:glPointSizePointerOESx", &pointerPy) ) { + return NULL; + } + + if(pointerPy == Py_None) { + gles_free_array(GL_POINT_SIZE_ARRAY_OES); + RETURN_PYNONE; + } + + return gles_wrap_glPointSizePointerOES(/*type*/ GL_FIXED, /*stride*/ 0, pointerPy); +} + +PyObject *gles_wrap_glWeightPointerOES(GLint size, GLenum type, GLsizei stride, PyObject *pointerPy) { + void *wptr = NULL; + array_object *arrobj=NULL; + void (*func)(GLint, GLenum, GLsizei, void*) = NULL; + + func = eglGetProcAddress("glWeightPointerOES"); + if(!func) { + PyErr_SetString(PyExc_NotImplementedError, "Extension not found"); + return NULL; + } + + // We can use either the array type or a sequence + // Check the array type first + if(PyObject_TypeCheck(pointerPy, GLES_ARRAY_TYPE) ) { + arrobj = (array_object*)pointerPy; + wptr = arrobj->arrdata; + } else if(pointerPy == Py_None) { + wptr = NULL; + } // Try to convert it as a sequence + else { + pointerPy = gles_PySequence_Collapse(type, pointerPy, NULL); + if(pointerPy == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + switch(type) { + case GL_FLOAT: + wptr = gles_PySequence_AsGLfloatArray(pointerPy); + break; + case GL_FIXED: + wptr = gles_PySequence_AsGLfixedArray(pointerPy); + break; + default: + PyErr_SetString(PyExc_ValueError, "Unsupported array type"); + return NULL; + break; + } + if(wptr == NULL) { + assert(PyErr_Occurred() != NULL); + return NULL; + } + } + + gles_assign_array(GL_WEIGHT_ARRAY_OES, wptr, arrobj); + func(size, type, stride, wptr); + + RETURN_IF_GLERROR; + RETURN_PYNONE; +} + +PyObject *gles_glWeightPointerOES(PyObject *self, PyObject *args) { + GLint size; + GLenum type; + GLsizei stride; + + PyObject * pointerPy; + if ( !PyArg_ParseTuple(args, "iiiO:glWeightPointerOES", &size, &type, &stride, &pointerPy) ) { + return NULL; + } + + return gles_wrap_glWeightPointerOES(size, type, stride, pointerPy); +} + +PyObject *gles_glWeightPointerOESf(PyObject *self, PyObject *args) { + GLint size; + + PyObject * pointerPy; + if ( !PyArg_ParseTuple(args, "O:glWeightPointerOESf", &pointerPy) ) { + return NULL; + } + + if(pointerPy == Py_None) { + gles_free_array(GL_WEIGHT_ARRAY_OES); + RETURN_PYNONE; + } + + if( PyObject_TypeCheck(pointerPy, GLES_ARRAY_TYPE) ) { + size = ((array_object*)pointerPy)->dimension; + } else { + size = gles_PySequence_Dimension(pointerPy); + } + + return gles_wrap_glWeightPointerOES(size, /*type*/ GL_FLOAT, /*stride*/ 0, pointerPy); +} + +PyObject *gles_glWeightPointerOESx(PyObject *self, PyObject *args) { + GLint size; + + PyObject * pointerPy; + if ( !PyArg_ParseTuple(args, "O:glWeightPointerOESx", &pointerPy) ) { + return NULL; + } + + if(pointerPy == Py_None) { + gles_free_array(GL_WEIGHT_ARRAY_OES); + RETURN_PYNONE; + } + + if( PyObject_TypeCheck(pointerPy, GLES_ARRAY_TYPE) ) { + size = ((array_object*)pointerPy)->dimension; + } else { + size = gles_PySequence_Dimension(pointerPy); + } + + return gles_wrap_glWeightPointerOES(size, /*type*/ GL_FIXED, /*stride*/ 0, pointerPy); +} + +#endif + +/***************************************************** + * Utility functions for your Python coding pleasure * + *****************************************************/ + +/** + * Checks if an extension function is available + * + * @return Py_True if the given extension function is available, Py_False otherwise + */ +PyObject *gles_CheckExtension(PyObject *self, PyObject *args) { + char *funcname = NULL; + + if( !PyArg_ParseTuple(args, "s", &funcname) ) { + return NULL; + } + + if(eglGetProcAddress(funcname) != NULL) { + RETURN_PYTRUE; + } + RETURN_PYFALSE; +} + +//////////////INIT//////////////////////////// + +//{ + static const PyMethodDef gles_methods[] = { + //{"Image2str", (PyCFunction)gles_Image2str, METH_VARARGS, NULL}, + {"CheckExtension", (PyCFunction)gles_CheckExtension, METH_VARARGS, NULL}, +#ifdef GL_OES_VERSION_1_1 + {"glBindBuffer", (PyCFunction)gles_glBindBuffer, METH_VARARGS, NULL}, + {"glBufferData", (PyCFunction)gles_glBufferData, METH_VARARGS, NULL}, + {"glBufferDatab", (PyCFunction)gles_glBufferDatab, METH_VARARGS, NULL}, + {"glBufferDataub", (PyCFunction)gles_glBufferDataub, METH_VARARGS, NULL}, + {"glBufferDatas", (PyCFunction)gles_glBufferDatas, METH_VARARGS, NULL}, + {"glBufferDataus", (PyCFunction)gles_glBufferDataus, METH_VARARGS, NULL}, + {"glBufferDataf", (PyCFunction)gles_glBufferDataf, METH_VARARGS, NULL}, + {"glBufferDatax", (PyCFunction)gles_glBufferDatax, METH_VARARGS, NULL}, + {"glBufferSubData", (PyCFunction)gles_glBufferSubData, METH_VARARGS, NULL}, + {"glBufferSubDataub", (PyCFunction)gles_glBufferSubDataub, METH_VARARGS, NULL}, + {"glBufferSubDatas", (PyCFunction)gles_glBufferSubDatas, METH_VARARGS, NULL}, + {"glBufferSubDataus", (PyCFunction)gles_glBufferSubDataus, METH_VARARGS, NULL}, + {"glBufferSubDataf", (PyCFunction)gles_glBufferSubDataf, METH_VARARGS, NULL}, + {"glBufferSubDatax", (PyCFunction)gles_glBufferSubDatax, METH_VARARGS, NULL}, + + {"glClipPlanef", (PyCFunction)gles_glClipPlanef, METH_VARARGS, NULL}, + {"glClipPlanex", (PyCFunction)gles_glClipPlanex, METH_VARARGS, NULL}, + //{"glCurrentPaletteMatrixOES", (PyCFunction)gles_glCurrentPaletteMatrixOES, METH_VARARGS, NULL}, + + {"glDeleteBuffers", (PyCFunction)gles_glDeleteBuffers, METH_VARARGS, NULL}, + {"glDrawTexsOES", (PyCFunction)gles_glDrawTexsOES, METH_VARARGS, NULL}, + {"glDrawTexiOES", (PyCFunction)gles_glDrawTexiOES, METH_VARARGS, NULL}, + {"glDrawTexfOES", (PyCFunction)gles_glDrawTexfOES, METH_VARARGS, NULL}, + {"glDrawTexxOES", (PyCFunction)gles_glDrawTexxOES, METH_VARARGS, NULL}, + {"glDrawTexsvOES", (PyCFunction)gles_glDrawTexsvOES, METH_VARARGS, NULL}, + {"glDrawTexivOES", (PyCFunction)gles_glDrawTexivOES, METH_VARARGS, NULL}, + {"glDrawTexfvOES", (PyCFunction)gles_glDrawTexfvOES, METH_VARARGS, NULL}, + {"glDrawTexxvOES", (PyCFunction)gles_glDrawTexxvOES, METH_VARARGS, NULL}, + + {"glGenBuffers", (PyCFunction)gles_glGenBuffers, METH_VARARGS, NULL}, + {"glGetBooleanv", (PyCFunction)gles_glGetBooleanv, METH_VARARGS, NULL}, + {"glGetBufferParameteriv", (PyCFunction)gles_glGetBufferParameteriv, METH_VARARGS, NULL}, + {"glGetClipPlanef", (PyCFunction)gles_glGetClipPlanef, METH_VARARGS, NULL}, + {"glGetClipPlanex", (PyCFunction)gles_glGetClipPlanex, METH_VARARGS, NULL}, + {"glGetFixedv", (PyCFunction)gles_glGetFixedv, METH_VARARGS, NULL}, + {"glGetFloatv", (PyCFunction)gles_glGetFloatv, METH_VARARGS, NULL}, + {"glGetLightfv", (PyCFunction)gles_glGetLightfv, METH_VARARGS, NULL}, + {"glGetLightxv", (PyCFunction)gles_glGetLightxv, METH_VARARGS, NULL}, + {"glGetMaterialfv", (PyCFunction)gles_glGetMaterialfv, METH_VARARGS, NULL}, + {"glGetMaterialxv", (PyCFunction)gles_glGetMaterialxv, METH_VARARGS, NULL}, + // glGetPointerv not implemented + {"glGetTexEnvf", (PyCFunction)gles_glGetTexEnvf, METH_VARARGS, NULL}, + {"glGetTexEnvx", (PyCFunction)gles_glGetTexEnvx, METH_VARARGS, NULL}, + + {"glIsBuffer", (PyCFunction)gles_glIsBuffer, METH_VARARGS, NULL}, + {"glIsEnabled", (PyCFunction)gles_glIsEnabled, METH_VARARGS, NULL}, + {"glIsTexture", (PyCFunction)gles_glIsTexture, METH_VARARGS, NULL}, + + {"glLoadPaletteFromModelViewMatrixOES",(PyCFunction)gles_glLoadPaletteFromModelViewMatrixOES,METH_NOARGS, NULL}, + {"glMatrixIndexPointerOES", (PyCFunction)gles_glMatrixIndexPointerOES, METH_VARARGS, NULL}, + {"glMatrixIndexPointerOESub", (PyCFunction)gles_glMatrixIndexPointerOESub, METH_VARARGS, NULL}, + {"glPointParameterf", (PyCFunction)gles_glPointParameterf, METH_VARARGS, NULL}, + {"glPointParameterx", (PyCFunction)gles_glPointParameterx, METH_VARARGS, NULL}, + {"glPointParameterfv", (PyCFunction)gles_glPointParameterfv, METH_VARARGS, NULL}, + {"glPointParameterxv", (PyCFunction)gles_glPointParameterxv, METH_VARARGS, NULL}, + + {"glPointSizePointerOES", (PyCFunction)gles_glPointSizePointerOES, METH_VARARGS, NULL}, + {"glPointSizePointerOESf", (PyCFunction)gles_glPointSizePointerOESf, METH_VARARGS, NULL}, + {"glPointSizePointerOESx", (PyCFunction)gles_glPointSizePointerOESx, METH_VARARGS, NULL}, + + {"glWeightPointerOES", (PyCFunction)gles_glWeightPointerOES, METH_VARARGS, NULL}, + {"glWeightPointerOESf", (PyCFunction)gles_glWeightPointerOESf, METH_VARARGS, NULL}, + {"glWeightPointerOESx", (PyCFunction)gles_glWeightPointerOESx, METH_VARARGS, NULL}, +#endif + {"array", (PyCFunction)new_array_object, METH_VARARGS, NULL}, + + {"glActiveTexture", (PyCFunction)gles_glActiveTexture, METH_VARARGS, NULL}, + {"glAlphaFunc", (PyCFunction)gles_glAlphaFunc, METH_VARARGS, NULL}, + {"glAlphaFuncx", (PyCFunction)gles_glAlphaFuncx, METH_VARARGS, NULL}, + + {"glBindTexture", (PyCFunction)gles_glBindTexture, METH_VARARGS, NULL}, + {"glBlendFunc", (PyCFunction)gles_glBlendFunc, METH_VARARGS, NULL}, + + {"glClear", (PyCFunction)gles_glClear, METH_VARARGS, NULL}, + {"glClearColor", (PyCFunction)gles_glClearColor, METH_VARARGS, NULL}, + {"glClearColorx", (PyCFunction)gles_glClearColorx, METH_VARARGS, NULL}, + {"glClearDepthf", (PyCFunction)gles_glClearDepthf, METH_VARARGS, NULL}, + {"glClearDepthx", (PyCFunction)gles_glClearDepthx, METH_VARARGS, NULL}, + {"glClearStencil", (PyCFunction)gles_glClearStencil, METH_VARARGS, NULL}, + {"glClientActiveTexture", (PyCFunction)gles_glClientActiveTexture, METH_VARARGS, NULL}, + {"glColor4f", (PyCFunction)gles_glColor4f, METH_VARARGS, NULL}, + {"glColor4x", (PyCFunction)gles_glColor4x, METH_VARARGS, NULL}, + {"glColorPointer", (PyCFunction)gles_glColorPointer, METH_VARARGS, NULL}, + {"glColorPointerub", (PyCFunction)gles_glColorPointerub, METH_VARARGS, NULL}, + {"glColorPointerf", (PyCFunction)gles_glColorPointerf, METH_VARARGS, NULL}, + {"glColorPointerx", (PyCFunction)gles_glColorPointerx, METH_VARARGS, NULL}, + + {"glCompressedTexImage2D", (PyCFunction)gles_glCompressedTexImage2D, METH_VARARGS, NULL}, + {"glCompressedTexSubImage2D", (PyCFunction)gles_glCompressedTexSubImage2D, METH_VARARGS, NULL}, + {"glCopyTexImage2D", (PyCFunction)gles_glCopyTexImage2D, METH_VARARGS, NULL}, + {"glCopyTexSubImage2D", (PyCFunction)gles_glCopyTexSubImage2D, METH_VARARGS, NULL}, + {"glCullFace", (PyCFunction)gles_glCullFace, METH_VARARGS, NULL}, + + {"glDeleteTextures", (PyCFunction)gles_glDeleteTextures, METH_VARARGS, NULL}, + {"glDepthFunc", (PyCFunction)gles_glDepthFunc, METH_VARARGS, NULL}, + {"glDepthMask", (PyCFunction)gles_glDepthMask, METH_VARARGS, NULL}, + {"glDepthRangef", (PyCFunction)gles_glDepthRangef, METH_VARARGS, NULL}, + {"glDepthRangex", (PyCFunction)gles_glDepthRangex, METH_VARARGS, NULL}, + {"glDisable", (PyCFunction)gles_glDisable, METH_VARARGS, NULL}, + {"glDisableClientState", (PyCFunction)gles_glDisableClientState, METH_VARARGS, NULL}, + {"glDrawArrays", (PyCFunction)gles_glDrawArrays, METH_VARARGS, NULL}, + {"glDrawElements", (PyCFunction)gles_glDrawElements, METH_VARARGS, NULL}, + {"glDrawElementsub", (PyCFunction)gles_glDrawElementsub, METH_VARARGS, NULL}, + {"glDrawElementsus", (PyCFunction)gles_glDrawElementsus, METH_VARARGS, NULL}, + + {"glEnable", (PyCFunction)gles_glEnable, METH_VARARGS, NULL}, + {"glEnableClientState", (PyCFunction)gles_glEnableClientState, METH_VARARGS, NULL}, + + {"glFinish", (PyCFunction)gles_glFinish, METH_VARARGS, NULL}, + {"glFlush", (PyCFunction)gles_glFlush, METH_VARARGS, NULL}, + + {"glFogf", (PyCFunction)gles_glFogf, METH_VARARGS, NULL}, + {"glFogfv", (PyCFunction)gles_glFogfv, METH_VARARGS, NULL}, + {"glFogx", (PyCFunction)gles_glFogx, METH_VARARGS, NULL}, + {"glFogxv", (PyCFunction)gles_glFogxv, METH_VARARGS, NULL}, + {"glFrontFace", (PyCFunction)gles_glFrontFace, METH_VARARGS, NULL}, + {"glFrustumf", (PyCFunction)gles_glFrustumf, METH_VARARGS, NULL}, + {"glFrustumx", (PyCFunction)gles_glFrustumx, METH_VARARGS, NULL}, + + {"glGenTextures", (PyCFunction)gles_glGenTextures, METH_VARARGS, NULL}, + {"glGetIntegerv", (PyCFunction)gles_glGetIntegerv, METH_VARARGS, NULL}, + {"glGetString", (PyCFunction)gles_glGetString, METH_VARARGS, NULL}, + + {"glHint", (PyCFunction)gles_glHint, METH_VARARGS, NULL}, + + {"glLightModelf", (PyCFunction)gles_glLightModelf, METH_VARARGS, NULL}, + {"glLightModelfv", (PyCFunction)gles_glLightModelfv, METH_VARARGS, NULL}, + {"glLightModelx", (PyCFunction)gles_glLightModelx, METH_VARARGS, NULL}, + {"glLightModelxv", (PyCFunction)gles_glLightModelxv, METH_VARARGS, NULL}, + {"glLightf", (PyCFunction)gles_glLightf, METH_VARARGS, NULL}, + {"glLightfv", (PyCFunction)gles_glLightfv, METH_VARARGS, NULL}, + {"glLightx", (PyCFunction)gles_glLightx, METH_VARARGS, NULL}, + {"glLightxv", (PyCFunction)gles_glLightxv, METH_VARARGS, NULL}, + {"glLineWidth", (PyCFunction)gles_glLineWidth, METH_VARARGS, NULL}, + {"glLineWidthx", (PyCFunction)gles_glLineWidthx, METH_VARARGS, NULL}, + {"glLoadIdentity", (PyCFunction)gles_glLoadIdentity, METH_NOARGS, NULL}, + {"glLoadMatrixf", (PyCFunction)gles_glLoadMatrixf, METH_VARARGS, NULL}, + {"glLoadMatrixx", (PyCFunction)gles_glLoadMatrixx, METH_VARARGS, NULL}, + {"glLogicOp", (PyCFunction)gles_glLogicOp, METH_VARARGS, NULL}, + + {"glMaterialf", (PyCFunction)gles_glMaterialf, METH_VARARGS, NULL}, + {"glMaterialfv", (PyCFunction)gles_glMaterialfv, METH_VARARGS, NULL}, + {"glMaterialx", (PyCFunction)gles_glMaterialx, METH_VARARGS, NULL}, + {"glMaterialxv", (PyCFunction)gles_glMaterialxv, METH_VARARGS, NULL}, + {"glMatrixMode", (PyCFunction)gles_glMatrixMode, METH_VARARGS, NULL}, + {"glMultMatrixf", (PyCFunction)gles_glMultMatrixf, METH_VARARGS, NULL}, + {"glMultMatrixx", (PyCFunction)gles_glMultMatrixx, METH_VARARGS, NULL}, + {"glMultiTexCoord4f", (PyCFunction)gles_glMultiTexCoord4f, METH_VARARGS, NULL}, + {"glMultiTexCoord4x", (PyCFunction)gles_glMultiTexCoord4x, METH_VARARGS, NULL}, + + {"glNormal3f", (PyCFunction)gles_glNormal3f, METH_VARARGS, NULL}, + {"glNormal3x", (PyCFunction)gles_glNormal3x, METH_VARARGS, NULL}, + {"glNormalPointer", (PyCFunction)gles_glNormalPointer, METH_VARARGS, NULL}, + {"glNormalPointerb", (PyCFunction)gles_glNormalPointerb, METH_VARARGS, NULL}, + {"glNormalPointers", (PyCFunction)gles_glNormalPointers, METH_VARARGS, NULL}, + {"glNormalPointerf", (PyCFunction)gles_glNormalPointerf, METH_VARARGS, NULL}, + {"glNormalPointerx", (PyCFunction)gles_glNormalPointerx, METH_VARARGS, NULL}, + + {"glOrthof", (PyCFunction)gles_glOrthof, METH_VARARGS, NULL}, + {"glOrthox", (PyCFunction)gles_glOrthox, METH_VARARGS, NULL}, + + {"glPixelStorei", (PyCFunction)gles_glPixelStorei, METH_VARARGS, NULL}, + {"glPointSize", (PyCFunction)gles_glPointSize, METH_VARARGS, NULL}, + {"glPointSizex", (PyCFunction)gles_glPointSizex, METH_VARARGS, NULL}, + {"glPolygonOffset", (PyCFunction)gles_glPolygonOffset, METH_VARARGS, NULL}, + {"glPolygonOffsetx", (PyCFunction)gles_glPolygonOffsetx, METH_VARARGS, NULL}, + {"glPopMatrix", (PyCFunction)gles_glPopMatrix, METH_NOARGS, NULL}, + {"glPushMatrix", (PyCFunction)gles_glPushMatrix, METH_NOARGS, NULL}, + + {"glReadPixels", (PyCFunction)gles_glReadPixels, METH_VARARGS, NULL}, + {"glRotatex", (PyCFunction)gles_glRotatex, METH_VARARGS, NULL}, + {"glRotatef", (PyCFunction)gles_glRotatef, METH_VARARGS, NULL}, + + {"glScalef", (PyCFunction)gles_glScalef, METH_VARARGS, NULL}, + {"glScalex", (PyCFunction)gles_glScalex, METH_VARARGS, NULL}, + {"glScissor", (PyCFunction)gles_glScissor, METH_VARARGS, NULL}, + {"glShadeModel", (PyCFunction)gles_glShadeModel, METH_VARARGS, NULL}, + {"glStencilFunc", (PyCFunction)gles_glStencilFunc, METH_VARARGS, NULL}, + {"glStencilMask", (PyCFunction)gles_glStencilMask, METH_VARARGS, NULL}, + {"glStencilOp", (PyCFunction)gles_glStencilOp, METH_VARARGS, NULL}, + + {"glTexCoordPointer", (PyCFunction)gles_glTexCoordPointer, METH_VARARGS, NULL}, + {"glTexCoordPointerb", (PyCFunction)gles_glTexCoordPointerb, METH_VARARGS, NULL}, + {"glTexCoordPointers", (PyCFunction)gles_glTexCoordPointers, METH_VARARGS, NULL}, + {"glTexCoordPointerf", (PyCFunction)gles_glTexCoordPointerf, METH_VARARGS, NULL}, + {"glTexCoordPointerx", (PyCFunction)gles_glTexCoordPointerx, METH_VARARGS, NULL}, + + {"glTexEnvf", (PyCFunction)gles_glTexEnvf, METH_VARARGS, NULL}, + {"glTexEnvfv", (PyCFunction)gles_glTexEnvfv, METH_VARARGS, NULL}, + {"glTexEnvx", (PyCFunction)gles_glTexEnvx, METH_VARARGS, NULL}, + {"glTexEnvxv", (PyCFunction)gles_glTexEnvxv, METH_VARARGS, NULL}, + {"glTexImage2D", (PyCFunction)gles_glTexImage2D, METH_VARARGS, NULL}, + // A reduced argument version of glTexImage2D, accepting only Image objects. + //{"glTexImage2DIO", (PyCFunction)gles_glTexImage2DIO, METH_VARARGS, NULL}, + {"glTexParameterf", (PyCFunction)gles_glTexParameterf, METH_VARARGS, NULL}, + {"glTexParameterx", (PyCFunction)gles_glTexParameterx, METH_VARARGS, NULL}, + {"glTexSubImage2D", (PyCFunction)gles_glTexSubImage2D, METH_VARARGS, NULL}, + //{"glTexSubImage2DIO", (PyCFunction)gles_glTexSubImage2DIO, METH_VARARGS, NULL}, + {"glTranslatex", (PyCFunction)gles_glTranslatex, METH_VARARGS, NULL}, + {"glTranslatef", (PyCFunction)gles_glTranslatef, METH_VARARGS, NULL}, + + {"glVertexPointer", (PyCFunction)gles_glVertexPointer, METH_VARARGS, NULL}, + {"glVertexPointerb", (PyCFunction)gles_glVertexPointerb, METH_VARARGS, NULL}, + {"glVertexPointers", (PyCFunction)gles_glVertexPointers, METH_VARARGS, NULL}, + {"glVertexPointerf", (PyCFunction)gles_glVertexPointerf, METH_VARARGS, NULL}, + {"glVertexPointerx", (PyCFunction)gles_glVertexPointerx, METH_VARARGS, NULL}, + {"glViewport", (PyCFunction)gles_glViewport, METH_VARARGS, NULL}, + + {NULL, NULL} /* sentinel */ + }; + +/* DL_EXPORT(void) zfinalizegles(void) + { + gles_uninit_arrays(); +#ifdef DEBUG_GLES + DEBUGMSG("GLES finalized\n"); +#endif + } + */ + DL_EXPORT(void) initgles(void) + { + PyObject *m, *d; // Pointer for module object and it's dictionary + + PyObject *GLError; + + // Initialize internal array memory + gles_init_arrays(); + // The previous function may fail at runtime + if(PyErr_Occurred()) { + return; + } + + // Initialize the module + m = Py_InitModule("gles", (PyMethodDef*)gles_methods); + // Add the GLError + GLError = PyErr_NewException( "_gles.GLError", NULL, NULL); + PyModule_AddObject(m, "GLError", GLError); + + // Create a new type for gles.array + array_type = PyObject_New(PyTypeObject, &PyType_Type); + *array_type = c_array_type; + array_type->ob_type = &PyType_Type; + //SPyAddGlobalString("GLESArrayType", (PyObject*)array_type); + + d = PyModule_GetDict(m); + + // defines for OpenGL ES 1.0 + PyDict_SetItemString(d, "GL_OES_VERSION_1_0", PyInt_FromLong(GL_OES_VERSION_1_0)); + PyDict_SetItemString(d, "GL_OES_read_format", PyInt_FromLong(GL_OES_read_format)); + PyDict_SetItemString(d, "GL_OES_compressed_paletted_texture", PyInt_FromLong(GL_OES_compressed_paletted_texture)); + + PyDict_SetItemString(d, "GL_DEPTH_BUFFER_BIT", PyInt_FromLong(GL_DEPTH_BUFFER_BIT)); + PyDict_SetItemString(d, "GL_STENCIL_BUFFER_BIT", PyInt_FromLong(GL_STENCIL_BUFFER_BIT)); + PyDict_SetItemString(d, "GL_COLOR_BUFFER_BIT", PyInt_FromLong(GL_COLOR_BUFFER_BIT)); + + PyDict_SetItemString(d, "GL_FALSE", PyInt_FromLong(GL_FALSE)); + PyDict_SetItemString(d, "GL_TRUE", PyInt_FromLong(GL_TRUE)); + + PyDict_SetItemString(d, "GL_POINTS", PyInt_FromLong(GL_POINTS)); + PyDict_SetItemString(d, "GL_LINES", PyInt_FromLong(GL_LINES)); + PyDict_SetItemString(d, "GL_LINE_LOOP", PyInt_FromLong(GL_LINE_LOOP)); + PyDict_SetItemString(d, "GL_LINE_STRIP", PyInt_FromLong(GL_LINE_STRIP)); + PyDict_SetItemString(d, "GL_TRIANGLES", PyInt_FromLong(GL_TRIANGLES)); + PyDict_SetItemString(d, "GL_TRIANGLE_STRIP", PyInt_FromLong(GL_TRIANGLE_STRIP)); + PyDict_SetItemString(d, "GL_TRIANGLE_FAN", PyInt_FromLong(GL_TRIANGLE_FAN)); + + PyDict_SetItemString(d, "GL_NEVER", PyInt_FromLong(GL_NEVER)); + PyDict_SetItemString(d, "GL_LESS", PyInt_FromLong(GL_LESS)); + PyDict_SetItemString(d, "GL_EQUAL", PyInt_FromLong(GL_EQUAL)); + PyDict_SetItemString(d, "GL_LEQUAL", PyInt_FromLong(GL_LEQUAL)); + PyDict_SetItemString(d, "GL_GREATER", PyInt_FromLong(GL_GREATER)); + PyDict_SetItemString(d, "GL_NOTEQUAL", PyInt_FromLong(GL_NOTEQUAL)); + PyDict_SetItemString(d, "GL_GEQUAL", PyInt_FromLong(GL_GEQUAL)); + PyDict_SetItemString(d, "GL_ALWAYS", PyInt_FromLong(GL_ALWAYS)); + + PyDict_SetItemString(d, "GL_ZERO", PyInt_FromLong(GL_ZERO)); + PyDict_SetItemString(d, "GL_ONE", PyInt_FromLong(GL_ONE)); + PyDict_SetItemString(d, "GL_SRC_COLOR", PyInt_FromLong(GL_SRC_COLOR)); + PyDict_SetItemString(d, "GL_ONE_MINUS_SRC_COLOR", PyInt_FromLong(GL_ONE_MINUS_SRC_COLOR)); + PyDict_SetItemString(d, "GL_SRC_ALPHA", PyInt_FromLong(GL_SRC_ALPHA)); + PyDict_SetItemString(d, "GL_ONE_MINUS_SRC_ALPHA", PyInt_FromLong(GL_ONE_MINUS_SRC_ALPHA)); + PyDict_SetItemString(d, "GL_DST_ALPHA", PyInt_FromLong(GL_DST_ALPHA)); + PyDict_SetItemString(d, "GL_ONE_MINUS_DST_ALPHA", PyInt_FromLong(GL_ONE_MINUS_DST_ALPHA)); + + PyDict_SetItemString(d, "GL_DST_COLOR", PyInt_FromLong(GL_DST_COLOR)); + PyDict_SetItemString(d, "GL_ONE_MINUS_DST_COLOR", PyInt_FromLong(GL_ONE_MINUS_DST_COLOR)); + PyDict_SetItemString(d, "GL_SRC_ALPHA_SATURATE", PyInt_FromLong(GL_SRC_ALPHA_SATURATE)); + + PyDict_SetItemString(d, "GL_FRONT", PyInt_FromLong(GL_FRONT)); + PyDict_SetItemString(d, "GL_BACK", PyInt_FromLong(GL_BACK)); + PyDict_SetItemString(d, "GL_FRONT_AND_BACK", PyInt_FromLong(GL_FRONT_AND_BACK)); + + PyDict_SetItemString(d, "GL_FOG", PyInt_FromLong(GL_FOG)); + PyDict_SetItemString(d, "GL_LIGHTING", PyInt_FromLong(GL_LIGHTING)); + PyDict_SetItemString(d, "GL_TEXTURE_2D", PyInt_FromLong(GL_TEXTURE_2D)); + PyDict_SetItemString(d, "GL_CULL_FACE", PyInt_FromLong(GL_CULL_FACE)); + PyDict_SetItemString(d, "GL_ALPHA_TEST", PyInt_FromLong(GL_ALPHA_TEST)); + PyDict_SetItemString(d, "GL_BLEND", PyInt_FromLong(GL_BLEND)); + PyDict_SetItemString(d, "GL_COLOR_LOGIC_OP", PyInt_FromLong(GL_COLOR_LOGIC_OP)); + PyDict_SetItemString(d, "GL_DITHER", PyInt_FromLong(GL_DITHER)); + PyDict_SetItemString(d, "GL_STENCIL_TEST", PyInt_FromLong(GL_STENCIL_TEST)); + PyDict_SetItemString(d, "GL_DEPTH_TEST", PyInt_FromLong(GL_DEPTH_TEST)); + PyDict_SetItemString(d, "GL_POINT_SMOOTH", PyInt_FromLong(GL_POINT_SMOOTH)); + PyDict_SetItemString(d, "GL_LINE_SMOOTH", PyInt_FromLong(GL_LINE_SMOOTH)); + PyDict_SetItemString(d, "GL_SCISSOR_TEST", PyInt_FromLong(GL_SCISSOR_TEST)); + PyDict_SetItemString(d, "GL_COLOR_MATERIAL", PyInt_FromLong(GL_COLOR_MATERIAL)); + PyDict_SetItemString(d, "GL_NORMALIZE", PyInt_FromLong(GL_NORMALIZE)); + PyDict_SetItemString(d, "GL_RESCALE_NORMAL", PyInt_FromLong(GL_RESCALE_NORMAL)); + PyDict_SetItemString(d, "GL_POLYGON_OFFSET_FILL", PyInt_FromLong(GL_POLYGON_OFFSET_FILL)); + PyDict_SetItemString(d, "GL_VERTEX_ARRAY", PyInt_FromLong(GL_VERTEX_ARRAY)); + PyDict_SetItemString(d, "GL_NORMAL_ARRAY", PyInt_FromLong(GL_NORMAL_ARRAY)); + PyDict_SetItemString(d, "GL_COLOR_ARRAY", PyInt_FromLong(GL_COLOR_ARRAY)); + PyDict_SetItemString(d, "GL_TEXTURE_COORD_ARRAY", PyInt_FromLong(GL_TEXTURE_COORD_ARRAY)); + PyDict_SetItemString(d, "GL_MULTISAMPLE", PyInt_FromLong(GL_MULTISAMPLE)); + PyDict_SetItemString(d, "GL_SAMPLE_ALPHA_TO_COVERAGE", PyInt_FromLong(GL_SAMPLE_ALPHA_TO_COVERAGE)); + PyDict_SetItemString(d, "GL_SAMPLE_ALPHA_TO_ONE", PyInt_FromLong(GL_SAMPLE_ALPHA_TO_ONE)); + PyDict_SetItemString(d, "GL_SAMPLE_COVERAGE", PyInt_FromLong(GL_SAMPLE_COVERAGE)); + + PyDict_SetItemString(d, "GL_NO_ERROR", PyInt_FromLong(GL_NO_ERROR)); + PyDict_SetItemString(d, "GL_INVALID_ENUM", PyInt_FromLong(GL_INVALID_ENUM)); + PyDict_SetItemString(d, "GL_INVALID_VALUE", PyInt_FromLong(GL_INVALID_VALUE)); + PyDict_SetItemString(d, "GL_INVALID_OPERATION", PyInt_FromLong(GL_INVALID_OPERATION)); + PyDict_SetItemString(d, "GL_STACK_OVERFLOW", PyInt_FromLong(GL_STACK_OVERFLOW)); + PyDict_SetItemString(d, "GL_STACK_UNDERFLOW", PyInt_FromLong(GL_STACK_UNDERFLOW)); + PyDict_SetItemString(d, "GL_OUT_OF_MEMORY", PyInt_FromLong(GL_OUT_OF_MEMORY)); + + PyDict_SetItemString(d, "GL_EXP", PyInt_FromLong(GL_EXP)); + PyDict_SetItemString(d, "GL_EXP2", PyInt_FromLong(GL_EXP2)); + + PyDict_SetItemString(d, "GL_FOG_DENSITY", PyInt_FromLong(GL_FOG_DENSITY)); + PyDict_SetItemString(d, "GL_FOG_START", PyInt_FromLong(GL_FOG_START)); + PyDict_SetItemString(d, "GL_FOG_END", PyInt_FromLong(GL_FOG_END)); + PyDict_SetItemString(d, "GL_FOG_MODE", PyInt_FromLong(GL_FOG_MODE)); + PyDict_SetItemString(d, "GL_FOG_COLOR", PyInt_FromLong(GL_FOG_COLOR)); + + PyDict_SetItemString(d, "GL_CW", PyInt_FromLong(GL_CW)); + PyDict_SetItemString(d, "GL_CCW", PyInt_FromLong(GL_CCW)); + + PyDict_SetItemString(d, "GL_SMOOTH_POINT_SIZE_RANGE", PyInt_FromLong(GL_SMOOTH_POINT_SIZE_RANGE)); + PyDict_SetItemString(d, "GL_SMOOTH_LINE_WIDTH_RANGE", PyInt_FromLong(GL_SMOOTH_LINE_WIDTH_RANGE)); + PyDict_SetItemString(d, "GL_ALIASED_POINT_SIZE_RANGE", PyInt_FromLong(GL_ALIASED_POINT_SIZE_RANGE)); + PyDict_SetItemString(d, "GL_ALIASED_LINE_WIDTH_RANGE", PyInt_FromLong(GL_ALIASED_LINE_WIDTH_RANGE)); + PyDict_SetItemString(d, "GL_IMPLEMENTATION_COLOR_READ_TYPE_OES", PyInt_FromLong(GL_IMPLEMENTATION_COLOR_READ_TYPE_OES)); + PyDict_SetItemString(d, "GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES", PyInt_FromLong(GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES)); + PyDict_SetItemString(d, "GL_MAX_LIGHTS", PyInt_FromLong(GL_MAX_LIGHTS)); + PyDict_SetItemString(d, "GL_MAX_TEXTURE_SIZE", PyInt_FromLong(GL_MAX_TEXTURE_SIZE)); + PyDict_SetItemString(d, "GL_MAX_MODELVIEW_STACK_DEPTH", PyInt_FromLong(GL_MAX_MODELVIEW_STACK_DEPTH)); + PyDict_SetItemString(d, "GL_MAX_PROJECTION_STACK_DEPTH", PyInt_FromLong(GL_MAX_PROJECTION_STACK_DEPTH)); + PyDict_SetItemString(d, "GL_MAX_TEXTURE_STACK_DEPTH", PyInt_FromLong(GL_MAX_TEXTURE_STACK_DEPTH)); + PyDict_SetItemString(d, "GL_MAX_VIEWPORT_DIMS", PyInt_FromLong(GL_MAX_VIEWPORT_DIMS)); + PyDict_SetItemString(d, "GL_MAX_ELEMENTS_VERTICES", PyInt_FromLong(GL_MAX_ELEMENTS_VERTICES)); + PyDict_SetItemString(d, "GL_MAX_ELEMENTS_INDICES", PyInt_FromLong(GL_MAX_ELEMENTS_INDICES)); + PyDict_SetItemString(d, "GL_MAX_TEXTURE_UNITS", PyInt_FromLong(GL_MAX_TEXTURE_UNITS)); + PyDict_SetItemString(d, "GL_NUM_COMPRESSED_TEXTURE_FORMATS", PyInt_FromLong(GL_NUM_COMPRESSED_TEXTURE_FORMATS)); + PyDict_SetItemString(d, "GL_COMPRESSED_TEXTURE_FORMATS", PyInt_FromLong(GL_COMPRESSED_TEXTURE_FORMATS)); + PyDict_SetItemString(d, "GL_SUBPIXEL_BITS", PyInt_FromLong(GL_SUBPIXEL_BITS)); + PyDict_SetItemString(d, "GL_RED_BITS", PyInt_FromLong(GL_RED_BITS)); + PyDict_SetItemString(d, "GL_GREEN_BITS", PyInt_FromLong(GL_GREEN_BITS)); + PyDict_SetItemString(d, "GL_BLUE_BITS", PyInt_FromLong(GL_BLUE_BITS)); + PyDict_SetItemString(d, "GL_ALPHA_BITS", PyInt_FromLong(GL_ALPHA_BITS)); + PyDict_SetItemString(d, "GL_DEPTH_BITS", PyInt_FromLong(GL_DEPTH_BITS)); + PyDict_SetItemString(d, "GL_STENCIL_BITS", PyInt_FromLong(GL_STENCIL_BITS)); + + PyDict_SetItemString(d, "GL_DONT_CARE", PyInt_FromLong(GL_DONT_CARE)); + PyDict_SetItemString(d, "GL_FASTEST", PyInt_FromLong(GL_FASTEST)); + PyDict_SetItemString(d, "GL_NICEST", PyInt_FromLong(GL_NICEST)); + + PyDict_SetItemString(d, "GL_PERSPECTIVE_CORRECTION_HINT", PyInt_FromLong(GL_PERSPECTIVE_CORRECTION_HINT)); + PyDict_SetItemString(d, "GL_POINT_SMOOTH_HINT", PyInt_FromLong(GL_POINT_SMOOTH_HINT)); + PyDict_SetItemString(d, "GL_LINE_SMOOTH_HINT", PyInt_FromLong(GL_LINE_SMOOTH_HINT)); + PyDict_SetItemString(d, "GL_POLYGON_SMOOTH_HINT", PyInt_FromLong(GL_POLYGON_SMOOTH_HINT)); + PyDict_SetItemString(d, "GL_FOG_HINT", PyInt_FromLong(GL_FOG_HINT)); + + PyDict_SetItemString(d, "GL_LIGHT_MODEL_AMBIENT", PyInt_FromLong(GL_LIGHT_MODEL_AMBIENT)); + PyDict_SetItemString(d, "GL_LIGHT_MODEL_TWO_SIDE", PyInt_FromLong(GL_LIGHT_MODEL_TWO_SIDE)); + + PyDict_SetItemString(d, "GL_AMBIENT", PyInt_FromLong(GL_AMBIENT)); + PyDict_SetItemString(d, "GL_DIFFUSE", PyInt_FromLong(GL_DIFFUSE)); + PyDict_SetItemString(d, "GL_SPECULAR", PyInt_FromLong(GL_SPECULAR)); + PyDict_SetItemString(d, "GL_POSITION", PyInt_FromLong(GL_POSITION)); + PyDict_SetItemString(d, "GL_SPOT_DIRECTION", PyInt_FromLong(GL_SPOT_DIRECTION)); + PyDict_SetItemString(d, "GL_SPOT_EXPONENT", PyInt_FromLong(GL_SPOT_EXPONENT)); + PyDict_SetItemString(d, "GL_SPOT_CUTOFF", PyInt_FromLong(GL_SPOT_CUTOFF)); + PyDict_SetItemString(d, "GL_CONSTANT_ATTENUATION", PyInt_FromLong(GL_CONSTANT_ATTENUATION)); + PyDict_SetItemString(d, "GL_LINEAR_ATTENUATION", PyInt_FromLong(GL_LINEAR_ATTENUATION)); + PyDict_SetItemString(d, "GL_QUADRATIC_ATTENUATION", PyInt_FromLong(GL_QUADRATIC_ATTENUATION)); + + PyDict_SetItemString(d, "GL_BYTE", PyInt_FromLong(GL_BYTE)); + PyDict_SetItemString(d, "GL_UNSIGNED_BYTE", PyInt_FromLong(GL_UNSIGNED_BYTE)); + PyDict_SetItemString(d, "GL_SHORT", PyInt_FromLong(GL_SHORT)); + PyDict_SetItemString(d, "GL_UNSIGNED_SHORT", PyInt_FromLong(GL_UNSIGNED_SHORT)); + PyDict_SetItemString(d, "GL_FLOAT", PyInt_FromLong(GL_FLOAT)); + PyDict_SetItemString(d, "GL_FIXED", PyInt_FromLong(GL_FIXED)); + + PyDict_SetItemString(d, "GL_CLEAR", PyInt_FromLong(GL_CLEAR)); + PyDict_SetItemString(d, "GL_AND", PyInt_FromLong(GL_AND)); + PyDict_SetItemString(d, "GL_AND_REVERSE", PyInt_FromLong(GL_AND_REVERSE)); + PyDict_SetItemString(d, "GL_COPY", PyInt_FromLong(GL_COPY)); + PyDict_SetItemString(d, "GL_AND_INVERTED", PyInt_FromLong(GL_AND_INVERTED)); + PyDict_SetItemString(d, "GL_NOOP", PyInt_FromLong(GL_NOOP)); + PyDict_SetItemString(d, "GL_XOR", PyInt_FromLong(GL_XOR)); + PyDict_SetItemString(d, "GL_OR", PyInt_FromLong(GL_OR)); + PyDict_SetItemString(d, "GL_NOR", PyInt_FromLong(GL_NOR)); + PyDict_SetItemString(d, "GL_EQUIV", PyInt_FromLong(GL_EQUIV)); + PyDict_SetItemString(d, "GL_INVERT", PyInt_FromLong(GL_INVERT)); + PyDict_SetItemString(d, "GL_OR_REVERSE", PyInt_FromLong(GL_OR_REVERSE)); + PyDict_SetItemString(d, "GL_COPY_INVERTED", PyInt_FromLong(GL_COPY_INVERTED)); + PyDict_SetItemString(d, "GL_OR_INVERTED", PyInt_FromLong(GL_OR_INVERTED)); + PyDict_SetItemString(d, "GL_NAND", PyInt_FromLong(GL_NAND)); + PyDict_SetItemString(d, "GL_SET", PyInt_FromLong(GL_SET)); + + PyDict_SetItemString(d, "GL_EMISSION", PyInt_FromLong(GL_EMISSION)); + PyDict_SetItemString(d, "GL_SHININESS", PyInt_FromLong(GL_SHININESS)); + PyDict_SetItemString(d, "GL_AMBIENT_AND_DIFFUSE", PyInt_FromLong(GL_AMBIENT_AND_DIFFUSE)); + + PyDict_SetItemString(d, "GL_MODELVIEW", PyInt_FromLong(GL_MODELVIEW)); + PyDict_SetItemString(d, "GL_PROJECTION", PyInt_FromLong(GL_PROJECTION)); + PyDict_SetItemString(d, "GL_TEXTURE", PyInt_FromLong(GL_TEXTURE)); + + PyDict_SetItemString(d, "GL_ALPHA", PyInt_FromLong(GL_ALPHA)); + PyDict_SetItemString(d, "GL_RGB", PyInt_FromLong(GL_RGB)); + PyDict_SetItemString(d, "GL_RGBA", PyInt_FromLong(GL_RGBA)); + PyDict_SetItemString(d, "GL_LUMINANCE", PyInt_FromLong(GL_LUMINANCE)); + PyDict_SetItemString(d, "GL_LUMINANCE_ALPHA", PyInt_FromLong(GL_LUMINANCE_ALPHA)); + + PyDict_SetItemString(d, "GL_UNPACK_ALIGNMENT", PyInt_FromLong(GL_UNPACK_ALIGNMENT)); + PyDict_SetItemString(d, "GL_PACK_ALIGNMENT", PyInt_FromLong(GL_PACK_ALIGNMENT)); + + PyDict_SetItemString(d, "GL_UNSIGNED_SHORT_4_4_4_4", PyInt_FromLong(GL_UNSIGNED_SHORT_4_4_4_4)); + PyDict_SetItemString(d, "GL_UNSIGNED_SHORT_5_5_5_1", PyInt_FromLong(GL_UNSIGNED_SHORT_5_5_5_1)); + PyDict_SetItemString(d, "GL_UNSIGNED_SHORT_5_6_5", PyInt_FromLong(GL_UNSIGNED_SHORT_5_6_5)); + + PyDict_SetItemString(d, "GL_FLAT", PyInt_FromLong(GL_FLAT)); + PyDict_SetItemString(d, "GL_SMOOTH", PyInt_FromLong(GL_SMOOTH)); + + PyDict_SetItemString(d, "GL_KEEP", PyInt_FromLong(GL_KEEP)); + PyDict_SetItemString(d, "GL_REPLACE", PyInt_FromLong(GL_REPLACE)); + PyDict_SetItemString(d, "GL_INCR", PyInt_FromLong(GL_INCR)); + PyDict_SetItemString(d, "GL_DECR", PyInt_FromLong(GL_DECR)); + + PyDict_SetItemString(d, "GL_VENDOR", PyInt_FromLong(GL_VENDOR)); + PyDict_SetItemString(d, "GL_RENDERER", PyInt_FromLong(GL_RENDERER)); + PyDict_SetItemString(d, "GL_VERSION", PyInt_FromLong(GL_VERSION)); + PyDict_SetItemString(d, "GL_EXTENSIONS", PyInt_FromLong(GL_EXTENSIONS)); + + PyDict_SetItemString(d, "GL_MODULATE", PyInt_FromLong(GL_MODULATE)); + PyDict_SetItemString(d, "GL_DECAL", PyInt_FromLong(GL_DECAL)); + PyDict_SetItemString(d, "GL_ADD", PyInt_FromLong(GL_ADD)); + + PyDict_SetItemString(d, "GL_TEXTURE_ENV_MODE", PyInt_FromLong(GL_TEXTURE_ENV_MODE)); + PyDict_SetItemString(d, "GL_TEXTURE_ENV_COLOR", PyInt_FromLong(GL_TEXTURE_ENV_COLOR)); + + PyDict_SetItemString(d, "GL_TEXTURE_ENV", PyInt_FromLong(GL_TEXTURE_ENV)); + + PyDict_SetItemString(d, "GL_NEAREST", PyInt_FromLong(GL_NEAREST)); + PyDict_SetItemString(d, "GL_LINEAR", PyInt_FromLong(GL_LINEAR)); + + PyDict_SetItemString(d, "GL_NEAREST_MIPMAP_NEAREST", PyInt_FromLong(GL_NEAREST_MIPMAP_NEAREST)); + PyDict_SetItemString(d, "GL_LINEAR_MIPMAP_NEAREST", PyInt_FromLong(GL_LINEAR_MIPMAP_NEAREST)); + PyDict_SetItemString(d, "GL_NEAREST_MIPMAP_LINEAR", PyInt_FromLong(GL_NEAREST_MIPMAP_LINEAR)); + PyDict_SetItemString(d, "GL_LINEAR_MIPMAP_LINEAR", PyInt_FromLong(GL_LINEAR_MIPMAP_LINEAR)); + + PyDict_SetItemString(d, "GL_TEXTURE_MAG_FILTER", PyInt_FromLong(GL_TEXTURE_MAG_FILTER)); + PyDict_SetItemString(d, "GL_TEXTURE_MIN_FILTER", PyInt_FromLong(GL_TEXTURE_MIN_FILTER)); + PyDict_SetItemString(d, "GL_TEXTURE_WRAP_S", PyInt_FromLong(GL_TEXTURE_WRAP_S)); + PyDict_SetItemString(d, "GL_TEXTURE_WRAP_T", PyInt_FromLong(GL_TEXTURE_WRAP_T)); + + PyDict_SetItemString(d, "GL_TEXTURE0", PyInt_FromLong(GL_TEXTURE0)); + PyDict_SetItemString(d, "GL_TEXTURE1", PyInt_FromLong(GL_TEXTURE1)); + PyDict_SetItemString(d, "GL_TEXTURE2", PyInt_FromLong(GL_TEXTURE2)); + PyDict_SetItemString(d, "GL_TEXTURE3", PyInt_FromLong(GL_TEXTURE3)); + PyDict_SetItemString(d, "GL_TEXTURE4", PyInt_FromLong(GL_TEXTURE4)); + PyDict_SetItemString(d, "GL_TEXTURE5", PyInt_FromLong(GL_TEXTURE5)); + PyDict_SetItemString(d, "GL_TEXTURE6", PyInt_FromLong(GL_TEXTURE6)); + PyDict_SetItemString(d, "GL_TEXTURE7", PyInt_FromLong(GL_TEXTURE7)); + PyDict_SetItemString(d, "GL_TEXTURE8", PyInt_FromLong(GL_TEXTURE8)); + PyDict_SetItemString(d, "GL_TEXTURE9", PyInt_FromLong(GL_TEXTURE9)); + PyDict_SetItemString(d, "GL_TEXTURE10", PyInt_FromLong(GL_TEXTURE10)); + PyDict_SetItemString(d, "GL_TEXTURE11", PyInt_FromLong(GL_TEXTURE11)); + PyDict_SetItemString(d, "GL_TEXTURE12", PyInt_FromLong(GL_TEXTURE12)); + PyDict_SetItemString(d, "GL_TEXTURE13", PyInt_FromLong(GL_TEXTURE13)); + PyDict_SetItemString(d, "GL_TEXTURE14", PyInt_FromLong(GL_TEXTURE14)); + PyDict_SetItemString(d, "GL_TEXTURE15", PyInt_FromLong(GL_TEXTURE15)); + PyDict_SetItemString(d, "GL_TEXTURE16", PyInt_FromLong(GL_TEXTURE16)); + PyDict_SetItemString(d, "GL_TEXTURE17", PyInt_FromLong(GL_TEXTURE17)); + PyDict_SetItemString(d, "GL_TEXTURE18", PyInt_FromLong(GL_TEXTURE18)); + PyDict_SetItemString(d, "GL_TEXTURE19", PyInt_FromLong(GL_TEXTURE19)); + PyDict_SetItemString(d, "GL_TEXTURE20", PyInt_FromLong(GL_TEXTURE20)); + PyDict_SetItemString(d, "GL_TEXTURE21", PyInt_FromLong(GL_TEXTURE21)); + PyDict_SetItemString(d, "GL_TEXTURE22", PyInt_FromLong(GL_TEXTURE22)); + PyDict_SetItemString(d, "GL_TEXTURE23", PyInt_FromLong(GL_TEXTURE23)); + PyDict_SetItemString(d, "GL_TEXTURE24", PyInt_FromLong(GL_TEXTURE24)); + PyDict_SetItemString(d, "GL_TEXTURE25", PyInt_FromLong(GL_TEXTURE25)); + PyDict_SetItemString(d, "GL_TEXTURE26", PyInt_FromLong(GL_TEXTURE26)); + PyDict_SetItemString(d, "GL_TEXTURE27", PyInt_FromLong(GL_TEXTURE27)); + PyDict_SetItemString(d, "GL_TEXTURE28", PyInt_FromLong(GL_TEXTURE28)); + PyDict_SetItemString(d, "GL_TEXTURE29", PyInt_FromLong(GL_TEXTURE29)); + PyDict_SetItemString(d, "GL_TEXTURE30", PyInt_FromLong(GL_TEXTURE30)); + PyDict_SetItemString(d, "GL_TEXTURE31", PyInt_FromLong(GL_TEXTURE31)); + + PyDict_SetItemString(d, "GL_REPEAT", PyInt_FromLong(GL_REPEAT)); + PyDict_SetItemString(d, "GL_CLAMP_TO_EDGE", PyInt_FromLong(GL_CLAMP_TO_EDGE)); + + PyDict_SetItemString(d, "GL_PALETTE4_RGB8_OES", PyInt_FromLong(GL_PALETTE4_RGB8_OES)); + PyDict_SetItemString(d, "GL_PALETTE4_RGBA8_OES", PyInt_FromLong(GL_PALETTE4_RGBA8_OES)); + PyDict_SetItemString(d, "GL_PALETTE4_R5_G6_B5_OES", PyInt_FromLong(GL_PALETTE4_R5_G6_B5_OES)); + PyDict_SetItemString(d, "GL_PALETTE4_RGBA4_OES", PyInt_FromLong(GL_PALETTE4_RGBA4_OES)); + PyDict_SetItemString(d, "GL_PALETTE4_RGB5_A1_OES", PyInt_FromLong(GL_PALETTE4_RGB5_A1_OES)); + PyDict_SetItemString(d, "GL_PALETTE8_RGB8_OES", PyInt_FromLong(GL_PALETTE8_RGB8_OES)); + PyDict_SetItemString(d, "GL_PALETTE8_RGBA8_OES", PyInt_FromLong(GL_PALETTE8_RGBA8_OES)); + PyDict_SetItemString(d, "GL_PALETTE8_R5_G6_B5_OES", PyInt_FromLong(GL_PALETTE8_R5_G6_B5_OES)); + PyDict_SetItemString(d, "GL_PALETTE8_RGBA4_OES", PyInt_FromLong(GL_PALETTE8_RGBA4_OES)); + PyDict_SetItemString(d, "GL_PALETTE8_RGB5_A1_OES", PyInt_FromLong(GL_PALETTE8_RGB5_A1_OES)); + + PyDict_SetItemString(d, "GL_LIGHT0", PyInt_FromLong(GL_LIGHT0)); + PyDict_SetItemString(d, "GL_LIGHT1", PyInt_FromLong(GL_LIGHT1)); + PyDict_SetItemString(d, "GL_LIGHT2", PyInt_FromLong(GL_LIGHT2)); + PyDict_SetItemString(d, "GL_LIGHT3", PyInt_FromLong(GL_LIGHT3)); + PyDict_SetItemString(d, "GL_LIGHT4", PyInt_FromLong(GL_LIGHT4)); + PyDict_SetItemString(d, "GL_LIGHT5", PyInt_FromLong(GL_LIGHT5)); + PyDict_SetItemString(d, "GL_LIGHT6", PyInt_FromLong(GL_LIGHT6)); + PyDict_SetItemString(d, "GL_LIGHT7", PyInt_FromLong(GL_LIGHT7)); + +#ifdef GL_OES_VERSION_1_1 + // Defines for OpenGL ES 1.1 + PyDict_SetItemString(d, "GL_OES_VERSION_1_1", PyInt_FromLong(GL_OES_VERSION_1_1)); + + //PyDict_SetItemString(d, "GL_OES_byte_coordinates", PyInt_FromLong(GL_OES_byte_coordinates)); + //PyDict_SetItemString(d, "GL_OES_draw_texture", PyInt_FromLong(GL_OES_draw_texture)); + //PyDict_SetItemString(d, "GL_OES_fixed_point", PyInt_FromLong(GL_OES_fixed_point)); + PyDict_SetItemString(d, "GL_OES_matrix_get", PyInt_FromLong(GL_OES_matrix_get)); + PyDict_SetItemString(d, "GL_OES_matrix_palette", PyInt_FromLong(GL_OES_matrix_palette)); + PyDict_SetItemString(d, "GL_OES_point_size_array", PyInt_FromLong(GL_OES_point_size_array)); + PyDict_SetItemString(d, "GL_OES_point_sprite", PyInt_FromLong(GL_OES_point_sprite)); + //PyDict_SetItemString(d, "GL_OES_single_precision", PyInt_FromLong(GL_OES_single_precision)); + + PyDict_SetItemString(d, "GL_CLIP_PLANE0", PyInt_FromLong(GL_CLIP_PLANE0)); + PyDict_SetItemString(d, "GL_CLIP_PLANE1", PyInt_FromLong(GL_CLIP_PLANE1)); + PyDict_SetItemString(d, "GL_CLIP_PLANE2", PyInt_FromLong(GL_CLIP_PLANE2)); + PyDict_SetItemString(d, "GL_CLIP_PLANE3", PyInt_FromLong(GL_CLIP_PLANE3)); + PyDict_SetItemString(d, "GL_CLIP_PLANE4", PyInt_FromLong(GL_CLIP_PLANE4)); + PyDict_SetItemString(d, "GL_CLIP_PLANE5", PyInt_FromLong(GL_CLIP_PLANE5)); + + PyDict_SetItemString(d, "GL_CURRENT_COLOR", PyInt_FromLong(GL_CURRENT_COLOR)); + PyDict_SetItemString(d, "GL_CURRENT_NORMAL", PyInt_FromLong(GL_CURRENT_NORMAL)); + PyDict_SetItemString(d, "GL_CURRENT_TEXTURE_COORDS", PyInt_FromLong(GL_CURRENT_TEXTURE_COORDS)); + PyDict_SetItemString(d, "GL_POINT_SIZE", PyInt_FromLong(GL_POINT_SIZE)); + PyDict_SetItemString(d, "GL_POINT_SIZE_MIN", PyInt_FromLong(GL_POINT_SIZE_MIN)); + PyDict_SetItemString(d, "GL_POINT_SIZE_MAX", PyInt_FromLong(GL_POINT_SIZE_MAX)); + PyDict_SetItemString(d, "GL_POINT_FADE_THRESHOLD_SIZE", PyInt_FromLong(GL_POINT_FADE_THRESHOLD_SIZE)); + PyDict_SetItemString(d, "GL_POINT_DISTANCE_ATTENUATION", PyInt_FromLong(GL_POINT_DISTANCE_ATTENUATION)); + + PyDict_SetItemString(d, "GL_LINE_WIDTH", PyInt_FromLong(GL_LINE_WIDTH)); + + PyDict_SetItemString(d, "GL_CULL_FACE_MODE", PyInt_FromLong(GL_CULL_FACE_MODE)); + PyDict_SetItemString(d, "GL_FRONT_FACE", PyInt_FromLong(GL_FRONT_FACE)); + PyDict_SetItemString(d, "GL_SHADE_MODEL", PyInt_FromLong(GL_SHADE_MODEL)); + PyDict_SetItemString(d, "GL_DEPTH_RANGE", PyInt_FromLong(GL_DEPTH_RANGE)); + PyDict_SetItemString(d, "GL_DEPTH_WRITEMASK", PyInt_FromLong(GL_DEPTH_WRITEMASK)); + PyDict_SetItemString(d, "GL_DEPTH_CLEAR_VALUE", PyInt_FromLong(GL_DEPTH_CLEAR_VALUE)); + PyDict_SetItemString(d, "GL_DEPTH_FUNC", PyInt_FromLong(GL_DEPTH_FUNC)); + PyDict_SetItemString(d, "GL_STENCIL_CLEAR_VALUE", PyInt_FromLong(GL_STENCIL_CLEAR_VALUE)); + PyDict_SetItemString(d, "GL_STENCIL_FUNC", PyInt_FromLong(GL_STENCIL_FUNC)); + PyDict_SetItemString(d, "GL_STENCIL_VALUE_MASK", PyInt_FromLong(GL_STENCIL_VALUE_MASK)); + PyDict_SetItemString(d, "GL_STENCIL_FAIL", PyInt_FromLong(GL_STENCIL_FAIL)); + PyDict_SetItemString(d, "GL_STENCIL_PASS_DEPTH_FAIL", PyInt_FromLong(GL_STENCIL_PASS_DEPTH_FAIL)); + PyDict_SetItemString(d, "GL_STENCIL_PASS_DEPTH_PASS", PyInt_FromLong(GL_STENCIL_PASS_DEPTH_PASS)); + PyDict_SetItemString(d, "GL_STENCIL_REF", PyInt_FromLong(GL_STENCIL_REF)); + PyDict_SetItemString(d, "GL_STENCIL_WRITEMASK", PyInt_FromLong(GL_STENCIL_WRITEMASK)); + PyDict_SetItemString(d, "GL_MATRIX_MODE", PyInt_FromLong(GL_MATRIX_MODE)); + PyDict_SetItemString(d, "GL_VIEWPORT", PyInt_FromLong(GL_VIEWPORT)); + PyDict_SetItemString(d, "GL_MODELVIEW_STACK_DEPTH", PyInt_FromLong(GL_MODELVIEW_STACK_DEPTH)); + PyDict_SetItemString(d, "GL_PROJECTION_STACK_DEPTH", PyInt_FromLong(GL_PROJECTION_STACK_DEPTH)); + PyDict_SetItemString(d, "GL_TEXTURE_STACK_DEPTH", PyInt_FromLong(GL_TEXTURE_STACK_DEPTH)); + PyDict_SetItemString(d, "GL_MODELVIEW_MATRIX", PyInt_FromLong(GL_MODELVIEW_MATRIX)); + PyDict_SetItemString(d, "GL_PROJECTION_MATRIX", PyInt_FromLong(GL_PROJECTION_MATRIX)); + PyDict_SetItemString(d, "GL_TEXTURE_MATRIX", PyInt_FromLong(GL_TEXTURE_MATRIX)); + PyDict_SetItemString(d, "GL_ALPHA_TEST_FUNC", PyInt_FromLong(GL_ALPHA_TEST_FUNC)); + PyDict_SetItemString(d, "GL_ALPHA_TEST_REF", PyInt_FromLong(GL_ALPHA_TEST_REF)); + PyDict_SetItemString(d, "GL_BLEND_DST", PyInt_FromLong(GL_BLEND_DST)); + PyDict_SetItemString(d, "GL_BLEND_SRC", PyInt_FromLong(GL_BLEND_SRC)); + PyDict_SetItemString(d, "GL_LOGIC_OP_MODE", PyInt_FromLong(GL_LOGIC_OP_MODE)); + PyDict_SetItemString(d, "GL_SCISSOR_BOX", PyInt_FromLong(GL_SCISSOR_BOX)); + PyDict_SetItemString(d, "GL_SCISSOR_TEST", PyInt_FromLong(GL_SCISSOR_TEST)); + PyDict_SetItemString(d, "GL_COLOR_CLEAR_VALUE", PyInt_FromLong(GL_COLOR_CLEAR_VALUE)); + PyDict_SetItemString(d, "GL_COLOR_WRITEMASK", PyInt_FromLong(GL_COLOR_WRITEMASK)); + PyDict_SetItemString(d, "GL_UNPACK_ALIGNMENT", PyInt_FromLong(GL_UNPACK_ALIGNMENT)); + PyDict_SetItemString(d, "GL_PACK_ALIGNMENT", PyInt_FromLong(GL_PACK_ALIGNMENT)); + + PyDict_SetItemString(d, "GL_MAX_CLIP_PLANES", PyInt_FromLong(GL_MAX_CLIP_PLANES)); + + PyDict_SetItemString(d, "GL_POLYGON_OFFSET_UNITS", PyInt_FromLong(GL_POLYGON_OFFSET_UNITS)); + PyDict_SetItemString(d, "GL_POLYGON_OFFSET_FILL", PyInt_FromLong(GL_POLYGON_OFFSET_FILL)); + PyDict_SetItemString(d, "GL_POLYGON_OFFSET_FACTOR", PyInt_FromLong(GL_POLYGON_OFFSET_FACTOR)); + PyDict_SetItemString(d, "GL_TEXTURE_BINDING_2D", PyInt_FromLong(GL_TEXTURE_BINDING_2D)); + PyDict_SetItemString(d, "GL_VERTEX_ARRAY_SIZE", PyInt_FromLong(GL_VERTEX_ARRAY_SIZE)); + PyDict_SetItemString(d, "GL_VERTEX_ARRAY_TYPE", PyInt_FromLong(GL_VERTEX_ARRAY_TYPE)); + PyDict_SetItemString(d, "GL_VERTEX_ARRAY_STRIDE", PyInt_FromLong(GL_VERTEX_ARRAY_STRIDE)); + PyDict_SetItemString(d, "GL_NORMAL_ARRAY_TYPE", PyInt_FromLong(GL_NORMAL_ARRAY_TYPE)); + PyDict_SetItemString(d, "GL_NORMAL_ARRAY_STRIDE", PyInt_FromLong(GL_NORMAL_ARRAY_STRIDE)); + PyDict_SetItemString(d, "GL_COLOR_ARRAY_SIZE", PyInt_FromLong(GL_COLOR_ARRAY_SIZE)); + PyDict_SetItemString(d, "GL_COLOR_ARRAY_TYPE", PyInt_FromLong(GL_COLOR_ARRAY_TYPE)); + PyDict_SetItemString(d, "GL_COLOR_ARRAY_STRIDE", PyInt_FromLong(GL_COLOR_ARRAY_STRIDE)); + PyDict_SetItemString(d, "GL_TEXTURE_COORD_ARRAY_SIZE", PyInt_FromLong(GL_TEXTURE_COORD_ARRAY_SIZE)); + PyDict_SetItemString(d, "GL_TEXTURE_COORD_ARRAY_TYPE", PyInt_FromLong(GL_TEXTURE_COORD_ARRAY_TYPE)); + PyDict_SetItemString(d, "GL_TEXTURE_COORD_ARRAY_STRIDE", PyInt_FromLong(GL_TEXTURE_COORD_ARRAY_STRIDE)); + PyDict_SetItemString(d, "GL_VERTEX_ARRAY_POINTER", PyInt_FromLong(GL_VERTEX_ARRAY_POINTER)); + PyDict_SetItemString(d, "GL_NORMAL_ARRAY_POINTER", PyInt_FromLong(GL_NORMAL_ARRAY_POINTER)); + PyDict_SetItemString(d, "GL_COLOR_ARRAY_POINTER", PyInt_FromLong(GL_COLOR_ARRAY_POINTER)); + PyDict_SetItemString(d, "GL_TEXTURE_COORD_ARRAY_POINTER", PyInt_FromLong(GL_TEXTURE_COORD_ARRAY_POINTER)); + PyDict_SetItemString(d, "GL_SAMPLE_BUFFERS", PyInt_FromLong(GL_SAMPLE_BUFFERS)); + PyDict_SetItemString(d, "GL_SAMPLES", PyInt_FromLong(GL_SAMPLES)); + PyDict_SetItemString(d, "GL_SAMPLE_COVERAGE_VALUE", PyInt_FromLong(GL_SAMPLE_COVERAGE_VALUE)); + PyDict_SetItemString(d, "GL_SAMPLE_COVERAGE_INVERT", PyInt_FromLong(GL_SAMPLE_COVERAGE_INVERT)); + PyDict_SetItemString(d, "GL_IMPLEMENTATION_COLOR_READ_TYPE_OES", PyInt_FromLong(GL_IMPLEMENTATION_COLOR_READ_TYPE_OES)); + PyDict_SetItemString(d, "GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES", PyInt_FromLong(GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES)); + PyDict_SetItemString(d, "GL_NUM_COMPRESSED_TEXTURE_FORMATS", PyInt_FromLong(GL_NUM_COMPRESSED_TEXTURE_FORMATS)); + PyDict_SetItemString(d, "GL_COMPRESSED_TEXTURE_FORMATS", PyInt_FromLong(GL_COMPRESSED_TEXTURE_FORMATS)); + + PyDict_SetItemString(d, "GL_GENERATE_MIPMAP_HINT", PyInt_FromLong(GL_GENERATE_MIPMAP_HINT)); + + PyDict_SetItemString(d, "GL_GENERATE_MIPMAP", PyInt_FromLong(GL_GENERATE_MIPMAP)); + + PyDict_SetItemString(d, "GL_ACTIVE_TEXTURE", PyInt_FromLong(GL_ACTIVE_TEXTURE)); + PyDict_SetItemString(d, "GL_CLIENT_ACTIVE_TEXTURE", PyInt_FromLong(GL_CLIENT_ACTIVE_TEXTURE)); + + PyDict_SetItemString(d, "GL_ARRAY_BUFFER", PyInt_FromLong(GL_ARRAY_BUFFER)); + PyDict_SetItemString(d, "GL_ELEMENT_ARRAY_BUFFER", PyInt_FromLong(GL_ELEMENT_ARRAY_BUFFER)); + PyDict_SetItemString(d, "GL_ARRAY_BUFFER_BINDING", PyInt_FromLong(GL_ARRAY_BUFFER_BINDING)); + PyDict_SetItemString(d, "GL_ELEMENT_ARRAY_BUFFER_BINDING", PyInt_FromLong(GL_ELEMENT_ARRAY_BUFFER_BINDING)); + PyDict_SetItemString(d, "GL_VERTEX_ARRAY_BUFFER_BINDING", PyInt_FromLong(GL_VERTEX_ARRAY_BUFFER_BINDING)); + PyDict_SetItemString(d, "GL_NORMAL_ARRAY_BUFFER_BINDING", PyInt_FromLong(GL_NORMAL_ARRAY_BUFFER_BINDING)); + PyDict_SetItemString(d, "GL_COLOR_ARRAY_BUFFER_BINDING", PyInt_FromLong(GL_COLOR_ARRAY_BUFFER_BINDING)); + PyDict_SetItemString(d, "GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING", PyInt_FromLong(GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING)); + PyDict_SetItemString(d, "GL_STATIC_DRAW", PyInt_FromLong(GL_STATIC_DRAW)); + PyDict_SetItemString(d, "GL_DYNAMIC_DRAW", PyInt_FromLong(GL_DYNAMIC_DRAW)); + PyDict_SetItemString(d, "GL_WRITE_ONLY", PyInt_FromLong(GL_WRITE_ONLY)); + PyDict_SetItemString(d, "GL_BUFFER_SIZE", PyInt_FromLong(GL_BUFFER_SIZE)); + PyDict_SetItemString(d, "GL_BUFFER_USAGE", PyInt_FromLong(GL_BUFFER_USAGE)); + PyDict_SetItemString(d, "GL_BUFFER_ACCESS", PyInt_FromLong(GL_BUFFER_ACCESS)); + PyDict_SetItemString(d, "GL_SUBTRACT", PyInt_FromLong(GL_SUBTRACT)); + PyDict_SetItemString(d, "GL_COMBINE", PyInt_FromLong(GL_COMBINE)); + PyDict_SetItemString(d, "GL_COMBINE_RGB", PyInt_FromLong(GL_COMBINE_RGB)); + PyDict_SetItemString(d, "GL_COMBINE_ALPHA", PyInt_FromLong(GL_COMBINE_ALPHA)); + PyDict_SetItemString(d, "GL_RGB_SCALE", PyInt_FromLong(GL_RGB_SCALE)); + PyDict_SetItemString(d, "GL_ADD_SIGNED", PyInt_FromLong(GL_ADD_SIGNED)); + PyDict_SetItemString(d, "GL_INTERPOLATE", PyInt_FromLong(GL_INTERPOLATE)); + PyDict_SetItemString(d, "GL_CONSTANT", PyInt_FromLong(GL_CONSTANT)); + PyDict_SetItemString(d, "GL_PRIMARY_COLOR", PyInt_FromLong(GL_PRIMARY_COLOR)); + PyDict_SetItemString(d, "GL_PREVIOUS", PyInt_FromLong(GL_PREVIOUS)); + PyDict_SetItemString(d, "GL_OPERAND0_RGB", PyInt_FromLong(GL_OPERAND0_RGB)); + PyDict_SetItemString(d, "GL_OPERAND1_RGB", PyInt_FromLong(GL_OPERAND1_RGB)); + PyDict_SetItemString(d, "GL_OPERAND2_RGB", PyInt_FromLong(GL_OPERAND2_RGB)); + PyDict_SetItemString(d, "GL_OPERAND0_ALPHA", PyInt_FromLong(GL_OPERAND0_ALPHA)); + PyDict_SetItemString(d, "GL_OPERAND1_ALPHA", PyInt_FromLong(GL_OPERAND1_ALPHA)); + PyDict_SetItemString(d, "GL_OPERAND2_ALPHA", PyInt_FromLong(GL_OPERAND2_ALPHA)); + PyDict_SetItemString(d, "GL_ALPHA_SCALE", PyInt_FromLong(GL_ALPHA_SCALE)); + PyDict_SetItemString(d, "GL_SRC0_RGB", PyInt_FromLong(GL_SRC0_RGB)); + PyDict_SetItemString(d, "GL_SRC1_RGB", PyInt_FromLong(GL_SRC1_RGB)); + PyDict_SetItemString(d, "GL_SRC2_RGB", PyInt_FromLong(GL_SRC2_RGB)); + PyDict_SetItemString(d, "GL_SRC0_ALPHA", PyInt_FromLong(GL_SRC0_ALPHA)); + PyDict_SetItemString(d, "GL_SRC1_ALPHA", PyInt_FromLong(GL_SRC1_ALPHA)); + PyDict_SetItemString(d, "GL_SRC2_ALPHA", PyInt_FromLong(GL_SRC2_ALPHA)); + PyDict_SetItemString(d, "GL_DOT3_RGB", PyInt_FromLong(GL_DOT3_RGB)); + PyDict_SetItemString(d, "GL_DOT3_RGBA", PyInt_FromLong(GL_DOT3_RGBA)); + PyDict_SetItemString(d, "GL_TEXTURE_CROP_RECT_OES", PyInt_FromLong(GL_TEXTURE_CROP_RECT_OES)); + //PyDict_SetItemString(d, "GL_MODELVIEW_MATRIX_FLOAT_AS_INT_BITS_OES", PyInt_FromLong(GL_MODELVIEW_MATRIX_FLOAT_AS_INT_BITS_OES)); + //PyDict_SetItemString(d, "GL_PROJECTION_MATRIX_FLOAT_AS_INT_BITS_OES", PyInt_FromLong(GL_PROJECTION_MATRIX_FLOAT_AS_INT_BITS_OES)); + //PyDict_SetItemString(d, "GL_TEXTURE_MATRIX_FLOAT_AS_INT_BITS_OES", PyInt_FromLong(GL_TEXTURE_MATRIX_FLOAT_AS_INT_BITS_OES)); + PyDict_SetItemString(d, "GL_MAX_VERTEX_UNITS_OES", PyInt_FromLong(GL_MAX_VERTEX_UNITS_OES)); + PyDict_SetItemString(d, "GL_MAX_PALETTE_MATRICES_OES", PyInt_FromLong(GL_MAX_PALETTE_MATRICES_OES)); + PyDict_SetItemString(d, "GL_MATRIX_PALETTE_OES", PyInt_FromLong(GL_MATRIX_PALETTE_OES)); + PyDict_SetItemString(d, "GL_MATRIX_INDEX_ARRAY_OES", PyInt_FromLong(GL_MATRIX_INDEX_ARRAY_OES)); + PyDict_SetItemString(d, "GL_WEIGHT_ARRAY_OES", PyInt_FromLong(GL_WEIGHT_ARRAY_OES)); + PyDict_SetItemString(d, "GL_MATRIX_INDEX_ARRAY_SIZE_OES", PyInt_FromLong(GL_MATRIX_INDEX_ARRAY_SIZE_OES)); + PyDict_SetItemString(d, "GL_MATRIX_INDEX_ARRAY_TYPE_OES", PyInt_FromLong(GL_MATRIX_INDEX_ARRAY_TYPE_OES)); + PyDict_SetItemString(d, "GL_MATRIX_INDEX_ARRAY_STRIDE_OES", PyInt_FromLong(GL_MATRIX_INDEX_ARRAY_STRIDE_OES)); + PyDict_SetItemString(d, "GL_MATRIX_INDEX_ARRAY_POINTER_OES", PyInt_FromLong(GL_MATRIX_INDEX_ARRAY_POINTER_OES)); + PyDict_SetItemString(d, "GL_MATRIX_INDEX_ARRAY_BUFFER_BINDING_OES", PyInt_FromLong(GL_MATRIX_INDEX_ARRAY_BUFFER_BINDING_OES)); + PyDict_SetItemString(d, "GL_WEIGHT_ARRAY_SIZE_OES", PyInt_FromLong(GL_WEIGHT_ARRAY_SIZE_OES)); + PyDict_SetItemString(d, "GL_WEIGHT_ARRAY_TYPE_OES", PyInt_FromLong(GL_WEIGHT_ARRAY_TYPE_OES)); + PyDict_SetItemString(d, "GL_WEIGHT_ARRAY_STRIDE_OES", PyInt_FromLong(GL_WEIGHT_ARRAY_STRIDE_OES)); + PyDict_SetItemString(d, "GL_WEIGHT_ARRAY_POINTER_OES", PyInt_FromLong(GL_WEIGHT_ARRAY_POINTER_OES)); + PyDict_SetItemString(d, "GL_WEIGHT_ARRAY_BUFFER_BINDING_OES", PyInt_FromLong(GL_WEIGHT_ARRAY_BUFFER_BINDING_OES)); + PyDict_SetItemString(d, "GL_POINT_SIZE_ARRAY_OES", PyInt_FromLong(GL_POINT_SIZE_ARRAY_OES)); + PyDict_SetItemString(d, "GL_POINT_SIZE_ARRAY_TYPE_OES", PyInt_FromLong(GL_POINT_SIZE_ARRAY_TYPE_OES)); + PyDict_SetItemString(d, "GL_POINT_SIZE_ARRAY_STRIDE_OES", PyInt_FromLong(GL_POINT_SIZE_ARRAY_STRIDE_OES)); + PyDict_SetItemString(d, "GL_POINT_SIZE_ARRAY_POINTER_OES", PyInt_FromLong(GL_POINT_SIZE_ARRAY_POINTER_OES)); + PyDict_SetItemString(d, "GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES", PyInt_FromLong(GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES)); + PyDict_SetItemString(d, "GL_POINT_SPRITE_OES", PyInt_FromLong(GL_POINT_SPRITE_OES)); + PyDict_SetItemString(d, "GL_COORD_REPLACE_OES", PyInt_FromLong(GL_COORD_REPLACE_OES)); +#endif /* GL_OES_VERSION_1_1 */ + + } +//} /* */ diff --git a/glesmodule.h b/glesmodule.h new file mode 100644 index 0000000..06ef06c --- /dev/null +++ b/glesmodule.h @@ -0,0 +1,108 @@ +/** + * ==================================================================== + * glesmodule.h + * + * Copyright (c) 2006 Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __GLES_H +#define __GLES_H + +#include "Python.h" + +#include +#include + +// comment this out to disable RDebug messages +//#define DEBUG_GLES + +#define RETURN_PYNONE { Py_INCREF(Py_None); return Py_None; } +#define RETURN_PYTRUE { Py_INCREF(Py_True); return Py_True; } +#define RETURN_PYFALSE { Py_INCREF(Py_False); return Py_False; } + +#define RETURN_IF_GLERROR { if(gles_check_error() != 0) { return NULL; } } + +//#define GLES_ARRAY_TYPE ((PyTypeObject*)SPyGetGlobalString("GLESArrayType")) +//#define IMAGE_TYPE ((PyTypeObject*)SPyGetGlobalString("ImageType")) + +#define DEBUGMSG(msg) printf(msg) +#define DEBUGMSG1(msg,arg1) printf(msg,arg1) +#define DEBUGMSG2(msg,arg1,arg2) printf(msg,arg1,arg2) +#define DEBUGMSG3(msg,arg1,arg2,arg3) printf(msg,arg1,arg2,arg3) +#define DEBUGMSG4(msg,arg1,arg2,arg3,arg4) printf(msg,arg1,arg2,arg3,arg4) + +// Structure for an array pointer +typedef struct { + void* ptr; // A pointer to the vertex/etc. data + PyObject *obj; // Associated Python object (can be NULL). +} gles_array_t; + +// Structure for array storage in TLS +typedef struct { + gles_array_t color; // Pointer for color array + gles_array_t normal; // Pointer for normal array + gles_array_t texcoord; // Pointer for texture coordinate array + gles_array_t vertex; // Pointer for vertex array + gles_array_t matrix; // Pointer for matrix index array + gles_array_t pointsize; // Pointer for point size array + gles_array_t weight; // Pointer for weight array +} GLES_Arrays; + +// Definition for gles.array object +typedef struct { + PyObject_VAR_HEAD + // Array object specific fields below. + void *arrdata; // A pointer to the raw data. + signed int len; // How many elements in the array. + GLenum arrtype; // Type of array. + // Length of a single element (needed for glVertexPointer etc.) + signed int dimension; + // Lenght of an item in bytes + signed int item_size; + // Lenght of the data in bytes + signed int real_len; +} array_object; + +PyObject *new_array_object(PyObject */*self*/, PyObject *args); +/*extern "C" static void array_dealloc(array_object *op); +extern "C" static PyObject *array_getattr(array_object *op, char *name); +extern "C" static int array_setattr(array_object *op, char *name, PyObject *v);*/ + +// Prototypes for functions in gles_util.cpp +//void *gles_convert_fbsbitmap(CFbsBitmap *bitmap, GLenum format, GLenum type, unsigned int *datalen); +//CFbsBitmap *Bitmap_AsFbsBitmap(PyObject *obj); +//PyObject *PyCAPI_GetCAPI(PyObject *object, const char *apiname); + +int gles_PySequence_Dimension(PyObject *seq); +PyObject *gles_PySequence_Collapse(GLenum type, PyObject *source, PyObject *target); +void *gles_assign_array(GLenum targetarr, void *ptr, array_object *object); + +GLbyte *gles_PySequence_AsGLbyteArray(PyObject *seq); +GLubyte *gles_PySequence_AsGLubyteArray(PyObject *seq); +GLfloat *gles_PySequence_AsGLfloatArray(PyObject *seq); +GLshort *gles_PySequence_AsGLshortArray(PyObject *seq); +GLushort *gles_PySequence_AsGLushortArray(PyObject *seq); +GLint *gles_PySequence_AsGLintArray(PyObject *seq); +GLuint *gles_PySequence_AsGLuintArray(PyObject *seq); +GLfixed *gles_PySequence_AsGLfixedArray(PyObject *seq); + +void *gles_alloc(size_t size); +void gles_free(void *ptr); + +void gles_free_array(GLenum arrtype); +void gles_init_arrays(); +void gles_uninit_arrays(); +unsigned int gles_check_error(); + +#endif // __GLES_H diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..894990d --- /dev/null +++ b/setup.py @@ -0,0 +1,12 @@ +from distutils.core import setup, Extension + +module1 = Extension('gles', + sources = ['glesmodule.c','gles_util.c'], + libraries = ['gles_cm'] + ) + +setup (name = 'gles', + version = '0.1', + description = 'OpenGL ES module', + ext_modules = [module1] + )