testgles2: Call correct function to get shader info log and add link status checking
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
diff --git a/test/testgles2.c b/test/testgles2.c
index 153ebe4..2000e01 100644
--- a/test/testgles2.c
+++ b/test/testgles2.c
@@ -38,6 +38,18 @@ typedef struct GLES2_Context
#undef SDL_PROC
} GLES2_Context;
+typedef struct shader_data
+{
+ GLuint shader_program, shader_frag, shader_vert;
+
+ GLint attr_position;
+ GLint attr_color, attr_mvp;
+
+ int angle_x, angle_y, angle_z;
+
+ GLuint position_buffer;
+ GLuint color_buffer;
+} shader_data;
static SDLTest_CommonState *state;
static SDL_GLContext *context = NULL;
@@ -197,13 +209,13 @@ multiply_matrix(float *lhs, float *rhs, float *r)
* source: Passed-in shader source code.
* shader_type: Passed to GL, e.g. GL_VERTEX_SHADER.
*/
-void
+static void
process_shader(GLuint *shader, const char * source, GLint shader_type)
{
GLint status = GL_FALSE;
const char *shaders[1] = { NULL };
char buffer[1024];
- GLsizei length;
+ GLsizei length = 0;
/* Create shader and load into GL. */
*shader = GL_CHECK(ctx.glCreateShader(shader_type));
@@ -221,13 +233,35 @@ process_shader(GLuint *shader, const char * source, GLint shader_type)
/* Dump debug info (source and log) if compilation failed. */
if(status != GL_TRUE) {
- ctx.glGetProgramInfoLog(*shader, sizeof(buffer), &length, &buffer[0]);
+ ctx.glGetShaderInfoLog(*shader, sizeof(buffer), &length, &buffer[0]);
buffer[length] = '\0';
- SDL_Log("Shader compilation failed: %s", buffer);fflush(stderr);
+ SDL_Log("Shader compilation failed: %s", buffer);
+ fflush(stderr);
quit(-1);
}
}
+static void
+link_program(struct shader_data *data)
+{
+ GLint status = GL_FALSE;
+ char buffer[1024];
+ GLsizei length = 0;
+
+ GL_CHECK(ctx.glAttachShader(data->shader_program, data->shader_vert));
+ GL_CHECK(ctx.glAttachShader(data->shader_program, data->shader_frag));
+ GL_CHECK(ctx.glLinkProgram(data->shader_program));
+ GL_CHECK(ctx.glGetProgramiv(data->shader_program, GL_LINK_STATUS, &status));
+
+ if(status != GL_TRUE) {
+ ctx.glGetProgramInfoLog(data->shader_program, sizeof(buffer), &length, &buffer[0]);
+ buffer[length] = '\0';
+ SDL_Log("Program linking failed: %s", buffer);
+ fflush(stderr);
+ quit(-1);
+ }
+}
+
/* 3D data. Vertex range -0.5..0.5 in all axes.
* Z -0.5 is near, 0.5 is far. */
const float _vertices[] =
@@ -363,19 +397,6 @@ const char* _shader_frag_src =
" gl_FragColor = vec4(vv3color, 1.0); "
" } ";
-typedef struct shader_data
-{
- GLuint shader_program, shader_frag, shader_vert;
-
- GLint attr_position;
- GLint attr_color, attr_mvp;
-
- int angle_x, angle_y, angle_z;
-
- GLuint position_buffer;
- GLuint color_buffer;
-} shader_data;
-
static void
Render(unsigned int width, unsigned int height, shader_data* data)
{
@@ -672,9 +693,7 @@ main(int argc, char *argv[])
data->shader_program = GL_CHECK(ctx.glCreateProgram());
/* Attach shaders and link shader_program */
- GL_CHECK(ctx.glAttachShader(data->shader_program, data->shader_vert));
- GL_CHECK(ctx.glAttachShader(data->shader_program, data->shader_frag));
- GL_CHECK(ctx.glLinkProgram(data->shader_program));
+ link_program(data);
/* Get attribute locations of non-fixed attributes like color and texture coordinates. */
data->attr_position = GL_CHECK(ctx.glGetAttribLocation(data->shader_program, "av4position"));