1 /**
2 * @file
3 * @brief OpenGL bindings
4 */
5
6 /*
7 Copyright (C) 1997-2001 Id Software, Inc.
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18 See the GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24 */
25
26 #pragma once
27
28 #ifdef ANDROID
29 #include "../../ports/android/r_gles_android.h"
30 #include <stdlib.h>
31 #else
32 #include <SDL_opengl.h>
33 #endif
34
R_DrawArrays(GLint first,GLsizei count)35 inline void R_DrawArrays (GLint first, GLsizei count) {
36 #ifdef GL_VERSION_ES_CM_1_0
37 const int cnt = count / 4;
38 for (int i = 0; i < cnt; i++)
39 glDrawArrays(GL_TRIANGLE_FAN, i * 4, 4);
40 #else
41 glDrawArrays(GL_QUADS, first, count);
42 #endif
43 }
44
45 #ifdef GL_VERSION_ES_CM_1_0
46 /* glDrawElements() cannot be invoked with GL_UNSIGNED_INT on GLES */
47 typedef GLushort glElementIndex_t;
48 #define GL_ELEMENT_INDEX_TYPE GL_UNSIGNED_SHORT
49
50 #define glOrtho glOrthof
51 #define glFrustum glFrustumf
52 #define glFogi glFogx
53 #define glDepthRange glDepthRangef
54 /* Stub, so that we won't clutter the code with #ifdefs */
55 #define glPolygonMode(x, y)
56 #else
57 typedef GLuint glElementIndex_t;
58 #define GL_ELEMENT_INDEX_TYPE GL_UNSIGNED_INT
59 #endif
60
61 /** @todo update SDL to version that includes these */
62 #ifndef GL_READ_FRAMEBUFFER_EXT
63 #define GL_READ_FRAMEBUFFER_EXT 0x8CA8
64 #endif
65
66 #ifndef GL_DRAW_FRAMEBUFFER_EXT
67 #define GL_DRAW_FRAMEBUFFER_EXT 0x8CA9
68 #endif
69
70 #ifndef QGL_EXTERN
71 #define QGL_EXTERN extern
72 #endif
73
74 /* internally defined convenience constant */
75 /* @todo sanitize those */
76 #define GL_TANGENT_ARRAY -1
77 #define GL_NEXT_VERTEX_ARRAY -2
78 #define GL_NEXT_NORMAL_ARRAY -3
79 #define GL_NEXT_TANGENT_ARRAY -4
80
81 /* multitexture */
82 QGL_EXTERN void (APIENTRY* qglActiveTexture)(GLenum texture);
83 QGL_EXTERN void (APIENTRY* qglClientActiveTexture)(GLenum texture);
84
85 /* vertex buffer objects */
86 QGL_EXTERN void (APIENTRY* qglGenBuffers) (GLuint count, GLuint* id);
87 QGL_EXTERN void (APIENTRY* qglDeleteBuffers) (GLuint count, GLuint* id);
88 QGL_EXTERN void (APIENTRY* qglBindBuffer) (GLenum target, GLuint id);
89 QGL_EXTERN void (APIENTRY* qglBufferData) (GLenum target, GLsizei size, const GLvoid* data, GLenum usage);
90
91 /* vertex attribute arrays */
92 QGL_EXTERN void (APIENTRY* qglEnableVertexAttribArray)(GLuint index);
93 QGL_EXTERN void (APIENTRY* qglDisableVertexAttribArray)(GLuint index);
94 QGL_EXTERN void (APIENTRY* qglVertexAttribPointer)(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* pointer);
95
96 /* glsl vertex and fragment shaders and programs */
97 QGL_EXTERN GLuint (APIENTRY* qglCreateShader)(GLenum type);
98 QGL_EXTERN void (APIENTRY* qglDeleteShader)(GLuint id);
99 QGL_EXTERN void (APIENTRY* qglShaderSource)(GLuint id, GLuint count, GLchar** sources, GLuint* len);
100 QGL_EXTERN void (APIENTRY* qglCompileShader)(GLuint id);
101 QGL_EXTERN void (APIENTRY* qglGetShaderiv)(GLuint id, GLenum field, GLuint* dest);
102 QGL_EXTERN void (APIENTRY* qglGetShaderInfoLog)(GLuint id, GLuint maxlen, GLuint* len, GLchar* dest);
103 QGL_EXTERN GLuint (APIENTRY* qglCreateProgram)(void);
104 QGL_EXTERN void (APIENTRY* qglDeleteProgram)(GLuint id);
105 QGL_EXTERN void (APIENTRY* qglAttachShader)(GLuint prog, GLuint shader);
106 QGL_EXTERN void (APIENTRY* qglDetachShader)(GLuint prog, GLuint shader);
107 QGL_EXTERN void (APIENTRY* qglLinkProgram)(GLuint id);
108 QGL_EXTERN void (APIENTRY* qglUseProgram)(GLuint id);
109 QGL_EXTERN void (APIENTRY* qglGetProgramiv)(GLuint id, GLenum field, GLuint* dest);
110 QGL_EXTERN void (APIENTRY* qglGetActiveUniform)(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint* size, GLenum *type, GLchar* name);
111 QGL_EXTERN void (APIENTRY* qglGetProgramInfoLog)(GLuint id, GLuint maxlen, GLuint* len, GLchar* dest);
112 QGL_EXTERN GLint (APIENTRY* qglGetUniformLocation)(GLuint id, const GLchar* name);
113 QGL_EXTERN void (APIENTRY* qglUniform1i)(GLint location, GLint i);
114 QGL_EXTERN void (APIENTRY* qglUniform1f)(GLint location, GLfloat f);
115 QGL_EXTERN void (APIENTRY* qglUniform1fv)(GLint location, int count, GLfloat* f);
116 QGL_EXTERN void (APIENTRY* qglUniform2fv)(GLint location, int count, GLfloat* f);
117 QGL_EXTERN void (APIENTRY* qglUniform3fv)(GLint location, int count, GLfloat* f);
118 QGL_EXTERN void (APIENTRY* qglUniform4fv)(GLint location, int count, GLfloat* f);
119 QGL_EXTERN GLint (APIENTRY* qglGetAttribLocation)(GLuint id, const GLchar* name);
120 QGL_EXTERN void (APIENTRY* qglUniformMatrix4fv)(GLint location, int count, GLboolean transpose, GLfloat* v);
121
122 /* frame buffer objects (fbo) */
123 QGL_EXTERN GLboolean (APIENTRY* qglIsRenderbufferEXT) (GLuint);
124 QGL_EXTERN void (APIENTRY* qglBindRenderbufferEXT) (GLenum, GLuint);
125 QGL_EXTERN void (APIENTRY* qglDeleteRenderbuffersEXT) (GLsizei, const GLuint*);
126 QGL_EXTERN void (APIENTRY* qglGenRenderbuffersEXT) (GLsizei, GLuint*);
127 QGL_EXTERN void (APIENTRY* qglRenderbufferStorageEXT) (GLenum, GLenum, GLsizei, GLsizei);
128 QGL_EXTERN void (APIENTRY* qglRenderbufferStorageMultisampleEXT) (GLenum, GLsizei, GLenum, GLsizei, GLsizei);
129 QGL_EXTERN void (APIENTRY* qglGetRenderbufferParameterivEXT) (GLenum, GLenum, GLint*);
130 QGL_EXTERN GLboolean (APIENTRY* qglIsFramebufferEXT) (GLuint);
131 QGL_EXTERN void (APIENTRY* qglBindFramebufferEXT) (GLenum, GLuint);
132 QGL_EXTERN void (APIENTRY* qglDeleteFramebuffersEXT) (GLsizei, const GLuint*);
133 QGL_EXTERN void (APIENTRY* qglGenFramebuffersEXT) (GLsizei, GLuint*);
134 QGL_EXTERN GLenum (APIENTRY* qglCheckFramebufferStatusEXT) (GLenum);
135 QGL_EXTERN void (APIENTRY* qglFramebufferTexture1DEXT) (GLenum, GLenum, GLenum, GLuint, GLint);
136 QGL_EXTERN void (APIENTRY* qglFramebufferTexture2DEXT) (GLenum, GLenum, GLenum, GLuint, GLint);
137 QGL_EXTERN void (APIENTRY* qglFramebufferTexture3DEXT) (GLenum, GLenum, GLenum, GLuint, GLint, GLint);
138 QGL_EXTERN void (APIENTRY* qglFramebufferRenderbufferEXT) (GLenum, GLenum, GLenum, GLuint);
139 QGL_EXTERN void (APIENTRY* qglGetFramebufferAttachmentParameterivEXT) (GLenum, GLenum, GLenum, GLint*);
140 QGL_EXTERN void (APIENTRY* qglGenerateMipmapEXT) (GLenum);
141 QGL_EXTERN void (APIENTRY* qglDrawBuffers) (GLsizei, const GLenum *);
142 QGL_EXTERN void (APIENTRY* qglBlitFramebuffer)( GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLbitfield, GLenum);
143
144 /* multitexture */
145 typedef void (APIENTRY* ActiveTexture_t)(GLenum texture);
146 typedef void (APIENTRY* ClientActiveTexture_t)(GLenum texture);
147
148 /* vertex buffer objects */
149 typedef void (APIENTRY* GenBuffers_t) (GLuint count, GLuint* id);
150 typedef void (APIENTRY* DeleteBuffers_t) (GLuint count, GLuint* id);
151 typedef void (APIENTRY* BindBuffer_t) (GLenum target, GLuint id);
152 typedef void (APIENTRY* BufferData_t) (GLenum target, GLsizei size, const GLvoid* data, GLenum usage);
153
154 /* vertex attribute arrays */
155 typedef void (APIENTRY* EnableVertexAttribArray_t)(GLuint index);
156 typedef void (APIENTRY* DisableVertexAttribArray_t)(GLuint index);
157 typedef void (APIENTRY* VertexAttribPointer_t)(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* pointer);
158
159 /* glsl vertex and fragment shaders and programs */
160 typedef GLuint (APIENTRY* CreateShader_t)(GLenum type);
161 typedef void (APIENTRY* DeleteShader_t)(GLuint id);
162 typedef void (APIENTRY* ShaderSource_t)(GLuint id, GLuint count, GLchar** sources, GLuint* len);
163 typedef void (APIENTRY* CompileShader_t)(GLuint id);
164 typedef void (APIENTRY* GetShaderiv_t)(GLuint id, GLenum field, GLuint* dest);
165 typedef void (APIENTRY* GetShaderInfoLog_t)(GLuint id, GLuint maxlen, GLuint* len, GLchar* dest);
166 typedef GLuint (APIENTRY* CreateProgram_t)(void);
167 typedef void (APIENTRY* DeleteProgram_t)(GLuint id);
168 typedef void (APIENTRY* AttachShader_t)(GLuint prog, GLuint shader);
169 typedef void (APIENTRY* DetachShader_t)(GLuint prog, GLuint shader);
170 typedef void (APIENTRY* LinkProgram_t)(GLuint id);
171 typedef void (APIENTRY* UseProgram_t)(GLuint id);
172 typedef void (APIENTRY* GetActiveUniforms_t)(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint* size, GLenum *type, GLchar* name);
173 typedef void (APIENTRY* GetProgramiv_t)(GLuint id, GLenum field, GLuint* dest);
174 typedef void (APIENTRY* GetProgramInfoLog_t)(GLuint id, GLuint maxlen, GLuint* len, GLchar* dest);
175 typedef GLint (APIENTRY* GetUniformLocation_t)(GLuint id, const GLchar* name);
176 typedef void (APIENTRY* Uniform1i_t)(GLint location, GLint i);
177 typedef void (APIENTRY* Uniform1f_t)(GLint location, GLfloat f);
178 typedef void (APIENTRY* Uniform1fv_t)(GLint location, int count, GLfloat* f);
179 typedef void (APIENTRY* Uniform2fv_t)(GLint location, int count, GLfloat* f);
180 typedef void (APIENTRY* Uniform3fv_t)(GLint location, int count, GLfloat* f);
181 typedef void (APIENTRY* Uniform4fv_t)(GLint location, int count, GLfloat* f);
182 typedef GLint (APIENTRY* GetAttribLocation_t)(GLuint id, const GLchar* name);
183 typedef void (APIENTRY* UniformMatrix4fv_t)(GLint location, int count, GLboolean transpose, GLfloat* v);
184
185 /* frame buffer objects (fbo) */
186 typedef GLboolean (APIENTRY* IsRenderbufferEXT_t) (GLuint);
187 typedef void (APIENTRY* BindRenderbufferEXT_t) (GLenum, GLuint);
188 typedef void (APIENTRY* DeleteRenderbuffersEXT_t) (GLsizei, const GLuint*);
189 typedef void (APIENTRY* GenRenderbuffersEXT_t) (GLsizei, GLuint*);
190 typedef void (APIENTRY* RenderbufferStorageEXT_t) (GLenum, GLenum, GLsizei, GLsizei);
191 typedef void (APIENTRY* RenderbufferStorageMultisampleEXT_t) (GLenum, GLsizei, GLenum, GLsizei, GLsizei);
192 typedef void (APIENTRY* GetRenderbufferParameterivEXT_t) (GLenum, GLenum, GLint*);
193 typedef GLboolean (APIENTRY* IsFramebufferEXT_t) (GLuint);
194 typedef void (APIENTRY* BindFramebufferEXT_t) (GLenum, GLuint);
195 typedef void (APIENTRY* DeleteFramebuffersEXT_t) (GLsizei, const GLuint*);
196 typedef void (APIENTRY* GenFramebuffersEXT_t) (GLsizei, GLuint*);
197 typedef GLenum (APIENTRY* CheckFramebufferStatusEXT_t) (GLenum);
198 typedef void (APIENTRY* FramebufferTexture1DEXT_t) (GLenum, GLenum, GLenum, GLuint, GLint);
199 typedef void (APIENTRY* FramebufferTexture2DEXT_t) (GLenum, GLenum, GLenum, GLuint, GLint);
200 typedef void (APIENTRY* FramebufferTexture3DEXT_t) (GLenum, GLenum, GLenum, GLuint, GLint, GLint);
201 typedef void (APIENTRY* FramebufferRenderbufferEXT_t) (GLenum, GLenum, GLenum, GLuint);
202 typedef void (APIENTRY* GetFramebufferAttachmentParameterivEXT_t) (GLenum, GLenum, GLenum, GLint*);
203 typedef void (APIENTRY* GenerateMipmapEXT_t) (GLenum);
204 typedef void (APIENTRY* DrawBuffers_t) (GLsizei, const GLenum *);
205 typedef void (APIENTRY* BlitFramebuffer_t)( GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLbitfield, GLenum);
206