Hopefully glSDL has been superceded by the OpenGL render driver.
authorSam Lantinga <slouken@libsdl.org>
Wed, 26 Jul 2006 03:12:05 +0000
changeset 19424371d679ee12
parent 1941 bf09d535e014
child 1943 7d642361ef0f
Hopefully glSDL has been superceded by the OpenGL render driver.
configure.in
include/SDL_config.h.in
include/SDL_config_amiga.h
include/SDL_config_dreamcast.h
include/SDL_config_macos.h
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/glsdl/SDL_glsdl.c
src/video/glsdl/SDL_glsdl.h
     1.1 --- a/configure.in	Wed Jul 26 03:08:25 2006 +0000
     1.2 +++ b/configure.in	Wed Jul 26 03:12:05 2006 +0000
     1.3 @@ -1486,20 +1486,6 @@
     1.4      fi
     1.5  }
     1.6  
     1.7 -dnl Find glSDL
     1.8 -CheckglSDL()
     1.9 -{
    1.10 -    AC_ARG_ENABLE(video-glsdl,
    1.11 -[  --enable-video-glsdl    use glSDL video driver [default=yes]],
    1.12 -                  , enable_video_glsdl=yes)
    1.13 -    AC_MSG_CHECKING(for glSDL support)
    1.14 -    AC_MSG_RESULT($video_opengl)
    1.15 -    if test x$video_opengl = xyes -a x$enable_video_glsdl = xyes; then
    1.16 -        AC_DEFINE(SDL_VIDEO_DRIVER_GLSDL)
    1.17 -        SOURCES="$SOURCES $srcdir/src/video/glsdl/*.c"
    1.18 -    fi
    1.19 -}
    1.20 -
    1.21  dnl Check for Mesa offscreen rendering
    1.22  CheckAtariOSMesa()
    1.23  {
    1.24 @@ -2106,7 +2092,6 @@
    1.25          CheckQtopia
    1.26          CheckPicoGUI
    1.27          CheckOpenGLX11
    1.28 -        CheckglSDL
    1.29          CheckInputEvents
    1.30          CheckTslib
    1.31          CheckUSBHID
    1.32 @@ -2205,7 +2190,6 @@
    1.33          CheckPHOTON
    1.34          CheckX11
    1.35          CheckOpenGLX11
    1.36 -        CheckglSDL
    1.37          CheckPTHREAD
    1.38          # Set up files for the audio library
    1.39          if test x$enable_audio = xyes; then
    1.40 @@ -2243,7 +2227,6 @@
    1.41          CheckDummyAudio
    1.42          CheckWIN32
    1.43          CheckWIN32GL
    1.44 -        CheckglSDL
    1.45          CheckDIRECTX
    1.46          CheckNASM
    1.47          # Set up files for the video library
    1.48 @@ -2328,7 +2311,6 @@
    1.49          CheckNASM
    1.50          CheckBWINDOW
    1.51          CheckBeGL
    1.52 -        CheckglSDL
    1.53          # Set up files for the audio library
    1.54          if test x$enable_audio = xyes; then
    1.55              AC_DEFINE(SDL_AUDIO_DRIVER_BAUDIO)
    1.56 @@ -2409,7 +2391,6 @@
    1.57          CheckX11
    1.58          CheckMacGL
    1.59          CheckOpenGLX11
    1.60 -        CheckglSDL
    1.61          CheckPTHREAD
    1.62          CheckAltivec
    1.63  
    1.64 @@ -2463,7 +2444,6 @@
    1.65          CheckAtariAudio
    1.66          CheckAtariLdg
    1.67          CheckAtariOSMesa
    1.68 -        CheckglSDL
    1.69          CheckPTH
    1.70          # Set up files for the audio library
    1.71          if test x$enable_threads = xyes -a x$enable_pth = xyes; then
     2.1 --- a/include/SDL_config.h.in	Wed Jul 26 03:08:25 2006 +0000
     2.2 +++ b/include/SDL_config.h.in	Wed Jul 26 03:12:05 2006 +0000
     2.3 @@ -262,7 +262,6 @@
     2.4  #undef SDL_VIDEO_DRIVER_GAPI
     2.5  #undef SDL_VIDEO_DRIVER_GEM
     2.6  #undef SDL_VIDEO_DRIVER_GGI
     2.7 -#undef SDL_VIDEO_DRIVER_GLSDL
     2.8  #undef SDL_VIDEO_DRIVER_IPOD
     2.9  #undef SDL_VIDEO_DRIVER_NANOX
    2.10  #undef SDL_VIDEO_DRIVER_OS2FS
     3.1 --- a/include/SDL_config_amiga.h	Wed Jul 26 03:08:25 2006 +0000
     3.2 +++ b/include/SDL_config_amiga.h	Wed Jul 26 03:12:05 2006 +0000
     3.3 @@ -73,7 +73,6 @@
     3.4  /* Enable various video drivers */
     3.5  #define SDL_VIDEO_DRIVER_CYBERGRAPHICS	1
     3.6  #define SDL_VIDEO_DRIVER_DUMMY	1
     3.7 -#define SDL_VIDEO_DRIVER_GLSDL	1
     3.8  
     3.9  /* Enable OpenGL support */
    3.10  #define SDL_VIDEO_OPENGL	1
     4.1 --- a/include/SDL_config_dreamcast.h	Wed Jul 26 03:08:25 2006 +0000
     4.2 +++ b/include/SDL_config_dreamcast.h	Wed Jul 26 03:12:05 2006 +0000
     4.3 @@ -102,6 +102,5 @@
     4.4  /* Enable various video drivers */
     4.5  #define SDL_VIDEO_DRIVER_DC	1
     4.6  #define SDL_VIDEO_DRIVER_DUMMY	1
     4.7 -#define SDL_VIDEO_DRIVER_GLSDL	1
     4.8  
     4.9  #endif /* _SDL_config_dreamcast_h */
     5.1 --- a/include/SDL_config_macos.h	Wed Jul 26 03:08:25 2006 +0000
     5.2 +++ b/include/SDL_config_macos.h	Wed Jul 26 03:12:05 2006 +0000
     5.3 @@ -104,7 +104,6 @@
     5.4  /* Enable various video drivers */
     5.5  #define SDL_VIDEO_DRIVER_DUMMY	1
     5.6  #define SDL_VIDEO_DRIVER_DRAWSPROCKET	1
     5.7 -#define SDL_VIDEO_DRIVER_GLSDL	1
     5.8  #define SDL_VIDEO_DRIVER_TOOLBOX	1
     5.9  
    5.10  /* Enable OpenGL support */
     6.1 --- a/src/video/SDL_sysvideo.h	Wed Jul 26 03:08:25 2006 +0000
     6.2 +++ b/src/video/SDL_sysvideo.h	Wed Jul 26 03:12:05 2006 +0000
     6.3 @@ -378,9 +378,6 @@
     6.4  #if SDL_VIDEO_DRIVER_DUMMY
     6.5  extern VideoBootStrap DUMMY_bootstrap;
     6.6  #endif
     6.7 -#if SDL_VIDEO_DRIVER_GLSDL
     6.8 -extern VideoBootStrap glSDL_bootstrap;
     6.9 -#endif
    6.10  
    6.11  #define SDL_CurrentDisplay	(_this->displays[_this->current_display])
    6.12  
     7.1 --- a/src/video/SDL_video.c	Wed Jul 26 03:08:25 2006 +0000
     7.2 +++ b/src/video/SDL_video.c	Wed Jul 26 03:12:05 2006 +0000
     7.3 @@ -127,9 +127,6 @@
     7.4  #if SDL_VIDEO_DRIVER_DUMMY
     7.5      &DUMMY_bootstrap,
     7.6  #endif
     7.7 -#if SDL_VIDEO_DRIVER_GLSDL
     7.8 -    &glSDL_bootstrap,
     7.9 -#endif
    7.10      NULL
    7.11  };
    7.12  
     8.1 --- a/src/video/glsdl/SDL_glsdl.c	Wed Jul 26 03:08:25 2006 +0000
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,2465 +0,0 @@
     8.4 -/*
     8.5 -    SDL - Simple DirectMedia Layer
     8.6 -    Copyright (C) 1997-2006 Sam Lantinga
     8.7 -
     8.8 -    This library is free software; you can redistribute it and/or
     8.9 -    modify it under the terms of the GNU Lesser General Public
    8.10 -    License as published by the Free Software Foundation; either
    8.11 -    version 2.1 of the License, or (at your option) any later version.
    8.12 -
    8.13 -    This library is distributed in the hope that it will be useful,
    8.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    8.16 -    Lesser General Public License for more details.
    8.17 -
    8.18 -    You should have received a copy of the GNU Lesser General Public
    8.19 -    License along with this library; if not, write to the Free Software
    8.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    8.21 -
    8.22 -    Sam Lantinga
    8.23 -    slouken@libsdl.org
    8.24 -*/
    8.25 -#include "SDL_config.h"
    8.26 -
    8.27 -/*
    8.28 - * glSDL "SDL-over-OpenGL" video driver implemented by
    8.29 - * David Olofson <david@olofson.net> and
    8.30 - * Stephane Marchesin <stephane.marchesin@wanadoo.fr>
    8.31 - */
    8.32 -#include <math.h>
    8.33 -
    8.34 -#include "SDL.h"
    8.35 -#include "SDL_error.h"
    8.36 -#include "SDL_video.h"
    8.37 -#include "SDL_mouse.h"
    8.38 -#include "../SDL_sysvideo.h"
    8.39 -#include "../SDL_pixels_c.h"
    8.40 -
    8.41 -#include "SDL_glsdl.h"
    8.42 -
    8.43 -#undef	DEBUG_GLSDL
    8.44 -#undef	DEBUG_GLSDL_CHOP
    8.45 -#define	FAKE_MAXTEXSIZE	256
    8.46 -#undef GLSDL_GRAPHICAL_DEBUG
    8.47 -
    8.48 -/* Initialization/Query functions */
    8.49 -
    8.50 -/* Hardware surface functions */
    8.51 -static int glSDL_SetColors(_THIS, int firstcolor, int ncolors,
    8.52 -                           SDL_Color * colors);
    8.53 -static int glSDL_AllocHWSurface(_THIS, SDL_Surface * surface);
    8.54 -static int glSDL_LockHWSurface(_THIS, SDL_Surface * surface);
    8.55 -static int glSDL_FlipHWSurface(_THIS, SDL_Surface * surface);
    8.56 -static void glSDL_UnlockHWSurface(_THIS, SDL_Surface * surface);
    8.57 -static void glSDL_FreeHWSurface(_THIS, SDL_Surface * surface);
    8.58 -static int glSDL_FillHWRect(_THIS, SDL_Surface * dst, SDL_Rect * rect,
    8.59 -                            Uint32 color);
    8.60 -static int glSDL_CheckHWBlit(_THIS, SDL_Surface * src, SDL_Surface * dst);
    8.61 -static int glSDL_SetHWColorKey(_THIS, SDL_Surface * surface, Uint32 key);
    8.62 -static int glSDL_SetHWAlpha(_THIS, SDL_Surface * surface, Uint8 alpha);
    8.63 -static int glSDL_VideoInit(_THIS, SDL_PixelFormat * vformat);
    8.64 -static SDL_Rect **glSDL_ListModes(_THIS, SDL_PixelFormat * format,
    8.65 -                                  Uint32 flags);
    8.66 -static void glSDL_VideoQuit(_THIS);
    8.67 -static void glSDL_UpdateRects(_THIS, int numrects, SDL_Rect * rects);
    8.68 -static SDL_Surface *glSDL_SetVideoMode(_THIS, SDL_Surface * current,
    8.69 -                                       int width, int height, int bpp,
    8.70 -                                       Uint32 flags);
    8.71 -
    8.72 -#define	IS_GLSDL_SURFACE(s)	((s) && glSDL_GetTexInfo(s))
    8.73 -
    8.74 -#define	LOGIC_W(s)	( IS_GLSDL_SURFACE(this,s) ? TEXINFO(s)->lw : (s)->w )
    8.75 -#define	LOGIC_H(s)	( IS_GLSDL_SURFACE(this,s) ? TEXINFO(s)->lh : (s)->h )
    8.76 -
    8.77 -#define	GLSDL_NOTEX	(~0)
    8.78 -
    8.79 -/*
    8.80 - * Special version for glSDL, which ignores the fake SDL_HWSURFACE
    8.81 - * flags, so we don't have SDL calling us back whenever we want to
    8.82 - * do some internal blitting...
    8.83 - */
    8.84 -static void
    8.85 -glSDL_SoftBlit(SDL_Surface * src, SDL_Rect * srcrect,
    8.86 -               SDL_Surface * dst, SDL_Rect * dstrect)
    8.87 -{
    8.88 -    SDL_BlitInfo info;
    8.89 -
    8.90 -    if (srcrect)
    8.91 -        if (!srcrect->w || !srcrect->h)
    8.92 -            return;
    8.93 -
    8.94 -    /* Check to make sure the blit mapping is valid */
    8.95 -    if ((src->map->dst != dst) ||
    8.96 -        (src->map->dst->format_version != src->map->format_version))
    8.97 -        if (SDL_MapSurface(src, dst) < 0)
    8.98 -            return;
    8.99 -
   8.100 -    /* Set up the blit information */
   8.101 -    if (srcrect) {
   8.102 -        info.s_pixels = (Uint8 *) src->pixels +
   8.103 -            (Uint16) srcrect->y * src->pitch +
   8.104 -            (Uint16) srcrect->x * src->format->BytesPerPixel;
   8.105 -        info.s_width = srcrect->w;
   8.106 -        info.s_height = srcrect->h;
   8.107 -    } else {
   8.108 -        info.s_pixels = (Uint8 *) src->pixels;
   8.109 -        info.s_width = src->w;
   8.110 -        info.s_height = src->h;
   8.111 -    }
   8.112 -    info.s_skip = src->pitch - info.s_width * src->format->BytesPerPixel;
   8.113 -    if (dstrect) {
   8.114 -        info.d_pixels = (Uint8 *) dst->pixels +
   8.115 -            (Uint16) dstrect->y * dst->pitch +
   8.116 -            (Uint16) dstrect->x * dst->format->BytesPerPixel;
   8.117 -        /*
   8.118 -         * NOTE: SDL_SoftBlit() uses the 'dstrect' for this!
   8.119 -         *       This version is more like SDL_BlitSurface().
   8.120 -         */
   8.121 -        info.d_width = srcrect->w;
   8.122 -        info.d_height = srcrect->h;
   8.123 -    } else {
   8.124 -        info.d_pixels = (Uint8 *) dst->pixels;
   8.125 -        info.d_width = dst->w;
   8.126 -        info.d_height = dst->h;
   8.127 -    }
   8.128 -    info.d_skip = dst->pitch - info.d_width * dst->format->BytesPerPixel;
   8.129 -    info.aux_data = src->map->sw_data->aux_data;
   8.130 -    info.src = src->format;
   8.131 -    info.table = src->map->table;
   8.132 -    info.dst = dst->format;
   8.133 -
   8.134 -    src->map->sw_data->blit(&info);
   8.135 -}
   8.136 -
   8.137 -
   8.138 -/* 
   8.139 - * Another special version. Doesn't lock/unlock, and doesn't mess
   8.140 - * with flags and stuff. It just converts the surface, period.
   8.141 - * Does not convert into palletized formats.
   8.142 - */
   8.143 -static SDL_Surface *
   8.144 -glSDL_ConvertSurface(SDL_Surface * surface,
   8.145 -                     SDL_PixelFormat * format, Uint32 flags)
   8.146 -{
   8.147 -    SDL_Surface *convert;
   8.148 -    Uint32 colorkey = 0;
   8.149 -    Uint8 alpha = 0;
   8.150 -    Uint32 surface_flags;
   8.151 -    SDL_Rect bounds;
   8.152 -
   8.153 -    /* Create a new surface with the desired format */
   8.154 -    convert = SDL_CreateRGBSurface(flags,
   8.155 -                                   surface->w, surface->h,
   8.156 -                                   format->BitsPerPixel, format->Rmask,
   8.157 -                                   format->Gmask, format->Bmask,
   8.158 -                                   format->Amask);
   8.159 -    if (convert == NULL) {
   8.160 -        return (NULL);
   8.161 -    }
   8.162 -
   8.163 -    /* Save the original surface color key and alpha */
   8.164 -    surface_flags = surface->flags;
   8.165 -    if ((surface_flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
   8.166 -        /* Convert colourkeyed surfaces to RGBA if requested */
   8.167 -        if ((flags & SDL_SRCCOLORKEY) != SDL_SRCCOLORKEY && format->Amask) {
   8.168 -            surface_flags &= ~SDL_SRCCOLORKEY;
   8.169 -        } else {
   8.170 -            colorkey = surface->format->colorkey;
   8.171 -            SDL_SetColorKey(surface, 0, 0);
   8.172 -        }
   8.173 -    }
   8.174 -    if ((surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
   8.175 -        /* Copy over the alpha channel to RGBA if requested */
   8.176 -        if (format->Amask) {
   8.177 -            surface->flags &= ~SDL_SRCALPHA;
   8.178 -        } else {
   8.179 -            alpha = surface->format->alpha;
   8.180 -            SDL_SetAlpha(surface, 0, 0);
   8.181 -        }
   8.182 -    }
   8.183 -
   8.184 -    /* Copy over the image data */
   8.185 -    bounds.x = 0;
   8.186 -    bounds.y = 0;
   8.187 -    bounds.w = surface->w;
   8.188 -    bounds.h = surface->h;
   8.189 -    glSDL_SoftBlit(surface, &bounds, convert, &bounds);
   8.190 -
   8.191 -    /* Clean up the original surface, and update converted surface */
   8.192 -    if (convert != NULL) {
   8.193 -        SDL_SetClipRect(convert, &surface->clip_rect);
   8.194 -    }
   8.195 -    if ((surface_flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
   8.196 -        Uint32 cflags = surface_flags & (SDL_SRCCOLORKEY | SDL_RLEACCELOK);
   8.197 -        if (convert != NULL) {
   8.198 -            Uint8 keyR, keyG, keyB;
   8.199 -
   8.200 -            SDL_GetRGB(colorkey, surface->format, &keyR, &keyG, &keyB);
   8.201 -            SDL_SetColorKey(convert, cflags | (flags & SDL_RLEACCELOK),
   8.202 -                            SDL_MapRGB(convert->format, keyR, keyG, keyB));
   8.203 -        }
   8.204 -        SDL_SetColorKey(surface, cflags, colorkey);
   8.205 -    }
   8.206 -    if ((surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
   8.207 -        Uint32 aflags = surface_flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
   8.208 -        if (convert != NULL) {
   8.209 -            SDL_SetAlpha(convert, aflags | (flags & SDL_RLEACCELOK), alpha);
   8.210 -        }
   8.211 -        if (format->Amask) {
   8.212 -            surface->flags |= SDL_SRCALPHA;
   8.213 -        } else {
   8.214 -            SDL_SetAlpha(surface, aflags, alpha);
   8.215 -        }
   8.216 -    }
   8.217 -
   8.218 -    /* We're ready to go! */
   8.219 -    return (convert);
   8.220 -}
   8.221 -
   8.222 -
   8.223 -/*----------------------------------------------------------
   8.224 -  Some OpenGL function wrappers
   8.225 -  ----------------------------------------------------------*/
   8.226 -
   8.227 -static struct
   8.228 -{
   8.229 -    int do_blend;
   8.230 -    int do_texture;
   8.231 -    GLuint texture;
   8.232 -    GLenum sfactor, dfactor;
   8.233 -} glstate;
   8.234 -
   8.235 -static void
   8.236 -glSDL_reset(void)
   8.237 -{
   8.238 -    glstate.do_blend = -1;
   8.239 -    glstate.do_blend = -1;
   8.240 -    glstate.texture = GLSDL_NOTEX;
   8.241 -    glstate.sfactor = 0xffffffff;
   8.242 -    glstate.dfactor = 0xffffffff;
   8.243 -}
   8.244 -
   8.245 -static __inline__ void
   8.246 -glSDL_do_blend(_THIS, int on)
   8.247 -{
   8.248 -    if (glstate.do_blend == on)
   8.249 -        return;
   8.250 -
   8.251 -    if (on)
   8.252 -        this->glEnable(GL_BLEND);
   8.253 -    else
   8.254 -        this->glDisable(GL_BLEND);
   8.255 -    glstate.do_blend = on;
   8.256 -}
   8.257 -
   8.258 -static __inline__ void
   8.259 -glSDL_do_texture(_THIS, int on)
   8.260 -{
   8.261 -    if (glstate.do_texture == on)
   8.262 -        return;
   8.263 -
   8.264 -    if (on)
   8.265 -        this->glEnable(GL_TEXTURE_2D);
   8.266 -    else
   8.267 -        this->glDisable(GL_TEXTURE_2D);
   8.268 -    glstate.do_texture = on;
   8.269 -}
   8.270 -
   8.271 -static __inline__ void
   8.272 -glSDL_blendfunc(_THIS, GLenum sfactor, GLenum dfactor)
   8.273 -{
   8.274 -    if ((sfactor == glstate.sfactor) && (dfactor == glstate.dfactor))
   8.275 -        return;
   8.276 -
   8.277 -    this->glBlendFunc(sfactor, dfactor);
   8.278 -
   8.279 -    glstate.sfactor = sfactor;
   8.280 -    glstate.dfactor = dfactor;
   8.281 -}
   8.282 -
   8.283 -static __inline__ void
   8.284 -glSDL_texture(_THIS, GLuint tx)
   8.285 -{
   8.286 -    if (tx == glstate.texture)
   8.287 -        return;
   8.288 -
   8.289 -    this->glBindTexture(GL_TEXTURE_2D, tx);
   8.290 -    glstate.texture = tx;
   8.291 -}
   8.292 -
   8.293 -
   8.294 -
   8.295 -
   8.296 -/*----------------------------------------------------------
   8.297 -  glSDL specific data types
   8.298 -  ----------------------------------------------------------*/
   8.299 -
   8.300 -typedef enum
   8.301 -{
   8.302 -    GLSDL_TM_SINGLE,
   8.303 -    GLSDL_TM_HORIZONTAL,
   8.304 -    GLSDL_TM_VERTICAL,
   8.305 -    GLSDL_TM_HUGE
   8.306 -} GLSDL_TileModes;
   8.307 -
   8.308 -
   8.309 -typedef struct private_hwdata
   8.310 -{
   8.311 -    /* Size of surface in logic screen pixels */
   8.312 -    int lw, lh;
   8.313 -
   8.314 -    int textures;
   8.315 -    GLuint *texture;
   8.316 -    int texsize;                /* width/height of OpenGL texture */
   8.317 -    GLSDL_TileModes tilemode;
   8.318 -    int tilew, tileh;           /* At least one must equal texsize! */
   8.319 -    int tilespertex;
   8.320 -    SDL_Rect virt;              /* Total size of assembled surface */
   8.321 -
   8.322 -    /* Area of surface to upload when/after unlocking */
   8.323 -    SDL_Rect invalid_area;
   8.324 -
   8.325 -    int temporary;              /* Throw away after one use. */
   8.326 -
   8.327 -    SDL_Surface *next;          /* The next Surface in our linked list of hardware surfaces ; == NULL if first surface */
   8.328 -    SDL_Surface *prev;          /* The prev Surface in our linked list of hardware surfaces ; == NULL if last surface */
   8.329 -} private_hwdata;
   8.330 -
   8.331 -/* some function prototypes */
   8.332 -static void glSDL_Invalidate(SDL_Surface * surface, SDL_Rect * area);
   8.333 -static void glSDL_SetLogicSize(_THIS, SDL_Surface * surface, int w, int h);
   8.334 -static private_hwdata *glSDL_UploadSurface(_THIS, SDL_Surface * surface);
   8.335 -static private_hwdata *glSDL_GetTexInfo(SDL_Surface * surface);
   8.336 -static void glSDL_init_formats(_THIS);
   8.337 -static private_hwdata *glSDL_AddTexInfo(_THIS, SDL_Surface * surface);
   8.338 -static void glSDL_RemoveTexInfo(_THIS, SDL_Surface * surface);
   8.339 -static void glSDL_UnloadTexture(_THIS, private_hwdata * txi);
   8.340 -static int glSDL_BlitGL(_THIS, SDL_Surface * src,
   8.341 -                        SDL_Rect * srcrect, SDL_Rect * dstrect);
   8.342 -
   8.343 -/* some variables */
   8.344 -static GLint maxtexsize = -1;
   8.345 -static SDL_PixelFormat *RGBfmt = NULL;
   8.346 -static SDL_PixelFormat *RGBAfmt = NULL;
   8.347 -static void *mirrorbuf = NULL;
   8.348 -/* the raw 888 opengl surface, hidden from the application */
   8.349 -SDL_Surface *OpenGL_Surface;
   8.350 -
   8.351 -/* pointer to the beggining of the list used for memory allocation */
   8.352 -SDL_Surface *first = NULL;
   8.353 -
   8.354 -#ifdef DEBUG_GLSDL
   8.355 -static __inline__ int
   8.356 -GLERET(const char *txt)
   8.357 -{
   8.358 -    fprintf(stderr, "glSDL ERROR: '%s'\n", txt);
   8.359 -    return -1;
   8.360 -}
   8.361 -static __inline__ void
   8.362 -GLERR(const char *txt)
   8.363 -{
   8.364 -    fprintf(stderr, "glSDL ERROR: '%s'\n", txt);
   8.365 -}
   8.366 -#else
   8.367 -#define	GLERET(x)	(-1)
   8.368 -#define	GLERR(x)
   8.369 -#endif
   8.370 -
   8.371 -static SDL_VideoDevice underlying_device;
   8.372 -static int old_screen_flags;
   8.373 -
   8.374 -/* 
   8.375 - * List of video drivers known to support OpenGL 
   8.376 - * The purpose of this is to make glSDL "portable" across
   8.377 - * all video backends that support OpenGL
   8.378 - */
   8.379 -static VideoBootStrap *opengl_bootstrap =
   8.380 -#if SDL_VIDEO_DRIVER_QUARTZ
   8.381 -    &QZ_bootstrap;
   8.382 -#elif SDL_VIDEO_DRIVER_X11
   8.383 -    &X11_bootstrap;
   8.384 -#elif SDL_VIDEO_DRIVER_WINDIB
   8.385 -    &WINDIB_bootstrap;
   8.386 -#elif SDL_VIDEO_DRIVER_BWINDOW
   8.387 -    &BWINDOW_bootstrap;
   8.388 -#elif SDL_VIDEO_DRIVER_TOOLBOX
   8.389 -    &TOOLBOX_bootstrap;
   8.390 -#elif SDL_VIDEO_DRIVER_CYBERGRAPHICS
   8.391 -    &CGX_bootstrap;
   8.392 -#elif SDL_VIDEO_DRIVER_PHOTON
   8.393 -    &ph_bootstrap;
   8.394 -#elif SDL_VIDEO_DRIVER_DC
   8.395 -    &DC_bootstrap;
   8.396 -#else
   8.397 -    NULL;
   8.398 -#endif
   8.399 -
   8.400 -static int
   8.401 -glSDL_Available(void)
   8.402 -{
   8.403 -#ifdef DEBUG_GLSDL
   8.404 -    fprintf(stderr, "available\n");
   8.405 -#endif
   8.406 -    if (opengl_bootstrap == NULL)
   8.407 -        return 0;
   8.408 -    return (opengl_bootstrap->available());
   8.409 -}
   8.410 -
   8.411 -static void
   8.412 -glSDL_DeleteDevice(SDL_VideoDevice * device)
   8.413 -{
   8.414 -    SDL_free(device->hidden);
   8.415 -    SDL_free(device);
   8.416 -}
   8.417 -
   8.418 -/* Create a glSDL device */
   8.419 -static SDL_VideoDevice *
   8.420 -glSDL_CreateDevice(int devindex)
   8.421 -{
   8.422 -    SDL_VideoDevice *device;
   8.423 -#ifdef DEBUG_GLSDL
   8.424 -    fprintf(stderr, "entering createdevice\n");
   8.425 -#endif
   8.426 -
   8.427 -    /* Create the device with the underlying driver */
   8.428 -    device = opengl_bootstrap->create(devindex);
   8.429 -
   8.430 -    /* Save the video device contents for future use */
   8.431 -    SDL_memcpy(&underlying_device, device, sizeof(SDL_VideoDevice));
   8.432 -
   8.433 -    /* Hook glSDL on the video device */
   8.434 -    device->VideoInit = glSDL_VideoInit;
   8.435 -    device->ListModes = glSDL_ListModes;
   8.436 -    device->VideoQuit = glSDL_VideoQuit;
   8.437 -    device->UpdateRects = glSDL_UpdateRects;
   8.438 -    device->FillHWRect = glSDL_FillHWRect;
   8.439 -    device->SetHWColorKey = glSDL_SetHWColorKey;
   8.440 -    device->SetHWAlpha = glSDL_SetHWAlpha;
   8.441 -    device->AllocHWSurface = glSDL_AllocHWSurface;
   8.442 -    device->LockHWSurface = glSDL_LockHWSurface;
   8.443 -    device->UnlockHWSurface = glSDL_UnlockHWSurface;
   8.444 -    device->FlipHWSurface = glSDL_FlipHWSurface;
   8.445 -    device->FreeHWSurface = glSDL_FreeHWSurface;
   8.446 -    device->CheckHWBlit = glSDL_CheckHWBlit;
   8.447 -    device->SetColors = glSDL_SetColors;
   8.448 -    device->SetVideoMode = glSDL_SetVideoMode;
   8.449 -    device->info.hw_available = 1;
   8.450 -    device->info.blit_hw = 1;
   8.451 -    device->info.blit_hw_CC = 1;
   8.452 -    device->info.blit_hw_A = 1;
   8.453 -    device->info.blit_sw = 1;
   8.454 -    device->info.blit_sw_CC = 1;
   8.455 -    device->info.blit_sw_A = 1;
   8.456 -    device->info.blit_fill = 1;
   8.457 -
   8.458 -    /* These functions are not supported by glSDL, so we NULLify them */
   8.459 -    device->SetGamma = NULL;
   8.460 -    device->GetGamma = NULL;
   8.461 -    device->SetGammaRamp = NULL;
   8.462 -    device->GetGammaRamp = NULL;
   8.463 -    device->ToggleFullScreen = NULL;
   8.464 -
   8.465 -    device->free = glSDL_DeleteDevice;
   8.466 -
   8.467 -#ifdef DEBUG_GLSDL
   8.468 -    fprintf(stderr, "leaving createdevice\n");
   8.469 -#endif
   8.470 -
   8.471 -    return device;
   8.472 -}
   8.473 -
   8.474 -/* Our bootstraping structure */
   8.475 -VideoBootStrap glSDL_bootstrap = {
   8.476 -    "glSDL", "glSDL - SDL over OpenGL",
   8.477 -    glSDL_Available, glSDL_CreateDevice
   8.478 -};
   8.479 -
   8.480 -static int
   8.481 -glSDL_VideoInit(_THIS, SDL_PixelFormat * vformat)
   8.482 -{
   8.483 -    int r;
   8.484 -    printf("glSDL videoinit\n");
   8.485 -#ifdef DEBUG_GLSDL
   8.486 -    fprintf(stderr, "videoinit\n");
   8.487 -#endif
   8.488 -    r = underlying_device.VideoInit(this, vformat);
   8.489 -    this->info.hw_available = 1;
   8.490 -    this->info.blit_hw = 1;
   8.491 -    this->info.blit_hw_CC = 1;
   8.492 -    this->info.blit_hw_A = 1;
   8.493 -    this->info.blit_sw = 1;
   8.494 -    this->info.blit_sw_CC = 1;
   8.495 -    this->info.blit_sw_A = 1;
   8.496 -    this->info.blit_fill = 1;
   8.497 -
   8.498 -    return r;
   8.499 -}
   8.500 -
   8.501 -SDL_Rect **
   8.502 -glSDL_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
   8.503 -{
   8.504 -    return ((SDL_Rect **) - 1);
   8.505 -}
   8.506 -
   8.507 -static void
   8.508 -glSDL_VideoQuit(_THIS)
   8.509 -{
   8.510 -    SDL_Surface *scr;
   8.511 -
   8.512 -    /* free all hwdata structures */
   8.513 -    while (first != NULL)
   8.514 -        glSDL_RemoveTexInfo(this, first);
   8.515 -
   8.516 -    SDL_free(mirrorbuf);
   8.517 -    mirrorbuf = NULL;
   8.518 -
   8.519 -    SDL_FreeFormat(RGBfmt);
   8.520 -    SDL_FreeFormat(RGBAfmt);
   8.521 -    RGBfmt = RGBAfmt = NULL;
   8.522 -
   8.523 -    SDL_FreeFormat(this->displayformatalphapixel);
   8.524 -    this->displayformatalphapixel = NULL;
   8.525 -
   8.526 -    SDL_FreeSurface(OpenGL_Surface);
   8.527 -    OpenGL_Surface = NULL;
   8.528 -
   8.529 -    /* restore the flags to gracefully exit from fullscreen */
   8.530 -    this->screen->flags = old_screen_flags;
   8.531 -
   8.532 -    /* keep the screen */
   8.533 -    scr = this->screen;
   8.534 -
   8.535 -    /* we cleaned up our stuff, now restore the underlying video driver */
   8.536 -    SDL_memcpy(this, &underlying_device, sizeof(SDL_VideoDevice));
   8.537 -
   8.538 -    this->screen = scr;
   8.539 -
   8.540 -    /* call the underlying video driver's VideoQuit function */
   8.541 -    this->VideoQuit(this);
   8.542 -}
   8.543 -
   8.544 -static SDL_Surface *
   8.545 -glSDL_SetVideoMode(_THIS, SDL_Surface * current, int width, int height,
   8.546 -                   int bpp, Uint32 flags)
   8.547 -{
   8.548 -    SDL_Surface *hooked_screen;
   8.549 -    int i;
   8.550 -    int flag_doublebuf = 0;
   8.551 -
   8.552 -    if (opengl_bootstrap == NULL) {
   8.553 -        GLERR("No bootstrap for glSDL compiled in !\n");
   8.554 -        return NULL;
   8.555 -    }
   8.556 -
   8.557 -    /* we don't have OpenGL */
   8.558 -    if ((flags & SDL_INTERNALOPENGL) == SDL_INTERNALOPENGL) {
   8.559 -        GLERR("OpenGL video modes are not supported by glSDL !\n");
   8.560 -        return (NULL);
   8.561 -    }
   8.562 -
   8.563 -    /* 
   8.564 -     * Adjust the flags
   8.565 -     */
   8.566 -    flags &= ~SDL_HWPALETTE;
   8.567 -    flags |= SDL_INTERNALOPENGL;
   8.568 -
   8.569 -    /* remember whether the user requested DOUBLEBUF */
   8.570 -
   8.571 -    if (flags & SDL_DOUBLEBUF) {
   8.572 -        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
   8.573 -        flag_doublebuf = 1;
   8.574 -    } else {
   8.575 -        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
   8.576 -        flag_doublebuf = 0;
   8.577 -    }
   8.578 -
   8.579 -    hooked_screen =
   8.580 -        underlying_device.SetVideoMode(this, current, width, height, 0,
   8.581 -                                       flags);
   8.582 -
   8.583 -    if (!hooked_screen) {
   8.584 -        GLERR("Unable to open an OpenGL window !\n");
   8.585 -        return (NULL);
   8.586 -    }
   8.587 -
   8.588 -    /* save the screen flags for restore time */
   8.589 -    old_screen_flags = hooked_screen->flags;
   8.590 -
   8.591 -#ifdef DEBUG_GLSDL
   8.592 -    fprintf(stderr, "got %d bpp\n", bpp);
   8.593 -#endif
   8.594 -
   8.595 -    /* setup the public surface format
   8.596 -     * glSDL always returns the bpp its asked
   8.597 -     */
   8.598 -    switch (bpp) {
   8.599 -    case 32:
   8.600 -        this->is_32bit = 1;
   8.601 -        this->screen = SDL_CreateRGBSurface(flags, width, height, bpp,
   8.602 -#if SDL_BYTEORDER == SDL_LIL_ENDIAN
   8.603 -                                            0x00FF0000,
   8.604 -                                            0x0000FF00, 0x000000FF, 0x00000000
   8.605 -#else
   8.606 -                                            0x0000FF00,
   8.607 -                                            0x00FF0000, 0xFF000000, 0x00000000
   8.608 -#endif
   8.609 -            );
   8.610 -        break;
   8.611 -    case 24:
   8.612 -        this->is_32bit = 0;
   8.613 -        this->screen = SDL_CreateRGBSurface(flags, width, height, bpp,
   8.614 -#if SDL_BYTEORDER == SDL_LIL_ENDIAN
   8.615 -                                            0x00FF0000,
   8.616 -                                            0x0000FF00, 0x000000FF, 0x00000000
   8.617 -#else
   8.618 -                                            0x0000FF00,
   8.619 -                                            0x00FF0000, 0xFF000000, 0x00000000
   8.620 -#endif
   8.621 -            );
   8.622 -        break;
   8.623 -    case 16:
   8.624 -        this->is_32bit = 0;
   8.625 -        this->screen = SDL_CreateRGBSurface(flags, width, height, bpp,
   8.626 -#if SDL_BYTEORDER == SDL_LIL_ENDIAN
   8.627 -                                            0x0000F800,
   8.628 -                                            0x000007E0, 0x0000001F, 0x00000000
   8.629 -#else
   8.630 -                                            0x0000001F,
   8.631 -                                            0x000007E0, 0x0000F800, 0x00000000
   8.632 -#endif
   8.633 -            );
   8.634 -        break;
   8.635 -    case 15:
   8.636 -        this->is_32bit = 0;
   8.637 -        this->screen = SDL_CreateRGBSurface(flags, width, height, bpp,
   8.638 -#if SDL_BYTEORDER == SDL_LIL_ENDIAN
   8.639 -                                            0x00007C00,
   8.640 -                                            0x000003E0, 0x0000001F, 0x00000000
   8.641 -#else
   8.642 -                                            0x0000001F,
   8.643 -                                            0x000003E0, 0x00007C00, 0x00000000
   8.644 -#endif
   8.645 -            );
   8.646 -        break;
   8.647 -    case 8:
   8.648 -    default:
   8.649 -        this->is_32bit = 0;
   8.650 -        this->screen =
   8.651 -            SDL_CreateRGBSurface(flags, width, height, bpp, 0, 0, 0, 0);
   8.652 -        /* give it a default palette if 8 bpp
   8.653 -         * note : SDL already takes care of the palette for 4 bits & 1 bit surfaces 
   8.654 -         */
   8.655 -/*			if (bpp==8)
   8.656 -			{
   8.657 -				this->screen->format->palette->ncolors=255;
   8.658 -				SDL_DitherColors(this->screen->format->palette->colors,bpp);
   8.659 -			}*/
   8.660 -        break;
   8.661 -    }
   8.662 -
   8.663 -    /* also, we add SDL_HWSURFACE all the time, and let SDL create a shadow surface accordingly */
   8.664 -    this->screen->flags =
   8.665 -        hooked_screen->flags | SDL_HWSURFACE | SDL_INTERNALOPENGL;
   8.666 -    /* add SDL_DOUBLEBUF if it was requested */
   8.667 -    if (flag_doublebuf)
   8.668 -        this->screen->flags |= SDL_DOUBLEBUF;
   8.669 -
   8.670 -    /* Tell SDL the alpha pixel format we'd like to have */
   8.671 -    this->displayformatalphapixel = SDL_AllocFormat(32,
   8.672 -#if SDL_BYTEORDER == SDL_BIG_ENDIAN
   8.673 -                                                    0xFF000000,
   8.674 -                                                    0x00FF0000,
   8.675 -                                                    0x0000FF00, 0x000000FF
   8.676 -#else
   8.677 -                                                    0x000000FF,
   8.678 -                                                    0x0000FF00,
   8.679 -                                                    0x00FF0000, 0xFF000000
   8.680 -#endif
   8.681 -        );
   8.682 -
   8.683 -    /* Now create the raw OpenGL surface */
   8.684 -    OpenGL_Surface = SDL_CreateRGBSurface(flags, width, height, 24,
   8.685 -#if SDL_BYTEORDER == SDL_LIL_ENDIAN
   8.686 -                                          0x000000FF,
   8.687 -                                          0x0000FF00, 0x00FF0000, 0x00000000
   8.688 -#else
   8.689 -                                          0xFF000000,
   8.690 -                                          0x00FF0000, 0x0000FF00, 0x00000000
   8.691 -#endif
   8.692 -        );
   8.693 -
   8.694 -    /* Here we have to setup OpenGL funcs ourselves */
   8.695 -#ifndef __QNXNTO__
   8.696 -#define SDL_PROC(ret,func,params) \
   8.697 -	do { \
   8.698 -		this->func = SDL_GL_GetProcAddress(#func); \
   8.699 -			if ( ! this->func ) { \
   8.700 -				SDL_SetError("Couldn't load GL function: %s\n", #func); \
   8.701 -					return(NULL); \
   8.702 -			} \
   8.703 -	} while ( 0 );
   8.704 -#else
   8.705 -#define SDL_PROC(ret,func,params) this->func=func;
   8.706 -#endif /* __QNXNTO__ */
   8.707 -#include "../SDL_glfuncs.h"
   8.708 -#undef SDL_PROC
   8.709 -
   8.710 -    if (this->GL_MakeCurrent(this) < 0)
   8.711 -        return (NULL);
   8.712 -#define SDL_PROC(ret,func,params) \
   8.713 -	do { \
   8.714 -		this->func = SDL_GL_GetProcAddress(#func); \
   8.715 -			if ( ! this->func ) { \
   8.716 -				SDL_SetError("Couldn't load GL function: %s\n", #func); \
   8.717 -					return(NULL); \
   8.718 -			} \
   8.719 -	} while ( 0 );
   8.720 -#include "../SDL_glfuncs.h"
   8.721 -#undef SDL_PROC
   8.722 -
   8.723 -
   8.724 -#ifdef	FAKE_MAXTEXSIZE
   8.725 -    maxtexsize = FAKE_MAXTEXSIZE;
   8.726 -#else
   8.727 -    this->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxtexsize);
   8.728 -#endif
   8.729 -#ifdef DEBUG_GLSDL
   8.730 -    fprintf(stderr, "glSDL: Max texture size: %d\n", maxtexsize);
   8.731 -#endif
   8.732 -
   8.733 -    glSDL_init_formats(this);
   8.734 -
   8.735 -    if (flag_doublebuf)
   8.736 -        this->glDrawBuffer(GL_BACK);
   8.737 -    else
   8.738 -        this->glDrawBuffer(GL_FRONT);
   8.739 -
   8.740 -    this->glDisable(GL_DITHER);
   8.741 -
   8.742 -    if (glSDL_AddTexInfo(this, this->screen) < 0) {
   8.743 -        GLERR("HookDevice() failed to add info to screen surface!");
   8.744 -        return NULL;
   8.745 -    }
   8.746 -
   8.747 -    glSDL_SetLogicSize(this, this->screen, this->screen->w, this->screen->h);
   8.748 -
   8.749 -    glSDL_do_texture(this, 0);
   8.750 -    glSDL_do_blend(this, 0);
   8.751 -
   8.752 -    for (i = 0; i < 1 + flag_doublebuf; ++i) {
   8.753 -        this->glBegin(GL_TRIANGLE_FAN);
   8.754 -        this->glColor3ub(0, 0, 0);
   8.755 -        this->glVertex2i(0, 0);
   8.756 -        this->glVertex2i(this->screen->w, 0);
   8.757 -        this->glVertex2i(this->screen->w, this->screen->h);
   8.758 -        this->glVertex2i(0, this->screen->h);
   8.759 -        this->glEnd();
   8.760 -        if (!i)
   8.761 -            this->GL_SwapBuffers(this);
   8.762 -    }
   8.763 -
   8.764 -    mirrorbuf = SDL_malloc(this->screen->h * this->screen->pitch);
   8.765 -    if (!mirrorbuf) {
   8.766 -        GLERR("HookDevice() failed to allocate temp buffer for mirroring!");
   8.767 -        return NULL;
   8.768 -    }
   8.769 -
   8.770 -    return this->screen;
   8.771 -}
   8.772 -
   8.773 -static int
   8.774 -glSDL_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
   8.775 -{
   8.776 -    /* We don't need to fill this one */
   8.777 -    return 0;
   8.778 -}
   8.779 -
   8.780 -
   8.781 -#ifdef DEBUG_GLSDL
   8.782 -static void
   8.783 -glSDL_print_glerror(_THIS, int point)
   8.784 -{
   8.785 -    const char *err = "<unknown>";
   8.786 -    switch (this->glGetError()) {
   8.787 -    case GL_NO_ERROR:
   8.788 -        return;
   8.789 -    case GL_INVALID_ENUM:
   8.790 -        err = "GL_INVALID_ENUM";
   8.791 -        break;
   8.792 -    case GL_INVALID_VALUE:
   8.793 -        err = "GL_INVALID_VALUE";
   8.794 -        break;
   8.795 -    case GL_INVALID_OPERATION:
   8.796 -        err = "GL_INVALID_OPERATION";
   8.797 -        break;
   8.798 -    case GL_STACK_OVERFLOW:
   8.799 -        err = "GL_STACK_OVERFLOW";
   8.800 -        break;
   8.801 -    case GL_STACK_UNDERFLOW:
   8.802 -        err = "GL_STACK_UNDERFLOW";
   8.803 -        break;
   8.804 -    case GL_OUT_OF_MEMORY:
   8.805 -        err = "GL_OUT_OF_MEMORY";
   8.806 -    default:
   8.807 -        break;
   8.808 -    }
   8.809 -    fprintf(stderr, "OpenGL error \"%s\" at point %d.\n", err, point);
   8.810 -}
   8.811 -#endif
   8.812 -
   8.813 -/* Get texinfo for a surface. */
   8.814 -static __inline__ private_hwdata *
   8.815 -glSDL_GetTexInfo(SDL_Surface * surface)
   8.816 -{
   8.817 -    if (!surface)
   8.818 -        return NULL;
   8.819 -    return surface->hwdata;
   8.820 -}
   8.821 -
   8.822 -
   8.823 -/* Allocate a "blank" texinfo for a suface. */
   8.824 -static private_hwdata *
   8.825 -glSDL_AllocTexInfo(SDL_Surface * surface)
   8.826 -{
   8.827 -    private_hwdata *txi;
   8.828 -    if (!surface)
   8.829 -        return NULL;
   8.830 -
   8.831 -    txi = glSDL_GetTexInfo(surface);
   8.832 -    if (txi)
   8.833 -        return txi;             /* There already is one! --> */
   8.834 -
   8.835 -    /* ...and hook a new texinfo struct up to it. */
   8.836 -    txi = (private_hwdata *) SDL_calloc(1, sizeof(private_hwdata));
   8.837 -    if (!txi) {
   8.838 -        GLERR("AllocTexInfo(): Failed allocating TexInfo struct!");
   8.839 -        return NULL;
   8.840 -    }
   8.841 -    txi->temporary = 1;
   8.842 -#ifdef DEBUG_GLSDL
   8.843 -    fprintf(stderr, "glSDL: Allocated TexInfo %p.\n", txi);
   8.844 -#endif
   8.845 -    return txi;
   8.846 -}
   8.847 -
   8.848 -
   8.849 -static void
   8.850 -glSDL_FreeTexInfo(_THIS, private_hwdata * txi)
   8.851 -{
   8.852 -    if (!txi)
   8.853 -        return;
   8.854 -
   8.855 -    glSDL_UnloadTexture(this, txi);
   8.856 -    SDL_free(txi->texture);
   8.857 -    SDL_free(txi);
   8.858 -#ifdef DEBUG_GLSDL
   8.859 -    fprintf(stderr, "glSDL: Freed TexInfo %p.\n", txi);
   8.860 -#endif
   8.861 -}
   8.862 -
   8.863 -
   8.864 -/* Detach and free the texinfo of a surface. */
   8.865 -static void
   8.866 -glSDL_RemoveTexInfo(_THIS, SDL_Surface * surface)
   8.867 -{
   8.868 -    SDL_Surface *next, *prev;
   8.869 -    if (!glSDL_GetTexInfo(surface))
   8.870 -        return;
   8.871 -
   8.872 -    /* maintain our doubly linked list */
   8.873 -    next = surface->hwdata->next;
   8.874 -    prev = surface->hwdata->prev;
   8.875 -    if (prev != NULL) {
   8.876 -        prev->hwdata->next = next;
   8.877 -    } else {
   8.878 -        first = next;
   8.879 -    }
   8.880 -    if (next != NULL) {
   8.881 -        next->hwdata->prev = prev;
   8.882 -    }
   8.883 -
   8.884 -    glSDL_FreeTexInfo(this, surface->hwdata);
   8.885 -    surface->hwdata = NULL;
   8.886 -}
   8.887 -
   8.888 -
   8.889 -/*
   8.890 - * Calculate chopping/tiling of a surface to
   8.891 - * fit it into the smallest possible OpenGL
   8.892 - * texture.
   8.893 - */
   8.894 -static int
   8.895 -glSDL_CalcChop(private_hwdata * txi)
   8.896 -{
   8.897 -    int rows, vw, vh;
   8.898 -    int vertical = 0;
   8.899 -    int texsize;
   8.900 -    int lastw, lasth, minsize;
   8.901 -
   8.902 -    vw = txi->virt.w;
   8.903 -    vh = txi->virt.h;
   8.904 -
   8.905 -#ifdef DEBUG_GLSDL_CHOP
   8.906 -    fprintf(stderr, "w=%d, h=%d ", vw, vh);
   8.907 -#endif
   8.908 -    if (vh > vw) {
   8.909 -        int t = vw;
   8.910 -        vw = vh;
   8.911 -        vh = t;
   8.912 -        vertical = 1;
   8.913 -#ifdef DEBUG_GLSDL_CHOP
   8.914 -        fprintf(stderr, "(vertical) \t");
   8.915 -#endif
   8.916 -    }
   8.917 -
   8.918 -    /*
   8.919 -     * Check whether this is a "huge" surface - at least one dimension
   8.920 -     * must be <= than the maximum texture size, or we'll have to chop
   8.921 -     * in both directions.
   8.922 -     */
   8.923 -#ifdef DEBUG_GLSDL
   8.924 -    if (maxtexsize < 0)
   8.925 -        return GLERET("glSDL_CalcChop() called before OpenGL init!");
   8.926 -#endif
   8.927 -    if (vh > maxtexsize) {
   8.928 -        /*
   8.929 -         * Very simple hack for now; we just tile
   8.930 -         * both ways with maximum size textures.
   8.931 -         */
   8.932 -        texsize = maxtexsize;
   8.933 -
   8.934 -        txi->tilemode = GLSDL_TM_HUGE;
   8.935 -        txi->texsize = texsize;
   8.936 -        txi->tilew = texsize;
   8.937 -        txi->tileh = texsize;
   8.938 -        txi->tilespertex = 1;
   8.939 -
   8.940 -        /* Calculate number of textures needed */
   8.941 -        txi->textures = (vw + texsize - 1) / texsize;
   8.942 -        txi->textures *= (vh + texsize - 1) / texsize;
   8.943 -        txi->texture = SDL_malloc(txi->textures * sizeof(int));
   8.944 -        SDL_memset(txi->texture, -1, txi->textures * sizeof(int));
   8.945 -#ifdef DEBUG_GLSDL
   8.946 -        fprintf(stderr, "two-way tiling; textures=%d\n", txi->textures);
   8.947 -#endif
   8.948 -        if (!txi->texture) {
   8.949 -            fprintf(stderr, "glSDL: INTERNAL ERROR: Failed to allocate"
   8.950 -                    " texture name table!\n");
   8.951 -            return -3;
   8.952 -        }
   8.953 -        return 0;
   8.954 -    }
   8.955 -
   8.956 -    /* Calculate minimum size */
   8.957 -    rows = 1;
   8.958 -    lastw = vw;
   8.959 -    lasth = vh;
   8.960 -    minsize = lastw > lasth ? lastw : lasth;
   8.961 -    while (1) {
   8.962 -        int w, h, size;
   8.963 -        ++rows;
   8.964 -        w = vw / rows;
   8.965 -        h = rows * vh;
   8.966 -        size = w > h ? w : h;
   8.967 -        if (size >= minsize) {
   8.968 -            --rows;
   8.969 -            break;
   8.970 -        }
   8.971 -        lastw = w;
   8.972 -        lasth = h;
   8.973 -        minsize = size;
   8.974 -    }
   8.975 -    if (minsize > maxtexsize) {
   8.976 -        /* Handle multiple textures for very wide/tall surfaces. */
   8.977 -        minsize = maxtexsize;
   8.978 -        rows = (vw + minsize - 1) / minsize;
   8.979 -    }
   8.980 -#ifdef DEBUG_GLSDL_CHOP
   8.981 -    fprintf(stderr, "==> minsize=%d ", minsize);
   8.982 -    fprintf(stderr, "(rows=%d) \t", rows);
   8.983 -#endif
   8.984 -
   8.985 -    /* Recalculate with nearest higher power-of-2 width. */
   8.986 -    for (texsize = 1; texsize < minsize; texsize <<= 1);
   8.987 -    txi->texsize = texsize;
   8.988 -    rows = (vw + texsize - 1) / texsize;
   8.989 -#ifdef DEBUG_GLSDL_CHOP
   8.990 -    fprintf(stderr, "==> texsize=%d (rows=%d) \t", texsize, rows);
   8.991 -#endif
   8.992 -
   8.993 -    /* Calculate number of tiles per texture */
   8.994 -    txi->tilespertex = txi->texsize / vh;
   8.995 -#ifdef DEBUG_GLSDL_CHOP
   8.996 -    fprintf(stderr, "tilespertex=%d \t", txi->tilespertex);
   8.997 -#endif
   8.998 -
   8.999 -    /* Calculate number of textures needed */
  8.1000 -    txi->textures = (rows + txi->tilespertex - 1) / txi->tilespertex;
  8.1001 -    txi->texture = (GLuint *) SDL_malloc(txi->textures * sizeof(GLuint));
  8.1002 -    SDL_memset(txi->texture, GLSDL_NOTEX, txi->textures * sizeof(GLuint));
  8.1003 -#ifdef DEBUG_GLSDL_CHOP
  8.1004 -    fprintf(stderr, "textures=%d, ", txi->textures);
  8.1005 -#endif
  8.1006 -    if (!txi->texture)
  8.1007 -        return GLERET("Failed to allocate texture name table!");
  8.1008 -
  8.1009 -    /* Set up tile size. (Only one axis supported here!) */
  8.1010 -    if (1 == rows) {
  8.1011 -        txi->tilemode = GLSDL_TM_SINGLE;
  8.1012 -        if (vertical) {
  8.1013 -            txi->tilew = vh;
  8.1014 -            txi->tileh = vw;
  8.1015 -        } else {
  8.1016 -            txi->tilew = vw;
  8.1017 -            txi->tileh = vh;
  8.1018 -        }
  8.1019 -    } else if (vertical) {
  8.1020 -        txi->tilemode = GLSDL_TM_VERTICAL;
  8.1021 -        txi->tilew = vh;
  8.1022 -        txi->tileh = texsize;
  8.1023 -    } else {
  8.1024 -        txi->tilemode = GLSDL_TM_HORIZONTAL;
  8.1025 -        txi->tilew = texsize;
  8.1026 -        txi->tileh = vh;
  8.1027 -    }
  8.1028 -
  8.1029 -#ifdef DEBUG_GLSDL_CHOP
  8.1030 -    fprintf(stderr, "tilew=%d, tileh=%d\n", txi->tilew, txi->tileh);
  8.1031 -#endif
  8.1032 -    return 0;
  8.1033 -}
  8.1034 -
  8.1035 -
  8.1036 -/* Create a temporary TexInfo struct for an SDL_Surface */
  8.1037 -static private_hwdata *
  8.1038 -glSDL_CreateTempTexInfo(_THIS, SDL_Surface * surface)
  8.1039 -{
  8.1040 -    private_hwdata *txi;
  8.1041 -    if (!surface) {
  8.1042 -        GLERR("CreateTempTexInfo(); no surface!");
  8.1043 -        return NULL;
  8.1044 -    }
  8.1045 -    if (IS_GLSDL_SURFACE(surface))
  8.1046 -        return glSDL_GetTexInfo(surface);       /* Do nothing */
  8.1047 -
  8.1048 -    txi = glSDL_AllocTexInfo(surface);
  8.1049 -    if (!txi) {
  8.1050 -        GLERR("CreateTempTexInfo(); Could not alloc TexInfo!");
  8.1051 -        return NULL;
  8.1052 -    }
  8.1053 -    txi->virt.w = txi->lw = surface->w;
  8.1054 -    txi->virt.h = txi->lh = surface->h;
  8.1055 -
  8.1056 -    if (glSDL_CalcChop(txi) < 0) {
  8.1057 -        glSDL_FreeTexInfo(this, txi);
  8.1058 -        GLERR("CreateTempTexInfo(); CalcChop() failed!");
  8.1059 -        return NULL;
  8.1060 -    }
  8.1061 -
  8.1062 -    return txi;
  8.1063 -}
  8.1064 -
  8.1065 -/* Add a glSDL_TexInfo struct to an SDL_Surface */
  8.1066 -static private_hwdata *
  8.1067 -glSDL_AddTexInfo(_THIS, SDL_Surface * surface)
  8.1068 -{
  8.1069 -    private_hwdata *txi = glSDL_CreateTempTexInfo(this, surface);
  8.1070 -    if (!txi)
  8.1071 -        return NULL;
  8.1072 -
  8.1073 -    /* Connect the surface to the new TexInfo. */
  8.1074 -    txi->temporary = 0;
  8.1075 -    surface->hwdata = txi;
  8.1076 -
  8.1077 -    /* add this new surface in front of the list of hw surfaces */
  8.1078 -    txi->next = first;
  8.1079 -    txi->prev = NULL;
  8.1080 -    first = surface;
  8.1081 -    if (txi->next != NULL) {
  8.1082 -        txi->next->hwdata->prev = surface;
  8.1083 -    }
  8.1084 -
  8.1085 -    SDL_SetClipRect(surface, &txi->virt);
  8.1086 -    return txi;
  8.1087 -}
  8.1088 -
  8.1089 -
  8.1090 -/* Create a surface of the prefered OpenGL RGB texture format */
  8.1091 -/*static SDL_Surface *glSDL_CreateRGBSurface(int w, int h)
  8.1092 -{
  8.1093 -	SDL_Surface *s;
  8.1094 -	Uint32 rmask, gmask, bmask;
  8.1095 -	int bits = 24;
  8.1096 -#if SDL_BYTEORDER == SDL_LIL_ENDIAN
  8.1097 -	rmask = 0x000000FF;
  8.1098 -	gmask = 0x0000FF00;
  8.1099 -	bmask = 0x00FF0000;
  8.1100 -#else
  8.1101 -	rmask = 0x00FF0000;
  8.1102 -	gmask = 0x0000FF00;
  8.1103 -	bmask = 0x000000FF;
  8.1104 -#endif
  8.1105 -	s = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h,
  8.1106 -			bits, rmask, gmask, bmask, 0);
  8.1107 -	if(s)
  8.1108 -		s->flags |= SDL_HWACCEL;
  8.1109 -
  8.1110 -	return s;
  8.1111 -}
  8.1112 -*/
  8.1113 -
  8.1114 -/* Create a surface of the prefered OpenGL RGBA texture format */
  8.1115 -static SDL_Surface *
  8.1116 -glSDL_CreateRGBASurface(int w, int h)
  8.1117 -{
  8.1118 -    SDL_Surface *s;
  8.1119 -    Uint32 rmask, gmask, bmask, amask;
  8.1120 -    int bits = 32;
  8.1121 -#if SDL_BYTEORDER == SDL_LIL_ENDIAN
  8.1122 -    rmask = 0x000000FF;
  8.1123 -    gmask = 0x0000FF00;
  8.1124 -    bmask = 0x00FF0000;
  8.1125 -    amask = 0xFF000000;
  8.1126 -#else
  8.1127 -    rmask = 0xFF000000;
  8.1128 -    gmask = 0x00FF0000;
  8.1129 -    bmask = 0x0000FF00;
  8.1130 -    amask = 0x000000FF;
  8.1131 -#endif
  8.1132 -    s = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h,
  8.1133 -                             bits, rmask, gmask, bmask, amask);
  8.1134 -    if (s)
  8.1135 -        s->flags |= SDL_HWACCEL;
  8.1136 -
  8.1137 -    return s;
  8.1138 -}
  8.1139 -
  8.1140 -
  8.1141 -static void
  8.1142 -glSDL_init_formats(_THIS)
  8.1143 -{
  8.1144 -    RGBfmt = SDL_AllocFormat(24,
  8.1145 -#if SDL_BYTEORDER == SDL_LIL_ENDIAN
  8.1146 -                             0x000000FF, 0x0000FF00, 0x00FF0000, 0);
  8.1147 -#else
  8.1148 -                             0x00FF0000, 0x0000FF00, 0x000000FF, 0);
  8.1149 -#endif
  8.1150 -    RGBAfmt = SDL_AllocFormat(32,
  8.1151 -#if SDL_BYTEORDER == SDL_LIL_ENDIAN
  8.1152 -                              0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
  8.1153 -#else
  8.1154 -                              0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
  8.1155 -#endif
  8.1156 -}
  8.1157 -
  8.1158 -
  8.1159 -static int
  8.1160 -glSDL_FormatIsOk(SDL_Surface * surface)
  8.1161 -{
  8.1162 -    SDL_PixelFormat *pf;
  8.1163 -    if (!surface)
  8.1164 -        return 1;               /* Well, there ain't much we can do anyway... */
  8.1165 -
  8.1166 -    pf = surface->format;
  8.1167 -
  8.1168 -    /* Colorkeying requires an alpha channel! */
  8.1169 -    if (surface->flags & SDL_SRCCOLORKEY)
  8.1170 -        if (!pf->Amask)
  8.1171 -            return 0;
  8.1172 -
  8.1173 -    /* We need pitch == (width * BytesPerPixel) for glTex[Sub]Image2D() */
  8.1174 -    if (surface->pitch != (surface->w * pf->BytesPerPixel))
  8.1175 -        return 0;
  8.1176 -
  8.1177 -    if (pf->Amask) {
  8.1178 -        if (pf->BytesPerPixel != RGBAfmt->BytesPerPixel)
  8.1179 -            return 0;
  8.1180 -        if (pf->Rmask != RGBAfmt->Rmask)
  8.1181 -            return 0;
  8.1182 -        if (pf->Gmask != RGBAfmt->Gmask)
  8.1183 -            return 0;
  8.1184 -        if (pf->Bmask != RGBAfmt->Bmask)
  8.1185 -            return 0;
  8.1186 -        if (pf->Amask != RGBAfmt->Amask)
  8.1187 -            return 0;
  8.1188 -    } else {
  8.1189 -        if (pf->BytesPerPixel != RGBfmt->BytesPerPixel)
  8.1190 -            return 0;
  8.1191 -        if (pf->Rmask != RGBfmt->Rmask)
  8.1192 -            return 0;
  8.1193 -        if (pf->Gmask != RGBfmt->Gmask)
  8.1194 -            return 0;
  8.1195 -        if (pf->Bmask != RGBfmt->Bmask)
  8.1196 -            return 0;
  8.1197 -    }
  8.1198 -    return 1;
  8.1199 -}
  8.1200 -
  8.1201 -static void
  8.1202 -glSDL_key2alpha(SDL_Surface * surface)
  8.1203 -{
  8.1204 -    int x, y;
  8.1205 -    Uint32 ckey = surface->format->colorkey;
  8.1206 -
  8.1207 -#ifdef DEBUG_GLSDL
  8.1208 -    fprintf(stderr, "glSDL_key2alpha()\n");
  8.1209 -#endif
  8.1210 -    for (y = 0; y < surface->h; ++y) {
  8.1211 -        Uint32 *px =
  8.1212 -            (Uint32 *) ((char *) surface->pixels + y * surface->pitch);
  8.1213 -        for (x = 0; x < surface->w; ++x)
  8.1214 -            if (px[x] == ckey)
  8.1215 -                px[x] = 0;
  8.1216 -    }
  8.1217 -}
  8.1218 -
  8.1219 -
  8.1220 -
  8.1221 -/*----------------------------------------------------------
  8.1222 -  SDL style API
  8.1223 -  ----------------------------------------------------------*/
  8.1224 -
  8.1225 -static int
  8.1226 -glSDL_FlipHWSurface(_THIS, SDL_Surface * surface)
  8.1227 -{
  8.1228 -#ifdef GLSDL_GRAPHICAL_DEBUG
  8.1229 -    this->glDisable(GL_TEXTURE_2D);
  8.1230 -    this->glBegin(GL_LINE_LOOP);
  8.1231 -    this->glColor4ub(0, 0, 255, 128);
  8.1232 -    this->glVertex2i(0, 0);
  8.1233 -    this->glVertex2i(surface->w, 0);
  8.1234 -    this->glVertex2i(surface->w, surface->h);
  8.1235 -    this->glVertex2i(0, surface->h);
  8.1236 -    this->glEnd();
  8.1237 -    this->glEnable(GL_TEXTURE_2D);
  8.1238 -#endif
  8.1239 -    if (this->screen->flags & SDL_DOUBLEBUF)
  8.1240 -        this->GL_SwapBuffers(this);
  8.1241 -    else
  8.1242 -        this->glFinish();
  8.1243 -    return 0;
  8.1244 -}
  8.1245 -
  8.1246 -
  8.1247 -static void
  8.1248 -glSDL_UpdateRects(_THIS, int numrects, SDL_Rect * rects)
  8.1249 -{
  8.1250 -#ifdef GLSDL_GRAPHICAL_DEBUG
  8.1251 -    int i;
  8.1252 -    this->glDisable(GL_TEXTURE_2D);
  8.1253 -    for (i = 0; i < numrects; i++) {
  8.1254 -        this->glColor4ub(255, 0, 0, 128);
  8.1255 -        this->glBegin(GL_LINE_LOOP);
  8.1256 -        this->glVertex2i(rects[i].x, rects[i].y);
  8.1257 -        this->glVertex2i(rects[i].x + rects[i].w, rects[i].y);
  8.1258 -        this->glVertex2i(rects[i].x + rects[i].w, rects[i].y + rects[i].h);
  8.1259 -        this->glVertex2i(rects[i].x, rects[i].y + rects[i].h);
  8.1260 -        this->glEnd();
  8.1261 -    }
  8.1262 -    this->glEnable(GL_TEXTURE_2D);
  8.1263 -#endif
  8.1264 -    if (this->screen->flags & SDL_DOUBLEBUF)
  8.1265 -        this->GL_SwapBuffers(this);
  8.1266 -    else
  8.1267 -        this->glFinish();
  8.1268 -}
  8.1269 -
  8.1270 -
  8.1271 -static int
  8.1272 -glSDL_AllocHWSurface(_THIS, SDL_Surface * surface)
  8.1273 -{
  8.1274 -    surface->flags |= (SDL_HWSURFACE | SDL_HWACCEL);
  8.1275 -
  8.1276 -    surface->pixels = SDL_malloc(surface->h * surface->pitch);
  8.1277 -    if (surface->pixels == NULL) {
  8.1278 -        SDL_FreeSurface(surface);
  8.1279 -        SDL_OutOfMemory();
  8.1280 -        return (-1);
  8.1281 -    }
  8.1282 -    SDL_memset(surface->pixels, 0, surface->h * surface->pitch);
  8.1283 -    return 0;
  8.1284 -}
  8.1285 -
  8.1286 -
  8.1287 -static void
  8.1288 -glSDL_FreeHWSurface(_THIS, SDL_Surface * surface)
  8.1289 -{
  8.1290 -    if (!surface)
  8.1291 -        return;
  8.1292 -    glSDL_RemoveTexInfo(this, surface);
  8.1293 -}
  8.1294 -
  8.1295 -
  8.1296 -static int
  8.1297 -glSDL_LockHWSurface(_THIS, SDL_Surface * surface)
  8.1298 -{
  8.1299 -    int y;
  8.1300 -
  8.1301 -    if (!surface)
  8.1302 -        return -1;
  8.1303 -
  8.1304 -#ifdef DEBUG_GLSDL
  8.1305 -    fprintf(stderr, "glSDL: Lock Surface.\n");
  8.1306 -#endif
  8.1307 -
  8.1308 -    if (SDL_VideoSurface == surface) {
  8.1309 -        glSDL_Invalidate(surface, NULL);
  8.1310 -        this->glPixelStorei(GL_UNPACK_ROW_LENGTH,
  8.1311 -                            surface->pitch / surface->format->BytesPerPixel);
  8.1312 -        this->glReadPixels(0, 0, OpenGL_Surface->w, OpenGL_Surface->h,
  8.1313 -                           GL_RGB, GL_UNSIGNED_BYTE, OpenGL_Surface->pixels);
  8.1314 -        for (y = 0; y < OpenGL_Surface->h / 2; ++y) {
  8.1315 -            void *upper = (Uint8 *) OpenGL_Surface->pixels +
  8.1316 -                OpenGL_Surface->pitch * y;
  8.1317 -            void *lower = (Uint8 *) OpenGL_Surface->pixels +
  8.1318 -                OpenGL_Surface->pitch * (OpenGL_Surface->h - y - 1);
  8.1319 -            SDL_memcpy(mirrorbuf, upper, OpenGL_Surface->pitch);
  8.1320 -            SDL_memcpy(upper, lower, OpenGL_Surface->pitch);
  8.1321 -            SDL_memcpy(lower, mirrorbuf, OpenGL_Surface->pitch);
  8.1322 -        }
  8.1323 -        /* the mapping has to be invalidated on 8bpp video surfaces in case of a hw palette change. 
  8.1324 -         * Now if someone could tell me why this is not handled by SDL... */
  8.1325 -        if (SDL_VideoSurface->format->BitsPerPixel == 8)
  8.1326 -            SDL_InvalidateMap(OpenGL_Surface->map);
  8.1327 -
  8.1328 -        /* convert this raw surface to the application-requested format 
  8.1329 -         * FIXME this is sometimes overkill, we could use glPixelStore smartly
  8.1330 -         * But this would be slow anyway :) */
  8.1331 -
  8.1332 -        glSDL_SoftBlit(OpenGL_Surface, NULL, SDL_VideoSurface, NULL);
  8.1333 -    } else
  8.1334 -        glSDL_Invalidate(surface, NULL);
  8.1335 -
  8.1336 -    return 0;
  8.1337 -}
  8.1338 -
  8.1339 -
  8.1340 -static void
  8.1341 -glSDL_UnlockHWSurface(_THIS, SDL_Surface * surface)
  8.1342 -{
  8.1343 -    private_hwdata *txi;
  8.1344 -
  8.1345 -    if (!surface)
  8.1346 -        return;
  8.1347 -
  8.1348 -    /* upload this surface ONLY if this is a glSDL surface
  8.1349 -     * because sometimes (during displayformating for ex.) surfaces are unlocked that aren't glSDL
  8.1350 -     */
  8.1351 -    if (!IS_GLSDL_SURFACE(surface))
  8.1352 -        return;
  8.1353 -
  8.1354 -#ifdef DEBUG_GLSDL
  8.1355 -    fprintf(stderr, "glSDL: Unlock Surface.\n");
  8.1356 -#endif
  8.1357 -
  8.1358 -    txi = glSDL_UploadSurface(this, surface);
  8.1359 -
  8.1360 -    if (!txi) {
  8.1361 -        GLERR("glSDL_UnlockHWSurface() failed to upload surface!");
  8.1362 -        return;
  8.1363 -    }
  8.1364 -    if (txi->temporary) {
  8.1365 -        GLERR
  8.1366 -            ("Weirdness... glSDL_UnlockHWSurface() got a temporary TexInfo.");
  8.1367 -        return;
  8.1368 -    }
  8.1369 -    if (surface == SDL_VideoSurface)
  8.1370 -        glSDL_BlitGL(this, SDL_VideoSurface, NULL, NULL);
  8.1371 -}
  8.1372 -
  8.1373 -
  8.1374 -static int
  8.1375 -glSDL_SetHWColorKey(_THIS, SDL_Surface * surface, Uint32 key)
  8.1376 -{
  8.1377 -    /*
  8.1378 -     * If an application does this *after* SDL_DisplayFormat,
  8.1379 -     * we're basically screwed, unless we want to do an
  8.1380 -     * in-place surface conversion hack here.
  8.1381 -     *
  8.1382 -     * What we do is just kill the glSDL texinfo... No big
  8.1383 -     * deal in most cases, as glSDL only converts once anyway,
  8.1384 -     * *unless* you keep modifying the surface.
  8.1385 -     */
  8.1386 -    if (IS_GLSDL_SURFACE(surface))
  8.1387 -        glSDL_RemoveTexInfo(this, surface);
  8.1388 -    return 0;
  8.1389 -}
  8.1390 -
  8.1391 -
  8.1392 -static int
  8.1393 -glSDL_SetHWAlpha(_THIS, SDL_Surface * surface, Uint8 alpha)
  8.1394 -{
  8.1395 -    /*
  8.1396 -     * If an application does this *after* SDL_DisplayFormat,
  8.1397 -     * we're basically screwed, unless we want to do an
  8.1398 -     * in-place surface conversion hack here.
  8.1399 -     *
  8.1400 -     * What we do is just kill the glSDL texinfo... No big
  8.1401 -     * deal in most cases, as glSDL only converts once anyway,
  8.1402 -     * *unless* you keep modifying the surface.
  8.1403 -     */
  8.1404 -    if (IS_GLSDL_SURFACE(surface))
  8.1405 -        glSDL_RemoveTexInfo(this, surface);
  8.1406 -    return 0;
  8.1407 -}
  8.1408 -
  8.1409 -static SDL_bool
  8.1410 -glSDL_SetClipRect(_THIS, SDL_Surface * surface, SDL_Rect * rect)
  8.1411 -{
  8.1412 -    SDL_bool res;
  8.1413 -    if (!surface)
  8.1414 -        return SDL_FALSE;
  8.1415 -
  8.1416 -    res = SDL_SetClipRect(surface, rect);
  8.1417 -    if (!res)
  8.1418 -        return SDL_FALSE;
  8.1419 -
  8.1420 -    rect = &surface->clip_rect;
  8.1421 -
  8.1422 -    if (surface == SDL_VideoSurface) {
  8.1423 -        SDL_Rect r;
  8.1424 -        float xscale, yscale;
  8.1425 -        private_hwdata *txi;
  8.1426 -
  8.1427 -        r.x = rect->x;
  8.1428 -        r.y = rect->y;
  8.1429 -        r.w = rect->w;
  8.1430 -        r.h = rect->h;
  8.1431 -        SDL_SetClipRect(surface, rect);
  8.1432 -
  8.1433 -        txi = glSDL_GetTexInfo(surface);
  8.1434 -        if (!txi)
  8.1435 -            return GLERET("SetClipRect(): Could not get TexInfo!");
  8.1436 -
  8.1437 -        this->glViewport(rect->x,
  8.1438 -                         surface->h - (rect->y + rect->h), rect->w, rect->h);
  8.1439 -        /*
  8.1440 -         * Note that this projection is upside down in
  8.1441 -         * relation to the OpenGL coordinate system.
  8.1442 -         */
  8.1443 -        this->glMatrixMode(GL_PROJECTION);
  8.1444 -        this->glLoadIdentity();
  8.1445 -        xscale = (float) txi->lw / (float) surface->w;
  8.1446 -        yscale = (float) txi->lh / (float) surface->h;
  8.1447 -        this->glOrtho(xscale * (float) rect->x,
  8.1448 -                      xscale * (float) (rect->w + rect->x),
  8.1449 -                      yscale * (float) (rect->h + rect->y),
  8.1450 -                      yscale * (float) rect->y, -1.0, 1.0);
  8.1451 -        return SDL_TRUE;
  8.1452 -    }
  8.1453 -    return res;
  8.1454 -}
  8.1455 -
  8.1456 -static int
  8.1457 -glSDL_BlitFromGL(_THIS, SDL_Rect * srcrect,
  8.1458 -                 SDL_Surface * dst, SDL_Rect * dstrect)
  8.1459 -{
  8.1460 -    SDL_Rect sr, dr;
  8.1461 -
  8.1462 -    /* In case the destination has an OpenGL texture... */
  8.1463 -    glSDL_Invalidate(dst, dstrect);
  8.1464 -
  8.1465 -    /* Abuse the fake screen buffer a little. */
  8.1466 -    this->glPixelStorei(GL_UNPACK_ROW_LENGTH, SDL_VideoSurface->pitch /
  8.1467 -                        SDL_VideoSurface->format->BytesPerPixel);
  8.1468 -    if (srcrect)
  8.1469 -        this->glReadPixels(srcrect->x,
  8.1470 -                           OpenGL_Surface->h - (srcrect->y + srcrect->h - 1),
  8.1471 -                           srcrect->w, srcrect->h, GL_RGB, GL_UNSIGNED_BYTE,
  8.1472 -                           OpenGL_Surface->pixels);
  8.1473 -    else
  8.1474 -        this->glReadPixels(0, 0, OpenGL_Surface->w, OpenGL_Surface->h,
  8.1475 -                           GL_RGB, GL_UNSIGNED_BYTE, OpenGL_Surface->pixels);
  8.1476 -    sr = *srcrect;
  8.1477 -    dr = *dstrect;
  8.1478 -    glSDL_SoftBlit(OpenGL_Surface, &sr, dst, &dr);
  8.1479 -    return 0;
  8.1480 -}
  8.1481 -
  8.1482 -static __inline__ void
  8.1483 -glSDL_BlitGL_single(_THIS, private_hwdata * txi,
  8.1484 -                    float sx1, float sy1, SDL_Rect * dst, unsigned char alpha)
  8.1485 -{
  8.1486 -    float sx2, sy2, texscale;
  8.1487 -    if (!txi->textures)
  8.1488 -        return;
  8.1489 -    if (-1 == txi->texture[0])
  8.1490 -        return;
  8.1491 -    glSDL_texture(this, txi->texture[0]);
  8.1492 -
  8.1493 -    texscale = 1.0 / (float) txi->texsize;
  8.1494 -    sx2 = (sx1 + (float) dst->w) * texscale;
  8.1495 -    sy2 = (sy1 + (float) dst->h) * texscale;
  8.1496 -    sx1 *= texscale;
  8.1497 -    sy1 *= texscale;
  8.1498 -
  8.1499 -#ifdef GLSDL_GRAPHICAL_DEBUG
  8.1500 -    this->glDisable(GL_TEXTURE_2D);
  8.1501 -    this->glBegin(GL_LINE_LOOP);
  8.1502 -    this->glColor4ub(0, 255, 0, 128);
  8.1503 -    this->glVertex2i(dst->x, dst->y);
  8.1504 -    this->glVertex2i(dst->x + dst->w, dst->y);
  8.1505 -    this->glVertex2i(dst->x + dst->w, dst->y + dst->h);
  8.1506 -    this->glVertex2i(dst->x, dst->y + dst->h);
  8.1507 -    this->glEnd();
  8.1508 -    this->glEnable(GL_TEXTURE_2D);
  8.1509 -#endif
  8.1510 -
  8.1511 -    this->glBegin(GL_TRIANGLE_FAN);
  8.1512 -    this->glColor4ub(255, 255, 255, alpha);
  8.1513 -    this->glTexCoord2f(sx1, sy1);
  8.1514 -    this->glVertex2i(dst->x, dst->y);
  8.1515 -    this->glTexCoord2f(sx2, sy1);
  8.1516 -    this->glVertex2i(dst->x + dst->w, dst->y);
  8.1517 -    this->glTexCoord2f(sx2, sy2);
  8.1518 -    this->glVertex2i(dst->x + dst->w, dst->y + dst->h);
  8.1519 -    this->glTexCoord2f(sx1, sy2);
  8.1520 -    this->glVertex2i(dst->x, dst->y + dst->h);
  8.1521 -    this->glEnd();
  8.1522 -}
  8.1523 -
  8.1524 -
  8.1525 -static void
  8.1526 -glSDL_BlitGL_htile(_THIS, private_hwdata * txi,
  8.1527 -                   float sx1, float sy1, SDL_Rect * dst, unsigned char alpha)
  8.1528 -{
  8.1529 -    int tex;
  8.1530 -    float tile, sx2, sy2, yo;
  8.1531 -    float texscale = 1.0 / (float) txi->texsize;
  8.1532 -    float tileh = (float) txi->tileh * texscale;
  8.1533 -    sx2 = (sx1 + (float) dst->w) * texscale;
  8.1534 -    sy2 = (sy1 + (float) dst->h) * texscale;
  8.1535 -    sx1 *= texscale;
  8.1536 -    sy1 *= texscale;
  8.1537 -    tile = floor(sx1);
  8.1538 -    tex = (int) tile / txi->tilespertex;
  8.1539 -    yo = ((int) tile % txi->tilespertex) * tileh;
  8.1540 -
  8.1541 -    if (tex >= txi->textures)
  8.1542 -        return;
  8.1543 -    if (-1 == txi->texture[tex])
  8.1544 -        return;
  8.1545 -    glSDL_texture(this, txi->texture[tex]);
  8.1546 -
  8.1547 -    while (tile < sx2) {
  8.1548 -        int tdx1 = dst->x;
  8.1549 -        int tdx2 = dst->x + dst->w;
  8.1550 -        float tsx1 = sx1 - tile;
  8.1551 -        float tsx2 = sx2 - tile;
  8.1552 -
  8.1553 -        /* Clip to current tile */
  8.1554 -        if (tsx1 < 0.0) {
  8.1555 -            tdx1 -= tsx1 * txi->texsize;
  8.1556 -            tsx1 = 0.0;
  8.1557 -        }
  8.1558 -        if (tsx2 > 1.0) {
  8.1559 -            tdx2 -= (tsx2 - 1.0) * txi->texsize;
  8.1560 -            tsx2 = 1.0;
  8.1561 -        }
  8.1562 -
  8.1563 -        /* Maybe select next texture? */
  8.1564 -        if (yo + tileh > 1.0) {
  8.1565 -            ++tex;
  8.1566 -            if (tex >= txi->textures)
  8.1567 -                return;
  8.1568 -            if (-1 == txi->texture[tex])
  8.1569 -                return;
  8.1570 -            glSDL_texture(this, txi->texture[tex]);
  8.1571 -            yo = 0.0;
  8.1572 -        }
  8.1573 -#ifdef GLSDL_GRAPHICAL_DEBUG
  8.1574 -        this->glDisable(GL_TEXTURE_2D);
  8.1575 -        this->glBegin(GL_LINE_LOOP);
  8.1576 -        this->glColor4ub(0, 255, 0, 128);
  8.1577 -        this->glVertex2i(tdx1, dst->y);
  8.1578 -        this->glVertex2i(tdx2, dst->y);
  8.1579 -        this->glVertex2i(tdx2, dst->y + dst->h);
  8.1580 -        this->glVertex2i(tdx1, dst->y + dst->h);
  8.1581 -        this->glEnd();
  8.1582 -        this->glEnable(GL_TEXTURE_2D);
  8.1583 -#endif
  8.1584 -
  8.1585 -        this->glBegin(GL_TRIANGLE_FAN);
  8.1586 -        this->glColor4ub(255, 255, 255, alpha);
  8.1587 -        this->glTexCoord2f(tsx1, yo + sy1);
  8.1588 -        this->glVertex2i(tdx1, dst->y);
  8.1589 -        this->glTexCoord2f(tsx2, yo + sy1);
  8.1590 -        this->glVertex2i(tdx2, dst->y);
  8.1591 -        this->glTexCoord2f(tsx2, yo + sy2);
  8.1592 -        this->glVertex2i(tdx2, dst->y + dst->h);
  8.1593 -        this->glTexCoord2f(tsx1, yo + sy2);
  8.1594 -        this->glVertex2i(tdx1, dst->y + dst->h);
  8.1595 -        this->glEnd();
  8.1596 -        tile += 1.0;
  8.1597 -        yo += tileh;
  8.1598 -    }
  8.1599 -}
  8.1600 -
  8.1601 -
  8.1602 -static void
  8.1603 -glSDL_BlitGL_vtile(_THIS, private_hwdata * txi,
  8.1604 -                   float sx1, float sy1, SDL_Rect * dst, unsigned char alpha)
  8.1605 -{
  8.1606 -    int tex;
  8.1607 -    float tile, sx2, sy2, xo;
  8.1608 -    float texscale = 1.0 / (float) txi->texsize;
  8.1609 -    float tilew = (float) txi->tilew * texscale;
  8.1610 -    sx2 = (sx1 + (float) dst->w) * texscale;
  8.1611 -    sy2 = (sy1 + (float) dst->h) * texscale;
  8.1612 -    sx1 *= texscale;
  8.1613 -    sy1 *= texscale;
  8.1614 -    tile = floor(sy1);
  8.1615 -    tex = (int) tile / txi->tilespertex;
  8.1616 -    xo = ((int) tile % txi->tilespertex) * tilew;
  8.1617 -
  8.1618 -    if (tex >= txi->textures)
  8.1619 -        return;
  8.1620 -    if (-1 == txi->texture[tex])
  8.1621 -        return;
  8.1622 -    glSDL_texture(this, txi->texture[tex]);
  8.1623 -
  8.1624 -    while (tile < sy2) {
  8.1625 -        int tdy1 = dst->y;
  8.1626 -        int tdy2 = dst->y + dst->h;
  8.1627 -        float tsy1 = sy1 - tile;
  8.1628 -        float tsy2 = sy2 - tile;
  8.1629 -
  8.1630 -        /* Clip to current tile */
  8.1631 -        if (tsy1 < 0.0) {
  8.1632 -            tdy1 -= tsy1 * txi->texsize;
  8.1633 -            tsy1 = 0.0;
  8.1634 -        }
  8.1635 -        if (tsy2 > 1.0) {
  8.1636 -            tdy2 -= (tsy2 - 1.0) * txi->texsize;
  8.1637 -            tsy2 = 1.0;
  8.1638 -        }
  8.1639 -
  8.1640 -        /* Maybe select next texture? */
  8.1641 -        if (xo + tilew > 1.0) {
  8.1642 -            ++tex;
  8.1643 -            if (tex >= txi->textures)
  8.1644 -                return;
  8.1645 -            if (-1 == txi->texture[tex])
  8.1646 -                return;
  8.1647 -            glSDL_texture(this, txi->texture[tex]);
  8.1648 -            xo = 0.0;
  8.1649 -        }
  8.1650 -#ifdef GLSDL_GRAPHICAL_DEBUG
  8.1651 -        this->glDisable(GL_TEXTURE_2D);
  8.1652 -        this->glBegin(GL_LINE_LOOP);
  8.1653 -        this->glColor4ub(0, 255, 0, 128);
  8.1654 -        this->glVertex2i(dst->x, tdy1);
  8.1655 -        this->glVertex2i(dst->x + dst->w, tdy1);
  8.1656 -        this->glVertex2i(dst->x + dst->w, tdy2);
  8.1657 -        this->glVertex2i(dst->x, tdy2);
  8.1658 -        this->glEnd();
  8.1659 -        this->glEnable(GL_TEXTURE_2D);
  8.1660 -#endif
  8.1661 -
  8.1662 -        this->glBegin(GL_TRIANGLE_FAN);
  8.1663 -        this->glColor4ub(255, 255, 255, alpha);
  8.1664 -        this->glTexCoord2f(xo + sx1, tsy1);
  8.1665 -        this->glVertex2i(dst->x, tdy1);
  8.1666 -        this->glTexCoord2f(xo + sx2, tsy1);
  8.1667 -        this->glVertex2i(dst->x + dst->w, tdy1);
  8.1668 -        this->glTexCoord2f(xo + sx2, tsy2);
  8.1669 -        this->glVertex2i(dst->x + dst->w, tdy2);
  8.1670 -        this->glTexCoord2f(xo + sx1, tsy2);
  8.1671 -        this->glVertex2i(dst->x, tdy2);
  8.1672 -        this->glEnd();
  8.1673 -
  8.1674 -        tile += 1.0;
  8.1675 -        xo += tilew;
  8.1676 -    }
  8.1677 -}
  8.1678 -
  8.1679 -
  8.1680 -static void
  8.1681 -glSDL_BlitGL_hvtile(_THIS, SDL_Surface * src, private_hwdata * txi,
  8.1682 -                    float sx1, float sy1, SDL_Rect * dst, unsigned char alpha)
  8.1683 -{
  8.1684 -    int x, y, last_tex, tex;
  8.1685 -    float sx2, sy2;
  8.1686 -    float texscale = 1.0 / (float) txi->texsize;
  8.1687 -    int tilesperrow = (src->w + txi->tilew - 1) / txi->tilew;
  8.1688 -    sx2 = (sx1 + (float) dst->w) * texscale;
  8.1689 -    sy2 = (sy1 + (float) dst->h) * texscale;
  8.1690 -    sx1 *= texscale;
  8.1691 -    sy1 *= texscale;
  8.1692 -
  8.1693 -    last_tex = tex = floor(sy1) * tilesperrow + floor(sx1);
  8.1694 -    if (tex >= txi->textures)
  8.1695 -        return;
  8.1696 -    if (-1 == txi->texture[tex])
  8.1697 -        return;
  8.1698 -    glSDL_texture(this, txi->texture[tex]);
  8.1699 -
  8.1700 -    for (y = floor(sy1); y < sy2; ++y) {
  8.1701 -        int tdy1 = dst->y;
  8.1702 -        int tdy2 = dst->y + dst->h;
  8.1703 -        float tsy1 = sy1 - y;
  8.1704 -        float tsy2 = sy2 - y;
  8.1705 -
  8.1706 -        /* Clip to current tile */
  8.1707 -        if (tsy1 < 0.0) {
  8.1708 -            tdy1 -= tsy1 * txi->texsize;
  8.1709 -            tsy1 = 0.0;
  8.1710 -        }
  8.1711 -        if (tsy2 > 1.0) {
  8.1712 -            tdy2 -= (tsy2 - 1.0) * txi->texsize;
  8.1713 -            tsy2 = 1.0;
  8.1714 -        }
  8.1715 -        for (x = floor(sx1); x < sx2; ++x) {
  8.1716 -            int tdx1 = dst->x;
  8.1717 -            int tdx2 = dst->x + dst->w;
  8.1718 -            float tsx1 = sx1 - x;
  8.1719 -            float tsx2 = sx2 - x;
  8.1720 -
  8.1721 -            /* Clip to current tile */
  8.1722 -            if (tsx1 < 0.0) {
  8.1723 -                tdx1 -= tsx1 * txi->texsize;
  8.1724 -                tsx1 = 0.0;
  8.1725 -            }
  8.1726 -            if (tsx2 > 1.0) {
  8.1727 -                tdx2 -= (tsx2 - 1.0) * txi->texsize;
  8.1728 -                tsx2 = 1.0;
  8.1729 -            }
  8.1730 -
  8.1731 -            /* Select texture */
  8.1732 -            tex = y * tilesperrow + x;
  8.1733 -            if (tex != last_tex) {
  8.1734 -                if (tex >= txi->textures)
  8.1735 -                    return;
  8.1736 -                if (-1 == txi->texture[tex])
  8.1737 -                    return;
  8.1738 -                glSDL_texture(this, txi->texture[tex]);
  8.1739 -                last_tex = tex;
  8.1740 -            }
  8.1741 -#ifdef GLSDL_GRAPHICAL_DEBUG
  8.1742 -            this->glDisable(GL_TEXTURE_2D);
  8.1743 -            this->glBegin(GL_LINE_LOOP);
  8.1744 -            this->glColor4ub(0, 255, 0, 128);
  8.1745 -            this->glVertex2i(tdx1, tdy1);
  8.1746 -            this->glVertex2i(tdx2, tdy1);
  8.1747 -            this->glVertex2i(tdx2, tdy2);
  8.1748 -            this->glVertex2i(tdx1, tdy2);
  8.1749 -            this->glEnd();
  8.1750 -            this->glEnable(GL_TEXTURE_2D);
  8.1751 -#endif
  8.1752 -
  8.1753 -            this->glBegin(GL_TRIANGLE_FAN);
  8.1754 -            this->glColor4ub(255, 255, 255, alpha);
  8.1755 -            this->glTexCoord2f(tsx1, tsy1);
  8.1756 -            this->glVertex2i(tdx1, tdy1);
  8.1757 -            this->glTexCoord2f(tsx2, tsy1);
  8.1758 -            this->glVertex2i(tdx2, tdy1);
  8.1759 -            this->glTexCoord2f(tsx2, tsy2);
  8.1760 -            this->glVertex2i(tdx2, tdy2);
  8.1761 -            this->glTexCoord2f(tsx1, tsy2);
  8.1762 -            this->glVertex2i(tdx1, tdy2);
  8.1763 -            this->glEnd();
  8.1764 -        }
  8.1765 -    }
  8.1766 -}
  8.1767 -
  8.1768 -/*
  8.1769 - * Calculate the actual blit rectangle and source offset
  8.1770 - * for a blit from a rectangle in a surface with specified
  8.1771 - * size to a surface with a cliprect.
  8.1772 - *
  8.1773 - * In:	rect	source rectangle
  8.1774 - *	w, h	source surface size
  8.1775 - *	(x, y)	destination coordinate
  8.1776 - *	clip	destination clip rectangle
  8.1777 - *
  8.1778 - * Out:	(x, y)	source top-left offset
  8.1779 - *	rect	destination rectangle
  8.1780 - *
  8.1781 - * Returns 1 if the result is visible, otherwise 0.
  8.1782 - */
  8.1783 -static __inline__ int
  8.1784 -blitclip(SDL_Rect * rect, int w, int h, int *x, int *y, SDL_Rect * clip)
  8.1785 -{
  8.1786 -    int sx1, sy1, sx2, sy2;
  8.1787 -    int dx1, dy1, dx2, dy2;
  8.1788 -
  8.1789 -    /* Get source and destination coordinates */
  8.1790 -    sx1 = rect->x;
  8.1791 -    sy1 = rect->y;
  8.1792 -    sx2 = sx1 + rect->w;
  8.1793 -    sy2 = sy1 + rect->h;
  8.1794 -    dx1 = *x;
  8.1795 -    dy1 = *y;
  8.1796 -
  8.1797 -    /* Keep source rect inside source surface */
  8.1798 -    if (sx1 < 0) {
  8.1799 -        dx1 -= sx1;
  8.1800 -        sx1 = 0;
  8.1801 -    }
  8.1802 -    if (sy1 < 0) {
  8.1803 -        dy1 -= sy1;
  8.1804 -        sy1 = 0;
  8.1805 -    }
  8.1806 -    if (sx2 > w)
  8.1807 -        sx2 = w;
  8.1808 -    if (sy2 > h)
  8.1809 -        sy2 = h;
  8.1810 -
  8.1811 -    /* Cull blits from void space */
  8.1812 -    if (sx1 >= sx2 || sy1 >= sy2)
  8.1813 -        return 0;
  8.1814 -
  8.1815 -    /* Calculate destination lower-right */
  8.1816 -    dx2 = dx1 + (sx2 - sx1);
  8.1817 -    dy2 = dy1 + (sy2 - sy1);
  8.1818 -
  8.1819 -    /* Clip to destination cliprect */
  8.1820 -    if (dx1 < clip->x) {
  8.1821 -        sx1 += clip->x - dx1;
  8.1822 -        dx1 = clip->x;
  8.1823 -    }
  8.1824 -    if (dy1 < clip->y) {
  8.1825 -        sy1 += clip->y - dy1;
  8.1826 -        dy1 = clip->y;
  8.1827 -    }
  8.1828 -    if (dx2 > clip->x + clip->w)
  8.1829 -        dx2 = clip->x + clip->w;
  8.1830 -    if (dy2 > clip->y + clip->h)
  8.1831 -        dy2 = clip->y + clip->h;
  8.1832 -
  8.1833 -    /* Cull nop/off-screen blits */
  8.1834 -    if (dx1 >= dx2 || dy1 >= dy2)
  8.1835 -        return 0;
  8.1836 -
  8.1837 -    *x = sx1;
  8.1838 -    *y = sy1;
  8.1839 -    rect->x = dx1;
  8.1840 -    rect->y = dy1;
  8.1841 -    rect->w = dx2 - dx1;
  8.1842 -    rect->h = dy2 - dy1;
  8.1843 -    return 1;
  8.1844 -}
  8.1845 -
  8.1846 -static int
  8.1847 -glSDL_BlitGL(_THIS, SDL_Surface * src, SDL_Rect * srcrect, SDL_Rect * dstrect)
  8.1848 -{
  8.1849 -    private_hwdata *txi;
  8.1850 -    float x1, y1;
  8.1851 -    unsigned char alpha;
  8.1852 -    SDL_Rect d;
  8.1853 -    int x, y;
  8.1854 -    SDL_Rect r;
  8.1855 -
  8.1856 -    if (!src)
  8.1857 -        return GLERET("BlitGL(): No src surface!");
  8.1858 -
  8.1859 -    /* Get source and destination coordinates */
  8.1860 -    if (srcrect)
  8.1861 -        r = *srcrect;
  8.1862 -    else {
  8.1863 -        r.x = r.y = 0;
  8.1864 -        r.w = src->w;
  8.1865 -        r.h = src->h;
  8.1866 -    }
  8.1867 -    if (dstrect) {
  8.1868 -        x = dstrect->x;
  8.1869 -        y = dstrect->y;
  8.1870 -    } else
  8.1871 -        x = y = 0;
  8.1872 -
  8.1873 -    /* Clip! */
  8.1874 -    if (!blitclip(&r, src->w, src->h, &x, &y, &this->screen->clip_rect)) {
  8.1875 -        if (dstrect)
  8.1876 -            dstrect->w = dstrect->h = 0;
  8.1877 -        return 0;
  8.1878 -    }
  8.1879 -
  8.1880 -    /* Write back the resulting cliprect */
  8.1881 -    if (dstrect)
  8.1882 -        *dstrect = r;
  8.1883 -
  8.1884 -    /* Make sure we have a source with a valid texture */
  8.1885 -    txi = glSDL_UploadSurface(this, src);
  8.1886 -    if (!txi)
  8.1887 -        return GLERET("BlitGL(): Could not get a TexInfo!");
  8.1888 -
  8.1889 -    /* Set up blending */
  8.1890 -    if (src->flags & (SDL_SRCALPHA | SDL_SRCCOLORKEY)) {
  8.1891 -        glSDL_blendfunc(this, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  8.1892 -        glSDL_do_blend(this, 1);
  8.1893 -    } else
  8.1894 -        glSDL_do_blend(this, 0);
  8.1895 -
  8.1896 -    /* Enable texturing */
  8.1897 -    glSDL_do_texture(this, 1);
  8.1898 -
  8.1899 -    /* Calculate texcoords */
  8.1900 -    if (!srcrect)
  8.1901 -        srcrect = &txi->virt;
  8.1902 -    x1 = (float) srcrect->x;
  8.1903 -    y1 = (float) srcrect->y;
  8.1904 -
  8.1905 -    /* Calculate screen coords. */
  8.1906 -    if (dstrect) {
  8.1907 -        d.x = dstrect->x;
  8.1908 -        d.y = dstrect->y;
  8.1909 -        d.w = (int) (srcrect->w * (float) txi->lw / (float) txi->virt.w);
  8.1910 -        d.h = (int) (srcrect->h * (float) txi->lh / (float) txi->virt.h);
  8.1911 -    } else {
  8.1912 -        d.x = 0;
  8.1913 -        d.y = 0;
  8.1914 -        d.w = (int) (srcrect->w * (float) txi->lw / (float) txi->virt.w);
  8.1915 -        d.h = (int) (srcrect->h * (float) txi->lh / (float) txi->virt.h);
  8.1916 -    }
  8.1917 -
  8.1918 -    /*
  8.1919 -     * Note that we actually *prevent* the use of "full surface alpha"
  8.1920 -     * and alpha channel in combination - to stay SDL 2D compatible.
  8.1921 -     */
  8.1922 -    if ((src->flags & SDL_SRCALPHA) && (src->format->Amask))
  8.1923 -        alpha = 255;
  8.1924 -    else
  8.1925 -        alpha = src->format->alpha;
  8.1926 -
  8.1927 -    /* Render! */
  8.1928 -    switch (txi->tilemode) {
  8.1929 -    case GLSDL_TM_SINGLE:
  8.1930 -        glSDL_BlitGL_single(this, txi, x1, y1, &d, alpha);
  8.1931 -        break;
  8.1932 -    case GLSDL_TM_HORIZONTAL:
  8.1933 -        glSDL_BlitGL_htile(this, txi, x1, y1, &d, alpha);
  8.1934 -        break;
  8.1935 -    case GLSDL_TM_VERTICAL:
  8.1936 -        glSDL_BlitGL_vtile(this, txi, x1, y1, &d, alpha);
  8.1937 -        break;
  8.1938 -    case GLSDL_TM_HUGE:
  8.1939 -        glSDL_BlitGL_hvtile(this, src, txi, x1, y1, &d, alpha);
  8.1940 -        break;
  8.1941 -    }
  8.1942 -
  8.1943 -    if (txi->temporary)
  8.1944 -        glSDL_FreeTexInfo(this, txi);
  8.1945 -
  8.1946 -    return 0;
  8.1947 -}
  8.1948 -
  8.1949 -
  8.1950 -static int
  8.1951 -glSDL_HWAccelBlit(SDL_Surface * src, SDL_Rect * srcrect,
  8.1952 -                  SDL_Surface * dst, SDL_Rect * dstrect)
  8.1953 -{
  8.1954 -    SDL_Surface *vs;
  8.1955 -
  8.1956 -    if (!src)
  8.1957 -        return GLERET("HWAccelBlit(): No src surface!");
  8.1958 -    if (!dst)
  8.1959 -        return GLERET("HWAccelBlit(): No dst surface!");
  8.1960 -
  8.1961 -    /*
  8.1962 -     * Figure out what to do:
  8.1963 -     *      screen->screen:         glSDL_BlitFromGL() + glSDL_BlitGL()
  8.1964 -     *      surface->screen:        glSDL_BlitGL()
  8.1965 -     *      screen->surface:        glSDL_BlitFromGL()
  8.1966 -     *      surface->surface:       glSDL_SoftBlit()
  8.1967 -     */
  8.1968 -    vs = SDL_VideoSurface;
  8.1969 -    if (src == vs) {
  8.1970 -        if (dst == vs) {
  8.1971 -            /*
  8.1972 -               FIXME: Try glCopyPixels() instead...
  8.1973 -             */
  8.1974 -            glSDL_BlitFromGL(current_video, srcrect, vs, dstrect);
  8.1975 -            return glSDL_BlitGL(current_video, vs, srcrect, dstrect);
  8.1976 -        } else {
  8.1977 -            return glSDL_BlitFromGL(current_video, srcrect, dst, dstrect);
  8.1978 -        }
  8.1979 -    } else {
  8.1980 -        if (dst == vs) {
  8.1981 -            return glSDL_BlitGL(current_video, src, srcrect, dstrect);
  8.1982 -        } else {
  8.1983 -            glSDL_Invalidate(dst, dstrect);
  8.1984 -            glSDL_SoftBlit(src, srcrect, dst, dstrect);
  8.1985 -            return 0;
  8.1986 -        }
  8.1987 -    }
  8.1988 -}
  8.1989 -
  8.1990 -
  8.1991 -static int
  8.1992 -glSDL_FillHWRect(_THIS, SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color)
  8.1993 -{
  8.1994 -    SDL_Surface *vs = SDL_VideoSurface;
  8.1995 -    int dx1, dy1, dx2, dy2;
  8.1996 -    Uint32 r, g, b;
  8.1997 -    Uint8 br, bg, bb;
  8.1998 -
  8.1999 -    /*
  8.2000 -     * Some ugly reverse conversion for compatibility...
  8.2001 -     * (We must do this before losing the dst pointer,
  8.2002 -     * as the pixel formats of the screen and
  8.2003 -     * SDL_VideoSurface may differ!)
  8.2004 -     */
  8.2005 -
  8.2006 -    if (dst->format->palette) {
  8.2007 -        /* this a paletted color */
  8.2008 -        SDL_GetRGB(color, dst->format, &br, &bg, &bb);
  8.2009 -    } else {
  8.2010 -        /* this a RGB color */
  8.2011 -        r = color & dst->format->Rmask;
  8.2012 -        r = r >> dst->format->Rshift;
  8.2013 -        r = r << dst->format->Rloss;
  8.2014 -        br = r;
  8.2015 -
  8.2016 -        g = color & dst->format->Gmask;
  8.2017 -        g = g >> dst->format->Gshift;
  8.2018 -        g = g << dst->format->Gloss;
  8.2019 -        bg = g;
  8.2020 -
  8.2021 -        b = color & dst->format->Bmask;
  8.2022 -        b = b >> dst->format->Bshift;
  8.2023 -        b = b << dst->format->Bloss;
  8.2024 -        bb = b;
  8.2025 -    }
  8.2026 -
  8.2027 -    if (vs != dst) {
  8.2028 -        /* draw a rect offscreen */
  8.2029 -        glSDL_Invalidate(dst, dstrect);
  8.2030 -        /* software-fill the surface by faking it as a SW_SURFACE */
  8.2031 -        dst->flags &= ~SDL_HWSURFACE;
  8.2032 -        SDL_FillRect(dst, dstrect, color);
  8.2033 -        dst->flags |= SDL_HWSURFACE;
  8.2034 -    } else {
  8.2035 -        /* draw a rect onscreen */
  8.2036 -        glSDL_do_texture(this, 0);
  8.2037 -        glSDL_do_blend(this, 0);
  8.2038 -
  8.2039 -        dx1 = dstrect->x;
  8.2040 -        dy1 = dstrect->y;
  8.2041 -        dx2 = dx1 + dstrect->w;
  8.2042 -        dy2 = dy1 + dstrect->h;
  8.2043 -
  8.2044 -        this->glBegin(GL_TRIANGLE_FAN);
  8.2045 -        this->glColor3ub(br, bg, bb);
  8.2046 -        this->glVertex2i(dx1, dy1);
  8.2047 -        this->glVertex2i(dx2, dy1);
  8.2048 -        this->glVertex2i(dx2, dy2);
  8.2049 -        this->glVertex2i(dx1, dy2);
  8.2050 -        this->glEnd();
  8.2051 -    }
  8.2052 -    return 0;
  8.2053 -}
  8.2054 -
  8.2055 -static int
  8.2056 -glSDL_CheckHWBlit(_THIS, SDL_Surface * src, SDL_Surface * dst)
  8.2057 -{
  8.2058 -    src->flags |= SDL_HWACCEL;
  8.2059 -    src->map->hw_blit = glSDL_HWAccelBlit;
  8.2060 -    return 1;
  8.2061 -}
  8.2062 -
  8.2063 -
  8.2064 -static SDL_Surface *
  8.2065 -glSDL_DisplayFormat(SDL_Surface * surface)
  8.2066 -{
  8.2067 -    SDL_Surface *tmp;
  8.2068 -    int use_rgba = (surface->flags & SDL_SRCCOLORKEY) ||
  8.2069 -        ((surface->flags & SDL_SRCALPHA) && surface->format->Amask);
  8.2070 -#ifdef DEBUG_GLSDL
  8.2071 -    fprintf(stderr, "#### glSDL_DisplayFormat()\n");
  8.2072 -#endif
  8.2073 -    if (use_rgba)
  8.2074 -        tmp = glSDL_ConvertSurface(surface, RGBAfmt, SDL_SWSURFACE);
  8.2075 -    else
  8.2076 -        tmp = glSDL_ConvertSurface(surface, RGBfmt, SDL_SWSURFACE);
  8.2077 -    if (!tmp) {
  8.2078 -        GLERR("glSDL_DisplayFormat() could not convert surface!");
  8.2079 -        return NULL;
  8.2080 -    }
  8.2081 -    SDL_SetAlpha(tmp, 0, 0);
  8.2082 -
  8.2083 -    if (surface->flags & SDL_SRCCOLORKEY) {
  8.2084 -        /*
  8.2085 -         * We drop colorkey data here, but we have to,
  8.2086 -         * or we'll run into trouble when converting,
  8.2087 -         * in particular from indexed color formats.
  8.2088 -         */
  8.2089 -        SDL_SetColorKey(tmp, SDL_SRCCOLORKEY, surface->format->colorkey);
  8.2090 -        glSDL_key2alpha(tmp);
  8.2091 -        SDL_SetColorKey(tmp, 0, 0);
  8.2092 -    }
  8.2093 -
  8.2094 -    return tmp;
  8.2095 -}
  8.2096 -
  8.2097 -
  8.2098 -static SDL_Surface *
  8.2099 -glSDL_DisplayFormatAlpha(SDL_Surface * surface)
  8.2100 -{
  8.2101 -    SDL_Surface *s, *tmp;
  8.2102 -    tmp = glSDL_ConvertSurface(surface, RGBAfmt, SDL_SWSURFACE);
  8.2103 -#ifdef DEBUG_GLSDL
  8.2104 -    fprintf(stderr, "#### glSDL_DisplayFormatAlpha()\n");
  8.2105 -#endif
  8.2106 -    if (!tmp)
  8.2107 -        return NULL;
  8.2108 -
  8.2109 -    SDL_SetAlpha(tmp, 0, 0);
  8.2110 -    SDL_SetColorKey(tmp, 0, 0);
  8.2111 -    s = glSDL_CreateRGBASurface(surface->w, surface->h);
  8.2112 -    if (!s) {
  8.2113 -        SDL_FreeSurface(tmp);
  8.2114 -        return NULL;
  8.2115 -    }
  8.2116 -    glSDL_SoftBlit(tmp, NULL, s, NULL);
  8.2117 -    SDL_FreeSurface(tmp);
  8.2118 -
  8.2119 -    if (surface->flags & SDL_SRCCOLORKEY) {
  8.2120 -        SDL_SetColorKey(s, SDL_SRCCOLORKEY, surface->format->colorkey);
  8.2121 -        glSDL_key2alpha(s);
  8.2122 -        SDL_SetColorKey(s, 0, 0);
  8.2123 -    }
  8.2124 -
  8.2125 -    if (surface->flags & SDL_SRCALPHA)
  8.2126 -        SDL_SetAlpha(s, SDL_SRCALPHA, surface->format->alpha);
  8.2127 -    return s;
  8.2128 -}
  8.2129 -
  8.2130 -
  8.2131 -/*----------------------------------------------------------
  8.2132 -  glSDL specific API extensions
  8.2133 -  ----------------------------------------------------------*/
  8.2134 -
  8.2135 -static void
  8.2136 -glSDL_Invalidate(SDL_Surface * surface, SDL_Rect * area)
  8.2137 -{
  8.2138 -    private_hwdata *txi;
  8.2139 -    if (!surface)
  8.2140 -        return;
  8.2141 -    txi = glSDL_GetTexInfo(surface);
  8.2142 -    if (!txi)
  8.2143 -        return;
  8.2144 -    if (!area) {
  8.2145 -        txi->invalid_area.x = 0;
  8.2146 -        txi->invalid_area.y = 0;
  8.2147 -        txi->invalid_area.w = surface->w;
  8.2148 -        txi->invalid_area.h = surface->h;
  8.2149 -        return;
  8.2150 -    }
  8.2151 -    txi->invalid_area = *area;
  8.2152 -}
  8.2153 -
  8.2154 -
  8.2155 -static void
  8.2156 -glSDL_SetLogicSize(_THIS, SDL_Surface * surface, int w, int h)
  8.2157 -{
  8.2158 -    SDL_Rect r;
  8.2159 -    private_hwdata *txi;
  8.2160 -    if (!IS_GLSDL_SURFACE(surface))
  8.2161 -        return;
  8.2162 -
  8.2163 -    txi = glSDL_GetTexInfo(surface);
  8.2164 -
  8.2165 -    txi->lw = w;
  8.2166 -    txi->lh = h;
  8.2167 -
  8.2168 -    if (SDL_VideoSurface != surface)
  8.2169 -        return;
  8.2170 -
  8.2171 -    r.x = r.y = 0;
  8.2172 -    r.w = w;
  8.2173 -    r.h = h;
  8.2174 -    glSDL_SetClipRect(this, surface, &r);
  8.2175 -
  8.2176 -    this->glMatrixMode(GL_MODELVIEW);
  8.2177 -    this->glLoadIdentity();
  8.2178 -    this->glTranslated(0.0f, 0.0f, 0.0f);
  8.2179 -
  8.2180 -    this->glDisable(GL_DEPTH_TEST);
  8.2181 -    this->glDisable(GL_CULL_FACE);
  8.2182 -
  8.2183 -    glSDL_reset();
  8.2184 -}
  8.2185 -
  8.2186 -static int
  8.2187 -glSDL_InitTexture(_THIS, SDL_Surface * datasurf, private_hwdata * txi,
  8.2188 -                  int tex)
  8.2189 -{
  8.2190 -    this->glGenTextures(1, (GLuint *) & txi->texture[tex]);
  8.2191 -    this->glBindTexture(GL_TEXTURE_2D, txi->texture[tex]);
  8.2192 -    glstate.texture = txi->texture[tex];
  8.2193 -    this->glPixelStorei(GL_UNPACK_ROW_LENGTH, datasurf->pitch /
  8.2194 -                        datasurf->format->BytesPerPixel);
  8.2195 -    this->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  8.2196 -    this->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  8.2197 -    this->glTexImage2D(GL_TEXTURE_2D, 0,
  8.2198 -                       datasurf->format->Amask ? GL_RGBA8 : GL_RGB8,
  8.2199 -                       txi->texsize, txi->texsize, 0,
  8.2200 -                       datasurf->format->Amask ? GL_RGBA : GL_RGB,
  8.2201 -                       GL_UNSIGNED_BYTE, NULL);
  8.2202 -#ifdef DEBUG_GLSDL
  8.2203 -    glSDL_print_glerror(this, 1);
  8.2204 -#endif
  8.2205 -    return 0;
  8.2206 -}
  8.2207 -
  8.2208 -
  8.2209 -/* Image tiled horizontally (wide surface), or not at all */
  8.2210 -static int
  8.2211 -glSDL_UploadHoriz(_THIS, SDL_Surface * datasurf, private_hwdata * txi)
  8.2212 -{
  8.2213 -    int bpp = datasurf->format->BytesPerPixel;
  8.2214 -    int res;
  8.2215 -    int tex = 0;
  8.2216 -    int fromx = 0;
  8.2217 -    int toy = txi->texsize;     /* To init first texture */
  8.2218 -    while (1) {
  8.2219 -        int thistw = datasurf->w - fromx;
  8.2220 -        if (thistw > txi->tilew)
  8.2221 -            thistw = txi->tilew;
  8.2222 -        else if (thistw <= 0)
  8.2223 -            break;
  8.2224 -        if (toy + txi->tileh > txi->texsize) {
  8.2225 -            toy = 0;
  8.2226 -            res = glSDL_InitTexture(this, datasurf, txi, tex);
  8.2227 -            if (res < 0)
  8.2228 -                return res;
  8.2229 -            ++tex;
  8.2230 -        }
  8.2231 -        this->glTexSubImage2D(GL_TEXTURE_2D, 0, 0, toy,
  8.2232 -                              thistw, txi->tileh,
  8.2233 -                              datasurf->format->Amask ? GL_RGBA : GL_RGB,
  8.2234 -                              GL_UNSIGNED_BYTE,
  8.2235 -                              (char *) datasurf->pixels + bpp * fromx);
  8.2236 -#ifdef DEBUG_GLSDL
  8.2237 -        glSDL_print_glerror(this, 2);
  8.2238 -#endif
  8.2239 -        fromx += txi->tilew;
  8.2240 -        toy += txi->tileh;
  8.2241 -    }
  8.2242 -    return 0;
  8.2243 -}
  8.2244 -
  8.2245 -
  8.2246 -/* Image tiled vertically (tall surface) */
  8.2247 -static int
  8.2248 -glSDL_UploadVert(_THIS, SDL_Surface * datasurf, private_hwdata * txi)
  8.2249 -{
  8.2250 -    int res;
  8.2251 -    int tex = 0;
  8.2252 -    int fromy = 0;
  8.2253 -    int tox = txi->texsize;     /* To init first texture */
  8.2254 -    while (1) {
  8.2255 -        int thisth = datasurf->h - fromy;
  8.2256 -        if (thisth > txi->tileh)
  8.2257 -            thisth = txi->tileh;
  8.2258 -        else if (thisth <= 0)
  8.2259 -            break;
  8.2260 -        if (tox + txi->tilew > txi->texsize) {
  8.2261 -            tox = 0;
  8.2262 -            res = glSDL_InitTexture(this, datasurf, txi, tex);
  8.2263 -            if (res < 0)
  8.2264 -                return res;
  8.2265 -            ++tex;
  8.2266 -        }
  8.2267 -        this->glTexSubImage2D(GL_TEXTURE_2D, 0, tox, 0,
  8.2268 -                              txi->tilew, thisth,
  8.2269 -                              datasurf->format->Amask ? GL_RGBA : GL_RGB,
  8.2270 -                              GL_UNSIGNED_BYTE,
  8.2271 -                              (char *) datasurf->pixels +
  8.2272 -                              datasurf->pitch * fromy);
  8.2273 -#ifdef DEBUG_GLSDL
  8.2274 -        glSDL_print_glerror(this, 3);
  8.2275 -#endif
  8.2276 -        fromy += txi->tileh;
  8.2277 -        tox += txi->tilew;
  8.2278 -    }
  8.2279 -    return 0;
  8.2280 -}
  8.2281 -
  8.2282 -
  8.2283 -/* Image tiled two-way (huge surface) */
  8.2284 -static int
  8.2285 -glSDL_UploadHuge(_THIS, SDL_Surface * datasurf, private_hwdata * txi)
  8.2286 -{
  8.2287 -    int bpp = datasurf->format->BytesPerPixel;
  8.2288 -    int res;
  8.2289 -    int tex = 0;
  8.2290 -    int y = 0;
  8.2291 -    while (y < datasurf->h) {
  8.2292 -        int x;
  8.2293 -        int thisth = datasurf->h - y;
  8.2294 -        if (thisth > txi->tileh)
  8.2295 -            thisth = txi->tileh;
  8.2296 -        x = 0;
  8.2297 -        while (x < datasurf->w) {
  8.2298 -            int thistw = datasurf->w - x;
  8.2299 -            if (thistw > txi->tilew)
  8.2300 -                thistw = txi->tilew;
  8.2301 -            res = glSDL_InitTexture(this, datasurf, txi, tex++);
  8.2302 -            if (res < 0)
  8.2303 -                return res;
  8.2304 -            this->glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
  8.2305 -                                  thistw, thisth,
  8.2306 -                                  datasurf->format->
  8.2307 -                                  Amask ? GL_RGBA : GL_RGB,
  8.2308 -                                  GL_UNSIGNED_BYTE,
  8.2309 -                                  (char *) datasurf->pixels +
  8.2310 -                                  datasurf->pitch * y + bpp * x);
  8.2311 -#ifdef DEBUG_GLSDL
  8.2312 -            fprintf(stderr,
  8.2313 -                    "glTexSubImage(x = %d, y = %d, w = %d, h = %d)\n", x,
  8.2314 -                    y, thistw, thisth);
  8.2315 -            glSDL_print_glerror(this, 4);
  8.2316 -#endif
  8.2317 -            x += txi->tilew;
  8.2318 -        }
  8.2319 -        y += txi->tileh;
  8.2320 -    }
  8.2321 -    return 0;
  8.2322 -}
  8.2323 -
  8.2324 -
  8.2325 -/* Upload all textures for a surface. */
  8.2326 -static int
  8.2327 -glSDL_UploadTextures(_THIS, SDL_Surface * datasurf, private_hwdata * txi)
  8.2328 -{
  8.2329 -    switch (txi->tilemode) {
  8.2330 -    case GLSDL_TM_SINGLE:
  8.2331 -    case GLSDL_TM_HORIZONTAL:
  8.2332 -        glSDL_UploadHoriz(this, datasurf, txi);
  8.2333 -        break;
  8.2334 -    case GLSDL_TM_VERTICAL:
  8.2335 -        glSDL_UploadVert(this, datasurf, txi);
  8.2336 -        break;
  8.2337 -    case GLSDL_TM_HUGE:
  8.2338 -        glSDL_UploadHuge(this, datasurf, txi);
  8.2339 -        break;
  8.2340 -    }
  8.2341 -    return 0;
  8.2342 -}
  8.2343 -
  8.2344 -
  8.2345 -/*
  8.2346 - * IMPORTANT:
  8.2347 - *	This function will try various ways of giving you
  8.2348 - *	a TexInfo, and will succeed most of the time.
  8.2349 - *
  8.2350 - *	However, the TexInfo returned may be temporary,
  8.2351 - *	(as opposed to connected to 'surface'). A temporary
  8.2352 - *	TexInfo must be used only once and then thrown away,
  8.2353 - *	since it means that glSDL cannot track changes in
  8.2354 - *	the pixel data of 'texture'.
  8.2355 - */
  8.2356 -static private_hwdata *
  8.2357 -glSDL_UploadSurface(_THIS, SDL_Surface * surface)
  8.2358 -{
  8.2359 -    int i;
  8.2360 -    int converted = 0;
  8.2361 -    private_hwdata *txi = glSDL_GetTexInfo(surface);
  8.2362 -
  8.2363 -    if (IS_GLSDL_SURFACE(surface)) {
  8.2364 -        /*
  8.2365 -         * Ok, this is a glSDL surface, and it *might* be
  8.2366 -         * in texture memory already. If so, it may need
  8.2367 -         * an update.
  8.2368 -         */
  8.2369 -        if (txi->invalid_area.w) {
  8.2370 -            glSDL_UnloadTexture(this, txi);
  8.2371 -        } else {
  8.2372 -            int missing = 0;
  8.2373 -            if (txi->textures) {
  8.2374 -                for (i = 0; i < txi->textures; ++i)
  8.2375 -                    if (GLSDL_NOTEX == txi->texture[i]) {
  8.2376 -                        missing = 1;
  8.2377 -                        break;
  8.2378 -                    }
  8.2379 -                if (!missing)
  8.2380 -                    return txi; /* They're already there! */
  8.2381 -            }
  8.2382 -        }
  8.2383 -    } else {
  8.2384 -        /*
  8.2385 -         * Nope, this isn't (yet) a glSDL surface. Let's
  8.2386 -         * try to either make it one, or set up a temporary
  8.2387 -         * TexInfo for it, valid for only one blit.
  8.2388 -         */
  8.2389 -        if ((surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE) {
  8.2390 -            txi = glSDL_AddTexInfo(this, surface);
  8.2391 -            if (!txi) {
  8.2392 -                GLERR("UploadSurface(): Could not add TexInfo!");
  8.2393 -                return NULL;
  8.2394 -            }
  8.2395 -            surface->flags |= SDL_HWSURFACE;
  8.2396 -            surface->flags |= SDL_HWACCEL;
  8.2397 -        } else {
  8.2398 -            /* 
  8.2399 -             * FIXME
  8.2400 -             * here if the surface is small enough, it's a good 
  8.2401 -             * candidate for a blit using glDrawPixels instead 
  8.2402 -             * of a texture blit
  8.2403 -             */
  8.2404 -            txi = glSDL_CreateTempTexInfo(this, surface);
  8.2405 -            if (!txi) {
  8.2406 -                GLERR("UploadSurface(): Could not create temp TexInfo!");
  8.2407 -                return NULL;
  8.2408 -            }
  8.2409 -        }
  8.2410 -    }
  8.2411 -
  8.2412 -    if (txi->texsize > maxtexsize) {
  8.2413 -        /* This surface wasn't tiled properly... */
  8.2414 -        if (txi->temporary)
  8.2415 -            glSDL_FreeTexInfo(this, txi);
  8.2416 -        GLERR("UploadSurface(): Too large texture!");
  8.2417 -        return NULL;
  8.2418 -    }
  8.2419 -
  8.2420 -    /*
  8.2421 -     * Kludge: Convert if not of preferred RGB or RGBA format.
  8.2422 -     *
  8.2423 -     *      Conversion should only be done when *really* needed.
  8.2424 -     *      That is, it should rarely have to be done with OpenGL
  8.2425 -     *      1.2+.
  8.2426 -     *
  8.2427 -     *      Besides, any surface that's been SDL_DisplayFormat()ed
  8.2428 -     *      should already be in the best known OpenGL format -
  8.2429 -     *      preferably one that makes DMA w/o conversion possible.
  8.2430 -     */
  8.2431 -    if (!glSDL_FormatIsOk(surface)) {
  8.2432 -#ifdef DEBUG_GLSDL
  8.2433 -        fprintf(stderr, "glSDL: WARNING: On-the-fly conversion performed!\n");
  8.2434 -#endif
  8.2435 -        converted = 1;
  8.2436 -        /* NOTE: We forget about the original surface here. */
  8.2437 -        if (surface->format->Amask)
  8.2438 -            surface = glSDL_DisplayFormatAlpha(surface);
  8.2439 -        else
  8.2440 -            surface = glSDL_DisplayFormat(surface);
  8.2441 -        if (!surface) {
  8.2442 -            GLERR("UploadSurface(): Could not convert surface!");
  8.2443 -            if (txi->temporary)
  8.2444 -                glSDL_FreeTexInfo(this, txi);
  8.2445 -            return NULL;
  8.2446 -        }
  8.2447 -    }
  8.2448 -
  8.2449 -    glSDL_UploadTextures(this, surface, txi);
  8.2450 -
  8.2451 -    if (converted)
  8.2452 -        SDL_FreeSurface(surface);
  8.2453 -
  8.2454 -    return txi;
  8.2455 -}
  8.2456 -
  8.2457 -
  8.2458 -static void
  8.2459 -glSDL_UnloadTexture(_THIS, private_hwdata * txi)
  8.2460 -{
  8.2461 -    int i;
  8.2462 -    for (i = 0; i < txi->textures; ++i)
  8.2463 -        if (txi->texture[i] != GLSDL_NOTEX)
  8.2464 -            this->glDeleteTextures(1, &txi->texture[i]);
  8.2465 -    SDL_memset(&txi->invalid_area, 0, sizeof(txi->invalid_area));
  8.2466 -}
  8.2467 -
  8.2468 -/* vi: set ts=4 sw=4 expandtab: */
     9.1 --- a/src/video/glsdl/SDL_glsdl.h	Wed Jul 26 03:08:25 2006 +0000
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,39 +0,0 @@
     9.4 -/*
     9.5 -    SDL - Simple DirectMedia Layer
     9.6 -    Copyright (C) 1997-2006 Sam Lantinga
     9.7 -
     9.8 -    This library is free software; you can redistribute it and/or
     9.9 -    modify it under the terms of the GNU Lesser General Public
    9.10 -    License as published by the Free Software Foundation; either
    9.11 -    version 2.1 of the License, or (at your option) any later version.
    9.12 -
    9.13 -    This library is distributed in the hope that it will be useful,
    9.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    9.16 -    Lesser General Public License for more details.
    9.17 -
    9.18 -    You should have received a copy of the GNU Lesser General Public
    9.19 -    License along with this library; if not, write to the Free Software
    9.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    9.21 -
    9.22 -    Sam Lantinga
    9.23 -    slouken@libsdl.org
    9.24 -*/
    9.25 -#include "SDL_config.h"
    9.26 -
    9.27 -/*
    9.28 - * glSDL "SDL-over-OpenGL" video driver implemented by
    9.29 - * David Olofson <david@olofson.net> and
    9.30 - * Stephane Marchesin <stephane.marchesin@wanadoo.fr>
    9.31 - */
    9.32 -
    9.33 -#ifndef _SDL_gl_h
    9.34 -#define _SDL_gl_h
    9.35 -
    9.36 -#include "../SDL_sysvideo.h"
    9.37 -
    9.38 -/* Hidden "this" pointer for the video functions */
    9.39 -#define _THIS	SDL_VideoDevice *this
    9.40 -
    9.41 -#endif /* _SDL_gl_h */
    9.42 -/* vi: set ts=4 sw=4 expandtab: */