Home | History | Annotate | Download | only in GLESv1_dec
      1 /*
      2 * Copyright (C) 2011 The Android Open Source Project
      3 *
      4 * Licensed under the Apache License, Version 2.0 (the "License");
      5 * you may not use this file except in compliance with the License.
      6 * You may obtain a copy of the License at
      7 *
      8 * http://www.apache.org/licenses/LICENSE-2.0
      9 *
     10 * Unless required by applicable law or agreed to in writing, software
     11 * distributed under the License is distributed on an "AS IS" BASIS,
     12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 * See the License for the specific language governing permissions and
     14 * limitations under the License.
     15 */
     16 #include "GLDecoder.h"
     17 #include <string.h>
     18 #include <stdio.h>
     19 #include <stdlib.h>
     20 #include <EGL/egl.h>
     21 #include <GLES/gl.h>
     22 #include <GLES/glext.h>
     23 
     24 GLDecoder::GLDecoder()
     25 {
     26     m_contextData = NULL;
     27     m_glesDso = NULL;
     28 }
     29 
     30 GLDecoder::~GLDecoder()
     31 {
     32     if (m_glesDso != NULL) {
     33         delete m_glesDso;
     34     }
     35 }
     36 
     37 
     38 int GLDecoder::initGL(get_proc_func_t getProcFunc, void *getProcFuncData)
     39 {
     40     if (getProcFunc == NULL) {
     41         const char *libname = GLES_LIBNAME;
     42         if (getenv(GLES_LIBNAME_VAR) != NULL) {
     43             libname = getenv(GLES_LIBNAME_VAR);
     44         }
     45 
     46         m_glesDso = osUtils::dynLibrary::open(libname);
     47         if (m_glesDso == NULL) {
     48             fprintf(stderr, "Couldn't find %s \n", GLES_LIBNAME);
     49             return -1;
     50         }
     51 
     52         this->initDispatchByName(s_getProc, this);
     53     } else {
     54         this->initDispatchByName(getProcFunc, getProcFuncData);
     55     }
     56 
     57     set_glGetCompressedTextureFormats(s_glGetCompressedTextureFormats);
     58     set_glVertexPointerOffset(s_glVertexPointerOffset);
     59     set_glColorPointerOffset(s_glColorPointerOffset);
     60     set_glNormalPointerOffset(s_glNormalPointerOffset);
     61     set_glTexCoordPointerOffset(s_glTexCoordPointerOffset);
     62     set_glPointSizePointerOffset(s_glPointSizePointerOffset);
     63     set_glWeightPointerOffset(s_glWeightPointerOffset);
     64     set_glMatrixIndexPointerOffset(s_glMatrixIndexPointerOffset);
     65 
     66     set_glVertexPointerData(s_glVertexPointerData);
     67     set_glColorPointerData(s_glColorPointerData);
     68     set_glNormalPointerData(s_glNormalPointerData);
     69     set_glTexCoordPointerData(s_glTexCoordPointerData);
     70     set_glPointSizePointerData(s_glPointSizePointerData);
     71     set_glWeightPointerData(s_glWeightPointerData);
     72     set_glMatrixIndexPointerData(s_glMatrixIndexPointerData);
     73 
     74     set_glDrawElementsOffset(s_glDrawElementsOffset);
     75     set_glDrawElementsData(s_glDrawElementsData);
     76     set_glFinishRoundTrip(s_glFinishRoundTrip);
     77 
     78     return 0;
     79 }
     80 
     81 int GLDecoder::s_glFinishRoundTrip(void *self)
     82 {
     83     GLDecoder *ctx = (GLDecoder *)self;
     84     ctx->glFinish();
     85     return 0;
     86 }
     87 
     88 void GLDecoder::s_glVertexPointerOffset(void *self, GLint size, GLenum type, GLsizei stride, GLuint offset)
     89 {
     90     GLDecoder *ctx = (GLDecoder *)self;
     91     ctx->glVertexPointer(size, type, stride, (void *)offset);
     92 }
     93 
     94 void GLDecoder::s_glColorPointerOffset(void *self, GLint size, GLenum type, GLsizei stride, GLuint offset)
     95 {
     96     GLDecoder *ctx = (GLDecoder *)self;
     97     ctx->glColorPointer(size, type, stride, (void *)offset);
     98 }
     99 
    100 void GLDecoder::s_glTexCoordPointerOffset(void *self, GLint size, GLenum type, GLsizei stride, GLuint offset)
    101 {
    102     GLDecoder *ctx = (GLDecoder *)self;
    103     ctx->glTexCoordPointer(size, type, stride, (void *) offset);
    104 }
    105 
    106 void GLDecoder::s_glNormalPointerOffset(void *self, GLenum type, GLsizei stride, GLuint offset)
    107 {
    108     GLDecoder *ctx = (GLDecoder *)self;
    109     ctx->glNormalPointer(type, stride, (void *)offset);
    110 }
    111 
    112 void GLDecoder::s_glPointSizePointerOffset(void *self, GLenum type, GLsizei stride, GLuint offset)
    113 {
    114     GLDecoder *ctx = (GLDecoder *)self;
    115     ctx->glPointSizePointerOES(type, stride, (void *)offset);
    116 }
    117 
    118 void GLDecoder::s_glWeightPointerOffset(void * self, GLint size, GLenum type, GLsizei stride, GLuint offset)
    119 {
    120     GLDecoder *ctx = (GLDecoder *)self;
    121     ctx->glWeightPointerOES(size, type, stride, (void*)offset);
    122 }
    123 
    124 void GLDecoder::s_glMatrixIndexPointerOffset(void * self, GLint size, GLenum type, GLsizei stride, GLuint offset)
    125 {
    126     GLDecoder *ctx = (GLDecoder *)self;
    127     ctx->glMatrixIndexPointerOES(size, type, stride, (void*)offset);
    128 }
    129 
    130 
    131 
    132 #define STORE_POINTER_DATA_OR_ABORT(location)    \
    133     if (ctx->m_contextData != NULL) {   \
    134         ctx->m_contextData->storePointerData((location), data, datalen); \
    135     } else { \
    136         return; \
    137     }
    138 
    139 void GLDecoder::s_glVertexPointerData(void *self, GLint size, GLenum type, GLsizei stride, void *data, GLuint datalen)
    140 {
    141     GLDecoder *ctx = (GLDecoder *)self;
    142 
    143     STORE_POINTER_DATA_OR_ABORT(GLDecoderContextData::VERTEX_LOCATION);
    144 
    145     ctx->glVertexPointer(size, type, 0, ctx->m_contextData->pointerData(GLDecoderContextData::VERTEX_LOCATION));
    146 }
    147 
    148 void GLDecoder::s_glColorPointerData(void *self, GLint size, GLenum type, GLsizei stride, void *data, GLuint datalen)
    149 {
    150     GLDecoder *ctx = (GLDecoder *)self;
    151 
    152     STORE_POINTER_DATA_OR_ABORT(GLDecoderContextData::COLOR_LOCATION);
    153 
    154     ctx->glColorPointer(size, type, 0, ctx->m_contextData->pointerData(GLDecoderContextData::COLOR_LOCATION));
    155 }
    156 
    157 void GLDecoder::s_glTexCoordPointerData(void *self, GLint unit, GLint size, GLenum type, GLsizei stride, void *data, GLuint datalen)
    158 {
    159     GLDecoder *ctx = (GLDecoder *)self;
    160     STORE_POINTER_DATA_OR_ABORT((GLDecoderContextData::PointerDataLocation)
    161                                 (GLDecoderContextData::TEXCOORD0_LOCATION + unit));
    162 
    163     ctx->glTexCoordPointer(size, type, 0,
    164                            ctx->m_contextData->pointerData((GLDecoderContextData::PointerDataLocation)
    165                                                            (GLDecoderContextData::TEXCOORD0_LOCATION + unit)));
    166 }
    167 
    168 void GLDecoder::s_glNormalPointerData(void *self, GLenum type, GLsizei stride, void *data, GLuint datalen)
    169 {
    170     GLDecoder *ctx = (GLDecoder *)self;
    171 
    172     STORE_POINTER_DATA_OR_ABORT(GLDecoderContextData::NORMAL_LOCATION);
    173 
    174     ctx->glNormalPointer(type, 0, ctx->m_contextData->pointerData(GLDecoderContextData::NORMAL_LOCATION));
    175 }
    176 
    177 void GLDecoder::s_glPointSizePointerData(void *self, GLenum type, GLsizei stride, void *data, GLuint datalen)
    178 {
    179     GLDecoder *ctx = (GLDecoder *)self;
    180 
    181     STORE_POINTER_DATA_OR_ABORT(GLDecoderContextData::POINTSIZE_LOCATION);
    182 
    183     ctx->glPointSizePointerOES(type, 0, ctx->m_contextData->pointerData(GLDecoderContextData::POINTSIZE_LOCATION));
    184 }
    185 
    186 void GLDecoder::s_glWeightPointerData(void * self, GLint size, GLenum type, GLsizei stride, void * data, GLuint datalen)
    187 {
    188     GLDecoder *ctx = (GLDecoder *)self;
    189 
    190     STORE_POINTER_DATA_OR_ABORT(GLDecoderContextData::WEIGHT_LOCATION);
    191 
    192     ctx->glWeightPointerOES(size, type, 0, ctx->m_contextData->pointerData(GLDecoderContextData::WEIGHT_LOCATION));
    193 }
    194 
    195 void GLDecoder::s_glMatrixIndexPointerData(void * self, GLint size, GLenum type, GLsizei stride, void * data, GLuint datalen)
    196 {
    197     GLDecoder *ctx = (GLDecoder *)self;
    198 
    199     STORE_POINTER_DATA_OR_ABORT(GLDecoderContextData::MATRIXINDEX_LOCATION);
    200 
    201     ctx->glMatrixIndexPointerOES(size, type, 0, ctx->m_contextData->pointerData(GLDecoderContextData::MATRIXINDEX_LOCATION));
    202 }
    203 
    204 void GLDecoder::s_glDrawElementsOffset(void *self, GLenum mode, GLsizei count, GLenum type, GLuint offset)
    205 {
    206     GLDecoder *ctx = (GLDecoder *)self;
    207     ctx->glDrawElements(mode, count, type, (void *)offset);
    208 }
    209 
    210 void GLDecoder::s_glDrawElementsData(void *self, GLenum mode, GLsizei count, GLenum type, void * data, GLuint datalen)
    211 {
    212     GLDecoder *ctx = (GLDecoder *)self;
    213     ctx->glDrawElements(mode, count, type, data);
    214 }
    215 
    216 void GLDecoder::s_glGetCompressedTextureFormats(void *self, GLint count, GLint *data)
    217 {
    218     GLDecoder *ctx = (GLDecoder *) self;
    219     ctx->glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, data);
    220 }
    221 
    222 void *GLDecoder::s_getProc(const char *name, void *userData)
    223 {
    224     GLDecoder *ctx = (GLDecoder *)userData;
    225 
    226     if (ctx == NULL || ctx->m_glesDso == NULL) {
    227         return NULL;
    228     }
    229 
    230     void *func = NULL;
    231 #ifdef USE_EGL_GETPROCADDRESS
    232     func = (void *) eglGetProcAddress(name);
    233 #endif
    234     if (func == NULL) {
    235         func = (void *)(ctx->m_glesDso->findSymbol(name));
    236     }
    237     return func;
    238 }
    239