openmohaa/code/renderergl2/tr_extensions.c

254 lines
6.8 KiB
C
Raw Normal View History

2016-03-27 11:49:47 +02:00
/*
===========================================================================
Copyright (C) 2011 James Canete (use.less01@gmail.com)
This file is part of Quake III Arena source code.
Quake III Arena source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
Quake III Arena source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Quake III Arena source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
// tr_extensions.c - extensions needed by the renderer not in sdl_glimp.c
#ifdef USE_LOCAL_HEADERS
# include "SDL.h"
#else
# include <SDL.h>
#endif
#include "tr_local.h"
2023-05-08 19:53:53 +02:00
#include "tr_dsa.h"
2016-03-27 11:49:47 +02:00
2023-05-08 19:53:53 +02:00
void GLimp_InitExtraExtensions(void)
2016-03-27 11:49:47 +02:00
{
char *extension;
const char* result[3] = { "...ignoring %s\n", "...using %s\n", "...%s not found\n" };
2023-05-08 19:53:53 +02:00
qboolean q_gl_version_at_least_3_0;
qboolean q_gl_version_at_least_3_2;
2016-03-27 11:49:47 +02:00
2023-05-08 19:53:53 +02:00
q_gl_version_at_least_3_0 = QGL_VERSION_ATLEAST( 3, 0 );
q_gl_version_at_least_3_2 = QGL_VERSION_ATLEAST( 3, 2 );
2016-03-27 11:49:47 +02:00
2023-05-08 19:53:53 +02:00
// Check if we need Intel graphics specific fixes.
glRefConfig.intelGraphics = qfalse;
if (strstr((char *)qglGetString(GL_RENDERER), "Intel"))
glRefConfig.intelGraphics = qtrue;
2016-03-27 11:49:47 +02:00
2023-05-08 19:53:53 +02:00
// set DSA fallbacks
#define GLE(ret, name, ...) qgl##name = GLDSA_##name;
QGL_EXT_direct_state_access_PROCS;
#undef GLE
2016-03-27 11:49:47 +02:00
2023-05-08 19:53:53 +02:00
// GL function loader, based on https://gist.github.com/rygorous/16796a0c876cf8a5f542caddb55bce8a
#define GLE(ret, name, ...) qgl##name = (name##proc *) SDL_GL_GetProcAddress("gl" #name);
2016-03-27 11:49:47 +02:00
2023-05-08 19:53:53 +02:00
// OpenGL 1.5 - GL_ARB_occlusion_query
glRefConfig.occlusionQuery = qtrue;
QGL_ARB_occlusion_query_PROCS;
2016-03-27 11:49:47 +02:00
2023-05-08 19:53:53 +02:00
// OpenGL 3.0 - GL_ARB_framebuffer_object
extension = "GL_ARB_framebuffer_object";
glRefConfig.framebufferObject = qfalse;
glRefConfig.framebufferBlit = qfalse;
glRefConfig.framebufferMultisample = qfalse;
if (q_gl_version_at_least_3_0 || SDL_GL_ExtensionSupported(extension))
2016-03-27 11:49:47 +02:00
{
2023-05-08 19:53:53 +02:00
glRefConfig.framebufferObject = !!r_ext_framebuffer_object->integer;
glRefConfig.framebufferBlit = qtrue;
glRefConfig.framebufferMultisample = qtrue;
2016-03-27 11:49:47 +02:00
2023-05-08 19:53:53 +02:00
qglGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &glRefConfig.maxRenderbufferSize);
qglGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &glRefConfig.maxColorAttachments);
2016-03-27 11:49:47 +02:00
2023-05-08 19:53:53 +02:00
QGL_ARB_framebuffer_object_PROCS;
2016-03-27 11:49:47 +02:00
2023-05-08 19:53:53 +02:00
ri.Printf(PRINT_ALL, result[glRefConfig.framebufferObject], extension);
2016-03-27 11:49:47 +02:00
}
else
{
2023-05-08 19:53:53 +02:00
ri.Printf(PRINT_ALL, result[2], extension);
2016-03-27 11:49:47 +02:00
}
2023-05-08 19:53:53 +02:00
// OpenGL 3.0 - GL_ARB_vertex_array_object
extension = "GL_ARB_vertex_array_object";
glRefConfig.vertexArrayObject = qfalse;
if (q_gl_version_at_least_3_0 || SDL_GL_ExtensionSupported(extension))
2016-03-27 11:49:47 +02:00
{
2023-05-08 19:53:53 +02:00
if (q_gl_version_at_least_3_0)
2016-03-27 11:49:47 +02:00
{
2023-05-08 19:53:53 +02:00
// force VAO, core context requires it
glRefConfig.vertexArrayObject = qtrue;
2016-03-27 11:49:47 +02:00
}
2023-05-08 19:53:53 +02:00
else
2016-03-27 11:49:47 +02:00
{
2023-05-08 19:53:53 +02:00
glRefConfig.vertexArrayObject = !!r_arb_vertex_array_object->integer;
2016-03-27 11:49:47 +02:00
}
2023-05-08 19:53:53 +02:00
QGL_ARB_vertex_array_object_PROCS;
ri.Printf(PRINT_ALL, result[glRefConfig.vertexArrayObject], extension);
2016-03-27 11:49:47 +02:00
}
else
{
ri.Printf(PRINT_ALL, result[2], extension);
}
2023-05-08 19:53:53 +02:00
// OpenGL 3.0 - GL_ARB_texture_float
2016-03-27 11:49:47 +02:00
extension = "GL_ARB_texture_float";
glRefConfig.textureFloat = qfalse;
2023-05-08 19:53:53 +02:00
if (q_gl_version_at_least_3_0 || SDL_GL_ExtensionSupported(extension))
2016-03-27 11:49:47 +02:00
{
2023-05-08 19:53:53 +02:00
glRefConfig.textureFloat = !!r_ext_texture_float->integer;
2016-03-27 11:49:47 +02:00
ri.Printf(PRINT_ALL, result[glRefConfig.textureFloat], extension);
}
else
{
ri.Printf(PRINT_ALL, result[2], extension);
}
2023-05-08 19:53:53 +02:00
// OpenGL 3.2 - GL_ARB_depth_clamp
extension = "GL_ARB_depth_clamp";
glRefConfig.depthClamp = qfalse;
if (q_gl_version_at_least_3_2 || SDL_GL_ExtensionSupported(extension))
2016-03-27 11:49:47 +02:00
{
2023-05-08 19:53:53 +02:00
glRefConfig.depthClamp = qtrue;
2016-03-27 11:49:47 +02:00
2023-05-08 19:53:53 +02:00
ri.Printf(PRINT_ALL, result[glRefConfig.depthClamp], extension);
2016-03-27 11:49:47 +02:00
}
else
{
ri.Printf(PRINT_ALL, result[2], extension);
}
2023-05-08 19:53:53 +02:00
// OpenGL 3.2 - GL_ARB_seamless_cube_map
extension = "GL_ARB_seamless_cube_map";
glRefConfig.seamlessCubeMap = qfalse;
if (q_gl_version_at_least_3_2 || SDL_GL_ExtensionSupported(extension))
2016-03-27 11:49:47 +02:00
{
2023-05-08 19:53:53 +02:00
glRefConfig.seamlessCubeMap = !!r_arb_seamless_cube_map->integer;
2016-03-27 11:49:47 +02:00
2023-05-08 19:53:53 +02:00
ri.Printf(PRINT_ALL, result[glRefConfig.seamlessCubeMap], extension);
2016-03-27 11:49:47 +02:00
}
else
{
ri.Printf(PRINT_ALL, result[2], extension);
}
2023-05-08 19:53:53 +02:00
// Determine GLSL version
if (1)
2016-03-27 11:49:47 +02:00
{
2023-05-08 19:53:53 +02:00
char version[256];
2016-03-27 11:49:47 +02:00
2023-05-08 19:53:53 +02:00
Q_strncpyz(version, (char *)qglGetString(GL_SHADING_LANGUAGE_VERSION), sizeof(version));
2016-03-27 11:49:47 +02:00
2023-05-08 19:53:53 +02:00
sscanf(version, "%d.%d", &glRefConfig.glslMajorVersion, &glRefConfig.glslMinorVersion);
2016-03-27 11:49:47 +02:00
2023-05-08 19:53:53 +02:00
ri.Printf(PRINT_ALL, "...using GLSL version %s\n", version);
2016-03-27 11:49:47 +02:00
}
2023-05-08 19:53:53 +02:00
glRefConfig.memInfo = MI_NONE;
2016-03-27 11:49:47 +02:00
2023-05-08 19:53:53 +02:00
// GL_NVX_gpu_memory_info
extension = "GL_NVX_gpu_memory_info";
if( SDL_GL_ExtensionSupported( extension ) )
2016-03-27 11:49:47 +02:00
{
2023-05-08 19:53:53 +02:00
glRefConfig.memInfo = MI_NVX;
2016-03-27 11:49:47 +02:00
ri.Printf(PRINT_ALL, result[1], extension);
}
else
{
ri.Printf(PRINT_ALL, result[2], extension);
}
2023-05-08 19:53:53 +02:00
// GL_ATI_meminfo
extension = "GL_ATI_meminfo";
if( SDL_GL_ExtensionSupported( extension ) )
2016-03-27 11:49:47 +02:00
{
2023-05-08 19:53:53 +02:00
if (glRefConfig.memInfo == MI_NONE)
{
glRefConfig.memInfo = MI_ATI;
ri.Printf(PRINT_ALL, result[1], extension);
}
else
{
ri.Printf(PRINT_ALL, result[0], extension);
}
2016-03-27 11:49:47 +02:00
}
else
{
ri.Printf(PRINT_ALL, result[2], extension);
}
2023-05-08 19:53:53 +02:00
glRefConfig.textureCompression = TCR_NONE;
2016-03-27 11:49:47 +02:00
2023-05-08 19:53:53 +02:00
// GL_ARB_texture_compression_rgtc
extension = "GL_ARB_texture_compression_rgtc";
if (SDL_GL_ExtensionSupported(extension))
2016-03-27 11:49:47 +02:00
{
2023-05-08 19:53:53 +02:00
qboolean useRgtc = r_ext_compressed_textures->integer >= 1;
2016-03-27 11:49:47 +02:00
2023-05-08 19:53:53 +02:00
if (useRgtc)
glRefConfig.textureCompression |= TCR_RGTC;
2016-03-27 11:49:47 +02:00
2023-05-08 19:53:53 +02:00
ri.Printf(PRINT_ALL, result[useRgtc], extension);
2016-03-27 11:49:47 +02:00
}
else
{
ri.Printf(PRINT_ALL, result[2], extension);
}
2023-05-08 19:53:53 +02:00
glRefConfig.swizzleNormalmap = r_ext_compressed_textures->integer && !(glRefConfig.textureCompression & TCR_RGTC);
2016-03-27 11:49:47 +02:00
2023-05-08 19:53:53 +02:00
// GL_ARB_texture_compression_bptc
extension = "GL_ARB_texture_compression_bptc";
if (SDL_GL_ExtensionSupported(extension))
2016-03-27 11:49:47 +02:00
{
2023-05-08 19:53:53 +02:00
qboolean useBptc = r_ext_compressed_textures->integer >= 2;
2016-03-27 11:49:47 +02:00
2023-05-08 19:53:53 +02:00
if (useBptc)
glRefConfig.textureCompression |= TCR_BPTC;
2016-03-27 11:49:47 +02:00
2023-05-08 19:53:53 +02:00
ri.Printf(PRINT_ALL, result[useBptc], extension);
2016-03-27 11:49:47 +02:00
}
else
{
ri.Printf(PRINT_ALL, result[2], extension);
}
2023-05-08 19:53:53 +02:00
// GL_EXT_direct_state_access
extension = "GL_EXT_direct_state_access";
glRefConfig.directStateAccess = qfalse;
if (SDL_GL_ExtensionSupported(extension))
2016-03-27 11:49:47 +02:00
{
2023-05-08 19:53:53 +02:00
glRefConfig.directStateAccess = !!r_ext_direct_state_access->integer;
// QGL_*_PROCS becomes several functions, do not remove {}
if (glRefConfig.directStateAccess)
2016-03-27 11:49:47 +02:00
{
2023-05-08 19:53:53 +02:00
QGL_EXT_direct_state_access_PROCS;
2016-03-27 11:49:47 +02:00
}
2023-05-08 19:53:53 +02:00
ri.Printf(PRINT_ALL, result[glRefConfig.directStateAccess], extension);
2016-03-27 11:49:47 +02:00
}
else
{
ri.Printf(PRINT_ALL, result[2], extension);
}
2023-05-08 19:53:53 +02:00
#undef GLE
2016-03-27 11:49:47 +02:00
}