Skip to content

Commit b2149ca

Browse files
KOPRajsgarbear
authored andcommitted
[PR 26961] RetroPlayer: Fix video shaders scaling
1 parent f393137 commit b2149ca

20 files changed

+171
-136
lines changed

xbmc/cores/RetroPlayer/rendering/VideoRenderers/RPBaseRenderer.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ void CRPBaseRenderer::ManageRenderArea(const IRenderBuffer& renderBuffer)
183183
float screenPixelRatio;
184184
GetScreenDimensions(screenWidth, screenHeight, screenPixelRatio);
185185

186-
// Entire target rendering area for the video (including black bars)
186+
// Get target rendering area for the game view window (including black bars)
187187
const CRect viewRect = m_context.GetViewWindow();
188188

189189
// Calculate pixel ratio and zoom amount
@@ -192,10 +192,41 @@ void CRPBaseRenderer::ManageRenderArea(const IRenderBuffer& renderBuffer)
192192
CRenderUtils::CalculateStretchMode(stretchMode, rotationDegCCW, sourceWidth, sourceHeight,
193193
screenWidth, screenHeight, pixelRatio, zoomAmount);
194194

195-
// Calculate destination dimensions
195+
// Calculate destination rectangle for the game view window
196196
CRect destRect;
197197
CRenderUtils::CalcNormalRenderRect(viewRect, sourceFrameRatio * pixelRatio, zoomAmount, destRect);
198198

199+
// Calculate destination rectangle size for the fullscreen game window
200+
CRect fullDestRect;
201+
CRect viewPort;
202+
m_context.GetViewPort(viewPort);
203+
204+
if (viewPort == viewRect)
205+
{
206+
fullDestRect = destRect;
207+
}
208+
else
209+
{
210+
CRenderUtils::CalcNormalRenderRect(viewPort, sourceFrameRatio * pixelRatio, zoomAmount, fullDestRect);
211+
}
212+
213+
switch (rotationDegCCW)
214+
{
215+
case 90:
216+
case 270:
217+
{
218+
m_fullDestWidth = fullDestRect.Height();
219+
m_fullDestHeight = fullDestRect.Width();
220+
break;
221+
}
222+
default:
223+
{
224+
m_fullDestWidth = fullDestRect.Width();
225+
m_fullDestHeight = fullDestRect.Height();
226+
break;
227+
}
228+
}
229+
199230
m_sourceRect.x1 = 0.0f;
200231
m_sourceRect.y1 = 0.0f;
201232
m_sourceRect.x2 = static_cast<float>(sourceWidth);

xbmc/cores/RetroPlayer/rendering/VideoRenderers/RPBaseRenderer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ class CRPBaseRenderer
9595

9696
// Geometry properties
9797
CRect m_sourceRect;
98+
float m_fullDestWidth{0.0f};
99+
float m_fullDestHeight{0.0f};
98100
ViewportCoordinates m_rotatedDestCoords{};
99101

100102
// Video shaders

xbmc/cores/RetroPlayer/rendering/VideoRenderers/RPRendererDMAOpenGL.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ CRPRendererDMAOpenGL::CRPRendererDMAOpenGL(const CRenderSettings& renderSettings
5555

5656
void CRPRendererDMAOpenGL::Render(uint8_t alpha)
5757
{
58+
const ViewportCoordinates dest{m_rotatedDestCoords};
59+
5860
auto renderBuffer = static_cast<CRenderBufferDMA*>(m_renderBuffer);
5961
assert(renderBuffer != nullptr);
6062

@@ -97,11 +99,9 @@ void CRPRendererDMAOpenGL::Render(uint8_t alpha)
9799
glTexParameteri(m_textureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
98100
glTexParameteri(m_textureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
99101

100-
const ViewportCoordinates destPoints{m_rotatedDestCoords};
101-
102102
SHADER::CShaderTextureGL source(sourceTexture, false);
103103
SHADER::CShaderTextureGL target(targetTexture, false);
104-
if (!m_shaderPreset->RenderUpdate(destPoints, source, target))
104+
if (!m_shaderPreset->RenderUpdate(dest, {m_fullDestWidth, m_fullDestHeight}, source, target))
105105
{
106106
m_bShadersNeedUpdate = false;
107107
m_bUseShaderPreset = false;

xbmc/cores/RetroPlayer/rendering/VideoRenderers/RPRendererDMAOpenGLES.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ CRPRendererDMAOpenGLES::CRPRendererDMAOpenGLES(const CRenderSettings& renderSett
5555

5656
void CRPRendererDMAOpenGLES::Render(uint8_t alpha)
5757
{
58+
const ViewportCoordinates dest{m_rotatedDestCoords};
59+
5860
auto renderBuffer = static_cast<CRenderBufferDMA*>(m_renderBuffer);
5961
assert(renderBuffer != nullptr);
6062

@@ -97,11 +99,9 @@ void CRPRendererDMAOpenGLES::Render(uint8_t alpha)
9799
glTexParameteri(m_textureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
98100
glTexParameteri(m_textureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
99101

100-
const ViewportCoordinates destPoints{m_rotatedDestCoords};
101-
102102
SHADER::CShaderTextureGLES source(sourceTexture, false);
103103
SHADER::CShaderTextureGLES target(targetTexture, false);
104-
if (!m_shaderPreset->RenderUpdate(destPoints, source, target))
104+
if (!m_shaderPreset->RenderUpdate(dest, {m_fullDestWidth, m_fullDestHeight}, source, target))
105105
{
106106
m_bShadersNeedUpdate = false;
107107
m_bUseShaderPreset = false;

xbmc/cores/RetroPlayer/rendering/VideoRenderers/RPRendererOpenGL.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,9 @@ void CRPRendererOpenGL::DrawBlackBars()
274274

275275
void CRPRendererOpenGL::Render(uint8_t alpha)
276276
{
277-
CRenderBufferOpenGL* renderBuffer = static_cast<CRenderBufferOpenGL*>(m_renderBuffer);
277+
const ViewportCoordinates dest{m_rotatedDestCoords};
278278

279+
CRenderBufferOpenGL* renderBuffer = static_cast<CRenderBufferOpenGL*>(m_renderBuffer);
279280
if (renderBuffer == nullptr)
280281
return;
281282

@@ -318,11 +319,9 @@ void CRPRendererOpenGL::Render(uint8_t alpha)
318319
glTexParameteri(m_textureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
319320
glTexParameteri(m_textureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
320321

321-
const ViewportCoordinates destPoints{m_rotatedDestCoords};
322-
323322
SHADER::CShaderTextureGL source(sourceTexture, false);
324323
SHADER::CShaderTextureGL target(targetTexture, false);
325-
if (!m_shaderPreset->RenderUpdate(destPoints, source, target))
324+
if (!m_shaderPreset->RenderUpdate(dest, {m_fullDestWidth, m_fullDestHeight}, source, target))
326325
{
327326
m_bShadersNeedUpdate = false;
328327
m_bUseShaderPreset = false;

xbmc/cores/RetroPlayer/rendering/VideoRenderers/RPRendererOpenGLES.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,9 @@ void CRPRendererOpenGLES::DrawBlackBars()
246246

247247
void CRPRendererOpenGLES::Render(uint8_t alpha)
248248
{
249-
CRenderBufferOpenGLES* renderBuffer = static_cast<CRenderBufferOpenGLES*>(m_renderBuffer);
249+
const ViewportCoordinates dest{m_rotatedDestCoords};
250250

251+
CRenderBufferOpenGLES* renderBuffer = static_cast<CRenderBufferOpenGLES*>(m_renderBuffer);
251252
if (renderBuffer == nullptr)
252253
return;
253254

@@ -290,11 +291,9 @@ void CRPRendererOpenGLES::Render(uint8_t alpha)
290291
glTexParameteri(m_textureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
291292
glTexParameteri(m_textureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
292293

293-
const ViewportCoordinates destPoints{m_rotatedDestCoords};
294-
295294
SHADER::CShaderTextureGLES source(sourceTexture, false);
296295
SHADER::CShaderTextureGLES target(targetTexture, false);
297-
if (!m_shaderPreset->RenderUpdate(destPoints, source, target))
296+
if (!m_shaderPreset->RenderUpdate(dest, {m_fullDestWidth, m_fullDestHeight}, source, target))
298297
{
299298
m_bShadersNeedUpdate = false;
300299
m_bUseShaderPreset = false;

xbmc/cores/RetroPlayer/rendering/VideoRenderers/RPWinRenderer.cpp

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ bool CRPWinRenderer::SupportsScalingMethod(SCALINGMETHOD method)
295295

296296
void CRPWinRenderer::Render(CD3DTexture& target)
297297
{
298-
const ViewportCoordinates destPoints{m_rotatedDestCoords};
298+
const ViewportCoordinates dest{m_rotatedDestCoords};
299299

300300
CWinRenderBuffer* renderBuffer = static_cast<CWinRenderBuffer*>(m_renderBuffer);
301301
if (renderBuffer == nullptr)
@@ -310,29 +310,11 @@ void CRPWinRenderer::Render(CD3DTexture& target)
310310
// Use video shader preset
311311
if (m_bUseShaderPreset)
312312
{
313-
//! @todo Orientation?
314-
/*
315-
ViewportCoordinates destPoints = {};
316-
// select destination rectangle
317-
if (m_renderOrientation)
318-
{
319-
for (size_t i = 0; i < 4; ++i)
320-
destPoints[i] = m_rotatedDestCoords[i];
321-
}
322-
else
323-
{
324-
CRect destRect = m_context.StereoCorrection(m_renderSettings.Geometry().Dimensions());
325-
destPoints[0] = { destRect.x1, destRect.y1 };
326-
destPoints[1] = { destRect.x2, destRect.y1 };
327-
destPoints[2] = { destRect.x2, destRect.y2 };
328-
destPoints[3] = { destRect.x1, destRect.y2 };
329-
}
330-
*/
331-
332313
SHADER::CShaderTextureDXRef targetTexture{target};
333314

334315
// Render shaders and ouput to display
335-
if (!m_shaderPreset->RenderUpdate(destPoints, *renderBufferTarget, targetTexture))
316+
if (!m_shaderPreset->RenderUpdate(dest, {m_fullDestWidth, m_fullDestHeight},
317+
*renderBufferTarget, targetTexture))
336318
{
337319
m_bShadersNeedUpdate = false;
338320
m_bUseShaderPreset = false;
@@ -355,7 +337,7 @@ void CRPWinRenderer::Render(CD3DTexture& target)
355337
// Use the picked output shader to render to the target
356338
if (outputShader != nullptr)
357339
{
358-
outputShader->Render(intermediateTarget, m_sourceRect, destPoints, viewPort, target,
340+
outputShader->Render(intermediateTarget, m_sourceRect, dest, viewPort, target,
359341
m_context.UseLimitedColor() ? 1 : 0);
360342
}
361343
}

xbmc/cores/RetroPlayer/shaders/IShader.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class IShader
3333
* \param shaderPath Full path to the shader file
3434
* \param shaderParameters Struct with all parameters pertaining to the shader
3535
* \param luts Look-up textures pertaining to the shader
36-
* \param viewPortSize Size of the window/viewport
3736
* \param passIdx Index of the video shader pass
3837
* \param frameCountMod Modulo applied to the frame count before sendign it to the shader
3938
*
@@ -43,7 +42,6 @@ class IShader
4342
std::string shaderPath,
4443
ShaderParameterMap shaderParameters,
4544
std::vector<std::shared_ptr<IShaderLut>> luts,
46-
float2 viewPortSize,
4745
unsigned int passIdx,
4846
unsigned int frameCountMod = 0) = 0;
4947

@@ -72,14 +70,16 @@ class IShader
7270
* Updates any internal state needed to ensure that correct data is passed to
7371
* the shader when rendering.
7472
*
75-
* \param dest Coordinates of the 4 corners of the output viewport/window
73+
* \param dest Coordinates of the 4 corners of the destination rectangle
74+
* \param fullDestSize Destination rectangle size for the fullscreen game window
7675
* \param sourceTexture Source texture of the first shader pass
7776
* \param pShaderTextures Intermediate textures used for all shader passes
7877
* \param pShaders All shader passes
7978
* \param frameCount Number of frames that have passed
8079
*/
8180
virtual void PrepareParameters(
8281
const RETRO::ViewportCoordinates& dest,
82+
const float2 fullDestSize,
8383
IShaderTexture& sourceTexture,
8484
const std::vector<std::unique_ptr<IShaderTexture>>& pShaderTextures,
8585
const std::vector<std::unique_ptr<IShader>>& pShaders,

xbmc/cores/RetroPlayer/shaders/IShaderPreset.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ class IShaderPreset
3838
/*!
3939
* \brief Updates state if needed and renderes the preset to the target texture
4040
*
41-
* \param dest Coordinates of the 4 corners of the output viewport/window
41+
* \param dest Coordinates of the 4 corners of the destination rectangle
42+
* \param fullDestSize Destination rectangle size for the fullscreen game window
4243
* \param source The source of the video frame, in its original resolution (unscaled)
4344
* \param target The target texture that the final result will be rendered to
4445
*
4546
* \return Returns false if updating or rendering failed, true if both succeeded
4647
*/
4748
virtual bool RenderUpdate(const RETRO::ViewportCoordinates& dest,
49+
const float2 fullDestSize,
4850
IShaderTexture& source,
4951
IShaderTexture& target) = 0;
5052

0 commit comments

Comments
 (0)