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 + SafeUIntFromPointer(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 switch(pname) 703 { 704 case GL_FRAMEBUFFER_BINDING_OES: 705 case GL_RENDERBUFFER_BINDING_OES: 706 { 707 GLint name; 708 glGetIntegerv(pname,&name); 709 *params = name!=0 ? GL_TRUE: GL_FALSE; 710 } 711 break; 712 case GL_TEXTURE_GEN_STR_OES: 713 { 714 GLboolean state_s = GL_FALSE; 715 GLboolean state_t = GL_FALSE; 716 GLboolean state_r = GL_FALSE; 717 ctx->dispatcher().glGetBooleanv(GL_TEXTURE_GEN_S,&state_s); 718 ctx->dispatcher().glGetBooleanv(GL_TEXTURE_GEN_T,&state_t); 719 ctx->dispatcher().glGetBooleanv(GL_TEXTURE_GEN_R,&state_r); 720 *params = state_s && state_t && state_r ? GL_TRUE: GL_FALSE; 721 } 722 break; 723 case GL_NUM_COMPRESSED_TEXTURE_FORMATS: 724 *params = (GLboolean)getCompressedFormats(NULL); 725 break; 726 case GL_COMPRESSED_TEXTURE_FORMATS: 727 { 728 int nparams = getCompressedFormats(NULL); 729 if (nparams>0) { 730 int * iparams = new int[nparams]; 731 getCompressedFormats(iparams); 732 for (int i=0; i<nparams; i++) params[i] = (GLboolean)iparams[i]; 733 delete [] iparams; 734 } 735 } 736 break; 737 default: 738 ctx->dispatcher().glGetBooleanv(pname,params); 739 } 740 } 741 742 GL_API void GL_APIENTRY glGetBufferParameteriv( GLenum target, GLenum pname, GLint *params) { 743 GET_CTX() 744 SET_ERROR_IF(!(GLEScmValidate::bufferTarget(target) && GLEScmValidate::bufferParam(pname)),GL_INVALID_ENUM); 745 SET_ERROR_IF(!ctx->isBindedBuffer(target),GL_INVALID_OPERATION); 746 switch(pname) { 747 case GL_BUFFER_SIZE: 748 ctx->getBufferSize(target,params); 749 break; 750 case GL_BUFFER_USAGE: 751 ctx->getBufferUsage(target,params); 752 break; 753 } 754 755 } 756 757 GL_API void GL_APIENTRY glGetClipPlanef( GLenum pname, GLfloat eqn[4]) { 758 GET_CTX() 759 GLdouble tmpEqn[4]; 760 761 ctx->dispatcher().glGetClipPlane(pname,tmpEqn); 762 for(int i =0 ;i < 4; i++){ 763 eqn[i] = static_cast<GLfloat>(tmpEqn[i]); 764 } 765 } 766 767 GL_API void GL_APIENTRY glGetClipPlanex( GLenum pname, GLfixed eqn[4]) { 768 GET_CTX() 769 GLdouble tmpEqn[4]; 770 771 ctx->dispatcher().glGetClipPlane(pname,tmpEqn); 772 for(int i =0 ;i < 4; i++){ 773 eqn[i] = F2X(tmpEqn[i]); 774 } 775 } 776 777 GL_API void GL_APIENTRY glGetFixedv( GLenum pname, GLfixed *params) { 778 GET_CTX() 779 780 if(ctx->glGetFixedv(pname, params)) 781 { 782 return; 783 } 784 785 size_t nParams = glParamSize(pname); 786 GLfloat fParams[16]; 787 788 switch(pname) 789 { 790 case GL_FRAMEBUFFER_BINDING_OES: 791 case GL_RENDERBUFFER_BINDING_OES: 792 case GL_TEXTURE_GEN_STR_OES: 793 glGetFloatv(pname,&fParams[0]); 794 break; 795 case GL_NUM_COMPRESSED_TEXTURE_FORMATS: 796 *params = I2X(getCompressedFormats(NULL)); 797 return; 798 break; 799 case GL_COMPRESSED_TEXTURE_FORMATS: 800 { 801 int nparams = getCompressedFormats(NULL); 802 if (nparams>0) { 803 int * iparams = new int[nparams]; 804 getCompressedFormats(iparams); 805 for (int i=0; i<nparams; i++) params[i] = I2X(iparams[i]); 806 delete [] iparams; 807 } 808 return; 809 } 810 break; 811 default: 812 ctx->dispatcher().glGetFloatv(pname,fParams); 813 } 814 815 if (nParams) 816 { 817 for(size_t i =0 ; i < nParams;i++) { 818 params[i] = F2X(fParams[i]); 819 } 820 } 821 } 822 823 GL_API void GL_APIENTRY glGetFloatv( GLenum pname, GLfloat *params) { 824 GET_CTX() 825 826 if(ctx->glGetFloatv(pname, params)) 827 { 828 return; 829 } 830 831 GLint i; 832 833 switch (pname) { 834 case GL_FRAMEBUFFER_BINDING_OES: 835 case GL_RENDERBUFFER_BINDING_OES: 836 case GL_TEXTURE_GEN_STR_OES: 837 glGetIntegerv(pname,&i); 838 *params = (GLfloat)i; 839 break; 840 case GL_NUM_COMPRESSED_TEXTURE_FORMATS: 841 *params = (GLfloat)getCompressedFormats(NULL); 842 break; 843 case GL_COMPRESSED_TEXTURE_FORMATS: 844 { 845 int nparams = getCompressedFormats(NULL); 846 if (nparams>0) { 847 int * iparams = new int[nparams]; 848 getCompressedFormats(iparams); 849 for (int i=0; i<nparams; i++) params[i] = (GLfloat)iparams[i]; 850 delete [] iparams; 851 } 852 } 853 break; 854 default: 855 ctx->dispatcher().glGetFloatv(pname,params); 856 } 857 } 858 859 GL_API void GL_APIENTRY glGetIntegerv( GLenum pname, GLint *params) { 860 GET_CTX() 861 862 if(ctx->glGetIntegerv(pname, params)) 863 { 864 return; 865 } 866 867 GLint i; 868 GLfloat f; 869 870 switch(pname) 871 { 872 case GL_TEXTURE_GEN_STR_OES: 873 ctx->dispatcher().glGetIntegerv(GL_TEXTURE_GEN_S,¶ms[0]); 874 break; 875 case GL_FRAMEBUFFER_BINDING_OES: 876 if (ctx->shareGroup().Ptr()) { 877 ctx->dispatcher().glGetIntegerv(pname,&i); 878 *params = ctx->shareGroup()->getLocalName(FRAMEBUFFER,i); 879 } 880 break; 881 case GL_RENDERBUFFER_BINDING_OES: 882 if (ctx->shareGroup().Ptr()) { 883 ctx->dispatcher().glGetIntegerv(pname,&i); 884 *params = ctx->shareGroup()->getLocalName(RENDERBUFFER,i); 885 } 886 break; 887 case GL_NUM_COMPRESSED_TEXTURE_FORMATS: 888 *params = getCompressedFormats(NULL); 889 break; 890 case GL_COMPRESSED_TEXTURE_FORMATS: 891 getCompressedFormats(params); 892 break; 893 case GL_MAX_CLIP_PLANES: 894 ctx->dispatcher().glGetIntegerv(pname,params); 895 if(*params > 6) 896 { 897 // GLES spec requires only 6, and the ATI driver erronously 898 // returns 8 (although it supports only 6). This WAR is simple, 899 // compliant and good enough for developers. 900 *params = 6; 901 } 902 break; 903 case GL_ALPHA_TEST_REF: 904 // Both the ATI and nVidia OpenGL drivers return the wrong answer 905 // here. So return the right one. 906 ctx->dispatcher().glGetFloatv(pname,&f); 907 *params = (int)(f * (float)0x7fffffff); 908 break; 909 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: 910 ctx->dispatcher().glGetIntegerv(pname,params); 911 if(*params > 16) 912 { 913 // GLES spec requires only 2, and the ATI driver erronously 914 // returns 32 (although it supports only 16). This WAR is simple, 915 // compliant and good enough for developers. 916 *params = 16; 917 } 918 break; 919 920 default: 921 ctx->dispatcher().glGetIntegerv(pname,params); 922 } 923 } 924 925 GL_API void GL_APIENTRY glGetLightfv( GLenum light, GLenum pname, GLfloat *params) { 926 GET_CTX() 927 ctx->dispatcher().glGetLightfv(light,pname,params); 928 } 929 930 GL_API void GL_APIENTRY glGetLightxv( GLenum light, GLenum pname, GLfixed *params) { 931 GET_CTX() 932 GLfloat tmpParams[4]; 933 934 ctx->dispatcher().glGetLightfv(light,pname,tmpParams); 935 switch (pname){ 936 case GL_AMBIENT: 937 case GL_DIFFUSE: 938 case GL_SPECULAR: 939 case GL_POSITION: 940 params[3] = F2X(tmpParams[3]); 941 case GL_SPOT_DIRECTION: 942 params[2] = F2X(tmpParams[2]); 943 case GL_SPOT_EXPONENT: 944 case GL_SPOT_CUTOFF: 945 case GL_CONSTANT_ATTENUATION: 946 case GL_LINEAR_ATTENUATION: 947 case GL_QUADRATIC_ATTENUATION: 948 params[1] = F2X(tmpParams[1]); 949 break; 950 default:{ 951 ctx->setGLerror(GL_INVALID_ENUM); 952 return; 953 } 954 955 } 956 params[0] = F2X(tmpParams[0]); 957 } 958 959 GL_API void GL_APIENTRY glGetMaterialfv( GLenum face, GLenum pname, GLfloat *params) { 960 GET_CTX() 961 ctx->dispatcher().glGetMaterialfv(face,pname,params); 962 } 963 964 GL_API void GL_APIENTRY glGetMaterialxv( GLenum face, GLenum pname, GLfixed *params) { 965 GET_CTX() 966 GLfloat tmpParams[4]; 967 ctx->dispatcher().glGetMaterialfv(face,pname,tmpParams); 968 switch(pname){ 969 case GL_AMBIENT: 970 case GL_DIFFUSE: 971 case GL_SPECULAR: 972 case GL_EMISSION: 973 case GL_AMBIENT_AND_DIFFUSE: 974 params[3] = tmpParams[3]; 975 params[2] = tmpParams[2]; 976 params[1] = tmpParams[1]; 977 case GL_SHININESS: 978 params[0] = tmpParams[0]; 979 break; 980 default:{ 981 ctx->setGLerror(GL_INVALID_ENUM); 982 return; 983 } 984 } 985 } 986 987 GL_API void GL_APIENTRY glGetPointerv( GLenum pname, void **params) { 988 GET_CTX() 989 const GLESpointer* p = ctx->getPointer(pname); 990 if(p) { 991 if(p->isVBO()) 992 { 993 *params = SafePointerFromUInt(p->getBufferOffset()); 994 }else{ 995 *params = const_cast<void *>(p->getArrayData()); 996 } 997 } else { 998 ctx->setGLerror(GL_INVALID_ENUM); 999 } 1000 1001 } 1002 1003 GL_API void GL_APIENTRY glGetTexEnvfv( GLenum env, GLenum pname, GLfloat *params) { 1004 GET_CTX() 1005 ctx->dispatcher().glGetTexEnvfv(env,pname,params); 1006 } 1007 1008 GL_API void GL_APIENTRY glGetTexEnviv( GLenum env, GLenum pname, GLint *params) { 1009 GET_CTX() 1010 ctx->dispatcher().glGetTexEnviv(env,pname,params); 1011 } 1012 1013 GL_API void GL_APIENTRY glGetTexEnvxv( GLenum env, GLenum pname, GLfixed *params) { 1014 GET_CTX() 1015 GLfloat tmpParams[4]; 1016 1017 ctx->dispatcher().glGetTexEnvfv(env,pname,tmpParams); 1018 if(pname == GL_TEXTURE_ENV_MODE) { 1019 params[0] = static_cast<GLfixed>(tmpParams[0]); 1020 } else { 1021 for(int i=0 ; i < 4 ; i++) 1022 params[i] = F2X(tmpParams[i]); 1023 } 1024 } 1025 1026 GL_API void GL_APIENTRY glGetTexParameterfv( GLenum target, GLenum pname, GLfloat *params) { 1027 GET_CTX() 1028 if (pname==GL_TEXTURE_CROP_RECT_OES) { 1029 TextureData *texData = getTextureTargetData(target); 1030 SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION); 1031 for (int i=0;i<4;++i) 1032 params[i] = texData->crop_rect[i]; 1033 } 1034 else { 1035 ctx->dispatcher().glGetTexParameterfv(target,pname,params); 1036 } 1037 } 1038 1039 GL_API void GL_APIENTRY glGetTexParameteriv( GLenum target, GLenum pname, GLint *params) { 1040 GET_CTX() 1041 if (pname==GL_TEXTURE_CROP_RECT_OES) { 1042 TextureData *texData = getTextureTargetData(target); 1043 SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION); 1044 for (int i=0;i<4;++i) 1045 params[i] = texData->crop_rect[i]; 1046 } 1047 else { 1048 ctx->dispatcher().glGetTexParameteriv(target,pname,params); 1049 } 1050 } 1051 1052 GL_API void GL_APIENTRY glGetTexParameterxv( GLenum target, GLenum pname, GLfixed *params) { 1053 GET_CTX() 1054 if (pname==GL_TEXTURE_CROP_RECT_OES) { 1055 TextureData *texData = getTextureTargetData(target); 1056 SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION); 1057 for (int i=0;i<4;++i) 1058 params[i] = F2X(texData->crop_rect[i]); 1059 } 1060 else { 1061 GLfloat tmpParam; 1062 ctx->dispatcher().glGetTexParameterfv(target,pname,&tmpParam); 1063 params[0] = static_cast<GLfixed>(tmpParam); 1064 } 1065 } 1066 1067 GL_API void GL_APIENTRY glHint( GLenum target, GLenum mode) { 1068 GET_CTX() 1069 SET_ERROR_IF(!GLEScmValidate::hintTargetMode(target,mode),GL_INVALID_ENUM); 1070 ctx->dispatcher().glHint(target,mode); 1071 } 1072 1073 GL_API void GL_APIENTRY glLightModelf( GLenum pname, GLfloat param) { 1074 GET_CTX() 1075 ctx->dispatcher().glLightModelf(pname,param); 1076 } 1077 1078 GL_API void GL_APIENTRY glLightModelfv( GLenum pname, const GLfloat *params) { 1079 GET_CTX() 1080 ctx->dispatcher().glLightModelfv(pname,params); 1081 } 1082 1083 GL_API void GL_APIENTRY glLightModelx( GLenum pname, GLfixed param) { 1084 GET_CTX() 1085 GLfloat tmpParam = static_cast<GLfloat>(param); 1086 ctx->dispatcher().glLightModelf(pname,tmpParam); 1087 } 1088 1089 GL_API void GL_APIENTRY glLightModelxv( GLenum pname, const GLfixed *params) { 1090 GET_CTX() 1091 GLfloat tmpParams[4]; 1092 if(pname == GL_LIGHT_MODEL_TWO_SIDE) { 1093 tmpParams[0] = X2F(params[0]); 1094 } else if (pname == GL_LIGHT_MODEL_AMBIENT) { 1095 for(int i=0;i<4;i++) { 1096 tmpParams[i] = X2F(params[i]); 1097 } 1098 } 1099 1100 ctx->dispatcher().glLightModelfv(pname,tmpParams); 1101 } 1102 1103 GL_API void GL_APIENTRY glLightf( GLenum light, GLenum pname, GLfloat param) { 1104 GET_CTX() 1105 ctx->dispatcher().glLightf(light,pname,param); 1106 } 1107 1108 GL_API void GL_APIENTRY glLightfv( GLenum light, GLenum pname, const GLfloat *params) { 1109 GET_CTX() 1110 ctx->dispatcher().glLightfv(light,pname,params); 1111 } 1112 1113 GL_API void GL_APIENTRY glLightx( GLenum light, GLenum pname, GLfixed param) { 1114 GET_CTX() 1115 ctx->dispatcher().glLightf(light,pname,X2F(param)); 1116 } 1117 1118 GL_API void GL_APIENTRY glLightxv( GLenum light, GLenum pname, const GLfixed *params) { 1119 GET_CTX() 1120 GLfloat tmpParams[4]; 1121 1122 switch (pname) { 1123 case GL_AMBIENT: 1124 case GL_DIFFUSE: 1125 case GL_SPECULAR: 1126 case GL_EMISSION: 1127 case GL_POSITION: 1128 tmpParams[3] = X2F(params[3]); 1129 case GL_SPOT_DIRECTION: 1130 tmpParams[2] = X2F(params[2]); 1131 tmpParams[1] = X2F(params[1]); 1132 case GL_SPOT_EXPONENT: 1133 case GL_SPOT_CUTOFF: 1134 case GL_CONSTANT_ATTENUATION: 1135 case GL_LINEAR_ATTENUATION: 1136 case GL_QUADRATIC_ATTENUATION: 1137 tmpParams[0] = X2F(params[0]); 1138 break; 1139 default: { 1140 ctx->setGLerror(GL_INVALID_ENUM); 1141 return; 1142 } 1143 } 1144 ctx->dispatcher().glLightfv(light,pname,tmpParams); 1145 } 1146 1147 GL_API void GL_APIENTRY glLineWidth( GLfloat width) { 1148 GET_CTX() 1149 ctx->dispatcher().glLineWidth(width); 1150 } 1151 1152 GL_API void GL_APIENTRY glLineWidthx( GLfixed width) { 1153 GET_CTX() 1154 ctx->dispatcher().glLineWidth(X2F(width)); 1155 } 1156 1157 GL_API void GL_APIENTRY glLoadIdentity( void) { 1158 GET_CTX() 1159 ctx->dispatcher().glLoadIdentity(); 1160 } 1161 1162 GL_API void GL_APIENTRY glLoadMatrixf( const GLfloat *m) { 1163 GET_CTX() 1164 ctx->dispatcher().glLoadMatrixf(m); 1165 } 1166 1167 GL_API void GL_APIENTRY glLoadMatrixx( const GLfixed *m) { 1168 GET_CTX() 1169 GLfloat mat[16]; 1170 for(int i=0; i< 16 ; i++) { 1171 mat[i] = X2F(m[i]); 1172 } 1173 ctx->dispatcher().glLoadMatrixf(mat); 1174 } 1175 1176 GL_API void GL_APIENTRY glLogicOp( GLenum opcode) { 1177 GET_CTX() 1178 ctx->dispatcher().glLogicOp(opcode); 1179 } 1180 1181 GL_API void GL_APIENTRY glMaterialf( GLenum face, GLenum pname, GLfloat param) { 1182 GET_CTX() 1183 ctx->dispatcher().glMaterialf(face,pname,param); 1184 } 1185 1186 GL_API void GL_APIENTRY glMaterialfv( GLenum face, GLenum pname, const GLfloat *params) { 1187 GET_CTX() 1188 ctx->dispatcher().glMaterialfv(face,pname,params); 1189 } 1190 1191 GL_API void GL_APIENTRY glMaterialx( GLenum face, GLenum pname, GLfixed param) { 1192 GET_CTX() 1193 ctx->dispatcher().glMaterialf(face,pname,X2F(param)); 1194 } 1195 1196 GL_API void GL_APIENTRY glMaterialxv( GLenum face, GLenum pname, const GLfixed *params) { 1197 GET_CTX() 1198 GLfloat tmpParams[4]; 1199 1200 for(int i=0; i< 4; i++) { 1201 tmpParams[i] = X2F(params[i]); 1202 } 1203 ctx->dispatcher().glMaterialfv(face,pname,tmpParams); 1204 } 1205 1206 GL_API void GL_APIENTRY glMatrixMode( GLenum mode) { 1207 GET_CTX() 1208 ctx->dispatcher().glMatrixMode(mode); 1209 } 1210 1211 GL_API void GL_APIENTRY glMultMatrixf( const GLfloat *m) { 1212 GET_CTX() 1213 ctx->dispatcher().glMultMatrixf(m); 1214 } 1215 1216 GL_API void GL_APIENTRY glMultMatrixx( const GLfixed *m) { 1217 GET_CTX() 1218 GLfloat mat[16]; 1219 for(int i=0; i< 16 ; i++) { 1220 mat[i] = X2F(m[i]); 1221 } 1222 ctx->dispatcher().glMultMatrixf(mat); 1223 } 1224 1225 GL_API void GL_APIENTRY glMultiTexCoord4f( GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q) { 1226 GET_CTX_CM() 1227 SET_ERROR_IF(!GLEScmValidate::textureEnum(target,ctx->getMaxTexUnits()),GL_INVALID_ENUM); 1228 ctx->dispatcher().glMultiTexCoord4f(target,s,t,r,q); 1229 } 1230 1231 GL_API void GL_APIENTRY glMultiTexCoord4x( GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q) { 1232 GET_CTX_CM() 1233 SET_ERROR_IF(!GLEScmValidate::textureEnum(target,ctx->getMaxTexUnits()),GL_INVALID_ENUM); 1234 ctx->dispatcher().glMultiTexCoord4f(target,X2F(s),X2F(t),X2F(r),X2F(q)); 1235 } 1236 1237 GL_API void GL_APIENTRY glNormal3f( GLfloat nx, GLfloat ny, GLfloat nz) { 1238 GET_CTX() 1239 ctx->dispatcher().glNormal3f(nx,ny,nz); 1240 } 1241 1242 GL_API void GL_APIENTRY glNormal3x( GLfixed nx, GLfixed ny, GLfixed nz) { 1243 GET_CTX() 1244 ctx->dispatcher().glNormal3f(X2F(nx),X2F(ny),X2F(nz)); 1245 } 1246 1247 GL_API void GL_APIENTRY glNormalPointer( GLenum type, GLsizei stride, const GLvoid *pointer) { 1248 GET_CTX() 1249 SET_ERROR_IF(stride < 0,GL_INVALID_VALUE); 1250 SET_ERROR_IF(!GLEScmValidate::normalPointerType(type),GL_INVALID_ENUM); 1251 ctx->setPointer(GL_NORMAL_ARRAY,3,type,stride,pointer);//3 normal verctor 1252 } 1253 1254 GL_API void GL_APIENTRY glOrthof( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar) { 1255 GET_CTX() 1256 ctx->dispatcher().glOrtho(left,right,bottom,top,zNear,zFar); 1257 } 1258 1259 GL_API void GL_APIENTRY glOrthox( GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar) { 1260 GET_CTX() 1261 ctx->dispatcher().glOrtho(X2F(left),X2F(right),X2F(bottom),X2F(top),X2F(zNear),X2F(zFar)); 1262 } 1263 1264 GL_API void GL_APIENTRY glPixelStorei( GLenum pname, GLint param) { 1265 GET_CTX() 1266 SET_ERROR_IF(!(pname == GL_PACK_ALIGNMENT || pname == GL_UNPACK_ALIGNMENT),GL_INVALID_ENUM); 1267 SET_ERROR_IF(!((param==1)||(param==2)||(param==4)||(param==8)), GL_INVALID_VALUE); 1268 ctx->setUnpackAlignment(param); 1269 ctx->dispatcher().glPixelStorei(pname,param); 1270 } 1271 1272 GL_API void GL_APIENTRY glPointParameterf( GLenum pname, GLfloat param) { 1273 GET_CTX() 1274 ctx->dispatcher().glPointParameterf(pname,param); 1275 } 1276 1277 GL_API void GL_APIENTRY glPointParameterfv( GLenum pname, const GLfloat *params) { 1278 GET_CTX() 1279 ctx->dispatcher().glPointParameterfv(pname,params); 1280 } 1281 1282 GL_API void GL_APIENTRY glPointParameterx( GLenum pname, GLfixed param) 1283 { 1284 GET_CTX() 1285 ctx->dispatcher().glPointParameterf(pname,X2F(param)); 1286 } 1287 1288 GL_API void GL_APIENTRY glPointParameterxv( GLenum pname, const GLfixed *params) { 1289 GET_CTX() 1290 1291 GLfloat tmpParam = X2F(*params) ; 1292 ctx->dispatcher().glPointParameterfv(pname,&tmpParam); 1293 } 1294 1295 GL_API void GL_APIENTRY glPointSize( GLfloat size) { 1296 GET_CTX() 1297 ctx->dispatcher().glPointSize(size); 1298 } 1299 1300 GL_API void GL_APIENTRY glPointSizePointerOES( GLenum type, GLsizei stride, const GLvoid *pointer) { 1301 GET_CTX() 1302 SET_ERROR_IF(stride < 0,GL_INVALID_VALUE); 1303 SET_ERROR_IF(!GLEScmValidate::pointPointerType(type),GL_INVALID_ENUM); 1304 ctx->setPointer(GL_POINT_SIZE_ARRAY_OES,1,type,stride,pointer); 1305 } 1306 1307 GL_API void GL_APIENTRY glPointSizex( GLfixed size) { 1308 GET_CTX() 1309 ctx->dispatcher().glPointSize(X2F(size)); 1310 } 1311 1312 GL_API void GL_APIENTRY glPolygonOffset( GLfloat factor, GLfloat units) { 1313 GET_CTX() 1314 ctx->dispatcher().glPolygonOffset(factor,units); 1315 } 1316 1317 GL_API void GL_APIENTRY glPolygonOffsetx( GLfixed factor, GLfixed units) { 1318 GET_CTX() 1319 ctx->dispatcher().glPolygonOffset(X2F(factor),X2F(units)); 1320 } 1321 1322 GL_API void GL_APIENTRY glPopMatrix(void) { 1323 GET_CTX() 1324 ctx->dispatcher().glPopMatrix(); 1325 } 1326 1327 GL_API void GL_APIENTRY glPushMatrix(void) { 1328 GET_CTX() 1329 ctx->dispatcher().glPushMatrix(); 1330 } 1331 1332 GL_API void GL_APIENTRY glReadPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels) { 1333 GET_CTX() 1334 SET_ERROR_IF(!(GLEScmValidate::pixelFrmt(ctx,format) && GLEScmValidate::pixelType(ctx,type)),GL_INVALID_ENUM); 1335 SET_ERROR_IF(!(GLEScmValidate::pixelOp(format,type)),GL_INVALID_OPERATION); 1336 1337 ctx->dispatcher().glReadPixels(x,y,width,height,format,type,pixels); 1338 } 1339 1340 GL_API void GL_APIENTRY glRotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z) { 1341 GET_CTX() 1342 ctx->dispatcher().glRotatef(angle,x,y,z); 1343 } 1344 1345 GL_API void GL_APIENTRY glRotatex( GLfixed angle, GLfixed x, GLfixed y, GLfixed z) { 1346 GET_CTX() 1347 ctx->dispatcher().glRotatef(angle,X2F(x),X2F(y),X2F(z)); 1348 } 1349 1350 GL_API void GL_APIENTRY glSampleCoverage( GLclampf value, GLboolean invert) { 1351 GET_CTX() 1352 ctx->dispatcher().glSampleCoverage(value,invert); 1353 } 1354 1355 GL_API void GL_APIENTRY glSampleCoveragex( GLclampx value, GLboolean invert) { 1356 GET_CTX() 1357 ctx->dispatcher().glSampleCoverage(X2F(value),invert); 1358 } 1359 1360 GL_API void GL_APIENTRY glScalef( GLfloat x, GLfloat y, GLfloat z) { 1361 GET_CTX() 1362 ctx->dispatcher().glScalef(x,y,z); 1363 } 1364 1365 GL_API void GL_APIENTRY glScalex( GLfixed x, GLfixed y, GLfixed z) { 1366 GET_CTX() 1367 ctx->dispatcher().glScalef(X2F(x),X2F(y),X2F(z)); 1368 } 1369 1370 GL_API void GL_APIENTRY glScissor( GLint x, GLint y, GLsizei width, GLsizei height) { 1371 GET_CTX() 1372 ctx->dispatcher().glScissor(x,y,width,height); 1373 } 1374 1375 GL_API void GL_APIENTRY glShadeModel( GLenum mode) { 1376 GET_CTX() 1377 ctx->dispatcher().glShadeModel(mode); 1378 } 1379 1380 GL_API void GL_APIENTRY glStencilFunc( GLenum func, GLint ref, GLuint mask) { 1381 GET_CTX() 1382 ctx->dispatcher().glStencilFunc(func,ref,mask); 1383 } 1384 1385 GL_API void GL_APIENTRY glStencilMask( GLuint mask) { 1386 GET_CTX() 1387 ctx->dispatcher().glStencilMask(mask); 1388 } 1389 1390 GL_API void GL_APIENTRY glStencilOp( GLenum fail, GLenum zfail, GLenum zpass) { 1391 GET_CTX() 1392 SET_ERROR_IF(!(GLEScmValidate::stencilOp(fail) && GLEScmValidate::stencilOp(zfail) && GLEScmValidate::stencilOp(zpass)),GL_INVALID_ENUM); 1393 ctx->dispatcher().glStencilOp(fail,zfail,zpass); 1394 } 1395 1396 GL_API void GL_APIENTRY glTexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) { 1397 GET_CTX() 1398 SET_ERROR_IF(!GLEScmValidate::texCoordPointerParams(size,stride),GL_INVALID_VALUE); 1399 SET_ERROR_IF(!GLEScmValidate::texCoordPointerType(type),GL_INVALID_ENUM); 1400 ctx->setPointer(GL_TEXTURE_COORD_ARRAY,size,type,stride,pointer); 1401 } 1402 1403 GL_API void GL_APIENTRY glTexEnvf( GLenum target, GLenum pname, GLfloat param) { 1404 GET_CTX() 1405 SET_ERROR_IF(!GLEScmValidate::texEnv(target,pname),GL_INVALID_ENUM); 1406 ctx->dispatcher().glTexEnvf(target,pname,param); 1407 } 1408 1409 GL_API void GL_APIENTRY glTexEnvfv( GLenum target, GLenum pname, const GLfloat *params) { 1410 GET_CTX() 1411 SET_ERROR_IF(!GLEScmValidate::texEnv(target,pname),GL_INVALID_ENUM); 1412 ctx->dispatcher().glTexEnvfv(target,pname,params); 1413 } 1414 1415 GL_API void GL_APIENTRY glTexEnvi( GLenum target, GLenum pname, GLint param) { 1416 GET_CTX() 1417 SET_ERROR_IF(!GLEScmValidate::texEnv(target,pname),GL_INVALID_ENUM); 1418 ctx->dispatcher().glTexEnvi(target,pname,param); 1419 } 1420 1421 GL_API void GL_APIENTRY glTexEnviv( GLenum target, GLenum pname, const GLint *params) { 1422 GET_CTX() 1423 SET_ERROR_IF(!GLEScmValidate::texEnv(target,pname),GL_INVALID_ENUM); 1424 ctx->dispatcher().glTexEnviv(target,pname,params); 1425 } 1426 1427 GL_API void GL_APIENTRY glTexEnvx( GLenum target, GLenum pname, GLfixed param) { 1428 GET_CTX() 1429 SET_ERROR_IF(!GLEScmValidate::texEnv(target,pname),GL_INVALID_ENUM); 1430 GLfloat tmpParam = static_cast<GLfloat>(param); 1431 ctx->dispatcher().glTexEnvf(target,pname,tmpParam); 1432 } 1433 1434 GL_API void GL_APIENTRY glTexEnvxv( GLenum target, GLenum pname, const GLfixed *params) { 1435 GET_CTX() 1436 SET_ERROR_IF(!GLEScmValidate::texEnv(target,pname),GL_INVALID_ENUM); 1437 1438 GLfloat tmpParams[4]; 1439 if(pname == GL_TEXTURE_ENV_COLOR) { 1440 for(int i =0;i<4;i++) { 1441 tmpParams[i] = X2F(params[i]); 1442 } 1443 } else { 1444 tmpParams[0] = static_cast<GLfloat>(params[0]); 1445 } 1446 ctx->dispatcher().glTexEnvfv(target,pname,tmpParams); 1447 } 1448 1449 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) { 1450 GET_CTX() 1451 1452 SET_ERROR_IF(!(GLEScmValidate::textureTargetEx(target) && 1453 GLEScmValidate::pixelFrmt(ctx,internalformat) && 1454 GLEScmValidate::pixelFrmt(ctx,format) && 1455 GLEScmValidate::pixelType(ctx,type)),GL_INVALID_ENUM); 1456 1457 SET_ERROR_IF(!(GLEScmValidate::pixelOp(format,type) && internalformat == ((GLint)format)),GL_INVALID_OPERATION); 1458 1459 bool needAutoMipmap = false; 1460 1461 if (ctx->shareGroup().Ptr()){ 1462 TextureData *texData = getTextureTargetData(target); 1463 SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION); 1464 if(texData) { 1465 texData->width = width; 1466 texData->height = height; 1467 texData->border = border; 1468 texData->internalFormat = internalformat; 1469 texData->target = target; 1470 1471 if (texData->sourceEGLImage != 0) { 1472 // 1473 // This texture was a target of EGLImage, 1474 // but now it is re-defined so we need to detach 1475 // from the EGLImage and re-generate global texture name 1476 // for it. 1477 // 1478 if (texData->eglImageDetach) { 1479 (*texData->eglImageDetach)(texData->sourceEGLImage); 1480 } 1481 unsigned int tex = ctx->getBindedTexture(target); 1482 ctx->shareGroup()->replaceGlobalName(TEXTURE, 1483 tex, 1484 texData->oldGlobal); 1485 ctx->dispatcher().glBindTexture(GL_TEXTURE_2D, texData->oldGlobal); 1486 texData->sourceEGLImage = 0; 1487 texData->oldGlobal = 0; 1488 } 1489 1490 needAutoMipmap = texData->requiresAutoMipmap; 1491 } 1492 } 1493 1494 ctx->dispatcher().glTexImage2D(target,level, 1495 internalformat,width,height, 1496 border,format,type,pixels); 1497 1498 if(needAutoMipmap) 1499 { 1500 ctx->dispatcher().glGenerateMipmapEXT(target); 1501 } 1502 } 1503 1504 static bool handleMipmapGeneration(GLenum target, GLenum pname, bool param) 1505 { 1506 GET_CTX_RET(false) 1507 1508 if(pname == GL_GENERATE_MIPMAP && !ctx->isAutoMipmapSupported()) 1509 { 1510 TextureData *texData = getTextureTargetData(target); 1511 if(texData) 1512 { 1513 texData->requiresAutoMipmap = param; 1514 } 1515 return true; 1516 } 1517 1518 return false; 1519 } 1520 1521 GL_API void GL_APIENTRY glTexParameterf( GLenum target, GLenum pname, GLfloat param) { 1522 GET_CTX() 1523 SET_ERROR_IF(!GLEScmValidate::texParams(target,pname),GL_INVALID_ENUM); 1524 1525 if(handleMipmapGeneration(target, pname, (bool)param)) 1526 return; 1527 1528 ctx->dispatcher().glTexParameterf(target,pname,param); 1529 } 1530 1531 GL_API void GL_APIENTRY glTexParameterfv( GLenum target, GLenum pname, const GLfloat *params) { 1532 GET_CTX() 1533 SET_ERROR_IF(!GLEScmValidate::texParams(target,pname),GL_INVALID_ENUM); 1534 1535 if(handleMipmapGeneration(target, pname, (bool)(*params))) 1536 return; 1537 1538 if (pname==GL_TEXTURE_CROP_RECT_OES) { 1539 TextureData *texData = getTextureTargetData(target); 1540 SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION); 1541 for (int i=0;i<4;++i) 1542 texData->crop_rect[i] = params[i]; 1543 } 1544 else { 1545 ctx->dispatcher().glTexParameterfv(target,pname,params); 1546 } 1547 } 1548 1549 GL_API void GL_APIENTRY glTexParameteri( GLenum target, GLenum pname, GLint param) { 1550 GET_CTX() 1551 SET_ERROR_IF(!GLEScmValidate::texParams(target,pname),GL_INVALID_ENUM); 1552 1553 if(handleMipmapGeneration(target, pname, (bool)param)) 1554 return; 1555 1556 ctx->dispatcher().glTexParameteri(target,pname,param); 1557 } 1558 1559 GL_API void GL_APIENTRY glTexParameteriv( GLenum target, GLenum pname, const GLint *params) { 1560 GET_CTX() 1561 SET_ERROR_IF(!GLEScmValidate::texParams(target,pname),GL_INVALID_ENUM); 1562 1563 if(handleMipmapGeneration(target, pname, (bool)(*params))) 1564 return; 1565 1566 if (pname==GL_TEXTURE_CROP_RECT_OES) { 1567 TextureData *texData = getTextureTargetData(target); 1568 SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION); 1569 for (int i=0;i<4;++i) 1570 texData->crop_rect[i] = params[i]; 1571 } 1572 else { 1573 ctx->dispatcher().glTexParameteriv(target,pname,params); 1574 } 1575 } 1576 1577 GL_API void GL_APIENTRY glTexParameterx( GLenum target, GLenum pname, GLfixed param) { 1578 GET_CTX() 1579 SET_ERROR_IF(!GLEScmValidate::texParams(target,pname),GL_INVALID_ENUM); 1580 1581 if(handleMipmapGeneration(target, pname, (bool)param)) 1582 return; 1583 1584 ctx->dispatcher().glTexParameterf(target,pname,static_cast<GLfloat>(param)); 1585 } 1586 1587 GL_API void GL_APIENTRY glTexParameterxv( GLenum target, GLenum pname, const GLfixed *params) { 1588 GET_CTX() 1589 SET_ERROR_IF(!GLEScmValidate::texParams(target,pname),GL_INVALID_ENUM); 1590 1591 if(handleMipmapGeneration(target, pname, (bool)(*params))) 1592 return; 1593 1594 if (pname==GL_TEXTURE_CROP_RECT_OES) { 1595 TextureData *texData = getTextureTargetData(target); 1596 SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION); 1597 for (int i=0;i<4;++i) 1598 texData->crop_rect[i] = X2F(params[i]); 1599 } 1600 else { 1601 GLfloat param = static_cast<GLfloat>(params[0]); 1602 ctx->dispatcher().glTexParameterfv(target,pname,¶m); 1603 } 1604 } 1605 1606 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) { 1607 GET_CTX() 1608 SET_ERROR_IF(!(GLEScmValidate::textureTargetEx(target) && 1609 GLEScmValidate::pixelFrmt(ctx,format)&& 1610 GLEScmValidate::pixelType(ctx,type)),GL_INVALID_ENUM); 1611 SET_ERROR_IF(!GLEScmValidate::pixelOp(format,type),GL_INVALID_OPERATION); 1612 1613 ctx->dispatcher().glTexSubImage2D(target,level,xoffset,yoffset,width,height,format,type,pixels); 1614 1615 if (ctx->shareGroup().Ptr()){ 1616 TextureData *texData = getTextureTargetData(target); 1617 SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION); 1618 if(texData && texData->requiresAutoMipmap) 1619 { 1620 ctx->dispatcher().glGenerateMipmapEXT(target); 1621 } 1622 } 1623 } 1624 1625 GL_API void GL_APIENTRY glTranslatef( GLfloat x, GLfloat y, GLfloat z) { 1626 GET_CTX() 1627 ctx->dispatcher().glTranslatef(x,y,z); 1628 } 1629 1630 GL_API void GL_APIENTRY glTranslatex( GLfixed x, GLfixed y, GLfixed z) { 1631 GET_CTX() 1632 ctx->dispatcher().glTranslatef(X2F(x),X2F(y),X2F(z)); 1633 } 1634 1635 GL_API void GL_APIENTRY glVertexPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) { 1636 GET_CTX() 1637 SET_ERROR_IF(!GLEScmValidate::vertexPointerParams(size,stride),GL_INVALID_VALUE); 1638 SET_ERROR_IF(!GLEScmValidate::vertexPointerType(type),GL_INVALID_ENUM); 1639 ctx->setPointer(GL_VERTEX_ARRAY,size,type,stride,pointer); 1640 } 1641 1642 GL_API void GL_APIENTRY glViewport( GLint x, GLint y, GLsizei width, GLsizei height) { 1643 GET_CTX() 1644 ctx->dispatcher().glViewport(x,y,width,height); 1645 } 1646 1647 GL_API void GL_APIENTRY glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image) 1648 { 1649 GET_CTX(); 1650 SET_ERROR_IF(!GLEScmValidate::textureTargetLimited(target),GL_INVALID_ENUM); 1651 unsigned int imagehndl = SafeUIntFromPointer(image); 1652 EglImage *img = s_eglIface->eglAttachEGLImage(imagehndl); 1653 if (img) { 1654 // Create the texture object in the underlying EGL implementation, 1655 // flag to the OpenGL layer to skip the image creation and map the 1656 // current binded texture object to the existing global object. 1657 if (ctx->shareGroup().Ptr()) { 1658 ObjectLocalName tex = TextureLocalName(target,ctx->getBindedTexture(target)); 1659 unsigned int oldGlobal = ctx->shareGroup()->getGlobalName(TEXTURE, tex); 1660 // Delete old texture object but only if it is not a target of a EGLImage 1661 if (oldGlobal) { 1662 TextureData* oldTexData = getTextureData(tex); 1663 if (!oldTexData || oldTexData->sourceEGLImage == 0) { 1664 ctx->dispatcher().glDeleteTextures(1, &oldGlobal); 1665 } 1666 } 1667 // replace mapping and bind the new global object 1668 ctx->shareGroup()->replaceGlobalName(TEXTURE, tex,img->globalTexName); 1669 ctx->dispatcher().glBindTexture(GL_TEXTURE_2D, img->globalTexName); 1670 TextureData *texData = getTextureTargetData(target); 1671 SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION); 1672 texData->width = img->width; 1673 texData->height = img->height; 1674 texData->border = img->border; 1675 texData->internalFormat = img->internalFormat; 1676 texData->sourceEGLImage = imagehndl; 1677 texData->eglImageDetach = s_eglIface->eglDetachEGLImage; 1678 texData->oldGlobal = oldGlobal; 1679 } 1680 } 1681 } 1682 1683 GL_API void GL_APIENTRY glEGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image) 1684 { 1685 GET_CTX(); 1686 SET_ERROR_IF(target != GL_RENDERBUFFER_OES,GL_INVALID_ENUM); 1687 unsigned int imagehndl = SafeUIntFromPointer(image); 1688 EglImage *img = s_eglIface->eglAttachEGLImage(imagehndl); 1689 SET_ERROR_IF(!img,GL_INVALID_VALUE); 1690 SET_ERROR_IF(!ctx->shareGroup().Ptr(),GL_INVALID_OPERATION); 1691 1692 // Get current bounded renderbuffer 1693 // raise INVALID_OPERATIOn if no renderbuffer is bounded 1694 GLuint rb = ctx->getRenderbufferBinding(); 1695 SET_ERROR_IF(rb == 0,GL_INVALID_OPERATION); 1696 ObjectDataPtr objData = ctx->shareGroup()->getObjectData(RENDERBUFFER,rb); 1697 RenderbufferData *rbData = (RenderbufferData *)objData.Ptr(); 1698 SET_ERROR_IF(!rbData,GL_INVALID_OPERATION); 1699 1700 // 1701 // flag in the renderbufferData that it is an eglImage target 1702 // 1703 rbData->sourceEGLImage = imagehndl; 1704 rbData->eglImageDetach = s_eglIface->eglDetachEGLImage; 1705 rbData->eglImageGlobalTexName = img->globalTexName; 1706 1707 // 1708 // if the renderbuffer is attached to a framebuffer 1709 // change the framebuffer attachment in the undelying OpenGL 1710 // to point to the eglImage texture object. 1711 // 1712 if (rbData->attachedFB) { 1713 // update the framebuffer attachment point to the 1714 // underlying texture of the img 1715 GLuint prevFB = ctx->getFramebufferBinding(); 1716 if (prevFB != rbData->attachedFB) { 1717 ctx->dispatcher().glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 1718 rbData->attachedFB); 1719 } 1720 ctx->dispatcher().glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, 1721 rbData->attachedPoint, 1722 GL_TEXTURE_2D, 1723 img->globalTexName,0); 1724 if (prevFB != rbData->attachedFB) { 1725 ctx->dispatcher().glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 1726 prevFB); 1727 } 1728 } 1729 } 1730 1731 /* GL_OES_blend_subtract*/ 1732 GL_API void GL_APIENTRY glBlendEquationOES(GLenum mode) { 1733 GET_CTX() 1734 SET_ERROR_IF(!(GLEScmValidate::blendEquationMode(mode)), GL_INVALID_ENUM); 1735 ctx->dispatcher().glBlendEquation(mode); 1736 } 1737 1738 /* GL_OES_blend_equation_separate */ 1739 GL_API void GL_APIENTRY glBlendEquationSeparateOES (GLenum modeRGB, GLenum modeAlpha) { 1740 GET_CTX() 1741 SET_ERROR_IF(!(GLEScmValidate::blendEquationMode(modeRGB) && GLEScmValidate::blendEquationMode(modeAlpha)), GL_INVALID_ENUM); 1742 ctx->dispatcher().glBlendEquationSeparate(modeRGB,modeAlpha); 1743 } 1744 1745 /* GL_OES_blend_func_separate */ 1746 GL_API void GL_APIENTRY glBlendFuncSeparateOES(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) { 1747 GET_CTX() 1748 SET_ERROR_IF(!GLEScmValidate::blendSrc(srcRGB) || !GLEScmValidate::blendDst(dstRGB) || 1749 !GLEScmValidate::blendSrc(srcAlpha) || ! GLEScmValidate::blendDst(dstAlpha) ,GL_INVALID_ENUM); 1750 ctx->dispatcher().glBlendFuncSeparate(srcRGB,dstRGB,srcAlpha,dstAlpha); 1751 } 1752 1753 /* GL_OES_framebuffer_object */ 1754 GL_API GLboolean GL_APIENTRY glIsRenderbufferOES(GLuint renderbuffer) { 1755 GET_CTX_RET(GL_FALSE) 1756 RET_AND_SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION,GL_FALSE); 1757 if(renderbuffer && ctx->shareGroup().Ptr()){ 1758 return ctx->shareGroup()->isObject(RENDERBUFFER,renderbuffer) ? GL_TRUE :GL_FALSE; 1759 } 1760 return ctx->dispatcher().glIsRenderbufferEXT(renderbuffer); 1761 } 1762 1763 GL_API void GLAPIENTRY glBindRenderbufferOES(GLenum target, GLuint renderbuffer) { 1764 GET_CTX() 1765 SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION); 1766 SET_ERROR_IF(!GLEScmValidate::renderbufferTarget(target),GL_INVALID_ENUM); 1767 1768 //if buffer wasn't generated before,generate one 1769 if(renderbuffer && ctx->shareGroup().Ptr() && !ctx->shareGroup()->isObject(RENDERBUFFER,renderbuffer)){ 1770 ctx->shareGroup()->genName(RENDERBUFFER,renderbuffer); 1771 ctx->shareGroup()->setObjectData(RENDERBUFFER, 1772 renderbuffer, 1773 ObjectDataPtr(new RenderbufferData())); 1774 } 1775 1776 int globalBufferName = (renderbuffer != 0) ? ctx->shareGroup()->getGlobalName(RENDERBUFFER,renderbuffer) : 0; 1777 ctx->dispatcher().glBindRenderbufferEXT(target,globalBufferName); 1778 1779 // update renderbuffer binding state 1780 ctx->setRenderbufferBinding(renderbuffer); 1781 } 1782 1783 GL_API void GLAPIENTRY glDeleteRenderbuffersOES(GLsizei n, const GLuint *renderbuffers) { 1784 GET_CTX() 1785 SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION); 1786 for (int i=0;i<n;++i) { 1787 GLuint globalBufferName = ctx->shareGroup()->getGlobalName(RENDERBUFFER,renderbuffers[i]); 1788 ctx->dispatcher().glDeleteRenderbuffersEXT(1,&globalBufferName); 1789 } 1790 } 1791 1792 GL_API void GLAPIENTRY glGenRenderbuffersOES(GLsizei n, GLuint *renderbuffers) { 1793 GET_CTX() 1794 SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION); 1795 SET_ERROR_IF(n<0,GL_INVALID_VALUE); 1796 if(ctx->shareGroup().Ptr()) { 1797 for(int i=0; i<n ;i++) { 1798 renderbuffers[i] = ctx->shareGroup()->genName(RENDERBUFFER, 0, true); 1799 ctx->shareGroup()->setObjectData(RENDERBUFFER, 1800 renderbuffers[i], 1801 ObjectDataPtr(new RenderbufferData())); 1802 } 1803 } 1804 } 1805 1806 GL_API void GLAPIENTRY glRenderbufferStorageOES(GLenum target, GLenum internalformat, GLsizei width, GLsizei height){ 1807 GET_CTX() 1808 SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION); 1809 SET_ERROR_IF(!GLEScmValidate::renderbufferTarget(target) || !GLEScmValidate::renderbufferInternalFrmt(ctx,internalformat) ,GL_INVALID_ENUM); 1810 if (internalformat==GL_RGB565_OES) //RGB565 not supported by GL 1811 internalformat = GL_RGB8_OES; 1812 1813 // Get current bounded renderbuffer 1814 // raise INVALID_OPERATIOn if no renderbuffer is bounded 1815 GLuint rb = ctx->getRenderbufferBinding(); 1816 SET_ERROR_IF(rb == 0,GL_INVALID_OPERATION); 1817 ObjectDataPtr objData = ctx->shareGroup()->getObjectData(RENDERBUFFER,rb); 1818 RenderbufferData *rbData = (RenderbufferData *)objData.Ptr(); 1819 SET_ERROR_IF(!rbData,GL_INVALID_OPERATION); 1820 1821 // 1822 // if the renderbuffer was an eglImage target, detach from 1823 // the eglImage. 1824 // 1825 if (rbData->sourceEGLImage != 0) { 1826 if (rbData->eglImageDetach) { 1827 (*rbData->eglImageDetach)(rbData->sourceEGLImage); 1828 } 1829 rbData->sourceEGLImage = 0; 1830 rbData->eglImageGlobalTexName = 0; 1831 } 1832 1833 ctx->dispatcher().glRenderbufferStorageEXT(target,internalformat,width,height); 1834 } 1835 1836 GL_API void GLAPIENTRY glGetRenderbufferParameterivOES(GLenum target, GLenum pname, GLint* params) { 1837 GET_CTX() 1838 SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION); 1839 SET_ERROR_IF(!GLEScmValidate::renderbufferTarget(target) || !GLEScmValidate::renderbufferParams(pname) ,GL_INVALID_ENUM); 1840 1841 // 1842 // If this is a renderbuffer which is eglimage's target, we 1843 // should query the underlying eglimage's texture object instead. 1844 // 1845 GLuint rb = ctx->getRenderbufferBinding(); 1846 if (rb) { 1847 ObjectDataPtr objData = ctx->shareGroup()->getObjectData(RENDERBUFFER,rb); 1848 RenderbufferData *rbData = (RenderbufferData *)objData.Ptr(); 1849 if (rbData && rbData->sourceEGLImage != 0) { 1850 GLenum texPname; 1851 switch(pname) { 1852 case GL_RENDERBUFFER_WIDTH_OES: 1853 texPname = GL_TEXTURE_WIDTH; 1854 break; 1855 case GL_RENDERBUFFER_HEIGHT_OES: 1856 texPname = GL_TEXTURE_HEIGHT; 1857 break; 1858 case GL_RENDERBUFFER_INTERNAL_FORMAT_OES: 1859 texPname = GL_TEXTURE_INTERNAL_FORMAT; 1860 break; 1861 case GL_RENDERBUFFER_RED_SIZE_OES: 1862 texPname = GL_TEXTURE_RED_SIZE; 1863 break; 1864 case GL_RENDERBUFFER_GREEN_SIZE_OES: 1865 texPname = GL_TEXTURE_GREEN_SIZE; 1866 break; 1867 case GL_RENDERBUFFER_BLUE_SIZE_OES: 1868 texPname = GL_TEXTURE_BLUE_SIZE; 1869 break; 1870 case GL_RENDERBUFFER_ALPHA_SIZE_OES: 1871 texPname = GL_TEXTURE_ALPHA_SIZE; 1872 break; 1873 case GL_RENDERBUFFER_DEPTH_SIZE_OES: 1874 texPname = GL_TEXTURE_DEPTH_SIZE; 1875 break; 1876 case GL_RENDERBUFFER_STENCIL_SIZE_OES: 1877 default: 1878 *params = 0; //XXX 1879 return; 1880 break; 1881 } 1882 1883 GLint prevTex; 1884 ctx->dispatcher().glGetIntegerv(GL_TEXTURE_BINDING_2D, &prevTex); 1885 ctx->dispatcher().glBindTexture(GL_TEXTURE_2D, 1886 rbData->eglImageGlobalTexName); 1887 ctx->dispatcher().glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, 1888 texPname, 1889 params); 1890 ctx->dispatcher().glBindTexture(GL_TEXTURE_2D, prevTex); 1891 return; 1892 } 1893 } 1894 1895 ctx->dispatcher().glGetRenderbufferParameterivEXT(target,pname,params); 1896 } 1897 1898 GL_API GLboolean GLAPIENTRY glIsFramebufferOES(GLuint framebuffer) { 1899 GET_CTX_RET(GL_FALSE) 1900 RET_AND_SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION,GL_FALSE); 1901 if (framebuffer && ctx->shareGroup().Ptr()) { 1902 return ctx->shareGroup()->isObject(FRAMEBUFFER,framebuffer) ? GL_TRUE : GL_FALSE; 1903 } 1904 return ctx->dispatcher().glIsFramebufferEXT(framebuffer); 1905 } 1906 1907 GL_API void GLAPIENTRY glBindFramebufferOES(GLenum target, GLuint framebuffer) { 1908 GET_CTX() 1909 SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION); 1910 SET_ERROR_IF(!GLEScmValidate::framebufferTarget(target) ,GL_INVALID_ENUM); 1911 if (framebuffer && ctx->shareGroup().Ptr() && !ctx->shareGroup()->isObject(FRAMEBUFFER,framebuffer)) { 1912 ctx->shareGroup()->genName(FRAMEBUFFER,framebuffer); 1913 ctx->shareGroup()->setObjectData(FRAMEBUFFER, framebuffer, 1914 ObjectDataPtr(new FramebufferData(framebuffer))); 1915 } 1916 int globalBufferName = (framebuffer!=0) ? ctx->shareGroup()->getGlobalName(FRAMEBUFFER,framebuffer) : 0; 1917 ctx->dispatcher().glBindFramebufferEXT(target,globalBufferName); 1918 1919 // update framebuffer binding state 1920 ctx->setFramebufferBinding(framebuffer); 1921 } 1922 1923 GL_API void GLAPIENTRY glDeleteFramebuffersOES(GLsizei n, const GLuint *framebuffers) { 1924 GET_CTX() 1925 SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION); 1926 for (int i=0;i<n;++i) { 1927 GLuint globalBufferName = ctx->shareGroup()->getGlobalName(FRAMEBUFFER,framebuffers[i]); 1928 ctx->dispatcher().glDeleteFramebuffersEXT(1,&globalBufferName); 1929 } 1930 } 1931 1932 GL_API void GLAPIENTRY glGenFramebuffersOES(GLsizei n, GLuint *framebuffers) { 1933 GET_CTX() 1934 SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION); 1935 SET_ERROR_IF(n<0,GL_INVALID_VALUE); 1936 if (ctx->shareGroup().Ptr()) { 1937 for (int i=0;i<n;i++) { 1938 framebuffers[i] = ctx->shareGroup()->genName(FRAMEBUFFER, 0, true); 1939 ctx->shareGroup()->setObjectData(FRAMEBUFFER, framebuffers[i], 1940 ObjectDataPtr(new FramebufferData(framebuffers[i]))); 1941 } 1942 } 1943 } 1944 1945 GL_API GLenum GLAPIENTRY glCheckFramebufferStatusOES(GLenum target) { 1946 GET_CTX_RET(0) 1947 RET_AND_SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION,0); 1948 RET_AND_SET_ERROR_IF(!GLEScmValidate::framebufferTarget(target) ,GL_INVALID_ENUM,0); 1949 return ctx->dispatcher().glCheckFramebufferStatusEXT(target); 1950 } 1951 1952 GL_API void GLAPIENTRY glFramebufferTexture2DOES(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) { 1953 GET_CTX() 1954 SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION); 1955 SET_ERROR_IF(!GLEScmValidate::framebufferTarget(target) || !GLEScmValidate::framebufferAttachment(attachment) || 1956 !GLEScmValidate::textureTargetEx(textarget),GL_INVALID_ENUM); 1957 SET_ERROR_IF(!ctx->shareGroup().Ptr(), GL_INVALID_OPERATION); 1958 1959 GLuint globalTexName = 0; 1960 if(texture) { 1961 if (!ctx->shareGroup()->isObject(TEXTURE,texture)) { 1962 ctx->shareGroup()->genName(TEXTURE,texture); 1963 } 1964 ObjectLocalName texname = TextureLocalName(textarget,texture); 1965 globalTexName = ctx->shareGroup()->getGlobalName(TEXTURE,texname); 1966 } 1967 1968 ctx->dispatcher().glFramebufferTexture2DEXT(target,attachment,textarget,globalTexName,level); 1969 1970 // Update the the current framebuffer object attachment state 1971 GLuint fbName = ctx->getFramebufferBinding(); 1972 ObjectDataPtr fbObj = ctx->shareGroup()->getObjectData(FRAMEBUFFER,fbName); 1973 if (fbObj.Ptr() != NULL) { 1974 FramebufferData *fbData = (FramebufferData *)fbObj.Ptr(); 1975 fbData->setAttachment(attachment, textarget, 1976 texture, ObjectDataPtr(NULL)); 1977 } 1978 } 1979 1980 GL_API void GLAPIENTRY glFramebufferRenderbufferOES(GLenum target, GLenum attachment,GLenum renderbuffertarget, GLuint renderbuffer) { 1981 GET_CTX() 1982 SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION); 1983 SET_ERROR_IF(!GLEScmValidate::framebufferTarget(target) || 1984 !GLEScmValidate::framebufferAttachment(attachment) || 1985 !GLEScmValidate::renderbufferTarget(renderbuffertarget), GL_INVALID_ENUM); 1986 1987 SET_ERROR_IF(!ctx->shareGroup().Ptr(), GL_INVALID_OPERATION); 1988 1989 GLuint globalBufferName = 0; 1990 ObjectDataPtr obj; 1991 1992 // generate the renderbuffer object if not yet exist 1993 if (renderbuffer) { 1994 if (!ctx->shareGroup()->isObject(RENDERBUFFER,renderbuffer)) { 1995 ctx->shareGroup()->genName(RENDERBUFFER,renderbuffer); 1996 obj = ObjectDataPtr(new RenderbufferData()); 1997 ctx->shareGroup()->setObjectData(RENDERBUFFER, 1998 renderbuffer, 1999 ObjectDataPtr(new RenderbufferData())); 2000 } 2001 else { 2002 obj = ctx->shareGroup()->getObjectData(RENDERBUFFER,renderbuffer); 2003 } 2004 globalBufferName = ctx->shareGroup()->getGlobalName(RENDERBUFFER,renderbuffer); 2005 } 2006 2007 // Update the the current framebuffer object attachment state 2008 GLuint fbName = ctx->getFramebufferBinding(); 2009 ObjectDataPtr fbObj = ctx->shareGroup()->getObjectData(FRAMEBUFFER,fbName); 2010 if (fbObj.Ptr() != NULL) { 2011 FramebufferData *fbData = (FramebufferData *)fbObj.Ptr(); 2012 fbData->setAttachment(attachment, renderbuffertarget, renderbuffer, obj); 2013 } 2014 2015 if (renderbuffer && obj.Ptr() != NULL) { 2016 RenderbufferData *rbData = (RenderbufferData *)obj.Ptr(); 2017 if (rbData->sourceEGLImage != 0) { 2018 // 2019 // This renderbuffer object is an eglImage target 2020 // attach the eglimage's texture instead the renderbuffer. 2021 // 2022 ctx->dispatcher().glFramebufferTexture2DEXT(target, 2023 attachment, 2024 GL_TEXTURE_2D, 2025 rbData->eglImageGlobalTexName,0); 2026 return; 2027 } 2028 } 2029 2030 ctx->dispatcher().glFramebufferRenderbufferEXT(target,attachment,renderbuffertarget,globalBufferName); 2031 } 2032 2033 GL_API void GLAPIENTRY glGetFramebufferAttachmentParameterivOES(GLenum target, GLenum attachment, GLenum pname, GLint *params) { 2034 GET_CTX() 2035 SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION); 2036 SET_ERROR_IF(!GLEScmValidate::framebufferTarget(target) || !GLEScmValidate::framebufferAttachment(attachment) || 2037 !GLEScmValidate::framebufferAttachmentParams(pname), GL_INVALID_ENUM); 2038 2039 // 2040 // Take the attachment attribute from our state - if available 2041 // 2042 GLuint fbName = ctx->getFramebufferBinding(); 2043 if (fbName) { 2044 ObjectDataPtr fbObj = ctx->shareGroup()->getObjectData(FRAMEBUFFER,fbName); 2045 if (fbObj.Ptr() != NULL) { 2046 FramebufferData *fbData = (FramebufferData *)fbObj.Ptr(); 2047 GLenum target; 2048 GLuint name = fbData->getAttachment(attachment, &target, NULL); 2049 if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_OES) { 2050 *params = target; 2051 return; 2052 } 2053 else if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_OES) { 2054 *params = name; 2055 return; 2056 } 2057 } 2058 } 2059 2060 ctx->dispatcher().glGetFramebufferAttachmentParameterivEXT(target,attachment,pname,params); 2061 } 2062 2063 GL_API void GL_APIENTRY glGenerateMipmapOES(GLenum target) { 2064 GET_CTX() 2065 SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION); 2066 SET_ERROR_IF(!GLEScmValidate::textureTargetLimited(target),GL_INVALID_ENUM); 2067 ctx->dispatcher().glGenerateMipmapEXT(target); 2068 } 2069 2070 GL_API void GL_APIENTRY glCurrentPaletteMatrixOES(GLuint index) { 2071 GET_CTX() 2072 SET_ERROR_IF(!(ctx->getCaps()->GL_ARB_MATRIX_PALETTE && ctx->getCaps()->GL_ARB_VERTEX_BLEND),GL_INVALID_OPERATION); 2073 ctx->dispatcher().glCurrentPaletteMatrixARB(index); 2074 } 2075 2076 GL_API void GL_APIENTRY glLoadPaletteFromModelViewMatrixOES() { 2077 GET_CTX() 2078 SET_ERROR_IF(!(ctx->getCaps()->GL_ARB_MATRIX_PALETTE && ctx->getCaps()->GL_ARB_VERTEX_BLEND),GL_INVALID_OPERATION); 2079 GLint matrix[16]; 2080 ctx->dispatcher().glGetIntegerv(GL_MODELVIEW_MATRIX,matrix); 2081 ctx->dispatcher().glMatrixIndexuivARB(1,(GLuint*)matrix); 2082 2083 } 2084 2085 GL_API void GL_APIENTRY glMatrixIndexPointerOES(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) { 2086 GET_CTX() 2087 SET_ERROR_IF(!(ctx->getCaps()->GL_ARB_MATRIX_PALETTE && ctx->getCaps()->GL_ARB_VERTEX_BLEND),GL_INVALID_OPERATION); 2088 ctx->dispatcher().glMatrixIndexPointerARB(size,type,stride,pointer); 2089 } 2090 2091 GL_API void GL_APIENTRY glWeightPointerOES(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) { 2092 GET_CTX() 2093 SET_ERROR_IF(!(ctx->getCaps()->GL_ARB_MATRIX_PALETTE && ctx->getCaps()->GL_ARB_VERTEX_BLEND),GL_INVALID_OPERATION); 2094 ctx->dispatcher().glWeightPointerARB(size,type,stride,pointer); 2095 2096 } 2097 2098 GL_API void GL_APIENTRY glTexGenfOES (GLenum coord, GLenum pname, GLfloat param) { 2099 GET_CTX() 2100 SET_ERROR_IF(!GLEScmValidate::texGen(coord,pname),GL_INVALID_ENUM); 2101 if (coord == GL_TEXTURE_GEN_STR_OES) { 2102 ctx->dispatcher().glTexGenf(GL_S,pname,param); 2103 ctx->dispatcher().glTexGenf(GL_T,pname,param); 2104 ctx->dispatcher().glTexGenf(GL_R,pname,param); 2105 } 2106 else 2107 ctx->dispatcher().glTexGenf(coord,pname,param); 2108 } 2109 2110 GL_API void GL_APIENTRY glTexGenfvOES (GLenum coord, GLenum pname, const GLfloat *params) { 2111 GET_CTX() 2112 SET_ERROR_IF(!GLEScmValidate::texGen(coord,pname),GL_INVALID_ENUM); 2113 if (coord == GL_TEXTURE_GEN_STR_OES) { 2114 ctx->dispatcher().glTexGenfv(GL_S,pname,params); 2115 ctx->dispatcher().glTexGenfv(GL_T,pname,params); 2116 ctx->dispatcher().glTexGenfv(GL_R,pname,params); 2117 } 2118 else 2119 ctx->dispatcher().glTexGenfv(coord,pname,params); 2120 } 2121 GL_API void GL_APIENTRY glTexGeniOES (GLenum coord, GLenum pname, GLint param) { 2122 GET_CTX() 2123 SET_ERROR_IF(!GLEScmValidate::texGen(coord,pname),GL_INVALID_ENUM); 2124 if (coord == GL_TEXTURE_GEN_STR_OES) { 2125 ctx->dispatcher().glTexGeni(GL_S,pname,param); 2126 ctx->dispatcher().glTexGeni(GL_T,pname,param); 2127 ctx->dispatcher().glTexGeni(GL_R,pname,param); 2128 } 2129 else 2130 ctx->dispatcher().glTexGeni(coord,pname,param); 2131 } 2132 GL_API void GL_APIENTRY glTexGenivOES (GLenum coord, GLenum pname, const GLint *params) { 2133 GET_CTX() 2134 SET_ERROR_IF(!GLEScmValidate::texGen(coord,pname),GL_INVALID_ENUM); 2135 if (coord == GL_TEXTURE_GEN_STR_OES) { 2136 ctx->dispatcher().glTexGeniv(GL_S,pname,params); 2137 ctx->dispatcher().glTexGeniv(GL_T,pname,params); 2138 ctx->dispatcher().glTexGeniv(GL_R,pname,params); 2139 } 2140 else 2141 ctx->dispatcher().glTexGeniv(coord,pname,params); 2142 } 2143 GL_API void GL_APIENTRY glTexGenxOES (GLenum coord, GLenum pname, GLfixed param) { 2144 GET_CTX() 2145 SET_ERROR_IF(!GLEScmValidate::texGen(coord,pname),GL_INVALID_ENUM); 2146 if (coord == GL_TEXTURE_GEN_STR_OES) { 2147 ctx->dispatcher().glTexGenf(GL_S,pname,X2F(param)); 2148 ctx->dispatcher().glTexGenf(GL_T,pname,X2F(param)); 2149 ctx->dispatcher().glTexGenf(GL_R,pname,X2F(param)); 2150 } 2151 else 2152 ctx->dispatcher().glTexGenf(coord,pname,X2F(param)); 2153 } 2154 GL_API void GL_APIENTRY glTexGenxvOES (GLenum coord, GLenum pname, const GLfixed *params) { 2155 GLfloat tmpParams[1]; 2156 GET_CTX() 2157 SET_ERROR_IF(!GLEScmValidate::texGen(coord,pname),GL_INVALID_ENUM); 2158 tmpParams[0] = X2F(params[0]); 2159 if (coord == GL_TEXTURE_GEN_STR_OES) { 2160 ctx->dispatcher().glTexGenfv(GL_S,pname,tmpParams); 2161 ctx->dispatcher().glTexGenfv(GL_T,pname,tmpParams); 2162 ctx->dispatcher().glTexGenfv(GL_R,pname,tmpParams); 2163 } 2164 else 2165 ctx->dispatcher().glTexGenfv(coord,pname,tmpParams); 2166 } 2167 2168 GL_API void GL_APIENTRY glGetTexGenfvOES (GLenum coord, GLenum pname, GLfloat *params) { 2169 GET_CTX() 2170 if (coord == GL_TEXTURE_GEN_STR_OES) 2171 { 2172 GLfloat state_s = GL_FALSE; 2173 GLfloat state_t = GL_FALSE; 2174 GLfloat state_r = GL_FALSE; 2175 ctx->dispatcher().glGetTexGenfv(GL_S,pname,&state_s); 2176 ctx->dispatcher().glGetTexGenfv(GL_T,pname,&state_t); 2177 ctx->dispatcher().glGetTexGenfv(GL_R,pname,&state_r); 2178 *params = state_s && state_t && state_r ? GL_TRUE: GL_FALSE; 2179 } 2180 else 2181 ctx->dispatcher().glGetTexGenfv(coord,pname,params); 2182 2183 } 2184 GL_API void GL_APIENTRY glGetTexGenivOES (GLenum coord, GLenum pname, GLint *params) { 2185 GET_CTX() 2186 if (coord == GL_TEXTURE_GEN_STR_OES) 2187 { 2188 GLint state_s = GL_FALSE; 2189 GLint state_t = GL_FALSE; 2190 GLint state_r = GL_FALSE; 2191 ctx->dispatcher().glGetTexGeniv(GL_S,pname,&state_s); 2192 ctx->dispatcher().glGetTexGeniv(GL_T,pname,&state_t); 2193 ctx->dispatcher().glGetTexGeniv(GL_R,pname,&state_r); 2194 *params = state_s && state_t && state_r ? GL_TRUE: GL_FALSE; 2195 } 2196 else 2197 ctx->dispatcher().glGetTexGeniv(coord,pname,params); 2198 } 2199 2200 GL_API void GL_APIENTRY glGetTexGenxvOES (GLenum coord, GLenum pname, GLfixed *params) { 2201 GET_CTX() 2202 GLfloat tmpParams[1]; 2203 2204 if (coord == GL_TEXTURE_GEN_STR_OES) 2205 { 2206 GLfloat state_s = GL_FALSE; 2207 GLfloat state_t = GL_FALSE; 2208 GLfloat state_r = GL_FALSE; 2209 ctx->dispatcher().glGetTexGenfv(GL_TEXTURE_GEN_S,pname,&state_s); 2210 ctx->dispatcher().glGetTexGenfv(GL_TEXTURE_GEN_T,pname,&state_t); 2211 ctx->dispatcher().glGetTexGenfv(GL_TEXTURE_GEN_R,pname,&state_r); 2212 tmpParams[0] = state_s && state_t && state_r ? GL_TRUE: GL_FALSE; 2213 } 2214 else 2215 ctx->dispatcher().glGetTexGenfv(coord,pname,tmpParams); 2216 2217 params[0] = F2X(tmpParams[1]); 2218 } 2219 2220 template <class T, GLenum TypeName> 2221 void glDrawTexOES (T x, T y, T z, T width, T height) { 2222 GET_CTX() 2223 2224 SET_ERROR_IF((width<=0 || height<=0),GL_INVALID_VALUE); 2225 2226 ctx->drawValidate(); 2227 2228 int numClipPlanes; 2229 2230 GLint viewport[4] = {}; 2231 z = (z>1 ? 1 : (z<0 ? 0 : z)); 2232 2233 T vertices[4*3] = { 2234 x , y, z, 2235 x , static_cast<T>(y+height), z, 2236 static_cast<T>(x+width), static_cast<T>(y+height), z, 2237 static_cast<T>(x+width), y, z 2238 }; 2239 GLfloat texels[ctx->getMaxTexUnits()][4*2]; 2240 memset((void*)texels, 0, ctx->getMaxTexUnits()*4*2*sizeof(GLfloat)); 2241 2242 ctx->dispatcher().glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT); 2243 ctx->dispatcher().glPushAttrib(GL_TRANSFORM_BIT); 2244 2245 //setup projection matrix to draw in viewport aligned coordinates 2246 ctx->dispatcher().glMatrixMode(GL_PROJECTION); 2247 ctx->dispatcher().glPushMatrix(); 2248 ctx->dispatcher().glLoadIdentity(); 2249 ctx->dispatcher().glGetIntegerv(GL_VIEWPORT,viewport); 2250 ctx->dispatcher().glOrtho(viewport[0],viewport[0] + viewport[2],viewport[1],viewport[1]+viewport[3],0,-1); 2251 //setup texture matrix 2252 ctx->dispatcher().glMatrixMode(GL_TEXTURE); 2253 ctx->dispatcher().glPushMatrix(); 2254 ctx->dispatcher().glLoadIdentity(); 2255 //setup modelview matrix 2256 ctx->dispatcher().glMatrixMode(GL_MODELVIEW); 2257 ctx->dispatcher().glPushMatrix(); 2258 ctx->dispatcher().glLoadIdentity(); 2259 //backup vbo's 2260 int array_buffer,element_array_buffer; 2261 glGetIntegerv(GL_ARRAY_BUFFER_BINDING,&array_buffer); 2262 glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING,&element_array_buffer); 2263 ctx->dispatcher().glBindBuffer(GL_ARRAY_BUFFER,0); 2264 ctx->dispatcher().glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0); 2265 2266 //disable clip planes 2267 ctx->dispatcher().glGetIntegerv(GL_MAX_CLIP_PLANES,&numClipPlanes); 2268 for (int i=0;i<numClipPlanes;++i) 2269 ctx->dispatcher().glDisable(GL_CLIP_PLANE0+i); 2270 2271 int nTexPtrs = 0; 2272 for (int i=0;i<ctx->getMaxTexUnits();++i) { 2273 if (ctx->isTextureUnitEnabled(GL_TEXTURE0+i)) { 2274 TextureData * texData = NULL; 2275 unsigned int texname = ctx->getBindedTexture(GL_TEXTURE0+i,GL_TEXTURE_2D); 2276 ObjectLocalName tex = TextureLocalName(GL_TEXTURE_2D,texname); 2277 ctx->dispatcher().glClientActiveTexture(GL_TEXTURE0+i); 2278 ObjectDataPtr objData = ctx->shareGroup()->getObjectData(TEXTURE,tex); 2279 if (objData.Ptr()) { 2280 texData = (TextureData*)objData.Ptr(); 2281 //calculate texels 2282 texels[i][0] = (float)(texData->crop_rect[0])/(float)(texData->width); 2283 texels[i][1] = (float)(texData->crop_rect[1])/(float)(texData->height); 2284 2285 texels[i][2] = (float)(texData->crop_rect[0])/(float)(texData->width); 2286 texels[i][3] = (float)(texData->crop_rect[3]+texData->crop_rect[1])/(float)(texData->height); 2287 2288 texels[i][4] = (float)(texData->crop_rect[2]+texData->crop_rect[0])/(float)(texData->width); 2289 texels[i][5] = (float)(texData->crop_rect[3]+texData->crop_rect[1])/(float)(texData->height); 2290 2291 texels[i][6] = (float)(texData->crop_rect[2]+texData->crop_rect[0])/(float)(texData->width); 2292 texels[i][7] = (float)(texData->crop_rect[1])/(float)(texData->height); 2293 2294 ctx->dispatcher().glTexCoordPointer(2,GL_FLOAT,0,texels[i]); 2295 nTexPtrs++; 2296 } 2297 } 2298 } 2299 2300 if (nTexPtrs>0) { 2301 //draw rectangle - only if we have some textures enabled & ready 2302 ctx->dispatcher().glEnableClientState(GL_VERTEX_ARRAY); 2303 ctx->dispatcher().glVertexPointer(3,TypeName,0,vertices); 2304 ctx->dispatcher().glEnableClientState(GL_TEXTURE_COORD_ARRAY); 2305 ctx->dispatcher().glDrawArrays(GL_TRIANGLE_FAN,0,4); 2306 } 2307 2308 //restore vbo's 2309 ctx->dispatcher().glBindBuffer(GL_ARRAY_BUFFER,array_buffer); 2310 ctx->dispatcher().glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,element_array_buffer); 2311 2312 //restore matrix state 2313 2314 ctx->dispatcher().glMatrixMode(GL_MODELVIEW); 2315 ctx->dispatcher().glPopMatrix(); 2316 ctx->dispatcher().glMatrixMode(GL_TEXTURE); 2317 ctx->dispatcher().glPopMatrix(); 2318 ctx->dispatcher().glMatrixMode(GL_PROJECTION); 2319 ctx->dispatcher().glPopMatrix(); 2320 2321 ctx->dispatcher().glPopAttrib(); 2322 ctx->dispatcher().glPopClientAttrib(); 2323 } 2324 2325 GL_API void GL_APIENTRY glDrawTexsOES (GLshort x, GLshort y, GLshort z, GLshort width, GLshort height) { 2326 glDrawTexOES<GLshort,GL_SHORT>(x,y,z,width,height); 2327 } 2328 2329 GL_API void GL_APIENTRY glDrawTexiOES (GLint x, GLint y, GLint z, GLint width, GLint height) { 2330 glDrawTexOES<GLint,GL_INT>(x,y,z,width,height); 2331 } 2332 2333 GL_API void GL_APIENTRY glDrawTexfOES (GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height) { 2334 glDrawTexOES<GLfloat,GL_FLOAT>(x,y,z,width,height); 2335 } 2336 2337 GL_API void GL_APIENTRY glDrawTexxOES (GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height) { 2338 glDrawTexOES<GLfloat,GL_FLOAT>(X2F(x),X2F(y),X2F(z),X2F(width),X2F(height)); 2339 } 2340 2341 GL_API void GL_APIENTRY glDrawTexsvOES (const GLshort * coords) { 2342 glDrawTexOES<GLshort,GL_SHORT>(coords[0],coords[1],coords[2],coords[3],coords[4]); 2343 } 2344 2345 GL_API void GL_APIENTRY glDrawTexivOES (const GLint * coords) { 2346 glDrawTexOES<GLint,GL_INT>(coords[0],coords[1],coords[2],coords[3],coords[4]); 2347 } 2348 2349 GL_API void GL_APIENTRY glDrawTexfvOES (const GLfloat * coords) { 2350 glDrawTexOES<GLfloat,GL_FLOAT>(coords[0],coords[1],coords[2],coords[3],coords[4]); 2351 } 2352 2353 GL_API void GL_APIENTRY glDrawTexxvOES (const GLfixed * coords) { 2354 glDrawTexOES<GLfloat,GL_FLOAT>(X2F(coords[0]),X2F(coords[1]),X2F(coords[2]),X2F(coords[3]),X2F(coords[4])); 2355 } 2356