1ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall/*
2ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall* Copyright (C) 2011 The Android Open Source Project
3ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall*
4ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall* Licensed under the Apache License, Version 2.0 (the "License")
5ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall* you may not use this file except in compliance with the License.
6ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall* You may obtain a copy of the License at
7ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall*
8ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall* http://www.apache.org/licenses/LICENSE-2.0
9ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall*
10ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall* Unless required by applicable law or agreed to in writing, software
11ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall* distributed under the License is distributed on an "AS IS" BASIS,
12ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall* See the License for the specific language governing permissions and
14ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall* limitations under the License.
15ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall*/
16ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
17ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall#ifdef _WIN32
18ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall#undef  GL_APICALL
19ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall#define GL_API __declspec(dllexport)
20ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall#define GL_APICALL __declspec(dllexport)
21ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall#endif
22ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
23ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall#define GL_GLEXT_PROTOTYPES
24ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall#include <stdio.h>
25ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall#include <GLES2/gl2.h>
26ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall#include <GLES2/gl2ext.h>
27ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall#include <GLcommon/TranslatorIfaces.h>
28ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall#include <GLcommon/gldefs.h>
29ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall#include "GLESv2Context.h"
30ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall#include "GLESv2Validate.h"
31ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall#include "ShaderParser.h"
32ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall#include "ProgramData.h"
33ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall#include <GLcommon/TextureUtils.h>
34ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall#include <GLcommon/FramebufferData.h>
35ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
36ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hallextern "C" {
37ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
38ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall//decleration
39ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hallstatic void initContext(GLEScontext* ctx,ShareGroupPtr grp);
40ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hallstatic void deleteGLESContext(GLEScontext* ctx);
41ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hallstatic void setShareGroup(GLEScontext* ctx,ShareGroupPtr grp);
42ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hallstatic GLEScontext* createGLESContext();
43ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hallstatic __translatorMustCastToProperFunctionPointerType getProcAddress(const char* procName);
44ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
45ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
46ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
47ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall/************************************** GLES EXTENSIONS *********************************************************/
48ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall//extentions descriptor
49ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Halltypedef std::map<std::string, __translatorMustCastToProperFunctionPointerType> ProcTableMap;
50ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallProcTableMap *s_glesExtensions = NULL;
51ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall/****************************************************************************************************************/
52ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
53ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hallstatic EGLiface*  s_eglIface = NULL;
54ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hallstatic GLESiface  s_glesIface = {
55ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    createGLESContext:createGLESContext,
56ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    initContext      :initContext,
57ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    deleteGLESContext:deleteGLESContext,
58ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    flush            :(FUNCPTR)glFlush,
59ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    finish           :(FUNCPTR)glFinish,
60ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    setShareGroup    :setShareGroup,
61ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    getProcAddress   :getProcAddress
62ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall};
63ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
64ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall#include <GLcommon/GLESmacros.h>
65ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
66ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hallextern "C" {
67ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
68ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hallstatic void initContext(GLEScontext* ctx,ShareGroupPtr grp) {
69ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if (!ctx->isInitialized()) {
70ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->setShareGroup(grp);
71ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->init();
72ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        glBindTexture(GL_TEXTURE_2D,0);
73ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        glBindTexture(GL_TEXTURE_CUBE_MAP,0);
74ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
75ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
76ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hallstatic GLEScontext* createGLESContext() {
77ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    return new GLESv2Context();
78ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
79ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
80ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hallstatic void deleteGLESContext(GLEScontext* ctx) {
81ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    delete ctx;
82ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
83ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
84ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hallstatic void setShareGroup(GLEScontext* ctx,ShareGroupPtr grp) {
85ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx) {
86ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->setShareGroup(grp);
87ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
88ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
89ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
90ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hallstatic __translatorMustCastToProperFunctionPointerType getProcAddress(const char* procName) {
91ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_RET(NULL)
92ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->getGlobalLock();
93ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    static bool proc_table_initialized = false;
94ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if (!proc_table_initialized) {
95ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        proc_table_initialized = true;
96ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if (!s_glesExtensions)
97ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            s_glesExtensions = new ProcTableMap();
98ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        else
99ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            s_glesExtensions->clear();
100ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        (*s_glesExtensions)["glEGLImageTargetTexture2DOES"] = (__translatorMustCastToProperFunctionPointerType)glEGLImageTargetTexture2DOES;
101ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        (*s_glesExtensions)["glEGLImageTargetRenderbufferStorageOES"]=(__translatorMustCastToProperFunctionPointerType)glEGLImageTargetRenderbufferStorageOES;
102ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
103ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    __translatorMustCastToProperFunctionPointerType ret=NULL;
104ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ProcTableMap::iterator val = s_glesExtensions->find(procName);
105ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if (val!=s_glesExtensions->end())
106ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ret = val->second;
107ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->releaseGlobalLock();
108ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
109ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    return ret;
110ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
111ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
112ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL GLESiface* __translator_getIfaces(EGLiface* eglIface){
113ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    s_eglIface = eglIface;
114ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    return & s_glesIface;
115ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
116ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
117ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
118ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
119ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hallstatic ObjectLocalName TextureLocalName(GLenum target,unsigned int tex) {
120ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_RET(0);
121ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    return (tex!=0? tex : ctx->getDefaultTextureName(target));
122ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
123ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
124ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hallstatic TextureData* getTextureData(ObjectLocalName tex) {
125ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_RET(NULL);
126ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    TextureData *texData = NULL;
127ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ObjectDataPtr objData = ctx->shareGroup()->getObjectData(TEXTURE,tex);
128ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(!objData.Ptr()){
129ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        texData = new TextureData();
130ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->shareGroup()->setObjectData(TEXTURE, tex, ObjectDataPtr(texData));
131ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    } else {
132ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        texData = (TextureData*)objData.Ptr();
133ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
134ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    return texData;
135ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
136ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
137ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hallstatic TextureData* getTextureTargetData(GLenum target){
138ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_RET(NULL);
139ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    unsigned int tex = ctx->getBindedTexture(target);
140ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    return getTextureData(TextureLocalName(target,tex));
141ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
142ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
143ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glActiveTexture(GLenum texture){
144ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_V2();
145ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF (!GLESv2Validate::textureEnum(texture,ctx->getMaxTexUnits()),GL_INVALID_ENUM);
146ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->setActiveTexture(texture);
147ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glActiveTexture(texture);
148ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
149ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
150ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glAttachShader(GLuint program, GLuint shader){
151ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
152ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr()) {
153ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program);
154ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE);
155ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        const GLuint globalShaderName  = ctx->shareGroup()->getGlobalName(SHADER,shader);
156ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(globalShaderName==0, GL_INVALID_VALUE);
157ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
158ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ObjectDataPtr programData = ctx->shareGroup()->getObjectData(SHADER,program);
159ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ObjectDataPtr shaderData = ctx->shareGroup()->getObjectData(SHADER,shader);
160ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(!shaderData.Ptr() || !programData.Ptr() ,GL_INVALID_OPERATION);
161ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(!(shaderData.Ptr()->getDataType() ==SHADER_DATA) ||
162ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                     !(programData.Ptr()->getDataType()==PROGRAM_DATA) ,GL_INVALID_OPERATION);
163ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
164ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        GLenum shaderType = ((ShaderParser*)shaderData.Ptr())->getType();
165ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ProgramData* pData = (ProgramData*)programData.Ptr();
166ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF((pData->getAttachedShader(shaderType)!=0), GL_INVALID_OPERATION);
167ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        pData->attachShader(shader,shaderType);
168ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glAttachShader(globalProgramName,globalShaderName);
169ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
170ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
171ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
172ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glBindAttribLocation(GLuint program, GLuint index, const GLchar* name){
173ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
174ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!GLESv2Validate::attribName(name),GL_INVALID_OPERATION);
175ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!GLESv2Validate::attribIndex(index),GL_INVALID_VALUE);
176ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr()) {
177ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program);
178ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE);
179ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program);
180ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(objData.Ptr()->getDataType()!=PROGRAM_DATA,GL_INVALID_OPERATION);
181ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
182ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glBindAttribLocation(globalProgramName,index,name);
183ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
184ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
185ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
186ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glBindBuffer(GLenum target, GLuint buffer){
187ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
188ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!GLESv2Validate::bufferTarget(target),GL_INVALID_ENUM);
189ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    //if buffer wasn't generated before,generate one
190ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(buffer && ctx->shareGroup().Ptr() && !ctx->shareGroup()->isObject(VERTEXBUFFER,buffer)){
191ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->shareGroup()->genName(VERTEXBUFFER,buffer);
192ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->shareGroup()->setObjectData(VERTEXBUFFER,buffer,ObjectDataPtr(new GLESbuffer()));
193ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
194ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->bindBuffer(target,buffer);
195ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if (buffer) {
196ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        GLESbuffer* vbo = (GLESbuffer*)ctx->shareGroup()->getObjectData(VERTEXBUFFER,buffer).Ptr();
197ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        vbo->setBinded();
198ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
199ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
200ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
201ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glBindFramebuffer(GLenum target, GLuint framebuffer){
202ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
203ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!GLESv2Validate::framebufferTarget(target),GL_INVALID_ENUM);
204ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
205ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GLuint globalFrameBufferName = framebuffer;
206ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(framebuffer && ctx->shareGroup().Ptr()){
207ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        globalFrameBufferName = ctx->shareGroup()->getGlobalName(FRAMEBUFFER,framebuffer);
208ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        //if framebuffer wasn't generated before,generate one
209ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if(!globalFrameBufferName){
210ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->shareGroup()->genName(FRAMEBUFFER,framebuffer);
211ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->shareGroup()->setObjectData(FRAMEBUFFER, framebuffer,
212ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                                             ObjectDataPtr(new FramebufferData(framebuffer)));
213ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            globalFrameBufferName = ctx->shareGroup()->getGlobalName(FRAMEBUFFER,framebuffer);
214ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
215ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
216ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glBindFramebufferEXT(target,globalFrameBufferName);
217ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
218ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    // update framebuffer binding state
219ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->setFramebufferBinding(framebuffer);
220ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
221ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
222ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glBindRenderbuffer(GLenum target, GLuint renderbuffer){
223ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
224ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!GLESv2Validate::renderbufferTarget(target),GL_INVALID_ENUM);
225ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
226ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GLuint globalRenderBufferName = renderbuffer;
227ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(renderbuffer && ctx->shareGroup().Ptr()){
228ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        globalRenderBufferName = ctx->shareGroup()->getGlobalName(RENDERBUFFER,renderbuffer);
229ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        //if renderbuffer wasn't generated before,generate one
230ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if(!globalRenderBufferName){
231ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->shareGroup()->genName(RENDERBUFFER,renderbuffer);
232ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->shareGroup()->setObjectData(RENDERBUFFER,
233ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                                         renderbuffer,
234ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                                         ObjectDataPtr(new RenderbufferData()));
235ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            globalRenderBufferName = ctx->shareGroup()->getGlobalName(RENDERBUFFER,renderbuffer);
236ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
237ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
238ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glBindRenderbufferEXT(target,globalRenderBufferName);
239ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
240ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    // update renderbuffer binding state
241ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->setRenderbufferBinding(renderbuffer);
242ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
243ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
244ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glBindTexture(GLenum target, GLuint texture){
245ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
246ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!GLESv2Validate::textureTarget(target),GL_INVALID_ENUM)
247ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
248ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    //for handling default texture (0)
249ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ObjectLocalName localTexName = TextureLocalName(target,texture);
250ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
251ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GLuint globalTextureName = localTexName;
252ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr()){
253ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        globalTextureName = ctx->shareGroup()->getGlobalName(TEXTURE,localTexName);
254ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        //if texture wasn't generated before,generate one
255ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if(!globalTextureName){
256ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->shareGroup()->genName(TEXTURE,localTexName);
257ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            globalTextureName = ctx->shareGroup()->getGlobalName(TEXTURE,localTexName);
258ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
259ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
260ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        TextureData* texData = getTextureData(localTexName);
261ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if (texData->target==0)
262ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            texData->target = target;
263ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        //if texture was already bound to another target
264ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(ctx->GLTextureTargetToLocal(texData->target) != ctx->GLTextureTargetToLocal(target), GL_INVALID_OPERATION);
265ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        texData->wasBound = true;
266ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
267ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
268ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->setBindedTexture(target,texture);
269ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glBindTexture(target,globalTextureName);
270ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
271ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
272ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha){
273ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
274ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glBlendColor(red,green,blue,alpha);
275ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
276ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
277ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glBlendEquation( GLenum mode ){
278ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
279ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!GLESv2Validate::blendEquationMode(mode),GL_INVALID_ENUM)
280ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glBlendEquation(mode);
281ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
282ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
283ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha){
284ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
285ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!(GLESv2Validate::blendEquationMode(modeRGB) && GLESv2Validate::blendEquationMode(modeAlpha)),GL_INVALID_ENUM);
286ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glBlendEquationSeparate(modeRGB,modeAlpha);
287ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
288ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
289ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor){
290ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
291ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!GLESv2Validate::blendSrc(sfactor) || !GLESv2Validate::blendDst(dfactor),GL_INVALID_ENUM)
292ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glBlendFunc(sfactor,dfactor);
293ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
294ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
295ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha){
296ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
297ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(
298ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall!(GLESv2Validate::blendSrc(srcRGB) && GLESv2Validate::blendDst(dstRGB) && GLESv2Validate::blendSrc(srcAlpha) && GLESv2Validate::blendDst(dstAlpha)),GL_INVALID_ENUM);
299ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glBlendFuncSeparate(srcRGB,dstRGB,srcAlpha,dstAlpha);
300ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
301ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
302ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage){
303ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
304ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!GLESv2Validate::bufferTarget(target),GL_INVALID_ENUM);
305ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!ctx->isBindedBuffer(target),GL_INVALID_OPERATION);
306ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->setBufferData(target,size,data,usage);
307ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
308ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
309ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data){
310ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
311ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!ctx->isBindedBuffer(target),GL_INVALID_OPERATION);
312ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!GLESv2Validate::bufferTarget(target),GL_INVALID_ENUM);
313ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!ctx->setBufferSubData(target,offset,size,data),GL_INVALID_VALUE);
314ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
315ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
316ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
317ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL GLenum GL_APIENTRY glCheckFramebufferStatus(GLenum target){
318ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_RET(GL_FRAMEBUFFER_COMPLETE);
319ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    RET_AND_SET_ERROR_IF(!GLESv2Validate::framebufferTarget(target),GL_INVALID_ENUM,GL_FRAMEBUFFER_COMPLETE);
320ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->drawValidate();
321ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    return ctx->dispatcher().glCheckFramebufferStatusEXT(target);
322ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
323ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
324ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glClear(GLbitfield mask){
325ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
326ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->drawValidate();
327ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
328ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glClear(mask);
329ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
330ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha){
331ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
332ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glClearColor(red,green,blue,alpha);
333ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
334ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glClearDepthf(GLclampf depth){
335ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
336ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glClearDepth(depth);
337ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
338ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glClearStencil(GLint s){
339ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
340ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glClearStencil(s);
341ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
342ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha){
343ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
344ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glColorMask(red,green,blue,alpha);
345ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
346ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
347ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glCompileShader(GLuint shader){
348ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
349ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr()) {
350ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        const GLuint globalShaderName = ctx->shareGroup()->getGlobalName(SHADER,shader);
351ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(globalShaderName==0, GL_INVALID_VALUE);
352ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,shader);
353ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(objData.Ptr()->getDataType()!= SHADER_DATA,GL_INVALID_OPERATION);
354ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ShaderParser* sp = (ShaderParser*)objData.Ptr();
355ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glCompileShader(globalShaderName);
356ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
357ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        GLsizei infoLogLength=0;
358ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        GLchar* infoLog;
359ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glGetShaderiv(globalShaderName,GL_INFO_LOG_LENGTH,&infoLogLength);
360ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        infoLog = new GLchar[infoLogLength+1];
361ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glGetShaderInfoLog(globalShaderName,infoLogLength,NULL,infoLog);
362ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        sp->setInfoLog(infoLog);
363ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
364ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
365ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
366ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid* data)
367ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall{
368ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
369ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!GLESv2Validate::textureTargetEx(target),GL_INVALID_ENUM);
370ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
371ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    doCompressedTexImage2D(ctx, target, level, internalformat,
372ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                                width, height, border,
373ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                                imageSize, data, (void*)glTexImage2D);
374ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
375ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
376ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid* data){
377ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
378ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!GLESv2Validate::textureTargetEx(target),GL_INVALID_ENUM);
379ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glCompressedTexSubImage2D(target,level,xoffset,yoffset,width,height,format,imageSize,data);
380ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
381ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
382ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border){
383ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
384ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!(GLESv2Validate::pixelFrmt(ctx,internalformat) && GLESv2Validate::textureTargetEx(target)),GL_INVALID_ENUM);
385ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(border != 0,GL_INVALID_VALUE);
386ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glCopyTexImage2D(target,level,internalformat,x,y,width,height,border);
387ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
388ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
389ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height){
390ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
391ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!GLESv2Validate::textureTargetEx(target),GL_INVALID_ENUM);
392ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glCopyTexSubImage2D(target,level,xoffset,yoffset,x,y,width,height);
393ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
394ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
395ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL GLuint GL_APIENTRY glCreateProgram(void){
396ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_RET(0);
397ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    const GLuint globalProgramName = ctx->dispatcher().glCreateProgram();
398ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr() && globalProgramName) {
399ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ProgramData* programInfo = new ProgramData();
400ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            const GLuint localProgramName = ctx->shareGroup()->genName(SHADER, 0, true);
401ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->shareGroup()->replaceGlobalName(SHADER,localProgramName,globalProgramName);
402ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->shareGroup()->setObjectData(SHADER,localProgramName,ObjectDataPtr(programInfo));
403ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            return localProgramName;
404ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
405ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(globalProgramName){
406ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glDeleteProgram(globalProgramName);
407ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
408ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    return 0;
409ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
410ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
411ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL GLuint GL_APIENTRY glCreateShader(GLenum type){
412ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_V2_RET(0);
413ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    RET_AND_SET_ERROR_IF(!GLESv2Validate::shaderType(type),GL_INVALID_ENUM,0);
414ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    const GLuint globalShaderName = ctx->dispatcher().glCreateShader(type);
415ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr() && globalShaderName) {
416ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            const GLuint localShaderName = ctx->shareGroup()->genName(SHADER, 0, true);
417ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ShaderParser* sp = new ShaderParser(type);
418ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->shareGroup()->replaceGlobalName(SHADER,localShaderName,globalShaderName);
419ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->shareGroup()->setObjectData(SHADER,localShaderName,ObjectDataPtr(sp));
420ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            return localShaderName;
421ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
422ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(globalShaderName){
423ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glDeleteShader(globalShaderName);
424ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
425ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    return 0;
426ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
427ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
428ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glCullFace(GLenum mode){
429ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
430ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glCullFace(mode);
431ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
432ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
433ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glDeleteBuffers(GLsizei n, const GLuint* buffers){
434ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
435ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(n<0,GL_INVALID_VALUE);
436ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr()) {
437ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        for(int i=0; i < n; i++){
438ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall           ctx->shareGroup()->deleteName(VERTEXBUFFER,buffers[i]);
439ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
440ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
441ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
442ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
443ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers){
444ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
445ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(n<0,GL_INVALID_VALUE);
446ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr()) {
447ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        for(int i=0; i < n; i++){
448ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall           const GLuint globalFrameBufferName = ctx->shareGroup()->getGlobalName(FRAMEBUFFER,framebuffers[i]);
449ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall           ctx->shareGroup()->deleteName(FRAMEBUFFER,framebuffers[i]);
450ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall           ctx->dispatcher().glDeleteFramebuffersEXT(1,&globalFrameBufferName);
451ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
452ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
453ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
454ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
455ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers){
456ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
457ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(n<0,GL_INVALID_VALUE);
458ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr()) {
459ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        for(int i=0; i < n; i++){
460ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall           const GLuint globalRenderBufferName = ctx->shareGroup()->getGlobalName(RENDERBUFFER,renderbuffers[i]);
461ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall           ctx->shareGroup()->deleteName(RENDERBUFFER,renderbuffers[i]);
462ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall           ctx->dispatcher().glDeleteRenderbuffersEXT(1,&globalRenderBufferName);
463ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
464ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
465ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
466ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
467ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glDeleteTextures(GLsizei n, const GLuint* textures){
468ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
469ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(n<0,GL_INVALID_VALUE);
470ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr()) {
471ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        for(int i=0; i < n; i++){
472ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            if (textures[i]!=0) {
473ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                TextureData* tData = getTextureData(textures[i]);
474ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                // delete the underlying OpenGL texture but only if this
475ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                // texture is not a target of EGLImage.
476ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                if (!tData || tData->sourceEGLImage == 0) {
477ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    const GLuint globalTextureName = ctx->shareGroup()->getGlobalName(TEXTURE,textures[i]);
478ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    ctx->dispatcher().glDeleteTextures(1,&globalTextureName);
479ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                }
480ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                ctx->shareGroup()->deleteName(TEXTURE,textures[i]);
481ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
482ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                if (ctx->getBindedTexture(GL_TEXTURE_2D) == textures[i])
483ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    ctx->setBindedTexture(GL_TEXTURE_2D,0);
484ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                if (ctx->getBindedTexture(GL_TEXTURE_CUBE_MAP) == textures[i])
485ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    ctx->setBindedTexture(GL_TEXTURE_CUBE_MAP,0);
486ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            }
487ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
488ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
489ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
490ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
491ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glDeleteProgram(GLuint program){
492ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
493ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(program && ctx->shareGroup().Ptr()) {
494ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program);
495ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(!globalProgramName, GL_INVALID_VALUE);
496ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->shareGroup()->deleteName(SHADER,program);
497ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glDeleteProgram(globalProgramName);
498ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
499ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
500ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
501ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glDeleteShader(GLuint shader){
502ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
503ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(shader && ctx->shareGroup().Ptr()) {
504ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        const GLuint globalShaderName = ctx->shareGroup()->getGlobalName(SHADER,shader);
505ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(!globalShaderName, GL_INVALID_VALUE);
506ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->shareGroup()->deleteName(SHADER,shader);
507ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glDeleteShader(globalShaderName);
508ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
509ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
510ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
511ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
512ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glDepthFunc(GLenum func){
513ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
514ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glDepthFunc(func);
515ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
516ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glDepthMask(GLboolean flag){
517ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
518ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glDepthMask(flag);
519ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
520ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glDepthRangef(GLclampf zNear, GLclampf zFar){
521ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
522ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glDepthRange(zNear,zFar);
523ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
524ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
525ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glDetachShader(GLuint program, GLuint shader){
526ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
527ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr()) {
528ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program);
529ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE);
530ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        const GLuint globalShaderName  = ctx->shareGroup()->getGlobalName(SHADER,shader);
531ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(globalShaderName==0, GL_INVALID_VALUE);
532ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
533ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program);
534ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(!objData.Ptr(),GL_INVALID_OPERATION);
535ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(!(objData.Ptr()->getDataType()==PROGRAM_DATA) ,GL_INVALID_OPERATION);
536ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
537ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ProgramData* programData = (ProgramData*)objData.Ptr();
538ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(!programData->isAttached(shader),GL_INVALID_OPERATION);
539ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        programData->detachShader(shader);
540ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
541ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glDetachShader(globalProgramName,globalShaderName);
542ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
543ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
544ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
545ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glDisable(GLenum cap){
546ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
547ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glDisable(cap);
548ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
549ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
550ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glDisableVertexAttribArray(GLuint index){
551ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
552ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF((!GLESv2Validate::arrayIndex(ctx,index)),GL_INVALID_VALUE);
553ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->enableArr(index,false);
554ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glDisableVertexAttribArray(index);
555ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
556ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
557ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glDrawArrays(GLenum mode, GLint first, GLsizei count){
558ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_V2();
559ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(count < 0,GL_INVALID_VALUE)
560ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!GLESv2Validate::drawMode(mode),GL_INVALID_ENUM);
561ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
562ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->drawValidate();
563ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
564ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GLESConversionArrays tmpArrs;
565ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->setupArraysPointers(tmpArrs,first,count,0,NULL,true);
566ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
567ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->validateAtt0PreDraw(count);
568ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
569ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    //Enable texture generation for GL_POINTS and gl_PointSize shader variable
570ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    //GLES2 assumes this is enabled by default, we need to set this state for GL
571ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if (mode==GL_POINTS) {
572ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glEnable(GL_POINT_SPRITE);
573ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
574ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
575ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
576ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glDrawArrays(mode,first,count);
577ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
578ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if (mode==GL_POINTS) {
579ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
580ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glDisable(GL_POINT_SPRITE);
581ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
582ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
583ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->validateAtt0PostDraw();
584ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
585ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
586ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* elementsIndices){
587ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_V2();
588ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(count < 0,GL_INVALID_VALUE)
589ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!(GLESv2Validate::drawMode(mode) && GLESv2Validate::drawType(type)),GL_INVALID_ENUM);
590ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
591ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->drawValidate();
592ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
593ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    const GLvoid* indices = elementsIndices;
594ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->isBindedBuffer(GL_ELEMENT_ARRAY_BUFFER)) { // if vbo is binded take the indices from the vbo
595ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        const unsigned char* buf = static_cast<unsigned char *>(ctx->getBindedBuffer(GL_ELEMENT_ARRAY_BUFFER));
596ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        indices = buf+reinterpret_cast<uintptr_t>(elementsIndices);
597ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
598ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
599ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GLESConversionArrays tmpArrs;
600ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->setupArraysPointers(tmpArrs,0,count,type,indices,false);
601ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
602ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    int maxIndex = ctx->findMaxIndex(count, type, indices);
603ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->validateAtt0PreDraw(maxIndex);
604ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
605ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    //See glDrawArrays
606ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if (mode==GL_POINTS) {
607ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glEnable(GL_POINT_SPRITE);
608ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
609ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
610ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
611ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glDrawElements(mode,count,type,indices);
612ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
613ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if (mode==GL_POINTS) {
614ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
615ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glDisable(GL_POINT_SPRITE);
616ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
617ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
618ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->validateAtt0PostDraw();
619ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
620ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
621ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glEnable(GLenum cap){
622ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
623ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glEnable(cap);
624ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
625ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
626ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glEnableVertexAttribArray(GLuint index){
627ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
628ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!(GLESv2Validate::arrayIndex(ctx,index)),GL_INVALID_VALUE);
629ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->enableArr(index,true);
630ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glEnableVertexAttribArray(index);
631ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
632ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
633ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glFinish(void){
634ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
635ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glFinish();
636ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
637ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glFlush(void){
638ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
639ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glFlush();
640ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
641ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
642ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
643ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer){
644ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
645ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!(GLESv2Validate::framebufferTarget(target)              &&
646ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                   GLESv2Validate::renderbufferTarget(renderbuffertarget) &&
647ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                   GLESv2Validate::framebufferAttachment(attachment)),GL_INVALID_ENUM);
648ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!ctx->shareGroup().Ptr(), GL_INVALID_OPERATION);
649ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
650ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GLuint globalRenderbufferName = 0;
651ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ObjectDataPtr obj;
652ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
653ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    // generate the renderbuffer object if not yet exist
654ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(renderbuffer) {
655ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if (!ctx->shareGroup()->isObject(RENDERBUFFER,renderbuffer)) {
656ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->shareGroup()->genName(RENDERBUFFER,renderbuffer);
657ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            obj = ObjectDataPtr(new RenderbufferData());
658ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->shareGroup()->setObjectData(RENDERBUFFER,
659ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                                         renderbuffer, obj);
660ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
661ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        else {
662ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            obj = ctx->shareGroup()->getObjectData(RENDERBUFFER, renderbuffer);
663ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
664ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
665ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        globalRenderbufferName = ctx->shareGroup()->getGlobalName(RENDERBUFFER,renderbuffer);
666ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
667ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
668ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    // Update the the current framebuffer object attachment state
669ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GLuint fbName = ctx->getFramebufferBinding();
670ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ObjectDataPtr fbObj = ctx->shareGroup()->getObjectData(FRAMEBUFFER,fbName);
671ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if (fbObj.Ptr() != NULL) {
672ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        FramebufferData *fbData = (FramebufferData *)fbObj.Ptr();
673ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        fbData->setAttachment(attachment, renderbuffertarget, renderbuffer, obj);
674ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
675ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
676ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if (renderbuffer && obj.Ptr() != NULL) {
677ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        RenderbufferData *rbData = (RenderbufferData *)obj.Ptr();
678ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if (rbData->sourceEGLImage != 0) {
679ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            //
680ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            // This renderbuffer object is an eglImage target
681ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            // attach the eglimage's texture instead the renderbuffer.
682ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            //
683ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->dispatcher().glFramebufferTexture2DEXT(target,
684ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                                                    attachment,
685ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                                                    GL_TEXTURE_2D,
686ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                                                    rbData->eglImageGlobalTexName,0);
687ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            return;
688ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
689ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
690ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
691ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glFramebufferRenderbufferEXT(target,attachment,renderbuffertarget,globalRenderbufferName);
692ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
693ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
694ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level){
695ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
696ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!(GLESv2Validate::framebufferTarget(target) &&
697ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                   GLESv2Validate::textureTargetEx(textarget)  &&
698ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                   GLESv2Validate::framebufferAttachment(attachment)),GL_INVALID_ENUM);
699ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(level != 0, GL_INVALID_VALUE);
700ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!ctx->shareGroup().Ptr(), GL_INVALID_OPERATION);
701ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
702ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GLuint globalTextureName = 0;
703ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
704ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(texture) {
705ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if (!ctx->shareGroup()->isObject(TEXTURE,texture)) {
706ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->shareGroup()->genName(TEXTURE,texture);
707ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
708ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ObjectLocalName texname = TextureLocalName(textarget,texture);
709ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        globalTextureName = ctx->shareGroup()->getGlobalName(TEXTURE,texname);
710ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
711ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
712ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glFramebufferTexture2DEXT(target,attachment,textarget,globalTextureName,level);
713ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
714ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    // Update the the current framebuffer object attachment state
715ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GLuint fbName = ctx->getFramebufferBinding();
716ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ObjectDataPtr fbObj = ctx->shareGroup()->getObjectData(FRAMEBUFFER,fbName);
717ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if (fbObj.Ptr() != NULL) {
718ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        FramebufferData *fbData = (FramebufferData *)fbObj.Ptr();
719ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        fbData->setAttachment(attachment, textarget,
720ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                              texture, ObjectDataPtr(NULL));
721ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
722ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
723ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
724ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
725ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glFrontFace(GLenum mode){
726ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
727ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glFrontFace(mode);
728ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
729ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
730ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glGenBuffers(GLsizei n, GLuint* buffers){
731ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
732ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(n<0,GL_INVALID_VALUE);
733ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr()) {
734ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        for(int i=0; i<n ;i++) {
735ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            buffers[i] = ctx->shareGroup()->genName(VERTEXBUFFER, 0, true);
736ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            //generating vbo object related to this buffer name
737ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->shareGroup()->setObjectData(VERTEXBUFFER,buffers[i],ObjectDataPtr(new GLESbuffer()));
738ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
739ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
740ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
741ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
742ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glGenerateMipmap(GLenum target){
743ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
744ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!GLESv2Validate::textureTargetEx(target),GL_INVALID_ENUM);
745ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glGenerateMipmapEXT(target);
746ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
747ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
748ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glGenFramebuffers(GLsizei n, GLuint* framebuffers){
749ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
750ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(n<0,GL_INVALID_VALUE);
751ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr()) {
752ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        for(int i=0; i<n ;i++) {
753ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            framebuffers[i] = ctx->shareGroup()->genName(FRAMEBUFFER, 0 ,true);
754ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->shareGroup()->setObjectData(FRAMEBUFFER, framebuffers[i],
755ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                                             ObjectDataPtr(new FramebufferData(framebuffers[i])));
756ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
757ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
758ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
759ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
760ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glGenRenderbuffers(GLsizei n, GLuint* renderbuffers){
761ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
762ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(n<0,GL_INVALID_VALUE);
763ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr()) {
764ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        for(int i=0; i<n ;i++) {
765ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            renderbuffers[i] = ctx->shareGroup()->genName(RENDERBUFFER, 0, true);
766ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->shareGroup()->setObjectData(RENDERBUFFER,
767ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                                         renderbuffers[i],
768ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                                         ObjectDataPtr(new RenderbufferData()));
769ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
770ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
771ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
772ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
773ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glGenTextures(GLsizei n, GLuint* textures){
774ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
775ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(n<0,GL_INVALID_VALUE);
776ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr()) {
777ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        for(int i=0; i<n ;i++) {
778ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            textures[i] = ctx->shareGroup()->genName(TEXTURE, 0, true);
779ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
780ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
781ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
782ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
783ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name){
784ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
785ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr()) {
786ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program);
787ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE);
788ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program);
789ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(objData.Ptr()->getDataType()!=PROGRAM_DATA,GL_INVALID_OPERATION);
790ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glGetActiveAttrib(globalProgramName,index,bufsize,length,size,type,name);
791ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
792ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
793ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
794ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name){
795ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
796ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr()) {
797ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program);
798ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE);
799ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program);
800ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(objData.Ptr()->getDataType()!=PROGRAM_DATA,GL_INVALID_OPERATION);
801ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glGetActiveUniform(globalProgramName,index,bufsize,length,size,type,name);
802ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
803ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
804ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
805ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders){
806ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
807ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr()) {
808ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program);
809ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE);
810ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glGetAttachedShaders(globalProgramName,maxcount,count,shaders);
811ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program);
812ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(objData.Ptr()->getDataType()!=PROGRAM_DATA,GL_INVALID_OPERATION);
813ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        GLint numShaders=0;
814ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glGetProgramiv(globalProgramName,GL_ATTACHED_SHADERS,&numShaders);
815ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        for(int i=0 ; i < maxcount && i<numShaders ;i++){
816ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall           shaders[i] = ctx->shareGroup()->getLocalName(SHADER,shaders[i]);
817ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
818ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
819ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
820ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
821ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL int GL_APIENTRY glGetAttribLocation(GLuint program, const GLchar* name){
822ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall     GET_CTX_RET(-1);
823ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall     if(ctx->shareGroup().Ptr()) {
824ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program);
825ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        RET_AND_SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE,-1);
826ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program);
827ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        RET_AND_SET_ERROR_IF(objData.Ptr()->getDataType()!=PROGRAM_DATA,GL_INVALID_OPERATION,-1);
828ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ProgramData* pData = (ProgramData *)objData.Ptr();
829ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        RET_AND_SET_ERROR_IF(pData->getLinkStatus() != GL_TRUE,GL_INVALID_OPERATION,-1);
830ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        return ctx->dispatcher().glGetAttribLocation(globalProgramName,name);
831ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall     }
832ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall     return -1;
833ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
834ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
835ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glGetBooleanv(GLenum pname, GLboolean* params){
836ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
837ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
838ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if (ctx->glGetBooleanv(pname,params))
839ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    {
840ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        return;
841ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
842ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
843ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    switch(pname)
844ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    {
845ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        case GL_SHADER_COMPILER:
846ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        case GL_SHADER_BINARY_FORMATS:
847ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        case GL_NUM_SHADER_BINARY_FORMATS:
848ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        case GL_MAX_VERTEX_UNIFORM_VECTORS:
849ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        case GL_MAX_VARYING_VECTORS:
850ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
851ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            if(ctx->getCaps()->GL_ARB_ES2_COMPATIBILITY)
852ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                ctx->dispatcher().glGetBooleanv(pname,params);
853ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            else
854ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            {
855ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                GLint iparam;
856ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                glGetIntegerv(pname,&iparam);
857ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                *params = (iparam != 0);
858ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            }
859ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            break;
860ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
861ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        default:
862ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->dispatcher().glGetBooleanv(pname,params);
863ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
864ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
865ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
866ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params){
867ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
868ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!(GLESv2Validate::bufferTarget(target) && GLESv2Validate::bufferParam(pname)),GL_INVALID_ENUM);
869ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!ctx->isBindedBuffer(target),GL_INVALID_OPERATION);
870ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    bool ret = true;
871ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    switch(pname) {
872ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_BUFFER_SIZE:
873ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->getBufferSize(target,params);
874ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        break;
875ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_BUFFER_USAGE:
876ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->getBufferUsage(target,params);
877ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        break;
878ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
879ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
880ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
881ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
882ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL GLenum GL_APIENTRY glGetError(void){
883ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_RET(GL_NO_ERROR)
884ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GLenum err = ctx->getGLerror();
885ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(err != GL_NO_ERROR) {
886ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->setGLerror(GL_NO_ERROR);
887ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        return err;
888ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
889ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    return ctx->dispatcher().glGetError();
890ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
891ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
892ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glGetFloatv(GLenum pname, GLfloat* params){
893ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
894ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
895ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if (ctx->glGetFloatv(pname,params)) {
896ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        return;
897ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
898ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
899ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GLint i;
900ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
901ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    switch (pname) {
902ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_CURRENT_PROGRAM:
903ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_FRAMEBUFFER_BINDING:
904ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_RENDERBUFFER_BINDING:
905ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        glGetIntegerv(pname,&i);
906ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        *params = (GLfloat)i;
907ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        break;
908ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
909ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        *params = (GLfloat)getCompressedFormats(NULL);
910ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        break;
911ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_COMPRESSED_TEXTURE_FORMATS:
912ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        {
913ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            int nparams = getCompressedFormats(NULL);
914ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            if (nparams>0) {
915ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                int * iparams = new int[nparams];
916ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                getCompressedFormats(iparams);
917ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                for (int i=0; i<nparams; i++) params[i] = (GLfloat)iparams[i];
918ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                delete [] iparams;
919ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            }
920ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
921ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        break;
922ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
923ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_SHADER_COMPILER:
924ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_SHADER_BINARY_FORMATS:
925ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_NUM_SHADER_BINARY_FORMATS:
926ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_MAX_VERTEX_UNIFORM_VECTORS:
927ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_MAX_VARYING_VECTORS:
928ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
929ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if(ctx->getCaps()->GL_ARB_ES2_COMPATIBILITY)
930ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->dispatcher().glGetFloatv(pname,params);
931ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        else
932ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        {
933ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            glGetIntegerv(pname,&i);
934ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            *params = (GLfloat)i;
935ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
936ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        break;
937ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
938ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    default:
939ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glGetFloatv(pname,params);
940ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
941ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
942ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
943ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glGetIntegerv(GLenum pname, GLint* params){
944ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
945ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
946ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if (ctx->glGetIntegerv(pname,params))
947ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    {
948ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        return;
949ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
950ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
951ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    bool es2 = ctx->getCaps()->GL_ARB_ES2_COMPATIBILITY;
952ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GLint i;
953ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
954ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    switch (pname) {
955ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_CURRENT_PROGRAM:
956ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if (ctx->shareGroup().Ptr()) {
957ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->dispatcher().glGetIntegerv(pname,&i);
958ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            *params = ctx->shareGroup()->getLocalName(SHADER,i);
959ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
960ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        break;
961ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_FRAMEBUFFER_BINDING:
962ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if (ctx->shareGroup().Ptr()) {
963ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->dispatcher().glGetIntegerv(pname,&i);
964ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            *params = ctx->shareGroup()->getLocalName(FRAMEBUFFER,i);
965ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
966ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        break;
967ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_RENDERBUFFER_BINDING:
968ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if (ctx->shareGroup().Ptr()) {
969ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->dispatcher().glGetIntegerv(pname,&i);
970ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            *params = ctx->shareGroup()->getLocalName(RENDERBUFFER,i);
971ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
972ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        break;
973ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
974ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
975ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        *params = getCompressedFormats(NULL);
976ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        break;
977ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_COMPRESSED_TEXTURE_FORMATS:
978ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        getCompressedFormats(params);
979ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        break;
980ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
981ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_SHADER_COMPILER:
982ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if(es2)
983ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->dispatcher().glGetIntegerv(pname,params);
984ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        else
985ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            *params = 1;
986ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        break;
987ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
988ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_SHADER_BINARY_FORMATS:
989ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if(es2)
990ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->dispatcher().glGetIntegerv(pname,params);
991ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        break;
992ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
993ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_NUM_SHADER_BINARY_FORMATS:
994ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if(es2)
995ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->dispatcher().glGetIntegerv(pname,params);
996ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        else
997ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            *params = 0;
998ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        break;
999ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1000ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_MAX_VERTEX_UNIFORM_VECTORS:
1001ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if(es2)
1002ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->dispatcher().glGetIntegerv(pname,params);
1003ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        else
1004ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            *params = 128;
1005ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        break;
1006ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1007ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_MAX_VARYING_VECTORS:
1008ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if(es2)
1009ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->dispatcher().glGetIntegerv(pname,params);
1010ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        else
1011ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            *params = 8;
1012ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        break;
1013ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1014ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1015ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if(es2)
1016ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->dispatcher().glGetIntegerv(pname,params);
1017ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        else
1018ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            *params = 16;
1019ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        break;
1020ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1021ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1022ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glGetIntegerv(pname,params);
1023ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if(*params > 16)
1024ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        {
1025ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            // GLES spec requires only 2, and the ATI driver erronously
1026ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            // returns 32 (although it supports only 16). This WAR is simple,
1027ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            // compliant and good enough for developers.
1028ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            *params = 16;
1029ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
1030ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        break;
1031ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    default:
1032ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glGetIntegerv(pname,params);
1033ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
1034ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1035ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1036ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params){
1037ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1038ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!(GLESv2Validate::framebufferTarget(target)         &&
1039ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                   GLESv2Validate::framebufferAttachment(attachment) &&
1040ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                   GLESv2Validate::framebufferAttachmentParams(pname)),GL_INVALID_ENUM);
1041ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1042ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    //
1043ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    // Take the attachment attribute from our state - if available
1044ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    //
1045ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GLuint fbName = ctx->getFramebufferBinding();
1046ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if (fbName) {
1047ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ObjectDataPtr fbObj = ctx->shareGroup()->getObjectData(FRAMEBUFFER,fbName);
1048ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if (fbObj.Ptr() != NULL) {
1049ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            FramebufferData *fbData = (FramebufferData *)fbObj.Ptr();
1050ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            GLenum target;
1051ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            GLuint name = fbData->getAttachment(attachment, &target, NULL);
1052ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE) {
1053ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                if (target == GL_TEXTURE_2D) {
1054ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    *params = GL_TEXTURE;
1055ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    return;
1056ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                }
1057ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                else if (target == GL_RENDERBUFFER) {
1058ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    *params = GL_RENDERBUFFER;
1059ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    return;
1060ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                }
1061ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            }
1062ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            else if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) {
1063ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                *params = name;
1064ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                return;
1065ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            }
1066ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
1067ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
1068ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1069ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glGetFramebufferAttachmentParameterivEXT(target,attachment,pname,params);
1070ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1071ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1072ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params){
1073ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1074ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!(GLESv2Validate::renderbufferTarget(target) && GLESv2Validate::renderbufferParams(pname)),GL_INVALID_ENUM);
1075ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1076ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    //
1077ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    // If this is a renderbuffer which is eglimage's target, we
1078ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    // should query the underlying eglimage's texture object instead.
1079ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    //
1080ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GLuint rb = ctx->getRenderbufferBinding();
1081ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if (rb) {
1082ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ObjectDataPtr objData = ctx->shareGroup()->getObjectData(RENDERBUFFER,rb);
1083ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        RenderbufferData *rbData = (RenderbufferData *)objData.Ptr();
1084ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if (rbData && rbData->sourceEGLImage != 0) {
1085ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            GLenum texPname;
1086ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            switch(pname) {
1087ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                case GL_RENDERBUFFER_WIDTH:
1088ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    texPname = GL_TEXTURE_WIDTH;
1089ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    break;
1090ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                case GL_RENDERBUFFER_HEIGHT:
1091ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    texPname = GL_TEXTURE_HEIGHT;
1092ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    break;
1093ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                case GL_RENDERBUFFER_INTERNAL_FORMAT:
1094ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    texPname = GL_TEXTURE_INTERNAL_FORMAT;
1095ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    break;
1096ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                case GL_RENDERBUFFER_RED_SIZE:
1097ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    texPname = GL_TEXTURE_RED_SIZE;
1098ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    break;
1099ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                case GL_RENDERBUFFER_GREEN_SIZE:
1100ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    texPname = GL_TEXTURE_GREEN_SIZE;
1101ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    break;
1102ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                case GL_RENDERBUFFER_BLUE_SIZE:
1103ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    texPname = GL_TEXTURE_BLUE_SIZE;
1104ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    break;
1105ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                case GL_RENDERBUFFER_ALPHA_SIZE:
1106ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    texPname = GL_TEXTURE_ALPHA_SIZE;
1107ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    break;
1108ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                case GL_RENDERBUFFER_DEPTH_SIZE:
1109ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    texPname = GL_TEXTURE_DEPTH_SIZE;
1110ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    break;
1111ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                case GL_RENDERBUFFER_STENCIL_SIZE:
1112ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                default:
1113ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    *params = 0; //XXX
1114ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    return;
1115ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    break;
1116ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            }
1117ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1118ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            GLint prevTex;
1119ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->dispatcher().glGetIntegerv(GL_TEXTURE_BINDING_2D, &prevTex);
1120ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->dispatcher().glBindTexture(GL_TEXTURE_2D,
1121ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                                            rbData->eglImageGlobalTexName);
1122ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->dispatcher().glGetTexLevelParameteriv(GL_TEXTURE_2D, 0,
1123ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                                                       texPname,
1124ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                                                       params);
1125ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->dispatcher().glBindTexture(GL_TEXTURE_2D, prevTex);
1126ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            return;
1127ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
1128ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
1129ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1130ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glGetRenderbufferParameterivEXT(target,pname,params);
1131ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1132ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1133ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1134ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glGetProgramiv(GLuint program, GLenum pname, GLint* params){
1135ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1136ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!GLESv2Validate::programParam(pname),GL_INVALID_ENUM);
1137ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr()) {
1138ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program);
1139ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE);
1140ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        switch(pname) {
1141ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        case GL_LINK_STATUS:
1142ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            {
1143ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program);
1144ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                SET_ERROR_IF(!objData.Ptr() ,GL_INVALID_OPERATION);
1145ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                SET_ERROR_IF(objData.Ptr()->getDataType()!=PROGRAM_DATA,GL_INVALID_OPERATION);
1146ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                ProgramData* programData = (ProgramData*)objData.Ptr();
1147ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                params[0] = programData->getLinkStatus();
1148ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            }
1149ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            break;
1150ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        //validate status should not return GL_TRUE if link failed
1151ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        case GL_VALIDATE_STATUS:
1152ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            {
1153ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program);
1154ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                SET_ERROR_IF(!objData.Ptr() ,GL_INVALID_OPERATION);
1155ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                SET_ERROR_IF(objData.Ptr()->getDataType()!=PROGRAM_DATA,GL_INVALID_OPERATION);
1156ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                ProgramData* programData = (ProgramData*)objData.Ptr();
1157ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                if (programData->getLinkStatus()==GL_TRUE)
1158ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    ctx->dispatcher().glGetProgramiv(globalProgramName,pname,params);
1159ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                else
1160ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    params[0] = GL_FALSE;
1161ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            }
1162ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            break;
1163ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        case GL_INFO_LOG_LENGTH:
1164ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            {
1165ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program);
1166ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                SET_ERROR_IF(!objData.Ptr() ,GL_INVALID_OPERATION);
1167ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                SET_ERROR_IF(objData.Ptr()->getDataType()!=PROGRAM_DATA,GL_INVALID_OPERATION);
1168ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                ProgramData* programData = (ProgramData*)objData.Ptr();
1169ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                GLint logLength = strlen(programData->getInfoLog());
1170ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                params[0] = (logLength>0) ? logLength+1 : 0;
1171ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            }
1172ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            break;
1173ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        default:
1174ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->dispatcher().glGetProgramiv(globalProgramName,pname,params);
1175ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
1176ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
1177ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1178ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1179ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog){
1180ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1181ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr()) {
1182ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program);
1183ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE);
1184ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program);
1185ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(!objData.Ptr() ,GL_INVALID_OPERATION);
1186ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(objData.Ptr()->getDataType()!=PROGRAM_DATA,GL_INVALID_OPERATION);
1187ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ProgramData* programData = (ProgramData*)objData.Ptr();
1188ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1189ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if (bufsize==0) {
1190ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            if (length) {
1191ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                *length = 0;
1192ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            }
1193ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            return;
1194ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
1195ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1196ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        GLsizei logLength;
1197ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        logLength = strlen(programData->getInfoLog());
1198ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1199ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        GLsizei returnLength=0;
1200ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if (infolog) {
1201ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            returnLength = bufsize-1 < logLength ? bufsize-1 : logLength;
1202ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            strncpy(infolog,programData->getInfoLog(),returnLength+1);
1203ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            infolog[returnLength] = '\0';
1204ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
1205ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if (length) {
1206ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            *length = returnLength;
1207ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
1208ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
1209ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1210ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1211ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glGetShaderiv(GLuint shader, GLenum pname, GLint* params){
1212ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1213ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr()) {
1214ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        const GLuint globalShaderName = ctx->shareGroup()->getGlobalName(SHADER,shader);
1215ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(globalShaderName==0, GL_INVALID_VALUE);
1216ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        switch(pname) {
1217ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        case GL_INFO_LOG_LENGTH:
1218ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            {
1219ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,shader);
1220ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                SET_ERROR_IF(!objData.Ptr() ,GL_INVALID_OPERATION);
1221ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                SET_ERROR_IF(objData.Ptr()->getDataType()!=SHADER_DATA,GL_INVALID_OPERATION);
1222ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                ShaderParser* sp = (ShaderParser*)objData.Ptr();
1223ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                GLint logLength = strlen(sp->getInfoLog());
1224ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                params[0] = (logLength>0) ? logLength+1 : 0;
1225ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            }
1226ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            break;
1227ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        default:
1228ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->dispatcher().glGetShaderiv(globalShaderName,pname,params);
1229ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
1230ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
1231ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1232ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1233ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1234ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog){
1235ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1236ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr()) {
1237ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        const GLuint globalShaderName = ctx->shareGroup()->getGlobalName(SHADER,shader);
1238ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(globalShaderName==0, GL_INVALID_VALUE);
1239ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,shader);
1240ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(!objData.Ptr() ,GL_INVALID_OPERATION);
1241ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(objData.Ptr()->getDataType()!=SHADER_DATA,GL_INVALID_OPERATION);
1242ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ShaderParser* sp = (ShaderParser*)objData.Ptr();
1243ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1244ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if (bufsize==0) {
1245ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            if (length) {
1246ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                *length = 0;
1247ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            }
1248ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            return;
1249ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
1250ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1251ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        GLsizei logLength;
1252ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        logLength = strlen(sp->getInfoLog());
1253ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1254ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        GLsizei returnLength=0;
1255ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if (infolog) {
1256ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            returnLength = bufsize-1 <logLength ? bufsize-1 : logLength;
1257ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            strncpy(infolog,sp->getInfoLog(),returnLength+1);
1258ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            infolog[returnLength] = '\0';
1259ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
1260ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if (length) {
1261ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            *length = returnLength;
1262ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
1263ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
1264ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1265ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1266ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision){
1267ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_V2();
1268ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!(GLESv2Validate::shaderType(shadertype) && GLESv2Validate::precisionType(precisiontype)),GL_INVALID_ENUM);
1269ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1270ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    switch (precisiontype) {
1271ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_LOW_INT:
1272ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_MEDIUM_INT:
1273ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_HIGH_INT:
1274ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        range[0] = range[1] = 16;
1275ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        *precision = 0;
1276ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        break;
1277ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1278ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_LOW_FLOAT:
1279ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_MEDIUM_FLOAT:
1280ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_HIGH_FLOAT:
1281ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if(ctx->dispatcher().glGetShaderPrecisionFormat != NULL) {
1282ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->dispatcher().glGetShaderPrecisionFormat(shadertype,precisiontype,range,precision);
1283ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        } else {
1284ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            range[0] = range[1] = 127;
1285ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            *precision = 24;
1286ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
1287ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        break;
1288ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
1289ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1290ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1291ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source){
1292ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1293ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr()) {
1294ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall       const GLuint globalShaderName = ctx->shareGroup()->getGlobalName(SHADER,shader);
1295ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall       SET_ERROR_IF(globalShaderName == 0,GL_INVALID_VALUE);
1296ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall       ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,shader);
1297ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall       SET_ERROR_IF(!objData.Ptr(),GL_INVALID_OPERATION);
1298ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall       SET_ERROR_IF(objData.Ptr()->getDataType()!=SHADER_DATA,GL_INVALID_OPERATION);
1299ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall       const char* src = ((ShaderParser*)objData.Ptr())->getOriginalSrc();
1300ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall       int srcLength = 0;
1301ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall       if (src) {
1302ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            srcLength = strlen(src);
1303ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall       }
1304ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1305ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall       int returnLength = bufsize<srcLength ? bufsize-1 : srcLength;
1306ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall       if (returnLength) {
1307ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            strncpy(source,src, returnLength);
1308ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            source[returnLength] = '\0';
1309ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall       }
1310ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1311ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall       if (length)
1312ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall          *length = returnLength;
1313ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
1314ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1315ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1316ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1317ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL const GLubyte* GL_APIENTRY glGetString(GLenum name){
1318ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_RET(NULL)
1319ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    static const GLubyte SHADING[] = "OpenGL ES GLSL ES 1.0.17";
1320ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    switch(name) {
1321ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        case GL_VENDOR:
132281e372046c2212585a4ff518ccdcff950d476717Jesse Hall            return (const GLubyte*)ctx->getVendorString();
1323ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        case GL_RENDERER:
1324ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            return (const GLubyte*)ctx->getRendererString();
1325ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        case GL_VERSION:
132681e372046c2212585a4ff518ccdcff950d476717Jesse Hall            return (const GLubyte*)ctx->getVersionString();
1327ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        case GL_SHADING_LANGUAGE_VERSION:
1328ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            return SHADING;
1329ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        case GL_EXTENSIONS:
1330ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            return (const GLubyte*)ctx->getExtensionString();
1331ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        default:
1332ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            RET_AND_SET_ERROR_IF(true,GL_INVALID_ENUM,NULL);
1333ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
1334ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1335ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1336ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params){
1337ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1338ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!(GLESv2Validate::textureTarget(target) && GLESv2Validate::textureParams(pname)),GL_INVALID_ENUM);
1339ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glGetTexParameterfv(target,pname,params);
1340ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1341ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1342ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glGetTexParameteriv(GLenum target, GLenum pname, GLint* params){
1343ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1344ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!(GLESv2Validate::textureTarget(target) && GLESv2Validate::textureParams(pname)),GL_INVALID_ENUM);
1345ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glGetTexParameteriv(target,pname,params);
1346ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1347ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1348ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glGetUniformfv(GLuint program, GLint location, GLfloat* params){
1349ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1350ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(location < 0,GL_INVALID_OPERATION);
1351ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr()) {
1352ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program);
1353ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE);
1354ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program);
1355ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(objData.Ptr()->getDataType()!=PROGRAM_DATA,GL_INVALID_OPERATION);
1356ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ProgramData* pData = (ProgramData *)objData.Ptr();
1357ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(pData->getLinkStatus() != GL_TRUE,GL_INVALID_OPERATION);
1358ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glGetUniformfv(globalProgramName,location,params);
1359ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
1360ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1361ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1362ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glGetUniformiv(GLuint program, GLint location, GLint* params){
1363ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1364ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(location < 0,GL_INVALID_OPERATION);
1365ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr()) {
1366ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program);
1367ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE);
1368ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program);
1369ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(objData.Ptr()->getDataType()!=PROGRAM_DATA,GL_INVALID_OPERATION);
1370ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ProgramData* pData = (ProgramData *)objData.Ptr();
1371ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(pData->getLinkStatus() != GL_TRUE,GL_INVALID_OPERATION);
1372ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glGetUniformiv(globalProgramName,location,params);
1373ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
1374ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1375ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1376ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL int GL_APIENTRY glGetUniformLocation(GLuint program, const GLchar* name){
1377ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_RET(-1);
1378ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr()) {
1379ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program);
1380ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        RET_AND_SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE,-1);
1381ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program);
1382ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        RET_AND_SET_ERROR_IF(objData.Ptr()->getDataType()!=PROGRAM_DATA,GL_INVALID_OPERATION,-1);
1383ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ProgramData* pData = (ProgramData *)objData.Ptr();
1384ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        RET_AND_SET_ERROR_IF(pData->getLinkStatus() != GL_TRUE,GL_INVALID_OPERATION,-1);
1385ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        return ctx->dispatcher().glGetUniformLocation(globalProgramName,name);
1386ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
1387ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    return -1;
1388ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1389ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1390ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1391ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1392ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params){
1393ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_V2();
1394ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    const GLESpointer* p = ctx->getPointer(index);
1395ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(p) {
1396ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        switch(pname){
1397ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
1398ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            *params = 0;
1399ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            break;
1400ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
1401ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            *params = p->isEnable();
1402ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            break;
1403ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        case GL_VERTEX_ATTRIB_ARRAY_SIZE:
1404ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            *params = p->getSize();
1405ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            break;
1406ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
1407ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            *params = p->getStride();
1408ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            break;
1409ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        case GL_VERTEX_ATTRIB_ARRAY_TYPE:
1410ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            *params = p->getType();
1411ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            break;
1412ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
1413ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            *params = p->isNormalize();
1414ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            break;
1415ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        case GL_CURRENT_VERTEX_ATTRIB:
1416ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            if(index == 0)
1417ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            {
1418ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                const float* att0 = ctx->getAtt0();
1419ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                for(int i=0; i<4; i++)
1420ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    params[i] = att0[i];
1421ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            }
1422ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            else
1423ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                ctx->dispatcher().glGetVertexAttribfv(index,pname,params);
1424ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            break;
1425ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        default:
1426ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->setGLerror(GL_INVALID_ENUM);
1427ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
1428ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    } else {
1429ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->setGLerror(GL_INVALID_VALUE);
1430ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
1431ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1432ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1433ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params){
1434ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_V2();
1435ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    const GLESpointer* p = ctx->getPointer(index);
1436ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(p) {
1437ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        switch(pname){
1438ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
1439ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            *params = 0;
1440ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            break;
1441ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
1442ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            *params = p->isEnable();
1443ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            break;
1444ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        case GL_VERTEX_ATTRIB_ARRAY_SIZE:
1445ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            *params = p->getSize();
1446ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            break;
1447ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
1448ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            *params = p->getStride();
1449ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            break;
1450ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        case GL_VERTEX_ATTRIB_ARRAY_TYPE:
1451ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            *params = p->getType();
1452ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            break;
1453ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
1454ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            *params = p->isNormalize();
1455ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            break;
1456ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        case GL_CURRENT_VERTEX_ATTRIB:
1457ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            if(index == 0)
1458ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            {
1459ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                const float* att0 = ctx->getAtt0();
1460ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                for(int i=0; i<4; i++)
1461ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    params[i] = (GLint)att0[i];
1462ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            }
1463ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            else
1464ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                ctx->dispatcher().glGetVertexAttribiv(index,pname,params);
1465ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            break;
1466ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        default:
1467ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->setGLerror(GL_INVALID_ENUM);
1468ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
1469ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    } else {
1470ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->setGLerror(GL_INVALID_VALUE);
1471ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
1472ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1473ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1474ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer){
1475ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1476ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(pname != GL_VERTEX_ATTRIB_ARRAY_POINTER,GL_INVALID_ENUM);
1477ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF((!GLESv2Validate::arrayIndex(ctx,index)),GL_INVALID_VALUE);
1478ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1479ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    const GLESpointer* p = ctx->getPointer(index);
1480ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(p) {
1481ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        *pointer = const_cast<void *>( p->getBufferData());
1482ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    } else {
1483ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->setGLerror(GL_INVALID_VALUE);
1484ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
1485ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1486ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1487ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glHint(GLenum target, GLenum mode){
1488ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1489ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!GLESv2Validate::hintTargetMode(target,mode),GL_INVALID_ENUM);
1490ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glHint(target,mode);
1491ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1492ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1493ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL GLboolean    GL_APIENTRY glIsEnabled(GLenum cap){
1494ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_RET(GL_FALSE);
1495ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    RET_AND_SET_ERROR_IF(!GLESv2Validate::capability(cap),GL_INVALID_ENUM,GL_FALSE);
1496ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    return ctx->dispatcher().glIsEnabled(cap);
1497ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1498ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1499ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL GLboolean    GL_APIENTRY glIsBuffer(GLuint buffer){
1500ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_RET(GL_FALSE)
1501ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(buffer && ctx->shareGroup().Ptr()) {
1502ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall       ObjectDataPtr objData = ctx->shareGroup()->getObjectData(VERTEXBUFFER,buffer);
1503ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall       return objData.Ptr() ? ((GLESbuffer*)objData.Ptr())->wasBinded():GL_FALSE;
1504ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
1505ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    return GL_FALSE;
1506ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1507ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1508ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL GLboolean    GL_APIENTRY glIsFramebuffer(GLuint framebuffer){
1509ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_RET(GL_FALSE)
1510ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(framebuffer && ctx->shareGroup().Ptr()){
1511ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        return ctx->shareGroup()->isObject(FRAMEBUFFER,framebuffer) ? GL_TRUE :GL_FALSE;
1512ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
1513ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    return GL_FALSE;
1514ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1515ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1516ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL GLboolean    GL_APIENTRY glIsRenderbuffer(GLuint renderbuffer){
1517ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_RET(GL_FALSE)
1518ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(renderbuffer && ctx->shareGroup().Ptr()){
1519ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        return ctx->shareGroup()->isObject(RENDERBUFFER,renderbuffer) ? GL_TRUE :GL_FALSE;
1520ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
1521ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    return GL_FALSE;
1522ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1523ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1524ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL GLboolean    GL_APIENTRY glIsTexture(GLuint texture){
1525ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_RET(GL_FALSE)
1526ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if (texture==0)
1527ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        return GL_FALSE;
1528ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    TextureData* tex = getTextureData(texture);
1529ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    return tex ? tex->wasBound : GL_FALSE;
1530ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1531ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1532ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL GLboolean    GL_APIENTRY glIsProgram(GLuint program){
1533ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_RET(GL_FALSE)
1534ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(program && ctx->shareGroup().Ptr() &&
1535ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall       ctx->shareGroup()->isObject(SHADER,program)) {
1536ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program);
1537ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        return ctx->dispatcher().glIsProgram(globalProgramName);
1538ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
1539ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    return GL_FALSE;
1540ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1541ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1542ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL GLboolean    GL_APIENTRY glIsShader(GLuint shader){
1543ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_RET(GL_FALSE)
1544ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(shader && ctx->shareGroup().Ptr() &&
1545ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall       ctx->shareGroup()->isObject(SHADER,shader)) {
1546ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        const GLuint globalShaderName = ctx->shareGroup()->getGlobalName(SHADER,shader);
1547ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        return ctx->dispatcher().glIsShader(globalShaderName);
1548ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
1549ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    return GL_FALSE;
1550ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1551ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1552ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glLineWidth(GLfloat width){
1553ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1554ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glLineWidth(width);
1555ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1556ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1557ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glLinkProgram(GLuint program){
1558ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1559ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GLint linkStatus = GL_FALSE;
1560ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr()) {
1561ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program);
1562ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE);
1563ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1564ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program);
1565ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(!objData.Ptr(), GL_INVALID_OPERATION);
1566ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(objData.Ptr()->getDataType()!=PROGRAM_DATA, GL_INVALID_OPERATION);
1567ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ProgramData* programData = (ProgramData*)objData.Ptr();
1568ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        GLint fragmentShader   = programData->getAttachedFragmentShader();
1569ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        GLint vertexShader =  programData->getAttachedVertexShader();
1570ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if (vertexShader != 0 && fragmentShader!=0) {
1571ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            /* validating that the fragment & vertex shaders were compiled successfuly*/
1572ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            GLint fCompileStatus = GL_FALSE;
1573ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            GLint vCompileStatus = GL_FALSE;
1574ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            GLuint fragmentShaderGlobal = ctx->shareGroup()->getGlobalName(SHADER,fragmentShader);
1575ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            GLuint vertexShaderGlobal = ctx->shareGroup()->getGlobalName(SHADER,vertexShader);
1576ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->dispatcher().glGetShaderiv(fragmentShaderGlobal,GL_COMPILE_STATUS,&fCompileStatus);
1577ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->dispatcher().glGetShaderiv(vertexShaderGlobal,GL_COMPILE_STATUS,&vCompileStatus);
1578ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1579ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            if(fCompileStatus != 0 && vCompileStatus != 0){
1580ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                ctx->dispatcher().glLinkProgram(globalProgramName);
1581ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                ctx->dispatcher().glGetProgramiv(globalProgramName,GL_LINK_STATUS,&linkStatus);
1582ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            }
1583ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
1584ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        programData->setLinkStatus(linkStatus);
1585ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1586ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        GLsizei infoLogLength=0;
1587ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        GLchar* infoLog;
1588ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glGetProgramiv(globalProgramName,GL_INFO_LOG_LENGTH,&infoLogLength);
1589ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        infoLog = new GLchar[infoLogLength+1];
1590ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glGetProgramInfoLog(globalProgramName,infoLogLength,NULL,infoLog);
1591ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        programData->setInfoLog(infoLog);
1592ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
1593ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1594ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1595ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glPixelStorei(GLenum pname, GLint param){
1596ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1597ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!GLESv2Validate::pixelStoreParam(pname),GL_INVALID_ENUM);
1598ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!((param==1)||(param==2)||(param==4)||(param==8)), GL_INVALID_VALUE);
1599ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->setUnpackAlignment(param);
1600ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glPixelStorei(pname,param);
1601ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1602ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1603ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glPolygonOffset(GLfloat factor, GLfloat units){
1604ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1605ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glPolygonOffset(factor,units);
1606ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1607ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1608ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels){
1609ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1610ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!(GLESv2Validate::readPixelFrmt(format) && GLESv2Validate::pixelType(ctx,type)),GL_INVALID_ENUM);
1611ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!(GLESv2Validate::pixelOp(format,type)),GL_INVALID_OPERATION);
1612ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glReadPixels(x,y,width,height,format,type,pixels);
1613ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1614ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1615ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1616ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glReleaseShaderCompiler(void){
1617ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1618ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1619ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->dispatcher().glReleaseShaderCompiler != NULL)
1620ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    {
1621ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glReleaseShaderCompiler();
1622ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
1623ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1624ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1625ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height){
1626ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1627ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GLenum internal = internalformat;
1628ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    switch (internalformat) {
1629ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_RGB565:
1630ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        internal = GL_RGB;
1631ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        break;
1632ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    case GL_RGB5_A1:
1633ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        internal = GL_RGBA;
1634ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        break;
1635ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    default:
1636ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        internal = internalformat;
1637ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        break;
1638ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
1639ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1640ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    // Get current bounded renderbuffer
1641ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    // raise INVALID_OPERATIOn if no renderbuffer is bounded
1642ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GLuint rb = ctx->getRenderbufferBinding();
1643ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(rb == 0,GL_INVALID_OPERATION);
1644ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ObjectDataPtr objData = ctx->shareGroup()->getObjectData(RENDERBUFFER,rb);
1645ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    RenderbufferData *rbData = (RenderbufferData *)objData.Ptr();
1646ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!rbData,GL_INVALID_OPERATION);
1647ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1648ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    //
1649ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    // if the renderbuffer was an eglImage target, detach from
1650ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    // the eglImage.
1651ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    //
1652ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if (rbData->sourceEGLImage != 0) {
1653ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if (rbData->eglImageDetach) {
1654ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            (*rbData->eglImageDetach)(rbData->sourceEGLImage);
1655ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
1656ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        rbData->sourceEGLImage = 0;
1657ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        rbData->eglImageGlobalTexName = 0;
1658ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
1659ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1660ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glRenderbufferStorageEXT(target,internal,width,height);
1661ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1662ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1663ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glSampleCoverage(GLclampf value, GLboolean invert){
1664ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1665ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glSampleCoverage(value,invert);
1666ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1667ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1668ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glScissor(GLint x, GLint y, GLsizei width, GLsizei height){
1669ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1670ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glScissor(x,y,width,height);
1671ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1672ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1673ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length){
1674ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1675ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1676ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF( (ctx->dispatcher().glShaderBinary == NULL), GL_INVALID_OPERATION);
1677ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1678ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr()){
1679ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        for(int i=0; i < n ; i++){
1680ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            const GLuint globalShaderName = ctx->shareGroup()->getGlobalName(SHADER,shaders[i]);
1681ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            SET_ERROR_IF(globalShaderName == 0,GL_INVALID_VALUE);
1682ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->dispatcher().glShaderBinary(1,&globalShaderName,binaryformat,binary,length);
1683ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
1684ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
1685ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1686ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1687ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glShaderSource(GLuint shader, GLsizei count, const GLchar** string, const GLint* length){
1688ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_V2();
1689ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(count < 0,GL_INVALID_VALUE);
1690ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr()){
1691ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            const GLuint globalShaderName = ctx->shareGroup()->getGlobalName(SHADER,shader);
1692ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            SET_ERROR_IF(globalShaderName == 0,GL_INVALID_VALUE);
1693ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,shader);
1694ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            SET_ERROR_IF(!objData.Ptr(),GL_INVALID_OPERATION);
1695ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            SET_ERROR_IF(objData.Ptr()->getDataType()!=SHADER_DATA,GL_INVALID_OPERATION);
1696ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ShaderParser* sp = (ShaderParser*)objData.Ptr();
1697ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            sp->setSrc(ctx->glslVersion(),count,string,length);
1698ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->dispatcher().glShaderSource(globalShaderName,1,sp->parsedLines(),NULL);
1699ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
1700ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1701ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1702ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glStencilFunc(GLenum func, GLint ref, GLuint mask){
1703ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1704ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glStencilFunc(func,ref,mask);
1705ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1706ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask){
1707ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1708ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glStencilFuncSeparate(face,func,ref,mask);
1709ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1710ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glStencilMask(GLuint mask){
1711ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1712ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glStencilMask(mask);
1713ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1714ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1715ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glStencilMaskSeparate(GLenum face, GLuint mask){
1716ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1717ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glStencilMaskSeparate(face,mask);
1718ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1719ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1720ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glStencilOp(GLenum fail, GLenum zfail, GLenum zpass){
1721ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1722ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glStencilOp(fail,zfail,zpass);
1723ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1724ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1725ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass){
1726ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1727ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glStencilOp(fail,zfail,zpass);
1728ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1729ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1730ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* pixels){
1731ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1732ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!(GLESv2Validate::textureTargetEx(target) &&
1733ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                   GLESv2Validate::pixelFrmt(ctx,internalformat) &&
1734ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                   GLESv2Validate::pixelFrmt(ctx,format)&&
1735ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                   GLESv2Validate::pixelType(ctx,type)),GL_INVALID_ENUM);
1736ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1737ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF((format == GL_DEPTH_COMPONENT || internalformat == GL_DEPTH_COMPONENT) &&
1738ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    (type != GL_UNSIGNED_SHORT && type != GL_UNSIGNED_INT), GL_INVALID_OPERATION);
1739ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1740ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF((type == GL_UNSIGNED_SHORT || type == GL_UNSIGNED_INT) &&
1741ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    (format != GL_DEPTH_COMPONENT || internalformat != GL_DEPTH_COMPONENT), GL_INVALID_OPERATION);
1742ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1743ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!(GLESv2Validate::pixelOp(format,type) && internalformat == ((GLint)format)),GL_INVALID_OPERATION);
1744ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(border != 0,GL_INVALID_VALUE);
1745ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1746ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if (ctx->shareGroup().Ptr()){
1747ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        TextureData *texData = getTextureTargetData(target);
1748ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if(texData) {
1749ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            texData->width = width;
1750ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            texData->height = height;
1751ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            texData->border = border;
1752ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            texData->internalFormat = internalformat;
1753ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            texData->target = target;
1754ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1755ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            if (texData->sourceEGLImage != 0) {
1756ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                //
1757ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                // This texture was a target of EGLImage,
1758ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                // but now it is re-defined so we need to detach
1759ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                // from the EGLImage and re-generate global texture name
1760ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                // for it.
1761ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                //
1762ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                if (texData->eglImageDetach) {
1763ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    (*texData->eglImageDetach)(texData->sourceEGLImage);
1764ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                }
1765ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                unsigned int tex = ctx->getBindedTexture(target);
1766ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                ctx->shareGroup()->replaceGlobalName(TEXTURE,
1767ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                                                     tex,
1768ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                                                     texData->oldGlobal);
1769ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                ctx->dispatcher().glBindTexture(GL_TEXTURE_2D, texData->oldGlobal);
1770ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                texData->sourceEGLImage = 0;
1771ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                texData->oldGlobal = 0;
1772ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            }
1773ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
1774ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
1775ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1776ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if (type==GL_HALF_FLOAT_OES)
1777ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        type = GL_HALF_FLOAT_NV;
1778ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if (pixels==NULL && type==GL_UNSIGNED_SHORT_5_5_5_1)
1779ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        type = GL_UNSIGNED_SHORT;
1780ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glTexImage2D(target,level,internalformat,width,height,border,format,type,pixels);
1781ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1782ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1783ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1784ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glTexParameterf(GLenum target, GLenum pname, GLfloat param){
1785ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1786ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!(GLESv2Validate::textureTarget(target) && GLESv2Validate::textureParams(pname)),GL_INVALID_ENUM);
1787ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glTexParameterf(target,pname,param);
1788ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1789ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params){
1790ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1791ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!(GLESv2Validate::textureTarget(target) && GLESv2Validate::textureParams(pname)),GL_INVALID_ENUM);
1792ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glTexParameterfv(target,pname,params);
1793ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1794ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glTexParameteri(GLenum target, GLenum pname, GLint param){
1795ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1796ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!(GLESv2Validate::textureTarget(target) && GLESv2Validate::textureParams(pname)),GL_INVALID_ENUM);
1797ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glTexParameteri(target,pname,param);
1798ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1799ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glTexParameteriv(GLenum target, GLenum pname, const GLint* params){
1800ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1801ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!(GLESv2Validate::textureTarget(target) && GLESv2Validate::textureParams(pname)),GL_INVALID_ENUM);
1802ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glTexParameteriv(target,pname,params);
1803ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1804ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1805ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid* pixels){
1806ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1807ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!(GLESv2Validate::textureTargetEx(target) &&
1808ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                   GLESv2Validate::pixelFrmt(ctx,format)&&
1809ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                   GLESv2Validate::pixelType(ctx,type)),GL_INVALID_ENUM);
1810ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!GLESv2Validate::pixelOp(format,type),GL_INVALID_OPERATION);
1811ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if (type==GL_HALF_FLOAT_OES)
1812ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        type = GL_HALF_FLOAT_NV;
1813ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1814ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glTexSubImage2D(target,level,xoffset,yoffset,width,height,format,type,pixels);
1815ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1816ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1817ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1818ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glUniform1f(GLint location, GLfloat x){
1819ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1820ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glUniform1f(location,x);
1821ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1822ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glUniform1fv(GLint location, GLsizei count, const GLfloat* v){
1823ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1824ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glUniform1fv(location,count,v);
1825ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1826ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1827ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glUniform1i(GLint location, GLint x){
1828ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1829ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glUniform1i(location,x);
1830ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1831ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glUniform1iv(GLint location, GLsizei count, const GLint* v){
1832ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1833ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glUniform1iv(location,count,v);
1834ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1835ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glUniform2f(GLint location, GLfloat x, GLfloat y){
1836ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1837ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glUniform2f(location,x,y);
1838ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1839ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glUniform2fv(GLint location, GLsizei count, const GLfloat* v){
1840ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1841ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glUniform2fv(location,count,v);
1842ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1843ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glUniform2i(GLint location, GLint x, GLint y){
1844ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1845ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glUniform2i(location,x,y);
1846ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1847ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glUniform2iv(GLint location, GLsizei count, const GLint* v){
1848ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1849ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glUniform2iv(location,count,v);
1850ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1851ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z){
1852ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1853ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glUniform3f(location,x,y,z);
1854ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1855ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glUniform3fv(GLint location, GLsizei count, const GLfloat* v){
1856ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1857ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glUniform3fv(location,count,v);
1858ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1859ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glUniform3i(GLint location, GLint x, GLint y, GLint z){
1860ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1861ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glUniform3i(location,x,y,z);
1862ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1863ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1864ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glUniform3iv(GLint location, GLsizei count, const GLint* v){
1865ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1866ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glUniform3iv(location,count,v);
1867ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1868ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1869ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w){
1870ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1871ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glUniform4f(location,x,y,z,w);
1872ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1873ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1874ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glUniform4fv(GLint location, GLsizei count, const GLfloat* v){
1875ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1876ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glUniform4fv(location,count,v);
1877ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1878ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1879ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w){
1880ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1881ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glUniform4i(location,x,y,z,w);
1882ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1883ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1884ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glUniform4iv(GLint location, GLsizei count, const GLint* v){
1885ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1886ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glUniform4iv(location,count,v);
1887ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1888ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1889ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value){
1890ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1891ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(transpose != GL_FALSE,GL_INVALID_VALUE);
1892ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glUniformMatrix2fv(location,count,transpose,value);
1893ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1894ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1895ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value){
1896ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1897ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(transpose != GL_FALSE,GL_INVALID_VALUE);
1898ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glUniformMatrix3fv(location,count,transpose,value);
1899ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1900ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1901ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value){
1902ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1903ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(transpose != GL_FALSE,GL_INVALID_VALUE);
1904ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glUniformMatrix4fv(location,count,transpose,value);
1905ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1906ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1907ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glUseProgram(GLuint program){
1908ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1909ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr()) {
1910ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program);
1911ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(program!=0 && globalProgramName==0,GL_INVALID_VALUE);
1912ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program);
1913ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(objData.Ptr() && (objData.Ptr()->getDataType()!=PROGRAM_DATA),GL_INVALID_OPERATION);
1914ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glUseProgram(globalProgramName);
1915ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
1916ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1917ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1918ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glValidateProgram(GLuint program){
1919ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1920ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(ctx->shareGroup().Ptr()) {
1921ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program);
1922ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE);
1923ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program);
1924ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        SET_ERROR_IF(objData.Ptr()->getDataType()!=PROGRAM_DATA,GL_INVALID_OPERATION);
1925ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ProgramData* programData = (ProgramData*)objData.Ptr();
1926ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glValidateProgram(globalProgramName);
1927ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1928ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        GLsizei infoLogLength=0;
1929ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        GLchar* infoLog;
1930ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glGetProgramiv(globalProgramName,GL_INFO_LOG_LENGTH,&infoLogLength);
1931ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        infoLog = new GLchar[infoLogLength+1];
1932ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glGetProgramInfoLog(globalProgramName,infoLogLength,NULL,infoLog);
1933ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        programData->setInfoLog(infoLog);
1934ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
1935ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1936ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1937ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glVertexAttrib1f(GLuint indx, GLfloat x){
1938ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_V2();
1939ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glVertexAttrib1f(indx,x);
1940ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(indx == 0)
1941ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->setAttribute0value(x, 0.0, 0.0, 1.0);
1942ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1943ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1944ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glVertexAttrib1fv(GLuint indx, const GLfloat* values){
1945ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_V2();
1946ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glVertexAttrib1fv(indx,values);
1947ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(indx == 0)
1948ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->setAttribute0value(values[0], 0.0, 0.0, 1.0);
1949ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1950ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1951ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glVertexAttrib2f(GLuint indx, GLfloat x, GLfloat y){
1952ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_V2();
1953ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glVertexAttrib2f(indx,x,y);
1954ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(indx == 0)
1955ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->setAttribute0value(x, y, 0.0, 1.0);
1956ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1957ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1958ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glVertexAttrib2fv(GLuint indx, const GLfloat* values){
1959ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_V2();
1960ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glVertexAttrib2fv(indx,values);
1961ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(indx == 0)
1962ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->setAttribute0value(values[0], values[1], 0.0, 1.0);
1963ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1964ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1965ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glVertexAttrib3f(GLuint indx, GLfloat x, GLfloat y, GLfloat z){
1966ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_V2();
1967ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glVertexAttrib3f(indx,x,y,z);
1968ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(indx == 0)
1969ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->setAttribute0value(x, y, z, 1.0);
1970ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1971ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1972ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glVertexAttrib3fv(GLuint indx, const GLfloat* values){
1973ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_V2();
1974ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glVertexAttrib3fv(indx,values);
1975ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(indx == 0)
1976ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->setAttribute0value(values[0], values[1], values[2], 1.0);
1977ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1978ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1979ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glVertexAttrib4f(GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w){
1980ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_V2();
1981ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glVertexAttrib4f(indx,x,y,z,w);
1982ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(indx == 0)
1983ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->setAttribute0value(x, y, z, w);
1984ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1985ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1986ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glVertexAttrib4fv(GLuint indx, const GLfloat* values){
1987ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX_V2();
1988ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glVertexAttrib4fv(indx,values);
1989ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if(indx == 0)
1990ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->setAttribute0value(values[0], values[1], values[2], values[3]);
1991ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1992ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
1993ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glVertexAttribPointer(GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr){
1994ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
1995ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF((!GLESv2Validate::arrayIndex(ctx,indx)),GL_INVALID_VALUE);
1996ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if (type == GL_HALF_FLOAT_OES) type = GL_HALF_FLOAT;
1997ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->setPointer(indx,size,type,stride,ptr,normalized);
1998ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
1999ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
2000ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void  GL_APIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height){
2001ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
2002ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ctx->dispatcher().glViewport(x,y,width,height);
2003ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
2004ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
2005ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void GL_APIENTRY glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image)
2006ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall{
2007ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
2008ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!GLESv2Validate::textureTargetLimited(target),GL_INVALID_ENUM);
2009ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    unsigned int imagehndl = ToTargetCompatibleHandle((uintptr_t)image);
2010ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    EglImage *img = s_eglIface->eglAttachEGLImage(imagehndl);
2011ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if (img) {
2012ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        // Create the texture object in the underlying EGL implementation,
2013ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        // flag to the OpenGL layer to skip the image creation and map the
2014ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        // current binded texture object to the existing global object.
2015ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if (ctx->shareGroup().Ptr()) {
2016ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ObjectLocalName tex = TextureLocalName(target,ctx->getBindedTexture(target));
2017ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            unsigned int oldGlobal = ctx->shareGroup()->getGlobalName(TEXTURE, tex);
2018ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            // Delete old texture object but only if it is not a target of a EGLImage
2019ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            if (oldGlobal) {
2020ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                TextureData* oldTexData = getTextureData(tex);
2021ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                if (!oldTexData || oldTexData->sourceEGLImage == 0) {
2022ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                    ctx->dispatcher().glDeleteTextures(1, &oldGlobal);
2023ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                }
2024ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            }
2025ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            // replace mapping and bind the new global object
2026ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->shareGroup()->replaceGlobalName(TEXTURE, tex,img->globalTexName);
2027ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->dispatcher().glBindTexture(GL_TEXTURE_2D, img->globalTexName);
2028ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            TextureData *texData = getTextureTargetData(target);
2029ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION);
2030ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            texData->width = img->width;
2031ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            texData->height = img->height;
2032ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            texData->border = img->border;
2033ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            texData->internalFormat = img->internalFormat;
2034ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            texData->sourceEGLImage = imagehndl;
2035ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            texData->eglImageDetach = s_eglIface->eglDetachEGLImage;
2036ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            texData->oldGlobal = oldGlobal;
2037ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
2038ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
2039ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
2040ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
2041ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse HallGL_APICALL void GL_APIENTRY glEGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image)
2042ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall{
2043ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GET_CTX();
2044ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(target != GL_RENDERBUFFER_OES,GL_INVALID_ENUM);
2045ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    unsigned int imagehndl = ToTargetCompatibleHandle((uintptr_t)image);
2046ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    EglImage *img = s_eglIface->eglAttachEGLImage(imagehndl);
2047ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!img,GL_INVALID_VALUE);
2048ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!ctx->shareGroup().Ptr(),GL_INVALID_OPERATION);
2049ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
2050ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    // Get current bounded renderbuffer
2051ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    // raise INVALID_OPERATIOn if no renderbuffer is bounded
2052ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    GLuint rb = ctx->getRenderbufferBinding();
2053ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(rb == 0,GL_INVALID_OPERATION);
2054ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    ObjectDataPtr objData = ctx->shareGroup()->getObjectData(RENDERBUFFER,rb);
2055ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    RenderbufferData *rbData = (RenderbufferData *)objData.Ptr();
2056ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    SET_ERROR_IF(!rbData,GL_INVALID_OPERATION);
2057ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
2058ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    //
2059ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    // flag in the renderbufferData that it is an eglImage target
2060ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    //
2061ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    rbData->sourceEGLImage = imagehndl;
2062ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    rbData->eglImageDetach = s_eglIface->eglDetachEGLImage;
2063ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    rbData->eglImageGlobalTexName = img->globalTexName;
2064ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall
2065ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    //
2066ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    // if the renderbuffer is attached to a framebuffer
2067ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    // change the framebuffer attachment in the undelying OpenGL
2068ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    // to point to the eglImage texture object.
2069ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    //
2070ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    if (rbData->attachedFB) {
2071ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        // update the framebuffer attachment point to the
2072ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        // underlying texture of the img
2073ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        GLuint prevFB = ctx->getFramebufferBinding();
2074ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if (prevFB != rbData->attachedFB) {
2075ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->dispatcher().glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,
2076ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                                                   rbData->attachedFB);
2077ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
2078ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        ctx->dispatcher().glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
2079ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                                                    rbData->attachedPoint,
2080ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                                                    GL_TEXTURE_2D,
2081ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                                                    img->globalTexName,0);
2082ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        if (prevFB != rbData->attachedFB) {
2083ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall            ctx->dispatcher().glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,
2084ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall                                                   prevFB);
2085ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall        }
2086ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall    }
2087ce6c3389061fb9fcdefc94fab2044a8e11600b52Jesse Hall}
2088