2 * Copyright 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.
17 #include "GLESv2Decoder.h"
20 #include <GLES2/gl2.h>
21 #include <GLES2/gl2ext.h>
23 static inline void* SafePointerFromUInt(GLuint value) {
24 return (void*)(uintptr_t)value;
27 GLESv2Decoder::GLESv2Decoder()
33 GLESv2Decoder::~GLESv2Decoder()
38 void *GLESv2Decoder::s_getProc(const char *name, void *userData)
40 GLESv2Decoder *ctx = (GLESv2Decoder *) userData;
42 if (ctx == NULL || ctx->m_GL2library == NULL) {
47 #ifdef USE_EGL_GETPROCADDRESS
48 func = (void *) eglGetProcAddress(name);
51 func = (void *) ctx->m_GL2library->findSymbol(name);
56 int GLESv2Decoder::initGL(get_proc_func_t getProcFunc, void *getProcFuncData)
58 this->initDispatchByName(getProcFunc, getProcFuncData);
60 glGetCompressedTextureFormats = s_glGetCompressedTextureFormats;
61 glVertexAttribPointerData = s_glVertexAttribPointerData;
62 glVertexAttribPointerOffset = s_glVertexAttribPointerOffset;
64 glDrawElementsOffset = s_glDrawElementsOffset;
65 glDrawElementsData = s_glDrawElementsData;
66 glShaderString = s_glShaderString;
67 glFinishRoundTrip = s_glFinishRoundTrip;
72 int GLESv2Decoder::s_glFinishRoundTrip(void *self)
74 GLESv2Decoder *ctx = (GLESv2Decoder *)self;
79 void GLESv2Decoder::s_glGetCompressedTextureFormats(void *self, int count, GLint *formats)
81 GLESv2Decoder *ctx = (GLESv2Decoder *) self;
84 ctx->glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &nFormats);
85 if (nFormats > count) {
86 fprintf(stderr, "%s: GetCompressedTextureFormats: The requested number of formats does not match the number that is reported by OpenGL\n", __FUNCTION__);
88 ctx->glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, formats);
92 void GLESv2Decoder::s_glVertexAttribPointerData(void *self, GLuint indx, GLint size, GLenum type,
93 GLboolean normalized, GLsizei stride, void * data, GLuint datalen)
95 GLESv2Decoder *ctx = (GLESv2Decoder *) self;
96 if (ctx->m_contextData != NULL) {
97 ctx->m_contextData->storePointerData(indx, data, datalen);
98 // note - the stride of the data is always zero when it comes out of the codec.
99 // See gl2.attrib for the packing function call.
100 ctx->glVertexAttribPointer(indx, size, type, normalized, 0, ctx->m_contextData->pointerData(indx));
104 void GLESv2Decoder::s_glVertexAttribPointerOffset(void *self, GLuint indx, GLint size, GLenum type,
105 GLboolean normalized, GLsizei stride, GLuint data)
107 GLESv2Decoder *ctx = (GLESv2Decoder *) self;
108 ctx->glVertexAttribPointer(indx, size, type, normalized, stride, SafePointerFromUInt(data));
112 void GLESv2Decoder::s_glDrawElementsData(void *self, GLenum mode, GLsizei count, GLenum type, void * data, GLuint datalen)
114 GLESv2Decoder *ctx = (GLESv2Decoder *)self;
115 ctx->glDrawElements(mode, count, type, data);
119 void GLESv2Decoder::s_glDrawElementsOffset(void *self, GLenum mode, GLsizei count, GLenum type, GLuint offset)
121 GLESv2Decoder *ctx = (GLESv2Decoder *)self;
122 ctx->glDrawElements(mode, count, type, SafePointerFromUInt(offset));
125 void GLESv2Decoder::s_glShaderString(void *self, GLuint shader, const GLchar* string, GLsizei len)
127 GLESv2Decoder *ctx = (GLESv2Decoder *)self;
128 ctx->glShaderSource(shader, 1, &string, NULL);