[client] egl: rename "shader" to "this" for consistancy

This commit is contained in:
Geoffrey McRae 2018-12-12 16:31:25 +11:00
parent 4654f317ca
commit 43d08df6b3

View File

@ -33,32 +33,32 @@ struct EGL_Shader
GLuint shader; GLuint shader;
}; };
bool egl_shader_init(EGL_Shader ** shader) bool egl_shader_init(EGL_Shader ** this)
{ {
*shader = (EGL_Shader *)malloc(sizeof(EGL_Shader)); *this = (EGL_Shader *)malloc(sizeof(EGL_Shader));
if (!*shader) if (!*this)
{ {
DEBUG_ERROR("Failed to malloc EGL_Shader"); DEBUG_ERROR("Failed to malloc EGL_Shader");
return false; return false;
} }
memset(*shader, 0, sizeof(EGL_Shader)); memset(*this, 0, sizeof(EGL_Shader));
return true; return true;
} }
void egl_shader_free(EGL_Shader ** shader) void egl_shader_free(EGL_Shader ** this)
{ {
if (!*shader) if (!*this)
return; return;
if ((*shader)->hasShader) if ((*this)->hasShader)
glDeleteProgram((*shader)->shader); glDeleteProgram((*this)->shader);
free(*shader); free(*this);
*shader = NULL; *this = NULL;
} }
bool egl_shader_load(EGL_Shader * shader, const char * vertex_file, const char * fragment_file) bool egl_shader_load(EGL_Shader * this, const char * vertex_file, const char * fragment_file)
{ {
char * vertex_code, * fragment_code; char * vertex_code, * fragment_code;
size_t vertex_size, fragment_size; size_t vertex_size, fragment_size;
@ -80,18 +80,18 @@ bool egl_shader_load(EGL_Shader * shader, const char * vertex_file, const char *
DEBUG_INFO("Loaded fragment shader: %s", fragment_file); DEBUG_INFO("Loaded fragment shader: %s", fragment_file);
bool ret = egl_shader_compile(shader, vertex_code, vertex_size, fragment_code, fragment_size); bool ret = egl_shader_compile(this, vertex_code, vertex_size, fragment_code, fragment_size);
free(vertex_code); free(vertex_code);
free(fragment_code); free(fragment_code);
return ret; return ret;
} }
bool egl_shader_compile(EGL_Shader * shader, const char * vertex_code, size_t vertex_size, const char * fragment_code, size_t fragment_size) bool egl_shader_compile(EGL_Shader * this, const char * vertex_code, size_t vertex_size, const char * fragment_code, size_t fragment_size)
{ {
if (shader->hasShader) if (this->hasShader)
{ {
glDeleteProgram(shader->shader); glDeleteProgram(this->shader);
shader->hasShader = false; this->hasShader = false;
} }
GLint length; GLint length;
@ -149,59 +149,59 @@ bool egl_shader_compile(EGL_Shader * shader, const char * vertex_code, size_t ve
return false; return false;
} }
shader->shader = glCreateProgram(); this->shader = glCreateProgram();
glAttachShader(shader->shader, vertexShader ); glAttachShader(this->shader, vertexShader );
glAttachShader(shader->shader, fragmentShader); glAttachShader(this->shader, fragmentShader);
glLinkProgram(shader->shader); glLinkProgram(this->shader);
glGetProgramiv(shader->shader, GL_LINK_STATUS, &result); glGetProgramiv(this->shader, GL_LINK_STATUS, &result);
if (result == GL_FALSE) if (result == GL_FALSE)
{ {
DEBUG_ERROR("Failed to link shader program"); DEBUG_ERROR("Failed to link shader program");
int logLength; int logLength;
glGetProgramiv(shader->shader, GL_INFO_LOG_LENGTH, &logLength); glGetProgramiv(this->shader, GL_INFO_LOG_LENGTH, &logLength);
if (logLength > 0) if (logLength > 0)
{ {
char *log = malloc(logLength + 1); char *log = malloc(logLength + 1);
glGetProgramInfoLog(shader->shader, logLength, NULL, log); glGetProgramInfoLog(this->shader, logLength, NULL, log);
log[logLength] = 0; log[logLength] = 0;
DEBUG_ERROR("%s", log); DEBUG_ERROR("%s", log);
free(log); free(log);
} }
glDetachShader(shader->shader, vertexShader ); glDetachShader(this->shader, vertexShader );
glDetachShader(shader->shader, fragmentShader); glDetachShader(this->shader, fragmentShader);
glDeleteShader(fragmentShader); glDeleteShader(fragmentShader);
glDeleteShader(vertexShader ); glDeleteShader(vertexShader );
glDeleteProgram(shader->shader ); glDeleteProgram(this->shader );
return false; return false;
} }
glDetachShader(shader->shader, vertexShader ); glDetachShader(this->shader, vertexShader );
glDetachShader(shader->shader, fragmentShader); glDetachShader(this->shader, fragmentShader);
glDeleteShader(fragmentShader); glDeleteShader(fragmentShader);
glDeleteShader(vertexShader ); glDeleteShader(vertexShader );
shader->hasShader = true; this->hasShader = true;
return true; return true;
} }
void egl_shader_use(EGL_Shader * shader) void egl_shader_use(EGL_Shader * this)
{ {
if (shader->hasShader) if (this->hasShader)
glUseProgram(shader->shader); glUseProgram(this->shader);
else else
DEBUG_ERROR("Shader program has not been compiled"); DEBUG_ERROR("Shader program has not been compiled");
} }
void egl_shader_associate_textures(EGL_Shader * shader, const int count) void egl_shader_associate_textures(EGL_Shader * this, const int count)
{ {
char name[] = "sampler1"; char name[] = "sampler1";
glUseProgram(shader->shader); glUseProgram(this->shader);
for(int i = 0; i < count; ++i, name[7]++) for(int i = 0; i < count; ++i, name[7]++)
{ {
GLint loc = glGetUniformLocation(shader->shader, name); GLint loc = glGetUniformLocation(this->shader, name);
if (loc == -1) if (loc == -1)
{ {
DEBUG_WARN("Shader uniform location `%s` not found", name); DEBUG_WARN("Shader uniform location `%s` not found", name);
@ -213,7 +213,7 @@ void egl_shader_associate_textures(EGL_Shader * shader, const int count)
glUseProgram(0); glUseProgram(0);
} }
GLint egl_shader_get_uniform_location(EGL_Shader * shader, const char * name) GLint egl_shader_get_uniform_location(EGL_Shader * this, const char * name)
{ {
return glGetUniformLocation(shader->shader, name); return glGetUniformLocation(this->shader, name);
} }