aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorArisotura <thetotalworm@gmail.com>2019-04-01 04:50:48 +0200
committerArisotura <thetotalworm@gmail.com>2019-04-01 04:50:48 +0200
commit1f13d9ce80c0cd5e94ba883ff6bb30c95d48a48a (patch)
tree88ba77ce41be20b0f726897411974560de122862 /src
parent2d0d501d1ffe972dcc0a8879b95aaed9328650c7 (diff)
* move GL init to main thread
* fix potential bug causing the screen bitmap to be created twice
Diffstat (limited to 'src')
-rw-r--r--src/GPU3D_OpenGL43.cpp2
-rw-r--r--src/libui_sdl/libui/windows/alloc.cpp2
-rw-r--r--src/libui_sdl/libui/windows/gl.cpp9
-rw-r--r--src/libui_sdl/main.cpp29
4 files changed, 27 insertions, 15 deletions
diff --git a/src/GPU3D_OpenGL43.cpp b/src/GPU3D_OpenGL43.cpp
index 58539fa..ea8bbd7 100644
--- a/src/GPU3D_OpenGL43.cpp
+++ b/src/GPU3D_OpenGL43.cpp
@@ -53,7 +53,7 @@ bool InitGLExtensions()
{
#define LOADPROC(type, name) \
name = (PFN##type##PROC)Platform::GL_GetProcAddress(#name); \
- if (!name) return false;
+ if (!name) { printf("OpenGL: " #name " not found\n"); return false; }
LOADPROC(GLGENFRAMEBUFFERS, glGenFramebuffers);
LOADPROC(GLDELETEFRAMEBUFFERS, glDeleteFramebuffers);
diff --git a/src/libui_sdl/libui/windows/alloc.cpp b/src/libui_sdl/libui/windows/alloc.cpp
index cf6bd2e..e29d60e 100644
--- a/src/libui_sdl/libui/windows/alloc.cpp
+++ b/src/libui_sdl/libui/windows/alloc.cpp
@@ -32,7 +32,7 @@ void *uiAlloc(size_t size, const char *type)
{
byteArray *out;
- out = new byteArray(size, 0);
+ out = new byteArray(size, 0);//printf("alloc %s at %08X\n", type, rawBytes(out));
heap[rawBytes(out)] = out;
types[out] = type;
return rawBytes(out);
diff --git a/src/libui_sdl/libui/windows/gl.cpp b/src/libui_sdl/libui/windows/gl.cpp
index eb7d33d..beccb79 100644
--- a/src/libui_sdl/libui/windows/gl.cpp
+++ b/src/libui_sdl/libui/windows/gl.cpp
@@ -120,7 +120,14 @@ void uiGLFreeContext(uiGLContext* ctx)
void uiGLMakeContextCurrent(uiGLContext* ctx)
{
- wglMakeCurrent(ctx->dc, ctx->rc);
+ if (ctx == NULL)
+ {
+ wglMakeCurrent(NULL, NULL);
+ return;
+ }
+
+ if (wglGetCurrentContext() == ctx->rc) return;
+ int res = wglMakeCurrent(ctx->dc, ctx->rc);
}
void *uiGLGetProcAddress(const char* proc)
diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp
index d892912..2705560 100644
--- a/src/libui_sdl/main.cpp
+++ b/src/libui_sdl/main.cpp
@@ -60,6 +60,7 @@ char* EmuDirectory;
uiWindow* MainWindow;
uiArea* MainDrawArea;
+uiGLContext* GLContext;
int WindowWidth, WindowHeight;
@@ -392,14 +393,7 @@ void FeedMicInput()
int EmuThreadFunc(void* burp)
{
- // TODO: fail gracefully, support older OpenGL, etc
- uiGLContext* glctx = uiGLNewContext(uiControl(MainDrawArea), 4, 3); // haw haw haw
- uiGLMakeContextCurrent(glctx);
-
- void* testor = uiGLGetProcAddress("glUseProgram");
- void* testor2 = uiGLGetProcAddress("glBindFramebuffer");
- printf("OPENGL: %p %p\n", testor, testor2);
-
+ uiGLMakeContextCurrent(GLContext);
NDS::Init();
MainScreenPos[0] = 0;
@@ -407,7 +401,6 @@ int EmuThreadFunc(void* burp)
MainScreenPos[2] = 0;
AutoScreenSizing = 0;
- ScreenDrawInited = false;
Touching = false;
KeyInputMask = 0xFFF;
HotkeyMask = 0;
@@ -440,6 +433,8 @@ int EmuThreadFunc(void* burp)
{
EmuStatus = 1;
+ uiGLMakeContextCurrent(GLContext);
+
SDL_JoystickUpdate();
if (Joystick)
@@ -624,8 +619,6 @@ int EmuThreadFunc(void* burp)
NDS::DeInit();
Platform::LAN_DeInit();
- uiGLFreeContext(glctx);
-
return 44203;
}
@@ -634,8 +627,8 @@ void OnAreaDraw(uiAreaHandler* handler, uiArea* area, uiAreaDrawParams* params)
{
if (!ScreenDrawInited)
{
- ScreenBitmap = uiDrawNewBitmap(params->Context, 256, 384);
ScreenDrawInited = true;
+ ScreenBitmap = uiDrawNewBitmap(params->Context, 256, 384);
}
if (!ScreenBitmap) return;
@@ -1981,6 +1974,7 @@ int main(int argc, char** argv)
areahandler.KeyEvent = OnAreaKeyEvent;
areahandler.Resize = OnAreaResize;
+ ScreenDrawInited = false;
MainDrawArea = uiNewArea(&areahandler);
uiWindowSetChild(MainWindow, uiControl(MainDrawArea));
uiControlSetMinSize(uiControl(MainDrawArea), 256, 384);
@@ -2011,6 +2005,15 @@ int main(int argc, char** argv)
OnSetScreenRotation(MenuItem_ScreenRot[ScreenRotation], MainWindow, (void*)&kScreenRot[ScreenRotation]);
+ // TODO: fail gracefully, support older OpenGL, etc
+ GLContext = uiGLNewContext(uiControl(MainDrawArea), 4, 3); // haw haw haw
+ 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;
@@ -2092,6 +2095,8 @@ int main(int argc, char** argv)
if (MicWavBuffer) delete[] MicWavBuffer;
+ uiGLFreeContext(GLContext);
+
Config::ScreenRotation = ScreenRotation;
Config::ScreenGap = ScreenGap;
Config::ScreenLayout = ScreenLayout;