all repos — mgba @ b3d9a1918b3e32a184147323da688786d8dca387

mGBA Game Boy Advance Emulator

Kludge to prevent busy-waiting while no frames are generating
Jeffrey Pfau jeffrey@endrift.com
Tue, 23 Apr 2013 23:07:24 -0700
commit

b3d9a1918b3e32a184147323da688786d8dca387

parent

754725e1244bbf6c4aa8d54c0e4f7c0370f921ad

1 files changed, 11 insertions(+), 7 deletions(-)

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

@@ -106,19 +106,23 @@ glMatrixMode (GL_PROJECTION);

glLoadIdentity(); glOrtho(0, 240, 160, 0, 0, 1); while (context->started) { - glBindTexture(GL_TEXTURE_2D, renderer->tex); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB5, 256, 256, 0, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, renderer->d.outputBuffer); - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - pthread_mutex_lock(&renderer->d.mutex); if (renderer->d.d.framesPending) { - --renderer->d.d.framesPending; + renderer->d.d.framesPending = 0; pthread_mutex_unlock(&renderer->d.mutex); + glBindTexture(GL_TEXTURE_2D, renderer->tex); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB5, 256, 256, 0, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, renderer->d.outputBuffer); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + SDL_GL_SwapBuffers(); pthread_mutex_lock(&renderer->d.mutex); + pthread_cond_broadcast(&renderer->d.cond); + pthread_mutex_unlock(&renderer->d.mutex); + } else { + pthread_mutex_unlock(&renderer->d.mutex); + // We have no frame, let's just wait a sec to see if we get one. + usleep(500); } - pthread_cond_broadcast(&renderer->d.cond); - pthread_mutex_unlock(&renderer->d.mutex); while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: