Home | History | Annotate | Download | only in GLES_CM
      1 /*
      2 * Copyright (C) 2011 The Android Open Source Project
      3 *
      4 * Licensed under the Apache License, Version 2.0 (the "License");
      5 * you may not use this file except in compliance with the License.
      6 * You may obtain a copy of the License at
      7 *
      8 * http://www.apache.org/licenses/LICENSE-2.0
      9 *
     10 * Unless required by applicable law or agreed to in writing, software
     11 * distributed under the License is distributed on an "AS IS" BASIS,
     12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 * See the License for the specific language governing permissions and
     14 * limitations under the License.
     15 */
     16 
     17 #ifdef _WIN32
     18 #undef GL_API
     19 #define GL_API __declspec(dllexport)
     20 #define GL_APICALL __declspec(dllexport)
     21 #endif
     22 #define GL_GLEXT_PROTOTYPES
     23 #include "GLEScmContext.h"
     24 #include "GLEScmValidate.h"
     25 #include "GLEScmUtils.h"
     26 #include <GLcommon/TextureUtils.h>
     27 
     28 #include <stdio.h>
     29 #include <GLcommon/gldefs.h>
     30 #include <GLcommon/GLDispatch.h>
     31 #include <GLcommon/GLconversion_macros.h>
     32 #include <GLcommon/TranslatorIfaces.h>
     33 #include <GLcommon/FramebufferData.h>
     34 #include <GLES/gl.h>
     35 #include <GLES/glext.h>
     36 #include <cmath>
     37 #include <map>
     38 
     39 extern "C" {
     40 
     41 //decleration
     42 static void initContext(GLEScontext* ctx,ShareGroupPtr grp);
     43 static void deleteGLESContext(GLEScontext* ctx);
     44 static void setShareGroup(GLEScontext* ctx,ShareGroupPtr grp);
     45 static GLEScontext* createGLESContext();
     46 static __translatorMustCastToProperFunctionPointerType getProcAddress(const char* procName);
     47 
     48 }
     49 
     50 /************************************** GLES EXTENSIONS *********************************************************/
     51 //extentions descriptor
     52 typedef std::map<std::string, __translatorMustCastToProperFunctionPointerType> ProcTableMap;
     53 ProcTableMap *s_glesExtensions = NULL;
     54 /****************************************************************************************************************/
     55 
     56 static EGLiface*  s_eglIface = NULL;
     57 static GLESiface  s_glesIface = {
     58     createGLESContext:createGLESContext,
     59     initContext      :initContext,
     60     deleteGLESContext:deleteGLESContext,
     61     flush            :(FUNCPTR)glFlush,
     62     finish           :(FUNCPTR)glFinish,
     63     setShareGroup    :setShareGroup,
     64     getProcAddress   :getProcAddress
     65 };
     66 
     67 #include <GLcommon/GLESmacros.h>
     68 
     69 extern "C" {
     70 
     71 static void initContext(GLEScontext* ctx,ShareGroupPtr grp) {
     72     if (!ctx->isInitialized()) {
     73         ctx->setShareGroup(grp);
     74         ctx->init();
     75         glBindTexture(GL_TEXTURE_2D,0);
     76         glBindTexture(GL_TEXTURE_CUBE_MAP_OES,0);
     77      }
     78 }
     79 
     80 static GLEScontext* createGLESContext() {
     81     return new GLEScmContext();
     82 }
     83 
     84 static void deleteGLESContext(GLEScontext* ctx) {
     85     if(ctx) delete ctx;
     86 }
     87 
     88 static void setShareGroup(GLEScontext* ctx,ShareGroupPtr grp) {
     89     if(ctx) {
     90         ctx->setShareGroup(grp);
     91     }
     92 }
     93 static __translatorMustCastToProperFunctionPointerType getProcAddress(const char* procName) {
     94     GET_CTX_RET(NULL)
     95     ctx->getGlobalLock();
     96     static bool proc_table_initialized = false;
     97     if (!proc_table_initialized) {
     98         proc_table_initialized = true;
     99         if (!s_glesExtensions)
    100             s_glesExtensions = new ProcTableMap();
    101         else
    102             s_glesExtensions->clear();
    103         (*s_glesExtensions)["glEGLImageTargetTexture2DOES"] = (__translatorMustCastToProperFunctionPointerType)glEGLImageTargetTexture2DOES;
    104         (*s_glesExtensions)["glEGLImageTargetRenderbufferStorageOES"]=(__translatorMustCastToProperFunctionPointerType)glEGLImageTargetRenderbufferStorageOES;
    105         (*s_glesExtensions)["glBlendEquationSeparateOES"] = (__translatorMustCastToProperFunctionPointerType)glBlendEquationSeparateOES;
    106         (*s_glesExtensions)["glBlendFuncSeparateOES"] = (__translatorMustCastToProperFunctionPointerType)glBlendFuncSeparateOES;
    107         (*s_glesExtensions)["glBlendEquationOES"] = (__translatorMustCastToProperFunctionPointerType)glBlendEquationOES;
    108 
    109         if (ctx->getCaps()->GL_ARB_MATRIX_PALETTE && ctx->getCaps()->GL_ARB_VERTEX_BLEND) {
    110             (*s_glesExtensions)["glCurrentPaletteMatrixOES"] = (__translatorMustCastToProperFunctionPointerType)glCurrentPaletteMatrixOES;
    111             (*s_glesExtensions)["glLoadPaletteFromModelViewMatrixOES"]=(__translatorMustCastToProperFunctionPointerType)glLoadPaletteFromModelViewMatrixOES;
    112             (*s_glesExtensions)["glMatrixIndexPointerOES"] = (__translatorMustCastToProperFunctionPointerType)glMatrixIndexPointerOES;
    113             (*s_glesExtensions)["glWeightPointerOES"] = (__translatorMustCastToProperFunctionPointerType)glWeightPointerOES;
    114         }
    115         (*s_glesExtensions)["glDepthRangefOES"] = (__translatorMustCastToProperFunctionPointerType)glDepthRangef;
    116         (*s_glesExtensions)["glFrustumfOES"] = (__translatorMustCastToProperFunctionPointerType)glFrustumf;
    117         (*s_glesExtensions)["glOrthofOES"] = (__translatorMustCastToProperFunctionPointerType)glOrthof;
    118         (*s_glesExtensions)["glClipPlanefOES"] = (__translatorMustCastToProperFunctionPointerType)glClipPlanef;
    119         (*s_glesExtensions)["glGetClipPlanefOES"] = (__translatorMustCastToProperFunctionPointerType)glGetClipPlanef;
    120         (*s_glesExtensions)["glClearDepthfOES"] = (__translatorMustCastToProperFunctionPointerType)glClearDepthf;
    121         (*s_glesExtensions)["glPointSizePointerOES"] = (__translatorMustCastToProperFunctionPointerType)glPointSizePointerOES;
    122         (*s_glesExtensions)["glTexGenfOES"] = (__translatorMustCastToProperFunctionPointerType)glTexGenfOES;
    123         (*s_glesExtensions)["glTexGenfvOES"] = (__translatorMustCastToProperFunctionPointerType)glTexGenfvOES;
    124         (*s_glesExtensions)["glTexGeniOES"] = (__translatorMustCastToProperFunctionPointerType)glTexGeniOES;
    125         (*s_glesExtensions)["glTexGenivOES"] = (__translatorMustCastToProperFunctionPointerType)glTexGenivOES;
    126         (*s_glesExtensions)["glTexGenxOES"] = (__translatorMustCastToProperFunctionPointerType)glTexGenxOES;
    127         (*s_glesExtensions)["glTexGenxvOES"] = (__translatorMustCastToProperFunctionPointerType)glTexGenxvOES;
    128         (*s_glesExtensions)["glGetTexGenfvOES"] = (__translatorMustCastToProperFunctionPointerType)glGetTexGenfvOES;
    129         (*s_glesExtensions)["glGetTexGenivOES"] = (__translatorMustCastToProperFunctionPointerType)glGetTexGenivOES;
    130         (*s_glesExtensions)["glGetTexGenxvOES"] = (__translatorMustCastToProperFunctionPointerType)glGetTexGenxvOES;
    131         if (ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT) {
    132             (*s_glesExtensions)["glIsRenderbufferOES"] = (__translatorMustCastToProperFunctionPointerType)glIsRenderbufferOES;
    133             (*s_glesExtensions)["glBindRenderbufferOES"] = (__translatorMustCastToProperFunctionPointerType)glBindRenderbufferOES;
    134             (*s_glesExtensions)["glDeleteRenderbuffersOES"] = (__translatorMustCastToProperFunctionPointerType)glDeleteRenderbuffersOES;
    135             (*s_glesExtensions)["glGenRenderbuffersOES"] = (__translatorMustCastToProperFunctionPointerType)glGenRenderbuffersOES;
    136             (*s_glesExtensions)["glRenderbufferStorageOES"] = (__translatorMustCastToProperFunctionPointerType)glRenderbufferStorageOES;
    137             (*s_glesExtensions)["glGetRenderbufferParameterivOES"] = (__translatorMustCastToProperFunctionPointerType)glGetRenderbufferParameterivOES;
    138             (*s_glesExtensions)["glIsFramebufferOES"] = (__translatorMustCastToProperFunctionPointerType)glIsFramebufferOES;
    139             (*s_glesExtensions)["glBindFramebufferOES"] = (__translatorMustCastToProperFunctionPointerType)glBindFramebufferOES;
    140             (*s_glesExtensions)["glDeleteFramebuffersOES"] = (__translatorMustCastToProperFunctionPointerType)glDeleteFramebuffersOES;
    141             (*s_glesExtensions)["glGenFramebuffersOES"] = (__translatorMustCastToProperFunctionPointerType)glGenFramebuffersOES;
    142             (*s_glesExtensions)["glCheckFramebufferStatusOES"] = (__translatorMustCastToProperFunctionPointerType)glCheckFramebufferStatusOES;
    143             (*s_glesExtensions)["glFramebufferTexture2DOES"] = (__translatorMustCastToProperFunctionPointerType)glFramebufferTexture2DOES;
    144             (*s_glesExtensions)["glFramebufferRenderbufferOES"] = (__translatorMustCastToProperFunctionPointerType)glFramebufferRenderbufferOES;
    145             (*s_glesExtensions)["glGetFramebufferAttachmentParameterivOES"] = (__translatorMustCastToProperFunctionPointerType)glGetFramebufferAttachmentParameterivOES;
    146             (*s_glesExtensions)["glGenerateMipmapOES"] = (__translatorMustCastToProperFunctionPointerType)glGenerateMipmapOES;
    147         }
    148         (*s_glesExtensions)["glDrawTexsOES"] = (__translatorMustCastToProperFunctionPointerType)glDrawTexsOES;
    149         (*s_glesExtensions)["glDrawTexiOES"] = (__translatorMustCastToProperFunctionPointerType)glDrawTexiOES;
    150         (*s_glesExtensions)["glDrawTexfOES"] = (__translatorMustCastToProperFunctionPointerType)glDrawTexfOES;
    151         (*s_glesExtensions)["glDrawTexxOES"] = (__translatorMustCastToProperFunctionPointerType)glDrawTexxOES;
    152         (*s_glesExtensions)["glDrawTexsvOES"] = (__translatorMustCastToProperFunctionPointerType)glDrawTexsvOES;
    153         (*s_glesExtensions)["glDrawTexivOES"] = (__translatorMustCastToProperFunctionPointerType)glDrawTexivOES;
    154         (*s_glesExtensions)["glDrawTexfvOES"] = (__translatorMustCastToProperFunctionPointerType)glDrawTexfvOES;
    155         (*s_glesExtensions)["glDrawTexxvOES"] = (__translatorMustCastToProperFunctionPointerType)glDrawTexxvOES;
    156     }
    157     __translatorMustCastToProperFunctionPointerType ret=NULL;
    158     ProcTableMap::iterator val = s_glesExtensions->find(procName);
    159     if (val!=s_glesExtensions->end())
    160         ret = val->second;
    161     ctx->releaseGlobalLock();
    162 
    163     return ret;
    164 }
    165 
    166 GL_API GLESiface* __translator_getIfaces(EGLiface* eglIface){
    167     s_eglIface = eglIface;
    168     return & s_glesIface;
    169 }
    170 
    171 }
    172 
    173 static ObjectLocalName TextureLocalName(GLenum target, unsigned int tex) {
    174     GET_CTX_RET(0);
    175     return (tex!=0? tex : ctx->getDefaultTextureName(target));
    176 }
    177 
    178 static TextureData* getTextureData(ObjectLocalName tex){
    179     GET_CTX_RET(NULL);
    180 
    181     if(!ctx->shareGroup()->isObject(TEXTURE,tex))
    182     {
    183         return NULL;
    184     }
    185 
    186     TextureData *texData = NULL;
    187     ObjectDataPtr objData = ctx->shareGroup()->getObjectData(TEXTURE,tex);
    188     if(!objData.Ptr()){
    189         texData = new TextureData();
    190         ctx->shareGroup()->setObjectData(TEXTURE, tex, ObjectDataPtr(texData));
    191     } else {
    192         texData = (TextureData*)objData.Ptr();
    193     }
    194     return texData;
    195 }
    196 
    197 static TextureData* getTextureTargetData(GLenum target){
    198     GET_CTX_RET(NULL);
    199     unsigned int tex = ctx->getBindedTexture(target);
    200     return getTextureData(TextureLocalName(target,tex));
    201 }
    202 
    203 GL_API GLboolean GL_APIENTRY glIsBuffer(GLuint buffer) {
    204     GET_CTX_RET(GL_FALSE)
    205 
    206     if(buffer && ctx->shareGroup().Ptr()) {
    207        ObjectDataPtr objData = ctx->shareGroup()->getObjectData(VERTEXBUFFER,buffer);
    208        return objData.Ptr() ? ((GLESbuffer*)objData.Ptr())->wasBinded():GL_FALSE;
    209     }
    210     return GL_FALSE;
    211 }
    212 
    213 GL_API GLboolean GL_APIENTRY  glIsEnabled( GLenum cap) {
    214     GET_CTX_CM_RET(GL_FALSE)
    215     RET_AND_SET_ERROR_IF(!GLEScmValidate::capability(cap,ctx->getMaxLights(),ctx->getMaxClipPlanes()),GL_INVALID_ENUM,GL_FALSE);
    216 
    217     if (cap == GL_POINT_SIZE_ARRAY_OES)
    218         return ctx->isArrEnabled(cap);
    219     else if (cap==GL_TEXTURE_GEN_STR_OES)
    220         return (ctx->dispatcher().glIsEnabled(GL_TEXTURE_GEN_S) &&
    221                 ctx->dispatcher().glIsEnabled(GL_TEXTURE_GEN_T) &&
    222                 ctx->dispatcher().glIsEnabled(GL_TEXTURE_GEN_R));
    223     else
    224         return ctx->dispatcher().glIsEnabled(cap);
    225 }
    226 
    227 GL_API GLboolean GL_APIENTRY  glIsTexture( GLuint texture) {
    228     GET_CTX_RET(GL_FALSE)
    229 
    230     if(texture == 0) // Special case
    231         return GL_FALSE;
    232 
    233     TextureData* tex = getTextureData(texture);
    234     return tex ? tex->wasBound : GL_FALSE;
    235 }
    236 
    237 GL_API GLenum GL_APIENTRY  glGetError(void) {
    238     GET_CTX_RET(GL_NO_ERROR)
    239     GLenum err = ctx->getGLerror();
    240     if(err != GL_NO_ERROR) {
    241         ctx->setGLerror(GL_NO_ERROR);
    242         return err;
    243     }
    244 
    245     return ctx->dispatcher().glGetError();
    246 }
    247 
    248 GL_API const GLubyte * GL_APIENTRY  glGetString( GLenum name) {
    249 
    250     GET_CTX_RET(NULL)
    251     switch(name) {
    252         case GL_VENDOR:
    253             return (const GLubyte*)ctx->getVendorString();
    254         case GL_RENDERER:
    255             return (const GLubyte*)ctx->getRendererString();
    256         case GL_VERSION:
    257             return (const GLubyte*)ctx->getVersionString();
    258         case GL_EXTENSIONS:
    259             return (const GLubyte*)ctx->getExtensionString();
    260         default:
    261             RET_AND_SET_ERROR_IF(true,GL_INVALID_ENUM,NULL);
    262     }
    263 }
    264 
    265 GL_API void GL_APIENTRY  glActiveTexture( GLenum texture) {
    266     GET_CTX_CM()
    267     SET_ERROR_IF(!GLEScmValidate::textureEnum(texture,ctx->getMaxTexUnits()),GL_INVALID_ENUM);
    268     ctx->setActiveTexture(texture);
    269     ctx->dispatcher().glActiveTexture(texture);
    270 }
    271 
    272 GL_API void GL_APIENTRY  glAlphaFunc( GLenum func, GLclampf ref) {
    273     GET_CTX()
    274     SET_ERROR_IF(!GLEScmValidate::alphaFunc(func),GL_INVALID_ENUM);
    275     ctx->dispatcher().glAlphaFunc(func,ref);
    276 }
    277 
    278 
    279 GL_API void GL_APIENTRY  glAlphaFuncx( GLenum func, GLclampx ref) {
    280     GET_CTX()
    281     SET_ERROR_IF(!GLEScmValidate::alphaFunc(func),GL_INVALID_ENUM);
    282     ctx->dispatcher().glAlphaFunc(func,X2F(ref));
    283 }
    284 
    285 
    286 GL_API void GL_APIENTRY  glBindBuffer( GLenum target, GLuint buffer) {
    287     GET_CTX()
    288     SET_ERROR_IF(!GLEScmValidate::bufferTarget(target),GL_INVALID_ENUM);
    289 
    290     //if buffer wasn't generated before,generate one
    291     if(buffer && ctx->shareGroup().Ptr() && !ctx->shareGroup()->isObject(VERTEXBUFFER,buffer)){
    292         ctx->shareGroup()->genName(VERTEXBUFFER,buffer);
    293         ctx->shareGroup()->setObjectData(VERTEXBUFFER,buffer,ObjectDataPtr(new GLESbuffer()));
    294     }
    295     ctx->bindBuffer(target,buffer);
    296     if (buffer) {
    297         GLESbuffer* vbo = (GLESbuffer*)ctx->shareGroup()->getObjectData(VERTEXBUFFER,buffer).Ptr();
    298         vbo->setBinded();
    299     }
    300 }
    301 
    302 
    303 GL_API void GL_APIENTRY  glBindTexture( GLenum target, GLuint texture) {
    304     GET_CTX()
    305     SET_ERROR_IF(!GLEScmValidate::textureTarget(target),GL_INVALID_ENUM)
    306 
    307     //for handling default texture (0)
    308     ObjectLocalName localTexName = TextureLocalName(target,texture);
    309 
    310     GLuint globalTextureName = localTexName;
    311     if(ctx->shareGroup().Ptr()){
    312         globalTextureName = ctx->shareGroup()->getGlobalName(TEXTURE,localTexName);
    313         //if texture wasn't generated before,generate one
    314         if(!globalTextureName){
    315             ctx->shareGroup()->genName(TEXTURE,localTexName);
    316             globalTextureName = ctx->shareGroup()->getGlobalName(TEXTURE,localTexName);
    317         }
    318 
    319         TextureData* texData = getTextureData(localTexName);
    320         if (texData->target==0)
    321             texData->target = target;
    322         //if texture was already bound to another target
    323         SET_ERROR_IF(ctx->GLTextureTargetToLocal(texData->target) != ctx->GLTextureTargetToLocal(target), GL_INVALID_OPERATION);
    324         texData->wasBound = true;
    325     }
    326 
    327     ctx->setBindedTexture(target,texture);
    328     ctx->dispatcher().glBindTexture(target,globalTextureName);
    329 }
    330 
    331 GL_API void GL_APIENTRY  glBlendFunc( GLenum sfactor, GLenum dfactor) {
    332     GET_CTX()
    333     SET_ERROR_IF(!GLEScmValidate::blendSrc(sfactor) || !GLEScmValidate::blendDst(dfactor),GL_INVALID_ENUM)
    334     ctx->dispatcher().glBlendFunc(sfactor,dfactor);
    335 }
    336 
    337 GL_API void GL_APIENTRY  glBufferData( GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage) {
    338     GET_CTX()
    339     SET_ERROR_IF(!GLEScmValidate::bufferTarget(target),GL_INVALID_ENUM);
    340     SET_ERROR_IF(!ctx->isBindedBuffer(target),GL_INVALID_OPERATION);
    341     ctx->setBufferData(target,size,data,usage);
    342 }
    343 
    344 GL_API void GL_APIENTRY  glBufferSubData( GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data) {
    345     GET_CTX()
    346     SET_ERROR_IF(!ctx->isBindedBuffer(target),GL_INVALID_OPERATION);
    347     SET_ERROR_IF(!GLEScmValidate::bufferTarget(target),GL_INVALID_ENUM);
    348     SET_ERROR_IF(!ctx->setBufferSubData(target,offset,size,data),GL_INVALID_VALUE);
    349 }
    350 
    351 GL_API void GL_APIENTRY  glClear( GLbitfield mask) {
    352     GET_CTX()
    353     ctx->drawValidate();
    354 
    355     ctx->dispatcher().glClear(mask);
    356 }
    357 
    358 GL_API void GL_APIENTRY  glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) {
    359     GET_CTX()
    360     ctx->dispatcher().glClearColor(red,green,blue,alpha);
    361 }
    362 
    363 GL_API void GL_APIENTRY  glClearColorx( GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha) {
    364     GET_CTX()
    365     ctx->dispatcher().glClearColor(X2F(red),X2F(green),X2F(blue),X2F(alpha));
    366 }
    367 
    368 
    369 GL_API void GL_APIENTRY  glClearDepthf( GLclampf depth) {
    370     GET_CTX()
    371     ctx->dispatcher().glClearDepth(depth);
    372 }
    373 
    374 GL_API void GL_APIENTRY  glClearDepthx( GLclampx depth) {
    375     GET_CTX()
    376     ctx->dispatcher().glClearDepth(X2F(depth));
    377 }
    378 
    379 GL_API void GL_APIENTRY  glClearStencil( GLint s) {
    380     GET_CTX()
    381     ctx->dispatcher().glClearStencil(s);
    382 }
    383 
    384 GL_API void GL_APIENTRY  glClientActiveTexture( GLenum texture) {
    385     GET_CTX_CM()
    386     SET_ERROR_IF(!GLEScmValidate::textureEnum(texture,ctx->getMaxTexUnits()),GL_INVALID_ENUM);
    387     ctx->setClientActiveTexture(texture);
    388     ctx->dispatcher().glClientActiveTexture(texture);
    389 
    390 }
    391 
    392 GL_API void GL_APIENTRY  glClipPlanef( GLenum plane, const GLfloat *equation) {
    393     GET_CTX()
    394     GLdouble tmpEquation[4];
    395 
    396     for(int i = 0; i < 4; i++) {
    397          tmpEquation[i] = static_cast<GLdouble>(equation[i]);
    398     }
    399     ctx->dispatcher().glClipPlane(plane,tmpEquation);
    400 }
    401 
    402 GL_API void GL_APIENTRY  glClipPlanex( GLenum plane, const GLfixed *equation) {
    403     GET_CTX()
    404     GLdouble tmpEquation[4];
    405     for(int i = 0; i < 4; i++) {
    406         tmpEquation[i] = X2D(equation[i]);
    407     }
    408     ctx->dispatcher().glClipPlane(plane,tmpEquation);
    409 }
    410 
    411 GL_API void GL_APIENTRY  glColor4f( GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) {
    412     GET_CTX()
    413     ctx->dispatcher().glColor4f(red,green,blue,alpha);
    414 }
    415 
    416 GL_API void GL_APIENTRY  glColor4ub( GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha) {
    417     GET_CTX()
    418     ctx->dispatcher().glColor4ub(red,green,blue,alpha);
    419 }
    420 
    421 GL_API void GL_APIENTRY  glColor4x( GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha) {
    422     GET_CTX()
    423     ctx->dispatcher().glColor4f(X2F(red),X2F(green),X2F(blue),X2F(alpha));
    424 }
    425 
    426 GL_API void GL_APIENTRY  glColorMask( GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) {
    427     GET_CTX()
    428     ctx->dispatcher().glColorMask(red,green,blue,alpha);
    429 }
    430 
    431 GL_API void GL_APIENTRY  glColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) {
    432     GET_CTX()
    433     SET_ERROR_IF(!GLEScmValidate::colorPointerParams(size,stride),GL_INVALID_VALUE);
    434     SET_ERROR_IF(!GLEScmValidate::colorPointerType(type),GL_INVALID_ENUM);
    435     ctx->setPointer(GL_COLOR_ARRAY,size,type,stride,pointer);
    436 }
    437 
    438 GL_API void GL_APIENTRY  glCompressedTexImage2D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data) {
    439     GET_CTX_CM()
    440     SET_ERROR_IF(!GLEScmValidate::textureTargetEx(target),GL_INVALID_ENUM);
    441 
    442     doCompressedTexImage2D(ctx, target, level, internalformat,
    443                                 width, height, border,
    444                                 imageSize, data, (void*)glTexImage2D);
    445 }
    446 
    447 GL_API void GL_APIENTRY  glCompressedTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data) {
    448     GET_CTX_CM()
    449     SET_ERROR_IF(!(GLEScmValidate::texCompImgFrmt(format) && GLEScmValidate::textureTargetEx(target)),GL_INVALID_ENUM);
    450     SET_ERROR_IF(level < 0 || level > log2(ctx->getMaxTexSize()),GL_INVALID_VALUE)
    451 
    452     GLenum uncompressedFrmt;
    453     unsigned char* uncompressed = uncompressTexture(format,uncompressedFrmt,width,height,imageSize,data,level);
    454     ctx->dispatcher().glTexSubImage2D(target,level,xoffset,yoffset,width,height,uncompressedFrmt,GL_UNSIGNED_BYTE,uncompressed);
    455     delete uncompressed;
    456 }
    457 
    458 GL_API void GL_APIENTRY  glCopyTexImage2D( GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) {
    459     GET_CTX()
    460     SET_ERROR_IF(!(GLEScmValidate::pixelFrmt(ctx,internalformat) && GLEScmValidate::textureTargetEx(target)),GL_INVALID_ENUM);
    461     SET_ERROR_IF(border != 0,GL_INVALID_VALUE);
    462     ctx->dispatcher().glCopyTexImage2D(target,level,internalformat,x,y,width,height,border);
    463 }
    464 
    465 GL_API void GL_APIENTRY  glCopyTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) {
    466     GET_CTX()
    467     SET_ERROR_IF(!GLEScmValidate::textureTargetEx(target),GL_INVALID_ENUM);
    468     ctx->dispatcher().glCopyTexSubImage2D(target,level,xoffset,yoffset,x,y,width,height);
    469 }
    470 
    471 GL_API void GL_APIENTRY  glCullFace( GLenum mode) {
    472     GET_CTX()
    473     ctx->dispatcher().glCullFace(mode);
    474 }
    475 
    476 GL_API void GL_APIENTRY  glDeleteBuffers( GLsizei n, const GLuint *buffers) {
    477     GET_CTX()
    478     SET_ERROR_IF(n<0,GL_INVALID_VALUE);
    479     if(ctx->shareGroup().Ptr()) {
    480         for(int i=0; i < n; i++){
    481            ctx->shareGroup()->deleteName(VERTEXBUFFER,buffers[i]);
    482            ctx->unbindBuffer(buffers[i]);
    483         }
    484     }
    485 }
    486 
    487 GL_API void GL_APIENTRY  glDeleteTextures( GLsizei n, const GLuint *textures) {
    488     GET_CTX()
    489     SET_ERROR_IF(n<0,GL_INVALID_VALUE);
    490     if(ctx->shareGroup().Ptr()) {
    491         for(int i=0; i < n; i++){
    492             if(textures[i] != 0)
    493             {
    494                 TextureData* tData = getTextureData(textures[i]);
    495                 // delete the underlying OpenGL texture but only if this
    496                 // texture is not a target of EGLImage.
    497                 if (!tData || tData->sourceEGLImage == 0) {
    498                     const GLuint globalTextureName = ctx->shareGroup()->getGlobalName(TEXTURE,textures[i]);
    499                     ctx->dispatcher().glDeleteTextures(1,&globalTextureName);
    500                 }
    501                 ctx->shareGroup()->deleteName(TEXTURE,textures[i]);
    502 
    503                 if(ctx->getBindedTexture(GL_TEXTURE_2D) == textures[i])
    504                     ctx->setBindedTexture(GL_TEXTURE_2D,0);
    505                 if (ctx->getBindedTexture(GL_TEXTURE_CUBE_MAP) == textures[i])
    506                     ctx->setBindedTexture(GL_TEXTURE_CUBE_MAP,0);
    507             }
    508         }
    509     }
    510 }
    511 
    512 GL_API void GL_APIENTRY  glDepthFunc( GLenum func) {
    513     GET_CTX()
    514     ctx->dispatcher().glDepthFunc(func);
    515 }
    516 
    517 GL_API void GL_APIENTRY  glDepthMask( GLboolean flag) {
    518     GET_CTX()
    519     ctx->dispatcher().glDepthMask(flag);
    520 }
    521 
    522 GL_API void GL_APIENTRY  glDepthRangef( GLclampf zNear, GLclampf zFar) {
    523     GET_CTX()
    524     ctx->dispatcher().glDepthRange(zNear,zFar);
    525 }
    526 
    527 GL_API void GL_APIENTRY  glDepthRangex( GLclampx zNear, GLclampx zFar) {
    528     GET_CTX()
    529     ctx->dispatcher().glDepthRange(X2F(zNear),X2F(zFar));
    530 }
    531 
    532 GL_API void GL_APIENTRY  glDisable( GLenum cap) {
    533     GET_CTX()
    534     if (cap==GL_TEXTURE_GEN_STR_OES) {
    535         ctx->dispatcher().glDisable(GL_TEXTURE_GEN_S);
    536         ctx->dispatcher().glDisable(GL_TEXTURE_GEN_T);
    537         ctx->dispatcher().glDisable(GL_TEXTURE_GEN_R);
    538     }
    539     else ctx->dispatcher().glDisable(cap);
    540     if (cap==GL_TEXTURE_2D || cap==GL_TEXTURE_CUBE_MAP_OES)
    541         ctx->setTextureEnabled(cap,false);
    542 }
    543 
    544 GL_API void GL_APIENTRY  glDisableClientState( GLenum array) {
    545     GET_CTX()
    546     SET_ERROR_IF(!GLEScmValidate::supportedArrays(array),GL_INVALID_ENUM)
    547 
    548     ctx->enableArr(array,false);
    549     if(array != GL_POINT_SIZE_ARRAY_OES) ctx->dispatcher().glDisableClientState(array);
    550 }
    551 
    552 
    553 GL_API void GL_APIENTRY  glDrawArrays( GLenum mode, GLint first, GLsizei count) {
    554     GET_CTX_CM()
    555     SET_ERROR_IF(count < 0,GL_INVALID_VALUE)
    556     SET_ERROR_IF(!GLEScmValidate::drawMode(mode),GL_INVALID_ENUM)
    557 
    558     ctx->drawValidate();
    559 
    560     if(!ctx->isArrEnabled(GL_VERTEX_ARRAY)) return;
    561 
    562     GLESConversionArrays tmpArrs;
    563     ctx->setupArraysPointers(tmpArrs,first,count,0,NULL,true);
    564     if(mode == GL_POINTS && ctx->isArrEnabled(GL_POINT_SIZE_ARRAY_OES)){
    565         ctx->drawPointsArrs(tmpArrs,first,count);
    566     }
    567     else
    568     {
    569         ctx->dispatcher().glDrawArrays(mode,first,count);
    570     }
    571 }
    572 
    573 GL_API void GL_APIENTRY  glDrawElements( GLenum mode, GLsizei count, GLenum type, const GLvoid *elementsIndices) {
    574     GET_CTX_CM()
    575     SET_ERROR_IF(count < 0,GL_INVALID_VALUE)
    576     SET_ERROR_IF((!GLEScmValidate::drawMode(mode) || !GLEScmValidate::drawType(type)),GL_INVALID_ENUM)
    577     if(!ctx->isArrEnabled(GL_VERTEX_ARRAY)) return;
    578 
    579     ctx->drawValidate();
    580 
    581     const GLvoid* indices = elementsIndices;
    582     GLESConversionArrays tmpArrs;
    583     if(ctx->isBindedBuffer(GL_ELEMENT_ARRAY_BUFFER)) { // if vbo is binded take the indices from the vbo
    584         const unsigned char* buf = static_cast<unsigned char *>(ctx->getBindedBuffer(GL_ELEMENT_ARRAY_BUFFER));
    585         indices = buf+reinterpret_cast<uintptr_t>(elementsIndices);
    586     }
    587 
    588     ctx->setupArraysPointers(tmpArrs,0,count,type,indices,false);
    589     if(mode == GL_POINTS && ctx->isArrEnabled(GL_POINT_SIZE_ARRAY_OES)){
    590         ctx->drawPointsElems(tmpArrs,count,type,indices);
    591     }
    592     else{
    593         ctx->dispatcher().glDrawElements(mode,count,type,indices);
    594     }
    595 }
    596 
    597 GL_API void GL_APIENTRY  glEnable( GLenum cap) {
    598     GET_CTX()
    599     if (cap==GL_TEXTURE_GEN_STR_OES) {
    600         ctx->dispatcher().glEnable(GL_TEXTURE_GEN_S);
    601         ctx->dispatcher().glEnable(GL_TEXTURE_GEN_T);
    602         ctx->dispatcher().glEnable(GL_TEXTURE_GEN_R);
    603     }
    604     else
    605         ctx->dispatcher().glEnable(cap);
    606     if (cap==GL_TEXTURE_2D || cap==GL_TEXTURE_CUBE_MAP_OES)
    607         ctx->setTextureEnabled(cap,true);
    608 }
    609 
    610 GL_API void GL_APIENTRY  glEnableClientState( GLenum array) {
    611     GET_CTX()
    612     SET_ERROR_IF(!GLEScmValidate::supportedArrays(array),GL_INVALID_ENUM)
    613 
    614     ctx->enableArr(array,true);
    615     if(array != GL_POINT_SIZE_ARRAY_OES) ctx->dispatcher().glEnableClientState(array);
    616 }
    617 
    618 GL_API void GL_APIENTRY  glFinish( void) {
    619     GET_CTX()
    620     ctx->dispatcher().glFinish();
    621 }
    622 
    623 GL_API void GL_APIENTRY  glFlush( void) {
    624     GET_CTX()
    625     ctx->dispatcher().glFlush();
    626 }
    627 
    628 GL_API void GL_APIENTRY  glFogf( GLenum pname, GLfloat param) {
    629     GET_CTX()
    630     ctx->dispatcher().glFogf(pname,param);
    631 }
    632 
    633 GL_API void GL_APIENTRY  glFogfv( GLenum pname, const GLfloat *params) {
    634     GET_CTX()
    635     ctx->dispatcher().glFogfv(pname,params);
    636 }
    637 
    638 GL_API void GL_APIENTRY  glFogx( GLenum pname, GLfixed param) {
    639     GET_CTX()
    640     ctx->dispatcher().glFogf(pname,(pname == GL_FOG_MODE)? static_cast<GLfloat>(param):X2F(param));
    641 }
    642 
    643 GL_API void GL_APIENTRY  glFogxv( GLenum pname, const GLfixed *params) {
    644     GET_CTX()
    645     if(pname == GL_FOG_MODE) {
    646         GLfloat tmpParam = static_cast<GLfloat>(params[0]);
    647         ctx->dispatcher().glFogfv(pname,&tmpParam);
    648     } else {
    649         GLfloat tmpParams[4];
    650         for(int i=0; i< 4; i++) {
    651             tmpParams[i] = X2F(params[i]);
    652         }
    653         ctx->dispatcher().glFogfv(pname,tmpParams);
    654     }
    655 
    656 }
    657 
    658 GL_API void GL_APIENTRY  glFrontFace( GLenum mode) {
    659     GET_CTX()
    660     ctx->dispatcher().glFrontFace(mode);
    661 }
    662 
    663 GL_API void GL_APIENTRY  glFrustumf( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar) {
    664     GET_CTX()
    665     ctx->dispatcher().glFrustum(left,right,bottom,top,zNear,zFar);
    666 }
    667 
    668 GL_API void GL_APIENTRY  glFrustumx( GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar) {
    669     GET_CTX()
    670     ctx->dispatcher().glFrustum(X2F(left),X2F(right),X2F(bottom),X2F(top),X2F(zNear),X2F(zFar));
    671 }
    672 
    673 GL_API void GL_APIENTRY  glGenBuffers( GLsizei n, GLuint *buffers) {
    674     GET_CTX()
    675     SET_ERROR_IF(n<0,GL_INVALID_VALUE);
    676     if(ctx->shareGroup().Ptr()) {
    677         for(int i=0; i<n ;i++) {
    678             buffers[i] = ctx->shareGroup()->genName(VERTEXBUFFER, 0, true);
    679             //generating vbo object related to this buffer name
    680             ctx->shareGroup()->setObjectData(VERTEXBUFFER,buffers[i],ObjectDataPtr(new GLESbuffer()));
    681         }
    682     }
    683 }
    684 
    685 GL_API void GL_APIENTRY  glGenTextures( GLsizei n, GLuint *textures) {
    686     GET_CTX();
    687     if(ctx->shareGroup().Ptr()) {
    688         for(int i=0; i<n ;i++) {
    689             textures[i] = ctx->shareGroup()->genName(TEXTURE, 0, true);
    690         }
    691     }
    692 }
    693 
    694 GL_API void GL_APIENTRY  glGetBooleanv( GLenum pname, GLboolean *params) {
    695     GET_CTX()
    696 
    697     if(ctx->glGetBooleanv(pname, params))
    698     {
    699         return;
    700     }
    701 
    702     GLint i;
    703 
    704     switch(pname)
    705     {
    706     case GL_FRAMEBUFFER_BINDING_OES:
    707     case GL_RENDERBUFFER_BINDING_OES:
    708         {
    709             GLint name;
    710             glGetIntegerv(pname,&name);
    711             *params = name!=0 ? GL_TRUE: GL_FALSE;
    712         }
    713     break;
    714     case GL_TEXTURE_GEN_STR_OES:
    715         {
    716             GLboolean state_s = GL_FALSE;
    717             GLboolean state_t = GL_FALSE;
    718             GLboolean state_r = GL_FALSE;
    719             ctx->dispatcher().glGetBooleanv(GL_TEXTURE_GEN_S,&state_s);
    720             ctx->dispatcher().glGetBooleanv(GL_TEXTURE_GEN_T,&state_t);
    721             ctx->dispatcher().glGetBooleanv(GL_TEXTURE_GEN_R,&state_r);
    722             *params = state_s && state_t && state_r ? GL_TRUE: GL_FALSE;
    723         }
    724     break;
    725     case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
    726         *params = (GLboolean)getCompressedFormats(NULL);
    727     break;
    728     case GL_COMPRESSED_TEXTURE_FORMATS:
    729         {
    730             int nparams = getCompressedFormats(NULL);
    731             if (nparams>0) {
    732                 int * iparams = new int[nparams];
    733                 getCompressedFormats(iparams);
    734                 for (int i=0; i<nparams; i++) params[i] = (GLboolean)iparams[i];
    735                 delete [] iparams;
    736             }
    737         }
    738     break;
    739     default:
    740         ctx->dispatcher().glGetBooleanv(pname,params);
    741     }
    742 }
    743 
    744 GL_API void GL_APIENTRY  glGetBufferParameteriv( GLenum target, GLenum pname, GLint *params) {
    745     GET_CTX()
    746     SET_ERROR_IF(!(GLEScmValidate::bufferTarget(target) && GLEScmValidate::bufferParam(pname)),GL_INVALID_ENUM);
    747     SET_ERROR_IF(!ctx->isBindedBuffer(target),GL_INVALID_OPERATION);
    748     bool ret = true;
    749     switch(pname) {
    750     case GL_BUFFER_SIZE:
    751         ctx->getBufferSize(target,params);
    752         break;
    753     case GL_BUFFER_USAGE:
    754         ctx->getBufferUsage(target,params);
    755         break;
    756     }
    757 
    758 }
    759 
    760 GL_API void GL_APIENTRY  glGetClipPlanef( GLenum pname, GLfloat eqn[4]) {
    761     GET_CTX()
    762     GLdouble tmpEqn[4];
    763 
    764     ctx->dispatcher().glGetClipPlane(pname,tmpEqn);
    765     for(int i =0 ;i < 4; i++){
    766         eqn[i] = static_cast<GLfloat>(tmpEqn[i]);
    767     }
    768 }
    769 
    770 GL_API void GL_APIENTRY  glGetClipPlanex( GLenum pname, GLfixed eqn[4]) {
    771     GET_CTX()
    772     GLdouble tmpEqn[4];
    773 
    774     ctx->dispatcher().glGetClipPlane(pname,tmpEqn);
    775     for(int i =0 ;i < 4; i++){
    776         eqn[i] = F2X(tmpEqn[i]);
    777     }
    778 }
    779 
    780 GL_API void GL_APIENTRY  glGetFixedv( GLenum pname, GLfixed *params) {
    781     GET_CTX()
    782 
    783     if(ctx->glGetFixedv(pname, params))
    784     {
    785         return;
    786     }
    787 
    788     size_t nParams = glParamSize(pname);
    789     GLfloat fParams[16];
    790     GLint i;
    791 
    792     switch(pname)
    793     {
    794     case GL_FRAMEBUFFER_BINDING_OES:
    795     case GL_RENDERBUFFER_BINDING_OES:
    796     case GL_TEXTURE_GEN_STR_OES:
    797         glGetFloatv(pname,&fParams[0]);
    798         break;
    799     case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
    800         *params = I2X(getCompressedFormats(NULL));
    801         return;
    802     break;
    803     case GL_COMPRESSED_TEXTURE_FORMATS:
    804         {
    805             int nparams = getCompressedFormats(NULL);
    806             if (nparams>0) {
    807                 int * iparams = new int[nparams];
    808                 getCompressedFormats(iparams);
    809                 for (int i=0; i<nparams; i++) params[i] = I2X(iparams[i]);
    810                 delete [] iparams;
    811             }
    812             return;
    813         }
    814     break;
    815     default:
    816         ctx->dispatcher().glGetFloatv(pname,fParams);
    817     }
    818 
    819     if (nParams)
    820     {
    821         for(size_t i =0 ; i < nParams;i++) {
    822             params[i] = F2X(fParams[i]);
    823         }
    824     }
    825 }
    826 
    827 GL_API void GL_APIENTRY  glGetFloatv( GLenum pname, GLfloat *params) {
    828     GET_CTX()
    829 
    830     if(ctx->glGetFloatv(pname, params))
    831     {
    832         return;
    833     }
    834 
    835     GLint i;
    836 
    837     switch (pname) {
    838     case GL_FRAMEBUFFER_BINDING_OES:
    839     case GL_RENDERBUFFER_BINDING_OES:
    840     case GL_TEXTURE_GEN_STR_OES:
    841         glGetIntegerv(pname,&i);
    842         *params = (GLfloat)i;
    843     break;
    844     case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
    845         *params = (GLfloat)getCompressedFormats(NULL);
    846     break;
    847     case GL_COMPRESSED_TEXTURE_FORMATS:
    848         {
    849             int nparams = getCompressedFormats(NULL);
    850             if (nparams>0) {
    851                 int * iparams = new int[nparams];
    852                 getCompressedFormats(iparams);
    853                 for (int i=0; i<nparams; i++) params[i] = (GLfloat)iparams[i];
    854                 delete [] iparams;
    855             }
    856         }
    857     break;
    858     default:
    859         ctx->dispatcher().glGetFloatv(pname,params);
    860     }
    861 }
    862 
    863 GL_API void GL_APIENTRY  glGetIntegerv( GLenum pname, GLint *params) {
    864     GET_CTX()
    865 
    866     if(ctx->glGetIntegerv(pname, params))
    867     {
    868         return;
    869     }
    870 
    871     GLint i;
    872     GLfloat f;
    873 
    874     switch(pname)
    875     {
    876     case GL_TEXTURE_GEN_STR_OES:
    877         ctx->dispatcher().glGetIntegerv(GL_TEXTURE_GEN_S,&params[0]);
    878         break;
    879     case GL_FRAMEBUFFER_BINDING_OES:
    880         if (ctx->shareGroup().Ptr()) {
    881             ctx->dispatcher().glGetIntegerv(pname,&i);
    882             *params = ctx->shareGroup()->getLocalName(FRAMEBUFFER,i);
    883         }
    884         break;
    885     case GL_RENDERBUFFER_BINDING_OES:
    886         if (ctx->shareGroup().Ptr()) {
    887             ctx->dispatcher().glGetIntegerv(pname,&i);
    888             *params = ctx->shareGroup()->getLocalName(RENDERBUFFER,i);
    889         }
    890         break;
    891     case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
    892         *params = getCompressedFormats(NULL);
    893         break;
    894     case GL_COMPRESSED_TEXTURE_FORMATS:
    895         getCompressedFormats(params);
    896         break;
    897     case GL_MAX_CLIP_PLANES:
    898         ctx->dispatcher().glGetIntegerv(pname,params);
    899         if(*params > 6)
    900         {
    901             // GLES spec requires only 6, and the ATI driver erronously
    902             // returns 8 (although it supports only 6). This WAR is simple,
    903             // compliant and good enough for developers.
    904             *params = 6;
    905         }
    906         break;
    907     case GL_ALPHA_TEST_REF:
    908         // Both the ATI and nVidia OpenGL drivers return the wrong answer
    909         // here. So return the right one.
    910         ctx->dispatcher().glGetFloatv(pname,&f);
    911         *params = (int)(f * (float)0x7fffffff);
    912         break;
    913     case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
    914         ctx->dispatcher().glGetIntegerv(pname,params);
    915         if(*params > 16)
    916         {
    917             // GLES spec requires only 2, and the ATI driver erronously
    918             // returns 32 (although it supports only 16). This WAR is simple,
    919             // compliant and good enough for developers.
    920             *params = 16;
    921         }
    922         break;
    923 
    924     default:
    925         ctx->dispatcher().glGetIntegerv(pname,params);
    926     }
    927 }
    928 
    929 GL_API void GL_APIENTRY  glGetLightfv( GLenum light, GLenum pname, GLfloat *params) {
    930     GET_CTX()
    931     ctx->dispatcher().glGetLightfv(light,pname,params);
    932 }
    933 
    934 GL_API void GL_APIENTRY  glGetLightxv( GLenum light, GLenum pname, GLfixed *params) {
    935     GET_CTX()
    936     GLfloat tmpParams[4];
    937 
    938     ctx->dispatcher().glGetLightfv(light,pname,tmpParams);
    939     switch (pname){
    940         case GL_AMBIENT:
    941         case GL_DIFFUSE:
    942         case GL_SPECULAR:
    943         case GL_POSITION:
    944             params[3] = F2X(tmpParams[3]);
    945         case GL_SPOT_DIRECTION:
    946             params[2] = F2X(tmpParams[2]);
    947         case GL_SPOT_EXPONENT:
    948         case GL_SPOT_CUTOFF:
    949         case GL_CONSTANT_ATTENUATION:
    950         case GL_LINEAR_ATTENUATION:
    951         case GL_QUADRATIC_ATTENUATION:
    952             params[1] = F2X(tmpParams[1]);
    953             break;
    954         default:{
    955             ctx->setGLerror(GL_INVALID_ENUM);
    956             return;
    957         }
    958 
    959     }
    960     params[0] = F2X(tmpParams[0]);
    961 }
    962 
    963 GL_API void GL_APIENTRY  glGetMaterialfv( GLenum face, GLenum pname, GLfloat *params) {
    964     GET_CTX()
    965     ctx->dispatcher().glGetMaterialfv(face,pname,params);
    966 }
    967 
    968 GL_API void GL_APIENTRY  glGetMaterialxv( GLenum face, GLenum pname, GLfixed *params) {
    969     GET_CTX()
    970     GLfloat tmpParams[4];
    971     ctx->dispatcher().glGetMaterialfv(face,pname,tmpParams);
    972     switch(pname){
    973     case GL_AMBIENT:
    974     case GL_DIFFUSE:
    975     case GL_SPECULAR:
    976     case GL_EMISSION:
    977     case GL_AMBIENT_AND_DIFFUSE:
    978         params[3] = tmpParams[3];
    979         params[2] = tmpParams[2];
    980         params[1] = tmpParams[1];
    981     case GL_SHININESS:
    982         params[0] = tmpParams[0];
    983         break;
    984     default:{
    985             ctx->setGLerror(GL_INVALID_ENUM);
    986             return;
    987         }
    988     }
    989 }
    990 
    991 GL_API void GL_APIENTRY  glGetPointerv( GLenum pname, void **params) {
    992     GET_CTX()
    993     const GLESpointer* p = ctx->getPointer(pname);
    994     if(p) {
    995         if(p->isVBO())
    996         {
    997             *params = (void*)(p->getBufferOffset());
    998         }else{
    999             *params = const_cast<void *>( p->getArrayData());
   1000         }
   1001     } else {
   1002         ctx->setGLerror(GL_INVALID_ENUM);
   1003     }
   1004 
   1005 }
   1006 
   1007 GL_API void GL_APIENTRY  glGetTexEnvfv( GLenum env, GLenum pname, GLfloat *params) {
   1008     GET_CTX()
   1009     ctx->dispatcher().glGetTexEnvfv(env,pname,params);
   1010 }
   1011 
   1012 GL_API void GL_APIENTRY  glGetTexEnviv( GLenum env, GLenum pname, GLint *params) {
   1013     GET_CTX()
   1014     ctx->dispatcher().glGetTexEnviv(env,pname,params);
   1015 }
   1016 
   1017 GL_API void GL_APIENTRY  glGetTexEnvxv( GLenum env, GLenum pname, GLfixed *params) {
   1018     GET_CTX()
   1019     GLfloat tmpParams[4];
   1020 
   1021     ctx->dispatcher().glGetTexEnvfv(env,pname,tmpParams);
   1022     if(pname == GL_TEXTURE_ENV_MODE) {
   1023         params[0] = static_cast<GLfixed>(tmpParams[0]);
   1024     } else {
   1025         for(int i=0 ; i < 4 ; i++)
   1026             params[i] = F2X(tmpParams[i]);
   1027     }
   1028 }
   1029 
   1030 GL_API void GL_APIENTRY  glGetTexParameterfv( GLenum target, GLenum pname, GLfloat *params) {
   1031     GET_CTX()
   1032    if (pname==GL_TEXTURE_CROP_RECT_OES) {
   1033       TextureData *texData = getTextureTargetData(target);
   1034       SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION);
   1035       for (int i=0;i<4;++i)
   1036         params[i] = texData->crop_rect[i];
   1037     }
   1038     else {
   1039       ctx->dispatcher().glGetTexParameterfv(target,pname,params);
   1040     }
   1041 }
   1042 
   1043 GL_API void GL_APIENTRY  glGetTexParameteriv( GLenum target, GLenum pname, GLint *params) {
   1044     GET_CTX()
   1045     if (pname==GL_TEXTURE_CROP_RECT_OES) {
   1046       TextureData *texData = getTextureTargetData(target);
   1047       SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION);
   1048       for (int i=0;i<4;++i)
   1049         params[i] = texData->crop_rect[i];
   1050     }
   1051     else {
   1052       ctx->dispatcher().glGetTexParameteriv(target,pname,params);
   1053     }
   1054 }
   1055 
   1056 GL_API void GL_APIENTRY  glGetTexParameterxv( GLenum target, GLenum pname, GLfixed *params) {
   1057     GET_CTX()
   1058     if (pname==GL_TEXTURE_CROP_RECT_OES) {
   1059       TextureData *texData = getTextureTargetData(target);
   1060       SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION);
   1061       for (int i=0;i<4;++i)
   1062         params[i] = F2X(texData->crop_rect[i]);
   1063     }
   1064     else {
   1065       GLfloat tmpParam;
   1066       ctx->dispatcher().glGetTexParameterfv(target,pname,&tmpParam);
   1067       params[0] = static_cast<GLfixed>(tmpParam);
   1068     }
   1069 }
   1070 
   1071 GL_API void GL_APIENTRY  glHint( GLenum target, GLenum mode) {
   1072     GET_CTX()
   1073     SET_ERROR_IF(!GLEScmValidate::hintTargetMode(target,mode),GL_INVALID_ENUM);
   1074     ctx->dispatcher().glHint(target,mode);
   1075 }
   1076 
   1077 GL_API void GL_APIENTRY  glLightModelf( GLenum pname, GLfloat param) {
   1078     GET_CTX()
   1079     ctx->dispatcher().glLightModelf(pname,param);
   1080 }
   1081 
   1082 GL_API void GL_APIENTRY  glLightModelfv( GLenum pname, const GLfloat *params) {
   1083     GET_CTX()
   1084     ctx->dispatcher().glLightModelfv(pname,params);
   1085 }
   1086 
   1087 GL_API void GL_APIENTRY  glLightModelx( GLenum pname, GLfixed param) {
   1088     GET_CTX()
   1089     GLfloat tmpParam = static_cast<GLfloat>(param);
   1090     ctx->dispatcher().glLightModelf(pname,tmpParam);
   1091 }
   1092 
   1093 GL_API void GL_APIENTRY  glLightModelxv( GLenum pname, const GLfixed *params) {
   1094     GET_CTX()
   1095     GLfloat tmpParams[4];
   1096     if(pname == GL_LIGHT_MODEL_TWO_SIDE) {
   1097         tmpParams[0] = X2F(params[0]);
   1098     } else if (pname == GL_LIGHT_MODEL_AMBIENT) {
   1099         for(int i=0;i<4;i++) {
   1100             tmpParams[i] = X2F(params[i]);
   1101         }
   1102     }
   1103 
   1104     ctx->dispatcher().glLightModelfv(pname,tmpParams);
   1105 }
   1106 
   1107 GL_API void GL_APIENTRY  glLightf( GLenum light, GLenum pname, GLfloat param) {
   1108     GET_CTX()
   1109     ctx->dispatcher().glLightf(light,pname,param);
   1110 }
   1111 
   1112 GL_API void GL_APIENTRY  glLightfv( GLenum light, GLenum pname, const GLfloat *params) {
   1113     GET_CTX()
   1114     ctx->dispatcher().glLightfv(light,pname,params);
   1115 }
   1116 
   1117 GL_API void GL_APIENTRY  glLightx( GLenum light, GLenum pname, GLfixed param) {
   1118     GET_CTX()
   1119     ctx->dispatcher().glLightf(light,pname,X2F(param));
   1120 }
   1121 
   1122 GL_API void GL_APIENTRY  glLightxv( GLenum light, GLenum pname, const GLfixed *params) {
   1123     GET_CTX()
   1124     GLfloat tmpParams[4];
   1125 
   1126     switch (pname) {
   1127         case GL_AMBIENT:
   1128         case GL_DIFFUSE:
   1129         case GL_SPECULAR:
   1130         case GL_EMISSION:
   1131         case GL_POSITION:
   1132             tmpParams[3] = X2F(params[3]);
   1133         case GL_SPOT_DIRECTION:
   1134             tmpParams[2] = X2F(params[2]);
   1135             tmpParams[1] = X2F(params[1]);
   1136         case GL_SPOT_EXPONENT:
   1137         case GL_SPOT_CUTOFF:
   1138         case GL_CONSTANT_ATTENUATION:
   1139         case GL_LINEAR_ATTENUATION:
   1140         case GL_QUADRATIC_ATTENUATION:
   1141             tmpParams[0] = X2F(params[0]);
   1142             break;
   1143         default: {
   1144                 ctx->setGLerror(GL_INVALID_ENUM);
   1145                 return;
   1146             }
   1147     }
   1148     ctx->dispatcher().glLightfv(light,pname,tmpParams);
   1149 }
   1150 
   1151 GL_API void GL_APIENTRY  glLineWidth( GLfloat width) {
   1152     GET_CTX()
   1153     ctx->dispatcher().glLineWidth(width);
   1154 }
   1155 
   1156 GL_API void GL_APIENTRY  glLineWidthx( GLfixed width) {
   1157     GET_CTX()
   1158     ctx->dispatcher().glLineWidth(X2F(width));
   1159 }
   1160 
   1161 GL_API void GL_APIENTRY  glLoadIdentity( void) {
   1162     GET_CTX()
   1163     ctx->dispatcher().glLoadIdentity();
   1164 }
   1165 
   1166 GL_API void GL_APIENTRY  glLoadMatrixf( const GLfloat *m) {
   1167     GET_CTX()
   1168     ctx->dispatcher().glLoadMatrixf(m);
   1169 }
   1170 
   1171 GL_API void GL_APIENTRY  glLoadMatrixx( const GLfixed *m) {
   1172     GET_CTX()
   1173     GLfloat mat[16];
   1174     for(int i=0; i< 16 ; i++) {
   1175         mat[i] = X2F(m[i]);
   1176     }
   1177     ctx->dispatcher().glLoadMatrixf(mat);
   1178 }
   1179 
   1180 GL_API void GL_APIENTRY  glLogicOp( GLenum opcode) {
   1181     GET_CTX()
   1182     ctx->dispatcher().glLogicOp(opcode);
   1183 }
   1184 
   1185 GL_API void GL_APIENTRY  glMaterialf( GLenum face, GLenum pname, GLfloat param) {
   1186     GET_CTX()
   1187     ctx->dispatcher().glMaterialf(face,pname,param);
   1188 }
   1189 
   1190 GL_API void GL_APIENTRY  glMaterialfv( GLenum face, GLenum pname, const GLfloat *params) {
   1191     GET_CTX()
   1192     ctx->dispatcher().glMaterialfv(face,pname,params);
   1193 }
   1194 
   1195 GL_API void GL_APIENTRY  glMaterialx( GLenum face, GLenum pname, GLfixed param) {
   1196     GET_CTX()
   1197     ctx->dispatcher().glMaterialf(face,pname,X2F(param));
   1198 }
   1199 
   1200 GL_API void GL_APIENTRY  glMaterialxv( GLenum face, GLenum pname, const GLfixed *params) {
   1201     GET_CTX()
   1202     GLfloat tmpParams[4];
   1203 
   1204     for(int i=0; i< 4; i++) {
   1205         tmpParams[i] = X2F(params[i]);
   1206     }
   1207     ctx->dispatcher().glMaterialfv(face,pname,tmpParams);
   1208 }
   1209 
   1210 GL_API void GL_APIENTRY  glMatrixMode( GLenum mode) {
   1211     GET_CTX()
   1212     ctx->dispatcher().glMatrixMode(mode);
   1213 }
   1214 
   1215 GL_API void GL_APIENTRY  glMultMatrixf( const GLfloat *m) {
   1216     GET_CTX()
   1217     ctx->dispatcher().glMultMatrixf(m);
   1218 }
   1219 
   1220 GL_API void GL_APIENTRY  glMultMatrixx( const GLfixed *m) {
   1221     GET_CTX()
   1222     GLfloat mat[16];
   1223     for(int i=0; i< 16 ; i++) {
   1224         mat[i] = X2F(m[i]);
   1225     }
   1226     ctx->dispatcher().glMultMatrixf(mat);
   1227 }
   1228 
   1229 GL_API void GL_APIENTRY  glMultiTexCoord4f( GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q) {
   1230     GET_CTX_CM()
   1231     SET_ERROR_IF(!GLEScmValidate::textureEnum(target,ctx->getMaxTexUnits()),GL_INVALID_ENUM);
   1232     ctx->dispatcher().glMultiTexCoord4f(target,s,t,r,q);
   1233 }
   1234 
   1235 GL_API void GL_APIENTRY  glMultiTexCoord4x( GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q) {
   1236     GET_CTX_CM()
   1237     SET_ERROR_IF(!GLEScmValidate::textureEnum(target,ctx->getMaxTexUnits()),GL_INVALID_ENUM);
   1238     ctx->dispatcher().glMultiTexCoord4f(target,X2F(s),X2F(t),X2F(r),X2F(q));
   1239 }
   1240 
   1241 GL_API void GL_APIENTRY  glNormal3f( GLfloat nx, GLfloat ny, GLfloat nz) {
   1242     GET_CTX()
   1243     ctx->dispatcher().glNormal3f(nx,ny,nz);
   1244 }
   1245 
   1246 GL_API void GL_APIENTRY  glNormal3x( GLfixed nx, GLfixed ny, GLfixed nz) {
   1247     GET_CTX()
   1248     ctx->dispatcher().glNormal3f(X2F(nx),X2F(ny),X2F(nz));
   1249 }
   1250 
   1251 GL_API void GL_APIENTRY  glNormalPointer( GLenum type, GLsizei stride, const GLvoid *pointer) {
   1252     GET_CTX()
   1253     SET_ERROR_IF(stride < 0,GL_INVALID_VALUE);
   1254     SET_ERROR_IF(!GLEScmValidate::normalPointerType(type),GL_INVALID_ENUM);
   1255     ctx->setPointer(GL_NORMAL_ARRAY,3,type,stride,pointer);//3 normal verctor
   1256 }
   1257 
   1258 GL_API void GL_APIENTRY  glOrthof( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar) {
   1259     GET_CTX()
   1260     ctx->dispatcher().glOrtho(left,right,bottom,top,zNear,zFar);
   1261 }
   1262 
   1263 GL_API void GL_APIENTRY  glOrthox( GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar) {
   1264     GET_CTX()
   1265     ctx->dispatcher().glOrtho(X2F(left),X2F(right),X2F(bottom),X2F(top),X2F(zNear),X2F(zFar));
   1266 }
   1267 
   1268 GL_API void GL_APIENTRY  glPixelStorei( GLenum pname, GLint param) {
   1269     GET_CTX()
   1270     SET_ERROR_IF(!(pname == GL_PACK_ALIGNMENT || pname == GL_UNPACK_ALIGNMENT),GL_INVALID_ENUM);
   1271     SET_ERROR_IF(!((param==1)||(param==2)||(param==4)||(param==8)), GL_INVALID_VALUE);
   1272     ctx->setUnpackAlignment(param);
   1273     ctx->dispatcher().glPixelStorei(pname,param);
   1274 }
   1275 
   1276 GL_API void GL_APIENTRY  glPointParameterf( GLenum pname, GLfloat param) {
   1277     GET_CTX()
   1278     ctx->dispatcher().glPointParameterf(pname,param);
   1279 }
   1280 
   1281 GL_API void GL_APIENTRY  glPointParameterfv( GLenum pname, const GLfloat *params) {
   1282     GET_CTX()
   1283     ctx->dispatcher().glPointParameterfv(pname,params);
   1284 }
   1285 
   1286 GL_API void GL_APIENTRY  glPointParameterx( GLenum pname, GLfixed param)
   1287 {
   1288     GET_CTX()
   1289     ctx->dispatcher().glPointParameterf(pname,X2F(param));
   1290 }
   1291 
   1292 GL_API void GL_APIENTRY  glPointParameterxv( GLenum pname, const GLfixed *params) {
   1293     GET_CTX()
   1294 
   1295     GLfloat tmpParam = X2F(*params) ;
   1296     ctx->dispatcher().glPointParameterfv(pname,&tmpParam);
   1297 }
   1298 
   1299 GL_API void GL_APIENTRY  glPointSize( GLfloat size) {
   1300     GET_CTX()
   1301     ctx->dispatcher().glPointSize(size);
   1302 }
   1303 
   1304 GL_API void GL_APIENTRY  glPointSizePointerOES( GLenum type, GLsizei stride, const GLvoid *pointer) {
   1305     GET_CTX()
   1306     SET_ERROR_IF(stride < 0,GL_INVALID_VALUE);
   1307     SET_ERROR_IF(!GLEScmValidate::pointPointerType(type),GL_INVALID_ENUM);
   1308     ctx->setPointer(GL_POINT_SIZE_ARRAY_OES,1,type,stride,pointer);
   1309 }
   1310 
   1311 GL_API void GL_APIENTRY  glPointSizex( GLfixed size) {
   1312     GET_CTX()
   1313     ctx->dispatcher().glPointSize(X2F(size));
   1314 }
   1315 
   1316 GL_API void GL_APIENTRY  glPolygonOffset( GLfloat factor, GLfloat units) {
   1317     GET_CTX()
   1318     ctx->dispatcher().glPolygonOffset(factor,units);
   1319 }
   1320 
   1321 GL_API void GL_APIENTRY  glPolygonOffsetx( GLfixed factor, GLfixed units) {
   1322     GET_CTX()
   1323     ctx->dispatcher().glPolygonOffset(X2F(factor),X2F(units));
   1324 }
   1325 
   1326 GL_API void GL_APIENTRY  glPopMatrix(void) {
   1327     GET_CTX()
   1328     ctx->dispatcher().glPopMatrix();
   1329 }
   1330 
   1331 GL_API void GL_APIENTRY  glPushMatrix(void) {
   1332     GET_CTX()
   1333     ctx->dispatcher().glPushMatrix();
   1334 }
   1335 
   1336 GL_API void GL_APIENTRY  glReadPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels) {
   1337     GET_CTX()
   1338     SET_ERROR_IF(!(GLEScmValidate::pixelFrmt(ctx,format) && GLEScmValidate::pixelType(ctx,type)),GL_INVALID_ENUM);
   1339     SET_ERROR_IF(!(GLEScmValidate::pixelOp(format,type)),GL_INVALID_OPERATION);
   1340 
   1341     ctx->dispatcher().glReadPixels(x,y,width,height,format,type,pixels);
   1342 }
   1343 
   1344 GL_API void GL_APIENTRY  glRotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z) {
   1345     GET_CTX()
   1346     ctx->dispatcher().glRotatef(angle,x,y,z);
   1347 }
   1348 
   1349 GL_API void GL_APIENTRY  glRotatex( GLfixed angle, GLfixed x, GLfixed y, GLfixed z) {
   1350     GET_CTX()
   1351     ctx->dispatcher().glRotatef(angle,X2F(x),X2F(y),X2F(z));
   1352 }
   1353 
   1354 GL_API void GL_APIENTRY  glSampleCoverage( GLclampf value, GLboolean invert) {
   1355     GET_CTX()
   1356     ctx->dispatcher().glSampleCoverage(value,invert);
   1357 }
   1358 
   1359 GL_API void GL_APIENTRY  glSampleCoveragex( GLclampx value, GLboolean invert) {
   1360     GET_CTX()
   1361     ctx->dispatcher().glSampleCoverage(X2F(value),invert);
   1362 }
   1363 
   1364 GL_API void GL_APIENTRY  glScalef( GLfloat x, GLfloat y, GLfloat z) {
   1365     GET_CTX()
   1366     ctx->dispatcher().glScalef(x,y,z);
   1367 }
   1368 
   1369 GL_API void GL_APIENTRY  glScalex( GLfixed x, GLfixed y, GLfixed z) {
   1370     GET_CTX()
   1371     ctx->dispatcher().glScalef(X2F(x),X2F(y),X2F(z));
   1372 }
   1373 
   1374 GL_API void GL_APIENTRY  glScissor( GLint x, GLint y, GLsizei width, GLsizei height) {
   1375     GET_CTX()
   1376     ctx->dispatcher().glScissor(x,y,width,height);
   1377 }
   1378 
   1379 GL_API void GL_APIENTRY  glShadeModel( GLenum mode) {
   1380     GET_CTX()
   1381     ctx->dispatcher().glShadeModel(mode);
   1382 }
   1383 
   1384 GL_API void GL_APIENTRY  glStencilFunc( GLenum func, GLint ref, GLuint mask) {
   1385     GET_CTX()
   1386     ctx->dispatcher().glStencilFunc(func,ref,mask);
   1387 }
   1388 
   1389 GL_API void GL_APIENTRY  glStencilMask( GLuint mask) {
   1390     GET_CTX()
   1391     ctx->dispatcher().glStencilMask(mask);
   1392 }
   1393 
   1394 GL_API void GL_APIENTRY  glStencilOp( GLenum fail, GLenum zfail, GLenum zpass) {
   1395     GET_CTX()
   1396     SET_ERROR_IF(!(GLEScmValidate::stencilOp(fail) && GLEScmValidate::stencilOp(zfail) && GLEScmValidate::stencilOp(zpass)),GL_INVALID_ENUM);
   1397     ctx->dispatcher().glStencilOp(fail,zfail,zpass);
   1398 }
   1399 
   1400 GL_API void GL_APIENTRY  glTexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) {
   1401     GET_CTX()
   1402     SET_ERROR_IF(!GLEScmValidate::texCoordPointerParams(size,stride),GL_INVALID_VALUE);
   1403     SET_ERROR_IF(!GLEScmValidate::texCoordPointerType(type),GL_INVALID_ENUM);
   1404     ctx->setPointer(GL_TEXTURE_COORD_ARRAY,size,type,stride,pointer);
   1405 }
   1406 
   1407 GL_API void GL_APIENTRY  glTexEnvf( GLenum target, GLenum pname, GLfloat param) {
   1408     GET_CTX()
   1409     SET_ERROR_IF(!GLEScmValidate::texEnv(target,pname),GL_INVALID_ENUM);
   1410     ctx->dispatcher().glTexEnvf(target,pname,param);
   1411 }
   1412 
   1413 GL_API void GL_APIENTRY  glTexEnvfv( GLenum target, GLenum pname, const GLfloat *params) {
   1414     GET_CTX()
   1415     SET_ERROR_IF(!GLEScmValidate::texEnv(target,pname),GL_INVALID_ENUM);
   1416     ctx->dispatcher().glTexEnvfv(target,pname,params);
   1417 }
   1418 
   1419 GL_API void GL_APIENTRY  glTexEnvi( GLenum target, GLenum pname, GLint param) {
   1420     GET_CTX()
   1421     SET_ERROR_IF(!GLEScmValidate::texEnv(target,pname),GL_INVALID_ENUM);
   1422     ctx->dispatcher().glTexEnvi(target,pname,param);
   1423 }
   1424 
   1425 GL_API void GL_APIENTRY  glTexEnviv( GLenum target, GLenum pname, const GLint *params) {
   1426     GET_CTX()
   1427     SET_ERROR_IF(!GLEScmValidate::texEnv(target,pname),GL_INVALID_ENUM);
   1428     ctx->dispatcher().glTexEnviv(target,pname,params);
   1429 }
   1430 
   1431 GL_API void GL_APIENTRY  glTexEnvx( GLenum target, GLenum pname, GLfixed param) {
   1432     GET_CTX()
   1433     SET_ERROR_IF(!GLEScmValidate::texEnv(target,pname),GL_INVALID_ENUM);
   1434     GLfloat tmpParam = static_cast<GLfloat>(param);
   1435     ctx->dispatcher().glTexEnvf(target,pname,tmpParam);
   1436 }
   1437 
   1438 GL_API void GL_APIENTRY  glTexEnvxv( GLenum target, GLenum pname, const GLfixed *params) {
   1439     GET_CTX()
   1440     SET_ERROR_IF(!GLEScmValidate::texEnv(target,pname),GL_INVALID_ENUM);
   1441 
   1442     GLfloat tmpParams[4];
   1443     if(pname == GL_TEXTURE_ENV_COLOR) {
   1444         for(int i =0;i<4;i++) {
   1445             tmpParams[i] = X2F(params[i]);
   1446         }
   1447     } else {
   1448         tmpParams[0] = static_cast<GLfloat>(params[0]);
   1449     }
   1450     ctx->dispatcher().glTexEnvfv(target,pname,tmpParams);
   1451 }
   1452 
   1453 GL_API void GL_APIENTRY  glTexImage2D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels) {
   1454     GET_CTX()
   1455 
   1456     SET_ERROR_IF(!(GLEScmValidate::textureTargetEx(target) &&
   1457                      GLEScmValidate::pixelFrmt(ctx,internalformat) &&
   1458                      GLEScmValidate::pixelFrmt(ctx,format) &&
   1459                      GLEScmValidate::pixelType(ctx,type)),GL_INVALID_ENUM);
   1460 
   1461     SET_ERROR_IF(!(GLEScmValidate::pixelOp(format,type) && internalformat == ((GLint)format)),GL_INVALID_OPERATION);
   1462 
   1463     bool needAutoMipmap = false;
   1464 
   1465     if (ctx->shareGroup().Ptr()){
   1466         TextureData *texData = getTextureTargetData(target);
   1467         SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION);
   1468         if(texData) {
   1469             texData->width = width;
   1470             texData->height = height;
   1471             texData->border = border;
   1472             texData->internalFormat = internalformat;
   1473             texData->target = target;
   1474 
   1475             if (texData->sourceEGLImage != 0) {
   1476                 //
   1477                 // This texture was a target of EGLImage,
   1478                 // but now it is re-defined so we need to detach
   1479                 // from the EGLImage and re-generate global texture name
   1480                 // for it.
   1481                 //
   1482                 if (texData->eglImageDetach) {
   1483                     (*texData->eglImageDetach)(texData->sourceEGLImage);
   1484                 }
   1485                 unsigned int tex = ctx->getBindedTexture(target);
   1486                 ctx->shareGroup()->replaceGlobalName(TEXTURE,
   1487                                                      tex,
   1488                                                      texData->oldGlobal);
   1489                 ctx->dispatcher().glBindTexture(GL_TEXTURE_2D, texData->oldGlobal);
   1490                 texData->sourceEGLImage = 0;
   1491                 texData->oldGlobal = 0;
   1492             }
   1493 
   1494             needAutoMipmap = texData->requiresAutoMipmap;
   1495         }
   1496     }
   1497 
   1498     ctx->dispatcher().glTexImage2D(target,level,
   1499                                    internalformat,width,height,
   1500                                    border,format,type,pixels);
   1501 
   1502     if(needAutoMipmap)
   1503     {
   1504         ctx->dispatcher().glGenerateMipmapEXT(target);
   1505     }
   1506 }
   1507 
   1508 static bool handleMipmapGeneration(GLenum target, GLenum pname, bool param)
   1509 {
   1510     GET_CTX_RET(false)
   1511 
   1512     if(pname == GL_GENERATE_MIPMAP && !ctx->isAutoMipmapSupported())
   1513     {
   1514         TextureData *texData = getTextureTargetData(target);
   1515         if(texData)
   1516         {
   1517             texData->requiresAutoMipmap = param;
   1518         }
   1519         return true;
   1520     }
   1521 
   1522     return false;
   1523 }
   1524 
   1525 GL_API void GL_APIENTRY  glTexParameterf( GLenum target, GLenum pname, GLfloat param) {
   1526     GET_CTX()
   1527     SET_ERROR_IF(!GLEScmValidate::texParams(target,pname),GL_INVALID_ENUM);
   1528 
   1529     if(handleMipmapGeneration(target, pname, (bool)param))
   1530         return;
   1531 
   1532     ctx->dispatcher().glTexParameterf(target,pname,param);
   1533 }
   1534 
   1535 GL_API void GL_APIENTRY  glTexParameterfv( GLenum target, GLenum pname, const GLfloat *params) {
   1536     GET_CTX()
   1537     SET_ERROR_IF(!GLEScmValidate::texParams(target,pname),GL_INVALID_ENUM);
   1538 
   1539     if(handleMipmapGeneration(target, pname, (bool)(*params)))
   1540         return;
   1541 
   1542     if (pname==GL_TEXTURE_CROP_RECT_OES) {
   1543         TextureData *texData = getTextureTargetData(target);
   1544         SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION);
   1545         for (int i=0;i<4;++i)
   1546             texData->crop_rect[i] = params[i];
   1547     }
   1548     else {
   1549         ctx->dispatcher().glTexParameterfv(target,pname,params);
   1550     }
   1551 }
   1552 
   1553 GL_API void GL_APIENTRY  glTexParameteri( GLenum target, GLenum pname, GLint param) {
   1554     GET_CTX()
   1555     SET_ERROR_IF(!GLEScmValidate::texParams(target,pname),GL_INVALID_ENUM);
   1556 
   1557     if(handleMipmapGeneration(target, pname, (bool)param))
   1558         return;
   1559 
   1560     ctx->dispatcher().glTexParameteri(target,pname,param);
   1561 }
   1562 
   1563 GL_API void GL_APIENTRY  glTexParameteriv( GLenum target, GLenum pname, const GLint *params) {
   1564     GET_CTX()
   1565     SET_ERROR_IF(!GLEScmValidate::texParams(target,pname),GL_INVALID_ENUM);
   1566 
   1567     if(handleMipmapGeneration(target, pname, (bool)(*params)))
   1568         return;
   1569 
   1570     if (pname==GL_TEXTURE_CROP_RECT_OES) {
   1571         TextureData *texData = getTextureTargetData(target);
   1572         SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION);
   1573         for (int i=0;i<4;++i)
   1574             texData->crop_rect[i] = params[i];
   1575     }
   1576     else {
   1577         ctx->dispatcher().glTexParameteriv(target,pname,params);
   1578     }
   1579 }
   1580 
   1581 GL_API void GL_APIENTRY  glTexParameterx( GLenum target, GLenum pname, GLfixed param) {
   1582     GET_CTX()
   1583     SET_ERROR_IF(!GLEScmValidate::texParams(target,pname),GL_INVALID_ENUM);
   1584 
   1585     if(handleMipmapGeneration(target, pname, (bool)param))
   1586         return;
   1587 
   1588     ctx->dispatcher().glTexParameterf(target,pname,static_cast<GLfloat>(param));
   1589 }
   1590 
   1591 GL_API void GL_APIENTRY  glTexParameterxv( GLenum target, GLenum pname, const GLfixed *params) {
   1592     GET_CTX()
   1593     SET_ERROR_IF(!GLEScmValidate::texParams(target,pname),GL_INVALID_ENUM);
   1594 
   1595     if(handleMipmapGeneration(target, pname, (bool)(*params)))
   1596         return;
   1597 
   1598     if (pname==GL_TEXTURE_CROP_RECT_OES) {
   1599         TextureData *texData = getTextureTargetData(target);
   1600         SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION);
   1601         for (int i=0;i<4;++i)
   1602             texData->crop_rect[i] = X2F(params[i]);
   1603     }
   1604     else {
   1605         GLfloat param = static_cast<GLfloat>(params[0]);
   1606         ctx->dispatcher().glTexParameterfv(target,pname,&param);
   1607     }
   1608 }
   1609 
   1610 GL_API void GL_APIENTRY  glTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels) {
   1611     GET_CTX()
   1612     SET_ERROR_IF(!(GLEScmValidate::textureTargetEx(target) &&
   1613                    GLEScmValidate::pixelFrmt(ctx,format)&&
   1614                    GLEScmValidate::pixelType(ctx,type)),GL_INVALID_ENUM);
   1615     SET_ERROR_IF(!GLEScmValidate::pixelOp(format,type),GL_INVALID_OPERATION);
   1616 
   1617     ctx->dispatcher().glTexSubImage2D(target,level,xoffset,yoffset,width,height,format,type,pixels);
   1618 
   1619     if (ctx->shareGroup().Ptr()){
   1620         TextureData *texData = getTextureTargetData(target);
   1621         SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION);
   1622         if(texData && texData->requiresAutoMipmap)
   1623         {
   1624                 ctx->dispatcher().glGenerateMipmapEXT(target);
   1625         }
   1626     }
   1627 }
   1628 
   1629 GL_API void GL_APIENTRY  glTranslatef( GLfloat x, GLfloat y, GLfloat z) {
   1630     GET_CTX()
   1631     ctx->dispatcher().glTranslatef(x,y,z);
   1632 }
   1633 
   1634 GL_API void GL_APIENTRY  glTranslatex( GLfixed x, GLfixed y, GLfixed z) {
   1635     GET_CTX()
   1636     ctx->dispatcher().glTranslatef(X2F(x),X2F(y),X2F(z));
   1637 }
   1638 
   1639 GL_API void GL_APIENTRY  glVertexPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) {
   1640     GET_CTX()
   1641     SET_ERROR_IF(!GLEScmValidate::vertexPointerParams(size,stride),GL_INVALID_VALUE);
   1642     SET_ERROR_IF(!GLEScmValidate::vertexPointerType(type),GL_INVALID_ENUM);
   1643     ctx->setPointer(GL_VERTEX_ARRAY,size,type,stride,pointer);
   1644 }
   1645 
   1646 GL_API void GL_APIENTRY  glViewport( GLint x, GLint y, GLsizei width, GLsizei height) {
   1647     GET_CTX()
   1648     ctx->dispatcher().glViewport(x,y,width,height);
   1649 }
   1650 
   1651 GL_API void GL_APIENTRY glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image)
   1652 {
   1653     GET_CTX();
   1654     SET_ERROR_IF(!GLEScmValidate::textureTargetLimited(target),GL_INVALID_ENUM);
   1655     unsigned int imagehndl = ToTargetCompatibleHandle((uintptr_t)image);
   1656     EglImage *img = s_eglIface->eglAttachEGLImage(imagehndl);
   1657     if (img) {
   1658         // Create the texture object in the underlying EGL implementation,
   1659         // flag to the OpenGL layer to skip the image creation and map the
   1660         // current binded texture object to the existing global object.
   1661         if (ctx->shareGroup().Ptr()) {
   1662             ObjectLocalName tex = TextureLocalName(target,ctx->getBindedTexture(target));
   1663             unsigned int oldGlobal = ctx->shareGroup()->getGlobalName(TEXTURE, tex);
   1664             // Delete old texture object but only if it is not a target of a EGLImage
   1665             if (oldGlobal) {
   1666                 TextureData* oldTexData = getTextureData(tex);
   1667                 if (!oldTexData || oldTexData->sourceEGLImage == 0) {
   1668                     ctx->dispatcher().glDeleteTextures(1, &oldGlobal);
   1669                 }
   1670             }
   1671             // replace mapping and bind the new global object
   1672             ctx->shareGroup()->replaceGlobalName(TEXTURE, tex,img->globalTexName);
   1673             ctx->dispatcher().glBindTexture(GL_TEXTURE_2D, img->globalTexName);
   1674             TextureData *texData = getTextureTargetData(target);
   1675             SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION);
   1676             texData->width = img->width;
   1677             texData->height = img->height;
   1678             texData->border = img->border;
   1679             texData->internalFormat = img->internalFormat;
   1680             texData->sourceEGLImage = imagehndl;
   1681             texData->eglImageDetach = s_eglIface->eglDetachEGLImage;
   1682             texData->oldGlobal = oldGlobal;
   1683         }
   1684     }
   1685 }
   1686 
   1687 GL_API void GL_APIENTRY glEGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image)
   1688 {
   1689     GET_CTX();
   1690     SET_ERROR_IF(target != GL_RENDERBUFFER_OES,GL_INVALID_ENUM);
   1691     unsigned int imagehndl = ToTargetCompatibleHandle((uintptr_t)image);
   1692     EglImage *img = s_eglIface->eglAttachEGLImage(imagehndl);
   1693     SET_ERROR_IF(!img,GL_INVALID_VALUE);
   1694     SET_ERROR_IF(!ctx->shareGroup().Ptr(),GL_INVALID_OPERATION);
   1695 
   1696     // Get current bounded renderbuffer
   1697     // raise INVALID_OPERATIOn if no renderbuffer is bounded
   1698     GLuint rb = ctx->getRenderbufferBinding();
   1699     SET_ERROR_IF(rb == 0,GL_INVALID_OPERATION);
   1700     ObjectDataPtr objData = ctx->shareGroup()->getObjectData(RENDERBUFFER,rb);
   1701     RenderbufferData *rbData = (RenderbufferData *)objData.Ptr();
   1702     SET_ERROR_IF(!rbData,GL_INVALID_OPERATION);
   1703 
   1704     //
   1705     // flag in the renderbufferData that it is an eglImage target
   1706     //
   1707     rbData->sourceEGLImage = imagehndl;
   1708     rbData->eglImageDetach = s_eglIface->eglDetachEGLImage;
   1709     rbData->eglImageGlobalTexName = img->globalTexName;
   1710 
   1711     //
   1712     // if the renderbuffer is attached to a framebuffer
   1713     // change the framebuffer attachment in the undelying OpenGL
   1714     // to point to the eglImage texture object.
   1715     //
   1716     if (rbData->attachedFB) {
   1717         // update the framebuffer attachment point to the
   1718         // underlying texture of the img
   1719         GLuint prevFB = ctx->getFramebufferBinding();
   1720         if (prevFB != rbData->attachedFB) {
   1721             ctx->dispatcher().glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,
   1722                                                    rbData->attachedFB);
   1723         }
   1724         ctx->dispatcher().glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
   1725                                                     rbData->attachedPoint,
   1726                                                     GL_TEXTURE_2D,
   1727                                                     img->globalTexName,0);
   1728         if (prevFB != rbData->attachedFB) {
   1729             ctx->dispatcher().glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,
   1730                                                    prevFB);
   1731         }
   1732     }
   1733 }
   1734 
   1735 /* GL_OES_blend_subtract*/
   1736 GL_API void GL_APIENTRY glBlendEquationOES(GLenum mode) {
   1737     GET_CTX()
   1738     SET_ERROR_IF(!(GLEScmValidate::blendEquationMode(mode)), GL_INVALID_ENUM);
   1739     ctx->dispatcher().glBlendEquation(mode);
   1740 }
   1741 
   1742 /* GL_OES_blend_equation_separate */
   1743 GL_API void GL_APIENTRY glBlendEquationSeparateOES (GLenum modeRGB, GLenum modeAlpha) {
   1744     GET_CTX()
   1745     SET_ERROR_IF(!(GLEScmValidate::blendEquationMode(modeRGB) && GLEScmValidate::blendEquationMode(modeAlpha)), GL_INVALID_ENUM);
   1746     ctx->dispatcher().glBlendEquationSeparate(modeRGB,modeAlpha);
   1747 }
   1748 
   1749 /* GL_OES_blend_func_separate */
   1750 GL_API void GL_APIENTRY glBlendFuncSeparateOES(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) {
   1751     GET_CTX()
   1752     SET_ERROR_IF(!GLEScmValidate::blendSrc(srcRGB) || !GLEScmValidate::blendDst(dstRGB) ||
   1753                  !GLEScmValidate::blendSrc(srcAlpha) || ! GLEScmValidate::blendDst(dstAlpha) ,GL_INVALID_ENUM);
   1754     ctx->dispatcher().glBlendFuncSeparate(srcRGB,dstRGB,srcAlpha,dstAlpha);
   1755 }
   1756 
   1757 /* GL_OES_framebuffer_object */
   1758 GL_API GLboolean GL_APIENTRY glIsRenderbufferOES(GLuint renderbuffer) {
   1759     GET_CTX_RET(GL_FALSE)
   1760     RET_AND_SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION,GL_FALSE);
   1761     if(renderbuffer && ctx->shareGroup().Ptr()){
   1762         return ctx->shareGroup()->isObject(RENDERBUFFER,renderbuffer) ? GL_TRUE :GL_FALSE;
   1763     }
   1764     return ctx->dispatcher().glIsRenderbufferEXT(renderbuffer);
   1765 }
   1766 
   1767 GL_API void GLAPIENTRY glBindRenderbufferOES(GLenum target, GLuint renderbuffer) {
   1768     GET_CTX()
   1769     SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION);
   1770     SET_ERROR_IF(!GLEScmValidate::renderbufferTarget(target),GL_INVALID_ENUM);
   1771 
   1772     //if buffer wasn't generated before,generate one
   1773     if(renderbuffer && ctx->shareGroup().Ptr() && !ctx->shareGroup()->isObject(RENDERBUFFER,renderbuffer)){
   1774         ctx->shareGroup()->genName(RENDERBUFFER,renderbuffer);
   1775         ctx->shareGroup()->setObjectData(RENDERBUFFER,
   1776                                          renderbuffer,
   1777                                          ObjectDataPtr(new RenderbufferData()));
   1778     }
   1779 
   1780     int globalBufferName = (renderbuffer != 0) ? ctx->shareGroup()->getGlobalName(RENDERBUFFER,renderbuffer) : 0;
   1781     ctx->dispatcher().glBindRenderbufferEXT(target,globalBufferName);
   1782 
   1783     // update renderbuffer binding state
   1784     ctx->setRenderbufferBinding(renderbuffer);
   1785 }
   1786 
   1787 GL_API void GLAPIENTRY glDeleteRenderbuffersOES(GLsizei n, const GLuint *renderbuffers) {
   1788     GET_CTX()
   1789     SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION);
   1790     for (int i=0;i<n;++i) {
   1791         GLuint globalBufferName = ctx->shareGroup()->getGlobalName(RENDERBUFFER,renderbuffers[i]);
   1792         ctx->dispatcher().glDeleteRenderbuffersEXT(1,&globalBufferName);
   1793     }
   1794 }
   1795 
   1796 GL_API void GLAPIENTRY glGenRenderbuffersOES(GLsizei n, GLuint *renderbuffers) {
   1797     GET_CTX()
   1798     SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION);
   1799     SET_ERROR_IF(n<0,GL_INVALID_VALUE);
   1800     if(ctx->shareGroup().Ptr()) {
   1801         for(int i=0; i<n ;i++) {
   1802             renderbuffers[i] = ctx->shareGroup()->genName(RENDERBUFFER, 0, true);
   1803             ctx->shareGroup()->setObjectData(RENDERBUFFER,
   1804                                              renderbuffers[i],
   1805                                          ObjectDataPtr(new RenderbufferData()));
   1806         }
   1807     }
   1808 }
   1809 
   1810 GL_API void GLAPIENTRY glRenderbufferStorageOES(GLenum target, GLenum internalformat, GLsizei width, GLsizei height){
   1811     GET_CTX()
   1812     SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION);
   1813     SET_ERROR_IF(!GLEScmValidate::renderbufferTarget(target) || !GLEScmValidate::renderbufferInternalFrmt(ctx,internalformat) ,GL_INVALID_ENUM);
   1814     if (internalformat==GL_RGB565_OES) //RGB565 not supported by GL
   1815         internalformat = GL_RGB8_OES;
   1816 
   1817     // Get current bounded renderbuffer
   1818     // raise INVALID_OPERATIOn if no renderbuffer is bounded
   1819     GLuint rb = ctx->getRenderbufferBinding();
   1820     SET_ERROR_IF(rb == 0,GL_INVALID_OPERATION);
   1821     ObjectDataPtr objData = ctx->shareGroup()->getObjectData(RENDERBUFFER,rb);
   1822     RenderbufferData *rbData = (RenderbufferData *)objData.Ptr();
   1823     SET_ERROR_IF(!rbData,GL_INVALID_OPERATION);
   1824 
   1825     //
   1826     // if the renderbuffer was an eglImage target, detach from
   1827     // the eglImage.
   1828     //
   1829     if (rbData->sourceEGLImage != 0) {
   1830         if (rbData->eglImageDetach) {
   1831             (*rbData->eglImageDetach)(rbData->sourceEGLImage);
   1832         }
   1833         rbData->sourceEGLImage = 0;
   1834         rbData->eglImageGlobalTexName = 0;
   1835     }
   1836 
   1837     ctx->dispatcher().glRenderbufferStorageEXT(target,internalformat,width,height);
   1838 }
   1839 
   1840 GL_API void GLAPIENTRY glGetRenderbufferParameterivOES(GLenum target, GLenum pname, GLint* params) {
   1841     GET_CTX()
   1842     SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION);
   1843     SET_ERROR_IF(!GLEScmValidate::renderbufferTarget(target) || !GLEScmValidate::renderbufferParams(pname) ,GL_INVALID_ENUM);
   1844 
   1845     //
   1846     // If this is a renderbuffer which is eglimage's target, we
   1847     // should query the underlying eglimage's texture object instead.
   1848     //
   1849     GLuint rb = ctx->getRenderbufferBinding();
   1850     if (rb) {
   1851         ObjectDataPtr objData = ctx->shareGroup()->getObjectData(RENDERBUFFER,rb);
   1852         RenderbufferData *rbData = (RenderbufferData *)objData.Ptr();
   1853         if (rbData && rbData->sourceEGLImage != 0) {
   1854             GLenum texPname;
   1855             switch(pname) {
   1856                 case GL_RENDERBUFFER_WIDTH_OES:
   1857                     texPname = GL_TEXTURE_WIDTH;
   1858                     break;
   1859                 case GL_RENDERBUFFER_HEIGHT_OES:
   1860                     texPname = GL_TEXTURE_HEIGHT;
   1861                     break;
   1862                 case GL_RENDERBUFFER_INTERNAL_FORMAT_OES:
   1863                     texPname = GL_TEXTURE_INTERNAL_FORMAT;
   1864                     break;
   1865                 case GL_RENDERBUFFER_RED_SIZE_OES:
   1866                     texPname = GL_TEXTURE_RED_SIZE;
   1867                     break;
   1868                 case GL_RENDERBUFFER_GREEN_SIZE_OES:
   1869                     texPname = GL_TEXTURE_GREEN_SIZE;
   1870                     break;
   1871                 case GL_RENDERBUFFER_BLUE_SIZE_OES:
   1872                     texPname = GL_TEXTURE_BLUE_SIZE;
   1873                     break;
   1874                 case GL_RENDERBUFFER_ALPHA_SIZE_OES:
   1875                     texPname = GL_TEXTURE_ALPHA_SIZE;
   1876                     break;
   1877                 case GL_RENDERBUFFER_DEPTH_SIZE_OES:
   1878                     texPname = GL_TEXTURE_DEPTH_SIZE;
   1879                     break;
   1880                 case GL_RENDERBUFFER_STENCIL_SIZE_OES:
   1881                 default:
   1882                     *params = 0; //XXX
   1883                     return;
   1884                     break;
   1885             }
   1886 
   1887             GLint prevTex;
   1888             ctx->dispatcher().glGetIntegerv(GL_TEXTURE_BINDING_2D, &prevTex);
   1889             ctx->dispatcher().glBindTexture(GL_TEXTURE_2D,
   1890                                             rbData->eglImageGlobalTexName);
   1891             ctx->dispatcher().glGetTexLevelParameteriv(GL_TEXTURE_2D, 0,
   1892                                                        texPname,
   1893                                                        params);
   1894             ctx->dispatcher().glBindTexture(GL_TEXTURE_2D, prevTex);
   1895             return;
   1896         }
   1897     }
   1898 
   1899     ctx->dispatcher().glGetRenderbufferParameterivEXT(target,pname,params);
   1900 }
   1901 
   1902 GL_API GLboolean GLAPIENTRY glIsFramebufferOES(GLuint framebuffer) {
   1903     GET_CTX_RET(GL_FALSE)
   1904     RET_AND_SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION,GL_FALSE);
   1905     if (framebuffer && ctx->shareGroup().Ptr()) {
   1906         return ctx->shareGroup()->isObject(FRAMEBUFFER,framebuffer) ? GL_TRUE : GL_FALSE;
   1907     }
   1908     return ctx->dispatcher().glIsFramebufferEXT(framebuffer);
   1909 }
   1910 
   1911 GL_API void GLAPIENTRY glBindFramebufferOES(GLenum target, GLuint framebuffer) {
   1912     GET_CTX()
   1913     SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION);
   1914     SET_ERROR_IF(!GLEScmValidate::framebufferTarget(target) ,GL_INVALID_ENUM);
   1915     if (framebuffer && ctx->shareGroup().Ptr() && !ctx->shareGroup()->isObject(FRAMEBUFFER,framebuffer)) {
   1916         ctx->shareGroup()->genName(FRAMEBUFFER,framebuffer);
   1917         ctx->shareGroup()->setObjectData(FRAMEBUFFER, framebuffer,
   1918                                          ObjectDataPtr(new FramebufferData(framebuffer)));
   1919     }
   1920     int globalBufferName = (framebuffer!=0) ? ctx->shareGroup()->getGlobalName(FRAMEBUFFER,framebuffer) : 0;
   1921     ctx->dispatcher().glBindFramebufferEXT(target,globalBufferName);
   1922 
   1923     // update framebuffer binding state
   1924     ctx->setFramebufferBinding(framebuffer);
   1925 }
   1926 
   1927 GL_API void GLAPIENTRY glDeleteFramebuffersOES(GLsizei n, const GLuint *framebuffers) {
   1928     GET_CTX()
   1929     SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION);
   1930     for (int i=0;i<n;++i) {
   1931         GLuint globalBufferName = ctx->shareGroup()->getGlobalName(FRAMEBUFFER,framebuffers[i]);
   1932         ctx->dispatcher().glDeleteFramebuffersEXT(1,&globalBufferName);
   1933     }
   1934 }
   1935 
   1936 GL_API void GLAPIENTRY glGenFramebuffersOES(GLsizei n, GLuint *framebuffers) {
   1937     GET_CTX()
   1938     SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION);
   1939     SET_ERROR_IF(n<0,GL_INVALID_VALUE);
   1940     if (ctx->shareGroup().Ptr()) {
   1941         for (int i=0;i<n;i++) {
   1942             framebuffers[i] = ctx->shareGroup()->genName(FRAMEBUFFER, 0, true);
   1943             ctx->shareGroup()->setObjectData(FRAMEBUFFER, framebuffers[i],
   1944                                              ObjectDataPtr(new FramebufferData(framebuffers[i])));
   1945         }
   1946     }
   1947 }
   1948 
   1949 GL_API GLenum GLAPIENTRY glCheckFramebufferStatusOES(GLenum target) {
   1950     GET_CTX_RET(0)
   1951     RET_AND_SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION,0);
   1952     RET_AND_SET_ERROR_IF(!GLEScmValidate::framebufferTarget(target) ,GL_INVALID_ENUM,0);
   1953     return ctx->dispatcher().glCheckFramebufferStatusEXT(target);
   1954 }
   1955 
   1956 GL_API void GLAPIENTRY glFramebufferTexture2DOES(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) {
   1957     GET_CTX()
   1958     SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION);
   1959     SET_ERROR_IF(!GLEScmValidate::framebufferTarget(target) || !GLEScmValidate::framebufferAttachment(attachment) ||
   1960                  !GLEScmValidate::textureTargetEx(textarget),GL_INVALID_ENUM);
   1961     SET_ERROR_IF(!ctx->shareGroup().Ptr(), GL_INVALID_OPERATION);
   1962 
   1963     GLuint globalTexName = 0;
   1964     if(texture) {
   1965         if (!ctx->shareGroup()->isObject(TEXTURE,texture)) {
   1966             ctx->shareGroup()->genName(TEXTURE,texture);
   1967         }
   1968         ObjectLocalName texname = TextureLocalName(textarget,texture);
   1969         globalTexName = ctx->shareGroup()->getGlobalName(TEXTURE,texname);
   1970     }
   1971 
   1972     ctx->dispatcher().glFramebufferTexture2DEXT(target,attachment,textarget,globalTexName,level);
   1973 
   1974     // Update the the current framebuffer object attachment state
   1975     GLuint fbName = ctx->getFramebufferBinding();
   1976     ObjectDataPtr fbObj = ctx->shareGroup()->getObjectData(FRAMEBUFFER,fbName);
   1977     if (fbObj.Ptr() != NULL) {
   1978         FramebufferData *fbData = (FramebufferData *)fbObj.Ptr();
   1979         fbData->setAttachment(attachment, textarget,
   1980                               texture, ObjectDataPtr(NULL));
   1981     }
   1982 }
   1983 
   1984 GL_API void GLAPIENTRY glFramebufferRenderbufferOES(GLenum target, GLenum attachment,GLenum renderbuffertarget, GLuint renderbuffer) {
   1985     GET_CTX()
   1986     SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION);
   1987     SET_ERROR_IF(!GLEScmValidate::framebufferTarget(target) ||
   1988                  !GLEScmValidate::framebufferAttachment(attachment) ||
   1989                  !GLEScmValidate::renderbufferTarget(renderbuffertarget), GL_INVALID_ENUM);
   1990 
   1991     SET_ERROR_IF(!ctx->shareGroup().Ptr(), GL_INVALID_OPERATION);
   1992 
   1993     GLuint globalBufferName = 0;
   1994     ObjectDataPtr obj;
   1995 
   1996     // generate the renderbuffer object if not yet exist
   1997     if (renderbuffer) {
   1998         if (!ctx->shareGroup()->isObject(RENDERBUFFER,renderbuffer)) {
   1999             ctx->shareGroup()->genName(RENDERBUFFER,renderbuffer);
   2000             obj = ObjectDataPtr(new RenderbufferData());
   2001             ctx->shareGroup()->setObjectData(RENDERBUFFER,
   2002                                          renderbuffer,
   2003                                          ObjectDataPtr(new RenderbufferData()));
   2004         }
   2005         else {
   2006             obj = ctx->shareGroup()->getObjectData(RENDERBUFFER,renderbuffer);
   2007         }
   2008         globalBufferName = ctx->shareGroup()->getGlobalName(RENDERBUFFER,renderbuffer);
   2009     }
   2010 
   2011     // Update the the current framebuffer object attachment state
   2012     GLuint fbName = ctx->getFramebufferBinding();
   2013     ObjectDataPtr fbObj = ctx->shareGroup()->getObjectData(FRAMEBUFFER,fbName);
   2014     if (fbObj.Ptr() != NULL) {
   2015         FramebufferData *fbData = (FramebufferData *)fbObj.Ptr();
   2016         fbData->setAttachment(attachment, renderbuffertarget, renderbuffer, obj);
   2017     }
   2018 
   2019     if (renderbuffer && obj.Ptr() != NULL) {
   2020         RenderbufferData *rbData = (RenderbufferData *)obj.Ptr();
   2021         if (rbData->sourceEGLImage != 0) {
   2022             //
   2023             // This renderbuffer object is an eglImage target
   2024             // attach the eglimage's texture instead the renderbuffer.
   2025             //
   2026             ctx->dispatcher().glFramebufferTexture2DEXT(target,
   2027                                                     attachment,
   2028                                                     GL_TEXTURE_2D,
   2029                                                     rbData->eglImageGlobalTexName,0);
   2030             return;
   2031         }
   2032     }
   2033 
   2034     ctx->dispatcher().glFramebufferRenderbufferEXT(target,attachment,renderbuffertarget,globalBufferName);
   2035 }
   2036 
   2037 GL_API void GLAPIENTRY glGetFramebufferAttachmentParameterivOES(GLenum target, GLenum attachment, GLenum pname, GLint *params) {
   2038     GET_CTX()
   2039     SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION);
   2040     SET_ERROR_IF(!GLEScmValidate::framebufferTarget(target) || !GLEScmValidate::framebufferAttachment(attachment) ||
   2041                  !GLEScmValidate::framebufferAttachmentParams(pname), GL_INVALID_ENUM);
   2042 
   2043     //
   2044     // Take the attachment attribute from our state - if available
   2045     //
   2046     GLuint fbName = ctx->getFramebufferBinding();
   2047     if (fbName) {
   2048         ObjectDataPtr fbObj = ctx->shareGroup()->getObjectData(FRAMEBUFFER,fbName);
   2049         if (fbObj.Ptr() != NULL) {
   2050             FramebufferData *fbData = (FramebufferData *)fbObj.Ptr();
   2051             GLenum target;
   2052             GLuint name = fbData->getAttachment(attachment, &target, NULL);
   2053             if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_OES) {
   2054                 *params = target;
   2055                 return;
   2056             }
   2057             else if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_OES) {
   2058                 *params = name;
   2059                 return;
   2060             }
   2061         }
   2062     }
   2063 
   2064     ctx->dispatcher().glGetFramebufferAttachmentParameterivEXT(target,attachment,pname,params);
   2065 }
   2066 
   2067 GL_API void GL_APIENTRY glGenerateMipmapOES(GLenum target) {
   2068     GET_CTX()
   2069     SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION);
   2070     SET_ERROR_IF(!GLEScmValidate::textureTargetLimited(target),GL_INVALID_ENUM);
   2071     ctx->dispatcher().glGenerateMipmapEXT(target);
   2072 }
   2073 
   2074 GL_API void GL_APIENTRY glCurrentPaletteMatrixOES(GLuint index) {
   2075     GET_CTX()
   2076     SET_ERROR_IF(!(ctx->getCaps()->GL_ARB_MATRIX_PALETTE && ctx->getCaps()->GL_ARB_VERTEX_BLEND),GL_INVALID_OPERATION);
   2077     ctx->dispatcher().glCurrentPaletteMatrixARB(index);
   2078 }
   2079 
   2080 GL_API void GL_APIENTRY glLoadPaletteFromModelViewMatrixOES() {
   2081     GET_CTX()
   2082     SET_ERROR_IF(!(ctx->getCaps()->GL_ARB_MATRIX_PALETTE && ctx->getCaps()->GL_ARB_VERTEX_BLEND),GL_INVALID_OPERATION);
   2083     GLint matrix[16];
   2084     ctx->dispatcher().glGetIntegerv(GL_MODELVIEW_MATRIX,matrix);
   2085     ctx->dispatcher().glMatrixIndexuivARB(1,(GLuint*)matrix);
   2086 
   2087 }
   2088 
   2089 GL_API void GL_APIENTRY glMatrixIndexPointerOES(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) {
   2090     GET_CTX()
   2091     SET_ERROR_IF(!(ctx->getCaps()->GL_ARB_MATRIX_PALETTE && ctx->getCaps()->GL_ARB_VERTEX_BLEND),GL_INVALID_OPERATION);
   2092     ctx->dispatcher().glMatrixIndexPointerARB(size,type,stride,pointer);
   2093 }
   2094 
   2095 GL_API void GL_APIENTRY glWeightPointerOES(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) {
   2096     GET_CTX()
   2097     SET_ERROR_IF(!(ctx->getCaps()->GL_ARB_MATRIX_PALETTE && ctx->getCaps()->GL_ARB_VERTEX_BLEND),GL_INVALID_OPERATION);
   2098     ctx->dispatcher().glWeightPointerARB(size,type,stride,pointer);
   2099 
   2100 }
   2101 
   2102 GL_API void GL_APIENTRY glTexGenfOES (GLenum coord, GLenum pname, GLfloat param) {
   2103     GET_CTX()
   2104     SET_ERROR_IF(!GLEScmValidate::texGen(coord,pname),GL_INVALID_ENUM);
   2105     if (coord == GL_TEXTURE_GEN_STR_OES) {
   2106         ctx->dispatcher().glTexGenf(GL_S,pname,param);
   2107         ctx->dispatcher().glTexGenf(GL_T,pname,param);
   2108         ctx->dispatcher().glTexGenf(GL_R,pname,param);
   2109     }
   2110     else
   2111         ctx->dispatcher().glTexGenf(coord,pname,param);
   2112 }
   2113 
   2114 GL_API void GL_APIENTRY glTexGenfvOES (GLenum coord, GLenum pname, const GLfloat *params) {
   2115     GET_CTX()
   2116     SET_ERROR_IF(!GLEScmValidate::texGen(coord,pname),GL_INVALID_ENUM);
   2117     if (coord == GL_TEXTURE_GEN_STR_OES) {
   2118         ctx->dispatcher().glTexGenfv(GL_S,pname,params);
   2119         ctx->dispatcher().glTexGenfv(GL_T,pname,params);
   2120         ctx->dispatcher().glTexGenfv(GL_R,pname,params);
   2121     }
   2122     else
   2123         ctx->dispatcher().glTexGenfv(coord,pname,params);
   2124 }
   2125 GL_API void GL_APIENTRY glTexGeniOES (GLenum coord, GLenum pname, GLint param) {
   2126     GET_CTX()
   2127     SET_ERROR_IF(!GLEScmValidate::texGen(coord,pname),GL_INVALID_ENUM);
   2128     if (coord == GL_TEXTURE_GEN_STR_OES) {
   2129         ctx->dispatcher().glTexGeni(GL_S,pname,param);
   2130         ctx->dispatcher().glTexGeni(GL_T,pname,param);
   2131         ctx->dispatcher().glTexGeni(GL_R,pname,param);
   2132     }
   2133     else
   2134         ctx->dispatcher().glTexGeni(coord,pname,param);
   2135 }
   2136 GL_API void GL_APIENTRY glTexGenivOES (GLenum coord, GLenum pname, const GLint *params) {
   2137     GET_CTX()
   2138     SET_ERROR_IF(!GLEScmValidate::texGen(coord,pname),GL_INVALID_ENUM);
   2139     if (coord == GL_TEXTURE_GEN_STR_OES) {
   2140         ctx->dispatcher().glTexGeniv(GL_S,pname,params);
   2141         ctx->dispatcher().glTexGeniv(GL_T,pname,params);
   2142         ctx->dispatcher().glTexGeniv(GL_R,pname,params);
   2143     }
   2144     else
   2145         ctx->dispatcher().glTexGeniv(coord,pname,params);
   2146 }
   2147 GL_API void GL_APIENTRY glTexGenxOES (GLenum coord, GLenum pname, GLfixed param) {
   2148     GET_CTX()
   2149     SET_ERROR_IF(!GLEScmValidate::texGen(coord,pname),GL_INVALID_ENUM);
   2150     if (coord == GL_TEXTURE_GEN_STR_OES) {
   2151         ctx->dispatcher().glTexGenf(GL_S,pname,X2F(param));
   2152         ctx->dispatcher().glTexGenf(GL_T,pname,X2F(param));
   2153         ctx->dispatcher().glTexGenf(GL_R,pname,X2F(param));
   2154     }
   2155     else
   2156         ctx->dispatcher().glTexGenf(coord,pname,X2F(param));
   2157 }
   2158 GL_API void GL_APIENTRY glTexGenxvOES (GLenum coord, GLenum pname, const GLfixed *params) {
   2159     GLfloat tmpParams[1];
   2160     GET_CTX()
   2161     SET_ERROR_IF(!GLEScmValidate::texGen(coord,pname),GL_INVALID_ENUM);
   2162     tmpParams[0] = X2F(params[0]);
   2163     if (coord == GL_TEXTURE_GEN_STR_OES) {
   2164         ctx->dispatcher().glTexGenfv(GL_S,pname,tmpParams);
   2165         ctx->dispatcher().glTexGenfv(GL_T,pname,tmpParams);
   2166         ctx->dispatcher().glTexGenfv(GL_R,pname,tmpParams);
   2167     }
   2168     else
   2169         ctx->dispatcher().glTexGenfv(coord,pname,tmpParams);
   2170 }
   2171 
   2172 GL_API void GL_APIENTRY glGetTexGenfvOES (GLenum coord, GLenum pname, GLfloat *params) {
   2173     GET_CTX()
   2174     if (coord == GL_TEXTURE_GEN_STR_OES)
   2175     {
   2176         GLfloat state_s = GL_FALSE;
   2177         GLfloat state_t = GL_FALSE;
   2178         GLfloat state_r = GL_FALSE;
   2179         ctx->dispatcher().glGetTexGenfv(GL_S,pname,&state_s);
   2180         ctx->dispatcher().glGetTexGenfv(GL_T,pname,&state_t);
   2181         ctx->dispatcher().glGetTexGenfv(GL_R,pname,&state_r);
   2182         *params = state_s && state_t && state_r ? GL_TRUE: GL_FALSE;
   2183     }
   2184     else
   2185         ctx->dispatcher().glGetTexGenfv(coord,pname,params);
   2186 
   2187 }
   2188 GL_API void GL_APIENTRY glGetTexGenivOES (GLenum coord, GLenum pname, GLint *params) {
   2189     GET_CTX()
   2190     if (coord == GL_TEXTURE_GEN_STR_OES)
   2191     {
   2192         GLint state_s = GL_FALSE;
   2193         GLint state_t = GL_FALSE;
   2194         GLint state_r = GL_FALSE;
   2195         ctx->dispatcher().glGetTexGeniv(GL_S,pname,&state_s);
   2196         ctx->dispatcher().glGetTexGeniv(GL_T,pname,&state_t);
   2197         ctx->dispatcher().glGetTexGeniv(GL_R,pname,&state_r);
   2198         *params = state_s && state_t && state_r ? GL_TRUE: GL_FALSE;
   2199     }
   2200     else
   2201         ctx->dispatcher().glGetTexGeniv(coord,pname,params);
   2202 }
   2203 
   2204 GL_API void GL_APIENTRY glGetTexGenxvOES (GLenum coord, GLenum pname, GLfixed *params) {
   2205     GET_CTX()
   2206     GLfloat tmpParams[1];
   2207 
   2208     if (coord == GL_TEXTURE_GEN_STR_OES)
   2209     {
   2210         GLfloat state_s = GL_FALSE;
   2211         GLfloat state_t = GL_FALSE;
   2212         GLfloat state_r = GL_FALSE;
   2213         ctx->dispatcher().glGetTexGenfv(GL_TEXTURE_GEN_S,pname,&state_s);
   2214         ctx->dispatcher().glGetTexGenfv(GL_TEXTURE_GEN_T,pname,&state_t);
   2215         ctx->dispatcher().glGetTexGenfv(GL_TEXTURE_GEN_R,pname,&state_r);
   2216         tmpParams[0] = state_s && state_t && state_r ? GL_TRUE: GL_FALSE;
   2217     }
   2218     else
   2219         ctx->dispatcher().glGetTexGenfv(coord,pname,tmpParams);
   2220 
   2221     params[0] = F2X(tmpParams[1]);
   2222 }
   2223 
   2224 template <class T, GLenum TypeName>
   2225 void glDrawTexOES (T x, T y, T z, T width, T height) {
   2226     GET_CTX()
   2227 
   2228     SET_ERROR_IF((width<=0 || height<=0),GL_INVALID_VALUE);
   2229 
   2230     ctx->drawValidate();
   2231 
   2232     int numClipPlanes;
   2233 
   2234     GLint viewport[4];
   2235     z = (z>1 ? 1 : (z<0 ?  0 : z));
   2236 
   2237     T     vertices[4*3] = {x , y, z,
   2238                              x , y+height, z,
   2239                              x+width, y+height, z,
   2240                              x+width, y, z};
   2241     GLfloat texels[ctx->getMaxTexUnits()][4*2];
   2242     memset((void*)texels, 0, ctx->getMaxTexUnits()*4*2*sizeof(GLfloat));
   2243 
   2244     ctx->dispatcher().glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
   2245     ctx->dispatcher().glPushAttrib(GL_TRANSFORM_BIT);
   2246 
   2247     //setup projection matrix to draw in viewport aligned coordinates
   2248     ctx->dispatcher().glMatrixMode(GL_PROJECTION);
   2249     ctx->dispatcher().glPushMatrix();
   2250     ctx->dispatcher().glLoadIdentity();
   2251     ctx->dispatcher().glGetIntegerv(GL_VIEWPORT,viewport);
   2252     ctx->dispatcher().glOrtho(viewport[0],viewport[0] + viewport[2],viewport[1],viewport[1]+viewport[3],0,-1);
   2253     //setup texture matrix
   2254     ctx->dispatcher().glMatrixMode(GL_TEXTURE);
   2255     ctx->dispatcher().glPushMatrix();
   2256     ctx->dispatcher().glLoadIdentity();
   2257     //setup modelview matrix
   2258     ctx->dispatcher().glMatrixMode(GL_MODELVIEW);
   2259     ctx->dispatcher().glPushMatrix();
   2260     ctx->dispatcher().glLoadIdentity();
   2261     //backup vbo's
   2262     int array_buffer,element_array_buffer;
   2263     glGetIntegerv(GL_ARRAY_BUFFER_BINDING,&array_buffer);
   2264     glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING,&element_array_buffer);
   2265     ctx->dispatcher().glBindBuffer(GL_ARRAY_BUFFER,0);
   2266     ctx->dispatcher().glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
   2267 
   2268     //disable clip planes
   2269     ctx->dispatcher().glGetIntegerv(GL_MAX_CLIP_PLANES,&numClipPlanes);
   2270     for (int i=0;i<numClipPlanes;++i)
   2271         ctx->dispatcher().glDisable(GL_CLIP_PLANE0+i);
   2272 
   2273     int nTexPtrs = 0;
   2274     for (int i=0;i<ctx->getMaxTexUnits();++i) {
   2275         if (ctx->isTextureUnitEnabled(GL_TEXTURE0+i)) {
   2276             TextureData * texData = NULL;
   2277             unsigned int texname = ctx->getBindedTexture(GL_TEXTURE0+i,GL_TEXTURE_2D);
   2278             ObjectLocalName tex = TextureLocalName(GL_TEXTURE_2D,texname);
   2279             ctx->dispatcher().glClientActiveTexture(GL_TEXTURE0+i);
   2280             ObjectDataPtr objData = ctx->shareGroup()->getObjectData(TEXTURE,tex);
   2281             if (objData.Ptr()) {
   2282                 texData = (TextureData*)objData.Ptr();
   2283                 //calculate texels
   2284                 texels[i][0] = (float)(texData->crop_rect[0])/(float)(texData->width);
   2285                 texels[i][1] = (float)(texData->crop_rect[1])/(float)(texData->height);
   2286 
   2287                 texels[i][2] = (float)(texData->crop_rect[0])/(float)(texData->width);
   2288                 texels[i][3] = (float)(texData->crop_rect[3]+texData->crop_rect[1])/(float)(texData->height);
   2289 
   2290                 texels[i][4] = (float)(texData->crop_rect[2]+texData->crop_rect[0])/(float)(texData->width);
   2291                 texels[i][5] = (float)(texData->crop_rect[3]+texData->crop_rect[1])/(float)(texData->height);
   2292 
   2293                 texels[i][6] = (float)(texData->crop_rect[2]+texData->crop_rect[0])/(float)(texData->width);
   2294                 texels[i][7] = (float)(texData->crop_rect[1])/(float)(texData->height);
   2295 
   2296                 ctx->dispatcher().glTexCoordPointer(2,GL_FLOAT,0,texels[i]);
   2297                 nTexPtrs++;
   2298              }
   2299         }
   2300     }
   2301 
   2302     if (nTexPtrs>0) {
   2303         //draw rectangle - only if we have some textures enabled & ready
   2304         ctx->dispatcher().glEnableClientState(GL_VERTEX_ARRAY);
   2305         ctx->dispatcher().glVertexPointer(3,TypeName,0,vertices);
   2306         ctx->dispatcher().glEnableClientState(GL_TEXTURE_COORD_ARRAY);
   2307         ctx->dispatcher().glDrawArrays(GL_TRIANGLE_FAN,0,4);
   2308     }
   2309 
   2310     //restore vbo's
   2311     ctx->dispatcher().glBindBuffer(GL_ARRAY_BUFFER,array_buffer);
   2312     ctx->dispatcher().glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,element_array_buffer);
   2313 
   2314     //restore matrix state
   2315 
   2316     ctx->dispatcher().glMatrixMode(GL_MODELVIEW);
   2317     ctx->dispatcher().glPopMatrix();
   2318     ctx->dispatcher().glMatrixMode(GL_TEXTURE);
   2319     ctx->dispatcher().glPopMatrix();
   2320     ctx->dispatcher().glMatrixMode(GL_PROJECTION);
   2321     ctx->dispatcher().glPopMatrix();
   2322 
   2323     ctx->dispatcher().glPopAttrib();
   2324     ctx->dispatcher().glPopClientAttrib();
   2325 }
   2326 
   2327 GL_API void GL_APIENTRY glDrawTexsOES (GLshort x, GLshort y, GLshort z, GLshort width, GLshort height) {
   2328     glDrawTexOES<GLshort,GL_SHORT>(x,y,z,width,height);
   2329 }
   2330 
   2331 GL_API void GL_APIENTRY glDrawTexiOES (GLint x, GLint y, GLint z, GLint width, GLint height) {
   2332     glDrawTexOES<GLint,GL_INT>(x,y,z,width,height);
   2333 }
   2334 
   2335 GL_API void GL_APIENTRY glDrawTexfOES (GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height) {
   2336     glDrawTexOES<GLfloat,GL_FLOAT>(x,y,z,width,height);
   2337 }
   2338 
   2339 GL_API void GL_APIENTRY glDrawTexxOES (GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height) {
   2340     glDrawTexOES<GLfloat,GL_FLOAT>(X2F(x),X2F(y),X2F(z),X2F(width),X2F(height));
   2341 }
   2342 
   2343 GL_API void GL_APIENTRY glDrawTexsvOES (const GLshort * coords) {
   2344     glDrawTexOES<GLshort,GL_SHORT>(coords[0],coords[1],coords[2],coords[3],coords[4]);
   2345 }
   2346 
   2347 GL_API void GL_APIENTRY glDrawTexivOES (const GLint * coords) {
   2348     glDrawTexOES<GLint,GL_INT>(coords[0],coords[1],coords[2],coords[3],coords[4]);
   2349 }
   2350 
   2351 GL_API void GL_APIENTRY glDrawTexfvOES (const GLfloat * coords) {
   2352     glDrawTexOES<GLfloat,GL_FLOAT>(coords[0],coords[1],coords[2],coords[3],coords[4]);
   2353 }
   2354 
   2355 GL_API void GL_APIENTRY glDrawTexxvOES (const GLfixed * coords) {
   2356     glDrawTexOES<GLfloat,GL_FLOAT>(X2F(coords[0]),X2F(coords[1]),X2F(coords[2]),X2F(coords[3]),X2F(coords[4]));
   2357 }
   2358