2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include "GLESv1Decoder.h"
20 #include <GLES/glext.h>
26 static inline void* SafePointerFromUInt(GLuint value) {
27 return (void*)(uintptr_t)value;
30 GLESv1Decoder::GLESv1Decoder()
36 GLESv1Decoder::~GLESv1Decoder()
38 if (m_glesDso != NULL) {
44 int GLESv1Decoder::initGL(get_proc_func_t getProcFunc, void *getProcFuncData)
46 this->initDispatchByName(getProcFunc, getProcFuncData);
48 glGetCompressedTextureFormats = s_glGetCompressedTextureFormats;
49 glVertexPointerOffset = s_glVertexPointerOffset;
50 glColorPointerOffset = s_glColorPointerOffset;
51 glNormalPointerOffset = s_glNormalPointerOffset;
52 glTexCoordPointerOffset = s_glTexCoordPointerOffset;
53 glPointSizePointerOffset = s_glPointSizePointerOffset;
54 glWeightPointerOffset = s_glWeightPointerOffset;
55 glMatrixIndexPointerOffset = s_glMatrixIndexPointerOffset;
57 glVertexPointerData = s_glVertexPointerData;
58 glColorPointerData = s_glColorPointerData;
59 glNormalPointerData = s_glNormalPointerData;
60 glTexCoordPointerData = s_glTexCoordPointerData;
61 glPointSizePointerData = s_glPointSizePointerData;
62 glWeightPointerData = s_glWeightPointerData;
63 glMatrixIndexPointerData = s_glMatrixIndexPointerData;
65 glDrawElementsOffset = s_glDrawElementsOffset;
66 glDrawElementsData = s_glDrawElementsData;
67 glFinishRoundTrip = s_glFinishRoundTrip;
72 int GLESv1Decoder::s_glFinishRoundTrip(void *self)
74 GLESv1Decoder *ctx = (GLESv1Decoder *)self;
79 void GLESv1Decoder::s_glVertexPointerOffset(void *self, GLint size, GLenum type, GLsizei stride, GLuint offset)
81 GLESv1Decoder *ctx = (GLESv1Decoder *)self;
82 ctx->glVertexPointer(size, type, stride, SafePointerFromUInt(offset));
85 void GLESv1Decoder::s_glColorPointerOffset(void *self, GLint size, GLenum type, GLsizei stride, GLuint offset)
87 GLESv1Decoder *ctx = (GLESv1Decoder *)self;
88 ctx->glColorPointer(size, type, stride, SafePointerFromUInt(offset));
91 void GLESv1Decoder::s_glTexCoordPointerOffset(void *self, GLint size, GLenum type, GLsizei stride, GLuint offset)
93 GLESv1Decoder *ctx = (GLESv1Decoder *)self;
94 ctx->glTexCoordPointer(size, type, stride, SafePointerFromUInt(offset));
97 void GLESv1Decoder::s_glNormalPointerOffset(void *self, GLenum type, GLsizei stride, GLuint offset)
99 GLESv1Decoder *ctx = (GLESv1Decoder *)self;
100 ctx->glNormalPointer(type, stride, SafePointerFromUInt(offset));
103 void GLESv1Decoder::s_glPointSizePointerOffset(void *self, GLenum type, GLsizei stride, GLuint offset)
105 GLESv1Decoder *ctx = (GLESv1Decoder *)self;
106 ctx->glPointSizePointerOES(type, stride, SafePointerFromUInt(offset));
109 void GLESv1Decoder::s_glWeightPointerOffset(void * self, GLint size, GLenum type, GLsizei stride, GLuint offset)
111 GLESv1Decoder *ctx = (GLESv1Decoder *)self;
112 ctx->glWeightPointerOES(size, type, stride, SafePointerFromUInt(offset));
115 void GLESv1Decoder::s_glMatrixIndexPointerOffset(void * self, GLint size, GLenum type, GLsizei stride, GLuint offset)
117 GLESv1Decoder *ctx = (GLESv1Decoder *)self;
118 ctx->glMatrixIndexPointerOES(size, type, stride, SafePointerFromUInt(offset));
123 #define STORE_POINTER_DATA_OR_ABORT(location) \
124 if (ctx->m_contextData != NULL) { \
125 ctx->m_contextData->storePointerData((location), data, datalen); \
130 void GLESv1Decoder::s_glVertexPointerData(void *self, GLint size, GLenum type, GLsizei stride, void *data, GLuint datalen)
132 GLESv1Decoder *ctx = (GLESv1Decoder *)self;
134 STORE_POINTER_DATA_OR_ABORT(GLDecoderContextData::VERTEX_LOCATION);
136 ctx->glVertexPointer(size, type, 0, ctx->m_contextData->pointerData(GLDecoderContextData::VERTEX_LOCATION));
139 void GLESv1Decoder::s_glColorPointerData(void *self, GLint size, GLenum type, GLsizei stride, void *data, GLuint datalen)
141 GLESv1Decoder *ctx = (GLESv1Decoder *)self;
143 STORE_POINTER_DATA_OR_ABORT(GLDecoderContextData::COLOR_LOCATION);
145 ctx->glColorPointer(size, type, 0, ctx->m_contextData->pointerData(GLDecoderContextData::COLOR_LOCATION));
148 void GLESv1Decoder::s_glTexCoordPointerData(void *self, GLint unit, GLint size, GLenum type, GLsizei stride, void *data, GLuint datalen)
150 GLESv1Decoder *ctx = (GLESv1Decoder *)self;
151 STORE_POINTER_DATA_OR_ABORT((GLDecoderContextData::PointerDataLocation)
152 (GLDecoderContextData::TEXCOORD0_LOCATION + unit));
154 ctx->glTexCoordPointer(size, type, 0,
155 ctx->m_contextData->pointerData((GLDecoderContextData::PointerDataLocation)
156 (GLDecoderContextData::TEXCOORD0_LOCATION + unit)));
159 void GLESv1Decoder::s_glNormalPointerData(void *self, GLenum type, GLsizei stride, void *data, GLuint datalen)
161 GLESv1Decoder *ctx = (GLESv1Decoder *)self;
163 STORE_POINTER_DATA_OR_ABORT(GLDecoderContextData::NORMAL_LOCATION);
165 ctx->glNormalPointer(type, 0, ctx->m_contextData->pointerData(GLDecoderContextData::NORMAL_LOCATION));
168 void GLESv1Decoder::s_glPointSizePointerData(void *self, GLenum type, GLsizei stride, void *data, GLuint datalen)
170 GLESv1Decoder *ctx = (GLESv1Decoder *)self;
172 STORE_POINTER_DATA_OR_ABORT(GLDecoderContextData::POINTSIZE_LOCATION);
174 ctx->glPointSizePointerOES(type, 0, ctx->m_contextData->pointerData(GLDecoderContextData::POINTSIZE_LOCATION));
177 void GLESv1Decoder::s_glWeightPointerData(void * self, GLint size, GLenum type, GLsizei stride, void * data, GLuint datalen)
179 GLESv1Decoder *ctx = (GLESv1Decoder *)self;
181 STORE_POINTER_DATA_OR_ABORT(GLDecoderContextData::WEIGHT_LOCATION);
183 ctx->glWeightPointerOES(size, type, 0, ctx->m_contextData->pointerData(GLDecoderContextData::WEIGHT_LOCATION));
186 void GLESv1Decoder::s_glMatrixIndexPointerData(void * self, GLint size, GLenum type, GLsizei stride, void * data, GLuint datalen)
188 GLESv1Decoder *ctx = (GLESv1Decoder *)self;
190 STORE_POINTER_DATA_OR_ABORT(GLDecoderContextData::MATRIXINDEX_LOCATION);
192 ctx->glMatrixIndexPointerOES(size, type, 0, ctx->m_contextData->pointerData(GLDecoderContextData::MATRIXINDEX_LOCATION));
195 void GLESv1Decoder::s_glDrawElementsOffset(void *self, GLenum mode, GLsizei count, GLenum type, GLuint offset)
197 GLESv1Decoder *ctx = (GLESv1Decoder *)self;
198 ctx->glDrawElements(mode, count, type, SafePointerFromUInt(offset));
201 void GLESv1Decoder::s_glDrawElementsData(void *self, GLenum mode, GLsizei count, GLenum type, void * data, GLuint datalen)
203 GLESv1Decoder *ctx = (GLESv1Decoder *)self;
204 ctx->glDrawElements(mode, count, type, data);
207 void GLESv1Decoder::s_glGetCompressedTextureFormats(void *self, GLint count, GLint *data)
209 GLESv1Decoder *ctx = (GLESv1Decoder *) self;
210 ctx->glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, data);
213 void *GLESv1Decoder::s_getProc(const char *name, void *userData)
215 GLESv1Decoder *ctx = (GLESv1Decoder *)userData;
217 if (ctx == NULL || ctx->m_glesDso == NULL) {
222 #ifdef USE_EGL_GETPROCADDRESS
223 func = (void *) eglGetProcAddress(name);
226 func = (void *)(ctx->m_glesDso->findSymbol(name));