Merge pull request #832 from reicast/holzhaus/sdl-opengl
Move to SDL2 for OpenGL 3.1 and GLES support
This commit is contained in:
commit
52afec6f7d
|
@ -1,6 +1,25 @@
|
||||||
#include <GL3/gl3w.h>
|
#include <GL3/gl3w.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#if defined(USE_SDL)
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
static void open_libgl(void)
|
||||||
|
{
|
||||||
|
SDL_GL_LoadLibrary(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void close_libgl(void)
|
||||||
|
{
|
||||||
|
SDL_GL_UnloadLibrary();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *get_proc(const char *proc)
|
||||||
|
{
|
||||||
|
void *res = NULL;
|
||||||
|
res = (void*)SDL_GL_GetProcAddress(proc);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(_WIN32)
|
||||||
#define WIN32_LEAN_AND_MEAN 1
|
#define WIN32_LEAN_AND_MEAN 1
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
|
|
|
@ -355,7 +355,7 @@ int screen_width;
|
||||||
int screen_height;
|
int screen_height;
|
||||||
|
|
||||||
#if (HOST_OS != OS_DARWIN) && !defined(TARGET_NACL32)
|
#if (HOST_OS != OS_DARWIN) && !defined(TARGET_NACL32)
|
||||||
#ifdef GLES
|
#if defined(GLES) && !defined(USE_SDL)
|
||||||
// Create a basic GLES context
|
// Create a basic GLES context
|
||||||
bool gl_init(void* wind, void* disp)
|
bool gl_init(void* wind, void* disp)
|
||||||
{
|
{
|
||||||
|
|
107
core/sdl/sdl.cpp
107
core/sdl/sdl.cpp
|
@ -3,9 +3,13 @@
|
||||||
#include "cfg/cfg.h"
|
#include "cfg/cfg.h"
|
||||||
#include "linux-dist/main.h"
|
#include "linux-dist/main.h"
|
||||||
#include "sdl/sdl.h"
|
#include "sdl/sdl.h"
|
||||||
#ifdef GLES
|
#ifndef GLES
|
||||||
#include <EGL/egl.h>
|
#include "khronos/GL3/gl3w.h"
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static SDL_Window* window = NULL;
|
||||||
|
static SDL_GLContext glcontext;
|
||||||
|
|
||||||
#ifdef TARGET_PANDORA
|
#ifdef TARGET_PANDORA
|
||||||
#define WINDOW_WIDTH 800
|
#define WINDOW_WIDTH 800
|
||||||
|
@ -14,9 +18,7 @@
|
||||||
#endif
|
#endif
|
||||||
#define WINDOW_HEIGHT 480
|
#define WINDOW_HEIGHT 480
|
||||||
|
|
||||||
SDL_Surface *screen = NULL;
|
static SDL_Joystick* JoySDL = 0;
|
||||||
|
|
||||||
static SDL_Joystick *JoySDL = 0;
|
|
||||||
|
|
||||||
extern bool FrameSkipping;
|
extern bool FrameSkipping;
|
||||||
extern void dc_term();
|
extern void dc_term();
|
||||||
|
@ -80,11 +82,11 @@ void input_sdl_init()
|
||||||
|
|
||||||
AxisCount = SDL_JoystickNumAxes(JoySDL);
|
AxisCount = SDL_JoystickNumAxes(JoySDL);
|
||||||
ButtonCount = SDL_JoystickNumButtons(JoySDL);
|
ButtonCount = SDL_JoystickNumButtons(JoySDL);
|
||||||
Name = SDL_JoystickName(0);
|
Name = SDL_JoystickName(JoySDL);
|
||||||
|
|
||||||
printf("SDK: Found '%s' joystick with %d axes and %d buttons\n", Name, AxisCount, ButtonCount);
|
printf("SDK: Found '%s' joystick with %d axes and %d buttons\n", Name, AxisCount, ButtonCount);
|
||||||
|
|
||||||
if (strcmp(Name,"Microsoft X-Box 360 pad")==0)
|
if (Name != NULL && strcmp(Name,"Microsoft X-Box 360 pad")==0)
|
||||||
{
|
{
|
||||||
sdl_map_btn = sdl_map_btn_xbox360;
|
sdl_map_btn = sdl_map_btn_xbox360;
|
||||||
sdl_map_axis = sdl_map_axis_xbox360;
|
sdl_map_axis = sdl_map_axis_xbox360;
|
||||||
|
@ -113,12 +115,7 @@ void input_sdl_init()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SDL_ShowCursor(0);
|
SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||||
|
|
||||||
if (SDL_WM_GrabInput( SDL_GRAB_ON ) != SDL_GRAB_ON)
|
|
||||||
{
|
|
||||||
printf("SDK: Error while grabbing mouse\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void input_sdl_handle(u32 port)
|
void input_sdl_handle(u32 port)
|
||||||
|
@ -397,12 +394,13 @@ void sdl_window_set_text(const char* text)
|
||||||
#ifdef TARGET_PANDORA
|
#ifdef TARGET_PANDORA
|
||||||
strncpy(OSD_Counters, text, 256);
|
strncpy(OSD_Counters, text, 256);
|
||||||
#else
|
#else
|
||||||
SDL_WM_SetCaption(text, NULL); // *TODO* Set Icon also...
|
if(window)
|
||||||
|
{
|
||||||
|
SDL_SetWindowTitle(window, text); // *TODO* Set Icon also...
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int ndcid = 0;
|
|
||||||
|
|
||||||
void sdl_window_create()
|
void sdl_window_create()
|
||||||
{
|
{
|
||||||
if (SDL_WasInit(SDL_INIT_VIDEO) == 0)
|
if (SDL_WasInit(SDL_INIT_VIDEO) == 0)
|
||||||
|
@ -415,17 +413,76 @@ void sdl_window_create()
|
||||||
|
|
||||||
int window_width = cfgLoadInt("x11","width", WINDOW_WIDTH);
|
int window_width = cfgLoadInt("x11","width", WINDOW_WIDTH);
|
||||||
int window_height = cfgLoadInt("x11","height", WINDOW_HEIGHT);
|
int window_height = cfgLoadInt("x11","height", WINDOW_HEIGHT);
|
||||||
|
|
||||||
|
int flags = SDL_WINDOW_OPENGL;
|
||||||
#ifdef TARGET_PANDORA
|
#ifdef TARGET_PANDORA
|
||||||
int flags = SDL_FULLSCREEN;
|
flags |= SDL_FULLSCREEN;
|
||||||
#else
|
#else
|
||||||
int flags = SDL_SWSURFACE;
|
flags |= SDL_SWSURFACE;
|
||||||
#endif
|
#endif
|
||||||
screen = SDL_SetVideoMode(window_width, window_height, 0, flags);
|
|
||||||
if (!screen)
|
#ifdef GLES
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
||||||
|
#else
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 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_ALPHA_SIZE, 8);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||||
|
|
||||||
|
window = SDL_CreateWindow("Reicast Emulator", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, window_width, window_height, flags);
|
||||||
|
if (!window)
|
||||||
{
|
{
|
||||||
die("error creating SDL screen");
|
die("error creating SDL window");
|
||||||
}
|
}
|
||||||
x11_disp = EGL_DEFAULT_DISPLAY;
|
|
||||||
printf("Created SDL Windows (%ix%i) successfully\n", window_width, window_height);
|
glcontext = SDL_GL_CreateContext(window);
|
||||||
|
if (!glcontext)
|
||||||
|
{
|
||||||
|
die("Error creating SDL GL context");
|
||||||
|
}
|
||||||
|
SDL_GL_MakeCurrent(window, NULL);
|
||||||
|
|
||||||
|
printf("Created SDL Window (%ix%i) and GL Context successfully\n", window_width, window_height);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern int screen_width, screen_height;
|
||||||
|
|
||||||
|
bool gl_init(void* wind, void* disp)
|
||||||
|
{
|
||||||
|
SDL_GL_MakeCurrent(window, glcontext);
|
||||||
|
#ifdef GLES
|
||||||
|
return true;
|
||||||
|
#else
|
||||||
|
return gl3wInit() != -1 && gl3wIsSupported(3, 1);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void gl_swap()
|
||||||
|
{
|
||||||
|
SDL_GL_SwapWindow(window);
|
||||||
|
|
||||||
|
/* Check if drawable has been resized */
|
||||||
|
int new_width, new_height;
|
||||||
|
SDL_GL_GetDrawableSize(window, &new_width, &new_height);
|
||||||
|
|
||||||
|
if (new_width != screen_width || new_height != screen_height)
|
||||||
|
{
|
||||||
|
screen_width = new_width;
|
||||||
|
screen_height = new_height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void gl_term()
|
||||||
|
{
|
||||||
|
SDL_GL_DeleteContext(glcontext);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <SDL/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
extern void* sdl_glc;
|
|
||||||
extern void input_sdl_init();
|
extern void input_sdl_init();
|
||||||
extern void input_sdl_handle(u32 port);
|
extern void input_sdl_handle(u32 port);
|
||||||
extern void sdl_window_create();
|
extern void sdl_window_create();
|
||||||
|
|
|
@ -213,8 +213,8 @@ ifndef NOT_ARM
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifdef USE_SDL
|
ifdef USE_SDL
|
||||||
CXXFLAGS += `sdl-config --cflags` -D USE_SDL
|
CXXFLAGS += `sdl2-config --cflags` -D USE_SDL
|
||||||
LIBS += `sdl-config --libs`
|
LIBS += `sdl2-config --libs`
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifdef PGO_MAKE
|
ifdef PGO_MAKE
|
||||||
|
|
Loading…
Reference in New Issue