Skip to content

Commit

Permalink
retroplayer/gl: Don't allocate render buffers every frame
Browse files Browse the repository at this point in the history
Fixes stuttering (occasional black frames every few seconds).
  • Loading branch information
VelocityRa authored and gusandrianos committed Oct 18, 2019
1 parent 460af74 commit db8f7fc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,31 @@ void CRPRendererOpenGL::Render(uint8_t alpha)

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

const std::unique_ptr<CGLTexture> sourceTexture(new CGLTexture(
static_cast<unsigned int>(renderBuffer->GetWidth()),
static_cast<unsigned int>(renderBuffer->GetHeight()),
GL_RGB,
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());

Expand All @@ -320,14 +340,10 @@ void CRPRendererOpenGL::Render(uint8_t alpha)
m_rotatedDestCoords[3]
};

const std::unique_ptr<CGLTexture> renderTargetTexture(new CGLTexture(
static_cast<unsigned int>(m_context.GetScreenWidth()),
static_cast<unsigned int>(m_context.GetScreenHeight())));

renderTargetTexture->CreateTextureObject();
targetTexture->CreateTextureObject();

SHADER::CShaderTextureGL source(*sourceTexture);
SHADER::CShaderTextureGL target(*renderTargetTexture);
SHADER::CShaderTextureGL target(*targetTexture);
if (!m_shaderPreset->RenderUpdate(destPoints, &source, &target))
{
m_shadersNeedUpdate = false;
Expand Down
11 changes: 11 additions & 0 deletions xbmc/cores/RetroPlayer/rendering/VideoRenderers/RPRendererOpenGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@

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

#include "system_gl.h"

#include <map>

namespace KODI
{
namespace RETRO
{
class CRenderContext;
class CRenderBufferOpenGL;


class CRendererFactoryOpenGL : public IRendererFactory
{
Expand Down Expand Up @@ -54,6 +59,10 @@ namespace RETRO
float y;
float z;
};
struct RenderBufferTextures {
CGLTexture source;
CGLTexture target;
};

// implementation of CRPBaseRenderer
bool ConfigureInternal() override;
Expand All @@ -76,6 +85,8 @@ namespace RETRO

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

0 comments on commit db8f7fc

Please sign in to comment.