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 7d6dbc5f2..2fbe2e273 100644 --- a/tools/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmContext.cpp +++ b/tools/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmContext.cpp @@ -60,20 +60,21 @@ GLEScmContext::~GLEScmContext(){ } -//sending data to server side -void GLEScmContext::sendArr(GLvoid* arr,GLenum arrayType,GLint size,GLsizei stride,int index) { +//setting client side arr +void GLEScmContext::setupArr(const GLvoid* arr,GLenum arrayType,GLenum dataType,GLint size,GLsizei stride,int index){ + if( arr == NULL) return; switch(arrayType) { case GL_VERTEX_ARRAY: - s_glDispatch.glVertexPointer(size,GL_FLOAT,stride,arr); + s_glDispatch.glVertexPointer(size,dataType,stride,arr); break; case GL_NORMAL_ARRAY: - s_glDispatch.glNormalPointer(GL_FLOAT,stride,arr); + s_glDispatch.glNormalPointer(dataType,stride,arr); break; case GL_TEXTURE_COORD_ARRAY: - s_glDispatch.glTexCoordPointer(size,GL_FLOAT,stride,arr); + s_glDispatch.glTexCoordPointer(size,dataType,stride,arr); break; case GL_COLOR_ARRAY: - s_glDispatch.glColorPointer(size,GL_FLOAT,stride,arr); + s_glDispatch.glColorPointer(size,dataType,stride,arr); break; case GL_POINT_SIZE_ARRAY_OES: m_pointsIndex = index; @@ -81,18 +82,37 @@ void GLEScmContext::sendArr(GLvoid* arr,GLenum arrayType,GLint size,GLsizei stri } } -void GLEScmContext::convertArrs(GLESFloatArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct) { + +void GLEScmContext::setupArrayPointerHelper(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct,GLenum array_id,GLESpointer* p){ + unsigned int size = p->getSize(); + bool usingVBO = p->isVBO(); + GLenum dataType = p->getType(); + + if(needConvert(fArrs,first,count,type,indices,direct,p,array_id)){ + //conversion has occured + unsigned int convertedStride = (usingVBO && dataType != GL_BYTE) ? p->getStride() : 0; + const void* data = (usingVBO && dataType!= GL_BYTE) ? p->getBufferData() : fArrs.getCurrentData(); + dataType = (dataType == GL_FIXED) ? GL_FLOAT:GL_SHORT; + setupArr(data,array_id,dataType,size,convertedStride,fArrs.getCurrentIndex()); + ++fArrs; + } else { + const void* data = usingVBO ? p->getBufferData() : p->getArrayData(); + setupArr(data,array_id,dataType,size,p->getStride()); + } +} + +void GLEScmContext::setupArraysPointers(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct) { ArraysMap::iterator it; - unsigned int index = 0; m_pointsIndex = -1; //going over all clients arrays Pointers for ( it=m_map.begin() ; it != m_map.end(); it++ ) { + GLenum array_id = (*it).first; GLESpointer* p = (*it).second; - + if(!isArrEnabled(array_id)) continue; if(array_id == GL_TEXTURE_COORD_ARRAY) continue; //handling textures later - chooseConvertMethod(fArrs,first,count,type,indices,direct,p,array_id,index); + setupArrayPointerHelper(fArrs,first,count,type,indices,direct,array_id,p); } unsigned int activeTexture = m_clientActiveTexture + GL_TEXTURE0; @@ -110,7 +130,8 @@ void GLEScmContext::convertArrs(GLESFloatArrays& fArrs,GLint first,GLsizei count GLenum array_id = GL_TEXTURE_COORD_ARRAY; GLESpointer* p = m_map[array_id]; - chooseConvertMethod(fArrs,first,count,type,indices,direct,p,array_id,index); + if(!isArrEnabled(array_id)) continue; + setupArrayPointerHelper(fArrs,first,count,type,indices,direct,array_id,p); } setClientActiveTexture(activeTexture); @@ -142,17 +163,18 @@ void GLEScmContext::drawPoints(PointSizeIndices* points) { if(indices) delete [] indices; } -void GLEScmContext::drawPointsData(GLESFloatArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices_in,bool isElemsDraw) { +void GLEScmContext::drawPointsData(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices_in,bool isElemsDraw) { const GLfloat *pointsArr = NULL; int stride = 0; //steps in GLfloats + bool usingVBO = isBindedBuffer(GL_ARRAY_BUFFER); //choosing the right points sizes array source - if(m_pointsIndex >= 0) { //point size array was converted - pointsArr=fArrs.arrays[m_pointsIndex]; + if(m_pointsIndex >= 0 && !usingVBO) { //point size array was converted + pointsArr= (const GLfloat*)fArrs[m_pointsIndex]; stride = 1; } else { GLESpointer* p = m_map[GL_POINT_SIZE_ARRAY_OES]; - pointsArr = static_cast(isBindedBuffer(GL_ARRAY_BUFFER)?p->getBufferData():p->getArrayData()); + pointsArr = static_cast(usingVBO ? p->getBufferData():p->getArrayData()); stride = p->getStride()?p->getStride()/sizeof(GLfloat):1; } @@ -173,14 +195,49 @@ void GLEScmContext::drawPointsData(GLESFloatArrays& fArrs,GLint first,GLsizei c drawPoints(&points); } -void GLEScmContext::drawPointsArrs(GLESFloatArrays& arrs,GLint first,GLsizei count) { +void GLEScmContext::drawPointsArrs(GLESConversionArrays& arrs,GLint first,GLsizei count) { drawPointsData(arrs,first,count,0,NULL,false); } -void GLEScmContext::drawPointsElems(GLESFloatArrays& arrs,GLsizei count,GLenum type,const GLvoid* indices_in) { +void GLEScmContext::drawPointsElems(GLESConversionArrays& arrs,GLsizei count,GLenum type,const GLvoid* indices_in) { drawPointsData(arrs,0,count,type,indices_in,true); } +bool GLEScmContext::needConvert(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct,GLESpointer* p,GLenum array_id) { + + bool usingVBO = p->isVBO(); + GLenum arrType = p->getType(); + /* + conversion is not necessary in the following cases: + (*) array type is byte but it is not vertex or texture array + (*) array type is not fixed + */ + if((arrType != GL_FIXED) && (arrType != GL_BYTE)) return false; + if((arrType == GL_BYTE && (array_id != GL_VERTEX_ARRAY)) && + (arrType == GL_BYTE && (array_id != GL_TEXTURE_COORD_ARRAY)) ) return false; + + + bool byteVBO = (arrType == GL_BYTE) && usingVBO; + if(byteVBO){ + p->redirectPointerData(); + } + + if(!usingVBO || byteVBO) { + if (direct) { + convertDirect(fArrs,first,count,array_id,p); + } else { + convertIndirect(fArrs,count,type,indices,array_id,p); + } + } else { + if (direct) { + convertDirectVBO(first,count,array_id,p) ; + } else { + convertIndirectVBO(count,type,indices,array_id,p); + } + } + return true; +} + 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 " @@ -205,5 +262,5 @@ void GLEScmContext::initExtensionString() { dispatcher().glGetIntegerv(GL_MAX_VERTEX_UNITS_OES,&max_vertex_units); if (max_palette_matrices>=32 && max_vertex_units>=4) *s_glExtensions+="GL_OES_extended_matrix_palette "; - } + } } 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 d68375528..f3f4a6aeb 100644 --- a/tools/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmContext.h +++ b/tools/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmContext.h @@ -38,16 +38,19 @@ public: void setClientActiveTexture(GLenum tex); GLenum getActiveTexture() { return GL_TEXTURE0 + m_activeTexture;}; GLenum getClientActiveTexture() { return GL_TEXTURE0 + m_clientActiveTexture;}; - void convertArrs(GLESFloatArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct); - void drawPointsArrs(GLESFloatArrays& arrs,GLint first,GLsizei count); - void drawPointsElems(GLESFloatArrays& arrs,GLsizei count,GLenum type,const GLvoid* indices); - - ~GLEScmContext(); + 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); + ~GLEScmContext(); +protected: + + bool needConvert(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct,GLESpointer* p,GLenum array_id); private: - void sendArr(GLvoid* arr,GLenum arrayType,GLint size,GLsizei stride,int pointsIndex = -1); + void setupArrayPointerHelper(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct,GLenum array_id,GLESpointer* p); + void setupArr(const GLvoid* arr,GLenum arrayType,GLenum dataType,GLint size,GLsizei stride,int pointsIndex = -1); void drawPoints(PointSizeIndices* points); - void drawPointsData(GLESFloatArrays& arrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices_in,bool isElemsDraw); + void drawPointsData(GLESConversionArrays& arrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices_in,bool isElemsDraw); void initExtensionString(); GLESpointer* m_texCoords; 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 e3a32145a..4dc3fa80b 100644 --- a/tools/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmImp.cpp +++ b/tools/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmImp.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include @@ -192,7 +192,7 @@ GL_API GLboolean GL_APIENTRY glIsEnabled( GLenum cap) { GET_CTX_CM_RET(GL_FALSE) RET_AND_SET_ERROR_IF(!GLEScmValidate::capability(cap,ctx->getMaxLights(),ctx->getMaxClipPlanes()),GL_INVALID_ENUM,GL_FALSE); - if (cap == GL_POINT_SIZE_ARRAY_OES) + if (cap == GL_POINT_SIZE_ARRAY_OES) return ctx->isArrEnabled(cap); else if (cap==GL_TEXTURE_GEN_STR_OES) return (ctx->dispatcher().glIsEnabled(GL_TEXTURE_GEN_S) && @@ -396,9 +396,7 @@ GL_API void GL_APIENTRY glColorMask( GLboolean red, GLboolean green, GLboolean GL_API void GL_APIENTRY glColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) { GET_CTX() SET_ERROR_IF(!GLEScmValidate::colorPointerParams(size,stride),GL_INVALID_VALUE); - - const GLvoid* data = ctx->setPointer(GL_COLOR_ARRAY,size,type,stride,pointer); - if(type != GL_FIXED) ctx->dispatcher().glColorPointer(size,type,stride,data); + ctx->setPointer(GL_COLOR_ARRAY,size,type,stride,pointer); } GL_API void GL_APIENTRY glCompressedTexImage2D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data) { @@ -523,8 +521,8 @@ GL_API void GL_APIENTRY glDrawArrays( GLenum mode, GLint first, GLsizei count) if(!ctx->isArrEnabled(GL_VERTEX_ARRAY)) return; - GLESFloatArrays tmpArrs; - ctx->convertArrs(tmpArrs,first,count,0,NULL,true); + GLESConversionArrays tmpArrs; + ctx->setupArraysPointers(tmpArrs,first,count,0,NULL,true); if(mode != GL_POINTS || !ctx->isArrEnabled(GL_POINT_SIZE_ARRAY_OES)){ ctx->dispatcher().glDrawArrays(mode,first,count); } @@ -540,13 +538,13 @@ GL_API void GL_APIENTRY glDrawElements( GLenum mode, GLsizei count, GLenum type if(!ctx->isArrEnabled(GL_VERTEX_ARRAY)) return; const GLvoid* indices = elementsIndices; - GLESFloatArrays tmpArrs; + GLESConversionArrays tmpArrs; if(ctx->isBindedBuffer(GL_ELEMENT_ARRAY_BUFFER)) { // if vbo is binded take the indices from the vbo const unsigned char* buf = static_cast(ctx->getBindedBuffer(GL_ELEMENT_ARRAY_BUFFER)); indices = buf+reinterpret_cast(elementsIndices); } - ctx->convertArrs(tmpArrs,0,count,type,indices,false); + ctx->setupArraysPointers(tmpArrs,0,count,type,indices,false); if(mode != GL_POINTS || !ctx->isArrEnabled(GL_POINT_SIZE_ARRAY_OES)){ ctx->dispatcher().glDrawElements(mode,count,type,indices); } @@ -1161,8 +1159,7 @@ GL_API void GL_APIENTRY glNormal3x( GLfixed nx, GLfixed ny, GLfixed nz) { GL_API void GL_APIENTRY glNormalPointer( GLenum type, GLsizei stride, const GLvoid *pointer) { GET_CTX() SET_ERROR_IF(stride < 0,GL_INVALID_VALUE); - const GLvoid* data = ctx->setPointer(GL_NORMAL_ARRAY,3,type,stride,pointer);//3 normal verctor - if(type != GL_FIXED) ctx->dispatcher().glNormalPointer(type,stride,data); + ctx->setPointer(GL_NORMAL_ARRAY,3,type,stride,pointer);//3 normal verctor } GL_API void GL_APIENTRY glOrthof( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar) { @@ -1306,9 +1303,7 @@ GL_API void GL_APIENTRY glStencilOp( GLenum fail, GLenum zfail, GLenum zpass) { GL_API void GL_APIENTRY glTexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) { GET_CTX() SET_ERROR_IF(!GLEScmValidate::texCoordPointerParams(size,stride),GL_INVALID_VALUE); - - const GLvoid* data = ctx->setPointer(GL_TEXTURE_COORD_ARRAY,size,type,stride,pointer); - if(type != GL_FIXED) ctx->dispatcher().glTexCoordPointer(size,type,stride,data); + ctx->setPointer(GL_TEXTURE_COORD_ARRAY,size,type,stride,pointer); } GL_API void GL_APIENTRY glTexEnvf( GLenum target, GLenum pname, GLfloat param) { @@ -1464,9 +1459,7 @@ GL_API void GL_APIENTRY glTranslatex( GLfixed x, GLfixed y, GLfixed z) { GL_API void GL_APIENTRY glVertexPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) { GET_CTX() SET_ERROR_IF(!GLEScmValidate::vertexPointerParams(size,stride),GL_INVALID_VALUE); - - const GLvoid* data = ctx->setPointer(GL_VERTEX_ARRAY,size,type,stride,pointer); - if(type != GL_FIXED) ctx->dispatcher().glVertexPointer(size,type,stride,data); + ctx->setPointer(GL_VERTEX_ARRAY,size,type,stride,pointer); } GL_API void GL_APIENTRY glViewport( GLint x, GLint y, GLsizei width, GLsizei height) { @@ -1505,21 +1498,21 @@ GL_API void GL_APIENTRY glEGLImageTargetRenderbufferStorageOES(GLenum target, GL { GET_CTX() //not supported by EGL - SET_ERROR_IF(false,GL_INVALID_OPERATION); + SET_ERROR_IF(false,GL_INVALID_OPERATION); } /* GL_OES_blend_subtract*/ GL_API void GL_APIENTRY glBlendEquationOES(GLenum mode) { GET_CTX() SET_ERROR_IF(!(GLEScmValidate::blendEquationMode(mode)), GL_INVALID_ENUM); - ctx->dispatcher().glBlendEquation(mode); + ctx->dispatcher().glBlendEquation(mode); } /* GL_OES_blend_equation_separate */ GL_API void GL_APIENTRY glBlendEquationSeparateOES (GLenum modeRGB, GLenum modeAlpha) { GET_CTX() SET_ERROR_IF(!(GLEScmValidate::blendEquationMode(modeRGB) && GLEScmValidate::blendEquationMode(modeAlpha)), GL_INVALID_ENUM); - ctx->dispatcher().glBlendEquationSeparate(modeRGB,modeAlpha); + ctx->dispatcher().glBlendEquationSeparate(modeRGB,modeAlpha); } /* GL_OES_blend_func_separate */ @@ -1551,7 +1544,7 @@ GL_API void GLAPIENTRY glBindRenderbufferOES(GLenum target, GLuint renderbuffer) } int globalBufferName = thrd->shareGroup->getGlobalName(RENDERBUFFER,renderbuffer); - ctx->dispatcher().glBindRenderbufferEXT(target,globalBufferName); + ctx->dispatcher().glBindRenderbufferEXT(target,globalBufferName); } GL_API void GLAPIENTRY glDeleteRenderbuffersOES(GLsizei n, const GLuint *renderbuffers) { @@ -1584,7 +1577,7 @@ GL_API void GLAPIENTRY glRenderbufferStorageOES(GLenum target, GLenum internalfo } GL_API void GLAPIENTRY glGetRenderbufferParameterivOES(GLenum target, GLenum pname, GLint* params) { - GET_CTX() + GET_CTX() SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION); SET_ERROR_IF(!GLEScmValidate::renderbufferTarget(target) || !GLEScmValidate::renderbufferParams(pname) ,GL_INVALID_ENUM); ctx->dispatcher().glGetRenderbufferParameterivEXT(target,pname,params); @@ -1600,8 +1593,8 @@ GL_API GLboolean GLAPIENTRY glIsFramebufferOES(GLuint framebuffer) { } GL_API void GLAPIENTRY glBindFramebufferOES(GLenum target, GLuint framebuffer) { - GET_CTX() - SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION); + 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)) { thrd->shareGroup->genName(FRAMEBUFFER,framebuffer); @@ -1612,16 +1605,16 @@ GL_API void GLAPIENTRY glBindFramebufferOES(GLenum target, GLuint framebuffer) { GL_API void GLAPIENTRY glDeleteFramebuffersOES(GLsizei n, const GLuint *framebuffers) { 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); for (int i=0;ishareGroup->getGlobalName(FRAMEBUFFER,framebuffers[i]); ctx->dispatcher().glDeleteFramebuffersEXT(1,&globalBufferName); } } -GL_API void GLAPIENTRY glGenFramebuffersOES(GLsizei n, GLuint *framebuffers) { +GL_API void GLAPIENTRY glGenFramebuffersOES(GLsizei n, GLuint *framebuffers) { 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(n<0,GL_INVALID_VALUE); if (thrd->shareGroup.Ptr()) { for (int i=0;igetCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION,0); + GET_CTX_RET(0) + RET_AND_SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION,0); RET_AND_SET_ERROR_IF(!GLEScmValidate::framebufferTarget(target) ,GL_INVALID_ENUM,0); return ctx->dispatcher().glCheckFramebufferStatusEXT(target); } GL_API void GLAPIENTRY glFramebufferTexture2DOES(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) { 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) || !GLEScmValidate::framebufferAttachment(attachment) || !GLEScmValidate::textureTargetEx(textarget),GL_INVALID_ENUM); if (thrd->shareGroup.Ptr() && !thrd->shareGroup->isObject(TEXTURE,texture)) { @@ -1671,14 +1664,14 @@ GL_API void GLAPIENTRY glGetFramebufferAttachmentParameterivOES(GLenum target, G GL_API void GL_APIENTRY glGenerateMipmapOES(GLenum target) { 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::textureTargetLimited(target),GL_INVALID_ENUM); ctx->dispatcher().glGenerateMipmapEXT(target); } GL_API void GL_APIENTRY glCurrentPaletteMatrixOES(GLuint index) { GET_CTX() - SET_ERROR_IF(!(ctx->getCaps()->GL_ARB_MATRIX_PALETTE && ctx->getCaps()->GL_ARB_VERTEX_BLEND),GL_INVALID_OPERATION); + SET_ERROR_IF(!(ctx->getCaps()->GL_ARB_MATRIX_PALETTE && ctx->getCaps()->GL_ARB_VERTEX_BLEND),GL_INVALID_OPERATION); ctx->dispatcher().glCurrentPaletteMatrixARB(index); } @@ -1693,13 +1686,13 @@ GL_API void GL_APIENTRY glLoadPaletteFromModelViewMatrixOES() { GL_API void GL_APIENTRY glMatrixIndexPointerOES(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) { GET_CTX() - SET_ERROR_IF(!(ctx->getCaps()->GL_ARB_MATRIX_PALETTE && ctx->getCaps()->GL_ARB_VERTEX_BLEND),GL_INVALID_OPERATION); + SET_ERROR_IF(!(ctx->getCaps()->GL_ARB_MATRIX_PALETTE && ctx->getCaps()->GL_ARB_VERTEX_BLEND),GL_INVALID_OPERATION); ctx->dispatcher().glMatrixIndexPointerARB(size,type,stride,pointer); } GL_API void GL_APIENTRY glWeightPointerOES(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) { GET_CTX() - SET_ERROR_IF(!(ctx->getCaps()->GL_ARB_MATRIX_PALETTE && ctx->getCaps()->GL_ARB_VERTEX_BLEND),GL_INVALID_OPERATION); + SET_ERROR_IF(!(ctx->getCaps()->GL_ARB_MATRIX_PALETTE && ctx->getCaps()->GL_ARB_VERTEX_BLEND),GL_INVALID_OPERATION); ctx->dispatcher().glWeightPointerARB(size,type,stride,pointer); } @@ -1710,7 +1703,7 @@ GL_API void GL_APIENTRY glTexGenfOES (GLenum coord, GLenum pname, GLfloat param) if (coord == GL_TEXTURE_GEN_STR_OES) { ctx->dispatcher().glTexGenf(GL_TEXTURE_GEN_S,pname,param); ctx->dispatcher().glTexGenf(GL_TEXTURE_GEN_T,pname,param); - ctx->dispatcher().glTexGenf(GL_TEXTURE_GEN_R,pname,param); + ctx->dispatcher().glTexGenf(GL_TEXTURE_GEN_R,pname,param); } else ctx->dispatcher().glTexGenf(coord,pname,param); @@ -1733,7 +1726,7 @@ GL_API void GL_APIENTRY glTexGeniOES (GLenum coord, GLenum pname, GLint param) { if (coord == GL_TEXTURE_GEN_STR_OES) { ctx->dispatcher().glTexGeni(GL_TEXTURE_GEN_S,pname,param); ctx->dispatcher().glTexGeni(GL_TEXTURE_GEN_T,pname,param); - ctx->dispatcher().glTexGeni(GL_TEXTURE_GEN_R,pname,param); + ctx->dispatcher().glTexGeni(GL_TEXTURE_GEN_R,pname,param); } else ctx->dispatcher().glTexGeni(coord,pname,param); @@ -1744,7 +1737,7 @@ GL_API void GL_APIENTRY glTexGenivOES (GLenum coord, GLenum pname, const GLint * if (coord == GL_TEXTURE_GEN_STR_OES) { ctx->dispatcher().glTexGeniv(GL_TEXTURE_GEN_S,pname,params); ctx->dispatcher().glTexGeniv(GL_TEXTURE_GEN_T,pname,params); - ctx->dispatcher().glTexGeniv(GL_TEXTURE_GEN_R,pname,params); + ctx->dispatcher().glTexGeniv(GL_TEXTURE_GEN_R,pname,params); } else ctx->dispatcher().glTexGeniv(coord,pname,params); @@ -1755,7 +1748,7 @@ GL_API void GL_APIENTRY glTexGenxOES (GLenum coord, GLenum pname, GLfixed param) if (coord == GL_TEXTURE_GEN_STR_OES) { ctx->dispatcher().glTexGenf(GL_TEXTURE_GEN_S,pname,X2F(param)); ctx->dispatcher().glTexGenf(GL_TEXTURE_GEN_T,pname,X2F(param)); - ctx->dispatcher().glTexGenf(GL_TEXTURE_GEN_R,pname,X2F(param)); + ctx->dispatcher().glTexGenf(GL_TEXTURE_GEN_R,pname,X2F(param)); } else ctx->dispatcher().glTexGenf(coord,pname,X2F(param)); @@ -1768,7 +1761,7 @@ GL_API void GL_APIENTRY glTexGenxvOES (GLenum coord, GLenum pname, const GLfixed if (coord == GL_TEXTURE_GEN_STR_OES) { ctx->dispatcher().glTexGenfv(GL_TEXTURE_GEN_S,pname,tmpParams); ctx->dispatcher().glTexGenfv(GL_TEXTURE_GEN_T,pname,tmpParams); - ctx->dispatcher().glTexGenfv(GL_TEXTURE_GEN_R,pname,tmpParams); + ctx->dispatcher().glTexGenfv(GL_TEXTURE_GEN_R,pname,tmpParams); } else ctx->dispatcher().glTexGenfv(coord,pname,tmpParams); @@ -1886,7 +1879,7 @@ void glDrawTexOES (T x, T y, T z, T width, T height) { texels[i][4] = (float)(texData->crop_rect[2]+texData->crop_rect[0])/(float)(texData->width); texels[i][5] = (float)(texData->crop_rect[3]+texData->crop_rect[1])/(float)(texData->height); - + texels[i][6] = (float)(texData->crop_rect[2]+texData->crop_rect[0])/(float)(texData->width); texels[i][7] = (float)(texData->crop_rect[1])/(float)(texData->height); @@ -1934,18 +1927,18 @@ GL_API void GL_APIENTRY glDrawTexxOES (GLfixed x, GLfixed y, GLfixed z, GLfixed glDrawTexOES(X2F(x),X2F(y),X2F(z),X2F(width),X2F(height)); } -GL_API void GL_APIENTRY glDrawTexsvOES (const GLshort * coords) { +GL_API void GL_APIENTRY glDrawTexsvOES (const GLshort * coords) { glDrawTexOES(coords[0],coords[1],coords[2],coords[3],coords[4]); } -GL_API void GL_APIENTRY glDrawTexivOES (const GLint * coords) { +GL_API void GL_APIENTRY glDrawTexivOES (const GLint * coords) { glDrawTexOES(coords[0],coords[1],coords[2],coords[3],coords[4]); } -GL_API void GL_APIENTRY glDrawTexfvOES (const GLfloat * coords) { +GL_API void GL_APIENTRY glDrawTexfvOES (const GLfloat * coords) { glDrawTexOES(coords[0],coords[1],coords[2],coords[3],coords[4]); } -GL_API void GL_APIENTRY glDrawTexxvOES (const GLfixed * coords) { +GL_API void GL_APIENTRY glDrawTexxvOES (const GLfixed * coords) { glDrawTexOES(X2F(coords[0]),X2F(coords[1]),X2F(coords[2]),X2F(coords[3]),X2F(coords[4])); } 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 ffd791a90..24dfe1b13 100644 --- a/tools/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Context.cpp +++ b/tools/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Context.cpp @@ -34,28 +34,67 @@ void GLESv2Context::init() { GLESv2Context::GLESv2Context():GLEScontext(){}; -void GLESv2Context::convertArrs(GLESFloatArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct) { +void GLESv2Context::setupArraysPointers(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct) { ArraysMap::iterator it; - unsigned int index = 0; //going over all clients arrays Pointers for ( it=m_map.begin() ; it != m_map.end(); it++ ) { GLenum array_id = (*it).first; GLESpointer* p = (*it).second; + if(!isArrEnabled(array_id)) continue; - chooseConvertMethod(fArrs,first,count,type,indices,direct,p,array_id,index); + unsigned int size = p->getSize(); + bool usingVBO = p->isVBO(); + + if(needConvert(fArrs,first,count,type,indices,direct,p,array_id)){ + //conversion has occured + unsigned int convertedStride = usingVBO ? p->getStride() : 0; + const void* data = usingVBO ? p->getBufferData() : fArrs.getCurrentData(); + setupArr(data,array_id,GL_FLOAT,size,convertedStride); + ++fArrs; + } else { + const void* data = usingVBO ? p->getBufferData() : p->getArrayData(); + setupArr(data,array_id,p->getType(),size,p->getStride()); + } } } -//sending data to server side -void GLESv2Context::sendArr(GLvoid* arr,GLenum arrayType,GLint size,GLsizei stride,int index) { - s_glDispatch.glVertexAttribPointer(arrayType,size,GL_FLOAT,GL_FALSE,stride,arr); +//setting client side arr +void GLESv2Context::setupArr(const GLvoid* arr,GLenum arrayType,GLenum dataType,GLint size,GLsizei stride,int index){ + if(arr == NULL) return; + s_glDispatch.glVertexAttribPointer(arrayType,size,dataType,GL_FALSE,stride,arr); +} + +bool GLESv2Context::needConvert(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct,GLESpointer* p,GLenum array_id) { + + bool usingVBO = p->isVBO(); + GLenum arrType = p->getType(); + /* + conversion is not necessary in the following cases: + (*) array type is not fixed + */ + if(arrType != GL_FIXED) return false; + + if(!usingVBO) { + if (direct) { + convertDirect(fArrs,first,count,array_id,p); + } else { + convertIndirect(fArrs,count,type,indices,array_id,p); + } + } else { + if (direct) { + convertDirectVBO(first,count,array_id,p) ; + } else { + convertIndirectVBO(count,type,indices,array_id,p); + } + } + return true; } void GLESv2Context::initExtensionString() { *s_glExtensions = "GL_OES_EGL_image GL_OES_depth24 GL_OES_depth32 GL_OES_element_index_uint " "GL_OES_standard_derivatives GL_OES_texture_float GL_OES_texture_float_linear "; - if (s_glSupport.GL_ARB_HALF_FLOAT_PIXEL || s_glSupport.GL_NV_HALF_FLOAT) + if (s_glSupport.GL_ARB_HALF_FLOAT_PIXEL || s_glSupport.GL_NV_HALF_FLOAT) *s_glExtensions+="GL_OES_texture_half_float GL_OES_texture_half_float_linear "; if (s_glSupport.GL_NV_PACKED_DEPTH_STENCIL) *s_glExtensions+="GL_OES_packed_depth_stencil "; 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 5bee0797b..5f4fa23d2 100644 --- a/tools/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Context.h +++ b/tools/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Context.h @@ -28,9 +28,11 @@ class GLESv2Context : public GLEScontext{ public: void init(); GLESv2Context(); - void convertArrs(GLESFloatArrays& 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); +protected: + bool needConvert(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct,GLESpointer* p,GLenum array_id); private: - void sendArr(GLvoid* arr,GLenum arrayType,GLint size,GLsizei stride,int pointsIndex = -1); + void setupArr(const GLvoid* arr,GLenum arrayType,GLenum dataType,GLint size,GLsizei stride,int pointsIndex = -1); void initExtensionString(); }; 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 7e2141c5e..39803a509 100644 --- a/tools/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp +++ b/tools/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp @@ -440,8 +440,8 @@ GL_APICALL void GL_APIENTRY glDrawArrays(GLenum mode, GLint first, GLsizei coun //if no vertex are enabled no need to convert anything if(!ctx->isArrEnabled(0)) return; - GLESFloatArrays tmpArrs; - ctx->convertArrs(tmpArrs,first,count,0,NULL,true); + GLESConversionArrays tmpArrs; + ctx->setupArraysPointers(tmpArrs,first,count,0,NULL,true); ctx->dispatcher().glDrawArrays(mode,first,count); } @@ -459,8 +459,8 @@ GL_APICALL void GL_APIENTRY glDrawElements(GLenum mode, GLsizei count, GLenum t //if no vertex are enabled no need to convert anything if(!ctx->isArrEnabled(0)) return; - GLESFloatArrays tmpArrs; - ctx->convertArrs(tmpArrs,0,count,type,indices,false); + GLESConversionArrays tmpArrs; + ctx->setupArraysPointers(tmpArrs,0,count,type,indices,false); ctx->dispatcher().glDrawElements(mode,count,type,indices); } @@ -848,8 +848,8 @@ 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); - + SET_ERROR_IF(pname != GL_VERTEX_ATTRIB_ARRAY_POINTER,GL_INVALID_ENUM); + const GLESpointer* p = ctx->getPointer(pname); if(p) { *pointer = const_cast( p->getBufferData()); @@ -1248,10 +1248,8 @@ GL_APICALL void GL_APIENTRY glVertexAttrib4fv(GLuint indx, const GLfloat* value GL_APICALL void GL_APIENTRY glVertexAttribPointer(GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr){ GET_CTX(); - if (type==GL_HALF_FLOAT_OES) - type = GL_HALF_FLOAT; - const GLvoid* data = ctx->setPointer(indx,size,type,stride,ptr); - if(type != GL_FIXED) ctx->dispatcher().glVertexAttribPointer(indx,size,type,normalized,stride,data); + if (type == GL_HALF_FLOAT_OES) type = GL_HALF_FLOAT; + ctx->setPointer(indx,size,type,stride,ptr,normalized); } GL_APICALL void GL_APIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height){ diff --git a/tools/emulator/opengl/host/libs/Translator/GLcommon/GLEScontext.cpp b/tools/emulator/opengl/host/libs/Translator/GLcommon/GLEScontext.cpp index 93818feae..66948bc99 100644 --- a/tools/emulator/opengl/host/libs/Translator/GLcommon/GLEScontext.cpp +++ b/tools/emulator/opengl/host/libs/Translator/GLcommon/GLEScontext.cpp @@ -1,22 +1,53 @@ #include -#include +#include #include #include //decleration static int findMaxIndex(GLsizei count,GLenum type,const GLvoid* indices); -static void convertDirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,unsigned int nBytes,unsigned int strideOut,int attribSize); -static void convertIndirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,GLsizei count,GLenum indices_type,const GLvoid* indices,unsigned int strideOut,int attribSize); +static void convertFixedDirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,unsigned int nBytes,unsigned int strideOut,int attribSize); +static void convertFixedIndirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,GLsizei count,GLenum indices_type,const GLvoid* indices,unsigned int strideOut,int attribSize); +static void convertByteDirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,unsigned int nBytes,unsigned int strideOut,int attribSize); +static void convertByteIndirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,GLsizei count,GLenum indices_type,const GLvoid* indices,unsigned int strideOut,int attribSize); -GLESFloatArrays::~GLESFloatArrays() { - for(std::map::iterator it = arrays.begin(); it != arrays.end();it++) { - GLfloat* p = (*it).second; - if(p) { - delete[] p; +GLESConversionArrays::~GLESConversionArrays() { + for(std::map >::iterator it = m_arrays.begin(); it != m_arrays.end();it++) { + if((*it).second.first == GL_FLOAT){ + GLfloat* p = (GLfloat *)((*it).second.second); + if(p) delete[] p; + } else if((*it).second.first == GL_SHORT){ + GLshort* p = (GLshort *)((*it).second.second); + if(p) delete[] p; } } } +void GLESConversionArrays::alloc(unsigned int size,GLenum type){ + if(type == GL_FIXED){ + m_arrays[m_current].second = new GLfloat[size]; + m_arrays[m_current].first = GL_FLOAT; + } else if(type == GL_BYTE){ + m_arrays[m_current].second = new GLshort[size]; + m_arrays[m_current].first = GL_SHORT; + } +} + +void* GLESConversionArrays::getCurrentData(){ + return m_arrays[m_current].second; +} + +unsigned int GLESConversionArrays::getCurrentIndex(){ + return m_current; +} + +void* GLESConversionArrays::operator[](int i){ + return m_arrays[i].second; +} + +void GLESConversionArrays::operator++(){ + m_current++; +} + GLDispatch GLEScontext::s_glDispatch; android::Mutex GLEScontext::s_lock; std::string* GLEScontext::s_glExtensions= NULL; @@ -36,10 +67,10 @@ Version::Version(const Version& ver):m_major(ver.m_major), Version::Version(const char* versionString){ m_release = 0; - if((!versionString) || - ((!(sscanf(versionString,"%d.%d" ,&m_major,&m_minor) == 2)) && + if((!versionString) || + ((!(sscanf(versionString,"%d.%d" ,&m_major,&m_minor) == 2)) && (!(sscanf(versionString,"%d.%d.%d",&m_major,&m_minor,&m_release) == 3)))){ - m_major = m_minor = 0; // the version is not in the right format + m_major = m_minor = 0; // the version is not in the right format } } @@ -71,7 +102,7 @@ GLEScontext::GLEScontext(): m_tex2DBind[i].texture = 0; for (int j=0;j(&static_cast(dataOut)[i])[j] = B2S(byte_data[j]); + } + dataIn += strideIn; + } +} + +static void convertByteIndirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,GLsizei count,GLenum indices_type,const GLvoid* indices,unsigned int strideOut,int attribSize) { + for(int i = 0 ;i < count ;i++) { + unsigned short index = indices_type == GL_UNSIGNED_BYTE? ((GLubyte *)indices)[i]: + ((GLushort *)indices)[i]; + const GLbyte* bytes_data = (GLbyte *)(dataIn + index*strideIn); + GLshort* short_data = reinterpret_cast(static_cast(dataOut) + index*strideOut); + + for(int j=0;jgetSize()*4; //4 is the sizeof GLfixed or GLfloat in bytes @@ -200,46 +255,46 @@ int bytesRangesToIndices(RangeList& ranges,GLESpointer* p,GLushort* indices) { } return n; } -void GLEScontext::convertDirect(GLESFloatArrays& fArrs,GLint first,GLsizei count,GLenum array_id,GLESpointer* p,unsigned int& index) { - GLenum type = p->getType(); - if(isArrEnabled(array_id) && type == GL_FIXED) { - int attribSize = p->getSize(); - unsigned int size = attribSize*count + first; - fArrs.arrays[index] = new GLfloat[size]; - int stride = p->getStride()?p->getStride():sizeof(GLfixed)*attribSize; - const char* data = (const char*)p->getArrayData() + (first*stride); - convertDirectLoop(data,stride,fArrs.arrays[index],size*sizeof(GLfloat),attribSize*sizeof(GLfloat),attribSize); - sendArr(fArrs.arrays[index],array_id,attribSize,0,index); - index++; +void GLEScontext::convertDirect(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum array_id,GLESpointer* p) { + + GLenum type = p->getType(); + int attribSize = p->getSize(); + unsigned int size = attribSize*count + first; + unsigned int bytes = type == GL_FIXED ? sizeof(GLfixed):sizeof(GLbyte); + fArrs.alloc(size,type); + int stride = p->getStride()?p->getStride():bytes*attribSize; + const char* data = (const char*)p->getArrayData() + (first*stride); + + if(type == GL_FIXED) { + convertFixedDirectLoop(data,stride,fArrs.getCurrentData(),size*sizeof(GLfloat),attribSize*sizeof(GLfloat),attribSize); + } else if(type == GL_BYTE) { + convertByteDirectLoop(data,stride,fArrs.getCurrentData(),size*sizeof(GLshort),attribSize*sizeof(GLshort),attribSize); } } void GLEScontext::convertDirectVBO(GLint first,GLsizei count,GLenum array_id,GLESpointer* p) { + + RangeList ranges; + RangeList conversions; + GLushort* indices = NULL; GLenum type = p->getType(); - if(isArrEnabled(array_id) && type == GL_FIXED) { - RangeList ranges; - RangeList conversions; - GLushort* indices = NULL; - int attribSize = p->getSize(); - int stride = p->getStride()?p->getStride():sizeof(GLfixed)*attribSize; - unsigned int size = p->getStride()?p->getStride()*count:attribSize*count*sizeof(GLfixed); - char* data = (char*)p->getBufferData() + (first*stride); + int attribSize = p->getSize(); + int stride = p->getStride()?p->getStride():sizeof(GLfixed)*attribSize; + unsigned int size = p->getStride()?p->getStride()*count:attribSize*count*sizeof(GLfixed); + char* data = (char*)p->getBufferData() + (first*stride); - if(p->bufferNeedConversion()) { - directToBytesRanges(first,count,p,ranges); //converting indices range to buffer bytes ranges by offset - p->getBufferConversions(ranges,conversions); // getting from the buffer the relevant ranges that still needs to be converted + if(p->bufferNeedConversion()) { + directToBytesRanges(first,count,p,ranges); //converting indices range to buffer bytes ranges by offset + p->getBufferConversions(ranges,conversions); // getting from the buffer the relevant ranges that still needs to be converted - if(conversions.size()) { // there are some elements to convert - indices = new GLushort[count]; - int nIndices = bytesRangesToIndices(conversions,p,indices); //converting bytes ranges by offset to indices in this array - convertIndirectLoop(data,stride,data,nIndices,GL_UNSIGNED_SHORT,indices,stride,attribSize); - } + if(conversions.size()) { // there are some elements to convert + indices = new GLushort[count]; + int nIndices = bytesRangesToIndices(conversions,p,indices); //converting bytes ranges by offset to indices in this array + convertFixedIndirectLoop(data,stride,data,nIndices,GL_UNSIGNED_SHORT,indices,stride,attribSize); } - - sendArr(data,array_id,attribSize,p->getStride()); - if(indices) delete[] indices; } + if(indices) delete[] indices; } static int findMaxIndex(GLsizei count,GLenum type,const GLvoid* indices) { @@ -259,66 +314,46 @@ static int findMaxIndex(GLsizei count,GLenum type,const GLvoid* indices) { return max; } -void GLEScontext::convertIndirect(GLESFloatArrays& fArrs,GLsizei count,GLenum indices_type,const GLvoid* indices,GLenum array_id,GLESpointer* p,unsigned int& index_out) { +void GLEScontext::convertIndirect(GLESConversionArrays& fArrs,GLsizei count,GLenum indices_type,const GLvoid* indices,GLenum array_id,GLESpointer* p) { GLenum type = p->getType(); int maxElements = findMaxIndex(count,type,indices) + 1; - if(isArrEnabled(array_id) && type == GL_FIXED) { - int attribSize = p->getSize(); - int size = attribSize * maxElements; - fArrs.arrays[index_out] = new GLfloat[size]; - int stride = p->getStride()?p->getStride():sizeof(GLfixed)*attribSize; + int attribSize = p->getSize(); + int size = attribSize * maxElements; + unsigned int bytes = type == GL_FIXED ? sizeof(GLfixed):sizeof(GLbyte); + fArrs.alloc(size,type); + int stride = p->getStride()?p->getStride():bytes*attribSize; - const char* data = (const char*)p->getArrayData(); - convertIndirectLoop(data,stride,fArrs.arrays[index_out],count,indices_type,indices,attribSize*sizeof(GLfloat),attribSize); - sendArr(fArrs.arrays[index_out],array_id,attribSize,0,index_out); - index_out++; + const char* data = (const char*)p->getArrayData(); + if(type == GL_FIXED) { + convertFixedIndirectLoop(data,stride,fArrs.getCurrentData(),count,indices_type,indices,attribSize*sizeof(GLfloat),attribSize); + } else if(type == GL_BYTE){ + convertByteIndirectLoop(data,stride,fArrs.getCurrentData(),count,indices_type,indices,attribSize*sizeof(GLshort),attribSize); } } void GLEScontext::convertIndirectVBO(GLsizei count,GLenum indices_type,const GLvoid* indices,GLenum array_id,GLESpointer* p) { + RangeList ranges; + RangeList conversions; + GLushort* conversionIndices = NULL; GLenum type = p->getType(); - - if(isArrEnabled(array_id) && type == GL_FIXED) { - RangeList ranges; - RangeList conversions; - GLushort* conversionIndices = NULL; - int attribSize = p->getSize(); - int stride = p->getStride()?p->getStride():sizeof(GLfixed)*attribSize; - char* data = static_cast(p->getBufferData()); - if(p->bufferNeedConversion()) { - indirectToBytesRanges(indices,indices_type,count,p,ranges); //converting indices range to buffer bytes ranges by offset - p->getBufferConversions(ranges,conversions); // getting from the buffer the relevant ranges that still needs to be converted - if(conversions.size()) { // there are some elements to convert - conversionIndices = new GLushort[count]; - int nIndices = bytesRangesToIndices(conversions,p,conversionIndices); //converting bytes ranges by offset to indices in this array - convertIndirectLoop(data,stride,data,nIndices,GL_UNSIGNED_SHORT,conversionIndices,stride,attribSize); - } - } - sendArr(data,array_id,attribSize,p->getStride()); - if(conversionIndices) delete[] conversionIndices; - } -} - -void GLEScontext::chooseConvertMethod(GLESFloatArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct,GLESpointer* p,GLenum array_id, unsigned int& index) { - - bool vertexVBO = m_arrayBuffer!= 0; - if(direct) { - if(vertexVBO) { - convertDirectVBO(first,count,array_id,p); - } else { - convertDirect(fArrs,first,count,array_id,p,index); - } - } else { - if(vertexVBO) { - convertIndirectVBO(count,type,indices,array_id,p); - } else { - convertIndirect(fArrs,count,type,indices,array_id,p,index); + int attribSize = p->getSize(); + int stride = p->getStride()?p->getStride():sizeof(GLfixed)*attribSize; + char* data = static_cast(p->getBufferData()); + if(p->bufferNeedConversion()) { + indirectToBytesRanges(indices,indices_type,count,p,ranges); //converting indices range to buffer bytes ranges by offset + p->getBufferConversions(ranges,conversions); // getting from the buffer the relevant ranges that still needs to be converted + if(conversions.size()) { // there are some elements to convert + conversionIndices = new GLushort[count]; + int nIndices = bytesRangesToIndices(conversions,p,conversionIndices); //converting bytes ranges by offset to indices in this array + convertFixedIndirectLoop(data,stride,data,nIndices,GL_UNSIGNED_SHORT,conversionIndices,stride,attribSize); } } + if(conversionIndices) delete[] conversionIndices; } + void GLEScontext::bindBuffer(GLenum target,GLuint buffer) { if(target == GL_ARRAY_BUFFER) { m_arrayBuffer = buffer; @@ -386,12 +421,12 @@ bool GLEScontext::setBufferSubData(GLenum target,GLintptr offset,GLsizeiptr size return vbo->setSubBuffer(offset,size,data); } -const char * GLEScontext::getExtensionString() { +const char * GLEScontext::getExtensionString() { const char * ret; s_lock.lock(); if (s_glExtensions) ret = s_glExtensions->c_str(); - else + else ret=""; s_lock.unlock(); return ret; @@ -409,7 +444,7 @@ void GLEScontext::releaseGlobalLock() { 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_CLIP_PLANES,&s_glSupport.maxClipPlane); diff --git a/tools/emulator/opengl/host/libs/Translator/GLcommon/GLESpointer.cpp b/tools/emulator/opengl/host/libs/Translator/GLcommon/GLESpointer.cpp index d297a7cb2..05cd96723 100644 --- a/tools/emulator/opengl/host/libs/Translator/GLcommon/GLESpointer.cpp +++ b/tools/emulator/opengl/host/libs/Translator/GLcommon/GLESpointer.cpp @@ -23,7 +23,8 @@ GLESpointer::GLESpointer():m_size(0), m_normalize(false), m_data(NULL), m_buffer(NULL), - m_buffOffset(0){}; + m_buffOffset(0), + m_isVBO(false){}; GLenum GLESpointer:: getType() const { @@ -44,7 +45,11 @@ const GLvoid* GLESpointer::getArrayData() const { GLvoid* GLESpointer::getBufferData() const { - return static_cast(m_buffer->getData()) + m_buffOffset; + return m_buffer ? static_cast(m_buffer->getData()) + m_buffOffset : NULL; +} + +void GLESpointer::redirectPointerData(){ + m_data = getBufferData(); } unsigned int GLESpointer::getBufferOffset() const { @@ -60,6 +65,10 @@ bool GLESpointer::isNormalize() const { return m_normalize; } +bool GLESpointer::isVBO() const { + return m_isVBO; +} + void GLESpointer::enable(bool b) { m_enabled = b; } @@ -71,6 +80,7 @@ void GLESpointer::setArray(GLint size,GLenum type,GLsizei stride,const GLvoid* d m_data = data; m_buffer = NULL; m_normalize = normalize; + m_isVBO = false; } void GLESpointer::setBuffer(GLint size,GLenum type,GLsizei stride,GLESbuffer* buf,int offset,bool normalize) { @@ -81,6 +91,7 @@ void GLESpointer::setBuffer(GLint size,GLenum type,GLsizei stride,GLESbuffer* bu m_buffer = buf; m_buffOffset = offset; m_normalize = normalize; + m_isVBO = true; } void GLESpointer::getBufferConversions(const RangeList& rl,RangeList& rlOut) { 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 af2d39a82..3b2937ad2 100644 --- a/tools/emulator/opengl/host/libs/Translator/include/GLcommon/GLEScontext.h +++ b/tools/emulator/opengl/host/libs/Translator/include/GLcommon/GLEScontext.h @@ -6,6 +6,7 @@ #include "objectNameManager.h" #include #include +#include #define MAX_TEX_UNITS 8 @@ -61,11 +62,20 @@ struct GLSupport { }; -struct GLESFloatArrays +class GLESConversionArrays { - GLESFloatArrays(){}; - ~GLESFloatArrays(); - std::map arrays; +public: + GLESConversionArrays():m_current(0){}; + void alloc(unsigned int size,GLenum type); + void* operator[](int i); + void* getCurrentData(); + unsigned int getCurrentIndex(); + void operator++(); + + ~GLESConversionArrays(); +private: + std::map > m_arrays; + unsigned int m_current; }; class GLEScontext{ @@ -86,7 +96,7 @@ public: void enableArr(GLenum arr,bool enable); const GLvoid* setPointer(GLenum arrType,GLint size,GLenum type,GLsizei stride,const GLvoid* data,bool normalize = false); const GLESpointer* getPointer(GLenum arrType); - virtual void convertArrs(GLESFloatArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct) = 0; + virtual void setupArraysPointers(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct) = 0; void bindBuffer(GLenum target,GLuint buffer); void unbindBuffer(GLuint buffer); bool isBuffer(GLuint buffer); @@ -112,7 +122,11 @@ public: protected: - void chooseConvertMethod(GLESFloatArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct,GLESpointer* p,GLenum array_id,unsigned int& index); + virtual bool needConvert(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct,GLESpointer* p,GLenum array_id) = 0; + void convertDirect(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum array_id,GLESpointer* p); + void convertDirectVBO(GLint first,GLsizei count,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 initCapsLocked(const GLubyte * extensionString); static android::Mutex s_lock; static GLDispatch s_glDispatch; @@ -124,12 +138,8 @@ protected: private: - virtual void sendArr(GLvoid* arr,GLenum arrayType,GLint size,GLsizei stride,int pointsIndex = -1) = 0 ; + virtual void setupArr(const GLvoid* arr,GLenum arrayType,GLenum dataType,GLint size,GLsizei stride,int pointsIndex = -1) = 0 ; GLuint getBuffer(GLenum target); - void convertDirect(GLESFloatArrays& fArrs,GLint first,GLsizei count,GLenum array_id,GLESpointer* p,unsigned int& index); - void convertDirectVBO(GLint first,GLsizei count,GLenum array_id,GLESpointer* p); - void convertIndirect(GLESFloatArrays& fArrs,GLsizei count,GLenum type,const GLvoid* indices,GLenum array_id,GLESpointer* p,unsigned int& index); - void convertIndirectVBO(GLsizei count,GLenum indices_type,const GLvoid* indices,GLenum array_id,GLESpointer* p); ShareGroupPtr m_shareGroup; GLenum m_glError; diff --git a/tools/emulator/opengl/host/libs/Translator/include/GLcommon/GLESpointer.h b/tools/emulator/opengl/host/libs/Translator/include/GLcommon/GLESpointer.h index c17be74a1..d5d6b1cb0 100644 --- a/tools/emulator/opengl/host/libs/Translator/include/GLcommon/GLESpointer.h +++ b/tools/emulator/opengl/host/libs/Translator/include/GLcommon/GLESpointer.h @@ -30,12 +30,14 @@ public: const GLvoid* getArrayData() const; GLvoid* getBufferData() const; unsigned int getBufferOffset() const; + void redirectPointerData(); void getBufferConversions(const RangeList& rl,RangeList& rlOut); bool bufferNeedConversion(){ return !m_buffer->fullyConverted();} void setArray (GLint size,GLenum type,GLsizei stride,const GLvoid* data,bool normalize = false); void setBuffer(GLint size,GLenum type,GLsizei stride,GLESbuffer* buf,int offset,bool normalize = false); bool isEnable() const; bool isNormalize() const; + bool isVBO() const; void enable(bool b); private: @@ -47,5 +49,6 @@ private: const GLvoid* m_data; GLESbuffer* m_buffer; unsigned int m_buffOffset; + bool m_isVBO; }; #endif diff --git a/tools/emulator/opengl/host/libs/Translator/include/GLcommon/GLfixed_ops.h b/tools/emulator/opengl/host/libs/Translator/include/GLcommon/GLconversion_macros.h similarity index 84% rename from tools/emulator/opengl/host/libs/Translator/include/GLcommon/GLfixed_ops.h rename to tools/emulator/opengl/host/libs/Translator/include/GLcommon/GLconversion_macros.h index 0cf6566a5..83e99b46c 100644 --- a/tools/emulator/opengl/host/libs/Translator/include/GLcommon/GLfixed_ops.h +++ b/tools/emulator/opengl/host/libs/Translator/include/GLcommon/GLconversion_macros.h @@ -16,9 +16,10 @@ #ifndef _GL_FIXED_OPS_H #define _GL_FIXED_OPS_H -#define X2F(x) (((float)(x))/65536.0f) -#define X2D(x) (((double)(x))/65536.0) -#define X2I(x) ((x) /65536) +#define X2F(x) (((float)(x))/65536.0f) +#define X2D(x) (((double)(x))/65536.0) +#define X2I(x) ((x) /65536) +#define B2S(x) ((short)x) #define F2X(d) ((d) > 32767.65535 ? 32767 * 65536 + 65535 : \ diff --git a/tools/emulator/opengl/tests/translator_tests/GLES_CM/triangleCM.cpp b/tools/emulator/opengl/tests/translator_tests/GLES_CM/triangleCM.cpp index 56922c822..7d681ad89 100644 --- a/tools/emulator/opengl/tests/translator_tests/GLES_CM/triangleCM.cpp +++ b/tools/emulator/opengl/tests/translator_tests/GLES_CM/triangleCM.cpp @@ -45,6 +45,7 @@ unsigned char *genTexture(int width, int height, int comp) for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { unsigned char col = ((i / 8 + j / 8) % 2) * 255 ; + if (j>(width/2)) col/=2; for (int c = 0; c < comp; c++) { *ptr = col; ptr++; } @@ -99,6 +100,17 @@ void usage(const char *progname) fprintf(stderr, "\t-p: use point size OES extention\n"); } +#define SWITCH_SOURCE(add)\ + if(useConvertedType){ \ + if(useFixed){ \ + data = (GLvoid*)(fixedVertices+(add)); \ + } else { \ + data = (GLvoid*)(byteVertices +(add)); \ + } \ + } else { \ + data = (GLvoid*)(afVertices+(add)); \ + } \ + #ifdef _WIN32 int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) #else @@ -110,12 +122,13 @@ int main(int argc, char **argv) GLuint ui32Texture; int nframes = 100; - bool immidateMode = true; - bool useIndices = false; + bool immidateMode = false; + bool useIndices = true; bool useTexture = false; bool useCompTexture = false; + bool useConvertedType = true; bool useFixed = false; - bool usePoints = true; + bool usePoints = false; bool useCopy = false; bool useSubCopy = false; @@ -248,6 +261,26 @@ int main(int argc, char **argv) 14.0f }; +#define MAX_T 1 +#define MID_T 0 +#define MIN_T 0 + + GLbyte byteVertices[] = { -1,-1,0, // Position + 255,0,0,255, // Color + MIN_T, MIN_T, // texture + 12, //point size + + 1,-1,0, + 0,255,0,255, + MAX_T,MIN_T, + 47, + + 0,1,0, + 0,0,255,255, + MID_T, MAX_T, + 14 + }; + GLfixed fixedVertices[] = { F_to_X(-0.4f),F_to_X(-0.4f),F_to_X(0.0f), // Position F_to_X(1.0f),F_to_X(0.0f),F_to_X(0.0f),F_to_X(1.0f), // Color F_to_X(0.0f),F_to_X(0.0f), // texture @@ -272,8 +305,17 @@ int main(int argc, char **argv) printf("ui32Vbo = %d\n", ui32Vbo); glBindBuffer(GL_ARRAY_BUFFER, ui32Vbo); - unsigned int uiSize = 3 * (sizeof(float) * 10); - glBufferData(GL_ARRAY_BUFFER, uiSize, useFixed?(void *)fixedVertices:(void*)afVertices, GL_STATIC_DRAW); + void* data = (void*)afVertices; + unsigned int uiSize = 3*(sizeof(float)*10); + if(useConvertedType){ + if(useFixed){ + data = (void*)fixedVertices; + } else { + data = (void*)byteVertices; + uiSize = 3*(sizeof(GLbyte)*10); + } + } + glBufferData(GL_ARRAY_BUFFER, uiSize,data, GL_STATIC_DRAW); ui32IndexVbo = 2; glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ui32IndexVbo); @@ -290,18 +332,24 @@ int main(int argc, char **argv) GLvoid* arr = NULL; GLenum type; GLenum drawType; + GLenum colorType; int size_of; - if(useFixed) - { - arr = fixedVertices; - type = GL_FIXED; - size_of = sizeof(GLfixed); - } - else - { + if(useConvertedType){ + if(useFixed) + { + arr = fixedVertices; + colorType = type = GL_FIXED; + size_of = sizeof(GLfixed); + } else { + arr = byteVertices; + colorType = GL_UNSIGNED_BYTE; + type = GL_BYTE; + size_of = sizeof(GLbyte); + } + }else { arr = afVertices; - type = GL_FLOAT; + colorType = type = GL_FLOAT; size_of = sizeof(float); } @@ -312,7 +360,8 @@ int main(int argc, char **argv) else drawType = GL_TRIANGLES; - for (int i = 0; i < 10000; i++) { + GLvoid* data = NULL; + for (int i = 0; i < 100; i++) { glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); @@ -329,14 +378,16 @@ int main(int argc, char **argv) // Set color data in the same way glEnableClientState(GL_COLOR_ARRAY); if (immidateMode) { - glColorPointer(4, type, size_of * 10, useFixed?(GLvoid*)(fixedVertices+3):(GLvoid*)(afVertices+3)); + SWITCH_SOURCE(3) + glColorPointer(4, colorType, size_of * 10, data); } else { - glColorPointer(4,type,size_of * 10, (GLvoid*) (size_of * 3) ); + glColorPointer(4,colorType,size_of * 10, (GLvoid*) (size_of * 3) ); } if (useTexture) { glEnableClientState(GL_TEXTURE_COORD_ARRAY); if (immidateMode) { - glTexCoordPointer(2, type, size_of * 10, useFixed?(GLvoid*)(fixedVertices + 7):(GLvoid*)(afVertices+7)); + SWITCH_SOURCE(7) + glTexCoordPointer(2, type, size_of * 10,data); } else { glTexCoordPointer(2, type, size_of * 10, (GLvoid*)(size_of * 7)); } @@ -345,7 +396,8 @@ int main(int argc, char **argv) { glEnableClientState(GL_POINT_SIZE_ARRAY_OES); if (immidateMode) { - glPointSizePointerOES(type,size_of * 10,useFixed?(GLvoid*)(fixedVertices + 9):(GLvoid*)(afVertices+9)); + SWITCH_SOURCE(9) + glPointSizePointerOES(type,size_of * 10,data); } else { glPointSizePointerOES(type,size_of * 10,(GLvoid*)(size_of * 9)); }