Somewhat haphazard. Can't find some needed API calls :\

This commit is contained in:
Themaister 2011-09-13 18:50:40 +02:00
parent 21c6b75839
commit 642316a1e2
4 changed files with 106 additions and 16 deletions

View File

@ -992,6 +992,7 @@ static void gl_free(void *data)
pglDeleteFramebuffers(gl->fbo_pass, gl->fbo);
}
#endif
sdlwrap_destroy();
SDL_QuitSubSystem(SDL_INIT_VIDEO);
if (gl->empty_buf)
@ -1027,8 +1028,16 @@ static void* gl_init(const video_info_t *video, const input_driver_t **input, vo
sdlwrap_set_swap_interval(video->vsync ? 1 : 0, false);
if (!sdlwrap_set_video_mode(video->width, video->height,
g_settings.video.force_16bit ? 16 : 0, video->fullscreen))
unsigned win_width = video->width;
unsigned win_height = video->height;
if (video->fullscreen && (win_width == 0) && (win_height == 0))
{
win_width = full_x;
win_height = full_y;
}
if (!sdlwrap_set_video_mode(win_width, win_height,
g_settings.video.force_16bit ? 15 : 0, video->fullscreen))
return NULL;
gfx_window_title_reset();
@ -1045,6 +1054,7 @@ static void* gl_init(const video_info_t *video, const input_driver_t **input, vo
// Need to load dynamically :(
if (!load_gl_proc())
{
sdlwrap_destroy();
SDL_QuitSubSystem(SDL_INIT_VIDEO);
return NULL;
}
@ -1053,6 +1063,7 @@ static void* gl_init(const video_info_t *video, const input_driver_t **input, vo
gl_t *gl = calloc(1, sizeof(gl_t));
if (!gl)
{
sdlwrap_destroy();
SDL_QuitSubSystem(SDL_INIT_VIDEO);
return NULL;
}
@ -1062,23 +1073,15 @@ static void* gl_init(const video_info_t *video, const input_driver_t **input, vo
gl->full_x = full_x;
gl->full_y = full_y;
if (video->fullscreen)
{
gl->win_width = video->width ? video->width : gl->full_x;
gl->win_height = video->height ? video->height : gl->full_y;
}
else
{
gl->win_width = video->width;
gl->win_height = video->height;
}
gl->win_width = win_width;
gl->win_height = win_height;
SSNES_LOG("GL: Using resolution %ux%u\n", gl->win_width, gl->win_height);
if (!gl_shader_init())
{
SSNES_ERR("Shader init failed.\n");
sdlwrap_destroy();
SDL_QuitSubSystem(SDL_INIT_VIDEO);
free(gl);
return NULL;
@ -1181,6 +1184,7 @@ static void* gl_init(const video_info_t *video, const input_driver_t **input, vo
if (!gl_check_error())
{
sdlwrap_destroy();
SDL_QuitSubSystem(SDL_INIT_VIDEO);
free(gl);
return NULL;
@ -1198,7 +1202,7 @@ static bool gl_alive(void *data)
static bool gl_focus(void *data)
{
(void)data;
return (SDL_GetAppState() & (SDL_APPINPUTFOCUS | SDL_APPACTIVE)) == (SDL_APPINPUTFOCUS | SDL_APPACTIVE);
return sdlwrap_window_has_focus();
}
#ifdef HAVE_XML

View File

@ -69,13 +69,35 @@ void sdlwrap_set_swap_interval(unsigned interval, bool inited)
#endif
}
#if SDL_MODERN
static SDL_Window* g_window;
static SDL_GLContext g_ctx;
void sdlwrap_destroy(void)
{
if (g_ctx)
SDL_GL_DeleteContext(g_ctx);
if (g_window)
SDL_DestroyWindow(g_window);
g_ctx = NULL;
g_window = 0;
}
#else
void sdlwrap_destroy(void) {}
#endif
bool sdlwrap_set_video_mode(
unsigned width, unsigned height,
unsigned bits, bool fullscreen)
{
// Resizing in windowed mode appears to be broken on OSX. Yay!
#ifndef __APPLE__
#if SDL_MODERN
static const int resizable = SDL_WINDOW_RESIZABLE;
#else
static const int resizable = SDL_RESIZABLE;
#endif
#else
static const int resizable = 0;
#endif
@ -86,9 +108,23 @@ bool sdlwrap_set_video_mode(
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, g_interval);
#endif
#if SDL_MODERN
if (bits == 15)
{
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
}
g_window = SDL_CreateWindow("SSNES", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | (fullscreen ? SDL_WINDOW_FULLSCREEN : 0) | resizable);
if (!g_window)
return false;
g_ctx = SDL_GL_CreateContext(g_window);
#else
if (!SDL_SetVideoMode(width, height, bits,
SDL_OPENGL | (fullscreen ? SDL_FULLSCREEN : resizable)))
return false;
#endif
int attr = 0;
#if SDL_MODERN
@ -114,12 +150,20 @@ bool sdlwrap_set_video_mode(
void sdlwrap_wm_set_caption(const char *str)
{
#if SDL_MODERN
SDL_SetWindowTitle(g_window, str);
#else
SDL_WM_SetCaption(str, NULL);
#endif
}
void sdlwrap_swap_buffers(void)
{
#if SDL_MODERN
SDL_GL_SwapWindow(g_window);
#else
SDL_GL_SwapBuffers();
#endif
}
bool sdlwrap_key_pressed(int key)
@ -169,8 +213,22 @@ void sdlwrap_check_window(bool *quit,
{
*quit = false;
*resize = false;
SDL_Event event;
#if SDL_MODERN
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
*quit = true;
break;
}
}
#else
while (SDL_PollEvent(&event))
{
@ -203,5 +261,25 @@ void sdlwrap_check_window(bool *quit,
}
}
#endif
#endif
}
bool sdlwrap_get_wm_info(SDL_SysWMinfo *info)
{
#if SDL_MODERN
return SDL_GetWindowWMInfo(g_window, info);
#else
return SDL_GetWMInfo(info) == 1;
#endif
}
bool sdlwrap_window_has_focus(void)
{
#if SDL_MODERN
//return true; // TODO: Figure out how ...
return true;
#else
return (SDL_GetAppState() & (SDL_APPINPUTFOCUS | SDL_APPACTIVE)) == (SDL_APPINPUTFOCUS | SDL_APPACTIVE);
#endif
}

View File

@ -25,6 +25,7 @@
#include "SDL.h"
#include "SDL_version.h"
#include "SDL_syswm.h"
#if SDL_VERSION_ATLEAST(1, 3, 0)
#define SDL_MODERN 1
@ -49,6 +50,8 @@ bool sdlwrap_set_video_mode(
unsigned width, unsigned height,
unsigned bits, bool fullscreen);
void sdlwrap_destroy(void);
void sdlwrap_wm_set_caption(const char *str);
void sdlwrap_swap_buffers(void);
@ -58,5 +61,9 @@ bool sdlwrap_key_pressed(int key);
void sdlwrap_check_window(bool *quit,
bool *resize, unsigned *width, unsigned *height, unsigned frame_count);
bool sdlwrap_get_wm_info(SDL_SysWMinfo *info);
bool sdlwrap_window_has_focus(void);
#endif

View File

@ -105,7 +105,8 @@ sdl_dinput_t* sdl_dinput_init(void)
SDL_SysWMinfo info;
SDL_VERSION(&info.version);
if (!SDL_GetWMInfo(&info))
if (!sdlwrap_get_wm_info(&info))
{
SSNES_ERR("Failed to get SysWM info.\n");
goto error;