2001-04-26 16:45:43 +00:00
|
|
|
/*
|
|
|
|
SDL - Simple DirectMedia Layer
|
2011-02-11 22:37:15 -08:00
|
|
|
Copyright (C) 1997-2011 Sam Lantinga
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2006-02-01 06:32:25 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
2001-04-26 16:45:43 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2006-02-01 06:32:25 +00:00
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2006-02-01 06:32:25 +00:00
|
|
|
Lesser General Public License for more details.
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-02-01 06:32:25 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
Sam Lantinga
|
2001-12-14 12:38:15 +00:00
|
|
|
slouken@libsdl.org
|
2001-04-26 16:45:43 +00:00
|
|
|
*/
|
2006-02-21 08:46:50 +00:00
|
|
|
#include "SDL_config.h"
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
/* The high-level video driver subsystem */
|
|
|
|
|
2009-01-04 23:48:23 +00:00
|
|
|
#include "SDL.h"
|
2009-01-04 05:41:52 +00:00
|
|
|
#include "SDL_video.h"
|
2001-04-26 16:45:43 +00:00
|
|
|
#include "SDL_sysvideo.h"
|
|
|
|
#include "SDL_blit.h"
|
|
|
|
#include "SDL_pixels_c.h"
|
2011-02-13 23:09:18 -08:00
|
|
|
#include "SDL_rect_c.h"
|
2006-02-16 10:11:48 +00:00
|
|
|
#include "../events/SDL_events_c.h"
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2011-02-06 10:22:25 -08:00
|
|
|
#if SDL_VIDEO_OPENGL
|
|
|
|
#include "SDL_opengl.h"
|
|
|
|
#endif /* SDL_VIDEO_OPENGL */
|
|
|
|
|
2008-09-02 20:19:45 +00:00
|
|
|
#if SDL_VIDEO_OPENGL_ES
|
|
|
|
#include "SDL_opengles.h"
|
2008-09-15 04:32:36 +00:00
|
|
|
#endif /* SDL_VIDEO_OPENGL_ES */
|
2008-09-02 20:19:45 +00:00
|
|
|
|
2011-02-06 10:22:25 -08:00
|
|
|
#if SDL_VIDEO_OPENGL_ES2
|
|
|
|
#include "SDL_opengles2.h"
|
|
|
|
#endif /* SDL_VIDEO_OPENGL_ES2 */
|
2010-09-27 01:24:05 -07:00
|
|
|
|
|
|
|
#include "SDL_syswm.h"
|
2006-07-22 21:58:17 +00:00
|
|
|
|
|
|
|
/* On Windows, windows.h defines CreateWindow */
|
|
|
|
#ifdef CreateWindow
|
|
|
|
#undef CreateWindow
|
|
|
|
#endif
|
|
|
|
|
2001-04-26 16:45:43 +00:00
|
|
|
/* Available video drivers */
|
2009-06-05 07:35:06 +00:00
|
|
|
static VideoBootStrap *bootstrap[] = {
|
2006-07-23 09:11:10 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_COCOA
|
2008-09-15 04:32:36 +00:00
|
|
|
&COCOA_bootstrap,
|
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
To: SDL Developers <sdl@libsdl.org>
From: =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb@algonet.se>
Date: Mon, 30 May 2005 23:29:04 +0200
Subject: [SDL] Mac OS X Video Drivers [patch]
I've updated/added the Carbon and X11 video drivers
to the Mac OS X port of SDL 1.2 (the CVS version),
and made the Cocoa driver and runtime *optional*.
The default is still Cocoa, and the "Quartz" driver.
But you can now also use "toolbox" for Carbon, and
"x11" for running with Apple's (or other) X11 server:
export SDL_VIDEODRIVER=x11
export SDL_VIDEO_GL_DRIVER=/usr/X11R6/lib/libGL.dylib
It also checks if the frameworks are available, by a:
#include <Carbon/Carbon.h> or #import <Cocoa/Cocoa.h>
(this should make it configure on plain Darwin as well?)
Here are the new configure targets:
--enable-video-cocoa use Cocoa/Quartz video driver default=yes
--enable-video-carbon use Carbon/QuickDraw video driver default=yes
--enable-video-x11 use X11 video driver default=no
./configure --enable-video-cocoa --enable-video-carbon
--enable-video-x11 \
--x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib
The Carbon version is just an updated version of the old
SDL driver for Mac OS 9, and could probably be improved...
(but it does work, including the Carbon version of SDLmain)
If you disable cocoa, you can run with -framework Carbon only,
and the C version of SDL_main.c. And if you disable carbon too,
you can still use the X11 version which doesn't require SDLmain.
I updated the DrawSprocket version, but did not include it.
(no blitters or VRAM GWorlds etc. available on OS X anyway)
Besides for Mac OS 9, I don't think there's any use for it ?
And note that any performance on Mac OS X equals OpenGL anyway...
You can get "fair" software SDL results on captured CG displays,
but for decent frame rates you need to be using GL for rendering.
Finally, here is the patch itself:
http://www.algonet.se/~afb/SDL-12CVS-macvideo.patch
--anders
PS. It says "video", but as usual it applies to mouse/keyboard too.
------
To: A list for developers using the SDL library <sdl@libsdl.org>
From: =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb@algonet.se>
Date: Sun, 4 Sep 2005 10:02:15 +0200
Subject: [SDL] Updated Mac patch
Updated the previous Mac patch to disable Carbon by default.
Also "fixed" the SDL.spec again, so that it builds on Darwin.
http://www.algonet.se/~afb/SDL-1.2.9-mac.patch
Also applied fine to SDL12 CVS, when I tried it.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401136
2005-09-08 06:16:14 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_X11
|
2008-09-15 04:32:36 +00:00
|
|
|
&X11_bootstrap,
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_DIRECTFB
|
2008-09-15 04:32:36 +00:00
|
|
|
&DirectFB_bootstrap,
|
2001-09-04 22:53:46 +00:00
|
|
|
#endif
|
2011-01-20 18:04:05 -08:00
|
|
|
#if SDL_VIDEO_DRIVER_WINDOWS
|
|
|
|
&WINDOWS_bootstrap,
|
2006-01-01 23:34:06 +00:00
|
|
|
#endif
|
2006-02-16 10:11:48 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_BWINDOW
|
2008-09-15 04:32:36 +00:00
|
|
|
&BWINDOW_bootstrap,
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
2011-02-01 21:40:03 -08:00
|
|
|
#if SDL_VIDEO_DRIVER_PANDORA
|
|
|
|
&PND_bootstrap,
|
2001-09-11 20:38:49 +00:00
|
|
|
#endif
|
2008-09-02 20:05:33 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_NDS
|
2008-09-15 04:32:36 +00:00
|
|
|
&NDS_bootstrap,
|
2008-08-27 15:10:03 +00:00
|
|
|
#endif
|
2008-09-02 20:19:45 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_UIKIT
|
2008-09-15 04:32:36 +00:00
|
|
|
&UIKIT_bootstrap,
|
2008-09-02 20:19:45 +00:00
|
|
|
#endif
|
2010-06-10 18:54:23 +12:00
|
|
|
#if SDL_VIDEO_DRIVER_ANDROID
|
|
|
|
&Android_bootstrap,
|
2011-02-01 21:40:03 -08:00
|
|
|
#endif
|
|
|
|
#if SDL_VIDEO_DRIVER_DUMMY
|
|
|
|
&DUMMY_bootstrap,
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
2008-09-15 04:32:36 +00:00
|
|
|
NULL
|
2001-04-26 16:45:43 +00:00
|
|
|
};
|
2001-09-11 20:38:49 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
static SDL_VideoDevice *_this = NULL;
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2010-01-24 20:21:51 +00:00
|
|
|
#define CHECK_WINDOW_MAGIC(window, retval) \
|
|
|
|
if (!_this) { \
|
|
|
|
SDL_UninitializedVideo(); \
|
|
|
|
return retval; \
|
|
|
|
} \
|
2010-02-01 01:19:37 +00:00
|
|
|
if (!window || window->magic != &_this->window_magic) { \
|
2010-01-24 20:21:51 +00:00
|
|
|
SDL_SetError("Invalid window"); \
|
|
|
|
return retval; \
|
|
|
|
}
|
|
|
|
|
2011-02-10 12:14:37 -08:00
|
|
|
#define CHECK_DISPLAY_INDEX(displayIndex, retval) \
|
|
|
|
if (!_this) { \
|
|
|
|
SDL_UninitializedVideo(); \
|
|
|
|
return retval; \
|
|
|
|
} \
|
|
|
|
if (displayIndex < 0 || displayIndex >= _this->num_displays) { \
|
|
|
|
SDL_SetError("displayIndex must be in the range 0 - %d", \
|
|
|
|
_this->num_displays - 1); \
|
|
|
|
return retval; \
|
|
|
|
}
|
|
|
|
|
2011-02-03 15:49:37 -08:00
|
|
|
/* Support for framebuffer emulation using an accelerated renderer */
|
|
|
|
|
|
|
|
#define SDL_WINDOWTEXTUREDATA "_SDL_WindowTextureData"
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
SDL_Renderer *renderer;
|
|
|
|
SDL_Texture *texture;
|
|
|
|
void *pixels;
|
|
|
|
int pitch;
|
2011-02-04 12:24:28 -08:00
|
|
|
int bytes_per_pixel;
|
2011-02-03 15:49:37 -08:00
|
|
|
} SDL_WindowTextureData;
|
|
|
|
|
2011-02-05 10:03:12 -08:00
|
|
|
static SDL_bool
|
|
|
|
ShouldUseTextureFramebuffer()
|
|
|
|
{
|
|
|
|
const char *hint;
|
|
|
|
|
|
|
|
/* If there's no native framebuffer support then there's no option */
|
|
|
|
if (!_this->CreateWindowFramebuffer) {
|
|
|
|
return SDL_TRUE;
|
|
|
|
}
|
|
|
|
|
2011-02-05 10:35:36 -08:00
|
|
|
/* If the user has specified a software renderer we can't use a
|
|
|
|
texture framebuffer, or renderer creation will go recursive.
|
|
|
|
*/
|
|
|
|
hint = SDL_GetHint(SDL_HINT_RENDER_DRIVER);
|
|
|
|
if (hint && SDL_strcasecmp(hint, "software") == 0) {
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
|
2011-02-05 10:03:12 -08:00
|
|
|
/* See if the user or application wants a specific behavior */
|
|
|
|
hint = SDL_GetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION);
|
|
|
|
if (hint) {
|
|
|
|
if (*hint == '0') {
|
|
|
|
return SDL_FALSE;
|
|
|
|
} else {
|
|
|
|
return SDL_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Each platform has different performance characteristics */
|
|
|
|
#if defined(__WIN32__)
|
|
|
|
/* GDI BitBlt() is way faster than Direct3D dynamic textures right now.
|
|
|
|
*/
|
|
|
|
return SDL_FALSE;
|
|
|
|
|
|
|
|
#elif defined(__MACOSX__)
|
|
|
|
/* Mac OS X uses OpenGL as the native fast path */
|
|
|
|
return SDL_TRUE;
|
|
|
|
|
|
|
|
#elif defined(__LINUX__)
|
|
|
|
/* Properly configured OpenGL drivers are faster than MIT-SHM */
|
|
|
|
#if SDL_VIDEO_OPENGL
|
|
|
|
/* Ugh, find a way to cache this value! */
|
|
|
|
{
|
|
|
|
SDL_Window *window;
|
|
|
|
SDL_GLContext context;
|
|
|
|
SDL_bool hasAcceleratedOpenGL = SDL_FALSE;
|
|
|
|
|
2011-02-21 22:52:07 -08:00
|
|
|
window = SDL_CreateWindow("OpenGL test", -32, -32, 32, 32, SDL_WINDOW_OPENGL|SDL_WINDOW_HIDDEN);
|
2011-02-05 10:03:12 -08:00
|
|
|
if (window) {
|
|
|
|
context = SDL_GL_CreateContext(window);
|
|
|
|
if (context) {
|
|
|
|
const GLubyte *(APIENTRY * glGetStringFunc) (GLenum);
|
|
|
|
const char *vendor = NULL;
|
|
|
|
|
|
|
|
glGetStringFunc = SDL_GL_GetProcAddress("glGetString");
|
|
|
|
if (glGetStringFunc) {
|
|
|
|
vendor = (const char *) glGetStringFunc(GL_VENDOR);
|
|
|
|
}
|
|
|
|
/* Add more vendors here at will... */
|
|
|
|
if (vendor &&
|
|
|
|
(SDL_strstr(vendor, "ATI Technologies") ||
|
|
|
|
SDL_strstr(vendor, "NVIDIA"))) {
|
|
|
|
hasAcceleratedOpenGL = SDL_TRUE;
|
|
|
|
}
|
|
|
|
SDL_GL_DeleteContext(context);
|
|
|
|
}
|
|
|
|
SDL_DestroyWindow(window);
|
|
|
|
}
|
|
|
|
return hasAcceleratedOpenGL;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
return SDL_FALSE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#else
|
|
|
|
/* Play it safe, assume that if there is a framebuffer driver that it's
|
|
|
|
optimized for the current platform.
|
|
|
|
*/
|
|
|
|
return SDL_FALSE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-02-03 15:49:37 -08:00
|
|
|
static int
|
|
|
|
SDL_CreateWindowTexture(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
|
|
|
|
{
|
|
|
|
SDL_WindowTextureData *data;
|
|
|
|
SDL_RendererInfo info;
|
|
|
|
Uint32 i;
|
|
|
|
|
|
|
|
data = SDL_GetWindowData(window, SDL_WINDOWTEXTUREDATA);
|
|
|
|
if (!data) {
|
2011-02-13 14:05:33 -08:00
|
|
|
SDL_Renderer *renderer = NULL;
|
2011-02-03 17:42:58 -08:00
|
|
|
SDL_RendererInfo info;
|
|
|
|
int i;
|
2011-02-05 10:11:27 -08:00
|
|
|
const char *hint = SDL_GetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION);
|
|
|
|
|
|
|
|
/* Check to see if there's a specific driver requested */
|
|
|
|
if (hint && *hint != '0' && *hint != '1' &&
|
|
|
|
SDL_strcasecmp(hint, "software") != 0) {
|
|
|
|
for (i = 0; i < SDL_GetNumRenderDrivers(); ++i) {
|
|
|
|
SDL_GetRenderDriverInfo(i, &info);
|
|
|
|
if (SDL_strcasecmp(info.name, hint) == 0) {
|
|
|
|
renderer = SDL_CreateRenderer(window, i, 0);
|
2011-02-03 17:42:58 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-02-05 10:11:27 -08:00
|
|
|
|
|
|
|
if (!renderer) {
|
|
|
|
for (i = 0; i < SDL_GetNumRenderDrivers(); ++i) {
|
|
|
|
SDL_GetRenderDriverInfo(i, &info);
|
|
|
|
if (SDL_strcmp(info.name, "software") != 0) {
|
|
|
|
renderer = SDL_CreateRenderer(window, i, 0);
|
|
|
|
if (renderer) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-02-03 15:49:37 -08:00
|
|
|
if (!renderer) {
|
|
|
|
return -1;
|
|
|
|
}
|
2011-02-12 17:51:47 -08:00
|
|
|
|
|
|
|
/* Create the data after we successfully create the renderer (bug #1116) */
|
|
|
|
data = (SDL_WindowTextureData *)SDL_calloc(1, sizeof(*data));
|
|
|
|
if (!data) {
|
|
|
|
SDL_DestroyRenderer(renderer);
|
|
|
|
SDL_OutOfMemory();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
SDL_SetWindowData(window, SDL_WINDOWTEXTUREDATA, data);
|
|
|
|
|
2011-02-03 15:49:37 -08:00
|
|
|
data->renderer = renderer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free any old texture and pixel data */
|
|
|
|
if (data->texture) {
|
|
|
|
SDL_DestroyTexture(data->texture);
|
|
|
|
data->texture = NULL;
|
|
|
|
}
|
|
|
|
if (data->pixels) {
|
|
|
|
SDL_free(data->pixels);
|
|
|
|
data->pixels = NULL;
|
|
|
|
}
|
|
|
|
|
2011-02-13 14:05:33 -08:00
|
|
|
if (SDL_GetRendererInfo(data->renderer, &info) < 0) {
|
2011-02-03 15:49:37 -08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the first format without an alpha channel */
|
|
|
|
*format = info.texture_formats[0];
|
|
|
|
for (i = 0; i < info.num_texture_formats; ++i) {
|
2011-02-12 08:17:58 -08:00
|
|
|
if (!SDL_ISPIXELFORMAT_FOURCC(info.texture_formats[i]) &&
|
|
|
|
!SDL_ISPIXELFORMAT_ALPHA(info.texture_formats[i])) {
|
2011-02-03 15:49:37 -08:00
|
|
|
*format = info.texture_formats[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-13 14:05:33 -08:00
|
|
|
data->texture = SDL_CreateTexture(data->renderer, *format,
|
2011-02-03 15:49:37 -08:00
|
|
|
SDL_TEXTUREACCESS_STREAMING,
|
|
|
|
window->w, window->h);
|
|
|
|
if (!data->texture) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create framebuffer data */
|
2011-02-04 12:24:28 -08:00
|
|
|
data->bytes_per_pixel = SDL_BYTESPERPIXEL(*format);
|
|
|
|
data->pitch = (((window->w * data->bytes_per_pixel) + 3) & ~3);
|
2011-02-03 15:49:37 -08:00
|
|
|
data->pixels = SDL_malloc(window->h * data->pitch);
|
|
|
|
if (!data->pixels) {
|
|
|
|
SDL_OutOfMemory();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pixels = data->pixels;
|
|
|
|
*pitch = data->pitch;
|
2011-02-15 13:59:59 -08:00
|
|
|
|
|
|
|
/* Make sure we're not double-scaling the viewport */
|
|
|
|
SDL_RenderSetViewport(data->renderer, NULL);
|
|
|
|
|
2011-02-03 15:49:37 -08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2011-02-15 13:59:59 -08:00
|
|
|
SDL_UpdateWindowTexture(_THIS, SDL_Window * window, SDL_Rect * rects, int numrects)
|
2011-02-03 15:49:37 -08:00
|
|
|
{
|
|
|
|
SDL_WindowTextureData *data;
|
2011-02-13 23:09:18 -08:00
|
|
|
SDL_Rect rect;
|
|
|
|
void *src;
|
2011-02-03 15:49:37 -08:00
|
|
|
|
|
|
|
data = SDL_GetWindowData(window, SDL_WINDOWTEXTUREDATA);
|
|
|
|
if (!data || !data->texture) {
|
|
|
|
SDL_SetError("No window texture data");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-02-13 23:09:18 -08:00
|
|
|
/* Update a single rect that contains subrects for best DMA performance */
|
|
|
|
if (SDL_GetSpanEnclosingRect(window->w, window->h, numrects, rects, &rect)) {
|
2011-02-04 12:24:28 -08:00
|
|
|
src = (void *)((Uint8 *)data->pixels +
|
2011-02-13 23:09:18 -08:00
|
|
|
rect.y * data->pitch +
|
|
|
|
rect.x * data->bytes_per_pixel);
|
|
|
|
if (SDL_UpdateTexture(data->texture, &rect, src, data->pitch) < 0) {
|
2011-02-04 12:24:28 -08:00
|
|
|
return -1;
|
|
|
|
}
|
2011-02-13 23:09:18 -08:00
|
|
|
|
|
|
|
if (SDL_RenderCopy(data->renderer, data->texture, NULL, NULL) < 0) {
|
|
|
|
return -1;
|
2011-02-04 12:24:28 -08:00
|
|
|
}
|
|
|
|
|
2011-02-13 23:09:18 -08:00
|
|
|
SDL_RenderPresent(data->renderer);
|
2011-02-03 15:49:37 -08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
SDL_DestroyWindowTexture(_THIS, SDL_Window * window)
|
|
|
|
{
|
|
|
|
SDL_WindowTextureData *data;
|
|
|
|
|
|
|
|
data = SDL_SetWindowData(window, SDL_WINDOWTEXTUREDATA, NULL);
|
|
|
|
if (!data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (data->texture) {
|
|
|
|
SDL_DestroyTexture(data->texture);
|
|
|
|
}
|
|
|
|
if (data->renderer) {
|
|
|
|
SDL_DestroyRenderer(data->renderer);
|
|
|
|
}
|
|
|
|
if (data->pixels) {
|
|
|
|
SDL_free(data->pixels);
|
|
|
|
}
|
|
|
|
SDL_free(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
static int
|
|
|
|
cmpmodes(const void *A, const void *B)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_DisplayMode a = *(const SDL_DisplayMode *) A;
|
|
|
|
SDL_DisplayMode b = *(const SDL_DisplayMode *) B;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (a.w != b.w) {
|
|
|
|
return b.w - a.w;
|
|
|
|
}
|
|
|
|
if (a.h != b.h) {
|
|
|
|
return b.h - a.h;
|
|
|
|
}
|
|
|
|
if (SDL_BITSPERPIXEL(a.format) != SDL_BITSPERPIXEL(b.format)) {
|
|
|
|
return SDL_BITSPERPIXEL(b.format) - SDL_BITSPERPIXEL(a.format);
|
|
|
|
}
|
2009-06-09 08:56:43 +00:00
|
|
|
if (SDL_PIXELLAYOUT(a.format) != SDL_PIXELLAYOUT(b.format)) {
|
|
|
|
return SDL_PIXELLAYOUT(b.format) - SDL_PIXELLAYOUT(a.format);
|
|
|
|
}
|
2008-09-15 04:32:36 +00:00
|
|
|
if (a.refresh_rate != b.refresh_rate) {
|
|
|
|
return b.refresh_rate - a.refresh_rate;
|
|
|
|
}
|
|
|
|
return 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-07-16 09:34:01 +00:00
|
|
|
static void
|
|
|
|
SDL_UninitializedVideo()
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_SetError("Video subsystem has not been initialized");
|
2006-07-16 09:34:01 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
|
|
|
SDL_GetNumVideoDrivers(void)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
return SDL_arraysize(bootstrap) - 1;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
const char *
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_GetVideoDriver(int index)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if (index >= 0 && index < SDL_GetNumVideoDrivers()) {
|
|
|
|
return bootstrap[index]->name;
|
|
|
|
}
|
|
|
|
return NULL;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the video and event subsystems -- determine native pixel format
|
|
|
|
*/
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
2011-01-27 22:44:08 -08:00
|
|
|
SDL_VideoInit(const char *driver_name)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_VideoDevice *video;
|
|
|
|
int index;
|
|
|
|
int i;
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2010-01-24 19:47:17 +00:00
|
|
|
/* Check to make sure we don't overwrite '_this' */
|
|
|
|
if (_this != NULL) {
|
|
|
|
SDL_VideoQuit();
|
|
|
|
}
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
/* Start the event loop */
|
2011-01-27 22:44:08 -08:00
|
|
|
if (SDL_StartEventLoop() < 0 ||
|
|
|
|
SDL_KeyboardInit() < 0 ||
|
|
|
|
SDL_MouseInit() < 0 ||
|
|
|
|
SDL_TouchInit() < 0 ||
|
|
|
|
SDL_QuitInit() < 0) {
|
2008-09-15 04:32:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2010-01-24 19:47:17 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
/* Select the proper video driver */
|
|
|
|
index = 0;
|
|
|
|
video = NULL;
|
|
|
|
if (driver_name == NULL) {
|
|
|
|
driver_name = SDL_getenv("SDL_VIDEODRIVER");
|
|
|
|
}
|
|
|
|
if (driver_name != NULL) {
|
|
|
|
for (i = 0; bootstrap[i]; ++i) {
|
|
|
|
if (SDL_strcasecmp(bootstrap[i]->name, driver_name) == 0) {
|
2009-11-18 08:54:13 +00:00
|
|
|
video = bootstrap[i]->create(index);
|
2008-09-15 04:32:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 0; bootstrap[i]; ++i) {
|
|
|
|
if (bootstrap[i]->available()) {
|
|
|
|
video = bootstrap[i]->create(index);
|
|
|
|
if (video != NULL) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (video == NULL) {
|
|
|
|
if (driver_name) {
|
|
|
|
SDL_SetError("%s not available", driver_name);
|
|
|
|
} else {
|
|
|
|
SDL_SetError("No available video device");
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
_this = video;
|
|
|
|
_this->name = bootstrap[i]->name;
|
|
|
|
_this->next_object_id = 1;
|
|
|
|
|
|
|
|
|
|
|
|
/* Set some very sane GL defaults */
|
|
|
|
_this->gl_config.driver_loaded = 0;
|
|
|
|
_this->gl_config.dll_handle = NULL;
|
|
|
|
_this->gl_config.red_size = 3;
|
|
|
|
_this->gl_config.green_size = 3;
|
|
|
|
_this->gl_config.blue_size = 2;
|
|
|
|
_this->gl_config.alpha_size = 0;
|
|
|
|
_this->gl_config.buffer_size = 0;
|
|
|
|
_this->gl_config.depth_size = 16;
|
|
|
|
_this->gl_config.stencil_size = 0;
|
|
|
|
_this->gl_config.double_buffer = 1;
|
|
|
|
_this->gl_config.accum_red_size = 0;
|
|
|
|
_this->gl_config.accum_green_size = 0;
|
|
|
|
_this->gl_config.accum_blue_size = 0;
|
|
|
|
_this->gl_config.accum_alpha_size = 0;
|
|
|
|
_this->gl_config.stereo = 0;
|
|
|
|
_this->gl_config.multisamplebuffers = 0;
|
|
|
|
_this->gl_config.multisamplesamples = 0;
|
|
|
|
_this->gl_config.retained_backing = 1;
|
2009-12-15 20:53:09 +00:00
|
|
|
_this->gl_config.accelerated = -1; /* accelerated or not, both are fine */
|
2011-02-06 10:22:25 -08:00
|
|
|
#if SDL_VIDEO_OPENGL
|
Date: Sun, 22 Mar 2009 12:52:29 +0000
From: Luke Benstead
Subject: OpenGL 3.0 Context Creation
I've attached a patch which implements OpenGL 3.x context creation on
the latest SVN. I've added two options to SDL_GL_SetAttribute, these
are SDL_GL_CONTEXT_MAJOR_VERSION and SDL_GL_CONTEXT_MINOR_VERSION.
These default to 2 and 1 respectively. If the major version is less
than 3 then the current context creation method is used, otherwise the
appropriate new context creation function is called (depending on the
platform).
Sample code:
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); //Without these 2 lines, SDL will create a GL 2.x context
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_Surface* screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL | SDL_FULLSCREEN );
I've implemented context creation on both Win32 and X and run basic
tests on both. This patch doesn't provide access to all the options
allowed by the new context creation (e.g. shared contexts, forward
compatible contexts) but they can be added pretty easily.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403567
2009-03-24 10:43:53 +00:00
|
|
|
_this->gl_config.major_version = 2;
|
|
|
|
_this->gl_config.minor_version = 1;
|
2011-02-06 10:22:25 -08:00
|
|
|
#elif SDL_VIDEO_OPENGL_ES
|
|
|
|
_this->gl_config.major_version = 1;
|
|
|
|
_this->gl_config.minor_version = 1;
|
2011-02-07 09:23:01 -08:00
|
|
|
#elif SDL_VIDEO_OPENGL_ES2
|
|
|
|
_this->gl_config.major_version = 2;
|
|
|
|
_this->gl_config.minor_version = 0;
|
2011-02-06 10:22:25 -08:00
|
|
|
#endif
|
2008-09-15 04:32:36 +00:00
|
|
|
|
|
|
|
/* Initialize the video subsystem */
|
|
|
|
if (_this->VideoInit(_this) < 0) {
|
|
|
|
SDL_VideoQuit();
|
|
|
|
return -1;
|
|
|
|
}
|
2011-02-03 15:49:37 -08:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
/* Make sure some displays were added */
|
|
|
|
if (_this->num_displays == 0) {
|
|
|
|
SDL_SetError("The video driver did not add any displays");
|
|
|
|
SDL_VideoQuit();
|
|
|
|
return (-1);
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2011-02-05 10:03:12 -08:00
|
|
|
/* Add the renderer framebuffer emulation if desired */
|
|
|
|
if (ShouldUseTextureFramebuffer()) {
|
2011-02-03 15:49:37 -08:00
|
|
|
_this->CreateWindowFramebuffer = SDL_CreateWindowTexture;
|
|
|
|
_this->UpdateWindowFramebuffer = SDL_UpdateWindowTexture;
|
|
|
|
_this->DestroyWindowFramebuffer = SDL_DestroyWindowTexture;
|
|
|
|
}
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
/* We're ready to go! */
|
|
|
|
return 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
const char *
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_GetCurrentVideoDriver()
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return _this->name;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_VideoDevice *
|
2010-06-26 08:56:48 -07:00
|
|
|
SDL_GetVideoDevice(void)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
return _this;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
|
|
|
SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_VideoDisplay display;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_zero(display);
|
|
|
|
if (desktop_mode) {
|
|
|
|
display.desktop_mode = *desktop_mode;
|
|
|
|
}
|
|
|
|
display.current_mode = display.desktop_mode;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
return SDL_AddVideoDisplay(&display);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
|
|
|
SDL_AddVideoDisplay(const SDL_VideoDisplay * display)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_VideoDisplay *displays;
|
|
|
|
int index = -1;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
displays =
|
|
|
|
SDL_realloc(_this->displays,
|
|
|
|
(_this->num_displays + 1) * sizeof(*displays));
|
|
|
|
if (displays) {
|
|
|
|
index = _this->num_displays++;
|
|
|
|
displays[index] = *display;
|
|
|
|
displays[index].device = _this;
|
|
|
|
_this->displays = displays;
|
|
|
|
} else {
|
|
|
|
SDL_OutOfMemory();
|
|
|
|
}
|
|
|
|
return index;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
|
|
|
SDL_GetNumVideoDisplays(void)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return _this->num_displays;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2011-02-21 22:03:39 -08:00
|
|
|
int
|
|
|
|
SDL_GetIndexOfDisplay(SDL_VideoDisplay *display)
|
|
|
|
{
|
|
|
|
int displayIndex;
|
|
|
|
|
|
|
|
for (displayIndex = 0; displayIndex < _this->num_displays; ++displayIndex) {
|
|
|
|
if (display == &_this->displays[displayIndex]) {
|
|
|
|
return displayIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Couldn't find the display, just use index 0 */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-06 08:03:38 +00:00
|
|
|
int
|
2011-02-10 12:14:37 -08:00
|
|
|
SDL_GetDisplayBounds(int displayIndex, SDL_Rect * rect)
|
2009-12-06 08:03:38 +00:00
|
|
|
{
|
2011-02-10 12:14:37 -08:00
|
|
|
CHECK_DISPLAY_INDEX(displayIndex, -1);
|
|
|
|
|
2009-12-06 08:03:38 +00:00
|
|
|
if (rect) {
|
2011-02-10 12:14:37 -08:00
|
|
|
SDL_VideoDisplay *display = &_this->displays[displayIndex];
|
2009-12-06 08:03:38 +00:00
|
|
|
|
|
|
|
if (_this->GetDisplayBounds) {
|
2011-02-11 00:25:44 -08:00
|
|
|
if (_this->GetDisplayBounds(_this, display, rect) == 0) {
|
|
|
|
return 0;
|
2009-12-06 08:03:38 +00:00
|
|
|
}
|
2011-02-11 00:25:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Assume that the displays are left to right */
|
|
|
|
if (displayIndex == 0) {
|
|
|
|
rect->x = 0;
|
|
|
|
rect->y = 0;
|
2009-12-06 08:03:38 +00:00
|
|
|
} else {
|
2011-02-11 00:25:44 -08:00
|
|
|
SDL_GetDisplayBounds(displayIndex-1, rect);
|
|
|
|
rect->x += rect->w;
|
2009-12-06 08:03:38 +00:00
|
|
|
}
|
2011-02-11 00:25:44 -08:00
|
|
|
rect->w = display->desktop_mode.w;
|
|
|
|
rect->h = display->desktop_mode.h;
|
2009-12-06 08:03:38 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_bool
|
2009-12-01 05:57:15 +00:00
|
|
|
SDL_AddDisplayMode(SDL_VideoDisplay * display, const SDL_DisplayMode * mode)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_DisplayMode *modes;
|
|
|
|
int i, nmodes;
|
|
|
|
|
|
|
|
/* Make sure we don't already have the mode in the list */
|
|
|
|
modes = display->display_modes;
|
|
|
|
nmodes = display->num_display_modes;
|
|
|
|
for (i = nmodes; i--;) {
|
|
|
|
if (SDL_memcmp(mode, &modes[i], sizeof(*mode)) == 0) {
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Go ahead and add the new mode */
|
|
|
|
if (nmodes == display->max_display_modes) {
|
|
|
|
modes =
|
|
|
|
SDL_realloc(modes,
|
|
|
|
(display->max_display_modes + 32) * sizeof(*modes));
|
|
|
|
if (!modes) {
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
display->display_modes = modes;
|
|
|
|
display->max_display_modes += 32;
|
|
|
|
}
|
|
|
|
modes[nmodes] = *mode;
|
|
|
|
display->num_display_modes++;
|
|
|
|
|
2009-06-09 08:56:43 +00:00
|
|
|
/* Re-sort video modes */
|
|
|
|
SDL_qsort(display->display_modes, display->num_display_modes,
|
2009-06-10 13:34:20 +00:00
|
|
|
sizeof(SDL_DisplayMode), cmpmodes);
|
2009-06-09 08:56:43 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
return SDL_TRUE;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2011-02-10 14:44:25 -08:00
|
|
|
SDL_VideoDisplay *
|
|
|
|
SDL_GetFirstDisplay(void)
|
|
|
|
{
|
|
|
|
return &_this->displays[0];
|
|
|
|
}
|
|
|
|
|
2011-02-10 12:14:37 -08:00
|
|
|
static int
|
2009-12-01 05:57:15 +00:00
|
|
|
SDL_GetNumDisplayModesForDisplay(SDL_VideoDisplay * display)
|
|
|
|
{
|
|
|
|
if (!display->num_display_modes && _this->GetDisplayModes) {
|
|
|
|
_this->GetDisplayModes(_this, display);
|
|
|
|
SDL_qsort(display->display_modes, display->num_display_modes,
|
|
|
|
sizeof(SDL_DisplayMode), cmpmodes);
|
|
|
|
}
|
|
|
|
return display->num_display_modes;
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
2011-02-10 12:14:37 -08:00
|
|
|
SDL_GetNumDisplayModes(int displayIndex)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2011-02-10 12:14:37 -08:00
|
|
|
CHECK_DISPLAY_INDEX(displayIndex, -1);
|
|
|
|
|
|
|
|
return SDL_GetNumDisplayModesForDisplay(&_this->displays[displayIndex]);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-08-05 22:34:23 +00:00
|
|
|
int
|
2011-02-10 12:14:37 -08:00
|
|
|
SDL_GetDisplayMode(int displayIndex, int index, SDL_DisplayMode * mode)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2011-02-10 12:14:37 -08:00
|
|
|
SDL_VideoDisplay *display;
|
|
|
|
|
|
|
|
CHECK_DISPLAY_INDEX(displayIndex, -1);
|
|
|
|
|
|
|
|
display = &_this->displays[displayIndex];
|
2009-12-01 05:57:15 +00:00
|
|
|
if (index < 0 || index >= SDL_GetNumDisplayModesForDisplay(display)) {
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_SetError("index must be in the range of 0 - %d",
|
2009-12-01 05:57:15 +00:00
|
|
|
SDL_GetNumDisplayModesForDisplay(display) - 1);
|
2008-09-15 04:32:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (mode) {
|
2009-12-01 05:57:15 +00:00
|
|
|
*mode = display->display_modes[index];
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-02-10 12:14:37 -08:00
|
|
|
SDL_GetDesktopDisplayMode(int displayIndex, SDL_DisplayMode * mode)
|
2009-12-01 05:57:15 +00:00
|
|
|
{
|
2011-02-10 12:14:37 -08:00
|
|
|
SDL_VideoDisplay *display;
|
2009-12-01 05:57:15 +00:00
|
|
|
|
2011-02-10 12:14:37 -08:00
|
|
|
CHECK_DISPLAY_INDEX(displayIndex, -1);
|
|
|
|
|
|
|
|
display = &_this->displays[displayIndex];
|
2009-12-01 05:57:15 +00:00
|
|
|
if (mode) {
|
|
|
|
*mode = display->desktop_mode;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
|
|
|
return 0;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-08-05 22:34:23 +00:00
|
|
|
int
|
2011-02-10 12:14:37 -08:00
|
|
|
SDL_GetCurrentDisplayMode(int displayIndex, SDL_DisplayMode * mode)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2011-02-10 12:14:37 -08:00
|
|
|
SDL_VideoDisplay *display;
|
2009-12-01 05:57:15 +00:00
|
|
|
|
2011-02-10 12:14:37 -08:00
|
|
|
CHECK_DISPLAY_INDEX(displayIndex, -1);
|
|
|
|
|
|
|
|
display = &_this->displays[displayIndex];
|
2008-09-15 04:32:36 +00:00
|
|
|
if (mode) {
|
2009-12-01 05:57:15 +00:00
|
|
|
*mode = display->current_mode;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
|
|
|
return 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2011-02-10 12:14:37 -08:00
|
|
|
static SDL_DisplayMode *
|
2009-12-01 05:57:15 +00:00
|
|
|
SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay * display,
|
|
|
|
const SDL_DisplayMode * mode,
|
|
|
|
SDL_DisplayMode * closest)
|
2008-09-15 04:32:36 +00:00
|
|
|
{
|
|
|
|
Uint32 target_format;
|
|
|
|
int target_refresh_rate;
|
|
|
|
int i;
|
|
|
|
SDL_DisplayMode *current, *match;
|
|
|
|
|
2009-12-01 05:57:15 +00:00
|
|
|
if (!mode || !closest) {
|
|
|
|
SDL_SetError("Missing desired mode or closest mode parameter");
|
2008-09-15 04:32:36 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2009-12-01 05:57:15 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
/* Default to the desktop format */
|
|
|
|
if (mode->format) {
|
|
|
|
target_format = mode->format;
|
|
|
|
} else {
|
2009-12-01 05:57:15 +00:00
|
|
|
target_format = display->desktop_mode.format;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Default to the desktop refresh rate */
|
|
|
|
if (mode->refresh_rate) {
|
|
|
|
target_refresh_rate = mode->refresh_rate;
|
|
|
|
} else {
|
2009-12-01 05:57:15 +00:00
|
|
|
target_refresh_rate = display->desktop_mode.refresh_rate;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
match = NULL;
|
2009-12-01 05:57:15 +00:00
|
|
|
for (i = 0; i < SDL_GetNumDisplayModesForDisplay(display); ++i) {
|
|
|
|
current = &display->display_modes[i];
|
2008-09-15 04:32:36 +00:00
|
|
|
|
2008-11-25 20:06:27 +00:00
|
|
|
if (current->w && (current->w < mode->w)) {
|
2008-09-15 04:32:36 +00:00
|
|
|
/* Out of sorted modes large enough here */
|
|
|
|
break;
|
|
|
|
}
|
2008-11-25 20:06:27 +00:00
|
|
|
if (current->h && (current->h < mode->h)) {
|
|
|
|
if (current->w && (current->w == mode->w)) {
|
|
|
|
/* Out of sorted modes large enough here */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Wider, but not tall enough, due to a different
|
|
|
|
aspect ratio. This mode must be skipped, but closer
|
|
|
|
modes may still follow. */
|
|
|
|
continue;
|
|
|
|
}
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!match || current->w < match->w || current->h < match->h) {
|
|
|
|
match = current;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (current->format != match->format) {
|
|
|
|
/* Sorted highest depth to lowest */
|
|
|
|
if (current->format == target_format ||
|
|
|
|
(SDL_BITSPERPIXEL(current->format) >=
|
|
|
|
SDL_BITSPERPIXEL(target_format)
|
|
|
|
&& SDL_PIXELTYPE(current->format) ==
|
|
|
|
SDL_PIXELTYPE(target_format))) {
|
|
|
|
match = current;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (current->refresh_rate != match->refresh_rate) {
|
|
|
|
/* Sorted highest refresh to lowest */
|
|
|
|
if (current->refresh_rate >= target_refresh_rate) {
|
|
|
|
match = current;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (match) {
|
|
|
|
if (match->format) {
|
|
|
|
closest->format = match->format;
|
|
|
|
} else {
|
|
|
|
closest->format = mode->format;
|
|
|
|
}
|
|
|
|
if (match->w && match->h) {
|
|
|
|
closest->w = match->w;
|
|
|
|
closest->h = match->h;
|
|
|
|
} else {
|
|
|
|
closest->w = mode->w;
|
|
|
|
closest->h = mode->h;
|
|
|
|
}
|
|
|
|
if (match->refresh_rate) {
|
|
|
|
closest->refresh_rate = match->refresh_rate;
|
|
|
|
} else {
|
|
|
|
closest->refresh_rate = mode->refresh_rate;
|
|
|
|
}
|
|
|
|
closest->driverdata = match->driverdata;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pick some reasonable defaults if the app and driver don't
|
|
|
|
* care
|
|
|
|
*/
|
|
|
|
if (!closest->format) {
|
|
|
|
closest->format = SDL_PIXELFORMAT_RGB888;
|
|
|
|
}
|
|
|
|
if (!closest->w) {
|
|
|
|
closest->w = 640;
|
|
|
|
}
|
|
|
|
if (!closest->h) {
|
|
|
|
closest->h = 480;
|
|
|
|
}
|
|
|
|
return closest;
|
|
|
|
}
|
|
|
|
return NULL;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2004-02-24 07:42:19 +00:00
|
|
|
|
2009-12-01 05:57:15 +00:00
|
|
|
SDL_DisplayMode *
|
2011-02-10 12:14:37 -08:00
|
|
|
SDL_GetClosestDisplayMode(int displayIndex,
|
|
|
|
const SDL_DisplayMode * mode,
|
2009-12-01 05:57:15 +00:00
|
|
|
SDL_DisplayMode * closest)
|
|
|
|
{
|
2011-02-10 12:14:37 -08:00
|
|
|
SDL_VideoDisplay *display;
|
|
|
|
|
|
|
|
CHECK_DISPLAY_INDEX(displayIndex, NULL);
|
|
|
|
|
|
|
|
display = &_this->displays[displayIndex];
|
|
|
|
return SDL_GetClosestDisplayModeForDisplay(display, mode, closest);
|
2009-12-01 05:57:15 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
2009-12-01 05:57:15 +00:00
|
|
|
SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * mode)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_DisplayMode display_mode;
|
|
|
|
SDL_DisplayMode current_mode;
|
|
|
|
|
2009-12-01 08:56:12 +00:00
|
|
|
if (mode) {
|
|
|
|
display_mode = *mode;
|
2008-09-15 04:32:36 +00:00
|
|
|
|
2009-12-01 08:56:12 +00:00
|
|
|
/* Default to the current mode */
|
|
|
|
if (!display_mode.format) {
|
|
|
|
display_mode.format = display->current_mode.format;
|
|
|
|
}
|
|
|
|
if (!display_mode.w) {
|
|
|
|
display_mode.w = display->current_mode.w;
|
|
|
|
}
|
|
|
|
if (!display_mode.h) {
|
|
|
|
display_mode.h = display->current_mode.h;
|
|
|
|
}
|
|
|
|
if (!display_mode.refresh_rate) {
|
|
|
|
display_mode.refresh_rate = display->current_mode.refresh_rate;
|
|
|
|
}
|
2009-12-01 05:57:15 +00:00
|
|
|
|
2009-12-01 08:56:12 +00:00
|
|
|
/* Get a good video mode, the closest one possible */
|
|
|
|
if (!SDL_GetClosestDisplayModeForDisplay(display, &display_mode, &display_mode)) {
|
|
|
|
SDL_SetError("No video mode large enough for %dx%d",
|
|
|
|
display_mode.w, display_mode.h);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
display_mode = display->desktop_mode;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2009-12-01 05:57:15 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
/* See if there's anything left to do */
|
2011-02-10 12:14:37 -08:00
|
|
|
current_mode = display->current_mode;
|
2008-09-15 04:32:36 +00:00
|
|
|
if (SDL_memcmp(&display_mode, ¤t_mode, sizeof(display_mode)) == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
2009-12-01 05:57:15 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
/* Actually change the display mode */
|
2011-01-12 13:46:37 -08:00
|
|
|
if (!_this->SetDisplayMode) {
|
|
|
|
SDL_SetError("Video driver doesn't support changing display mode");
|
|
|
|
return -1;
|
|
|
|
}
|
2009-12-01 05:57:15 +00:00
|
|
|
if (_this->SetDisplayMode(_this, display, &display_mode) < 0) {
|
2008-09-15 04:32:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
display->current_mode = display_mode;
|
|
|
|
return 0;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2011-02-10 14:44:25 -08:00
|
|
|
int
|
2011-02-21 15:08:36 -08:00
|
|
|
SDL_GetWindowDisplay(SDL_Window * window)
|
2011-02-10 14:44:25 -08:00
|
|
|
{
|
|
|
|
int displayIndex;
|
|
|
|
int i, dist;
|
|
|
|
int closest = -1;
|
|
|
|
int closest_dist = 0x7FFFFFFF;
|
|
|
|
SDL_Point center;
|
|
|
|
SDL_Point delta;
|
|
|
|
SDL_Rect rect;
|
|
|
|
|
|
|
|
CHECK_WINDOW_MAGIC(window, -1);
|
|
|
|
|
|
|
|
if (SDL_WINDOWPOS_ISUNDEFINED(window->x) ||
|
|
|
|
SDL_WINDOWPOS_ISCENTERED(window->x)) {
|
|
|
|
displayIndex = (window->x & 0xFFFF);
|
|
|
|
if (displayIndex >= _this->num_displays) {
|
|
|
|
displayIndex = 0;
|
|
|
|
}
|
|
|
|
return displayIndex;
|
|
|
|
}
|
|
|
|
if (SDL_WINDOWPOS_ISUNDEFINED(window->y) ||
|
|
|
|
SDL_WINDOWPOS_ISCENTERED(window->y)) {
|
|
|
|
displayIndex = (window->y & 0xFFFF);
|
|
|
|
if (displayIndex >= _this->num_displays) {
|
|
|
|
displayIndex = 0;
|
|
|
|
}
|
|
|
|
return displayIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the display containing the window */
|
|
|
|
center.x = window->x + window->w / 2;
|
|
|
|
center.y = window->y + window->h / 2;
|
|
|
|
for (i = 0; i < _this->num_displays; ++i) {
|
|
|
|
SDL_VideoDisplay *display = &_this->displays[i];
|
|
|
|
|
|
|
|
SDL_GetDisplayBounds(i, &rect);
|
|
|
|
if (display->fullscreen_window == window || SDL_EnclosePoints(¢er, 1, &rect, NULL)) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
delta.x = center.x - (rect.x + rect.w / 2);
|
|
|
|
delta.y = center.y - (rect.y + rect.h / 2);
|
|
|
|
dist = (delta.x*delta.x + delta.y*delta.y);
|
|
|
|
if (dist < closest_dist) {
|
|
|
|
closest = i;
|
|
|
|
closest_dist = dist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (closest < 0) {
|
|
|
|
SDL_SetError("Couldn't find any displays");
|
|
|
|
}
|
|
|
|
return closest;
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_VideoDisplay *
|
|
|
|
SDL_GetDisplayForWindow(SDL_Window *window)
|
|
|
|
{
|
2011-02-21 15:08:36 -08:00
|
|
|
int displayIndex = SDL_GetWindowDisplay(window);
|
|
|
|
if (displayIndex >= 0) {
|
|
|
|
return &_this->displays[displayIndex];
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-02-10 14:44:25 -08:00
|
|
|
}
|
|
|
|
|
2009-12-01 05:57:15 +00:00
|
|
|
int
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_SetWindowDisplayMode(SDL_Window * window, const SDL_DisplayMode * mode)
|
2009-12-01 05:57:15 +00:00
|
|
|
{
|
2010-01-24 20:21:51 +00:00
|
|
|
CHECK_WINDOW_MAGIC(window, -1);
|
2008-09-15 04:32:36 +00:00
|
|
|
|
2009-12-01 05:57:15 +00:00
|
|
|
if (mode) {
|
|
|
|
window->fullscreen_mode = *mode;
|
|
|
|
} else {
|
|
|
|
SDL_zero(window->fullscreen_mode);
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2009-12-05 22:13:36 +00:00
|
|
|
return 0;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-08-05 22:34:23 +00:00
|
|
|
int
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_GetWindowDisplayMode(SDL_Window * window, SDL_DisplayMode * mode)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2009-12-01 05:57:15 +00:00
|
|
|
SDL_DisplayMode fullscreen_mode;
|
|
|
|
|
2010-01-24 20:21:51 +00:00
|
|
|
CHECK_WINDOW_MAGIC(window, -1);
|
2009-12-01 05:57:15 +00:00
|
|
|
|
|
|
|
fullscreen_mode = window->fullscreen_mode;
|
|
|
|
if (!fullscreen_mode.w) {
|
|
|
|
fullscreen_mode.w = window->w;
|
|
|
|
}
|
|
|
|
if (!fullscreen_mode.h) {
|
|
|
|
fullscreen_mode.h = window->h;
|
|
|
|
}
|
|
|
|
|
2011-02-10 14:44:25 -08:00
|
|
|
if (!SDL_GetClosestDisplayModeForDisplay(SDL_GetDisplayForWindow(window),
|
2009-12-01 05:57:15 +00:00
|
|
|
&fullscreen_mode,
|
|
|
|
&fullscreen_mode)) {
|
|
|
|
SDL_SetError("Couldn't find display mode match");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (mode) {
|
2009-12-01 05:57:15 +00:00
|
|
|
*mode = fullscreen_mode;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
|
|
|
return 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2004-07-18 19:46:38 +00:00
|
|
|
|
2011-02-02 14:34:54 -08:00
|
|
|
Uint32
|
|
|
|
SDL_GetWindowPixelFormat(SDL_Window * window)
|
|
|
|
{
|
2011-02-10 14:44:25 -08:00
|
|
|
SDL_VideoDisplay *display;
|
|
|
|
|
|
|
|
CHECK_WINDOW_MAGIC(window, SDL_PIXELFORMAT_UNKNOWN);
|
|
|
|
|
|
|
|
display = SDL_GetDisplayForWindow(window);
|
|
|
|
return display->current_mode.format;
|
2011-02-02 14:34:54 -08:00
|
|
|
}
|
|
|
|
|
2009-12-01 08:56:12 +00:00
|
|
|
static void
|
2011-02-15 23:07:14 -08:00
|
|
|
SDL_UpdateFullscreenMode(SDL_Window * window)
|
2009-12-01 08:56:12 +00:00
|
|
|
{
|
2011-02-10 14:44:25 -08:00
|
|
|
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
2011-02-11 00:25:44 -08:00
|
|
|
SDL_Window *other;
|
2009-12-01 08:56:12 +00:00
|
|
|
|
|
|
|
if (FULLSCREEN_VISIBLE(window)) {
|
|
|
|
/* Hide any other fullscreen windows */
|
2011-02-11 00:25:44 -08:00
|
|
|
if (display->fullscreen_window &&
|
|
|
|
display->fullscreen_window != window) {
|
2011-02-10 14:44:25 -08:00
|
|
|
SDL_MinimizeWindow(display->fullscreen_window);
|
2009-12-01 08:56:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-15 23:07:14 -08:00
|
|
|
/* See if anything needs to be done now */
|
|
|
|
if ((display->fullscreen_window == window) == FULLSCREEN_VISIBLE(window)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-12-01 08:56:12 +00:00
|
|
|
/* See if there are any fullscreen windows */
|
2011-02-11 00:25:44 -08:00
|
|
|
for (other = _this->windows; other; other = other->next) {
|
|
|
|
if (FULLSCREEN_VISIBLE(other) &&
|
|
|
|
SDL_GetDisplayForWindow(other) == display) {
|
2009-12-01 08:56:12 +00:00
|
|
|
SDL_DisplayMode fullscreen_mode;
|
2011-02-11 00:25:44 -08:00
|
|
|
if (SDL_GetWindowDisplayMode(other, &fullscreen_mode) == 0) {
|
2011-02-16 00:11:48 -08:00
|
|
|
SDL_bool resized = SDL_TRUE;
|
|
|
|
|
|
|
|
if (other->w == fullscreen_mode.w && other->h == fullscreen_mode.h) {
|
|
|
|
resized = SDL_FALSE;
|
2011-02-11 00:25:44 -08:00
|
|
|
}
|
|
|
|
|
2009-12-01 08:56:12 +00:00
|
|
|
SDL_SetDisplayModeForDisplay(display, &fullscreen_mode);
|
2011-02-11 00:25:44 -08:00
|
|
|
if (_this->SetWindowFullscreen) {
|
2011-02-15 23:07:14 -08:00
|
|
|
_this->SetWindowFullscreen(_this, other, display, SDL_TRUE);
|
2011-02-11 00:25:44 -08:00
|
|
|
}
|
|
|
|
display->fullscreen_window = other;
|
|
|
|
|
2011-02-16 00:11:48 -08:00
|
|
|
/* Generate a mode change event here */
|
|
|
|
if (resized) {
|
|
|
|
SDL_SendWindowEvent(other, SDL_WINDOWEVENT_RESIZED,
|
|
|
|
fullscreen_mode.w, fullscreen_mode.h);
|
|
|
|
} else {
|
|
|
|
SDL_OnWindowResized(other);
|
|
|
|
}
|
2009-12-01 08:56:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Nope, restore the desktop mode */
|
|
|
|
SDL_SetDisplayModeForDisplay(display, NULL);
|
2011-02-11 00:25:44 -08:00
|
|
|
|
|
|
|
if (_this->SetWindowFullscreen) {
|
2011-02-15 23:07:14 -08:00
|
|
|
_this->SetWindowFullscreen(_this, window, display, SDL_FALSE);
|
2011-02-11 00:25:44 -08:00
|
|
|
}
|
2009-12-03 08:33:39 +00:00
|
|
|
display->fullscreen_window = NULL;
|
2011-02-16 00:11:48 -08:00
|
|
|
|
|
|
|
/* Generate a mode change event here */
|
|
|
|
SDL_OnWindowResized(window);
|
2009-12-01 08:56:12 +00:00
|
|
|
}
|
|
|
|
|
2011-02-21 22:03:39 -08:00
|
|
|
#define CREATE_FLAGS \
|
|
|
|
(SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS | SDL_WINDOW_RESIZABLE)
|
|
|
|
|
|
|
|
static void
|
|
|
|
SDL_FinishWindowCreation(SDL_Window *window, Uint32 flags)
|
|
|
|
{
|
2011-02-26 10:11:09 -08:00
|
|
|
window->windowed.x = window->x;
|
|
|
|
window->windowed.y = window->y;
|
|
|
|
window->windowed.w = window->w;
|
|
|
|
window->windowed.h = window->h;
|
|
|
|
|
2011-02-21 22:03:39 -08:00
|
|
|
if (flags & SDL_WINDOW_MAXIMIZED) {
|
|
|
|
SDL_MaximizeWindow(window);
|
|
|
|
}
|
|
|
|
if (flags & SDL_WINDOW_MINIMIZED) {
|
|
|
|
SDL_MinimizeWindow(window);
|
|
|
|
}
|
|
|
|
if (flags & SDL_WINDOW_FULLSCREEN) {
|
|
|
|
SDL_SetWindowFullscreen(window, SDL_TRUE);
|
|
|
|
}
|
|
|
|
if (flags & SDL_WINDOW_INPUT_GRABBED) {
|
|
|
|
SDL_SetWindowGrab(window, SDL_TRUE);
|
|
|
|
}
|
|
|
|
if (!(flags & SDL_WINDOW_HIDDEN)) {
|
|
|
|
SDL_ShowWindow(window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_Window *
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
|
|
|
|
{
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_Window *window;
|
2008-09-15 04:32:36 +00:00
|
|
|
|
|
|
|
if (!_this) {
|
2009-10-28 06:04:07 +00:00
|
|
|
/* Initialize the video system if needed */
|
2011-01-27 22:44:08 -08:00
|
|
|
if (SDL_VideoInit(NULL) < 0) {
|
2010-01-21 06:21:52 +00:00
|
|
|
return NULL;
|
2009-10-28 06:04:07 +00:00
|
|
|
}
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2011-02-11 00:25:44 -08:00
|
|
|
|
|
|
|
/* Some platforms have OpenGL enabled by default */
|
|
|
|
#if (SDL_VIDEO_OPENGL && __MACOSX__) || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
|
|
|
|
flags |= SDL_WINDOW_OPENGL;
|
|
|
|
#endif
|
2009-02-09 05:32:12 +00:00
|
|
|
if (flags & SDL_WINDOW_OPENGL) {
|
|
|
|
if (!_this->GL_CreateContext) {
|
|
|
|
SDL_SetError("No OpenGL support in video driver");
|
2010-01-21 06:21:52 +00:00
|
|
|
return NULL;
|
2009-02-09 05:32:12 +00:00
|
|
|
}
|
|
|
|
SDL_GL_LoadLibrary(NULL);
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2010-01-21 06:21:52 +00:00
|
|
|
window = (SDL_Window *)SDL_calloc(1, sizeof(*window));
|
2010-01-24 20:21:51 +00:00
|
|
|
window->magic = &_this->window_magic;
|
2010-01-21 06:21:52 +00:00
|
|
|
window->id = _this->next_object_id++;
|
|
|
|
window->x = x;
|
|
|
|
window->y = y;
|
|
|
|
window->w = w;
|
|
|
|
window->h = h;
|
2011-02-21 22:03:39 -08:00
|
|
|
if (SDL_WINDOWPOS_ISUNDEFINED(x) || SDL_WINDOWPOS_ISUNDEFINED(y) ||
|
|
|
|
SDL_WINDOWPOS_ISCENTERED(x) || SDL_WINDOWPOS_ISCENTERED(y)) {
|
|
|
|
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
|
|
|
int displayIndex;
|
|
|
|
SDL_Rect bounds;
|
|
|
|
|
|
|
|
displayIndex = SDL_GetIndexOfDisplay(display);
|
|
|
|
SDL_GetDisplayBounds(displayIndex, &bounds);
|
|
|
|
if (SDL_WINDOWPOS_ISUNDEFINED(x) || SDL_WINDOWPOS_ISCENTERED(y)) {
|
|
|
|
window->x = bounds.x + (bounds.w - w) / 2;
|
|
|
|
}
|
|
|
|
if (SDL_WINDOWPOS_ISUNDEFINED(y) || SDL_WINDOWPOS_ISCENTERED(y)) {
|
|
|
|
window->y = bounds.y + (bounds.h - h) / 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
window->flags = ((flags & CREATE_FLAGS) | SDL_WINDOW_HIDDEN);
|
2011-02-10 14:44:25 -08:00
|
|
|
window->next = _this->windows;
|
|
|
|
if (_this->windows) {
|
|
|
|
_this->windows->prev = window;
|
2010-01-22 16:17:11 +00:00
|
|
|
}
|
2011-02-10 14:44:25 -08:00
|
|
|
_this->windows = window;
|
2008-09-15 04:32:36 +00:00
|
|
|
|
2010-01-21 06:21:52 +00:00
|
|
|
if (_this->CreateWindow && _this->CreateWindow(_this, window) < 0) {
|
|
|
|
SDL_DestroyWindow(window);
|
|
|
|
return NULL;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (title) {
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_SetWindowTitle(window, title);
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2011-02-21 22:03:39 -08:00
|
|
|
SDL_FinishWindowCreation(window, flags);
|
2008-12-17 07:17:54 +00:00
|
|
|
|
2010-01-21 06:21:52 +00:00
|
|
|
return window;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_Window *
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_CreateWindowFrom(const void *data)
|
|
|
|
{
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_Window *window;
|
2008-09-15 04:32:36 +00:00
|
|
|
|
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
2010-01-21 06:21:52 +00:00
|
|
|
return NULL;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2010-01-21 06:21:52 +00:00
|
|
|
window = (SDL_Window *)SDL_calloc(1, sizeof(*window));
|
2010-01-24 20:21:51 +00:00
|
|
|
window->magic = &_this->window_magic;
|
2010-01-21 06:21:52 +00:00
|
|
|
window->id = _this->next_object_id++;
|
|
|
|
window->flags = SDL_WINDOW_FOREIGN;
|
2011-02-10 14:44:25 -08:00
|
|
|
window->next = _this->windows;
|
|
|
|
if (_this->windows) {
|
|
|
|
_this->windows->prev = window;
|
2010-01-22 16:17:11 +00:00
|
|
|
}
|
2011-02-10 14:44:25 -08:00
|
|
|
_this->windows = window;
|
2008-09-15 04:32:36 +00:00
|
|
|
|
|
|
|
if (!_this->CreateWindowFrom ||
|
2010-01-21 06:21:52 +00:00
|
|
|
_this->CreateWindowFrom(_this, window, data) < 0) {
|
|
|
|
SDL_DestroyWindow(window);
|
|
|
|
return NULL;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2010-01-21 06:21:52 +00:00
|
|
|
return window;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-22 21:02:57 +00:00
|
|
|
int
|
2006-07-23 00:19:12 +00:00
|
|
|
SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
|
2006-07-22 21:02:57 +00:00
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
char *title = window->title;
|
|
|
|
|
|
|
|
if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) {
|
|
|
|
SDL_SetError("No OpenGL support in video driver");
|
|
|
|
return -1;
|
|
|
|
}
|
2009-02-09 05:32:12 +00:00
|
|
|
|
|
|
|
if (window->flags & SDL_WINDOW_FOREIGN) {
|
|
|
|
/* Can't destroy and re-create foreign windows, hrm */
|
|
|
|
flags |= SDL_WINDOW_FOREIGN;
|
|
|
|
} else {
|
|
|
|
flags &= ~SDL_WINDOW_FOREIGN;
|
|
|
|
}
|
|
|
|
|
2011-02-11 00:25:44 -08:00
|
|
|
/* Restore video mode, etc. */
|
2011-02-15 23:07:14 -08:00
|
|
|
SDL_HideWindow(window);
|
2011-02-11 00:25:44 -08:00
|
|
|
|
|
|
|
/* Tear down the old native window */
|
|
|
|
if (window->surface) {
|
2011-02-13 13:46:10 -08:00
|
|
|
window->surface->flags &= ~SDL_DONTFREE;
|
2011-02-11 00:25:44 -08:00
|
|
|
SDL_FreeSurface(window->surface);
|
|
|
|
}
|
|
|
|
if (_this->DestroyWindowFramebuffer) {
|
|
|
|
_this->DestroyWindowFramebuffer(_this, window);
|
|
|
|
}
|
2009-02-09 05:32:12 +00:00
|
|
|
if (_this->DestroyWindow && !(flags & SDL_WINDOW_FOREIGN)) {
|
2008-09-15 04:32:36 +00:00
|
|
|
_this->DestroyWindow(_this, window);
|
|
|
|
}
|
2009-02-09 05:32:12 +00:00
|
|
|
|
2011-02-11 00:25:44 -08:00
|
|
|
if ((window->flags & SDL_WINDOW_OPENGL) != (flags & SDL_WINDOW_OPENGL)) {
|
|
|
|
if (flags & SDL_WINDOW_OPENGL) {
|
|
|
|
SDL_GL_LoadLibrary(NULL);
|
|
|
|
} else {
|
|
|
|
SDL_GL_UnloadLibrary();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
window->title = NULL;
|
2011-02-21 22:03:39 -08:00
|
|
|
window->flags = ((flags & CREATE_FLAGS) | SDL_WINDOW_HIDDEN);
|
2008-09-15 04:32:36 +00:00
|
|
|
|
2009-02-09 05:32:12 +00:00
|
|
|
if (_this->CreateWindow && !(flags & SDL_WINDOW_FOREIGN)) {
|
|
|
|
if (_this->CreateWindow(_this, window) < 0) {
|
|
|
|
if (flags & SDL_WINDOW_OPENGL) {
|
|
|
|
SDL_GL_UnloadLibrary();
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2009-02-09 05:32:12 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (title) {
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_SetWindowTitle(window, title);
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_free(title);
|
|
|
|
}
|
2011-02-21 22:03:39 -08:00
|
|
|
SDL_FinishWindowCreation(window, flags);
|
2008-12-17 07:17:54 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-01-21 06:21:52 +00:00
|
|
|
Uint32
|
|
|
|
SDL_GetWindowID(SDL_Window * window)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2010-01-24 20:21:51 +00:00
|
|
|
CHECK_WINDOW_MAGIC(window, 0);
|
|
|
|
|
2010-01-21 06:21:52 +00:00
|
|
|
return window->id;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_Window *
|
|
|
|
SDL_GetWindowFromID(Uint32 id)
|
2009-10-28 06:04:07 +00:00
|
|
|
{
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_Window *window;
|
|
|
|
|
2009-10-28 06:04:07 +00:00
|
|
|
if (!_this) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-02-10 14:44:25 -08:00
|
|
|
for (window = _this->windows; window; window = window->next) {
|
|
|
|
if (window->id == id) {
|
|
|
|
return window;
|
2009-10-28 06:04:07 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-21 06:21:52 +00:00
|
|
|
return NULL;
|
2009-10-28 06:04:07 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
Uint32
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_GetWindowFlags(SDL_Window * window)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2010-01-24 20:21:51 +00:00
|
|
|
CHECK_WINDOW_MAGIC(window, 0);
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
return window->flags;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_SetWindowTitle(SDL_Window * window, const char *title)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2010-01-24 20:21:51 +00:00
|
|
|
CHECK_WINDOW_MAGIC(window, );
|
|
|
|
|
|
|
|
if (title == window->title) {
|
2008-09-15 04:32:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (window->title) {
|
|
|
|
SDL_free(window->title);
|
|
|
|
}
|
2010-08-29 16:26:35 -07:00
|
|
|
if (title && *title) {
|
2008-09-15 04:32:36 +00:00
|
|
|
window->title = SDL_strdup(title);
|
|
|
|
} else {
|
|
|
|
window->title = NULL;
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (_this->SetWindowTitle) {
|
|
|
|
_this->SetWindowTitle(_this, window);
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
const char *
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_GetWindowTitle(SDL_Window * window)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2010-08-29 16:28:04 -07:00
|
|
|
CHECK_WINDOW_MAGIC(window, "");
|
2010-01-24 20:21:51 +00:00
|
|
|
|
2010-08-29 16:26:35 -07:00
|
|
|
return window->title ? window->title : "";
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2009-01-02 17:39:48 +00:00
|
|
|
void
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_SetWindowIcon(SDL_Window * window, SDL_Surface * icon)
|
2009-01-02 17:39:48 +00:00
|
|
|
{
|
2010-01-24 20:21:51 +00:00
|
|
|
CHECK_WINDOW_MAGIC(window, );
|
|
|
|
|
2011-02-21 16:45:23 -08:00
|
|
|
if (!icon) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-02 17:39:48 +00:00
|
|
|
if (_this->SetWindowIcon) {
|
|
|
|
_this->SetWindowIcon(_this, window, icon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-03 11:16:57 -08:00
|
|
|
void*
|
|
|
|
SDL_SetWindowData(SDL_Window * window, const char *name, void *userdata)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2011-02-03 11:16:57 -08:00
|
|
|
SDL_WindowUserData *prev, *data;
|
|
|
|
|
|
|
|
CHECK_WINDOW_MAGIC(window, NULL);
|
|
|
|
|
|
|
|
/* See if the named data already exists */
|
|
|
|
prev = NULL;
|
|
|
|
for (data = window->data; data; prev = data, data = data->next) {
|
|
|
|
if (SDL_strcmp(data->name, name) == 0) {
|
|
|
|
void *last_value = data->data;
|
|
|
|
|
|
|
|
if (userdata) {
|
|
|
|
/* Set the new value */
|
|
|
|
data->data = userdata;
|
|
|
|
} else {
|
|
|
|
/* Delete this value */
|
|
|
|
if (prev) {
|
|
|
|
prev->next = data->next;
|
|
|
|
} else {
|
|
|
|
window->data = data->next;
|
|
|
|
}
|
|
|
|
SDL_free(data->name);
|
|
|
|
SDL_free(data);
|
|
|
|
}
|
|
|
|
return last_value;
|
|
|
|
}
|
|
|
|
}
|
2010-01-24 20:21:51 +00:00
|
|
|
|
2011-02-03 11:16:57 -08:00
|
|
|
/* Add new data to the window */
|
|
|
|
if (userdata) {
|
|
|
|
data = (SDL_WindowUserData *)SDL_malloc(sizeof(*data));
|
|
|
|
data->name = SDL_strdup(name);
|
|
|
|
data->data = userdata;
|
|
|
|
data->next = window->data;
|
|
|
|
window->data = data;
|
|
|
|
}
|
|
|
|
return NULL;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
void *
|
2011-02-03 11:16:57 -08:00
|
|
|
SDL_GetWindowData(SDL_Window * window, const char *name)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2011-02-03 11:16:57 -08:00
|
|
|
SDL_WindowUserData *data;
|
|
|
|
|
2010-01-24 20:21:51 +00:00
|
|
|
CHECK_WINDOW_MAGIC(window, NULL);
|
|
|
|
|
2011-02-03 11:16:57 -08:00
|
|
|
for (data = window->data; data; data = data->next) {
|
|
|
|
if (SDL_strcmp(data->name, name) == 0) {
|
|
|
|
return data->data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_SetWindowPosition(SDL_Window * window, int x, int y)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2010-01-24 20:21:51 +00:00
|
|
|
CHECK_WINDOW_MAGIC(window, );
|
|
|
|
|
2011-02-15 23:07:14 -08:00
|
|
|
if (!SDL_WINDOWPOS_ISUNDEFINED(x)) {
|
2008-09-15 04:32:36 +00:00
|
|
|
window->x = x;
|
|
|
|
}
|
2011-02-15 23:07:14 -08:00
|
|
|
if (!SDL_WINDOWPOS_ISUNDEFINED(y)) {
|
2008-09-15 04:32:36 +00:00
|
|
|
window->y = y;
|
|
|
|
}
|
2011-02-10 14:44:25 -08:00
|
|
|
if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
|
|
|
|
if (_this->SetWindowPosition) {
|
|
|
|
_this->SetWindowPosition(_this, window);
|
|
|
|
}
|
|
|
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_GetWindowPosition(SDL_Window * window, int *x, int *y)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2011-02-10 14:44:25 -08:00
|
|
|
/* Clear the values */
|
|
|
|
if (x) {
|
|
|
|
*x = 0;
|
|
|
|
}
|
|
|
|
if (y) {
|
|
|
|
*y = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CHECK_WINDOW_MAGIC(window, );
|
|
|
|
|
|
|
|
/* Fullscreen windows are always at their display's origin */
|
|
|
|
if (window->flags & SDL_WINDOW_FULLSCREEN) {
|
|
|
|
} else {
|
2011-02-10 10:37:35 -08:00
|
|
|
if (x) {
|
|
|
|
*x = window->x;
|
|
|
|
}
|
|
|
|
if (y) {
|
|
|
|
*y = window->y;
|
|
|
|
}
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_SetWindowSize(SDL_Window * window, int w, int h)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2010-01-24 20:21:51 +00:00
|
|
|
CHECK_WINDOW_MAGIC(window, );
|
|
|
|
|
2011-02-11 00:25:44 -08:00
|
|
|
/* FIXME: Should this change fullscreen modes? */
|
|
|
|
if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
|
2011-02-12 19:02:14 -08:00
|
|
|
window->w = w;
|
|
|
|
window->h = h;
|
2011-02-11 00:25:44 -08:00
|
|
|
if (_this->SetWindowSize) {
|
|
|
|
_this->SetWindowSize(_this, window);
|
|
|
|
}
|
2011-02-12 19:02:14 -08:00
|
|
|
if (window->w == w && window->h == h) {
|
|
|
|
/* We didn't get a SDL_WINDOWEVENT_RESIZED event (by design) */
|
|
|
|
SDL_OnWindowResized(window);
|
|
|
|
}
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_GetWindowSize(SDL_Window * window, int *w, int *h)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2011-02-10 14:44:25 -08:00
|
|
|
int dummy;
|
|
|
|
|
|
|
|
if (!w) {
|
|
|
|
w = &dummy;
|
|
|
|
}
|
|
|
|
if (!h) {
|
|
|
|
h = &dummy;
|
|
|
|
}
|
|
|
|
|
|
|
|
*w = 0;
|
|
|
|
*h = 0;
|
|
|
|
|
|
|
|
CHECK_WINDOW_MAGIC(window, );
|
|
|
|
|
2011-02-10 10:37:35 -08:00
|
|
|
if (_this && window && window->magic == &_this->window_magic) {
|
2008-12-07 21:53:28 +00:00
|
|
|
if (w) {
|
|
|
|
*w = window->w;
|
|
|
|
}
|
|
|
|
if (h) {
|
|
|
|
*h = window->h;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (w) {
|
|
|
|
*w = 0;
|
|
|
|
}
|
|
|
|
if (h) {
|
|
|
|
*h = 0;
|
|
|
|
}
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_ShowWindow(SDL_Window * window)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2010-01-24 20:21:51 +00:00
|
|
|
CHECK_WINDOW_MAGIC(window, );
|
|
|
|
|
|
|
|
if (window->flags & SDL_WINDOW_SHOWN) {
|
2008-09-15 04:32:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (_this->ShowWindow) {
|
|
|
|
_this->ShowWindow(_this, window);
|
|
|
|
}
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SHOWN, 0, 0);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_HideWindow(SDL_Window * window)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2010-01-24 20:21:51 +00:00
|
|
|
CHECK_WINDOW_MAGIC(window, );
|
|
|
|
|
|
|
|
if (!(window->flags & SDL_WINDOW_SHOWN)) {
|
2008-09-15 04:32:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (_this->HideWindow) {
|
|
|
|
_this->HideWindow(_this, window);
|
|
|
|
}
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_RaiseWindow(SDL_Window * window)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2010-01-24 20:21:51 +00:00
|
|
|
CHECK_WINDOW_MAGIC(window, );
|
|
|
|
|
|
|
|
if (!(window->flags & SDL_WINDOW_SHOWN)) {
|
2008-09-15 04:32:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_this->RaiseWindow) {
|
|
|
|
_this->RaiseWindow(_this, window);
|
2009-12-01 08:56:12 +00:00
|
|
|
} else {
|
|
|
|
/* FIXME: What we really want is a way to request focus */
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_MaximizeWindow(SDL_Window * window)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2010-01-24 20:21:51 +00:00
|
|
|
CHECK_WINDOW_MAGIC(window, );
|
|
|
|
|
|
|
|
if (window->flags & SDL_WINDOW_MAXIMIZED) {
|
2008-09-15 04:32:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (_this->MaximizeWindow) {
|
|
|
|
_this->MaximizeWindow(_this, window);
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_MinimizeWindow(SDL_Window * window)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2010-01-24 20:21:51 +00:00
|
|
|
CHECK_WINDOW_MAGIC(window, );
|
|
|
|
|
|
|
|
if (window->flags & SDL_WINDOW_MINIMIZED) {
|
2008-09-15 04:32:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (_this->MinimizeWindow) {
|
|
|
|
_this->MinimizeWindow(_this, window);
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
|
|
|
void
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_RestoreWindow(SDL_Window * window)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2010-01-24 20:21:51 +00:00
|
|
|
CHECK_WINDOW_MAGIC(window, );
|
|
|
|
|
|
|
|
if (!(window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) {
|
2008-09-15 04:32:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (_this->RestoreWindow) {
|
|
|
|
_this->RestoreWindow(_this, window);
|
|
|
|
}
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-02-10 14:44:25 -08:00
|
|
|
SDL_SetWindowFullscreen(SDL_Window * window, SDL_bool fullscreen)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2010-01-24 20:21:51 +00:00
|
|
|
CHECK_WINDOW_MAGIC(window, -1);
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (fullscreen) {
|
|
|
|
fullscreen = SDL_WINDOW_FULLSCREEN;
|
|
|
|
}
|
|
|
|
if ((window->flags & SDL_WINDOW_FULLSCREEN) == fullscreen) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (fullscreen) {
|
|
|
|
window->flags |= SDL_WINDOW_FULLSCREEN;
|
|
|
|
} else {
|
|
|
|
window->flags &= ~SDL_WINDOW_FULLSCREEN;
|
|
|
|
}
|
2011-02-15 23:07:14 -08:00
|
|
|
SDL_UpdateFullscreenMode(window);
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
return 0;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2011-02-03 15:49:37 -08:00
|
|
|
static SDL_Surface *
|
|
|
|
SDL_CreateWindowFramebuffer(SDL_Window * window)
|
|
|
|
{
|
|
|
|
Uint32 format;
|
|
|
|
void *pixels;
|
|
|
|
int pitch;
|
|
|
|
int bpp;
|
|
|
|
Uint32 Rmask, Gmask, Bmask, Amask;
|
|
|
|
|
|
|
|
if (!_this->CreateWindowFramebuffer || !_this->UpdateWindowFramebuffer) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_this->CreateWindowFramebuffer(_this, window, &format, &pixels, &pitch) < 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SDL_CreateRGBSurfaceFrom(pixels, window->w, window->h, bpp, pitch, Rmask, Gmask, Bmask, Amask);
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_Surface *
|
|
|
|
SDL_GetWindowSurface(SDL_Window * window)
|
|
|
|
{
|
|
|
|
CHECK_WINDOW_MAGIC(window, NULL);
|
|
|
|
|
2011-02-04 12:24:28 -08:00
|
|
|
if (!window->surface_valid) {
|
|
|
|
if (window->surface) {
|
2011-02-13 13:46:10 -08:00
|
|
|
window->surface->flags &= ~SDL_DONTFREE;
|
2011-02-04 12:24:28 -08:00
|
|
|
SDL_FreeSurface(window->surface);
|
|
|
|
}
|
2011-02-03 15:49:37 -08:00
|
|
|
window->surface = SDL_CreateWindowFramebuffer(window);
|
2011-02-03 21:13:55 -08:00
|
|
|
if (window->surface) {
|
2011-02-04 12:24:28 -08:00
|
|
|
window->surface_valid = SDL_TRUE;
|
2011-02-13 13:46:10 -08:00
|
|
|
window->surface->flags |= SDL_DONTFREE;
|
2011-02-03 21:13:55 -08:00
|
|
|
}
|
2011-02-03 15:49:37 -08:00
|
|
|
}
|
|
|
|
return window->surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_UpdateWindowSurface(SDL_Window * window)
|
|
|
|
{
|
|
|
|
SDL_Rect full_rect;
|
|
|
|
|
|
|
|
CHECK_WINDOW_MAGIC(window, -1);
|
|
|
|
|
|
|
|
full_rect.x = 0;
|
|
|
|
full_rect.y = 0;
|
|
|
|
full_rect.w = window->w;
|
|
|
|
full_rect.h = window->h;
|
2011-02-15 13:59:59 -08:00
|
|
|
return SDL_UpdateWindowSurfaceRects(window, &full_rect, 1);
|
2011-02-03 15:49:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-02-15 13:59:59 -08:00
|
|
|
SDL_UpdateWindowSurfaceRects(SDL_Window * window, SDL_Rect * rects,
|
|
|
|
int numrects)
|
2011-02-03 15:49:37 -08:00
|
|
|
{
|
|
|
|
CHECK_WINDOW_MAGIC(window, -1);
|
|
|
|
|
2011-02-04 12:24:28 -08:00
|
|
|
if (!window->surface_valid) {
|
2011-02-03 15:49:37 -08:00
|
|
|
SDL_SetError("Window surface is invalid, please call SDL_GetWindowSurface() to get a new surface");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-02-15 13:59:59 -08:00
|
|
|
return _this->UpdateWindowFramebuffer(_this, window, rects, numrects);
|
2011-02-03 15:49:37 -08:00
|
|
|
}
|
|
|
|
|
2011-02-27 20:06:45 -08:00
|
|
|
static void
|
|
|
|
SDL_UpdateWindowGrab(SDL_Window * window)
|
|
|
|
{
|
|
|
|
if ((window->flags & SDL_WINDOW_INPUT_FOCUS) && _this->SetWindowGrab) {
|
|
|
|
_this->SetWindowGrab(_this, window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
2011-02-27 20:06:45 -08:00
|
|
|
SDL_SetWindowGrab(SDL_Window * window, SDL_bool grabbed)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2010-01-24 20:21:51 +00:00
|
|
|
CHECK_WINDOW_MAGIC(window, );
|
|
|
|
|
2011-02-27 20:06:45 -08:00
|
|
|
if ((!!grabbed == !!(window->flags & SDL_WINDOW_INPUT_GRABBED))) {
|
2008-09-15 04:32:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-02-27 20:06:45 -08:00
|
|
|
if (grabbed) {
|
2008-09-15 04:32:36 +00:00
|
|
|
window->flags |= SDL_WINDOW_INPUT_GRABBED;
|
|
|
|
} else {
|
|
|
|
window->flags &= ~SDL_WINDOW_INPUT_GRABBED;
|
|
|
|
}
|
2008-12-17 07:17:54 +00:00
|
|
|
SDL_UpdateWindowGrab(window);
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2011-02-27 20:06:45 -08:00
|
|
|
SDL_bool
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_GetWindowGrab(SDL_Window * window)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2010-01-24 20:21:51 +00:00
|
|
|
CHECK_WINDOW_MAGIC(window, 0);
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
return ((window->flags & SDL_WINDOW_INPUT_GRABBED) != 0);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_OnWindowShown(SDL_Window * window)
|
|
|
|
{
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_RaiseWindow(window);
|
2011-02-15 23:07:14 -08:00
|
|
|
SDL_UpdateFullscreenMode(window);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_OnWindowHidden(SDL_Window * window)
|
|
|
|
{
|
2011-02-15 23:07:14 -08:00
|
|
|
SDL_UpdateFullscreenMode(window);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
2011-02-03 15:49:37 -08:00
|
|
|
void
|
|
|
|
SDL_OnWindowResized(SDL_Window * window)
|
|
|
|
{
|
2011-02-04 12:24:28 -08:00
|
|
|
window->surface_valid = SDL_FALSE;
|
2011-02-12 19:02:14 -08:00
|
|
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SIZE_CHANGED, window->w, window->h);
|
2011-02-03 15:49:37 -08:00
|
|
|
}
|
|
|
|
|
2009-12-01 08:56:12 +00:00
|
|
|
void
|
|
|
|
SDL_OnWindowMinimized(SDL_Window * window)
|
|
|
|
{
|
2011-02-15 23:07:14 -08:00
|
|
|
SDL_UpdateFullscreenMode(window);
|
2009-12-01 08:56:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_OnWindowRestored(SDL_Window * window)
|
|
|
|
{
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_RaiseWindow(window);
|
2011-02-15 23:07:14 -08:00
|
|
|
SDL_UpdateFullscreenMode(window);
|
2009-12-01 08:56:12 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_OnWindowFocusGained(SDL_Window * window)
|
|
|
|
{
|
2008-12-17 07:19:55 +00:00
|
|
|
if ((window->flags & (SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_FULLSCREEN))
|
|
|
|
&& _this->SetWindowGrab) {
|
2008-09-15 04:32:36 +00:00
|
|
|
_this->SetWindowGrab(_this, window);
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_OnWindowFocusLost(SDL_Window * window)
|
|
|
|
{
|
2009-12-02 07:42:10 +00:00
|
|
|
/* If we're fullscreen on a single-head system and lose focus, minimize */
|
|
|
|
if ((window->flags & SDL_WINDOW_FULLSCREEN) &&
|
|
|
|
_this->num_displays == 1) {
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_MinimizeWindow(window);
|
2009-12-02 07:42:10 +00:00
|
|
|
}
|
|
|
|
|
2008-12-17 07:19:55 +00:00
|
|
|
if ((window->flags & (SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_FULLSCREEN))
|
|
|
|
&& _this->SetWindowGrab) {
|
2008-09-15 04:32:36 +00:00
|
|
|
_this->SetWindowGrab(_this, window);
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_Window *
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_GetFocusWindow(void)
|
|
|
|
{
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_Window *window;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this) {
|
2010-01-21 06:21:52 +00:00
|
|
|
return NULL;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2011-02-10 14:44:25 -08:00
|
|
|
for (window = _this->windows; window; window = window->next) {
|
2008-09-15 04:32:36 +00:00
|
|
|
if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
|
2010-01-21 06:21:52 +00:00
|
|
|
return window;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-21 06:21:52 +00:00
|
|
|
return NULL;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_DestroyWindow(SDL_Window * window)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_VideoDisplay *display;
|
2008-09-15 04:32:36 +00:00
|
|
|
|
2010-01-24 20:21:51 +00:00
|
|
|
CHECK_WINDOW_MAGIC(window, );
|
2009-12-01 09:04:28 +00:00
|
|
|
|
2010-01-21 06:21:52 +00:00
|
|
|
/* Restore video mode, etc. */
|
2011-02-15 23:07:14 -08:00
|
|
|
SDL_HideWindow(window);
|
2009-12-03 05:05:26 +00:00
|
|
|
|
2011-02-03 21:13:55 -08:00
|
|
|
if (window->surface) {
|
2011-02-13 13:46:10 -08:00
|
|
|
window->surface->flags &= ~SDL_DONTFREE;
|
2011-02-03 21:13:55 -08:00
|
|
|
SDL_FreeSurface(window->surface);
|
|
|
|
}
|
2011-02-03 15:49:37 -08:00
|
|
|
if (_this->DestroyWindowFramebuffer) {
|
|
|
|
_this->DestroyWindowFramebuffer(_this, window);
|
|
|
|
}
|
2010-01-21 06:21:52 +00:00
|
|
|
if (_this->DestroyWindow) {
|
|
|
|
_this->DestroyWindow(_this, window);
|
|
|
|
}
|
|
|
|
if (window->flags & SDL_WINDOW_OPENGL) {
|
|
|
|
SDL_GL_UnloadLibrary();
|
|
|
|
}
|
|
|
|
|
2011-02-10 14:44:25 -08:00
|
|
|
display = SDL_GetDisplayForWindow(window);
|
|
|
|
if (display->fullscreen_window == window) {
|
|
|
|
display->fullscreen_window = NULL;
|
|
|
|
}
|
|
|
|
|
2010-09-27 01:30:42 -07:00
|
|
|
/* Now invalidate magic */
|
2010-09-27 00:49:34 -07:00
|
|
|
window->magic = NULL;
|
|
|
|
|
2011-02-03 11:16:57 -08:00
|
|
|
/* Free memory associated with the window */
|
|
|
|
if (window->title) {
|
|
|
|
SDL_free(window->title);
|
|
|
|
}
|
|
|
|
while (window->data) {
|
|
|
|
SDL_WindowUserData *data = window->data;
|
|
|
|
|
|
|
|
window->data = data->next;
|
|
|
|
SDL_free(data->name);
|
|
|
|
SDL_free(data);
|
|
|
|
}
|
|
|
|
|
2010-01-21 06:21:52 +00:00
|
|
|
/* Unlink the window from the list */
|
2010-01-22 16:17:11 +00:00
|
|
|
if (window->next) {
|
|
|
|
window->next->prev = window->prev;
|
|
|
|
}
|
2010-01-21 06:21:52 +00:00
|
|
|
if (window->prev) {
|
|
|
|
window->prev->next = window->next;
|
|
|
|
} else {
|
2011-02-10 14:44:25 -08:00
|
|
|
_this->windows = window->next;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
2010-01-21 06:21:52 +00:00
|
|
|
|
|
|
|
SDL_free(window);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
2009-01-12 06:19:05 +00:00
|
|
|
SDL_bool
|
|
|
|
SDL_IsScreenSaverEnabled()
|
|
|
|
{
|
|
|
|
if (!_this) {
|
|
|
|
return SDL_TRUE;
|
|
|
|
}
|
|
|
|
return _this->suspend_screensaver ? SDL_FALSE : SDL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_EnableScreenSaver()
|
|
|
|
{
|
|
|
|
if (!_this) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!_this->suspend_screensaver) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_this->suspend_screensaver = SDL_FALSE;
|
|
|
|
if (_this->SuspendScreenSaver) {
|
|
|
|
_this->SuspendScreenSaver(_this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_DisableScreenSaver()
|
|
|
|
{
|
|
|
|
if (!_this) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_this->suspend_screensaver) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_this->suspend_screensaver = SDL_TRUE;
|
|
|
|
if (_this->SuspendScreenSaver) {
|
|
|
|
_this->SuspendScreenSaver(_this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_VideoQuit(void)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
int i, j;
|
|
|
|
|
|
|
|
if (!_this) {
|
|
|
|
return;
|
|
|
|
}
|
2011-01-27 22:44:08 -08:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
/* Halt event processing before doing anything else */
|
2011-01-27 22:44:08 -08:00
|
|
|
SDL_QuitQuit();
|
|
|
|
SDL_MouseQuit();
|
|
|
|
SDL_KeyboardQuit();
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_StopEventLoop();
|
2011-01-27 22:44:08 -08:00
|
|
|
|
2009-01-12 08:23:47 +00:00
|
|
|
SDL_EnableScreenSaver();
|
2008-09-15 04:32:36 +00:00
|
|
|
|
|
|
|
/* Clean up the system video */
|
2011-02-10 14:44:25 -08:00
|
|
|
while (_this->windows) {
|
|
|
|
SDL_DestroyWindow(_this->windows);
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
|
|
|
_this->VideoQuit(_this);
|
|
|
|
|
|
|
|
for (i = _this->num_displays; i--;) {
|
|
|
|
SDL_VideoDisplay *display = &_this->displays[i];
|
|
|
|
for (j = display->num_display_modes; j--;) {
|
|
|
|
if (display->display_modes[j].driverdata) {
|
|
|
|
SDL_free(display->display_modes[j].driverdata);
|
|
|
|
display->display_modes[j].driverdata = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (display->display_modes) {
|
|
|
|
SDL_free(display->display_modes);
|
|
|
|
display->display_modes = NULL;
|
|
|
|
}
|
|
|
|
if (display->desktop_mode.driverdata) {
|
|
|
|
SDL_free(display->desktop_mode.driverdata);
|
|
|
|
display->desktop_mode.driverdata = NULL;
|
|
|
|
}
|
|
|
|
if (display->driverdata) {
|
|
|
|
SDL_free(display->driverdata);
|
|
|
|
display->driverdata = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_this->displays) {
|
|
|
|
SDL_free(_this->displays);
|
|
|
|
_this->displays = NULL;
|
|
|
|
}
|
2010-07-07 23:54:03 -07:00
|
|
|
if (_this->clipboard_text) {
|
|
|
|
SDL_free(_this->clipboard_text);
|
|
|
|
_this->clipboard_text = NULL;
|
|
|
|
}
|
2008-09-15 04:32:36 +00:00
|
|
|
_this->free(_this);
|
|
|
|
_this = NULL;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_GL_LoadLibrary(const char *path)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
int retval;
|
2006-07-16 09:34:01 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return -1;
|
|
|
|
}
|
2009-02-09 05:32:12 +00:00
|
|
|
if (_this->gl_config.driver_loaded) {
|
|
|
|
if (path && SDL_strcmp(path, _this->gl_config.driver_path) != 0) {
|
|
|
|
SDL_SetError("OpenGL library already loaded");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
retval = 0;
|
2008-09-15 04:32:36 +00:00
|
|
|
} else {
|
2009-02-09 05:32:12 +00:00
|
|
|
if (!_this->GL_LoadLibrary) {
|
|
|
|
SDL_SetError("No dynamic GL support in video driver");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
retval = _this->GL_LoadLibrary(_this, path);
|
|
|
|
}
|
|
|
|
if (retval == 0) {
|
|
|
|
++_this->gl_config.driver_loaded;
|
2008-09-15 04:32:36 +00:00
|
|
|
}
|
|
|
|
return (retval);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
void *
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_GL_GetProcAddress(const char *proc)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
void *func;
|
|
|
|
|
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
func = NULL;
|
|
|
|
if (_this->GL_GetProcAddress) {
|
|
|
|
if (_this->gl_config.driver_loaded) {
|
|
|
|
func = _this->GL_GetProcAddress(_this, proc);
|
|
|
|
} else {
|
|
|
|
SDL_SetError("No GL driver has been loaded");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SDL_SetError("No dynamic GL support in video driver");
|
|
|
|
}
|
|
|
|
return func;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
2009-02-09 05:32:12 +00:00
|
|
|
void
|
|
|
|
SDL_GL_UnloadLibrary(void)
|
|
|
|
{
|
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_this->gl_config.driver_loaded > 0) {
|
|
|
|
if (--_this->gl_config.driver_loaded > 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_this->GL_UnloadLibrary) {
|
|
|
|
_this->GL_UnloadLibrary(_this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-22 21:58:17 +00:00
|
|
|
SDL_bool
|
|
|
|
SDL_GL_ExtensionSupported(const char *extension)
|
|
|
|
{
|
2011-02-06 10:22:25 -08:00
|
|
|
#if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
|
2008-09-15 04:32:36 +00:00
|
|
|
const GLubyte *(APIENTRY * glGetStringFunc) (GLenum);
|
|
|
|
const char *extensions;
|
|
|
|
const char *start;
|
|
|
|
const char *where, *terminator;
|
|
|
|
|
|
|
|
/* Extension names should not have spaces. */
|
|
|
|
where = SDL_strchr(extension, ' ');
|
|
|
|
if (where || *extension == '\0') {
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
/* See if there's an environment variable override */
|
|
|
|
start = SDL_getenv(extension);
|
|
|
|
if (start && *start == '0') {
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
/* Lookup the available extensions */
|
|
|
|
glGetStringFunc = SDL_GL_GetProcAddress("glGetString");
|
|
|
|
if (glGetStringFunc) {
|
|
|
|
extensions = (const char *) glGetStringFunc(GL_EXTENSIONS);
|
|
|
|
} else {
|
|
|
|
extensions = NULL;
|
|
|
|
}
|
|
|
|
if (!extensions) {
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* It takes a bit of care to be fool-proof about parsing the OpenGL
|
|
|
|
* extensions string. Don't be fooled by sub-strings, etc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
start = extensions;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
where = SDL_strstr(start, extension);
|
|
|
|
if (!where)
|
|
|
|
break;
|
|
|
|
|
|
|
|
terminator = where + SDL_strlen(extension);
|
|
|
|
if (where == start || *(where - 1) == ' ')
|
|
|
|
if (*terminator == ' ' || *terminator == '\0')
|
|
|
|
return SDL_TRUE;
|
|
|
|
|
|
|
|
start = terminator;
|
|
|
|
}
|
|
|
|
return SDL_FALSE;
|
2006-07-22 21:58:17 +00:00
|
|
|
#else
|
2008-09-15 04:32:36 +00:00
|
|
|
return SDL_FALSE;
|
2006-07-22 21:58:17 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
|
|
|
SDL_GL_SetAttribute(SDL_GLattr attr, int value)
|
|
|
|
{
|
2011-02-06 10:22:25 -08:00
|
|
|
#if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
|
2008-09-15 04:32:36 +00:00
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
retval = 0;
|
|
|
|
switch (attr) {
|
|
|
|
case SDL_GL_RED_SIZE:
|
|
|
|
_this->gl_config.red_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_GREEN_SIZE:
|
|
|
|
_this->gl_config.green_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_BLUE_SIZE:
|
|
|
|
_this->gl_config.blue_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_ALPHA_SIZE:
|
|
|
|
_this->gl_config.alpha_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_DOUBLEBUFFER:
|
|
|
|
_this->gl_config.double_buffer = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_BUFFER_SIZE:
|
|
|
|
_this->gl_config.buffer_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_DEPTH_SIZE:
|
|
|
|
_this->gl_config.depth_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_STENCIL_SIZE:
|
|
|
|
_this->gl_config.stencil_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_ACCUM_RED_SIZE:
|
|
|
|
_this->gl_config.accum_red_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_ACCUM_GREEN_SIZE:
|
|
|
|
_this->gl_config.accum_green_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_ACCUM_BLUE_SIZE:
|
|
|
|
_this->gl_config.accum_blue_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_ACCUM_ALPHA_SIZE:
|
|
|
|
_this->gl_config.accum_alpha_size = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_STEREO:
|
|
|
|
_this->gl_config.stereo = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_MULTISAMPLEBUFFERS:
|
|
|
|
_this->gl_config.multisamplebuffers = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_MULTISAMPLESAMPLES:
|
|
|
|
_this->gl_config.multisamplesamples = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_ACCELERATED_VISUAL:
|
|
|
|
_this->gl_config.accelerated = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_RETAINED_BACKING:
|
|
|
|
_this->gl_config.retained_backing = value;
|
|
|
|
break;
|
Date: Sun, 22 Mar 2009 12:52:29 +0000
From: Luke Benstead
Subject: OpenGL 3.0 Context Creation
I've attached a patch which implements OpenGL 3.x context creation on
the latest SVN. I've added two options to SDL_GL_SetAttribute, these
are SDL_GL_CONTEXT_MAJOR_VERSION and SDL_GL_CONTEXT_MINOR_VERSION.
These default to 2 and 1 respectively. If the major version is less
than 3 then the current context creation method is used, otherwise the
appropriate new context creation function is called (depending on the
platform).
Sample code:
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); //Without these 2 lines, SDL will create a GL 2.x context
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_Surface* screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL | SDL_FULLSCREEN );
I've implemented context creation on both Win32 and X and run basic
tests on both. This patch doesn't provide access to all the options
allowed by the new context creation (e.g. shared contexts, forward
compatible contexts) but they can be added pretty easily.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403567
2009-03-24 10:43:53 +00:00
|
|
|
case SDL_GL_CONTEXT_MAJOR_VERSION:
|
|
|
|
_this->gl_config.major_version = value;
|
|
|
|
break;
|
|
|
|
case SDL_GL_CONTEXT_MINOR_VERSION:
|
|
|
|
_this->gl_config.minor_version = value;
|
|
|
|
break;
|
2008-09-15 04:32:36 +00:00
|
|
|
default:
|
|
|
|
SDL_SetError("Unknown OpenGL attribute");
|
|
|
|
retval = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return retval;
|
2006-07-25 06:22:42 +00:00
|
|
|
#else
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Unsupported();
|
|
|
|
return -1;
|
|
|
|
#endif /* SDL_VIDEO_OPENGL */
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2006-07-25 06:22:42 +00:00
|
|
|
SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2011-02-06 10:22:25 -08:00
|
|
|
#if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
|
2008-09-15 04:32:36 +00:00
|
|
|
void (APIENTRY * glGetIntegervFunc) (GLenum pname, GLint * params);
|
2009-05-23 22:41:08 +00:00
|
|
|
GLenum(APIENTRY * glGetErrorFunc) (void);
|
2008-09-15 04:32:36 +00:00
|
|
|
GLenum attrib = 0;
|
Date: Mon, 23 Mar 2009 09:17:24 +0200
From: "Mike Gorchak"
Subject: New QNX patches
Please apply patch qnx4.diff, which is attached. What has been done:
1)Added back OpenGL ES renderer for QNX target. Added few corrections to
OpenGL ES renderer to let it work under QNX. OpenGL ES renderer do not
support textures under QNX, so I think some additional work must be done.
2) Added GL_OES_query_matrix extension to SDL_opengles.h header file, which
required by OpenGL ES 1.1 specification.
3) Added attribute clearing at the entrance of function
SDL_GL_GetAttribure(). Added error checking into the function
SDL_GL_GetAttribure(), because some attributes can't be obtained in OpenGL
ES 1.0.
4) Porting testdyngles to OpenGL ES 1.0 (1.1 has glColor4ub() and
glColor4f() functions, but 1.0 has glColor4f() only).
5) Added error checking after obtaining attributes using
SDL_GL_GetAttribute() function to the testgl2 and testgles.
6) Small correction to testmultiaudio with printing errors.
7) Added software and accelerated OpenGL ES 1.0 support into the QNX GF
driver.
Please remove ./src/audio/nto directory - it will not be used anymore.
Please create ./src/audio/qsa directory and add content of the archive
qsa.tar.gz into this directory. I rewrote some sound code, added support for
multiple audio cards, enumeration, etc. Added initial support for capture.
As far as I can understand SDL 1.3 is not supporting audio capture right now
? Sam, Am I right ? Or audio capture must be supported through the
PlayDevice routine ?
And last, please put file SDL_gf_opengles.c to the ./src/video/qnxgf
directory. It is OpenGL ES 1.1 emulation layer for some functions, which are
not supported by OpenGL ES 1.0.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403566
2009-03-24 10:33:12 +00:00
|
|
|
GLenum error = 0;
|
2008-09-15 04:32:36 +00:00
|
|
|
|
|
|
|
glGetIntegervFunc = SDL_GL_GetProcAddress("glGetIntegerv");
|
|
|
|
if (!glGetIntegervFunc) {
|
|
|
|
return -1;
|
|
|
|
}
|
Date: Mon, 23 Mar 2009 09:17:24 +0200
From: "Mike Gorchak"
Subject: New QNX patches
Please apply patch qnx4.diff, which is attached. What has been done:
1)Added back OpenGL ES renderer for QNX target. Added few corrections to
OpenGL ES renderer to let it work under QNX. OpenGL ES renderer do not
support textures under QNX, so I think some additional work must be done.
2) Added GL_OES_query_matrix extension to SDL_opengles.h header file, which
required by OpenGL ES 1.1 specification.
3) Added attribute clearing at the entrance of function
SDL_GL_GetAttribure(). Added error checking into the function
SDL_GL_GetAttribure(), because some attributes can't be obtained in OpenGL
ES 1.0.
4) Porting testdyngles to OpenGL ES 1.0 (1.1 has glColor4ub() and
glColor4f() functions, but 1.0 has glColor4f() only).
5) Added error checking after obtaining attributes using
SDL_GL_GetAttribute() function to the testgl2 and testgles.
6) Small correction to testmultiaudio with printing errors.
7) Added software and accelerated OpenGL ES 1.0 support into the QNX GF
driver.
Please remove ./src/audio/nto directory - it will not be used anymore.
Please create ./src/audio/qsa directory and add content of the archive
qsa.tar.gz into this directory. I rewrote some sound code, added support for
multiple audio cards, enumeration, etc. Added initial support for capture.
As far as I can understand SDL 1.3 is not supporting audio capture right now
? Sam, Am I right ? Or audio capture must be supported through the
PlayDevice routine ?
And last, please put file SDL_gf_opengles.c to the ./src/video/qnxgf
directory. It is OpenGL ES 1.1 emulation layer for some functions, which are
not supported by OpenGL ES 1.0.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403566
2009-03-24 10:33:12 +00:00
|
|
|
|
|
|
|
glGetErrorFunc = SDL_GL_GetProcAddress("glGetError");
|
|
|
|
if (!glGetErrorFunc) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear value in any case */
|
2009-05-23 22:41:08 +00:00
|
|
|
*value = 0;
|
Date: Mon, 23 Mar 2009 09:17:24 +0200
From: "Mike Gorchak"
Subject: New QNX patches
Please apply patch qnx4.diff, which is attached. What has been done:
1)Added back OpenGL ES renderer for QNX target. Added few corrections to
OpenGL ES renderer to let it work under QNX. OpenGL ES renderer do not
support textures under QNX, so I think some additional work must be done.
2) Added GL_OES_query_matrix extension to SDL_opengles.h header file, which
required by OpenGL ES 1.1 specification.
3) Added attribute clearing at the entrance of function
SDL_GL_GetAttribure(). Added error checking into the function
SDL_GL_GetAttribure(), because some attributes can't be obtained in OpenGL
ES 1.0.
4) Porting testdyngles to OpenGL ES 1.0 (1.1 has glColor4ub() and
glColor4f() functions, but 1.0 has glColor4f() only).
5) Added error checking after obtaining attributes using
SDL_GL_GetAttribute() function to the testgl2 and testgles.
6) Small correction to testmultiaudio with printing errors.
7) Added software and accelerated OpenGL ES 1.0 support into the QNX GF
driver.
Please remove ./src/audio/nto directory - it will not be used anymore.
Please create ./src/audio/qsa directory and add content of the archive
qsa.tar.gz into this directory. I rewrote some sound code, added support for
multiple audio cards, enumeration, etc. Added initial support for capture.
As far as I can understand SDL 1.3 is not supporting audio capture right now
? Sam, Am I right ? Or audio capture must be supported through the
PlayDevice routine ?
And last, please put file SDL_gf_opengles.c to the ./src/video/qnxgf
directory. It is OpenGL ES 1.1 emulation layer for some functions, which are
not supported by OpenGL ES 1.0.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403566
2009-03-24 10:33:12 +00:00
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
switch (attr) {
|
|
|
|
case SDL_GL_RED_SIZE:
|
|
|
|
attrib = GL_RED_BITS;
|
|
|
|
break;
|
|
|
|
case SDL_GL_BLUE_SIZE:
|
|
|
|
attrib = GL_BLUE_BITS;
|
|
|
|
break;
|
|
|
|
case SDL_GL_GREEN_SIZE:
|
|
|
|
attrib = GL_GREEN_BITS;
|
|
|
|
break;
|
|
|
|
case SDL_GL_ALPHA_SIZE:
|
|
|
|
attrib = GL_ALPHA_BITS;
|
|
|
|
break;
|
|
|
|
case SDL_GL_DOUBLEBUFFER:
|
2011-02-06 10:22:25 -08:00
|
|
|
#if SDL_VIDEO_OPENGL
|
2008-09-15 04:32:36 +00:00
|
|
|
attrib = GL_DOUBLEBUFFER;
|
|
|
|
break;
|
2008-09-02 20:19:45 +00:00
|
|
|
#else
|
Date: Mon, 23 Mar 2009 09:17:24 +0200
From: "Mike Gorchak"
Subject: New QNX patches
Please apply patch qnx4.diff, which is attached. What has been done:
1)Added back OpenGL ES renderer for QNX target. Added few corrections to
OpenGL ES renderer to let it work under QNX. OpenGL ES renderer do not
support textures under QNX, so I think some additional work must be done.
2) Added GL_OES_query_matrix extension to SDL_opengles.h header file, which
required by OpenGL ES 1.1 specification.
3) Added attribute clearing at the entrance of function
SDL_GL_GetAttribure(). Added error checking into the function
SDL_GL_GetAttribure(), because some attributes can't be obtained in OpenGL
ES 1.0.
4) Porting testdyngles to OpenGL ES 1.0 (1.1 has glColor4ub() and
glColor4f() functions, but 1.0 has glColor4f() only).
5) Added error checking after obtaining attributes using
SDL_GL_GetAttribute() function to the testgl2 and testgles.
6) Small correction to testmultiaudio with printing errors.
7) Added software and accelerated OpenGL ES 1.0 support into the QNX GF
driver.
Please remove ./src/audio/nto directory - it will not be used anymore.
Please create ./src/audio/qsa directory and add content of the archive
qsa.tar.gz into this directory. I rewrote some sound code, added support for
multiple audio cards, enumeration, etc. Added initial support for capture.
As far as I can understand SDL 1.3 is not supporting audio capture right now
? Sam, Am I right ? Or audio capture must be supported through the
PlayDevice routine ?
And last, please put file SDL_gf_opengles.c to the ./src/video/qnxgf
directory. It is OpenGL ES 1.1 emulation layer for some functions, which are
not supported by OpenGL ES 1.0.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403566
2009-03-24 10:33:12 +00:00
|
|
|
/* OpenGL ES 1.0 and above specifications have EGL_SINGLE_BUFFER */
|
|
|
|
/* parameter which switches double buffer to single buffer. OpenGL ES */
|
|
|
|
/* SDL driver must set proper value after initialization */
|
|
|
|
*value = _this->gl_config.double_buffer;
|
2008-09-15 04:32:36 +00:00
|
|
|
return 0;
|
2008-09-02 20:19:45 +00:00
|
|
|
#endif
|
2008-09-15 04:32:36 +00:00
|
|
|
case SDL_GL_DEPTH_SIZE:
|
|
|
|
attrib = GL_DEPTH_BITS;
|
|
|
|
break;
|
|
|
|
case SDL_GL_STENCIL_SIZE:
|
|
|
|
attrib = GL_STENCIL_BITS;
|
|
|
|
break;
|
2011-02-06 10:22:25 -08:00
|
|
|
#if SDL_VIDEO_OPENGL
|
2008-09-15 04:32:36 +00:00
|
|
|
case SDL_GL_ACCUM_RED_SIZE:
|
|
|
|
attrib = GL_ACCUM_RED_BITS;
|
|
|
|
break;
|
|
|
|
case SDL_GL_ACCUM_GREEN_SIZE:
|
|
|
|
attrib = GL_ACCUM_GREEN_BITS;
|
|
|
|
break;
|
|
|
|
case SDL_GL_ACCUM_BLUE_SIZE:
|
|
|
|
attrib = GL_ACCUM_BLUE_BITS;
|
|
|
|
break;
|
|
|
|
case SDL_GL_ACCUM_ALPHA_SIZE:
|
|
|
|
attrib = GL_ACCUM_ALPHA_BITS;
|
|
|
|
break;
|
|
|
|
case SDL_GL_STEREO:
|
|
|
|
attrib = GL_STEREO;
|
|
|
|
break;
|
2008-09-02 20:19:45 +00:00
|
|
|
#else
|
2008-09-15 04:32:36 +00:00
|
|
|
case SDL_GL_ACCUM_RED_SIZE:
|
|
|
|
case SDL_GL_ACCUM_GREEN_SIZE:
|
|
|
|
case SDL_GL_ACCUM_BLUE_SIZE:
|
|
|
|
case SDL_GL_ACCUM_ALPHA_SIZE:
|
|
|
|
case SDL_GL_STEREO:
|
|
|
|
/* none of these are supported in OpenGL ES */
|
|
|
|
*value = 0;
|
|
|
|
return 0;
|
2008-09-02 20:19:45 +00:00
|
|
|
#endif
|
2008-09-15 04:32:36 +00:00
|
|
|
case SDL_GL_MULTISAMPLEBUFFERS:
|
2011-02-06 10:22:25 -08:00
|
|
|
#if SDL_VIDEO_OPENGL
|
2008-09-15 04:32:36 +00:00
|
|
|
attrib = GL_SAMPLE_BUFFERS_ARB;
|
2008-09-02 20:19:45 +00:00
|
|
|
#else
|
2008-09-15 04:32:36 +00:00
|
|
|
attrib = GL_SAMPLE_BUFFERS;
|
2008-09-02 20:19:45 +00:00
|
|
|
#endif
|
2008-09-15 04:32:36 +00:00
|
|
|
break;
|
|
|
|
case SDL_GL_MULTISAMPLESAMPLES:
|
2011-02-06 10:22:25 -08:00
|
|
|
#if SDL_VIDEO_OPENGL
|
2008-09-15 04:32:36 +00:00
|
|
|
attrib = GL_SAMPLES_ARB;
|
2008-09-02 20:19:45 +00:00
|
|
|
#else
|
2008-09-15 04:32:36 +00:00
|
|
|
attrib = GL_SAMPLES;
|
2008-09-02 20:19:45 +00:00
|
|
|
#endif
|
2008-09-15 04:32:36 +00:00
|
|
|
break;
|
|
|
|
case SDL_GL_BUFFER_SIZE:
|
|
|
|
{
|
|
|
|
GLint bits = 0;
|
|
|
|
GLint component;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* there doesn't seem to be a single flag in OpenGL
|
|
|
|
* for this!
|
|
|
|
*/
|
|
|
|
glGetIntegervFunc(GL_RED_BITS, &component);
|
|
|
|
bits += component;
|
|
|
|
glGetIntegervFunc(GL_GREEN_BITS, &component);
|
|
|
|
bits += component;
|
|
|
|
glGetIntegervFunc(GL_BLUE_BITS, &component);
|
|
|
|
bits += component;
|
|
|
|
glGetIntegervFunc(GL_ALPHA_BITS, &component);
|
|
|
|
bits += component;
|
|
|
|
|
|
|
|
*value = bits;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case SDL_GL_ACCELERATED_VISUAL:
|
|
|
|
{
|
|
|
|
/* FIXME: How do we get this information? */
|
2009-12-15 20:53:09 +00:00
|
|
|
*value = (_this->gl_config.accelerated != 0);
|
2008-09-15 04:32:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2011-02-06 10:24:08 -08:00
|
|
|
case SDL_GL_RETAINED_BACKING:
|
|
|
|
{
|
|
|
|
*value = _this->gl_config.retained_backing;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case SDL_GL_CONTEXT_MAJOR_VERSION:
|
|
|
|
{
|
|
|
|
*value = _this->gl_config.major_version;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case SDL_GL_CONTEXT_MINOR_VERSION:
|
|
|
|
{
|
|
|
|
*value = _this->gl_config.minor_version;
|
|
|
|
return 0;
|
|
|
|
}
|
2008-09-15 04:32:36 +00:00
|
|
|
default:
|
|
|
|
SDL_SetError("Unknown OpenGL attribute");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
glGetIntegervFunc(attrib, (GLint *) value);
|
2009-05-23 22:41:08 +00:00
|
|
|
error = glGetErrorFunc();
|
|
|
|
if (error != GL_NO_ERROR) {
|
|
|
|
switch (error) {
|
|
|
|
case GL_INVALID_ENUM:
|
|
|
|
{
|
|
|
|
SDL_SetError("OpenGL error: GL_INVALID_ENUM");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GL_INVALID_VALUE:
|
|
|
|
{
|
|
|
|
SDL_SetError("OpenGL error: GL_INVALID_VALUE");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
SDL_SetError("OpenGL error: %08X", error);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return -1;
|
Date: Mon, 23 Mar 2009 09:17:24 +0200
From: "Mike Gorchak"
Subject: New QNX patches
Please apply patch qnx4.diff, which is attached. What has been done:
1)Added back OpenGL ES renderer for QNX target. Added few corrections to
OpenGL ES renderer to let it work under QNX. OpenGL ES renderer do not
support textures under QNX, so I think some additional work must be done.
2) Added GL_OES_query_matrix extension to SDL_opengles.h header file, which
required by OpenGL ES 1.1 specification.
3) Added attribute clearing at the entrance of function
SDL_GL_GetAttribure(). Added error checking into the function
SDL_GL_GetAttribure(), because some attributes can't be obtained in OpenGL
ES 1.0.
4) Porting testdyngles to OpenGL ES 1.0 (1.1 has glColor4ub() and
glColor4f() functions, but 1.0 has glColor4f() only).
5) Added error checking after obtaining attributes using
SDL_GL_GetAttribute() function to the testgl2 and testgles.
6) Small correction to testmultiaudio with printing errors.
7) Added software and accelerated OpenGL ES 1.0 support into the QNX GF
driver.
Please remove ./src/audio/nto directory - it will not be used anymore.
Please create ./src/audio/qsa directory and add content of the archive
qsa.tar.gz into this directory. I rewrote some sound code, added support for
multiple audio cards, enumeration, etc. Added initial support for capture.
As far as I can understand SDL 1.3 is not supporting audio capture right now
? Sam, Am I right ? Or audio capture must be supported through the
PlayDevice routine ?
And last, please put file SDL_gf_opengles.c to the ./src/video/qnxgf
directory. It is OpenGL ES 1.1 emulation layer for some functions, which are
not supported by OpenGL ES 1.0.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403566
2009-03-24 10:33:12 +00:00
|
|
|
}
|
2008-09-15 04:32:36 +00:00
|
|
|
return 0;
|
2006-07-25 06:22:42 +00:00
|
|
|
#else
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_Unsupported();
|
|
|
|
return -1;
|
|
|
|
#endif /* SDL_VIDEO_OPENGL */
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
2006-07-16 09:34:01 +00:00
|
|
|
SDL_GLContext
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_GL_CreateContext(SDL_Window * window)
|
2006-07-16 09:34:01 +00:00
|
|
|
{
|
2010-01-24 20:21:51 +00:00
|
|
|
CHECK_WINDOW_MAGIC(window, NULL);
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!(window->flags & SDL_WINDOW_OPENGL)) {
|
|
|
|
SDL_SetError("The specified window isn't an OpenGL window");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return _this->GL_CreateContext(_this, window);
|
2006-07-16 09:34:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_GL_MakeCurrent(SDL_Window * window, SDL_GLContext context)
|
2006-07-16 09:34:01 +00:00
|
|
|
{
|
2010-01-24 20:21:51 +00:00
|
|
|
CHECK_WINDOW_MAGIC(window, -1);
|
|
|
|
|
|
|
|
if (!(window->flags & SDL_WINDOW_OPENGL)) {
|
2008-09-15 04:32:36 +00:00
|
|
|
SDL_SetError("The specified window isn't an OpenGL window");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!context) {
|
|
|
|
window = NULL;
|
|
|
|
}
|
|
|
|
return _this->GL_MakeCurrent(_this, window, context);
|
2006-07-16 09:34:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_GL_SetSwapInterval(int interval)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (_this->GL_SetSwapInterval) {
|
|
|
|
return _this->GL_SetSwapInterval(_this, interval);
|
|
|
|
} else {
|
|
|
|
SDL_SetError("Setting the swap interval is not supported");
|
|
|
|
return -1;
|
|
|
|
}
|
2006-07-16 09:34:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_GL_GetSwapInterval(void)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!_this) {
|
|
|
|
SDL_UninitializedVideo();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (_this->GL_GetSwapInterval) {
|
|
|
|
return _this->GL_GetSwapInterval(_this);
|
|
|
|
} else {
|
|
|
|
SDL_SetError("Getting the swap interval is not supported");
|
|
|
|
return -1;
|
|
|
|
}
|
2006-07-16 09:34:01 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_GL_SwapWindow(SDL_Window * window)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2010-01-24 20:21:51 +00:00
|
|
|
CHECK_WINDOW_MAGIC(window, );
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
if (!(window->flags & SDL_WINDOW_OPENGL)) {
|
|
|
|
SDL_SetError("The specified window isn't an OpenGL window");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_this->GL_SwapWindow(_this, window);
|
2006-07-16 09:34:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_GL_DeleteContext(SDL_GLContext context)
|
|
|
|
{
|
2010-07-14 07:48:35 -07:00
|
|
|
if (!_this || !_this->gl_data || !context) {
|
2008-09-15 04:32:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
_this->GL_MakeCurrent(_this, NULL, NULL);
|
|
|
|
_this->GL_DeleteContext(_this, context);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0 // FIXME
|
2008-09-02 20:11:06 +00:00
|
|
|
/*
|
|
|
|
* Utility function used by SDL_WM_SetIcon(); flags & 1 for color key, flags
|
|
|
|
* & 2 for alpha channel.
|
|
|
|
*/
|
2006-07-10 21:04:37 +00:00
|
|
|
static void
|
|
|
|
CreateMaskFromColorKeyOrAlpha(SDL_Surface * icon, Uint8 * mask, int flags)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
int x, y;
|
|
|
|
Uint32 colorkey;
|
2006-07-10 21:04:37 +00:00
|
|
|
#define SET_MASKBIT(icon, x, y, mask) \
|
|
|
|
mask[(y*((icon->w+7)/8))+(x/8)] &= ~(0x01<<(7-(x%8)))
|
|
|
|
|
2008-09-15 04:32:36 +00:00
|
|
|
colorkey = icon->format->colorkey;
|
|
|
|
switch (icon->format->BytesPerPixel) {
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
Uint8 *pixels;
|
|
|
|
for (y = 0; y < icon->h; ++y) {
|
|
|
|
pixels = (Uint8 *) icon->pixels + y * icon->pitch;
|
|
|
|
for (x = 0; x < icon->w; ++x) {
|
|
|
|
if (*pixels++ == colorkey) {
|
|
|
|
SET_MASKBIT(icon, x, y, mask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
Uint16 *pixels;
|
|
|
|
for (y = 0; y < icon->h; ++y) {
|
|
|
|
pixels = (Uint16 *) icon->pixels + y * icon->pitch / 2;
|
|
|
|
for (x = 0; x < icon->w; ++x) {
|
|
|
|
if ((flags & 1) && *pixels == colorkey) {
|
|
|
|
SET_MASKBIT(icon, x, y, mask);
|
|
|
|
} else if ((flags & 2)
|
|
|
|
&& (*pixels & icon->format->Amask) == 0) {
|
|
|
|
SET_MASKBIT(icon, x, y, mask);
|
|
|
|
}
|
|
|
|
pixels++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
Uint32 *pixels;
|
|
|
|
for (y = 0; y < icon->h; ++y) {
|
|
|
|
pixels = (Uint32 *) icon->pixels + y * icon->pitch / 4;
|
|
|
|
for (x = 0; x < icon->w; ++x) {
|
|
|
|
if ((flags & 1) && *pixels == colorkey) {
|
|
|
|
SET_MASKBIT(icon, x, y, mask);
|
|
|
|
} else if ((flags & 2)
|
|
|
|
&& (*pixels & icon->format->Amask) == 0) {
|
|
|
|
SET_MASKBIT(icon, x, y, mask);
|
|
|
|
}
|
|
|
|
pixels++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-07-10 21:04:37 +00:00
|
|
|
* Sets the window manager icon for the display window.
|
2001-04-26 16:45:43 +00:00
|
|
|
*/
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_WM_SetIcon(SDL_Surface * icon, Uint8 * mask)
|
|
|
|
{
|
2008-09-15 04:32:36 +00:00
|
|
|
if (icon && _this->SetIcon) {
|
|
|
|
/* Generate a mask if necessary, and create the icon! */
|
|
|
|
if (mask == NULL) {
|
|
|
|
int mask_len = icon->h * (icon->w + 7) / 8;
|
|
|
|
int flags = 0;
|
|
|
|
mask = (Uint8 *) SDL_malloc(mask_len);
|
|
|
|
if (mask == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SDL_memset(mask, ~0, mask_len);
|
|
|
|
if (icon->flags & SDL_SRCCOLORKEY)
|
|
|
|
flags |= 1;
|
|
|
|
if (icon->flags & SDL_SRCALPHA)
|
|
|
|
flags |= 2;
|
|
|
|
if (flags) {
|
|
|
|
CreateMaskFromColorKeyOrAlpha(icon, mask, flags);
|
|
|
|
}
|
|
|
|
_this->SetIcon(_this, icon, mask);
|
|
|
|
SDL_free(mask);
|
|
|
|
} else {
|
|
|
|
_this->SetIcon(_this, icon, mask);
|
|
|
|
}
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
SDL_bool
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_GetWindowWMInfo(SDL_Window * window, struct SDL_SysWMinfo *info)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2010-01-24 20:21:51 +00:00
|
|
|
CHECK_WINDOW_MAGIC(window, SDL_FALSE);
|
|
|
|
|
2010-09-27 01:24:05 -07:00
|
|
|
if (!info) {
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
info->subsystem = SDL_SYSWM_UNKNOWN;
|
|
|
|
|
2010-01-24 20:21:51 +00:00
|
|
|
if (!_this->GetWindowWMInfo) {
|
2008-09-15 04:32:36 +00:00
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
return (_this->GetWindowWMInfo(_this, window, info));
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2009-09-19 13:29:40 +00:00
|
|
|
void
|
|
|
|
SDL_StartTextInput(void)
|
|
|
|
{
|
2010-01-19 07:28:51 +00:00
|
|
|
if (_this && _this->StartTextInput) {
|
2009-09-19 13:29:40 +00:00
|
|
|
_this->StartTextInput(_this);
|
|
|
|
}
|
|
|
|
SDL_EventState(SDL_TEXTINPUT, SDL_ENABLE);
|
|
|
|
SDL_EventState(SDL_TEXTEDITING, SDL_ENABLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_StopTextInput(void)
|
|
|
|
{
|
2010-01-19 07:28:51 +00:00
|
|
|
if (_this && _this->StopTextInput) {
|
2009-09-19 13:29:40 +00:00
|
|
|
_this->StopTextInput(_this);
|
|
|
|
}
|
|
|
|
SDL_EventState(SDL_TEXTINPUT, SDL_DISABLE);
|
|
|
|
SDL_EventState(SDL_TEXTEDITING, SDL_DISABLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_SetTextInputRect(SDL_Rect *rect)
|
|
|
|
{
|
2010-01-19 07:28:51 +00:00
|
|
|
if (_this && _this->SetTextInputRect) {
|
2009-09-19 13:29:40 +00:00
|
|
|
_this->SetTextInputRect(_this, rect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|