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
This commit is contained in:
Liran
2011-06-05 11:42:50 +03:00
committed by Guy Zadickario
parent 61d845731a
commit 3c15de2f2e
13 changed files with 130 additions and 95 deletions

View File

@@ -753,8 +753,7 @@ EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay display, EGLSurface draw
thread->updateInfo(newCtx,dpy,newCtx->getGlesContext(),newCtx->getShareGroup(),dpy->getManager(newCtx->version())); thread->updateInfo(newCtx,dpy,newCtx->getGlesContext(),newCtx->getShareGroup(),dpy->getManager(newCtx->version()));
newCtx->setSurfaces(newReadSrfc,newDrawSrfc); newCtx->setSurfaces(newReadSrfc,newDrawSrfc);
g_eglInfo->getIface(newCtx->version())->initContext(newCtx->getGlesContext()); g_eglInfo->getIface(newCtx->version())->initContext(newCtx->getGlesContext(),newCtx->getShareGroup());
g_eglInfo->getIface(newCtx->version())->setShareGroup(newCtx->getGlesContext(),newCtx->getShareGroup());
} }
SurfacePtr prevRead; SurfacePtr prevRead;

View File

@@ -25,11 +25,12 @@ void GLEScmContext::init() {
android::Mutex::Autolock mutex(s_lock); android::Mutex::Autolock mutex(s_lock);
if(!m_initialized) { if(!m_initialized) {
s_glDispatch.dispatchFuncs(GLES_1_1); s_glDispatch.dispatchFuncs(GLES_1_1);
initCapsLocked(s_glDispatch.glGetString(GL_EXTENSIONS)); GLEScontext::init();
initExtensionString();
}
m_texCoords = new GLESpointer[s_glSupport.maxTexUnits]; m_texCoords = new GLESpointer[s_glSupport.maxTexUnits];
m_map[GL_TEXTURE_COORD_ARRAY] = &m_texCoords[m_clientActiveTexture]; m_map[GL_TEXTURE_COORD_ARRAY] = &m_texCoords[m_clientActiveTexture];
}
m_initialized = true; m_initialized = true;
} }
@@ -238,6 +239,21 @@ bool GLEScmContext::needConvert(GLESConversionArrays& fArrs,GLint first,GLsizei
return true; 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() { void GLEScmContext::initExtensionString() {
*s_glExtensions = "GL_OES_blend_func_separate GL_OES_blend_equation_separate GL_OES_blend_subtract " *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 " "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 "; *s_glExtensions+="GL_OES_extended_matrix_palette ";
} }
} }
int GLEScmContext::getMaxTexUnits() {
return getCaps()->maxTexUnits;
}

View File

@@ -41,6 +41,8 @@ public:
void setupArraysPointers(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct); void setupArraysPointers(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct);
void drawPointsArrs(GLESConversionArrays& arrs,GLint first,GLsizei count); void drawPointsArrs(GLESConversionArrays& arrs,GLint first,GLsizei count);
void drawPointsElems(GLESConversionArrays& arrs,GLsizei count,GLenum type,const GLvoid* indices); void drawPointsElems(GLESConversionArrays& arrs,GLsizei count,GLenum type,const GLvoid* indices);
const GLESpointer* getPointer(GLenum arrType);
int getMaxTexUnits();
~GLEScmContext(); ~GLEScmContext();
protected: protected:

View File

@@ -38,7 +38,7 @@
extern "C" { extern "C" {
//decleration //decleration
static void initContext(GLEScontext* ctx); static void initContext(GLEScontext* ctx,ShareGroupPtr grp);
static void deleteGLESContext(GLEScontext* ctx); static void deleteGLESContext(GLEScontext* ctx);
static void setShareGroup(GLEScontext* ctx,ShareGroupPtr grp); static void setShareGroup(GLEScontext* ctx,ShareGroupPtr grp);
static GLEScontext* createGLESContext(); static GLEScontext* createGLESContext();
@@ -67,8 +67,12 @@ static GLESiface s_glesIface = {
extern "C" { extern "C" {
static void initContext(GLEScontext* ctx) { static void initContext(GLEScontext* ctx,ShareGroupPtr grp) {
if (!ctx->isInitialized()) {
ctx->setShareGroup(grp);
ctx->init(); ctx->init();
glBindTexture(GL_TEXTURE_2D,0);
}
} }
static GLEScontext* createGLESContext() { 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); SET_ERROR_IF(!GLEScmValidate::bufferTarget(target),GL_INVALID_ENUM);
//if buffer wasn't generated before,generate one //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->genName(VERTEXBUFFER,buffer);
thrd->shareGroup->setObjectData(VERTEXBUFFER,buffer,ObjectDataPtr(new GLESbuffer())); thrd->shareGroup->setObjectData(VERTEXBUFFER,buffer,ObjectDataPtr(new GLESbuffer()));
} }
ctx->bindBuffer(target,buffer); ctx->bindBuffer(target,buffer);
if (buffer) {
GLESbuffer* vbo = (GLESbuffer*)thrd->shareGroup->getObjectData(VERTEXBUFFER,buffer).Ptr(); GLESbuffer* vbo = (GLESbuffer*)thrd->shareGroup->getObjectData(VERTEXBUFFER,buffer).Ptr();
vbo->wasBinded(); 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) SET_ERROR_IF(!GLEScmValidate::textureTarget(target),GL_INVALID_ENUM)
GLuint globalTextureName = texture; GLuint globalTextureName = texture;
if(texture && thrd->shareGroup.Ptr()){ if(thrd->shareGroup.Ptr()){
globalTextureName = thrd->shareGroup->getGlobalName(TEXTURE,texture); globalTextureName = thrd->shareGroup->getGlobalName(TEXTURE,texture);
//if texture wasn't generated before,generate one //if texture wasn't generated before,generate one
if(!globalTextureName){ if(!globalTextureName){
@@ -637,7 +643,7 @@ GL_API void GL_APIENTRY glGenBuffers( GLsizei n, GLuint *buffers) {
SET_ERROR_IF(n<0,GL_INVALID_VALUE); SET_ERROR_IF(n<0,GL_INVALID_VALUE);
if(thrd->shareGroup.Ptr()) { if(thrd->shareGroup.Ptr()) {
for(int i=0; i<n ;i++) { for(int i=0; i<n ;i++) {
buffers[i] = thrd->shareGroup->genName(VERTEXBUFFER); buffers[i] = thrd->shareGroup->genName(VERTEXBUFFER, 0, true);
//generating vbo object related to this buffer name //generating vbo object related to this buffer name
thrd->shareGroup->setObjectData(VERTEXBUFFER,buffers[i],ObjectDataPtr(new GLESbuffer())); 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(); GET_CTX();
if(thrd->shareGroup.Ptr()) { if(thrd->shareGroup.Ptr()) {
for(int i=0; i<n ;i++) { for(int i=0; i<n ;i++) {
textures[i] = thrd->shareGroup->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); SET_ERROR_IF(!GLEScmValidate::renderbufferTarget(target),GL_INVALID_ENUM);
//if buffer wasn't generated before,generate one //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); 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); 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); SET_ERROR_IF(n<0,GL_INVALID_VALUE);
if(thrd->shareGroup.Ptr()) { if(thrd->shareGroup.Ptr()) {
for(int i=0; i<n ;i++) { for(int i=0; i<n ;i++) {
renderbuffers[i] = thrd->shareGroup->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() GET_CTX()
SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION); SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION);
SET_ERROR_IF(!GLEScmValidate::framebufferTarget(target) ,GL_INVALID_ENUM); 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); 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); 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); SET_ERROR_IF(n<0,GL_INVALID_VALUE);
if (thrd->shareGroup.Ptr()) { if (thrd->shareGroup.Ptr()) {
for (int i=0;i<n;i++) { for (int i=0;i<n;i++) {
framebuffers[i] = thrd->shareGroup->genName(FRAMEBUFFER); framebuffers[i] = thrd->shareGroup->genName(FRAMEBUFFER, 0, true);
} }
} }
} }

View File

@@ -22,9 +22,7 @@ void GLESv2Context::init() {
android::Mutex::Autolock mutex(s_lock); android::Mutex::Autolock mutex(s_lock);
if(!m_initialized) { if(!m_initialized) {
s_glDispatch.dispatchFuncs(GLES_2_0); s_glDispatch.dispatchFuncs(GLES_2_0);
initCapsLocked(s_glDispatch.glGetString(GL_EXTENSIONS)); GLEScontext::init();
initExtensionString();
for(int i=0; i < s_glSupport.maxVertexAttribs;i++){ for(int i=0; i < s_glSupport.maxVertexAttribs;i++){
m_map[i] = new GLESpointer(); m_map[i] = new GLESpointer();
} }
@@ -101,3 +99,7 @@ void GLESv2Context::initExtensionString() {
if (s_glSupport.GL_ARB_HALF_FLOAT_VERTEX) if (s_glSupport.GL_ARB_HALF_FLOAT_VERTEX)
*s_glExtensions+="GL_OES_vertex_half_float "; *s_glExtensions+="GL_OES_vertex_half_float ";
} }
int GLESv2Context::getMaxTexUnits() {
return getCaps()->maxTexImageUnits;
}

View File

@@ -29,6 +29,7 @@ public:
void init(); void init();
GLESv2Context(); GLESv2Context();
void setupArraysPointers(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct); void setupArraysPointers(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct);
int getMaxTexUnits();
protected: protected:
bool needConvert(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct,GLESpointer* p,GLenum array_id); bool needConvert(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct,GLESpointer* p,GLenum array_id);
private: private:

View File

@@ -32,7 +32,7 @@
extern "C" { extern "C" {
//decleration //decleration
static void initContext(GLEScontext* ctx); static void initContext(GLEScontext* ctx,ShareGroupPtr grp);
static void deleteGLESContext(GLEScontext* ctx); static void deleteGLESContext(GLEScontext* ctx);
static void setShareGroup(GLEScontext* ctx,ShareGroupPtr grp); static void setShareGroup(GLEScontext* ctx,ShareGroupPtr grp);
static GLEScontext* createGLESContext(); static GLEScontext* createGLESContext();
@@ -61,8 +61,12 @@ static GLESiface s_glesIface = {
extern "C" { extern "C" {
static void initContext(GLEScontext* ctx) { static void initContext(GLEScontext* ctx,ShareGroupPtr grp) {
if (!ctx->isInitialized()) {
ctx->setShareGroup(grp);
ctx->init(); ctx->init();
glBindTexture(GL_TEXTURE_2D,0);
}
} }
static GLEScontext* createGLESContext() { static GLEScontext* createGLESContext() {
return new GLESv2Context(); return new GLESv2Context();
@@ -135,13 +139,15 @@ GL_APICALL void GL_APIENTRY glBindBuffer(GLenum target, GLuint buffer){
GET_CTX(); GET_CTX();
SET_ERROR_IF(!GLESv2Validate::bufferTarget(target),GL_INVALID_ENUM); SET_ERROR_IF(!GLESv2Validate::bufferTarget(target),GL_INVALID_ENUM);
//if buffer wasn't generated before,generate one //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->genName(VERTEXBUFFER,buffer);
thrd->shareGroup->setObjectData(VERTEXBUFFER,buffer,ObjectDataPtr(new GLESbuffer())); thrd->shareGroup->setObjectData(VERTEXBUFFER,buffer,ObjectDataPtr(new GLESbuffer()));
} }
ctx->bindBuffer(target,buffer); ctx->bindBuffer(target,buffer);
if (buffer) {
GLESbuffer* vbo = (GLESbuffer*)thrd->shareGroup->getObjectData(VERTEXBUFFER,buffer).Ptr(); GLESbuffer* vbo = (GLESbuffer*)thrd->shareGroup->getObjectData(VERTEXBUFFER,buffer).Ptr();
vbo->setBinded(); vbo->setBinded();
}
} }
GL_APICALL void GL_APIENTRY glBindFramebuffer(GLenum target, GLuint framebuffer){ 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) SET_ERROR_IF(!GLESv2Validate::textureTarget(target),GL_INVALID_ENUM)
GLuint globalTextureName = texture; GLuint globalTextureName = texture;
if(texture && thrd->shareGroup.Ptr()){ if(thrd->shareGroup.Ptr()){
globalTextureName = thrd->shareGroup->getGlobalName(TEXTURE,texture); globalTextureName = thrd->shareGroup->getGlobalName(TEXTURE,texture);
//if texture wasn't generated before,generate one //if texture wasn't generated before,generate one
if(!globalTextureName){ if(!globalTextureName){
@@ -189,7 +195,7 @@ GL_APICALL void GL_APIENTRY glBindTexture(GLenum target, GLuint texture){
globalTextureName = thrd->shareGroup->getGlobalName(TEXTURE,texture); globalTextureName = thrd->shareGroup->getGlobalName(TEXTURE,texture);
} }
} }
ctx->setBindedTexture(globalTextureName); ctx->setBindedTexture(texture);
ctx->dispatcher().glBindTexture(target,globalTextureName); ctx->dispatcher().glBindTexture(target,globalTextureName);
} }
@@ -303,7 +309,7 @@ GL_APICALL GLuint GL_APIENTRY glCreateProgram(void){
GET_CTX_RET(0); GET_CTX_RET(0);
const GLuint globalProgramName = ctx->dispatcher().glCreateProgram(); const GLuint globalProgramName = ctx->dispatcher().glCreateProgram();
if(thrd->shareGroup.Ptr() && globalProgramName) { 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); thrd->shareGroup->replaceGlobalName(SHADER,localProgramName,globalProgramName);
return localProgramName; return localProgramName;
} }
@@ -317,7 +323,7 @@ GL_APICALL GLuint GL_APIENTRY glCreateShader(GLenum type){
GET_CTX_V2_RET(0); GET_CTX_V2_RET(0);
const GLuint globalShaderName = ctx->dispatcher().glCreateShader(type); const GLuint globalShaderName = ctx->dispatcher().glCreateShader(type);
if(thrd->shareGroup.Ptr() && globalShaderName) { 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); ShaderParser* sp = new ShaderParser(type);
thrd->shareGroup->replaceGlobalName(SHADER,localShaderName,globalShaderName); thrd->shareGroup->replaceGlobalName(SHADER,localShaderName,globalShaderName);
thrd->shareGroup->setObjectData(SHADER,localShaderName,ObjectDataPtr(sp)); thrd->shareGroup->setObjectData(SHADER,localShaderName,ObjectDataPtr(sp));
@@ -385,7 +391,7 @@ GL_APICALL void GL_APIENTRY glDeleteProgram(GLuint program){
if(thrd->shareGroup.Ptr()) { if(thrd->shareGroup.Ptr()) {
const GLuint globalProgramName = thrd->shareGroup->getGlobalName(SHADER,program); const GLuint globalProgramName = thrd->shareGroup->getGlobalName(SHADER,program);
thrd->shareGroup->deleteName(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()) { if(thrd->shareGroup.Ptr()) {
const GLuint globalShaderName = thrd->shareGroup->getGlobalName(SHADER,shader); const GLuint globalShaderName = thrd->shareGroup->getGlobalName(SHADER,shader);
thrd->shareGroup->deleteName(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(count < 0,GL_INVALID_VALUE)
SET_ERROR_IF(!GLESv2Validate::drawMode(mode),GL_INVALID_ENUM); 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; GLESConversionArrays tmpArrs;
ctx->setupArraysPointers(tmpArrs,first,count,0,NULL,true); ctx->setupArraysPointers(tmpArrs,first,count,0,NULL,true);
ctx->dispatcher().glDrawArrays(mode,first,count); 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<unsigned int>(elementsIndices); indices = buf+reinterpret_cast<unsigned int>(elementsIndices);
} }
//if no vertex are enabled no need to convert anything
if(!ctx->isArrEnabled(0)) return;
GLESConversionArrays tmpArrs; GLESConversionArrays tmpArrs;
ctx->setupArraysPointers(tmpArrs,0,count,type,indices,false); ctx->setupArraysPointers(tmpArrs,0,count,type,indices,false);
ctx->dispatcher().glDrawElements(mode,count,type,indices); 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); SET_ERROR_IF(n<0,GL_INVALID_VALUE);
if(thrd->shareGroup.Ptr()) { if(thrd->shareGroup.Ptr()) {
for(int i=0; i<n ;i++) { for(int i=0; i<n ;i++) {
buffers[i] = thrd->shareGroup->genName(VERTEXBUFFER); buffers[i] = thrd->shareGroup->genName(VERTEXBUFFER, 0, true);
//generating vbo object related to this buffer name //generating vbo object related to this buffer name
thrd->shareGroup->setObjectData(VERTEXBUFFER,buffers[i],ObjectDataPtr(new GLESbuffer())); 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); SET_ERROR_IF(n<0,GL_INVALID_VALUE);
if(thrd->shareGroup.Ptr()) { if(thrd->shareGroup.Ptr()) {
for(int i=0; i<n ;i++) { for(int i=0; i<n ;i++) {
framebuffers[i] = thrd->shareGroup->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); SET_ERROR_IF(n<0,GL_INVALID_VALUE);
if(thrd->shareGroup.Ptr()) { if(thrd->shareGroup.Ptr()) {
for(int i=0; i<n ;i++) { for(int i=0; i<n ;i++) {
renderbuffers[i] = thrd->shareGroup->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); SET_ERROR_IF(n<0,GL_INVALID_VALUE);
if(thrd->shareGroup.Ptr()) { if(thrd->shareGroup.Ptr()) {
for(int i=0; i<n ;i++) { for(int i=0; i<n ;i++) {
textures[i] = thrd->shareGroup->genName(TEXTURE); textures[i] = thrd->shareGroup->genName(TEXTURE, 0, true);
} }
} }
} }
@@ -710,6 +710,7 @@ GL_APICALL void GL_APIENTRY glGetShaderSource(GLuint shader, GLsizei bufsize, G
const char* src = ((ShaderParser*)objData.Ptr())->getOriginalSrc(); const char* src = ((ShaderParser*)objData.Ptr())->getOriginalSrc();
int srcLength = strlen(src); int srcLength = strlen(src);
SET_ERROR_IF(bufsize < 0 || srcLength > bufsize,GL_INVALID_VALUE); SET_ERROR_IF(bufsize < 0 || srcLength > bufsize,GL_INVALID_VALUE);
if (length)
*length = srcLength; *length = srcLength;
strncpy(source,src,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){ GL_APICALL void GL_APIENTRY glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params){
GET_CTX(); GET_CTX();
const GLESpointer* p = ctx->getPointer(pname); const GLESpointer* p = ctx->getPointer(index);
if(p) { if(p) {
switch(pname){ switch(pname){
case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: 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){ GL_APICALL void GL_APIENTRY glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params){
GET_CTX(); GET_CTX();
const GLESpointer* p = ctx->getPointer(pname); const GLESpointer* p = ctx->getPointer(index);
if(p) { if(p) {
switch(pname){ switch(pname){
case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
@@ -850,7 +851,7 @@ GL_APICALL void GL_APIENTRY glGetVertexAttribPointerv(GLuint index, GLenum pnam
GET_CTX(); GET_CTX();
SET_ERROR_IF(pname != GL_VERTEX_ATTRIB_ARRAY_POINTER,GL_INVALID_ENUM); SET_ERROR_IF(pname != GL_VERTEX_ATTRIB_ARRAY_POINTER,GL_INVALID_ENUM);
const GLESpointer* p = ctx->getPointer(pname); const GLESpointer* p = ctx->getPointer(index);
if(p) { if(p) {
*pointer = const_cast<void *>( p->getBufferData()); *pointer = const_cast<void *>( p->getBufferData());
} else { } else {

View File

@@ -92,18 +92,33 @@ bool Version::operator<(const Version& ver) const{
return false; return false;
} }
GLEScontext::GLEScontext(): void GLEScontext::init() {
m_initialized(false) ,
m_activeTexture(0) , if (!s_glExtensions) {
m_glError(GL_NO_ERROR) , initCapsLocked(s_glDispatch.glGetString(GL_EXTENSIONS));
m_arrayBuffer(0) , s_glExtensions = new std::string("");
m_elementBuffer(0) { }
for (int i=0;i<MAX_TEX_UNITS;++i) {
if (!m_initialized) {
initExtensionString();
int maxTexUnits = getMaxTexUnits();
m_tex2DBind = new textureUnitState[maxTexUnits];
for (int i=0;i<maxTexUnits;++i) {
m_tex2DBind[i].texture = 0; m_tex2DBind[i].texture = 0;
for (int j=0;j<NUM_TEXTURE_TARGETS;++j) for (int j=0;j<NUM_TEXTURE_TARGETS;++j)
m_tex2DBind[i].enabled[j] = GL_FALSE; m_tex2DBind[i].enabled[j] = GL_FALSE;
} }
}; }
}
GLEScontext::GLEScontext():
m_initialized(false) ,
m_activeTexture(0) ,
m_glError(GL_NO_ERROR) ,
m_tex2DBind(0) ,
m_arrayBuffer(0) ,
m_elementBuffer(0){};
GLenum GLEScontext::getGLerror() { GLenum GLEScontext::getGLerror() {
return m_glError; return m_glError;
@@ -124,6 +139,8 @@ GLEScontext::~GLEScontext() {
delete p; delete p;
} }
} }
delete[] m_tex2DBind;
m_tex2DBind = NULL;
} }
const GLvoid* GLEScontext::setPointer(GLenum arrType,GLint size,GLenum type,GLsizei stride,const GLvoid* data,bool normalize) { const GLvoid* GLEScontext::setPointer(GLenum arrType,GLint size,GLenum type,GLsizei stride,const GLvoid* data,bool normalize) {
@@ -147,18 +164,7 @@ bool GLEScontext::isArrEnabled(GLenum arr) {
} }
const GLESpointer* GLEScontext::getPointer(GLenum arrType) { const GLESpointer* GLEScontext::getPointer(GLenum arrType) {
GLenum type = if (m_map.find(arrType) != m_map.end()) return m_map[arrType];
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 && m_map.find(type) != m_map.end())
{
return m_map[type];
}
return NULL; return NULL;
} }
@@ -443,15 +449,14 @@ void GLEScontext::releaseGlobalLock() {
void GLEScontext::initCapsLocked(const GLubyte * extensionString) void GLEScontext::initCapsLocked(const GLubyte * extensionString)
{ {
int maxTexUnits;
const char* cstring = (const char*)extensionString; const char* cstring = (const char*)extensionString;
s_glDispatch.glGetIntegerv(GL_MAX_VERTEX_ATTRIBS,&s_glSupport.maxVertexAttribs); s_glDispatch.glGetIntegerv(GL_MAX_VERTEX_ATTRIBS,&s_glSupport.maxVertexAttribs);
s_glDispatch.glGetIntegerv(GL_MAX_CLIP_PLANES,&s_glSupport.maxClipPlane); s_glDispatch.glGetIntegerv(GL_MAX_CLIP_PLANES,&s_glSupport.maxClipPlane);
s_glDispatch.glGetIntegerv(GL_MAX_LIGHTS,&s_glSupport.maxLights); s_glDispatch.glGetIntegerv(GL_MAX_LIGHTS,&s_glSupport.maxLights);
s_glDispatch.glGetIntegerv(GL_MAX_TEXTURE_SIZE,&s_glSupport.maxTexSize); s_glDispatch.glGetIntegerv(GL_MAX_TEXTURE_SIZE,&s_glSupport.maxTexSize);
s_glDispatch.glGetIntegerv(GL_MAX_TEXTURE_UNITS,&maxTexUnits); s_glDispatch.glGetIntegerv(GL_MAX_TEXTURE_UNITS,&s_glSupport.maxTexUnits);
s_glSupport.maxTexUnits = maxTexUnits < MAX_TEX_UNITS ? maxTexUnits:MAX_TEX_UNITS; s_glDispatch.glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS,&s_glSupport.maxTexImageUnits);
const GLubyte* glslVersion = s_glDispatch.glGetString(GL_SHADING_LANGUAGE_VERSION); const GLubyte* glslVersion = s_glDispatch.glGetString(GL_SHADING_LANGUAGE_VERSION);
s_glSupport.glslVersion = Version((const char*)(glslVersion)); s_glSupport.glslVersion = Version((const char*)(glslVersion));
@@ -482,8 +487,6 @@ void GLEScontext::initCapsLocked(const GLubyte * extensionString)
if (strstr(cstring,"GL_ARB_half_float_vertex ")!=NULL) if (strstr(cstring,"GL_ARB_half_float_vertex ")!=NULL)
s_glSupport.GL_ARB_HALF_FLOAT_VERTEX = true; s_glSupport.GL_ARB_HALF_FLOAT_VERTEX = true;
//init extension string
s_glExtensions = new std::string("");
} }
bool GLEScontext::isTextureUnitEnabled(GLenum unit) { bool GLEScontext::isTextureUnitEnabled(GLenum unit) {

View File

@@ -44,7 +44,6 @@ const GLvoid* GLESpointer::getArrayData() const {
} }
GLvoid* GLESpointer::getBufferData() const { GLvoid* GLESpointer::getBufferData() const {
return m_buffer ? static_cast<unsigned char*>(m_buffer->getData()) + m_buffOffset : NULL; return m_buffer ? static_cast<unsigned char*>(m_buffer->getData()) + m_buffOffset : NULL;
} }

View File

@@ -34,11 +34,11 @@ NameSpace::~NameSpace()
} }
unsigned int 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; unsigned int localName = p_localName;
if (localName == 0) { if (genLocal) {
do { do {
localName = ++m_nextName; localName = ++m_nextName;
} while( localName == 0 || m_localToGlobalMap.find(localName) != m_localToGlobalMap.end() ); } while( localName == 0 || m_localToGlobalMap.find(localName) != m_localToGlobalMap.end() );
@@ -134,12 +134,12 @@ ShareGroup::~ShareGroup()
} }
unsigned int 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; if (p_type >= NUM_OBJECT_TYPES) return 0;
mutex_lock(&m_lock); 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); mutex_unlock(&m_lock);
return localName; return localName;

View File

@@ -8,8 +8,6 @@
#include <string> #include <string>
#include <utility> #include <utility>
#define MAX_TEX_UNITS 8
typedef std::map<GLenum,GLESpointer*> ArraysMap; typedef std::map<GLenum,GLESpointer*> ArraysMap;
enum TextureTarget { enum TextureTarget {
@@ -38,7 +36,8 @@ private:
}; };
struct GLSupport { 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_EXT_TEXTURE_FORMAT_BGRA8888(false), GL_EXT_FRAMEBUFFER_OBJECT(false), \
GL_ARB_VERTEX_BLEND(false), GL_ARB_MATRIX_PALETTE(false), \ GL_ARB_VERTEX_BLEND(false), GL_ARB_MATRIX_PALETTE(false), \
GL_NV_PACKED_DEPTH_STENCIL(false) , GL_OES_READ_FORMAT(false), \ GL_NV_PACKED_DEPTH_STENCIL(false) , GL_OES_READ_FORMAT(false), \
@@ -48,6 +47,7 @@ struct GLSupport {
int maxVertexAttribs; int maxVertexAttribs;
int maxClipPlane; int maxClipPlane;
int maxTexUnits; int maxTexUnits;
int maxTexImageUnits;
int maxTexSize; int maxTexSize;
Version glslVersion; Version glslVersion;
bool GL_EXT_TEXTURE_FORMAT_BGRA8888; bool GL_EXT_TEXTURE_FORMAT_BGRA8888;
@@ -80,7 +80,7 @@ private:
class GLEScontext{ class GLEScontext{
public: public:
virtual void init() = 0; virtual void init();
GLEScontext(); GLEScontext();
GLenum getGLerror(); GLenum getGLerror();
void setGLerror(GLenum err); void setGLerror(GLenum err);
@@ -91,6 +91,7 @@ public:
void setBindedTexture(unsigned int tex){ m_tex2DBind[m_activeTexture].texture = tex;}; void setBindedTexture(unsigned int tex){ m_tex2DBind[m_activeTexture].texture = tex;};
bool isTextureUnitEnabled(GLenum unit); bool isTextureUnitEnabled(GLenum unit);
void setTextureEnabled(TextureTarget target, GLenum enable) {m_tex2DBind[m_activeTexture].enabled[target] = enable; }; void setTextureEnabled(TextureTarget target, GLenum enable) {m_tex2DBind[m_activeTexture].enabled[target] = enable; };
bool isInitialized() { return m_initialized; };
bool isArrEnabled(GLenum); bool isArrEnabled(GLenum);
void enableArr(GLenum arr,bool enable); void enableArr(GLenum arr,bool enable);
@@ -111,12 +112,12 @@ public:
void releaseGlobalLock(); void releaseGlobalLock();
virtual GLSupport* getCaps(){return &s_glSupport;}; virtual GLSupport* getCaps(){return &s_glSupport;};
virtual ~GLEScontext(); virtual ~GLEScontext();
virtual int getMaxTexUnits() = 0;
static GLDispatch& dispatcher(){return s_glDispatch;}; static GLDispatch& dispatcher(){return s_glDispatch;};
static int getMaxLights(){return s_glSupport.maxLights;} static int getMaxLights(){return s_glSupport.maxLights;}
static int getMaxClipPlanes(){return s_glSupport.maxClipPlane;} static int getMaxClipPlanes(){return s_glSupport.maxClipPlane;}
static int getMaxTexUnits(){return s_glSupport.maxTexUnits;}
static int getMaxTexSize(){return s_glSupport.maxTexSize;} static int getMaxTexSize(){return s_glSupport.maxTexSize;}
static Version glslVersion(){return s_glSupport.glslVersion;} 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 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 convertIndirectVBO(GLsizei count,GLenum indices_type,const GLvoid* indices,GLenum array_id,GLESpointer* p);
void initCapsLocked(const GLubyte * extensionString); void initCapsLocked(const GLubyte * extensionString);
virtual void initExtensionString() =0;
static android::Mutex s_lock; static android::Mutex s_lock;
static GLDispatch s_glDispatch; static GLDispatch s_glDispatch;
bool m_initialized; bool m_initialized;
@@ -143,7 +145,7 @@ private:
ShareGroupPtr m_shareGroup; ShareGroupPtr m_shareGroup;
GLenum m_glError; GLenum m_glError;
textureUnitState m_tex2DBind[MAX_TEX_UNITS]; textureUnitState* m_tex2DBind;
unsigned int m_arrayBuffer; unsigned int m_arrayBuffer;
unsigned int m_elementBuffer; unsigned int m_elementBuffer;
}; };

View File

@@ -68,7 +68,7 @@ class GLEScontext;
typedef struct { typedef struct {
GLEScontext* (*createGLESContext)(); GLEScontext* (*createGLESContext)();
void (*initContext)(GLEScontext*); void (*initContext)(GLEScontext*,ShareGroupPtr);
void (*deleteGLESContext)(GLEScontext*); void (*deleteGLESContext)(GLEScontext*);
void (*flush)(); void (*flush)();
void (*finish)(); void (*finish)();

View File

@@ -60,12 +60,12 @@ private:
// //
// genName - creates new object in the namespace and returns its name. // 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, // This function also generate a global name for the object,
// the value of the global name can be retrieved using the // the value of the global name can be retrieved using the
// getGlobalName function. // 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 // 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; if ( p_type >= NUM_OBJECT_TYPES ) return 0;
mutex_lock(&m_lock); 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); mutex_unlock(&m_lock);
return name; return name;
} }
@@ -166,11 +166,11 @@ public:
// //
// genName - generates new object name and returns its name value. // 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 // This function also generates a "global" name for the object
// which can be queried using the getGlobalName function. // 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 // getGlobalName - retrieves the "global" name of an object or 0 if the