Debian Codegraph @

code/renderergl2/tr_dsa.c

raw symbols SCIP
1 /*
2 ===========================================================================
3 Copyright (C) 2016 James Canete
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 ===========================================================================
19 */
20
21 #include "tr_local.h"
22
23 #include "tr_dsa.h"
24
25 static struct
26 {
27 GLuint textures[NUM_TEXTURE_BUNDLES];
28 GLenum texunit;
29
30 GLuint program;
31
32 GLuint drawFramebuffer;
33 GLuint readFramebuffer;
34 GLuint renderbuffer;
35 }
36 glDsaState;
37
38 void GL_BindNullTextures(void)
39 {
40 int i;
41
42 if (glRefConfig.directStateAccess)
43 {
44 for (i = 0; i < NUM_TEXTURE_BUNDLES; i++)
45 {
46 qglBindMultiTextureEXT(GL_TEXTURE0 + i, GL_TEXTURE_2D, 0);
47 glDsaState.textures[i] = 0;
48 }
49 }
50 else
51 {
52 for (i = 0; i < NUM_TEXTURE_BUNDLES; i++)
53 {
54 qglActiveTexture(GL_TEXTURE0 + i);
55 qglBindTexture(GL_TEXTURE_2D, 0);
56 glDsaState.textures[i] = 0;
57 }
58
59 qglActiveTexture(GL_TEXTURE0);
60 glDsaState.texunit = GL_TEXTURE0;
61 }
62 }
63
64 int GL_BindMultiTexture(GLenum texunit, GLenum target, GLuint texture)
65 {
66 GLuint tmu = texunit - GL_TEXTURE0;
67
68 if (glDsaState.textures[tmu] == texture)
69 return 0;
70
71 if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)
72 target = GL_TEXTURE_CUBE_MAP;
73
74 qglBindMultiTextureEXT(texunit, target, texture);
75 glDsaState.textures[tmu] = texture;
76 return 1;
77 }
78
79 GLvoid APIENTRY GLDSA_BindMultiTextureEXT(GLenum texunit, GLenum target, GLuint texture)
80 {
81 if (glDsaState.texunit != texunit)
82 {
83 qglActiveTexture(texunit);
84 glDsaState.texunit = texunit;
85 }
86
87 qglBindTexture(target, texture);
88 }
89
90 GLvoid APIENTRY GLDSA_TextureParameterfEXT(GLuint texture, GLenum target, GLenum pname, GLfloat param)
91 {
92 GL_BindMultiTexture(glDsaState.texunit, target, texture);
93 qglTexParameterf(target, pname, param);
94 }
95
96 GLvoid APIENTRY GLDSA_TextureParameteriEXT(GLuint texture, GLenum target, GLenum pname, GLint param)
97 {
98 GL_BindMultiTexture(glDsaState.texunit, target, texture);
99 qglTexParameteri(target, pname, param);
100 }
101
102 GLvoid APIENTRY GLDSA_TextureImage2DEXT(GLuint texture, GLenum target, GLint level, GLint internalformat,
103 GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels)
104 {
105 GL_BindMultiTexture(glDsaState.texunit, target, texture);
106 qglTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
107 }
108
109 GLvoid APIENTRY GLDSA_TextureSubImage2DEXT(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset,
110 GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels)
111 {
112 GL_BindMultiTexture(glDsaState.texunit, target, texture);
113 qglTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
114 }
115
116 GLvoid APIENTRY GLDSA_CopyTextureSubImage2DEXT(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset,
117 GLint x, GLint y, GLsizei width, GLsizei height)
118 {
119 GL_BindMultiTexture(glDsaState.texunit, target, texture);
120 qglCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
121 }
122
123 GLvoid APIENTRY GLDSA_CompressedTextureImage2DEXT(GLuint texture, GLenum target, GLint level, GLenum internalformat,
124 GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data)
125 {
126 GL_BindMultiTexture(glDsaState.texunit, target, texture);
127 qglCompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
128 }
129
130 GLvoid APIENTRY GLDSA_CompressedTextureSubImage2DEXT(GLuint texture, GLenum target, GLint level,
131 GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format,
132 GLsizei imageSize, const GLvoid *data)
133 {
134 GL_BindMultiTexture(glDsaState.texunit, target, texture);
135 qglCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data);
136 }
137
138 GLvoid APIENTRY GLDSA_GenerateTextureMipmapEXT(GLuint texture, GLenum target)
139 {
140 GL_BindMultiTexture(glDsaState.texunit, target, texture);
141 qglGenerateMipmap(target);
142 }
143
144 void GL_BindNullProgram(void)
145 {
146 qglUseProgram(0);
147 glDsaState.program = 0;
148 }
149
150 int GL_UseProgram(GLuint program)
151 {
152 if (glDsaState.program == program)
153 return 0;
154
155 qglUseProgram(program);
156 glDsaState.program = program;
157 return 1;
158 }
159
160 GLvoid APIENTRY GLDSA_ProgramUniform1iEXT(GLuint program, GLint location, GLint v0)
161 {
162 GL_UseProgram(program);
163 qglUniform1i(location, v0);
164 }
165
166 GLvoid APIENTRY GLDSA_ProgramUniform1fEXT(GLuint program, GLint location, GLfloat v0)
167 {
168 GL_UseProgram(program);
169 qglUniform1f(location, v0);
170 }
171
172 GLvoid APIENTRY GLDSA_ProgramUniform2fEXT(GLuint program, GLint location,
173 GLfloat v0, GLfloat v1)
174 {
175 GL_UseProgram(program);
176 qglUniform2f(location, v0, v1);
177 }
178
179 GLvoid APIENTRY GLDSA_ProgramUniform3fEXT(GLuint program, GLint location,
180 GLfloat v0, GLfloat v1, GLfloat v2)
181 {
182 GL_UseProgram(program);
183 qglUniform3f(location, v0, v1, v2);
184 }
185
186 GLvoid APIENTRY GLDSA_ProgramUniform4fEXT(GLuint program, GLint location,
187 GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3)
188 {
189 GL_UseProgram(program);
190 qglUniform4f(location, v0, v1, v2, v3);
191 }
192
193 GLvoid APIENTRY GLDSA_ProgramUniform1fvEXT(GLuint program, GLint location,
194 GLsizei count, const GLfloat *value)
195 {
196 GL_UseProgram(program);
197 qglUniform1fv(location, count, value);
198 }
199
200 GLvoid APIENTRY GLDSA_ProgramUniformMatrix4fvEXT(GLuint program, GLint location,
201 GLsizei count, GLboolean transpose,
202 const GLfloat *value)
203 {
204 GL_UseProgram(program);
205 qglUniformMatrix4fv(location, count, transpose, value);
206 }
207
208 void GL_BindNullFramebuffers(void)
209 {
210 qglBindFramebuffer(GL_FRAMEBUFFER, 0);
211 glDsaState.drawFramebuffer = glDsaState.readFramebuffer = 0;
212 qglBindRenderbuffer(GL_RENDERBUFFER, 0);
213 glDsaState.renderbuffer = 0;
214 }
215
216 void GL_BindFramebuffer(GLenum target, GLuint framebuffer)
217 {
218 switch (target)
219 {
220 case GL_FRAMEBUFFER:
221 if (framebuffer != glDsaState.drawFramebuffer || framebuffer != glDsaState.readFramebuffer)
222 {
223 qglBindFramebuffer(target, framebuffer);
224 glDsaState.drawFramebuffer = glDsaState.readFramebuffer = framebuffer;
225 }
226 break;
227
228 case GL_DRAW_FRAMEBUFFER:
229 if (framebuffer != glDsaState.drawFramebuffer)
230 {
231 qglBindFramebuffer(target, framebuffer);
232 glDsaState.drawFramebuffer = framebuffer;
233 }
234 break;
235
236 case GL_READ_FRAMEBUFFER:
237 if (framebuffer != glDsaState.readFramebuffer)
238 {
239 qglBindFramebuffer(target, framebuffer);
240 glDsaState.readFramebuffer = framebuffer;
241 }
242 break;
243 }
244 }
245
246 void GL_BindRenderbuffer(GLuint renderbuffer)
247 {
248 if (renderbuffer != glDsaState.renderbuffer)
249 {
250 qglBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
251 glDsaState.renderbuffer = renderbuffer;
252 }
253 }
254
255 GLvoid APIENTRY GLDSA_NamedRenderbufferStorageEXT(GLuint renderbuffer,
256 GLenum internalformat, GLsizei width, GLsizei height)
257 {
258 GL_BindRenderbuffer(renderbuffer);
259 qglRenderbufferStorage(GL_RENDERBUFFER, internalformat, width, height);
260 }
261
262 GLvoid APIENTRY GLDSA_NamedRenderbufferStorageMultisampleEXT(GLuint renderbuffer,
263 GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
264 {
265 GL_BindRenderbuffer(renderbuffer);
266 qglRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, internalformat, width, height);
267 }
268
269 GLenum APIENTRY GLDSA_CheckNamedFramebufferStatusEXT(GLuint framebuffer, GLenum target)
270 {
271 GL_BindFramebuffer(target, framebuffer);
272 return qglCheckFramebufferStatus(target);
273 }
274
275 GLvoid APIENTRY GLDSA_NamedFramebufferTexture2DEXT(GLuint framebuffer,
276 GLenum attachment, GLenum textarget, GLuint texture, GLint level)
277 {
278 GL_BindFramebuffer(GL_FRAMEBUFFER, framebuffer);
279 qglFramebufferTexture2D(GL_FRAMEBUFFER, attachment, textarget, texture, level);
280 }
281
282 GLvoid APIENTRY GLDSA_NamedFramebufferRenderbufferEXT(GLuint framebuffer,
283 GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
284 {
285 GL_BindFramebuffer(GL_FRAMEBUFFER, framebuffer);
286 qglFramebufferRenderbuffer(GL_FRAMEBUFFER, attachment, renderbuffertarget, renderbuffer);
287 }