libretro: Recreate resources after context reset

This commit is contained in:
Connor McLaughlin 2020-08-23 14:21:06 +10:00
parent 32921acc5a
commit df14519a97
4 changed files with 15 additions and 0 deletions

View file

@ -59,6 +59,8 @@ public:
virtual void DestroyRenderDevice() = 0;
virtual void DestroyRenderSurface() = 0;
virtual bool ChangeRenderWindow(const WindowInfo& wi) = 0;
virtual bool CreateResources() = 0;
virtual void DestroyResources() = 0;
/// Call when the window size changes externally to recreate any resources.
virtual void ResizeRenderWindow(s32 new_window_width, s32 new_window_height) = 0;

View file

@ -137,6 +137,13 @@ void LibretroHostDisplay::DestroyRenderDevice() {}
void LibretroHostDisplay::DestroyRenderSurface() {}
bool LibretroHostDisplay::CreateResources()
{
return true;
}
void LibretroHostDisplay::DestroyResources() {}
bool LibretroHostDisplay::ChangeRenderWindow(const WindowInfo& wi)
{
m_window_info = wi;

View file

@ -26,6 +26,9 @@ public:
void ResizeRenderWindow(s32 new_window_width, s32 new_window_height) override;
void DestroyRenderSurface() override;
bool CreateResources() override;
void DestroyResources() override;
std::unique_ptr<HostDisplayTexture> CreateTexture(u32 width, u32 height, const void* data, u32 data_stride,
bool dynamic) override;
void UpdateTexture(HostDisplayTexture* texture, u32 x, u32 y, u32 width, u32 height, const void* data,

View file

@ -935,6 +935,8 @@ void LibretroHostInterface::SwitchToHardwareRenderer()
{
Log_InfoPrintf("Using existing hardware display");
renderer = RenderAPIToRenderer(display->GetRenderAPI());
if (!display->CreateResources())
Panic("Failed to recreate resources after reinit");
}
else
{
@ -1013,6 +1015,7 @@ void LibretroHostInterface::SwitchToSoftwareRenderer()
if (m_using_hardware_renderer)
{
m_hw_render_display = std::move(m_display);
m_hw_render_display->DestroyResources();
m_using_hardware_renderer = false;
}