Debian Codegraph @

code/renderergl2/tr_extensions.c

raw symbols SCIP
1 /*
2 ===========================================================================
3 Copyright (C) 2011 James Canete ([email protected])
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22 // tr_extensions.c - extensions needed by the renderer not in sdl_glimp.c
23
24 #ifdef USE_INTERNAL_SDL_HEADERS
25 # include "SDL.h"
26 #else
27 # include <SDL.h>
28 #endif
29
30 #include "tr_local.h"
31 #include "tr_dsa.h"
32
33 void GLimp_InitExtraExtensions(void)
34 {
35 char *extension;
36 const char* result[3] = { "...ignoring %s\n", "...using %s\n", "...%s not found\n" };
37 qboolean q_gl_version_at_least_3_0;
38 qboolean q_gl_version_at_least_3_2;
39
40 q_gl_version_at_least_3_0 = QGL_VERSION_ATLEAST( 3, 0 );
41 q_gl_version_at_least_3_2 = QGL_VERSION_ATLEAST( 3, 2 );
42
43 // Check if we need Intel graphics specific fixes.
44 glRefConfig.intelGraphics = qfalse;
45 if (strstr((char *)qglGetString(GL_RENDERER), "Intel"))
46 glRefConfig.intelGraphics = qtrue;
47
48 if (qglesMajorVersion)
49 {
50 glRefConfig.vaoCacheGlIndexType = GL_UNSIGNED_SHORT;
51 glRefConfig.vaoCacheGlIndexSize = sizeof(unsigned short);
52 }
53 else
54 {
55 glRefConfig.vaoCacheGlIndexType = GL_UNSIGNED_INT;
56 glRefConfig.vaoCacheGlIndexSize = sizeof(unsigned int);
57 }
58
59 // set DSA fallbacks
60 #define GLE(ret, name, ...) qgl##name = GLDSA_##name;
61 QGL_EXT_direct_state_access_PROCS;
62 #undef GLE
63
64 // GL function loader, based on https://gist.github.com/rygorous/16796a0c876cf8a5f542caddb55bce8a
65 #define GLE(ret, name, ...) qgl##name = (name##proc *) SDL_GL_GetProcAddress("gl" #name);
66
67 //
68 // OpenGL ES extensions
69 //
70 if (qglesMajorVersion)
71 {
72 if (!r_allowExtensions->integer)
73 goto done;
74
75 extension = "GL_EXT_occlusion_query_boolean";
76 if (qglesMajorVersion >= 3 || SDL_GL_ExtensionSupported(extension))
77 {
78 glRefConfig.occlusionQuery = qtrue;
79 glRefConfig.occlusionQueryTarget = GL_ANY_SAMPLES_PASSED;
80
81 if (qglesMajorVersion >= 3) {
82 QGL_ARB_occlusion_query_PROCS;
83 } else {
84 // GL_EXT_occlusion_query_boolean uses EXT suffix
85 #undef GLE
86 #define GLE(ret, name, ...) qgl##name = (name##proc *) SDL_GL_GetProcAddress("gl" #name "EXT");
87
88 QGL_ARB_occlusion_query_PROCS;
89
90 #undef GLE
91 #define GLE(ret, name, ...) qgl##name = (name##proc *) SDL_GL_GetProcAddress("gl" #name);
92 }
93
94 ri.Printf(PRINT_ALL, result[glRefConfig.occlusionQuery], extension);
95 }
96 else
97 {
98 ri.Printf(PRINT_ALL, result[2], extension);
99 }
100
101 // GL_NV_read_depth
102 extension = "GL_NV_read_depth";
103 if (SDL_GL_ExtensionSupported(extension))
104 {
105 glRefConfig.readDepth = qtrue;
106 ri.Printf(PRINT_ALL, result[glRefConfig.readDepth], extension);
107 }
108 else
109 {
110 ri.Printf(PRINT_ALL, result[2], extension);
111 }
112
113 // GL_NV_read_stencil
114 extension = "GL_NV_read_stencil";
115 if (SDL_GL_ExtensionSupported(extension))
116 {
117 glRefConfig.readStencil = qtrue;
118 ri.Printf(PRINT_ALL, result[glRefConfig.readStencil], extension);
119 }
120 else
121 {
122 ri.Printf(PRINT_ALL, result[2], extension);
123 }
124
125 // GL_EXT_shadow_samplers
126 extension = "GL_EXT_shadow_samplers";
127 if (qglesMajorVersion >= 3 || SDL_GL_ExtensionSupported(extension))
128 {
129 glRefConfig.shadowSamplers = qtrue;
130 ri.Printf(PRINT_ALL, result[glRefConfig.shadowSamplers], extension);
131 }
132 else
133 {
134 ri.Printf(PRINT_ALL, result[2], extension);
135 }
136
137 // GL_OES_standard_derivatives
138 extension = "GL_OES_standard_derivatives";
139 if (qglesMajorVersion >= 3 || SDL_GL_ExtensionSupported(extension))
140 {
141 glRefConfig.standardDerivatives = qtrue;
142 ri.Printf(PRINT_ALL, result[glRefConfig.standardDerivatives], extension);
143 }
144 else
145 {
146 ri.Printf(PRINT_ALL, result[2], extension);
147 }
148
149 // GL_OES_element_index_uint
150 extension = "GL_OES_element_index_uint";
151 if (qglesMajorVersion >= 3 || SDL_GL_ExtensionSupported(extension))
152 {
153 glRefConfig.vaoCacheGlIndexType = GL_UNSIGNED_INT;
154 glRefConfig.vaoCacheGlIndexSize = sizeof(unsigned int);
155 ri.Printf(PRINT_ALL, result[1], extension);
156 }
157 else
158 {
159 ri.Printf(PRINT_ALL, result[2], extension);
160 }
161
162 goto done;
163 }
164
165 // OpenGL 1.5 - GL_ARB_occlusion_query
166 glRefConfig.occlusionQuery = qtrue;
167 glRefConfig.occlusionQueryTarget = GL_SAMPLES_PASSED;
168 QGL_ARB_occlusion_query_PROCS;
169
170 // OpenGL 3.0 - GL_ARB_framebuffer_object
171 extension = "GL_ARB_framebuffer_object";
172 glRefConfig.framebufferObject = qfalse;
173 glRefConfig.framebufferBlit = qfalse;
174 glRefConfig.framebufferMultisample = qfalse;
175 if (q_gl_version_at_least_3_0 || SDL_GL_ExtensionSupported(extension))
176 {
177 glRefConfig.framebufferObject = !!r_ext_framebuffer_object->integer;
178 glRefConfig.framebufferBlit = qtrue;
179 glRefConfig.framebufferMultisample = qtrue;
180
181 qglGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &glRefConfig.maxRenderbufferSize);
182 qglGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &glRefConfig.maxColorAttachments);
183
184 QGL_ARB_framebuffer_object_PROCS;
185
186 ri.Printf(PRINT_ALL, result[glRefConfig.framebufferObject], extension);
187 }
188 else
189 {
190 ri.Printf(PRINT_ALL, result[2], extension);
191 }
192
193 // OpenGL 3.0 - GL_ARB_vertex_array_object
194 extension = "GL_ARB_vertex_array_object";
195 glRefConfig.vertexArrayObject = qfalse;
196 if (q_gl_version_at_least_3_0 || SDL_GL_ExtensionSupported(extension))
197 {
198 if (q_gl_version_at_least_3_0)
199 {
200 // force VAO, core context requires it
201 glRefConfig.vertexArrayObject = qtrue;
202 }
203 else
204 {
205 glRefConfig.vertexArrayObject = !!r_arb_vertex_array_object->integer;
206 }
207
208 QGL_ARB_vertex_array_object_PROCS;
209
210 ri.Printf(PRINT_ALL, result[glRefConfig.vertexArrayObject], extension);
211 }
212 else
213 {
214 ri.Printf(PRINT_ALL, result[2], extension);
215 }
216
217 // OpenGL 3.0 - GL_ARB_texture_float
218 extension = "GL_ARB_texture_float";
219 glRefConfig.textureFloat = qfalse;
220 if (q_gl_version_at_least_3_0 || SDL_GL_ExtensionSupported(extension))
221 {
222 glRefConfig.textureFloat = !!r_ext_texture_float->integer;
223
224 ri.Printf(PRINT_ALL, result[glRefConfig.textureFloat], extension);
225 }
226 else
227 {
228 ri.Printf(PRINT_ALL, result[2], extension);
229 }
230
231 // OpenGL 3.2 - GL_ARB_depth_clamp
232 extension = "GL_ARB_depth_clamp";
233 glRefConfig.depthClamp = qfalse;
234 if (q_gl_version_at_least_3_2 || SDL_GL_ExtensionSupported(extension))
235 {
236 glRefConfig.depthClamp = qtrue;
237
238 ri.Printf(PRINT_ALL, result[glRefConfig.depthClamp], extension);
239 }
240 else
241 {
242 ri.Printf(PRINT_ALL, result[2], extension);
243 }
244
245 // OpenGL 3.2 - GL_ARB_seamless_cube_map
246 extension = "GL_ARB_seamless_cube_map";
247 glRefConfig.seamlessCubeMap = qfalse;
248 if (q_gl_version_at_least_3_2 || SDL_GL_ExtensionSupported(extension))
249 {
250 glRefConfig.seamlessCubeMap = !!r_arb_seamless_cube_map->integer;
251
252 ri.Printf(PRINT_ALL, result[glRefConfig.seamlessCubeMap], extension);
253 }
254 else
255 {
256 ri.Printf(PRINT_ALL, result[2], extension);
257 }
258
259 glRefConfig.memInfo = MI_NONE;
260
261 // GL_NVX_gpu_memory_info
262 extension = "GL_NVX_gpu_memory_info";
263 if( SDL_GL_ExtensionSupported( extension ) )
264 {
265 glRefConfig.memInfo = MI_NVX;
266
267 ri.Printf(PRINT_ALL, result[1], extension);
268 }
269 else
270 {
271 ri.Printf(PRINT_ALL, result[2], extension);
272 }
273
274 // GL_ATI_meminfo
275 extension = "GL_ATI_meminfo";
276 if( SDL_GL_ExtensionSupported( extension ) )
277 {
278 if (glRefConfig.memInfo == MI_NONE)
279 {
280 glRefConfig.memInfo = MI_ATI;
281
282 ri.Printf(PRINT_ALL, result[1], extension);
283 }
284 else
285 {
286 ri.Printf(PRINT_ALL, result[0], extension);
287 }
288 }
289 else
290 {
291 ri.Printf(PRINT_ALL, result[2], extension);
292 }
293
294 glRefConfig.textureCompression = TCR_NONE;
295
296 // GL_ARB_texture_compression_rgtc
297 extension = "GL_ARB_texture_compression_rgtc";
298 if (SDL_GL_ExtensionSupported(extension))
299 {
300 qboolean useRgtc = r_ext_compressed_textures->integer >= 1;
301
302 if (useRgtc)
303 glRefConfig.textureCompression |= TCR_RGTC;
304
305 ri.Printf(PRINT_ALL, result[useRgtc], extension);
306 }
307 else
308 {
309 ri.Printf(PRINT_ALL, result[2], extension);
310 }
311
312 glRefConfig.swizzleNormalmap = r_ext_compressed_textures->integer && !(glRefConfig.textureCompression & TCR_RGTC);
313
314 // GL_ARB_texture_compression_bptc
315 extension = "GL_ARB_texture_compression_bptc";
316 if (SDL_GL_ExtensionSupported(extension))
317 {
318 qboolean useBptc = r_ext_compressed_textures->integer >= 2;
319
320 if (useBptc)
321 glRefConfig.textureCompression |= TCR_BPTC;
322
323 ri.Printf(PRINT_ALL, result[useBptc], extension);
324 }
325 else
326 {
327 ri.Printf(PRINT_ALL, result[2], extension);
328 }
329
330 // GL_EXT_direct_state_access
331 extension = "GL_EXT_direct_state_access";
332 glRefConfig.directStateAccess = qfalse;
333 if (SDL_GL_ExtensionSupported(extension))
334 {
335 glRefConfig.directStateAccess = !!r_ext_direct_state_access->integer;
336
337 // QGL_*_PROCS becomes several functions, do not remove {}
338 if (glRefConfig.directStateAccess)
339 {
340 QGL_EXT_direct_state_access_PROCS;
341 }
342
343 ri.Printf(PRINT_ALL, result[glRefConfig.directStateAccess], extension);
344 }
345 else
346 {
347 ri.Printf(PRINT_ALL, result[2], extension);
348 }
349
350 done:
351
352 // Determine GLSL version
353 if (1)
354 {
355 char version[256], *version_p;
356
357 Q_strncpyz(version, (char *)qglGetString(GL_SHADING_LANGUAGE_VERSION), sizeof(version));
358
359 // Skip leading text such as "OpenGL ES GLSL ES "
360 version_p = version;
361 while ( *version_p && !isdigit( *version_p ) )
362 {
363 version_p++;
364 }
365
366 sscanf(version_p, "%d.%d", &glRefConfig.glslMajorVersion, &glRefConfig.glslMinorVersion);
367
368 ri.Printf(PRINT_ALL, "...using GLSL version %s\n", version);
369 }
370
371 #undef GLE
372 }