Skip to content

Commit

Permalink
RetroPlayer: Add PreRender/PostRender calls to RPBaseRenderer.
Browse files Browse the repository at this point in the history
This removes a lot of repetition for renderers and makes
RPWinRenderer more modular by limiting g_* (global) calls to only 3.
  • Loading branch information
VelocityRa committed Aug 30, 2017
1 parent 7b8923c commit b44ed3f
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 32 deletions.
4 changes: 3 additions & 1 deletion xbmc/cores/RetroPlayer/rendering/RPRenderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ void CRPRenderManager::Render(bool clear, DWORD alpha)

CSingleExit exitLock(g_graphicsContext);

m_renderer->RenderUpdate(clear, alpha);
m_renderer->PreRender(clear, alpha);
m_renderer->RenderUpdate();
m_renderer->PostRender();
}

void CRPRenderManager::Flush()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
*/

#include "RPBaseRenderer.h"
#include "ServiceBroker.h"
#include "cores/RetroPlayer/rendering/VideoShaders/IVideoShaderPreset.h"
#include "guilib/GraphicContext.h"
#include "guilib/GUIWindowManager.h"
#include "settings/GameSettings.h"
#include "settings/MediaSettings.h"
#include "settings/Settings.h"
#include "utils/MathUtils.h"
#include "ServiceBroker.h"
#include "windowing/WindowingFactory.h"

#include <cmath>
#include <cstdlib>
Expand Down Expand Up @@ -542,3 +543,39 @@ void CRPBaseRenderer::UpdateVideoShaders()
}
}
}

void CRPBaseRenderer::PreRender(bool clear, unsigned int alpha)
{
if (m_bUseShaderPreset)
{
// select destination rectangle
if (m_renderOrientation)
{
for (size_t i = 0; i < 4; i++)
m_destPoints[i] = m_rotatedDestCoords[i];
}
else
{
CRect destRect = g_graphicsContext.StereoCorrection(m_destRect);
m_destPoints[0] = { destRect.x1, destRect.y1 };
m_destPoints[1] = { destRect.x2, destRect.y1 };
m_destPoints[2] = { destRect.x2, destRect.y2 };
m_destPoints[3] = { destRect.x1, destRect.y2 };
}
}
// Clear screen
if (clear)
g_graphicsContext.Clear(g_Windowing.UseLimitedColor() ? 0x101010 : 0);

// Set alpha blend state
g_Windowing.SetAlphaBlendEnable(alpha < 255);

ManageRenderArea();

UpdateVideoShaders();
}

void CRPBaseRenderer::PostRender()
{
g_Windowing.ApplyStateBlock();
}
13 changes: 12 additions & 1 deletion xbmc/cores/RetroPlayer/rendering/VideoRenderers/RPBaseRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace RETRO
virtual bool Configure(AVPixelFormat format, unsigned int width, unsigned int height, unsigned int orientation) = 0;
virtual void AddFrame(const uint8_t* data, unsigned int size) = 0;
virtual void Flush() = 0;
virtual void RenderUpdate(bool clear, unsigned int alpha) = 0;
virtual void RenderUpdate() = 0;
virtual void Deinitialize() = 0;
virtual void SetSpeed(double speed) = 0;

Expand Down Expand Up @@ -83,6 +83,16 @@ namespace RETRO

bool IsNonLinearStretch() const { return m_bNonLinearStretch; }

/*!
* \brief Performs whatever nessesary before rendering the frame. Must be called before RenderUpdate()
*/
void PreRender(bool clear, unsigned int alpha);

/*!
* \brief Performs whatever nessesary after a frame has been rendered. Must be called after RenderUpdate()
*/
void PostRender();

protected:
/*!
* \brief Call this from the base class to initialize render settings
Expand All @@ -102,6 +112,7 @@ namespace RETRO
unsigned int m_sourceWidth = 0;
unsigned int m_sourceHeight = 0;
unsigned int m_renderOrientation = 0; // Degrees counter-clockwise
CPoint m_destPoints[4];

/*!
* \brief Orientation of the previous frame
Expand Down
30 changes: 2 additions & 28 deletions xbmc/cores/RetroPlayer/rendering/VideoRenderers/RPWinRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,11 @@ void CRPWinRenderer::Flush()
m_bQueued = false;
}

void CRPWinRenderer::RenderUpdate(bool clear, unsigned int alpha)
void CRPWinRenderer::RenderUpdate()
{
if (clear)
g_graphicsContext.Clear(g_Windowing.UseLimitedColor() ? 0x101010 : 0);

if (!m_bConfigured)
return;

g_Windowing.SetAlphaBlendEnable(alpha < 255);

ManageRenderArea();

UpdateVideoShaders();

if (m_bQueued)
{
if (UploadTexture())
Expand Down Expand Up @@ -223,25 +214,9 @@ void CRPWinRenderer::Render(CD3DTexture *target)
// Are we using video shaders?
if (m_bUseShaderPreset)
{
// select destination rectangle
CPoint destPoints[4];
if (m_renderOrientation)
{
for (size_t i = 0; i < 4; i++)
destPoints[i] = m_rotatedDestCoords[i];
}
else
{
CRect destRect = g_graphicsContext.StereoCorrection(m_destRect);
destPoints[0] = { destRect.x1, destRect.y1 };
destPoints[1] = { destRect.x2, destRect.y1 };
destPoints[2] = { destRect.x2, destRect.y2 };
destPoints[3] = { destRect.x1, destRect.y2 };
}

// Render shaders and ouput to display
m_targetTexture.SetTexture(target);
if (!m_shaderPreset->RenderUpdate(destPoints, m_intermediateTarget.get(), &m_targetTexture))
if (!m_shaderPreset->RenderUpdate(m_destPoints, m_intermediateTarget.get(), &m_targetTexture))
{
m_shadersNeedUpdate = false;
m_bUseShaderPreset = false;
Expand All @@ -257,5 +232,4 @@ void CRPWinRenderer::Render(CD3DTexture *target)
g_Windowing.UseLimitedColor() ? 1 : 0, 0.5f, 0.5f);
}
}
g_Windowing.ApplyStateBlock();
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace RETRO
bool Configure(AVPixelFormat format, unsigned int width, unsigned int height, unsigned int orientation) override;
void AddFrame(const uint8_t* data, unsigned int size) override;
void Flush() override;
void RenderUpdate(bool clear, unsigned int alpha) override;
void RenderUpdate() override;
void Deinitialize() override;
bool Supports(ERENDERFEATURE feature) const override;
bool Supports(ESCALINGMETHOD method) const override;
Expand Down

0 comments on commit b44ed3f

Please sign in to comment.