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
23 #define GL_GLEXT_PROTOTYPES
24 #include "GLEScmContext.h"
25 #include "GLEScmValidate.h"
26 #include "GLEScmUtils.h"
27 #include <GLcommon/TextureUtils.h>
28
29 #include <GLcommon/GLDispatch.h>
30 #include <GLcommon/GLconversion_macros.h>
31 #include <GLcommon/TextureData.h>
32 #include <GLcommon/TranslatorIfaces.h>
33 #include <GLcommon/FramebufferData.h>
34
35 #include "host-common/crash_reporter.h"
36 #include "host-common/logging.h"
37
38 #include <cmath>
39 #include <unordered_map>
40
41 #include <stdio.h>
42
43 #define DEBUG 0
44
45 #if DEBUG
46 #define GLES_CM_TRACE() fprintf(stderr, "%s\n", __func__); ERRCHECK()
47 #else
48 #define GLES_CM_TRACE()
49 #endif
50
51 #define GLES1_NAMESPACED(f) translator::gles1::f
52
53 namespace translator {
54 namespace gles1 {
55
56 GL_API void GL_APIENTRY glFlush( void);
57 GL_API void GL_APIENTRY glFinish( void);
58 GL_API GLenum GL_APIENTRY glGetError( void);
59
60 } // namespace gles1
61 } // namespace translator
62
63 extern "C" {
64
65 //decleration
66 static void initGLESx(bool isGles2Gles);
67 static void initContext(GLEScontext* ctx, ShareGroupPtr grp, bool nativeTextureDecompressionEnabled);
68 static void setMaxGlesVersion(GLESVersion version);
69 static void deleteGLESContext(GLEScontext* ctx);
70 static void setShareGroup(GLEScontext* ctx,ShareGroupPtr grp);
71 static GLEScontext* createGLESContext(int maj, int min,
72 GlobalNameSpace* globalNameSpace, android::base::Stream* stream);
73 static __translatorMustCastToProperFunctionPointerType getProcAddressGles1(const char* procName);
74 static bool vulkanInteropSupported();
75 }
76
77 /************************************** GLES EXTENSIONS *********************************************************/
78 typedef std::unordered_map<std::string, __translatorMustCastToProperFunctionPointerType> ProcTableMap;
79 ProcTableMap *s_glesExtensions = NULL;
80 /****************************************************************************************************************/
81
82 static EGLiface* s_eglIface = NULL;
83 static GLESiface s_glesIface = {
84 .initGLESx = initGLESx,
85 .createGLESContext = createGLESContext,
86 .initContext = initContext,
87 .setMaxGlesVersion = setMaxGlesVersion,
88 .deleteGLESContext = deleteGLESContext,
89 .flush = (FUNCPTR_NO_ARGS_RET_VOID)GLES1_NAMESPACED(glFlush),
90 .finish = (FUNCPTR_NO_ARGS_RET_VOID)GLES1_NAMESPACED(glFinish),
91 .getError = (FUNCPTR_NO_ARGS_RET_INT)GLES1_NAMESPACED(glGetError),
92 .setShareGroup = setShareGroup,
93 .getProcAddress = getProcAddressGles1,
94 .fenceSync = NULL,
95 .clientWaitSync = NULL,
96 .waitSync = NULL,
97 .deleteSync = NULL,
98 .preSaveTexture = NULL,
99 .postSaveTexture = NULL,
100 .saveTexture = NULL,
101 .createTexture = NULL,
102 .restoreTexture = NULL,
103 .deleteRbo = NULL,
104 .blitFromCurrentReadBufferANDROID = NULL,
105 .vulkanInteropSupported = vulkanInteropSupported,
106 .getSynciv = NULL,
107 };
108
109 #include <GLcommon/GLESmacros.h>
110
111 namespace translator {
112 namespace gles1 {
113
114 GL_API void GL_APIENTRY glBindTexture (GLenum target, GLuint texture);
115 GL_APICALL void GL_APIENTRY glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image);
116 GL_APICALL void GL_APIENTRY glEGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image);
117
118 GL_APICALL void GL_APIENTRY glVertexAttribPointerWithDataSize(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr, GLsizei dataSize);
119 GL_APICALL void GL_APIENTRY glVertexAttribIPointerWithDataSize(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* ptr, GLsizei dataSize);
120
121 GL_API void GL_APIENTRY glColorPointerWithDataSize( GLint size, GLenum type,
122 GLsizei stride, const GLvoid *pointer, GLsizei dataSize);
123 GL_API void GL_APIENTRY glNormalPointerWithDataSize(GLenum type,
124 GLsizei stride, const GLvoid *pointer, GLsizei dataSize);
125 GL_API void GL_APIENTRY glTexCoordPointerWithDataSize( GLint size, GLenum type,
126 GLsizei stride, const GLvoid *pointer, GLsizei dataSize);
127 GL_API void GL_APIENTRY glVertexPointerWithDataSize( GLint size, GLenum type,
128 GLsizei stride, const GLvoid *pointer, GLsizei dataSize);
129
130 GL_API void GL_APIENTRY glBlendEquationOES(GLenum mode);
131 GL_API void GL_APIENTRY glBlendEquationSeparateOES (GLenum modeRGB, GLenum modeAlpha);
132 GL_API void GL_APIENTRY glBlendFuncSeparateOES(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
133 GL_API void GL_APIENTRY glCurrentPaletteMatrixOES(GLuint index);
134 GL_API void GL_APIENTRY glLoadPaletteFromModelViewMatrixOES();
135 GL_API void GL_APIENTRY glMatrixIndexPointerOES(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
136 GL_API void GL_APIENTRY glWeightPointerOES(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
137 GL_API void GL_APIENTRY glDepthRangef( GLclampf zNear, GLclampf zFar);
138 GL_API void GL_APIENTRY glFrustumf( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar);
139 GL_API void GL_APIENTRY glOrthof( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar);
140 GL_API void GL_APIENTRY glClipPlanef( GLenum plane, const GLfloat *equation);
141 GL_API void GL_APIENTRY glGetClipPlanef( GLenum pname, GLfloat eqn[4]);
142 GL_API void GL_APIENTRY glClearDepthf( GLclampf depth);
143 GL_API void GL_APIENTRY glPointSizePointerOES( GLenum type, GLsizei stride, const GLvoid *pointer);
144 GL_API void GL_APIENTRY glTexGenfOES (GLenum coord, GLenum pname, GLfloat param);
145 GL_API void GL_APIENTRY glTexGenfvOES (GLenum coord, GLenum pname, const GLfloat *params);
146 GL_API void GL_APIENTRY glTexGeniOES (GLenum coord, GLenum pname, GLint param);
147 GL_API void GL_APIENTRY glTexGenivOES (GLenum coord, GLenum pname, const GLint *params);
148 GL_API void GL_APIENTRY glTexGenxOES (GLenum coord, GLenum pname, GLfixed param);
149 GL_API void GL_APIENTRY glTexGenxvOES (GLenum coord, GLenum pname, const GLfixed *params);
150 GL_API void GL_APIENTRY glGetTexGenfvOES (GLenum coord, GLenum pname, GLfloat *params);
151 GL_API void GL_APIENTRY glGetTexGenivOES (GLenum coord, GLenum pname, GLint *params);
152 GL_API void GL_APIENTRY glGetTexGenxvOES (GLenum coord, GLenum pname, GLfixed *params);
153 GL_API void GL_APIENTRY glDrawTexsOES (GLshort x, GLshort y, GLshort z, GLshort width, GLshort height);
154 GL_API void GL_APIENTRY glDrawTexiOES (GLint x, GLint y, GLint z, GLint width, GLint height);
155 GL_API void GL_APIENTRY glDrawTexfOES (GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height);
156 GL_API void GL_APIENTRY glDrawTexxOES (GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height);
157 GL_API void GL_APIENTRY glDrawTexsvOES (const GLshort * coords);
158 GL_API void GL_APIENTRY glDrawTexivOES (const GLint * coords);
159 GL_API void GL_APIENTRY glDrawTexfvOES (const GLfloat * coords);
160 GL_API void GL_APIENTRY glDrawTexfvOES (const GLfloat * coords);
161 GL_API void GL_APIENTRY glDrawTexxvOES (const GLfixed * coords);
162
163 GL_API void GLAPIENTRY glGenRenderbuffersOES(GLsizei n, GLuint *renderbuffers);
164 GL_API GLboolean GL_APIENTRY glIsRenderbufferOES(GLuint renderbuffer);
165 GL_API void GLAPIENTRY glBindRenderbufferOES(GLenum target, GLuint renderbuffer);
166 GL_API void GLAPIENTRY glDeleteRenderbuffersOES(GLsizei n, const GLuint *renderbuffers);
167 GL_API void GLAPIENTRY glRenderbufferStorageOES(GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
168 GL_API void GLAPIENTRY glGetRenderbufferParameterivOES(GLenum target, GLenum pname, GLint* params);
169
170 GL_API GLboolean GLAPIENTRY glIsFramebufferOES(GLuint framebuffer);
171 GL_API void GLAPIENTRY glBindFramebufferOES(GLenum target, GLuint framebuffer);
172 GL_API void GLAPIENTRY glDeleteFramebuffersOES(GLsizei n, const GLuint *framebuffers);
173 GL_API void GLAPIENTRY glGenFramebuffersOES(GLsizei n, GLuint *framebuffers);
174 GL_API void GLAPIENTRY glFramebufferTexture2DOES(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
175 GL_API void GLAPIENTRY glFramebufferRenderbufferOES(GLenum target, GLenum attachment,GLenum renderbuffertarget, GLuint renderbuffer);
176 GL_API void GLAPIENTRY glGetFramebufferAttachmentParameterivOES(GLenum target, GLenum attachment, GLenum pname, GLint *params);
177
178 GL_API GLenum GLAPIENTRY glCheckFramebufferStatusOES(GLenum target);
179
180 GL_API void GL_APIENTRY glGenerateMipmapOES(GLenum target);
181
182 } // namespace gles1
183 } // namespace translator
184
185 extern "C" {
186
setMaxGlesVersion(GLESVersion version)187 static void setMaxGlesVersion(GLESVersion version) {
188 GLEScmContext::setMaxGlesVersion(version);
189 }
190
191 #define ERRCHECK() { \
192 GLint err = ctx->dispatcher().glGetError(); \
193 if (err) fprintf(stderr, "%s:%d GL err 0x%x\n", __func__, __LINE__, err); } \
194
195 #define CORE_ERR_FORWARD() \
196 if (isCoreProfile()) { \
197 GLint __core_error = ctx->getErrorCoreProfile(); \
198 SET_ERROR_IF(__core_error, __core_error); \
199 } \
200
initGLESx(bool isGles2Gles)201 static void initGLESx(bool isGles2Gles) {
202 setGles2Gles(isGles2Gles);
203 return;
204 }
205
initContext(GLEScontext * ctx,ShareGroupPtr grp,bool nativeTextureDecompressionEnabled)206 static void initContext(GLEScontext* ctx, ShareGroupPtr grp, bool nativeTextureDecompressionEnabled) {
207 setCoreProfile(ctx->isCoreProfile());
208 GLEScmContext::initGlobal(s_eglIface);
209
210 // TODO: Properly restore GLES1 context from snapshot.
211 // This is just to avoid a crash.
212 if (ctx->needRestore()) {
213 // TODO: metrics for GLES1 snapshots
214 fprintf(stderr,
215 "Warning: restoring GLES1 context from snapshot. App "
216 "may need reloading.\n");
217 }
218
219 if (!ctx->shareGroup()) {
220 ctx->setShareGroup(grp);
221 }
222 if (!ctx->isInitialized()) {
223 ctx->init(nativeTextureDecompressionEnabled);
224 translator::gles1::glBindTexture(GL_TEXTURE_2D,0);
225 translator::gles1::glBindTexture(GL_TEXTURE_CUBE_MAP_OES,0);
226 }
227 if (ctx->needRestore()) {
228 ctx->restore();
229 }
230 }
231
createGLESContext(int maj,int min,GlobalNameSpace * globalNameSpace,android::base::Stream * stream)232 static GLEScontext* createGLESContext(int maj, int min,
233 GlobalNameSpace* globalNameSpace, android::base::Stream* stream) {
234 (void)stream;
235 return new GLEScmContext(maj, min, globalNameSpace, stream);
236 }
237
deleteGLESContext(GLEScontext * ctx)238 static void deleteGLESContext(GLEScontext* ctx) {
239 if(ctx) delete ctx;
240 }
241
setShareGroup(GLEScontext * ctx,ShareGroupPtr grp)242 static void setShareGroup(GLEScontext* ctx,ShareGroupPtr grp) {
243 if(ctx) {
244 ctx->setShareGroup(grp);
245 }
246 }
247
vulkanInteropSupported()248 static bool vulkanInteropSupported() {
249 return GLEScontext::vulkanInteropSupported();
250 }
251
getProcAddressGles1(const char * procName)252 static __translatorMustCastToProperFunctionPointerType getProcAddressGles1(const char* procName) {
253 GET_CTX_RET(NULL)
254 ctx->getGlobalLock();
255 static bool proc_table_initialized = false;
256 if (!proc_table_initialized) {
257 proc_table_initialized = true;
258 if (!s_glesExtensions)
259 s_glesExtensions = new ProcTableMap();
260 else
261 s_glesExtensions->clear();
262
263 (*s_glesExtensions)["glEGLImageTargetTexture2DOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glEGLImageTargetTexture2DOES);
264 (*s_glesExtensions)["glEGLImageTargetRenderbufferStorageOES"]=(__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glEGLImageTargetRenderbufferStorageOES);
265 (*s_glesExtensions)["glBlendEquationSeparateOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glBlendEquationSeparateOES);
266 (*s_glesExtensions)["glBlendFuncSeparateOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glBlendFuncSeparateOES);
267 (*s_glesExtensions)["glBlendEquationOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glBlendEquationOES);
268
269 if (ctx->getCaps()->GL_ARB_MATRIX_PALETTE && ctx->getCaps()->GL_ARB_VERTEX_BLEND) {
270 (*s_glesExtensions)["glCurrentPaletteMatrixOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glCurrentPaletteMatrixOES);
271 (*s_glesExtensions)["glLoadPaletteFromModelViewMatrixOES"]=(__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glLoadPaletteFromModelViewMatrixOES);
272 (*s_glesExtensions)["glMatrixIndexPointerOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glMatrixIndexPointerOES);
273 (*s_glesExtensions)["glWeightPointerOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glWeightPointerOES);
274 }
275 (*s_glesExtensions)["glDepthRangefOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glDepthRangef);
276 (*s_glesExtensions)["glFrustumfOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glFrustumf);
277 (*s_glesExtensions)["glOrthofOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glOrthof);
278 (*s_glesExtensions)["glClipPlanefOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glClipPlanef);
279 (*s_glesExtensions)["glGetClipPlanefOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glGetClipPlanef);
280 (*s_glesExtensions)["glClearDepthfOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glClearDepthf);
281 (*s_glesExtensions)["glPointSizePointerOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glPointSizePointerOES);
282 (*s_glesExtensions)["glTexGenfOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glTexGenfOES);
283 (*s_glesExtensions)["glTexGenfvOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glTexGenfvOES);
284 (*s_glesExtensions)["glTexGeniOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glTexGeniOES);
285 (*s_glesExtensions)["glTexGenivOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glTexGenivOES);
286 (*s_glesExtensions)["glTexGenxOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glTexGenxOES);
287 (*s_glesExtensions)["glTexGenxvOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glTexGenxvOES);
288 (*s_glesExtensions)["glGetTexGenfvOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glGetTexGenfvOES);
289 (*s_glesExtensions)["glGetTexGenivOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glGetTexGenivOES);
290 (*s_glesExtensions)["glGetTexGenxvOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glGetTexGenxvOES);
291 if (ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT) {
292 (*s_glesExtensions)["glIsRenderbufferOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glIsRenderbufferOES);
293 (*s_glesExtensions)["glBindRenderbufferOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glBindRenderbufferOES);
294 (*s_glesExtensions)["glDeleteRenderbuffersOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glDeleteRenderbuffersOES);
295 (*s_glesExtensions)["glGenRenderbuffersOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glGenRenderbuffersOES);
296 (*s_glesExtensions)["glRenderbufferStorageOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glRenderbufferStorageOES);
297 (*s_glesExtensions)["glGetRenderbufferParameterivOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glGetRenderbufferParameterivOES);
298 (*s_glesExtensions)["glIsFramebufferOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glIsFramebufferOES);
299 (*s_glesExtensions)["glBindFramebufferOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glBindFramebufferOES);
300 (*s_glesExtensions)["glDeleteFramebuffersOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glDeleteFramebuffersOES);
301 (*s_glesExtensions)["glGenFramebuffersOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glGenFramebuffersOES);
302 (*s_glesExtensions)["glCheckFramebufferStatusOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glCheckFramebufferStatusOES);
303 (*s_glesExtensions)["glFramebufferTexture2DOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glFramebufferTexture2DOES);
304 (*s_glesExtensions)["glFramebufferRenderbufferOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glFramebufferRenderbufferOES);
305 (*s_glesExtensions)["glGetFramebufferAttachmentParameterivOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glGetFramebufferAttachmentParameterivOES);
306 (*s_glesExtensions)["glGenerateMipmapOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glGenerateMipmapOES);
307 }
308 (*s_glesExtensions)["glDrawTexsOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glDrawTexsOES);
309 (*s_glesExtensions)["glDrawTexiOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glDrawTexiOES);
310 (*s_glesExtensions)["glDrawTexfOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glDrawTexfOES);
311 (*s_glesExtensions)["glDrawTexxOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glDrawTexxOES);
312 (*s_glesExtensions)["glDrawTexsvOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glDrawTexsvOES);
313 (*s_glesExtensions)["glDrawTexivOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glDrawTexivOES);
314 (*s_glesExtensions)["glDrawTexfvOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glDrawTexfvOES);
315 (*s_glesExtensions)["glDrawTexxvOES"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glDrawTexxvOES);
316
317 // Vertex array functions with size for snapshot
318 (*s_glesExtensions)["glColorPointerWithDataSize"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glColorPointerWithDataSize);
319 (*s_glesExtensions)["glNormalPointerWithDataSize"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glNormalPointerWithDataSize);
320 (*s_glesExtensions)["glTexCoordPointerWithDataSize"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glTexCoordPointerWithDataSize);
321 (*s_glesExtensions)["glVertexPointerWithDataSize"] = (__translatorMustCastToProperFunctionPointerType)GLES1_NAMESPACED(glVertexPointerWithDataSize);
322 }
323 __translatorMustCastToProperFunctionPointerType ret=NULL;
324 ProcTableMap::iterator val = s_glesExtensions->find(procName);
325 if (val!=s_glesExtensions->end())
326 ret = val->second;
327 ctx->releaseGlobalLock();
328
329 return ret;
330 }
331
332 GL_APICALL GLESiface* GL_APIENTRY static_translator_glescm_getIfaces(const EGLiface* eglIface);
333
static_translator_glescm_getIfaces(const EGLiface * eglIface)334 GLESiface* static_translator_glescm_getIfaces(const EGLiface* eglIface) {
335 s_eglIface = (EGLiface*)eglIface;
336 return &s_glesIface;
337 }
338
339 } // extern "C"
340
getTextureData(ObjectLocalName tex)341 static TextureData* getTextureData(ObjectLocalName tex){
342 GET_CTX_RET(NULL);
343
344 if (!ctx->shareGroup()->isObject(NamedObjectType::TEXTURE, tex)) {
345 return NULL;
346 }
347
348 TextureData *texData = NULL;
349 auto objData =
350 ctx->shareGroup()->getObjectData(NamedObjectType::TEXTURE, tex);
351 if(!objData){
352 texData = new TextureData();
353 ctx->shareGroup()->setObjectData(NamedObjectType::TEXTURE, tex,
354 ObjectDataPtr(texData));
355 } else {
356 texData = (TextureData*)objData;
357 }
358 return texData;
359 }
360
getTextureTargetData(GLenum target)361 static TextureData* getTextureTargetData(GLenum target){
362 GET_CTX_RET(NULL);
363 unsigned int tex = ctx->getBindedTexture(target);
364 return getTextureData(ctx->getTextureLocalName(target,tex));
365 }
366
367 namespace translator {
368 namespace gles1 {
369
glIsBuffer(GLuint buffer)370 GL_API GLboolean GL_APIENTRY glIsBuffer(GLuint buffer) {
371 GET_CTX_RET(GL_FALSE)
372 GLES_CM_TRACE()
373
374 if(buffer && ctx->shareGroup().get()) {
375 auto objData = ctx->shareGroup()->getObjectData(
376 NamedObjectType::VERTEXBUFFER, buffer);
377 return objData ? ((GLESbuffer*)objData)->wasBinded()
378 : GL_FALSE;
379 }
380 return GL_FALSE;
381 }
382
glIsEnabled(GLenum cap)383 GL_API GLboolean GL_APIENTRY glIsEnabled( GLenum cap) {
384 GET_CTX_CM_RET(GL_FALSE)
385 GLES_CM_TRACE()
386 RET_AND_SET_ERROR_IF(!GLEScmValidate::capability(cap,ctx->getMaxLights(),ctx->getMaxClipPlanes()),GL_INVALID_ENUM,GL_FALSE);
387
388 if (cap == GL_POINT_SIZE_ARRAY_OES)
389 return ctx->isArrEnabled(cap);
390 else if (cap==GL_TEXTURE_GEN_STR_OES)
391 return (ctx->dispatcher().glIsEnabled(GL_TEXTURE_GEN_S) &&
392 ctx->dispatcher().glIsEnabled(GL_TEXTURE_GEN_T) &&
393 ctx->dispatcher().glIsEnabled(GL_TEXTURE_GEN_R));
394 else
395 return ctx->dispatcher().glIsEnabled(cap);
396 }
397
glIsTexture(GLuint texture)398 GL_API GLboolean GL_APIENTRY glIsTexture( GLuint texture) {
399 GET_CTX_RET(GL_FALSE)
400 GLES_CM_TRACE()
401
402 if(texture == 0) // Special case
403 return GL_FALSE;
404
405 TextureData* tex = getTextureData(texture);
406 return tex ? tex->wasBound : GL_FALSE;
407 }
408
glGetError(void)409 GL_API GLenum GL_APIENTRY glGetError(void) {
410 GET_CTX_RET(GL_NO_ERROR)
411 GLES_CM_TRACE()
412 GLenum err = ctx->getGLerror();
413 if(err != GL_NO_ERROR) {
414 ctx->setGLerror(GL_NO_ERROR);
415 return err;
416 }
417
418 return ctx->dispatcher().glGetError();
419 }
420
glGetString(GLenum name)421 GL_API const GLubyte * GL_APIENTRY glGetString( GLenum name) {
422 GET_CTX_RET(NULL)
423 GLES_CM_TRACE()
424 switch(name) {
425 case GL_VENDOR:
426 return (const GLubyte*)ctx->getVendorString(true /* is gles1 */);
427 case GL_RENDERER:
428 return (const GLubyte*)ctx->getRendererString(true /* is gles1 */);
429 case GL_VERSION:
430 return (const GLubyte*)ctx->getVersionString(true /* is gles1 */);
431 case GL_EXTENSIONS:
432 return (const GLubyte*)ctx->getExtensionString(true /* is gles1 */);
433 default:
434 RET_AND_SET_ERROR_IF(true,GL_INVALID_ENUM,NULL);
435 }
436 }
437
glActiveTexture(GLenum texture)438 GL_API void GL_APIENTRY glActiveTexture( GLenum texture) {
439 GET_CTX_CM()
440 GLES_CM_TRACE()
441 SET_ERROR_IF(!GLEScmValidate::textureEnum(texture,ctx->getMaxTexUnits()),GL_INVALID_ENUM);
442 ctx->setActiveTexture(texture);
443 ctx->dispatcher().glActiveTexture(texture);
444 }
445
glAlphaFunc(GLenum func,GLclampf ref)446 GL_API void GL_APIENTRY glAlphaFunc( GLenum func, GLclampf ref) {
447 GET_CTX()
448 GLES_CM_TRACE()
449 SET_ERROR_IF(!GLEScmValidate::alphaFunc(func),GL_INVALID_ENUM);
450 ctx->dispatcher().glAlphaFunc(func,ref);
451 }
452
453
glAlphaFuncx(GLenum func,GLclampx ref)454 GL_API void GL_APIENTRY glAlphaFuncx( GLenum func, GLclampx ref) {
455 GET_CTX()
456 GLES_CM_TRACE()
457 SET_ERROR_IF(!GLEScmValidate::alphaFunc(func),GL_INVALID_ENUM);
458 ctx->dispatcher().glAlphaFunc(func,X2F(ref));
459 }
460
461
glBindBuffer(GLenum target,GLuint buffer)462 GL_API void GL_APIENTRY glBindBuffer( GLenum target, GLuint buffer) {
463 GET_CTX()
464 GLES_CM_TRACE()
465 SET_ERROR_IF(!GLEScmValidate::bufferTarget(target),GL_INVALID_ENUM);
466
467 //if buffer wasn't generated before,generate one
468 if (buffer && ctx->shareGroup().get() &&
469 !ctx->shareGroup()->isObject(NamedObjectType::VERTEXBUFFER, buffer)) {
470 ctx->shareGroup()->genName(NamedObjectType::VERTEXBUFFER, buffer);
471 ctx->shareGroup()->setObjectData(NamedObjectType::VERTEXBUFFER, buffer,
472 ObjectDataPtr(new GLESbuffer()));
473 }
474 ctx->bindBuffer(target,buffer);
475 ctx->dispatcher().glBindBuffer(target, ctx->shareGroup()->getGlobalName(
476 NamedObjectType::VERTEXBUFFER, buffer));
477 if (buffer) {
478 GLESbuffer* vbo =
479 (GLESbuffer*)ctx->shareGroup()
480 ->getObjectData(NamedObjectType::VERTEXBUFFER, buffer);
481 vbo->setBinded();
482 }
483 }
484
485
glBindTexture(GLenum target,GLuint texture)486 GL_API void GL_APIENTRY glBindTexture( GLenum target, GLuint texture) {
487 GET_CTX_CM()
488 GLES_CM_TRACE()
489 SET_ERROR_IF(!GLEScmValidate::textureTarget(target),GL_INVALID_ENUM)
490
491 //for handling default texture (0)
492 ObjectLocalName localTexName = ctx->getTextureLocalName(target,texture);
493
494 GLuint globalTextureName = localTexName;
495 if(ctx->shareGroup().get()){
496 globalTextureName = ctx->shareGroup()->getGlobalName(
497 NamedObjectType::TEXTURE, localTexName);
498 //if texture wasn't generated before,generate one
499 if(!globalTextureName){
500 ctx->shareGroup()->genName(NamedObjectType::TEXTURE, localTexName);
501 globalTextureName = ctx->shareGroup()->getGlobalName(
502 NamedObjectType::TEXTURE, localTexName);
503 }
504
505 TextureData* texData = getTextureData(localTexName);
506 if (texData->target==0)
507 texData->setTarget(target);
508 //if texture was already bound to another target
509 SET_ERROR_IF(ctx->GLTextureTargetToLocal(texData->target) != ctx->GLTextureTargetToLocal(target), GL_INVALID_OPERATION);
510 texData->setGlobalName(globalTextureName);
511 if (!texData->wasBound) {
512 texData->resetSaveableTexture();
513 }
514 texData->wasBound = true;
515 }
516
517 ctx->setBindedTexture(target, texture, globalTextureName);
518 ctx->dispatcher().glBindTexture(target, globalTextureName);
519 }
520
glBlendFunc(GLenum sfactor,GLenum dfactor)521 GL_API void GL_APIENTRY glBlendFunc( GLenum sfactor, GLenum dfactor) {
522 GET_CTX()
523 GLES_CM_TRACE()
524 SET_ERROR_IF(!GLEScmValidate::blendSrc(sfactor) || !GLEScmValidate::blendDst(dfactor),GL_INVALID_ENUM)
525 ctx->setBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
526 ctx->dispatcher().glBlendFunc(sfactor,dfactor);
527 }
528
glBufferData(GLenum target,GLsizeiptr size,const GLvoid * data,GLenum usage)529 GL_API void GL_APIENTRY glBufferData( GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage) {
530 GET_CTX()
531 GLES_CM_TRACE()
532 SET_ERROR_IF(!GLEScmValidate::bufferTarget(target),GL_INVALID_ENUM);
533 SET_ERROR_IF(!ctx->isBindedBuffer(target),GL_INVALID_OPERATION);
534 ctx->setBufferData(target,size,data,usage);
535 ctx->dispatcher().glBufferData(target, size, data, usage);
536 }
537
glBufferSubData(GLenum target,GLintptr offset,GLsizeiptr size,const GLvoid * data)538 GL_API void GL_APIENTRY glBufferSubData( GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data) {
539 GET_CTX()
540 GLES_CM_TRACE()
541 SET_ERROR_IF(!ctx->isBindedBuffer(target),GL_INVALID_OPERATION);
542 SET_ERROR_IF(!GLEScmValidate::bufferTarget(target),GL_INVALID_ENUM);
543 SET_ERROR_IF(!ctx->setBufferSubData(target,offset,size,data),GL_INVALID_VALUE);
544 ctx->dispatcher().glBufferSubData(target, offset, size, data);
545 }
546
glClear(GLbitfield mask)547 GL_API void GL_APIENTRY glClear( GLbitfield mask) {
548 GET_CTX()
549 GLES_CM_TRACE()
550 ERRCHECK()
551 ctx->drawValidate();
552 ERRCHECK()
553 ctx->dispatcher().glClear(mask);
554 ERRCHECK()
555 }
556
glClearColor(GLclampf red,GLclampf green,GLclampf blue,GLclampf alpha)557 GL_API void GL_APIENTRY glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) {
558 GET_CTX()
559 GLES_CM_TRACE()
560 ctx->setClearColor(red, green, blue, alpha);
561 ctx->dispatcher().glClearColor(red,green,blue,alpha);
562 }
563
glClearColorx(GLclampx red,GLclampx green,GLclampx blue,GLclampx alpha)564 GL_API void GL_APIENTRY glClearColorx( GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha) {
565 GET_CTX()
566 GLES_CM_TRACE()
567 ctx->setClearColor(X2F(red),X2F(green),X2F(blue),X2F(alpha));
568 ctx->dispatcher().glClearColor(X2F(red),X2F(green),X2F(blue),X2F(alpha));
569 }
570
571
glClearDepthf(GLclampf depth)572 GL_API void GL_APIENTRY glClearDepthf( GLclampf depth) {
573 GET_CTX()
574 GLES_CM_TRACE()
575 ctx->setClearDepth(depth);
576 ctx->dispatcher().glClearDepth(depth);
577 }
578
glClearDepthx(GLclampx depth)579 GL_API void GL_APIENTRY glClearDepthx( GLclampx depth) {
580 GET_CTX()
581 GLES_CM_TRACE()
582 ctx->setClearDepth(X2F(depth));
583 ctx->dispatcher().glClearDepth(X2F(depth));
584 }
585
glClearStencil(GLint s)586 GL_API void GL_APIENTRY glClearStencil( GLint s) {
587 GET_CTX()
588 GLES_CM_TRACE()
589 ctx->setClearStencil(s);
590 ctx->dispatcher().glClearStencil(s);
591 }
592
glClientActiveTexture(GLenum texture)593 GL_API void GL_APIENTRY glClientActiveTexture( GLenum texture) {
594 GET_CTX_CM()
595 GLES_CM_TRACE()
596 SET_ERROR_IF(!GLEScmValidate::textureEnum(texture,ctx->getMaxTexUnits()),GL_INVALID_ENUM);
597 ctx->clientActiveTexture(texture);
598 }
599
glClipPlanef(GLenum plane,const GLfloat * equation)600 GL_API void GL_APIENTRY glClipPlanef( GLenum plane, const GLfloat *equation) {
601 GET_CTX()
602 GLES_CM_TRACE()
603 GLdouble tmpEquation[4];
604
605 for(int i = 0; i < 4; i++) {
606 tmpEquation[i] = static_cast<GLdouble>(equation[i]);
607 }
608 ctx->dispatcher().glClipPlane(plane,tmpEquation);
609 }
610
glClipPlanex(GLenum plane,const GLfixed * equation)611 GL_API void GL_APIENTRY glClipPlanex( GLenum plane, const GLfixed *equation) {
612 GET_CTX()
613 GLES_CM_TRACE()
614 GLdouble tmpEquation[4];
615 for(int i = 0; i < 4; i++) {
616 tmpEquation[i] = X2D(equation[i]);
617 }
618 ctx->dispatcher().glClipPlane(plane,tmpEquation);
619 }
620
glColor4f(GLfloat red,GLfloat green,GLfloat blue,GLfloat alpha)621 GL_API void GL_APIENTRY glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) {
622 GET_CTX_CM()
623 GLES_CM_TRACE()
624 ctx->color4f(red, green, blue, alpha);
625 }
626
glColor4ub(GLubyte red,GLubyte green,GLubyte blue,GLubyte alpha)627 GL_API void GL_APIENTRY glColor4ub( GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha) {
628 GET_CTX_CM()
629 GLES_CM_TRACE()
630 ctx->color4ub(red, green, blue, alpha);
631 }
632
glColor4x(GLfixed red,GLfixed green,GLfixed blue,GLfixed alpha)633 GL_API void GL_APIENTRY glColor4x( GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha) {
634 GET_CTX_CM()
635 GLES_CM_TRACE()
636 ctx->color4f(X2F(red),X2F(green),X2F(blue),X2F(alpha));
637 }
638
glColorMask(GLboolean red,GLboolean green,GLboolean blue,GLboolean alpha)639 GL_API void GL_APIENTRY glColorMask( GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) {
640 GET_CTX()
641 GLES_CM_TRACE()
642 ctx->setColorMask(red, green, blue, alpha);
643 ctx->dispatcher().glColorMask(red,green,blue,alpha);
644 }
645
glColorPointer(GLint size,GLenum type,GLsizei stride,const GLvoid * pointer)646 GL_API void GL_APIENTRY glColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) {
647 GET_CTX_CM()
648 GLES_CM_TRACE()
649 SET_ERROR_IF(!GLEScmValidate::colorPointerParams(size,stride),GL_INVALID_VALUE);
650 SET_ERROR_IF(!GLEScmValidate::colorPointerType(type),GL_INVALID_ENUM);
651 ctx->setPointer(GL_COLOR_ARRAY,size,type,stride,pointer, 0);
652 }
653
glColorPointerWithDataSize(GLint size,GLenum type,GLsizei stride,const GLvoid * pointer,GLsizei dataSize)654 GL_API void GL_APIENTRY glColorPointerWithDataSize( GLint size, GLenum type,
655 GLsizei stride, const GLvoid *pointer, GLsizei dataSize) {
656 GET_CTX_CM()
657 GLES_CM_TRACE()
658 SET_ERROR_IF(!GLEScmValidate::colorPointerParams(size,stride),GL_INVALID_VALUE);
659 SET_ERROR_IF(!GLEScmValidate::colorPointerType(type),GL_INVALID_ENUM);
660 ctx->setPointer(GL_COLOR_ARRAY,size,type,stride,pointer, dataSize);
661 }
662
maxMipmapLevel(GLsizei width,GLsizei height)663 static int maxMipmapLevel(GLsizei width, GLsizei height) {
664 // + 0.5 for potential floating point rounding issue
665 return log2(std::max(width, height) + 0.5);
666 }
667
s_glInitTexImage2D(GLenum target,GLint level,GLint internalformat,GLsizei width,GLsizei height,GLint border,GLenum * format,GLenum * type,GLint * internalformat_out,bool * needAutoMipmap)668 void s_glInitTexImage2D(GLenum target, GLint level, GLint internalformat,
669 GLsizei width, GLsizei height, GLint border, GLenum* format,
670 GLenum* type, GLint* internalformat_out,
671 bool* needAutoMipmap) {
672 GET_CTX();
673
674 if (ctx->shareGroup().get()) {
675 TextureData *texData = getTextureTargetData(target);
676
677 if (texData) {
678 texData->hasStorage = true;
679 if (needAutoMipmap) {
680 *needAutoMipmap = texData->requiresAutoMipmap;
681 }
682 if (texData->requiresAutoMipmap) {
683 texData->setMipmapLevelAtLeast(maxMipmapLevel(width, height));
684 } else {
685 texData->setMipmapLevelAtLeast(
686 static_cast<unsigned int>(level));
687 }
688 }
689
690 if (texData && level == 0) {
691 assert(texData->target == GL_TEXTURE_2D ||
692 texData->target == GL_TEXTURE_CUBE_MAP);
693 texData->internalFormat = internalformat;
694 if (internalformat_out) {
695 *internalformat_out = texData->internalFormat;
696 }
697 texData->width = width;
698 texData->height = height;
699 texData->border = border;
700 if (format) texData->format = *format;
701 if (type) texData->type = *type;
702
703 if (texData->sourceEGLImage != 0) {
704 //
705 // This texture was a target of EGLImage,
706 // but now it is re-defined so we need to
707 // re-generate global texture name for it.
708 //
709 unsigned int tex = ctx->getBindedTexture(target);
710 ctx->shareGroup()->genName(NamedObjectType::TEXTURE, tex,
711 false);
712 unsigned int globalTextureName =
713 ctx->shareGroup()->getGlobalName(
714 NamedObjectType::TEXTURE, tex);
715 ctx->dispatcher().glBindTexture(GL_TEXTURE_2D,
716 globalTextureName);
717 texData->sourceEGLImage = 0;
718 texData->setGlobalName(globalTextureName);
719 }
720 texData->resetSaveableTexture();
721 }
722 texData->makeDirty();
723 }
724 }
725
726 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);
727
glCompressedTexImage2D(GLenum target,GLint level,GLenum internalformat,GLsizei width,GLsizei height,GLint border,GLsizei imageSize,const GLvoid * data)728 GL_API void GL_APIENTRY glCompressedTexImage2D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data) {
729 GET_CTX_CM()
730 GLES_CM_TRACE()
731 SET_ERROR_IF(!GLEScmValidate::textureTargetEx(target),GL_INVALID_ENUM);
732 SET_ERROR_IF(!data,GL_INVALID_OPERATION);
733
734 if (shouldPassthroughCompressedFormat(ctx, internalformat)) {
735 doCompressedTexImage2DNative(ctx, target, level, internalformat, width,
736 height, border, imageSize, data);
737 } else {
738 doCompressedTexImage2D(ctx, target, level, internalformat,
739 width, height, border,
740 imageSize, data, glTexImage2D);
741 }
742
743 TextureData* texData = getTextureTargetData(target);
744 if (texData) {
745 texData->compressed = true;
746 texData->compressedFormat = internalformat;
747 if (shouldPassthroughCompressedFormat(ctx, internalformat)) {
748 texData->internalFormat = internalformat;
749 }
750 }
751 }
752
glCompressedTexSubImage2D(GLenum target,GLint level,GLint xoffset,GLint yoffset,GLsizei width,GLsizei height,GLenum format,GLsizei imageSize,const GLvoid * data)753 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) {
754 GET_CTX_CM()
755 GLES_CM_TRACE()
756 SET_ERROR_IF(!(GLEScmValidate::texCompImgFrmt(format) && GLEScmValidate::textureTargetEx(target)),GL_INVALID_ENUM);
757 SET_ERROR_IF(level < 0 || level > log2(ctx->getMaxTexSize()),GL_INVALID_VALUE)
758 SET_ERROR_IF(!data,GL_INVALID_OPERATION);
759
760 if (shouldPassthroughCompressedFormat(ctx, format)) {
761 doCompressedTexSubImage2DNative(ctx, target, level, xoffset, yoffset, width,
762 height, format, imageSize, data);
763 } else {
764 GLenum uncompressedFrmt;
765 unsigned char* uncompressed = uncompressTexture(format,uncompressedFrmt,width,height,imageSize,data,level);
766 ctx->dispatcher().glTexSubImage2D(target,level,xoffset,yoffset,width,height,uncompressedFrmt,GL_UNSIGNED_BYTE,uncompressed);
767 delete uncompressed;
768 }
769
770 TextureData* texData = getTextureTargetData(target);
771 if (texData) {
772 texData->setMipmapLevelAtLeast(level);
773 texData->makeDirty();
774 }
775 }
776
glCopyTexImage2D(GLenum target,GLint level,GLenum internalformat,GLint x,GLint y,GLsizei width,GLsizei height,GLint border)777 GL_API void GL_APIENTRY glCopyTexImage2D( GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) {
778 GET_CTX()
779 GLES_CM_TRACE()
780 SET_ERROR_IF(!(GLEScmValidate::pixelFrmt(ctx,internalformat)
781 && GLEScmValidate::textureTargetEx(target)),GL_INVALID_ENUM);
782 SET_ERROR_IF(border != 0,GL_INVALID_VALUE);
783
784 GLenum format = baseFormatOfInternalFormat((GLint)internalformat);
785 GLenum type = accurateTypeOfInternalFormat((GLint)internalformat);
786 s_glInitTexImage2D(
787 target, level, internalformat, width, height, border,
788 &format, &type, (GLint*)&internalformat, nullptr);
789
790 TextureData* texData = getTextureTargetData(target);
791 if (texData && isCoreProfile() &&
792 isCoreProfileEmulatedFormat(texData->format)) {
793 GLEScontext::prepareCoreProfileEmulatedTexture(
794 getTextureTargetData(target),
795 false, target, format, type,
796 (GLint*)&internalformat, &format);
797 ctx->copyTexImageWithEmulation(
798 texData, false, target, level, internalformat,
799 0, 0, x, y, width, height, border);
800 } else {
801 ctx->dispatcher().glCopyTexImage2D(
802 target, level, internalformat,
803 x, y, width, height, border);
804 }
805 }
806
glCopyTexSubImage2D(GLenum target,GLint level,GLint xoffset,GLint yoffset,GLint x,GLint y,GLsizei width,GLsizei height)807 GL_API void GL_APIENTRY glCopyTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) {
808 GET_CTX()
809 GLES_CM_TRACE()
810 SET_ERROR_IF(!GLEScmValidate::textureTargetEx(target),GL_INVALID_ENUM);
811 if (ctx->shareGroup().get()){
812 TextureData *texData = getTextureTargetData(target);
813 SET_ERROR_IF(!texData, GL_INVALID_OPERATION);
814 texData->makeDirty();
815 }
816 ctx->dispatcher().glCopyTexSubImage2D(target,level,xoffset,yoffset,x,y,width,height);
817 }
818
glCullFace(GLenum mode)819 GL_API void GL_APIENTRY glCullFace( GLenum mode) {
820 GET_CTX()
821 GLES_CM_TRACE()
822 ctx->setCullFace(mode);
823 ctx->dispatcher().glCullFace(mode);
824 }
825
glDeleteBuffers(GLsizei n,const GLuint * buffers)826 GL_API void GL_APIENTRY glDeleteBuffers( GLsizei n, const GLuint *buffers) {
827 GET_CTX()
828 GLES_CM_TRACE()
829 SET_ERROR_IF(n<0,GL_INVALID_VALUE);
830 if(ctx->shareGroup().get()) {
831 for(int i=0; i < n; i++){
832 ctx->shareGroup()->deleteName(NamedObjectType::VERTEXBUFFER,
833 buffers[i]);
834 ctx->unbindBuffer(buffers[i]);
835 }
836 }
837 }
838
glDeleteTextures(GLsizei n,const GLuint * textures)839 GL_API void GL_APIENTRY glDeleteTextures( GLsizei n, const GLuint *textures) {
840 GET_CTX()
841 GLES_CM_TRACE()
842 SET_ERROR_IF(n<0,GL_INVALID_VALUE);
843 if(ctx->shareGroup().get()) {
844 for(int i=0; i < n; i++){
845 if(textures[i] != 0)
846 {
847 if(ctx->getBindedTexture(GL_TEXTURE_2D) == textures[i])
848 ctx->setBindedTexture(GL_TEXTURE_2D,0);
849 if (ctx->getBindedTexture(GL_TEXTURE_CUBE_MAP) == textures[i])
850 ctx->setBindedTexture(GL_TEXTURE_CUBE_MAP,0);
851 ctx->shareGroup()->deleteName(NamedObjectType::TEXTURE,
852 textures[i]);
853 }
854 }
855 }
856 }
857
glDepthFunc(GLenum func)858 GL_API void GL_APIENTRY glDepthFunc( GLenum func) {
859 GET_CTX()
860 GLES_CM_TRACE()
861 ctx->setDepthFunc(func);
862 ctx->dispatcher().glDepthFunc(func);
863 }
864
glDepthMask(GLboolean flag)865 GL_API void GL_APIENTRY glDepthMask( GLboolean flag) {
866 GET_CTX()
867 GLES_CM_TRACE()
868 ctx->setDepthMask(flag);
869 ctx->dispatcher().glDepthMask(flag);
870 }
871
glDepthRangef(GLclampf zNear,GLclampf zFar)872 GL_API void GL_APIENTRY glDepthRangef( GLclampf zNear, GLclampf zFar) {
873 GET_CTX()
874 GLES_CM_TRACE()
875 ctx->setDepthRangef(zNear, zFar);
876 ctx->dispatcher().glDepthRange(zNear,zFar);
877 }
878
glDepthRangex(GLclampx zNear,GLclampx zFar)879 GL_API void GL_APIENTRY glDepthRangex( GLclampx zNear, GLclampx zFar) {
880 GET_CTX()
881 GLES_CM_TRACE()
882 ctx->setDepthRangef(X2F(zNear),X2F(zFar));
883 ctx->dispatcher().glDepthRange(X2F(zNear),X2F(zFar));
884 }
885
glDisable(GLenum cap)886 GL_API void GL_APIENTRY glDisable( GLenum cap) {
887 GET_CTX_CM()
888 GLES_CM_TRACE()
889 ctx->disable(cap);
890 }
891
glDisableClientState(GLenum array)892 GL_API void GL_APIENTRY glDisableClientState( GLenum array) {
893 GET_CTX_CM()
894 GLES_CM_TRACE()
895 SET_ERROR_IF(!GLEScmValidate::supportedArrays(array),GL_INVALID_ENUM)
896
897 ctx->enableArr(array,false);
898
899 if(array != GL_POINT_SIZE_ARRAY_OES) ctx->disableClientState(array);
900 }
901
902
glDrawArrays(GLenum mode,GLint first,GLsizei count)903 GL_API void GL_APIENTRY glDrawArrays( GLenum mode, GLint first, GLsizei count) {
904 GET_CTX_CM()
905 GLES_CM_TRACE()
906 SET_ERROR_IF(count < 0,GL_INVALID_VALUE)
907 SET_ERROR_IF(!GLEScmValidate::drawMode(mode),GL_INVALID_ENUM)
908
909 ctx->drawArrays(mode, first, count);
910 }
911
glDrawElements(GLenum mode,GLsizei count,GLenum type,const GLvoid * elementsIndices)912 GL_API void GL_APIENTRY glDrawElements( GLenum mode, GLsizei count, GLenum type, const GLvoid *elementsIndices) {
913 GET_CTX_CM()
914 GLES_CM_TRACE()
915 SET_ERROR_IF(count < 0,GL_INVALID_VALUE)
916 SET_ERROR_IF((!GLEScmValidate::drawMode(mode) || !GLEScmValidate::drawType(type)),GL_INVALID_ENUM)
917
918 ctx->drawElements(mode, count, type, elementsIndices);
919 }
920
glEnable(GLenum cap)921 GL_API void GL_APIENTRY glEnable( GLenum cap) {
922 GET_CTX_CM()
923 GLES_CM_TRACE()
924 ctx->enable(cap);
925 }
926
glEnableClientState(GLenum array)927 GL_API void GL_APIENTRY glEnableClientState( GLenum array) {
928 GET_CTX_CM()
929 GLES_CM_TRACE()
930 SET_ERROR_IF(!GLEScmValidate::supportedArrays(array),GL_INVALID_ENUM)
931
932 ctx->enableArr(array,true);
933 if(array != GL_POINT_SIZE_ARRAY_OES) {
934 ctx->enableClientState(array);
935 }
936 }
937
glFinish(void)938 GL_API void GL_APIENTRY glFinish( void) {
939 GET_CTX()
940 GLES_CM_TRACE()
941 ctx->dispatcher().glFinish();
942 }
943
glFlush(void)944 GL_API void GL_APIENTRY glFlush( void) {
945 GET_CTX()
946 GLES_CM_TRACE()
947 ctx->dispatcher().glFlush();
948 }
949
glFogf(GLenum pname,GLfloat param)950 GL_API void GL_APIENTRY glFogf( GLenum pname, GLfloat param) {
951 GET_CTX_CM()
952 GLES_CM_TRACE()
953 ctx->fogf(pname,param);
954 }
955
glFogfv(GLenum pname,const GLfloat * params)956 GL_API void GL_APIENTRY glFogfv( GLenum pname, const GLfloat *params) {
957 GET_CTX_CM()
958 GLES_CM_TRACE()
959 ctx->fogfv(pname,params);
960 }
961
glFogx(GLenum pname,GLfixed param)962 GL_API void GL_APIENTRY glFogx( GLenum pname, GLfixed param) {
963 GET_CTX_CM()
964 GLES_CM_TRACE()
965 ctx->fogf(pname,(pname == GL_FOG_MODE)? static_cast<GLfloat>(param):X2F(param));
966 }
967
glFogxv(GLenum pname,const GLfixed * params)968 GL_API void GL_APIENTRY glFogxv( GLenum pname, const GLfixed *params) {
969 GET_CTX_CM()
970 GLES_CM_TRACE()
971 if(pname == GL_FOG_MODE) {
972 GLfloat tmpParam = static_cast<GLfloat>(params[0]);
973 ctx->fogfv(pname,&tmpParam);
974 } else {
975 GLfloat tmpParams[4];
976 for(int i=0; i< 4; i++) {
977 tmpParams[i] = X2F(params[i]);
978 }
979 ctx->fogfv(pname,tmpParams);
980 }
981
982 }
983
glFrontFace(GLenum mode)984 GL_API void GL_APIENTRY glFrontFace( GLenum mode) {
985 GET_CTX()
986 GLES_CM_TRACE()
987 ctx->setFrontFace(mode);
988 ctx->dispatcher().glFrontFace(mode);
989 }
990
glFrustumf(GLfloat left,GLfloat right,GLfloat bottom,GLfloat top,GLfloat zNear,GLfloat zFar)991 GL_API void GL_APIENTRY glFrustumf( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar) {
992 GET_CTX_CM()
993 GLES_CM_TRACE()
994 ctx->frustumf(left, right, bottom, top, zNear,zFar);
995 ERRCHECK()
996 }
997
glFrustumx(GLfixed left,GLfixed right,GLfixed bottom,GLfixed top,GLfixed zNear,GLfixed zFar)998 GL_API void GL_APIENTRY glFrustumx( GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar) {
999 GET_CTX_CM()
1000 GLES_CM_TRACE()
1001 ctx->frustumf(X2F(left),X2F(right),X2F(bottom),X2F(top),X2F(zNear),X2F(zFar));
1002 }
1003
glGenBuffers(GLsizei n,GLuint * buffers)1004 GL_API void GL_APIENTRY glGenBuffers( GLsizei n, GLuint *buffers) {
1005 GET_CTX()
1006 GLES_CM_TRACE()
1007 SET_ERROR_IF(n<0,GL_INVALID_VALUE);
1008 if(ctx->shareGroup().get()) {
1009 for(int i=0; i<n ;i++) {
1010 buffers[i] = ctx->shareGroup()->genName(
1011 NamedObjectType::VERTEXBUFFER, 0, true);
1012 //generating vbo object related to this buffer name
1013 ctx->shareGroup()->setObjectData(NamedObjectType::VERTEXBUFFER,
1014 buffers[i],
1015 ObjectDataPtr(new GLESbuffer()));
1016 }
1017 }
1018 }
1019
glGenTextures(GLsizei n,GLuint * textures)1020 GL_API void GL_APIENTRY glGenTextures( GLsizei n, GLuint *textures) {
1021 GET_CTX();
1022 GLES_CM_TRACE()
1023 if(ctx->shareGroup().get()) {
1024 for(int i=0; i<n ;i++) {
1025 textures[i] = ctx->shareGroup()->genName(NamedObjectType::TEXTURE,
1026 0, true);
1027 }
1028 }
1029 }
1030
1031 GL_API void GL_APIENTRY glGetIntegerv( GLenum pname, GLint *params);
1032
glGetBooleanv(GLenum pname,GLboolean * params)1033 GL_API void GL_APIENTRY glGetBooleanv( GLenum pname, GLboolean *params) {
1034 GET_CTX()
1035 GLES_CM_TRACE()
1036
1037 #define TO_GLBOOL(params, x) \
1038 *params = x ? GL_TRUE : GL_FALSE; \
1039
1040 if(ctx->glGetBooleanv(pname, params))
1041 {
1042 return;
1043 }
1044
1045 switch(pname)
1046 {
1047 case GL_FRAMEBUFFER_BINDING_OES:
1048 case GL_RENDERBUFFER_BINDING_OES:
1049 {
1050 GLint name;
1051 glGetIntegerv(pname,&name);
1052 *params = name!=0 ? GL_TRUE: GL_FALSE;
1053 }
1054 break;
1055 case GL_TEXTURE_GEN_STR_OES:
1056 {
1057 GLboolean state_s = GL_FALSE;
1058 GLboolean state_t = GL_FALSE;
1059 GLboolean state_r = GL_FALSE;
1060 ctx->dispatcher().glGetBooleanv(GL_TEXTURE_GEN_S,&state_s);
1061 ctx->dispatcher().glGetBooleanv(GL_TEXTURE_GEN_T,&state_t);
1062 ctx->dispatcher().glGetBooleanv(GL_TEXTURE_GEN_R,&state_r);
1063 *params = state_s && state_t && state_r ? GL_TRUE: GL_FALSE;
1064 }
1065 break;
1066 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1067 *params = (GLboolean)getCompressedFormats(1, NULL);
1068 break;
1069 case GL_COMPRESSED_TEXTURE_FORMATS:
1070 {
1071 int nparams = getCompressedFormats(1, NULL);
1072 if (nparams>0) {
1073 int * iparams = new int[nparams];
1074 getCompressedFormats(1, iparams);
1075 for (int i=0; i<nparams; i++) params[i] = (GLboolean)iparams[i];
1076 delete [] iparams;
1077 }
1078 }
1079 break;
1080 case GL_GENERATE_MIPMAP_HINT:
1081 if (isCoreProfile()) {
1082 TO_GLBOOL(params, ctx->getHint(GL_GENERATE_MIPMAP_HINT));
1083 } else {
1084 ctx->dispatcher().glGetBooleanv(pname,params);
1085 }
1086 break;
1087 case GL_RED_BITS:
1088 case GL_GREEN_BITS:
1089 case GL_BLUE_BITS:
1090 case GL_ALPHA_BITS:
1091 case GL_DEPTH_BITS:
1092 case GL_STENCIL_BITS:
1093 if (isCoreProfile()) {
1094 GLuint fboBinding = ctx->getFramebufferBinding(GL_DRAW_FRAMEBUFFER);
1095 TO_GLBOOL(params, ctx->queryCurrFboBits(fboBinding, pname));
1096 } else {
1097 ctx->dispatcher().glGetBooleanv(pname,params);
1098 }
1099 break;
1100 default:
1101 ctx->dispatcher().glGetBooleanv(pname,params);
1102 }
1103 }
1104
glGetBufferParameteriv(GLenum target,GLenum pname,GLint * params)1105 GL_API void GL_APIENTRY glGetBufferParameteriv( GLenum target, GLenum pname, GLint *params) {
1106 GET_CTX()
1107 GLES_CM_TRACE()
1108 SET_ERROR_IF(!(GLEScmValidate::bufferTarget(target) && GLEScmValidate::bufferParam(pname)),GL_INVALID_ENUM);
1109 SET_ERROR_IF(!ctx->isBindedBuffer(target),GL_INVALID_OPERATION);
1110 switch(pname) {
1111 case GL_BUFFER_SIZE:
1112 ctx->getBufferSize(target,params);
1113 break;
1114 case GL_BUFFER_USAGE:
1115 ctx->getBufferUsage(target,params);
1116 break;
1117 }
1118
1119 }
1120
glGetClipPlanef(GLenum pname,GLfloat eqn[4])1121 GL_API void GL_APIENTRY glGetClipPlanef( GLenum pname, GLfloat eqn[4]) {
1122 GET_CTX()
1123 GLES_CM_TRACE()
1124 GLdouble tmpEqn[4];
1125
1126 ctx->dispatcher().glGetClipPlane(pname,tmpEqn);
1127 for(int i =0 ;i < 4; i++){
1128 eqn[i] = static_cast<GLfloat>(tmpEqn[i]);
1129 }
1130 }
1131
glGetClipPlanex(GLenum pname,GLfixed eqn[4])1132 GL_API void GL_APIENTRY glGetClipPlanex( GLenum pname, GLfixed eqn[4]) {
1133 GET_CTX()
1134 GLES_CM_TRACE()
1135 GLdouble tmpEqn[4];
1136
1137 ctx->dispatcher().glGetClipPlane(pname,tmpEqn);
1138 for(int i =0 ;i < 4; i++){
1139 eqn[i] = F2X(tmpEqn[i]);
1140 }
1141 }
1142
1143 GL_API void GL_APIENTRY glGetFloatv( GLenum pname, GLfloat *params);
1144
glGetFixedv(GLenum pname,GLfixed * params)1145 GL_API void GL_APIENTRY glGetFixedv( GLenum pname, GLfixed *params) {
1146 GET_CTX()
1147 GLES_CM_TRACE()
1148
1149 if(ctx->glGetFixedv(pname, params))
1150 {
1151 return;
1152 }
1153
1154 size_t nParams = glParamSize(pname);
1155 GLfloat fParams[16];
1156
1157 switch(pname)
1158 {
1159 case GL_FRAMEBUFFER_BINDING_OES:
1160 case GL_RENDERBUFFER_BINDING_OES:
1161 case GL_TEXTURE_GEN_STR_OES:
1162 glGetFloatv(pname,&fParams[0]);
1163 break;
1164 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1165 *params = I2X(getCompressedFormats(1, NULL));
1166 return;
1167 break;
1168 case GL_COMPRESSED_TEXTURE_FORMATS:
1169 {
1170 int nparams = getCompressedFormats(1, NULL);
1171 if (nparams>0) {
1172 int * iparams = new int[nparams];
1173 getCompressedFormats(1, iparams);
1174 for (int i=0; i<nparams; i++) params[i] = I2X(iparams[i]);
1175 delete [] iparams;
1176 }
1177 return;
1178 }
1179 break;
1180 default:
1181 ctx->dispatcher().glGetFloatv(pname,fParams);
1182 }
1183
1184 if (nParams)
1185 {
1186 for(size_t i =0 ; i < nParams;i++) {
1187 params[i] = F2X(fParams[i]);
1188 }
1189 }
1190 }
1191
glGetFloatv(GLenum pname,GLfloat * params)1192 GL_API void GL_APIENTRY glGetFloatv( GLenum pname, GLfloat *params) {
1193 GET_CTX()
1194 GLES_CM_TRACE()
1195
1196 if(ctx->glGetFloatv(pname, params))
1197 {
1198 return;
1199 }
1200
1201 GLint i = 0;
1202
1203 switch (pname) {
1204 case GL_FRAMEBUFFER_BINDING_OES:
1205 case GL_RENDERBUFFER_BINDING_OES:
1206 case GL_TEXTURE_GEN_STR_OES:
1207 glGetIntegerv(pname,&i);
1208 *params = (GLfloat)i;
1209 break;
1210 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1211 *params = (GLfloat)getCompressedFormats(1, NULL);
1212 break;
1213 case GL_COMPRESSED_TEXTURE_FORMATS:
1214 {
1215 int nparams = getCompressedFormats(1, NULL);
1216 if (nparams>0) {
1217 int * iparams = new int[nparams];
1218 getCompressedFormats(1, iparams);
1219 for (int i=0; i<nparams; i++) params[i] = (GLfloat)iparams[i];
1220 delete [] iparams;
1221 }
1222 }
1223 break;
1224 default:
1225 ctx->dispatcher().glGetFloatv(pname,params);
1226 }
1227 }
1228
glGetIntegerv(GLenum pname,GLint * params)1229 GL_API void GL_APIENTRY glGetIntegerv( GLenum pname, GLint *params) {
1230 GET_CTX()
1231 GLES_CM_TRACE()
1232
1233 if(ctx->glGetIntegerv(pname, params))
1234 {
1235 return;
1236 }
1237
1238 GLint i;
1239 GLfloat f;
1240
1241 switch(pname)
1242 {
1243 case GL_READ_BUFFER:
1244 case GL_DRAW_BUFFER0:
1245 if (ctx->shareGroup().get()) {
1246 ctx->dispatcher().glGetIntegerv(pname, &i);
1247 GLenum target = pname == GL_READ_BUFFER ? GL_READ_FRAMEBUFFER : GL_DRAW_FRAMEBUFFER;
1248 if (ctx->isDefaultFBOBound(target) && (GLint)i == GL_COLOR_ATTACHMENT0) {
1249 i = GL_BACK;
1250 }
1251 *params = i;
1252 }
1253 break;
1254 case GL_TEXTURE_GEN_STR_OES:
1255 ctx->dispatcher().glGetIntegerv(GL_TEXTURE_GEN_S,¶ms[0]);
1256 break;
1257 case GL_FRAMEBUFFER_BINDING_OES:
1258 ctx->dispatcher().glGetIntegerv(pname,&i);
1259 *params = ctx->getFBOLocalName(i);
1260 break;
1261 case GL_RENDERBUFFER_BINDING_OES:
1262 if (ctx->shareGroup().get()) {
1263 ctx->dispatcher().glGetIntegerv(pname,&i);
1264 *params = ctx->shareGroup()->getLocalName(
1265 NamedObjectType::RENDERBUFFER, i);
1266 }
1267 break;
1268 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1269 *params = getCompressedFormats(1, NULL);
1270 break;
1271 case GL_COMPRESSED_TEXTURE_FORMATS:
1272 getCompressedFormats(1, params);
1273 break;
1274 case GL_MAX_CLIP_PLANES:
1275 ctx->dispatcher().glGetIntegerv(pname,params);
1276 if(*params > 6)
1277 {
1278 // GLES spec requires only 6, and the ATI driver erronously
1279 // returns 8 (although it supports only 6). This WAR is simple,
1280 // compliant and good enough for developers.
1281 *params = 6;
1282 }
1283 break;
1284 case GL_ALPHA_TEST_REF:
1285 // Both the ATI and nVidia OpenGL drivers return the wrong answer
1286 // here. So return the right one.
1287 ctx->dispatcher().glGetFloatv(pname,&f);
1288 *params = (int)(f * (float)0x7fffffff);
1289 break;
1290 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1291 ctx->dispatcher().glGetIntegerv(pname,params);
1292 if(*params > 16)
1293 {
1294 // GLES spec requires only 2, and the ATI driver erronously
1295 // returns 32 (although it supports only 16). This WAR is simple,
1296 // compliant and good enough for developers.
1297 *params = 16;
1298 }
1299 break;
1300 case GL_GENERATE_MIPMAP_HINT:
1301 if (isCoreProfile()) {
1302 *params = ctx->getHint(GL_GENERATE_MIPMAP_HINT);
1303 } else {
1304 ctx->dispatcher().glGetIntegerv(pname,params);
1305 }
1306 break;
1307 case GL_RED_BITS:
1308 case GL_GREEN_BITS:
1309 case GL_BLUE_BITS:
1310 case GL_ALPHA_BITS:
1311 case GL_DEPTH_BITS:
1312 case GL_STENCIL_BITS:
1313 if (isCoreProfile()) {
1314 GLuint fboBinding = ctx->getFramebufferBinding(GL_DRAW_FRAMEBUFFER);
1315 *params = ctx->queryCurrFboBits(fboBinding, pname);
1316 } else {
1317 ctx->dispatcher().glGetIntegerv(pname,params);
1318 }
1319 break;
1320
1321 default:
1322 ctx->dispatcher().glGetIntegerv(pname,params);
1323 }
1324 }
1325
glGetLightfv(GLenum light,GLenum pname,GLfloat * params)1326 GL_API void GL_APIENTRY glGetLightfv( GLenum light, GLenum pname, GLfloat *params) {
1327 GET_CTX_CM()
1328 GLES_CM_TRACE()
1329 ctx->getLightfv(light,pname,params);
1330 }
1331
glGetLightxv(GLenum light,GLenum pname,GLfixed * params)1332 GL_API void GL_APIENTRY glGetLightxv( GLenum light, GLenum pname, GLfixed *params) {
1333 GET_CTX_CM()
1334 GLES_CM_TRACE()
1335 GLfloat tmpParams[4];
1336
1337 ctx->getLightfv(light,pname,tmpParams);
1338 switch (pname){
1339 case GL_AMBIENT:
1340 case GL_DIFFUSE:
1341 case GL_SPECULAR:
1342 case GL_POSITION:
1343 params[3] = F2X(tmpParams[3]);
1344 case GL_SPOT_DIRECTION:
1345 params[2] = F2X(tmpParams[2]);
1346 case GL_SPOT_EXPONENT:
1347 case GL_SPOT_CUTOFF:
1348 case GL_CONSTANT_ATTENUATION:
1349 case GL_LINEAR_ATTENUATION:
1350 case GL_QUADRATIC_ATTENUATION:
1351 params[1] = F2X(tmpParams[1]);
1352 break;
1353 default:{
1354 ctx->setGLerror(GL_INVALID_ENUM);
1355 return;
1356 }
1357
1358 }
1359 params[0] = F2X(tmpParams[0]);
1360 }
1361
glGetMaterialfv(GLenum face,GLenum pname,GLfloat * params)1362 GL_API void GL_APIENTRY glGetMaterialfv( GLenum face, GLenum pname, GLfloat *params) {
1363 GET_CTX_CM()
1364 GLES_CM_TRACE()
1365 ctx->getMaterialfv(face,pname,params);
1366 }
1367
glGetMaterialxv(GLenum face,GLenum pname,GLfixed * params)1368 GL_API void GL_APIENTRY glGetMaterialxv( GLenum face, GLenum pname, GLfixed *params) {
1369 GET_CTX_CM()
1370 GLES_CM_TRACE()
1371 GLfloat tmpParams[4];
1372 ctx->getMaterialfv(face,pname,tmpParams);
1373 switch(pname){
1374 case GL_AMBIENT:
1375 case GL_DIFFUSE:
1376 case GL_SPECULAR:
1377 case GL_EMISSION:
1378 case GL_AMBIENT_AND_DIFFUSE:
1379 params[3] = tmpParams[3];
1380 params[2] = tmpParams[2];
1381 params[1] = tmpParams[1];
1382 case GL_SHININESS:
1383 params[0] = tmpParams[0];
1384 break;
1385 default:{
1386 ctx->setGLerror(GL_INVALID_ENUM);
1387 return;
1388 }
1389 }
1390 }
1391
glGetPointerv(GLenum pname,void ** params)1392 GL_API void GL_APIENTRY glGetPointerv( GLenum pname, void **params) {
1393 GET_CTX()
1394 GLES_CM_TRACE()
1395 const GLESpointer* p = ctx->getPointer(pname);
1396 if(p) {
1397 if (p->getAttribType() == GLESpointer::BUFFER) {
1398 *params = SafePointerFromUInt(p->getBufferOffset());
1399 } else if (p->getAttribType() == GLESpointer::ARRAY) {
1400 *params = const_cast<void *>(p->getArrayData());
1401 }
1402 } else {
1403 ctx->setGLerror(GL_INVALID_ENUM);
1404 }
1405
1406 }
1407
glGetTexEnvfv(GLenum env,GLenum pname,GLfloat * params)1408 GL_API void GL_APIENTRY glGetTexEnvfv( GLenum env, GLenum pname, GLfloat *params) {
1409 GET_CTX_CM()
1410 GLES_CM_TRACE()
1411
1412 ctx->getTexEnvfv(env, pname, params);
1413 }
1414
glGetTexEnviv(GLenum env,GLenum pname,GLint * params)1415 GL_API void GL_APIENTRY glGetTexEnviv( GLenum env, GLenum pname, GLint *params) {
1416 GET_CTX_CM()
1417 GLES_CM_TRACE()
1418
1419 ctx->getTexEnviv(env, pname, params);
1420 }
1421
glGetTexEnvxv(GLenum env,GLenum pname,GLfixed * params)1422 GL_API void GL_APIENTRY glGetTexEnvxv( GLenum env, GLenum pname, GLfixed *params) {
1423 GET_CTX_CM()
1424 GLES_CM_TRACE()
1425 GLfloat tmpParams[4];
1426
1427 ctx->getTexEnvfv(env, pname, tmpParams);
1428
1429 if(pname == GL_TEXTURE_ENV_MODE) {
1430 params[0] = static_cast<GLfixed>(tmpParams[0]);
1431 } else {
1432 for(int i=0 ; i < 4 ; i++)
1433 params[i] = F2X(tmpParams[i]);
1434 }
1435 }
1436
glGetTexParameterfv(GLenum target,GLenum pname,GLfloat * params)1437 GL_API void GL_APIENTRY glGetTexParameterfv( GLenum target, GLenum pname, GLfloat *params) {
1438 GET_CTX()
1439 GLES_CM_TRACE()
1440 if (pname==GL_TEXTURE_CROP_RECT_OES) {
1441 TextureData *texData = getTextureTargetData(target);
1442 SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION);
1443 for (int i=0;i<4;++i)
1444 params[i] = texData->crop_rect[i];
1445 }
1446 else {
1447 ctx->dispatcher().glGetTexParameterfv(target,pname,params);
1448 }
1449 }
1450
glGetTexParameteriv(GLenum target,GLenum pname,GLint * params)1451 GL_API void GL_APIENTRY glGetTexParameteriv( GLenum target, GLenum pname, GLint *params) {
1452 GET_CTX()
1453 GLES_CM_TRACE()
1454 if (pname==GL_TEXTURE_CROP_RECT_OES) {
1455 TextureData *texData = getTextureTargetData(target);
1456 SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION);
1457 for (int i=0;i<4;++i)
1458 params[i] = texData->crop_rect[i];
1459 }
1460 else {
1461 ctx->dispatcher().glGetTexParameteriv(target,pname,params);
1462 }
1463 }
1464
glGetTexParameterxv(GLenum target,GLenum pname,GLfixed * params)1465 GL_API void GL_APIENTRY glGetTexParameterxv( GLenum target, GLenum pname, GLfixed *params) {
1466 GET_CTX()
1467 GLES_CM_TRACE()
1468 if (pname==GL_TEXTURE_CROP_RECT_OES) {
1469 TextureData *texData = getTextureTargetData(target);
1470 SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION);
1471 for (int i=0;i<4;++i)
1472 params[i] = F2X(texData->crop_rect[i]);
1473 }
1474 else {
1475 GLfloat tmpParam;
1476 ctx->dispatcher().glGetTexParameterfv(target,pname,&tmpParam);
1477 params[0] = static_cast<GLfixed>(tmpParam);
1478 }
1479 }
1480
glHint(GLenum target,GLenum mode)1481 GL_API void GL_APIENTRY glHint( GLenum target, GLenum mode) {
1482 GET_CTX()
1483 GLES_CM_TRACE()
1484 SET_ERROR_IF(!GLEScmValidate::hintTargetMode(target,mode),GL_INVALID_ENUM);
1485
1486 // No GLES1 hints are supported.
1487 if (isGles2Gles() || isCoreProfile()) {
1488 ctx->setHint(target, mode);
1489 } else {
1490 ctx->dispatcher().glHint(target,mode);
1491 }
1492 }
1493
glLightModelf(GLenum pname,GLfloat param)1494 GL_API void GL_APIENTRY glLightModelf( GLenum pname, GLfloat param) {
1495 GET_CTX_CM()
1496 GLES_CM_TRACE()
1497 ctx->lightModelf(pname,param);
1498 }
1499
glLightModelfv(GLenum pname,const GLfloat * params)1500 GL_API void GL_APIENTRY glLightModelfv( GLenum pname, const GLfloat *params) {
1501 GET_CTX_CM()
1502 GLES_CM_TRACE()
1503
1504 ctx->lightModelfv(pname,params);
1505 }
1506
glLightModelx(GLenum pname,GLfixed param)1507 GL_API void GL_APIENTRY glLightModelx( GLenum pname, GLfixed param) {
1508 GET_CTX_CM()
1509 GLES_CM_TRACE()
1510 GLfloat tmpParam = static_cast<GLfloat>(param);
1511 ctx->lightModelf(pname,tmpParam);
1512 }
1513
glLightModelxv(GLenum pname,const GLfixed * params)1514 GL_API void GL_APIENTRY glLightModelxv( GLenum pname, const GLfixed *params) {
1515 GET_CTX_CM()
1516 GLES_CM_TRACE()
1517 GLfloat tmpParams[4];
1518 if(pname == GL_LIGHT_MODEL_TWO_SIDE) {
1519 tmpParams[0] = X2F(params[0]);
1520 } else if (pname == GL_LIGHT_MODEL_AMBIENT) {
1521 for(int i=0;i<4;i++) {
1522 tmpParams[i] = X2F(params[i]);
1523 }
1524 }
1525
1526 ctx->lightModelfv(pname,tmpParams);
1527 }
1528
glLightf(GLenum light,GLenum pname,GLfloat param)1529 GL_API void GL_APIENTRY glLightf( GLenum light, GLenum pname, GLfloat param) {
1530 GET_CTX_CM()
1531 GLES_CM_TRACE()
1532 ctx->lightf(light,pname,param);
1533 }
1534
glLightfv(GLenum light,GLenum pname,const GLfloat * params)1535 GL_API void GL_APIENTRY glLightfv( GLenum light, GLenum pname, const GLfloat *params) {
1536 GET_CTX_CM()
1537 GLES_CM_TRACE()
1538 ctx->lightfv(light,pname,params);
1539 }
1540
glLightx(GLenum light,GLenum pname,GLfixed param)1541 GL_API void GL_APIENTRY glLightx( GLenum light, GLenum pname, GLfixed param) {
1542 GET_CTX_CM()
1543 GLES_CM_TRACE()
1544 ctx->lightf(light,pname,X2F(param));
1545 }
1546
glLightxv(GLenum light,GLenum pname,const GLfixed * params)1547 GL_API void GL_APIENTRY glLightxv( GLenum light, GLenum pname, const GLfixed *params) {
1548 GET_CTX_CM()
1549 GLES_CM_TRACE()
1550 GLfloat tmpParams[4];
1551
1552 switch (pname) {
1553 case GL_AMBIENT:
1554 case GL_DIFFUSE:
1555 case GL_SPECULAR:
1556 case GL_EMISSION:
1557 case GL_POSITION:
1558 tmpParams[3] = X2F(params[3]);
1559 case GL_SPOT_DIRECTION:
1560 tmpParams[2] = X2F(params[2]);
1561 tmpParams[1] = X2F(params[1]);
1562 case GL_SPOT_EXPONENT:
1563 case GL_SPOT_CUTOFF:
1564 case GL_CONSTANT_ATTENUATION:
1565 case GL_LINEAR_ATTENUATION:
1566 case GL_QUADRATIC_ATTENUATION:
1567 tmpParams[0] = X2F(params[0]);
1568 break;
1569 default: {
1570 ctx->setGLerror(GL_INVALID_ENUM);
1571 return;
1572 }
1573 }
1574 ctx->lightfv(light,pname,tmpParams);
1575 }
1576
glLineWidth(GLfloat width)1577 GL_API void GL_APIENTRY glLineWidth( GLfloat width) {
1578 GET_CTX()
1579 GLES_CM_TRACE()
1580 ctx->setLineWidth(width);
1581 ctx->dispatcher().glLineWidth(width);
1582 }
1583
glLineWidthx(GLfixed width)1584 GL_API void GL_APIENTRY glLineWidthx( GLfixed width) {
1585 GET_CTX()
1586 GLES_CM_TRACE()
1587 ctx->setLineWidth(X2F(width));
1588 ctx->dispatcher().glLineWidth(X2F(width));
1589 }
1590
glLoadIdentity(void)1591 GL_API void GL_APIENTRY glLoadIdentity( void) {
1592 GET_CTX_CM()
1593 GLES_CM_TRACE()
1594 ctx->loadIdentity();
1595 ERRCHECK()
1596 }
1597
glLoadMatrixf(const GLfloat * m)1598 GL_API void GL_APIENTRY glLoadMatrixf( const GLfloat *m) {
1599 GET_CTX_CM()
1600 GLES_CM_TRACE()
1601 ctx->loadMatrixf(m);
1602 }
1603
glLoadMatrixx(const GLfixed * m)1604 GL_API void GL_APIENTRY glLoadMatrixx( const GLfixed *m) {
1605 GET_CTX_CM()
1606 GLES_CM_TRACE()
1607 GLfloat mat[16];
1608 for(int i=0; i< 16 ; i++) {
1609 mat[i] = X2F(m[i]);
1610 }
1611 ctx->loadMatrixf(mat);
1612 }
1613
glLogicOp(GLenum opcode)1614 GL_API void GL_APIENTRY glLogicOp( GLenum opcode) {
1615 GET_CTX()
1616 GLES_CM_TRACE()
1617 ctx->dispatcher().glLogicOp(opcode);
1618 }
1619
glMaterialf(GLenum face,GLenum pname,GLfloat param)1620 GL_API void GL_APIENTRY glMaterialf( GLenum face, GLenum pname, GLfloat param) {
1621 GET_CTX_CM()
1622 GLES_CM_TRACE()
1623
1624 ctx->materialf(face, pname, param);
1625 }
1626
glMaterialfv(GLenum face,GLenum pname,const GLfloat * params)1627 GL_API void GL_APIENTRY glMaterialfv( GLenum face, GLenum pname, const GLfloat *params) {
1628 GET_CTX_CM()
1629 GLES_CM_TRACE()
1630
1631 ctx->materialfv(face, pname, params);
1632 }
1633
glMaterialx(GLenum face,GLenum pname,GLfixed param)1634 GL_API void GL_APIENTRY glMaterialx( GLenum face, GLenum pname, GLfixed param) {
1635 GET_CTX_CM()
1636 GLES_CM_TRACE()
1637
1638 ctx->materialf(face, pname, X2F(param));
1639 }
1640
glMaterialxv(GLenum face,GLenum pname,const GLfixed * params)1641 GL_API void GL_APIENTRY glMaterialxv( GLenum face, GLenum pname, const GLfixed *params) {
1642 GET_CTX_CM()
1643 GLES_CM_TRACE()
1644 GLfloat tmpParams[4];
1645
1646 for(int i=0; i< 4; i++) {
1647 tmpParams[i] = X2F(params[i]);
1648 }
1649
1650 ctx->materialfv(face, pname, tmpParams);
1651 }
1652
glMatrixMode(GLenum mode)1653 GL_API void GL_APIENTRY glMatrixMode( GLenum mode) {
1654 GET_CTX_CM()
1655 GLES_CM_TRACE()
1656 SET_ERROR_IF(mode != GL_TEXTURE &&
1657 mode != GL_PROJECTION &&
1658 mode != GL_MODELVIEW, GL_INVALID_ENUM);
1659 ERRCHECK()
1660 ctx->matrixMode(mode);
1661 ERRCHECK()
1662 }
1663
glMultMatrixf(const GLfloat * m)1664 GL_API void GL_APIENTRY glMultMatrixf( const GLfloat *m) {
1665 GET_CTX_CM()
1666 GLES_CM_TRACE()
1667 ctx->multMatrixf(m);
1668 }
1669
glMultMatrixx(const GLfixed * m)1670 GL_API void GL_APIENTRY glMultMatrixx( const GLfixed *m) {
1671 GET_CTX_CM()
1672 GLES_CM_TRACE()
1673 GLfloat mat[16];
1674 for(int i=0; i< 16 ; i++) {
1675 mat[i] = X2F(m[i]);
1676 }
1677 ctx->multMatrixf(mat);
1678 }
1679
glMultiTexCoord4f(GLenum target,GLfloat s,GLfloat t,GLfloat r,GLfloat q)1680 GL_API void GL_APIENTRY glMultiTexCoord4f( GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q) {
1681 GET_CTX_CM()
1682 GLES_CM_TRACE()
1683 SET_ERROR_IF(!GLEScmValidate::textureEnum(target,ctx->getMaxTexUnits()),GL_INVALID_ENUM);
1684 ctx->multiTexCoord4f(target, s, t, r, q);
1685 }
1686
glMultiTexCoord4x(GLenum target,GLfixed s,GLfixed t,GLfixed r,GLfixed q)1687 GL_API void GL_APIENTRY glMultiTexCoord4x( GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q) {
1688 GET_CTX_CM()
1689 GLES_CM_TRACE()
1690 SET_ERROR_IF(!GLEScmValidate::textureEnum(target,ctx->getMaxTexUnits()),GL_INVALID_ENUM);
1691 ctx->multiTexCoord4f(target,X2F(s),X2F(t),X2F(r),X2F(q));
1692 }
1693
glNormal3f(GLfloat nx,GLfloat ny,GLfloat nz)1694 GL_API void GL_APIENTRY glNormal3f( GLfloat nx, GLfloat ny, GLfloat nz) {
1695 GET_CTX_CM()
1696 GLES_CM_TRACE()
1697 ctx->normal3f(nx, ny, nz);
1698 }
1699
glNormal3x(GLfixed nx,GLfixed ny,GLfixed nz)1700 GL_API void GL_APIENTRY glNormal3x( GLfixed nx, GLfixed ny, GLfixed nz) {
1701 GET_CTX_CM()
1702 GLES_CM_TRACE()
1703 ctx->normal3f(X2F(nx),X2F(ny),X2F(nz));
1704 }
1705
glNormalPointer(GLenum type,GLsizei stride,const GLvoid * pointer)1706 GL_API void GL_APIENTRY glNormalPointer( GLenum type, GLsizei stride, const GLvoid *pointer) {
1707 GET_CTX()
1708 GLES_CM_TRACE()
1709 SET_ERROR_IF(stride < 0,GL_INVALID_VALUE);
1710 SET_ERROR_IF(!GLEScmValidate::normalPointerType(type),GL_INVALID_ENUM);
1711 ctx->setPointer(GL_NORMAL_ARRAY,3,type,stride,pointer, 0);//3 normal verctor
1712 }
1713
glNormalPointerWithDataSize(GLenum type,GLsizei stride,const GLvoid * pointer,GLsizei dataSize)1714 GL_API void GL_APIENTRY glNormalPointerWithDataSize(GLenum type, GLsizei stride,
1715 const GLvoid *pointer, GLsizei dataSize) {
1716 GET_CTX()
1717 GLES_CM_TRACE()
1718 SET_ERROR_IF(stride < 0,GL_INVALID_VALUE);
1719 SET_ERROR_IF(!GLEScmValidate::normalPointerType(type),GL_INVALID_ENUM);
1720 ctx->setPointer(GL_NORMAL_ARRAY,3,type,stride,pointer, dataSize);//3 normal verctor
1721 }
1722
glOrthof(GLfloat left,GLfloat right,GLfloat bottom,GLfloat top,GLfloat zNear,GLfloat zFar)1723 GL_API void GL_APIENTRY glOrthof( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar) {
1724 GET_CTX_CM()
1725 GLES_CM_TRACE()
1726 ctx->orthof(left,right,bottom,top,zNear,zFar);
1727 }
1728
glOrthox(GLfixed left,GLfixed right,GLfixed bottom,GLfixed top,GLfixed zNear,GLfixed zFar)1729 GL_API void GL_APIENTRY glOrthox( GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar) {
1730 GET_CTX_CM()
1731 GLES_CM_TRACE()
1732 ctx->orthof(X2F(left),X2F(right),X2F(bottom),X2F(top),X2F(zNear),X2F(zFar));
1733 }
1734
glPixelStorei(GLenum pname,GLint param)1735 GL_API void GL_APIENTRY glPixelStorei( GLenum pname, GLint param) {
1736 GET_CTX()
1737 GLES_CM_TRACE()
1738 SET_ERROR_IF(!(pname == GL_PACK_ALIGNMENT || pname == GL_UNPACK_ALIGNMENT),GL_INVALID_ENUM);
1739 SET_ERROR_IF(!((param==1)||(param==2)||(param==4)||(param==8)), GL_INVALID_VALUE);
1740 ctx->setPixelStorei(pname, param);
1741 ctx->dispatcher().glPixelStorei(pname,param);
1742 }
1743
glPointParameterf(GLenum pname,GLfloat param)1744 GL_API void GL_APIENTRY glPointParameterf( GLenum pname, GLfloat param) {
1745 GET_CTX()
1746 GLES_CM_TRACE()
1747 ctx->dispatcher().glPointParameterf(pname,param);
1748 }
1749
glPointParameterfv(GLenum pname,const GLfloat * params)1750 GL_API void GL_APIENTRY glPointParameterfv( GLenum pname, const GLfloat *params) {
1751 GET_CTX()
1752 GLES_CM_TRACE()
1753 ctx->dispatcher().glPointParameterfv(pname,params);
1754 }
1755
glPointParameterx(GLenum pname,GLfixed param)1756 GL_API void GL_APIENTRY glPointParameterx( GLenum pname, GLfixed param)
1757 {
1758 GET_CTX()
1759 GLES_CM_TRACE()
1760 ctx->dispatcher().glPointParameterf(pname,X2F(param));
1761 }
1762
glPointParameterxv(GLenum pname,const GLfixed * params)1763 GL_API void GL_APIENTRY glPointParameterxv( GLenum pname, const GLfixed *params) {
1764 GET_CTX()
1765 GLES_CM_TRACE()
1766
1767 GLfloat tmpParam = X2F(*params) ;
1768 ctx->dispatcher().glPointParameterfv(pname,&tmpParam);
1769 }
1770
glPointSize(GLfloat size)1771 GL_API void GL_APIENTRY glPointSize( GLfloat size) {
1772 GET_CTX()
1773 GLES_CM_TRACE()
1774 ctx->dispatcher().glPointSize(size);
1775 }
1776
glPointSizePointerOES(GLenum type,GLsizei stride,const GLvoid * pointer)1777 GL_API void GL_APIENTRY glPointSizePointerOES( GLenum type, GLsizei stride, const GLvoid *pointer) {
1778 GET_CTX()
1779 GLES_CM_TRACE()
1780 SET_ERROR_IF(stride < 0,GL_INVALID_VALUE);
1781 SET_ERROR_IF(!GLEScmValidate::pointPointerType(type),GL_INVALID_ENUM);
1782 ctx->setPointer(GL_POINT_SIZE_ARRAY_OES,1,type,stride,pointer, 0);
1783 }
1784
glPointSizex(GLfixed size)1785 GL_API void GL_APIENTRY glPointSizex( GLfixed size) {
1786 GET_CTX()
1787 GLES_CM_TRACE()
1788 ctx->dispatcher().glPointSize(X2F(size));
1789 }
1790
glPolygonOffset(GLfloat factor,GLfloat units)1791 GL_API void GL_APIENTRY glPolygonOffset( GLfloat factor, GLfloat units) {
1792 GET_CTX()
1793 GLES_CM_TRACE()
1794 ctx->setPolygonOffset(factor, units);
1795 ctx->dispatcher().glPolygonOffset(factor,units);
1796 }
1797
glPolygonOffsetx(GLfixed factor,GLfixed units)1798 GL_API void GL_APIENTRY glPolygonOffsetx( GLfixed factor, GLfixed units) {
1799 GET_CTX()
1800 GLES_CM_TRACE()
1801 ctx->setPolygonOffset(X2F(factor), X2F(units));
1802 ctx->dispatcher().glPolygonOffset(X2F(factor),X2F(units));
1803 }
1804
glPopMatrix(void)1805 GL_API void GL_APIENTRY glPopMatrix(void) {
1806 GET_CTX_CM()
1807 GLES_CM_TRACE()
1808 ctx->popMatrix();
1809 CORE_ERR_FORWARD()
1810 }
1811
glPushMatrix(void)1812 GL_API void GL_APIENTRY glPushMatrix(void) {
1813 GET_CTX_CM()
1814 GLES_CM_TRACE()
1815 ctx->pushMatrix();
1816 CORE_ERR_FORWARD()
1817 }
1818
glRotatef(GLfloat angle,GLfloat x,GLfloat y,GLfloat z)1819 GL_API void GL_APIENTRY glRotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z) {
1820 GET_CTX_CM()
1821 GLES_CM_TRACE()
1822 ctx->rotatef(angle, x, y, z);
1823 }
1824
glRotatex(GLfixed angle,GLfixed x,GLfixed y,GLfixed z)1825 GL_API void GL_APIENTRY glRotatex( GLfixed angle, GLfixed x, GLfixed y, GLfixed z) {
1826 GET_CTX_CM()
1827 GLES_CM_TRACE()
1828 ctx->rotatef(angle,X2F(x),X2F(y),X2F(z));
1829 }
1830
glSampleCoverage(GLclampf value,GLboolean invert)1831 GL_API void GL_APIENTRY glSampleCoverage( GLclampf value, GLboolean invert) {
1832 GET_CTX()
1833 GLES_CM_TRACE()
1834 ctx->setSampleCoverage(value, invert);
1835 ctx->dispatcher().glSampleCoverage(value,invert);
1836 }
1837
glSampleCoveragex(GLclampx value,GLboolean invert)1838 GL_API void GL_APIENTRY glSampleCoveragex( GLclampx value, GLboolean invert) {
1839 GET_CTX()
1840 GLES_CM_TRACE()
1841 ctx->setSampleCoverage(X2F(value), invert);
1842 ctx->dispatcher().glSampleCoverage(X2F(value),invert);
1843 }
1844
glScalef(GLfloat x,GLfloat y,GLfloat z)1845 GL_API void GL_APIENTRY glScalef( GLfloat x, GLfloat y, GLfloat z) {
1846 GET_CTX_CM()
1847 GLES_CM_TRACE()
1848 ctx->scalef(x, y, z);
1849 }
1850
glScalex(GLfixed x,GLfixed y,GLfixed z)1851 GL_API void GL_APIENTRY glScalex( GLfixed x, GLfixed y, GLfixed z) {
1852 GET_CTX_CM()
1853 GLES_CM_TRACE()
1854 ctx->scalef(X2F(x),X2F(y),X2F(z));
1855 }
1856
glScissor(GLint x,GLint y,GLsizei width,GLsizei height)1857 GL_API void GL_APIENTRY glScissor( GLint x, GLint y, GLsizei width, GLsizei height) {
1858 GET_CTX()
1859 GLES_CM_TRACE()
1860 ctx->setScissor(x, y, width, height);
1861 ctx->dispatcher().glScissor(x,y,width,height);
1862 }
1863
glShadeModel(GLenum mode)1864 GL_API void GL_APIENTRY glShadeModel( GLenum mode ) {
1865 GET_CTX_CM()
1866 GLES_CM_TRACE()
1867 ctx->shadeModel(mode);
1868 }
1869
glStencilFunc(GLenum func,GLint ref,GLuint mask)1870 GL_API void GL_APIENTRY glStencilFunc( GLenum func, GLint ref, GLuint mask) {
1871 GET_CTX()
1872 GLES_CM_TRACE()
1873 ctx->setStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
1874 ctx->dispatcher().glStencilFunc(func,ref,mask);
1875 }
1876
glStencilMask(GLuint mask)1877 GL_API void GL_APIENTRY glStencilMask( GLuint mask) {
1878 GET_CTX()
1879 GLES_CM_TRACE()
1880 ctx->setStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
1881 ctx->dispatcher().glStencilMask(mask);
1882 }
1883
glStencilOp(GLenum fail,GLenum zfail,GLenum zpass)1884 GL_API void GL_APIENTRY glStencilOp( GLenum fail, GLenum zfail, GLenum zpass) {
1885 GET_CTX()
1886 GLES_CM_TRACE()
1887 SET_ERROR_IF(!(GLEScmValidate::stencilOp(fail) && GLEScmValidate::stencilOp(zfail) && GLEScmValidate::stencilOp(zpass)),GL_INVALID_ENUM);
1888 ctx->setStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
1889 ctx->dispatcher().glStencilOp(fail,zfail,zpass);
1890 }
1891
glTexCoordPointer(GLint size,GLenum type,GLsizei stride,const GLvoid * pointer)1892 GL_API void GL_APIENTRY glTexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) {
1893 GET_CTX()
1894 GLES_CM_TRACE()
1895 SET_ERROR_IF(!GLEScmValidate::texCoordPointerParams(size,stride),GL_INVALID_VALUE);
1896 SET_ERROR_IF(!GLEScmValidate::texCoordPointerType(type),GL_INVALID_ENUM);
1897 ctx->setPointer(GL_TEXTURE_COORD_ARRAY,size,type,stride,pointer, 0);
1898 }
1899
glTexCoordPointerWithDataSize(GLint size,GLenum type,GLsizei stride,const GLvoid * pointer,GLsizei dataSize)1900 GL_API void GL_APIENTRY glTexCoordPointerWithDataSize( GLint size, GLenum type,
1901 GLsizei stride, const GLvoid *pointer, GLsizei dataSize) {
1902 GET_CTX()
1903 GLES_CM_TRACE()
1904 SET_ERROR_IF(!GLEScmValidate::texCoordPointerParams(size,stride),GL_INVALID_VALUE);
1905 SET_ERROR_IF(!GLEScmValidate::texCoordPointerType(type),GL_INVALID_ENUM);
1906 ctx->setPointer(GL_TEXTURE_COORD_ARRAY,size,type,stride,pointer, dataSize);
1907 }
1908
glTexEnvf(GLenum target,GLenum pname,GLfloat param)1909 GL_API void GL_APIENTRY glTexEnvf( GLenum target, GLenum pname, GLfloat param) {
1910 GET_CTX_CM()
1911 GLES_CM_TRACE()
1912 SET_ERROR_IF(!GLEScmValidate::texEnv(target,pname),GL_INVALID_ENUM);
1913 ctx->texEnvf(target,pname,param);
1914 }
1915
glTexEnvfv(GLenum target,GLenum pname,const GLfloat * params)1916 GL_API void GL_APIENTRY glTexEnvfv( GLenum target, GLenum pname, const GLfloat *params) {
1917 GET_CTX_CM()
1918 GLES_CM_TRACE()
1919 SET_ERROR_IF(!GLEScmValidate::texEnv(target,pname),GL_INVALID_ENUM);
1920 ctx->texEnvfv(target, pname, params);
1921 }
1922
glTexEnvi(GLenum target,GLenum pname,GLint param)1923 GL_API void GL_APIENTRY glTexEnvi( GLenum target, GLenum pname, GLint param) {
1924 GET_CTX_CM()
1925 GLES_CM_TRACE()
1926 SET_ERROR_IF(!GLEScmValidate::texEnv(target,pname),GL_INVALID_ENUM);
1927 ctx->texEnvi(target, pname, param);
1928 }
1929
glTexEnviv(GLenum target,GLenum pname,const GLint * params)1930 GL_API void GL_APIENTRY glTexEnviv( GLenum target, GLenum pname, const GLint *params) {
1931 GET_CTX_CM()
1932 GLES_CM_TRACE()
1933 SET_ERROR_IF(!GLEScmValidate::texEnv(target,pname),GL_INVALID_ENUM);
1934 ctx->texEnviv(target, pname, params);
1935 }
1936
glTexEnvx(GLenum target,GLenum pname,GLfixed param)1937 GL_API void GL_APIENTRY glTexEnvx( GLenum target, GLenum pname, GLfixed param) {
1938 GET_CTX_CM()
1939 GLES_CM_TRACE()
1940 SET_ERROR_IF(!GLEScmValidate::texEnv(target,pname),GL_INVALID_ENUM);
1941
1942 GLfloat tmpParam = static_cast<GLfloat>(param);
1943 ctx->texEnvf(target, pname, tmpParam);
1944 CORE_ERR_FORWARD()
1945 }
1946
glTexEnvxv(GLenum target,GLenum pname,const GLfixed * params)1947 GL_API void GL_APIENTRY glTexEnvxv( GLenum target, GLenum pname, const GLfixed *params) {
1948 GET_CTX_CM()
1949 GLES_CM_TRACE()
1950 SET_ERROR_IF(!GLEScmValidate::texEnv(target,pname),GL_INVALID_ENUM);
1951
1952 GLfloat tmpParams[4];
1953 if(pname == GL_TEXTURE_ENV_COLOR) {
1954 for(int i =0;i<4;i++) {
1955 tmpParams[i] = X2F(params[i]);
1956 }
1957 } else {
1958 tmpParams[0] = static_cast<GLfloat>(params[0]);
1959 }
1960
1961 ctx->texEnvfv(target, pname, tmpParams);
1962 CORE_ERR_FORWARD()
1963 }
1964
glTexImage2D(GLenum target,GLint level,GLint internalformat,GLsizei width,GLsizei height,GLint border,GLenum format,GLenum type,const GLvoid * pixels)1965 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) {
1966 GET_CTX()
1967 GLES_CM_TRACE()
1968
1969 SET_ERROR_IF(!(GLEScmValidate::textureTargetEx(target) &&
1970 GLEScmValidate::pixelFrmt(ctx,internalformat) &&
1971 GLEScmValidate::pixelFrmt(ctx,format) &&
1972 GLEScmValidate::pixelType(ctx,type)),GL_INVALID_ENUM);
1973
1974 SET_ERROR_IF(!(GLEScmValidate::pixelOp(format,type) && internalformat == ((GLint)format)),GL_INVALID_OPERATION);
1975
1976 bool needAutoMipmap = false;
1977
1978 s_glInitTexImage2D(target, level, internalformat, width, height, border,
1979 &format, &type, &internalformat, &needAutoMipmap);
1980
1981 // TODO: Emulate swizzles
1982 if (isCoreProfile()) {
1983 GLEScontext::prepareCoreProfileEmulatedTexture(
1984 getTextureTargetData(target),
1985 false, target, format, type,
1986 &internalformat, &format);
1987 }
1988
1989 ctx->dispatcher().glTexImage2D(target,level,
1990 internalformat,width,height,
1991 border,format,type,pixels);
1992
1993 if (needAutoMipmap) {
1994 if ((isCoreProfile() || isGles2Gles()) &&
1995 !isCubeMapFaceTarget(target)) {
1996 ctx->dispatcher().glGenerateMipmap(target);
1997 } else if (isGles2Gles()) {
1998 ctx->dispatcher().glGenerateMipmap(target);
1999 } else {
2000 ctx->dispatcher().glGenerateMipmapEXT(target);
2001 }
2002 }
2003 }
2004
handleMipmapGeneration(GLenum target,GLenum pname,bool param)2005 static bool handleMipmapGeneration(GLenum target, GLenum pname, bool param)
2006 {
2007 GET_CTX_RET(false)
2008 GLES_CM_TRACE()
2009
2010 if (pname == GL_GENERATE_MIPMAP) {
2011 TextureData *texData = getTextureTargetData(target);
2012 if (texData) {
2013 if (param) {
2014 texData->setMipmapLevelAtLeast(maxMipmapLevel(texData->width,
2015 texData->height));
2016 }
2017 if (isCoreProfile() || isGles2Gles() ||
2018 !ctx->isAutoMipmapSupported()) {
2019 texData->requiresAutoMipmap = param;
2020 return true;
2021 }
2022 }
2023 }
2024
2025 return false;
2026 }
2027
glTexParameterf(GLenum target,GLenum pname,GLfloat param)2028 GL_API void GL_APIENTRY glTexParameterf( GLenum target, GLenum pname, GLfloat param) {
2029 GET_CTX()
2030 GLES_CM_TRACE()
2031 SET_ERROR_IF(!GLEScmValidate::texParams(target,pname),GL_INVALID_ENUM);
2032
2033 if(handleMipmapGeneration(target, pname, (bool)param))
2034 return;
2035
2036 TextureData *texData = getTextureTargetData(target);
2037 texData->setTexParam(pname, static_cast<GLint>(param));
2038 ctx->dispatcher().glTexParameterf(target,pname,param);
2039 }
2040
glTexParameterfv(GLenum target,GLenum pname,const GLfloat * params)2041 GL_API void GL_APIENTRY glTexParameterfv( GLenum target, GLenum pname, const GLfloat *params) {
2042 GET_CTX()
2043 GLES_CM_TRACE()
2044 SET_ERROR_IF(!GLEScmValidate::texParams(target,pname),GL_INVALID_ENUM);
2045
2046 if(handleMipmapGeneration(target, pname, (bool)(*params)))
2047 return;
2048
2049 TextureData *texData = getTextureTargetData(target);
2050
2051 if (pname==GL_TEXTURE_CROP_RECT_OES) {
2052 SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION);
2053 for (int i=0;i<4;++i)
2054 texData->crop_rect[i] = params[i];
2055 } else {
2056 texData->setTexParam(pname, static_cast<GLint>(params[0]));
2057 ctx->dispatcher().glTexParameterfv(target,pname,params);
2058 }
2059 }
2060
glTexParameteri(GLenum target,GLenum pname,GLint param)2061 GL_API void GL_APIENTRY glTexParameteri( GLenum target, GLenum pname, GLint param) {
2062 GET_CTX()
2063 GLES_CM_TRACE()
2064 SET_ERROR_IF(!GLEScmValidate::texParams(target,pname),GL_INVALID_ENUM);
2065
2066 if(handleMipmapGeneration(target, pname, (bool)param))
2067 return;
2068
2069 TextureData *texData = getTextureTargetData(target);
2070 texData->setTexParam(pname, (GLint)param);
2071 ctx->dispatcher().glTexParameteri(target,pname,param);
2072 }
2073
glTexParameteriv(GLenum target,GLenum pname,const GLint * params)2074 GL_API void GL_APIENTRY glTexParameteriv( GLenum target, GLenum pname, const GLint *params) {
2075 GET_CTX()
2076 GLES_CM_TRACE()
2077 SET_ERROR_IF(!GLEScmValidate::texParams(target,pname),GL_INVALID_ENUM);
2078
2079 if(handleMipmapGeneration(target, pname, (bool)(*params)))
2080 return;
2081
2082 TextureData *texData = getTextureTargetData(target);
2083 if (pname==GL_TEXTURE_CROP_RECT_OES) {
2084 SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION);
2085 for (int i=0;i<4;++i)
2086 texData->crop_rect[i] = params[i];
2087 }
2088 else {
2089 texData->setTexParam(pname, (GLint)params[0]);
2090 ctx->dispatcher().glTexParameteriv(target,pname,params);
2091 }
2092 }
2093
glTexParameterx(GLenum target,GLenum pname,GLfixed param)2094 GL_API void GL_APIENTRY glTexParameterx( GLenum target, GLenum pname, GLfixed param) {
2095 GET_CTX()
2096 GLES_CM_TRACE()
2097 SET_ERROR_IF(!GLEScmValidate::texParams(target,pname),GL_INVALID_ENUM);
2098 if(handleMipmapGeneration(target, pname, (bool)param))
2099 return;
2100
2101 TextureData *texData = getTextureTargetData(target);
2102 texData->setTexParam(pname, static_cast<GLint>(param));
2103 ctx->dispatcher().glTexParameterf(target,pname,static_cast<GLfloat>(param));
2104 }
2105
glTexParameterxv(GLenum target,GLenum pname,const GLfixed * params)2106 GL_API void GL_APIENTRY glTexParameterxv( GLenum target, GLenum pname, const GLfixed *params) {
2107 GET_CTX()
2108 GLES_CM_TRACE()
2109 SET_ERROR_IF(!GLEScmValidate::texParams(target,pname),GL_INVALID_ENUM);
2110
2111 if(handleMipmapGeneration(target, pname, (bool)(*params)))
2112 return;
2113
2114 TextureData *texData = getTextureTargetData(target);
2115 if (pname==GL_TEXTURE_CROP_RECT_OES) {
2116 SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION);
2117 for (int i=0;i<4;++i)
2118 texData->crop_rect[i] = X2F(params[i]);
2119 }
2120 else {
2121 GLfloat param = static_cast<GLfloat>(params[0]);
2122 texData->setTexParam(pname, static_cast<GLint>(params[0]));
2123 ctx->dispatcher().glTexParameterfv(target,pname,¶m);
2124 }
2125 }
2126
glTexSubImage2D(GLenum target,GLint level,GLint xoffset,GLint yoffset,GLsizei width,GLsizei height,GLenum format,GLenum type,const GLvoid * pixels)2127 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) {
2128 GET_CTX()
2129 GLES_CM_TRACE()
2130 SET_ERROR_IF(!(GLEScmValidate::textureTargetEx(target) &&
2131 GLEScmValidate::pixelFrmt(ctx,format)&&
2132 GLEScmValidate::pixelType(ctx,type)),GL_INVALID_ENUM);
2133 SET_ERROR_IF(!GLEScmValidate::pixelOp(format,type),GL_INVALID_OPERATION);
2134 // set an error if level < 0 or level > log 2 max
2135 SET_ERROR_IF(level < 0 || 1<<level > ctx->getMaxTexSize(), GL_INVALID_VALUE);
2136 SET_ERROR_IF(xoffset < 0 || yoffset < 0 || width < 0 || height < 0, GL_INVALID_VALUE);
2137 if (ctx->shareGroup().get()) {
2138 TextureData *texData = getTextureTargetData(target);
2139 SET_ERROR_IF(!texData, GL_INVALID_OPERATION);
2140 SET_ERROR_IF(xoffset + width > (GLint)texData->width ||
2141 yoffset + height > (GLint)texData->height,
2142 GL_INVALID_VALUE);
2143 }
2144 SET_ERROR_IF(!pixels,GL_INVALID_OPERATION);
2145
2146 ctx->dispatcher().glTexSubImage2D(target,level,xoffset,yoffset,width,height,format,type,pixels);
2147
2148 if (ctx->shareGroup().get()){
2149 TextureData *texData = getTextureTargetData(target);
2150 if(texData && texData->requiresAutoMipmap)
2151 {
2152 ctx->dispatcher().glGenerateMipmapEXT(target);
2153 }
2154 texData->setMipmapLevelAtLeast(level);
2155 texData->makeDirty();
2156 }
2157 }
2158
glTranslatef(GLfloat x,GLfloat y,GLfloat z)2159 GL_API void GL_APIENTRY glTranslatef( GLfloat x, GLfloat y, GLfloat z) {
2160 GET_CTX_CM()
2161 GLES_CM_TRACE()
2162 ctx->translatef(x, y, z);
2163 }
2164
glTranslatex(GLfixed x,GLfixed y,GLfixed z)2165 GL_API void GL_APIENTRY glTranslatex( GLfixed x, GLfixed y, GLfixed z) {
2166 GET_CTX_CM()
2167 GLES_CM_TRACE()
2168 ctx->translatef(X2F(x),X2F(y),X2F(z));
2169 }
2170
glVertexPointer(GLint size,GLenum type,GLsizei stride,const GLvoid * pointer)2171 GL_API void GL_APIENTRY glVertexPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) {
2172 GET_CTX()
2173 GLES_CM_TRACE()
2174
2175 SET_ERROR_IF(!GLEScmValidate::vertexPointerParams(size,stride),GL_INVALID_VALUE);
2176 SET_ERROR_IF(!GLEScmValidate::vertexPointerType(type),GL_INVALID_ENUM);
2177 ctx->setPointer(GL_VERTEX_ARRAY,size,type,stride,pointer, 0);
2178 }
2179
glVertexPointerWithDataSize(GLint size,GLenum type,GLsizei stride,const GLvoid * pointer,GLsizei dataSize)2180 GL_API void GL_APIENTRY glVertexPointerWithDataSize( GLint size, GLenum type,
2181 GLsizei stride, const GLvoid *pointer, GLsizei dataSize) {
2182 GET_CTX()
2183 GLES_CM_TRACE()
2184
2185 SET_ERROR_IF(!GLEScmValidate::vertexPointerParams(size,stride),GL_INVALID_VALUE);
2186 SET_ERROR_IF(!GLEScmValidate::vertexPointerType(type),GL_INVALID_ENUM);
2187 ctx->setPointer(GL_VERTEX_ARRAY,size,type,stride,pointer, dataSize);
2188 }
2189
glViewport(GLint x,GLint y,GLsizei width,GLsizei height)2190 GL_API void GL_APIENTRY glViewport( GLint x, GLint y, GLsizei width, GLsizei height) {
2191 GET_CTX()
2192 GLES_CM_TRACE()
2193 ctx->setViewport(x, y, width, height);
2194 ctx->dispatcher().glViewport(x,y,width,height);
2195 }
2196
glEGLImageTargetTexture2DOES(GLenum target,GLeglImageOES image)2197 GL_API void GL_APIENTRY glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image)
2198 {
2199 GET_CTX();
2200 GLES_CM_TRACE()
2201 SET_ERROR_IF(!GLEScmValidate::textureTargetLimited(target),GL_INVALID_ENUM);
2202 unsigned int imagehndl = SafeUIntFromPointer(image);
2203 ImagePtr img = s_eglIface->getEGLImage(imagehndl);
2204 if (img) {
2205 // Create the texture object in the underlying EGL implementation,
2206 // flag to the OpenGL layer to skip the image creation and map the
2207 // current binded texture object to the existing global object.
2208 if (ctx->shareGroup().get()) {
2209 ObjectLocalName tex = ctx->getTextureLocalName(target,ctx->getBindedTexture(target));
2210 // replace mapping and bind the new global object
2211 ctx->shareGroup()->replaceGlobalObject(NamedObjectType::TEXTURE, tex,
2212 img->globalTexObj);
2213 ctx->dispatcher().glBindTexture(GL_TEXTURE_2D,
2214 img->globalTexObj->getGlobalName());
2215 TextureData *texData = getTextureTargetData(target);
2216 SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION);
2217 texData->width = img->width;
2218 texData->height = img->height;
2219 texData->border = img->border;
2220 texData->internalFormat = img->internalFormat;
2221 texData->format = img->format;
2222 texData->type = img->type;
2223 texData->texStorageLevels = img->texStorageLevels;
2224 texData->sourceEGLImage = imagehndl;
2225 texData->setGlobalName(img->globalTexObj->getGlobalName());
2226 texData->setSaveableTexture(
2227 SaveableTexturePtr(img->saveableTexture));
2228 if (img->sync) {
2229 // insert gpu side fence to make sure we are done with any blit ops.
2230 ctx->dispatcher().glWaitSync(img->sync, 0, GL_TIMEOUT_IGNORED);
2231 }
2232 }
2233 }
2234 }
2235
glEGLImageTargetRenderbufferStorageOES(GLenum target,GLeglImageOES image)2236 GL_API void GL_APIENTRY glEGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image)
2237 {
2238 GET_CTX();
2239 GLES_CM_TRACE()
2240 SET_ERROR_IF(target != GL_RENDERBUFFER_OES,GL_INVALID_ENUM);
2241 unsigned int imagehndl = SafeUIntFromPointer(image);
2242 ImagePtr img = s_eglIface->getEGLImage(imagehndl);
2243 SET_ERROR_IF(!img,GL_INVALID_VALUE);
2244 SET_ERROR_IF(!ctx->shareGroup().get(),GL_INVALID_OPERATION);
2245
2246 // Get current bounded renderbuffer
2247 // raise INVALID_OPERATIOn if no renderbuffer is bounded
2248 GLuint rb = ctx->getRenderbufferBinding();
2249 SET_ERROR_IF(rb == 0,GL_INVALID_OPERATION);
2250 auto objData =
2251 ctx->shareGroup()->getObjectData(NamedObjectType::RENDERBUFFER, rb);
2252 RenderbufferData *rbData = (RenderbufferData *)objData;
2253 SET_ERROR_IF(!rbData,GL_INVALID_OPERATION);
2254
2255 //
2256 // acquire the texture in the renderbufferData that it is an eglImage target
2257 //
2258 rbData->eglImageGlobalTexObject = img->globalTexObj;
2259 rbData->saveableTexture = img->saveableTexture;
2260 img->saveableTexture->makeDirty();
2261
2262 //
2263 // if the renderbuffer is attached to a framebuffer
2264 // change the framebuffer attachment in the undelying OpenGL
2265 // to point to the eglImage texture object.
2266 //
2267 if (rbData->attachedFB) {
2268 // update the framebuffer attachment point to the
2269 // underlying texture of the img
2270 GLuint prevFB = ctx->getFramebufferBinding(GL_FRAMEBUFFER_EXT);
2271 if (prevFB != rbData->attachedFB) {
2272 if (isCoreProfile() || isGles2Gles()) {
2273 ctx->dispatcher().glBindFramebuffer(GL_FRAMEBUFFER,
2274 rbData->attachedFB);
2275 } else {
2276 ctx->dispatcher().glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,
2277 rbData->attachedFB);
2278 }
2279 }
2280 if (isCoreProfile() || isGles2Gles()) {
2281 ctx->dispatcher().glFramebufferTexture2D(GL_FRAMEBUFFER,
2282 rbData->attachedPoint,
2283 GL_TEXTURE_2D,
2284 img->globalTexObj->getGlobalName(),
2285 0);
2286 } else {
2287 ctx->dispatcher().glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
2288 rbData->attachedPoint,
2289 GL_TEXTURE_2D,
2290 img->globalTexObj->getGlobalName(),
2291 0);
2292 }
2293 if (prevFB != rbData->attachedFB) {
2294 if (isCoreProfile() || isGles2Gles()) {
2295 ctx->dispatcher().glBindFramebuffer(GL_FRAMEBUFFER,
2296 prevFB);
2297 } else {
2298 ctx->dispatcher().glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,
2299 prevFB);
2300 }
2301 }
2302 }
2303 }
2304
2305 /* GL_OES_blend_subtract*/
glBlendEquationOES(GLenum mode)2306 GL_API void GL_APIENTRY glBlendEquationOES(GLenum mode) {
2307 GET_CTX()
2308 GLES_CM_TRACE()
2309 SET_ERROR_IF(!(GLEScmValidate::blendEquationMode(mode)), GL_INVALID_ENUM);
2310 ctx->setBlendEquationSeparate(mode, mode);
2311 ctx->dispatcher().glBlendEquation(mode);
2312 }
2313
2314 /* GL_OES_blend_equation_separate */
glBlendEquationSeparateOES(GLenum modeRGB,GLenum modeAlpha)2315 GL_API void GL_APIENTRY glBlendEquationSeparateOES (GLenum modeRGB, GLenum modeAlpha) {
2316 GET_CTX()
2317 GLES_CM_TRACE()
2318 SET_ERROR_IF(!(GLEScmValidate::blendEquationMode(modeRGB) && GLEScmValidate::blendEquationMode(modeAlpha)), GL_INVALID_ENUM);
2319 ctx->setBlendEquationSeparate(modeRGB, modeAlpha);
2320 ctx->dispatcher().glBlendEquationSeparate(modeRGB,modeAlpha);
2321 }
2322
2323 /* GL_OES_blend_func_separate */
glBlendFuncSeparateOES(GLenum srcRGB,GLenum dstRGB,GLenum srcAlpha,GLenum dstAlpha)2324 GL_API void GL_APIENTRY glBlendFuncSeparateOES(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) {
2325 GET_CTX()
2326 GLES_CM_TRACE()
2327 SET_ERROR_IF(!GLEScmValidate::blendSrc(srcRGB) || !GLEScmValidate::blendDst(dstRGB) ||
2328 !GLEScmValidate::blendSrc(srcAlpha) || ! GLEScmValidate::blendDst(dstAlpha) ,GL_INVALID_ENUM);
2329 ctx->setBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
2330 ctx->dispatcher().glBlendFuncSeparate(srcRGB,dstRGB,srcAlpha,dstAlpha);
2331 }
2332
2333 /* GL_OES_framebuffer_object */
glIsRenderbufferOES(GLuint renderbuffer)2334 GL_API GLboolean GL_APIENTRY glIsRenderbufferOES(GLuint renderbuffer) {
2335 GET_CTX_RET(GL_FALSE)
2336 GLES_CM_TRACE()
2337 RET_AND_SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION,GL_FALSE);
2338 if(renderbuffer && ctx->shareGroup().get()){
2339 return ctx->shareGroup()->isObject(NamedObjectType::RENDERBUFFER,
2340 renderbuffer)
2341 ? GL_TRUE
2342 : GL_FALSE;
2343 }
2344 if (isCoreProfile() || isGles2Gles()) {
2345 return ctx->dispatcher().glIsRenderbuffer(renderbuffer);
2346 } else {
2347 return ctx->dispatcher().glIsRenderbufferEXT(renderbuffer);
2348 }
2349 }
2350
glBindRenderbufferOES(GLenum target,GLuint renderbuffer)2351 GL_API void GLAPIENTRY glBindRenderbufferOES(GLenum target, GLuint renderbuffer) {
2352 GET_CTX()
2353 GLES_CM_TRACE()
2354 SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION);
2355 SET_ERROR_IF(!GLEScmValidate::renderbufferTarget(target),GL_INVALID_ENUM);
2356
2357 //if buffer wasn't generated before,generate one
2358 if (renderbuffer && ctx->shareGroup().get() &&
2359 !ctx->shareGroup()->isObject(NamedObjectType::RENDERBUFFER,
2360 renderbuffer)) {
2361 ctx->shareGroup()->genName(NamedObjectType::RENDERBUFFER, renderbuffer);
2362 ctx->shareGroup()->setObjectData(NamedObjectType::RENDERBUFFER,
2363 renderbuffer,
2364 ObjectDataPtr(new RenderbufferData()));
2365 }
2366
2367 int globalBufferName =
2368 (renderbuffer != 0)
2369 ? ctx->shareGroup()->getGlobalName(
2370 NamedObjectType::RENDERBUFFER, renderbuffer)
2371 : 0;
2372 if (isCoreProfile() || isGles2Gles()) {
2373 ctx->dispatcher().glBindRenderbuffer(target,globalBufferName);
2374 } else {
2375 ctx->dispatcher().glBindRenderbufferEXT(target,globalBufferName);
2376 }
2377
2378 // update renderbuffer binding state
2379 ctx->setRenderbufferBinding(renderbuffer);
2380 }
2381
glDeleteRenderbuffersOES(GLsizei n,const GLuint * renderbuffers)2382 GL_API void GLAPIENTRY glDeleteRenderbuffersOES(GLsizei n, const GLuint *renderbuffers) {
2383 GET_CTX()
2384 GLES_CM_TRACE()
2385 SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION);
2386 for (int i=0;i<n;++i) {
2387 ctx->shareGroup()->deleteName(NamedObjectType::RENDERBUFFER,
2388 renderbuffers[i]);
2389 }
2390 }
2391
glGenRenderbuffersOES(GLsizei n,GLuint * renderbuffers)2392 GL_API void GLAPIENTRY glGenRenderbuffersOES(GLsizei n, GLuint *renderbuffers) {
2393 GET_CTX()
2394 GLES_CM_TRACE()
2395 SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION);
2396 SET_ERROR_IF(n<0,GL_INVALID_VALUE);
2397 if(ctx->shareGroup().get()) {
2398 for(int i=0; i<n ;i++) {
2399 renderbuffers[i] = ctx->shareGroup()->genName(
2400 NamedObjectType::RENDERBUFFER, 0, true);
2401 ctx->shareGroup()->setObjectData(
2402 NamedObjectType::RENDERBUFFER, renderbuffers[i],
2403 ObjectDataPtr(new RenderbufferData()));
2404 }
2405 }
2406 }
2407
glRenderbufferStorageOES(GLenum target,GLenum internalformat,GLsizei width,GLsizei height)2408 GL_API void GLAPIENTRY glRenderbufferStorageOES(GLenum target, GLenum internalformat, GLsizei width, GLsizei height){
2409 GET_CTX()
2410 GLES_CM_TRACE()
2411 SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION);
2412 SET_ERROR_IF(!GLEScmValidate::renderbufferTarget(target) || !GLEScmValidate::renderbufferInternalFrmt(ctx,internalformat) ,GL_INVALID_ENUM);
2413 if (internalformat==GL_RGB565_OES) //RGB565 not supported by GL
2414 internalformat = GL_RGB8_OES;
2415
2416 // Get current bounded renderbuffer
2417 // raise INVALID_OPERATIOn if no renderbuffer is bounded
2418 GLuint rb = ctx->getRenderbufferBinding();
2419 SET_ERROR_IF(rb == 0,GL_INVALID_OPERATION);
2420 auto objData = ctx->shareGroup()->getObjectData(NamedObjectType::RENDERBUFFER, rb);
2421 RenderbufferData *rbData = (RenderbufferData *)objData;
2422 SET_ERROR_IF(!rbData,GL_INVALID_OPERATION);
2423
2424 //
2425 // if the renderbuffer was an eglImage target, release
2426 // its underlying texture.
2427 //
2428 rbData->eglImageGlobalTexObject.reset();
2429 rbData->saveableTexture.reset();
2430
2431 ctx->dispatcher().glRenderbufferStorageEXT(target,internalformat,width,height);
2432 }
2433
glGetRenderbufferParameterivOES(GLenum target,GLenum pname,GLint * params)2434 GL_API void GLAPIENTRY glGetRenderbufferParameterivOES(GLenum target, GLenum pname, GLint* params) {
2435 GET_CTX()
2436 GLES_CM_TRACE()
2437 SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION);
2438 SET_ERROR_IF(!GLEScmValidate::renderbufferTarget(target) || !GLEScmValidate::renderbufferParams(pname) ,GL_INVALID_ENUM);
2439
2440 //
2441 // If this is a renderbuffer which is eglimage's target, we
2442 // should query the underlying eglimage's texture object instead.
2443 //
2444 GLuint rb = ctx->getRenderbufferBinding();
2445 if (rb) {
2446 auto objData = ctx->shareGroup()->getObjectData(
2447 NamedObjectType::RENDERBUFFER, rb);
2448 RenderbufferData *rbData = (RenderbufferData *)objData;
2449 if (rbData && rbData->eglImageGlobalTexObject) {
2450 GLenum texPname;
2451 switch(pname) {
2452 case GL_RENDERBUFFER_WIDTH_OES:
2453 texPname = GL_TEXTURE_WIDTH;
2454 break;
2455 case GL_RENDERBUFFER_HEIGHT_OES:
2456 texPname = GL_TEXTURE_HEIGHT;
2457 break;
2458 case GL_RENDERBUFFER_INTERNAL_FORMAT_OES:
2459 texPname = GL_TEXTURE_INTERNAL_FORMAT;
2460 break;
2461 case GL_RENDERBUFFER_RED_SIZE_OES:
2462 texPname = GL_TEXTURE_RED_SIZE;
2463 break;
2464 case GL_RENDERBUFFER_GREEN_SIZE_OES:
2465 texPname = GL_TEXTURE_GREEN_SIZE;
2466 break;
2467 case GL_RENDERBUFFER_BLUE_SIZE_OES:
2468 texPname = GL_TEXTURE_BLUE_SIZE;
2469 break;
2470 case GL_RENDERBUFFER_ALPHA_SIZE_OES:
2471 texPname = GL_TEXTURE_ALPHA_SIZE;
2472 break;
2473 case GL_RENDERBUFFER_DEPTH_SIZE_OES:
2474 texPname = GL_TEXTURE_DEPTH_SIZE;
2475 break;
2476 case GL_RENDERBUFFER_STENCIL_SIZE_OES:
2477 default:
2478 *params = 0; //XXX
2479 return;
2480 break;
2481 }
2482
2483 GLint prevTex;
2484 ctx->dispatcher().glGetIntegerv(GL_TEXTURE_BINDING_2D, &prevTex);
2485 ctx->dispatcher().glBindTexture(GL_TEXTURE_2D,
2486 rbData->eglImageGlobalTexObject->getGlobalName());
2487 ctx->dispatcher().glGetTexLevelParameteriv(GL_TEXTURE_2D, 0,
2488 texPname,
2489 params);
2490 ctx->dispatcher().glBindTexture(GL_TEXTURE_2D, prevTex);
2491 return;
2492 }
2493 }
2494
2495 ctx->dispatcher().glGetRenderbufferParameterivEXT(target,pname,params);
2496 }
2497
glIsFramebufferOES(GLuint framebuffer)2498 GL_API GLboolean GLAPIENTRY glIsFramebufferOES(GLuint framebuffer) {
2499 GET_CTX_RET(GL_FALSE)
2500 GLES_CM_TRACE()
2501 RET_AND_SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION,GL_FALSE);
2502 if (framebuffer) {
2503 return ctx->isFBO(framebuffer)
2504 ? GL_TRUE
2505 : GL_FALSE;
2506 }
2507 if (isCoreProfile() || isGles2Gles()) {
2508 return ctx->dispatcher().glIsFramebuffer(framebuffer);
2509 } else {
2510 return ctx->dispatcher().glIsFramebufferEXT(framebuffer);
2511 }
2512 }
2513
glBindFramebufferNoValidation(GLenum target,GLuint framebuffer)2514 void glBindFramebufferNoValidation(GLenum target, GLuint framebuffer) {
2515 GET_CTX()
2516 GLES_CM_TRACE()
2517 if (framebuffer && !ctx->isFBO(framebuffer)) {
2518 ctx->genFBOName(framebuffer);
2519 ctx->setFBOData(framebuffer,
2520 ObjectDataPtr(
2521 new FramebufferData(
2522 framebuffer,
2523 ctx->getFBOGlobalName(framebuffer))));
2524 }
2525 int globalBufferName =
2526 (framebuffer != 0)
2527 ? ctx->getFBOGlobalName(framebuffer)
2528 : ctx->getDefaultFBOGlobalName();
2529 if (isCoreProfile() || isGles2Gles()) {
2530 ctx->dispatcher().glBindFramebuffer(target,globalBufferName);
2531 } else {
2532 ctx->dispatcher().glBindFramebufferEXT(target,globalBufferName);
2533 }
2534
2535 // update framebuffer binding state
2536 ctx->setFramebufferBinding(GL_FRAMEBUFFER_EXT, framebuffer);
2537 }
2538
glBindFramebufferOES(GLenum target,GLuint framebuffer)2539 GL_API void GLAPIENTRY glBindFramebufferOES(GLenum target, GLuint framebuffer) {
2540 GET_CTX()
2541 GLES_CM_TRACE()
2542 SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION);
2543 SET_ERROR_IF(!GLEScmValidate::framebufferTarget(target) ,GL_INVALID_ENUM);
2544 glBindFramebufferNoValidation(target, framebuffer);
2545 }
2546
glDeleteFramebuffersOES(GLsizei n,const GLuint * framebuffers)2547 GL_API void GLAPIENTRY glDeleteFramebuffersOES(GLsizei n, const GLuint *framebuffers) {
2548 GET_CTX()
2549 GLES_CM_TRACE()
2550 SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION);
2551 GLuint fbName = ctx->getFramebufferBinding(GL_FRAMEBUFFER_EXT);
2552 for (int i=0;i<n;++i) {
2553 if (framebuffers[i] == fbName)
2554 glBindFramebufferOES(GL_FRAMEBUFFER_EXT, 0);
2555 ctx->deleteFBO(framebuffers[i]);
2556 }
2557 }
2558
glGenFramebuffersOES(GLsizei n,GLuint * framebuffers)2559 GL_API void GLAPIENTRY glGenFramebuffersOES(GLsizei n, GLuint *framebuffers) {
2560 GET_CTX()
2561 GLES_CM_TRACE()
2562 SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION);
2563 SET_ERROR_IF(n<0,GL_INVALID_VALUE);
2564 for (int i=0;i<n;i++) {
2565 framebuffers[i] = ctx->genFBOName(0, true);
2566 ctx->setFBOData(framebuffers[i],
2567 ObjectDataPtr(
2568 new FramebufferData(
2569 framebuffers[i],
2570 ctx->getFBOGlobalName(framebuffers[i]))));
2571 }
2572 }
2573
glCheckFramebufferStatusOES(GLenum target)2574 GL_API GLenum GLAPIENTRY glCheckFramebufferStatusOES(GLenum target) {
2575 GET_CTX_RET(0)
2576 GLES_CM_TRACE()
2577 RET_AND_SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION,0);
2578 RET_AND_SET_ERROR_IF(!GLEScmValidate::framebufferTarget(target) ,GL_INVALID_ENUM,0);
2579 return ctx->dispatcher().glCheckFramebufferStatusEXT(target);
2580 }
2581
glFramebufferTexture2DOES(GLenum target,GLenum attachment,GLenum textarget,GLuint texture,GLint level)2582 GL_API void GLAPIENTRY glFramebufferTexture2DOES(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) {
2583 GET_CTX()
2584 GLES_CM_TRACE()
2585 SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION);
2586 SET_ERROR_IF(!GLEScmValidate::framebufferTarget(target) || !GLEScmValidate::framebufferAttachment(attachment) ||
2587 !GLEScmValidate::textureTargetEx(textarget),GL_INVALID_ENUM);
2588 SET_ERROR_IF(!ctx->shareGroup().get(), GL_INVALID_OPERATION);
2589 SET_ERROR_IF(ctx->isDefaultFBOBound(target), GL_INVALID_OPERATION);
2590
2591 GLuint globalTexName = 0;
2592 if(texture) {
2593 if (!ctx->shareGroup()->isObject(NamedObjectType::TEXTURE, texture)) {
2594 ctx->shareGroup()->genName(NamedObjectType::TEXTURE, texture);
2595 }
2596 ObjectLocalName texname = ctx->getTextureLocalName(textarget,texture);
2597 globalTexName = ctx->shareGroup()->getGlobalName(
2598 NamedObjectType::TEXTURE, texname);
2599 }
2600
2601 ctx->dispatcher().glFramebufferTexture2DEXT(target,attachment,textarget,globalTexName,level);
2602
2603 // Update the the current framebuffer object attachment state
2604 GLuint fbName = ctx->getFramebufferBinding(GL_FRAMEBUFFER_EXT);
2605 auto fbObj = ctx->getFBOData(fbName);
2606 if (fbObj) {
2607 fbObj->setAttachment(
2608 ctx, attachment, textarget,
2609 texture, ObjectDataPtr());
2610 }
2611 }
2612
glFramebufferRenderbufferOES(GLenum target,GLenum attachment,GLenum renderbuffertarget,GLuint renderbuffer)2613 GL_API void GLAPIENTRY glFramebufferRenderbufferOES(GLenum target, GLenum attachment,GLenum renderbuffertarget, GLuint renderbuffer) {
2614 GET_CTX()
2615 GLES_CM_TRACE()
2616 SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION);
2617 SET_ERROR_IF(!GLEScmValidate::framebufferTarget(target) ||
2618 !GLEScmValidate::framebufferAttachment(attachment) ||
2619 !GLEScmValidate::renderbufferTarget(renderbuffertarget), GL_INVALID_ENUM);
2620 SET_ERROR_IF(!ctx->shareGroup().get(), GL_INVALID_OPERATION);
2621 SET_ERROR_IF(ctx->isDefaultFBOBound(target), GL_INVALID_OPERATION);
2622
2623 GLuint globalBufferName = 0;
2624 ObjectDataPtr obj;
2625
2626 // generate the renderbuffer object if not yet exist
2627 if (renderbuffer) {
2628 if (!ctx->shareGroup()->isObject(NamedObjectType::RENDERBUFFER,
2629 renderbuffer)) {
2630 ctx->shareGroup()->genName(NamedObjectType::RENDERBUFFER,
2631 renderbuffer);
2632 obj = ObjectDataPtr(new RenderbufferData());
2633 ctx->shareGroup()->setObjectData(
2634 NamedObjectType::RENDERBUFFER, renderbuffer, obj);
2635 }
2636 else {
2637 obj = ctx->shareGroup()->getObjectDataPtr(
2638 NamedObjectType::RENDERBUFFER, renderbuffer);
2639 }
2640 globalBufferName = ctx->shareGroup()->getGlobalName(
2641 NamedObjectType::RENDERBUFFER, renderbuffer);
2642 }
2643
2644 // Update the the current framebuffer object attachment state
2645 GLuint fbName = ctx->getFramebufferBinding(GL_FRAMEBUFFER_EXT);
2646 auto fbObj = ctx->getFBOData(fbName);
2647 if (fbObj) {
2648 fbObj->setAttachment(
2649 ctx, attachment, renderbuffertarget, renderbuffer, obj);
2650 }
2651
2652 if (renderbuffer && obj.get() != NULL) {
2653 RenderbufferData *rbData = (RenderbufferData *)obj.get();
2654 if (rbData->eglImageGlobalTexObject) {
2655 //
2656 // This renderbuffer object is an eglImage target
2657 // attach the eglimage's texture instead the renderbuffer.
2658 //
2659 ctx->dispatcher().glFramebufferTexture2DEXT(target,
2660 attachment,
2661 GL_TEXTURE_2D,
2662 rbData->eglImageGlobalTexObject->getGlobalName(),
2663 0);
2664 return;
2665 }
2666 }
2667
2668 if (isCoreProfile() || isGles2Gles()) {
2669 ctx->dispatcher().glFramebufferRenderbuffer(target,attachment,renderbuffertarget,globalBufferName);
2670 } else {
2671 ctx->dispatcher().glFramebufferRenderbufferEXT(target,attachment,renderbuffertarget,globalBufferName);
2672 }
2673 }
2674
glGetFramebufferAttachmentParameterivOES(GLenum target,GLenum attachment,GLenum pname,GLint * params)2675 GL_API void GLAPIENTRY glGetFramebufferAttachmentParameterivOES(GLenum target, GLenum attachment, GLenum pname, GLint *params) {
2676 GET_CTX()
2677 GLES_CM_TRACE()
2678 SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION);
2679 SET_ERROR_IF(!GLEScmValidate::framebufferTarget(target) || !GLEScmValidate::framebufferAttachment(attachment) ||
2680 !GLEScmValidate::framebufferAttachmentParams(pname), GL_INVALID_ENUM);
2681
2682 //
2683 // Take the attachment attribute from our state - if available
2684 //
2685 GLuint fbName = ctx->getFramebufferBinding(GL_FRAMEBUFFER_EXT);
2686 if (fbName) {
2687 auto fbObj = ctx->getFBOData(fbName);
2688 if (fbObj) {
2689 GLenum target;
2690 GLuint name = fbObj->getAttachment(attachment, &target, NULL);
2691 if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_OES) {
2692 *params = target;
2693 return;
2694 }
2695 else if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_OES) {
2696 *params = name;
2697 return;
2698 }
2699 }
2700 }
2701
2702 if (ctx->isDefaultFBOBound(target)) {
2703 SET_ERROR_IF(
2704 attachment == GL_DEPTH_ATTACHMENT ||
2705 attachment == GL_STENCIL_ATTACHMENT ||
2706 attachment == GL_DEPTH_STENCIL_ATTACHMENT ||
2707 (attachment >= GL_COLOR_ATTACHMENT0 &&
2708 attachment <= GL_COLOR_ATTACHMENT15), GL_INVALID_OPERATION);
2709 SET_ERROR_IF(pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, GL_INVALID_ENUM);
2710
2711 if (attachment == GL_BACK)
2712 attachment = GL_COLOR_ATTACHMENT0;
2713 if (attachment == GL_DEPTH)
2714 attachment = GL_DEPTH_ATTACHMENT;
2715 if (attachment == GL_STENCIL)
2716 attachment = GL_STENCIL_ATTACHMENT;
2717 }
2718
2719 ctx->dispatcher().glGetFramebufferAttachmentParameterivEXT(target,attachment,pname,params);
2720
2721 if (ctx->isDefaultFBOBound(target) && *params == GL_RENDERBUFFER) {
2722 *params = GL_FRAMEBUFFER_DEFAULT;
2723 }
2724 }
2725
glReadPixels(GLint x,GLint y,GLsizei width,GLsizei height,GLenum format,GLenum type,GLvoid * pixels)2726 GL_API void GL_APIENTRY glReadPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels) {
2727 GET_CTX()
2728 GLES_CM_TRACE()
2729 SET_ERROR_IF(!(GLEScmValidate::pixelFrmt(ctx,format) && GLEScmValidate::pixelType(ctx,type)),GL_INVALID_ENUM);
2730 SET_ERROR_IF(!(GLEScmValidate::pixelOp(format,type)),GL_INVALID_OPERATION);
2731
2732 if (ctx->isDefaultFBOBound(GL_READ_FRAMEBUFFER) &&
2733 ctx->getDefaultFBOMultisamples()) {
2734
2735 GLint prev_bound_rbo = 0;
2736 GLint prev_bound_draw_fbo = 0;
2737
2738 glGetIntegerv(GL_RENDERBUFFER_BINDING, &prev_bound_rbo);
2739 glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &prev_bound_draw_fbo);
2740
2741 GLuint resolve_fbo = 0;
2742 GLuint resolve_rbo = 0;
2743 glGenFramebuffersOES(1, &resolve_fbo);
2744 glGenRenderbuffersOES(1, &resolve_rbo);
2745
2746 int fboFormat = ctx->getDefaultFBOColorFormat();
2747 int fboWidth = ctx->getDefaultFBOWidth();
2748 int fboHeight = ctx->getDefaultFBOHeight();
2749
2750 glBindRenderbufferOES(GL_RENDERBUFFER, resolve_rbo);
2751 glRenderbufferStorageOES(GL_RENDERBUFFER, fboFormat, fboWidth, fboHeight);
2752 glBindFramebufferNoValidation(GL_FRAMEBUFFER, resolve_fbo);
2753 glFramebufferRenderbufferOES(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, resolve_rbo);
2754
2755 // GL_READ_FRAMEBUFFER was not supported in GLES1. But the
2756 // dispatcher actually supports it.
2757 glBindFramebufferNoValidation(GL_READ_FRAMEBUFFER, 0);
2758 glBindFramebufferNoValidation(GL_DRAW_FRAMEBUFFER, resolve_fbo);
2759
2760 bool scissorEnabled = glIsEnabled(GL_SCISSOR_TEST);
2761
2762 if (scissorEnabled) glDisable(GL_SCISSOR_TEST);
2763 ctx->dispatcher().glBlitFramebuffer(0, 0, fboWidth, fboHeight, 0, 0, fboWidth, fboHeight,
2764 GL_COLOR_BUFFER_BIT, GL_LINEAR);
2765 if (scissorEnabled) glEnable(GL_SCISSOR_TEST);
2766
2767 glBindFramebufferNoValidation(GL_READ_FRAMEBUFFER, resolve_fbo);
2768
2769 ctx->dispatcher().glReadPixels(x,y,width,height,format,type,pixels);
2770
2771 glDeleteRenderbuffersOES(1, &resolve_rbo);
2772 glDeleteFramebuffersOES(1, &resolve_fbo);
2773
2774 glBindRenderbufferOES(GL_RENDERBUFFER, prev_bound_rbo);
2775
2776 glBindFramebufferNoValidation(GL_DRAW_FRAMEBUFFER, prev_bound_draw_fbo);
2777 glBindFramebufferNoValidation(GL_READ_FRAMEBUFFER, 0);
2778 } else {
2779 ctx->dispatcher().glReadPixels(x,y,width,height,format,type,pixels);
2780 }
2781 }
2782
glGenerateMipmapOES(GLenum target)2783 GL_API void GL_APIENTRY glGenerateMipmapOES(GLenum target) {
2784 GET_CTX()
2785 GLES_CM_TRACE()
2786 SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION);
2787 SET_ERROR_IF(!GLEScmValidate::textureTargetLimited(target),GL_INVALID_ENUM);
2788 if (ctx->shareGroup().get()) {
2789 TextureData *texData = getTextureTargetData(target);
2790 if (texData) {
2791 unsigned int width = texData->width;
2792 unsigned int height = texData->height;
2793 // set error code if either the width or height is not a power of two.
2794 SET_ERROR_IF(width == 0 || height == 0 ||
2795 (width & (width - 1)) != 0 || (height & (height - 1)) != 0,
2796 GL_INVALID_OPERATION);
2797 texData->setMipmapLevelAtLeast(maxMipmapLevel(texData->width,
2798 texData->height));
2799 }
2800 }
2801 ctx->dispatcher().glGenerateMipmapEXT(target);
2802 }
2803
glCurrentPaletteMatrixOES(GLuint index)2804 GL_API void GL_APIENTRY glCurrentPaletteMatrixOES(GLuint index) {
2805 GET_CTX()
2806 GLES_CM_TRACE()
2807 SET_ERROR_IF(!(ctx->getCaps()->GL_ARB_MATRIX_PALETTE && ctx->getCaps()->GL_ARB_VERTEX_BLEND),GL_INVALID_OPERATION);
2808 ctx->dispatcher().glCurrentPaletteMatrixARB(index);
2809 }
2810
glLoadPaletteFromModelViewMatrixOES()2811 GL_API void GL_APIENTRY glLoadPaletteFromModelViewMatrixOES() {
2812 GET_CTX()
2813 GLES_CM_TRACE()
2814 SET_ERROR_IF(!(ctx->getCaps()->GL_ARB_MATRIX_PALETTE && ctx->getCaps()->GL_ARB_VERTEX_BLEND),GL_INVALID_OPERATION);
2815 GLint matrix[16];
2816 ctx->dispatcher().glGetIntegerv(GL_MODELVIEW_MATRIX,matrix);
2817 ctx->dispatcher().glMatrixIndexuivARB(1,(GLuint*)matrix);
2818
2819 }
2820
glMatrixIndexPointerOES(GLint size,GLenum type,GLsizei stride,const GLvoid * pointer)2821 GL_API void GL_APIENTRY glMatrixIndexPointerOES(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) {
2822 GET_CTX()
2823 GLES_CM_TRACE()
2824 SET_ERROR_IF(!(ctx->getCaps()->GL_ARB_MATRIX_PALETTE && ctx->getCaps()->GL_ARB_VERTEX_BLEND),GL_INVALID_OPERATION);
2825 ctx->dispatcher().glMatrixIndexPointerARB(size,type,stride,pointer);
2826 }
2827
glWeightPointerOES(GLint size,GLenum type,GLsizei stride,const GLvoid * pointer)2828 GL_API void GL_APIENTRY glWeightPointerOES(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) {
2829 GET_CTX()
2830 GLES_CM_TRACE()
2831 SET_ERROR_IF(!(ctx->getCaps()->GL_ARB_MATRIX_PALETTE && ctx->getCaps()->GL_ARB_VERTEX_BLEND),GL_INVALID_OPERATION);
2832 ctx->dispatcher().glWeightPointerARB(size,type,stride,pointer);
2833
2834 }
2835
glTexGenfOES(GLenum coord,GLenum pname,GLfloat param)2836 GL_API void GL_APIENTRY glTexGenfOES (GLenum coord, GLenum pname, GLfloat param) {
2837 GET_CTX()
2838 GLES_CM_TRACE()
2839 SET_ERROR_IF(!GLEScmValidate::texGen(coord,pname),GL_INVALID_ENUM);
2840 if (coord == GL_TEXTURE_GEN_STR_OES) {
2841 ctx->dispatcher().glTexGenf(GL_S,pname,param);
2842 ctx->dispatcher().glTexGenf(GL_T,pname,param);
2843 ctx->dispatcher().glTexGenf(GL_R,pname,param);
2844 }
2845 else
2846 ctx->dispatcher().glTexGenf(coord,pname,param);
2847 }
2848
glTexGenfvOES(GLenum coord,GLenum pname,const GLfloat * params)2849 GL_API void GL_APIENTRY glTexGenfvOES (GLenum coord, GLenum pname, const GLfloat *params) {
2850 GET_CTX()
2851 GLES_CM_TRACE()
2852 SET_ERROR_IF(!GLEScmValidate::texGen(coord,pname),GL_INVALID_ENUM);
2853 if (coord == GL_TEXTURE_GEN_STR_OES) {
2854 ctx->dispatcher().glTexGenfv(GL_S,pname,params);
2855 ctx->dispatcher().glTexGenfv(GL_T,pname,params);
2856 ctx->dispatcher().glTexGenfv(GL_R,pname,params);
2857 }
2858 else
2859 ctx->dispatcher().glTexGenfv(coord,pname,params);
2860 }
glTexGeniOES(GLenum coord,GLenum pname,GLint param)2861 GL_API void GL_APIENTRY glTexGeniOES (GLenum coord, GLenum pname, GLint param) {
2862 GET_CTX_CM()
2863 GLES_CM_TRACE()
2864 SET_ERROR_IF(!GLEScmValidate::texGen(coord,pname),GL_INVALID_ENUM);
2865 ctx->texGeni(coord, pname, param);
2866 }
glTexGenivOES(GLenum coord,GLenum pname,const GLint * params)2867 GL_API void GL_APIENTRY glTexGenivOES (GLenum coord, GLenum pname, const GLint *params) {
2868 GET_CTX_CM()
2869 GLES_CM_TRACE()
2870 SET_ERROR_IF(!GLEScmValidate::texGen(coord,pname),GL_INVALID_ENUM);
2871 ctx->texGeniv(coord, pname, params);
2872 }
glTexGenxOES(GLenum coord,GLenum pname,GLfixed param)2873 GL_API void GL_APIENTRY glTexGenxOES (GLenum coord, GLenum pname, GLfixed param) {
2874 GET_CTX_CM()
2875 GLES_CM_TRACE()
2876 SET_ERROR_IF(!GLEScmValidate::texGen(coord,pname),GL_INVALID_ENUM);
2877 ctx->texGenf(coord, pname, X2F(param));
2878 }
glTexGenxvOES(GLenum coord,GLenum pname,const GLfixed * params)2879 GL_API void GL_APIENTRY glTexGenxvOES (GLenum coord, GLenum pname, const GLfixed *params) {
2880 GET_CTX_CM()
2881 GLES_CM_TRACE()
2882 SET_ERROR_IF(!GLEScmValidate::texGen(coord,pname),GL_INVALID_ENUM);
2883 GLfloat tmpParams[1];
2884 tmpParams[0] = X2F(params[0]);
2885 ctx->texGenfv(coord, pname, tmpParams);
2886 }
2887
glGetTexGenfvOES(GLenum coord,GLenum pname,GLfloat * params)2888 GL_API void GL_APIENTRY glGetTexGenfvOES (GLenum coord, GLenum pname, GLfloat *params) {
2889 GET_CTX_CM()
2890 GLES_CM_TRACE()
2891 ctx->getTexGenfv(coord, pname, params);
2892 }
glGetTexGenivOES(GLenum coord,GLenum pname,GLint * params)2893 GL_API void GL_APIENTRY glGetTexGenivOES (GLenum coord, GLenum pname, GLint *params) {
2894 GET_CTX_CM()
2895 GLES_CM_TRACE()
2896 ctx->getTexGeniv(coord, pname, params);
2897 }
2898
glGetTexGenxvOES(GLenum coord,GLenum pname,GLfixed * params)2899 GL_API void GL_APIENTRY glGetTexGenxvOES (GLenum coord, GLenum pname, GLfixed *params) {
2900 GET_CTX_CM()
2901 GLES_CM_TRACE()
2902 GLfloat tmpParams[1];
2903 ctx->getTexGenfv(coord, pname, tmpParams);
2904 params[0] = F2X(tmpParams[0]);
2905 }
2906
2907
2908 template <class T, GLenum TypeName>
glDrawTexOES(T x,T y,T z,T width,T height)2909 void glDrawTexOES (T x, T y, T z, T width, T height) {
2910 GET_CTX_CM()
2911 GLES_CM_TRACE()
2912
2913 SET_ERROR_IF((width<=0 || height<=0),GL_INVALID_VALUE);
2914
2915 ctx->drawValidate();
2916 ctx->drawTexOES((float)x, (float)y, (float)z, (float)width, (float)height);
2917 }
2918
glDrawTexsOES(GLshort x,GLshort y,GLshort z,GLshort width,GLshort height)2919 GL_API void GL_APIENTRY glDrawTexsOES (GLshort x, GLshort y, GLshort z, GLshort width, GLshort height) {
2920 GET_CTX_CM()
2921 GLES_CM_TRACE()
2922 glDrawTexOES<GLshort,GL_SHORT>(x,y,z,width,height);
2923 }
2924
glDrawTexiOES(GLint x,GLint y,GLint z,GLint width,GLint height)2925 GL_API void GL_APIENTRY glDrawTexiOES (GLint x, GLint y, GLint z, GLint width, GLint height) {
2926 GET_CTX_CM()
2927 GLES_CM_TRACE()
2928 glDrawTexOES<GLint,GL_INT>(x,y,z,width,height);
2929 }
2930
glDrawTexfOES(GLfloat x,GLfloat y,GLfloat z,GLfloat width,GLfloat height)2931 GL_API void GL_APIENTRY glDrawTexfOES (GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height) {
2932 GET_CTX_CM()
2933 GLES_CM_TRACE()
2934 glDrawTexOES<GLfloat,GL_FLOAT>(x,y,z,width,height);
2935 }
2936
glDrawTexxOES(GLfixed x,GLfixed y,GLfixed z,GLfixed width,GLfixed height)2937 GL_API void GL_APIENTRY glDrawTexxOES (GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height) {
2938 GET_CTX_CM()
2939 GLES_CM_TRACE()
2940 glDrawTexOES<GLfloat,GL_FLOAT>(X2F(x),X2F(y),X2F(z),X2F(width),X2F(height));
2941 }
2942
glDrawTexsvOES(const GLshort * coords)2943 GL_API void GL_APIENTRY glDrawTexsvOES (const GLshort * coords) {
2944 GET_CTX_CM()
2945 GLES_CM_TRACE()
2946 glDrawTexOES<GLshort,GL_SHORT>(coords[0],coords[1],coords[2],coords[3],coords[4]);
2947 }
2948
glDrawTexivOES(const GLint * coords)2949 GL_API void GL_APIENTRY glDrawTexivOES (const GLint * coords) {
2950 GET_CTX_CM()
2951 GLES_CM_TRACE()
2952 glDrawTexOES<GLint,GL_INT>(coords[0],coords[1],coords[2],coords[3],coords[4]);
2953 }
2954
glDrawTexfvOES(const GLfloat * coords)2955 GL_API void GL_APIENTRY glDrawTexfvOES (const GLfloat * coords) {
2956 GET_CTX_CM()
2957 GLES_CM_TRACE()
2958 glDrawTexOES<GLfloat,GL_FLOAT>(coords[0],coords[1],coords[2],coords[3],coords[4]);
2959 }
2960
glDrawTexxvOES(const GLfixed * coords)2961 GL_API void GL_APIENTRY glDrawTexxvOES (const GLfixed * coords) {
2962 GET_CTX_CM()
2963 GLES_CM_TRACE()
2964 glDrawTexOES<GLfloat,GL_FLOAT>(X2F(coords[0]),X2F(coords[1]),X2F(coords[2]),X2F(coords[3]),X2F(coords[4]));
2965 }
2966
2967 } // namespace translator
2968 } // namespace gles1
2969