Skip to content

Commit

Permalink
* rework GPU's settings interface, make it config-agnostic
Browse files Browse the repository at this point in the history
* make video settings dialog functional, sorta
* fix dialogs that were resizable
  • Loading branch information
Arisotura committed May 28, 2020
1 parent 5005a7c commit 0804ab3
Show file tree
Hide file tree
Showing 15 changed files with 342 additions and 167 deletions.
78 changes: 73 additions & 5 deletions src/GPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ u8* VRAMPtr_BOBJ[0x8];

int FrontBuffer;
u32* Framebuffer[2][2];
int Renderer;
bool Accelerated;

GPU2D* GPU2D_A;
Expand All @@ -93,8 +94,8 @@ bool Init()
FrontBuffer = 0;
Framebuffer[0][0] = NULL; Framebuffer[0][1] = NULL;
Framebuffer[1][0] = NULL; Framebuffer[1][1] = NULL;
Renderer = 0;
Accelerated = false;
SetDisplaySettings(false);

return true;
}
Expand Down Expand Up @@ -182,6 +183,8 @@ void Reset()
int backbuf = FrontBuffer ? 0 : 1;
GPU2D_A->SetFramebuffer(Framebuffer[backbuf][1]);
GPU2D_B->SetFramebuffer(Framebuffer[backbuf][0]);

ResetRenderer();
}

void Stop()
Expand Down Expand Up @@ -274,8 +277,65 @@ void AssignFramebuffers()
}
}

void SetDisplaySettings(bool accel)
void InitRenderer(int renderer)
{
if (renderer == 1)
{
if (!GLCompositor::Init())
{
renderer = 0;
}
else if (!GPU3D::GLRenderer::Init())
{
GLCompositor::DeInit();
renderer = 0;
}
}

if (renderer == 0)
{
GPU3D::SoftRenderer::Init();
}

Renderer = renderer;
Accelerated = renderer != 0;
}

void DeInitRenderer()
{
if (Renderer == 0)
{
GPU3D::SoftRenderer::DeInit();
}
else
{
GPU3D::GLRenderer::DeInit();
GLCompositor::DeInit();
}
}

void ResetRenderer()
{
if (Renderer == 0)
{
GPU3D::SoftRenderer::Reset();
}
else
{
GLCompositor::Reset();
GPU3D::GLRenderer::Reset();
}
}

void SetRenderSettings(int renderer, RenderSettings& settings)
{
if (renderer != Renderer)
{
DeInitRenderer();
InitRenderer(renderer);
}

bool accel = Accelerated;
int fbsize;
if (accel) fbsize = (256*3 + 1) * 192;
else fbsize = 256 * 192;
Expand All @@ -296,10 +356,18 @@ void SetDisplaySettings(bool accel)

AssignFramebuffers();

GPU2D_A->SetDisplaySettings(accel);
GPU2D_B->SetDisplaySettings(accel);
GPU2D_A->SetRenderSettings(accel);
GPU2D_B->SetRenderSettings(accel);

Accelerated = accel;
if (Renderer == 0)
{
GPU3D::SoftRenderer::SetRenderSettings(settings);
}
else
{
GLCompositor::SetRenderSettings(settings);
GPU3D::GLRenderer::SetRenderSettings(settings);
}
}


Expand Down
22 changes: 19 additions & 3 deletions src/GPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#define GPU_H

#include "GPU2D.h"
#include "GPU3D.h"

namespace GPU
{
Expand Down Expand Up @@ -72,6 +71,17 @@ extern u32* Framebuffer[2][2];
extern GPU2D* GPU2D_A;
extern GPU2D* GPU2D_B;

extern int Renderer;


typedef struct
{
bool Soft_Threaded;

int GL_ScaleFactor;

} RenderSettings;


bool Init();
void DeInit();
Expand All @@ -80,7 +90,11 @@ void Stop();

void DoSavestate(Savestate* file);

void SetDisplaySettings(bool accel);
void InitRenderer(int renderer);
void DeInitRenderer();
void ResetRenderer();

void SetRenderSettings(int renderer, RenderSettings& settings);


u8* GetUniqueBankPtr(u32 mask, u32 offset);
Expand Down Expand Up @@ -429,7 +443,7 @@ bool Init();
void DeInit();
void Reset();

void UpdateDisplaySettings();
void SetRenderSettings(RenderSettings& settings);

void RenderFrame();
void BindOutputTexture();
Expand All @@ -438,4 +452,6 @@ void BindOutputTexture();

}

#include "GPU3D.h"

#endif
14 changes: 3 additions & 11 deletions src/GPU2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,8 @@ void GPU2D::DoSavestate(Savestate* file)
file->Var32(&CaptureCnt);
}

if (file->IsAtleastVersion(2, 1))
{
file->Var32(&Win0Active);
file->Var32(&Win1Active);
}
else
{
Win0Active = 0;
Win1Active = 0;
}
file->Var32(&Win0Active);
file->Var32(&Win1Active);

if (!file->Saving)
{
Expand All @@ -232,7 +224,7 @@ void GPU2D::SetFramebuffer(u32* buf)
Framebuffer = buf;
}

void GPU2D::SetDisplaySettings(bool accel)
void GPU2D::SetRenderSettings(bool accel)
{
Accelerated = accel;

Expand Down
2 changes: 1 addition & 1 deletion src/GPU2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class GPU2D

void SetEnabled(bool enable) { Enabled = enable; }
void SetFramebuffer(u32* buf);
void SetDisplaySettings(bool accel);
void SetRenderSettings(bool accel);

u8 Read8(u32 addr);
u16 Read16(u32 addr);
Expand Down
57 changes: 5 additions & 52 deletions src/GPU3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ u32 NumCommands, CurCommand, ParamCount, TotalParams;
bool GeometryEnabled;
bool RenderingEnabled;

int Renderer;

u32 DispCnt;
u8 AlphaRefVal, AlphaRef;

Expand Down Expand Up @@ -280,17 +278,11 @@ bool Init()

CmdStallQueue = new FIFO<CmdFIFOEntry>(64);

Renderer = -1;
// SetRenderer() will be called to set it up later

return true;
}

void DeInit()
{
if (Renderer == 0) SoftRenderer::DeInit();
else GLRenderer::DeInit();

delete CmdFIFO;
delete CmdPIPE;

Expand Down Expand Up @@ -391,8 +383,6 @@ void Reset()
FlushAttributes = 0;

ResetRenderingState();
if (Renderer == 0) SoftRenderer::Reset();
else GLRenderer::Reset();
}

void DoSavestate(Savestate* file)
Expand Down Expand Up @@ -607,43 +597,6 @@ void SetEnabled(bool geometry, bool rendering)
}


int InitRenderer(bool hasGL)
{
int renderer = hasGL ? Config::_3DRenderer : 0;

if (renderer == 1)
{
if (!GLRenderer::Init())
renderer = 0;
}
printf("renderer: %d\n", renderer);
if (renderer == 0) SoftRenderer::Init();

Renderer = renderer;
UpdateRendererConfig();
GPU::SetDisplaySettings(Renderer != 0);
return renderer;
}

void DeInitRenderer()
{
if (Renderer == 0) SoftRenderer::DeInit();
else GLRenderer::DeInit();
}

void UpdateRendererConfig()
{
if (Renderer == 0)
{
SoftRenderer::SetupRenderThread();
}
else
{
GLRenderer::UpdateDisplaySettings();
}
}



void MatrixLoadIdentity(s32* m)
{
Expand Down Expand Up @@ -2470,7 +2423,7 @@ void CheckFIFODMA()

void VCount144()
{
if (Renderer == 0) SoftRenderer::VCount144();
if (GPU::Renderer == 0) SoftRenderer::VCount144();
}


Expand Down Expand Up @@ -2552,14 +2505,14 @@ void VBlank()

void VCount215()
{
if (Renderer == 0) SoftRenderer::RenderFrame();
else GLRenderer::RenderFrame();
if (GPU::Renderer == 0) SoftRenderer::RenderFrame();
else GLRenderer::RenderFrame();
}

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


Expand Down
7 changes: 2 additions & 5 deletions src/GPU3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@ void DoSavestate(Savestate* file);

void SetEnabled(bool geometry, bool rendering);

int InitRenderer(bool hasGL);
void DeInitRenderer();
void UpdateRendererConfig();

void ExecuteCommand();

s32 CyclesToRunFor();
Expand Down Expand Up @@ -134,6 +130,7 @@ bool Init();
void DeInit();
void Reset();

void SetRenderSettings(GPU::RenderSettings& settings);
void SetupRenderThread();

void VCount144();
Expand All @@ -149,7 +146,7 @@ bool Init();
void DeInit();
void Reset();

void UpdateDisplaySettings();
void SetRenderSettings(GPU::RenderSettings& settings);

void RenderFrame();
void PrepareCaptureFrame();
Expand Down
17 changes: 3 additions & 14 deletions src/GPU3D_OpenGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,19 +372,11 @@ bool Init()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB5_A1, 1024, 48, 0, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, NULL);

if (!GPU::GLCompositor::Init())
{
// TODO: clean up things? fail more gracefully??
return false;
}

return true;
}

void DeInit()
{
GPU::GLCompositor::DeInit();

glDeleteTextures(1, &TexMemID);
glDeleteTextures(1, &TexPalMemID);

Expand All @@ -407,13 +399,12 @@ void DeInit()

void Reset()
{
GPU::GLCompositor::Reset();
}

void UpdateDisplaySettings()
void SetRenderSettings(GPU::RenderSettings& settings)
{
int scale = Config::GL_ScaleFactor;
bool antialias = false; //Config::GL_Antialias;
int scale = settings.GL_ScaleFactor;
bool antialias = false; // REMOVE ME!

if (antialias) scale *= 2;

Expand Down Expand Up @@ -490,8 +481,6 @@ void UpdateDisplaySettings()

//glLineWidth(scale);
//glLineWidth(1.5);

GPU::GLCompositor::UpdateDisplaySettings();
}


Expand Down
Loading

0 comments on commit 0804ab3

Please sign in to comment.