Skip to content

Commit

Permalink
Use OpenGL functions under extension names, if not present under regu…
Browse files Browse the repository at this point in the history
…lar names.
  • Loading branch information
Cyp committed Jun 16, 2012
1 parent 174c561 commit 96272eb
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
Binary file modified doc/gl/wzgl.ods
Binary file not shown.
34 changes: 31 additions & 3 deletions lib/ivis_opengl/screen.cpp
Expand Up @@ -204,12 +204,19 @@ void screenShutDown(void)
}

// Make OpenGL's VBO functions available under the core names for drivers that support OpenGL 1.4 only but have the VBO extension
void screen_EnableVBO()
void screen_EnableMissingFunctions()
{
// no need if there is OpenGL 1.5 available
if (!GLEW_VERSION_1_3 && GLEW_ARB_multitexture)
{
debug(LOG_WARNING, "Pre-OpenGL 1.3: Fixing ARB_multitexture extension function names.");

__glewActiveTexture = __glewActiveTextureARB;
__glewMultiTexCoord2fv = __glewMultiTexCoord2fvARB;
}

if (!GLEW_VERSION_1_5 && GLEW_ARB_vertex_buffer_object)
{
debug(LOG_WARNING, "OpenGL 1.4+: Using VBO extension functions under the core names.");
debug(LOG_WARNING, "Pre-OpenGL 1.5: Fixing ARB_vertex_buffer_object extension function names.");

__glewBindBuffer = __glewBindBufferARB;
__glewBufferData = __glewBufferDataARB;
Expand All @@ -223,6 +230,27 @@ void screen_EnableVBO()
__glewMapBuffer = __glewMapBufferARB;
__glewUnmapBuffer = __glewUnmapBufferARB;
}

if (!GLEW_VERSION_2_0 && GLEW_ARB_shader_objects)
{
debug(LOG_WARNING, "Pre-OpenGL 2.0: Fixing ARB_shader_objects extension function names.");

__glewGetUniformLocation = __glewGetUniformLocationARB;
__glewAttachShader = __glewAttachObjectARB;
__glewCompileShader = __glewCompileShaderARB;
__glewCreateProgram = __glewCreateProgramObjectARB;
__glewCreateShader = __glewCreateShaderObjectARB;
__glewGetProgramInfoLog = __glewGetInfoLogARB;
__glewGetShaderInfoLog = __glewGetInfoLogARB; // Same as previous.
__glewGetProgramiv = __glewGetObjectParameterivARB;
__glewUseProgram = __glewUseProgramObjectARB;
__glewGetShaderiv = __glewGetObjectParameterivARB;
__glewLinkProgram = __glewLinkProgramARB;
__glewShaderSource = __glewShaderSourceARB;
__glewUniform1f = __glewUniform1fARB;
__glewUniform1i = __glewUniform1iARB;
__glewUniform4fv = __glewUniform4fvARB;
}
}

void screen_SetBackDropFromFile(const char* filename)
Expand Down
2 changes: 1 addition & 1 deletion lib/ivis_opengl/screen.h
Expand Up @@ -63,8 +63,8 @@ extern void screenDoDumpToDiskIfRequired(void);
void screen_enableMapPreview(char *name, int width, int height, Vector2i *playerpositions);
void screen_disableMapPreview(void);
bool screen_getMapPreview(void);
void screen_EnableMissingFunctions();

void screen_EnableVBO();
struct OPENGL_DATA
{
char vendor[256];
Expand Down
4 changes: 4 additions & 0 deletions src/init.cpp
Expand Up @@ -35,6 +35,7 @@
#include "lib/framework/wzapp.h"
#include "lib/ivis_opengl/piemode.h"
#include "lib/ivis_opengl/piestate.h"
#include "lib/ivis_opengl/screen.h"
#include "lib/ivis_opengl/tex.h"
#include "lib/ivis_opengl/ivi.h"
#include "lib/netplay/netplay.h"
Expand Down Expand Up @@ -520,6 +521,9 @@ bool systemInitialise(void)
// Initialize the iVis text rendering module
iV_TextInit();

// Fix badly named OpenGL functions. Must be done after iV_TextInit, to avoid the renames being clobbered by an extra glewInit() call.
screen_EnableMissingFunctions();

iV_Reset(); // Reset the IV library.

readAIs();
Expand Down
3 changes: 0 additions & 3 deletions src/terrain.cpp
Expand Up @@ -711,9 +711,6 @@ bool initTerrain(void)
int decalSize;
int maxSectorSizeIndices, maxSectorSizeVertices;
bool decreasedSize = false;

// call VBO support hack before using it
screen_EnableVBO();

// this information is useful to prevent crashes with buggy opengl implementations
glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, &GLmaxElementsVertices);
Expand Down

0 comments on commit 96272eb

Please sign in to comment.