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

From cb5b8c97472ed1c759bb6934372e3c3ff4aad8f3 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Mon, 20 Nov 2023 15:10:30 -0500
Subject: [PATCH] testshader: Don't make local variables with the same name as
 GL entry points.

Reference Issue #2706.
---
 test/testshader.c | 118 +++++++++++++++++++++++-----------------------
 1 file changed, 59 insertions(+), 59 deletions(-)

diff --git a/test/testshader.c b/test/testshader.c
index 47bce205cfaa..6f59b5fbd3c8 100644
--- a/test/testshader.c
+++ b/test/testshader.c
@@ -109,36 +109,36 @@ static ShaderData shaders[NUM_SHADERS] = {
       "}" },
 };
 
-static PFNGLATTACHOBJECTARBPROC glAttachObjectARB;
-static PFNGLCOMPILESHADERARBPROC glCompileShaderARB;
-static PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB;
-static PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB;
-static PFNGLDELETEOBJECTARBPROC glDeleteObjectARB;
-static PFNGLGETINFOLOGARBPROC glGetInfoLogARB;
-static PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB;
-static PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB;
-static PFNGLLINKPROGRAMARBPROC glLinkProgramARB;
-static PFNGLSHADERSOURCEARBPROC glShaderSourceARB;
-static PFNGLUNIFORM1IARBPROC glUniform1iARB;
-static PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB;
+static PFNGLATTACHOBJECTARBPROC pglAttachObjectARB;
+static PFNGLCOMPILESHADERARBPROC pglCompileShaderARB;
+static PFNGLCREATEPROGRAMOBJECTARBPROC pglCreateProgramObjectARB;
+static PFNGLCREATESHADEROBJECTARBPROC pglCreateShaderObjectARB;
+static PFNGLDELETEOBJECTARBPROC pglDeleteObjectARB;
+static PFNGLGETINFOLOGARBPROC pglGetInfoLogARB;
+static PFNGLGETOBJECTPARAMETERIVARBPROC pglGetObjectParameterivARB;
+static PFNGLGETUNIFORMLOCATIONARBPROC pglGetUniformLocationARB;
+static PFNGLLINKPROGRAMARBPROC pglLinkProgramARB;
+static PFNGLSHADERSOURCEARBPROC pglShaderSourceARB;
+static PFNGLUNIFORM1IARBPROC pglUniform1iARB;
+static PFNGLUSEPROGRAMOBJECTARBPROC pglUseProgramObjectARB;
 
 static SDL_bool CompileShader(GLhandleARB shader, const char *source)
 {
     GLint status = 0;
 
-    glShaderSourceARB(shader, 1, &source, NULL);
-    glCompileShaderARB(shader);
-    glGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &status);
+    pglShaderSourceARB(shader, 1, &source, NULL);
+    pglCompileShaderARB(shader);
+    pglGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &status);
     if (status == 0) {
         GLint length = 0;
         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);
         if (!info) {
             SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!");
         } 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_free(info);
         }
@@ -152,21 +152,21 @@ static SDL_bool LinkProgram(ShaderData *data)
 {
     GLint status = 0;
 
-    glAttachObjectARB(data->program, data->vert_shader);
-    glAttachObjectARB(data->program, data->frag_shader);
-    glLinkProgramARB(data->program);
+    pglAttachObjectARB(data->program, data->vert_shader);
+    pglAttachObjectARB(data->program, data->frag_shader);
+    pglLinkProgramARB(data->program);
 
-    glGetObjectParameterivARB(data->program, GL_OBJECT_LINK_STATUS_ARB, &status);
+    pglGetObjectParameterivARB(data->program, GL_OBJECT_LINK_STATUS_ARB, &status);
     if (status == 0) {
         GLint length = 0;
         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);
         if (!info) {
             SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!");
         } 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_free(info);
         }
@@ -185,16 +185,16 @@ static SDL_bool CompileShaderProgram(ShaderData *data)
     glGetError();
 
     /* Create one program object to rule them all */
-    data->program = glCreateProgramObjectARB();
+    data->program = pglCreateProgramObjectARB();
 
     /* 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)) {
         return SDL_FALSE;
     }
 
     /* 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)) {
         return SDL_FALSE;
     }
@@ -205,16 +205,16 @@ static SDL_bool CompileShaderProgram(ShaderData *data)
     }
 
     /* Set up some uniform variables */
-    glUseProgramObjectARB(data->program);
+    pglUseProgramObjectARB(data->program);
     for (i = 0; i < num_tmus_bound; ++i) {
         char tex_name[5];
         (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) {
-            glUniform1iARB(location, i);
+            pglUniform1iARB(location, i);
         }
     }
-    glUseProgramObjectARB(0);
+    pglUseProgramObjectARB(0);
 
     return (glGetError() == GL_NO_ERROR) ? SDL_TRUE : SDL_FALSE;
 }
@@ -222,9 +222,9 @@ static SDL_bool CompileShaderProgram(ShaderData *data)
 static void DestroyShaderProgram(ShaderData *data)
 {
     if (shaders_supported) {
-        glDeleteObjectARB(data->vert_shader);
-        glDeleteObjectARB(data->frag_shader);
-        glDeleteObjectARB(data->program);
+        pglDeleteObjectARB(data->vert_shader);
+        pglDeleteObjectARB(data->frag_shader);
+        pglDeleteObjectARB(data->program);
     }
 }
 
@@ -238,30 +238,30 @@ static SDL_bool InitShaders()
         SDL_GL_ExtensionSupported("GL_ARB_shading_language_100") &&
         SDL_GL_ExtensionSupported("GL_ARB_vertex_shader") &&
         SDL_GL_ExtensionSupported("GL_ARB_fragment_shader")) {
-        glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)SDL_GL_GetProcAddress("glAttachObjectARB");
-        glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)SDL_GL_GetProcAddress("glCompileShaderARB");
-        glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)SDL_GL_GetProcAddress("glCreateProgramObjectARB");
-        glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)SDL_GL_GetProcAddress("glCreateShaderObjectARB");
-        glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC)SDL_GL_GetProcAddress("glDeleteObjectARB");
-        glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC)SDL_GL_GetProcAddress("glGetInfoLogARB");
-        glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC)SDL_GL_GetProcAddress("glGetObjectParameterivARB");
-        glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC)SDL_GL_GetProcAddress("glGetUniformLocationARB");
-        glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)SDL_GL_GetProcAddress("glLinkProgramARB");
-        glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)SDL_GL_GetProcAddress("glShaderSourceARB");
-        glUniform1iARB = (PFNGLUNIFORM1IARBPROC)SDL_GL_GetProcAddress("glUniform1iARB");
-        glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)SDL_GL_GetProcAddress("glUseProgramObjectARB");
-        if (glAttachObjectARB &&
-            glCompileShaderARB &&
-            glCreateProgramObjectARB &&
-            glCreateShaderObjectARB &&
-            glDeleteObjectARB &&
-            glGetInfoLogARB &&
-            glGetObjectParameterivARB &&
-            glGetUniformLocationARB &&
-            glLinkProgramARB &&
-            glShaderSourceARB &&
-            glUniform1iARB &&
-            glUseProgramObjectARB) {
+        pglAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)SDL_GL_GetProcAddress("glAttachObjectARB");
+        pglCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)SDL_GL_GetProcAddress("glCompileShaderARB");
+        pglCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)SDL_GL_GetProcAddress("glCreateProgramObjectARB");
+        pglCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)SDL_GL_GetProcAddress("glCreateShaderObjectARB");
+        pglDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC)SDL_GL_GetProcAddress("glDeleteObjectARB");
+        pglGetInfoLogARB = (PFNGLGETINFOLOGARBPROC)SDL_GL_GetProcAddress("glGetInfoLogARB");
+        pglGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC)SDL_GL_GetProcAddress("glGetObjectParameterivARB");
+        pglGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC)SDL_GL_GetProcAddress("glGetUniformLocationARB");
+        pglLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)SDL_GL_GetProcAddress("glLinkProgramARB");
+        pglShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)SDL_GL_GetProcAddress("glShaderSourceARB");
+        pglUniform1iARB = (PFNGLUNIFORM1IARBPROC)SDL_GL_GetProcAddress("glUniform1iARB");
+        pglUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)SDL_GL_GetProcAddress("glUseProgramObjectARB");
+        if (pglAttachObjectARB &&
+            pglCompileShaderARB &&
+            pglCreateProgramObjectARB &&
+            pglCreateShaderObjectARB &&
+            pglDeleteObjectARB &&
+            pglGetInfoLogARB &&
+            pglGetObjectParameterivARB &&
+            pglGetUniformLocationARB &&
+            pglLinkProgramARB &&
+            pglShaderSourceARB &&
+            pglUniform1iARB &&
+            pglUseProgramObjectARB) {
             shaders_supported = SDL_TRUE;
         }
     }
@@ -420,7 +420,7 @@ void DrawGLScene(SDL_Window *window, GLuint texture, GLfloat *texcoord)
     glBindTexture(GL_TEXTURE_2D, texture);
     glColor3f(1.0f, 1.0f, 1.0f);
     if (shaders_supported) {
-        glUseProgramObjectARB(shaders[current_shader].program);
+        pglUseProgramObjectARB(shaders[current_shader].program);
     }
 
     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 */
 
     if (shaders_supported) {
-        glUseProgramObjectARB(0);
+        pglUseProgramObjectARB(0);
     }
     glDisable(GL_TEXTURE_2D);