Skip to content

Commit

Permalink
RetroPlayer: OpenGL back-end for shaders
Browse files Browse the repository at this point in the history
  • Loading branch information
gusandrianos authored and garbear committed Mar 20, 2023
1 parent a16b092 commit 7acfe38
Show file tree
Hide file tree
Showing 18 changed files with 1,444 additions and 3 deletions.
1 change: 1 addition & 0 deletions cmake/treedata/linux/subdirs.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
xbmc/cores/RetroPlayer/shaders/gl cores/RetroPlayer/shaders/gl
xbmc/input/touch input/touch
xbmc/input/touch/generic input/touch/generic
xbmc/platform/common/speech platform/common/speech
Expand Down
1 change: 1 addition & 0 deletions cmake/treedata/osx/subdirs.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
xbmc/cores/RetroPlayer/process/osx cores/RetroPlayer/process/osx
xbmc/cores/RetroPlayer/shaders/gl cores/RetroPlayer/shaders/gl
xbmc/cores/VideoPlayer/Process/osx cores/VideoPlayer/Process/osx
xbmc/platform/darwin platform/darwin
xbmc/platform/darwin/network platform/darwin/network
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ void CRPBaseRenderer::Updateshaders()
{
if (!m_renderBuffer)
{
CLog::Log(LOGWARNING, "%s - Render buffer not set, can't update video shader source size!",
CLog::Log(LOGWARNING, "{} - Render buffer not set, can't update video shader source size!",
__FUNCTION__);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "cores/RetroPlayer/buffers/RenderBufferOpenGL.h"
#include "cores/RetroPlayer/buffers/RenderBufferPoolOpenGL.h"
#include "cores/RetroPlayer/rendering/RenderContext.h"
#include "cores/RetroPlayer/shaders/gl/ShaderPresetGL.h"
#include "utils/GLUtils.h"
#include "utils/log.h"

Expand Down Expand Up @@ -46,6 +47,9 @@ CRPRendererOpenGL::CRPRendererOpenGL(const CRenderSettings& renderSettings,
std::shared_ptr<IRenderBufferPool> bufferPool)
: CRPBaseRenderer(renderSettings, context, std::move(bufferPool))
{
// Initialize CRPBaseRenderer
m_shaderPreset.reset(new SHADER::CShaderPresetGL(m_context));

// Initialize CRPRendererOpenGL
m_clearColour = m_context.UseLimitedColor() ? (16.0f / 0xff) : 0.0f;

Expand Down Expand Up @@ -278,16 +282,57 @@ void CRPRendererOpenGL::Render(uint8_t alpha)

const uint32_t color = (alpha << 24) | 0xFFFFFF;

glBindTexture(m_textureTarget, renderBuffer->TextureID());
RenderBufferTextures* rbTextures;
const auto it = m_RBTexturesMap.find(renderBuffer);
if (it != m_RBTexturesMap.end())
{
rbTextures = it->second.get();
}
else
{
// We can't copy or move CGLTexture, so construct source/target in-place
rbTextures = new RenderBufferTextures{{// source texture
static_cast<unsigned int>(renderBuffer->GetWidth()),
static_cast<unsigned int>(renderBuffer->GetHeight()),
GL_RGB, renderBuffer->TextureID()},
{// target texture
static_cast<unsigned int>(m_context.GetScreenWidth()),
static_cast<unsigned int>(m_context.GetScreenHeight())}};
m_RBTexturesMap.emplace(renderBuffer, rbTextures);
}

const auto sourceTexture = &rbTextures->source;
const auto targetTexture = &rbTextures->target;

glBindTexture(m_textureTarget, sourceTexture->getMTexture());

GLint filter = GL_NEAREST;
if (GetRenderSettings().VideoSettings().GetScalingMethod() == SCALINGMETHOD::LINEAR)
filter = GL_LINEAR;

glTexParameteri(m_textureTarget, GL_TEXTURE_MAG_FILTER, filter);
glTexParameteri(m_textureTarget, GL_TEXTURE_MIN_FILTER, filter);
glTexParameteri(m_textureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(m_textureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

Updateshaders();

if (m_bUseShaderPreset)
{
const CPoint destPoints[4] = {m_rotatedDestCoords[0], m_rotatedDestCoords[1],
m_rotatedDestCoords[2], m_rotatedDestCoords[3]};

targetTexture->CreateTextureObject();

SHADER::CShaderTextureGL source(*sourceTexture);
SHADER::CShaderTextureGL target(*targetTexture);
if (!m_shaderPreset->RenderUpdate(destPoints, &source, &target))
{
m_shadersNeedUpdate = false;
m_bUseShaderPreset = false;
}
}
else
{
m_context.EnableGUIShader(GL_SHADER_METHOD::TEXTURE);

Expand Down
12 changes: 12 additions & 0 deletions xbmc/cores/RetroPlayer/rendering/VideoRenderers/RPRendererOpenGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

#include "RPBaseRenderer.h"
#include "cores/RetroPlayer/process/RPProcessInfo.h"
#include "guilib/TextureGL.h"

#include <map>
#include <memory>

#include "system_gl.h"

Expand All @@ -18,6 +22,7 @@ namespace KODI
namespace RETRO
{
class CRenderContext;
class CRenderBufferOpenGL;

class CRendererFactoryOpenGL : public IRendererFactory
{
Expand Down Expand Up @@ -58,6 +63,11 @@ class CRPRendererOpenGL : public CRPBaseRenderer
float y;
float z;
};
struct RenderBufferTextures
{
CGLTexture source;
CGLTexture target;
};

// implementation of CRPBaseRenderer
void RenderInternal(bool clear, uint8_t alpha) override;
Expand All @@ -78,6 +88,8 @@ class CRPRendererOpenGL : public CRPBaseRenderer

virtual void Render(uint8_t alpha);

std::map<CRenderBufferOpenGL*, std::unique_ptr<RenderBufferTextures>> m_RBTexturesMap;

GLuint m_mainVAO;
GLuint m_mainVertexVBO;
GLuint m_mainIndexVBO;
Expand Down
16 changes: 16 additions & 0 deletions xbmc/cores/RetroPlayer/shaders/gl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
set(SOURCES ShaderGL.cpp
ShaderLutGL.cpp
ShaderPresetGL.cpp
ShaderTextureGL.cpp
ShaderUtilsGL.cpp
)

set(HEADERS ShaderGL.h
ShaderLutGL.h
ShaderPresetGL.h
ShaderTextureGL.h
ShaderTypesGL.h
ShaderUtilsGL.h
)

core_add_library(rp-shaders-gl)
Loading

0 comments on commit 7acfe38

Please sign in to comment.