Skip to content

Commit

Permalink
make OpenGL renderer a build option
Browse files Browse the repository at this point in the history
mostly meant for the Switch port
  • Loading branch information
RSDuck committed Sep 30, 2020
1 parent 4b70555 commit 6977302
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ else()
option(ENABLE_LTO "Enable link-time optimization" OFF)
endif()

option(ENABLE_OGLRENDERER "Enable OpenGL renderer" ON)

if (ENABLE_OGLRENDERER)
add_definitions(-DOGLRENDERER_ENABLED)
endif()

if (CMAKE_BUILD_TYPE STREQUAL Debug)
add_compile_options(-Og)
endif()
Expand Down
31 changes: 22 additions & 9 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,12 @@ add_library(core STATIC
FIFO.h
GBACart.cpp
GPU.cpp
GPU_OpenGL.cpp
GPU_OpenGL_shaders.h
GPU2D.cpp
GPU3D.cpp
GPU3D_OpenGL.cpp
GPU3D_OpenGL_shaders.h
GPU3D_Soft.cpp
melonDLDI.h
NDS.cpp
NDSCart.cpp
OpenGLSupport.cpp
Platform.h
ROMList.h
RTC.cpp
Expand All @@ -52,6 +47,16 @@ add_library(core STATIC
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)
enable_language(ASM)

Expand Down Expand Up @@ -95,8 +100,16 @@ if (ENABLE_JIT)
endif()
endif()

if (WIN32)
target_link_libraries(core ole32 comctl32 ws2_32 opengl32)
if (ENABLE_OGLRENDERER)
if (WIN32)
target_link_libraries(core ole32 comctl32 ws2_32 opengl32)
else()
target_link_libraries(core GL EGL)
endif()
else()
target_link_libraries(core GL EGL)
endif()
if (WIN32)
target_link_libraries(core ole32 comctl32 ws2_32)
else()
target_link_libraries(core)
endif()
endif()
13 changes: 11 additions & 2 deletions src/GPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ void AssignFramebuffers()

void InitRenderer(int renderer)
{
#ifdef OGLRENDERER_ENABLED
if (renderer == 1)
{
if (!GLCompositor::Init())
Expand All @@ -292,8 +293,8 @@ void InitRenderer(int renderer)
renderer = 0;
}
}

if (renderer == 0)
else
#endif
{
GPU3D::SoftRenderer::Init();
}
Expand All @@ -308,11 +309,13 @@ void DeInitRenderer()
{
GPU3D::SoftRenderer::DeInit();
}
#ifdef OGLRENDERER_ENABLED
else
{
GPU3D::GLRenderer::DeInit();
GLCompositor::DeInit();
}
#endif
}

void ResetRenderer()
Expand All @@ -321,11 +324,13 @@ void ResetRenderer()
{
GPU3D::SoftRenderer::Reset();
}
#ifdef OGLRENDERER_ENABLED
else
{
GLCompositor::Reset();
GPU3D::GLRenderer::Reset();
}
#endif
}

void SetRenderSettings(int renderer, RenderSettings& settings)
Expand Down Expand Up @@ -364,11 +369,13 @@ void SetRenderSettings(int renderer, RenderSettings& settings)
{
GPU3D::SoftRenderer::SetRenderSettings(settings);
}
#ifdef OGLRENDERER_ENABLED
else
{
GLCompositor::SetRenderSettings(settings);
GPU3D::GLRenderer::SetRenderSettings(settings);
}
#endif
}


Expand Down Expand Up @@ -1055,7 +1062,9 @@ void StartScanline(u32 line)
GPU2D_B->VBlank();
GPU3D::VBlank();

#ifdef OGLRENDERER_ENABLED
if (Accelerated) GLCompositor::RenderFrame();
#endif
}
else if (VCount == 144)
{
Expand Down
2 changes: 2 additions & 0 deletions src/GPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ void SetDispStat(u32 cpu, u16 val);

void SetVCount(u16 val);

#ifdef OGLRENDERER_ENABLED
namespace GLCompositor
{

Expand All @@ -450,6 +451,7 @@ void RenderFrame();
void BindOutputTexture();

}
#endif

}

Expand Down
2 changes: 2 additions & 0 deletions src/GPU2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -949,13 +949,15 @@ void GPU2D::VBlankEnd()
//OBJMosaicY = 0;
//OBJMosaicYCount = 0;

#ifdef OGLRENDERER_ENABLED
if (Accelerated)
{
if ((Num == 0) && (CaptureCnt & (1<<31)) && (((CaptureCnt >> 29) & 0x3) != 1))
{
GPU3D::GLRenderer::PrepareCaptureFrame();
}
}
#endif
}


Expand Down
6 changes: 6 additions & 0 deletions src/GPU3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2528,13 +2528,19 @@ void VBlank()
void VCount215()
{
if (GPU::Renderer == 0) SoftRenderer::RenderFrame();
#ifdef OGLRENDERER_ENABLED
else GLRenderer::RenderFrame();
#endif
}

u32* GetLine(int line)
{
if (GPU::Renderer == 0) return SoftRenderer::GetLine(line);
#ifdef OGLRENDERER_ENABLED
else return GLRenderer::GetLine(line);
#else
return NULL;
#endif
}


Expand Down
2 changes: 2 additions & 0 deletions src/GPU3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ u32* GetLine(int line);

}

#ifdef OGLRENDERER_ENABLED
namespace GLRenderer
{

Expand All @@ -154,6 +155,7 @@ u32* GetLine(int line);
void SetupAccelFrame();

}
#endif

}

Expand Down
4 changes: 4 additions & 0 deletions src/frontend/qt_sdl/VideoSettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ VideoSettingsDialog::VideoSettingsDialog(QWidget* parent) : QDialog(parent), ui(
connect(grp3DRenderer, SIGNAL(buttonClicked(int)), this, SLOT(onChange3DRenderer(int)));
grp3DRenderer->button(Config::_3DRenderer)->setChecked(true);

#ifndef OGLRENDERER_ENABLED
ui->rb3DOpenGL->setEnabled(false);
#endif

ui->cbGLDisplay->setChecked(Config::ScreenUseGL != 0);

ui->cbVSync->setChecked(Config::ScreenVSync != 0);
Expand Down
12 changes: 12 additions & 0 deletions src/frontend/qt_sdl/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@

#include "NDS.h"
#include "GBACart.h"
#ifdef OGLRENDERER_ENABLED
#include "OpenGLSupport.h"
#endif
#include "GPU.h"
#include "SPU.h"
#include "Wifi.h"
Expand Down Expand Up @@ -336,13 +338,17 @@ void EmuThread::run()
videoSettings.Soft_Threaded = Config::Threaded3D != 0;
videoSettings.GL_ScaleFactor = Config::GL_ScaleFactor;

#ifdef OGLRENDERER_ENABLED
if (hasOGL)
{
oglContext->makeCurrent(oglSurface);
videoRenderer = OpenGL::Init() ? Config::_3DRenderer : 0;
}
else
#endif
{
videoRenderer = 0;
}

GPU::InitRenderer(videoRenderer);
GPU::SetRenderSettings(videoRenderer, videoSettings);
Expand Down Expand Up @@ -396,13 +402,17 @@ void EmuThread::run()
if (hasOGL != mainWindow->hasOGL)
{
hasOGL = mainWindow->hasOGL;
#ifdef OGLRENDERER_ENABLED
if (hasOGL)
{
oglContext->makeCurrent(oglSurface);
videoRenderer = OpenGL::Init() ? Config::_3DRenderer : 0;
}
else
#endif
{
videoRenderer = 0;
}
}
else
videoRenderer = hasOGL ? Config::_3DRenderer : 0;
Expand Down Expand Up @@ -923,12 +933,14 @@ void ScreenPanelGL::paintGL()
int frontbuf = GPU::FrontBuffer;
glActiveTexture(GL_TEXTURE0);

#ifdef OGLRENDERER_ENABLED
if (GPU::Renderer != 0)
{
// hardware-accelerated render
GPU::GLCompositor::BindOutputTexture();
}
else
#endif
{
// regular render
glBindTexture(GL_TEXTURE_2D, screenTexture);
Expand Down

0 comments on commit 6977302

Please sign in to comment.