make OpenGL renderer a build option

mostly meant for the Switch port
This commit is contained in:
RSDuck 2020-09-30 23:58:42 +02:00
parent 4b705556bc
commit 6977302403
9 changed files with 67 additions and 11 deletions

View File

@ -50,6 +50,12 @@ else()
option(ENABLE_LTO "Enable link-time optimization" OFF) option(ENABLE_LTO "Enable link-time optimization" OFF)
endif() endif()
option(ENABLE_OGLRENDERER "Enable OpenGL renderer" ON)
if (ENABLE_OGLRENDERER)
add_definitions(-DOGLRENDERER_ENABLED)
endif()
if (CMAKE_BUILD_TYPE STREQUAL Debug) if (CMAKE_BUILD_TYPE STREQUAL Debug)
add_compile_options(-Og) add_compile_options(-Og)
endif() endif()

View File

@ -26,17 +26,12 @@ add_library(core STATIC
FIFO.h FIFO.h
GBACart.cpp GBACart.cpp
GPU.cpp GPU.cpp
GPU_OpenGL.cpp
GPU_OpenGL_shaders.h
GPU2D.cpp GPU2D.cpp
GPU3D.cpp GPU3D.cpp
GPU3D_OpenGL.cpp
GPU3D_OpenGL_shaders.h
GPU3D_Soft.cpp GPU3D_Soft.cpp
melonDLDI.h melonDLDI.h
NDS.cpp NDS.cpp
NDSCart.cpp NDSCart.cpp
OpenGLSupport.cpp
Platform.h Platform.h
ROMList.h ROMList.h
RTC.cpp RTC.cpp
@ -52,6 +47,16 @@ add_library(core STATIC
xxhash/xxhash.c xxhash/xxhash.c
) )
if (ENABLE_OGLRENDERER)
target_sources(core PRIVATE
GPU_OpenGL.cpp
GPU_OpenGL_shaders.h
GPU3D_OpenGL.cpp
GPU3D_OpenGL_shaders.h
OpenGLSupport.cpp
)
endif()
if (ENABLE_JIT) if (ENABLE_JIT)
enable_language(ASM) enable_language(ASM)
@ -95,8 +100,16 @@ if (ENABLE_JIT)
endif() endif()
endif() endif()
if (WIN32) if (ENABLE_OGLRENDERER)
target_link_libraries(core ole32 comctl32 ws2_32 opengl32) if (WIN32)
target_link_libraries(core ole32 comctl32 ws2_32 opengl32)
else()
target_link_libraries(core GL EGL)
endif()
else() else()
target_link_libraries(core GL EGL) if (WIN32)
endif() target_link_libraries(core ole32 comctl32 ws2_32)
else()
target_link_libraries(core)
endif()
endif()

View File

@ -280,6 +280,7 @@ void AssignFramebuffers()
void InitRenderer(int renderer) void InitRenderer(int renderer)
{ {
#ifdef OGLRENDERER_ENABLED
if (renderer == 1) if (renderer == 1)
{ {
if (!GLCompositor::Init()) if (!GLCompositor::Init())
@ -292,8 +293,8 @@ void InitRenderer(int renderer)
renderer = 0; renderer = 0;
} }
} }
else
if (renderer == 0) #endif
{ {
GPU3D::SoftRenderer::Init(); GPU3D::SoftRenderer::Init();
} }
@ -308,11 +309,13 @@ void DeInitRenderer()
{ {
GPU3D::SoftRenderer::DeInit(); GPU3D::SoftRenderer::DeInit();
} }
#ifdef OGLRENDERER_ENABLED
else else
{ {
GPU3D::GLRenderer::DeInit(); GPU3D::GLRenderer::DeInit();
GLCompositor::DeInit(); GLCompositor::DeInit();
} }
#endif
} }
void ResetRenderer() void ResetRenderer()
@ -321,11 +324,13 @@ void ResetRenderer()
{ {
GPU3D::SoftRenderer::Reset(); GPU3D::SoftRenderer::Reset();
} }
#ifdef OGLRENDERER_ENABLED
else else
{ {
GLCompositor::Reset(); GLCompositor::Reset();
GPU3D::GLRenderer::Reset(); GPU3D::GLRenderer::Reset();
} }
#endif
} }
void SetRenderSettings(int renderer, RenderSettings& settings) void SetRenderSettings(int renderer, RenderSettings& settings)
@ -364,11 +369,13 @@ void SetRenderSettings(int renderer, RenderSettings& settings)
{ {
GPU3D::SoftRenderer::SetRenderSettings(settings); GPU3D::SoftRenderer::SetRenderSettings(settings);
} }
#ifdef OGLRENDERER_ENABLED
else else
{ {
GLCompositor::SetRenderSettings(settings); GLCompositor::SetRenderSettings(settings);
GPU3D::GLRenderer::SetRenderSettings(settings); GPU3D::GLRenderer::SetRenderSettings(settings);
} }
#endif
} }
@ -1055,7 +1062,9 @@ void StartScanline(u32 line)
GPU2D_B->VBlank(); GPU2D_B->VBlank();
GPU3D::VBlank(); GPU3D::VBlank();
#ifdef OGLRENDERER_ENABLED
if (Accelerated) GLCompositor::RenderFrame(); if (Accelerated) GLCompositor::RenderFrame();
#endif
} }
else if (VCount == 144) else if (VCount == 144)
{ {

View File

@ -437,6 +437,7 @@ void SetDispStat(u32 cpu, u16 val);
void SetVCount(u16 val); void SetVCount(u16 val);
#ifdef OGLRENDERER_ENABLED
namespace GLCompositor namespace GLCompositor
{ {
@ -450,6 +451,7 @@ void RenderFrame();
void BindOutputTexture(); void BindOutputTexture();
} }
#endif
} }

View File

@ -949,6 +949,7 @@ void GPU2D::VBlankEnd()
//OBJMosaicY = 0; //OBJMosaicY = 0;
//OBJMosaicYCount = 0; //OBJMosaicYCount = 0;
#ifdef OGLRENDERER_ENABLED
if (Accelerated) if (Accelerated)
{ {
if ((Num == 0) && (CaptureCnt & (1<<31)) && (((CaptureCnt >> 29) & 0x3) != 1)) if ((Num == 0) && (CaptureCnt & (1<<31)) && (((CaptureCnt >> 29) & 0x3) != 1))
@ -956,6 +957,7 @@ void GPU2D::VBlankEnd()
GPU3D::GLRenderer::PrepareCaptureFrame(); GPU3D::GLRenderer::PrepareCaptureFrame();
} }
} }
#endif
} }

View File

@ -2528,13 +2528,19 @@ void VBlank()
void VCount215() void VCount215()
{ {
if (GPU::Renderer == 0) SoftRenderer::RenderFrame(); if (GPU::Renderer == 0) SoftRenderer::RenderFrame();
#ifdef OGLRENDERER_ENABLED
else GLRenderer::RenderFrame(); else GLRenderer::RenderFrame();
#endif
} }
u32* GetLine(int line) u32* GetLine(int line)
{ {
if (GPU::Renderer == 0) return SoftRenderer::GetLine(line); if (GPU::Renderer == 0) return SoftRenderer::GetLine(line);
#ifdef OGLRENDERER_ENABLED
else return GLRenderer::GetLine(line); else return GLRenderer::GetLine(line);
#else
return NULL;
#endif
} }

View File

@ -139,6 +139,7 @@ u32* GetLine(int line);
} }
#ifdef OGLRENDERER_ENABLED
namespace GLRenderer namespace GLRenderer
{ {
@ -154,6 +155,7 @@ u32* GetLine(int line);
void SetupAccelFrame(); void SetupAccelFrame();
} }
#endif
} }

View File

@ -50,6 +50,10 @@ VideoSettingsDialog::VideoSettingsDialog(QWidget* parent) : QDialog(parent), ui(
connect(grp3DRenderer, SIGNAL(buttonClicked(int)), this, SLOT(onChange3DRenderer(int))); connect(grp3DRenderer, SIGNAL(buttonClicked(int)), this, SLOT(onChange3DRenderer(int)));
grp3DRenderer->button(Config::_3DRenderer)->setChecked(true); grp3DRenderer->button(Config::_3DRenderer)->setChecked(true);
#ifndef OGLRENDERER_ENABLED
ui->rb3DOpenGL->setEnabled(false);
#endif
ui->cbGLDisplay->setChecked(Config::ScreenUseGL != 0); ui->cbGLDisplay->setChecked(Config::ScreenUseGL != 0);
ui->cbVSync->setChecked(Config::ScreenVSync != 0); ui->cbVSync->setChecked(Config::ScreenVSync != 0);

View File

@ -49,7 +49,9 @@
#include "NDS.h" #include "NDS.h"
#include "GBACart.h" #include "GBACart.h"
#ifdef OGLRENDERER_ENABLED
#include "OpenGLSupport.h" #include "OpenGLSupport.h"
#endif
#include "GPU.h" #include "GPU.h"
#include "SPU.h" #include "SPU.h"
#include "Wifi.h" #include "Wifi.h"
@ -336,13 +338,17 @@ void EmuThread::run()
videoSettings.Soft_Threaded = Config::Threaded3D != 0; videoSettings.Soft_Threaded = Config::Threaded3D != 0;
videoSettings.GL_ScaleFactor = Config::GL_ScaleFactor; videoSettings.GL_ScaleFactor = Config::GL_ScaleFactor;
#ifdef OGLRENDERER_ENABLED
if (hasOGL) if (hasOGL)
{ {
oglContext->makeCurrent(oglSurface); oglContext->makeCurrent(oglSurface);
videoRenderer = OpenGL::Init() ? Config::_3DRenderer : 0; videoRenderer = OpenGL::Init() ? Config::_3DRenderer : 0;
} }
else else
#endif
{
videoRenderer = 0; videoRenderer = 0;
}
GPU::InitRenderer(videoRenderer); GPU::InitRenderer(videoRenderer);
GPU::SetRenderSettings(videoRenderer, videoSettings); GPU::SetRenderSettings(videoRenderer, videoSettings);
@ -396,13 +402,17 @@ void EmuThread::run()
if (hasOGL != mainWindow->hasOGL) if (hasOGL != mainWindow->hasOGL)
{ {
hasOGL = mainWindow->hasOGL; hasOGL = mainWindow->hasOGL;
#ifdef OGLRENDERER_ENABLED
if (hasOGL) if (hasOGL)
{ {
oglContext->makeCurrent(oglSurface); oglContext->makeCurrent(oglSurface);
videoRenderer = OpenGL::Init() ? Config::_3DRenderer : 0; videoRenderer = OpenGL::Init() ? Config::_3DRenderer : 0;
} }
else else
#endif
{
videoRenderer = 0; videoRenderer = 0;
}
} }
else else
videoRenderer = hasOGL ? Config::_3DRenderer : 0; videoRenderer = hasOGL ? Config::_3DRenderer : 0;
@ -923,12 +933,14 @@ void ScreenPanelGL::paintGL()
int frontbuf = GPU::FrontBuffer; int frontbuf = GPU::FrontBuffer;
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
#ifdef OGLRENDERER_ENABLED
if (GPU::Renderer != 0) if (GPU::Renderer != 0)
{ {
// hardware-accelerated render // hardware-accelerated render
GPU::GLCompositor::BindOutputTexture(); GPU::GLCompositor::BindOutputTexture();
} }
else else
#endif
{ {
// regular render // regular render
glBindTexture(GL_TEXTURE_2D, screenTexture); glBindTexture(GL_TEXTURE_2D, screenTexture);