From 9858cf98008296ce3ec6b824b9b02a2c65d9194f Mon Sep 17 00:00:00 2001 From: ecker Date: Sat, 16 Aug 2025 00:46:00 -0500 Subject: [PATCH] for opengl, have uniform colors bind to a draw command via pointer like an actual shader uniform (and also have it prioritize vertex colors instead) --- engine/inc/uf/ext/opengl/commands.h | 1 + engine/src/ext/opengl/commands.cpp | 13 +++++++------ engine/src/ext/opengl/graphic.cpp | 3 ++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/engine/inc/uf/ext/opengl/commands.h b/engine/inc/uf/ext/opengl/commands.h index fb36ca31..3b9eda65 100644 --- a/engine/inc/uf/ext/opengl/commands.h +++ b/engine/inc/uf/ext/opengl/commands.h @@ -75,6 +75,7 @@ namespace ext { struct { bool enabled = false; pod::Vector4f value = { 1, 1, 1, 1 }; + const pod::Vector4f* pointer = NULL; } color; }; /* diff --git a/engine/src/ext/opengl/commands.cpp b/engine/src/ext/opengl/commands.cpp index dbb62876..41abf113 100644 --- a/engine/src/ext/opengl/commands.cpp +++ b/engine/src/ext/opengl/commands.cpp @@ -434,18 +434,19 @@ void ext::opengl::CommandBuffer::drawIndexed( const ext::opengl::CommandBuffer:: GL_ERROR_CHECK(glNormalPointer(normalType, drawInfo.attributes.normal.stride, normalPtr)); } - if ( drawInfo.attributes.color.pointer ) { + // prioritize uniform color for now + if ( drawInfo.color.enabled ) { + const auto& color = drawInfo.color.pointer ? *drawInfo.color.pointer : drawInfo.color.value; + colors = uf::stl::vector( drawInfo.descriptor.inputs.vertex.count, color ); + GL_ERROR_CHECK(glColorPointer(4, GL_FLOAT, sizeof(pod::Vector4f), colors.data())); + // GL_ERROR_CHECK(glColor4f( color[0], color[1], color[2], color[3] )); + } else if ( drawInfo.attributes.color.pointer ) { GLenum colorType = GL_UNSIGNED_BYTE; switch ( drawInfo.attributes.color.descriptor.size / drawInfo.attributes.color.descriptor.components ) { case sizeof(uint8_t): colorType = GL_UNSIGNED_BYTE; break; case sizeof(float): colorType = GL_FLOAT; break; } GL_ERROR_CHECK(glColorPointer(drawInfo.attributes.color.descriptor.components, colorType, drawInfo.attributes.color.stride, colorPtr)); - } else if ( drawInfo.color.enabled ) { - colors = uf::stl::vector( drawInfo.descriptor.inputs.vertex.count, drawInfo.color.value ); - GL_ERROR_CHECK(glColorPointer(4, GL_FLOAT, sizeof(pod::Vector4f), &(colors[0][0]))); - - // GL_ERROR_CHECK(glColor4f( drawInfo.color.value[0], drawInfo.color.value[1], drawInfo.color.value[2], drawInfo.color.value[3] )); } if ( drawInfo.textures.primary.image && drawInfo.attributes.uv.pointer ) { diff --git a/engine/src/ext/opengl/graphic.cpp b/engine/src/ext/opengl/graphic.cpp index ed45c3b6..7d4a8714 100644 --- a/engine/src/ext/opengl/graphic.cpp +++ b/engine/src/ext/opengl/graphic.cpp @@ -389,8 +389,9 @@ void ext::opengl::Graphic::record( CommandBuffer& commandBuffer, const GraphicDe drawCommandInfoBase.matrices.model = &uniforms->modelView; drawCommandInfoBase.matrices.projection = &uniforms->projection; + drawCommandInfoBase.color.pointer = &uniforms->color; drawCommandInfoBase.color.value = uniforms->color; - drawCommandInfoBase.color.enabled = drawCommandInfoBase.color.value != pod::Vector4f{1.0f, 1.0f, 1.0f, 1.0f}; + drawCommandInfoBase.color.enabled = true; // drawCommandInfoBase.color.value != pod::Vector4f{1.0f, 1.0f, 1.0f, 1.0f}; } struct {