From b730bb890207d206505c338178fd49d244cd554d Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sat, 11 May 2019 15:36:42 +0200 Subject: welp --- src/libui_sdl/DlgVideoSettings.cpp | 150 +++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 src/libui_sdl/DlgVideoSettings.cpp (limited to 'src/libui_sdl/DlgVideoSettings.cpp') diff --git a/src/libui_sdl/DlgVideoSettings.cpp b/src/libui_sdl/DlgVideoSettings.cpp new file mode 100644 index 0000000..f27a80b --- /dev/null +++ b/src/libui_sdl/DlgVideoSettings.cpp @@ -0,0 +1,150 @@ +/* + Copyright 2016-2019 Arisotura + + This file is part of melonDS. + + melonDS is free software: you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + melonDS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#include +#include +#include + +#include "libui/ui.h" + +#include "../types.h" +#include "PlatformConfig.h" + +#include "DlgVideoSettings.h" + + +// + + +namespace DlgVideoSettings +{ + +bool opened; +uiWindow* win; + +// + + +int OnCloseWindow(uiWindow* window, void* blarg) +{ + opened = false; + return 1; +} + +// + +void OnCancel(uiButton* btn, void* blarg) +{ + // restore old settings here + + uiControlDestroy(uiControl(win)); + opened = false; +} + +void OnOk(uiButton* btn, void* blarg) +{ + // set config entries here + + Config::Save(); + + uiControlDestroy(uiControl(win)); + opened = false; +} + +void Open() +{ + if (opened) + { + uiControlSetFocus(uiControl(win)); + return; + } + + opened = true; + win = uiNewWindow("Video settings - melonDS", 400, 100, 0, 0, 0); + uiWindowSetMargined(win, 1); + uiWindowOnClosing(win, OnCloseWindow, NULL); + + uiBox* top = uiNewVerticalBox(); + uiWindowSetChild(win, uiControl(top)); + uiBoxSetPadded(top, 1); + + /*{ + uiGroup* grp = uiNewGroup("Audio output"); + uiBoxAppend(top, uiControl(grp), 0); + uiGroupSetMargined(grp, 1); + + uiBox* in_ctrl = uiNewVerticalBox(); + uiGroupSetChild(grp, uiControl(in_ctrl)); + + uiLabel* label_vol = uiNewLabel("Volume:"); + uiBoxAppend(in_ctrl, uiControl(label_vol), 0); + + slVolume = uiNewSlider(0, 256); + uiSliderOnChanged(slVolume, OnVolumeChanged, NULL); + uiBoxAppend(in_ctrl, uiControl(slVolume), 0); + } + + { + uiGroup* grp = uiNewGroup("Microphone input"); + uiBoxAppend(top, uiControl(grp), 0); + uiGroupSetMargined(grp, 1); + + uiBox* in_ctrl = uiNewVerticalBox(); + uiGroupSetChild(grp, uiControl(in_ctrl)); + + rbMicInputType = uiNewRadioButtons(); + uiRadioButtonsAppend(rbMicInputType, "None"); + uiRadioButtonsAppend(rbMicInputType, "Microphone"); + uiRadioButtonsAppend(rbMicInputType, "White noise"); + uiRadioButtonsAppend(rbMicInputType, "WAV file:"); + uiBoxAppend(in_ctrl, uiControl(rbMicInputType), 0); + + uiBox* path_box = uiNewHorizontalBox(); + uiBoxAppend(in_ctrl, uiControl(path_box), 0); + + txMicWavPath = uiNewEntry(); + uiBoxAppend(path_box, uiControl(txMicWavPath), 1); + + uiButton* path_browse = uiNewButton("..."); + uiButtonOnClicked(path_browse, OnMicWavBrowse, NULL); + uiBoxAppend(path_box, uiControl(path_browse), 0); + }*/ + + { + uiBox* in_ctrl = uiNewHorizontalBox(); + uiBoxSetPadded(in_ctrl, 1); + uiBoxAppend(top, uiControl(in_ctrl), 0); + + uiLabel* dummy = uiNewLabel(""); + uiBoxAppend(in_ctrl, uiControl(dummy), 1); + + uiButton* btncancel = uiNewButton("Cancel"); + uiButtonOnClicked(btncancel, OnCancel, NULL); + uiBoxAppend(in_ctrl, uiControl(btncancel), 0); + + uiButton* btnok = uiNewButton("Ok"); + uiButtonOnClicked(btnok, OnOk, NULL); + uiBoxAppend(in_ctrl, uiControl(btnok), 0); + } + + // + + uiControlShow(uiControl(win)); +} + +} -- cgit v1.2.3 From 39080be9b747795d8699b8f803a7f7888b0144ff Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sat, 11 May 2019 16:12:57 +0200 Subject: draft video settings dialog with the envisioned features --- src/libui_sdl/DlgVideoSettings.cpp | 89 ++++++++++++++++++++++++++++---------- 1 file changed, 65 insertions(+), 24 deletions(-) (limited to 'src/libui_sdl/DlgVideoSettings.cpp') diff --git a/src/libui_sdl/DlgVideoSettings.cpp b/src/libui_sdl/DlgVideoSettings.cpp index f27a80b..ed33cb5 100644 --- a/src/libui_sdl/DlgVideoSettings.cpp +++ b/src/libui_sdl/DlgVideoSettings.cpp @@ -83,47 +83,88 @@ void Open() uiWindowSetChild(win, uiControl(top)); uiBoxSetPadded(top, 1); - /*{ - uiGroup* grp = uiNewGroup("Audio output"); - uiBoxAppend(top, uiControl(grp), 0); + uiBox* splitter = uiNewHorizontalBox(); + uiBoxAppend(top, uiControl(splitter), 0); + uiBoxSetPadded(splitter, 1); + + uiBox* left = uiNewVerticalBox(); + uiBoxAppend(splitter, uiControl(left), 1); + uiBoxSetPadded(left, 1); + uiBox* right = uiNewVerticalBox(); + uiBoxAppend(splitter, uiControl(right), 1); + uiBoxSetPadded(right, 1); + + { + uiGroup* grp = uiNewGroup("3D renderer"); + uiBoxAppend(left, uiControl(grp), 0); uiGroupSetMargined(grp, 1); uiBox* in_ctrl = uiNewVerticalBox(); uiGroupSetChild(grp, uiControl(in_ctrl)); - uiLabel* label_vol = uiNewLabel("Volume:"); - uiBoxAppend(in_ctrl, uiControl(label_vol), 0); + uiRadioButtons* rbRenderer = uiNewRadioButtons(); + uiRadioButtonsAppend(rbRenderer, "Software"); + uiRadioButtonsAppend(rbRenderer, "OpenGL"); + uiBoxAppend(in_ctrl, uiControl(rbRenderer), 0); + } - slVolume = uiNewSlider(0, 256); - uiSliderOnChanged(slVolume, OnVolumeChanged, NULL); - uiBoxAppend(in_ctrl, uiControl(slVolume), 0); + { + 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("Microphone input"); - uiBoxAppend(top, uiControl(grp), 0); + uiGroup* grp = uiNewGroup("OpenGL renderer"); + uiBoxAppend(left, uiControl(grp), 0); uiGroupSetMargined(grp, 1); uiBox* in_ctrl = uiNewVerticalBox(); uiGroupSetChild(grp, uiControl(in_ctrl)); - rbMicInputType = uiNewRadioButtons(); - uiRadioButtonsAppend(rbMicInputType, "None"); - uiRadioButtonsAppend(rbMicInputType, "Microphone"); - uiRadioButtonsAppend(rbMicInputType, "White noise"); - uiRadioButtonsAppend(rbMicInputType, "WAV file:"); - uiBoxAppend(in_ctrl, uiControl(rbMicInputType), 0); + uiCheckbox* cbAntialias = uiNewCheckbox("Antialiasing"); + uiBoxAppend(in_ctrl, uiControl(cbAntialias), 0); + } - uiBox* path_box = uiNewHorizontalBox(); - uiBoxAppend(in_ctrl, uiControl(path_box), 0); + { + uiGroup* grp = uiNewGroup("Display settings"); + uiBoxAppend(right, uiControl(grp), 0); + uiGroupSetMargined(grp, 1); + + uiBox* in_ctrl = uiNewVerticalBox(); + uiGroupSetChild(grp, uiControl(in_ctrl)); - txMicWavPath = uiNewEntry(); - uiBoxAppend(path_box, uiControl(txMicWavPath), 1); + uiLabel* lbl = uiNewLabel("Resolution:"); + uiBoxAppend(in_ctrl, uiControl(lbl), 0); - uiButton* path_browse = uiNewButton("..."); - uiButtonOnClicked(path_browse, OnMicWavBrowse, NULL); - uiBoxAppend(path_box, uiControl(path_browse), 0); - }*/ + uiRadioButtons* rbResolution = uiNewRadioButtons(); + uiRadioButtonsAppend(rbResolution, "1x"); + uiRadioButtonsAppend(rbResolution, "2x"); + uiRadioButtonsAppend(rbResolution, "4x"); + uiBoxAppend(in_ctrl, uiControl(rbResolution), 0); + + uiCheckbox* cbWidescreen = uiNewCheckbox("Stretch to 16:9"); + uiBoxAppend(in_ctrl, uiControl(cbWidescreen), 0); + + lbl = uiNewLabel(""); + uiBoxAppend(in_ctrl, uiControl(lbl), 0); + + lbl = uiNewLabel("Apply upscaling to:"); + uiBoxAppend(in_ctrl, uiControl(lbl), 0); + + uiRadioButtons* rbApplyScalingTo = uiNewRadioButtons(); + uiRadioButtonsAppend(rbApplyScalingTo, "Both screens"); + uiRadioButtonsAppend(rbApplyScalingTo, "Emphasized screen"); + uiRadioButtonsAppend(rbApplyScalingTo, "Top screen"); + uiRadioButtonsAppend(rbApplyScalingTo, "Bottom screen"); + uiBoxAppend(in_ctrl, uiControl(rbApplyScalingTo), 0); + } { uiBox* in_ctrl = uiNewHorizontalBox(); -- cgit v1.2.3 From c88981b5892ed3faf7cd19302c398debe27d94ed Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 12 May 2019 15:01:40 +0200 Subject: split framebuffer. setup doublebuffering inside GPU.cpp. avoid copying a whole framebuffer every frame. better performance at higher res. --- src/GPU.cpp | 94 ++++++++++++++++++++++++++++---------- src/GPU.h | 5 +- src/libui_sdl/DlgVideoSettings.cpp | 2 +- src/libui_sdl/main.cpp | 27 +++++++---- 4 files changed, 91 insertions(+), 37 deletions(-) (limited to 'src/libui_sdl/DlgVideoSettings.cpp') diff --git a/src/GPU.cpp b/src/GPU.cpp index f272129..636c430 100644 --- a/src/GPU.cpp +++ b/src/GPU.cpp @@ -71,9 +71,9 @@ u32 VRAMMap_TexPal[8]; u32 VRAMMap_ARM7[2]; -u32* Framebuffer; -int FBScale; -int FBScreenStride; +int FrontBuffer; +u32* Framebuffer[2][2]; +int FBScale[2]; GPU2D* GPU2D_A; GPU2D* GPU2D_B; @@ -85,8 +85,12 @@ bool Init() GPU2D_B = new GPU2D(1); if (!GPU3D::Init()) return false; + FrontBuffer = 0; + Framebuffer[0][0] = NULL; Framebuffer[0][1] = NULL; + Framebuffer[1][0] = NULL; Framebuffer[1][1] = NULL; + FBScale[0] = -1; FBScale[1] = -1; //SetFramebufferScale(1); - SetFramebufferScale(2); + SetFramebufferScale(1, 1); return true; } @@ -97,7 +101,10 @@ void DeInit() delete GPU2D_B; GPU3D::DeInit(); - if (Framebuffer) delete[] Framebuffer; + if (Framebuffer[0][0]) delete[] Framebuffer[0][0]; + if (Framebuffer[0][1]) delete[] Framebuffer[0][1]; + if (Framebuffer[1][0]) delete[] Framebuffer[1][0]; + if (Framebuffer[1][1]) delete[] Framebuffer[1][1]; } void Reset() @@ -145,22 +152,32 @@ void Reset() VRAMMap_ARM7[0] = 0; VRAMMap_ARM7[1] = 0; - for (int i = 0; i < 256*192*2; i++) + for (int i = 0; i < (256*192)<<(FBScale[0]*2); i++) { - Framebuffer[i] = 0xFFFFFFFF; + Framebuffer[0][0][i] = 0xFFFFFFFF; + Framebuffer[1][0][i] = 0xFFFFFFFF; + } + for (int i = 0; i < (256*192)<<(FBScale[1]*2); i++) + { + Framebuffer[0][1][i] = 0xFFFFFFFF; + Framebuffer[1][1][i] = 0xFFFFFFFF; } GPU2D_A->Reset(); GPU2D_B->Reset(); GPU3D::Reset(); - GPU2D_A->SetFramebuffer(&Framebuffer[FBScreenStride]); - GPU2D_B->SetFramebuffer(&Framebuffer[0]); + int backbuf = FrontBuffer ? 0 : 1; + GPU2D_A->SetFramebuffer(Framebuffer[backbuf][1]); + GPU2D_B->SetFramebuffer(Framebuffer[backbuf][0]); } void Stop() { - memset(Framebuffer, 0, FBScreenStride*2*sizeof(u32)); + memset(Framebuffer[0][0], 0, (256*192)<<(FBScale[0]*2)); + memset(Framebuffer[0][1], 0, (256*192)<<(FBScale[1]*2)); + memset(Framebuffer[1][0], 0, (256*192)<<(FBScale[0]*2)); + memset(Framebuffer[1][1], 0, (256*192)<<(FBScale[1]*2)); } void DoSavestate(Savestate* file) @@ -215,13 +232,46 @@ void DoSavestate(Savestate* file) GPU3D::DoSavestate(file); } -void SetFramebufferScale(int scale) +void AssignFramebuffers() +{ + int backbuf = FrontBuffer ? 0 : 1; + if (NDS::PowerControl9 & (1<<15)) + { + GPU2D_A->SetFramebuffer(Framebuffer[backbuf][0]); + GPU2D_B->SetFramebuffer(Framebuffer[backbuf][1]); + } + else + { + GPU2D_A->SetFramebuffer(Framebuffer[backbuf][1]); + GPU2D_B->SetFramebuffer(Framebuffer[backbuf][0]); + } +} + +void SetFramebufferScale(int top, int bottom) { - FBScale = scale; - FBScreenStride = (256*scale) * (192*scale); + if (top != FBScale[0]) + { + FBScale[0] = top; - if (Framebuffer) delete[] Framebuffer; - Framebuffer = new u32[FBScreenStride * 2]; + int fbsize = (256 * 192) << (FBScale[0] * 2); + if (Framebuffer[0][0]) delete[] Framebuffer[0][0]; + if (Framebuffer[1][0]) delete[] Framebuffer[1][0]; + Framebuffer[0][0] = new u32[fbsize]; + Framebuffer[1][0] = new u32[fbsize]; + } + + if (bottom != FBScale[1]) + { + FBScale[1] = bottom; + + int fbsize = (256 * 192) << (FBScale[1] * 2); + if (Framebuffer[0][1]) delete[] Framebuffer[0][1]; + if (Framebuffer[1][1]) delete[] Framebuffer[1][1]; + Framebuffer[0][1] = new u32[fbsize]; + Framebuffer[1][1] = new u32[fbsize]; + } + + AssignFramebuffers(); } @@ -682,16 +732,7 @@ void SetPowerCnt(u32 val) GPU2D_B->SetEnabled(val & (1<<9)); GPU3D::SetEnabled(val & (1<<3), val & (1<<2)); - if (val & (1<<15)) - { - GPU2D_A->SetFramebuffer(&Framebuffer[0]); - GPU2D_B->SetFramebuffer(&Framebuffer[FBScreenStride]); - } - else - { - GPU2D_A->SetFramebuffer(&Framebuffer[FBScreenStride]); - GPU2D_B->SetFramebuffer(&Framebuffer[0]); - } + AssignFramebuffers(); } @@ -762,6 +803,9 @@ void StartHBlank(u32 line) void FinishFrame(u32 lines) { + FrontBuffer = FrontBuffer ? 0 : 1; + AssignFramebuffers(); + TotalScanlines = lines; } diff --git a/src/GPU.h b/src/GPU.h index a430a32..2e47fc4 100644 --- a/src/GPU.h +++ b/src/GPU.h @@ -61,7 +61,8 @@ extern u32 VRAMMap_Texture[4]; extern u32 VRAMMap_TexPal[8]; extern u32 VRAMMap_ARM7[2]; -extern u32* Framebuffer; +extern int FrontBuffer; +extern u32* Framebuffer[2][2]; extern GPU2D* GPU2D_A; extern GPU2D* GPU2D_B; @@ -74,7 +75,7 @@ void Stop(); void DoSavestate(Savestate* file); -void SetFramebufferScale(int scale); +void SetFramebufferScale(int top, int bottom); void MapVRAM_AB(u32 bank, u8 cnt); diff --git a/src/libui_sdl/DlgVideoSettings.cpp b/src/libui_sdl/DlgVideoSettings.cpp index ed33cb5..b6544ed 100644 --- a/src/libui_sdl/DlgVideoSettings.cpp +++ b/src/libui_sdl/DlgVideoSettings.cpp @@ -160,7 +160,7 @@ void Open() uiRadioButtons* rbApplyScalingTo = uiNewRadioButtons(); uiRadioButtonsAppend(rbApplyScalingTo, "Both screens"); - uiRadioButtonsAppend(rbApplyScalingTo, "Emphasized screen"); + uiRadioButtonsAppend(rbApplyScalingTo, "Emphasized screen (see 'Screen sizing')"); uiRadioButtonsAppend(rbApplyScalingTo, "Top screen"); uiRadioButtonsAppend(rbApplyScalingTo, "Bottom screen"); uiBoxAppend(in_ctrl, uiControl(rbApplyScalingTo), 0); diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index a8a5ceb..c8454ed 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -95,7 +95,8 @@ char PrevSRAMPath[1024]; // for savestate 'undo load' bool SavestateLoaded; bool ScreenDrawInited = false; -uiDrawBitmap* ScreenBitmap = NULL; +uiDrawBitmap* ScreenBitmap[2] = {NULL,NULL}; +SDL_mutex* ScreenMutex; u32* ScreenBuffer; int ScreenScale; @@ -555,7 +556,7 @@ int EmuThreadFunc(void* burp) } } - memcpy(ScreenBuffer, GPU::Framebuffer, (256*ScreenScale)*(384*ScreenScale)*4); + //memcpy(ScreenBuffer, GPU::Framebuffer, (256*ScreenScale)*(384*ScreenScale)*4); uiAreaQueueRedrawAll(MainDrawArea); // framerate limiter based off SDL2_gfx @@ -636,24 +637,27 @@ void OnAreaDraw(uiAreaHandler* handler, uiArea* area, uiAreaDrawParams* params) if (!ScreenDrawInited) { ScreenDrawInited = true; - ScreenBitmap = uiDrawNewBitmap(params->Context, 256*ScreenScale, 384*ScreenScale); + ScreenBitmap[0] = uiDrawNewBitmap(params->Context, 256*ScreenScale, 384*ScreenScale); + ScreenBitmap[1] = uiDrawNewBitmap(params->Context, 256*ScreenScale, 384*ScreenScale); } - if (!ScreenBitmap) return; + if (!ScreenBitmap[0] || !ScreenBitmap[1]) return; uiRect top = {0, 0, 256*ScreenScale, 192*ScreenScale}; - uiRect bot = {0, 192*ScreenScale, 256*ScreenScale, 192*ScreenScale}; + uiRect bot = {0, 0, 256*ScreenScale, 192*ScreenScale}; - if (ScreenBuffer) uiDrawBitmapUpdate(ScreenBitmap, ScreenBuffer); + int frontbuf = GPU::FrontBuffer; + uiDrawBitmapUpdate(ScreenBitmap[0], GPU::Framebuffer[frontbuf][0]); + uiDrawBitmapUpdate(ScreenBitmap[1], GPU::Framebuffer[frontbuf][1]); uiDrawSave(params->Context); uiDrawTransform(params->Context, &TopScreenTrans); - uiDrawBitmapDraw(params->Context, ScreenBitmap, &top, &TopScreenRect, Config::ScreenFilter==1); + uiDrawBitmapDraw(params->Context, ScreenBitmap[0], &top, &TopScreenRect, Config::ScreenFilter==1); uiDrawRestore(params->Context); uiDrawSave(params->Context); uiDrawTransform(params->Context, &BottomScreenTrans); - uiDrawBitmapDraw(params->Context, ScreenBitmap, &bot, &BottomScreenRect, Config::ScreenFilter==1); + uiDrawBitmapDraw(params->Context, ScreenBitmap[1], &bot, &BottomScreenRect, Config::ScreenFilter==1); uiDrawRestore(params->Context); } @@ -1993,6 +1997,8 @@ int main(int argc, char** argv) uiMenuItemDisable(MenuItem_Reset); uiMenuItemDisable(MenuItem_Stop); + ScreenMutex = SDL_CreateMutex(); + uiAreaHandler areahandler; areahandler.Draw = OnAreaDraw; areahandler.MouseEvent = OnAreaMouseEvent; @@ -2131,7 +2137,10 @@ int main(int argc, char** argv) Config::Save(); - if (ScreenBitmap) uiDrawFreeBitmap(ScreenBitmap); + SDL_DestroyMutex(ScreenMutex); + + if (ScreenBitmap[0]) uiDrawFreeBitmap(ScreenBitmap[0]); + if (ScreenBitmap[1]) uiDrawFreeBitmap(ScreenBitmap[1]); uiUninit(); SDL_Quit(); -- cgit v1.2.3 From f5ba35ca9f42974f250c0241ccf18a3f36da79c4 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 12 May 2019 16:47:34 +0200 Subject: don't scale the screen gap --- src/GPU.cpp | 11 ++++++----- src/libui_sdl/DlgVideoSettings.cpp | 8 +++++++- src/libui_sdl/main.cpp | 27 +++++++++++++++++---------- 3 files changed, 30 insertions(+), 16 deletions(-) (limited to 'src/libui_sdl/DlgVideoSettings.cpp') diff --git a/src/GPU.cpp b/src/GPU.cpp index a904a90..f4e9fd4 100644 --- a/src/GPU.cpp +++ b/src/GPU.cpp @@ -92,11 +92,6 @@ bool Init() //SetFramebufferScale(1); SetFramebufferScale(1, 1); - memset(Framebuffer[0][0], 0, (256*192)<<(FBScale[0]*2)); - memset(Framebuffer[0][1], 0, (256*192)<<(FBScale[1]*2)); - memset(Framebuffer[1][0], 0, (256*192)<<(FBScale[0]*2)); - memset(Framebuffer[1][1], 0, (256*192)<<(FBScale[1]*2)); - return true; } @@ -264,6 +259,9 @@ void SetFramebufferScale(int top, int bottom) Framebuffer[0][0] = new u32[fbsize]; Framebuffer[1][0] = new u32[fbsize]; + memset(Framebuffer[0][0], 0, fbsize*4); + memset(Framebuffer[1][0], 0, fbsize*4); + int backbuf = FrontBuffer ? 0 : 1; if (NDS::PowerControl9 & (1<<15)) { @@ -288,6 +286,9 @@ void SetFramebufferScale(int top, int bottom) Framebuffer[0][1] = new u32[fbsize]; Framebuffer[1][1] = new u32[fbsize]; + memset(Framebuffer[0][1], 0, fbsize*4); + memset(Framebuffer[1][1], 0, fbsize*4); + int backbuf = FrontBuffer ? 0 : 1; if (NDS::PowerControl9 & (1<<15)) { diff --git a/src/libui_sdl/DlgVideoSettings.cpp b/src/libui_sdl/DlgVideoSettings.cpp index b6544ed..4d5de71 100644 --- a/src/libui_sdl/DlgVideoSettings.cpp +++ b/src/libui_sdl/DlgVideoSettings.cpp @@ -46,7 +46,12 @@ int OnCloseWindow(uiWindow* window, void* blarg) return 1; } -// +void OnResolutionChanged(uiRadioButtons* rb, void* blarg) +{ + int id = uiRadioButtonsSelected(rb); + + printf("res=%d\n", id); +} void OnCancel(uiButton* btn, void* blarg) { @@ -144,6 +149,7 @@ void Open() uiBoxAppend(in_ctrl, uiControl(lbl), 0); uiRadioButtons* rbResolution = uiNewRadioButtons(); + uiRadioButtonsOnSelected(rbResolution, OnResolutionChanged, NULL); uiRadioButtonsAppend(rbResolution, "1x"); uiRadioButtonsAppend(rbResolution, "2x"); uiRadioButtonsAppend(rbResolution, "4x"); diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index 2853a90..b79853e 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -834,7 +834,6 @@ void SetupScreenRects(int width, int height) screenW *= ScreenScale; screenH *= ScreenScale; - gap *= ScreenScale; uiRect *topscreen, *bottomscreen; if (ScreenRotation == 1 || ScreenRotation == 2) @@ -1029,9 +1028,6 @@ void SetMinSize(int w, int h) int cw, ch; uiWindowContentSize(MainWindow, &cw, &ch); - w *= ScreenScale; - h *= ScreenScale; - uiControlSetMinSize(uiControl(MainDrawArea), w, h); if ((cw < w) || (ch < h)) { @@ -1534,26 +1530,31 @@ void EnsureProperMinSize() { bool isHori = (ScreenRotation == 1 || ScreenRotation == 3); + int w0 = 256 * ScreenScale; + int h0 = 192 * ScreenScale; + int w1 = 256 * ScreenScale; + int h1 = 192 * ScreenScale; + if (ScreenLayout == 0) // natural { if (isHori) - SetMinSize(384+ScreenGap, 256); + SetMinSize(h0+ScreenGap+h1, std::max(w0,w1)); else - SetMinSize(256, 384+ScreenGap); + SetMinSize(std::max(w0,w1), h0+ScreenGap+h1); } else if (ScreenLayout == 1) // vertical { if (isHori) - SetMinSize(192, 512+ScreenGap); + SetMinSize(std::max(h0,h1), w0+ScreenGap+w1); else - SetMinSize(256, 384+ScreenGap); + SetMinSize(std::max(w0,w1), h0+ScreenGap+h1); } else // horizontal { if (isHori) - SetMinSize(384+ScreenGap, 256); + SetMinSize(h0+ScreenGap+h1, std::max(w0,w1)); else - SetMinSize(512+ScreenGap, 192); + SetMinSize(w0+ScreenGap+w1, std::max(h0,h1)); } } @@ -1565,6 +1566,8 @@ void OnSetScreenSize(uiMenuItem* item, uiWindow* window, void* param) int w = 256*factor * ScreenScale; int h = 192*factor * ScreenScale; + // FIXME + if (ScreenLayout == 0) // natural { if (isHori) @@ -1696,6 +1699,10 @@ void ApplyNewSettings(int type) Platform::LAN_DeInit(); Platform::LAN_Init(); } + else if (type == 2) // upscaling/video settings + { + // + } EmuRunning = prevstatus; } -- cgit v1.2.3 From 02b4919005a3bab00a2b0aa9e62ae50541ef6513 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 12 May 2019 17:43:39 +0200 Subject: resolution switch somewhat functional --- src/GPU2D.cpp | 8 +-- src/libui_sdl/DlgVideoSettings.cpp | 9 +-- src/libui_sdl/main.cpp | 109 ++++++++++++++++++++++++++----------- 3 files changed, 85 insertions(+), 41 deletions(-) (limited to 'src/libui_sdl/DlgVideoSettings.cpp') diff --git a/src/GPU2D.cpp b/src/GPU2D.cpp index 521d86a..3a99964 100644 --- a/src/GPU2D.cpp +++ b/src/GPU2D.cpp @@ -1489,8 +1489,8 @@ void GPU2D::DrawBG_3D() { for (; i < iend; i++) { - int is = i << 1; - int xs = xoff << 1; + int is = i << 2; + int xs = xoff << 2; u32 c; xoff++; @@ -1511,8 +1511,8 @@ void GPU2D::DrawBG_3D() xs++; } - is += 1021; - xs += 1021; + is += 1020; + xs += 1020; } } } diff --git a/src/libui_sdl/DlgVideoSettings.cpp b/src/libui_sdl/DlgVideoSettings.cpp index 4d5de71..aee6d51 100644 --- a/src/libui_sdl/DlgVideoSettings.cpp +++ b/src/libui_sdl/DlgVideoSettings.cpp @@ -28,7 +28,7 @@ #include "DlgVideoSettings.h" -// +void ApplyNewSettings(int type); namespace DlgVideoSettings @@ -50,7 +50,8 @@ void OnResolutionChanged(uiRadioButtons* rb, void* blarg) { int id = uiRadioButtonsSelected(rb); - printf("res=%d\n", id); + Config::ScreenScale = id; + ApplyNewSettings(2); } void OnCancel(uiButton* btn, void* blarg) @@ -167,8 +168,8 @@ void Open() uiRadioButtons* rbApplyScalingTo = uiNewRadioButtons(); uiRadioButtonsAppend(rbApplyScalingTo, "Both screens"); uiRadioButtonsAppend(rbApplyScalingTo, "Emphasized screen (see 'Screen sizing')"); - uiRadioButtonsAppend(rbApplyScalingTo, "Top screen"); - uiRadioButtonsAppend(rbApplyScalingTo, "Bottom screen"); + //uiRadioButtonsAppend(rbApplyScalingTo, "Top screen"); + //uiRadioButtonsAppend(rbApplyScalingTo, "Bottom screen"); uiBoxAppend(in_ctrl, uiControl(rbApplyScalingTo), 0); } diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index b79853e..6fcb1ae 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -96,10 +96,9 @@ bool SavestateLoaded; bool ScreenDrawInited = false; uiDrawBitmap* ScreenBitmap[2] = {NULL,NULL}; -SDL_mutex* ScreenMutex; -u32* ScreenBuffer; -int ScreenScale; +int ScreenScale[3]; +int ScreenScaleMode; int ScreenGap = 0; int ScreenLayout = 0; @@ -400,13 +399,18 @@ int EmuThreadFunc(void* burp) uiGLMakeContextCurrent(GLContext); NDS::Init(); - ScreenBuffer = new u32[(256*ScreenScale) * (384*ScreenScale)]; - MainScreenPos[0] = 0; MainScreenPos[1] = 0; MainScreenPos[2] = 0; AutoScreenSizing = 0; + // FIXME + ScreenScale[2] = Config::ScreenScale; + ScreenScale[0] = ScreenScale[2]; + ScreenScale[1] = ScreenScale[2]; + + int lastscale[2] = {-1, -1}; + Touching = false; KeyInputMask = 0xFFF; HotkeyMask = 0; @@ -522,11 +526,6 @@ int EmuThreadFunc(void* burp) // microphone input FeedMicInput(); - // emulate - u32 nlines = NDS::RunFrame(); - - if (EmuRunning == 0) break; - // auto screen layout { MainScreenPos[2] = MainScreenPos[1]; @@ -556,7 +555,18 @@ int EmuThreadFunc(void* burp) } } - //memcpy(ScreenBuffer, GPU::Framebuffer, (256*ScreenScale)*(384*ScreenScale)*4); + if (ScreenScale[0] != lastscale[0] || + ScreenScale[1] != lastscale[1]) + { + GPU::SetFramebufferScale(ScreenScale[0], ScreenScale[1]); + ScreenDrawInited = false; + } + + // emulate + u32 nlines = NDS::RunFrame(); + + if (EmuRunning == 0) break; + uiAreaQueueRedrawAll(MainDrawArea); // framerate limiter based off SDL2_gfx @@ -622,8 +632,6 @@ int EmuThreadFunc(void* burp) if (joybuttons) delete[] joybuttons; - delete[] ScreenBuffer; - NDS::DeInit(); Platform::LAN_DeInit(); @@ -636,16 +644,19 @@ void OnAreaDraw(uiAreaHandler* handler, uiArea* area, uiAreaDrawParams* params) // TODO: recreate bitmap if screen scale changed if (!ScreenDrawInited) { + if (ScreenBitmap[0]) uiDrawFreeBitmap(ScreenBitmap[0]); + if (ScreenBitmap[1]) uiDrawFreeBitmap(ScreenBitmap[1]); + ScreenDrawInited = true; - ScreenBitmap[0] = uiDrawNewBitmap(params->Context, 256*ScreenScale, 192*ScreenScale); - ScreenBitmap[1] = uiDrawNewBitmap(params->Context, 256*ScreenScale, 192*ScreenScale); + ScreenBitmap[0] = uiDrawNewBitmap(params->Context, 256<Context, 256< Date: Tue, 21 May 2019 22:28:46 +0200 Subject: welp. progress --- src/Config.cpp | 2 + src/Config.h | 1 + src/GPU.cpp | 42 +---- src/GPU.h | 2 +- src/GPU2D.cpp | 2 +- src/GPU2D.h | 2 +- src/GPU3D.cpp | 51 ++++--- src/GPU3D.h | 11 +- src/GPU3D_OpenGL.cpp | 144 ++++++++---------- src/GPU3D_Soft.cpp | 15 -- src/libui_sdl/DlgVideoSettings.cpp | 174 ++++++++++++++++----- src/libui_sdl/PlatformConfig.cpp | 6 +- src/libui_sdl/PlatformConfig.h | 3 +- src/libui_sdl/main.cpp | 303 ++++++++++++++++++++----------------- 14 files changed, 403 insertions(+), 355 deletions(-) (limited to 'src/libui_sdl/DlgVideoSettings.cpp') diff --git a/src/Config.cpp b/src/Config.cpp index aca3d4f..42f18c7 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -31,6 +31,7 @@ const char* kConfigFile = "melonDS.ini"; int _3DRenderer; int Threaded3D; +int GL_ScaleFactor; int GL_Antialias; ConfigEntry ConfigFile[] = @@ -38,6 +39,7 @@ ConfigEntry ConfigFile[] = {"3DRenderer", 0, &_3DRenderer, 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}, {"", -1, NULL, 0, NULL, 0} diff --git a/src/Config.h b/src/Config.h index 8dc97d5..6ffc495 100644 --- a/src/Config.h +++ b/src/Config.h @@ -43,6 +43,7 @@ void Save(); extern int _3DRenderer; extern int Threaded3D; +extern int GL_ScaleFactor; extern int GL_Antialias; } diff --git a/src/GPU.cpp b/src/GPU.cpp index 8b94c94..959129e 100644 --- a/src/GPU.cpp +++ b/src/GPU.cpp @@ -73,7 +73,6 @@ u32 VRAMMap_ARM7[2]; int FrontBuffer; u32* Framebuffer[2][2]; -int ScreenScale[2]; bool Accelerated; GPU2D* GPU2D_A; @@ -89,8 +88,8 @@ bool Init() FrontBuffer = 0; Framebuffer[0][0] = NULL; Framebuffer[0][1] = NULL; Framebuffer[1][0] = NULL; Framebuffer[1][1] = NULL; - ScreenScale[0] = -1; ScreenScale[1] = -1; Accelerated = false; - SetDisplaySettings(0, 0, false); + Accelerated = false; + SetDisplaySettings(false); return true; } @@ -247,12 +246,10 @@ void AssignFramebuffers() } } -void SetDisplaySettings(int topscale, int bottomscale, bool accel) -{accel=true; +void SetDisplaySettings(bool accel) +{ if (accel != Accelerated) { - ScreenScale[0] = accel ? 0 : topscale; - int fbsize; if (accel) fbsize = (256*3 + 2) * 192; else fbsize = 256 * 192; @@ -273,35 +270,8 @@ void SetDisplaySettings(int topscale, int bottomscale, bool accel) AssignFramebuffers(); } - if (topscale != ScreenScale[0]) - { - 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); - } - } + GPU2D_A->SetDisplaySettings(accel); + GPU2D_B->SetDisplaySettings(accel); Accelerated = accel; } diff --git a/src/GPU.h b/src/GPU.h index cfa8d7d..b6f6473 100644 --- a/src/GPU.h +++ b/src/GPU.h @@ -75,7 +75,7 @@ void Stop(); void DoSavestate(Savestate* file); -void SetDisplaySettings(int topscale, int bottomscale, bool accel); +void SetDisplaySettings(bool accel); void MapVRAM_AB(u32 bank, u8 cnt); diff --git a/src/GPU2D.cpp b/src/GPU2D.cpp index fe1645e..88249ba 100644 --- a/src/GPU2D.cpp +++ b/src/GPU2D.cpp @@ -215,7 +215,7 @@ void GPU2D::SetFramebuffer(u32* buf) Framebuffer = buf; } -void GPU2D::SetDisplaySettings(int scale, bool accel) +void GPU2D::SetDisplaySettings(bool accel) { Accelerated = accel; diff --git a/src/GPU2D.h b/src/GPU2D.h index eb159f7..78e62f5 100644 --- a/src/GPU2D.h +++ b/src/GPU2D.h @@ -31,7 +31,7 @@ public: void SetEnabled(bool enable) { Enabled = enable; } void SetFramebuffer(u32* buf); - void SetDisplaySettings(int scale, bool accel); + void SetDisplaySettings(bool accel); u8 Read8(u32 addr); u16 Read16(u32 addr); diff --git a/src/GPU3D.cpp b/src/GPU3D.cpp index 04ec55e..0ca3cd4 100644 --- a/src/GPU3D.cpp +++ b/src/GPU3D.cpp @@ -156,6 +156,8 @@ u32 NumCommands, CurCommand, ParamCount, TotalParams; bool GeometryEnabled; bool RenderingEnabled; +int Renderer; + u32 DispCnt; u8 AlphaRefVal, AlphaRef; @@ -275,16 +277,16 @@ bool Init() CmdStallQueue = new FIFO(64); - //if (!SoftRenderer::Init()) return false; - if (!GLRenderer::Init()) return false; + Renderer = -1; + // SetRenderer() will be called to set it up later return true; } void DeInit() { - //SoftRenderer::DeInit(); - GLRenderer::DeInit(); + if (Renderer == 0) SoftRenderer::DeInit(); + else GLRenderer::DeInit(); delete CmdFIFO; delete CmdPIPE; @@ -384,8 +386,8 @@ void Reset() FlushAttributes = 0; ResetRenderingState(); - //SoftRenderer::Reset(); - GLRenderer::Reset(); + if (Renderer == 0) SoftRenderer::Reset(); + else GLRenderer::Reset(); } void DoSavestate(Savestate* file) @@ -607,14 +609,24 @@ void SetEnabled(bool geometry, bool rendering) 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() { - //SoftRenderer::VCount144(); + if (Renderer == 0) SoftRenderer::VCount144(); } @@ -2436,19 +2448,14 @@ void VBlank() void VCount215() { - //SoftRenderer::RenderFrame(); - GLRenderer::RenderFrame(); + if (Renderer == 0) SoftRenderer::RenderFrame(); + else GLRenderer::RenderFrame(); } u32* GetLine(int line) { - //return SoftRenderer::GetLine(line); - return GLRenderer::GetLine(line); -} - -void SetupAccelFrame() -{ - GLRenderer::SetupAccelFrame(); + if (Renderer == 0) return SoftRenderer::GetLine(line); + else return GLRenderer::GetLine(line); } diff --git a/src/GPU3D.h b/src/GPU3D.h index 280b99e..36c6c0f 100644 --- a/src/GPU3D.h +++ b/src/GPU3D.h @@ -97,8 +97,8 @@ void Reset(); void DoSavestate(Savestate* file); void SetEnabled(bool geometry, bool rendering); -void SetDisplaySettings(int scale, bool accel); -int GetScale(); + +int SetRenderer(int renderer); void ExecuteCommand(); @@ -129,15 +129,11 @@ bool Init(); void DeInit(); void Reset(); -void SetDisplaySettings(int scale, bool accel); -int GetScale(); - void SetupRenderThread(); void VCount144(); void RenderFrame(); u32* GetLine(int line); -void SetupAccelFrame(); } @@ -148,8 +144,7 @@ bool Init(); void DeInit(); void Reset(); -void SetDisplaySettings(int scale, bool accel); -int GetScale(); +void SetDisplaySettings(int scale, bool antialias); void RenderFrame(); void PrepareCaptureFrame(); diff --git a/src/GPU3D_OpenGL.cpp b/src/GPU3D_OpenGL.cpp index 0bb7e42..30c77bf 100644 --- a/src/GPU3D_OpenGL.cpp +++ b/src/GPU3D_OpenGL.cpp @@ -95,13 +95,13 @@ GLuint TexMemID; GLuint TexPalMemID; int ScaleFactor; -bool Accelerated; +bool Antialias; int ScreenW, ScreenH; GLuint FramebufferTex[8]; int FrontBuffer; 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: 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_STENCIL_TEST); @@ -317,6 +297,12 @@ bool Init() glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[1]); 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_COLOR_ATTACHMENT1, FramebufferTex[7], 0); glDrawBuffers(2, fbassign); @@ -324,8 +310,9 @@ bool Init() glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[0]); 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); - glBlendEquationSeparatei(0, GL_ADD, GL_MAX); + glBlendEquationSeparatei(0, GL_FUNC_ADD, GL_MAX); glBlendFuncSeparatei(1, GL_ONE, GL_ZERO, GL_ONE, GL_ZERO); 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_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); - +printf("init done. %04X\n", glGetError()); return true; } @@ -375,44 +362,55 @@ void DeInit() void Reset() { - // } -void SetDisplaySettings(int scale, bool accel) +void SetDisplaySettings(int scale, bool antialias) { + if (antialias) scale *= 2; + ScaleFactor = scale; - Accelerated = accel; - - // TODO: antialiasing setting - ScreenW = 256 << scale; - ScreenH = 192 << scale; - - glBindTexture(GL_TEXTURE_2D, FramebufferTex[0]); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ScreenW, ScreenH, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glBindTexture(GL_TEXTURE_2D, FramebufferTex[1]); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ScreenW, ScreenH, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glBindTexture(GL_TEXTURE_2D, FramebufferTex[2]); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ScreenW/2, ScreenH/2, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glBindTexture(GL_TEXTURE_2D, FramebufferTex[4]); - 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[5]); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, ScreenW, ScreenH, 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); + Antialias = antialias; - glBindBuffer(GL_PIXEL_PACK_BUFFER, PixelbufferID); - glBufferData(GL_PIXEL_PACK_BUFFER, 256*192*4, NULL, GL_DYNAMIC_READ); + ScreenW = 256 * scale; + ScreenH = 192 * scale; - if (Framebuffer) delete[] Framebuffer; - if (accel) Framebuffer = new u32[256*192]; - else Framebuffer = new u32[ScreenW*ScreenH]; -} + if (!antialias) + { + glBindTexture(GL_TEXTURE_2D, FramebufferTex[0]); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ScreenW, ScreenH, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glBindTexture(GL_TEXTURE_2D, FramebufferTex[1]); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ScreenW, ScreenH, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glBindTexture(GL_TEXTURE_2D, FramebufferTex[2]); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glBindTexture(GL_TEXTURE_2D, FramebufferTex[4]); + 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[5]); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, ScreenW, ScreenH, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, NULL); + glBindTexture(GL_TEXTURE_2D, FramebufferTex[6]); + 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); + } -int GetScale() -{ - return ScaleFactor; + glBindBuffer(GL_PIXEL_PACK_BUFFER, PixelbufferID); + glBufferData(GL_PIXEL_PACK_BUFFER, 256*192*4, NULL, GL_DYNAMIC_READ); } @@ -496,10 +494,10 @@ void BuildPolygons(RendererPolygon* polygons, int npolys) while (z > 0xFFFF) { z >>= 1; zshift++; } u32 x, y; - if (ScaleFactor > 0) + if (ScaleFactor > 1) { - x = vtx->HiresPosition[0] >> (4-ScaleFactor); - y = vtx->HiresPosition[1] >> (4-ScaleFactor); + x = (vtx->HiresPosition[0] * ScaleFactor) >> 4; + y = (vtx->HiresPosition[1] * ScaleFactor) >> 4; } else { @@ -829,8 +827,8 @@ void RenderFrame() glViewport(0, 0, ScreenW, ScreenH); - glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[FrontBuffer]); - FrontBuffer = FrontBuffer ? 0 : 1; + if (Antialias) glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[2]); + else glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[FrontBuffer]); glDisable(GL_BLEND); glColorMaski(0, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); @@ -902,26 +900,15 @@ void RenderFrame() RenderSceneChunk(0, 192); } - if (false) + if (Antialias) { - glBindFramebuffer(GL_READ_FRAMEBUFFER, FramebufferID[0]); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferID[1]); + glBindFramebuffer(GL_READ_FRAMEBUFFER, FramebufferID[2]); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferID[FrontBuffer]); 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) - { - glReadBuffer(GL_COLOR_ATTACHMENT0); - glBindBuffer(GL_PIXEL_PACK_BUFFER, PixelbufferID); - glReadPixels(0, 0, 256< 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)); } diff --git a/src/libui_sdl/PlatformConfig.cpp b/src/libui_sdl/PlatformConfig.cpp index 065d9c2..f700ecb 100644 --- a/src/libui_sdl/PlatformConfig.cpp +++ b/src/libui_sdl/PlatformConfig.cpp @@ -40,9 +40,8 @@ int ScreenLayout; int ScreenSizing; int ScreenFilter; -int ScreenScale; +int ScreenUseGL; int ScreenRatio; -int ScreenScaleMode; int LimitFPS; @@ -105,9 +104,8 @@ ConfigEntry PlatformConfigFile[] = {"ScreenSizing", 0, &ScreenSizing, 0, 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}, - {"ScreenScaleMode", 0, &ScreenScaleMode, 0, NULL, 0}, {"LimitFPS", 0, &LimitFPS, 1, NULL, 0}, diff --git a/src/libui_sdl/PlatformConfig.h b/src/libui_sdl/PlatformConfig.h index 0cff1d2..013a0a7 100644 --- a/src/libui_sdl/PlatformConfig.h +++ b/src/libui_sdl/PlatformConfig.h @@ -48,9 +48,8 @@ extern int ScreenLayout; extern int ScreenSizing; extern int ScreenFilter; -extern int ScreenScale; +extern int ScreenUseGL; extern int ScreenRatio; -extern int ScreenScaleMode; extern int LimitFPS; diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index b499da7..f0d7b74 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -100,6 +100,9 @@ char PrevSRAMPath[1024]; // for savestate 'undo load' bool SavestateLoaded; +bool Screen_UseGL; +int _3DRenderer; + bool ScreenDrawInited = false; uiDrawBitmap* ScreenBitmap[2] = {NULL,NULL}; @@ -117,8 +120,7 @@ float GL_ScreenVertices[2 * 3*2 * 4]; // position/texcoord GLuint GL_ScreenTexture; bool GL_ScreenSizeDirty; -int ScreenScale[3]; -int ScreenScaleMode; +int GL_3DScale; int ScreenGap = 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()) return false; if (!OpenGL_BuildShaderProgram(kScreenVS, kScreenFS, GL_ScreenShader, "ScreenShader")) return false; -printf("GL init looking good\n"); + GLuint uni_id; 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); GL_ScreenSizeDirty = true; -printf("finished w/ err: %04X\n", glGetError()); + return true; } -void GLDrawing_DeInit() +void GLScreen_DeInit() { glDeleteTextures(1, &GL_ScreenTexture); @@ -225,7 +227,7 @@ void GLDrawing_DeInit() OpenGL_DeleteShaderProgram(GL_ScreenShader); } -void GLDrawing_DrawScreen() +void GLScreen_DrawScreen() { if (GL_ScreenSizeDirty) { @@ -233,8 +235,8 @@ void GLDrawing_DrawScreen() GL_ShaderConfig.uScreenSize[0] = WindowWidth; 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); void* unibuf = glMapBuffer(GL_UNIFORM_BUFFER, GL_WRITE_ONLY); if (unibuf) memcpy(unibuf, &GL_ShaderConfig, sizeof(GL_ShaderConfig)); @@ -257,8 +259,8 @@ void GLDrawing_DrawScreen() x1 = TopScreenRect.X + TopScreenRect.Width; y1 = TopScreenRect.Y + TopScreenRect.Height; - scwidth = 256;// << ScreenScale[0]; - scheight = 192;// << ScreenScale[0]; + scwidth = 256; + scheight = 192; switch (ScreenRotation) { @@ -303,8 +305,8 @@ void GLDrawing_DrawScreen() x1 = BottomScreenRect.X + BottomScreenRect.Width; y1 = BottomScreenRect.Y + BottomScreenRect.Height; - scwidth = 256;// << ScreenScale[1]; - scheight = 192;// << ScreenScale[1]; + scwidth = 256; + scheight = 192; switch (ScreenRotation) { @@ -376,7 +378,8 @@ void GLDrawing_DrawScreen() GL_UNSIGNED_BYTE, GPU::Framebuffer[frontbuf][1]); glActiveTexture(GL_TEXTURE1); - GPU3D::SetupAccelFrame(); + if (_3DRenderer != 0) + GPU3D::GLRenderer::SetupAccelFrame(); glBindBuffer(GL_ARRAY_BUFFER, GL_ScreenVertexBufferID); glBindVertexArray(GL_ScreenVertexArrayID); @@ -384,7 +387,89 @@ void GLDrawing_DrawScreen() glFlush(); 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) @@ -642,8 +727,11 @@ void FeedMicInput() int EmuThreadFunc(void* burp) { - uiGLMakeContextCurrent(GLContext); - GLDrawing_Init(); + if (Screen_UseGL) + { + uiGLMakeContextCurrent(GLContext); + GLScreen_Init(); + } NDS::Init(); @@ -652,13 +740,8 @@ int EmuThreadFunc(void* burp) MainScreenPos[2] = 0; AutoScreenSizing = 0; - // FIXME - ScreenScale[2] = Config::ScreenScale; - ScreenScale[0] = ScreenScale[2]; - ScreenScale[1] = ScreenScale[2]; - - int lastscale[2] = {ScreenScale[0], ScreenScale[1]}; - GPU::SetDisplaySettings(ScreenScale[0], ScreenScale[1], false); + GPU::SetDisplaySettings(_3DRenderer != 0); + if (Screen_UseGL) uiGLMakeContextCurrent(NULL); Touching = false; KeyInputMask = 0xFFF; @@ -773,7 +856,7 @@ int EmuThreadFunc(void* burp) // microphone input FeedMicInput(); - uiGLMakeContextCurrent(GLContext); + if (Screen_UseGL) uiGLMakeContextCurrent(GLContext); // 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 u32 nlines = NDS::RunFrame(); if (EmuRunning == 0) break; - GLDrawing_DrawScreen(); - - //uiAreaQueueRedrawAll(MainDrawArea); - //uiGLSwapBuffers(GLContext); + if (Screen_UseGL) + { + GLScreen_DrawScreen(); + } + uiAreaQueueRedrawAll(MainDrawArea); // framerate limiter based off SDL2_gfx float framerate = (1000.0f * nlines) / (60.0f * 263.0f); @@ -869,13 +946,16 @@ int EmuThreadFunc(void* burp) if (EmuRunning == 2) { - uiGLMakeContextCurrent(GLContext); - - //uiAreaQueueRedrawAll(MainDrawArea); - //uiGLSwapBuffers(GLContext); - GLDrawing_DrawScreen(); + if (Screen_UseGL) + { + uiGLMakeContextCurrent(GLContext); + GLScreen_DrawScreen(); + } + uiAreaQueueRedrawAll(MainDrawArea); } + if (Screen_UseGL) uiGLMakeContextCurrent(NULL); + EmuStatus = EmuRunning; SDL_Delay(100); @@ -889,7 +969,7 @@ int EmuThreadFunc(void* burp) NDS::DeInit(); Platform::LAN_DeInit(); - GLDrawing_DeInit(); + if (Screen_UseGL) GLScreen_DeInit(); return 44203; } @@ -897,22 +977,21 @@ int EmuThreadFunc(void* burp) void OnAreaDraw(uiAreaHandler* handler, uiArea* area, uiAreaDrawParams* params) { - // TODO: recreate bitmap if screen scale changed if (!ScreenDrawInited) { if (ScreenBitmap[0]) uiDrawFreeBitmap(ScreenBitmap[0]); if (ScreenBitmap[1]) uiDrawFreeBitmap(ScreenBitmap[1]); ScreenDrawInited = true; - ScreenBitmap[0] = uiDrawNewBitmap(params->Context, 256<Context, 256<Context, 256, 192); + ScreenBitmap[1] = uiDrawNewBitmap(params->Context, 256, 192); } if (!ScreenBitmap[0] || !ScreenBitmap[1]) return; if (!GPU::Framebuffer[0][0]) return; - uiRect top = {0, 0, 256< 8) GL_3DScale = 8; MainWindow = uiNewWindow("melonDS " MELONDS_VERSION, w, h, Config::WindowMaximized, 1, 1); uiWindowOnClosing(MainWindow, OnCloseWindow, NULL); @@ -2346,11 +2378,7 @@ int main(int argc, char** argv) MainDrawAreaHandler.Resize = OnAreaResize; ScreenDrawInited = false; - //MainDrawArea = uiNewArea(&MainDrawAreaHandler); - MainDrawArea = uiNewGLArea(&MainDrawAreaHandler, kGLVersions); - uiWindowSetChild(MainWindow, uiControl(MainDrawArea)); - uiControlSetMinSize(uiControl(MainDrawArea), 256, 384); - uiAreaSetBackgroundColor(MainDrawArea, 0, 0, 0); // TODO: make configurable? + ScreenCreateArea(Screen_UseGL); ScreenRotation = Config::ScreenRotation; ScreenGap = Config::ScreenGap; @@ -2377,15 +2405,6 @@ int main(int argc, char** argv) 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; memset(&whatIwant, 0, sizeof(SDL_AudioSpec)); whatIwant.freq = 47340; @@ -2454,8 +2473,6 @@ int main(int argc, char** argv) } } - uiControlShow(uiControl(MainWindow)); - uiControlSetFocus(uiControl(MainDrawArea)); uiMain(); EmuRunning = 0; -- cgit v1.2.3 From 667dee67540482660fddd6ddd9bf7f7f639693aa Mon Sep 17 00:00:00 2001 From: Arisotura Date: Fri, 24 May 2019 02:04:41 +0200 Subject: more code botching it's less shitty tho but still has bugs --- src/GPU3D.cpp | 26 ++- src/GPU3D.h | 9 +- src/GPU3D_OpenGL.cpp | 9 +- src/libui_sdl/DlgVideoSettings.cpp | 17 +- src/libui_sdl/main.cpp | 334 +++++++++++++------------------------ 5 files changed, 164 insertions(+), 231 deletions(-) (limited to 'src/libui_sdl/DlgVideoSettings.cpp') diff --git a/src/GPU3D.cpp b/src/GPU3D.cpp index 0ca3cd4..115b31f 100644 --- a/src/GPU3D.cpp +++ b/src/GPU3D.cpp @@ -22,6 +22,7 @@ #include "NDS.h" #include "GPU.h" #include "FIFO.h" +#include "Config.h" // 3D engine notes @@ -610,12 +611,9 @@ void SetEnabled(bool geometry, bool rendering) } -int SetRenderer(int renderer) +int InitRenderer(bool hasGL) { - //if (renderer == Renderer) return renderer; - - //if (Renderer == 0) SoftRenderer::DeInit(); - //else GLRenderer::DeInit(); + int renderer = hasGL ? Config::_3DRenderer : 0; if (renderer == 1) { @@ -629,6 +627,24 @@ int SetRenderer(int renderer) 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) diff --git a/src/GPU3D.h b/src/GPU3D.h index 36c6c0f..4e7c01a 100644 --- a/src/GPU3D.h +++ b/src/GPU3D.h @@ -90,6 +90,8 @@ extern u32 RenderNumPolygons; extern u64 Timestamp; +extern int Renderer; + bool Init(); void DeInit(); void Reset(); @@ -98,7 +100,9 @@ void DoSavestate(Savestate* file); void SetEnabled(bool geometry, bool rendering); -int SetRenderer(int renderer); +int InitRenderer(bool hasGL); +void DeInitRenderer(); +void UpdateRendererConfig(); void ExecuteCommand(); @@ -111,7 +115,6 @@ void VCount144(); void VBlank(); void VCount215(); u32* GetLine(int line); -void SetupAccelFrame(); void WriteToGXFIFO(u32 val); @@ -144,7 +147,7 @@ bool Init(); void DeInit(); void Reset(); -void SetDisplaySettings(int scale, bool antialias); +void UpdateDisplaySettings(); void RenderFrame(); void PrepareCaptureFrame(); diff --git a/src/GPU3D_OpenGL.cpp b/src/GPU3D_OpenGL.cpp index 30c77bf..cbf5abd 100644 --- a/src/GPU3D_OpenGL.cpp +++ b/src/GPU3D_OpenGL.cpp @@ -20,6 +20,7 @@ #include #include "NDS.h" #include "GPU.h" +#include "Config.h" #include "OpenGLSupport.h" #include "GPU3D_OpenGL_shaders.h" @@ -362,10 +363,14 @@ void DeInit() void Reset() { + UpdateDisplaySettings(); } -void SetDisplaySettings(int scale, bool antialias) +void UpdateDisplaySettings() { + int scale = Config::GL_ScaleFactor; + bool antialias = false; //Config::GL_Antialias; + if (antialias) scale *= 2; ScaleFactor = scale; @@ -950,7 +955,7 @@ u32* GetLine(int line) } void SetupAccelFrame() -{ +{printf("morp %04X\n", glGetError()); glBindTexture(GL_TEXTURE_2D, FramebufferTex[FrontBuffer]); } diff --git a/src/libui_sdl/DlgVideoSettings.cpp b/src/libui_sdl/DlgVideoSettings.cpp index 3102873..26c0109 100644 --- a/src/libui_sdl/DlgVideoSettings.cpp +++ b/src/libui_sdl/DlgVideoSettings.cpp @@ -83,13 +83,14 @@ void OnRendererChanged(uiRadioButtons* rb, void* blarg) printf("RENDERER CHANGE: %d\n", id); Config::_3DRenderer = id; UpdateControls(); - ApplyNewSettings(2); + ApplyNewSettings(3); } void OnGLDisplayChanged(uiCheckbox* cb, void* blarg) { Config::ScreenUseGL = uiCheckboxChecked(cb); ApplyNewSettings(2); + uiControlSetFocus(uiControl(cb)); } void OnThreaded3DChanged(uiCheckbox* cb, void* blarg) @@ -103,21 +104,23 @@ void OnResolutionChanged(uiCombobox* cb, void* blarg) int id = uiComboboxSelected(cb); Config::GL_ScaleFactor = id+1; - ApplyNewSettings(3); + ApplyNewSettings(0); } void OnAntialiasChanged(uiCheckbox* cb, void* blarg) { Config::GL_Antialias = uiCheckboxChecked(cb); - ApplyNewSettings(3); + ApplyNewSettings(0); } void OnCancel(uiButton* btn, void* blarg) { + bool apply0 = false; + if (old_renderer != Config::_3DRenderer) { Config::_3DRenderer = old_renderer; - ApplyNewSettings(2); + ApplyNewSettings(3); } if (old_gldisplay != Config::ScreenUseGL) @@ -129,7 +132,7 @@ void OnCancel(uiButton* btn, void* blarg) if (old_threaded3D != Config::Threaded3D) { Config::Threaded3D = old_threaded3D; - ApplyNewSettings(0); + apply0 = true; } if (old_resolution != Config::GL_ScaleFactor || @@ -137,9 +140,11 @@ void OnCancel(uiButton* btn, void* blarg) { Config::GL_ScaleFactor = old_resolution; Config::GL_Antialias = old_antialias; - ApplyNewSettings(3); + apply0 = true; } + if (apply0) ApplyNewSettings(0); + uiControlDestroy(uiControl(win)); opened = false; } diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index 1f41bbe..efebc8d 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -104,7 +104,6 @@ char PrevSRAMPath[1024]; // for savestate 'undo load' bool SavestateLoaded; bool Screen_UseGL; -int _3DRenderer; bool ScreenDrawInited = false; uiDrawBitmap* ScreenBitmap[2] = {NULL,NULL}; @@ -164,6 +163,10 @@ void LoadState(int slot); void UndoStateLoad(); void GetSavestateName(int slot, char* filename, int len); +void CreateMainWindow(bool opengl); +void DestroyMainWindow(); +void RecreateMainWindow(bool opengl); + bool GLScreen_Init() @@ -239,7 +242,7 @@ void GLScreen_DrawScreen() GL_ShaderConfig.uScreenSize[0] = WindowWidth; GL_ShaderConfig.uScreenSize[1] = WindowHeight; GL_ShaderConfig.u3DScale = GL_3DScale; -printf("updating GL scale: %d\n", GL_3DScale); + glBindBuffer(GL_UNIFORM_BUFFER, GL_ShaderConfigUBO); void* unibuf = glMapBuffer(GL_UNIFORM_BUFFER, GL_WRITE_ONLY); if (unibuf) memcpy(unibuf, &GL_ShaderConfig, sizeof(GL_ShaderConfig)); @@ -381,7 +384,7 @@ printf("updating GL scale: %d\n", GL_3DScale); GL_UNSIGNED_BYTE, GPU::Framebuffer[frontbuf][1]); glActiveTexture(GL_TEXTURE1); - if (_3DRenderer != 0) + if (GPU3D::Renderer != 0) GPU3D::GLRenderer::SetupAccelFrame(); glBindBuffer(GL_ARRAY_BUFFER, GL_ScreenVertexBufferID); @@ -392,89 +395,6 @@ printf("updating GL scale: %d\n", GL_3DScale); uiGLSwapBuffers(GLContext); } -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) { SDL_AudioSpec format; @@ -730,12 +650,6 @@ void FeedMicInput() int EmuThreadFunc(void* burp) { - if (Screen_UseGL) - { - uiGLMakeContextCurrent(GLContext); - GLScreen_Init(); - } - NDS::Init(); MainScreenPos[0] = 0; @@ -743,8 +657,18 @@ int EmuThreadFunc(void* burp) MainScreenPos[2] = 0; AutoScreenSizing = 0; - GPU::SetDisplaySettings(_3DRenderer != 0); - if (Screen_UseGL) uiGLMakeContextCurrent(NULL); + if (Screen_UseGL) + { + uiGLMakeContextCurrent(GLContext); + GPU3D::InitRenderer(true); + GPU::SetDisplaySettings(GPU3D::Renderer != 0); + uiGLMakeContextCurrent(NULL); + } + else + { + GPU3D::InitRenderer(false); + GPU::SetDisplaySettings(false); + } Touching = false; KeyInputMask = 0xFFF; @@ -895,10 +819,7 @@ int EmuThreadFunc(void* burp) if (EmuRunning == 0) break; - if (Screen_UseGL) - { - GLScreen_DrawScreen(); - } + if (Screen_UseGL) GLScreen_DrawScreen(); uiAreaQueueRedrawAll(MainDrawArea); // framerate limiter based off SDL2_gfx @@ -1731,7 +1652,7 @@ void OnCloseByMenu(uiMenuItem* item, uiWindow* window, void* blarg) EmuRunning = 3; while (EmuStatus != 3); - uiControlDestroy(uiControl(window)); + DestroyMainWindow(); uiQuit(); } @@ -1851,22 +1772,10 @@ void OnOpenHotkeyConfig(uiMenuItem* item, uiWindow* window, void* blarg) { DlgInputConfig::Open(1); } -void zarg(); + void OnOpenVideoSettings(uiMenuItem* item, uiWindow* window, void* blarg) { - //DlgVideoSettings::Open(); - int zerp = EmuRunning; - EmuRunning = 3; - while (EmuStatus != 3); - - int winX, winY; - uiWindowPosition(MainWindow, &winX, &winY); - uiControlDestroy(uiControl(window)); - - zarg(); - uiWindowSetPosition(MainWindow, winX, winY); - - EmuRunning = zerp; + DlgVideoSettings::Open(); } void OnOpenAudioSettings(uiMenuItem* item, uiWindow* window, void* blarg) @@ -2037,23 +1946,18 @@ void OnSetLimitFPS(uiMenuItem* item, uiWindow* window, void* blarg) void ApplyNewSettings(int type) { - if (type == 2) - { - bool usegl = Config::ScreenUseGL || (Config::_3DRenderer != 0); - ScreenSetMethod(usegl); - return; - } - - if (!RunningSomething) return; + if (!RunningSomething && type != 2) return; int prevstatus = EmuRunning; EmuRunning = 3; while (EmuStatus != 3); - if (type == 0) // software renderer thread + if (type == 0) // 3D renderer settings { - if (_3DRenderer == 0) - GPU3D::SoftRenderer::SetupRenderThread(); + GPU3D::UpdateRendererConfig(); + + GL_3DScale = Config::GL_ScaleFactor; // dorp + GL_ScreenSizeDirty = true; } else if (type == 1) // wifi settings { @@ -2066,20 +1970,37 @@ void ApplyNewSettings(int type) Platform::LAN_DeInit(); Platform::LAN_Init(); } - else if (type == 3) // GL renderer settings + else if (type == 2) // video output method { - GL_3DScale = Config::GL_ScaleFactor; - - if (_3DRenderer != 0) + bool usegl = Config::ScreenUseGL || (Config::_3DRenderer != 0); + if (usegl != Screen_UseGL) { - uiGLMakeContextCurrent(GLContext); - printf("%04X\n", glGetError()); - printf("%04X\n", glGetError()); - GPU3D::GLRenderer::SetDisplaySettings(Config::GL_ScaleFactor, Config::GL_Antialias); - uiGLMakeContextCurrent(NULL); - GL_ScreenSizeDirty = true; + Screen_UseGL = usegl; + + if (RunningSomething) + { + if (usegl) uiGLMakeContextCurrent(GLContext); + GPU3D::DeInitRenderer(); + if (usegl) uiGLMakeContextCurrent(NULL); + } + + RecreateMainWindow(usegl); + + if (RunningSomething) + { + if (Screen_UseGL) uiGLMakeContextCurrent(GLContext); + GPU3D::InitRenderer(Screen_UseGL); + if (Screen_UseGL) uiGLMakeContextCurrent(NULL); + } } } + else if (type == 3) // 3D renderer + { + if (Screen_UseGL) uiGLMakeContextCurrent(GLContext); + GPU3D::DeInitRenderer(); + GPU3D::InitRenderer(Screen_UseGL); + if (Screen_UseGL) uiGLMakeContextCurrent(NULL); + } EmuRunning = prevstatus; } @@ -2251,24 +2172,11 @@ void CreateMainWindowMenu() uiMenuItemOnClicked(MenuItem_LimitFPS, OnSetLimitFPS, NULL); } -void zarg() +void CreateMainWindow(bool opengl) { - int w = Config::WindowWidth; - int h = Config::WindowHeight; - //if (w < 256) w = 256; - //if (h < 384) h = 384; - - WindowWidth = w; - WindowHeight = h; - - Screen_UseGL = Config::ScreenUseGL || (Config::_3DRenderer != 0); - _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, + WindowWidth, WindowHeight, + Config::WindowMaximized, 1, 1); uiWindowOnClosing(MainWindow, OnCloseWindow, NULL); uiWindowSetDropTarget(MainWindow, 1); @@ -2277,40 +2185,57 @@ void zarg() uiWindowOnGetFocus(MainWindow, OnGetFocus, NULL); uiWindowOnLoseFocus(MainWindow, OnLoseFocus, NULL); - MainDrawAreaHandler.Draw = OnAreaDraw; - MainDrawAreaHandler.MouseEvent = OnAreaMouseEvent; - MainDrawAreaHandler.MouseCrossed = OnAreaMouseCrossed; - MainDrawAreaHandler.DragBroken = OnAreaDragBroken; - MainDrawAreaHandler.KeyEvent = OnAreaKeyEvent; - MainDrawAreaHandler.Resize = OnAreaResize; - ScreenDrawInited = false; - ScreenCreateArea(Screen_UseGL); + bool opengl_good = opengl; - ScreenRotation = Config::ScreenRotation; - ScreenGap = Config::ScreenGap; - ScreenLayout = Config::ScreenLayout; - ScreenSizing = Config::ScreenSizing; + if (!opengl) MainDrawArea = uiNewArea(&MainDrawAreaHandler); + else MainDrawArea = uiNewGLArea(&MainDrawAreaHandler, kGLVersions); -#define SANITIZE(var, min, max) if ((var < min) || (var > max)) var = 0; - SANITIZE(ScreenRotation, 0, 3); - SANITIZE(ScreenLayout, 0, 2); - SANITIZE(ScreenSizing, 0, 3); -#undef SANITIZE + uiWindowSetChild(MainWindow, uiControl(MainDrawArea)); + uiControlSetMinSize(uiControl(MainDrawArea), 256, 384); + uiAreaSetBackgroundColor(MainDrawArea, 0, 0, 0); - /*uiMenuItemSetChecked(MenuItem_SavestateSRAMReloc, Config::SavestateRelocSRAM?1:0); + uiControlShow(uiControl(MainWindow)); + uiControlSetFocus(uiControl(MainDrawArea)); - uiMenuItemSetChecked(MenuItem_ScreenRot[ScreenRotation], 1); - uiMenuItemSetChecked(MenuItem_ScreenLayout[ScreenLayout], 1); - uiMenuItemSetChecked(MenuItem_ScreenSizing[ScreenSizing], 1); + if (opengl_good) + { + GLContext = uiAreaGetGLContext(MainDrawArea); + if (!GLContext) opengl_good = false; + } + if (opengl_good) + { + uiGLMakeContextCurrent(GLContext); + if (!GLScreen_Init()) opengl_good = false; + uiGLMakeContextCurrent(NULL); + } - for (int i = 0; i < 6; i++) + if (opengl && !opengl_good) { - if (ScreenGap == kScreenGap[i]) - uiMenuItemSetChecked(MenuItem_ScreenGap[i], 1); - }*/ + printf("OpenGL: initialization failed\n"); + RecreateMainWindow(false); + Screen_UseGL = false; + } +} - OnSetScreenRotation(MenuItem_ScreenRot[ScreenRotation], MainWindow, (void*)&kScreenRot[ScreenRotation]); +void DestroyMainWindow() +{ + uiControlDestroy(uiControl(MainWindow)); + + if (ScreenBitmap[0]) uiDrawFreeBitmap(ScreenBitmap[0]); + if (ScreenBitmap[1]) uiDrawFreeBitmap(ScreenBitmap[1]); + + ScreenBitmap[0] = NULL; + ScreenBitmap[1] = NULL; +} + +void RecreateMainWindow(bool opengl) +{ + int winX, winY; + uiWindowPosition(MainWindow, &winX, &winY); + DestroyMainWindow(); + CreateMainWindow(opengl); + uiWindowSetPosition(MainWindow, winX, winY); } @@ -2417,49 +2342,23 @@ int main(int argc, char** argv) CreateMainWindowMenu(); - int w = Config::WindowWidth; - int h = Config::WindowHeight; - //if (w < 256) w = 256; - //if (h < 384) h = 384; + MainDrawAreaHandler.Draw = OnAreaDraw; + MainDrawAreaHandler.MouseEvent = OnAreaMouseEvent; + MainDrawAreaHandler.MouseCrossed = OnAreaMouseCrossed; + MainDrawAreaHandler.DragBroken = OnAreaDragBroken; + MainDrawAreaHandler.KeyEvent = OnAreaKeyEvent; + MainDrawAreaHandler.Resize = OnAreaResize; - WindowWidth = w; - WindowHeight = h; + WindowWidth = Config::WindowWidth; + WindowHeight = Config::WindowHeight; Screen_UseGL = Config::ScreenUseGL || (Config::_3DRenderer != 0); - _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); - uiWindowOnClosing(MainWindow, OnCloseWindow, NULL); - - uiWindowSetDropTarget(MainWindow, 1); - uiWindowOnDropFile(MainWindow, OnDropFile, NULL); - - uiWindowOnGetFocus(MainWindow, OnGetFocus, NULL); - uiWindowOnLoseFocus(MainWindow, OnLoseFocus, NULL); - - //uiMenuItemDisable(MenuItem_SaveState); - //uiMenuItemDisable(MenuItem_LoadState); - for (int i = 0; i < 9; i++) uiMenuItemDisable(MenuItem_SaveStateSlot[i]); - for (int i = 0; i < 9; i++) uiMenuItemDisable(MenuItem_LoadStateSlot[i]); - uiMenuItemDisable(MenuItem_UndoStateLoad); - - uiMenuItemDisable(MenuItem_Pause); - uiMenuItemDisable(MenuItem_Reset); - uiMenuItemDisable(MenuItem_Stop); - - MainDrawAreaHandler.Draw = OnAreaDraw; - MainDrawAreaHandler.MouseEvent = OnAreaMouseEvent; - MainDrawAreaHandler.MouseCrossed = OnAreaMouseCrossed; - MainDrawAreaHandler.DragBroken = OnAreaDragBroken; - MainDrawAreaHandler.KeyEvent = OnAreaKeyEvent; - MainDrawAreaHandler.Resize = OnAreaResize; - - ScreenDrawInited = false; - ScreenCreateArea(Screen_UseGL); + CreateMainWindow(Screen_UseGL); ScreenRotation = Config::ScreenRotation; ScreenGap = Config::ScreenGap; @@ -2472,6 +2371,14 @@ int main(int argc, char** argv) SANITIZE(ScreenSizing, 0, 3); #undef SANITIZE + for (int i = 0; i < 9; i++) uiMenuItemDisable(MenuItem_SaveStateSlot[i]); + for (int i = 0; i < 9; i++) uiMenuItemDisable(MenuItem_LoadStateSlot[i]); + uiMenuItemDisable(MenuItem_UndoStateLoad); + + uiMenuItemDisable(MenuItem_Pause); + uiMenuItemDisable(MenuItem_Reset); + uiMenuItemDisable(MenuItem_Stop); + uiMenuItemSetChecked(MenuItem_SavestateSRAMReloc, Config::SavestateRelocSRAM?1:0); uiMenuItemSetChecked(MenuItem_ScreenRot[ScreenRotation], 1); @@ -2575,9 +2482,6 @@ int main(int argc, char** argv) Config::Save(); - if (ScreenBitmap[0]) uiDrawFreeBitmap(ScreenBitmap[0]); - if (ScreenBitmap[1]) uiDrawFreeBitmap(ScreenBitmap[1]); - uiUninit(); SDL_Quit(); delete[] EmuDirectory; -- cgit v1.2.3 From 79ea104931fd50039dd903eb6a12f40235e6f004 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Fri, 24 May 2019 02:12:46 +0200 Subject: properly recreate window based on changes to either video output method or 3D renderer --- src/libui_sdl/DlgVideoSettings.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'src/libui_sdl/DlgVideoSettings.cpp') diff --git a/src/libui_sdl/DlgVideoSettings.cpp b/src/libui_sdl/DlgVideoSettings.cpp index 26c0109..329c79e 100644 --- a/src/libui_sdl/DlgVideoSettings.cpp +++ b/src/libui_sdl/DlgVideoSettings.cpp @@ -80,10 +80,16 @@ int OnCloseWindow(uiWindow* window, void* blarg) void OnRendererChanged(uiRadioButtons* rb, void* blarg) { int id = uiRadioButtonsSelected(rb); -printf("RENDERER CHANGE: %d\n", id); + bool old_usegl = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0); + Config::_3DRenderer = id; UpdateControls(); - ApplyNewSettings(3); + + bool new_usegl = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0); + if (new_usegl != old_usegl) + ApplyNewSettings(2); + else + ApplyNewSettings(3); } void OnGLDisplayChanged(uiCheckbox* cb, void* blarg) @@ -116,17 +122,25 @@ void OnAntialiasChanged(uiCheckbox* cb, void* blarg) void OnCancel(uiButton* btn, void* blarg) { bool apply0 = false; + bool apply2 = false; + bool apply3 = false; + + bool old_usegl = (old_gldisplay != 0) || (old_renderer != 0); + bool new_usegl = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0); if (old_renderer != Config::_3DRenderer) { Config::_3DRenderer = old_renderer; - ApplyNewSettings(3); + apply3 = true; } if (old_gldisplay != Config::ScreenUseGL) { Config::ScreenUseGL = old_gldisplay; - ApplyNewSettings(2); + } + if (old_usegl != new_usegl) + { + apply2 = true; } if (old_threaded3D != Config::Threaded3D) @@ -143,6 +157,8 @@ void OnCancel(uiButton* btn, void* blarg) apply0 = true; } + if (apply2) ApplyNewSettings(2); + else if (apply3) ApplyNewSettings(3); if (apply0) ApplyNewSettings(0); uiControlDestroy(uiControl(win)); -- cgit v1.2.3 From af581513fb98e37b6c8b3d856ad7f63d4d905040 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sat, 25 May 2019 20:51:26 +0200 Subject: * remove old 'threaded 3D' setting from emu settings dialog * remove 'antialiasing' for now --- src/libui_sdl/DlgEmuSettings.cpp | 8 -------- src/libui_sdl/DlgVideoSettings.cpp | 16 ++++++++-------- 2 files changed, 8 insertions(+), 16 deletions(-) (limited to 'src/libui_sdl/DlgVideoSettings.cpp') diff --git a/src/libui_sdl/DlgEmuSettings.cpp b/src/libui_sdl/DlgEmuSettings.cpp index 7d774a0..ad8c047 100644 --- a/src/libui_sdl/DlgEmuSettings.cpp +++ b/src/libui_sdl/DlgEmuSettings.cpp @@ -37,7 +37,6 @@ bool opened; uiWindow* win; uiCheckbox* cbDirectBoot; -uiCheckbox* cbThreaded3D; int OnCloseWindow(uiWindow* window, void* blarg) @@ -55,14 +54,11 @@ void OnCancel(uiButton* btn, void* blarg) void OnOk(uiButton* btn, void* blarg) { Config::DirectBoot = uiCheckboxChecked(cbDirectBoot); - Config::Threaded3D = uiCheckboxChecked(cbThreaded3D); Config::Save(); uiControlDestroy(uiControl(win)); opened = false; - - ApplyNewSettings(0); } void Open() @@ -87,9 +83,6 @@ void Open() cbDirectBoot = uiNewCheckbox("Boot game directly"); uiBoxAppend(in_ctrl, uiControl(cbDirectBoot), 0); - - cbThreaded3D = uiNewCheckbox("Threaded 3D renderer"); - uiBoxAppend(in_ctrl, uiControl(cbThreaded3D), 0); } { @@ -110,7 +103,6 @@ void Open() } uiCheckboxSetChecked(cbDirectBoot, Config::DirectBoot); - uiCheckboxSetChecked(cbThreaded3D, Config::Threaded3D); uiControlShow(uiControl(win)); } diff --git a/src/libui_sdl/DlgVideoSettings.cpp b/src/libui_sdl/DlgVideoSettings.cpp index 329c79e..69e5ac5 100644 --- a/src/libui_sdl/DlgVideoSettings.cpp +++ b/src/libui_sdl/DlgVideoSettings.cpp @@ -59,14 +59,14 @@ void UpdateControls() uiControlEnable(uiControl(cbGLDisplay)); uiControlEnable(uiControl(cbThreaded3D)); uiControlDisable(uiControl(cbResolution)); - uiControlDisable(uiControl(cbAntialias)); + //uiControlDisable(uiControl(cbAntialias)); } else { uiControlDisable(uiControl(cbGLDisplay)); uiControlDisable(uiControl(cbThreaded3D)); uiControlEnable(uiControl(cbResolution)); - uiControlEnable(uiControl(cbAntialias)); + //uiControlEnable(uiControl(cbAntialias)); } } @@ -260,12 +260,12 @@ void Open() } uiBoxAppend(in_ctrl, uiControl(cbResolution), 0); - lbl = uiNewLabel(""); - uiBoxAppend(in_ctrl, uiControl(lbl), 0); + //lbl = uiNewLabel(""); + //uiBoxAppend(in_ctrl, uiControl(lbl), 0); - cbAntialias = uiNewCheckbox("Antialiasing"); - uiCheckboxOnToggled(cbAntialias, OnAntialiasChanged, NULL); - uiBoxAppend(in_ctrl, uiControl(cbAntialias), 0); + //cbAntialias = uiNewCheckbox("Antialiasing"); + //uiCheckboxOnToggled(cbAntialias, OnAntialiasChanged, NULL); + //uiBoxAppend(in_ctrl, uiControl(cbAntialias), 0); } { @@ -299,7 +299,7 @@ void Open() uiCheckboxSetChecked(cbGLDisplay, Config::ScreenUseGL); uiCheckboxSetChecked(cbThreaded3D, Config::Threaded3D); uiComboboxSetSelected(cbResolution, Config::GL_ScaleFactor-1); - uiCheckboxSetChecked(cbAntialias, Config::GL_Antialias); + //uiCheckboxSetChecked(cbAntialias, Config::GL_Antialias); uiRadioButtonsSetSelected(rbRenderer, Config::_3DRenderer); UpdateControls(); -- cgit v1.2.3 From eb6fe823f8196373906916b47fbeecf5d7a63e8a Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sat, 25 May 2019 20:58:32 +0200 Subject: close any opened dialogs when closing the main window --- src/libui_sdl/DlgAudioSettings.cpp | 7 +++++++ src/libui_sdl/DlgAudioSettings.h | 1 + src/libui_sdl/DlgEmuSettings.cpp | 7 +++++++ src/libui_sdl/DlgEmuSettings.h | 1 + src/libui_sdl/DlgInputConfig.cpp | 8 ++++++++ src/libui_sdl/DlgInputConfig.h | 1 + src/libui_sdl/DlgVideoSettings.cpp | 7 +++++++ src/libui_sdl/DlgVideoSettings.h | 1 + src/libui_sdl/DlgWifiSettings.cpp | 7 +++++++ src/libui_sdl/DlgWifiSettings.h | 1 + src/libui_sdl/main.cpp | 13 +++++++++++++ 11 files changed, 54 insertions(+) (limited to 'src/libui_sdl/DlgVideoSettings.cpp') diff --git a/src/libui_sdl/DlgAudioSettings.cpp b/src/libui_sdl/DlgAudioSettings.cpp index 66bdf61..385128c 100644 --- a/src/libui_sdl/DlgAudioSettings.cpp +++ b/src/libui_sdl/DlgAudioSettings.cpp @@ -180,4 +180,11 @@ void Open() uiControlShow(uiControl(win)); } +void Close() +{ + if (!opened) return; + uiControlDestroy(uiControl(win)); + opened = false; +} + } diff --git a/src/libui_sdl/DlgAudioSettings.h b/src/libui_sdl/DlgAudioSettings.h index 30a5d53..f058c25 100644 --- a/src/libui_sdl/DlgAudioSettings.h +++ b/src/libui_sdl/DlgAudioSettings.h @@ -23,6 +23,7 @@ namespace DlgAudioSettings { void Open(); +void Close(); } diff --git a/src/libui_sdl/DlgEmuSettings.cpp b/src/libui_sdl/DlgEmuSettings.cpp index ad8c047..768560d 100644 --- a/src/libui_sdl/DlgEmuSettings.cpp +++ b/src/libui_sdl/DlgEmuSettings.cpp @@ -107,4 +107,11 @@ void Open() uiControlShow(uiControl(win)); } +void Close() +{ + if (!opened) return; + uiControlDestroy(uiControl(win)); + opened = false; +} + } diff --git a/src/libui_sdl/DlgEmuSettings.h b/src/libui_sdl/DlgEmuSettings.h index 126497a..baff7ce 100644 --- a/src/libui_sdl/DlgEmuSettings.h +++ b/src/libui_sdl/DlgEmuSettings.h @@ -23,6 +23,7 @@ namespace DlgEmuSettings { void Open(); +void Close(); } diff --git a/src/libui_sdl/DlgInputConfig.cpp b/src/libui_sdl/DlgInputConfig.cpp index 513bd90..98cdf8c 100644 --- a/src/libui_sdl/DlgInputConfig.cpp +++ b/src/libui_sdl/DlgInputConfig.cpp @@ -450,5 +450,13 @@ void Open(int type) uiControlShow(uiControl(dlg->win)); } +void Close(int type) +{ + if (openedmask & (1< Date: Sat, 25 May 2019 21:03:39 +0200 Subject: for config dialogs that reflect changes instantly, make behavior of window close button consistent with that of Cancel button --- src/libui_sdl/DlgAudioSettings.cpp | 9 +++- src/libui_sdl/DlgVideoSettings.cpp | 84 ++++++++++++++++++++------------------ 2 files changed, 53 insertions(+), 40 deletions(-) (limited to 'src/libui_sdl/DlgVideoSettings.cpp') diff --git a/src/libui_sdl/DlgAudioSettings.cpp b/src/libui_sdl/DlgAudioSettings.cpp index 385128c..d649321 100644 --- a/src/libui_sdl/DlgAudioSettings.cpp +++ b/src/libui_sdl/DlgAudioSettings.cpp @@ -44,8 +44,15 @@ uiEntry* txMicWavPath; int oldvolume; +void RevertSettings() +{ + Config::AudioVolume = oldvolume; +} + + int OnCloseWindow(uiWindow* window, void* blarg) { + RevertSettings(); opened = false; return 1; } @@ -69,7 +76,7 @@ void OnMicWavBrowse(uiButton* btn, void* blarg) void OnCancel(uiButton* btn, void* blarg) { - Config::AudioVolume = oldvolume; + RevertSettings(); uiControlDestroy(uiControl(win)); opened = false; diff --git a/src/libui_sdl/DlgVideoSettings.cpp b/src/libui_sdl/DlgVideoSettings.cpp index 8749dc5..5c5d5f9 100644 --- a/src/libui_sdl/DlgVideoSettings.cpp +++ b/src/libui_sdl/DlgVideoSettings.cpp @@ -70,9 +70,53 @@ void UpdateControls() } } +void RevertSettings() +{ + bool apply0 = false; + bool apply2 = false; + bool apply3 = false; + + bool old_usegl = (old_gldisplay != 0) || (old_renderer != 0); + bool new_usegl = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0); + + if (old_renderer != Config::_3DRenderer) + { + Config::_3DRenderer = old_renderer; + apply3 = true; + } + + if (old_gldisplay != Config::ScreenUseGL) + { + Config::ScreenUseGL = old_gldisplay; + } + if (old_usegl != new_usegl) + { + apply2 = true; + } + + if (old_threaded3D != Config::Threaded3D) + { + Config::Threaded3D = old_threaded3D; + apply0 = true; + } + + if (old_resolution != Config::GL_ScaleFactor || + old_antialias != Config::GL_Antialias) + { + Config::GL_ScaleFactor = old_resolution; + Config::GL_Antialias = old_antialias; + apply0 = true; + } + + if (apply2) ApplyNewSettings(2); + else if (apply3) ApplyNewSettings(3); + if (apply0) ApplyNewSettings(0); +} + int OnCloseWindow(uiWindow* window, void* blarg) { + RevertSettings(); opened = false; return 1; } @@ -121,45 +165,7 @@ void OnAntialiasChanged(uiCheckbox* cb, void* blarg) void OnCancel(uiButton* btn, void* blarg) { - bool apply0 = false; - bool apply2 = false; - bool apply3 = false; - - bool old_usegl = (old_gldisplay != 0) || (old_renderer != 0); - bool new_usegl = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0); - - if (old_renderer != Config::_3DRenderer) - { - Config::_3DRenderer = old_renderer; - apply3 = true; - } - - if (old_gldisplay != Config::ScreenUseGL) - { - Config::ScreenUseGL = old_gldisplay; - } - if (old_usegl != new_usegl) - { - apply2 = true; - } - - if (old_threaded3D != Config::Threaded3D) - { - Config::Threaded3D = old_threaded3D; - apply0 = true; - } - - if (old_resolution != Config::GL_ScaleFactor || - old_antialias != Config::GL_Antialias) - { - Config::GL_ScaleFactor = old_resolution; - Config::GL_Antialias = old_antialias; - apply0 = true; - } - - if (apply2) ApplyNewSettings(2); - else if (apply3) ApplyNewSettings(3); - if (apply0) ApplyNewSettings(0); + RevertSettings(); uiControlDestroy(uiControl(win)); opened = false; -- cgit v1.2.3 From d8d7ba9251042fbef425509831fe5b642cf083f1 Mon Sep 17 00:00:00 2001 From: StapleButter Date: Fri, 31 May 2019 03:18:09 +0200 Subject: fix potential crash when switching video output methods --- src/libui_sdl/DlgVideoSettings.cpp | 4 +++- src/libui_sdl/main.cpp | 7 +++---- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'src/libui_sdl/DlgVideoSettings.cpp') diff --git a/src/libui_sdl/DlgVideoSettings.cpp b/src/libui_sdl/DlgVideoSettings.cpp index 5c5d5f9..7d876e2 100644 --- a/src/libui_sdl/DlgVideoSettings.cpp +++ b/src/libui_sdl/DlgVideoSettings.cpp @@ -134,13 +134,15 @@ void OnRendererChanged(uiRadioButtons* rb, void* blarg) ApplyNewSettings(2); else ApplyNewSettings(3); + + uiControlSetFocus(uiControl(win)); } void OnGLDisplayChanged(uiCheckbox* cb, void* blarg) { Config::ScreenUseGL = uiCheckboxChecked(cb); ApplyNewSettings(2); - uiControlSetFocus(uiControl(cb)); + uiControlSetFocus(uiControl(win)); } void OnThreaded3DChanged(uiCheckbox* cb, void* blarg) diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index 986a809..74d3fc9 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -2043,15 +2043,14 @@ void ApplyNewSettings(int type) bool usegl = Config::ScreenUseGL || (Config::_3DRenderer != 0); if (usegl != Screen_UseGL) { - Screen_UseGL = usegl; - if (RunningSomething) { - if (usegl) uiGLMakeContextCurrent(GLContext); + if (Screen_UseGL) uiGLMakeContextCurrent(GLContext); GPU3D::DeInitRenderer(); - if (usegl) uiGLMakeContextCurrent(NULL); + if (Screen_UseGL) uiGLMakeContextCurrent(NULL); } + Screen_UseGL = usegl; RecreateMainWindow(usegl); if (RunningSomething) -- cgit v1.2.3