Skip to content

Commit

Permalink
Fix lookup textures (LUTs) support
Browse files Browse the repository at this point in the history
  • Loading branch information
KOPRajs committed Apr 20, 2024
1 parent f9e061b commit da12f87
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 29 deletions.
26 changes: 12 additions & 14 deletions xbmc/cores/RetroPlayer/shaders/gl/ShaderGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,19 @@ bool CShaderGL::Create(const std::string& shaderSource,
void CShaderGL::Render(IShaderTexture* source, IShaderTexture* target)
{
CShaderTextureGL* sourceGL = static_cast<CShaderTextureGL*>(source);
GLuint texture = sourceGL->GetPointer()->getMTexture();
sourceGL->GetPointer()->BindToUnit(0);
glUseProgram(m_shaderProgram);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);

// for (int i = 0; i < m_luts.size(); ++i)
// {
// auto* lutTexture = dynamic_cast<CShaderTextureGL*>(m_luts[i].get()->GetTexture());
// if (lutTexture)
// {
// glActiveTexture(GL_TEXTURE1 + i);
// GLuint lutTextureID = lutTexture->GetPointer()->getMTexture();
// glBindTexture(GL_TEXTURE_2D, lutTextureID);
// }
// }

for (unsigned int i = 0; i < m_luts.size(); ++i)
{
auto* lutTexture = dynamic_cast<CShaderTextureGL*>(m_luts[i].get()->GetTexture());
if (lutTexture)
{
GLint paramLoc = glGetUniformLocation(m_shaderProgram, m_luts[i]->GetID().c_str());
glUniform1i(paramLoc, 1 + i);
lutTexture->GetPointer()->BindToUnit(1 + i);
}
}

#ifndef HAS_GLES
glBindVertexArray(VAO);
Expand Down
19 changes: 9 additions & 10 deletions xbmc/cores/RetroPlayer/shaders/gl/ShaderLutGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ bool CShaderLutGL::Create(RETRO::CRenderContext& context, const ShaderLut& lut)
std::unique_ptr<IShaderTexture> CShaderLutGL::CreateLUTTexture(RETRO::CRenderContext& context,
const KODI::SHADER::ShaderLut& lut)
{
auto wrapType = CShaderUtilsGL::TranslateWrapType(lut.wrap);
auto filterType = lut.filter ? GL_LINEAR : GL_NEAREST;

std::unique_ptr<CTexture> texture = CGLTexture::LoadFromFile(lut.path);
std::unique_ptr<CTexture> texture = CTexture::LoadFromFile(lut.path);
CGLTexture* textureGL = static_cast<CGLTexture*>(texture.get());

if (textureGL == nullptr)
Expand All @@ -56,10 +53,15 @@ std::unique_ptr<IShaderTexture> CShaderLutGL::CreateLUTTexture(RETRO::CRenderCon
return std::unique_ptr<IShaderTexture>();
}

textureGL->CreateTextureObject();
if (lut.mipmap)
textureGL->SetMipmapping();

textureGL->SetScalingMethod(lut.filter == FILTER_TYPE_LINEAR ? TEXTURE_SCALING::LINEAR : TEXTURE_SCALING::NEAREST);
textureGL->LoadToGPU();

auto wrapType = CShaderUtilsGL::TranslateWrapType(lut.wrap);

glBindTexture(GL_TEXTURE_2D, textureGL->getMTexture());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filterType);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filterType);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapType);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapType);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, wrapType);
Expand All @@ -72,9 +74,6 @@ std::unique_ptr<IShaderTexture> CShaderLutGL::CreateLUTTexture(RETRO::CRenderCon
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, blackBorder);
#endif

if (lut.mipmap)
textureGL->SetMipmapping();

return std::unique_ptr<IShaderTexture>(
new CShaderTextureGL(static_cast<CGLTexture*>(texture.release())));
}
10 changes: 5 additions & 5 deletions xbmc/cores/RetroPlayer/shaders/gl/ShaderPresetGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,21 +293,21 @@ bool CShaderPresetGL::CreateShaderTextures()
textureFormat = GL_RGBA;
}

auto texture = new CGLTexture(static_cast<unsigned int>(scaledSize.x),
auto textureGL = new CGLTexture(static_cast<unsigned int>(scaledSize.x),
static_cast<unsigned int>(scaledSize.y),
static_cast<XB_FMT>(textureFormat)); //! @todo Format translation?

texture->CreateTextureObject();
textureGL->CreateTextureObject();

if (texture->getMTexture() <= 0)
if (textureGL->getMTexture() <= 0)
{
CLog::Log(LOGERROR, "Couldn't create a texture for video shader {}.", pass.sourcePath);
return false;
}

auto wrapType = CShaderUtilsGL::TranslateWrapType(WRAP_TYPE_BORDER);

glBindTexture(GL_TEXTURE_2D, texture->getMTexture());
glBindTexture(GL_TEXTURE_2D, textureGL->getMTexture());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapType);
Expand All @@ -322,7 +322,7 @@ bool CShaderPresetGL::CreateShaderTextures()
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, blackBorder);
#endif

m_pShaderTextures.emplace_back(new CShaderTextureGL(*texture));
m_pShaderTextures.emplace_back(new CShaderTextureGL(*textureGL));
m_pShaders[shaderIdx]->SetSizes(prevSize, scaledSize);

prevSize = scaledSize;
Expand Down

0 comments on commit da12f87

Please sign in to comment.