diff --git a/src/dusk/display/shader/shader.c b/src/dusk/display/shader/shader.c index cc6550a..d7a40c2 100644 --- a/src/dusk/display/shader/shader.c +++ b/src/dusk/display/shader/shader.c @@ -32,6 +32,17 @@ errorret_t shaderSetMatrix( 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"); +// errorChain(shaderSetColorPlatform(shader, name, color)); +// errorOk(); +// } + errorret_t shaderDispose(shader_t *shader) { assertNotNull(shader, "Shader cannot be null"); errorChain(shaderDisposePlatform(shader)); diff --git a/src/dusk/display/shader/shader.h b/src/dusk/display/shader/shader.h index 2af399d..7f2cf87 100644 --- a/src/dusk/display/shader/shader.h +++ b/src/dusk/display/shader/shader.h @@ -71,6 +71,20 @@ errorret_t shaderSetTexture( texture_t *texture ); +/** + * Sets a color uniform in the shader. This is platform dependant. + * + * @param shader Shader to set the color in + * @param name Name of the uniform to set + * @param color Color to set + * @return Error if failure, otherwise errorOk + */ +// errorret_t shaderSetColor( +// shader_t *shader, +// const char_t *name, +// color_t color +// ); + /** * Disposes of a shader. This is platform dependant. * diff --git a/src/dusk/display/shader/shaderunlit.h b/src/dusk/display/shader/shaderunlit.h index 881a695..752c732 100644 --- a/src/dusk/display/shader/shaderunlit.h +++ b/src/dusk/display/shader/shaderunlit.h @@ -11,6 +11,7 @@ #define SHADER_UNLIT_PROJECTION "u_Proj" #define SHADER_UNLIT_VIEW "u_View" #define SHADER_UNLIT_MODEL "u_Model" +// #define SHADER_UNLIT_COLOR "u_Color" extern shaderdefinition_t SHADER_UNLIT_DEFINITION; static shader_t SHADER_UNLIT; \ No newline at end of file diff --git a/src/duskgl/display/shader/shadergl.c b/src/duskgl/display/shader/shadergl.c index b753a43..148a306 100644 --- a/src/duskgl/display/shader/shadergl.c +++ b/src/duskgl/display/shader/shadergl.c @@ -203,6 +203,26 @@ errorret_t shaderSetMatrixGL( 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 +// assertUnreachable("Cannot set colors on legacy opengl."); +// #else +// GLint location; +// errorChain(shaderParamGetLocationGL(shader, name, &location)); + +// glUniform4f(location, color.r, color.g, color.b, color.a); +// errorChain(errorGLCheck()); +// #endif + +// errorOk(); +// } errorret_t shaderBindGL(shadergl_t *shader) { #ifdef DUSK_OPENGL_LEGACY diff --git a/src/duskgl/display/shader/shadergl.h b/src/duskgl/display/shader/shadergl.h index 2ba660e..0c6fa12 100644 --- a/src/duskgl/display/shader/shadergl.h +++ b/src/duskgl/display/shader/shadergl.h @@ -7,6 +7,7 @@ #pragma once #include "error/errorgl.h" +#include "display/color.h" typedef struct { #ifdef DUSK_OPENGL_LEGACY @@ -91,6 +92,34 @@ errorret_t shaderSetMatrixGL( mat4 matrix ); +/** + * Sets a color uniform parameter in the shader. + * + * @param shader The shader to update. + * @param name The name of the uniform parameter. + * @param color The color data to set. + * @return An errorret_t indicating success or failure. + */ +// errorret_t shaderSetTextureGL( +// shadergl_t *shader, +// const char_t *name, +// texture_t *texture +// ); + +/** + * Sets a color uniform parameter in the shader. + * + * @param shader The shader to update. + * @param name The name of the uniform parameter. + * @param color The color data to set. + * @return An errorret_t indicating success or failure. + */ +// errorret_t shaderSetColorGL( +// shadergl_t *shader, +// const char_t *name, +// color_t color +// ); + /** * Disposes of a shader, freeing any associated resources. * diff --git a/src/duskgl/display/shader/shaderplatform.h b/src/duskgl/display/shader/shaderplatform.h index 9d38587..2c5364a 100644 --- a/src/duskgl/display/shader/shaderplatform.h +++ b/src/duskgl/display/shader/shaderplatform.h @@ -15,4 +15,5 @@ typedef shaderdefinitiongl_t shaderdefinitionplatform_t; #define shaderBindPlatform shaderBindGL #define shaderSetMatrixPlatform shaderSetMatrixGL // #define shaderSetTexturePlatform shaderSetTextureGL +// #define shaderSetColorPlatform shaderSetColorGL #define shaderDisposePlatform shaderDisposeGL \ No newline at end of file diff --git a/src/duskgl/display/shader/shaderunlitgl.c b/src/duskgl/display/shader/shaderunlitgl.c index 179dc4e..7bc9123 100644 --- a/src/duskgl/display/shader/shaderunlitgl.c +++ b/src/duskgl/display/shader/shaderunlitgl.c @@ -14,18 +14,23 @@ .vert = "#version 330 core\n" "layout(location = 0) in vec3 aPos;\n" + "layout(location = 1) in vec2 aTexCoord;\n" + "layout(location = 2) in vec4 aColor;\n" "uniform mat4 u_Proj;\n" "uniform mat4 u_View;\n" "uniform mat4 u_Model;\n" + "out vec4 v_Color;\n" "void main() {\n" " gl_Position = u_Proj * u_View * u_Model * vec4(aPos, 1.0);\n" + " v_Color = aColor;\n" "}\n", .frag = "#version 330 core\n" + "in vec4 v_Color;\n" "out vec4 FragColor;\n" "void main() {\n" - " FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n" + " FragColor = v_Color;\n" "}\n" }; #endif \ No newline at end of file