glcore context switching

This commit is contained in:
barbudreadmon 2020-09-27 15:24:17 +02:00
parent 350cb11f9a
commit b41d20dd82
6 changed files with 117 additions and 22 deletions

View File

@ -3,6 +3,7 @@ set(LIBRETRO_SRCS
libretro.cpp
LibretroGraphicsContext.cpp
LibretroGLContext.cpp
LibretroGLCoreContext.cpp
LibretroVulkanContext.cpp
libretro_vulkan.cpp)

View File

@ -9,8 +9,6 @@ public:
LibretroGLContext()
#ifdef USING_GLES2
: LibretroHWRenderContext(RETRO_HW_CONTEXT_OPENGLES2)
#elif defined(HAVE_OPENGL_CORE)
: LibretroHWRenderContext(RETRO_HW_CONTEXT_OPENGL_CORE, 3, 1)
#else
: LibretroHWRenderContext(RETRO_HW_CONTEXT_OPENGL)
#endif

View File

@ -0,0 +1,36 @@
#include "Common/Log.h"
#include "Core/Config.h"
#include "Core/ConfigValues.h"
#include "Core/System.h"
#include "gfx_es2/gpu_features.h"
#include "libretro/LibretroGLCoreContext.h"
bool LibretroGLCoreContext::Init() {
if (!LibretroHWRenderContext::Init(true))
return false;
g_Config.iGPUBackend = (int)GPUBackend::OPENGL;
return true;
}
void LibretroGLCoreContext::CreateDrawContext() {
if (!glewInitDone) {
#if !defined(IOS) && !defined(USING_GLES2)
if (glewInit() != GLEW_OK) {
ERROR_LOG(G3D, "glewInit() failed.\n");
return;
}
#endif
glewInitDone = true;
CheckGLExtensions();
}
draw_ = Draw::T3DCreateGLContext();
renderManager_ = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
}
void LibretroGLCoreContext::DestroyDrawContext() {
LibretroHWRenderContext::DestroyDrawContext();
renderManager_ = nullptr;
}

View File

@ -0,0 +1,37 @@
#pragma once
#include "gfx/gl_common.h"
#include "libretro/LibretroGraphicsContext.h"
#include "thin3d/GLRenderManager.h"
class LibretroGLCoreContext : public LibretroHWRenderContext {
public:
LibretroGLCoreContext()
: LibretroHWRenderContext(RETRO_HW_CONTEXT_OPENGL_CORE, 3, 1)
{
hw_render_.bottom_left_origin = true;
}
bool Init() override;
void CreateDrawContext() override;
void DestroyDrawContext() override;
void SetRenderTarget() override {
extern GLuint g_defaultFBO;
g_defaultFBO = hw_render_.get_current_framebuffer();
}
void ThreadStart() override { renderManager_->ThreadStart(draw_); }
bool ThreadFrame() override { return renderManager_->ThreadFrame(); }
void ThreadEnd() override { renderManager_->ThreadEnd(); }
void StopThread() override {
renderManager_->WaitUntilQueueIdle();
renderManager_->StopThread();
}
GPUCore GetGPUCore() override { return GPUCORE_GLES; }
const char *Ident() override { return "OpenGL Core"; }
private:
GLRenderManager *renderManager_ = nullptr;
bool glewInitDone = false;
};

View File

@ -1,6 +1,7 @@
#include "libretro/LibretroGraphicsContext.h"
#include "libretro/LibretroGLContext.h"
#include "libretro/LibretroGLCoreContext.h"
#include "libretro/libretro.h"
#include "libretro/LibretroVulkanContext.h"
#ifdef _WIN32
@ -88,34 +89,55 @@ void LibretroGraphicsContext::LostBackbuffer() { draw_->HandleEvent(Draw::Event:
LibretroGraphicsContext *LibretroGraphicsContext::CreateGraphicsContext() {
LibretroGraphicsContext *ctx;
ctx = new LibretroGLContext();
retro_hw_context_type preferred;
if (!Libretro::environ_cb(RETRO_ENVIRONMENT_GET_PREFERRED_HW_RENDER, &preferred))
preferred = RETRO_HW_CONTEXT_DUMMY;
if (ctx->Init()) {
return ctx;
#ifndef USING_GLES2
if (preferred == RETRO_HW_CONTEXT_DUMMY || preferred == RETRO_HW_CONTEXT_OPENGL_CORE) {
ctx = new LibretroGLCoreContext();
if (ctx->Init()) {
return ctx;
}
delete ctx;
}
delete ctx;
#endif
ctx = new LibretroVulkanContext();
if (preferred == RETRO_HW_CONTEXT_DUMMY || preferred == RETRO_HW_CONTEXT_OPENGL) {
ctx = new LibretroGLContext();
if (ctx->Init()) {
return ctx;
if (ctx->Init()) {
return ctx;
}
delete ctx;
}
if (preferred == RETRO_HW_CONTEXT_DUMMY || preferred == RETRO_HW_CONTEXT_VULKAN) {
ctx = new LibretroVulkanContext();
if (ctx->Init()) {
return ctx;
}
delete ctx;
}
delete ctx;
#ifdef _WIN32
ctx = new LibretroD3D11Context();
if (preferred == RETRO_HW_CONTEXT_DUMMY || preferred == RETRO_HW_CONTEXT_DIRECT3D) {
ctx = new LibretroD3D11Context();
if (ctx->Init()) {
return ctx;
if (ctx->Init()) {
return ctx;
}
delete ctx;
ctx = new LibretroD3D9Context();
if (ctx->Init()) {
return ctx;
}
delete ctx;
}
delete ctx;
ctx = new LibretroD3D9Context();
if (ctx->Init()) {
return ctx;
}
delete ctx;
#endif
#if 1

View File

@ -696,7 +696,8 @@ endif
SOURCES_CXX += \
$(LIBRETRODIR)/libretro.cpp \
$(LIBRETRODIR)/LibretroGraphicsContext.cpp \
$(LIBRETRODIR)/LibretroGLContext.cpp
$(LIBRETRODIR)/LibretroGLContext.cpp \
$(LIBRETRODIR)/LibretroGLCoreContext.cpp
ifneq ($(STATIC_LINKING), 1)
SOURCES_C += \