Add SDL2 support
Jeffrey Pfau jeffrey@endrift.com
Sun, 02 Feb 2014 02:39:34 -0800
3 files changed,
38 insertions(+),
1 deletions(-)
M
src/platform/sdl/CMakeLists.txt
→
src/platform/sdl/CMakeLists.txt
@@ -1,4 +1,19 @@
-find_package(SDL 1.2 REQUIRED) +set(SDL_VERSION "2" CACHE STRING "Version of SDL to use (1.2 or 2)") + +if (SDL_VERSION EQUAL "2") + include(FindPkgConfig) + pkg_search_module(SDL2 sdl2) + if (SDL2_FOUND) + set(SDL_INCLUDE_DIR ${SDL2_INCLUDE_DIRS}) + set(SDL_LIBRARY ${SDL2_LIBRARIES}) + set(SDLMAIN_LIBRARY "") + endif() +endif() + +if(SDL_VERSION EQUAL "1.2" OR NOT SDL2_FOUND) + find_package(SDL 1.2 REQUIRED) +endif() + file(GLOB PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/sdl-*.c) set(PLATFORM_LIBRARY "${SDL_LIBRARY};${SDLMAIN_LIBRARY}") include_directories(${CMAKE_SOURCE_DIR}/src/platform/sdl)
M
src/platform/sdl/gl-main.c
→
src/platform/sdl/gl-main.c
@@ -22,6 +22,9 @@ struct GLSoftwareRenderer {
struct GBAVideoSoftwareRenderer d; struct GBASDLAudio audio; struct GBASDLEvents events; +#if SDL_VERSION_ATLEAST(2, 0, 0) + SDL_Window* window; +#endif int viewportWidth; int viewportHeight;@@ -105,15 +108,25 @@
GBASDLInitEvents(&renderer->events); GBASDLInitAudio(&renderer->audio); +#if SDL_VERSION_ATLEAST(2, 0, 0) + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); +#else SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1); +#endif SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); +#if SDL_VERSION_ATLEAST(2, 0, 0) + renderer->window = SDL_CreateWindow("GBAc", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, renderer->viewportWidth, renderer->viewportHeight, SDL_WINDOW_OPENGL); + SDL_GL_CreateContext(renderer->window); + SDL_GetWindowSize(renderer->window, &renderer->viewportWidth, &renderer->viewportHeight); +#else #ifdef COLOR_16_BIT SDL_SetVideoMode(renderer->viewportWidth, renderer->viewportHeight, 16, SDL_OPENGL); #else SDL_SetVideoMode(renderer->viewportWidth, renderer->viewportHeight, 32, SDL_OPENGL); +#endif #endif renderer->d.outputBuffer = malloc(256 * 256 * 4);@@ -158,7 +171,11 @@ glFlush();
} } GBASyncWaitFrameEnd(&context->sync); +#if SDL_VERSION_ATLEAST(2, 0, 0) + SDL_GL_SwapWindow(renderer->window); +#else SDL_GL_SwapBuffers(); +#endif while (SDL_PollEvent(&event)) { GBASDLHandleEvent(context, &event);@@ -171,6 +188,9 @@ free(renderer->d.outputBuffer);
GBASDLDeinitEvents(&renderer->events); GBASDLDeinitAudio(&renderer->audio); +#if SDL_VERSION_ATLEAST(2, 0, 0) + SDL_DestroyWindow(renderer->window); +#endif SDL_Quit(); }
M
src/platform/sdl/sdl-events.c
→
src/platform/sdl/sdl-events.c
@@ -11,7 +11,9 @@ return 0;
} SDL_JoystickEventState(SDL_ENABLE); context->joystick = SDL_JoystickOpen(0); +#if !SDL_VERSION_ATLEAST(2, 0, 0) SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); +#endif return 1; }