/** * Copyright (c) 2026 Dominic Masters * * This software is released under the MIT License. * https://opensource.org/licenses/MIT */ #include "shader.h" #include "shadermaterial.h" #include "assert/assert.h" #include "log/log.h" shader_t *bound = NULL; errorret_t shaderInit(shader_t *shader, const shaderdefinition_t *def) { assertNotNull(shader, "Shader cannot be null"); errorChain(shaderInitPlatform(shader, def)); bound = NULL; errorOk(); } errorret_t shaderBind(shader_t *shader) { assertNotNull(shader, "Shader cannot be null"); errorChain(shaderBindPlatform(shader)); bound = shader; errorOk(); } errorret_t shaderSetMatrix( shader_t *shader, const char_t *name, mat4 matrix ) { assertNotNull(shader, "Shader cannot be null"); assertStrLenMin(name, 1, "Uniform name cannot be empty"); assertNotNull(matrix, "Matrix cannot be null"); assertTrue(bound == shader, "Shader must be bound."); errorChain(shaderSetMatrixPlatform(shader, name, matrix)); errorOk(); } errorret_t shaderSetTexture( shader_t *shader, const char_t *name, texture_t *texture ) { assertNotNull(shader, "Shader cannot be null"); assertStrLenMin(name, 1, "Uniform name cannot be empty"); assertTrue(bound == shader, "Shader must be bound."); errorChain(shaderSetTexturePlatform(shader, name, texture)); errorOk(); } errorret_t shaderSetColor( shader_t *shader, const char_t *name, color_t color ) { assertNotNull(shader, "Shader cannot be null"); assertStrLenMin(name, 1, "Uniform name cannot be empty"); assertTrue(bound == shader, "Shader must be bound."); errorChain(shaderSetColorPlatform(shader, name, color)); errorOk(); } errorret_t shaderSetMaterial( shader_t *shader, const shadermaterial_t *material ) { assertNotNull(shader, "Shader cannot be null"); assertNotNull(material, "Material cannot be null"); assertTrue(bound == shader, "Shader must be bound."); assertNotNull(shader->definition, "Shader definition cannot be null"); assertNotNull(shader->definition->setMaterial, "Def lacks setMaterial"); return shader->definition->setMaterial(shader, material); } errorret_t shaderDispose(shader_t *shader) { assertNotNull(shader, "Shader cannot be null"); bound = NULL; errorChain(shaderDisposePlatform(shader)); errorOk(); }