mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-01 14:58:14 +00:00
Change the GraphicsContext interface to be more consistent
This commit is contained in:
1 parent
28a2c7bca6
commit
7f218acc53
51 files changed
+680
-628
No files matched your search
@@ -11,8 +11,8 @@
|
||||
#define __uuidof(type) IID_##type
|
||||
#endif
|
||||
|
||||
bool LibretroD3D11Context::Init() {
|
||||
if (!LibretroHWRenderContext::Init(true)) {
|
||||
bool LibretroD3D11Context::InitAPI(void *wnd, std::string *deviceName, std::string *error_message) {
|
||||
if (!LibretroHWRenderContext::InitHW(true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
class LibretroD3D11Context : public LibretroHWRenderContext {
|
||||
public:
|
||||
LibretroD3D11Context() : LibretroHWRenderContext(RETRO_HW_CONTEXT_D3D11, 11) {}
|
||||
bool Init() override;
|
||||
bool InitAPI(void *wnd, std::string *deviceName, std::string *error_message) override;
|
||||
|
||||
void SwapBuffers() override;
|
||||
void GotBackbuffer() override;
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
#include "libretro/LibretroGLContext.h"
|
||||
|
||||
bool LibretroGLContext::Init() {
|
||||
if (!LibretroHWRenderContext::Init(false))
|
||||
bool LibretroGLContext::InitAPI(void *wnd, std::string *deviceName, std::string *error_message) {
|
||||
if (!LibretroHWRenderContext::InitHW(false))
|
||||
return false;
|
||||
|
||||
g_Config.iGPUBackend = (int)GPUBackend::OPENGL;
|
||||
|
||||
@@ -16,9 +16,9 @@ public:
|
||||
hw_render_.bottom_left_origin = true;
|
||||
}
|
||||
|
||||
bool NeedsRenderThread() const override { return true; }
|
||||
bool NeedsSeparateEmuThread() const override { return true; }
|
||||
|
||||
bool Init() override;
|
||||
bool InitAPI(void *wnd, std::string *deviceName, std::string *error_message) override;
|
||||
void CreateDrawContext() override;
|
||||
void DestroyDrawContext() override;
|
||||
void SetRenderTarget() override {
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
#include "libretro/LibretroGLCoreContext.h"
|
||||
|
||||
bool LibretroGLCoreContext::Init() {
|
||||
if (!LibretroHWRenderContext::Init(false))
|
||||
bool LibretroGLCoreContext::InitAPI(void *wnd, std::string *deviceName, std::string *error_message) {
|
||||
if (!LibretroHWRenderContext::InitHW(false))
|
||||
return false;
|
||||
|
||||
g_Config.iGPUBackend = (int)GPUBackend::OPENGL;
|
||||
|
||||
@@ -10,9 +10,9 @@ public:
|
||||
: LibretroHWRenderContext(RETRO_HW_CONTEXT_OPENGL_CORE, 3, 1) {
|
||||
hw_render_.bottom_left_origin = true;
|
||||
}
|
||||
bool NeedsRenderThread() const override { return true; }
|
||||
bool NeedsSeparateEmuThread() const override { return true; }
|
||||
|
||||
bool Init() override;
|
||||
bool InitAPI(void *wnd, std::string *deviceName, std::string *error_message) override;
|
||||
void CreateDrawContext() override;
|
||||
void DestroyDrawContext() override;
|
||||
void SetRenderTarget() override {
|
||||
|
||||
@@ -22,7 +22,7 @@ void retro_set_video_refresh(retro_video_refresh_t cb) { LibretroGraphicsContext
|
||||
static void context_reset() { ((LibretroHWRenderContext *)Libretro::ctx)->ContextReset(); }
|
||||
static void context_destroy() { ((LibretroHWRenderContext *)Libretro::ctx)->ContextDestroy(); }
|
||||
|
||||
bool LibretroHWRenderContext::Init(bool cache_context) {
|
||||
bool LibretroHWRenderContext::InitHW(bool cache_context) {
|
||||
hw_render_.cache_context = cache_context;
|
||||
if (!Libretro::environ_cb(RETRO_ENVIRONMENT_SET_HW_RENDER, &hw_render_))
|
||||
return false;
|
||||
@@ -83,7 +83,7 @@ void LibretroHWRenderContext::ContextDestroy() {
|
||||
}
|
||||
|
||||
if (!hw_render_.cache_context && !Libretro::useEmuThread) {
|
||||
Shutdown();
|
||||
ShutdownAPI();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,13 +101,15 @@ LibretroGraphicsContext *LibretroGraphicsContext::CreateGraphicsContext() {
|
||||
if (Libretro::backend != RETRO_HW_CONTEXT_DUMMY)
|
||||
preferred = Libretro::backend;
|
||||
|
||||
std::string errorMessage;
|
||||
#ifndef USING_GLES2
|
||||
if (preferred == RETRO_HW_CONTEXT_DUMMY || preferred == RETRO_HW_CONTEXT_OPENGL_CORE) {
|
||||
ctx = new LibretroGLCoreContext();
|
||||
|
||||
if (ctx->Init()) {
|
||||
if (ctx->InitAPI(nullptr, nullptr, &errorMessage)) {
|
||||
return ctx;
|
||||
}
|
||||
// Failed? Try next.
|
||||
delete ctx;
|
||||
}
|
||||
#endif
|
||||
@@ -115,20 +117,24 @@ LibretroGraphicsContext *LibretroGraphicsContext::CreateGraphicsContext() {
|
||||
if (preferred == RETRO_HW_CONTEXT_DUMMY || preferred == RETRO_HW_CONTEXT_OPENGL || preferred == RETRO_HW_CONTEXT_OPENGLES3) {
|
||||
ctx = new LibretroGLContext();
|
||||
|
||||
if (ctx->Init()) {
|
||||
if (ctx->InitAPI(nullptr, nullptr, &errorMessage)) {
|
||||
return ctx;
|
||||
}
|
||||
delete ctx;
|
||||
|
||||
// Failed? Try next.
|
||||
delete ctx;
|
||||
}
|
||||
|
||||
#ifndef HAVE_LIBNX
|
||||
if (preferred == RETRO_HW_CONTEXT_DUMMY || preferred == RETRO_HW_CONTEXT_VULKAN) {
|
||||
ctx = new LibretroVulkanContext();
|
||||
|
||||
if (ctx->Init()) {
|
||||
if (ctx->InitAPI(nullptr, nullptr, &errorMessage)) {
|
||||
return ctx;
|
||||
}
|
||||
delete ctx;
|
||||
|
||||
// Failed? Try next.
|
||||
delete ctx;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -136,15 +142,18 @@ LibretroGraphicsContext *LibretroGraphicsContext::CreateGraphicsContext() {
|
||||
if (preferred == RETRO_HW_CONTEXT_DUMMY || preferred == RETRO_HW_CONTEXT_D3D11) {
|
||||
ctx = new LibretroD3D11Context();
|
||||
|
||||
if (ctx->Init()) {
|
||||
if (ctx->InitAPI(nullptr, nullptr, &errorMessage)) {
|
||||
return ctx;
|
||||
}
|
||||
|
||||
// Failed? Try next.
|
||||
delete ctx;
|
||||
}
|
||||
#endif
|
||||
|
||||
// End of the line.
|
||||
ctx = new LibretroSoftwareContext();
|
||||
ctx->Init();
|
||||
ctx->InitAPI(nullptr, nullptr, &errorMessage);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,14 +19,13 @@
|
||||
class LibretroGraphicsContext : public GraphicsContext {
|
||||
public:
|
||||
LibretroGraphicsContext() {}
|
||||
~LibretroGraphicsContext() override { Shutdown(); }
|
||||
~LibretroGraphicsContext() override { ShutdownAPI(); }
|
||||
|
||||
virtual bool Init() = 0;
|
||||
virtual void SetRenderTarget() {}
|
||||
virtual GPUCore GetGPUCore() = 0;
|
||||
virtual const char *Ident() = 0;
|
||||
|
||||
void Shutdown() override {
|
||||
void ShutdownAPI() override {
|
||||
DestroyDrawContext();
|
||||
}
|
||||
virtual void SwapBuffers() = 0;
|
||||
@@ -56,7 +55,7 @@ protected:
|
||||
class LibretroHWRenderContext : public LibretroGraphicsContext {
|
||||
public:
|
||||
LibretroHWRenderContext(retro_hw_context_type context_type, unsigned version_major = 0, unsigned version_minor = 0);
|
||||
bool Init(bool cache_context);
|
||||
bool InitHW(bool cache_context);
|
||||
void SetRenderTarget() override {}
|
||||
void SwapBuffers() override {
|
||||
video_cb(RETRO_HW_FRAME_BUFFER_VALID, PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight, 0);
|
||||
@@ -71,7 +70,6 @@ protected:
|
||||
class LibretroSoftwareContext : public LibretroGraphicsContext {
|
||||
public:
|
||||
LibretroSoftwareContext() {}
|
||||
bool Init() override { return true; }
|
||||
void SwapBuffers() override {
|
||||
GPUDebugBuffer buf;
|
||||
u16 w = NATIVEWIDTH;
|
||||
|
||||
@@ -90,8 +90,8 @@ static const VkApplicationInfo *GetApplicationInfo(void) {
|
||||
return &app_info;
|
||||
}
|
||||
|
||||
bool LibretroVulkanContext::Init() {
|
||||
if (!LibretroHWRenderContext::Init(true)) {
|
||||
bool LibretroVulkanContext::InitAPI(void *wnd, std::string *deviceName, std::string *error_message) {
|
||||
if (!LibretroHWRenderContext::InitHW(true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ void LibretroVulkanContext::CreateDrawContext() {
|
||||
SetGPUBackend(GPUBackend::VULKAN);
|
||||
}
|
||||
|
||||
void LibretroVulkanContext::Shutdown() {
|
||||
void LibretroVulkanContext::ShutdownAPI() {
|
||||
if (!vk) {
|
||||
return;
|
||||
}
|
||||
@@ -157,7 +157,7 @@ void LibretroVulkanContext::Shutdown() {
|
||||
if (draw_)
|
||||
draw_->HandleEvent(Draw::Event::LOST_BACKBUFFER, vk->GetBackbufferWidth(), vk->GetBackbufferHeight());
|
||||
|
||||
LibretroHWRenderContext::Shutdown();
|
||||
LibretroHWRenderContext::ShutdownAPI();
|
||||
|
||||
vk->WaitUntilQueueIdle();
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
class LibretroVulkanContext : public LibretroHWRenderContext {
|
||||
public:
|
||||
LibretroVulkanContext();
|
||||
~LibretroVulkanContext() override { Shutdown(); }
|
||||
bool Init() override;
|
||||
void Shutdown() override;
|
||||
~LibretroVulkanContext() override { ShutdownAPI(); }
|
||||
bool InitAPI(void *wnd, std::string *deviceName, std::string *error_message) override;
|
||||
void ShutdownAPI() override;
|
||||
void SwapBuffers() override;
|
||||
|
||||
void *GetAPIContext() override;
|
||||
|
||||
Reference in new issue
Block a user