progress
This commit is contained in:
Arisotura 2019-05-21 22:28:46 +02:00
parent c835b24f07
commit db396e992b
14 changed files with 412 additions and 364 deletions

View File

@ -31,6 +31,7 @@ const char* kConfigFile = "melonDS.ini";
int _3DRenderer; int _3DRenderer;
int Threaded3D; int Threaded3D;
int GL_ScaleFactor;
int GL_Antialias; int GL_Antialias;
ConfigEntry ConfigFile[] = ConfigEntry ConfigFile[] =
@ -38,6 +39,7 @@ ConfigEntry ConfigFile[] =
{"3DRenderer", 0, &_3DRenderer, 1, NULL, 0}, {"3DRenderer", 0, &_3DRenderer, 1, NULL, 0},
{"Threaded3D", 0, &Threaded3D, 1, NULL, 0}, {"Threaded3D", 0, &Threaded3D, 1, NULL, 0},
{"GL_ScaleFactor", 0, &GL_ScaleFactor, 1, NULL, 0},
{"GL_Antialias", 0, &GL_Antialias, 0, NULL, 0}, {"GL_Antialias", 0, &GL_Antialias, 0, NULL, 0},
{"", -1, NULL, 0, NULL, 0} {"", -1, NULL, 0, NULL, 0}

View File

@ -43,6 +43,7 @@ void Save();
extern int _3DRenderer; extern int _3DRenderer;
extern int Threaded3D; extern int Threaded3D;
extern int GL_ScaleFactor;
extern int GL_Antialias; extern int GL_Antialias;
} }

View File

@ -73,7 +73,6 @@ u32 VRAMMap_ARM7[2];
int FrontBuffer; int FrontBuffer;
u32* Framebuffer[2][2]; u32* Framebuffer[2][2];
int ScreenScale[2];
bool Accelerated; bool Accelerated;
GPU2D* GPU2D_A; GPU2D* GPU2D_A;
@ -89,8 +88,8 @@ bool Init()
FrontBuffer = 0; FrontBuffer = 0;
Framebuffer[0][0] = NULL; Framebuffer[0][1] = NULL; Framebuffer[0][0] = NULL; Framebuffer[0][1] = NULL;
Framebuffer[1][0] = NULL; Framebuffer[1][1] = NULL; Framebuffer[1][0] = NULL; Framebuffer[1][1] = NULL;
ScreenScale[0] = -1; ScreenScale[1] = -1; Accelerated = false; Accelerated = false;
SetDisplaySettings(0, 0, false); SetDisplaySettings(false);
return true; return true;
} }
@ -247,12 +246,10 @@ void AssignFramebuffers()
} }
} }
void SetDisplaySettings(int topscale, int bottomscale, bool accel) void SetDisplaySettings(bool accel)
{accel=true; {
if (accel != Accelerated) if (accel != Accelerated)
{ {
ScreenScale[0] = accel ? 0 : topscale;
int fbsize; int fbsize;
if (accel) fbsize = (256*3 + 2) * 192; if (accel) fbsize = (256*3 + 2) * 192;
else fbsize = 256 * 192; else fbsize = 256 * 192;
@ -273,35 +270,8 @@ void SetDisplaySettings(int topscale, int bottomscale, bool accel)
AssignFramebuffers(); AssignFramebuffers();
} }
if (topscale != ScreenScale[0]) GPU2D_A->SetDisplaySettings(accel);
{ GPU2D_B->SetDisplaySettings(accel);
ScreenScale[0] = topscale;
if (NDS::PowerControl9 & (1<<15))
{
GPU2D_A->SetDisplaySettings(ScreenScale[0], accel);
GPU3D::SetDisplaySettings(ScreenScale[0], accel);
}
else
{
GPU2D_B->SetDisplaySettings(ScreenScale[0], accel);
}
}
if (bottomscale != ScreenScale[1] || accel != Accelerated)
{
ScreenScale[1] = bottomscale;
if (NDS::PowerControl9 & (1<<15))
{
GPU2D_B->SetDisplaySettings(ScreenScale[1], accel);
}
else
{
GPU2D_A->SetDisplaySettings(ScreenScale[1], accel);
GPU3D::SetDisplaySettings(ScreenScale[1], accel);
}
}
Accelerated = accel; Accelerated = accel;
} }

View File

@ -75,7 +75,7 @@ void Stop();
void DoSavestate(Savestate* file); void DoSavestate(Savestate* file);
void SetDisplaySettings(int topscale, int bottomscale, bool accel); void SetDisplaySettings(bool accel);
void MapVRAM_AB(u32 bank, u8 cnt); void MapVRAM_AB(u32 bank, u8 cnt);

View File

@ -215,7 +215,7 @@ void GPU2D::SetFramebuffer(u32* buf)
Framebuffer = buf; Framebuffer = buf;
} }
void GPU2D::SetDisplaySettings(int scale, bool accel) void GPU2D::SetDisplaySettings(bool accel)
{ {
Accelerated = accel; Accelerated = accel;

View File

@ -31,7 +31,7 @@ public:
void SetEnabled(bool enable) { Enabled = enable; } void SetEnabled(bool enable) { Enabled = enable; }
void SetFramebuffer(u32* buf); void SetFramebuffer(u32* buf);
void SetDisplaySettings(int scale, bool accel); void SetDisplaySettings(bool accel);
u8 Read8(u32 addr); u8 Read8(u32 addr);
u16 Read16(u32 addr); u16 Read16(u32 addr);

View File

@ -156,6 +156,8 @@ u32 NumCommands, CurCommand, ParamCount, TotalParams;
bool GeometryEnabled; bool GeometryEnabled;
bool RenderingEnabled; bool RenderingEnabled;
int Renderer;
u32 DispCnt; u32 DispCnt;
u8 AlphaRefVal, AlphaRef; u8 AlphaRefVal, AlphaRef;
@ -275,16 +277,16 @@ bool Init()
CmdStallQueue = new FIFO<CmdFIFOEntry>(64); CmdStallQueue = new FIFO<CmdFIFOEntry>(64);
//if (!SoftRenderer::Init()) return false; Renderer = -1;
if (!GLRenderer::Init()) return false; // SetRenderer() will be called to set it up later
return true; return true;
} }
void DeInit() void DeInit()
{ {
//SoftRenderer::DeInit(); if (Renderer == 0) SoftRenderer::DeInit();
GLRenderer::DeInit(); else GLRenderer::DeInit();
delete CmdFIFO; delete CmdFIFO;
delete CmdPIPE; delete CmdPIPE;
@ -384,8 +386,8 @@ void Reset()
FlushAttributes = 0; FlushAttributes = 0;
ResetRenderingState(); ResetRenderingState();
//SoftRenderer::Reset(); if (Renderer == 0) SoftRenderer::Reset();
GLRenderer::Reset(); else GLRenderer::Reset();
} }
void DoSavestate(Savestate* file) void DoSavestate(Savestate* file)
@ -607,14 +609,24 @@ void SetEnabled(bool geometry, bool rendering)
if (!rendering) ResetRenderingState(); if (!rendering) ResetRenderingState();
} }
void SetDisplaySettings(int scale, bool accel)
{
GLRenderer::SetDisplaySettings(scale, accel);
}
int GetScale() int SetRenderer(int renderer)
{ {
return GLRenderer::GetScale(); //if (renderer == Renderer) return renderer;
//if (Renderer == 0) SoftRenderer::DeInit();
//else GLRenderer::DeInit();
if (renderer == 1)
{
if (!GLRenderer::Init())
renderer = 0;
}
if (renderer == 0) SoftRenderer::Init();
Renderer = renderer;
return renderer;
} }
@ -2354,7 +2366,7 @@ void CheckFIFODMA()
void VCount144() void VCount144()
{ {
//SoftRenderer::VCount144(); if (Renderer == 0) SoftRenderer::VCount144();
} }
@ -2436,19 +2448,14 @@ void VBlank()
void VCount215() void VCount215()
{ {
//SoftRenderer::RenderFrame(); if (Renderer == 0) SoftRenderer::RenderFrame();
GLRenderer::RenderFrame(); else GLRenderer::RenderFrame();
} }
u32* GetLine(int line) u32* GetLine(int line)
{ {
//return SoftRenderer::GetLine(line); if (Renderer == 0) return SoftRenderer::GetLine(line);
return GLRenderer::GetLine(line); else return GLRenderer::GetLine(line);
}
void SetupAccelFrame()
{
GLRenderer::SetupAccelFrame();
} }

View File

@ -97,8 +97,8 @@ void Reset();
void DoSavestate(Savestate* file); void DoSavestate(Savestate* file);
void SetEnabled(bool geometry, bool rendering); void SetEnabled(bool geometry, bool rendering);
void SetDisplaySettings(int scale, bool accel);
int GetScale(); int SetRenderer(int renderer);
void ExecuteCommand(); void ExecuteCommand();
@ -129,15 +129,11 @@ bool Init();
void DeInit(); void DeInit();
void Reset(); void Reset();
void SetDisplaySettings(int scale, bool accel);
int GetScale();
void SetupRenderThread(); void SetupRenderThread();
void VCount144(); void VCount144();
void RenderFrame(); void RenderFrame();
u32* GetLine(int line); u32* GetLine(int line);
void SetupAccelFrame();
} }
@ -148,8 +144,7 @@ bool Init();
void DeInit(); void DeInit();
void Reset(); void Reset();
void SetDisplaySettings(int scale, bool accel); void SetDisplaySettings(int scale, bool antialias);
int GetScale();
void RenderFrame(); void RenderFrame();
void PrepareCaptureFrame(); void PrepareCaptureFrame();

View File

@ -95,13 +95,13 @@ GLuint TexMemID;
GLuint TexPalMemID; GLuint TexPalMemID;
int ScaleFactor; int ScaleFactor;
bool Accelerated; bool Antialias;
int ScreenW, ScreenH; int ScreenW, ScreenH;
GLuint FramebufferTex[8]; GLuint FramebufferTex[8];
int FrontBuffer; int FrontBuffer;
GLuint FramebufferID[4], PixelbufferID; GLuint FramebufferID[4], PixelbufferID;
u32* Framebuffer = NULL; u32 Framebuffer[256*192];
@ -176,26 +176,6 @@ bool Init()
printf("OpenGL: renderer: %s\n", renderer); printf("OpenGL: renderer: %s\n", renderer);
printf("OpenGL: version: %s\n", version); printf("OpenGL: version: %s\n", version);
int barg1, barg2;
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &barg1);
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &barg2);
printf("max texture: %d\n", barg1);
printf("max comb. texture: %d\n", barg2);
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &barg1);
printf("max tex size: %d\n", barg1);
glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &barg1);
printf("max arraytex levels: %d\n", barg1);
/*glGetIntegerv(GL_NUM_EXTENSIONS, &barg1);
printf("extensions: %d\n", barg1);
for (int i = 0; i < barg1; i++)
{
const GLubyte* ext = glGetStringi(GL_EXTENSIONS, i);
printf("- %s\n", ext);
}*/
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glEnable(GL_STENCIL_TEST); glEnable(GL_STENCIL_TEST);
@ -317,6 +297,12 @@ bool Init()
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[1]); glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[1]);
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, FramebufferTex[1], 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, FramebufferTex[1], 0);
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, FramebufferTex[4], 0);
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, FramebufferTex[5], 0);
glDrawBuffers(2, fbassign);
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[2]);
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, FramebufferTex[2], 0);
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, FramebufferTex[6], 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, FramebufferTex[6], 0);
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, FramebufferTex[7], 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, FramebufferTex[7], 0);
glDrawBuffers(2, fbassign); glDrawBuffers(2, fbassign);
@ -324,8 +310,9 @@ bool Init()
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[0]); glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[0]);
glEnable(GL_BLEND); glEnable(GL_BLEND);
// TODO: these are said to require GL 4.0; use the regular ones instead?
glBlendFuncSeparatei(0, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); glBlendFuncSeparatei(0, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
glBlendEquationSeparatei(0, GL_ADD, GL_MAX); glBlendEquationSeparatei(0, GL_FUNC_ADD, GL_MAX);
glBlendFuncSeparatei(1, GL_ONE, GL_ZERO, GL_ONE, GL_ZERO); glBlendFuncSeparatei(1, GL_ONE, GL_ZERO, GL_ONE, GL_ZERO);
glGenBuffers(1, &PixelbufferID); glGenBuffers(1, &PixelbufferID);
@ -347,7 +334,7 @@ bool Init()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 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); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB5_A1, 1024, 48, 0, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, NULL);
printf("init done. %04X\n", glGetError());
return true; return true;
} }
@ -375,44 +362,55 @@ void DeInit()
void Reset() void Reset()
{ {
//
} }
void SetDisplaySettings(int scale, bool accel) void SetDisplaySettings(int scale, bool antialias)
{ {
if (antialias) scale *= 2;
ScaleFactor = scale; ScaleFactor = scale;
Accelerated = accel; Antialias = antialias;
// TODO: antialiasing setting ScreenW = 256 * scale;
ScreenW = 256 << scale; ScreenH = 192 * scale;
ScreenH = 192 << scale;
glBindTexture(GL_TEXTURE_2D, FramebufferTex[0]); if (!antialias)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ScreenW, ScreenH, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); {
glBindTexture(GL_TEXTURE_2D, FramebufferTex[1]); glBindTexture(GL_TEXTURE_2D, FramebufferTex[0]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ScreenW, ScreenH, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ScreenW, ScreenH, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D, FramebufferTex[2]); glBindTexture(GL_TEXTURE_2D, FramebufferTex[1]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ScreenW/2, ScreenH/2, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ScreenW, ScreenH, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D, FramebufferTex[4]); glBindTexture(GL_TEXTURE_2D, FramebufferTex[2]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, ScreenW, ScreenH, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D, FramebufferTex[5]); glBindTexture(GL_TEXTURE_2D, FramebufferTex[4]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, ScreenW, ScreenH, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, NULL); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, ScreenW, ScreenH, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
glBindTexture(GL_TEXTURE_2D, FramebufferTex[6]); glBindTexture(GL_TEXTURE_2D, FramebufferTex[5]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, ScreenW, ScreenH, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, ScreenW, ScreenH, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D, FramebufferTex[7]); glBindTexture(GL_TEXTURE_2D, FramebufferTex[6]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, ScreenW, ScreenH, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, NULL); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, 1, 1, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
glBindTexture(GL_TEXTURE_2D, FramebufferTex[7]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, NULL);
}
else
{
glBindTexture(GL_TEXTURE_2D, FramebufferTex[0]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ScreenW/2, ScreenH/2, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D, FramebufferTex[1]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ScreenW/2, ScreenH/2, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D, FramebufferTex[2]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ScreenW, ScreenH, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D, FramebufferTex[4]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, ScreenW/2, ScreenH/2, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
glBindTexture(GL_TEXTURE_2D, FramebufferTex[5]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, ScreenW/2, ScreenH/2, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D, FramebufferTex[6]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, ScreenW, ScreenH, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
glBindTexture(GL_TEXTURE_2D, FramebufferTex[7]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, ScreenW, ScreenH, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, NULL);
}
glBindBuffer(GL_PIXEL_PACK_BUFFER, PixelbufferID); glBindBuffer(GL_PIXEL_PACK_BUFFER, PixelbufferID);
glBufferData(GL_PIXEL_PACK_BUFFER, 256*192*4, NULL, GL_DYNAMIC_READ); glBufferData(GL_PIXEL_PACK_BUFFER, 256*192*4, NULL, GL_DYNAMIC_READ);
if (Framebuffer) delete[] Framebuffer;
if (accel) Framebuffer = new u32[256*192];
else Framebuffer = new u32[ScreenW*ScreenH];
}
int GetScale()
{
return ScaleFactor;
} }
@ -496,10 +494,10 @@ void BuildPolygons(RendererPolygon* polygons, int npolys)
while (z > 0xFFFF) { z >>= 1; zshift++; } while (z > 0xFFFF) { z >>= 1; zshift++; }
u32 x, y; u32 x, y;
if (ScaleFactor > 0) if (ScaleFactor > 1)
{ {
x = vtx->HiresPosition[0] >> (4-ScaleFactor); x = (vtx->HiresPosition[0] * ScaleFactor) >> 4;
y = vtx->HiresPosition[1] >> (4-ScaleFactor); y = (vtx->HiresPosition[1] * ScaleFactor) >> 4;
} }
else else
{ {
@ -829,8 +827,8 @@ void RenderFrame()
glViewport(0, 0, ScreenW, ScreenH); glViewport(0, 0, ScreenW, ScreenH);
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[FrontBuffer]); if (Antialias) glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[2]);
FrontBuffer = FrontBuffer ? 0 : 1; else glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[FrontBuffer]);
glDisable(GL_BLEND); glDisable(GL_BLEND);
glColorMaski(0, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glColorMaski(0, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
@ -902,26 +900,15 @@ void RenderFrame()
RenderSceneChunk(0, 192); RenderSceneChunk(0, 192);
} }
if (false) if (Antialias)
{ {
glBindFramebuffer(GL_READ_FRAMEBUFFER, FramebufferID[0]); glBindFramebuffer(GL_READ_FRAMEBUFFER, FramebufferID[2]);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferID[1]); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferID[FrontBuffer]);
glBlitFramebuffer(0, 0, ScreenW, ScreenH, 0, 0, ScreenW/2, ScreenH/2, GL_COLOR_BUFFER_BIT, GL_LINEAR); glBlitFramebuffer(0, 0, ScreenW, ScreenH, 0, 0, ScreenW/2, ScreenH/2, GL_COLOR_BUFFER_BIT, GL_LINEAR);
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[1]);
}
else
{
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[0]);
} }
/*if (!Accelerated) glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[FrontBuffer]);
{ FrontBuffer = FrontBuffer ? 0 : 1;
glReadBuffer(GL_COLOR_ATTACHMENT0);
glBindBuffer(GL_PIXEL_PACK_BUFFER, PixelbufferID);
glReadPixels(0, 0, 256<<ScaleFactor, 192<<ScaleFactor, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
}*/
} }
void PrepareCaptureFrame() void PrepareCaptureFrame()
@ -937,14 +924,11 @@ void PrepareCaptureFrame()
glBindFramebuffer(GL_READ_FRAMEBUFFER, FramebufferID[3]); glBindFramebuffer(GL_READ_FRAMEBUFFER, FramebufferID[3]);
glReadPixels(0, 0, 256, 192, GL_BGRA, GL_UNSIGNED_BYTE, NULL); glReadPixels(0, 0, 256, 192, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
//glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[original_fb]);
//glFlush();
} }
u32* GetLine(int line) u32* GetLine(int line)
{ {
int stride = 256;// << (ScaleFactor*2); int stride = 256;
if (line == 0) if (line == 0)
{ {

View File

@ -138,16 +138,6 @@ void Reset()
SetupRenderThread(); SetupRenderThread();
} }
void SetDisplaySettings(int scale, bool accel)
{
printf("SOFT RENDERER SCALE FACTOR: TODO!!!\n");
}
int GetScale()
{
return 0;
}
// Notes on the interpolator: // Notes on the interpolator:
@ -2127,10 +2117,5 @@ u32* GetLine(int line)
return &ColorBuffer[(line * ScanlineWidth) + FirstPixelOffset]; return &ColorBuffer[(line * ScanlineWidth) + FirstPixelOffset];
} }
void SetupAccelFrame()
{
// TODO
}
} }
} }

View File

@ -37,7 +37,38 @@ namespace DlgVideoSettings
bool opened; bool opened;
uiWindow* win; uiWindow* win;
// uiRadioButtons* rbRenderer;
uiCheckbox* cbGLDisplay;
uiCheckbox* cbThreaded3D;
uiCombobox* cbResolution;
uiCheckbox* cbAntialias;
int old_renderer;
int old_gldisplay;
int old_threaded3D;
int old_resolution;
int old_antialias;
void UpdateControls()
{
int renderer = uiRadioButtonsSelected(rbRenderer);
if (renderer == 0)
{
uiControlEnable(uiControl(cbGLDisplay));
uiControlEnable(uiControl(cbThreaded3D));
uiControlDisable(uiControl(cbResolution));
uiControlDisable(uiControl(cbAntialias));
}
else
{
uiControlDisable(uiControl(cbGLDisplay));
uiControlDisable(uiControl(cbThreaded3D));
uiControlEnable(uiControl(cbResolution));
uiControlEnable(uiControl(cbAntialias));
}
}
int OnCloseWindow(uiWindow* window, void* blarg) int OnCloseWindow(uiWindow* window, void* blarg)
@ -46,17 +77,68 @@ int OnCloseWindow(uiWindow* window, void* blarg)
return 1; return 1;
} }
void OnResolutionChanged(uiRadioButtons* rb, void* blarg) void OnRendererChanged(uiRadioButtons* rb, void* blarg)
{ {
int id = uiRadioButtonsSelected(rb); int id = uiRadioButtonsSelected(rb);
printf("RENDERER CHANGE: %d\n", id);
Config::ScreenScale = id; Config::_3DRenderer = id;
UpdateControls();
ApplyNewSettings(2); ApplyNewSettings(2);
} }
void OnGLDisplayChanged(uiCheckbox* cb, void* blarg)
{
Config::ScreenUseGL = uiCheckboxChecked(cb);
ApplyNewSettings(2);
}
void OnThreaded3DChanged(uiCheckbox* cb, void* blarg)
{
Config::Threaded3D = uiCheckboxChecked(cb);
ApplyNewSettings(0);
}
void OnResolutionChanged(uiCombobox* cb, void* blarg)
{
int id = uiComboboxSelected(cb);
Config::GL_ScaleFactor = id+1;
ApplyNewSettings(3);
}
void OnAntialiasChanged(uiCheckbox* cb, void* blarg)
{
Config::GL_Antialias = uiCheckboxChecked(cb);
ApplyNewSettings(3);
}
void OnCancel(uiButton* btn, void* blarg) void OnCancel(uiButton* btn, void* blarg)
{ {
// restore old settings here if (old_renderer != Config::_3DRenderer)
{
Config::_3DRenderer = old_renderer;
ApplyNewSettings(2);
}
if (old_gldisplay != Config::ScreenUseGL)
{
Config::ScreenUseGL = old_gldisplay;
ApplyNewSettings(2);
}
if (old_threaded3D != Config::Threaded3D)
{
Config::Threaded3D = old_threaded3D;
ApplyNewSettings(0);
}
if (old_resolution != Config::GL_ScaleFactor ||
old_antialias != Config::GL_Antialias)
{
Config::GL_ScaleFactor = old_resolution;
Config::GL_Antialias = old_antialias;
ApplyNewSettings(3);
}
uiControlDestroy(uiControl(win)); uiControlDestroy(uiControl(win));
opened = false; opened = false;
@ -64,8 +146,6 @@ void OnCancel(uiButton* btn, void* blarg)
void OnOk(uiButton* btn, void* blarg) void OnOk(uiButton* btn, void* blarg)
{ {
// set config entries here
Config::Save(); Config::Save();
uiControlDestroy(uiControl(win)); uiControlDestroy(uiControl(win));
@ -101,76 +181,70 @@ void Open()
uiBoxSetPadded(right, 1); uiBoxSetPadded(right, 1);
{ {
uiGroup* grp = uiNewGroup("3D renderer"); uiGroup* grp = uiNewGroup("Display settings");
uiBoxAppend(left, uiControl(grp), 0); uiBoxAppend(left, uiControl(grp), 0);
uiGroupSetMargined(grp, 1); uiGroupSetMargined(grp, 1);
uiBox* in_ctrl = uiNewVerticalBox(); uiBox* in_ctrl = uiNewVerticalBox();
uiGroupSetChild(grp, uiControl(in_ctrl)); uiGroupSetChild(grp, uiControl(in_ctrl));
uiRadioButtons* rbRenderer = uiNewRadioButtons(); uiLabel* lbl = uiNewLabel("3D renderer:");
uiBoxAppend(in_ctrl, uiControl(lbl), 0);
rbRenderer = uiNewRadioButtons();
uiRadioButtonsAppend(rbRenderer, "Software"); uiRadioButtonsAppend(rbRenderer, "Software");
uiRadioButtonsAppend(rbRenderer, "OpenGL"); uiRadioButtonsAppend(rbRenderer, "OpenGL");
uiRadioButtonsOnSelected(rbRenderer, OnRendererChanged, NULL);
uiBoxAppend(in_ctrl, uiControl(rbRenderer), 0); uiBoxAppend(in_ctrl, uiControl(rbRenderer), 0);
lbl = uiNewLabel("");
uiBoxAppend(in_ctrl, uiControl(lbl), 0);
cbGLDisplay = uiNewCheckbox("OpenGL display");
uiCheckboxOnToggled(cbGLDisplay, OnGLDisplayChanged, NULL);
uiBoxAppend(in_ctrl, uiControl(cbGLDisplay), 0);
} }
{ {
uiGroup* grp = uiNewGroup("Software renderer"); uiGroup* grp = uiNewGroup("Software renderer");
uiBoxAppend(left, uiControl(grp), 0);
uiGroupSetMargined(grp, 1);
uiBox* in_ctrl = uiNewVerticalBox();
uiGroupSetChild(grp, uiControl(in_ctrl));
uiCheckbox* cbThreaded3D = uiNewCheckbox("Threaded");
uiBoxAppend(in_ctrl, uiControl(cbThreaded3D), 0);
}
{
uiGroup* grp = uiNewGroup("OpenGL renderer");
uiBoxAppend(left, uiControl(grp), 0);
uiGroupSetMargined(grp, 1);
uiBox* in_ctrl = uiNewVerticalBox();
uiGroupSetChild(grp, uiControl(in_ctrl));
uiCheckbox* cbAntialias = uiNewCheckbox("Antialiasing");
uiBoxAppend(in_ctrl, uiControl(cbAntialias), 0);
}
{
uiGroup* grp = uiNewGroup("Display settings");
uiBoxAppend(right, uiControl(grp), 0); uiBoxAppend(right, uiControl(grp), 0);
uiGroupSetMargined(grp, 1); uiGroupSetMargined(grp, 1);
uiBox* in_ctrl = uiNewVerticalBox(); uiBox* in_ctrl = uiNewVerticalBox();
uiGroupSetChild(grp, uiControl(in_ctrl)); uiGroupSetChild(grp, uiControl(in_ctrl));
uiLabel* lbl = uiNewLabel("Resolution:"); cbThreaded3D = uiNewCheckbox("Threaded");
uiCheckboxOnToggled(cbThreaded3D, OnThreaded3DChanged, NULL);
uiBoxAppend(in_ctrl, uiControl(cbThreaded3D), 0);
}
{
uiGroup* grp = uiNewGroup("OpenGL renderer");
uiBoxAppend(right, uiControl(grp), 0);
uiGroupSetMargined(grp, 1);
uiBox* in_ctrl = uiNewVerticalBox();
uiGroupSetChild(grp, uiControl(in_ctrl));
uiLabel* lbl = uiNewLabel("Internal resolution:");
uiBoxAppend(in_ctrl, uiControl(lbl), 0); uiBoxAppend(in_ctrl, uiControl(lbl), 0);
uiRadioButtons* rbResolution = uiNewRadioButtons(); cbResolution = uiNewCombobox();
uiRadioButtonsOnSelected(rbResolution, OnResolutionChanged, NULL); uiComboboxOnSelected(cbResolution, OnResolutionChanged, NULL);
uiRadioButtonsAppend(rbResolution, "1x"); for (int i = 1; i <= 8; i++)
uiRadioButtonsAppend(rbResolution, "2x"); {
uiRadioButtonsAppend(rbResolution, "4x"); char txt[64];
uiBoxAppend(in_ctrl, uiControl(rbResolution), 0); sprintf(txt, "%dx native (%dx%d)", i, 256*i, 192*i);
uiComboboxAppend(cbResolution, txt);
uiCheckbox* cbWidescreen = uiNewCheckbox("Stretch to 16:9"); }
uiBoxAppend(in_ctrl, uiControl(cbWidescreen), 0); uiBoxAppend(in_ctrl, uiControl(cbResolution), 0);
lbl = uiNewLabel(""); lbl = uiNewLabel("");
uiBoxAppend(in_ctrl, uiControl(lbl), 0); uiBoxAppend(in_ctrl, uiControl(lbl), 0);
lbl = uiNewLabel("Apply upscaling to:"); cbAntialias = uiNewCheckbox("Antialiasing");
uiBoxAppend(in_ctrl, uiControl(lbl), 0); uiCheckboxOnToggled(cbAntialias, OnAntialiasChanged, NULL);
uiBoxAppend(in_ctrl, uiControl(cbAntialias), 0);
uiRadioButtons* rbApplyScalingTo = uiNewRadioButtons();
uiRadioButtonsAppend(rbApplyScalingTo, "Both screens");
uiRadioButtonsAppend(rbApplyScalingTo, "Emphasized screen (see 'Screen sizing')");
//uiRadioButtonsAppend(rbApplyScalingTo, "Top screen");
//uiRadioButtonsAppend(rbApplyScalingTo, "Bottom screen");
uiBoxAppend(in_ctrl, uiControl(rbApplyScalingTo), 0);
} }
{ {
@ -190,7 +264,23 @@ void Open()
uiBoxAppend(in_ctrl, uiControl(btnok), 0); uiBoxAppend(in_ctrl, uiControl(btnok), 0);
} }
// Config::_3DRenderer = Config::_3DRenderer ? 1 : 0;
if (Config::GL_ScaleFactor < 1) Config::GL_ScaleFactor = 1;
else if (Config::GL_ScaleFactor > 8) Config::GL_ScaleFactor = 8;
old_renderer = Config::_3DRenderer;
old_gldisplay = Config::ScreenUseGL;
old_threaded3D = Config::Threaded3D;
old_resolution = Config::GL_ScaleFactor;
old_antialias = Config::GL_Antialias;
uiCheckboxSetChecked(cbGLDisplay, Config::ScreenUseGL);
uiCheckboxSetChecked(cbThreaded3D, Config::Threaded3D);
uiComboboxSetSelected(cbResolution, Config::GL_ScaleFactor-1);
uiCheckboxSetChecked(cbAntialias, Config::GL_Antialias);
uiRadioButtonsSetSelected(rbRenderer, Config::_3DRenderer);
UpdateControls();
uiControlShow(uiControl(win)); uiControlShow(uiControl(win));
} }

View File

@ -40,9 +40,8 @@ int ScreenLayout;
int ScreenSizing; int ScreenSizing;
int ScreenFilter; int ScreenFilter;
int ScreenScale; int ScreenUseGL;
int ScreenRatio; int ScreenRatio;
int ScreenScaleMode;
int LimitFPS; int LimitFPS;
@ -105,9 +104,8 @@ ConfigEntry PlatformConfigFile[] =
{"ScreenSizing", 0, &ScreenSizing, 0, NULL, 0}, {"ScreenSizing", 0, &ScreenSizing, 0, NULL, 0},
{"ScreenFilter", 0, &ScreenFilter, 1, NULL, 0}, {"ScreenFilter", 0, &ScreenFilter, 1, NULL, 0},
{"ScreenScale", 0, &ScreenScale, 0, NULL, 0}, {"ScreenUseGL", 0, &ScreenUseGL, 1, NULL, 0},
{"ScreenRatio", 0, &ScreenRatio, 0, NULL, 0}, {"ScreenRatio", 0, &ScreenRatio, 0, NULL, 0},
{"ScreenScaleMode", 0, &ScreenScaleMode, 0, NULL, 0},
{"LimitFPS", 0, &LimitFPS, 1, NULL, 0}, {"LimitFPS", 0, &LimitFPS, 1, NULL, 0},

View File

@ -48,9 +48,8 @@ extern int ScreenLayout;
extern int ScreenSizing; extern int ScreenSizing;
extern int ScreenFilter; extern int ScreenFilter;
extern int ScreenScale; extern int ScreenUseGL;
extern int ScreenRatio; extern int ScreenRatio;
extern int ScreenScaleMode;
extern int LimitFPS; extern int LimitFPS;

View File

@ -100,6 +100,9 @@ char PrevSRAMPath[1024]; // for savestate 'undo load'
bool SavestateLoaded; bool SavestateLoaded;
bool Screen_UseGL;
int _3DRenderer;
bool ScreenDrawInited = false; bool ScreenDrawInited = false;
uiDrawBitmap* ScreenBitmap[2] = {NULL,NULL}; uiDrawBitmap* ScreenBitmap[2] = {NULL,NULL};
@ -117,8 +120,7 @@ float GL_ScreenVertices[2 * 3*2 * 4]; // position/texcoord
GLuint GL_ScreenTexture; GLuint GL_ScreenTexture;
bool GL_ScreenSizeDirty; bool GL_ScreenSizeDirty;
int ScreenScale[3]; int GL_3DScale;
int ScreenScaleMode;
int ScreenGap = 0; int ScreenGap = 0;
int ScreenLayout = 0; int ScreenLayout = 0;
@ -161,14 +163,14 @@ void GetSavestateName(int slot, char* filename, int len);
bool GLDrawing_Init() bool GLScreen_Init()
{ {
if (!OpenGL_Init()) if (!OpenGL_Init())
return false; return false;
if (!OpenGL_BuildShaderProgram(kScreenVS, kScreenFS, GL_ScreenShader, "ScreenShader")) if (!OpenGL_BuildShaderProgram(kScreenVS, kScreenFS, GL_ScreenShader, "ScreenShader"))
return false; return false;
printf("GL init looking good\n");
GLuint uni_id; GLuint uni_id;
memset(&GL_ShaderConfig, 0, sizeof(GL_ShaderConfig)); memset(&GL_ShaderConfig, 0, sizeof(GL_ShaderConfig));
@ -211,11 +213,11 @@ printf("GL init looking good\n");
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8UI, 1024, 1536, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, NULL); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8UI, 1024, 1536, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, NULL);
GL_ScreenSizeDirty = true; GL_ScreenSizeDirty = true;
printf("finished w/ err: %04X\n", glGetError());
return true; return true;
} }
void GLDrawing_DeInit() void GLScreen_DeInit()
{ {
glDeleteTextures(1, &GL_ScreenTexture); glDeleteTextures(1, &GL_ScreenTexture);
@ -225,7 +227,7 @@ void GLDrawing_DeInit()
OpenGL_DeleteShaderProgram(GL_ScreenShader); OpenGL_DeleteShaderProgram(GL_ScreenShader);
} }
void GLDrawing_DrawScreen() void GLScreen_DrawScreen()
{ {
if (GL_ScreenSizeDirty) if (GL_ScreenSizeDirty)
{ {
@ -233,8 +235,8 @@ void GLDrawing_DrawScreen()
GL_ShaderConfig.uScreenSize[0] = WindowWidth; GL_ShaderConfig.uScreenSize[0] = WindowWidth;
GL_ShaderConfig.uScreenSize[1] = WindowHeight; GL_ShaderConfig.uScreenSize[1] = WindowHeight;
GL_ShaderConfig.u3DScale = 1 << GPU3D::GetScale(); GL_ShaderConfig.u3DScale = GL_3DScale;
printf("updating GL scale: %d\n", GL_3DScale);
glBindBuffer(GL_UNIFORM_BUFFER, GL_ShaderConfigUBO); glBindBuffer(GL_UNIFORM_BUFFER, GL_ShaderConfigUBO);
void* unibuf = glMapBuffer(GL_UNIFORM_BUFFER, GL_WRITE_ONLY); void* unibuf = glMapBuffer(GL_UNIFORM_BUFFER, GL_WRITE_ONLY);
if (unibuf) memcpy(unibuf, &GL_ShaderConfig, sizeof(GL_ShaderConfig)); if (unibuf) memcpy(unibuf, &GL_ShaderConfig, sizeof(GL_ShaderConfig));
@ -257,8 +259,8 @@ void GLDrawing_DrawScreen()
x1 = TopScreenRect.X + TopScreenRect.Width; x1 = TopScreenRect.X + TopScreenRect.Width;
y1 = TopScreenRect.Y + TopScreenRect.Height; y1 = TopScreenRect.Y + TopScreenRect.Height;
scwidth = 256;// << ScreenScale[0]; scwidth = 256;
scheight = 192;// << ScreenScale[0]; scheight = 192;
switch (ScreenRotation) switch (ScreenRotation)
{ {
@ -303,8 +305,8 @@ void GLDrawing_DrawScreen()
x1 = BottomScreenRect.X + BottomScreenRect.Width; x1 = BottomScreenRect.X + BottomScreenRect.Width;
y1 = BottomScreenRect.Y + BottomScreenRect.Height; y1 = BottomScreenRect.Y + BottomScreenRect.Height;
scwidth = 256;// << ScreenScale[1]; scwidth = 256;
scheight = 192;// << ScreenScale[1]; scheight = 192;
switch (ScreenRotation) switch (ScreenRotation)
{ {
@ -376,7 +378,8 @@ void GLDrawing_DrawScreen()
GL_UNSIGNED_BYTE, GPU::Framebuffer[frontbuf][1]); GL_UNSIGNED_BYTE, GPU::Framebuffer[frontbuf][1]);
glActiveTexture(GL_TEXTURE1); glActiveTexture(GL_TEXTURE1);
GPU3D::SetupAccelFrame(); if (_3DRenderer != 0)
GPU3D::GLRenderer::SetupAccelFrame();
glBindBuffer(GL_ARRAY_BUFFER, GL_ScreenVertexBufferID); glBindBuffer(GL_ARRAY_BUFFER, GL_ScreenVertexBufferID);
glBindVertexArray(GL_ScreenVertexArrayID); glBindVertexArray(GL_ScreenVertexArrayID);
@ -384,7 +387,89 @@ void GLDrawing_DrawScreen()
glFlush(); glFlush();
uiGLSwapBuffers(GLContext); uiGLSwapBuffers(GLContext);
uiAreaQueueRedrawAll(MainDrawArea); }
void ScreenCreateArea(bool opengl)
{
bool opengl_good = opengl;
if (opengl_good)
{
MainDrawArea = uiNewGLArea(&MainDrawAreaHandler, kGLVersions);
uiWindowSetChild(MainWindow, uiControl(MainDrawArea));
uiControlSetMinSize(uiControl(MainDrawArea), 256, 384);
uiAreaSetBackgroundColor(MainDrawArea, 0, 0, 0);
GLContext = uiAreaGetGLContext(MainDrawArea);
if (!GLContext) opengl_good = false;
}
if (opengl_good)
{
uiGLMakeContextCurrent(GLContext);
if (!GLScreen_Init()) opengl_good = false;
}
if (opengl_good)
{
//if (_3DRenderer != 0)
{
_3DRenderer = GPU3D::SetRenderer(_3DRenderer);
if (_3DRenderer != 0)
GPU3D::GLRenderer::SetDisplaySettings(Config::GL_ScaleFactor, Config::GL_Antialias);
else if (RunningSomething)
GPU3D::SoftRenderer::SetupRenderThread();
}
uiGLMakeContextCurrent(NULL);
}
else
{
if (opengl)
{
uiWindowSetChild(MainWindow, NULL);
uiControlDestroy(uiControl(MainDrawArea));
}
Screen_UseGL = false;
MainDrawArea = uiNewArea(&MainDrawAreaHandler);
uiWindowSetChild(MainWindow, uiControl(MainDrawArea));
uiControlSetMinSize(uiControl(MainDrawArea), 256, 384);
uiAreaSetBackgroundColor(MainDrawArea, 0, 0, 0);
ScreenDrawInited = false;
}
uiControlShow(uiControl(MainWindow));
uiControlSetFocus(uiControl(MainDrawArea));
}
void ScreenSetMethod(bool opengl)
{
int oldstatus = EmuRunning;
EmuRunning = 3;
while (EmuStatus != 3);
if (Screen_UseGL)
{
uiGLMakeContextCurrent(GLContext);
if (_3DRenderer != 0) GPU3D::GLRenderer::DeInit();
else GPU3D::SoftRenderer::DeInit();
GLScreen_DeInit();
uiGLMakeContextCurrent(NULL);
}
else
{
if (ScreenBitmap[0]) uiDrawFreeBitmap(ScreenBitmap[0]);
if (ScreenBitmap[1]) uiDrawFreeBitmap(ScreenBitmap[1]);
}
uiWindowSetChild(MainWindow, NULL);
uiControlDestroy(uiControl(MainDrawArea));
Screen_UseGL = Config::ScreenUseGL;
_3DRenderer = Config::_3DRenderer;
ScreenCreateArea(opengl);
EmuRunning = oldstatus;
} }
void MicLoadWav(char* name) void MicLoadWav(char* name)
@ -642,8 +727,11 @@ void FeedMicInput()
int EmuThreadFunc(void* burp) int EmuThreadFunc(void* burp)
{ {
uiGLMakeContextCurrent(GLContext); if (Screen_UseGL)
GLDrawing_Init(); {
uiGLMakeContextCurrent(GLContext);
GLScreen_Init();
}
NDS::Init(); NDS::Init();
@ -652,13 +740,8 @@ int EmuThreadFunc(void* burp)
MainScreenPos[2] = 0; MainScreenPos[2] = 0;
AutoScreenSizing = 0; AutoScreenSizing = 0;
// FIXME GPU::SetDisplaySettings(_3DRenderer != 0);
ScreenScale[2] = Config::ScreenScale; if (Screen_UseGL) uiGLMakeContextCurrent(NULL);
ScreenScale[0] = ScreenScale[2];
ScreenScale[1] = ScreenScale[2];
int lastscale[2] = {ScreenScale[0], ScreenScale[1]};
GPU::SetDisplaySettings(ScreenScale[0], ScreenScale[1], false);
Touching = false; Touching = false;
KeyInputMask = 0xFFF; KeyInputMask = 0xFFF;
@ -773,7 +856,7 @@ int EmuThreadFunc(void* burp)
// microphone input // microphone input
FeedMicInput(); FeedMicInput();
uiGLMakeContextCurrent(GLContext); if (Screen_UseGL) uiGLMakeContextCurrent(GLContext);
// auto screen layout // auto screen layout
{ {
@ -804,22 +887,16 @@ int EmuThreadFunc(void* burp)
} }
} }
if (ScreenScale[0] != lastscale[0] ||
ScreenScale[1] != lastscale[1])
{
GPU::SetDisplaySettings(ScreenScale[0], ScreenScale[1], false);
ScreenDrawInited = false;
}
// emulate // emulate
u32 nlines = NDS::RunFrame(); u32 nlines = NDS::RunFrame();
if (EmuRunning == 0) break; if (EmuRunning == 0) break;
GLDrawing_DrawScreen(); if (Screen_UseGL)
{
//uiAreaQueueRedrawAll(MainDrawArea); GLScreen_DrawScreen();
//uiGLSwapBuffers(GLContext); }
uiAreaQueueRedrawAll(MainDrawArea);
// framerate limiter based off SDL2_gfx // framerate limiter based off SDL2_gfx
float framerate = (1000.0f * nlines) / (60.0f * 263.0f); float framerate = (1000.0f * nlines) / (60.0f * 263.0f);
@ -869,13 +946,16 @@ int EmuThreadFunc(void* burp)
if (EmuRunning == 2) if (EmuRunning == 2)
{ {
uiGLMakeContextCurrent(GLContext); if (Screen_UseGL)
{
//uiAreaQueueRedrawAll(MainDrawArea); uiGLMakeContextCurrent(GLContext);
//uiGLSwapBuffers(GLContext); GLScreen_DrawScreen();
GLDrawing_DrawScreen(); }
uiAreaQueueRedrawAll(MainDrawArea);
} }
if (Screen_UseGL) uiGLMakeContextCurrent(NULL);
EmuStatus = EmuRunning; EmuStatus = EmuRunning;
SDL_Delay(100); SDL_Delay(100);
@ -889,7 +969,7 @@ int EmuThreadFunc(void* burp)
NDS::DeInit(); NDS::DeInit();
Platform::LAN_DeInit(); Platform::LAN_DeInit();
GLDrawing_DeInit(); if (Screen_UseGL) GLScreen_DeInit();
return 44203; return 44203;
} }
@ -897,22 +977,21 @@ int EmuThreadFunc(void* burp)
void OnAreaDraw(uiAreaHandler* handler, uiArea* area, uiAreaDrawParams* params) void OnAreaDraw(uiAreaHandler* handler, uiArea* area, uiAreaDrawParams* params)
{ {
// TODO: recreate bitmap if screen scale changed
if (!ScreenDrawInited) if (!ScreenDrawInited)
{ {
if (ScreenBitmap[0]) uiDrawFreeBitmap(ScreenBitmap[0]); if (ScreenBitmap[0]) uiDrawFreeBitmap(ScreenBitmap[0]);
if (ScreenBitmap[1]) uiDrawFreeBitmap(ScreenBitmap[1]); if (ScreenBitmap[1]) uiDrawFreeBitmap(ScreenBitmap[1]);
ScreenDrawInited = true; ScreenDrawInited = true;
ScreenBitmap[0] = uiDrawNewBitmap(params->Context, 256<<ScreenScale[0], 192<<ScreenScale[0]); ScreenBitmap[0] = uiDrawNewBitmap(params->Context, 256, 192);
ScreenBitmap[1] = uiDrawNewBitmap(params->Context, 256<<ScreenScale[1], 192<<ScreenScale[1]); ScreenBitmap[1] = uiDrawNewBitmap(params->Context, 256, 192);
} }
if (!ScreenBitmap[0] || !ScreenBitmap[1]) return; if (!ScreenBitmap[0] || !ScreenBitmap[1]) return;
if (!GPU::Framebuffer[0][0]) return; if (!GPU::Framebuffer[0][0]) return;
uiRect top = {0, 0, 256<<ScreenScale[0], 192<<ScreenScale[0]}; uiRect top = {0, 0, 256, 192};
uiRect bot = {0, 0, 256<<ScreenScale[1], 192<<ScreenScale[1]}; uiRect bot = {0, 0, 256, 192};
int frontbuf = GPU::FrontBuffer; int frontbuf = GPU::FrontBuffer;
uiDrawBitmapUpdate(ScreenBitmap[0], GPU::Framebuffer[frontbuf][0]); uiDrawBitmapUpdate(ScreenBitmap[0], GPU::Framebuffer[frontbuf][0]);
@ -1097,33 +1176,6 @@ void SetupScreenRects(int width, int height)
screenH = 192; screenH = 192;
} }
if (ScreenScaleMode == 0 || sizemode == 0)
{
// scale both screens
screenW <<= ScreenScale[2];
screenH <<= ScreenScale[2];
ScreenScale[0] = ScreenScale[2];
ScreenScale[1] = ScreenScale[2];
}
else
{
// scale emphasized screen
// screenW/screenH will apply to the non-emphasized screen
// the emphasized screen basically taking up all the remaining space
if (sizemode == 1)
{
ScreenScale[0] = ScreenScale[2];
ScreenScale[1] = 0;
}
else if (sizemode == 2)
{
ScreenScale[0] = 0;
ScreenScale[1] = ScreenScale[2];
}
}
gap = ScreenGap; gap = ScreenGap;
uiRect *topscreen, *bottomscreen; uiRect *topscreen, *bottomscreen;
@ -1798,35 +1850,7 @@ void OnOpenHotkeyConfig(uiMenuItem* item, uiWindow* window, void* blarg)
void OnOpenVideoSettings(uiMenuItem* item, uiWindow* window, void* blarg) void OnOpenVideoSettings(uiMenuItem* item, uiWindow* window, void* blarg)
{ {
//DlgVideoSettings::Open(); DlgVideoSettings::Open();
int oldstatus = EmuRunning;
EmuRunning = 3;
while (EmuStatus != 3);
uiGLMakeContextCurrent(GLContext);
GPU3D::GLRenderer::DeInit();
GLDrawing_DeInit();
uiGLMakeContextCurrent(NULL);
uiWindowSetChild(MainWindow, NULL);
uiControlDestroy(uiControl(MainDrawArea));
MainDrawArea = uiNewGLArea(&MainDrawAreaHandler, kGLVersions);
uiWindowSetChild(MainWindow, uiControl(MainDrawArea));
uiControlSetMinSize(uiControl(MainDrawArea), 256, 384);
uiAreaSetBackgroundColor(MainDrawArea, 0, 0, 0);
//uiControlShow(uiControl(MainDrawArea));
GLContext = uiAreaGetGLContext(MainDrawArea);
uiGLMakeContextCurrent(GLContext);
GLDrawing_Init();
GPU3D::GLRenderer::Init();
GPU3D::GLRenderer::SetDisplaySettings(1, true);
uiGLMakeContextCurrent(NULL);
EmuRunning = oldstatus;
} }
void OnOpenAudioSettings(uiMenuItem* item, uiWindow* window, void* blarg) void OnOpenAudioSettings(uiMenuItem* item, uiWindow* window, void* blarg)
@ -1850,17 +1874,11 @@ void EnsureProperMinSize()
{ {
bool isHori = (ScreenRotation == 1 || ScreenRotation == 3); bool isHori = (ScreenRotation == 1 || ScreenRotation == 3);
int w0 = 256 << ScreenScale[2]; int w0 = 256;
int h0 = 192 << ScreenScale[2]; int h0 = 192;
int w1 = 256; int w1 = 256;
int h1 = 192; int h1 = 192;
if (ScreenScale[2] != 0 && (ScreenScaleMode != 1 || ScreenSizing == 0 || ScreenSizing == 3))
{
w1 <<= ScreenScale[2];
h1 <<= ScreenScale[2];
}
if (ScreenLayout == 0) // natural if (ScreenLayout == 0) // natural
{ {
if (isHori) if (isHori)
@ -1889,8 +1907,8 @@ void OnSetScreenSize(uiMenuItem* item, uiWindow* window, void* param)
int factor = *(int*)param; int factor = *(int*)param;
bool isHori = (ScreenRotation == 1 || ScreenRotation == 3); bool isHori = (ScreenRotation == 1 || ScreenRotation == 3);
int w = 256*factor;// * ScreenScale; int w = 256*factor;
int h = 192*factor;// * ScreenScale; int h = 192*factor;
// FIXME // FIXME
@ -2003,16 +2021,23 @@ void OnSetLimitFPS(uiMenuItem* item, uiWindow* window, void* blarg)
void ApplyNewSettings(int type) void ApplyNewSettings(int type)
{ {
if (type == 2)
{
bool usegl = Config::ScreenUseGL || (Config::_3DRenderer != 0);
ScreenSetMethod(usegl);
return;
}
if (!RunningSomething) return; if (!RunningSomething) return;
int prevstatus = EmuRunning; int prevstatus = EmuRunning;
EmuRunning = 2; EmuRunning = 3;
while (EmuStatus != 2); while (EmuStatus != 3);
if (type == 0) // general emu settings if (type == 0) // software renderer thread
{ {
// TODO!! REMOVE ME if (_3DRenderer == 0)
GPU3D::SoftRenderer::SetupRenderThread(); GPU3D::SoftRenderer::SetupRenderThread();
} }
else if (type == 1) // wifi settings else if (type == 1) // wifi settings
{ {
@ -2025,15 +2050,18 @@ void ApplyNewSettings(int type)
Platform::LAN_DeInit(); Platform::LAN_DeInit();
Platform::LAN_Init(); Platform::LAN_Init();
} }
else if (type == 2) // upscaling/video settings else if (type == 3) // GL renderer settings
{ {
int scale = Config::ScreenScale; GL_3DScale = Config::GL_ScaleFactor;
if (scale != ScreenScale[2])
{
ScreenScale[2] = scale;
EnsureProperMinSize(); if (_3DRenderer != 0)
SetupScreenRects(WindowWidth, WindowHeight); {
uiGLMakeContextCurrent(GLContext);
printf("%04X\n", glGetError());
printf("%04X\n", glGetError());
GPU3D::GLRenderer::SetDisplaySettings(Config::GL_ScaleFactor, Config::GL_Antialias);
uiGLMakeContextCurrent(NULL);
GL_ScreenSizeDirty = true;
} }
} }
@ -2316,8 +2344,12 @@ int main(int argc, char** argv)
WindowWidth = w; WindowWidth = w;
WindowHeight = h; WindowHeight = h;
//ScreenScale = 1; Screen_UseGL = Config::ScreenUseGL || (Config::_3DRenderer != 0);
ScreenScale[2] = 0; // FIXME _3DRenderer = Config::_3DRenderer;
GL_3DScale = Config::GL_ScaleFactor;
if (GL_3DScale < 1) GL_3DScale = 1;
else if (GL_3DScale > 8) GL_3DScale = 8;
MainWindow = uiNewWindow("melonDS " MELONDS_VERSION, w, h, Config::WindowMaximized, 1, 1); MainWindow = uiNewWindow("melonDS " MELONDS_VERSION, w, h, Config::WindowMaximized, 1, 1);
uiWindowOnClosing(MainWindow, OnCloseWindow, NULL); uiWindowOnClosing(MainWindow, OnCloseWindow, NULL);
@ -2346,11 +2378,7 @@ int main(int argc, char** argv)
MainDrawAreaHandler.Resize = OnAreaResize; MainDrawAreaHandler.Resize = OnAreaResize;
ScreenDrawInited = false; ScreenDrawInited = false;
//MainDrawArea = uiNewArea(&MainDrawAreaHandler); ScreenCreateArea(Screen_UseGL);
MainDrawArea = uiNewGLArea(&MainDrawAreaHandler, kGLVersions);
uiWindowSetChild(MainWindow, uiControl(MainDrawArea));
uiControlSetMinSize(uiControl(MainDrawArea), 256, 384);
uiAreaSetBackgroundColor(MainDrawArea, 0, 0, 0); // TODO: make configurable?
ScreenRotation = Config::ScreenRotation; ScreenRotation = Config::ScreenRotation;
ScreenGap = Config::ScreenGap; ScreenGap = Config::ScreenGap;
@ -2377,15 +2405,6 @@ int main(int argc, char** argv)
OnSetScreenRotation(MenuItem_ScreenRot[ScreenRotation], MainWindow, (void*)&kScreenRot[ScreenRotation]); OnSetScreenRotation(MenuItem_ScreenRot[ScreenRotation], MainWindow, (void*)&kScreenRot[ScreenRotation]);
// TODO: fail gracefully, support older OpenGL, etc
GLContext = uiAreaGetGLContext(MainDrawArea);
uiGLMakeContextCurrent(GLContext);
void* testor = uiGLGetProcAddress("glUseProgram");
void* testor2 = uiGLGetProcAddress("glBindFramebuffer");
printf("OPENGL: %p %p\n", testor, testor2);
uiGLMakeContextCurrent(NULL);
SDL_AudioSpec whatIwant, whatIget; SDL_AudioSpec whatIwant, whatIget;
memset(&whatIwant, 0, sizeof(SDL_AudioSpec)); memset(&whatIwant, 0, sizeof(SDL_AudioSpec));
whatIwant.freq = 47340; whatIwant.freq = 47340;
@ -2454,8 +2473,6 @@ int main(int argc, char** argv)
} }
} }
uiControlShow(uiControl(MainWindow));
uiControlSetFocus(uiControl(MainDrawArea));
uiMain(); uiMain();
EmuRunning = 0; EmuRunning = 0;