Home | History | Annotate | Download | only in GLcommon
      1 #include <GLcommon/GLEScontext.h>
      2 #include <GLcommon/GLconversion_macros.h>
      3 #include <GLcommon/GLESmacros.h>
      4 #include <GLES/gl.h>
      5 #include <GLES/glext.h>
      6 #include <GLcommon/GLESvalidate.h>
      7 #include <GLcommon/TextureUtils.h>
      8 #include <GLcommon/FramebufferData.h>
      9 #include <strings.h>
     10 
     11 //decleration
     12 static void convertFixedDirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,unsigned int nBytes,unsigned int strideOut,int attribSize);
     13 static void convertFixedIndirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,GLsizei count,GLenum indices_type,const GLvoid* indices,unsigned int strideOut,int attribSize);
     14 static void convertByteDirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,unsigned int nBytes,unsigned int strideOut,int attribSize);
     15 static void convertByteIndirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,GLsizei count,GLenum indices_type,const GLvoid* indices,unsigned int strideOut,int attribSize);
     16 
     17 GLESConversionArrays::~GLESConversionArrays() {
     18     for(std::map<GLenum,ArrayData>::iterator it = m_arrays.begin(); it != m_arrays.end();it++) {
     19         if((*it).second.allocated){
     20             if((*it).second.type == GL_FLOAT){
     21                 GLfloat* p = (GLfloat *)((*it).second.data);
     22                 if(p) delete[] p;
     23             } else if((*it).second.type == GL_SHORT){
     24                 GLshort* p = (GLshort *)((*it).second.data);
     25                 if(p) delete[] p;
     26             }
     27         }
     28     }
     29 }
     30 
     31 void GLESConversionArrays::allocArr(unsigned int size,GLenum type){
     32     if(type == GL_FIXED){
     33         m_arrays[m_current].data = new GLfloat[size];
     34         m_arrays[m_current].type = GL_FLOAT;
     35     } else if(type == GL_BYTE){
     36         m_arrays[m_current].data = new GLshort[size];
     37         m_arrays[m_current].type = GL_SHORT;
     38     }
     39     m_arrays[m_current].stride = 0;
     40     m_arrays[m_current].allocated = true;
     41 }
     42 
     43 void GLESConversionArrays::setArr(void* data,unsigned int stride,GLenum type){
     44    m_arrays[m_current].type = type;
     45    m_arrays[m_current].data = data;
     46    m_arrays[m_current].stride = stride;
     47    m_arrays[m_current].allocated = false;
     48 }
     49 
     50 void* GLESConversionArrays::getCurrentData(){
     51     return m_arrays[m_current].data;
     52 }
     53 
     54 ArrayData& GLESConversionArrays::getCurrentArray(){
     55     return m_arrays[m_current];
     56 }
     57 
     58 unsigned int GLESConversionArrays::getCurrentIndex(){
     59     return m_current;
     60 }
     61 
     62 ArrayData& GLESConversionArrays::operator[](int i){
     63     return m_arrays[i];
     64 }
     65 
     66 void GLESConversionArrays::operator++(){
     67     m_current++;
     68 }
     69 
     70 GLDispatch     GLEScontext::s_glDispatch;
     71 android::Mutex GLEScontext::s_lock;
     72 std::string*   GLEScontext::s_glExtensions= NULL;
     73 GLSupport      GLEScontext::s_glSupport;
     74 
     75 Version::Version():m_major(0),
     76                    m_minor(0),
     77                    m_release(0){};
     78 
     79 Version::Version(int major,int minor,int release):m_major(major),
     80                                                   m_minor(minor),
     81                                                   m_release(release){};
     82 
     83 Version::Version(const Version& ver):m_major(ver.m_major),
     84                                      m_minor(ver.m_minor),
     85                                      m_release(ver.m_release){}
     86 
     87 Version::Version(const char* versionString){
     88     m_release = 0;
     89     if((!versionString) ||
     90       ((!(sscanf(versionString,"%d.%d"   ,&m_major,&m_minor) == 2)) &&
     91        (!(sscanf(versionString,"%d.%d.%d",&m_major,&m_minor,&m_release) == 3)))){
     92         m_major = m_minor = 0; // the version is not in the right format
     93     }
     94 }
     95 
     96 Version& Version::operator=(const Version& ver){
     97     m_major   = ver.m_major;
     98     m_minor   = ver.m_minor;
     99     m_release = ver.m_release;
    100     return *this;
    101 }
    102 
    103 bool Version::operator<(const Version& ver) const{
    104     if(m_major < ver.m_major) return true;
    105     if(m_major == ver.m_major){
    106         if(m_minor < ver.m_minor) return true;
    107         if(m_minor == ver.m_minor){
    108            return m_release < ver.m_release;
    109         }
    110     }
    111     return false;
    112 }
    113 
    114 void GLEScontext::init() {
    115 
    116     if (!s_glExtensions) {
    117         initCapsLocked(s_glDispatch.glGetString(GL_EXTENSIONS));
    118         s_glExtensions = new std::string("");
    119     }
    120 
    121     if (!m_initialized) {
    122         initExtensionString();
    123 
    124         int maxTexUnits = getMaxTexUnits();
    125         m_texState = new textureUnitState[maxTexUnits];
    126         for (int i=0;i<maxTexUnits;++i) {
    127             for (int j=0;j<NUM_TEXTURE_TARGETS;++j)
    128             {
    129                 m_texState[i][j].texture = 0;
    130                 m_texState[i][j].enabled = GL_FALSE;
    131             }
    132         }
    133     }
    134 }
    135 
    136 GLEScontext::GLEScontext():
    137                            m_initialized(false)    ,
    138                            m_activeTexture(0)      ,
    139                            m_unpackAlignment(4)    ,
    140                            m_glError(GL_NO_ERROR)  ,
    141                            m_texState(0)          ,
    142                            m_arrayBuffer(0)        ,
    143                            m_elementBuffer(0),
    144                            m_renderbuffer(0),
    145                            m_framebuffer(0)
    146 {
    147 };
    148 
    149 GLenum GLEScontext::getGLerror() {
    150     return m_glError;
    151 }
    152 
    153 void GLEScontext::setGLerror(GLenum err) {
    154     m_glError = err;
    155 }
    156 
    157 void GLEScontext::setActiveTexture(GLenum tex) {
    158    m_activeTexture = tex - GL_TEXTURE0;
    159 }
    160 
    161 GLEScontext::~GLEScontext() {
    162     for(ArraysMap::iterator it = m_map.begin(); it != m_map.end();it++) {
    163         GLESpointer* p = (*it).second;
    164         if(p) {
    165             delete p;
    166         }
    167     }
    168     delete[] m_texState;
    169     m_texState = NULL;
    170 }
    171 
    172 const GLvoid* GLEScontext::setPointer(GLenum arrType,GLint size,GLenum type,GLsizei stride,const GLvoid* data,bool normalize) {
    173     GLuint bufferName = m_arrayBuffer;
    174     if(bufferName) {
    175         unsigned int offset = reinterpret_cast<unsigned int>(data);
    176         GLESbuffer* vbo = static_cast<GLESbuffer*>(m_shareGroup->getObjectData(VERTEXBUFFER,bufferName).Ptr());
    177         m_map[arrType]->setBuffer(size,type,stride,vbo,bufferName,offset,normalize);
    178         return  static_cast<const unsigned char*>(vbo->getData()) +  offset;
    179     }
    180     m_map[arrType]->setArray(size,type,stride,data,normalize);
    181     return data;
    182 }
    183 
    184 void GLEScontext::enableArr(GLenum arr,bool enable) {
    185     m_map[arr]->enable(enable);
    186 }
    187 
    188 bool GLEScontext::isArrEnabled(GLenum arr) {
    189     return m_map[arr]->isEnable();
    190 }
    191 
    192 const GLESpointer* GLEScontext::getPointer(GLenum arrType) {
    193     if (m_map.find(arrType) != m_map.end()) return m_map[arrType];
    194     return NULL;
    195 }
    196 
    197 static void convertFixedDirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,unsigned int nBytes,unsigned int strideOut,int attribSize) {
    198 
    199     for(unsigned int i = 0; i < nBytes;i+=strideOut) {
    200         const GLfixed* fixed_data = (const GLfixed *)dataIn;
    201         //filling attrib
    202         for(int j=0;j<attribSize;j++) {
    203             reinterpret_cast<GLfloat*>(&static_cast<unsigned char*>(dataOut)[i])[j] = X2F(fixed_data[j]);
    204         }
    205         dataIn += strideIn;
    206     }
    207 }
    208 
    209 static void convertFixedIndirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,GLsizei count,GLenum indices_type,const GLvoid* indices,unsigned int strideOut,int attribSize) {
    210     for(int i = 0 ;i < count ;i++) {
    211         unsigned short index = indices_type == GL_UNSIGNED_BYTE? ((GLubyte *)indices)[i]:
    212                                                              ((GLushort *)indices)[i];
    213         const GLfixed* fixed_data = (GLfixed *)(dataIn  + index*strideIn);
    214         GLfloat* float_data = reinterpret_cast<GLfloat*>(static_cast<unsigned char*>(dataOut) + index*strideOut);
    215 
    216         for(int j=0;j<attribSize;j++) {
    217             float_data[j] = X2F(fixed_data[j]);
    218          }
    219     }
    220 }
    221 
    222 static void convertByteDirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,unsigned int nBytes,unsigned int strideOut,int attribSize) {
    223 
    224     for(unsigned int i = 0; i < nBytes;i+=strideOut) {
    225         const GLbyte* byte_data = (const GLbyte *)dataIn;
    226         //filling attrib
    227         for(int j=0;j<attribSize;j++) {
    228             reinterpret_cast<GLshort*>(&static_cast<unsigned char*>(dataOut)[i])[j] = B2S(byte_data[j]);
    229         }
    230         dataIn += strideIn;
    231     }
    232 }
    233 
    234 static void convertByteIndirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,GLsizei count,GLenum indices_type,const GLvoid* indices,unsigned int strideOut,int attribSize) {
    235     for(int i = 0 ;i < count ;i++) {
    236         unsigned short index = indices_type == GL_UNSIGNED_BYTE? ((GLubyte *)indices)[i]:
    237                                                              ((GLushort *)indices)[i];
    238         const GLbyte* bytes_data = (GLbyte *)(dataIn  + index*strideIn);
    239         GLshort* short_data = reinterpret_cast<GLshort*>(static_cast<unsigned char*>(dataOut) + index*strideOut);
    240 
    241         for(int j=0;j<attribSize;j++) {
    242             short_data[j] = B2S(bytes_data[j]);
    243          }
    244     }
    245 }
    246 static void directToBytesRanges(GLint first,GLsizei count,GLESpointer* p,RangeList& list) {
    247 
    248     int attribSize = p->getSize()*4; //4 is the sizeof GLfixed or GLfloat in bytes
    249     int stride = p->getStride()?p->getStride():attribSize;
    250     int start  = p->getBufferOffset()+first*attribSize;
    251     if(!p->getStride()) {
    252         list.addRange(Range(start,count*attribSize));
    253     } else {
    254         for(int i = 0 ;i < count; i++,start+=stride) {
    255             list.addRange(Range(start,attribSize));
    256         }
    257     }
    258 }
    259 
    260 static void indirectToBytesRanges(const GLvoid* indices,GLenum indices_type,GLsizei count,GLESpointer* p,RangeList& list) {
    261 
    262     int attribSize = p->getSize() * 4; //4 is the sizeof GLfixed or GLfloat in bytes
    263     int stride = p->getStride()?p->getStride():attribSize;
    264     int start  = p->getBufferOffset();
    265     for(int i=0 ; i < count; i++) {
    266         GLushort index = (indices_type == GL_UNSIGNED_SHORT?
    267                          static_cast<const GLushort*>(indices)[i]:
    268                          static_cast<const GLubyte*>(indices)[i]);
    269         list.addRange(Range(start+index*stride,attribSize));
    270 
    271     }
    272 }
    273 
    274 int bytesRangesToIndices(RangeList& ranges,GLESpointer* p,GLushort* indices) {
    275 
    276     int attribSize = p->getSize() * 4; //4 is the sizeof GLfixed or GLfloat in bytes
    277     int stride = p->getStride()?p->getStride():attribSize;
    278     int offset = p->getBufferOffset();
    279 
    280     int n = 0;
    281     for(int i=0;i<ranges.size();i++) {
    282         int startIndex = (ranges[i].getStart() - offset) / stride;
    283         int nElements = ranges[i].getSize()/attribSize;
    284         for(int j=0;j<nElements;j++) {
    285             indices[n++] = startIndex+j;
    286         }
    287     }
    288     return n;
    289 }
    290 
    291 void GLEScontext::convertDirect(GLESConversionArrays& cArrs,GLint first,GLsizei count,GLenum array_id,GLESpointer* p) {
    292 
    293     GLenum type    = p->getType();
    294     int attribSize = p->getSize();
    295     unsigned int size = attribSize*count + first;
    296     unsigned int bytes = type == GL_FIXED ? sizeof(GLfixed):sizeof(GLbyte);
    297     cArrs.allocArr(size,type);
    298     int stride = p->getStride()?p->getStride():bytes*attribSize;
    299     const char* data = (const char*)p->getArrayData() + (first*stride);
    300 
    301     if(type == GL_FIXED) {
    302         convertFixedDirectLoop(data,stride,cArrs.getCurrentData(),size*sizeof(GLfloat),attribSize*sizeof(GLfloat),attribSize);
    303     } else if(type == GL_BYTE) {
    304         convertByteDirectLoop(data,stride,cArrs.getCurrentData(),size*sizeof(GLshort),attribSize*sizeof(GLshort),attribSize);
    305     }
    306 }
    307 
    308 void GLEScontext::convertDirectVBO(GLESConversionArrays& cArrs,GLint first,GLsizei count,GLenum array_id,GLESpointer* p) {
    309 
    310     RangeList ranges;
    311     RangeList conversions;
    312     GLushort* indices = NULL;
    313     GLenum type    = p->getType();
    314     int attribSize = p->getSize();
    315     int stride = p->getStride()?p->getStride():sizeof(GLfixed)*attribSize;
    316     unsigned int size = p->getStride()?p->getStride()*count:attribSize*count*sizeof(GLfixed);
    317     char* data = (char*)p->getBufferData() + (first*stride);
    318 
    319     if(p->bufferNeedConversion()) {
    320         directToBytesRanges(first,count,p,ranges); //converting indices range to buffer bytes ranges by offset
    321         p->getBufferConversions(ranges,conversions); // getting from the buffer the relevant ranges that still needs to be converted
    322 
    323         if(conversions.size()) { // there are some elements to convert
    324            indices = new GLushort[count];
    325            int nIndices = bytesRangesToIndices(conversions,p,indices); //converting bytes ranges by offset to indices in this array
    326            convertFixedIndirectLoop(data,stride,data,nIndices,GL_UNSIGNED_SHORT,indices,stride,attribSize);
    327         }
    328     }
    329     if(indices) delete[] indices;
    330     cArrs.setArr(data,p->getStride(),GL_FLOAT);
    331 }
    332 
    333 int GLEScontext::findMaxIndex(GLsizei count,GLenum type,const GLvoid* indices) {
    334     //finding max index
    335     int max = 0;
    336     if(type == GL_UNSIGNED_BYTE) {
    337         GLubyte*  b_indices  =(GLubyte *)indices;
    338         for(int i=0;i<count;i++) {
    339             if(b_indices[i] > max) max = b_indices[i];
    340         }
    341     } else {
    342         GLushort* us_indices =(GLushort *)indices;
    343         for(int i=0;i<count;i++) {
    344             if(us_indices[i] > max) max = us_indices[i];
    345         }
    346     }
    347     return max;
    348 }
    349 
    350 void GLEScontext::convertIndirect(GLESConversionArrays& cArrs,GLsizei count,GLenum indices_type,const GLvoid* indices,GLenum array_id,GLESpointer* p) {
    351     GLenum type    = p->getType();
    352     int maxElements = findMaxIndex(count,type,indices) + 1;
    353 
    354     int attribSize = p->getSize();
    355     int size = attribSize * maxElements;
    356     unsigned int bytes = type == GL_FIXED ? sizeof(GLfixed):sizeof(GLbyte);
    357     cArrs.allocArr(size,type);
    358     int stride = p->getStride()?p->getStride():bytes*attribSize;
    359 
    360     const char* data = (const char*)p->getArrayData();
    361     if(type == GL_FIXED) {
    362         convertFixedIndirectLoop(data,stride,cArrs.getCurrentData(),count,indices_type,indices,attribSize*sizeof(GLfloat),attribSize);
    363     } else if(type == GL_BYTE){
    364         convertByteIndirectLoop(data,stride,cArrs.getCurrentData(),count,indices_type,indices,attribSize*sizeof(GLshort),attribSize);
    365     }
    366 }
    367 
    368 void GLEScontext::convertIndirectVBO(GLESConversionArrays& cArrs,GLsizei count,GLenum indices_type,const GLvoid* indices,GLenum array_id,GLESpointer* p) {
    369     RangeList ranges;
    370     RangeList conversions;
    371     GLushort* conversionIndices = NULL;
    372     GLenum type    = p->getType();
    373     int attribSize = p->getSize();
    374     int stride = p->getStride()?p->getStride():sizeof(GLfixed)*attribSize;
    375     char* data = static_cast<char*>(p->getBufferData());
    376     if(p->bufferNeedConversion()) {
    377         indirectToBytesRanges(indices,indices_type,count,p,ranges); //converting indices range to buffer bytes ranges by offset
    378         p->getBufferConversions(ranges,conversions); // getting from the buffer the relevant ranges that still needs to be converted
    379         if(conversions.size()) { // there are some elements to convert
    380             conversionIndices = new GLushort[count];
    381             int nIndices = bytesRangesToIndices(conversions,p,conversionIndices); //converting bytes ranges by offset to indices in this array
    382             convertFixedIndirectLoop(data,stride,data,nIndices,GL_UNSIGNED_SHORT,conversionIndices,stride,attribSize);
    383         }
    384     }
    385     if(conversionIndices) delete[] conversionIndices;
    386     cArrs.setArr(data,p->getStride(),GL_FLOAT);
    387 }
    388 
    389 
    390 
    391 void GLEScontext::bindBuffer(GLenum target,GLuint buffer) {
    392     if(target == GL_ARRAY_BUFFER) {
    393         m_arrayBuffer = buffer;
    394     } else {
    395        m_elementBuffer = buffer;
    396     }
    397 }
    398 
    399 void GLEScontext::unbindBuffer(GLuint buffer) {
    400     if(m_arrayBuffer == buffer)
    401     {
    402         m_arrayBuffer = 0;
    403     }
    404     if(m_elementBuffer == buffer)
    405     {
    406         m_elementBuffer = 0;
    407     }
    408 }
    409 
    410 //checks if any buffer is binded to target
    411 bool GLEScontext::isBindedBuffer(GLenum target) {
    412     if(target == GL_ARRAY_BUFFER) {
    413         return m_arrayBuffer != 0;
    414     } else {
    415         return m_elementBuffer != 0;
    416     }
    417 }
    418 
    419 GLuint GLEScontext::getBuffer(GLenum target) {
    420     return target == GL_ARRAY_BUFFER ? m_arrayBuffer:m_elementBuffer;
    421 }
    422 
    423 GLvoid* GLEScontext::getBindedBuffer(GLenum target) {
    424     GLuint bufferName = getBuffer(target);
    425     if(!bufferName) return NULL;
    426 
    427     GLESbuffer* vbo = static_cast<GLESbuffer*>(m_shareGroup->getObjectData(VERTEXBUFFER,bufferName).Ptr());
    428     return vbo->getData();
    429 }
    430 
    431 void GLEScontext::getBufferSize(GLenum target,GLint* param) {
    432     GLuint bufferName = getBuffer(target);
    433     GLESbuffer* vbo = static_cast<GLESbuffer*>(m_shareGroup->getObjectData(VERTEXBUFFER,bufferName).Ptr());
    434     *param = vbo->getSize();
    435 }
    436 
    437 void GLEScontext::getBufferUsage(GLenum target,GLint* param) {
    438     GLuint bufferName = getBuffer(target);
    439     GLESbuffer* vbo = static_cast<GLESbuffer*>(m_shareGroup->getObjectData(VERTEXBUFFER,bufferName).Ptr());
    440     *param = vbo->getUsage();
    441 }
    442 
    443 bool GLEScontext::setBufferData(GLenum target,GLsizeiptr size,const GLvoid* data,GLenum usage) {
    444     GLuint bufferName = getBuffer(target);
    445     if(!bufferName) return false;
    446     GLESbuffer* vbo = static_cast<GLESbuffer*>(m_shareGroup->getObjectData(VERTEXBUFFER,bufferName).Ptr());
    447     return vbo->setBuffer(size,usage,data);
    448 }
    449 
    450 bool GLEScontext::setBufferSubData(GLenum target,GLintptr offset,GLsizeiptr size,const GLvoid* data) {
    451 
    452     GLuint bufferName = getBuffer(target);
    453     if(!bufferName) return false;
    454     GLESbuffer* vbo = static_cast<GLESbuffer*>(m_shareGroup->getObjectData(VERTEXBUFFER,bufferName).Ptr());
    455     return vbo->setSubBuffer(offset,size,data);
    456 }
    457 
    458 const char * GLEScontext::getExtensionString() {
    459     const char * ret;
    460     s_lock.lock();
    461     if (s_glExtensions)
    462         ret = s_glExtensions->c_str();
    463     else
    464         ret="";
    465     s_lock.unlock();
    466     return ret;
    467 }
    468 
    469 void GLEScontext::getGlobalLock() {
    470     s_lock.lock();
    471 }
    472 
    473 void GLEScontext::releaseGlobalLock() {
    474     s_lock.unlock();
    475 }
    476 
    477 
    478 void GLEScontext::initCapsLocked(const GLubyte * extensionString)
    479 {
    480     const char* cstring = (const char*)extensionString;
    481 
    482     s_glDispatch.glGetIntegerv(GL_MAX_VERTEX_ATTRIBS,&s_glSupport.maxVertexAttribs);
    483     s_glDispatch.glGetIntegerv(GL_MAX_CLIP_PLANES,&s_glSupport.maxClipPlane);
    484     s_glDispatch.glGetIntegerv(GL_MAX_LIGHTS,&s_glSupport.maxLights);
    485     s_glDispatch.glGetIntegerv(GL_MAX_TEXTURE_SIZE,&s_glSupport.maxTexSize);
    486     s_glDispatch.glGetIntegerv(GL_MAX_TEXTURE_UNITS,&s_glSupport.maxTexUnits);
    487     s_glDispatch.glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS,&s_glSupport.maxTexImageUnits);
    488     const GLubyte* glslVersion = s_glDispatch.glGetString(GL_SHADING_LANGUAGE_VERSION);
    489     s_glSupport.glslVersion = Version((const  char*)(glslVersion));
    490 
    491     if (strstr(cstring,"GL_EXT_bgra ")!=NULL)
    492         s_glSupport.GL_EXT_TEXTURE_FORMAT_BGRA8888 = true;
    493 
    494     if (strstr(cstring,"GL_EXT_framebuffer_object ")!=NULL)
    495         s_glSupport.GL_EXT_FRAMEBUFFER_OBJECT = true;
    496 
    497     if (strstr(cstring,"GL_ARB_vertex_blend ")!=NULL)
    498         s_glSupport.GL_ARB_VERTEX_BLEND = true;
    499 
    500     if (strstr(cstring,"GL_ARB_matrix_palette ")!=NULL)
    501         s_glSupport.GL_ARB_MATRIX_PALETTE = true;
    502 
    503     if (strstr(cstring,"GL_EXT_packed_depth_stencil ")!=NULL )
    504         s_glSupport.GL_EXT_PACKED_DEPTH_STENCIL = true;
    505 
    506     if (strstr(cstring,"GL_OES_read_format ")!=NULL)
    507         s_glSupport.GL_OES_READ_FORMAT = true;
    508 
    509     if (strstr(cstring,"GL_ARB_half_float_pixel ")!=NULL)
    510         s_glSupport.GL_ARB_HALF_FLOAT_PIXEL = true;
    511 
    512     if (strstr(cstring,"GL_NV_half_float ")!=NULL)
    513         s_glSupport.GL_NV_HALF_FLOAT = true;
    514 
    515     if (strstr(cstring,"GL_ARB_half_float_vertex ")!=NULL)
    516         s_glSupport.GL_ARB_HALF_FLOAT_VERTEX = true;
    517 
    518     if (strstr(cstring,"GL_SGIS_generate_mipmap ")!=NULL)
    519         s_glSupport.GL_SGIS_GENERATE_MIPMAP = true;
    520 
    521     if (strstr(cstring,"GL_ARB_ES2_compatibility ")!=NULL)
    522         s_glSupport.GL_ARB_ES2_COMPATIBILITY = true;
    523 
    524     if (strstr(cstring,"GL_OES_standard_derivatives ")!=NULL)
    525         s_glSupport.GL_OES_STANDARD_DERIVATIVES = true;
    526 
    527 }
    528 
    529 bool GLEScontext::isTextureUnitEnabled(GLenum unit) {
    530     for (int i=0;i<NUM_TEXTURE_TARGETS;++i) {
    531         if (m_texState[unit-GL_TEXTURE0][i].enabled)
    532             return true;
    533     }
    534     return false;
    535 }
    536 
    537 bool GLEScontext::glGetBooleanv(GLenum pname, GLboolean *params)
    538 {
    539     GLint iParam;
    540 
    541     if(glGetIntegerv(pname, &iParam))
    542     {
    543         *params = (iParam != 0);
    544         return true;
    545     }
    546 
    547     return false;
    548 }
    549 
    550 bool GLEScontext::glGetFixedv(GLenum pname, GLfixed *params)
    551 {
    552     bool result = false;
    553     GLint numParams = 1;
    554 
    555     GLint* iParams = new GLint[numParams];
    556     if (numParams>0 && glGetIntegerv(pname,iParams)) {
    557         while(numParams >= 0)
    558         {
    559             params[numParams] = I2X(iParams[numParams]);
    560             numParams--;
    561         }
    562         result = true;
    563     }
    564     delete [] iParams;
    565 
    566     return result;
    567 }
    568 
    569 bool GLEScontext::glGetFloatv(GLenum pname, GLfloat *params)
    570 {
    571     bool result = false;
    572     GLint numParams = 1;
    573 
    574     GLint* iParams = new GLint[numParams];
    575     if (numParams>0 && glGetIntegerv(pname,iParams)) {
    576         while(numParams >= 0)
    577         {
    578             params[numParams] = (GLfloat)iParams[numParams];
    579             numParams--;
    580         }
    581         result = true;
    582     }
    583     delete [] iParams;
    584 
    585     return result;
    586 }
    587 
    588 bool GLEScontext::glGetIntegerv(GLenum pname, GLint *params)
    589 {
    590     switch(pname)
    591     {
    592         case GL_ARRAY_BUFFER_BINDING:
    593             *params = m_arrayBuffer;
    594             break;
    595 
    596         case GL_ELEMENT_ARRAY_BUFFER_BINDING:
    597             *params = m_elementBuffer;
    598             break;
    599 
    600         case GL_TEXTURE_BINDING_CUBE_MAP:
    601             *params = m_texState[m_activeTexture][TEXTURE_CUBE_MAP].texture;
    602             break;
    603 
    604         case GL_TEXTURE_BINDING_2D:
    605             *params = m_texState[m_activeTexture][TEXTURE_2D].texture;
    606             break;
    607 
    608         case GL_ACTIVE_TEXTURE:
    609             *params = m_activeTexture+GL_TEXTURE0;
    610             break;
    611 
    612         case GL_IMPLEMENTATION_COLOR_READ_TYPE_OES:
    613             *params = GL_UNSIGNED_BYTE;
    614             break;
    615 
    616         case GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES:
    617             *params = GL_RGBA;
    618             break;
    619         default:
    620             return false;
    621     }
    622 
    623     return true;
    624 }
    625 
    626 TextureTarget GLEScontext::GLTextureTargetToLocal(GLenum target) {
    627     TextureTarget value=TEXTURE_2D;
    628     switch (target) {
    629     case GL_TEXTURE_CUBE_MAP:
    630     case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
    631     case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
    632     case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
    633     case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
    634     case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
    635     case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
    636         value = TEXTURE_CUBE_MAP;
    637         break;
    638     case GL_TEXTURE_2D:
    639         value = TEXTURE_2D;
    640         break;
    641     }
    642     return value;
    643 }
    644 
    645 unsigned int GLEScontext::getBindedTexture(GLenum target) {
    646     TextureTarget pos = GLTextureTargetToLocal(target);
    647     return m_texState[m_activeTexture][pos].texture;
    648 }
    649 
    650 unsigned int GLEScontext::getBindedTexture(GLenum unit, GLenum target) {
    651     TextureTarget pos = GLTextureTargetToLocal(target);
    652     return m_texState[unit-GL_TEXTURE0][pos].texture;
    653 }
    654 
    655 void GLEScontext::setBindedTexture(GLenum target, unsigned int tex) {
    656     TextureTarget pos = GLTextureTargetToLocal(target);
    657     m_texState[m_activeTexture][pos].texture = tex;
    658 }
    659 
    660 void GLEScontext::setTextureEnabled(GLenum target, GLenum enable) {
    661     TextureTarget pos = GLTextureTargetToLocal(target);
    662     m_texState[m_activeTexture][pos].enabled = enable;
    663 }
    664 
    665 #define INTERNAL_NAME(x) (x +0x100000000ll);
    666 
    667 ObjectLocalName GLEScontext::getDefaultTextureName(GLenum target) {
    668     ObjectLocalName name = 0;
    669     switch (GLTextureTargetToLocal(target)) {
    670     case TEXTURE_2D:
    671         name = INTERNAL_NAME(0);
    672         break;
    673     case TEXTURE_CUBE_MAP:
    674         name = INTERNAL_NAME(1);
    675         break;
    676     default:
    677         name = 0;
    678         break;
    679     }
    680     return name;
    681 }
    682 
    683 void GLEScontext::drawValidate(void)
    684 {
    685     if(m_framebuffer == 0)
    686         return;
    687 
    688     ObjectDataPtr fbObj = m_shareGroup->getObjectData(FRAMEBUFFER,m_framebuffer);
    689     if (fbObj.Ptr() == NULL)
    690         return;
    691 
    692     FramebufferData *fbData = (FramebufferData *)fbObj.Ptr();
    693 
    694     fbData->validate(this);
    695 }
    696