testgles2: Call correct function to get shader info log and add link status checking

This commit is contained in:
capehill 2022-03-26 19:31:17 +02:00 committed by Sam Lantinga
parent 6529bf3de7
commit 0dcfa92e4c
1 changed files with 39 additions and 20 deletions

View File

@ -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"));