Skip to content

Commit

Permalink
[GL] Removed unused function GLSetUniformsByLocation() due to wrong i…
Browse files Browse the repository at this point in the history
…ndex parameter.

- Removed GLSetUniformsByLocation() because the location was erroneously used as index for glGetActiveUniform(), which is not the correct value.
- Renamed GLSetUniformsByType() to "GLSetUniform".
- Renamed all "GL*SetUniforms" identifiers to "GL*SetUniform".
  • Loading branch information
LukasBanana committed Jun 26, 2024
1 parent e5dfadf commit c8fd96b
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 42 deletions.
2 changes: 1 addition & 1 deletion sources/Renderer/OpenGL/Command/GLCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ struct GLCmdSetStencilRef
GLenum face;
};

struct GLCmdSetUniforms
struct GLCmdSetUniform
{
GLuint program;
UniformType type;
Expand Down
6 changes: 3 additions & 3 deletions sources/Renderer/OpenGL/Command/GLCommandAssembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,10 @@ static std::size_t AssembleGLCommand(const GLOpcode opcode, const void* pc, JITC
compiler.CallMember(&GLStateManager::SetStencilRef, g_stateMngrArg, cmd->ref, cmd->face);
return sizeof(*cmd);
}
case GLOpcodeSetUniforms:
case GLOpcodeSetUniform:
{
auto cmd = reinterpret_cast<const GLCmdSetUniforms*>(pc);
compiler.Call(GLSetUniformsByType, cmd->type, cmd->location, cmd->count, (cmd + 1));
auto cmd = reinterpret_cast<const GLCmdSetUniform*>(pc);
compiler.Call(GLSetUniform, cmd->type, cmd->location, cmd->count, (cmd + 1));
return (sizeof(*cmd) + cmd->size);
}
case GLOpcodeBeginQuery:
Expand Down
6 changes: 3 additions & 3 deletions sources/Renderer/OpenGL/Command/GLCommandExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@ static std::size_t ExecuteGLCommand(const GLOpcode opcode, const void* pc, GLSta
stateMngr->SetStencilRef(cmd->ref, cmd->face);
return sizeof(*cmd);
}
case GLOpcodeSetUniforms:
case GLOpcodeSetUniform:
{
auto cmd = reinterpret_cast<const GLCmdSetUniforms*>(pc);
GLSetUniformsByType(cmd->type, cmd->location, cmd->count, (cmd + 1));
auto cmd = reinterpret_cast<const GLCmdSetUniform*>(pc);
GLSetUniform(cmd->type, cmd->location, cmd->count, (cmd + 1));
return (sizeof(*cmd) + cmd->size);
}
case GLOpcodeBeginQuery:
Expand Down
2 changes: 1 addition & 1 deletion sources/Renderer/OpenGL/Command/GLCommandOpcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ enum GLOpcode : std::uint8_t
GLOpcodeBindPipelineState,
GLOpcodeSetBlendColor,
GLOpcodeSetStencilRef,
GLOpcodeSetUniforms,
GLOpcodeSetUniform,
GLOpcodeBeginQuery,
GLOpcodeEndQuery,
GLOpcodeBeginConditionalRender,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ void GLDeferredCommandBuffer::SetUniforms(std::uint32_t first, const void* data,
/* Allocate GL command and copy data buffer */
const auto& uniform = uniformMap[first];
const std::uint32_t uniformSize = uniform.wordSize * 4;
auto cmd = AllocCommand<GLCmdSetUniforms>(GLOpcodeSetUniforms, dataSize);
auto cmd = AllocCommand<GLCmdSetUniform>(GLOpcodeSetUniform, dataSize);
{
cmd->program = boundShaderPipeline->GetID(); //TODO: must distinguish between GLShaderProgram and GLProgramPipeline
cmd->type = uniform.type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ void GLImmediateCommandBuffer::SetUniforms(std::uint32_t first, const void* data
return /*GL_INVALID_INDEX*/;

const auto& uniform = uniformMap[first];
GLSetUniformsByType(uniform.type, uniform.location, uniform.count, words);
GLSetUniform(uniform.type, uniform.location, uniform.count, words);

words += uniform.wordSize;
}
Expand Down
2 changes: 1 addition & 1 deletion sources/Renderer/OpenGL/GLStaticAssertions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ LLGL_ASSERT_STDLAYOUT_STRUCT( GLCmdBindRenderTarget );
LLGL_ASSERT_STDLAYOUT_STRUCT( GLCmdBindPipelineState );
LLGL_ASSERT_STDLAYOUT_STRUCT( GLCmdSetBlendColor );
LLGL_ASSERT_STDLAYOUT_STRUCT( GLCmdSetStencilRef );
LLGL_ASSERT_STDLAYOUT_STRUCT( GLCmdSetUniforms );
LLGL_ASSERT_STDLAYOUT_STRUCT( GLCmdSetUniform );
LLGL_ASSERT_STDLAYOUT_STRUCT( GLCmdBeginQuery );
LLGL_ASSERT_STDLAYOUT_STRUCT( GLCmdEndQuery );
LLGL_ASSERT_STDLAYOUT_STRUCT( GLCmdBeginConditionalRender );
Expand Down
42 changes: 15 additions & 27 deletions sources/Renderer/OpenGL/Shader/GLShaderUniform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace LLGL


// Requires GL 2.0
static void GLSetUniformsInt(UniformType type, GLint location, GLsizei count, const GLint* data)
static void GLSetUniformInt(UniformType type, GLint location, GLsizei count, const GLint* data)
{
switch (type)
{
Expand Down Expand Up @@ -45,7 +45,7 @@ static void GLSetUniformsInt(UniformType type, GLint location, GLsizei count, co
}

// Requires GL 2.0
static void GLSetUniformsFloat(UniformType type, GLint location, GLsizei count, const GLfloat* data)
static void GLSetUniformFloat(UniformType type, GLint location, GLsizei count, const GLfloat* data)
{
switch (type)
{
Expand Down Expand Up @@ -76,7 +76,7 @@ static void GLSetUniformsFloat(UniformType type, GLint location, GLsizei count,
}

// Requires GL 2.1
static void GLSetUniformsFloatNxM(UniformType type, GLint location, GLsizei count, const GLfloat* data)
static void GLSetUniformFloatNxM(UniformType type, GLint location, GLsizei count, const GLfloat* data)
{
if (!HasExtension(GLExt::ARB_shader_objects_21))
return;
Expand Down Expand Up @@ -107,7 +107,7 @@ static void GLSetUniformsFloatNxM(UniformType type, GLint location, GLsizei coun
}

// Requires GL 3.0
static void GLSetUniformsUInt(UniformType type, GLint location, GLsizei count, const GLuint* data)
static void GLSetUniformUInt(UniformType type, GLint location, GLsizei count, const GLuint* data)
{
if (!HasExtension(GLExt::ARB_shader_objects_30))
return;
Expand All @@ -134,7 +134,7 @@ static void GLSetUniformsUInt(UniformType type, GLint location, GLsizei count, c
#ifdef LLGL_OPENGL

// Requires GL 4.0
static void GLSetUniformsDouble(UniformType type, GLint location, GLsizei count, const GLdouble* data)
static void GLSetUniformDouble(UniformType type, GLint location, GLsizei count, const GLdouble* data)
{
if (!HasExtension(GLExt::ARB_shader_objects_40))
return;
Expand Down Expand Up @@ -188,7 +188,7 @@ static void GLSetUniformsDouble(UniformType type, GLint location, GLsizei count,
#endif // /LLGL_OPENGL


void GLSetUniformsByType(UniformType type, GLint location, GLsizei count, const void* data)
void GLSetUniform(UniformType type, GLint location, GLsizei count, const void* data)
{
switch (type)
{
Expand All @@ -200,44 +200,44 @@ void GLSetUniformsByType(UniformType type, GLint location, GLsizei count, const
case UniformType::Float2:
case UniformType::Float3:
case UniformType::Float4:
GLSetUniformsFloat(type, location, count, reinterpret_cast<const GLfloat*>(data));
GLSetUniformFloat(type, location, count, reinterpret_cast<const GLfloat*>(data));
break;

case UniformType::Double1:
case UniformType::Double2:
case UniformType::Double3:
case UniformType::Double4:
#ifdef LLGL_OPENGL
GLSetUniformsDouble(type, location, count, reinterpret_cast<const GLdouble*>(data));
GLSetUniformDouble(type, location, count, reinterpret_cast<const GLdouble*>(data));
#endif
break;

case UniformType::Int1:
case UniformType::Int2:
case UniformType::Int3:
case UniformType::Int4:
GLSetUniformsInt(type, location, count, reinterpret_cast<const GLint*>(data));
GLSetUniformInt(type, location, count, reinterpret_cast<const GLint*>(data));
break;

case UniformType::UInt1:
case UniformType::UInt2:
case UniformType::UInt3:
case UniformType::UInt4:
GLSetUniformsUInt(type, location, count, reinterpret_cast<const GLuint*>(data));
GLSetUniformUInt(type, location, count, reinterpret_cast<const GLuint*>(data));
break;

case UniformType::Bool1:
case UniformType::Bool2:
case UniformType::Bool3:
case UniformType::Bool4:
GLSetUniformsInt(type, location, count, reinterpret_cast<const GLint*>(data));
GLSetUniformInt(type, location, count, reinterpret_cast<const GLint*>(data));
break;

/* ----- Matrices ----- */
case UniformType::Float2x2:
case UniformType::Float3x3:
case UniformType::Float4x4:
GLSetUniformsFloat(type, location, count, reinterpret_cast<const GLfloat*>(data));
GLSetUniformFloat(type, location, count, reinterpret_cast<const GLfloat*>(data));
break;

case UniformType::Float2x3:
Expand All @@ -246,7 +246,7 @@ void GLSetUniformsByType(UniformType type, GLint location, GLsizei count, const
case UniformType::Float3x4:
case UniformType::Float4x2:
case UniformType::Float4x3:
GLSetUniformsFloatNxM(type, location, count, reinterpret_cast<const GLfloat*>(data));
GLSetUniformFloatNxM(type, location, count, reinterpret_cast<const GLfloat*>(data));
break;

case UniformType::Double2x2:
Expand All @@ -259,31 +259,19 @@ void GLSetUniformsByType(UniformType type, GLint location, GLsizei count, const
case UniformType::Double4x3:
case UniformType::Double4x4:
#ifdef LLGL_OPENGL
GLSetUniformsDouble(type, location, count, reinterpret_cast<const GLdouble*>(data));
GLSetUniformDouble(type, location, count, reinterpret_cast<const GLdouble*>(data));
#endif
break;

/* ----- Resources ----- */
case UniformType::Sampler:
case UniformType::Image:
case UniformType::AtomicCounter:
GLSetUniformsInt(type, location, count, reinterpret_cast<const GLint*>(data));
GLSetUniformInt(type, location, count, reinterpret_cast<const GLint*>(data));
break;
}
}

void GLSetUniformsByLocation(GLuint program, GLint location, GLsizei count, const void* data)
{
/* Determine type of uniform */
GLenum type = 0;
GLint size = 0;
glGetActiveUniform(program, static_cast<GLuint>(location), 0, nullptr, &size, &type, nullptr);

/* Submit data to respective uniform type */
UniformType uniformType = GLTypes::UnmapUniformType(type);
GLSetUniformsByType(uniformType, location, count, data);
}


} // /namespace LLGL

Expand Down
5 changes: 1 addition & 4 deletions sources/Renderer/OpenGL/Shader/GLShaderUniform.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ namespace LLGL


// Sets the data of the specified uniform in the active shader program.
void GLSetUniformsByType(UniformType type, GLint location, GLsizei count, const void* data);

// Sets the data of the specified uniform in the active shader program, where the type is determined by the specified shader program.
void GLSetUniformsByLocation(GLuint program, GLint location, GLsizei count, const void* data);
void GLSetUniform(UniformType type, GLint location, GLsizei count, const void* data);


} // /namespace LLGL
Expand Down

0 comments on commit c8fd96b

Please sign in to comment.