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