annotate src/video/glsdl/SDL_glsdl.c @ 1658:e49147870aac SDL-1.3

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