2 ** Copyright 2007, 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.
21 #include <sys/ioctl.h>
24 #include <GLES/glext.h>
26 #include <cutils/log.h>
27 #include <cutils/properties.h>
32 using namespace android;
34 // set this to 1 for crude GL debugging
35 #define CHECK_FOR_GL_ERRORS 0
37 // ----------------------------------------------------------------------------
38 // extensions for the framework
39 // ----------------------------------------------------------------------------
42 GL_API void GL_APIENTRY glColorPointerBounds(GLint size, GLenum type, GLsizei stride,
43 const GLvoid *ptr, GLsizei count);
44 GL_API void GL_APIENTRY glNormalPointerBounds(GLenum type, GLsizei stride,
45 const GLvoid *pointer, GLsizei count);
46 GL_API void GL_APIENTRY glTexCoordPointerBounds(GLint size, GLenum type,
47 GLsizei stride, const GLvoid *pointer, GLsizei count);
48 GL_API void GL_APIENTRY glVertexPointerBounds(GLint size, GLenum type,
49 GLsizei stride, const GLvoid *pointer, GLsizei count);
50 GL_API void GL_APIENTRY glPointSizePointerOESBounds(GLenum type,
51 GLsizei stride, const GLvoid *pointer, GLsizei count);
52 GL_API void GL_APIENTRY glMatrixIndexPointerOESBounds(GLint size, GLenum type,
53 GLsizei stride, const GLvoid *pointer, GLsizei count);
54 GL_API void GL_APIENTRY glWeightPointerOESBounds(GLint size, GLenum type,
55 GLsizei stride, const GLvoid *pointer, GLsizei count);
58 void glColorPointerBounds(GLint size, GLenum type, GLsizei stride,
59 const GLvoid *ptr, GLsizei count) {
60 glColorPointer(size, type, stride, ptr);
62 void glNormalPointerBounds(GLenum type, GLsizei stride,
63 const GLvoid *pointer, GLsizei count) {
64 glNormalPointer(type, stride, pointer);
66 void glTexCoordPointerBounds(GLint size, GLenum type,
67 GLsizei stride, const GLvoid *pointer, GLsizei count) {
68 glTexCoordPointer(size, type, stride, pointer);
70 void glVertexPointerBounds(GLint size, GLenum type,
71 GLsizei stride, const GLvoid *pointer, GLsizei count) {
72 glVertexPointer(size, type, stride, pointer);
75 void GL_APIENTRY glPointSizePointerOESBounds(GLenum type,
76 GLsizei stride, const GLvoid *pointer, GLsizei count) {
77 glPointSizePointerOES(type, stride, pointer);
80 GL_API void GL_APIENTRY glMatrixIndexPointerOESBounds(GLint size, GLenum type,
81 GLsizei stride, const GLvoid *pointer, GLsizei count) {
82 glMatrixIndexPointerOES(size, type, stride, pointer);
85 GL_API void GL_APIENTRY glWeightPointerOESBounds(GLint size, GLenum type,
86 GLsizei stride, const GLvoid *pointer, GLsizei count) {
87 glWeightPointerOES(size, type, stride, pointer);
90 // ----------------------------------------------------------------------------
91 // Actual GL entry-points
92 // ----------------------------------------------------------------------------
96 #undef CALL_GL_API_RETURN
98 #if USE_FAST_TLS_KEY && !CHECK_FOR_GL_ERRORS
100 #ifdef HAVE_ARM_TLS_REGISTER
101 #define GET_TLS(reg) \
102 "mrc p15, 0, " #reg ", c13, c0, 3 \n"
104 #define GET_TLS(reg) \
105 "mov " #reg ", #0xFFFF0FFF \n" \
106 "ldr " #reg ", [" #reg ", #-15] \n"
109 #define API_ENTRY(_api) __attribute__((naked)) _api
111 #define CALL_GL_API(_api, ...) \
114 "ldr r12, [r12, %[tls]] \n" \
116 "ldrne pc, [r12, %[api]] \n" \
120 : [tls] "J"(TLS_SLOT_OPENGL_API*4), \
121 [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api)) \
125 #define CALL_GL_API_RETURN(_api, ...) \
126 CALL_GL_API(_api, __VA_ARGS__) \
127 return 0; // placate gcc's warnings. never reached.
131 #if CHECK_FOR_GL_ERRORS
133 #define CHECK_GL_ERRORS(_api) \
134 do { GLint err = glGetError(); \
135 ALOGE_IF(err != GL_NO_ERROR, "%s failed (0x%04X)", #_api, err); \
140 #define CHECK_GL_ERRORS(_api) do { } while(false);
145 #define API_ENTRY(_api) _api
147 #define CALL_GL_API(_api, ...) \
148 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
149 _c->_api(__VA_ARGS__); \
150 CHECK_GL_ERRORS(_api)
152 #define CALL_GL_API_RETURN(_api, ...) \
153 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
154 return _c->_api(__VA_ARGS__)
161 #include "glext_api.in"
166 #undef CALL_GL_API_RETURN
169 * glGetString() is special because we expose some extensions in the wrapper
172 extern "C" const GLubyte * __glGetString(GLenum name);
174 const GLubyte * glGetString(GLenum name)
176 const GLubyte * ret = egl_get_string_for_current_context(name);
178 ret = __glGetString(name);
184 * These GL calls are special because they need to EGL to retrieve some
185 * informations before they can execute.
188 extern "C" void __glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image);
189 extern "C" void __glEGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image);
192 void glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image)
194 GLeglImageOES implImage =
195 (GLeglImageOES)egl_get_image_for_current_context((EGLImageKHR)image);
196 __glEGLImageTargetTexture2DOES(target, implImage);
199 void glEGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image)
201 GLeglImageOES implImage =
202 (GLeglImageOES)egl_get_image_for_current_context((EGLImageKHR)image);
203 __glEGLImageTargetRenderbufferStorageOES(target, implImage);