Play-/Source/ui_libretro/GSH_OpenGL_Libretro.cpp

117 lines
2.5 KiB
C++
Raw Permalink Normal View History

2019-12-31 21:02:35 +01:00
#include "GSH_OpenGL_Libretro.h"
#include "ext/libretro.h"
2019-12-31 21:02:35 +01:00
#include "Log.h"
#define LOG_NAME "LIBRETRO"
extern int g_res_factor;
extern CGSHandler::PRESENTATION_MODE g_presentation_mode;
2019-06-25 19:04:04 +01:00
extern retro_video_refresh_t g_video_cb;
2019-12-31 21:02:35 +01:00
extern struct retro_hw_render_callback g_hw_render;
CGSH_OpenGL_Libretro::CGSH_OpenGL_Libretro()
: CGSH_OpenGL(false)
{
}
CGSH_OpenGL_Libretro::~CGSH_OpenGL_Libretro()
{
}
CGSH_OpenGL::FactoryFunction CGSH_OpenGL_Libretro::GetFactoryFunction()
{
return []() { return new CGSH_OpenGL_Libretro(); };
}
void CGSH_OpenGL_Libretro::InitializeImpl()
{
fprintf(stderr, "%s\n", __FUNCTION__);
#if defined(USE_GLEW)
glewExperimental = GL_TRUE;
auto result = glewInit();
CLog::GetInstance().Warn(LOG_NAME, "glewInit %d\n", result == GLEW_OK);
assert(result == GLEW_OK);
if(result != GLEW_OK)
{
fprintf(stderr, "Error: %s\n", glewGetErrorString(result));
CLog::GetInstance().Warn(LOG_NAME, "Error: %s\n", glewGetErrorString(result));
return;
}
#endif
2019-06-25 19:04:04 +01:00
2019-12-31 21:02:35 +01:00
if(g_hw_render.get_current_framebuffer)
2019-06-25 19:04:04 +01:00
m_presentFramebuffer = g_hw_render.get_current_framebuffer();
2019-12-31 21:02:35 +01:00
UpdatePresentationImpl();
CGSH_OpenGL::InitializeImpl();
}
void CGSH_OpenGL_Libretro::UpdatePresentation()
{
SendGSCall([this]() { UpdatePresentationImpl(); });
}
void CGSH_OpenGL_Libretro::UpdatePresentationImpl()
{
PRESENTATION_PARAMS presentationParams;
presentationParams.mode = g_presentation_mode;
presentationParams.windowWidth = GetCrtWidth() * g_res_factor;
2019-06-25 19:04:04 +01:00
presentationParams.windowHeight = GetCrtHeight() * g_res_factor;
2019-12-31 21:02:35 +01:00
SetPresentationParams(presentationParams);
NotifyPreferencesChanged();
}
void CGSH_OpenGL_Libretro::FlushMailBox()
{
bool isFlushed = false;
SendGSCall([&]() {
isFlushed = true;
2020-12-28 01:24:54 +00:00
m_flipped = true;
2020-01-01 13:28:51 +00:00
},
true);
2019-12-31 21:02:35 +01:00
while(!isFlushed)
{
// Wait for flush to complete
ProcessSingleFrame();
}
}
void CGSH_OpenGL_Libretro::Reset()
{
FlushMailBox();
ResetBase();
CGSH_OpenGL::ReleaseImpl();
InitializeImpl();
}
void CGSH_OpenGL_Libretro::Release()
{
FlushMailBox();
ResetBase();
CGSH_OpenGL::ReleaseImpl();
}
2023-07-28 19:37:24 -04:00
void CGSH_OpenGL_Libretro::FlipImpl(const DISPLAY_INFO& dispInfo)
2019-12-31 21:02:35 +01:00
{
CLog::GetInstance().Print(LOG_NAME, "%s\n", __FUNCTION__);
if(g_hw_render.get_current_framebuffer)
2019-06-25 19:04:04 +01:00
m_presentFramebuffer = g_hw_render.get_current_framebuffer();
2019-12-31 21:02:35 +01:00
else
return;
2023-07-28 19:37:24 -04:00
CGSH_OpenGL::FlipImpl(dispInfo);
2019-12-31 21:02:35 +01:00
}
void CGSH_OpenGL_Libretro::PresentBackbuffer()
{
CLog::GetInstance().Print(LOG_NAME, "%s\n", __FUNCTION__);
if(g_video_cb)
2019-06-25 19:04:04 +01:00
g_video_cb(RETRO_HW_FRAME_BUFFER_VALID, GetCrtWidth() * g_res_factor, GetCrtHeight() * g_res_factor, 0);
2019-12-31 21:02:35 +01:00
}