Skip to content

Commit

Permalink
Sync SetShaderParameters()
Browse files Browse the repository at this point in the history
  • Loading branch information
KOPRajs authored and garbear committed Jan 18, 2025
1 parent fb626f4 commit 747b9b4
Showing 1 changed file with 16 additions and 26 deletions.
42 changes: 16 additions & 26 deletions xbmc/cores/RetroPlayer/shaders/gl/ShaderGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ bool CShaderGL::Create(const std::string& shaderSource,
glDeleteShader(vShader);
glDeleteShader(fShader);

SetShaderParameters();
GetUniformLocs();

#ifndef HAS_GLES
glGenVertexArrays(1, &VAO);
Expand All @@ -91,25 +91,16 @@ bool CShaderGL::Create(const std::string& shaderSource,

void CShaderGL::Render(IShaderTexture* source, IShaderTexture* target)
{
glUseProgram(m_shaderProgram);

#ifndef HAS_GLES
CShaderTextureGL* sourceGL = static_cast<CShaderTextureGL*>(source);
#else
CShaderTextureGLES* sourceGL = static_cast<CShaderTextureGLES*>(source);
#endif
sourceGL->GetPointer()->BindToUnit(0);

for (unsigned int i = 0; i < m_luts.size(); ++i)
{
#ifndef HAS_GLES
auto* lutTexture = dynamic_cast<CShaderTextureGL*>(m_luts[i].get()->GetTexture());
#else
auto* lutTexture = dynamic_cast<CShaderTextureGLES*>(m_luts[i].get()->GetTexture());
#endif
if (lutTexture)
lutTexture->GetPointer()->BindToUnit(1 + i);
}

glUseProgram(m_shaderProgram);
SetShaderParameters();

glUniformMatrix4fv(m_MVPMatrixLoc, 1, GL_FALSE, reinterpret_cast<const GLfloat*>(&m_MVP));

Expand Down Expand Up @@ -246,7 +237,6 @@ bool CShaderGL::CreateVertexBuffer(unsigned vertCount, unsigned vertSize)
//! @todo Change name of this method in IShader.h to CreateInputs
bool CShaderGL::CreateInputBuffer()
{
GetUniformLocs();
UpdateInputBuffer(0);
return true;
}
Expand Down Expand Up @@ -296,27 +286,27 @@ void CShaderGL::GetUniformLocs()

void CShaderGL::SetShaderParameters()
{
glUseProgram(m_shaderProgram);
unsigned int textureUnit = 1; // GL_TEXTURE0 is used by source texture

for (const auto& parameter : m_shaderParameters)
for (const auto& param : m_shaderParameters)
{
GLint paramLoc = glGetUniformLocation(m_shaderProgram, parameter.first.c_str());
glUniform1f(paramLoc, parameter.second);
GLint paramLoc = glGetUniformLocation(m_shaderProgram, param.first.c_str());
glUniform1f(paramLoc, param.second);
}

for (unsigned int i = 0; i < m_luts.size(); ++i)
for (const auto& lut : m_luts)
{
#ifndef HAS_GLES
auto* lutTexture = dynamic_cast<CShaderTextureGL*>(m_luts[i].get()->GetTexture());
auto* texture = dynamic_cast<CShaderTextureGL*>(lut->GetTexture());
#else
auto* lutTexture = dynamic_cast<CShaderTextureGLES*>(m_luts[i].get()->GetTexture());
auto* texture = dynamic_cast<CShaderTextureGLES*>(lut->GetTexture());
#endif
if (lutTexture)
if (texture != nullptr)
{
GLint paramLoc = glGetUniformLocation(m_shaderProgram, m_luts[i]->GetID().c_str());
glUniform1i(paramLoc, 1 + i);
GLint paramLoc = glGetUniformLocation(m_shaderProgram, lut->GetID().c_str());
glUniform1i(paramLoc, textureUnit);
texture->GetPointer()->BindToUnit(textureUnit);
textureUnit++;
}
}

glUseProgram(0);
}

0 comments on commit 747b9b4

Please sign in to comment.