• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* San Angeles Observation OpenGL ES version example
2  * Copyright 2004-2005 Jetro Lauha
3  * All rights reserved.
4  * Web: http://iki.fi/jetro/
5  *
6  * This source is free software; you can redistribute it and/or
7  * modify it under the terms of EITHER:
8  *   (1) The GNU Lesser General Public License as published by the Free
9  *       Software Foundation; either version 2.1 of the License, or (at
10  *       your option) any later version. The text of the GNU Lesser
11  *       General Public License is included with this source in the
12  *       file LICENSE-LGPL.txt.
13  *   (2) The BSD-style license that is included with this source in
14  *       the file LICENSE-BSD.txt.
15  *
16  * This source is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files
19  * LICENSE-LGPL.txt and LICENSE-BSD.txt for more details.
20  *
21  * $Id: importgl.h,v 1.4 2005/02/24 20:29:33 tonic Exp $
22  * $Revision: 1.4 $
23  */
24 
25 #ifndef IMPORTGL_H_INCLUDED
26 #define IMPORTGL_H_INCLUDED
27 
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #include <GLES2/gl2.h>
34 
35 /* Use DISABLE_IMPORTGL if you want to link the OpenGL ES at
36  * compile/link time and not import it dynamically runtime.
37  */
38 #ifndef DISABLE_IMPORTGL
39 
40 
41 /* Dynamically fetches pointers to the gl functions.
42  * Should be called once on application initialization.
43  * Returns non-zero on success and 0 on failure.
44  */
45 extern int importGLInit();
46 
47 
48 #ifndef IMPORTGL_API
49 #define IMPORTGL_API extern
50 #endif
51 #ifndef IMPORTGL_FNPTRINIT
52 #define IMPORTGL_FNPTRINIT
53 #endif
54 
55 #define FNDEF(retType, funcName, args) \
56         IMPORTGL_API retType (*funcPtr_##funcName) args IMPORTGL_FNPTRINIT;\
57         typedef retType (*funcType_##funcName) args
58 
59 
60 FNDEF(void, glAttachShader, (GLuint program, GLuint shader));
61 FNDEF(void, glBindBuffer, (GLenum target, GLuint buffer));
62 FNDEF(void, glBlendFunc, (GLenum sfactor, GLenum dfactor));
63 FNDEF(void, glBufferData, (GLenum target, GLsizeiptr size,
64                            const void* data, GLenum usage));
65 FNDEF(void, glBufferSubData, (GLenum target, GLintptr offset,
66                               GLsizeiptr size, const void* data));
67 FNDEF(void, glClear, (GLbitfield mask));
68 FNDEF(void, glClearColor, (GLclampf red, GLclampf green, GLclampf blue,
69                            GLclampf alpha));
70 FNDEF(void, glCompileShader, (GLuint shader));
71 FNDEF(GLuint, glCreateProgram, (void));
72 FNDEF(GLuint, glCreateShader, (GLenum type));
73 FNDEF(void, glDeleteBuffers, (GLsizei n, const GLuint* buffers));
74 FNDEF(void, glDeleteProgram, (GLuint program));
75 FNDEF(void, glDeleteShader, (GLuint shader));
76 FNDEF(void, glDisable, (GLenum cap));
77 FNDEF(void, glDisableVertexAttribArray, (GLuint index));
78 FNDEF(void, glDrawArrays, (GLenum mode, GLint first, GLsizei count));
79 FNDEF(void, glEnable, (GLenum cap));
80 FNDEF(void, glEnableVertexAttribArray, (GLuint index));
81 FNDEF(void, glGenBuffers, (GLsizei n, GLuint* buffers));
82 FNDEF(int, glGetAttribLocation, (GLuint program, const char* name));
83 FNDEF(GLenum, glGetError, (void));
84 FNDEF(void, glGetShaderiv, (GLuint shader, GLenum pname, GLint* params));
85 FNDEF(void, glGetShaderInfoLog, (GLuint shader, GLsizei bufsize,
86                                  GLsizei* length, char* infolog));
87 FNDEF(int, glGetUniformLocation, (GLuint program, const char* name));
88 FNDEF(void, glLinkProgram, (GLuint program));
89 FNDEF(void, glShaderSource, (GLuint shader, GLsizei count,
90                              const char** string, const GLint* length));
91 FNDEF(void, glUniform1f, (GLint location, GLfloat x));
92 FNDEF(void, glUniform3fv, (GLint location, GLsizei count, const GLfloat* v));
93 FNDEF(void, glUniform4fv, (GLint location, GLsizei count, const GLfloat* v));
94 FNDEF(void, glUniformMatrix3fv, (GLint location, GLsizei count,
95                                  GLboolean transpose, const GLfloat* value));
96 FNDEF(void, glUniformMatrix4fv, (GLint location, GLsizei count,
97                                  GLboolean transpose, const GLfloat* value));
98 FNDEF(void, glUseProgram, (GLuint program));
99 FNDEF(void, glVertexAttribPointer, (GLuint indx, GLint size, GLenum type,
100                                     GLboolean normalized, GLsizei stride,
101                                     const void* ptr));
102 FNDEF(void, glViewport, (GLint x, GLint y, GLsizei width, GLsizei height));
103 
104 #undef FN
105 #define FNPTR(name) funcPtr_##name
106 
107 #ifndef IMPORTGL_NO_FNPTR_DEFS
108 
109 // Redirect gl* function calls to funcPtr_gl*.
110 
111 #define glAttachShader              FNPTR(glAttachShader)
112 #define glBindBuffer                FNPTR(glBindBuffer)
113 #define glBlendFunc                 FNPTR(glBlendFunc)
114 #define glBufferData                FNPTR(glBufferData)
115 #define glBufferSubData             FNPTR(glBufferSubData)
116 #define glClear                     FNPTR(glClear)
117 #define glClearColor                FNPTR(glClearColor)
118 #define glCompileShader             FNPTR(glCompileShader)
119 #define glCreateProgram             FNPTR(glCreateProgram)
120 #define glCreateShader              FNPTR(glCreateShader)
121 #define glDeleteBuffers             FNPTR(glDeleteBuffers)
122 #define glDeleteProgram             FNPTR(glDeleteProgram)
123 #define glDeleteShader              FNPTR(glDeleteShader)
124 #define glDisable                   FNPTR(glDisable)
125 #define glDisableVertexAttribArray  FNPTR(glDisableVertexAttribArray)
126 #define glDrawArrays                FNPTR(glDrawArrays)
127 #define glEnable                    FNPTR(glEnable)
128 #define glEnableVertexAttribArray   FNPTR(glEnableVertexAttribArray)
129 #define glGenBuffers                FNPTR(glGenBuffers)
130 #define glGetAttribLocation         FNPTR(glGetAttribLocation)
131 #define glGetError                  FNPTR(glGetError)
132 #define glGetShaderiv               FNPTR(glGetShaderiv)
133 #define glGetShaderInfoLog          FNPTR(glGetShaderInfoLog)
134 #define glGetUniformLocation        FNPTR(glGetUniformLocation)
135 
136 #define glLinkProgram               FNPTR(glLinkProgram)
137 #define glShaderSource              FNPTR(glShaderSource)
138 #define glUniform1f                 FNPTR(glUniform1f)
139 #define glUniform3fv                FNPTR(glUniform3fv)
140 #define glUniform4fv                FNPTR(glUniform4fv)
141 #define glUniformMatrix3fv          FNPTR(glUniformMatrix3fv)
142 #define glUniformMatrix4fv          FNPTR(glUniformMatrix4fv)
143 #define glUseProgram                FNPTR(glUseProgram)
144 #define glViewport                  FNPTR(glViewport)
145 #define glVertexAttribPointer       FNPTR(glVertexAttribPointer)
146 
147 #endif // !IMPORTGL_NO_FNPTR_DEFS
148 
149 
150 #endif // !DISABLE_IMPORTGL
151 
152 
153 #ifdef __cplusplus
154 }
155 #endif
156 
157 
158 #endif // !IMPORTGL_H_INCLUDED
159