Moved texture setting around
This commit is contained in:
@@ -28,6 +28,11 @@ errorret_t shaderInitGL(shadergl_t *shader, const shaderdefinitiongl_t *def) {
|
||||
SHADER_LEGACY.boundShader = NULL;
|
||||
errorOk();
|
||||
#else
|
||||
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();
|
||||
@@ -212,6 +217,12 @@ errorret_t shaderSetTextureGL(
|
||||
assertStrLenMin(name, 1, "Uniform name cannot be empty");
|
||||
|
||||
#ifdef DUSK_OPENGL_LEGACY
|
||||
assertStringEqual(
|
||||
name,
|
||||
SHADER_UNLIT_TEXTURE,
|
||||
"Only one texture supported in legacy opengl."
|
||||
)
|
||||
|
||||
if(texture == NULL) {
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
errorChain(errorGLCheck());
|
||||
@@ -226,44 +237,10 @@ errorret_t shaderSetTextureGL(
|
||||
errorChain(errorGLCheck());
|
||||
|
||||
#else
|
||||
if(texture == NULL) {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
errorChain(errorGLCheck());
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
errorChain(errorGLCheck());
|
||||
errorOk();
|
||||
if(shader->setTexture == NULL) {
|
||||
assertUnreachable("Shader does not support setting textures.");
|
||||
}
|
||||
|
||||
GLint location;
|
||||
errorChain(shaderParamGetLocationGL(shader, name, &location));
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
errorChain(errorGLCheck());
|
||||
glBindTexture(GL_TEXTURE_2D, texture->id);
|
||||
errorChain(errorGLCheck());
|
||||
glUniform1i(location, 0);
|
||||
errorChain(errorGLCheck());
|
||||
|
||||
if(texture->format == TEXTURE_FORMAT_PALETTE) {
|
||||
shaderParamGetLocationGL(shader, "u_ColorCount", &location);
|
||||
glUniform1i(location, texture->palette->count);
|
||||
errorChain(errorGLCheck());
|
||||
|
||||
shaderParamGetLocationGL(shader, "u_Colors", &location);
|
||||
GLuint paletteData[texture->palette->count];
|
||||
for(size_t i = 0; i < texture->palette->count; i++) {
|
||||
color_t color = texture->palette->colors[i];
|
||||
paletteData[i] = (
|
||||
((uint32_t)color.r << 24) |
|
||||
((uint32_t)color.g << 16) |
|
||||
((uint32_t)color.b << 8) |
|
||||
((uint32_t)color.a << 0)
|
||||
);
|
||||
}
|
||||
glUniform1uiv(location, texture->palette->count, paletteData);
|
||||
errorChain(errorGLCheck());
|
||||
}
|
||||
|
||||
errorChain(shader->setTexture(shader, name, texture));
|
||||
#endif
|
||||
|
||||
errorOk();
|
||||
|
||||
Reference in New Issue
Block a user