Shader material ECS example
This commit is contained in:
@@ -20,6 +20,8 @@ errorret_t shaderInitGL(shadergl_t *shader, const shaderdefinitiongl_t *def) {
|
||||
assertNotNull(def, "Shader definition cannot be null");
|
||||
memoryZero(shader, sizeof(shadergl_t));
|
||||
|
||||
shader->definition = def;
|
||||
|
||||
#ifdef DUSK_OPENGL_LEGACY
|
||||
glm_mat4_identity(shader->view);
|
||||
glm_mat4_identity(shader->proj);
|
||||
@@ -31,8 +33,6 @@ errorret_t shaderInitGL(shadergl_t *shader, const shaderdefinitiongl_t *def) {
|
||||
assertNotNull(def->vert, "Vertex shader source cannot be null");
|
||||
assertNotNull(def->frag, "Fragment shader source cannot be null");
|
||||
|
||||
shader->setTexture = def->setTexture;
|
||||
|
||||
// Create vertex shader
|
||||
shader->vertexShaderId = glCreateShader(GL_VERTEX_SHADER);
|
||||
errorret_t err = errorGLCheck();
|
||||
@@ -237,10 +237,36 @@ errorret_t shaderSetTextureGL(
|
||||
errorChain(errorGLCheck());
|
||||
|
||||
#else
|
||||
if(shader->setTexture == NULL) {
|
||||
assertUnreachable("Shader does not support setting textures.");
|
||||
}
|
||||
errorChain(shader->setTexture(shader, name, texture));
|
||||
assertNotNull(shader->definition, "Shader definition cannot be null");
|
||||
assertNotNull(shader->definition->setTexture, "Shader cannot do textures.");
|
||||
errorChain(shader->definition->setTexture(shader, name, texture));
|
||||
#endif
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t shaderSetColorGL(
|
||||
shadergl_t *shader,
|
||||
const char_t *name,
|
||||
color_t color
|
||||
) {
|
||||
assertNotNull(shader, "Shader cannot be null");
|
||||
assertStrLenMin(name, 1, "Uniform name cannot be empty");
|
||||
|
||||
#ifdef DUSK_OPENGL_LEGACY
|
||||
glColor4ub(color.r, color.g, color.b, color.a);
|
||||
errorChain(errorGLCheck());
|
||||
#else
|
||||
GLint location;
|
||||
errorChain(shaderParamGetLocationGL(shader, name, &location));
|
||||
glUniform4f(
|
||||
location,
|
||||
color.r / 255.0f,
|
||||
color.g / 255.0f,
|
||||
color.b / 255.0f,
|
||||
color.a / 255.0f
|
||||
);
|
||||
errorChain(errorGLCheck());
|
||||
#endif
|
||||
|
||||
errorOk();
|
||||
|
||||
Reference in New Issue
Block a user