libretro: Use framebuffer view dimensions not texture dimensions

This commit is contained in:
Connor McLaughlin 2020-07-01 00:43:17 +10:00
parent 70f4ce7cde
commit 8cd9e0887e
6 changed files with 24 additions and 14 deletions

View File

@ -128,13 +128,18 @@ std::tuple<s32, s32, s32, s32> HostDisplay::CalculateDrawRect(s32 window_width,
}
std::tuple<s32, s32, s32, s32> HostDisplay::CalculateSoftwareCursorDrawRect() const
{
return CalculateSoftwareCursorDrawRect(m_mouse_position_x, m_mouse_position_y);
}
std::tuple<s32, s32, s32, s32> HostDisplay::CalculateSoftwareCursorDrawRect(s32 cursor_x, s32 cursor_y) const
{
const float scale = m_window_info.surface_scale * m_cursor_texture_scale;
const u32 cursor_extents_x = static_cast<u32>(static_cast<float>(m_cursor_texture->GetWidth()) * scale * 0.5f);
const u32 cursor_extents_y = static_cast<u32>(static_cast<float>(m_cursor_texture->GetHeight()) * scale * 0.5f);
const s32 out_left = m_mouse_position_x - cursor_extents_x;
const s32 out_top = m_mouse_position_y - cursor_extents_y;
const s32 out_left = cursor_x - cursor_extents_x;
const s32 out_top = cursor_y - cursor_extents_y;
const s32 out_width = cursor_extents_x * 2u;
const s32 out_height = cursor_extents_y * 2u;

View File

@ -160,6 +160,7 @@ protected:
float* out_y_scale) const;
std::tuple<s32, s32, s32, s32> CalculateSoftwareCursorDrawRect() const;
std::tuple<s32, s32, s32, s32> CalculateSoftwareCursorDrawRect(s32 cursor_x, s32 cursor_y) const;
WindowInfo m_window_info;

View File

@ -76,7 +76,7 @@ void LibretroD3D11HostDisplay::ResizeRenderWindow(s32 new_window_width, s32 new_
bool LibretroD3D11HostDisplay::Render()
{
// TODO: Skip framebuffer when offset is (0,0).
if (!CheckFramebufferSize(m_display_texture_width, m_display_texture_height))
if (!CheckFramebufferSize(m_display_texture_view_width, m_display_texture_view_height))
return false;
// Ensure we're not currently bound.
@ -86,21 +86,23 @@ bool LibretroD3D11HostDisplay::Render()
if (HasDisplayTexture())
{
RenderDisplay(0, 0, m_display_texture_width, m_display_texture_height, m_display_texture_handle,
RenderDisplay(0, 0, m_display_texture_view_width, m_display_texture_view_height, m_display_texture_handle,
m_display_texture_width, m_display_texture_height, m_display_texture_view_x, m_display_texture_view_y,
m_display_texture_view_width, m_display_texture_view_height, m_display_linear_filtering);
}
if (HasSoftwareCursor())
{
const auto [left, top, width, height] = CalculateSoftwareCursorDrawRect();
// TODO: Scale mouse x/y
const auto [left, top, width, height] = CalculateSoftwareCursorDrawRect(m_mouse_position_x, m_mouse_position_y);
RenderSoftwareCursor(left, top, width, height, m_cursor_texture.get());
}
// NOTE: libretro frontend expects the data bound to PS SRV slot 0.
m_context->OMSetRenderTargets(0, nullptr, nullptr);
m_context->PSSetShaderResources(0, 1, m_framebuffer.GetD3DSRVArray());
g_retro_video_refresh_callback(RETRO_HW_FRAME_BUFFER_VALID, m_display_texture_width, m_display_texture_height, 0);
g_retro_video_refresh_callback(RETRO_HW_FRAME_BUFFER_VALID, m_display_texture_view_width,
m_display_texture_view_height, 0);
return true;
}

View File

@ -125,18 +125,20 @@ bool LibretroOpenGLHostDisplay::Render()
if (HasDisplayTexture())
{
RenderDisplay(0, 0, m_display_texture_width, m_display_texture_height, m_display_texture_handle,
RenderDisplay(0, 0, m_display_texture_view_width, m_display_texture_view_height, m_display_texture_handle,
m_display_texture_width, m_display_texture_height, m_display_texture_view_x, m_display_texture_view_y,
m_display_texture_view_width, m_display_texture_view_height, m_display_linear_filtering);
}
if (HasSoftwareCursor())
{
const auto [left, top, width, height] = CalculateSoftwareCursorDrawRect();
RenderSoftwareCursor(left, top, width, height, m_cursor_texture.get());
// TODO: Scale mouse x/y
const auto [left, top, width, height] = CalculateSoftwareCursorDrawRect(m_mouse_position_x, m_mouse_position_y);
RenderSoftwareCursor(left, m_display_texture_view_height - top - height, width, height, m_cursor_texture.get());
}
g_retro_video_refresh_callback(RETRO_HW_FRAME_BUFFER_VALID, m_display_texture_width, m_display_texture_height, 0);
g_retro_video_refresh_callback(RETRO_HW_FRAME_BUFFER_VALID, m_display_texture_view_width,
m_display_texture_view_height, 0);
GL::Program::ResetLastProgram();
return true;

View File

@ -461,13 +461,13 @@ void OpenGLHostDisplay::RenderSoftwareCursor()
return;
const auto [left, top, width, height] = CalculateSoftwareCursorDrawRect();
RenderSoftwareCursor(left, top, width, height, m_cursor_texture.get());
RenderSoftwareCursor(left, GetWindowHeight() - top - height, width, height, m_cursor_texture.get());
}
void OpenGLHostDisplay::RenderSoftwareCursor(s32 left, s32 top, s32 width, s32 height,
void OpenGLHostDisplay::RenderSoftwareCursor(s32 left, s32 bottom, s32 width, s32 height,
HostDisplayTexture* texture_handle)
{
glViewport(left, GetWindowHeight() - top - height, width, height);
glViewport(left, bottom, width, height);
glEnable(GL_BLEND);
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);

View File

@ -69,7 +69,7 @@ protected:
void RenderDisplay(s32 left, s32 bottom, s32 width, s32 height, void* texture_handle, u32 texture_width,
s32 texture_height, s32 texture_view_x, s32 texture_view_y, s32 texture_view_width,
s32 texture_view_height, bool linear_filter);
void RenderSoftwareCursor(s32 left, s32 top, s32 width, s32 height, HostDisplayTexture* texture_handle);
void RenderSoftwareCursor(s32 left, s32 bottom, s32 width, s32 height, HostDisplayTexture* texture_handle);
std::unique_ptr<GL::Context> m_gl_context;