SDL: Merge egl-main

This commit is contained in:
Jeffrey Pfau 2014-11-05 04:11:09 -08:00
parent d5b8fdf81c
commit 25f5520b0b
6 changed files with 63 additions and 129 deletions

View File

@ -26,16 +26,18 @@ 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 ${SDL_INCLUDE_DIR})
set(MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/main.c)
if(BUILD_RASPI)
add_definitions(-DBUILD_RASPI)
set(EGL_MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/egl-main.c)
set(EGL_MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/egl-sdl.c)
set(EGL_LIBRARY "-lEGL -lGLESv2 -lbcm_host")
add_executable(${BINARY_NAME}-rpi ${PLATFORM_SRC} ${EGL_MAIN_SRC})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fgnu89-inline")
add_executable(${BINARY_NAME}-rpi ${PLATFORM_SRC} ${MAIN_SRC} ${EGL_MAIN_SRC})
target_link_libraries(${BINARY_NAME}-rpi ${BINARY_NAME} ${PLATFORM_LIBRARY} ${EGL_LIBRARY})
install(TARGETS ${BINARY_NAME}-rpi DESTINATION bin)
endif()
set(MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/main.c)
if(BUILD_BBB OR BUILD_RASPI OR NOT BUILD_GL)
list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/sw-sdl.c)
else()

View File

@ -1,39 +1,4 @@
#include "debugger/debugger.h"
#include "gba-thread.h"
#include "gba.h"
#include "renderers/video-software.h"
#include "sdl-audio.h"
#include "sdl-events.h"
#include <SDL/SDL.h>
#include <GLES2/gl2.h>
#include <EGL/egl.h>
#include <bcm_host.h>
#include <errno.h>
#include <fcntl.h>
#include <malloc.h>
#include <signal.h>
#include <sys/time.h>
struct GBAVideoEGLRenderer {
struct GBAVideoSoftwareRenderer d;
struct GBASDLAudio audio;
struct GBASDLEvents events;
EGLDisplay display;
EGLSurface surface;
EGLContext context;
EGL_DISPMANX_WINDOW_T window;
GLuint tex;
GLuint fragmentShader;
GLuint vertexShader;
GLuint program;
GLuint bufferObject;
GLuint texLocation;
GLuint positionLocation;
};
#include "main.h"
static const char* _vertexShader =
"attribute vec4 position;\n"
@ -61,75 +26,18 @@ static const GLfloat _vertices[] = {
1.f, -1.f,
};
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) {
struct GBAVideoEGLRenderer renderer;
struct StartupOptions opts;
if (!parseCommandArgs(&opts, argc, argv, 0)) {
usage(argv[0], 0);
freeOptions(&opts);
return 1;
}
if (!_GBAEGLInit(&renderer)) {
return 1;
}
GBAVideoSoftwareRendererCreate(&renderer.d);
struct GBAThread context = {
.renderer = &renderer.d.d,
.sync.videoFrameWait = 0,
.sync.audioWait = 1,
.startCallback = _GBASDLStart,
.cleanCallback = _GBASDLClean,
.userData = &renderer
};
context.debugger = createDebugger(&opts);
GBAMapOptionsToContext(&opts, &context);
renderer.audio.samples = context.audioBuffers;
GBASDLInitAudio(&renderer.audio);
renderer.events.bindings = &context.inputMap;
GBASDLInitEvents(&renderer.events);
GBAThreadStart(&context);
_GBAEGLRunloop(&context, &renderer);
GBAThreadJoin(&context);
freeOptions(&opts);
free(context.debugger);
_GBAEGLDeinit(&renderer);
return 0;
}
static int _GBAEGLInit(struct GBAVideoEGLRenderer* renderer) {
if (SDL_Init(SDL_INIT_JOYSTICK) < 0) {
return 0;
}
bool GBASDLInit(struct SDLSoftwareRenderer* renderer) {
bcm_host_init();
renderer->display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
int major, minor;
if (EGL_FALSE == eglInitialize(renderer->display, &major, &minor)) {
printf("Failed to initialize EGL");
return 0;
return false;
}
if (EGL_FALSE == eglBindAPI(EGL_OPENGL_ES_API)) {
printf("Failed to get GLES API");
return 0;
return false;
}
const EGLint requestConfig[] = {
@ -146,7 +54,7 @@ static int _GBAEGLInit(struct GBAVideoEGLRenderer* renderer) {
if (EGL_FALSE == eglChooseConfig(renderer->display, requestConfig, &config, 1, &numConfigs)) {
printf("Failed to choose EGL config\n");
return 0;
return false;
}
const EGLint contextAttributes[] = {
@ -185,7 +93,7 @@ static int _GBAEGLInit(struct GBAVideoEGLRenderer* renderer) {
renderer->surface = eglCreateWindowSurface(renderer->display, config, &renderer->window, 0);
if (EGL_FALSE == eglMakeCurrent(renderer->display, renderer->surface, renderer->surface, renderer->context)) {
return 0;
return false;
}
renderer->d.outputBuffer = memalign(16, 256 * 256 * 4);
@ -216,10 +124,9 @@ static int _GBAEGLInit(struct GBAVideoEGLRenderer* renderer) {
renderer->texLocation = glGetUniformLocation(renderer->program, "tex");
renderer->positionLocation = glGetAttribLocation(renderer->program, "position");
glClearColor(1.f, 0.f, 0.f, 1.f);
return 1;
}
static void _GBAEGLRunloop(struct GBAThread* context, struct GBAVideoEGLRenderer* renderer) {
void GBASDLRunloop(struct GBAThread* context, struct SDLSoftwareRenderer* renderer) {
SDL_Event event;
while (context->state < THREAD_EXITING) {
@ -245,26 +152,10 @@ static void _GBAEGLRunloop(struct GBAThread* context, struct GBAVideoEGLRenderer
}
}
static void _GBAEGLDeinit(struct GBAVideoEGLRenderer* renderer) {
void GBASDLDeinit(struct SDLSoftwareRenderer* renderer) {
eglMakeCurrent(renderer->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglDestroySurface(renderer->display, renderer->surface);
eglDestroyContext(renderer->display, renderer->context);
eglTerminate(renderer->display);
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;
renderer->audio.thread = threadContext;
}
static void _GBASDLClean(struct GBAThread* threadContext) {
struct GBAVideoEGLRenderer* renderer = threadContext->userData;
renderer->audio.audio = 0;
}

View File

@ -24,7 +24,7 @@ static const GLint _glTexCoords[] = {
};
#endif
void GBASDLInit(struct SDLSoftwareRenderer* renderer) {
bool GBASDLInit(struct SDLSoftwareRenderer* renderer) {
#ifndef COLOR_16_BIT
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
@ -67,6 +67,8 @@ void GBASDLInit(struct SDLSoftwareRenderer* renderer) {
#endif
glViewport(0, 0, renderer->viewportWidth, renderer->viewportHeight);
return true;
}
void GBASDLRunloop(struct GBAThread* context, struct SDLSoftwareRenderer* renderer) {
@ -117,3 +119,7 @@ void GBASDLRunloop(struct GBAThread* context, struct SDLSoftwareRenderer* render
}
}
}
void GBASDLDeinit(struct SDLSoftwareRenderer* renderer) {
UNUSED(renderer);
}

View File

@ -22,7 +22,7 @@
#define PORT "sdl"
static int _GBASDLInit(struct SDLSoftwareRenderer* renderer);
static bool _GBASDLInit(struct SDLSoftwareRenderer* renderer);
static void _GBASDLDeinit(struct SDLSoftwareRenderer* renderer);
static void _GBASDLStart(struct GBAThread* context);
static void _GBASDLClean(struct GBAThread* context);
@ -107,14 +107,12 @@ int main(int argc, char** argv) {
return 0;
}
static int _GBASDLInit(struct SDLSoftwareRenderer* renderer) {
static bool _GBASDLInit(struct SDLSoftwareRenderer* renderer) {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
return 0;
return false;
}
GBASDLInit(renderer);
return 1;
return GBASDLInit(renderer);
}
static void _GBASDLDeinit(struct SDLSoftwareRenderer* renderer) {
@ -125,7 +123,11 @@ static void _GBASDLDeinit(struct SDLSoftwareRenderer* renderer) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_DestroyWindow(renderer->window);
#endif
GBASDLDeinit(renderer);
SDL_Quit();
}
static void _GBASDLStart(struct GBAThread* threadContext) {

View File

@ -14,6 +14,18 @@
#endif
#endif
#ifdef BUILD_RASPI
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#include <SDL/SDL.h>
#include <GLES2/gl2.h>
#include <EGL/egl.h>
#include <bcm_host.h>
#pragma GCC diagnostic pop
#endif
struct SDLSoftwareRenderer {
struct GBAVideoSoftwareRenderer d;
struct GBASDLAudio audio;
@ -34,9 +46,24 @@ struct SDLSoftwareRenderer {
#ifdef BUILD_GL
GLuint tex;
#endif
#ifdef BUILD_RASPI
EGLDisplay display;
EGLSurface surface;
EGLContext context;
EGL_DISPMANX_WINDOW_T window;
GLuint tex;
GLuint fragmentShader;
GLuint vertexShader;
GLuint program;
GLuint bufferObject;
GLuint texLocation;
GLuint positionLocation;
#endif
};
void GBASDLInit(struct SDLSoftwareRenderer* renderer);
bool GBASDLInit(struct SDLSoftwareRenderer* renderer);
void GBASDLDeinit(struct SDLSoftwareRenderer* renderer);
void GBASDLRunloop(struct GBAThread* context, struct SDLSoftwareRenderer* renderer);
#endif

View File

@ -7,7 +7,7 @@ void _neon2x(void* dest, void* src, int width, int height);
void _neon4x(void* dest, void* src, int width, int height);
#endif
void GBASDLInit(struct SDLSoftwareRenderer* renderer) {
bool GBASDLInit(struct SDLSoftwareRenderer* renderer) {
#if !SDL_VERSION_ATLEAST(2, 0, 0)
#ifdef COLOR_16_BIT
SDL_SetVideoMode(renderer->viewportWidth, renderer->viewportHeight, 16, SDL_DOUBLEBUF | SDL_HWSURFACE);
@ -49,6 +49,8 @@ void GBASDLInit(struct SDLSoftwareRenderer* renderer) {
renderer->d.outputBufferStride = 240;
}
#endif
return true;
}
void GBASDLRunloop(struct GBAThread* context, struct SDLSoftwareRenderer* renderer) {
@ -92,3 +94,7 @@ void GBASDLRunloop(struct GBAThread* context, struct SDLSoftwareRenderer* render
}
}
}
void GBASDLDeinit(struct SDLSoftwareRenderer* renderer) {
UNUSED(renderer);
}