1/*
2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26#ifndef OGLFuncs_h_Included
27#define OGLFuncs_h_Included
28
29#ifdef MACOSX
30#include <dlfcn.h>
31#endif
32#include "jni.h"
33#include "J2D_GL/gl.h"
34#include "J2D_GL/glext.h"
35#include "OGLFuncMacros.h"
36#include "OGLFuncs_md.h"
37#include "Trace.h"
38
39jboolean OGLFuncs_OpenLibrary();
40void OGLFuncs_CloseLibrary();
41jboolean OGLFuncs_InitPlatformFuncs();
42jboolean OGLFuncs_InitBaseFuncs();
43jboolean OGLFuncs_InitExtFuncs();
44
45/**
46 * Core OpenGL 1.1 function typedefs
47 */
48typedef void (GLAPIENTRY *glAlphaFuncType)(GLenum func, GLclampf ref);
49typedef GLboolean (GLAPIENTRY *glAreTexturesResidentType)(GLsizei n, const GLuint *textures, GLboolean *residences);
50typedef void (GLAPIENTRY *glBeginType)(GLenum mode);
51typedef void (GLAPIENTRY *glBindTextureType)(GLenum target, GLuint texture);
52typedef void (GLAPIENTRY *glBitmapType)(GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, const GLubyte *bitmap);
53typedef void (GLAPIENTRY *glBlendFuncType)(GLenum sfactor, GLenum dfactor);
54typedef void (GLAPIENTRY *glClearType)(GLbitfield mask);
55typedef void (GLAPIENTRY *glClearColorType)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
56typedef void (GLAPIENTRY *glClearDepthType)(GLclampd depth);
57typedef void (GLAPIENTRY *glColor3ubType)(GLubyte red, GLubyte green, GLubyte blue);
58typedef void (GLAPIENTRY *glColor4fType)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
59typedef void (GLAPIENTRY *glColor4ubType)(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha);
60typedef void (GLAPIENTRY *glColorMaskType)(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
61typedef void (GLAPIENTRY *glColorPointerType)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
62typedef void (GLAPIENTRY *glCopyPixelsType)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type);
63typedef void (GLAPIENTRY *glCopyTexSubImage2DType)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
64typedef void (GLAPIENTRY *glDeleteTexturesType)(GLsizei n, const GLuint *textures);
65typedef void (GLAPIENTRY *glDepthFuncType)(GLenum func);
66typedef void (GLAPIENTRY *glDisableType)(GLenum cap);
67typedef void (GLAPIENTRY *glDisableClientStateType)(GLenum array);
68typedef void (GLAPIENTRY *glDrawArraysType)(GLenum mode, GLint first, GLsizei count);
69typedef void (GLAPIENTRY *glDrawBufferType)(GLenum mode);
70typedef void (GLAPIENTRY *glDrawPixelsType)(GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
71typedef void (GLAPIENTRY *glEnableType)(GLenum cap);
72typedef void (GLAPIENTRY *glEnableClientStateType)(GLenum array);
73typedef void (GLAPIENTRY *glEndType)(void);
74typedef void (GLAPIENTRY *glFinishType)(void);
75typedef void (GLAPIENTRY *glFlushType)(void);
76typedef void (GLAPIENTRY *glGenTexturesType)(GLsizei n, GLuint *textures);
77typedef void (GLAPIENTRY *glGetBooleanvType)(GLenum pname, GLboolean *params);
78typedef void (GLAPIENTRY *glGetDoublevType)(GLenum pname, GLdouble *params);
79typedef GLenum (GLAPIENTRY *glGetErrorType)(void);
80typedef void (GLAPIENTRY *glGetFloatvType)(GLenum pname, GLfloat *params);
81typedef void (GLAPIENTRY *glGetIntegervType)(GLenum pname, GLint *params);
82typedef const GLubyte * (GLAPIENTRY *glGetStringType)(GLenum name);
83typedef void (GLAPIENTRY *glGetTexLevelParameterivType)(GLenum target, GLint level, GLenum pname, GLint *params);
84typedef void (GLAPIENTRY *glHintType)(GLenum target, GLenum mode);
85typedef void (GLAPIENTRY *glInterleavedArraysType)(GLenum format, GLsizei stride, const GLvoid *pointer);
86typedef GLboolean (GLAPIENTRY *glIsEnabledType)(GLenum cap);
87typedef GLboolean (GLAPIENTRY *glIsTextureType)(GLuint texture);
88typedef void (GLAPIENTRY *glLoadIdentityType)(void);
89typedef void (GLAPIENTRY *glLoadMatrixdType)(const GLdouble *m);
90typedef void (GLAPIENTRY *glLogicOpType)(GLenum opcode);
91typedef void (GLAPIENTRY *glMatrixModeType)(GLenum mode);
92typedef void (GLAPIENTRY *glOrthoType)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
93typedef void (GLAPIENTRY *glPixelStoreiType)(GLenum pname, GLint param);
94typedef void (GLAPIENTRY *glPixelTransferfType)(GLenum pname, GLfloat param);
95typedef void (GLAPIENTRY *glPixelZoomType)(GLfloat xfactor, GLfloat yfactor);
96typedef void (GLAPIENTRY *glPolygonOffsetType)(GLfloat factor, GLfloat units);
97typedef void (GLAPIENTRY *glPopAttribType)(void);
98typedef void (GLAPIENTRY *glPopClientAttribType)(void);
99typedef void (GLAPIENTRY *glPopMatrixType)(void);
100typedef void (GLAPIENTRY *glPrioritizeTexturesType)(GLsizei n, const GLuint *textures, const GLclampf *priorities);
101typedef void (GLAPIENTRY *glPushAttribType)(GLbitfield);
102typedef void (GLAPIENTRY *glPushClientAttribType)(GLbitfield);
103typedef void (GLAPIENTRY *glPushMatrixType)(void);
104typedef void (GLAPIENTRY *glRasterPos2iType)(GLint x, GLint y);
105typedef void (GLAPIENTRY *glReadBufferType)(GLenum mode);
106typedef void (GLAPIENTRY *glReadPixelsType)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
107typedef void (GLAPIENTRY *glRectiType)(GLint x1, GLint y1, GLint x2, GLint y2);
108typedef void (GLAPIENTRY *glScalefType)(GLfloat x, GLfloat y, GLfloat z);
109typedef void (GLAPIENTRY *glScissorType)(GLint x, GLint y, GLsizei width, GLsizei height);
110typedef void (GLAPIENTRY *glTexCoord2dType)(GLdouble s, GLdouble t);
111typedef void (GLAPIENTRY *glTexCoord2fType)(GLfloat s, GLfloat t);
112typedef void (GLAPIENTRY *glTexCoordPointerType)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
113typedef void (GLAPIENTRY *glTexEnviType)(GLenum target, GLenum pname, GLint param);
114typedef void (GLAPIENTRY *glTexGeniType)(GLenum coord, GLenum pname, GLint param);
115typedef void (GLAPIENTRY *glTexGendvType)(GLenum coord, GLenum pname, const GLdouble *params);
116typedef void (GLAPIENTRY *glTexImage1DType)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
117typedef void (GLAPIENTRY *glTexImage2DType)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
118typedef void (GLAPIENTRY *glTexParameteriType)(GLenum target, GLenum pname, GLint param);
119typedef void (GLAPIENTRY *glTexSubImage1DType)(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels);
120typedef void (GLAPIENTRY *glTexSubImage2DType)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
121typedef void (GLAPIENTRY *glTranslatefType)(GLfloat x, GLfloat y, GLfloat z);
122typedef void (GLAPIENTRY *glVertex2dType)(GLdouble x, GLdouble y);
123typedef void (GLAPIENTRY *glVertex2fType)(GLfloat x, GLfloat y);
124typedef void (GLAPIENTRY *glVertex2iType)(GLint x, GLint y);
125typedef void (GLAPIENTRY *glVertexPointerType)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
126typedef void (GLAPIENTRY *glViewportType)(GLint x, GLint y, GLsizei width, GLsizei height);
127
128/**
129 * OpenGL 1.2 and extension function typedefs (functions that were added in
130 * the 1.2 spec and later need to be loaded on Windows as if they were
131 * extensions, which is why they are called out separately here)
132 */
133typedef void (GLAPIENTRY *glActiveTextureARBType)(GLenum texture);
134typedef void (GLAPIENTRY *glMultiTexCoord2fARBType)(GLenum texture, GLfloat s, GLfloat t);
135typedef void (GLAPIENTRY *glTexImage3DType)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
136
137/**
138 * GL_EXT_framebuffer_object function typedefs
139 */
140typedef void (GLAPIENTRY *glBindRenderbufferEXTType)(GLenum, GLuint);
141typedef void (GLAPIENTRY *glDeleteRenderbuffersEXTType)(GLsizei, const GLuint *);
142typedef void (GLAPIENTRY *glGenRenderbuffersEXTType)(GLsizei, GLuint *);
143typedef void (GLAPIENTRY *glRenderbufferStorageEXTType)(GLenum, GLenum, GLsizei, GLsizei);
144typedef void (GLAPIENTRY *glBindFramebufferEXTType)(GLenum, GLuint);
145typedef void (GLAPIENTRY *glDeleteFramebuffersEXTType)(GLsizei, const GLuint *);
146typedef void (GLAPIENTRY *glGenFramebuffersEXTType)(GLsizei, GLuint *);
147typedef GLenum (GLAPIENTRY *glCheckFramebufferStatusEXTType)(GLenum);
148typedef void (GLAPIENTRY *glFramebufferTexture2DEXTType)(GLenum, GLenum, GLenum, GLuint, GLint);
149typedef void (GLAPIENTRY *glFramebufferRenderbufferEXTType)(GLenum, GLenum, GLenum, GLuint);
150
151/**
152 * GL_ARB_fragment_shader extension function typedefs
153 */
154typedef GLhandleARB (GLAPIENTRY *glCreateShaderObjectARBType)(GLenum);
155typedef void (GLAPIENTRY *glShaderSourceARBType)(GLhandleARB, GLsizei, const GLcharARB* *, const GLint *);
156typedef void (GLAPIENTRY *glCompileShaderARBType)(GLhandleARB);
157typedef void (GLAPIENTRY *glUseProgramObjectARBType)(GLhandleARB);
158typedef void (GLAPIENTRY *glUniform1iARBType)(GLint, GLint);
159typedef void (GLAPIENTRY *glUniform1fARBType)(GLint, GLfloat);
160typedef void (GLAPIENTRY *glUniform1fvARBType)(GLint, GLsizei, const GLfloat *);
161typedef void (GLAPIENTRY *glUniform2fARBType)(GLint, GLfloat, GLfloat);
162typedef void (GLAPIENTRY *glUniform3fARBType)(GLint, GLfloat, GLfloat, GLfloat);
163typedef void (GLAPIENTRY *glUniform3fvARBType)(GLint, GLsizei, const GLfloat *);
164typedef void (GLAPIENTRY *glUniform4fARBType)(GLint, GLfloat, GLfloat, GLfloat, GLfloat);
165typedef void (GLAPIENTRY *glUniform4fvARBType)(GLint, GLsizei, const GLfloat *);
166typedef GLint (GLAPIENTRY *glGetUniformLocationARBType)(GLhandleARB, const GLcharARB *);
167typedef void (GLAPIENTRY *glGetInfoLogARBType)(GLhandleARB, GLsizei, GLsizei *, GLcharARB *);
168typedef void (GLAPIENTRY *glGetProgramivARBType)(GLenum, GLenum, GLint *);
169typedef void (GLAPIENTRY *glGetObjectParameterivARBType)(GLhandleARB, GLenum, GLint *);
170typedef GLhandleARB (GLAPIENTRY *glCreateProgramObjectARBType)(void);
171typedef void (GLAPIENTRY *glAttachObjectARBType)(GLhandleARB, GLhandleARB);
172typedef void (GLAPIENTRY *glLinkProgramARBType)(GLhandleARB);
173typedef void (GLAPIENTRY *glDeleteObjectARBType)(GLhandleARB);
174
175/**
176 * GL_NV_texture_barrier extension function typedef's
177 */
178typedef void (GLAPIENTRY *glTextureBarrierNVType) (void);
179
180/**
181 * REMIND: this caused an internal error in the MS compiler!?!?
182 *
183 *#define OGL_CHECK_FUNC_ERR(f) \
184 * J2dTrace1(J2D_TRACE_ERROR, "could not load function: %s", #f)
185 */
186
187#define OGL_CHECK_FUNC_ERR(f) \
188 J2dRlsTraceLn(J2D_TRACE_ERROR, #f)
189
190#define OGL_INIT_FUNC(f) \
191 OGL_J2D_MANGLE(f) = (OGL_FUNC_TYPE(f)) OGL_GET_PROC_ADDRESS(f)
192
193#define OGL_INIT_AND_CHECK_FUNC(f) \
194 OGL_INIT_FUNC(f); \
195 if (OGL_J2D_MANGLE(f) == NULL) { \
196 OGL_CHECK_FUNC_ERR(f); \
197 return JNI_FALSE; \
198 }
199
200#define OGL_INIT_EXT_FUNC(f) \
201 OGL_J2D_MANGLE(f) = (OGL_FUNC_TYPE(f)) OGL_GET_EXT_PROC_ADDRESS(f)
202
203#define OGL_INIT_AND_CHECK_EXT_FUNC(f) \
204 OGL_INIT_EXT_FUNC(f); \
205 if (OGL_J2D_MANGLE(f) == NULL) { \
206 OGL_CHECK_FUNC_ERR(f); \
207 return JNI_FALSE; \
208 }
209
210#define OGL_EXPRESS_BASE_FUNCS(action) \
211 OGL_##action##_FUNC(glAlphaFunc); \
212 OGL_##action##_FUNC(glAreTexturesResident); \
213 OGL_##action##_FUNC(glBegin); \
214 OGL_##action##_FUNC(glBindTexture); \
215 OGL_##action##_FUNC(glBitmap); \
216 OGL_##action##_FUNC(glBlendFunc); \
217 OGL_##action##_FUNC(glClear); \
218 OGL_##action##_FUNC(glClearColor); \
219 OGL_##action##_FUNC(glClearDepth); \
220 OGL_##action##_FUNC(glColor3ub); \
221 OGL_##action##_FUNC(glColor4f); \
222 OGL_##action##_FUNC(glColor4ub); \
223 OGL_##action##_FUNC(glColorMask); \
224 OGL_##action##_FUNC(glColorPointer); \
225 OGL_##action##_FUNC(glCopyPixels); \
226 OGL_##action##_FUNC(glCopyTexSubImage2D); \
227 OGL_##action##_FUNC(glDeleteTextures); \
228 OGL_##action##_FUNC(glDepthFunc); \
229 OGL_##action##_FUNC(glDisable); \
230 OGL_##action##_FUNC(glDisableClientState); \
231 OGL_##action##_FUNC(glDrawArrays); \
232 OGL_##action##_FUNC(glDrawBuffer); \
233 OGL_##action##_FUNC(glDrawPixels); \
234 OGL_##action##_FUNC(glEnable); \
235 OGL_##action##_FUNC(glEnableClientState); \
236 OGL_##action##_FUNC(glEnd); \
237 OGL_##action##_FUNC(glFinish); \
238 OGL_##action##_FUNC(glFlush); \
239 OGL_##action##_FUNC(glGenTextures); \
240 OGL_##action##_FUNC(glGetBooleanv); \
241 OGL_##action##_FUNC(glGetDoublev); \
242 OGL_##action##_FUNC(glGetError); \
243 OGL_##action##_FUNC(glGetFloatv); \
244 OGL_##action##_FUNC(glGetIntegerv); \
245 OGL_##action##_FUNC(glGetString); \
246 OGL_##action##_FUNC(glGetTexLevelParameteriv); \
247 OGL_##action##_FUNC(glHint); \
248 OGL_##action##_FUNC(glInterleavedArrays); \
249 OGL_##action##_FUNC(glIsEnabled); \
250 OGL_##action##_FUNC(glIsTexture); \
251 OGL_##action##_FUNC(glLoadIdentity); \
252 OGL_##action##_FUNC(glLoadMatrixd); \
253 OGL_##action##_FUNC(glLogicOp); \
254 OGL_##action##_FUNC(glMatrixMode); \
255 OGL_##action##_FUNC(glOrtho); \
256 OGL_##action##_FUNC(glPixelStorei); \
257 OGL_##action##_FUNC(glPixelTransferf); \
258 OGL_##action##_FUNC(glPixelZoom); \
259 OGL_##action##_FUNC(glPolygonOffset); \
260 OGL_##action##_FUNC(glPopAttrib); \
261 OGL_##action##_FUNC(glPopClientAttrib); \
262 OGL_##action##_FUNC(glPopMatrix); \
263 OGL_##action##_FUNC(glPrioritizeTextures); \
264 OGL_##action##_FUNC(glPushAttrib); \
265 OGL_##action##_FUNC(glPushClientAttrib); \
266 OGL_##action##_FUNC(glPushMatrix); \
267 OGL_##action##_FUNC(glRasterPos2i); \
268 OGL_##action##_FUNC(glReadBuffer); \
269 OGL_##action##_FUNC(glReadPixels); \
270 OGL_##action##_FUNC(glRecti); \
271 OGL_##action##_FUNC(glScalef); \
272 OGL_##action##_FUNC(glScissor); \
273 OGL_##action##_FUNC(glTexCoord2d); \
274 OGL_##action##_FUNC(glTexCoord2f); \
275 OGL_##action##_FUNC(glTexCoordPointer); \
276 OGL_##action##_FUNC(glTexEnvi); \
277 OGL_##action##_FUNC(glTexGeni); \
278 OGL_##action##_FUNC(glTexGendv); \
279 OGL_##action##_FUNC(glTexImage1D); \
280 OGL_##action##_FUNC(glTexImage2D); \
281 OGL_##action##_FUNC(glTexParameteri); \
282 OGL_##action##_FUNC(glTexSubImage1D); \
283 OGL_##action##_FUNC(glTexSubImage2D); \
284 OGL_##action##_FUNC(glTranslatef); \
285 OGL_##action##_FUNC(glVertex2d); \
286 OGL_##action##_FUNC(glVertex2f); \
287 OGL_##action##_FUNC(glVertex2i); \
288 OGL_##action##_FUNC(glVertexPointer); \
289 OGL_##action##_FUNC(glViewport);
290
291#define OGL_EXPRESS_EXT_FUNCS(action) \
292 OGL_##action##_EXT_FUNC(glActiveTextureARB); \
293 OGL_##action##_EXT_FUNC(glMultiTexCoord2fARB); \
294 OGL_##action##_EXT_FUNC(glTexImage3D); \
295 OGL_##action##_EXT_FUNC(glBindRenderbufferEXT); \
296 OGL_##action##_EXT_FUNC(glDeleteRenderbuffersEXT); \
297 OGL_##action##_EXT_FUNC(glGenRenderbuffersEXT); \
298 OGL_##action##_EXT_FUNC(glRenderbufferStorageEXT); \
299 OGL_##action##_EXT_FUNC(glBindFramebufferEXT); \
300 OGL_##action##_EXT_FUNC(glDeleteFramebuffersEXT); \
301 OGL_##action##_EXT_FUNC(glGenFramebuffersEXT); \
302 OGL_##action##_EXT_FUNC(glCheckFramebufferStatusEXT); \
303 OGL_##action##_EXT_FUNC(glFramebufferTexture2DEXT); \
304 OGL_##action##_EXT_FUNC(glFramebufferRenderbufferEXT); \
305 OGL_##action##_EXT_FUNC(glCreateProgramObjectARB); \
306 OGL_##action##_EXT_FUNC(glAttachObjectARB); \
307 OGL_##action##_EXT_FUNC(glLinkProgramARB); \
308 OGL_##action##_EXT_FUNC(glCreateShaderObjectARB); \
309 OGL_##action##_EXT_FUNC(glShaderSourceARB); \
310 OGL_##action##_EXT_FUNC(glCompileShaderARB); \
311 OGL_##action##_EXT_FUNC(glUseProgramObjectARB); \
312 OGL_##action##_EXT_FUNC(glUniform1iARB); \
313 OGL_##action##_EXT_FUNC(glUniform1fARB); \
314 OGL_##action##_EXT_FUNC(glUniform1fvARB); \
315 OGL_##action##_EXT_FUNC(glUniform2fARB); \
316 OGL_##action##_EXT_FUNC(glUniform3fARB); \
317 OGL_##action##_EXT_FUNC(glUniform3fvARB); \
318 OGL_##action##_EXT_FUNC(glUniform4fARB); \
319 OGL_##action##_EXT_FUNC(glUniform4fvARB); \
320 OGL_##action##_EXT_FUNC(glGetUniformLocationARB); \
321 OGL_##action##_EXT_FUNC(glGetProgramivARB); \
322 OGL_##action##_EXT_FUNC(glGetInfoLogARB); \
323 OGL_##action##_EXT_FUNC(glGetObjectParameterivARB); \
324 OGL_##action##_EXT_FUNC(glDeleteObjectARB); \
325 OGL_##action##_EXT_FUNC(glTextureBarrierNV);
326
327#define OGL_EXPRESS_ALL_FUNCS(action) \
328 OGL_EXPRESS_BASE_FUNCS(action) \
329 OGL_EXPRESS_EXT_FUNCS(action) \
330 OGL_EXPRESS_PLATFORM_FUNCS(action) \
331 OGL_EXPRESS_PLATFORM_EXT_FUNCS(action)
332
333OGL_EXPRESS_ALL_FUNCS(EXTERN)
334
335#endif /* OGLFuncs_h_Included */
336