testshader: Don't make local variables with the same name as GL entry points.

Reference Issue #2706.
This commit is contained in:
Ryan C. Gordon 2023-11-20 15:10:30 -05:00
parent c331b64d79
commit cb5b8c9747
No known key found for this signature in database
GPG key ID: FA148B892AB48044

View file

@ -109,36 +109,36 @@ static ShaderData shaders[NUM_SHADERS] = {
"}" }, "}" },
}; };
static PFNGLATTACHOBJECTARBPROC glAttachObjectARB; static PFNGLATTACHOBJECTARBPROC pglAttachObjectARB;
static PFNGLCOMPILESHADERARBPROC glCompileShaderARB; static PFNGLCOMPILESHADERARBPROC pglCompileShaderARB;
static PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB; static PFNGLCREATEPROGRAMOBJECTARBPROC pglCreateProgramObjectARB;
static PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB; static PFNGLCREATESHADEROBJECTARBPROC pglCreateShaderObjectARB;
static PFNGLDELETEOBJECTARBPROC glDeleteObjectARB; static PFNGLDELETEOBJECTARBPROC pglDeleteObjectARB;
static PFNGLGETINFOLOGARBPROC glGetInfoLogARB; static PFNGLGETINFOLOGARBPROC pglGetInfoLogARB;
static PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB; static PFNGLGETOBJECTPARAMETERIVARBPROC pglGetObjectParameterivARB;
static PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB; static PFNGLGETUNIFORMLOCATIONARBPROC pglGetUniformLocationARB;
static PFNGLLINKPROGRAMARBPROC glLinkProgramARB; static PFNGLLINKPROGRAMARBPROC pglLinkProgramARB;
static PFNGLSHADERSOURCEARBPROC glShaderSourceARB; static PFNGLSHADERSOURCEARBPROC pglShaderSourceARB;
static PFNGLUNIFORM1IARBPROC glUniform1iARB; static PFNGLUNIFORM1IARBPROC pglUniform1iARB;
static PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB; static PFNGLUSEPROGRAMOBJECTARBPROC pglUseProgramObjectARB;
static SDL_bool CompileShader(GLhandleARB shader, const char *source) static SDL_bool CompileShader(GLhandleARB shader, const char *source)
{ {
GLint status = 0; GLint status = 0;
glShaderSourceARB(shader, 1, &source, NULL); pglShaderSourceARB(shader, 1, &source, NULL);
glCompileShaderARB(shader); pglCompileShaderARB(shader);
glGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &status); pglGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &status);
if (status == 0) { if (status == 0) {
GLint length = 0; GLint length = 0;
char *info; char *info;
glGetObjectParameterivARB(shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length); pglGetObjectParameterivARB(shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
info = (char *)SDL_malloc((size_t)length + 1); info = (char *)SDL_malloc((size_t)length + 1);
if (!info) { if (!info) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!");
} else { } else {
glGetInfoLogARB(shader, length, NULL, info); pglGetInfoLogARB(shader, length, NULL, info);
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to compile shader:\n%s\n%s", source, info); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to compile shader:\n%s\n%s", source, info);
SDL_free(info); SDL_free(info);
} }
@ -152,21 +152,21 @@ static SDL_bool LinkProgram(ShaderData *data)
{ {
GLint status = 0; GLint status = 0;
glAttachObjectARB(data->program, data->vert_shader); pglAttachObjectARB(data->program, data->vert_shader);
glAttachObjectARB(data->program, data->frag_shader); pglAttachObjectARB(data->program, data->frag_shader);
glLinkProgramARB(data->program); pglLinkProgramARB(data->program);
glGetObjectParameterivARB(data->program, GL_OBJECT_LINK_STATUS_ARB, &status); pglGetObjectParameterivARB(data->program, GL_OBJECT_LINK_STATUS_ARB, &status);
if (status == 0) { if (status == 0) {
GLint length = 0; GLint length = 0;
char *info; char *info;
glGetObjectParameterivARB(data->program, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length); pglGetObjectParameterivARB(data->program, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
info = (char *)SDL_malloc((size_t)length + 1); info = (char *)SDL_malloc((size_t)length + 1);
if (!info) { if (!info) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!");
} else { } else {
glGetInfoLogARB(data->program, length, NULL, info); pglGetInfoLogARB(data->program, length, NULL, info);
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to link program:\n%s", info); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to link program:\n%s", info);
SDL_free(info); SDL_free(info);
} }
@ -185,16 +185,16 @@ static SDL_bool CompileShaderProgram(ShaderData *data)
glGetError(); glGetError();
/* Create one program object to rule them all */ /* Create one program object to rule them all */
data->program = glCreateProgramObjectARB(); data->program = pglCreateProgramObjectARB();
/* Create the vertex shader */ /* Create the vertex shader */
data->vert_shader = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB); data->vert_shader = pglCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
if (!CompileShader(data->vert_shader, data->vert_source)) { if (!CompileShader(data->vert_shader, data->vert_source)) {
return SDL_FALSE; return SDL_FALSE;
} }
/* Create the fragment shader */ /* Create the fragment shader */
data->frag_shader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB); data->frag_shader = pglCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
if (!CompileShader(data->frag_shader, data->frag_source)) { if (!CompileShader(data->frag_shader, data->frag_source)) {
return SDL_FALSE; return SDL_FALSE;
} }
@ -205,16 +205,16 @@ static SDL_bool CompileShaderProgram(ShaderData *data)
} }
/* Set up some uniform variables */ /* Set up some uniform variables */
glUseProgramObjectARB(data->program); pglUseProgramObjectARB(data->program);
for (i = 0; i < num_tmus_bound; ++i) { for (i = 0; i < num_tmus_bound; ++i) {
char tex_name[5]; char tex_name[5];
(void)SDL_snprintf(tex_name, SDL_arraysize(tex_name), "tex%d", i); (void)SDL_snprintf(tex_name, SDL_arraysize(tex_name), "tex%d", i);
location = glGetUniformLocationARB(data->program, tex_name); location = pglGetUniformLocationARB(data->program, tex_name);
if (location >= 0) { if (location >= 0) {
glUniform1iARB(location, i); pglUniform1iARB(location, i);
} }
} }
glUseProgramObjectARB(0); pglUseProgramObjectARB(0);
return (glGetError() == GL_NO_ERROR) ? SDL_TRUE : SDL_FALSE; return (glGetError() == GL_NO_ERROR) ? SDL_TRUE : SDL_FALSE;
} }
@ -222,9 +222,9 @@ static SDL_bool CompileShaderProgram(ShaderData *data)
static void DestroyShaderProgram(ShaderData *data) static void DestroyShaderProgram(ShaderData *data)
{ {
if (shaders_supported) { if (shaders_supported) {
glDeleteObjectARB(data->vert_shader); pglDeleteObjectARB(data->vert_shader);
glDeleteObjectARB(data->frag_shader); pglDeleteObjectARB(data->frag_shader);
glDeleteObjectARB(data->program); pglDeleteObjectARB(data->program);
} }
} }
@ -238,30 +238,30 @@ static SDL_bool InitShaders()
SDL_GL_ExtensionSupported("GL_ARB_shading_language_100") && SDL_GL_ExtensionSupported("GL_ARB_shading_language_100") &&
SDL_GL_ExtensionSupported("GL_ARB_vertex_shader") && SDL_GL_ExtensionSupported("GL_ARB_vertex_shader") &&
SDL_GL_ExtensionSupported("GL_ARB_fragment_shader")) { SDL_GL_ExtensionSupported("GL_ARB_fragment_shader")) {
glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)SDL_GL_GetProcAddress("glAttachObjectARB"); pglAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)SDL_GL_GetProcAddress("glAttachObjectARB");
glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)SDL_GL_GetProcAddress("glCompileShaderARB"); pglCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)SDL_GL_GetProcAddress("glCompileShaderARB");
glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)SDL_GL_GetProcAddress("glCreateProgramObjectARB"); pglCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)SDL_GL_GetProcAddress("glCreateProgramObjectARB");
glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)SDL_GL_GetProcAddress("glCreateShaderObjectARB"); pglCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)SDL_GL_GetProcAddress("glCreateShaderObjectARB");
glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC)SDL_GL_GetProcAddress("glDeleteObjectARB"); pglDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC)SDL_GL_GetProcAddress("glDeleteObjectARB");
glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC)SDL_GL_GetProcAddress("glGetInfoLogARB"); pglGetInfoLogARB = (PFNGLGETINFOLOGARBPROC)SDL_GL_GetProcAddress("glGetInfoLogARB");
glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC)SDL_GL_GetProcAddress("glGetObjectParameterivARB"); pglGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC)SDL_GL_GetProcAddress("glGetObjectParameterivARB");
glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC)SDL_GL_GetProcAddress("glGetUniformLocationARB"); pglGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC)SDL_GL_GetProcAddress("glGetUniformLocationARB");
glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)SDL_GL_GetProcAddress("glLinkProgramARB"); pglLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)SDL_GL_GetProcAddress("glLinkProgramARB");
glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)SDL_GL_GetProcAddress("glShaderSourceARB"); pglShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)SDL_GL_GetProcAddress("glShaderSourceARB");
glUniform1iARB = (PFNGLUNIFORM1IARBPROC)SDL_GL_GetProcAddress("glUniform1iARB"); pglUniform1iARB = (PFNGLUNIFORM1IARBPROC)SDL_GL_GetProcAddress("glUniform1iARB");
glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)SDL_GL_GetProcAddress("glUseProgramObjectARB"); pglUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)SDL_GL_GetProcAddress("glUseProgramObjectARB");
if (glAttachObjectARB && if (pglAttachObjectARB &&
glCompileShaderARB && pglCompileShaderARB &&
glCreateProgramObjectARB && pglCreateProgramObjectARB &&
glCreateShaderObjectARB && pglCreateShaderObjectARB &&
glDeleteObjectARB && pglDeleteObjectARB &&
glGetInfoLogARB && pglGetInfoLogARB &&
glGetObjectParameterivARB && pglGetObjectParameterivARB &&
glGetUniformLocationARB && pglGetUniformLocationARB &&
glLinkProgramARB && pglLinkProgramARB &&
glShaderSourceARB && pglShaderSourceARB &&
glUniform1iARB && pglUniform1iARB &&
glUseProgramObjectARB) { pglUseProgramObjectARB) {
shaders_supported = SDL_TRUE; shaders_supported = SDL_TRUE;
} }
} }
@ -420,7 +420,7 @@ void DrawGLScene(SDL_Window *window, GLuint texture, GLfloat *texcoord)
glBindTexture(GL_TEXTURE_2D, texture); glBindTexture(GL_TEXTURE_2D, texture);
glColor3f(1.0f, 1.0f, 1.0f); glColor3f(1.0f, 1.0f, 1.0f);
if (shaders_supported) { if (shaders_supported) {
glUseProgramObjectARB(shaders[current_shader].program); pglUseProgramObjectARB(shaders[current_shader].program);
} }
glBegin(GL_QUADS); /* start drawing a polygon (4 sided) */ glBegin(GL_QUADS); /* start drawing a polygon (4 sided) */
@ -435,7 +435,7 @@ void DrawGLScene(SDL_Window *window, GLuint texture, GLfloat *texcoord)
glEnd(); /* done with the polygon */ glEnd(); /* done with the polygon */
if (shaders_supported) { if (shaders_supported) {
glUseProgramObjectARB(0); pglUseProgramObjectARB(0);
} }
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);