all repos — mgba @ 25cc40f3e16871faf2950bd9e524e5a2d4923501

mGBA Game Boy Advance Emulator

Bring Raspberry Pi main to parity with GL main
Jeffrey Pfau jeffrey@endrift.com
Sat, 12 Oct 2013 01:18:34 -0700
commit

25cc40f3e16871faf2950bd9e524e5a2d4923501

parent

5caffd1f5a1abde86f735f01aa65430d6ebe9415

1 files changed, 49 insertions(+), 33 deletions(-)

jump to
M src/egl-main.csrc/egl-main.c

@@ -2,6 +2,7 @@ #include "debugger.h"

#include "gba-thread.h" #include "gba.h" #include "renderers/video-software.h" +#include "sdl-audio.h" #include "sdl-events.h" #include <SDL.h>

@@ -19,6 +20,8 @@ #include <unistd.h>

struct GBAVideoEGLRenderer { struct GBAVideoSoftwareRenderer d; + struct GBASDLAudio audio; + struct GBASDLEvents events; EGLDisplay display; EGLSurface surface;

@@ -60,6 +63,8 @@

static int _GBAEGLInit(struct GBAVideoEGLRenderer* renderer); static void _GBAEGLDeinit(struct GBAVideoEGLRenderer* renderer); static void _GBAEGLRunloop(struct GBAThread* context, struct GBAVideoEGLRenderer* renderer); +static void _GBASDLStart(struct GBAThread* context); +static void _GBASDLClean(struct GBAThread* context); int main(int argc, char** argv) { const char* fname = "test.rom";

@@ -80,7 +85,15 @@ }

GBAVideoSoftwareRendererCreate(&renderer.d); context.fd = fd; + context.fname = fname; + context.useDebugger = 0; context.renderer = &renderer.d.d; + context.frameskip = 0; + context.sync.videoFrameWait = 0; + context.sync.audioWait = 1; + context.startCallback = _GBASDLStart; + context.cleanCallback = _GBASDLClean; + context.userData = &renderer; GBAThreadStart(&context); _GBAEGLRunloop(&context, &renderer);

@@ -98,7 +111,9 @@ if (SDL_Init(SDL_INIT_JOYSTICK) < 0) {

return 0; } - GBASDLInitEvents(); + GBASDLInitEvents(&renderer->events); + GBASDLInitAudio(&renderer->audio); + bcm_host_init(); renderer->display = eglGetDisplay(EGL_DEFAULT_DISPLAY); int major, minor;

@@ -113,10 +128,10 @@ return 0;

} const EGLint requestConfig[] = { - EGL_RED_SIZE, 8, - EGL_GREEN_SIZE, 8, - EGL_BLUE_SIZE, 8, - EGL_ALPHA_SIZE, 8, + EGL_RED_SIZE, 5, + EGL_GREEN_SIZE, 5, + EGL_BLUE_SIZE, 5, + EGL_ALPHA_SIZE, 1, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_NONE };

@@ -202,35 +217,25 @@

static void _GBAEGLRunloop(struct GBAThread* context, struct GBAVideoEGLRenderer* renderer) { SDL_Event event; - while (context->started && context->debugger->state != DEBUGGER_EXITING) { - pthread_mutex_lock(&renderer->d.mutex); - if (renderer->d.d.framesPending) { - renderer->d.d.framesPending = 0; - pthread_mutex_unlock(&renderer->d.mutex); - - glViewport(0, 0, 240, 160); - glClear(GL_COLOR_BUFFER_BIT); - glUseProgram(renderer->program); - glUniform1i(renderer->texLocation, 0); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, renderer->tex); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, renderer->d.outputBuffer); - glVertexAttribPointer(renderer->positionLocation, 2, GL_FLOAT, GL_FALSE, 0, _vertices); - glEnableVertexAttribArray(renderer->positionLocation); - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - glUseProgram(0); - eglSwapBuffers(renderer->display, renderer->surface); + while (context->started && (!context->debugger || context->debugger->state != DEBUGGER_EXITING)) { + GBASyncWaitFrameStart(&context->sync, context->frameskip); + glViewport(0, 0, 240, 160); + glClear(GL_COLOR_BUFFER_BIT); + glUseProgram(renderer->program); + glUniform1i(renderer->texLocation, 0); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, renderer->tex); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, renderer->d.outputBuffer); + glVertexAttribPointer(renderer->positionLocation, 2, GL_FLOAT, GL_FALSE, 0, _vertices); + glEnableVertexAttribArray(renderer->positionLocation); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + glUseProgram(0); + eglSwapBuffers(renderer->display, renderer->surface); - while (SDL_PollEvent(&event)) { - GBASDLHandleEvent(context, &event); - } - pthread_mutex_lock(&renderer->d.mutex); - pthread_cond_broadcast(&renderer->d.downCond); - } else { - pthread_cond_broadcast(&renderer->d.downCond); - pthread_cond_wait(&renderer->d.upCond, &renderer->d.mutex); + while (SDL_PollEvent(&event)) { + GBASDLHandleEvent(context, &event); } - pthread_mutex_unlock(&renderer->d.mutex); + GBASyncWaitFrameEnd(&context->sync); } }

@@ -240,8 +245,19 @@ eglDestroySurface(renderer->display, renderer->surface);

eglDestroyContext(renderer->display, renderer->context); eglTerminate(renderer->display); - GBASDLDeinitEvents(); + GBASDLDeinitEvents(&renderer->events); + GBASDLDeinitAudio(&renderer->audio); SDL_Quit(); bcm_host_deinit(); } + +static void _GBASDLStart(struct GBAThread* threadContext) { + struct GBAVideoEGLRenderer* renderer = threadContext->userData; + renderer->audio.audio = &threadContext->gba->audio; +} + +static void _GBASDLClean(struct GBAThread* threadContext) { + struct GBAVideoEGLRenderer* renderer = threadContext->userData; + renderer->audio.audio = 0; +}