Merge "opengl translator: supporting GL_BYTE type"

This commit is contained in:
David Turner
2011-07-03 04:40:45 -07:00
committed by Android Code Review
12 changed files with 420 additions and 216 deletions

View File

@@ -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<const GLfloat*>(isBindedBuffer(GL_ARRAY_BUFFER)?p->getBufferData():p->getArrayData());
pointsArr = static_cast<const GLfloat*>(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 "

View File

@@ -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);
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;

View File

@@ -27,7 +27,7 @@
#include <stdio.h>
#include <GLcommon/gldefs.h>
#include <GLcommon/GLDispatch.h>
#include <GLcommon/GLfixed_ops.h>
#include <GLcommon/GLconversion_macros.h>
#include <GLcommon/TranslatorIfaces.h>
#include <GLcommon/ThreadInfo.h>
#include <GLES/gl.h>
@@ -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<unsigned char *>(ctx->getBindedBuffer(GL_ELEMENT_ARRAY_BUFFER));
indices = buf+reinterpret_cast<unsigned int>(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) {

View File

@@ -34,22 +34,61 @@ 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() {

View File

@@ -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();
};

View File

@@ -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);
}
@@ -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){

View File

@@ -1,22 +1,53 @@
#include <GLcommon/GLEScontext.h>
#include <GLcommon/GLfixed_ops.h>
#include <GLcommon/GLconversion_macros.h>
#include <GLES/gl.h>
#include <GLES/glext.h>
//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<GLenum,GLfloat*>::iterator it = arrays.begin(); it != arrays.end();it++) {
GLfloat* p = (*it).second;
if(p) {
delete[] p;
GLESConversionArrays::~GLESConversionArrays() {
for(std::map<GLenum,std::pair<GLenum,void*> >::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;
@@ -131,7 +162,7 @@ const GLESpointer* GLEScontext::getPointer(GLenum arrType) {
return NULL;
}
static void convertDirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,unsigned int nBytes,unsigned int strideOut,int attribSize) {
static void convertFixedDirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,unsigned int nBytes,unsigned int strideOut,int attribSize) {
for(unsigned int i = 0; i < nBytes;i+=strideOut) {
const GLfixed* fixed_data = (const GLfixed *)dataIn;
@@ -143,7 +174,7 @@ static void convertDirectLoop(const char* dataIn,unsigned int strideIn,void* dat
}
}
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 convertFixedIndirectLoop(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];
@@ -156,6 +187,30 @@ static void convertIndirectLoop(const char* dataIn,unsigned int strideIn,void* d
}
}
static void convertByteDirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,unsigned int nBytes,unsigned int strideOut,int attribSize) {
for(unsigned int i = 0; i < nBytes;i+=strideOut) {
const GLbyte* byte_data = (const GLbyte *)dataIn;
//filling attrib
for(int j=0;j<attribSize;j++) {
reinterpret_cast<GLshort*>(&static_cast<unsigned char*>(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<GLshort*>(static_cast<unsigned char*>(dataOut) + index*strideOut);
for(int j=0;j<attribSize;j++) {
short_data[j] = B2S(bytes_data[j]);
}
}
}
static void directToBytesRanges(GLint first,GLsizei count,GLESpointer* p,RangeList& list) {
int attribSize = p->getSize()*4; //4 is the sizeof GLfixed or GLfloat in bytes
@@ -200,27 +255,30 @@ 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) {
void GLEScontext::convertDirect(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum array_id,GLESpointer* p) {
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;
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);
convertDirectLoop(data,stride,fArrs.arrays[index],size*sizeof(GLfloat),attribSize*sizeof(GLfloat),attribSize);
sendArr(fArrs.arrays[index],array_id,attribSize,0,index);
index++;
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) {
GLenum type = p->getType();
if(isArrEnabled(array_id) && type == GL_FIXED) {
RangeList ranges;
RangeList conversions;
GLushort* indices = NULL;
GLenum type = p->getType();
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);
@@ -233,14 +291,11 @@ void GLEScontext::convertDirectVBO(GLint first,GLsizei count,GLenum array_id,GLE
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);
convertFixedIndirectLoop(data,stride,data,nIndices,GL_UNSIGNED_SHORT,indices,stride,attribSize);
}
}
sendArr(data,array_id,attribSize,p->getStride());
if(indices) delete[] indices;
}
}
static int findMaxIndex(GLsizei count,GLenum type,const GLvoid* indices) {
//finding max index
@@ -259,30 +314,29 @@ 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;
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++;
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) {
GLenum type = p->getType();
if(isArrEnabled(array_id) && type == GL_FIXED) {
RangeList ranges;
RangeList conversions;
GLushort* conversionIndices = NULL;
GLenum type = p->getType();
int attribSize = p->getSize();
int stride = p->getStride()?p->getStride():sizeof(GLfixed)*attribSize;
char* data = static_cast<char*>(p->getBufferData());
@@ -292,31 +346,12 @@ void GLEScontext::convertIndirectVBO(GLsizei count,GLenum indices_type,const GLv
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);
convertFixedIndirectLoop(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);
}
}
}
void GLEScontext::bindBuffer(GLenum target,GLuint buffer) {

View File

@@ -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<unsigned char*>(m_buffer->getData()) + m_buffOffset;
return m_buffer ? static_cast<unsigned char*>(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) {

View File

@@ -6,6 +6,7 @@
#include "objectNameManager.h"
#include <utils/threads.h>
#include <string>
#include <utility>
#define MAX_TEX_UNITS 8
@@ -61,11 +62,20 @@ struct GLSupport {
};
struct GLESFloatArrays
class GLESConversionArrays
{
GLESFloatArrays(){};
~GLESFloatArrays();
std::map<GLenum,GLfloat*> 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<GLenum,std::pair<GLenum,void*> > 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;

View File

@@ -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

View File

@@ -19,6 +19,7 @@
#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 : \

View File

@@ -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);
void* data = (void*)afVertices;
unsigned int uiSize = 3*(sizeof(float)*10);
glBufferData(GL_ARRAY_BUFFER, uiSize, useFixed?(void *)fixedVertices:(void*)afVertices, GL_STATIC_DRAW);
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(useConvertedType){
if(useFixed)
{
arr = fixedVertices;
type = GL_FIXED;
colorType = type = GL_FIXED;
size_of = sizeof(GLfixed);
} else {
arr = byteVertices;
colorType = GL_UNSIGNED_BYTE;
type = GL_BYTE;
size_of = sizeof(GLbyte);
}
else
{
}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));
}