OpenGL2: Use extension functions with OpenGL versions before 3.0.

This commit is contained in:
SmileTheory 2017-08-07 18:00:00 -07:00
parent 00a5339b27
commit 3f415abe61
2 changed files with 88 additions and 54 deletions

View file

@ -479,9 +479,12 @@ extern void (APIENTRYP qglUnlockArraysEXT) (void);
#define GL_HALF_FLOAT_ARB 0x140B
#endif
// OpenGL 3.0, was GL_EXT_framebuffer_object, GL_EXT_framebuffer_blit, GL_EXT_framebuffer_multisample, and GL_ARB_vertex_array_object
// OpenGL 3.0 specific
#define QGL_3_0_PROCS \
GLE(const GLubyte *, GetStringi, GLenum name, GLuint index) \
// GL_ARB_framebuffer_object, built-in to OpenGL 3.0
#define QGL_ARB_framebuffer_object_PROCS \
GLE(void, BindRenderbuffer, GLenum target, GLuint renderbuffer) \
GLE(void, DeleteRenderbuffers, GLsizei n, const GLuint *renderbuffers) \
GLE(void, GenRenderbuffers, GLsizei n, GLuint *renderbuffers) \
@ -495,6 +498,9 @@ extern void (APIENTRYP qglUnlockArraysEXT) (void);
GLE(void, GenerateMipmap, GLenum target) \
GLE(void, BlitFramebuffer, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter) \
GLE(void, RenderbufferStorageMultisample, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height) \
// GL_ARB_vertex_array_object, built-in to OpenGL 3.0
#define QGL_ARB_vertex_array_object_PROCS \
GLE(void, BindVertexArray, GLuint array) \
GLE(void, DeleteVertexArrays, GLsizei n, const GLuint *arrays) \
GLE(void, GenVertexArrays, GLsizei n, GLuint *arrays) \
@ -554,6 +560,8 @@ QGL_1_3_PROCS;
QGL_1_5_PROCS;
QGL_2_0_PROCS;
QGL_3_0_PROCS;
QGL_ARB_framebuffer_object_PROCS;
QGL_ARB_vertex_array_object_PROCS;
QGL_EXT_direct_state_access_PROCS;
#undef GLE

View file

@ -35,6 +35,8 @@ QGL_1_3_PROCS;
QGL_1_5_PROCS;
QGL_2_0_PROCS;
QGL_3_0_PROCS;
QGL_ARB_framebuffer_object_PROCS;
QGL_ARB_vertex_array_object_PROCS;
QGL_EXT_direct_state_access_PROCS;
#undef GLE
@ -42,6 +44,8 @@ void GLimp_InitExtraExtensions()
{
char *extension;
const char* result[3] = { "...ignoring %s\n", "...using %s\n", "...%s not found\n" };
qboolean q_gl_version_at_least_3_0;
qboolean q_gl_version_at_least_3_2;
// Check OpenGL version
sscanf(glConfig.version_string, "%d.%d", &glRefConfig.openglMajorVersion, &glRefConfig.openglMinorVersion);
@ -49,6 +53,9 @@ void GLimp_InitExtraExtensions()
ri.Error(ERR_FATAL, "OpenGL 2.0 required!");
ri.Printf(PRINT_ALL, "...using OpenGL %s\n", glConfig.version_string);
q_gl_version_at_least_3_0 = (glRefConfig.openglMajorVersion >= 3);
q_gl_version_at_least_3_2 = (glRefConfig.openglMajorVersion > 3 || (glRefConfig.openglMajorVersion == 3 && glRefConfig.openglMinorVersion > 2));
// Check if we need Intel graphics specific fixes.
glRefConfig.intelGraphics = qfalse;
if (strstr((char *)qglGetString(GL_RENDERER), "Intel"))
@ -72,31 +79,92 @@ void GLimp_InitExtraExtensions()
// OpenGL 2.0, was GL_ARB_shading_language_100, GL_ARB_vertex_program, GL_ARB_shader_objects, and GL_ARB_vertex_shader
QGL_2_0_PROCS;
// OpenGL 3.0, was GL_EXT_framebuffer_object, GL_EXT_framebuffer_blit, GL_EXT_framebuffer_multisample, and GL_ARB_vertex_array_object
// OpenGL 3.0 - no matching extension
// QGL_*_PROCS becomes several functions, do not remove {}
if (glRefConfig.openglMajorVersion >= 3)
if (q_gl_version_at_least_3_0)
{
QGL_3_0_PROCS;
}
// 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))
{
glRefConfig.framebufferObject = !!r_ext_framebuffer_object->integer;
glRefConfig.framebufferBlit = qtrue;
glRefConfig.framebufferMultisample = qtrue;
qglGetIntegerv(GL_MAX_RENDERBUFFER_SIZE_EXT, &glRefConfig.maxRenderbufferSize);
qglGetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &glRefConfig.maxColorAttachments);
qglGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &glRefConfig.maxRenderbufferSize);
qglGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &glRefConfig.maxColorAttachments);
ri.Printf(PRINT_ALL, result[glRefConfig.framebufferObject], "OpenGL 3.0+ framebuffer procs");
QGL_ARB_framebuffer_object_PROCS;
// Don't let this be disabled, core context requires it
glRefConfig.vertexArrayObject = qtrue;
ri.Printf(PRINT_ALL, result[glRefConfig.vertexArrayObject], "OpenGL 3.0+ vertex array object procs");
ri.Printf(PRINT_ALL, result[glRefConfig.framebufferObject], extension);
}
else
{
ri.Printf(PRINT_ALL, result[2], "OpenGL 3.0+ framebuffer procs");
ri.Printf(PRINT_ALL, result[2], "OpenGL 3.0+ vertex array object procs");
ri.Printf(PRINT_ALL, result[2], extension);
}
// OpenGL 3.0 - GL_ARB_vertex_array_object
extension = "GL_ARB_vertex_array_object";
glRefConfig.vertexArrayObject = qfalse;
if (SDL_GL_ExtensionSupported(extension))
{
glRefConfig.vertexArrayObject = !!r_arb_vertex_array_object->integer;
QGL_ARB_vertex_array_object_PROCS;
ri.Printf(PRINT_ALL, result[glRefConfig.vertexArrayObject], extension);
}
else
{
ri.Printf(PRINT_ALL, result[2], extension);
}
// OpenGL 3.0 - GL_ARB_texture_float
extension = "GL_ARB_texture_float";
glRefConfig.textureFloat = qfalse;
if (q_gl_version_at_least_3_0 || SDL_GL_ExtensionSupported(extension))
{
glRefConfig.textureFloat = !!r_ext_texture_float->integer;
ri.Printf(PRINT_ALL, result[glRefConfig.textureFloat], extension);
}
else
{
ri.Printf(PRINT_ALL, result[2], extension);
}
// 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))
{
glRefConfig.depthClamp = qtrue;
ri.Printf(PRINT_ALL, result[glRefConfig.depthClamp], extension);
}
else
{
ri.Printf(PRINT_ALL, result[2], extension);
}
// 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))
{
glRefConfig.seamlessCubeMap = !!r_arb_seamless_cube_map->integer;
ri.Printf(PRINT_ALL, result[glRefConfig.seamlessCubeMap], extension);
}
else
{
ri.Printf(PRINT_ALL, result[2], extension);
}
// Determine GLSL version
@ -146,20 +214,6 @@ void GLimp_InitExtraExtensions()
ri.Printf(PRINT_ALL, result[2], extension);
}
// GL_ARB_texture_float
extension = "GL_ARB_texture_float";
glRefConfig.textureFloat = qfalse;
if( SDL_GL_ExtensionSupported( extension ) )
{
glRefConfig.textureFloat = !!r_ext_texture_float->integer;
ri.Printf(PRINT_ALL, result[glRefConfig.textureFloat], extension);
}
else
{
ri.Printf(PRINT_ALL, result[2], extension);
}
glRefConfig.textureCompression = TCR_NONE;
// GL_ARB_texture_compression_rgtc
@ -196,34 +250,6 @@ void GLimp_InitExtraExtensions()
ri.Printf(PRINT_ALL, result[2], extension);
}
// GL_ARB_depth_clamp
extension = "GL_ARB_depth_clamp";
glRefConfig.depthClamp = qfalse;
if( SDL_GL_ExtensionSupported( extension ) )
{
glRefConfig.depthClamp = qtrue;
ri.Printf(PRINT_ALL, result[glRefConfig.depthClamp], extension);
}
else
{
ri.Printf(PRINT_ALL, result[2], extension);
}
// GL_ARB_seamless_cube_map
extension = "GL_ARB_seamless_cube_map";
glRefConfig.seamlessCubeMap = qfalse;
if( SDL_GL_ExtensionSupported( extension ) )
{
glRefConfig.seamlessCubeMap = !!r_arb_seamless_cube_map->integer;
ri.Printf(PRINT_ALL, result[glRefConfig.seamlessCubeMap], extension);
}
else
{
ri.Printf(PRINT_ALL, result[2], extension);
}
// GL_EXT_direct_state_access
extension = "GL_EXT_direct_state_access";
glRefConfig.directStateAccess = qfalse;