mirror of https://github.com/encounter/SDL.git
testgles2: Call correct function to get shader info log and add link status checking
This commit is contained in:
parent
6529bf3de7
commit
0dcfa92e4c
|
@ -38,6 +38,18 @@ typedef struct GLES2_Context
|
||||||
#undef SDL_PROC
|
#undef SDL_PROC
|
||||||
} GLES2_Context;
|
} 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 SDLTest_CommonState *state;
|
||||||
static SDL_GLContext *context = NULL;
|
static SDL_GLContext *context = NULL;
|
||||||
|
@ -197,13 +209,13 @@ multiply_matrix(float *lhs, float *rhs, float *r)
|
||||||
* source: Passed-in shader source code.
|
* source: Passed-in shader source code.
|
||||||
* shader_type: Passed to GL, e.g. GL_VERTEX_SHADER.
|
* shader_type: Passed to GL, e.g. GL_VERTEX_SHADER.
|
||||||
*/
|
*/
|
||||||
void
|
static void
|
||||||
process_shader(GLuint *shader, const char * source, GLint shader_type)
|
process_shader(GLuint *shader, const char * source, GLint shader_type)
|
||||||
{
|
{
|
||||||
GLint status = GL_FALSE;
|
GLint status = GL_FALSE;
|
||||||
const char *shaders[1] = { NULL };
|
const char *shaders[1] = { NULL };
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
GLsizei length;
|
GLsizei length = 0;
|
||||||
|
|
||||||
/* Create shader and load into GL. */
|
/* Create shader and load into GL. */
|
||||||
*shader = GL_CHECK(ctx.glCreateShader(shader_type));
|
*shader = GL_CHECK(ctx.glCreateShader(shader_type));
|
||||||
|
@ -221,9 +233,31 @@ process_shader(GLuint *shader, const char * source, GLint shader_type)
|
||||||
|
|
||||||
/* Dump debug info (source and log) if compilation failed. */
|
/* Dump debug info (source and log) if compilation failed. */
|
||||||
if(status != GL_TRUE) {
|
if(status != GL_TRUE) {
|
||||||
ctx.glGetProgramInfoLog(*shader, sizeof(buffer), &length, &buffer[0]);
|
ctx.glGetShaderInfoLog(*shader, sizeof(buffer), &length, &buffer[0]);
|
||||||
buffer[length] = '\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);
|
quit(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -363,19 +397,6 @@ const char* _shader_frag_src =
|
||||||
" gl_FragColor = vec4(vv3color, 1.0); "
|
" 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
|
static void
|
||||||
Render(unsigned int width, unsigned int height, shader_data* data)
|
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());
|
data->shader_program = GL_CHECK(ctx.glCreateProgram());
|
||||||
|
|
||||||
/* Attach shaders and link shader_program */
|
/* Attach shaders and link shader_program */
|
||||||
GL_CHECK(ctx.glAttachShader(data->shader_program, data->shader_vert));
|
link_program(data);
|
||||||
GL_CHECK(ctx.glAttachShader(data->shader_program, data->shader_frag));
|
|
||||||
GL_CHECK(ctx.glLinkProgram(data->shader_program));
|
|
||||||
|
|
||||||
/* Get attribute locations of non-fixed attributes like color and texture coordinates. */
|
/* Get attribute locations of non-fixed attributes like color and texture coordinates. */
|
||||||
data->attr_position = GL_CHECK(ctx.glGetAttribLocation(data->shader_program, "av4position"));
|
data->attr_position = GL_CHECK(ctx.glGetAttribLocation(data->shader_program, "av4position"));
|
||||||
|
|
Loading…
Reference in New Issue