From 3c15de2f2e80fb659924fc06296e04e17a9e43d0 Mon Sep 17 00:00:00 2001 From: Liran Date: Sun, 5 Jun 2011 11:42:50 +0300 Subject: [PATCH] opengl translator: conformance fixes fix shader and program names in glDeleteShader/Program fix object name manager to accept objects with name 0 fix unbinding of buffers,framebuffers and renderbuffers separate getPointer to have specific implementation for gles 1 and 2 fix number of supported texture images to match GL fix incorrect optimization that skips draw on false conditions --- .../host/libs/Translator/EGL/EglImp.cpp | 3 +- .../libs/Translator/GLES_CM/GLEScmContext.cpp | 28 +++++++-- .../libs/Translator/GLES_CM/GLEScmContext.h | 4 +- .../libs/Translator/GLES_CM/GLEScmImp.cpp | 36 +++++++----- .../libs/Translator/GLES_V2/GLESv2Context.cpp | 8 ++- .../libs/Translator/GLES_V2/GLESv2Context.h | 1 + .../libs/Translator/GLES_V2/GLESv2Imp.cpp | 57 ++++++++++--------- .../libs/Translator/GLcommon/GLEScontext.cpp | 53 +++++++++-------- .../libs/Translator/GLcommon/GLESpointer.cpp | 1 - .../Translator/GLcommon/objectNameManager.cpp | 8 +-- .../Translator/include/GLcommon/GLEScontext.h | 14 +++-- .../include/GLcommon/TranslatorIfaces.h | 2 +- .../include/GLcommon/objectNameManager.h | 10 ++-- 13 files changed, 130 insertions(+), 95 deletions(-) diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglImp.cpp b/tools/emulator/opengl/host/libs/Translator/EGL/EglImp.cpp index 999d13a78..dbecbe0b9 100644 --- a/tools/emulator/opengl/host/libs/Translator/EGL/EglImp.cpp +++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglImp.cpp @@ -753,8 +753,7 @@ EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay display, EGLSurface draw thread->updateInfo(newCtx,dpy,newCtx->getGlesContext(),newCtx->getShareGroup(),dpy->getManager(newCtx->version())); newCtx->setSurfaces(newReadSrfc,newDrawSrfc); - g_eglInfo->getIface(newCtx->version())->initContext(newCtx->getGlesContext()); - g_eglInfo->getIface(newCtx->version())->setShareGroup(newCtx->getGlesContext(),newCtx->getShareGroup()); + g_eglInfo->getIface(newCtx->version())->initContext(newCtx->getGlesContext(),newCtx->getShareGroup()); } SurfacePtr prevRead; diff --git a/tools/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmContext.cpp b/tools/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmContext.cpp index 2fbe2e273..69023c3bb 100644 --- a/tools/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmContext.cpp +++ b/tools/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmContext.cpp @@ -25,11 +25,12 @@ void GLEScmContext::init() { android::Mutex::Autolock mutex(s_lock); if(!m_initialized) { s_glDispatch.dispatchFuncs(GLES_1_1); - initCapsLocked(s_glDispatch.glGetString(GL_EXTENSIONS)); - initExtensionString(); + GLEScontext::init(); + + m_texCoords = new GLESpointer[s_glSupport.maxTexUnits]; + m_map[GL_TEXTURE_COORD_ARRAY] = &m_texCoords[m_clientActiveTexture]; + } - m_texCoords = new GLESpointer[s_glSupport.maxTexUnits]; - m_map[GL_TEXTURE_COORD_ARRAY] = &m_texCoords[m_clientActiveTexture]; m_initialized = true; } @@ -238,6 +239,21 @@ bool GLEScmContext::needConvert(GLESConversionArrays& fArrs,GLint first,GLsizei return true; } +const GLESpointer* GLEScmContext::getPointer(GLenum arrType) { + GLenum type = + arrType == GL_VERTEX_ARRAY_POINTER ? GL_VERTEX_ARRAY : + arrType == GL_NORMAL_ARRAY_POINTER ? GL_NORMAL_ARRAY : + arrType == GL_TEXTURE_COORD_ARRAY_POINTER ? GL_TEXTURE_COORD_ARRAY : + arrType == GL_COLOR_ARRAY_POINTER ? GL_COLOR_ARRAY : + arrType == GL_POINT_SIZE_ARRAY_POINTER_OES ? GL_POINT_SIZE_ARRAY_OES : + 0; + if(type != 0) + { + return GLEScontext::getPointer(type); + } + return NULL; +} + void GLEScmContext::initExtensionString() { *s_glExtensions = "GL_OES_blend_func_separate GL_OES_blend_equation_separate GL_OES_blend_subtract " "GL_OES_byte_coordinates GL_OES_compressed_paletted_texture GL_OES_point_size_array " @@ -264,3 +280,7 @@ void GLEScmContext::initExtensionString() { *s_glExtensions+="GL_OES_extended_matrix_palette "; } } + +int GLEScmContext::getMaxTexUnits() { + return getCaps()->maxTexUnits; +} diff --git a/tools/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmContext.h b/tools/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmContext.h index f3f4a6aeb..388c8d4cf 100644 --- a/tools/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmContext.h +++ b/tools/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmContext.h @@ -41,7 +41,9 @@ public: void setupArraysPointers(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct); void drawPointsArrs(GLESConversionArrays& arrs,GLint first,GLsizei count); void drawPointsElems(GLESConversionArrays& arrs,GLsizei count,GLenum type,const GLvoid* indices); - + const GLESpointer* getPointer(GLenum arrType); + int getMaxTexUnits(); + ~GLEScmContext(); protected: diff --git a/tools/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmImp.cpp b/tools/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmImp.cpp index 00d507092..50fff9925 100644 --- a/tools/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmImp.cpp +++ b/tools/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmImp.cpp @@ -38,7 +38,7 @@ extern "C" { //decleration -static void initContext(GLEScontext* ctx); +static void initContext(GLEScontext* ctx,ShareGroupPtr grp); static void deleteGLESContext(GLEScontext* ctx); static void setShareGroup(GLEScontext* ctx,ShareGroupPtr grp); static GLEScontext* createGLESContext(); @@ -67,8 +67,12 @@ static GLESiface s_glesIface = { extern "C" { -static void initContext(GLEScontext* ctx) { - ctx->init(); +static void initContext(GLEScontext* ctx,ShareGroupPtr grp) { + if (!ctx->isInitialized()) { + ctx->setShareGroup(grp); + ctx->init(); + glBindTexture(GL_TEXTURE_2D,0); + } } static GLEScontext* createGLESContext() { @@ -268,13 +272,15 @@ GL_API void GL_APIENTRY glBindBuffer( GLenum target, GLuint buffer) { SET_ERROR_IF(!GLEScmValidate::bufferTarget(target),GL_INVALID_ENUM); //if buffer wasn't generated before,generate one - if(thrd->shareGroup.Ptr() && !thrd->shareGroup->isObject(VERTEXBUFFER,buffer)){ + if(buffer && thrd->shareGroup.Ptr() && !thrd->shareGroup->isObject(VERTEXBUFFER,buffer)){ thrd->shareGroup->genName(VERTEXBUFFER,buffer); thrd->shareGroup->setObjectData(VERTEXBUFFER,buffer,ObjectDataPtr(new GLESbuffer())); } ctx->bindBuffer(target,buffer); - GLESbuffer* vbo = (GLESbuffer*)thrd->shareGroup->getObjectData(VERTEXBUFFER,buffer).Ptr(); - vbo->wasBinded(); + if (buffer) { + GLESbuffer* vbo = (GLESbuffer*)thrd->shareGroup->getObjectData(VERTEXBUFFER,buffer).Ptr(); + vbo->setBinded(); + } } @@ -283,7 +289,7 @@ GL_API void GL_APIENTRY glBindTexture( GLenum target, GLuint texture) { SET_ERROR_IF(!GLEScmValidate::textureTarget(target),GL_INVALID_ENUM) GLuint globalTextureName = texture; - if(texture && thrd->shareGroup.Ptr()){ + if(thrd->shareGroup.Ptr()){ globalTextureName = thrd->shareGroup->getGlobalName(TEXTURE,texture); //if texture wasn't generated before,generate one if(!globalTextureName){ @@ -637,7 +643,7 @@ GL_API void GL_APIENTRY glGenBuffers( GLsizei n, GLuint *buffers) { SET_ERROR_IF(n<0,GL_INVALID_VALUE); if(thrd->shareGroup.Ptr()) { for(int i=0; ishareGroup->genName(VERTEXBUFFER); + buffers[i] = thrd->shareGroup->genName(VERTEXBUFFER, 0, true); //generating vbo object related to this buffer name thrd->shareGroup->setObjectData(VERTEXBUFFER,buffers[i],ObjectDataPtr(new GLESbuffer())); } @@ -648,7 +654,7 @@ GL_API void GL_APIENTRY glGenTextures( GLsizei n, GLuint *textures) { GET_CTX(); if(thrd->shareGroup.Ptr()) { for(int i=0; ishareGroup->genName(TEXTURE); + textures[i] = thrd->shareGroup->genName(TEXTURE, 0, true); } } } @@ -1544,11 +1550,11 @@ GL_API void GLAPIENTRY glBindRenderbufferOES(GLenum target, GLuint renderbuffer) SET_ERROR_IF(!GLEScmValidate::renderbufferTarget(target),GL_INVALID_ENUM); //if buffer wasn't generated before,generate one - if(thrd->shareGroup.Ptr() && !thrd->shareGroup->isObject(RENDERBUFFER,renderbuffer)){ + if(renderbuffer && thrd->shareGroup.Ptr() && !thrd->shareGroup->isObject(RENDERBUFFER,renderbuffer)){ thrd->shareGroup->genName(RENDERBUFFER,renderbuffer); } - int globalBufferName = thrd->shareGroup->getGlobalName(RENDERBUFFER,renderbuffer); + int globalBufferName = (renderbuffer != 0) ? thrd->shareGroup->getGlobalName(RENDERBUFFER,renderbuffer) : 0; ctx->dispatcher().glBindRenderbufferEXT(target,globalBufferName); } @@ -1567,7 +1573,7 @@ GL_API void GLAPIENTRY glGenRenderbuffersOES(GLsizei n, GLuint *renderbuffers) { SET_ERROR_IF(n<0,GL_INVALID_VALUE); if(thrd->shareGroup.Ptr()) { for(int i=0; ishareGroup->genName(RENDERBUFFER); + renderbuffers[i] = thrd->shareGroup->genName(RENDERBUFFER, 0, true); } } } @@ -1601,10 +1607,10 @@ GL_API void GLAPIENTRY glBindFramebufferOES(GLenum target, GLuint framebuffer) { GET_CTX() SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION); SET_ERROR_IF(!GLEScmValidate::framebufferTarget(target) ,GL_INVALID_ENUM); - if (thrd->shareGroup.Ptr() && !thrd->shareGroup->isObject(FRAMEBUFFER,framebuffer)) { + if (framebuffer && thrd->shareGroup.Ptr() && !thrd->shareGroup->isObject(FRAMEBUFFER,framebuffer)) { thrd->shareGroup->genName(FRAMEBUFFER,framebuffer); } - int globalBufferName = thrd->shareGroup->getGlobalName(FRAMEBUFFER,framebuffer); + int globalBufferName = (framebuffer!=0) ? thrd->shareGroup->getGlobalName(FRAMEBUFFER,framebuffer) : 0; ctx->dispatcher().glBindFramebufferEXT(target,globalBufferName); } @@ -1623,7 +1629,7 @@ GL_API void GLAPIENTRY glGenFramebuffersOES(GLsizei n, GLuint *framebuffers) { SET_ERROR_IF(n<0,GL_INVALID_VALUE); if (thrd->shareGroup.Ptr()) { for (int i=0;ishareGroup->genName(FRAMEBUFFER); + framebuffers[i] = thrd->shareGroup->genName(FRAMEBUFFER, 0, true); } } } diff --git a/tools/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Context.cpp b/tools/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Context.cpp index 24dfe1b13..e8dfc3798 100644 --- a/tools/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Context.cpp +++ b/tools/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Context.cpp @@ -22,9 +22,7 @@ void GLESv2Context::init() { android::Mutex::Autolock mutex(s_lock); if(!m_initialized) { s_glDispatch.dispatchFuncs(GLES_2_0); - initCapsLocked(s_glDispatch.glGetString(GL_EXTENSIONS)); - initExtensionString(); - + GLEScontext::init(); for(int i=0; i < s_glSupport.maxVertexAttribs;i++){ m_map[i] = new GLESpointer(); } @@ -101,3 +99,7 @@ void GLESv2Context::initExtensionString() { if (s_glSupport.GL_ARB_HALF_FLOAT_VERTEX) *s_glExtensions+="GL_OES_vertex_half_float "; } + +int GLESv2Context::getMaxTexUnits() { + return getCaps()->maxTexImageUnits; +} diff --git a/tools/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Context.h b/tools/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Context.h index 5f4fa23d2..28cdbe9c4 100644 --- a/tools/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Context.h +++ b/tools/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Context.h @@ -29,6 +29,7 @@ public: void init(); GLESv2Context(); void setupArraysPointers(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct); + int getMaxTexUnits(); protected: bool needConvert(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct,GLESpointer* p,GLenum array_id); private: diff --git a/tools/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp b/tools/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp index 39803a509..7e749a206 100644 --- a/tools/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp +++ b/tools/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp @@ -32,7 +32,7 @@ extern "C" { //decleration -static void initContext(GLEScontext* ctx); +static void initContext(GLEScontext* ctx,ShareGroupPtr grp); static void deleteGLESContext(GLEScontext* ctx); static void setShareGroup(GLEScontext* ctx,ShareGroupPtr grp); static GLEScontext* createGLESContext(); @@ -61,8 +61,12 @@ static GLESiface s_glesIface = { extern "C" { -static void initContext(GLEScontext* ctx) { - ctx->init(); +static void initContext(GLEScontext* ctx,ShareGroupPtr grp) { + if (!ctx->isInitialized()) { + ctx->setShareGroup(grp); + ctx->init(); + glBindTexture(GL_TEXTURE_2D,0); + } } static GLEScontext* createGLESContext() { return new GLESv2Context(); @@ -135,13 +139,15 @@ GL_APICALL void GL_APIENTRY glBindBuffer(GLenum target, GLuint buffer){ GET_CTX(); SET_ERROR_IF(!GLESv2Validate::bufferTarget(target),GL_INVALID_ENUM); //if buffer wasn't generated before,generate one - if(thrd->shareGroup.Ptr() && !thrd->shareGroup->isObject(VERTEXBUFFER,buffer)){ + if(buffer && thrd->shareGroup.Ptr() && !thrd->shareGroup->isObject(VERTEXBUFFER,buffer)){ thrd->shareGroup->genName(VERTEXBUFFER,buffer); thrd->shareGroup->setObjectData(VERTEXBUFFER,buffer,ObjectDataPtr(new GLESbuffer())); } ctx->bindBuffer(target,buffer); - GLESbuffer* vbo = (GLESbuffer*)thrd->shareGroup->getObjectData(VERTEXBUFFER,buffer).Ptr(); - vbo->setBinded(); + if (buffer) { + GLESbuffer* vbo = (GLESbuffer*)thrd->shareGroup->getObjectData(VERTEXBUFFER,buffer).Ptr(); + vbo->setBinded(); + } } GL_APICALL void GL_APIENTRY glBindFramebuffer(GLenum target, GLuint framebuffer){ @@ -181,7 +187,7 @@ GL_APICALL void GL_APIENTRY glBindTexture(GLenum target, GLuint texture){ SET_ERROR_IF(!GLESv2Validate::textureTarget(target),GL_INVALID_ENUM) GLuint globalTextureName = texture; - if(texture && thrd->shareGroup.Ptr()){ + if(thrd->shareGroup.Ptr()){ globalTextureName = thrd->shareGroup->getGlobalName(TEXTURE,texture); //if texture wasn't generated before,generate one if(!globalTextureName){ @@ -189,7 +195,7 @@ GL_APICALL void GL_APIENTRY glBindTexture(GLenum target, GLuint texture){ globalTextureName = thrd->shareGroup->getGlobalName(TEXTURE,texture); } } - ctx->setBindedTexture(globalTextureName); + ctx->setBindedTexture(texture); ctx->dispatcher().glBindTexture(target,globalTextureName); } @@ -303,7 +309,7 @@ GL_APICALL GLuint GL_APIENTRY glCreateProgram(void){ GET_CTX_RET(0); const GLuint globalProgramName = ctx->dispatcher().glCreateProgram(); if(thrd->shareGroup.Ptr() && globalProgramName) { - const GLuint localProgramName = thrd->shareGroup->genName(SHADER); + const GLuint localProgramName = thrd->shareGroup->genName(SHADER, 0, true); thrd->shareGroup->replaceGlobalName(SHADER,localProgramName,globalProgramName); return localProgramName; } @@ -317,7 +323,7 @@ GL_APICALL GLuint GL_APIENTRY glCreateShader(GLenum type){ GET_CTX_V2_RET(0); const GLuint globalShaderName = ctx->dispatcher().glCreateShader(type); if(thrd->shareGroup.Ptr() && globalShaderName) { - const GLuint localShaderName = thrd->shareGroup->genName(SHADER); + const GLuint localShaderName = thrd->shareGroup->genName(SHADER, 0, true); ShaderParser* sp = new ShaderParser(type); thrd->shareGroup->replaceGlobalName(SHADER,localShaderName,globalShaderName); thrd->shareGroup->setObjectData(SHADER,localShaderName,ObjectDataPtr(sp)); @@ -385,7 +391,7 @@ GL_APICALL void GL_APIENTRY glDeleteProgram(GLuint program){ if(thrd->shareGroup.Ptr()) { const GLuint globalProgramName = thrd->shareGroup->getGlobalName(SHADER,program); thrd->shareGroup->deleteName(SHADER,program); - ctx->dispatcher().glDeleteProgram(program); + ctx->dispatcher().glDeleteProgram(globalProgramName); } } @@ -394,7 +400,7 @@ GL_APICALL void GL_APIENTRY glDeleteShader(GLuint shader){ if(thrd->shareGroup.Ptr()) { const GLuint globalShaderName = thrd->shareGroup->getGlobalName(SHADER,shader); thrd->shareGroup->deleteName(SHADER,shader); - ctx->dispatcher().glDeleteShader(shader); + ctx->dispatcher().glDeleteShader(globalShaderName); } } @@ -437,9 +443,6 @@ GL_APICALL void GL_APIENTRY glDrawArrays(GLenum mode, GLint first, GLsizei coun SET_ERROR_IF(count < 0,GL_INVALID_VALUE) SET_ERROR_IF(!GLESv2Validate::drawMode(mode),GL_INVALID_ENUM); - //if no vertex are enabled no need to convert anything - if(!ctx->isArrEnabled(0)) return; - GLESConversionArrays tmpArrs; ctx->setupArraysPointers(tmpArrs,first,count,0,NULL,true); ctx->dispatcher().glDrawArrays(mode,first,count); @@ -456,9 +459,6 @@ GL_APICALL void GL_APIENTRY glDrawElements(GLenum mode, GLsizei count, GLenum t indices = buf+reinterpret_cast(elementsIndices); } - //if no vertex are enabled no need to convert anything - if(!ctx->isArrEnabled(0)) return; - GLESConversionArrays tmpArrs; ctx->setupArraysPointers(tmpArrs,0,count,type,indices,false); ctx->dispatcher().glDrawElements(mode,count,type,indices); @@ -522,7 +522,7 @@ GL_APICALL void GL_APIENTRY glGenBuffers(GLsizei n, GLuint* buffers){ SET_ERROR_IF(n<0,GL_INVALID_VALUE); if(thrd->shareGroup.Ptr()) { for(int i=0; ishareGroup->genName(VERTEXBUFFER); + buffers[i] = thrd->shareGroup->genName(VERTEXBUFFER, 0, true); //generating vbo object related to this buffer name thrd->shareGroup->setObjectData(VERTEXBUFFER,buffers[i],ObjectDataPtr(new GLESbuffer())); } @@ -540,7 +540,7 @@ GL_APICALL void GL_APIENTRY glGenFramebuffers(GLsizei n, GLuint* framebuffers){ SET_ERROR_IF(n<0,GL_INVALID_VALUE); if(thrd->shareGroup.Ptr()) { for(int i=0; ishareGroup->genName(FRAMEBUFFER); + framebuffers[i] = thrd->shareGroup->genName(FRAMEBUFFER, 0 ,true); } } } @@ -550,7 +550,7 @@ GL_APICALL void GL_APIENTRY glGenRenderbuffers(GLsizei n, GLuint* renderbuffers SET_ERROR_IF(n<0,GL_INVALID_VALUE); if(thrd->shareGroup.Ptr()) { for(int i=0; ishareGroup->genName(RENDERBUFFER); + renderbuffers[i] = thrd->shareGroup->genName(RENDERBUFFER, 0, true); } } } @@ -560,7 +560,7 @@ GL_APICALL void GL_APIENTRY glGenTextures(GLsizei n, GLuint* textures){ SET_ERROR_IF(n<0,GL_INVALID_VALUE); if(thrd->shareGroup.Ptr()) { for(int i=0; ishareGroup->genName(TEXTURE); + textures[i] = thrd->shareGroup->genName(TEXTURE, 0, true); } } } @@ -710,7 +710,8 @@ GL_APICALL void GL_APIENTRY glGetShaderSource(GLuint shader, GLsizei bufsize, G const char* src = ((ShaderParser*)objData.Ptr())->getOriginalSrc(); int srcLength = strlen(src); SET_ERROR_IF(bufsize < 0 || srcLength > bufsize,GL_INVALID_VALUE); - *length = srcLength; + if (length) + *length = srcLength; strncpy(source,src,srcLength); } } @@ -780,7 +781,7 @@ GL_APICALL int GL_APIENTRY glGetUniformLocation(GLuint program, const GLchar* na GL_APICALL void GL_APIENTRY glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params){ GET_CTX(); - const GLESpointer* p = ctx->getPointer(pname); + const GLESpointer* p = ctx->getPointer(index); if(p) { switch(pname){ case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: @@ -814,7 +815,7 @@ GL_APICALL void GL_APIENTRY glGetVertexAttribfv(GLuint index, GLenum pname, GLf GL_APICALL void GL_APIENTRY glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params){ GET_CTX(); - const GLESpointer* p = ctx->getPointer(pname); + const GLESpointer* p = ctx->getPointer(index); if(p) { switch(pname){ case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: @@ -848,9 +849,9 @@ GL_APICALL void GL_APIENTRY glGetVertexAttribiv(GLuint index, GLenum pname, GLi GL_APICALL void GL_APIENTRY glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer){ GET_CTX(); - SET_ERROR_IF(pname != GL_VERTEX_ATTRIB_ARRAY_POINTER,GL_INVALID_ENUM); - - const GLESpointer* p = ctx->getPointer(pname); + SET_ERROR_IF(pname != GL_VERTEX_ATTRIB_ARRAY_POINTER,GL_INVALID_ENUM); + + const GLESpointer* p = ctx->getPointer(index); if(p) { *pointer = const_cast( p->getBufferData()); } else { diff --git a/tools/emulator/opengl/host/libs/Translator/GLcommon/GLEScontext.cpp b/tools/emulator/opengl/host/libs/Translator/GLcommon/GLEScontext.cpp index 66948bc99..5740b6cf3 100644 --- a/tools/emulator/opengl/host/libs/Translator/GLcommon/GLEScontext.cpp +++ b/tools/emulator/opengl/host/libs/Translator/GLcommon/GLEScontext.cpp @@ -92,18 +92,33 @@ bool Version::operator<(const Version& ver) const{ return false; } +void GLEScontext::init() { + + if (!s_glExtensions) { + initCapsLocked(s_glDispatch.glGetString(GL_EXTENSIONS)); + s_glExtensions = new std::string(""); + } + + if (!m_initialized) { + initExtensionString(); + + int maxTexUnits = getMaxTexUnits(); + m_tex2DBind = new textureUnitState[maxTexUnits]; + for (int i=0;i(m_buffer->getData()) + m_buffOffset : NULL; } diff --git a/tools/emulator/opengl/host/libs/Translator/GLcommon/objectNameManager.cpp b/tools/emulator/opengl/host/libs/Translator/GLcommon/objectNameManager.cpp index e6d42cf0f..24d751aa4 100644 --- a/tools/emulator/opengl/host/libs/Translator/GLcommon/objectNameManager.cpp +++ b/tools/emulator/opengl/host/libs/Translator/GLcommon/objectNameManager.cpp @@ -34,11 +34,11 @@ NameSpace::~NameSpace() } unsigned int -NameSpace::genName(unsigned int p_localName, bool genGlobal) +NameSpace::genName(unsigned int p_localName, bool genGlobal, bool genLocal) { unsigned int localName = p_localName; - if (localName == 0) { + if (genLocal) { do { localName = ++m_nextName; } while( localName == 0 || m_localToGlobalMap.find(localName) != m_localToGlobalMap.end() ); @@ -134,12 +134,12 @@ ShareGroup::~ShareGroup() } unsigned int -ShareGroup::genName(NamedObjectType p_type, unsigned int p_localName) +ShareGroup::genName(NamedObjectType p_type, unsigned int p_localName, bool genLocal) { if (p_type >= NUM_OBJECT_TYPES) return 0; mutex_lock(&m_lock); - unsigned int localName = m_nameSpace[p_type]->genName(p_localName); + unsigned int localName = m_nameSpace[p_type]->genName(p_localName,true,genLocal); mutex_unlock(&m_lock); return localName; diff --git a/tools/emulator/opengl/host/libs/Translator/include/GLcommon/GLEScontext.h b/tools/emulator/opengl/host/libs/Translator/include/GLcommon/GLEScontext.h index 3b2937ad2..d43dddbab 100644 --- a/tools/emulator/opengl/host/libs/Translator/include/GLcommon/GLEScontext.h +++ b/tools/emulator/opengl/host/libs/Translator/include/GLcommon/GLEScontext.h @@ -8,8 +8,6 @@ #include #include -#define MAX_TEX_UNITS 8 - typedef std::map ArraysMap; enum TextureTarget { @@ -38,7 +36,8 @@ private: }; struct GLSupport { - GLSupport():maxLights(0),maxVertexAttribs(0),maxClipPlane(0),maxTexUnits(0),maxTexSize(0) , \ + GLSupport():maxLights(0),maxVertexAttribs(0),maxClipPlane(0),maxTexUnits(0), \ + maxTexImageUnits(0),maxTexSize(0) , \ GL_EXT_TEXTURE_FORMAT_BGRA8888(false), GL_EXT_FRAMEBUFFER_OBJECT(false), \ GL_ARB_VERTEX_BLEND(false), GL_ARB_MATRIX_PALETTE(false), \ GL_NV_PACKED_DEPTH_STENCIL(false) , GL_OES_READ_FORMAT(false), \ @@ -48,6 +47,7 @@ struct GLSupport { int maxVertexAttribs; int maxClipPlane; int maxTexUnits; + int maxTexImageUnits; int maxTexSize; Version glslVersion; bool GL_EXT_TEXTURE_FORMAT_BGRA8888; @@ -80,7 +80,7 @@ private: class GLEScontext{ public: - virtual void init() = 0; + virtual void init(); GLEScontext(); GLenum getGLerror(); void setGLerror(GLenum err); @@ -91,6 +91,7 @@ public: void setBindedTexture(unsigned int tex){ m_tex2DBind[m_activeTexture].texture = tex;}; bool isTextureUnitEnabled(GLenum unit); void setTextureEnabled(TextureTarget target, GLenum enable) {m_tex2DBind[m_activeTexture].enabled[target] = enable; }; + bool isInitialized() { return m_initialized; }; bool isArrEnabled(GLenum); void enableArr(GLenum arr,bool enable); @@ -111,12 +112,12 @@ public: void releaseGlobalLock(); virtual GLSupport* getCaps(){return &s_glSupport;}; virtual ~GLEScontext(); + virtual int getMaxTexUnits() = 0; static GLDispatch& dispatcher(){return s_glDispatch;}; static int getMaxLights(){return s_glSupport.maxLights;} static int getMaxClipPlanes(){return s_glSupport.maxClipPlane;} - static int getMaxTexUnits(){return s_glSupport.maxTexUnits;} static int getMaxTexSize(){return s_glSupport.maxTexSize;} static Version glslVersion(){return s_glSupport.glslVersion;} @@ -128,6 +129,7 @@ protected: void convertIndirect(GLESConversionArrays& fArrs,GLsizei count,GLenum type,const GLvoid* indices,GLenum array_id,GLESpointer* p); void convertIndirectVBO(GLsizei count,GLenum indices_type,const GLvoid* indices,GLenum array_id,GLESpointer* p); void initCapsLocked(const GLubyte * extensionString); + virtual void initExtensionString() =0; static android::Mutex s_lock; static GLDispatch s_glDispatch; bool m_initialized; @@ -143,7 +145,7 @@ private: ShareGroupPtr m_shareGroup; GLenum m_glError; - textureUnitState m_tex2DBind[MAX_TEX_UNITS]; + textureUnitState* m_tex2DBind; unsigned int m_arrayBuffer; unsigned int m_elementBuffer; }; diff --git a/tools/emulator/opengl/host/libs/Translator/include/GLcommon/TranslatorIfaces.h b/tools/emulator/opengl/host/libs/Translator/include/GLcommon/TranslatorIfaces.h index 5d00ce62d..ee70f8a5b 100644 --- a/tools/emulator/opengl/host/libs/Translator/include/GLcommon/TranslatorIfaces.h +++ b/tools/emulator/opengl/host/libs/Translator/include/GLcommon/TranslatorIfaces.h @@ -68,7 +68,7 @@ class GLEScontext; typedef struct { GLEScontext* (*createGLESContext)(); - void (*initContext)(GLEScontext*); + void (*initContext)(GLEScontext*,ShareGroupPtr); void (*deleteGLESContext)(GLEScontext*); void (*flush)(); void (*finish)(); diff --git a/tools/emulator/opengl/host/libs/Translator/include/GLcommon/objectNameManager.h b/tools/emulator/opengl/host/libs/Translator/include/GLcommon/objectNameManager.h index 5f2e82c62..fdc4666c0 100644 --- a/tools/emulator/opengl/host/libs/Translator/include/GLcommon/objectNameManager.h +++ b/tools/emulator/opengl/host/libs/Translator/include/GLcommon/objectNameManager.h @@ -60,12 +60,12 @@ private: // // genName - creates new object in the namespace and returns its name. - // if p_localName is specified this name will be used. + // if genLocal is false then the specified p_localName will be used. // This function also generate a global name for the object, // the value of the global name can be retrieved using the // getGlobalName function. // - unsigned int genName(unsigned int p_localName = 0, bool genGlobal = true); + unsigned int genName(unsigned int p_localName, bool genGlobal, bool genLocal); // // getGlobalName - returns the global name of an object or 0 if the object @@ -130,7 +130,7 @@ public: if ( p_type >= NUM_OBJECT_TYPES ) return 0; mutex_lock(&m_lock); - unsigned int name = m_nameSpace[p_type]->genName(0, false); + unsigned int name = m_nameSpace[p_type]->genName(0, false,true); mutex_unlock(&m_lock); return name; } @@ -166,11 +166,11 @@ public: // // genName - generates new object name and returns its name value. - // if p_localName is specified this name will be used. + // if genLocal is false, p_localName will be used as the name. // This function also generates a "global" name for the object // which can be queried using the getGlobalName function. // - unsigned int genName(NamedObjectType p_type, unsigned int p_localName = 0); + unsigned int genName(NamedObjectType p_type, unsigned int p_localName = 0, bool genLocal= false); // // getGlobalName - retrieves the "global" name of an object or 0 if the