annotate src/video/glsdl/SDL_glsdl.c @ 1725:98a3207ddde8 SDL-1.3

Implemented Win32 video mode support
author Sam Lantinga <slouken@libsdl.org>
date Fri, 07 Jul 2006 08:05:39 +0000
parents 4da1ee79c9af
children
rev   line source
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 Copyright (C) 1997-2006 Sam Lantinga
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Lesser General Public License for more details.
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 #include "SDL_config.h"
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 /*
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 * glSDL "SDL-over-OpenGL" video driver implemented by
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 * David Olofson <david@olofson.net> and
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 * Stephane Marchesin <stephane.marchesin@wanadoo.fr>
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 */
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 #include <math.h>
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 #include "SDL.h"
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 #include "SDL_error.h"
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 #include "SDL_video.h"
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 #include "SDL_mouse.h"
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 #include "../SDL_sysvideo.h"
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 #include "../SDL_pixels_c.h"
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 #include "SDL_glsdl.h"
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 #undef DEBUG_GLSDL
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 #undef DEBUG_GLSDL_CHOP
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 #define FAKE_MAXTEXSIZE 256
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 #undef GLSDL_GRAPHICAL_DEBUG
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 /* Initialization/Query functions */
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 /* Hardware surface functions */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
48 static int glSDL_SetColors(_THIS, int firstcolor, int ncolors,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
49 SDL_Color * colors);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
50 static int glSDL_AllocHWSurface(_THIS, SDL_Surface * surface);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
51 static int glSDL_LockHWSurface(_THIS, SDL_Surface * surface);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
52 static int glSDL_FlipHWSurface(_THIS, SDL_Surface * surface);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
53 static void glSDL_UnlockHWSurface(_THIS, SDL_Surface * surface);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
54 static void glSDL_FreeHWSurface(_THIS, SDL_Surface * surface);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
55 static int glSDL_FillHWRect(_THIS, SDL_Surface * dst, SDL_Rect * rect,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
56 Uint32 color);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
57 static int glSDL_CheckHWBlit(_THIS, SDL_Surface * src, SDL_Surface * dst);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
58 static int glSDL_SetHWColorKey(_THIS, SDL_Surface * surface, Uint32 key);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
59 static int glSDL_SetHWAlpha(_THIS, SDL_Surface * surface, Uint8 alpha);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
60 static int glSDL_VideoInit(_THIS, SDL_PixelFormat * vformat);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
61 static SDL_Rect **glSDL_ListModes(_THIS, SDL_PixelFormat * format,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
62 Uint32 flags);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
63 static void glSDL_VideoQuit(_THIS);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
64 static void glSDL_UpdateRects(_THIS, int numrects, SDL_Rect * rects);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
65 static SDL_Surface *glSDL_SetVideoMode(_THIS, SDL_Surface * current,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
66 int width, int height, int bpp,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
67 Uint32 flags);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 #define IS_GLSDL_SURFACE(s) ((s) && glSDL_GetTexInfo(s))
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 #define LOGIC_W(s) ( IS_GLSDL_SURFACE(this,s) ? TEXINFO(s)->lw : (s)->w )
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 #define LOGIC_H(s) ( IS_GLSDL_SURFACE(this,s) ? TEXINFO(s)->lh : (s)->h )
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 #define GLSDL_NOTEX (~0)
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 /*
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 * Special version for glSDL, which ignores the fake SDL_HWSURFACE
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 * flags, so we don't have SDL calling us back whenever we want to
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 * do some internal blitting...
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
81 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
82 glSDL_SoftBlit(SDL_Surface * src, SDL_Rect * srcrect,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
83 SDL_Surface * dst, SDL_Rect * dstrect)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
85 SDL_BlitInfo info;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
87 if (srcrect)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
88 if (!srcrect->w || !srcrect->h)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
89 return;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
91 /* Check to make sure the blit mapping is valid */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
92 if ((src->map->dst != dst) ||
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
93 (src->map->dst->format_version != src->map->format_version))
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
94 if (SDL_MapSurface(src, dst) < 0)
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
95 return;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
97 /* Set up the blit information */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
98 if (srcrect) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
99 info.s_pixels = (Uint8 *) src->pixels +
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
100 (Uint16) srcrect->y * src->pitch +
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
101 (Uint16) srcrect->x * src->format->BytesPerPixel;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
102 info.s_width = srcrect->w;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
103 info.s_height = srcrect->h;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
104 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
105 info.s_pixels = (Uint8 *) src->pixels;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
106 info.s_width = src->w;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
107 info.s_height = src->h;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
108 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
109 info.s_skip = src->pitch - info.s_width * src->format->BytesPerPixel;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
110 if (dstrect) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
111 info.d_pixels = (Uint8 *) dst->pixels +
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
112 (Uint16) dstrect->y * dst->pitch +
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
113 (Uint16) dstrect->x * dst->format->BytesPerPixel;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
114 /*
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
115 * NOTE: SDL_SoftBlit() uses the 'dstrect' for this!
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
116 * This version is more like SDL_BlitSurface().
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
117 */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
118 info.d_width = srcrect->w;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
119 info.d_height = srcrect->h;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
120 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
121 info.d_pixels = (Uint8 *) dst->pixels;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
122 info.d_width = dst->w;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
123 info.d_height = dst->h;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
124 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
125 info.d_skip = dst->pitch - info.d_width * dst->format->BytesPerPixel;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
126 info.aux_data = src->map->sw_data->aux_data;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
127 info.src = src->format;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
128 info.table = src->map->table;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
129 info.dst = dst->format;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
131 src->map->sw_data->blit(&info);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 /*
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 * Another special version. Doesn't lock/unlock, and doesn't mess
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 * with flags and stuff. It just converts the surface, period.
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 * Does not convert into palletized formats.
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
140 static SDL_Surface *
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
141 glSDL_ConvertSurface(SDL_Surface * surface,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
142 SDL_PixelFormat * format, Uint32 flags)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
144 SDL_Surface *convert;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
145 Uint32 colorkey = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
146 Uint8 alpha = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
147 Uint32 surface_flags;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
148 SDL_Rect bounds;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
150 /* Create a new surface with the desired format */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
151 convert = SDL_CreateRGBSurface(flags,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
152 surface->w, surface->h,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
153 format->BitsPerPixel, format->Rmask,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
154 format->Gmask, format->Bmask,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
155 format->Amask);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
156 if (convert == NULL) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
157 return (NULL);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
158 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
160 /* Save the original surface color key and alpha */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
161 surface_flags = surface->flags;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
162 if ((surface_flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
163 /* Convert colourkeyed surfaces to RGBA if requested */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
164 if ((flags & SDL_SRCCOLORKEY) != SDL_SRCCOLORKEY && format->Amask) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
165 surface_flags &= ~SDL_SRCCOLORKEY;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
166 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
167 colorkey = surface->format->colorkey;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
168 SDL_SetColorKey(surface, 0, 0);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
169 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
170 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
171 if ((surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
172 /* Copy over the alpha channel to RGBA if requested */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
173 if (format->Amask) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
174 surface->flags &= ~SDL_SRCALPHA;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
175 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
176 alpha = surface->format->alpha;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
177 SDL_SetAlpha(surface, 0, 0);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
178 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
179 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
181 /* Copy over the image data */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
182 bounds.x = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
183 bounds.y = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
184 bounds.w = surface->w;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
185 bounds.h = surface->h;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
186 glSDL_SoftBlit(surface, &bounds, convert, &bounds);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
188 /* Clean up the original surface, and update converted surface */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
189 if (convert != NULL) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
190 SDL_SetClipRect(convert, &surface->clip_rect);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
191 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
192 if ((surface_flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
193 Uint32 cflags = surface_flags & (SDL_SRCCOLORKEY | SDL_RLEACCELOK);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
194 if (convert != NULL) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
195 Uint8 keyR, keyG, keyB;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
197 SDL_GetRGB(colorkey, surface->format, &keyR, &keyG, &keyB);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
198 SDL_SetColorKey(convert, cflags | (flags & SDL_RLEACCELOK),
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
199 SDL_MapRGB(convert->format, keyR, keyG, keyB));
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
200 }
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
201 SDL_SetColorKey(surface, cflags, colorkey);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
202 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
203 if ((surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
204 Uint32 aflags = surface_flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
205 if (convert != NULL) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
206 SDL_SetAlpha(convert, aflags | (flags & SDL_RLEACCELOK), alpha);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
207 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
208 if (format->Amask) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
209 surface->flags |= SDL_SRCALPHA;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
210 } else {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
211 SDL_SetAlpha(surface, aflags, alpha);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
212 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
213 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
215 /* We're ready to go! */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
216 return (convert);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220 /*----------------------------------------------------------
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221 Some OpenGL function wrappers
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 ----------------------------------------------------------*/
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
223
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224 static struct
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
226 int do_blend;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
227 int do_texture;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
228 GLuint texture;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
229 GLenum sfactor, dfactor;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230 } glstate;
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
232 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
233 glSDL_reset(void)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
235 glstate.do_blend = -1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
236 glstate.do_blend = -1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
237 glstate.texture = GLSDL_NOTEX;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
238 glstate.sfactor = 0xffffffff;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
239 glstate.dfactor = 0xffffffff;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
240 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
242 static __inline__ void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
243 glSDL_do_blend(_THIS, int on)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
244 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
245 if (glstate.do_blend == on)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
246 return;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
247
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
248 if (on)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
249 this->glEnable(GL_BLEND);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
250 else
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
251 this->glDisable(GL_BLEND);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
252 glstate.do_blend = on;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
254
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
255 static __inline__ void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
256 glSDL_do_texture(_THIS, int on)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
257 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
258 if (glstate.do_texture == on)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
259 return;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
261 if (on)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
262 this->glEnable(GL_TEXTURE_2D);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
263 else
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
264 this->glDisable(GL_TEXTURE_2D);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
265 glstate.do_texture = on;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
266 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
268 static __inline__ void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
269 glSDL_blendfunc(_THIS, GLenum sfactor, GLenum dfactor)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
271 if ((sfactor == glstate.sfactor) && (dfactor == glstate.dfactor))
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
272 return;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
273
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
274 this->glBlendFunc(sfactor, dfactor);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
275
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
276 glstate.sfactor = sfactor;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
277 glstate.dfactor = dfactor;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
278 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
279
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
280 static __inline__ void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
281 glSDL_texture(_THIS, GLuint tx)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
282 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
283 if (tx == glstate.texture)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
284 return;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
285
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
286 this->glBindTexture(GL_TEXTURE_2D, tx);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
287 glstate.texture = tx;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
288 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
289
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
290
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
291
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
292
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
293 /*----------------------------------------------------------
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
294 glSDL specific data types
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
295 ----------------------------------------------------------*/
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
296
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
297 typedef enum
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
298 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
299 GLSDL_TM_SINGLE,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
300 GLSDL_TM_HORIZONTAL,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
301 GLSDL_TM_VERTICAL,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
302 GLSDL_TM_HUGE
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
303 } GLSDL_TileModes;
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
304
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
305
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
306 typedef struct private_hwdata
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
307 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
308 /* Size of surface in logic screen pixels */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
309 int lw, lh;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
310
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
311 int textures;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
312 GLuint *texture;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
313 int texsize; /* width/height of OpenGL texture */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
314 GLSDL_TileModes tilemode;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
315 int tilew, tileh; /* At least one must equal texsize! */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
316 int tilespertex;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
317 SDL_Rect virt; /* Total size of assembled surface */
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
318
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
319 /* Area of surface to upload when/after unlocking */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
320 SDL_Rect invalid_area;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
321
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
322 int temporary; /* Throw away after one use. */
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
323
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
324 SDL_Surface *next; /* The next Surface in our linked list of hardware surfaces ; == NULL if first surface */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
325 SDL_Surface *prev; /* The prev Surface in our linked list of hardware surfaces ; == NULL if last surface */
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
326 } private_hwdata;
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
327
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
328 /* some function prototypes */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
329 static void glSDL_Invalidate(SDL_Surface * surface, SDL_Rect * area);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
330 static void glSDL_SetLogicSize(_THIS, SDL_Surface * surface, int w, int h);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
331 static private_hwdata *glSDL_UploadSurface(_THIS, SDL_Surface * surface);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
332 static private_hwdata *glSDL_GetTexInfo(SDL_Surface * surface);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
333 static void glSDL_init_formats(_THIS);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
334 static private_hwdata *glSDL_AddTexInfo(_THIS, SDL_Surface * surface);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
335 static void glSDL_RemoveTexInfo(_THIS, SDL_Surface * surface);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
336 static void glSDL_UnloadTexture(_THIS, private_hwdata * txi);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
337 static int glSDL_BlitGL(_THIS, SDL_Surface * src,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
338 SDL_Rect * srcrect, SDL_Rect * dstrect);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
339
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
340 /* some variables */
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
341 static GLint maxtexsize = -1;
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
342 static SDL_PixelFormat *RGBfmt = NULL;
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
343 static SDL_PixelFormat *RGBAfmt = NULL;
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
344 static void *mirrorbuf = NULL;
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
345 /* the raw 888 opengl surface, hidden from the application */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
346 SDL_Surface *OpenGL_Surface;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
347
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
348 /* pointer to the beggining of the list used for memory allocation */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
349 SDL_Surface *first = NULL;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
350
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
351 #ifdef DEBUG_GLSDL
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
352 static __inline__ int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
353 GLERET(const char *txt)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
354 {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
355 fprintf(stderr, "glSDL ERROR: '%s'\n", txt);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
356 return -1;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
357 }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
358 static __inline__ void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
359 GLERR(const char *txt)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
360 {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
361 fprintf(stderr, "glSDL ERROR: '%s'\n", txt);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
362 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
363 #else
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
364 #define GLERET(x) (-1)
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
365 #define GLERR(x)
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
366 #endif
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
367
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
368 static SDL_VideoDevice underlying_device;
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
369 static int old_screen_flags;
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
370
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
371 /*
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
372 * List of video drivers known to support OpenGL
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
373 * The purpose of this is to make glSDL "portable" across
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
374 * all video backends that support OpenGL
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
375 */
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
376 static VideoBootStrap *opengl_bootstrap =
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
377 #if SDL_VIDEO_DRIVER_QUARTZ
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
378 &QZ_bootstrap;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
379 #elif SDL_VIDEO_DRIVER_X11
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
380 &X11_bootstrap;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
381 #elif SDL_VIDEO_DRIVER_WINDIB
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
382 &WINDIB_bootstrap;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
383 #elif SDL_VIDEO_DRIVER_BWINDOW
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
384 &BWINDOW_bootstrap;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
385 #elif SDL_VIDEO_DRIVER_TOOLBOX
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
386 &TOOLBOX_bootstrap;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
387 #elif SDL_VIDEO_DRIVER_CYBERGRAPHICS
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
388 &CGX_bootstrap;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
389 #elif SDL_VIDEO_DRIVER_PHOTON
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
390 &ph_bootstrap;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
391 #elif SDL_VIDEO_DRIVER_DC
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
392 &DC_bootstrap;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
393 #else
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
394 NULL;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
395 #endif
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
396
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
397 static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
398 glSDL_Available(void)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
399 {
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
400 #ifdef DEBUG_GLSDL
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
401 fprintf(stderr, "available\n");
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
402 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
403 if (opengl_bootstrap == NULL)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
404 return 0;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
405 return (opengl_bootstrap->available());
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
406 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
407
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
408 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
409 glSDL_DeleteDevice(SDL_VideoDevice * device)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
410 {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
411 SDL_free(device->hidden);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
412 SDL_free(device);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
413 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
414
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
415 /* Create a glSDL device */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
416 static SDL_VideoDevice *
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
417 glSDL_CreateDevice(int devindex)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
418 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
419 SDL_VideoDevice *device;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
420 #ifdef DEBUG_GLSDL
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
421 fprintf(stderr, "entering createdevice\n");
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
422 #endif
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
423
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
424 /* Create the device with the underlying driver */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
425 device = opengl_bootstrap->create(devindex);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
426
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
427 /* Save the video device contents for future use */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
428 SDL_memcpy(&underlying_device, device, sizeof(SDL_VideoDevice));
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
429
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
430 /* Hook glSDL on the video device */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
431 device->VideoInit = glSDL_VideoInit;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
432 device->ListModes = glSDL_ListModes;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
433 device->VideoQuit = glSDL_VideoQuit;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
434 device->UpdateRects = glSDL_UpdateRects;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
435 device->FillHWRect = glSDL_FillHWRect;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
436 device->SetHWColorKey = glSDL_SetHWColorKey;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
437 device->SetHWAlpha = glSDL_SetHWAlpha;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
438 device->AllocHWSurface = glSDL_AllocHWSurface;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
439 device->LockHWSurface = glSDL_LockHWSurface;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
440 device->UnlockHWSurface = glSDL_UnlockHWSurface;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
441 device->FlipHWSurface = glSDL_FlipHWSurface;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
442 device->FreeHWSurface = glSDL_FreeHWSurface;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
443 device->CheckHWBlit = glSDL_CheckHWBlit;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
444 device->SetColors = glSDL_SetColors;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
445 device->SetVideoMode = glSDL_SetVideoMode;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
446 device->info.hw_available = 1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
447 device->info.blit_hw = 1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
448 device->info.blit_hw_CC = 1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
449 device->info.blit_hw_A = 1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
450 device->info.blit_sw = 1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
451 device->info.blit_sw_CC = 1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
452 device->info.blit_sw_A = 1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
453 device->info.blit_fill = 1;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
454
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
455 /* These functions are not supported by glSDL, so we NULLify them */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
456 device->SetGamma = NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
457 device->GetGamma = NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
458 device->SetGammaRamp = NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
459 device->GetGammaRamp = NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
460 device->ToggleFullScreen = NULL;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
461
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
462 device->free = glSDL_DeleteDevice;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
463
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
464 #ifdef DEBUG_GLSDL
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
465 fprintf(stderr, "leaving createdevice\n");
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
466 #endif
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
467
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
468 return device;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
469 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
470
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
471 /* Our bootstraping structure */
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
472 VideoBootStrap glSDL_bootstrap = {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
473 "glSDL", "glSDL - SDL over OpenGL",
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
474 glSDL_Available, glSDL_CreateDevice
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
475 };
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
476
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
477 static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
478 glSDL_VideoInit(_THIS, SDL_PixelFormat * vformat)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
479 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
480 int r;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
481 printf("glSDL videoinit\n");
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
482 #ifdef DEBUG_GLSDL
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
483 fprintf(stderr, "videoinit\n");
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
484 #endif
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
485 r = underlying_device.VideoInit(this, vformat);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
486 this->info.hw_available = 1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
487 this->info.blit_hw = 1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
488 this->info.blit_hw_CC = 1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
489 this->info.blit_hw_A = 1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
490 this->info.blit_sw = 1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
491 this->info.blit_sw_CC = 1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
492 this->info.blit_sw_A = 1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
493 this->info.blit_fill = 1;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
494
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
495 return r;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
496 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
497
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
498 SDL_Rect **
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
499 glSDL_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
500 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
501 return ((SDL_Rect **) - 1);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
502 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
503
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
504 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
505 glSDL_VideoQuit(_THIS)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
506 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
507 SDL_Surface *scr;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
508
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
509 /* free all hwdata structures */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
510 while (first != NULL)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
511 glSDL_RemoveTexInfo(this, first);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
512
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
513 SDL_free(mirrorbuf);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
514 mirrorbuf = NULL;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
515
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
516 SDL_FreeFormat(RGBfmt);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
517 SDL_FreeFormat(RGBAfmt);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
518 RGBfmt = RGBAfmt = NULL;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
519
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
520 SDL_FreeFormat(this->displayformatalphapixel);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
521 this->displayformatalphapixel = NULL;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
522
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
523 SDL_FreeSurface(OpenGL_Surface);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
524 OpenGL_Surface = NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
525
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
526 /* restore the flags to gracefully exit from fullscreen */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
527 this->screen->flags = old_screen_flags;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
528
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
529 /* keep the screen */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
530 scr = this->screen;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
531
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
532 /* we cleaned up our stuff, now restore the underlying video driver */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
533 SDL_memcpy(this, &underlying_device, sizeof(SDL_VideoDevice));
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
534
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
535 this->screen = scr;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
536
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
537 /* call the underlying video driver's VideoQuit function */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
538 this->VideoQuit(this);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
539 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
540
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
541 static SDL_Surface *
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
542 glSDL_SetVideoMode(_THIS, SDL_Surface * current, int width, int height,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
543 int bpp, Uint32 flags)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
544 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
545 SDL_Surface *hooked_screen;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
546 int i;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
547 int flag_doublebuf = 0;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
548
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
549 if (opengl_bootstrap == NULL) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
550 GLERR("No bootstrap for glSDL compiled in !\n");
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
551 return NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
552 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
553
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
554 /* we don't have OpenGL */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
555 if ((flags & SDL_INTERNALOPENGL) == SDL_INTERNALOPENGL) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
556 GLERR("OpenGL video modes are not supported by glSDL !\n");
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
557 return (NULL);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
558 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
559
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
560 /*
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
561 * Adjust the flags
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
562 */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
563 flags &= ~SDL_HWPALETTE;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
564 flags |= SDL_INTERNALOPENGL;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
565
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
566 /* remember whether the user requested DOUBLEBUF */
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
567
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
568 if (flags & SDL_DOUBLEBUF) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
569 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
570 flag_doublebuf = 1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
571 } else {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
572 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
573 flag_doublebuf = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
574 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
575
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
576 hooked_screen =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
577 underlying_device.SetVideoMode(this, current, width, height, 0,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
578 flags);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
579
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
580 if (!hooked_screen) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
581 GLERR("Unable to open an OpenGL window !\n");
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
582 return (NULL);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
583 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
584
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
585 /* save the screen flags for restore time */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
586 old_screen_flags = hooked_screen->flags;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
587
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
588 #ifdef DEBUG_GLSDL
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
589 fprintf(stderr, "got %d bpp\n", bpp);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
590 #endif
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
591
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
592 /* setup the public surface format
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
593 * glSDL always returns the bpp its asked
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
594 */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
595 switch (bpp) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
596 case 32:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
597 this->is_32bit = 1;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
598 this->screen = SDL_CreateRGBSurface(flags, width, height, bpp,
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
599 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
600 0x00FF0000,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
601 0x0000FF00, 0x000000FF, 0x00000000
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
602 #else
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
603 0x0000FF00,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
604 0x00FF0000, 0xFF000000, 0x00000000
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
605 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
606 );
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
607 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
608 case 24:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
609 this->is_32bit = 0;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
610 this->screen = SDL_CreateRGBSurface(flags, width, height, bpp,
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
611 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
612 0x00FF0000,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
613 0x0000FF00, 0x000000FF, 0x00000000
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
614 #else
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
615 0x0000FF00,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
616 0x00FF0000, 0xFF000000, 0x00000000
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
617 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
618 );
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
619 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
620 case 16:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
621 this->is_32bit = 0;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
622 this->screen = SDL_CreateRGBSurface(flags, width, height, bpp,
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
623 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
624 0x0000F800,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
625 0x000007E0, 0x0000001F, 0x00000000
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
626 #else
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
627 0x0000001F,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
628 0x000007E0, 0x0000F800, 0x00000000
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
629 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
630 );
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
631 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
632 case 15:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
633 this->is_32bit = 0;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
634 this->screen = SDL_CreateRGBSurface(flags, width, height, bpp,
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
635 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
636 0x00007C00,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
637 0x000003E0, 0x0000001F, 0x00000000
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
638 #else
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
639 0x0000001F,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
640 0x000003E0, 0x00007C00, 0x00000000
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
641 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
642 );
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
643 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
644 case 8:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
645 default:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
646 this->is_32bit = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
647 this->screen =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
648 SDL_CreateRGBSurface(flags, width, height, bpp, 0, 0, 0, 0);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
649 /* give it a default palette if 8 bpp
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
650 * note : SDL already takes care of the palette for 4 bits & 1 bit surfaces
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
651 */
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
652 /* if (bpp==8)
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
653 {
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
654 this->screen->format->palette->ncolors=255;
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
655 SDL_DitherColors(this->screen->format->palette->colors,bpp);
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
656 }*/
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
657 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
658 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
659
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
660 /* also, we add SDL_HWSURFACE all the time, and let SDL create a shadow surface accordingly */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
661 this->screen->flags =
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
662 hooked_screen->flags | SDL_HWSURFACE | SDL_INTERNALOPENGL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
663 /* add SDL_DOUBLEBUF if it was requested */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
664 if (flag_doublebuf)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
665 this->screen->flags |= SDL_DOUBLEBUF;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
666
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
667 /* Tell SDL the alpha pixel format we'd like to have */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
668 this->displayformatalphapixel = SDL_AllocFormat(32,
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
669 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
670 0xFF000000,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
671 0x00FF0000,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
672 0x0000FF00, 0x000000FF
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
673 #else
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
674 0x000000FF,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
675 0x0000FF00,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
676 0x00FF0000, 0xFF000000
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
677 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
678 );
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
679
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
680 /* Now create the raw OpenGL surface */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
681 OpenGL_Surface = SDL_CreateRGBSurface(flags, width, height, 24,
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
682 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
683 0x000000FF,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
684 0x0000FF00, 0x00FF0000, 0x00000000
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
685 #else
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
686 0xFF000000,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
687 0x00FF0000, 0x0000FF00, 0x00000000
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
688 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
689 );
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
690
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
691 /* Here we have to setup OpenGL funcs ourselves */
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
692 #ifndef __QNXNTO__
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
693 #define SDL_PROC(ret,func,params) \
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
694 do { \
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
695 this->func = SDL_GL_GetProcAddress(#func); \
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
696 if ( ! this->func ) { \
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
697 SDL_SetError("Couldn't load GL function: %s\n", #func); \
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
698 return(NULL); \
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
699 } \
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
700 } while ( 0 );
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
701 #else
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
702 #define SDL_PROC(ret,func,params) this->func=func;
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
703 #endif /* __QNXNTO__ */
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
704 #include "../SDL_glfuncs.h"
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
705 #undef SDL_PROC
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
706
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
707 if (this->GL_MakeCurrent(this) < 0)
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
708 return (NULL);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
709 #define SDL_PROC(ret,func,params) \
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
710 do { \
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
711 this->func = SDL_GL_GetProcAddress(#func); \
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
712 if ( ! this->func ) { \
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
713 SDL_SetError("Couldn't load GL function: %s\n", #func); \
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
714 return(NULL); \
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
715 } \
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
716 } while ( 0 );
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
717 #include "../SDL_glfuncs.h"
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
718 #undef SDL_PROC
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
719
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
720
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
721 #ifdef FAKE_MAXTEXSIZE
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
722 maxtexsize = FAKE_MAXTEXSIZE;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
723 #else
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
724 this->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxtexsize);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
725 #endif
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
726 #ifdef DEBUG_GLSDL
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
727 fprintf(stderr, "glSDL: Max texture size: %d\n", maxtexsize);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
728 #endif
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
729
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
730 glSDL_init_formats(this);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
731
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
732 if (flag_doublebuf)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
733 this->glDrawBuffer(GL_BACK);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
734 else
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
735 this->glDrawBuffer(GL_FRONT);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
736
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
737 this->glDisable(GL_DITHER);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
738
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
739 if (glSDL_AddTexInfo(this, this->screen) < 0) {
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
740 GLERR("HookDevice() failed to add info to screen surface!");
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
741 return NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
742 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
743
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
744 glSDL_SetLogicSize(this, this->screen, this->screen->w, this->screen->h);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
745
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
746 glSDL_do_texture(this, 0);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
747 glSDL_do_blend(this, 0);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
748
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
749 for (i = 0; i < 1 + flag_doublebuf; ++i) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
750 this->glBegin(GL_TRIANGLE_FAN);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
751 this->glColor3ub(0, 0, 0);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
752 this->glVertex2i(0, 0);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
753 this->glVertex2i(this->screen->w, 0);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
754 this->glVertex2i(this->screen->w, this->screen->h);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
755 this->glVertex2i(0, this->screen->h);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
756 this->glEnd();
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
757 if (!i)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
758 this->GL_SwapBuffers(this);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
759 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
760
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
761 mirrorbuf = SDL_malloc(this->screen->h * this->screen->pitch);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
762 if (!mirrorbuf) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
763 GLERR("HookDevice() failed to allocate temp buffer for mirroring!");
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
764 return NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
765 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
766
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
767 return this->screen;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
768 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
769
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
770 static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
771 glSDL_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
772 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
773 /* We don't need to fill this one */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
774 return 0;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
775 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
776
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
777
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
778 #ifdef DEBUG_GLSDL
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
779 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
780 glSDL_print_glerror(_THIS, int point)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
781 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
782 const char *err = "<unknown>";
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
783 switch (this->glGetError()) {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
784 case GL_NO_ERROR:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
785 return;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
786 case GL_INVALID_ENUM:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
787 err = "GL_INVALID_ENUM";
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
788 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
789 case GL_INVALID_VALUE:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
790 err = "GL_INVALID_VALUE";
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
791 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
792 case GL_INVALID_OPERATION:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
793 err = "GL_INVALID_OPERATION";
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
794 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
795 case GL_STACK_OVERFLOW:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
796 err = "GL_STACK_OVERFLOW";
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
797 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
798 case GL_STACK_UNDERFLOW:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
799 err = "GL_STACK_UNDERFLOW";
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
800 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
801 case GL_OUT_OF_MEMORY:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
802 err = "GL_OUT_OF_MEMORY";
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
803 default:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
804 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
805 }
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
806 fprintf(stderr, "OpenGL error \"%s\" at point %d.\n", err, point);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
807 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
808 #endif
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
809
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
810 /* Get texinfo for a surface. */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
811 static __inline__ private_hwdata *
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
812 glSDL_GetTexInfo(SDL_Surface * surface)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
813 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
814 if (!surface)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
815 return NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
816 return surface->hwdata;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
817 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
818
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
819
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
820 /* Allocate a "blank" texinfo for a suface. */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
821 static private_hwdata *
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
822 glSDL_AllocTexInfo(SDL_Surface * surface)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
823 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
824 private_hwdata *txi;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
825 if (!surface)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
826 return NULL;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
827
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
828 txi = glSDL_GetTexInfo(surface);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
829 if (txi)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
830 return txi; /* There already is one! --> */
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
831
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
832 /* ...and hook a new texinfo struct up to it. */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
833 txi = (private_hwdata *) SDL_calloc(1, sizeof(private_hwdata));
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
834 if (!txi) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
835 GLERR("AllocTexInfo(): Failed allocating TexInfo struct!");
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
836 return NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
837 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
838 txi->temporary = 1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
839 #ifdef DEBUG_GLSDL
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
840 fprintf(stderr, "glSDL: Allocated TexInfo %p.\n", txi);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
841 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
842 return txi;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
843 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
844
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
845
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
846 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
847 glSDL_FreeTexInfo(_THIS, private_hwdata * txi)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
848 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
849 if (!txi)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
850 return;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
851
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
852 glSDL_UnloadTexture(this, txi);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
853 SDL_free(txi->texture);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
854 SDL_free(txi);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
855 #ifdef DEBUG_GLSDL
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
856 fprintf(stderr, "glSDL: Freed TexInfo %p.\n", txi);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
857 #endif
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
858 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
859
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
860
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
861 /* Detach and free the texinfo of a surface. */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
862 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
863 glSDL_RemoveTexInfo(_THIS, SDL_Surface * surface)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
864 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
865 SDL_Surface *next, *prev;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
866 if (!glSDL_GetTexInfo(surface))
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
867 return;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
868
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
869 /* maintain our doubly linked list */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
870 next = surface->hwdata->next;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
871 prev = surface->hwdata->prev;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
872 if (prev != NULL) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
873 prev->hwdata->next = next;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
874 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
875 first = next;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
876 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
877 if (next != NULL) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
878 next->hwdata->prev = prev;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
879 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
880
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
881 glSDL_FreeTexInfo(this, surface->hwdata);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
882 surface->hwdata = NULL;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
883 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
884
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
885
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
886 /*
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
887 * Calculate chopping/tiling of a surface to
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
888 * fit it into the smallest possible OpenGL
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
889 * texture.
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
890 */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
891 static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
892 glSDL_CalcChop(private_hwdata * txi)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
893 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
894 int rows, vw, vh;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
895 int vertical = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
896 int texsize;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
897 int lastw, lasth, minsize;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
898
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
899 vw = txi->virt.w;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
900 vh = txi->virt.h;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
901
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
902 #ifdef DEBUG_GLSDL_CHOP
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
903 fprintf(stderr, "w=%d, h=%d ", vw, vh);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
904 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
905 if (vh > vw) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
906 int t = vw;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
907 vw = vh;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
908 vh = t;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
909 vertical = 1;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
910 #ifdef DEBUG_GLSDL_CHOP
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
911 fprintf(stderr, "(vertical) \t");
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
912 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
913 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
914
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
915 /*
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
916 * Check whether this is a "huge" surface - at least one dimension
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
917 * must be <= than the maximum texture size, or we'll have to chop
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
918 * in both directions.
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
919 */
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
920 #ifdef DEBUG_GLSDL
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
921 if (maxtexsize < 0)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
922 return GLERET("glSDL_CalcChop() called before OpenGL init!");
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
923 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
924 if (vh > maxtexsize) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
925 /*
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
926 * Very simple hack for now; we just tile
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
927 * both ways with maximum size textures.
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
928 */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
929 texsize = maxtexsize;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
930
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
931 txi->tilemode = GLSDL_TM_HUGE;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
932 txi->texsize = texsize;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
933 txi->tilew = texsize;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
934 txi->tileh = texsize;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
935 txi->tilespertex = 1;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
936
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
937 /* Calculate number of textures needed */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
938 txi->textures = (vw + texsize - 1) / texsize;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
939 txi->textures *= (vh + texsize - 1) / texsize;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
940 txi->texture = SDL_malloc(txi->textures * sizeof(int));
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
941 SDL_memset(txi->texture, -1, txi->textures * sizeof(int));
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
942 #ifdef DEBUG_GLSDL
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
943 fprintf(stderr, "two-way tiling; textures=%d\n", txi->textures);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
944 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
945 if (!txi->texture) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
946 fprintf(stderr, "glSDL: INTERNAL ERROR: Failed to allocate"
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
947 " texture name table!\n");
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
948 return -3;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
949 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
950 return 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
951 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
952
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
953 /* Calculate minimum size */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
954 rows = 1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
955 lastw = vw;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
956 lasth = vh;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
957 minsize = lastw > lasth ? lastw : lasth;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
958 while (1) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
959 int w, h, size;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
960 ++rows;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
961 w = vw / rows;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
962 h = rows * vh;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
963 size = w > h ? w : h;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
964 if (size >= minsize) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
965 --rows;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
966 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
967 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
968 lastw = w;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
969 lasth = h;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
970 minsize = size;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
971 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
972 if (minsize > maxtexsize) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
973 /* Handle multiple textures for very wide/tall surfaces. */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
974 minsize = maxtexsize;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
975 rows = (vw + minsize - 1) / minsize;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
976 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
977 #ifdef DEBUG_GLSDL_CHOP
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
978 fprintf(stderr, "==> minsize=%d ", minsize);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
979 fprintf(stderr, "(rows=%d) \t", rows);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
980 #endif
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
981
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
982 /* Recalculate with nearest higher power-of-2 width. */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
983 for (texsize = 1; texsize < minsize; texsize <<= 1);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
984 txi->texsize = texsize;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
985 rows = (vw + texsize - 1) / texsize;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
986 #ifdef DEBUG_GLSDL_CHOP
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
987 fprintf(stderr, "==> texsize=%d (rows=%d) \t", texsize, rows);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
988 #endif
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
989
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
990 /* Calculate number of tiles per texture */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
991 txi->tilespertex = txi->texsize / vh;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
992 #ifdef DEBUG_GLSDL_CHOP
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
993 fprintf(stderr, "tilespertex=%d \t", txi->tilespertex);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
994 #endif
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
995
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
996 /* Calculate number of textures needed */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
997 txi->textures = (rows + txi->tilespertex - 1) / txi->tilespertex;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
998 txi->texture = (GLuint *) SDL_malloc(txi->textures * sizeof(GLuint));
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
999 SDL_memset(txi->texture, GLSDL_NOTEX, txi->textures * sizeof(GLuint));
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1000 #ifdef DEBUG_GLSDL_CHOP
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1001 fprintf(stderr, "textures=%d, ", txi->textures);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1002 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1003 if (!txi->texture)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1004 return GLERET("Failed to allocate texture name table!");
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1005
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1006 /* Set up tile size. (Only one axis supported here!) */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1007 if (1 == rows) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1008 txi->tilemode = GLSDL_TM_SINGLE;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1009 if (vertical) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1010 txi->tilew = vh;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1011 txi->tileh = vw;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1012 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1013 txi->tilew = vw;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1014 txi->tileh = vh;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1015 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1016 } else if (vertical) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1017 txi->tilemode = GLSDL_TM_VERTICAL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1018 txi->tilew = vh;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1019 txi->tileh = texsize;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1020 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1021 txi->tilemode = GLSDL_TM_HORIZONTAL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1022 txi->tilew = texsize;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1023 txi->tileh = vh;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1024 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1025
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1026 #ifdef DEBUG_GLSDL_CHOP
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1027 fprintf(stderr, "tilew=%d, tileh=%d\n", txi->tilew, txi->tileh);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1028 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1029 return 0;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1030 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1031
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1032
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1033 /* Create a temporary TexInfo struct for an SDL_Surface */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1034 static private_hwdata *
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1035 glSDL_CreateTempTexInfo(_THIS, SDL_Surface * surface)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1036 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1037 private_hwdata *txi;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1038 if (!surface) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1039 GLERR("CreateTempTexInfo(); no surface!");
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1040 return NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1041 }
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1042 if (IS_GLSDL_SURFACE(surface))
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1043 return glSDL_GetTexInfo(surface); /* Do nothing */
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1044
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1045 txi = glSDL_AllocTexInfo(surface);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1046 if (!txi) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1047 GLERR("CreateTempTexInfo(); Could not alloc TexInfo!");
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1048 return NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1049 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1050 txi->virt.w = txi->lw = surface->w;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1051 txi->virt.h = txi->lh = surface->h;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1052
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1053 if (glSDL_CalcChop(txi) < 0) {
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1054 glSDL_FreeTexInfo(this, txi);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1055 GLERR("CreateTempTexInfo(); CalcChop() failed!");
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1056 return NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1057 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1058
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1059 return txi;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1060 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1061
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1062 /* Add a glSDL_TexInfo struct to an SDL_Surface */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1063 static private_hwdata *
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1064 glSDL_AddTexInfo(_THIS, SDL_Surface * surface)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1065 {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1066 private_hwdata *txi = glSDL_CreateTempTexInfo(this, surface);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1067 if (!txi)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1068 return NULL;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1069
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1070 /* Connect the surface to the new TexInfo. */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1071 txi->temporary = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1072 surface->hwdata = txi;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1073
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1074 /* add this new surface in front of the list of hw surfaces */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1075 txi->next = first;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1076 txi->prev = NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1077 first = surface;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1078 if (txi->next != NULL) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1079 txi->next->hwdata->prev = surface;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1080 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1081
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1082 SDL_SetClipRect(surface, &txi->virt);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1083 return txi;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1084 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1085
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1086
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1087 /* Create a surface of the prefered OpenGL RGB texture format */
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1088 /*static SDL_Surface *glSDL_CreateRGBSurface(int w, int h)
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1089 {
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1090 SDL_Surface *s;
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1091 Uint32 rmask, gmask, bmask;
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1092 int bits = 24;
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1093 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1094 rmask = 0x000000FF;
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1095 gmask = 0x0000FF00;
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1096 bmask = 0x00FF0000;
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1097 #else
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1098 rmask = 0x00FF0000;
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1099 gmask = 0x0000FF00;
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1100 bmask = 0x000000FF;
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1101 #endif
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1102 s = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h,
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1103 bits, rmask, gmask, bmask, 0);
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1104 if(s)
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1105 s->flags |= SDL_HWACCEL;
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1106
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1107 return s;
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1108 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1109 */
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1110
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1111 /* Create a surface of the prefered OpenGL RGBA texture format */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1112 static SDL_Surface *
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1113 glSDL_CreateRGBASurface(int w, int h)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1114 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1115 SDL_Surface *s;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1116 Uint32 rmask, gmask, bmask, amask;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1117 int bits = 32;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1118 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1119 rmask = 0x000000FF;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1120 gmask = 0x0000FF00;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1121 bmask = 0x00FF0000;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1122 amask = 0xFF000000;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1123 #else
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1124 rmask = 0xFF000000;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1125 gmask = 0x00FF0000;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1126 bmask = 0x0000FF00;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1127 amask = 0x000000FF;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1128 #endif
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1129 s = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1130 bits, rmask, gmask, bmask, amask);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1131 if (s)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1132 s->flags |= SDL_HWACCEL;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1133
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1134 return s;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1135 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1136
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1137
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1138 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1139 glSDL_init_formats(_THIS)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1140 {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1141 RGBfmt = SDL_AllocFormat(24,
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1142 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1143 0x000000FF, 0x0000FF00, 0x00FF0000, 0);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1144 #else
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1145 0x00FF0000, 0x0000FF00, 0x000000FF, 0);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1146 #endif
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1147 RGBAfmt = SDL_AllocFormat(32,
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1148 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1149 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1150 #else
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1151 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1152 #endif
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1153 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1154
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1155
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1156 static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1157 glSDL_FormatIsOk(SDL_Surface * surface)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1158 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1159 SDL_PixelFormat *pf;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1160 if (!surface)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1161 return 1; /* Well, there ain't much we can do anyway... */
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1162
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1163 pf = surface->format;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1164
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1165 /* Colorkeying requires an alpha channel! */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1166 if (surface->flags & SDL_SRCCOLORKEY)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1167 if (!pf->Amask)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1168 return 0;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1169
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1170 /* We need pitch == (width * BytesPerPixel) for glTex[Sub]Image2D() */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1171 if (surface->pitch != (surface->w * pf->BytesPerPixel))
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1172 return 0;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1173
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1174 if (pf->Amask) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1175 if (pf->BytesPerPixel != RGBAfmt->BytesPerPixel)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1176 return 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1177 if (pf->Rmask != RGBAfmt->Rmask)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1178 return 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1179 if (pf->Gmask != RGBAfmt->Gmask)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1180 return 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1181 if (pf->Bmask != RGBAfmt->Bmask)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1182 return 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1183 if (pf->Amask != RGBAfmt->Amask)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1184 return 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1185 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1186 if (pf->BytesPerPixel != RGBfmt->BytesPerPixel)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1187 return 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1188 if (pf->Rmask != RGBfmt->Rmask)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1189 return 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1190 if (pf->Gmask != RGBfmt->Gmask)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1191 return 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1192 if (pf->Bmask != RGBfmt->Bmask)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1193 return 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1194 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1195 return 1;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1196 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1197
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1198 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1199 glSDL_key2alpha(SDL_Surface * surface)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1200 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1201 int x, y;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1202 Uint32 ckey = surface->format->colorkey;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1203
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1204 #ifdef DEBUG_GLSDL
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1205 fprintf(stderr, "glSDL_key2alpha()\n");
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1206 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1207 for (y = 0; y < surface->h; ++y) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1208 Uint32 *px =
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1209 (Uint32 *) ((char *) surface->pixels + y * surface->pitch);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1210 for (x = 0; x < surface->w; ++x)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1211 if (px[x] == ckey)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1212 px[x] = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1213 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1214 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1215
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1216
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1217
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1218 /*----------------------------------------------------------
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1219 SDL style API
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1220 ----------------------------------------------------------*/
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1221
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1222 static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1223 glSDL_FlipHWSurface(_THIS, SDL_Surface * surface)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1224 {
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1225 #ifdef GLSDL_GRAPHICAL_DEBUG
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1226 this->glDisable(GL_TEXTURE_2D);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1227 this->glBegin(GL_LINE_LOOP);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1228 this->glColor4ub(0, 0, 255, 128);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1229 this->glVertex2i(0, 0);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1230 this->glVertex2i(surface->w, 0);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1231 this->glVertex2i(surface->w, surface->h);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1232 this->glVertex2i(0, surface->h);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1233 this->glEnd();
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1234 this->glEnable(GL_TEXTURE_2D);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1235 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1236 if (this->screen->flags & SDL_DOUBLEBUF)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1237 this->GL_SwapBuffers(this);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1238 else
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1239 this->glFinish();
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1240 return 0;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1241 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1242
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1243
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1244 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1245 glSDL_UpdateRects(_THIS, int numrects, SDL_Rect * rects)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1246 {
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1247 #ifdef GLSDL_GRAPHICAL_DEBUG
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1248 int i;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1249 this->glDisable(GL_TEXTURE_2D);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1250 for (i = 0; i < numrects; i++) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1251 this->glColor4ub(255, 0, 0, 128);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1252 this->glBegin(GL_LINE_LOOP);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1253 this->glVertex2i(rects[i].x, rects[i].y);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1254 this->glVertex2i(rects[i].x + rects[i].w, rects[i].y);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1255 this->glVertex2i(rects[i].x + rects[i].w, rects[i].y + rects[i].h);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1256 this->glVertex2i(rects[i].x, rects[i].y + rects[i].h);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1257 this->glEnd();
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1258 }
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1259 this->glEnable(GL_TEXTURE_2D);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1260 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1261 if (this->screen->flags & SDL_DOUBLEBUF)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1262 this->GL_SwapBuffers(this);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1263 else
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1264 this->glFinish();
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1265 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1266
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1267
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1268 static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1269 glSDL_AllocHWSurface(_THIS, SDL_Surface * surface)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1270 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1271 surface->flags |= (SDL_HWSURFACE | SDL_HWACCEL);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1272
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1273 surface->pixels = SDL_malloc(surface->h * surface->pitch);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1274 if (surface->pixels == NULL) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1275 SDL_FreeSurface(surface);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1276 SDL_OutOfMemory();
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1277 return (-1);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1278 }
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1279 SDL_memset(surface->pixels, 0, surface->h * surface->pitch);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1280 return 0;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1281 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1282
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1283
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1284 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1285 glSDL_FreeHWSurface(_THIS, SDL_Surface * surface)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1286 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1287 if (!surface)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1288 return;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1289 glSDL_RemoveTexInfo(this, surface);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1290 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1291
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1292
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1293 static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1294 glSDL_LockHWSurface(_THIS, SDL_Surface * surface)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1295 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1296 int y;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1297
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1298 if (!surface)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1299 return -1;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1300
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1301 #ifdef DEBUG_GLSDL
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1302 fprintf(stderr, "glSDL: Lock Surface.\n");
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1303 #endif
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1304
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1305 if (SDL_VideoSurface == surface) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1306 glSDL_Invalidate(surface, NULL);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1307 this->glPixelStorei(GL_UNPACK_ROW_LENGTH,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1308 surface->pitch / surface->format->BytesPerPixel);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1309 this->glReadPixels(0, 0, OpenGL_Surface->w, OpenGL_Surface->h,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1310 GL_RGB, GL_UNSIGNED_BYTE, OpenGL_Surface->pixels);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1311 for (y = 0; y < OpenGL_Surface->h / 2; ++y) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1312 void *upper = (Uint8 *) OpenGL_Surface->pixels +
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1313 OpenGL_Surface->pitch * y;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1314 void *lower = (Uint8 *) OpenGL_Surface->pixels +
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1315 OpenGL_Surface->pitch * (OpenGL_Surface->h - y - 1);
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1316 SDL_memcpy(mirrorbuf, upper, OpenGL_Surface->pitch);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1317 SDL_memcpy(upper, lower, OpenGL_Surface->pitch);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1318 SDL_memcpy(lower, mirrorbuf, OpenGL_Surface->pitch);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1319 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1320 /* the mapping has to be invalidated on 8bpp video surfaces in case of a hw palette change.
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1321 * Now if someone could tell me why this is not handled by SDL... */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1322 if (SDL_VideoSurface->format->BitsPerPixel == 8)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1323 SDL_InvalidateMap(OpenGL_Surface->map);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1324
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1325 /* convert this raw surface to the application-requested format
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1326 * FIXME this is sometimes overkill, we could use glPixelStore smartly
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1327 * But this would be slow anyway :) */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1328
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1329 glSDL_SoftBlit(OpenGL_Surface, NULL, SDL_VideoSurface, NULL);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1330 } else
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1331 glSDL_Invalidate(surface, NULL);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1332
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1333 return 0;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1334 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1335
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1336
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1337 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1338 glSDL_UnlockHWSurface(_THIS, SDL_Surface * surface)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1339 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1340 private_hwdata *txi;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1341
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1342 if (!surface)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1343 return;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1344
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1345 /* upload this surface ONLY if this is a glSDL surface
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1346 * because sometimes (during displayformating for ex.) surfaces are unlocked that aren't glSDL
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1347 */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1348 if (!IS_GLSDL_SURFACE(surface))
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1349 return;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1350
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1351 #ifdef DEBUG_GLSDL
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1352 fprintf(stderr, "glSDL: Unlock Surface.\n");
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1353 #endif
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1354
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1355 txi = glSDL_UploadSurface(this, surface);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1356
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1357 if (!txi) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1358 GLERR("glSDL_UnlockHWSurface() failed to upload surface!");
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1359 return;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1360 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1361 if (txi->temporary) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1362 GLERR
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1363 ("Weirdness... glSDL_UnlockHWSurface() got a temporary TexInfo.");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1364 return;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1365 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1366 if (surface == SDL_VideoSurface)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1367 glSDL_BlitGL(this, SDL_VideoSurface, NULL, NULL);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1368 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1369
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1370
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1371 static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1372 glSDL_SetHWColorKey(_THIS, SDL_Surface * surface, Uint32 key)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1373 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1374 /*
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1375 * If an application does this *after* SDL_DisplayFormat,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1376 * we're basically screwed, unless we want to do an
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1377 * in-place surface conversion hack here.
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1378 *
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1379 * What we do is just kill the glSDL texinfo... No big
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1380 * deal in most cases, as glSDL only converts once anyway,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1381 * *unless* you keep modifying the surface.
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1382 */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1383 if (IS_GLSDL_SURFACE(surface))
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1384 glSDL_RemoveTexInfo(this, surface);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1385 return 0;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1386 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1387
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1388
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1389 static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1390 glSDL_SetHWAlpha(_THIS, SDL_Surface * surface, Uint8 alpha)
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1391 {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1392 /*
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1393 * If an application does this *after* SDL_DisplayFormat,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1394 * we're basically screwed, unless we want to do an
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1395 * in-place surface conversion hack here.
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1396 *
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1397 * What we do is just kill the glSDL texinfo... No big
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1398 * deal in most cases, as glSDL only converts once anyway,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1399 * *unless* you keep modifying the surface.
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1400 */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1401 if (IS_GLSDL_SURFACE(surface))
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1402 glSDL_RemoveTexInfo(this, surface);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1403 return 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1404 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1405
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1406 static SDL_bool
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1407 glSDL_SetClipRect(_THIS, SDL_Surface * surface, SDL_Rect * rect)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1408 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1409 SDL_bool res;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1410 if (!surface)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1411 return SDL_FALSE;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1412
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1413 res = SDL_SetClipRect(surface, rect);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1414 if (!res)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1415 return SDL_FALSE;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1416
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1417 rect = &surface->clip_rect;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1418
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1419 if (surface == SDL_VideoSurface) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1420 SDL_Rect r;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1421 float xscale, yscale;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1422 private_hwdata *txi;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1423
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1424 r.x = rect->x;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1425 r.y = rect->y;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1426 r.w = rect->w;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1427 r.h = rect->h;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1428 SDL_SetClipRect(surface, rect);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1429
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1430 txi = glSDL_GetTexInfo(surface);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1431 if (!txi)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1432 return GLERET("SetClipRect(): Could not get TexInfo!");
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1433
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1434 this->glViewport(rect->x,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1435 surface->h - (rect->y + rect->h), rect->w, rect->h);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1436 /*
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1437 * Note that this projection is upside down in
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1438 * relation to the OpenGL coordinate system.
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1439 */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1440 this->glMatrixMode(GL_PROJECTION);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1441 this->glLoadIdentity();
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1442 xscale = (float) txi->lw / (float) surface->w;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1443 yscale = (float) txi->lh / (float) surface->h;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1444 this->glOrtho(xscale * (float) rect->x,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1445 xscale * (float) (rect->w + rect->x),
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1446 yscale * (float) (rect->h + rect->y),
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1447 yscale * (float) rect->y, -1.0, 1.0);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1448 return SDL_TRUE;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1449 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1450 return res;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1451 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1452
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1453 static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1454 glSDL_BlitFromGL(_THIS, SDL_Rect * srcrect,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1455 SDL_Surface * dst, SDL_Rect * dstrect)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1456 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1457 SDL_Rect sr, dr;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1458
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1459 /* In case the destination has an OpenGL texture... */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1460 glSDL_Invalidate(dst, dstrect);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1461
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1462 /* Abuse the fake screen buffer a little. */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1463 this->glPixelStorei(GL_UNPACK_ROW_LENGTH, SDL_VideoSurface->pitch /
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1464 SDL_VideoSurface->format->BytesPerPixel);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1465 if (srcrect)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1466 this->glReadPixels(srcrect->x,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1467 OpenGL_Surface->h - (srcrect->y + srcrect->h - 1),
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1468 srcrect->w, srcrect->h, GL_RGB, GL_UNSIGNED_BYTE,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1469 OpenGL_Surface->pixels);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1470 else
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1471 this->glReadPixels(0, 0, OpenGL_Surface->w, OpenGL_Surface->h,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1472 GL_RGB, GL_UNSIGNED_BYTE, OpenGL_Surface->pixels);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1473 sr = *srcrect;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1474 dr = *dstrect;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1475 glSDL_SoftBlit(OpenGL_Surface, &sr, dst, &dr);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1476 return 0;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1477 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1478
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1479 static __inline__ void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1480 glSDL_BlitGL_single(_THIS, private_hwdata * txi,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1481 float sx1, float sy1, SDL_Rect * dst, unsigned char alpha)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1482 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1483 float sx2, sy2, texscale;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1484 if (!txi->textures)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1485 return;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1486 if (-1 == txi->texture[0])
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1487 return;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1488 glSDL_texture(this, txi->texture[0]);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1489
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1490 texscale = 1.0 / (float) txi->texsize;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1491 sx2 = (sx1 + (float) dst->w) * texscale;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1492 sy2 = (sy1 + (float) dst->h) * texscale;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1493 sx1 *= texscale;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1494 sy1 *= texscale;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1495
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1496 #ifdef GLSDL_GRAPHICAL_DEBUG
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1497 this->glDisable(GL_TEXTURE_2D);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1498 this->glBegin(GL_LINE_LOOP);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1499 this->glColor4ub(0, 255, 0, 128);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1500 this->glVertex2i(dst->x, dst->y);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1501 this->glVertex2i(dst->x + dst->w, dst->y);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1502 this->glVertex2i(dst->x + dst->w, dst->y + dst->h);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1503 this->glVertex2i(dst->x, dst->y + dst->h);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1504 this->glEnd();
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1505 this->glEnable(GL_TEXTURE_2D);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1506 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1507
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1508 this->glBegin(GL_TRIANGLE_FAN);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1509 this->glColor4ub(255, 255, 255, alpha);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1510 this->glTexCoord2f(sx1, sy1);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1511 this->glVertex2i(dst->x, dst->y);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1512 this->glTexCoord2f(sx2, sy1);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1513 this->glVertex2i(dst->x + dst->w, dst->y);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1514 this->glTexCoord2f(sx2, sy2);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1515 this->glVertex2i(dst->x + dst->w, dst->y + dst->h);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1516 this->glTexCoord2f(sx1, sy2);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1517 this->glVertex2i(dst->x, dst->y + dst->h);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1518 this->glEnd();
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1519 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1520
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1521
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1522 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1523 glSDL_BlitGL_htile(_THIS, private_hwdata * txi,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1524 float sx1, float sy1, SDL_Rect * dst, unsigned char alpha)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1525 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1526 int tex;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1527 float tile, sx2, sy2, yo;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1528 float texscale = 1.0 / (float) txi->texsize;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1529 float tileh = (float) txi->tileh * texscale;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1530 sx2 = (sx1 + (float) dst->w) * texscale;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1531 sy2 = (sy1 + (float) dst->h) * texscale;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1532 sx1 *= texscale;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1533 sy1 *= texscale;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1534 tile = floor(sx1);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1535 tex = (int) tile / txi->tilespertex;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1536 yo = ((int) tile % txi->tilespertex) * tileh;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1537
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1538 if (tex >= txi->textures)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1539 return;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1540 if (-1 == txi->texture[tex])
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1541 return;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1542 glSDL_texture(this, txi->texture[tex]);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1543
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1544 while (tile < sx2) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1545 int tdx1 = dst->x;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1546 int tdx2 = dst->x + dst->w;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1547 float tsx1 = sx1 - tile;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1548 float tsx2 = sx2 - tile;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1549
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1550 /* Clip to current tile */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1551 if (tsx1 < 0.0) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1552 tdx1 -= tsx1 * txi->texsize;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1553 tsx1 = 0.0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1554 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1555 if (tsx2 > 1.0) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1556 tdx2 -= (tsx2 - 1.0) * txi->texsize;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1557 tsx2 = 1.0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1558 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1559
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1560 /* Maybe select next texture? */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1561 if (yo + tileh > 1.0) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1562 ++tex;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1563 if (tex >= txi->textures)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1564 return;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1565 if (-1 == txi->texture[tex])
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1566 return;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1567 glSDL_texture(this, txi->texture[tex]);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1568 yo = 0.0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1569 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1570 #ifdef GLSDL_GRAPHICAL_DEBUG
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1571 this->glDisable(GL_TEXTURE_2D);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1572 this->glBegin(GL_LINE_LOOP);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1573 this->glColor4ub(0, 255, 0, 128);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1574 this->glVertex2i(tdx1, dst->y);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1575 this->glVertex2i(tdx2, dst->y);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1576 this->glVertex2i(tdx2, dst->y + dst->h);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1577 this->glVertex2i(tdx1, dst->y + dst->h);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1578 this->glEnd();
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1579 this->glEnable(GL_TEXTURE_2D);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1580 #endif
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1581
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1582 this->glBegin(GL_TRIANGLE_FAN);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1583 this->glColor4ub(255, 255, 255, alpha);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1584 this->glTexCoord2f(tsx1, yo + sy1);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1585 this->glVertex2i(tdx1, dst->y);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1586 this->glTexCoord2f(tsx2, yo + sy1);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1587 this->glVertex2i(tdx2, dst->y);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1588 this->glTexCoord2f(tsx2, yo + sy2);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1589 this->glVertex2i(tdx2, dst->y + dst->h);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1590 this->glTexCoord2f(tsx1, yo + sy2);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1591 this->glVertex2i(tdx1, dst->y + dst->h);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1592 this->glEnd();
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1593 tile += 1.0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1594 yo += tileh;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1595 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1596 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1597
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1598
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1599 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1600 glSDL_BlitGL_vtile(_THIS, private_hwdata * txi,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1601 float sx1, float sy1, SDL_Rect * dst, unsigned char alpha)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1602 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1603 int tex;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1604 float tile, sx2, sy2, xo;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1605 float texscale = 1.0 / (float) txi->texsize;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1606 float tilew = (float) txi->tilew * texscale;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1607 sx2 = (sx1 + (float) dst->w) * texscale;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1608 sy2 = (sy1 + (float) dst->h) * texscale;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1609 sx1 *= texscale;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1610 sy1 *= texscale;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1611 tile = floor(sy1);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1612 tex = (int) tile / txi->tilespertex;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1613 xo = ((int) tile % txi->tilespertex) * tilew;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1614
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1615 if (tex >= txi->textures)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1616 return;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1617 if (-1 == txi->texture[tex])
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1618 return;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1619 glSDL_texture(this, txi->texture[tex]);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1620
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1621 while (tile < sy2) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1622 int tdy1 = dst->y;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1623 int tdy2 = dst->y + dst->h;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1624 float tsy1 = sy1 - tile;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1625 float tsy2 = sy2 - tile;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1626
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1627 /* Clip to current tile */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1628 if (tsy1 < 0.0) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1629 tdy1 -= tsy1 * txi->texsize;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1630 tsy1 = 0.0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1631 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1632 if (tsy2 > 1.0) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1633 tdy2 -= (tsy2 - 1.0) * txi->texsize;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1634 tsy2 = 1.0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1635 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1636
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1637 /* Maybe select next texture? */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1638 if (xo + tilew > 1.0) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1639 ++tex;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1640 if (tex >= txi->textures)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1641 return;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1642 if (-1 == txi->texture[tex])
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1643 return;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1644 glSDL_texture(this, txi->texture[tex]);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1645 xo = 0.0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1646 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1647 #ifdef GLSDL_GRAPHICAL_DEBUG
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1648 this->glDisable(GL_TEXTURE_2D);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1649 this->glBegin(GL_LINE_LOOP);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1650 this->glColor4ub(0, 255, 0, 128);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1651 this->glVertex2i(dst->x, tdy1);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1652 this->glVertex2i(dst->x + dst->w, tdy1);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1653 this->glVertex2i(dst->x + dst->w, tdy2);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1654 this->glVertex2i(dst->x, tdy2);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1655 this->glEnd();
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1656 this->glEnable(GL_TEXTURE_2D);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1657 #endif
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1658
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1659 this->glBegin(GL_TRIANGLE_FAN);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1660 this->glColor4ub(255, 255, 255, alpha);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1661 this->glTexCoord2f(xo + sx1, tsy1);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1662 this->glVertex2i(dst->x, tdy1);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1663 this->glTexCoord2f(xo + sx2, tsy1);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1664 this->glVertex2i(dst->x + dst->w, tdy1);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1665 this->glTexCoord2f(xo + sx2, tsy2);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1666 this->glVertex2i(dst->x + dst->w, tdy2);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1667 this->glTexCoord2f(xo + sx1, tsy2);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1668 this->glVertex2i(dst->x, tdy2);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1669 this->glEnd();
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1670
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1671 tile += 1.0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1672 xo += tilew;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1673 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1674 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1675
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1676
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1677 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1678 glSDL_BlitGL_hvtile(_THIS, SDL_Surface * src, private_hwdata * txi,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1679 float sx1, float sy1, SDL_Rect * dst, unsigned char alpha)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1680 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1681 int x, y, last_tex, tex;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1682 float sx2, sy2;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1683 float texscale = 1.0 / (float) txi->texsize;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1684 int tilesperrow = (src->w + txi->tilew - 1) / txi->tilew;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1685 sx2 = (sx1 + (float) dst->w) * texscale;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1686 sy2 = (sy1 + (float) dst->h) * texscale;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1687 sx1 *= texscale;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1688 sy1 *= texscale;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1689
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1690 last_tex = tex = floor(sy1) * tilesperrow + floor(sx1);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1691 if (tex >= txi->textures)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1692 return;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1693 if (-1 == txi->texture[tex])
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1694 return;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1695 glSDL_texture(this, txi->texture[tex]);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1696
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1697 for (y = floor(sy1); y < sy2; ++y) {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1698 int tdy1 = dst->y;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1699 int tdy2 = dst->y + dst->h;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1700 float tsy1 = sy1 - y;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1701 float tsy2 = sy2 - y;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1702
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1703 /* Clip to current tile */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1704 if (tsy1 < 0.0) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1705 tdy1 -= tsy1 * txi->texsize;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1706 tsy1 = 0.0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1707 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1708 if (tsy2 > 1.0) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1709 tdy2 -= (tsy2 - 1.0) * txi->texsize;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1710 tsy2 = 1.0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1711 }
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1712 for (x = floor(sx1); x < sx2; ++x) {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1713 int tdx1 = dst->x;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1714 int tdx2 = dst->x + dst->w;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1715 float tsx1 = sx1 - x;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1716 float tsx2 = sx2 - x;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1717
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1718 /* Clip to current tile */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1719 if (tsx1 < 0.0) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1720 tdx1 -= tsx1 * txi->texsize;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1721 tsx1 = 0.0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1722 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1723 if (tsx2 > 1.0) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1724 tdx2 -= (tsx2 - 1.0) * txi->texsize;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1725 tsx2 = 1.0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1726 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1727
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1728 /* Select texture */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1729 tex = y * tilesperrow + x;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1730 if (tex != last_tex) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1731 if (tex >= txi->textures)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1732 return;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1733 if (-1 == txi->texture[tex])
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1734 return;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1735 glSDL_texture(this, txi->texture[tex]);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1736 last_tex = tex;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1737 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1738 #ifdef GLSDL_GRAPHICAL_DEBUG
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1739 this->glDisable(GL_TEXTURE_2D);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1740 this->glBegin(GL_LINE_LOOP);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1741 this->glColor4ub(0, 255, 0, 128);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1742 this->glVertex2i(tdx1, tdy1);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1743 this->glVertex2i(tdx2, tdy1);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1744 this->glVertex2i(tdx2, tdy2);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1745 this->glVertex2i(tdx1, tdy2);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1746 this->glEnd();
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1747 this->glEnable(GL_TEXTURE_2D);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1748 #endif
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1749
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1750 this->glBegin(GL_TRIANGLE_FAN);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1751 this->glColor4ub(255, 255, 255, alpha);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1752 this->glTexCoord2f(tsx1, tsy1);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1753 this->glVertex2i(tdx1, tdy1);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1754 this->glTexCoord2f(tsx2, tsy1);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1755 this->glVertex2i(tdx2, tdy1);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1756 this->glTexCoord2f(tsx2, tsy2);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1757 this->glVertex2i(tdx2, tdy2);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1758 this->glTexCoord2f(tsx1, tsy2);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1759 this->glVertex2i(tdx1, tdy2);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1760 this->glEnd();
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1761 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1762 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1763 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1764
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1765 /*
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1766 * Calculate the actual blit rectangle and source offset
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1767 * for a blit from a rectangle in a surface with specified
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1768 * size to a surface with a cliprect.
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1769 *
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1770 * In: rect source rectangle
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1771 * w, h source surface size
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1772 * (x, y) destination coordinate
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1773 * clip destination clip rectangle
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1774 *
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1775 * Out: (x, y) source top-left offset
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1776 * rect destination rectangle
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1777 *
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1778 * Returns 1 if the result is visible, otherwise 0.
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1779 */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1780 static __inline__ int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1781 blitclip(SDL_Rect * rect, int w, int h, int *x, int *y, SDL_Rect * clip)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1782 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1783 int sx1, sy1, sx2, sy2;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1784 int dx1, dy1, dx2, dy2;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1785
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1786 /* Get source and destination coordinates */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1787 sx1 = rect->x;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1788 sy1 = rect->y;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1789 sx2 = sx1 + rect->w;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1790 sy2 = sy1 + rect->h;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1791 dx1 = *x;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1792 dy1 = *y;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1793
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1794 /* Keep source rect inside source surface */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1795 if (sx1 < 0) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1796 dx1 -= sx1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1797 sx1 = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1798 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1799 if (sy1 < 0) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1800 dy1 -= sy1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1801 sy1 = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1802 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1803 if (sx2 > w)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1804 sx2 = w;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1805 if (sy2 > h)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1806 sy2 = h;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1807
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1808 /* Cull blits from void space */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1809 if (sx1 >= sx2 || sy1 >= sy2)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1810 return 0;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1811
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1812 /* Calculate destination lower-right */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1813 dx2 = dx1 + (sx2 - sx1);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1814 dy2 = dy1 + (sy2 - sy1);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1815
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1816 /* Clip to destination cliprect */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1817 if (dx1 < clip->x) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1818 sx1 += clip->x - dx1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1819 dx1 = clip->x;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1820 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1821 if (dy1 < clip->y) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1822 sy1 += clip->y - dy1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1823 dy1 = clip->y;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1824 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1825 if (dx2 > clip->x + clip->w)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1826 dx2 = clip->x + clip->w;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1827 if (dy2 > clip->y + clip->h)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1828 dy2 = clip->y + clip->h;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1829
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1830 /* Cull nop/off-screen blits */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1831 if (dx1 >= dx2 || dy1 >= dy2)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1832 return 0;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1833
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1834 *x = sx1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1835 *y = sy1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1836 rect->x = dx1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1837 rect->y = dy1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1838 rect->w = dx2 - dx1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1839 rect->h = dy2 - dy1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1840 return 1;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1841 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1842
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1843 static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1844 glSDL_BlitGL(_THIS, SDL_Surface * src, SDL_Rect * srcrect, SDL_Rect * dstrect)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1845 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1846 private_hwdata *txi;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1847 float x1, y1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1848 unsigned char alpha;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1849 SDL_Rect d;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1850 int x, y;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1851 SDL_Rect r;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1852
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1853 if (!src)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1854 return GLERET("BlitGL(): No src surface!");
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1855
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1856 /* Get source and destination coordinates */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1857 if (srcrect)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1858 r = *srcrect;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1859 else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1860 r.x = r.y = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1861 r.w = src->w;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1862 r.h = src->h;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1863 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1864 if (dstrect) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1865 x = dstrect->x;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1866 y = dstrect->y;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1867 } else
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1868 x = y = 0;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1869
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1870 /* Clip! */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1871 if (!blitclip(&r, src->w, src->h, &x, &y, &this->screen->clip_rect)) {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1872 if (dstrect)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1873 dstrect->w = dstrect->h = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1874 return 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1875 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1876
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1877 /* Write back the resulting cliprect */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1878 if (dstrect)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1879 *dstrect = r;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1880
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1881 /* Make sure we have a source with a valid texture */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1882 txi = glSDL_UploadSurface(this, src);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1883 if (!txi)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1884 return GLERET("BlitGL(): Could not get a TexInfo!");
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1885
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1886 /* Set up blending */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1887 if (src->flags & (SDL_SRCALPHA | SDL_SRCCOLORKEY)) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1888 glSDL_blendfunc(this, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1889 glSDL_do_blend(this, 1);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1890 } else
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1891 glSDL_do_blend(this, 0);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1892
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1893 /* Enable texturing */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1894 glSDL_do_texture(this, 1);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1895
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1896 /* Calculate texcoords */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1897 if (!srcrect)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1898 srcrect = &txi->virt;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1899 x1 = (float) srcrect->x;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1900 y1 = (float) srcrect->y;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1901
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1902 /* Calculate screen coords. */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1903 if (dstrect) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1904 d.x = dstrect->x;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1905 d.y = dstrect->y;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1906 d.w = (int) (srcrect->w * (float) txi->lw / (float) txi->virt.w);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1907 d.h = (int) (srcrect->h * (float) txi->lh / (float) txi->virt.h);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1908 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1909 d.x = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1910 d.y = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1911 d.w = (int) (srcrect->w * (float) txi->lw / (float) txi->virt.w);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1912 d.h = (int) (srcrect->h * (float) txi->lh / (float) txi->virt.h);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1913 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1914
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1915 /*
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1916 * Note that we actually *prevent* the use of "full surface alpha"
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1917 * and alpha channel in combination - to stay SDL 2D compatible.
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1918 */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1919 if ((src->flags & SDL_SRCALPHA) && (src->format->Amask))
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1920 alpha = 255;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1921 else
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1922 alpha = src->format->alpha;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1923
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1924 /* Render! */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1925 switch (txi->tilemode) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1926 case GLSDL_TM_SINGLE:
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1927 glSDL_BlitGL_single(this, txi, x1, y1, &d, alpha);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1928 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1929 case GLSDL_TM_HORIZONTAL:
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1930 glSDL_BlitGL_htile(this, txi, x1, y1, &d, alpha);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1931 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1932 case GLSDL_TM_VERTICAL:
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1933 glSDL_BlitGL_vtile(this, txi, x1, y1, &d, alpha);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1934 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1935 case GLSDL_TM_HUGE:
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1936 glSDL_BlitGL_hvtile(this, src, txi, x1, y1, &d, alpha);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1937 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1938 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1939
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1940 if (txi->temporary)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1941 glSDL_FreeTexInfo(this, txi);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1942
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1943 return 0;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1944 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1945
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1946
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1947 static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1948 glSDL_HWAccelBlit(SDL_Surface * src, SDL_Rect * srcrect,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1949 SDL_Surface * dst, SDL_Rect * dstrect)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1950 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1951 SDL_Surface *vs;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1952
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1953 if (!src)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1954 return GLERET("HWAccelBlit(): No src surface!");
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1955 if (!dst)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1956 return GLERET("HWAccelBlit(): No dst surface!");
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1957
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1958 /*
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1959 * Figure out what to do:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1960 * screen->screen: glSDL_BlitFromGL() + glSDL_BlitGL()
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1961 * surface->screen: glSDL_BlitGL()
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1962 * screen->surface: glSDL_BlitFromGL()
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1963 * surface->surface: glSDL_SoftBlit()
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1964 */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1965 vs = SDL_VideoSurface;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1966 if (src == vs) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1967 if (dst == vs) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1968 /*
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1969 FIXME: Try glCopyPixels() instead...
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1970 */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1971 glSDL_BlitFromGL(current_video, srcrect, vs, dstrect);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1972 return glSDL_BlitGL(current_video, vs, srcrect, dstrect);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1973 } else {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1974 return glSDL_BlitFromGL(current_video, srcrect, dst, dstrect);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1975 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1976 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1977 if (dst == vs) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1978 return glSDL_BlitGL(current_video, src, srcrect, dstrect);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1979 } else {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1980 glSDL_Invalidate(dst, dstrect);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1981 glSDL_SoftBlit(src, srcrect, dst, dstrect);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1982 return 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1983 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1984 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1985 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1986
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1987
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1988 static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
1989 glSDL_FillHWRect(_THIS, SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1990 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1991 SDL_Surface *vs = SDL_VideoSurface;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1992 int dx1, dy1, dx2, dy2;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1993 Uint32 r, g, b;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1994 Uint8 br, bg, bb;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1995
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1996 /*
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1997 * Some ugly reverse conversion for compatibility...
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1998 * (We must do this before losing the dst pointer,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
1999 * as the pixel formats of the screen and
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2000 * SDL_VideoSurface may differ!)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2001 */
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2002
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2003 if (dst->format->palette) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2004 /* this a paletted color */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2005 SDL_GetRGB(color, dst->format, &br, &bg, &bb);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2006 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2007 /* this a RGB color */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2008 r = color & dst->format->Rmask;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2009 r = r >> dst->format->Rshift;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2010 r = r << dst->format->Rloss;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2011 br = r;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2012
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2013 g = color & dst->format->Gmask;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2014 g = g >> dst->format->Gshift;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2015 g = g << dst->format->Gloss;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2016 bg = g;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2017
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2018 b = color & dst->format->Bmask;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2019 b = b >> dst->format->Bshift;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2020 b = b << dst->format->Bloss;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2021 bb = b;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2022 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2023
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2024 if (vs != dst) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2025 /* draw a rect offscreen */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2026 glSDL_Invalidate(dst, dstrect);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2027 /* software-fill the surface by faking it as a SW_SURFACE */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2028 dst->flags &= ~SDL_HWSURFACE;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2029 SDL_FillRect(dst, dstrect, color);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2030 dst->flags |= SDL_HWSURFACE;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2031 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2032 /* draw a rect onscreen */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2033 glSDL_do_texture(this, 0);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2034 glSDL_do_blend(this, 0);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2035
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2036 dx1 = dstrect->x;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2037 dy1 = dstrect->y;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2038 dx2 = dx1 + dstrect->w;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2039 dy2 = dy1 + dstrect->h;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2040
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2041 this->glBegin(GL_TRIANGLE_FAN);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2042 this->glColor3ub(br, bg, bb);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2043 this->glVertex2i(dx1, dy1);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2044 this->glVertex2i(dx2, dy1);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2045 this->glVertex2i(dx2, dy2);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2046 this->glVertex2i(dx1, dy2);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2047 this->glEnd();
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2048 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2049 return 0;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2050 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2051
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2052 static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2053 glSDL_CheckHWBlit(_THIS, SDL_Surface * src, SDL_Surface * dst)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2054 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2055 src->flags |= SDL_HWACCEL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2056 src->map->hw_blit = glSDL_HWAccelBlit;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2057 return 1;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2058 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2059
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2060
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2061 static SDL_Surface *
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2062 glSDL_DisplayFormat(SDL_Surface * surface)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2063 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2064 SDL_Surface *tmp;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2065 int use_rgba = (surface->flags & SDL_SRCCOLORKEY) ||
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2066 ((surface->flags & SDL_SRCALPHA) && surface->format->Amask);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2067 #ifdef DEBUG_GLSDL
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2068 fprintf(stderr, "#### glSDL_DisplayFormat()\n");
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2069 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2070 if (use_rgba)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2071 tmp = glSDL_ConvertSurface(surface, RGBAfmt, SDL_SWSURFACE);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2072 else
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2073 tmp = glSDL_ConvertSurface(surface, RGBfmt, SDL_SWSURFACE);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2074 if (!tmp) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2075 GLERR("glSDL_DisplayFormat() could not convert surface!");
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2076 return NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2077 }
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2078 SDL_SetAlpha(tmp, 0, 0);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2079
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2080 if (surface->flags & SDL_SRCCOLORKEY) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2081 /*
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2082 * We drop colorkey data here, but we have to,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2083 * or we'll run into trouble when converting,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2084 * in particular from indexed color formats.
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2085 */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2086 SDL_SetColorKey(tmp, SDL_SRCCOLORKEY, surface->format->colorkey);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2087 glSDL_key2alpha(tmp);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2088 SDL_SetColorKey(tmp, 0, 0);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2089 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2090
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2091 return tmp;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2092 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2093
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2094
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2095 static SDL_Surface *
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2096 glSDL_DisplayFormatAlpha(SDL_Surface * surface)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2097 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2098 SDL_Surface *s, *tmp;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2099 tmp = glSDL_ConvertSurface(surface, RGBAfmt, SDL_SWSURFACE);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2100 #ifdef DEBUG_GLSDL
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2101 fprintf(stderr, "#### glSDL_DisplayFormatAlpha()\n");
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2102 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2103 if (!tmp)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2104 return NULL;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2105
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2106 SDL_SetAlpha(tmp, 0, 0);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2107 SDL_SetColorKey(tmp, 0, 0);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2108 s = glSDL_CreateRGBASurface(surface->w, surface->h);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2109 if (!s) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2110 SDL_FreeSurface(tmp);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2111 return NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2112 }
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2113 glSDL_SoftBlit(tmp, NULL, s, NULL);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2114 SDL_FreeSurface(tmp);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2115
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2116 if (surface->flags & SDL_SRCCOLORKEY) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2117 SDL_SetColorKey(s, SDL_SRCCOLORKEY, surface->format->colorkey);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2118 glSDL_key2alpha(s);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2119 SDL_SetColorKey(s, 0, 0);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2120 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2121
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2122 if (surface->flags & SDL_SRCALPHA)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2123 SDL_SetAlpha(s, SDL_SRCALPHA, surface->format->alpha);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2124 return s;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2125 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2126
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2127
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2128 /*----------------------------------------------------------
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2129 glSDL specific API extensions
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2130 ----------------------------------------------------------*/
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2131
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2132 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2133 glSDL_Invalidate(SDL_Surface * surface, SDL_Rect * area)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2134 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2135 private_hwdata *txi;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2136 if (!surface)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2137 return;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2138 txi = glSDL_GetTexInfo(surface);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2139 if (!txi)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2140 return;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2141 if (!area) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2142 txi->invalid_area.x = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2143 txi->invalid_area.y = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2144 txi->invalid_area.w = surface->w;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2145 txi->invalid_area.h = surface->h;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2146 return;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2147 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2148 txi->invalid_area = *area;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2149 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2150
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2151
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2152 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2153 glSDL_SetLogicSize(_THIS, SDL_Surface * surface, int w, int h)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2154 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2155 SDL_Rect r;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2156 private_hwdata *txi;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2157 if (!IS_GLSDL_SURFACE(surface))
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2158 return;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2159
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2160 txi = glSDL_GetTexInfo(surface);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2161
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2162 txi->lw = w;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2163 txi->lh = h;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2164
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2165 if (SDL_VideoSurface != surface)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2166 return;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2167
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2168 r.x = r.y = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2169 r.w = w;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2170 r.h = h;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2171 glSDL_SetClipRect(this, surface, &r);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2172
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2173 this->glMatrixMode(GL_MODELVIEW);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2174 this->glLoadIdentity();
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2175 this->glTranslated(0.0f, 0.0f, 0.0f);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2176
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2177 this->glDisable(GL_DEPTH_TEST);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2178 this->glDisable(GL_CULL_FACE);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2179
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2180 glSDL_reset();
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2181 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2182
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2183 static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2184 glSDL_InitTexture(_THIS, SDL_Surface * datasurf, private_hwdata * txi,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2185 int tex)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2186 {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2187 this->glGenTextures(1, (GLuint *) & txi->texture[tex]);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2188 this->glBindTexture(GL_TEXTURE_2D, txi->texture[tex]);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2189 glstate.texture = txi->texture[tex];
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2190 this->glPixelStorei(GL_UNPACK_ROW_LENGTH, datasurf->pitch /
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2191 datasurf->format->BytesPerPixel);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2192 this->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2193 this->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2194 this->glTexImage2D(GL_TEXTURE_2D, 0,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2195 datasurf->format->Amask ? GL_RGBA8 : GL_RGB8,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2196 txi->texsize, txi->texsize, 0,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2197 datasurf->format->Amask ? GL_RGBA : GL_RGB,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2198 GL_UNSIGNED_BYTE, NULL);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2199 #ifdef DEBUG_GLSDL
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2200 glSDL_print_glerror(this, 1);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2201 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2202 return 0;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2203 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2204
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2205
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2206 /* Image tiled horizontally (wide surface), or not at all */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2207 static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2208 glSDL_UploadHoriz(_THIS, SDL_Surface * datasurf, private_hwdata * txi)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2209 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2210 int bpp = datasurf->format->BytesPerPixel;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2211 int res;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2212 int tex = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2213 int fromx = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2214 int toy = txi->texsize; /* To init first texture */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2215 while (1) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2216 int thistw = datasurf->w - fromx;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2217 if (thistw > txi->tilew)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2218 thistw = txi->tilew;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2219 else if (thistw <= 0)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2220 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2221 if (toy + txi->tileh > txi->texsize) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2222 toy = 0;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2223 res = glSDL_InitTexture(this, datasurf, txi, tex);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2224 if (res < 0)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2225 return res;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2226 ++tex;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2227 }
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2228 this->glTexSubImage2D(GL_TEXTURE_2D, 0, 0, toy,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2229 thistw, txi->tileh,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2230 datasurf->format->Amask ? GL_RGBA : GL_RGB,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2231 GL_UNSIGNED_BYTE,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2232 (char *) datasurf->pixels + bpp * fromx);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2233 #ifdef DEBUG_GLSDL
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2234 glSDL_print_glerror(this, 2);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2235 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2236 fromx += txi->tilew;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2237 toy += txi->tileh;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2238 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2239 return 0;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2240 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2241
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2242
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2243 /* Image tiled vertically (tall surface) */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2244 static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2245 glSDL_UploadVert(_THIS, SDL_Surface * datasurf, private_hwdata * txi)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2246 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2247 int res;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2248 int tex = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2249 int fromy = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2250 int tox = txi->texsize; /* To init first texture */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2251 while (1) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2252 int thisth = datasurf->h - fromy;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2253 if (thisth > txi->tileh)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2254 thisth = txi->tileh;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2255 else if (thisth <= 0)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2256 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2257 if (tox + txi->tilew > txi->texsize) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2258 tox = 0;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2259 res = glSDL_InitTexture(this, datasurf, txi, tex);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2260 if (res < 0)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2261 return res;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2262 ++tex;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2263 }
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2264 this->glTexSubImage2D(GL_TEXTURE_2D, 0, tox, 0,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2265 txi->tilew, thisth,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2266 datasurf->format->Amask ? GL_RGBA : GL_RGB,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2267 GL_UNSIGNED_BYTE,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2268 (char *) datasurf->pixels +
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2269 datasurf->pitch * fromy);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2270 #ifdef DEBUG_GLSDL
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2271 glSDL_print_glerror(this, 3);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2272 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2273 fromy += txi->tileh;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2274 tox += txi->tilew;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2275 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2276 return 0;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2277 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2278
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2279
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2280 /* Image tiled two-way (huge surface) */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2281 static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2282 glSDL_UploadHuge(_THIS, SDL_Surface * datasurf, private_hwdata * txi)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2283 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2284 int bpp = datasurf->format->BytesPerPixel;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2285 int res;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2286 int tex = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2287 int y = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2288 while (y < datasurf->h) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2289 int x;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2290 int thisth = datasurf->h - y;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2291 if (thisth > txi->tileh)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2292 thisth = txi->tileh;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2293 x = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2294 while (x < datasurf->w) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2295 int thistw = datasurf->w - x;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2296 if (thistw > txi->tilew)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2297 thistw = txi->tilew;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2298 res = glSDL_InitTexture(this, datasurf, txi, tex++);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2299 if (res < 0)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2300 return res;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2301 this->glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2302 thistw, thisth,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2303 datasurf->format->
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2304 Amask ? GL_RGBA : GL_RGB,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2305 GL_UNSIGNED_BYTE,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2306 (char *) datasurf->pixels +
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2307 datasurf->pitch * y + bpp * x);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2308 #ifdef DEBUG_GLSDL
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2309 fprintf(stderr,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2310 "glTexSubImage(x = %d, y = %d, w = %d, h = %d)\n", x,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2311 y, thistw, thisth);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2312 glSDL_print_glerror(this, 4);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2313 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2314 x += txi->tilew;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2315 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2316 y += txi->tileh;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2317 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2318 return 0;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2319 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2320
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2321
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2322 /* Upload all textures for a surface. */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2323 static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2324 glSDL_UploadTextures(_THIS, SDL_Surface * datasurf, private_hwdata * txi)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2325 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2326 switch (txi->tilemode) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2327 case GLSDL_TM_SINGLE:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2328 case GLSDL_TM_HORIZONTAL:
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2329 glSDL_UploadHoriz(this, datasurf, txi);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2330 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2331 case GLSDL_TM_VERTICAL:
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2332 glSDL_UploadVert(this, datasurf, txi);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2333 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2334 case GLSDL_TM_HUGE:
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2335 glSDL_UploadHuge(this, datasurf, txi);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2336 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2337 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2338 return 0;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2339 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2340
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2341
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2342 /*
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2343 * IMPORTANT:
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2344 * This function will try various ways of giving you
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2345 * a TexInfo, and will succeed most of the time.
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2346 *
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2347 * However, the TexInfo returned may be temporary,
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2348 * (as opposed to connected to 'surface'). A temporary
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2349 * TexInfo must be used only once and then thrown away,
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2350 * since it means that glSDL cannot track changes in
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2351 * the pixel data of 'texture'.
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2352 */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2353 static private_hwdata *
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2354 glSDL_UploadSurface(_THIS, SDL_Surface * surface)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2355 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2356 int i;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2357 int converted = 0;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2358 private_hwdata *txi = glSDL_GetTexInfo(surface);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2359
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2360 if (IS_GLSDL_SURFACE(surface)) {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2361 /*
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2362 * Ok, this is a glSDL surface, and it *might* be
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2363 * in texture memory already. If so, it may need
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2364 * an update.
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2365 */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2366 if (txi->invalid_area.w) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2367 glSDL_UnloadTexture(this, txi);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2368 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2369 int missing = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2370 if (txi->textures) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2371 for (i = 0; i < txi->textures; ++i)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2372 if (GLSDL_NOTEX == txi->texture[i]) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2373 missing = 1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2374 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2375 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2376 if (!missing)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2377 return txi; /* They're already there! */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2378 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2379 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2380 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2381 /*
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2382 * Nope, this isn't (yet) a glSDL surface. Let's
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2383 * try to either make it one, or set up a temporary
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2384 * TexInfo for it, valid for only one blit.
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2385 */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2386 if ((surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2387 txi = glSDL_AddTexInfo(this, surface);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2388 if (!txi) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2389 GLERR("UploadSurface(): Could not add TexInfo!");
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2390 return NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2391 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2392 surface->flags |= SDL_HWSURFACE;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2393 surface->flags |= SDL_HWACCEL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2394 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2395 /*
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2396 * FIXME
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2397 * here if the surface is small enough, it's a good
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2398 * candidate for a blit using glDrawPixels instead
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2399 * of a texture blit
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2400 */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2401 txi = glSDL_CreateTempTexInfo(this, surface);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2402 if (!txi) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2403 GLERR("UploadSurface(): Could not create temp TexInfo!");
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2404 return NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2405 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2406 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2407 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2408
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2409 if (txi->texsize > maxtexsize) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2410 /* This surface wasn't tiled properly... */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2411 if (txi->temporary)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2412 glSDL_FreeTexInfo(this, txi);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2413 GLERR("UploadSurface(): Too large texture!");
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2414 return NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2415 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2416
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2417 /*
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2418 * Kludge: Convert if not of preferred RGB or RGBA format.
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2419 *
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2420 * Conversion should only be done when *really* needed.
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2421 * That is, it should rarely have to be done with OpenGL
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2422 * 1.2+.
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2423 *
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2424 * Besides, any surface that's been SDL_DisplayFormat()ed
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2425 * should already be in the best known OpenGL format -
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2426 * preferably one that makes DMA w/o conversion possible.
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2427 */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2428 if (!glSDL_FormatIsOk(surface)) {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2429 #ifdef DEBUG_GLSDL
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2430 fprintf(stderr, "glSDL: WARNING: On-the-fly conversion performed!\n");
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2431 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2432 converted = 1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2433 /* NOTE: We forget about the original surface here. */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2434 if (surface->format->Amask)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2435 surface = glSDL_DisplayFormatAlpha(surface);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2436 else
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2437 surface = glSDL_DisplayFormat(surface);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2438 if (!surface) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2439 GLERR("UploadSurface(): Could not convert surface!");
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2440 if (txi->temporary)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2441 glSDL_FreeTexInfo(this, txi);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2442 return NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2443 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2444 }
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2445
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2446 glSDL_UploadTextures(this, surface, txi);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2447
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2448 if (converted)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2449 SDL_FreeSurface(surface);
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2450
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2451 return txi;
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2452 }
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2453
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2454
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2455 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2456 glSDL_UnloadTexture(_THIS, private_hwdata * txi)
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2457 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2458 int i;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2459 for (i = 0; i < txi->textures; ++i)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2460 if (txi->texture[i] != GLSDL_NOTEX)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2461 this->glDeleteTextures(1, &txi->texture[i]);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
2462 SDL_memset(&txi->invalid_area, 0, sizeof(txi->invalid_area));
1658
e49147870aac glSDL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2463 }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2464
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1658
diff changeset
2465 /* vi: set ts=4 sw=4 expandtab: */