glSDL support SDL-1.3
authorSam Lantinga
Mon, 01 May 2006 06:58:33 +0000
branchSDL-1.3
changeset 1658e49147870aac
parent 1657 5b0805ceb50f
child 1659 14717b52abc0
glSDL support
Makefile.dc
configure.in
include/SDL_config.h.in
include/SDL_config_amiga.h
include/SDL_config_dreamcast.h
include/SDL_config_macos.h
include/SDL_config_macosx.h
include/SDL_config_win32.h
include/SDL_video.h
src/video/SDL_blit.c
src/video/SDL_glfuncs.h
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/bwindow/SDL_BWin.h
src/video/bwindow/SDL_sysvideo.cc
src/video/cybergfx/SDL_cgximage.c
src/video/cybergfx/SDL_cgxvideo.c
src/video/dc/SDL_dcvideo.c
src/video/gem/SDL_gemvideo.c
src/video/glsdl/SDL_glsdl.c
src/video/glsdl/SDL_glsdl.h
src/video/maccommon/SDL_macevents.c
src/video/macdsp/SDL_dspvideo.c
src/video/macrom/SDL_romvideo.c
src/video/photon/SDL_ph_image.c
src/video/photon/SDL_ph_modes.c
src/video/photon/SDL_ph_mouse.c
src/video/photon/SDL_ph_video.c
src/video/qtopia/SDL_sysvideo.cc
src/video/quartz/SDL_QuartzVideo.m
src/video/quartz/SDL_QuartzWM.m
src/video/quartz/SDL_QuartzWindow.m
src/video/wincommon/SDL_lowvideo.h
src/video/wincommon/SDL_sysevents.c
src/video/windib/SDL_dibvideo.c
src/video/windx5/SDL_dx5events.c
src/video/windx5/SDL_dx5video.c
src/video/x11/SDL_x11events.c
src/video/x11/SDL_x11image.c
src/video/x11/SDL_x11modes.c
src/video/x11/SDL_x11video.c
src/video/xbios/SDL_xbios.c
test/testblitspeed.c
     1.1 --- a/Makefile.dc	Fri Apr 28 16:55:41 2006 +0000
     1.2 +++ b/Makefile.dc	Mon May 01 06:58:33 2006 +0000
     1.3 @@ -55,6 +55,7 @@
     1.4  	src/video/dummy/SDL_nullevents.c \
     1.5  	src/video/dummy/SDL_nullmouse.c \
     1.6  	src/video/dummy/SDL_nullvideo.c \
     1.7 +	src/video/glsdl/SDL_glsdl.c \
     1.8  	src/video/SDL_blit.c \
     1.9  	src/video/SDL_blit_0.c \
    1.10  	src/video/SDL_blit_1.c \
     2.1 --- a/configure.in	Fri Apr 28 16:55:41 2006 +0000
     2.2 +++ b/configure.in	Mon May 01 06:58:33 2006 +0000
     2.3 @@ -1459,6 +1459,20 @@
     2.4      fi
     2.5  }
     2.6  
     2.7 +dnl Find glSDL
     2.8 +CheckglSDL()
     2.9 +{
    2.10 +    AC_ARG_ENABLE(video-glsdl,
    2.11 +[  --enable-video-glsdl    use glSDL video driver [default=yes]],
    2.12 +                  , enable_video_glsdl=yes)
    2.13 +    AC_MSG_CHECKING(for glSDL support)
    2.14 +    AC_MSG_RESULT($video_opengl)
    2.15 +    if test x$video_opengl = xyes -a x$enable_video_glsdl = xyes; then
    2.16 +        AC_DEFINE(SDL_VIDEO_DRIVER_GLSDL)
    2.17 +        SOURCES="$SOURCES $srcdir/src/video/glsdl/*.c"
    2.18 +    fi
    2.19 +}
    2.20 +
    2.21  dnl Check for Mesa offscreen rendering
    2.22  CheckAtariOSMesa()
    2.23  {
    2.24 @@ -2080,6 +2094,7 @@
    2.25          CheckQtopia
    2.26          CheckPicoGUI
    2.27          CheckOpenGLX11
    2.28 +        CheckglSDL
    2.29          CheckInputEvents
    2.30          CheckTslib
    2.31          CheckUSBHID
    2.32 @@ -2178,6 +2193,7 @@
    2.33          CheckPHOTON
    2.34          CheckX11
    2.35          CheckOpenGLX11
    2.36 +        CheckglSDL
    2.37          CheckPTHREAD
    2.38          # Set up files for the audio library
    2.39          if test x$enable_audio = xyes; then
    2.40 @@ -2215,6 +2231,7 @@
    2.41          CheckDummyAudio
    2.42          CheckWIN32
    2.43          CheckWIN32GL
    2.44 +        CheckglSDL
    2.45          CheckDIRECTX
    2.46          CheckNASM
    2.47          # Set up files for the audio library
    2.48 @@ -2279,6 +2296,7 @@
    2.49          CheckNASM
    2.50          CheckBWINDOW
    2.51          CheckBeGL
    2.52 +        CheckglSDL
    2.53          # Set up files for the audio library
    2.54          if test x$enable_audio = xyes; then
    2.55              AC_DEFINE(SDL_AUDIO_DRIVER_BAUDIO)
    2.56 @@ -2356,6 +2374,7 @@
    2.57          CheckX11
    2.58          CheckMacGL
    2.59          CheckOpenGLX11
    2.60 +        CheckglSDL
    2.61          CheckPTHREAD
    2.62          CheckAltivec
    2.63  
    2.64 @@ -2417,6 +2436,7 @@
    2.65          CheckAtariAudio
    2.66          CheckAtariLdg
    2.67          CheckAtariOSMesa
    2.68 +        CheckglSDL
    2.69          CheckPTH
    2.70          # Set up files for the audio library
    2.71          if test x$enable_threads = xyes -a x$enable_pth = xyes; then
     3.1 --- a/include/SDL_config.h.in	Fri Apr 28 16:55:41 2006 +0000
     3.2 +++ b/include/SDL_config.h.in	Mon May 01 06:58:33 2006 +0000
     3.3 @@ -262,6 +262,7 @@
     3.4  #undef SDL_VIDEO_DRIVER_GAPI
     3.5  #undef SDL_VIDEO_DRIVER_GEM
     3.6  #undef SDL_VIDEO_DRIVER_GGI
     3.7 +#undef SDL_VIDEO_DRIVER_GLSDL
     3.8  #undef SDL_VIDEO_DRIVER_IPOD
     3.9  #undef SDL_VIDEO_DRIVER_NANOX
    3.10  #undef SDL_VIDEO_DRIVER_OS2FS
     4.1 --- a/include/SDL_config_amiga.h	Fri Apr 28 16:55:41 2006 +0000
     4.2 +++ b/include/SDL_config_amiga.h	Mon May 01 06:58:33 2006 +0000
     4.3 @@ -73,6 +73,7 @@
     4.4  /* Enable various video drivers */
     4.5  #define SDL_VIDEO_DRIVER_CYBERGRAPHICS	1
     4.6  #define SDL_VIDEO_DRIVER_DUMMY	1
     4.7 +#define SDL_VIDEO_DRIVER_GLSDL	1
     4.8  
     4.9  /* Enable OpenGL support */
    4.10  #define SDL_VIDEO_OPENGL	1
     5.1 --- a/include/SDL_config_dreamcast.h	Fri Apr 28 16:55:41 2006 +0000
     5.2 +++ b/include/SDL_config_dreamcast.h	Mon May 01 06:58:33 2006 +0000
     5.3 @@ -102,5 +102,6 @@
     5.4  /* Enable various video drivers */
     5.5  #define SDL_VIDEO_DRIVER_DC	1
     5.6  #define SDL_VIDEO_DRIVER_DUMMY	1
     5.7 +#define SDL_VIDEO_DRIVER_GLSDL	1
     5.8  
     5.9  #endif /* _SDL_config_dreamcast_h */
     6.1 --- a/include/SDL_config_macos.h	Fri Apr 28 16:55:41 2006 +0000
     6.2 +++ b/include/SDL_config_macos.h	Mon May 01 06:58:33 2006 +0000
     6.3 @@ -90,6 +90,7 @@
     6.4  /* Enable various video drivers */
     6.5  #define SDL_VIDEO_DRIVER_DUMMY	1
     6.6  #define SDL_VIDEO_DRIVER_DRAWSPROCKET	1
     6.7 +#define SDL_VIDEO_DRIVER_GLSDL	1
     6.8  #define SDL_VIDEO_DRIVER_TOOLBOX	1
     6.9  
    6.10  /* Enable OpenGL support */
     7.1 --- a/include/SDL_config_macosx.h	Fri Apr 28 16:55:41 2006 +0000
     7.2 +++ b/include/SDL_config_macosx.h	Mon May 01 06:58:33 2006 +0000
     7.3 @@ -116,6 +116,7 @@
     7.4  
     7.5  /* Enable various video drivers */
     7.6  #define SDL_VIDEO_DRIVER_DUMMY	1
     7.7 +#define SDL_VIDEO_DRIVER_GLSDL	1
     7.8  #define SDL_VIDEO_DRIVER_QUARTZ	1
     7.9  
    7.10  /* Enable OpenGL support */
     8.1 --- a/include/SDL_config_win32.h	Fri Apr 28 16:55:41 2006 +0000
     8.2 +++ b/include/SDL_config_win32.h	Mon May 01 06:58:33 2006 +0000
     8.3 @@ -155,6 +155,9 @@
     8.4  #define SDL_VIDEO_DRIVER_DDRAW	1
     8.5  #endif
     8.6  #define SDL_VIDEO_DRIVER_DUMMY	1
     8.7 +#ifndef _WIN32_WCE
     8.8 +#define SDL_VIDEO_DRIVER_GLSDL	1
     8.9 +#endif
    8.10  #define SDL_VIDEO_DRIVER_WINDIB	1
    8.11  
    8.12  /* Enable OpenGL support */
     9.1 --- a/include/SDL_video.h	Fri Apr 28 16:55:41 2006 +0000
     9.2 +++ b/include/SDL_video.h	Mon May 01 06:58:33 2006 +0000
     9.3 @@ -124,7 +124,7 @@
     9.4  #define SDL_DOUBLEBUF	0x40000000	/* Set up double-buffered video mode */
     9.5  #define SDL_FULLSCREEN	0x80000000	/* Surface is a full screen display */
     9.6  #define SDL_OPENGL      0x00000002      /* Create an OpenGL rendering context */
     9.7 -#define SDL_OPENGLBLIT_OBSOLETE 0x0000000A /* Obsolete, do not use! */
     9.8 +#define SDL_INTERNALOPENGL 0x00000008   /* SDL uses OpenGL internally for this window */
     9.9  #define SDL_RESIZABLE	0x00000010	/* This video mode may be resized */
    9.10  #define SDL_NOFRAME	0x00000020	/* No window caption or edge frame */
    9.11  /* Used internally (read-only) */
    10.1 --- a/src/video/SDL_blit.c	Fri Apr 28 16:55:41 2006 +0000
    10.2 +++ b/src/video/SDL_blit.c	Mon May 01 06:58:33 2006 +0000
    10.3 @@ -281,7 +281,7 @@
    10.4  				video->CheckHWBlit(this, surface, surface->map->dst);
    10.5  			}
    10.6  	}
    10.7 -
    10.8 +	
    10.9  	/* Get the blit function index, based on surface mode */
   10.10  	/* { 0 = nothing, 1 = colorkey, 2 = alpha, 3 = colorkey+alpha } */
   10.11  	blit_index = 0;
    11.1 --- a/src/video/SDL_glfuncs.h	Fri Apr 28 16:55:41 2006 +0000
    11.2 +++ b/src/video/SDL_glfuncs.h	Mon May 01 06:58:33 2006 +0000
    11.3 @@ -30,7 +30,7 @@
    11.4  SDL_PROC_UNUSED(void,glColor3iv,(const GLint*))
    11.5  SDL_PROC_UNUSED(void,glColor3s,(GLshort,GLshort,GLshort))
    11.6  SDL_PROC_UNUSED(void,glColor3sv,(const GLshort*))
    11.7 -SDL_PROC_UNUSED(void,glColor3ub,(GLubyte,GLubyte,GLubyte))
    11.8 +SDL_PROC(void,glColor3ub,(GLubyte,GLubyte,GLubyte))
    11.9  SDL_PROC_UNUSED(void,glColor3ubv,(const GLubyte*))
   11.10  SDL_PROC_UNUSED(void,glColor3ui,(GLuint,GLuint,GLuint))
   11.11  SDL_PROC_UNUSED(void,glColor3uiv,(const GLuint*))
   11.12 @@ -46,7 +46,7 @@
   11.13  SDL_PROC_UNUSED(void,glColor4iv,(const GLint*))
   11.14  SDL_PROC_UNUSED(void,glColor4s,(GLshort,GLshort,GLshort,GLshort))
   11.15  SDL_PROC_UNUSED(void,glColor4sv,(const GLshort*))
   11.16 -SDL_PROC_UNUSED(void,glColor4ub,(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha))
   11.17 +SDL_PROC(void,glColor4ub,(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha))
   11.18  SDL_PROC_UNUSED(void,glColor4ubv,(const GLubyte *v))
   11.19  SDL_PROC_UNUSED(void,glColor4ui,(GLuint red, GLuint green, GLuint blue, GLuint alpha))
   11.20  SDL_PROC_UNUSED(void,glColor4uiv,(const GLuint *v))
   11.21 @@ -62,14 +62,14 @@
   11.22  SDL_PROC_UNUSED(void,glCopyTexSubImage2D,(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height))
   11.23  SDL_PROC_UNUSED(void,glCullFace,(GLenum mode))
   11.24  SDL_PROC_UNUSED(void,glDeleteLists,(GLuint list, GLsizei range))
   11.25 -SDL_PROC_UNUSED(void,glDeleteTextures,(GLsizei n, const GLuint *textures))
   11.26 +SDL_PROC(void,glDeleteTextures,(GLsizei n, const GLuint *textures))
   11.27  SDL_PROC_UNUSED(void,glDepthFunc,(GLenum func))
   11.28  SDL_PROC_UNUSED(void,glDepthMask,(GLboolean flag))
   11.29  SDL_PROC_UNUSED(void,glDepthRange,(GLclampd zNear, GLclampd zFar))
   11.30  SDL_PROC(void,glDisable,(GLenum cap))
   11.31  SDL_PROC_UNUSED(void,glDisableClientState,(GLenum array))
   11.32  SDL_PROC_UNUSED(void,glDrawArrays,(GLenum mode, GLint first, GLsizei count))
   11.33 -SDL_PROC_UNUSED(void,glDrawBuffer,(GLenum mode))
   11.34 +SDL_PROC(void,glDrawBuffer,(GLenum mode))
   11.35  SDL_PROC_UNUSED(void,glDrawElements,(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices))
   11.36  SDL_PROC_UNUSED(void,glDrawPixels,(GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels))
   11.37  SDL_PROC_UNUSED(void,glEdgeFlag,(GLboolean flag))
   11.38 @@ -92,7 +92,7 @@
   11.39  SDL_PROC_UNUSED(void,glEvalPoint1,(GLint i))
   11.40  SDL_PROC_UNUSED(void,glEvalPoint2,(GLint i, GLint j))
   11.41  SDL_PROC_UNUSED(void,glFeedbackBuffer,(GLsizei size, GLenum type, GLfloat *buffer))
   11.42 -SDL_PROC_UNUSED(void,glFinish,(void))
   11.43 +SDL_PROC(void,glFinish,(void))
   11.44  SDL_PROC(void,glFlush,(void))
   11.45  SDL_PROC_UNUSED(void,glFogf,(GLenum pname, GLfloat param))
   11.46  SDL_PROC_UNUSED(void,glFogfv,(GLenum pname, const GLfloat *params))
   11.47 @@ -105,9 +105,9 @@
   11.48  SDL_PROC_UNUSED(void,glGetBooleanv,(GLenum pname, GLboolean *params))
   11.49  SDL_PROC_UNUSED(void,glGetClipPlane,(GLenum plane, GLdouble *equation))
   11.50  SDL_PROC_UNUSED(void,glGetDoublev,(GLenum pname, GLdouble *params))
   11.51 -SDL_PROC_UNUSED(GLenum,glGetError,(void))
   11.52 +SDL_PROC(GLenum,glGetError,(void))
   11.53  SDL_PROC_UNUSED(void,glGetFloatv,(GLenum pname, GLfloat *params))
   11.54 -SDL_PROC_UNUSED(void,glGetIntegerv,(GLenum pname, GLint *params))
   11.55 +SDL_PROC(void,glGetIntegerv,(GLenum pname, GLint *params))
   11.56  SDL_PROC_UNUSED(void,glGetLightfv,(GLenum light, GLenum pname, GLfloat *params))
   11.57  SDL_PROC_UNUSED(void,glGetLightiv,(GLenum light, GLenum pname, GLint *params))
   11.58  SDL_PROC_UNUSED(void,glGetMapdv,(GLenum target, GLenum query, GLdouble *v))
   11.59 @@ -240,7 +240,7 @@
   11.60  SDL_PROC_UNUSED(void,glRasterPos4s,(GLshort x, GLshort y, GLshort z, GLshort w))
   11.61  SDL_PROC_UNUSED(void,glRasterPos4sv,(const GLshort *v))
   11.62  SDL_PROC_UNUSED(void,glReadBuffer,(GLenum mode))
   11.63 -SDL_PROC_UNUSED(void,glReadPixels,(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels))
   11.64 +SDL_PROC(void,glReadPixels,(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels))
   11.65  SDL_PROC_UNUSED(void,glRectd,(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2))
   11.66  SDL_PROC_UNUSED(void,glRectdv,(const GLdouble *v1, const GLdouble *v2))
   11.67  SDL_PROC_UNUSED(void,glRectf,(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2))
   11.68 @@ -311,7 +311,7 @@
   11.69  SDL_PROC_UNUSED(void,glTexParameteriv,(GLenum target, GLenum pname, const GLint *params))
   11.70  SDL_PROC_UNUSED(void,glTexSubImage1D,(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels))
   11.71  SDL_PROC(void,glTexSubImage2D,(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels))
   11.72 -SDL_PROC_UNUSED(void,glTranslated,(GLdouble x, GLdouble y, GLdouble z))
   11.73 +SDL_PROC(void,glTranslated,(GLdouble x, GLdouble y, GLdouble z))
   11.74  SDL_PROC_UNUSED(void,glTranslatef,(GLfloat x, GLfloat y, GLfloat z))
   11.75  SDL_PROC_UNUSED(void,glVertex2d,(GLdouble x, GLdouble y))
   11.76  SDL_PROC_UNUSED(void,glVertex2dv,(const GLdouble *v))
    12.1 --- a/src/video/SDL_sysvideo.h	Fri Apr 28 16:55:41 2006 +0000
    12.2 +++ b/src/video/SDL_sysvideo.h	Mon May 01 06:58:33 2006 +0000
    12.3 @@ -119,7 +119,7 @@
    12.4  
    12.5  	/* The pixel format used when SDL_CreateRGBSurface creates SDL_HWSURFACEs with alpha */
    12.6  	SDL_PixelFormat* displayformatalphapixel;
    12.7 -	
    12.8 +
    12.9  	/* Allocates a surface in video memory */
   12.10  	int (*AllocHWSurface)(_THIS, SDL_Surface *surface);
   12.11  
   12.12 @@ -407,6 +407,9 @@
   12.13  #if SDL_VIDEO_DRIVER_DUMMY
   12.14  extern VideoBootStrap DUMMY_bootstrap;
   12.15  #endif
   12.16 +#if SDL_VIDEO_DRIVER_GLSDL
   12.17 +extern VideoBootStrap glSDL_bootstrap;
   12.18 +#endif
   12.19  
   12.20  /* This is the current video device */
   12.21  extern SDL_VideoDevice *current_video;
    13.1 --- a/src/video/SDL_video.c	Fri Apr 28 16:55:41 2006 +0000
    13.2 +++ b/src/video/SDL_video.c	Mon May 01 06:58:33 2006 +0000
    13.3 @@ -123,6 +123,9 @@
    13.4  #if SDL_VIDEO_DRIVER_DUMMY
    13.5  	&DUMMY_bootstrap,
    13.6  #endif
    13.7 +#if SDL_VIDEO_DRIVER_GLSDL
    13.8 +	&glSDL_bootstrap,
    13.9 +#endif
   13.10  	NULL
   13.11  };
   13.12  
   13.13 @@ -575,12 +578,6 @@
   13.14  	int is_opengl;
   13.15  	SDL_GrabMode saved_grab;
   13.16  
   13.17 -	/* Handle obsolete flags */
   13.18 -	if ( (flags & SDL_OPENGLBLIT_OBSOLETE) == SDL_OPENGLBLIT_OBSOLETE ) {
   13.19 -		SDL_SetError("SDL_OPENGLBLIT is no longer supported");
   13.20 -		return(NULL);
   13.21 -	}
   13.22 -
   13.23  	/* Start up the video driver, if necessary..
   13.24  	   WARNING: This is the only function protected this way!
   13.25  	 */
   13.26 @@ -613,8 +610,12 @@
   13.27  	}
   13.28  
   13.29  	/* Check the requested flags */
   13.30 -	/* There's no palette in > 8 bits-per-pixel mode */
   13.31 +	if ( flags & SDL_INTERNALOPENGL ) {
   13.32 +		SDL_SetError("SDL_INTERNALOPENGL is for internal use only");
   13.33 +		return(NULL);
   13.34 +	}
   13.35  	if ( video_bpp > 8 ) {
   13.36 +		/* There's no palette in > 8 bits-per-pixel mode */
   13.37  		flags &= ~SDL_HWPALETTE;
   13.38  	}
   13.39  #if 0
   13.40 @@ -632,6 +633,8 @@
   13.41  	if ( is_opengl ) {
   13.42  		/* These flags are for 2D video modes only */
   13.43  		flags &= ~(SDL_HWSURFACE|SDL_DOUBLEBUF);
   13.44 +		/* This flag tells the backends to treat the surface accordingly */
   13.45 +		flags |= SDL_INTERNALOPENGL;
   13.46  	}
   13.47  
   13.48  	/* Reset the keyboard here so event callbacks can run */
   13.49 @@ -674,7 +677,7 @@
   13.50  #endif
   13.51  
   13.52  	    /* Sam - If we asked for OpenGL mode, and didn't get it, fail */
   13.53 -	    if ( is_opengl && !(mode->flags & SDL_OPENGL) ) {
   13.54 +	    if ( is_opengl && !(mode->flags & SDL_INTERNALOPENGL) ) {
   13.55  		mode = NULL;
   13.56  		SDL_SetError("OpenGL not available");
   13.57  	    }
   13.58 @@ -752,7 +755,7 @@
   13.59  
   13.60  #if SDL_VIDEO_OPENGL
   13.61  	/* Load GL symbols (before MakeCurrent, where we need glGetString). */
   13.62 -	if ( flags & SDL_OPENGL ) {
   13.63 +	if ( flags & SDL_INTERNALOPENGL ) {
   13.64  
   13.65  #if defined(__QNXNTO__) && (_NTO_VERSION < 630)
   13.66  #define __SDL_NOGETPROCADDR__
   13.67 @@ -779,7 +782,7 @@
   13.68  #endif /* SDL_VIDEO_OPENGL */
   13.69  
   13.70  	/* If we're running OpenGL, make the context current */
   13.71 -	if ( (video->screen->flags & SDL_OPENGL) &&
   13.72 +	if ( (video->screen->flags & SDL_INTERNALOPENGL) &&
   13.73  	      video->GL_MakeCurrent ) {
   13.74  		if ( video->GL_MakeCurrent(this) < 0 ) {
   13.75  			return(NULL);
   13.76 @@ -1431,7 +1434,7 @@
   13.77  	SDL_VideoDevice *video = current_video;
   13.78  	SDL_VideoDevice *this = current_video;
   13.79  
   13.80 -	if ( video->screen->flags & SDL_OPENGL ) {
   13.81 +	if ( video->screen->flags & SDL_INTERNALOPENGL ) {
   13.82  		video->GL_SwapBuffers(this);
   13.83  	} else {
   13.84  		SDL_SetError("OpenGL video mode has not been set");
    14.1 --- a/src/video/bwindow/SDL_BWin.h	Fri Apr 28 16:55:41 2006 +0000
    14.2 +++ b/src/video/bwindow/SDL_BWin.h	Mon May 01 06:58:33 2006 +0000
    14.3 @@ -219,7 +219,7 @@
    14.4  
    14.5  		retval = 0;
    14.6  		Lock();
    14.7 -		if ( flags & SDL_OPENGL ) {
    14.8 +		if ( flags & SDL_INTERNALOPENGL ) {
    14.9  #if SDL_VIDEO_OPENGL
   14.10  			if ( SDL_GLView == NULL ) {
   14.11  				SDL_GLView = new BGLView(Bounds(), "SDL GLView",
    15.1 --- a/src/video/bwindow/SDL_sysvideo.cc	Fri Apr 28 16:55:41 2006 +0000
    15.2 +++ b/src/video/bwindow/SDL_sysvideo.cc	Mon May 01 06:58:33 2006 +0000
    15.3 @@ -525,7 +525,7 @@
    15.4  		current->flags |= SDL_NOFRAME;
    15.5  		SDL_Win->SetLook(B_NO_BORDER_WINDOW_LOOK);
    15.6  	} else {
    15.7 -		if ( (flags & SDL_RESIZABLE) && !(flags & SDL_OPENGL) )  {
    15.8 +		if ( (flags & SDL_RESIZABLE) && !(flags & SDL_INTERNALOPENGL) )  {
    15.9  			current->flags |= SDL_RESIZABLE;
   15.10  			/* We don't want opaque resizing (TM). :-) */
   15.11  			SDL_Win->SetFlags(B_OUTLINE_RESIZE);
   15.12 @@ -534,8 +534,8 @@
   15.13  		}
   15.14  	}
   15.15  
   15.16 -	if ( flags & SDL_OPENGL ) {
   15.17 -		current->flags |= SDL_OPENGL;
   15.18 +	if ( flags & SDL_INTERNALOPENGL ) {
   15.19 +		current->flags |= SDL_INTERNALOPENGL;
   15.20  		current->pitch = 0;
   15.21  		current->pixels = NULL;
   15.22  		_this->UpdateRects = NULL;
    16.1 --- a/src/video/cybergfx/SDL_cgximage.c	Fri Apr 28 16:55:41 2006 +0000
    16.2 +++ b/src/video/cybergfx/SDL_cgximage.c	Mon May 01 06:58:33 2006 +0000
    16.3 @@ -135,7 +135,7 @@
    16.4  
    16.5  	CGX_DestroyImage(this, screen);
    16.6  
    16.7 -	if ( flags & SDL_OPENGL ) {  /* No image when using GL */
    16.8 +	if ( flags & SDL_INTERNALOPENGL ) {  /* No image when using GL */
    16.9          	retval = 0;
   16.10  	} else {
   16.11  		retval = CGX_SetupImage(this, screen);
    17.1 --- a/src/video/cybergfx/SDL_cgxvideo.c	Fri Apr 28 16:55:41 2006 +0000
    17.2 +++ b/src/video/cybergfx/SDL_cgxvideo.c	Mon May 01 06:58:33 2006 +0000
    17.3 @@ -598,7 +598,7 @@
    17.4  
    17.5  		/* Clean up OpenGL */
    17.6  		if ( screen ) {
    17.7 -		screen->flags &= ~SDL_OPENGL;
    17.8 +		screen->flags &= ~SDL_INTERNALOPENGL;
    17.9  		}
   17.10  
   17.11  		if ( screen && (screen->flags & SDL_FULLSCREEN) ) {
   17.12 @@ -687,7 +687,7 @@
   17.13  /* questo l'ho spostato nell'apertura dello schermo, in quanto su Amiga le finestre
   17.14     hanno il pixel mode degli schermi.
   17.15   */
   17.16 -	/*if ( flags & SDL_OPENGL ) {
   17.17 +	/*if ( flags & SDL_INTERNALOPENGL ) {
   17.18  		SDL_SetError("OpenGL not supported by the Amiga SDL!");
   17.19  		return -1;
   17.20  	}
   17.21 @@ -800,7 +800,7 @@
   17.22  			{
   17.23  				/* Create GimmeZeroZero window when OpenGL is used */
   17.24  				unsigned long gzz = FALSE;
   17.25 -				if( flags & SDL_OPENGL ) {
   17.26 +				if( flags & SDL_INTERNALOPENGL ) {
   17.27  					gzz = TRUE;
   17.28  				}
   17.29  
   17.30 @@ -840,7 +840,7 @@
   17.31  
   17.32  	/* Set our colormaps when not setting a GL mode */
   17.33  /*
   17.34 -	if ( ! (flags & SDL_OPENGL) ) {
   17.35 +	if ( ! (flags & SDL_INTERNALOPENGL) ) {
   17.36  		XSetWindowColormap(SDL_Display, SDL_Window, SDL_XColorMap);
   17.37  	}
   17.38  */
   17.39 @@ -861,18 +861,18 @@
   17.40  	CGX_ResizeImage(this, screen, flags);
   17.41  
   17.42  	/* Make OpenGL Context if needed*/
   17.43 -	if(flags & SDL_OPENGL) {
   17.44 +	if(flags & SDL_INTERNALOPENGL) {
   17.45  		if(this->gl_data->gl_active == 0) {
   17.46  			if(CGX_GL_Init(this) < 0)
   17.47  				return -1;
   17.48  			else
   17.49 -				screen->flags |= SDL_OPENGL;
   17.50 +				screen->flags |= SDL_INTERNALOPENGL;
   17.51  		}
   17.52  		else {
   17.53  			if(CGX_GL_Update(this) < 0)
   17.54  				return -1;
   17.55  			else
   17.56 -				screen->flags |= SDL_OPENGL;
   17.57 +				screen->flags |= SDL_INTERNALOPENGL;
   17.58  		}
   17.59  	}
   17.60  }
   17.61 @@ -1066,7 +1066,7 @@
   17.62  	/* Set up the X11 window */
   17.63  	saved_flags = current->flags;
   17.64  
   17.65 -	if (SDL_Window && (saved_flags&SDL_OPENGL) == (flags&SDL_OPENGL)
   17.66 +	if (SDL_Window && (saved_flags&SDL_INTERNALOPENGL) == (flags&SDL_INTERNALOPENGL)
   17.67  	    && bpp == current->format->BitsPerPixel && !needcreate) {
   17.68  		if (CGX_ResizeWindow(this, current, width, height, flags) < 0) {
   17.69  			current = NULL;
   17.70 @@ -1082,7 +1082,7 @@
   17.71  #if 0
   17.72  	/* Set up the new mode framebuffer */
   17.73  	if ( ((current->w != width) || (current->h != height)) ||
   17.74 -             ((saved_flags&SDL_OPENGL) != (flags&SDL_OPENGL)) ) {
   17.75 +             ((saved_flags&SDL_INTERNALOPENGL) != (flags&SDL_INTERNALOPENGL)) ) {
   17.76  		current->w = width;
   17.77  		current->h = height;
   17.78  		current->pitch = SDL_CalculatePitch(current);
    18.1 --- a/src/video/dc/SDL_dcvideo.c	Fri Apr 28 16:55:41 2006 +0000
    18.2 +++ b/src/video/dc/SDL_dcvideo.c	Mon May 01 06:58:33 2006 +0000
    18.3 @@ -167,7 +167,7 @@
    18.4  	case 16:
    18.5  		return &vid_modes;
    18.6  	case 32:
    18.7 -		if (!(flags & SDL_OPENGL))
    18.8 +		if (!(flags & SDL_INTERNALOPENGL))
    18.9  		return &vid_modes;
   18.10  	default:
   18.11  		return NULL;
   18.12 @@ -220,7 +220,7 @@
   18.13  		Gmask = 0x0000ff00;
   18.14  		Bmask = 0x000000ff;
   18.15  #if SDL_VIDEO_OPENGL
   18.16 -		if (!(flags & SDL_OPENGL))
   18.17 +		if (!(flags & SDL_INTERNALOPENGL))
   18.18  #endif
   18.19  		break;
   18.20  	default:
   18.21 @@ -252,9 +252,9 @@
   18.22  	current->pixels = vram_s;
   18.23  
   18.24  #if SDL_VIDEO_OPENGL
   18.25 -	if (flags & SDL_OPENGL) {
   18.26 +	if (flags & SDL_INTERNALOPENGL) {
   18.27  		this->gl_config.driver_loaded = 1;
   18.28 -		current->flags = SDL_FULLSCREEN | SDL_OPENGL;
   18.29 +		current->flags = SDL_FULLSCREEN | SDL_INTERNALOPENGL;
   18.30  		current->pixels = NULL;
   18.31  		pvr_inited = 1;
   18.32  		pvr_init(&params);
    19.1 --- a/src/video/gem/SDL_gemvideo.c	Fri Apr 28 16:55:41 2006 +0000
    19.2 +++ b/src/video/gem/SDL_gemvideo.c	Mon May 01 06:58:33 2006 +0000
    19.3 @@ -804,14 +804,14 @@
    19.4  	}
    19.5  
    19.6  #if SDL_VIDEO_OPENGL
    19.7 -	if (flags & SDL_OPENGL) {
    19.8 +	if (flags & SDL_INTERNALOPENGL) {
    19.9  		if (!SDL_AtariGL_Init(this, current)) {
   19.10  			GEM_FreeBuffers(this);
   19.11  			SDL_SetError("Can not create OpenGL context");
   19.12  			return NULL;
   19.13  		}
   19.14  
   19.15 -		modeflags |= SDL_OPENGL;
   19.16 +		modeflags |= SDL_INTERNALOPENGL;
   19.17  	}
   19.18  #endif
   19.19  
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/src/video/glsdl/SDL_glsdl.c	Mon May 01 06:58:33 2006 +0000
    20.3 @@ -0,0 +1,2573 @@
    20.4 +/*
    20.5 +    SDL - Simple DirectMedia Layer
    20.6 +    Copyright (C) 1997-2006 Sam Lantinga
    20.7 +
    20.8 +    This library is free software; you can redistribute it and/or
    20.9 +    modify it under the terms of the GNU Lesser General Public
   20.10 +    License as published by the Free Software Foundation; either
   20.11 +    version 2.1 of the License, or (at your option) any later version.
   20.12 +
   20.13 +    This library is distributed in the hope that it will be useful,
   20.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   20.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   20.16 +    Lesser General Public License for more details.
   20.17 +
   20.18 +    You should have received a copy of the GNU Lesser General Public
   20.19 +    License along with this library; if not, write to the Free Software
   20.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   20.21 +
   20.22 +    Sam Lantinga
   20.23 +    slouken@libsdl.org
   20.24 +*/
   20.25 +#include "SDL_config.h"
   20.26 +
   20.27 +/*
   20.28 + * glSDL "SDL-over-OpenGL" video driver implemented by
   20.29 + * David Olofson <david@olofson.net> and
   20.30 + * Stephane Marchesin <stephane.marchesin@wanadoo.fr>
   20.31 + */
   20.32 +#include <math.h>
   20.33 +
   20.34 +#include "SDL.h"
   20.35 +#include "SDL_error.h"
   20.36 +#include "SDL_video.h"
   20.37 +#include "SDL_mouse.h"
   20.38 +#include "../SDL_sysvideo.h"
   20.39 +#include "../SDL_pixels_c.h"
   20.40 +
   20.41 +#include "SDL_glsdl.h"
   20.42 +
   20.43 +#undef	DEBUG_GLSDL
   20.44 +#undef	DEBUG_GLSDL_CHOP
   20.45 +#define	FAKE_MAXTEXSIZE	256
   20.46 +#undef GLSDL_GRAPHICAL_DEBUG
   20.47 +
   20.48 +/* Initialization/Query functions */
   20.49 +
   20.50 +/* Hardware surface functions */
   20.51 +static int glSDL_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
   20.52 +static int glSDL_AllocHWSurface(_THIS, SDL_Surface *surface);
   20.53 +static int glSDL_LockHWSurface(_THIS, SDL_Surface *surface);
   20.54 +static int glSDL_FlipHWSurface(_THIS, SDL_Surface *surface);
   20.55 +static void glSDL_UnlockHWSurface(_THIS, SDL_Surface *surface);
   20.56 +static void glSDL_FreeHWSurface(_THIS, SDL_Surface *surface);
   20.57 +static int glSDL_FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color);
   20.58 +static int glSDL_CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst);
   20.59 +static int glSDL_SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key);
   20.60 +static int glSDL_SetHWAlpha(_THIS, SDL_Surface *surface, Uint8 alpha);
   20.61 +static int glSDL_VideoInit(_THIS, SDL_PixelFormat *vformat);
   20.62 +static SDL_Rect **glSDL_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
   20.63 +static void glSDL_VideoQuit(_THIS);
   20.64 +static void glSDL_UpdateRects(_THIS, int numrects, SDL_Rect *rects);
   20.65 +static SDL_Surface* glSDL_SetVideoMode(_THIS, SDL_Surface *current,int width, int height, int bpp, Uint32 flags);
   20.66 +
   20.67 +#define	IS_GLSDL_SURFACE(s)	((s) && glSDL_GetTexInfo(s))
   20.68 +
   20.69 +#define	LOGIC_W(s)	( IS_GLSDL_SURFACE(this,s) ? TEXINFO(s)->lw : (s)->w )
   20.70 +#define	LOGIC_H(s)	( IS_GLSDL_SURFACE(this,s) ? TEXINFO(s)->lh : (s)->h )
   20.71 +
   20.72 +#define	GLSDL_NOTEX	(~0)
   20.73 +
   20.74 +/*
   20.75 + * Special version for glSDL, which ignores the fake SDL_HWSURFACE
   20.76 + * flags, so we don't have SDL calling us back whenever we want to
   20.77 + * do some internal blitting...
   20.78 + */
   20.79 +static void glSDL_SoftBlit(SDL_Surface *src, SDL_Rect *srcrect,
   20.80 +		SDL_Surface *dst, SDL_Rect *dstrect)
   20.81 +{
   20.82 +	SDL_BlitInfo info;
   20.83 +
   20.84 +	if(srcrect)
   20.85 +		if(!srcrect->w || !srcrect->h)
   20.86 +			return;
   20.87 +
   20.88 +	/* Check to make sure the blit mapping is valid */
   20.89 +	if ( (src->map->dst != dst) ||
   20.90 +			(src->map->dst->format_version !=
   20.91 +			 src->map->format_version) )
   20.92 +		if ( SDL_MapSurface(src, dst) < 0 )
   20.93 +			return;
   20.94 +
   20.95 +	/* Set up the blit information */
   20.96 +	if(srcrect)
   20.97 +	{
   20.98 +		info.s_pixels = (Uint8 *) src->pixels +
   20.99 +			(Uint16) srcrect->y * src->pitch +
  20.100 +			(Uint16) srcrect->x * src->format->BytesPerPixel;
  20.101 +		info.s_width = srcrect->w;
  20.102 +		info.s_height = srcrect->h;
  20.103 +	}
  20.104 +	else
  20.105 +	{
  20.106 +		info.s_pixels = (Uint8 *) src->pixels;
  20.107 +		info.s_width = src->w;
  20.108 +		info.s_height = src->h;
  20.109 +	}
  20.110 +	info.s_skip = src->pitch - info.s_width * src->format->BytesPerPixel;
  20.111 +	if(dstrect)
  20.112 +	{
  20.113 +		info.d_pixels = (Uint8 *) dst->pixels +
  20.114 +			(Uint16) dstrect->y * dst->pitch +
  20.115 +			(Uint16) dstrect->x * dst->format->BytesPerPixel;
  20.116 +		/*
  20.117 +		 * NOTE: SDL_SoftBlit() uses the 'dstrect' for this!
  20.118 +		 *       This version is more like SDL_BlitSurface().
  20.119 +		 */
  20.120 +		info.d_width = srcrect->w;
  20.121 +		info.d_height = srcrect->h;
  20.122 +	}
  20.123 +	else
  20.124 +	{
  20.125 +		info.d_pixels = (Uint8 *) dst->pixels;
  20.126 +		info.d_width = dst->w;
  20.127 +		info.d_height = dst->h;
  20.128 +	}
  20.129 +	info.d_skip = dst->pitch - info.d_width * dst->format->BytesPerPixel;
  20.130 +	info.aux_data = src->map->sw_data->aux_data;
  20.131 +	info.src = src->format;
  20.132 +	info.table = src->map->table;
  20.133 +	info.dst = dst->format;
  20.134 +
  20.135 +	src->map->sw_data->blit(&info);
  20.136 +}
  20.137 +
  20.138 +
  20.139 +/* 
  20.140 + * Another special version. Doesn't lock/unlock, and doesn't mess
  20.141 + * with flags and stuff. It just converts the surface, period.
  20.142 + * Does not convert into palletized formats.
  20.143 + */
  20.144 +static SDL_Surface *glSDL_ConvertSurface (SDL_Surface *surface,
  20.145 +		SDL_PixelFormat *format, Uint32 flags)
  20.146 +{
  20.147 +	SDL_Surface *convert;
  20.148 +	Uint32 colorkey = 0;
  20.149 +	Uint8 alpha = 0;
  20.150 +	Uint32 surface_flags;
  20.151 +	SDL_Rect bounds;
  20.152 +
  20.153 +	/* Create a new surface with the desired format */
  20.154 +	convert = SDL_CreateRGBSurface(flags,
  20.155 +			surface->w, surface->h, format->BitsPerPixel,
  20.156 +			format->Rmask, format->Gmask, format->Bmask, format->Amask);
  20.157 +	if ( convert == NULL ) {
  20.158 +		return(NULL);
  20.159 +	}
  20.160 +
  20.161 +	/* Save the original surface color key and alpha */
  20.162 +	surface_flags = surface->flags;
  20.163 +	if ( (surface_flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) {
  20.164 +		/* Convert colourkeyed surfaces to RGBA if requested */
  20.165 +		if((flags & SDL_SRCCOLORKEY) != SDL_SRCCOLORKEY
  20.166 +				&& format->Amask) {
  20.167 +			surface_flags &= ~SDL_SRCCOLORKEY;
  20.168 +		} else {
  20.169 +			colorkey = surface->format->colorkey;
  20.170 +			SDL_SetColorKey(surface, 0, 0);
  20.171 +		}
  20.172 +	}
  20.173 +	if ( (surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
  20.174 +		/* Copy over the alpha channel to RGBA if requested */
  20.175 +		if ( format->Amask ) {
  20.176 +			surface->flags &= ~SDL_SRCALPHA;
  20.177 +		} else {
  20.178 +			alpha = surface->format->alpha;
  20.179 +			SDL_SetAlpha(surface, 0, 0);
  20.180 +		}
  20.181 +	}
  20.182 +
  20.183 +	/* Copy over the image data */
  20.184 +	bounds.x = 0;
  20.185 +	bounds.y = 0;
  20.186 +	bounds.w = surface->w;
  20.187 +	bounds.h = surface->h;
  20.188 +	glSDL_SoftBlit(surface, &bounds, convert, &bounds);
  20.189 +
  20.190 +	/* Clean up the original surface, and update converted surface */
  20.191 +	if ( convert != NULL ) {
  20.192 +		SDL_SetClipRect(convert, &surface->clip_rect);
  20.193 +	}
  20.194 +	if ( (surface_flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) {
  20.195 +		Uint32 cflags = surface_flags&(SDL_SRCCOLORKEY|SDL_RLEACCELOK);
  20.196 +		if ( convert != NULL ) {
  20.197 +			Uint8 keyR, keyG, keyB;
  20.198 +
  20.199 +			SDL_GetRGB(colorkey,surface->format,&keyR,&keyG,&keyB);
  20.200 +			SDL_SetColorKey(convert, cflags|(flags&SDL_RLEACCELOK),
  20.201 +					SDL_MapRGB(convert->format, keyR, keyG, keyB));
  20.202 +		}
  20.203 +		SDL_SetColorKey(surface, cflags, colorkey);
  20.204 +	}
  20.205 +	if ( (surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
  20.206 +		Uint32 aflags = surface_flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
  20.207 +		if ( convert != NULL ) {
  20.208 +			SDL_SetAlpha(convert, aflags|(flags&SDL_RLEACCELOK),
  20.209 +					alpha);
  20.210 +		}
  20.211 +		if ( format->Amask ) {
  20.212 +			surface->flags |= SDL_SRCALPHA;
  20.213 +		} else {
  20.214 +			SDL_SetAlpha(surface, aflags, alpha);
  20.215 +		}
  20.216 +	}
  20.217 +
  20.218 +	/* We're ready to go! */
  20.219 +	return(convert);
  20.220 +}
  20.221 +
  20.222 +
  20.223 +/*----------------------------------------------------------
  20.224 +  Some OpenGL function wrappers
  20.225 +  ----------------------------------------------------------*/
  20.226 +
  20.227 +static struct
  20.228 +{
  20.229 +	int	do_blend;
  20.230 +	int	do_texture;
  20.231 +	GLuint	texture;
  20.232 +	GLenum	sfactor, dfactor;
  20.233 +} glstate;
  20.234 +
  20.235 +static void glSDL_reset(void)
  20.236 +{
  20.237 +	glstate.do_blend = -1;
  20.238 +	glstate.do_blend = -1;
  20.239 +	glstate.texture = GLSDL_NOTEX;
  20.240 +	glstate.sfactor = 0xffffffff;
  20.241 +	glstate.dfactor = 0xffffffff;
  20.242 +}
  20.243 +
  20.244 +static __inline__ void glSDL_do_blend(_THIS, int on)
  20.245 +{
  20.246 +	if(glstate.do_blend == on)
  20.247 +		return;
  20.248 +
  20.249 +	if(on)
  20.250 +		this->glEnable(GL_BLEND);
  20.251 +	else
  20.252 +		this->glDisable(GL_BLEND);
  20.253 +	glstate.do_blend = on;
  20.254 +}
  20.255 +
  20.256 +static __inline__ void glSDL_do_texture(_THIS, int on)
  20.257 +{
  20.258 +	if(glstate.do_texture == on)
  20.259 +		return;
  20.260 +
  20.261 +	if(on)
  20.262 +		this->glEnable(GL_TEXTURE_2D);
  20.263 +	else
  20.264 +		this->glDisable(GL_TEXTURE_2D);
  20.265 +	glstate.do_texture = on;
  20.266 +}
  20.267 +
  20.268 +static __inline__ void glSDL_blendfunc(_THIS, GLenum sfactor, GLenum dfactor)
  20.269 +{
  20.270 +	if((sfactor == glstate.sfactor) && (dfactor == glstate.dfactor))
  20.271 +		return;
  20.272 +
  20.273 +	this->glBlendFunc(sfactor, dfactor);
  20.274 +
  20.275 +	glstate.sfactor = sfactor;
  20.276 +	glstate.dfactor = dfactor;
  20.277 +}
  20.278 +
  20.279 +static __inline__ void glSDL_texture(_THIS, GLuint tx)
  20.280 +{
  20.281 +	if(tx == glstate.texture)
  20.282 +		return;
  20.283 +
  20.284 +	this->glBindTexture(GL_TEXTURE_2D, tx);
  20.285 +	glstate.texture = tx;
  20.286 +}
  20.287 +
  20.288 +
  20.289 +
  20.290 +
  20.291 +/*----------------------------------------------------------
  20.292 +  glSDL specific data types
  20.293 +  ----------------------------------------------------------*/
  20.294 +
  20.295 +typedef enum
  20.296 +{
  20.297 +	GLSDL_TM_SINGLE,
  20.298 +	GLSDL_TM_HORIZONTAL,
  20.299 +	GLSDL_TM_VERTICAL,
  20.300 +	GLSDL_TM_HUGE
  20.301 +} GLSDL_TileModes;
  20.302 +
  20.303 +
  20.304 +typedef struct private_hwdata
  20.305 +{
  20.306 +	/* Size of surface in logic screen pixels */
  20.307 +	int		lw, lh;
  20.308 +
  20.309 +	int		textures;
  20.310 +	GLuint		*texture;
  20.311 +	int		texsize;	/* width/height of OpenGL texture */
  20.312 +	GLSDL_TileModes	tilemode;
  20.313 +	int		tilew, tileh;	/* At least one must equal texsize! */
  20.314 +	int		tilespertex;
  20.315 +	SDL_Rect	virt;		/* Total size of assembled surface */
  20.316 +
  20.317 +	/* Area of surface to upload when/after unlocking */
  20.318 +	SDL_Rect	invalid_area;
  20.319 +
  20.320 +	int		temporary;	/* Throw away after one use. */
  20.321 +
  20.322 +	SDL_Surface*	next;		/* The next Surface in our linked list of hardware surfaces ; == NULL if first surface */
  20.323 +	SDL_Surface*	prev;		/* The prev Surface in our linked list of hardware surfaces ; == NULL if last surface */
  20.324 +} private_hwdata;
  20.325 +
  20.326 +/* some function prototypes */
  20.327 +static void glSDL_Invalidate(SDL_Surface *surface, SDL_Rect *area);
  20.328 +static void glSDL_SetLogicSize(_THIS, SDL_Surface *surface, int w, int h);
  20.329 +static private_hwdata *glSDL_UploadSurface(_THIS, SDL_Surface *surface);
  20.330 +static private_hwdata *glSDL_GetTexInfo(SDL_Surface *surface);
  20.331 +static void glSDL_init_formats(_THIS);
  20.332 +static private_hwdata *glSDL_AddTexInfo(_THIS, SDL_Surface *surface);
  20.333 +static void glSDL_RemoveTexInfo(_THIS, SDL_Surface *surface);
  20.334 +static void glSDL_UnloadTexture(_THIS, private_hwdata *txi);
  20.335 +static int glSDL_BlitGL(_THIS, SDL_Surface *src,
  20.336 +		SDL_Rect *srcrect, SDL_Rect *dstrect);
  20.337 +
  20.338 +/* some variables */
  20.339 +static GLint maxtexsize = -1;
  20.340 +static SDL_PixelFormat *RGBfmt = NULL;
  20.341 +static SDL_PixelFormat *RGBAfmt = NULL;
  20.342 +static void *mirrorbuf = NULL;
  20.343 +/* the raw 888 opengl surface, hidden from the application */
  20.344 +SDL_Surface* OpenGL_Surface;
  20.345 +
  20.346 +/* pointer to the beggining of the list used for memory allocation */
  20.347 +SDL_Surface* first = NULL;
  20.348 +
  20.349 +#ifdef DEBUG_GLSDL
  20.350 +static __inline__ int GLERET(const char *txt)
  20.351 +{
  20.352 +	fprintf(stderr, "glSDL ERROR: '%s'\n", txt);
  20.353 +	return -1;
  20.354 +}
  20.355 +static __inline__ void GLERR(const char *txt)
  20.356 +{
  20.357 +	fprintf(stderr, "glSDL ERROR: '%s'\n", txt);
  20.358 +}
  20.359 +#else
  20.360 +#define	GLERET(x)	(-1)
  20.361 +#define	GLERR(x)
  20.362 +#endif
  20.363 +
  20.364 +static SDL_VideoDevice underlying_device;
  20.365 +static int old_screen_flags;
  20.366 +
  20.367 +/* 
  20.368 + * List of video drivers known to support OpenGL 
  20.369 + * The purpose of this is to make glSDL "portable" across
  20.370 + * all video backends that support OpenGL
  20.371 + */
  20.372 +static VideoBootStrap *opengl_bootstrap =
  20.373 +#if SDL_VIDEO_DRIVER_QUARTZ
  20.374 +	&QZ_bootstrap;
  20.375 +#elif SDL_VIDEO_DRIVER_X11
  20.376 +	&X11_bootstrap;
  20.377 +#elif SDL_VIDEO_DRIVER_WINDIB
  20.378 +	&WINDIB_bootstrap;
  20.379 +#elif SDL_VIDEO_DRIVER_BWINDOW
  20.380 +	&BWINDOW_bootstrap;
  20.381 +#elif SDL_VIDEO_DRIVER_TOOLBOX
  20.382 +	&TOOLBOX_bootstrap;
  20.383 +#elif SDL_VIDEO_DRIVER_CYBERGRAPHICS
  20.384 +	&CGX_bootstrap;
  20.385 +#elif SDL_VIDEO_DRIVER_PHOTON
  20.386 +	&ph_bootstrap;
  20.387 +#elif SDL_VIDEO_DRIVER_DC
  20.388 +	&DC_bootstrap;
  20.389 +#else
  20.390 +	NULL;
  20.391 +#endif
  20.392 +
  20.393 +static int glSDL_Available(void)
  20.394 +{
  20.395 +#ifdef DEBUG_GLSDL
  20.396 +	fprintf(stderr,"available\n");
  20.397 +#endif
  20.398 +	if (opengl_bootstrap==NULL)
  20.399 +		return 0;
  20.400 +	return (opengl_bootstrap->available());
  20.401 +}
  20.402 +
  20.403 +static void glSDL_DeleteDevice(SDL_VideoDevice *device)
  20.404 +{
  20.405 +	SDL_free(device->hidden);
  20.406 +	SDL_free(device);
  20.407 +}
  20.408 +
  20.409 +/* Create a glSDL device */
  20.410 +static SDL_VideoDevice* glSDL_CreateDevice(int devindex)
  20.411 +{
  20.412 +	SDL_VideoDevice *device;
  20.413 +#ifdef DEBUG_GLSDL
  20.414 +	fprintf(stderr,"entering createdevice\n");
  20.415 +#endif
  20.416 +
  20.417 +	/* Create the device with the underlying driver */
  20.418 +	device = opengl_bootstrap->create(devindex);
  20.419 +
  20.420 +	/* Save the video device contents for future use */
  20.421 +	SDL_memcpy(&underlying_device,device,sizeof(SDL_VideoDevice));
  20.422 +
  20.423 +	/* Hook glSDL on the video device */
  20.424 +	device->VideoInit = glSDL_VideoInit;
  20.425 +	device->ListModes = glSDL_ListModes;
  20.426 +	device->VideoQuit = glSDL_VideoQuit;
  20.427 +	device->UpdateRects = glSDL_UpdateRects;
  20.428 +	device->FillHWRect = glSDL_FillHWRect;
  20.429 +	device->SetHWColorKey = glSDL_SetHWColorKey;
  20.430 +	device->SetHWAlpha = glSDL_SetHWAlpha;
  20.431 +	device->AllocHWSurface = glSDL_AllocHWSurface;
  20.432 +	device->LockHWSurface = glSDL_LockHWSurface;
  20.433 +	device->UnlockHWSurface = glSDL_UnlockHWSurface;
  20.434 +	device->FlipHWSurface = glSDL_FlipHWSurface;
  20.435 +	device->FreeHWSurface = glSDL_FreeHWSurface;
  20.436 +	device->CheckHWBlit = glSDL_CheckHWBlit;
  20.437 +	device->SetColors = glSDL_SetColors;
  20.438 +	device->SetVideoMode = glSDL_SetVideoMode;
  20.439 +	device->info.hw_available=1;
  20.440 +	device->info.blit_hw=1;
  20.441 +	device->info.blit_hw_CC=1;
  20.442 +	device->info.blit_hw_A=1;
  20.443 +	device->info.blit_sw=1;
  20.444 +	device->info.blit_sw_CC=1;
  20.445 +	device->info.blit_sw_A=1;
  20.446 +	device->info.blit_fill=1;
  20.447 +
  20.448 +	/* These functions are not supported by glSDL, so we NULLify them */
  20.449 +	device->SetGamma = NULL;
  20.450 +	device->GetGamma = NULL;
  20.451 +	device->SetGammaRamp = NULL;
  20.452 +	device->GetGammaRamp = NULL;
  20.453 +	device->ToggleFullScreen = NULL;
  20.454 +
  20.455 +	device->free = glSDL_DeleteDevice;
  20.456 +
  20.457 +#ifdef DEBUG_GLSDL
  20.458 +	fprintf(stderr,"leaving createdevice\n");
  20.459 +#endif
  20.460 +
  20.461 +	return device;
  20.462 +}
  20.463 +
  20.464 +/* Our bootstraping structure */
  20.465 +VideoBootStrap glSDL_bootstrap = {
  20.466 +	"glSDL", "glSDL - SDL over OpenGL",
  20.467 +	glSDL_Available, glSDL_CreateDevice
  20.468 +};
  20.469 +
  20.470 +static int glSDL_VideoInit(_THIS, SDL_PixelFormat *vformat)
  20.471 +{
  20.472 +	int r;
  20.473 +	printf("glSDL videoinit\n");
  20.474 +#ifdef DEBUG_GLSDL
  20.475 +	fprintf(stderr,"videoinit\n");
  20.476 +#endif
  20.477 +	r=underlying_device.VideoInit(this,vformat);
  20.478 +	this->info.hw_available=1;
  20.479 +	this->info.blit_hw=1;
  20.480 +	this->info.blit_hw_CC=1;
  20.481 +	this->info.blit_hw_A=1;
  20.482 +	this->info.blit_sw=1;
  20.483 +	this->info.blit_sw_CC=1;
  20.484 +	this->info.blit_sw_A=1;
  20.485 +	this->info.blit_fill=1;
  20.486 +
  20.487 +	return r;
  20.488 +}
  20.489 +
  20.490 +SDL_Rect **glSDL_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
  20.491 +{
  20.492 +	return((SDL_Rect **)-1);
  20.493 +}
  20.494 +
  20.495 +static void glSDL_VideoQuit(_THIS)
  20.496 +{
  20.497 +	SDL_Surface* scr;
  20.498 +	
  20.499 +	/* free all hwdata structures */
  20.500 +	while(first!=NULL)
  20.501 +		glSDL_RemoveTexInfo(this, first);
  20.502 +
  20.503 +	SDL_free(mirrorbuf);
  20.504 +	mirrorbuf = NULL;
  20.505 +
  20.506 +	SDL_FreeFormat(RGBfmt);
  20.507 +	SDL_FreeFormat(RGBAfmt);
  20.508 +	RGBfmt = RGBAfmt = NULL;
  20.509 +
  20.510 +	SDL_FreeFormat(this->displayformatalphapixel);
  20.511 +	this->displayformatalphapixel = NULL;
  20.512 +
  20.513 +	SDL_FreeSurface(OpenGL_Surface);
  20.514 +	OpenGL_Surface = NULL;
  20.515 +
  20.516 +	/* restore the flags to gracefully exit from fullscreen */
  20.517 +	this->screen->flags = old_screen_flags;
  20.518 +	
  20.519 +	/* keep the screen */
  20.520 +	scr=this->screen;
  20.521 +	
  20.522 +	/* we cleaned up our stuff, now restore the underlying video driver */
  20.523 +	SDL_memcpy(this,&underlying_device,sizeof(SDL_VideoDevice));
  20.524 +
  20.525 +	this->screen=scr;
  20.526 +
  20.527 +	/* call the underlying video driver's VideoQuit function */
  20.528 +	this->VideoQuit(this);
  20.529 +}
  20.530 +
  20.531 +static SDL_Surface* glSDL_SetVideoMode(_THIS, SDL_Surface *current,int width, int height, int bpp, Uint32 flags)
  20.532 +{
  20.533 +	SDL_Surface* hooked_screen;
  20.534 +	int i;
  20.535 +	int flag_doublebuf=0;
  20.536 +
  20.537 +	if (opengl_bootstrap==NULL)
  20.538 +	{
  20.539 +		GLERR("No bootstrap for glSDL compiled in !\n");
  20.540 +		return NULL;
  20.541 +	}
  20.542 +	
  20.543 +	/* we don't have OpenGL */
  20.544 +	if ((flags&SDL_INTERNALOPENGL)==SDL_INTERNALOPENGL)
  20.545 +	{
  20.546 +		GLERR("OpenGL video modes are not supported by glSDL !\n");
  20.547 +		return(NULL);
  20.548 +	}
  20.549 +
  20.550 +	/* 
  20.551 +	 * Adjust the flags
  20.552 +	 */
  20.553 +	flags &= ~SDL_HWPALETTE;
  20.554 +	flags |= SDL_INTERNALOPENGL;
  20.555 +
  20.556 +	/* remember whether the user requested DOUBLEBUF */
  20.557 +
  20.558 +	if (flags&SDL_DOUBLEBUF)
  20.559 +	{
  20.560 +		SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);
  20.561 +		flag_doublebuf=1;
  20.562 +	}
  20.563 +	else
  20.564 +	{
  20.565 +		SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,0);
  20.566 +		flag_doublebuf=0;
  20.567 +	}
  20.568 +	
  20.569 +	hooked_screen = underlying_device.SetVideoMode(this,current,width,height,0,flags);
  20.570 +
  20.571 +	if (!hooked_screen)
  20.572 +	{
  20.573 +		GLERR("Unable to open an OpenGL window !\n");
  20.574 +		return(NULL);
  20.575 +	}
  20.576 +	
  20.577 +	/* save the screen flags for restore time */
  20.578 +	old_screen_flags = hooked_screen->flags;
  20.579 +
  20.580 +#ifdef DEBUG_GLSDL
  20.581 +	fprintf(stderr,"got %d bpp\n",bpp);
  20.582 +#endif
  20.583 +
  20.584 +	/* setup the public surface format
  20.585 +	 * glSDL always returns the bpp its asked
  20.586 +	 */
  20.587 +	switch(bpp)
  20.588 +	{
  20.589 +		case 32:
  20.590 +			this->is_32bit = 1;
  20.591 +			this->screen = SDL_CreateRGBSurface(flags, width, height, bpp, 
  20.592 +#if SDL_BYTEORDER == SDL_LIL_ENDIAN
  20.593 +					0x00FF0000,
  20.594 +					0x0000FF00,
  20.595 +					0x000000FF,
  20.596 +					0x00000000
  20.597 +#else
  20.598 +					0x0000FF00,
  20.599 +					0x00FF0000,
  20.600 +					0xFF000000,
  20.601 +					0x00000000
  20.602 +#endif
  20.603 +					);
  20.604 +			break;
  20.605 +		case 24:
  20.606 +			this->is_32bit = 0;
  20.607 +			this->screen = SDL_CreateRGBSurface(flags, width, height, bpp, 
  20.608 +#if SDL_BYTEORDER == SDL_LIL_ENDIAN
  20.609 +					0x00FF0000,
  20.610 +					0x0000FF00,
  20.611 +					0x000000FF,
  20.612 +					0x00000000
  20.613 +#else
  20.614 +					0x0000FF00,
  20.615 +					0x00FF0000,
  20.616 +					0xFF000000,
  20.617 +					0x00000000
  20.618 +#endif
  20.619 +					); 
  20.620 +			break;
  20.621 +		case 16:
  20.622 +			this->is_32bit = 0;
  20.623 +			this->screen = SDL_CreateRGBSurface(flags, width, height, bpp, 
  20.624 +#if SDL_BYTEORDER == SDL_LIL_ENDIAN
  20.625 +					0x0000F800,
  20.626 +					0x000007E0,
  20.627 +					0x0000001F,
  20.628 +					0x00000000
  20.629 +#else
  20.630 +					0x0000001F,
  20.631 +					0x000007E0,
  20.632 +					0x0000F800,
  20.633 +					0x00000000
  20.634 +#endif
  20.635 +					); 
  20.636 +			break;
  20.637 +		case 15:
  20.638 +			this->is_32bit = 0;
  20.639 +			this->screen = SDL_CreateRGBSurface(flags, width, height, bpp, 
  20.640 +#if SDL_BYTEORDER == SDL_LIL_ENDIAN
  20.641 +					0x00007C00,
  20.642 +					0x000003E0,
  20.643 +					0x0000001F,
  20.644 +					0x00000000
  20.645 +#else
  20.646 +					0x0000001F,
  20.647 +					0x000003E0,
  20.648 +					0x00007C00,
  20.649 +					0x00000000
  20.650 +#endif
  20.651 +					); 
  20.652 +			break;
  20.653 +		case 8:
  20.654 +		default:
  20.655 +			this->is_32bit = 0;
  20.656 +			this->screen = SDL_CreateRGBSurface(flags, width, height, bpp, 0, 0, 0, 0); 
  20.657 +			/* give it a default palette if 8 bpp
  20.658 +			 * note : SDL already takes care of the palette for 4 bits & 1 bit surfaces 
  20.659 +			 */
  20.660 +/*			if (bpp==8)
  20.661 +			{
  20.662 +				this->screen->format->palette->ncolors=255;
  20.663 +				SDL_DitherColors(this->screen->format->palette->colors,bpp);
  20.664 +			}*/
  20.665 +			break;
  20.666 +	}
  20.667 +
  20.668 +	/* also, we add SDL_HWSURFACE all the time, and let SDL create a shadow surface accordingly */
  20.669 +	this->screen->flags = hooked_screen->flags | SDL_HWSURFACE | SDL_INTERNALOPENGL;
  20.670 +	/* add SDL_DOUBLEBUF if it was requested */
  20.671 +	if (flag_doublebuf)
  20.672 +		this->screen->flags|=SDL_DOUBLEBUF;
  20.673 +
  20.674 +	/* Tell SDL the alpha pixel format we'd like to have */
  20.675 +	this->displayformatalphapixel = SDL_AllocFormat(32,
  20.676 +#if SDL_BYTEORDER == SDL_BIG_ENDIAN
  20.677 +			0xFF000000,
  20.678 +			0x00FF0000,
  20.679 +			0x0000FF00,
  20.680 +			0x000000FF
  20.681 +#else
  20.682 +			0x000000FF,
  20.683 +			0x0000FF00,
  20.684 +			0x00FF0000,
  20.685 +			0xFF000000
  20.686 +#endif
  20.687 +			);
  20.688 +
  20.689 +	/* Now create the raw OpenGL surface */
  20.690 +	OpenGL_Surface = SDL_CreateRGBSurface(flags, width, height, 24, 
  20.691 +#if SDL_BYTEORDER == SDL_LIL_ENDIAN
  20.692 +			0x000000FF,
  20.693 +			0x0000FF00,
  20.694 +			0x00FF0000,
  20.695 +			0x00000000
  20.696 +#else
  20.697 +			0xFF000000,
  20.698 +			0x00FF0000,
  20.699 +			0x0000FF00,
  20.700 +			0x00000000
  20.701 +#endif
  20.702 +			);
  20.703 +
  20.704 +	/* Here we have to setup OpenGL funcs ourselves */
  20.705 +#ifndef __QNXNTO__
  20.706 +#define SDL_PROC(ret,func,params) \
  20.707 +	do { \
  20.708 +		this->func = SDL_GL_GetProcAddress(#func); \
  20.709 +			if ( ! this->func ) { \
  20.710 +				SDL_SetError("Couldn't load GL function: %s\n", #func); \
  20.711 +					return(NULL); \
  20.712 +			} \
  20.713 +	} while ( 0 );
  20.714 +#else
  20.715 +#define SDL_PROC(ret,func,params) this->func=func;
  20.716 +#endif /* __QNXNTO__ */
  20.717 +#include "../SDL_glfuncs.h"
  20.718 +#undef SDL_PROC	
  20.719 +
  20.720 +	if ( this->GL_MakeCurrent(this) < 0 )
  20.721 +		return(NULL);
  20.722 +#define SDL_PROC(ret,func,params) \
  20.723 +	do { \
  20.724 +		this->func = SDL_GL_GetProcAddress(#func); \
  20.725 +			if ( ! this->func ) { \
  20.726 +				SDL_SetError("Couldn't load GL function: %s\n", #func); \
  20.727 +					return(NULL); \
  20.728 +			} \
  20.729 +	} while ( 0 );
  20.730 +#include "../SDL_glfuncs.h"
  20.731 +#undef SDL_PROC	
  20.732 +
  20.733 +
  20.734 +#ifdef	FAKE_MAXTEXSIZE
  20.735 +	maxtexsize = FAKE_MAXTEXSIZE;
  20.736 +#else
  20.737 +	this->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxtexsize);
  20.738 +#endif
  20.739 +#ifdef DEBUG_GLSDL
  20.740 +	fprintf(stderr, "glSDL: Max texture size: %d\n", maxtexsize);
  20.741 +#endif
  20.742 +
  20.743 +	glSDL_init_formats(this);
  20.744 +
  20.745 +	if (flag_doublebuf)
  20.746 +		this->glDrawBuffer(GL_BACK);
  20.747 +	else
  20.748 +		this->glDrawBuffer(GL_FRONT);
  20.749 +
  20.750 +	this->glDisable(GL_DITHER);
  20.751 +	
  20.752 +	if(glSDL_AddTexInfo(this, this->screen) < 0)
  20.753 +	{
  20.754 +		GLERR("HookDevice() failed to add info to screen surface!");
  20.755 +		return NULL;
  20.756 +	}
  20.757 +
  20.758 +	glSDL_SetLogicSize(this, this->screen,
  20.759 +			this->screen->w, this->screen->h);
  20.760 +
  20.761 +	glSDL_do_texture(this, 0);
  20.762 +	glSDL_do_blend(this, 0);
  20.763 +
  20.764 +	for(i = 0; i < 1+flag_doublebuf; ++i)
  20.765 +	{
  20.766 +		this->glBegin(GL_TRIANGLE_FAN);
  20.767 +		this->glColor3ub(0, 0, 0);
  20.768 +		this->glVertex2i(0, 0);
  20.769 +		this->glVertex2i(this->screen->w, 0);
  20.770 +		this->glVertex2i(this->screen->w, this->screen->h);
  20.771 +		this->glVertex2i(0, this->screen->h);
  20.772 +		this->glEnd();
  20.773 +		if(!i)
  20.774 +			this->GL_SwapBuffers(this);
  20.775 +	}
  20.776 +
  20.777 +	mirrorbuf = SDL_malloc(this->screen->h * this->screen->pitch);
  20.778 +	if(!mirrorbuf)
  20.779 +	{
  20.780 +		GLERR("HookDevice() failed to allocate temp buffer for mirroring!");
  20.781 +		return NULL;
  20.782 +	}
  20.783 +
  20.784 +	return this->screen;
  20.785 +}
  20.786 +
  20.787 +static int glSDL_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
  20.788 +{
  20.789 +	/* We don't need to fill this one */
  20.790 +	return 0;
  20.791 +}
  20.792 +
  20.793 +
  20.794 +#ifdef DEBUG_GLSDL
  20.795 +static void glSDL_print_glerror(_THIS, int point)
  20.796 +{
  20.797 +	const char *err = "<unknown>";
  20.798 +	switch(this->glGetError())
  20.799 +	{
  20.800 +		case GL_NO_ERROR:
  20.801 +			return;
  20.802 +		case GL_INVALID_ENUM:
  20.803 +			err = "GL_INVALID_ENUM";
  20.804 +			break;
  20.805 +		case GL_INVALID_VALUE:
  20.806 +			err = "GL_INVALID_VALUE";
  20.807 +			break;
  20.808 +		case GL_INVALID_OPERATION:
  20.809 +			err = "GL_INVALID_OPERATION";
  20.810 +			break;
  20.811 +		case GL_STACK_OVERFLOW:
  20.812 +			err = "GL_STACK_OVERFLOW";
  20.813 +			break;
  20.814 +		case GL_STACK_UNDERFLOW:
  20.815 +			err = "GL_STACK_UNDERFLOW";
  20.816 +			break;
  20.817 +		case GL_OUT_OF_MEMORY:
  20.818 +			err = "GL_OUT_OF_MEMORY";
  20.819 +		default:
  20.820 +			break;
  20.821 +	}
  20.822 +	fprintf(stderr,"OpenGL error \"%s\" at point %d.\n", err, point);
  20.823 +}
  20.824 +#endif
  20.825 +
  20.826 +/* Get texinfo for a surface. */
  20.827 +static __inline__ private_hwdata *glSDL_GetTexInfo(SDL_Surface *surface)
  20.828 +{
  20.829 +	if(!surface)
  20.830 +		return NULL;
  20.831 +	return surface->hwdata;
  20.832 +}
  20.833 +
  20.834 +
  20.835 +/* Allocate a "blank" texinfo for a suface. */
  20.836 +static private_hwdata *glSDL_AllocTexInfo(SDL_Surface *surface)
  20.837 +{
  20.838 +	private_hwdata *txi;
  20.839 +	if(!surface)
  20.840 +		return NULL;
  20.841 +
  20.842 +	txi = glSDL_GetTexInfo(surface);
  20.843 +	if(txi)
  20.844 +		return txi;		/* There already is one! --> */
  20.845 +
  20.846 +	/* ...and hook a new texinfo struct up to it. */
  20.847 +	txi = (private_hwdata *)SDL_calloc(1, sizeof(private_hwdata));
  20.848 +	if(!txi)
  20.849 +	{
  20.850 +		GLERR("AllocTexInfo(): Failed allocating TexInfo struct!");
  20.851 +		return NULL;
  20.852 +	}
  20.853 +	txi->temporary = 1;
  20.854 +#ifdef DEBUG_GLSDL		
  20.855 +	fprintf(stderr, "glSDL: Allocated TexInfo %p.\n", txi);
  20.856 +#endif
  20.857 +	return txi;
  20.858 +}
  20.859 +
  20.860 +
  20.861 +static void glSDL_FreeTexInfo(_THIS, private_hwdata *txi)
  20.862 +{
  20.863 +	if(!txi)
  20.864 +		return;
  20.865 +
  20.866 +	glSDL_UnloadTexture(this, txi);
  20.867 +	SDL_free(txi->texture);
  20.868 +	SDL_free(txi);
  20.869 +#ifdef DEBUG_GLSDL
  20.870 +	fprintf(stderr, "glSDL: Freed TexInfo %p.\n", txi);
  20.871 +#endif
  20.872 +}
  20.873 +
  20.874 +
  20.875 +/* Detach and free the texinfo of a surface. */
  20.876 +static void glSDL_RemoveTexInfo(_THIS, SDL_Surface *surface)
  20.877 +{
  20.878 +	SDL_Surface *next,*prev;
  20.879 +	if(!glSDL_GetTexInfo(surface))
  20.880 +		return;
  20.881 +
  20.882 +	/* maintain our doubly linked list */
  20.883 +	next=surface->hwdata->next;
  20.884 +	prev=surface->hwdata->prev;
  20.885 +	if (prev!=NULL)
  20.886 +	{
  20.887 +		prev->hwdata->next = next;
  20.888 +	}
  20.889 +	else
  20.890 +	{
  20.891 +		first = next;
  20.892 +	}
  20.893 +	if (next!=NULL)
  20.894 +	{
  20.895 +		next->hwdata->prev = prev;
  20.896 +	}
  20.897 +
  20.898 +	glSDL_FreeTexInfo(this, surface->hwdata);
  20.899 +	surface->hwdata = NULL;
  20.900 +}
  20.901 +
  20.902 +
  20.903 +/*
  20.904 + * Calculate chopping/tiling of a surface to
  20.905 + * fit it into the smallest possible OpenGL
  20.906 + * texture.
  20.907 + */
  20.908 +static int glSDL_CalcChop(private_hwdata *txi)
  20.909 +{
  20.910 +	int rows, vw, vh;
  20.911 +	int vertical = 0;
  20.912 +	int texsize;
  20.913 +	int lastw, lasth, minsize;
  20.914 +
  20.915 +	vw = txi->virt.w;
  20.916 +	vh = txi->virt.h;
  20.917 +
  20.918 +#ifdef DEBUG_GLSDL_CHOP
  20.919 +	fprintf(stderr, "w=%d, h=%d ", vw, vh);
  20.920 +#endif
  20.921 +	if(vh > vw)
  20.922 +	{
  20.923 +		int t = vw;
  20.924 +		vw = vh;
  20.925 +		vh = t;
  20.926 +		vertical = 1;
  20.927 +#ifdef DEBUG_GLSDL_CHOP
  20.928 +		fprintf(stderr, "(vertical) \t");
  20.929 +#endif
  20.930 +	}
  20.931 +
  20.932 +	/*
  20.933 +	 * Check whether this is a "huge" surface - at least one dimension
  20.934 +	 * must be <= than the maximum texture size, or we'll have to chop
  20.935 +	 * in both directions.
  20.936 +	 */
  20.937 +#ifdef DEBUG_GLSDL
  20.938 +	if(maxtexsize < 0)
  20.939 +		return GLERET("glSDL_CalcChop() called before OpenGL init!");
  20.940 +#endif
  20.941 +	if(vh > maxtexsize)
  20.942 +	{
  20.943 +		/*
  20.944 +		 * Very simple hack for now; we just tile
  20.945 +		 * both ways with maximum size textures.
  20.946 +		 */
  20.947 +		texsize = maxtexsize;
  20.948 +
  20.949 +		txi->tilemode = GLSDL_TM_HUGE;
  20.950 +		txi->texsize = texsize;
  20.951 +		txi->tilew = texsize;
  20.952 +		txi->tileh = texsize;
  20.953 +		txi->tilespertex = 1;
  20.954 +
  20.955 +		/* Calculate number of textures needed */
  20.956 +		txi->textures = (vw + texsize - 1) / texsize;
  20.957 +		txi->textures *= (vh + texsize - 1) / texsize;
  20.958 +		txi->texture = SDL_malloc(txi->textures * sizeof(int));
  20.959 +		SDL_memset(txi->texture, -1, txi->textures * sizeof(int));
  20.960 +#ifdef DEBUG_GLSDL		
  20.961 +		fprintf(stderr, "two-way tiling; textures=%d\n", txi->textures);
  20.962 +#endif
  20.963 +		if(!txi->texture)
  20.964 +		{
  20.965 +			fprintf(stderr, "glSDL: INTERNAL ERROR: Failed to allocate"
  20.966 +					" texture name table!\n");
  20.967 +			return -3;
  20.968 +		}
  20.969 +		return 0;
  20.970 +	}
  20.971 +
  20.972 +	/* Calculate minimum size */
  20.973 +	rows = 1;
  20.974 +	lastw = vw;
  20.975 +	lasth = vh;
  20.976 +	minsize = lastw > lasth ? lastw : lasth;
  20.977 +	while(1)
  20.978 +	{
  20.979 +		int w, h, size;
  20.980 +		++rows;
  20.981 +		w = vw / rows;
  20.982 +		h = rows * vh;
  20.983 +		size = w > h ? w : h;
  20.984 +		if(size >= minsize)
  20.985 +		{
  20.986 +			--rows;
  20.987 +			break;
  20.988 +		}
  20.989 +		lastw = w;
  20.990 +		lasth = h;
  20.991 +		minsize = size;
  20.992 +	}
  20.993 +	if(minsize > maxtexsize)
  20.994 +	{
  20.995 +		/* Handle multiple textures for very wide/tall surfaces. */
  20.996 +		minsize = maxtexsize;
  20.997 +		rows = (vw + minsize-1) / minsize;
  20.998 +	}
  20.999 +#ifdef DEBUG_GLSDL_CHOP
 20.1000 +	fprintf(stderr, "==> minsize=%d ", minsize);
 20.1001 +	fprintf(stderr, "(rows=%d) \t", rows);
 20.1002 +#endif
 20.1003 +
 20.1004 +	/* Recalculate with nearest higher power-of-2 width. */
 20.1005 +	for(texsize = 1; texsize < minsize; texsize <<= 1)
 20.1006 +		;
 20.1007 +	txi->texsize = texsize;
 20.1008 +	rows = (vw + texsize-1) / texsize;
 20.1009 +#ifdef DEBUG_GLSDL_CHOP
 20.1010 +	fprintf(stderr, "==> texsize=%d (rows=%d) \t", texsize, rows);
 20.1011 +#endif
 20.1012 +
 20.1013 +	/* Calculate number of tiles per texture */
 20.1014 +	txi->tilespertex = txi->texsize / vh;
 20.1015 +#ifdef DEBUG_GLSDL_CHOP
 20.1016 +	fprintf(stderr, "tilespertex=%d \t", txi->tilespertex);
 20.1017 +#endif
 20.1018 +
 20.1019 +	/* Calculate number of textures needed */
 20.1020 +	txi->textures = (rows + txi->tilespertex-1) / txi->tilespertex;
 20.1021 +	txi->texture = (GLuint *)SDL_malloc(txi->textures * sizeof(GLuint));
 20.1022 +	SDL_memset(txi->texture, GLSDL_NOTEX, txi->textures * sizeof(GLuint));
 20.1023 +#ifdef DEBUG_GLSDL_CHOP
 20.1024 +	fprintf(stderr, "textures=%d, ", txi->textures);
 20.1025 +#endif
 20.1026 +	if(!txi->texture)
 20.1027 +		return GLERET("Failed to allocate texture name table!");
 20.1028 +
 20.1029 +	/* Set up tile size. (Only one axis supported here!) */
 20.1030 +	if(1 == rows)
 20.1031 +	{
 20.1032 +		txi->tilemode = GLSDL_TM_SINGLE;
 20.1033 +		if(vertical)
 20.1034 +		{
 20.1035 +			txi->tilew = vh;
 20.1036 +			txi->tileh = vw;
 20.1037 +		}
 20.1038 +		else
 20.1039 +		{
 20.1040 +			txi->tilew = vw;
 20.1041 +			txi->tileh = vh;
 20.1042 +		}
 20.1043 +	}
 20.1044 +	else if(vertical)
 20.1045 +	{
 20.1046 +		txi->tilemode = GLSDL_TM_VERTICAL;
 20.1047 +		txi->tilew = vh;
 20.1048 +		txi->tileh = texsize;
 20.1049 +	}
 20.1050 +	else
 20.1051 +	{
 20.1052 +		txi->tilemode = GLSDL_TM_HORIZONTAL;
 20.1053 +		txi->tilew = texsize;
 20.1054 +		txi->tileh = vh;
 20.1055 +	}
 20.1056 +
 20.1057 +#ifdef DEBUG_GLSDL_CHOP
 20.1058 +	fprintf(stderr, "tilew=%d, tileh=%d\n", txi->tilew, txi->tileh);
 20.1059 +#endif
 20.1060 +	return 0;
 20.1061 +}
 20.1062 +
 20.1063 +
 20.1064 +/* Create a temporary TexInfo struct for an SDL_Surface */
 20.1065 +static private_hwdata *glSDL_CreateTempTexInfo(_THIS, SDL_Surface *surface)
 20.1066 +{
 20.1067 +	private_hwdata *txi;
 20.1068 +	if(!surface)
 20.1069 +	{
 20.1070 +		GLERR("CreateTempTexInfo(); no surface!");
 20.1071 +		return NULL;
 20.1072 +	}
 20.1073 +	if(IS_GLSDL_SURFACE(surface))
 20.1074 +		return glSDL_GetTexInfo(surface);	/* Do nothing */
 20.1075 +
 20.1076 +	txi = glSDL_AllocTexInfo(surface);
 20.1077 +	if(!txi)
 20.1078 +	{
 20.1079 +		GLERR("CreateTempTexInfo(); Could not alloc TexInfo!");
 20.1080 +		return NULL;
 20.1081 +	}
 20.1082 +	txi->virt.w = txi->lw = surface->w;
 20.1083 +	txi->virt.h = txi->lh = surface->h;
 20.1084 +
 20.1085 +	if(glSDL_CalcChop(txi) < 0)
 20.1086 +	{
 20.1087 +		glSDL_FreeTexInfo(this, txi);
 20.1088 +		GLERR("CreateTempTexInfo(); CalcChop() failed!");
 20.1089 +		return NULL;
 20.1090 +	}
 20.1091 +
 20.1092 +	return txi;
 20.1093 +}
 20.1094 +
 20.1095 +/* Add a glSDL_TexInfo struct to an SDL_Surface */
 20.1096 +static private_hwdata *glSDL_AddTexInfo(_THIS, SDL_Surface *surface)
 20.1097 +{
 20.1098 +	private_hwdata *txi = glSDL_CreateTempTexInfo(this, surface);
 20.1099 +	if(!txi)
 20.1100 +		return NULL;
 20.1101 +
 20.1102 +	/* Connect the surface to the new TexInfo. */
 20.1103 +	txi->temporary = 0;
 20.1104 +	surface->hwdata = txi;
 20.1105 +
 20.1106 +	/* add this new surface in front of the list of hw surfaces */
 20.1107 +	txi->next = first;
 20.1108 +	txi->prev = NULL;
 20.1109 +	first = surface;
 20.1110 +	if (txi->next!=NULL)
 20.1111 +	{
 20.1112 +		txi->next->hwdata->prev=surface;
 20.1113 +	}
 20.1114 +
 20.1115 +	SDL_SetClipRect(surface, &txi->virt);
 20.1116 +	return txi;
 20.1117 +}
 20.1118 +
 20.1119 +
 20.1120 +/* Create a surface of the prefered OpenGL RGB texture format */
 20.1121 +/*static SDL_Surface *glSDL_CreateRGBSurface(int w, int h)
 20.1122 +{
 20.1123 +	SDL_Surface *s;
 20.1124 +	Uint32 rmask, gmask, bmask;
 20.1125 +	int bits = 24;
 20.1126 +#if SDL_BYTEORDER == SDL_LIL_ENDIAN
 20.1127 +	rmask = 0x000000FF;
 20.1128 +	gmask = 0x0000FF00;
 20.1129 +	bmask = 0x00FF0000;
 20.1130 +#else
 20.1131 +	rmask = 0x00FF0000;
 20.1132 +	gmask = 0x0000FF00;
 20.1133 +	bmask = 0x000000FF;
 20.1134 +#endif
 20.1135 +	s = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h,
 20.1136 +			bits, rmask, gmask, bmask, 0);
 20.1137 +	if(s)
 20.1138 +		s->flags |= SDL_HWACCEL;
 20.1139 +
 20.1140 +	return s;
 20.1141 +}
 20.1142 +*/
 20.1143 +
 20.1144 +/* Create a surface of the prefered OpenGL RGBA texture format */
 20.1145 +static SDL_Surface *glSDL_CreateRGBASurface(int w, int h)
 20.1146 +{
 20.1147 +	SDL_Surface *s;
 20.1148 +	Uint32 rmask, gmask, bmask, amask;
 20.1149 +	int bits = 32;
 20.1150 +#if SDL_BYTEORDER == SDL_LIL_ENDIAN
 20.1151 +	rmask = 0x000000FF;
 20.1152 +	gmask = 0x0000FF00;
 20.1153 +	bmask = 0x00FF0000;
 20.1154 +	amask = 0xFF000000;
 20.1155 +#else
 20.1156 +	rmask = 0xFF000000;
 20.1157 +	gmask = 0x00FF0000;
 20.1158 +	bmask = 0x0000FF00;
 20.1159 +	amask = 0x000000FF;
 20.1160 +#endif
 20.1161 +	s = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h,
 20.1162 +			bits, rmask, gmask, bmask, amask);
 20.1163 +	if(s)
 20.1164 +		s->flags |= SDL_HWACCEL;
 20.1165 +
 20.1166 +	return s;
 20.1167 +}
 20.1168 +
 20.1169 +
 20.1170 +static void glSDL_init_formats(_THIS)
 20.1171 +{
 20.1172 +	RGBfmt = SDL_AllocFormat(24,
 20.1173 +#if SDL_BYTEORDER == SDL_LIL_ENDIAN
 20.1174 +			0x000000FF,
 20.1175 +			0x0000FF00,
 20.1176 +			0x00FF0000,
 20.1177 +			0);
 20.1178 +#else
 20.1179 +			0x00FF0000,
 20.1180 +			0x0000FF00,
 20.1181 +			0x000000FF,
 20.1182 +			0);
 20.1183 +#endif
 20.1184 +	RGBAfmt = SDL_AllocFormat(32,
 20.1185 +#if SDL_BYTEORDER == SDL_LIL_ENDIAN
 20.1186 +			0x000000FF,
 20.1187 +			0x0000FF00,
 20.1188 +			0x00FF0000,
 20.1189 +			0xFF000000);
 20.1190 +#else
 20.1191 +			0xFF000000,
 20.1192 +			0x00FF0000,
 20.1193 +			0x0000FF00,
 20.1194 +			0x000000FF);
 20.1195 +#endif
 20.1196 +}
 20.1197 +
 20.1198 +
 20.1199 +static int glSDL_FormatIsOk(SDL_Surface *surface)
 20.1200 +{
 20.1201 +	SDL_PixelFormat *pf;
 20.1202 +	if(!surface)
 20.1203 +		return 1;	/* Well, there ain't much we can do anyway... */
 20.1204 +
 20.1205 +	pf = surface->format;
 20.1206 +
 20.1207 +	/* Colorkeying requires an alpha channel! */
 20.1208 +	if(surface->flags & SDL_SRCCOLORKEY)
 20.1209 +		if(!pf->Amask)
 20.1210 +			return 0;
 20.1211 +
 20.1212 +	/* We need pitch == (width * BytesPerPixel) for glTex[Sub]Image2D() */
 20.1213 +	if(surface->pitch != (surface->w * pf->BytesPerPixel))
 20.1214 +		return 0;
 20.1215 +
 20.1216 +	if(pf->Amask)
 20.1217 +	{
 20.1218 +		if(pf->BytesPerPixel != RGBAfmt->BytesPerPixel)
 20.1219 +			return 0;
 20.1220 +		if(pf->Rmask != RGBAfmt->Rmask)
 20.1221 +			return 0;
 20.1222 +		if(pf->Gmask != RGBAfmt->Gmask)
 20.1223 +			return 0;
 20.1224 +		if(pf->Bmask != RGBAfmt->Bmask)
 20.1225 +			return 0;
 20.1226 +		if(pf->Amask != RGBAfmt->Amask)
 20.1227 +			return 0;
 20.1228 +	}
 20.1229 +	else
 20.1230 +	{
 20.1231 +		if(pf->BytesPerPixel != RGBfmt->BytesPerPixel)
 20.1232 +			return 0;
 20.1233 +		if(pf->Rmask != RGBfmt->Rmask)
 20.1234 +			return 0;
 20.1235 +		if(pf->Gmask != RGBfmt->Gmask)
 20.1236 +			return 0;
 20.1237 +		if(pf->Bmask != RGBfmt->Bmask)
 20.1238 +			return 0;
 20.1239 +	}
 20.1240 +	return 1;
 20.1241 +}
 20.1242 +
 20.1243 +static void glSDL_key2alpha(SDL_Surface *surface)
 20.1244 +{
 20.1245 +	int x, y;
 20.1246 +	Uint32 ckey = surface->format->colorkey;
 20.1247 +
 20.1248 +#ifdef DEBUG_GLSDL
 20.1249 +	fprintf(stderr,"glSDL_key2alpha()\n");
 20.1250 +#endif
 20.1251 +	for(y = 0; y < surface->h; ++y)
 20.1252 +	{
 20.1253 +		Uint32 *px = (Uint32 *)((char *)surface->pixels + y*surface->pitch);
 20.1254 +		for(x = 0; x < surface->w; ++x)
 20.1255 +			if(px[x] == ckey)
 20.1256 +				px[x] = 0;
 20.1257 +	}
 20.1258 +}
 20.1259 +
 20.1260 +
 20.1261 +
 20.1262 +/*----------------------------------------------------------
 20.1263 +  SDL style API
 20.1264 +  ----------------------------------------------------------*/
 20.1265 +
 20.1266 +static int glSDL_FlipHWSurface(_THIS, SDL_Surface *surface)
 20.1267 +{
 20.1268 +#ifdef GLSDL_GRAPHICAL_DEBUG
 20.1269 +	this->glDisable(GL_TEXTURE_2D);
 20.1270 +	this->glBegin(GL_LINE_LOOP);
 20.1271 +	this->glColor4ub(0, 0, 255, 128);
 20.1272 +	this->glVertex2i(0,0);
 20.1273 +	this->glVertex2i(surface->w,0);
 20.1274 +	this->glVertex2i(surface->w,surface->h);
 20.1275 +	this->glVertex2i(0,surface->h);
 20.1276 +	this->glEnd();
 20.1277 +	this->glEnable(GL_TEXTURE_2D);
 20.1278 +#endif
 20.1279 +	if (this->screen->flags&SDL_DOUBLEBUF)
 20.1280 +		this->GL_SwapBuffers(this);
 20.1281 +	else
 20.1282 +		this->glFinish();
 20.1283 +	return 0;
 20.1284 +}
 20.1285 +
 20.1286 +
 20.1287 +static void glSDL_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
 20.1288 +{
 20.1289 +#ifdef GLSDL_GRAPHICAL_DEBUG
 20.1290 +	int i;
 20.1291 +	this->glDisable(GL_TEXTURE_2D);
 20.1292 +	for(i=0;i<numrects;i++)
 20.1293 +	{
 20.1294 +		this->glColor4ub(255, 0, 0, 128);
 20.1295 +		this->glBegin(GL_LINE_LOOP);
 20.1296 +		this->glVertex2i(rects[i].x,rects[i].y);
 20.1297 +		this->glVertex2i(rects[i].x+rects[i].w,rects[i].y);
 20.1298 +		this->glVertex2i(rects[i].x+rects[i].w,rects[i].y+rects[i].h);
 20.1299 +		this->glVertex2i(rects[i].x,rects[i].y+rects[i].h);
 20.1300 +		this->glEnd();
 20.1301 +	}
 20.1302 +	this->glEnable(GL_TEXTURE_2D);
 20.1303 +#endif
 20.1304 +	if (this->screen->flags&SDL_DOUBLEBUF)
 20.1305 +		this->GL_SwapBuffers(this);
 20.1306 +	else
 20.1307 +		this->glFinish();
 20.1308 +}
 20.1309 +
 20.1310 +
 20.1311 +static int glSDL_AllocHWSurface(_THIS, SDL_Surface *surface)
 20.1312 +{
 20.1313 +	surface->flags |= (SDL_HWSURFACE|SDL_HWACCEL);
 20.1314 +
 20.1315 +	surface->pixels = SDL_malloc(surface->h*surface->pitch);
 20.1316 +	if ( surface->pixels == NULL ) {
 20.1317 +		SDL_FreeSurface(surface);
 20.1318 +		SDL_OutOfMemory();
 20.1319 +		return(-1);
 20.1320 +	}
 20.1321 +	SDL_memset(surface->pixels, 0, surface->h*surface->pitch);
 20.1322 +	return 0;
 20.1323 +}
 20.1324 +
 20.1325 +
 20.1326 +static void glSDL_FreeHWSurface(_THIS, SDL_Surface *surface)
 20.1327 +{
 20.1328 +	if(!surface)
 20.1329 +		return;
 20.1330 +	glSDL_RemoveTexInfo(this, surface);
 20.1331 +}
 20.1332 +
 20.1333 +
 20.1334 +static int glSDL_LockHWSurface(_THIS, SDL_Surface *surface)
 20.1335 +{
 20.1336 +	int y;
 20.1337 +
 20.1338 +	if(!surface)
 20.1339 +		return -1;
 20.1340 +
 20.1341 +#ifdef DEBUG_GLSDL		
 20.1342 +	fprintf(stderr, "glSDL: Lock Surface.\n");
 20.1343 +#endif
 20.1344 +
 20.1345 +	if(SDL_VideoSurface == surface)
 20.1346 +	{
 20.1347 +		glSDL_Invalidate(surface, NULL);
 20.1348 +		this->glPixelStorei(GL_UNPACK_ROW_LENGTH,
 20.1349 +				surface->pitch /
 20.1350 +				surface->format->BytesPerPixel);
 20.1351 +		this->glReadPixels(0, 0, OpenGL_Surface->w, OpenGL_Surface->h,
 20.1352 +				GL_RGB, 
 20.1353 +				GL_UNSIGNED_BYTE,
 20.1354 +				OpenGL_Surface->pixels);
 20.1355 +		for(y = 0; y < OpenGL_Surface->h / 2; ++y)
 20.1356 +		{
 20.1357 +			void *upper = (Uint8 *)OpenGL_Surface->pixels +
 20.1358 +				OpenGL_Surface->pitch * y;
 20.1359 +			void *lower = (Uint8 *)OpenGL_Surface->pixels +
 20.1360 +				OpenGL_Surface->pitch * (OpenGL_Surface->h - y - 1);
 20.1361 +			SDL_memcpy(mirrorbuf, upper, OpenGL_Surface->pitch);
 20.1362 +			SDL_memcpy(upper, lower, OpenGL_Surface->pitch);
 20.1363 +			SDL_memcpy(lower, mirrorbuf, OpenGL_Surface->pitch);
 20.1364 +		}
 20.1365 +		/* the mapping has to be invalidated on 8bpp video surfaces in case of a hw palette change. 
 20.1366 +		 * Now if someone could tell me why this is not handled by SDL... */
 20.1367 +		if (SDL_VideoSurface->format->BitsPerPixel==8)
 20.1368 +			SDL_InvalidateMap(OpenGL_Surface->map);
 20.1369 +		
 20.1370 +		/* convert this raw surface to the application-requested format 
 20.1371 +		 * FIXME this is sometimes overkill, we could use glPixelStore smartly
 20.1372 +		 * But this would be slow anyway :) */
 20.1373 +		
 20.1374 +		glSDL_SoftBlit(OpenGL_Surface, NULL, SDL_VideoSurface, NULL);
 20.1375 +	}
 20.1376 +	else
 20.1377 +		glSDL_Invalidate(surface, NULL);
 20.1378 +
 20.1379 +	return 0;
 20.1380 +}
 20.1381 +
 20.1382 +
 20.1383 +static void glSDL_UnlockHWSurface(_THIS, SDL_Surface *surface)
 20.1384 +{
 20.1385 +	private_hwdata *txi;
 20.1386 +
 20.1387 +	if(!surface)
 20.1388 +		return;
 20.1389 +
 20.1390 +	/* upload this surface ONLY if this is a glSDL surface
 20.1391 +	 * because sometimes (during displayformating for ex.) surfaces are unlocked that aren't glSDL
 20.1392 +	 */
 20.1393 +	if(!IS_GLSDL_SURFACE(surface))
 20.1394 +		return;
 20.1395 +
 20.1396 +#ifdef DEBUG_GLSDL		
 20.1397 +	fprintf(stderr, "glSDL: Unlock Surface.\n");
 20.1398 +#endif
 20.1399 +
 20.1400 +	txi = glSDL_UploadSurface(this, surface);
 20.1401 +
 20.1402 +	if(!txi)
 20.1403 +	{	
 20.1404 +		GLERR("glSDL_UnlockHWSurface() failed to upload surface!");
 20.1405 +		return;
 20.1406 +	}
 20.1407 +	if(txi->temporary)
 20.1408 +	{
 20.1409 +		GLERR("Weirdness... glSDL_UnlockHWSurface() got a temporary TexInfo.");	
 20.1410 +		return;
 20.1411 +	}
 20.1412 +	if(surface == SDL_VideoSurface)
 20.1413 +		glSDL_BlitGL(this, SDL_VideoSurface, NULL, NULL);
 20.1414 +}
 20.1415 +
 20.1416 +
 20.1417 +static int glSDL_SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key)
 20.1418 +{
 20.1419 +	/*
 20.1420 +	 * If an application does this *after* SDL_DisplayFormat,
 20.1421 +	 * we're basically screwed, unless we want to do an
 20.1422 +	 * in-place surface conversion hack here.
 20.1423 +	 *
 20.1424 +	 * What we do is just kill the glSDL texinfo... No big
 20.1425 +	 * deal in most cases, as glSDL only converts once anyway,
 20.1426 +	 * *unless* you keep modifying the surface.
 20.1427 +	 */
 20.1428 +	if(IS_GLSDL_SURFACE(surface))
 20.1429 +		glSDL_RemoveTexInfo(this, surface);
 20.1430 +	return 0;
 20.1431 +}
 20.1432 +
 20.1433 +
 20.1434 +static int glSDL_SetHWAlpha(_THIS, SDL_Surface *surface, Uint8 alpha)
 20.1435 +{
 20.1436 +	/*
 20.1437 +	 * If an application does this *after* SDL_DisplayFormat,
 20.1438 +	 * we're basically screwed, unless we want to do an
 20.1439 +	 * in-place surface conversion hack here.
 20.1440 +	 *
 20.1441 +	 * What we do is just kill the glSDL texinfo... No big
 20.1442 +	 * deal in most cases, as glSDL only converts once anyway,
 20.1443 +	 * *unless* you keep modifying the surface.
 20.1444 +	 */
 20.1445 +	if(IS_GLSDL_SURFACE(surface))
 20.1446 +		glSDL_RemoveTexInfo(this, surface);
 20.1447 +	return 0;
 20.1448 +}
 20.1449 +
 20.1450 +static SDL_bool glSDL_SetClipRect(_THIS, SDL_Surface *surface, SDL_Rect *rect)
 20.1451 +{
 20.1452 +	SDL_bool res;
 20.1453 +	if(!surface)
 20.1454 +		return SDL_FALSE;
 20.1455 +
 20.1456 +	res = SDL_SetClipRect(surface, rect);
 20.1457 +	if(!res)
 20.1458 +		return SDL_FALSE;
 20.1459 +
 20.1460 +	rect = &surface->clip_rect;
 20.1461 +
 20.1462 +	if(surface == SDL_VideoSurface)
 20.1463 +	{
 20.1464 +		SDL_Rect r;
 20.1465 +		float xscale, yscale;
 20.1466 +		private_hwdata *txi;
 20.1467 +
 20.1468 +		r.x = rect->x;
 20.1469 +		r.y = rect->y;
 20.1470 +		r.w = rect->w;
 20.1471 +		r.h = rect->h;
 20.1472 +		SDL_SetClipRect(surface, rect);
 20.1473 +
 20.1474 +		txi = glSDL_GetTexInfo(surface);
 20.1475 +		if(!txi)
 20.1476 +			return GLERET("SetClipRect(): Could not get TexInfo!");
 20.1477 +
 20.1478 +		this->glViewport(rect->x,
 20.1479 +				surface->h - (rect->y + rect->h),
 20.1480 +				rect->w,
 20.1481 +				rect->h);
 20.1482 +		/*
 20.1483 +		 * Note that this projection is upside down in
 20.1484 +		 * relation to the OpenGL coordinate system.
 20.1485 +		 */
 20.1486 +		this->glMatrixMode(GL_PROJECTION);
 20.1487 +		this->glLoadIdentity();
 20.1488 +		xscale = (float)txi->lw / (float)surface->w;
 20.1489 +		yscale = (float)txi->lh / (float)surface->h;
 20.1490 +		this->glOrtho(	xscale*(float)rect->x,
 20.1491 +				xscale*(float)(rect->w+rect->x),
 20.1492 +				yscale*(float)(rect->h+rect->y),
 20.1493 +				yscale*(float)rect->y,
 20.1494 +				-1.0, 1.0);
 20.1495 +		return SDL_TRUE;
 20.1496 +	}
 20.1497 +	return res;
 20.1498 +}
 20.1499 +
 20.1500 +static int glSDL_BlitFromGL(_THIS, SDL_Rect *srcrect,
 20.1501 +		SDL_Surface *dst, SDL_Rect *dstrect)
 20.1502 +{
 20.1503 +	SDL_Rect sr, dr;
 20.1504 +
 20.1505 +	/* In case the destination has an OpenGL texture... */
 20.1506 +	glSDL_Invalidate(dst, dstrect);
 20.1507 +
 20.1508 +	/* Abuse the fake screen buffer a little. */
 20.1509 +	this->glPixelStorei(GL_UNPACK_ROW_LENGTH, SDL_VideoSurface->pitch /
 20.1510 +			SDL_VideoSurface->format->BytesPerPixel);
 20.1511 +	if(srcrect)
 20.1512 +		this->glReadPixels(srcrect->x, OpenGL_Surface->h - (srcrect->y + srcrect->h - 1),
 20.1513 +				srcrect->w, srcrect->h,
 20.1514 +				GL_RGB, GL_UNSIGNED_BYTE, OpenGL_Surface->pixels);
 20.1515 +	else
 20.1516 +		this->glReadPixels(0, 0, OpenGL_Surface->w, OpenGL_Surface->h,
 20.1517 +				GL_RGB, GL_UNSIGNED_BYTE, OpenGL_Surface->pixels);
 20.1518 +	sr = *srcrect;
 20.1519 +	dr = *dstrect;
 20.1520 +	glSDL_SoftBlit(OpenGL_Surface, &sr, dst, &dr);
 20.1521 +	return 0;
 20.1522 +}
 20.1523 +
 20.1524 +static __inline__ void glSDL_BlitGL_single(_THIS, private_hwdata *txi,
 20.1525 +		float sx1, float sy1, SDL_Rect *dst, unsigned char alpha)
 20.1526 +{
 20.1527 +	float sx2, sy2, texscale;
 20.1528 +	if(!txi->textures)
 20.1529 +		return;
 20.1530 +	if(-1 == txi->texture[0])
 20.1531 +		return;
 20.1532 +	glSDL_texture(this, txi->texture[0]);
 20.1533 +
 20.1534 +	texscale = 1.0 / (float)txi->texsize;
 20.1535 +	sx2 = (sx1 + (float)dst->w) * texscale;
 20.1536 +	sy2 = (sy1 + (float)dst->h) * texscale;
 20.1537 +	sx1 *= texscale;
 20.1538 +	sy1 *= texscale;
 20.1539 +
 20.1540 +#ifdef GLSDL_GRAPHICAL_DEBUG
 20.1541 +	this->glDisable(GL_TEXTURE_2D);
 20.1542 +	this->glBegin(GL_LINE_LOOP);
 20.1543 +	this->glColor4ub(0, 255, 0, 128);
 20.1544 +	this->glVertex2i(dst->x, dst->y);
 20.1545 +	this->glVertex2i(dst->x + dst->w, dst->y);
 20.1546 +	this->glVertex2i(dst->x + dst->w, dst->y + dst->h);
 20.1547 +	this->glVertex2i(dst->x, dst->y + dst->h);
 20.1548 +	this->glEnd();
 20.1549 +	this->glEnable(GL_TEXTURE_2D);
 20.1550 +#endif
 20.1551 +	
 20.1552 +	this->glBegin(GL_TRIANGLE_FAN);
 20.1553 +	this->glColor4ub(255, 255, 255, alpha);
 20.1554 +	this->glTexCoord2f(sx1, sy1);
 20.1555 +	this->glVertex2i(dst->x, dst->y);
 20.1556 +	this->glTexCoord2f(sx2, sy1);
 20.1557 +	this->glVertex2i(dst->x + dst->w, dst->y);
 20.1558 +	this->glTexCoord2f(sx2, sy2);
 20.1559 +	this->glVertex2i(dst->x + dst->w, dst->y + dst->h);
 20.1560 +	this->glTexCoord2f(sx1, sy2);
 20.1561 +	this->glVertex2i(dst->x, dst->y + dst->h);
 20.1562 +	this->glEnd();
 20.1563 +}
 20.1564 +
 20.1565 +
 20.1566 +static void glSDL_BlitGL_htile(_THIS, private_hwdata *txi,
 20.1567 +		float sx1, float sy1, SDL_Rect *dst, unsigned char alpha)
 20.1568 +{
 20.1569 +	int tex;
 20.1570 +	float tile, sx2, sy2, yo;
 20.1571 +	float texscale = 1.0 / (float)txi->texsize;
 20.1572 +	float tileh = (float)txi->tileh * texscale;
 20.1573 +	sx2 = (sx1 + (float)dst->w) * texscale;
 20.1574 +	sy2 = (sy1 + (float)dst->h) * texscale;
 20.1575 +	sx1 *= texscale;
 20.1576 +	sy1 *= texscale;
 20.1577 +	tile = floor(sx1);
 20.1578 +	tex = (int)tile / txi->tilespertex;
 20.1579 +	yo = ((int)tile % txi->tilespertex) * tileh;
 20.1580 +
 20.1581 +	if(tex >= txi->textures)
 20.1582 +		return;
 20.1583 +	if(-1 == txi->texture[tex])
 20.1584 +		return;
 20.1585 +	glSDL_texture(this, txi->texture[tex]);
 20.1586 +
 20.1587 +	while(tile < sx2)
 20.1588 +	{
 20.1589 +		int tdx1 = dst->x;
 20.1590 +		int tdx2 = dst->x + dst->w;
 20.1591 +		float tsx1 = sx1 - tile;
 20.1592 +		float tsx2 = sx2 - tile;
 20.1593 +
 20.1594 +		/* Clip to current tile */
 20.1595 +		if(tsx1 < 0.0)
 20.1596 +		{
 20.1597 +			tdx1 -= tsx1 * txi->texsize;
 20.1598 +			tsx1 = 0.0;
 20.1599 +		}
 20.1600 +		if(tsx2 > 1.0)
 20.1601 +		{
 20.1602 +			tdx2 -= (tsx2 - 1.0) * txi->texsize;
 20.1603 +			tsx2 = 1.0;
 20.1604 +		}
 20.1605 +
 20.1606 +		/* Maybe select next texture? */
 20.1607 +		if(yo + tileh > 1.0)
 20.1608 +		{
 20.1609 +			++tex;
 20.1610 +			if(tex >= txi->textures)
 20.1611 +				return;
 20.1612 +			if(-1 == txi->texture[tex])
 20.1613 +				return;
 20.1614 +			glSDL_texture(this, txi->texture[tex]);
 20.1615 +			yo = 0.0;
 20.1616 +		}
 20.1617 +
 20.1618 +#ifdef GLSDL_GRAPHICAL_DEBUG
 20.1619 +		this->glDisable(GL_TEXTURE_2D);
 20.1620 +		this->glBegin(GL_LINE_LOOP);
 20.1621 +		this->glColor4ub(0, 255, 0, 128);
 20.1622 +		this->glVertex2i(tdx1, dst->y);
 20.1623 +		this->glVertex2i(tdx2, dst->y);
 20.1624 +		this->glVertex2i(tdx2, dst->y + dst->h);
 20.1625 +		this->glVertex2i(tdx1, dst->y + dst->h);
 20.1626 +		this->glEnd();
 20.1627 +		this->glEnable(GL_TEXTURE_2D);
 20.1628 +#endif
 20.1629 +
 20.1630 +		this->glBegin(GL_TRIANGLE_FAN);
 20.1631 +		this->glColor4ub(255, 255, 255, alpha);
 20.1632 +		this->glTexCoord2f(tsx1, yo + sy1);
 20.1633 +		this->glVertex2i(tdx1, dst->y);
 20.1634 +		this->glTexCoord2f(tsx2, yo + sy1);
 20.1635 +		this->glVertex2i(tdx2, dst->y);
 20.1636 +		this->glTexCoord2f(tsx2, yo + sy2);
 20.1637 +		this->glVertex2i(tdx2, dst->y + dst->h);
 20.1638 +		this->glTexCoord2f(tsx1, yo + sy2);
 20.1639 +		this->glVertex2i(tdx1, dst->y + dst->h);
 20.1640 +		this->glEnd();
 20.1641 +		tile += 1.0;
 20.1642 +		yo += tileh;
 20.1643 +	}
 20.1644 +}
 20.1645 +
 20.1646 +
 20.1647 +static void glSDL_BlitGL_vtile(_THIS, private_hwdata *txi,
 20.1648 +		float sx1, float sy1, SDL_Rect *dst, unsigned char alpha)
 20.1649 +{
 20.1650 +	int tex;
 20.1651 +	float tile, sx2, sy2, xo;
 20.1652 +	float texscale = 1.0 / (float)txi->texsize;
 20.1653 +	float tilew = (float)txi->tilew * texscale;
 20.1654 +	sx2 = (sx1 + (float)dst->w) * texscale;
 20.1655 +	sy2 = (sy1 + (float)dst->h) * texscale;
 20.1656 +	sx1 *= texscale;
 20.1657 +	sy1 *= texscale;
 20.1658 +	tile = floor(sy1);
 20.1659 +	tex = (int)tile / txi->tilespertex;
 20.1660 +	xo = ((int)tile % txi->tilespertex) * tilew;
 20.1661 +
 20.1662 +	if(tex >= txi->textures)
 20.1663 +		return;
 20.1664 +	if(-1 == txi->texture[tex])
 20.1665 +		return;
 20.1666 +	glSDL_texture(this, txi->texture[tex]);
 20.1667 +
 20.1668 +	while(tile < sy2)
 20.1669 +	{
 20.1670 +		int tdy1 = dst->y;
 20.1671 +		int tdy2 = dst->y + dst->h;
 20.1672 +		float tsy1 = sy1 - tile;
 20.1673 +		float tsy2 = sy2 - tile;
 20.1674 +
 20.1675 +		/* Clip to current tile */
 20.1676 +		if(tsy1 < 0.0)
 20.1677 +		{
 20.1678 +			tdy1 -= tsy1 * txi->texsize;
 20.1679 +			tsy1 = 0.0;
 20.1680 +		}
 20.1681 +		if(tsy2 > 1.0)
 20.1682 +		{
 20.1683 +			tdy2 -= (tsy2 - 1.0) * txi->texsize;
 20.1684 +			tsy2 = 1.0;
 20.1685 +		}
 20.1686 +
 20.1687 +		/* Maybe select next texture? */
 20.1688 +		if(xo + tilew > 1.0)
 20.1689 +		{
 20.1690 +			++tex;
 20.1691 +			if(tex >= txi->textures)
 20.1692 +				return;
 20.1693 +			if(-1 == txi->texture[tex])
 20.1694 +				return;
 20.1695 +			glSDL_texture(this, txi->texture[tex]);
 20.1696 +			xo = 0.0;
 20.1697 +		}
 20.1698 +
 20.1699 +#ifdef GLSDL_GRAPHICAL_DEBUG
 20.1700 +		this->glDisable(GL_TEXTURE_2D);
 20.1701 +		this->glBegin(GL_LINE_LOOP);
 20.1702 +		this->glColor4ub(0, 255, 0, 128);
 20.1703 +		this->glVertex2i(dst->x, tdy1);
 20.1704 +		this->glVertex2i(dst->x + dst->w, tdy1);
 20.1705 +		this->glVertex2i(dst->x + dst->w, tdy2);
 20.1706 +		this->glVertex2i(dst->x, tdy2);
 20.1707 +		this->glEnd();
 20.1708 +		this->glEnable(GL_TEXTURE_2D);
 20.1709 +#endif
 20.1710 +
 20.1711 +		this->glBegin(GL_TRIANGLE_FAN);
 20.1712 +		this->glColor4ub(255, 255, 255, alpha);
 20.1713 +		this->glTexCoord2f(xo + sx1, tsy1);
 20.1714 +		this->glVertex2i(dst->x, tdy1);
 20.1715 +		this->glTexCoord2f(xo + sx2, tsy1);
 20.1716 +		this->glVertex2i(dst->x + dst->w, tdy1);
 20.1717 +		this->glTexCoord2f(xo + sx2, tsy2);
 20.1718 +		this->glVertex2i(dst->x + dst->w, tdy2);
 20.1719 +		this->glTexCoord2f(xo + sx1, tsy2);
 20.1720 +		this->glVertex2i(dst->x, tdy2);
 20.1721 +		this->glEnd();
 20.1722 +
 20.1723 +		tile += 1.0;
 20.1724 +		xo += tilew;
 20.1725 +	}
 20.1726 +}
 20.1727 +
 20.1728 +
 20.1729 +static void glSDL_BlitGL_hvtile(_THIS, SDL_Surface *src, private_hwdata *txi,
 20.1730 +		float sx1, float sy1, SDL_Rect *dst, unsigned char alpha)
 20.1731 +{
 20.1732 +	int x, y, last_tex, tex;
 20.1733 +	float sx2, sy2;
 20.1734 +	float texscale = 1.0 / (float)txi->texsize;
 20.1735 +	int tilesperrow = (src->w + txi->tilew - 1) / txi->tilew;
 20.1736 +	sx2 = (sx1 + (float)dst->w) * texscale;
 20.1737 +	sy2 = (sy1 + (float)dst->h) * texscale;
 20.1738 +	sx1 *= texscale;
 20.1739 +	sy1 *= texscale;
 20.1740 +
 20.1741 +	last_tex = tex = floor(sy1) * tilesperrow + floor(sx1);
 20.1742 +	if(tex >= txi->textures)
 20.1743 +		return;
 20.1744 +	if(-1 == txi->texture[tex])
 20.1745 +		return;
 20.1746 +	glSDL_texture(this, txi->texture[tex]);
 20.1747 +
 20.1748 +	for(y = floor(sy1); y < sy2; ++y)
 20.1749 +	{
 20.1750 +		int tdy1 = dst->y;
 20.1751 +		int tdy2 = dst->y + dst->h;
 20.1752 +		float tsy1 = sy1 - y;
 20.1753 +		float tsy2 = sy2 - y;
 20.1754 +
 20.1755 +		/* Clip to current tile */
 20.1756 +		if(tsy1 < 0.0)
 20.1757 +		{
 20.1758 +			tdy1 -= tsy1 * txi->texsize;
 20.1759 +			tsy1 = 0.0;
 20.1760 +		}
 20.1761 +		if(tsy2 > 1.0)
 20.1762 +		{
 20.1763 +			tdy2 -= (tsy2 - 1.0) * txi->texsize;
 20.1764 +			tsy2 = 1.0;
 20.1765 +		}
 20.1766 +		for(x = floor(sx1); x < sx2; ++x)
 20.1767 +		{
 20.1768 +			int tdx1 = dst->x;
 20.1769 +			int tdx2 = dst->x + dst->w;
 20.1770 +			float tsx1 = sx1 - x;
 20.1771 +			float tsx2 = sx2 - x;
 20.1772 +
 20.1773 +			/* Clip to current tile */
 20.1774 +			if(tsx1 < 0.0)
 20.1775 +			{
 20.1776 +				tdx1 -= tsx1 * txi->texsize;
 20.1777 +				tsx1 = 0.0;
 20.1778 +			}
 20.1779 +			if(tsx2 > 1.0)
 20.1780 +			{
 20.1781 +				tdx2 -= (tsx2 - 1.0) * txi->texsize;
 20.1782 +				tsx2 = 1.0;
 20.1783 +			}
 20.1784 +
 20.1785 +			/* Select texture */
 20.1786 +			tex = y * tilesperrow + x;
 20.1787 +			if(tex != last_tex)
 20.1788 +			{
 20.1789 +				if(tex >= txi->textures)
 20.1790 +					return;
 20.1791 +				if(-1 == txi->texture[tex])
 20.1792 +					return;
 20.1793 +				glSDL_texture(this, txi->texture[tex]);
 20.1794 +				last_tex = tex;
 20.1795 +			}
 20.1796 +
 20.1797 +#ifdef GLSDL_GRAPHICAL_DEBUG
 20.1798 +			this->glDisable(GL_TEXTURE_2D);
 20.1799 +			this->glBegin(GL_LINE_LOOP);
 20.1800 +			this->glColor4ub(0, 255, 0, 128);
 20.1801 +			this->glVertex2i(tdx1, tdy1);
 20.1802 +			this->glVertex2i(tdx2, tdy1);
 20.1803 +			this->glVertex2i(tdx2, tdy2);
 20.1804 +			this->glVertex2i(tdx1, tdy2);
 20.1805 +			this->glEnd();
 20.1806 +			this->glEnable(GL_TEXTURE_2D);
 20.1807 +#endif
 20.1808 +
 20.1809 +			this->glBegin(GL_TRIANGLE_FAN);
 20.1810 +			this->glColor4ub(255, 255, 255, alpha);
 20.1811 +			this->glTexCoord2f(tsx1, tsy1);
 20.1812 +			this->glVertex2i(tdx1, tdy1);
 20.1813 +			this->glTexCoord2f(tsx2, tsy1);
 20.1814 +			this->glVertex2i(tdx2, tdy1);
 20.1815 +			this->glTexCoord2f(tsx2, tsy2);
 20.1816 +			this->glVertex2i(tdx2, tdy2);
 20.1817 +			this->glTexCoord2f(tsx1, tsy2);
 20.1818 +			this->glVertex2i(tdx1, tdy2);
 20.1819 +			this->glEnd();
 20.1820 +		}
 20.1821 +	}
 20.1822 +}
 20.1823 +
 20.1824 +/*
 20.1825 + * Calculate the actual blit rectangle and source offset
 20.1826 + * for a blit from a rectangle in a surface with specified
 20.1827 + * size to a surface with a cliprect.
 20.1828 + *
 20.1829 + * In:	rect	source rectangle
 20.1830 + *	w, h	source surface size
 20.1831 + *	(x, y)	destination coordinate
 20.1832 + *	clip	destination clip rectangle
 20.1833 + *
 20.1834 + * Out:	(x, y)	source top-left offset
 20.1835 + *	rect	destination rectangle
 20.1836 + *
 20.1837 + * Returns 1 if the result is visible, otherwise 0.
 20.1838 + */
 20.1839 +static __inline__ int blitclip(SDL_Rect *rect, int w, int h,
 20.1840 +		int *x, int *y, SDL_Rect *clip)
 20.1841 +{
 20.1842 +	int sx1, sy1, sx2, sy2;
 20.1843 +	int dx1, dy1, dx2, dy2;
 20.1844 +
 20.1845 +	/* Get source and destination coordinates */
 20.1846 +	sx1 = rect->x;
 20.1847 +	sy1 = rect->y;
 20.1848 +	sx2 = sx1 + rect->w;
 20.1849 +	sy2 = sy1 + rect->h;
 20.1850 +	dx1 = *x;
 20.1851 +	dy1 = *y;
 20.1852 +
 20.1853 +	/* Keep source rect inside source surface */
 20.1854 +	if(sx1 < 0)
 20.1855 +	{
 20.1856 +		dx1 -= sx1;
 20.1857 +		sx1 = 0;
 20.1858 +	}
 20.1859 +	if(sy1 < 0)
 20.1860 +	{
 20.1861 +		dy1 -= sy1;
 20.1862 +		sy1 = 0;
 20.1863 +	}
 20.1864 +	if(sx2 > w)
 20.1865 +		sx2 = w;
 20.1866 +	if(sy2 > h)
 20.1867 +		sy2 = h;
 20.1868 +
 20.1869 +	/* Cull blits from void space */
 20.1870 +	if(sx1 >= sx2 || sy1 >= sy2)
 20.1871 +		return 0;
 20.1872 +
 20.1873 +	/* Calculate destination lower-right */
 20.1874 +	dx2 = dx1 + (sx2 - sx1);
 20.1875 +	dy2 = dy1 + (sy2 - sy1);
 20.1876 +
 20.1877 +	/* Clip to destination cliprect */
 20.1878 +	if(dx1 < clip->x)
 20.1879 +	{
 20.1880 +		sx1 += clip->x - dx1;
 20.1881 +		dx1 = clip->x;
 20.1882 +	}
 20.1883 +	if(dy1 < clip->y)
 20.1884 +	{
 20.1885 +		sy1 += clip->y - dy1;
 20.1886 +		dy1 = clip->y;
 20.1887 +	}
 20.1888 +	if(dx2 > clip->x + clip->w)
 20.1889 +		dx2 = clip->x + clip->w;
 20.1890 +	if(dy2 > clip->y + clip->h)
 20.1891 +		dy2 = clip->y + clip->h;
 20.1892 +
 20.1893 +	/* Cull nop/off-screen blits */
 20.1894 +	if(dx1 >= dx2 || dy1 >= dy2)
 20.1895 +		return 0;
 20.1896 +
 20.1897 +	*x = sx1;
 20.1898 +	*y = sy1;
 20.1899 +	rect->x = dx1;
 20.1900 +	rect->y = dy1;
 20.1901 +	rect->w = dx2 - dx1;
 20.1902 +	rect->h = dy2 - dy1;
 20.1903 +	return 1;
 20.1904 +}
 20.1905 +
 20.1906 +static int glSDL_BlitGL(_THIS, SDL_Surface *src,
 20.1907 +		SDL_Rect *srcrect, SDL_Rect *dstrect)
 20.1908 +{
 20.1909 +	private_hwdata *txi;
 20.1910 +	float x1, y1;
 20.1911 +	unsigned char alpha;
 20.1912 +	SDL_Rect d;
 20.1913 +	int x, y;
 20.1914 +	SDL_Rect r;
 20.1915 +
 20.1916 +	if(!src)
 20.1917 +		return GLERET("BlitGL(): No src surface!");
 20.1918 +
 20.1919 +	/* Get source and destination coordinates */
 20.1920 +	if(srcrect)
 20.1921 +		r = *srcrect;
 20.1922 +	else
 20.1923 +	{
 20.1924 +		r.x = r.y = 0;
 20.1925 +		r.w = src->w;
 20.1926 +		r.h = src->h;
 20.1927 +	}
 20.1928 +	if(dstrect)
 20.1929 +	{
 20.1930 +		x = dstrect->x;
 20.1931 +		y = dstrect->y;
 20.1932 +	}
 20.1933 +	else
 20.1934 +		x = y = 0;
 20.1935 +
 20.1936 +	/* Clip! */
 20.1937 +	if(!blitclip(&r, src->w, src->h, &x, &y, &this->screen->clip_rect))
 20.1938 +	{
 20.1939 +		if(dstrect)
 20.1940 +			dstrect->w = dstrect->h = 0;
 20.1941 +		return 0;
 20.1942 +	}
 20.1943 +
 20.1944 +	/* Write back the resulting cliprect */
 20.1945 +	if(dstrect)
 20.1946 +		*dstrect = r;
 20.1947 +
 20.1948 +	/* Make sure we have a source with a valid texture */
 20.1949 +	txi = glSDL_UploadSurface(this, src);
 20.1950 +	if(!txi)
 20.1951 +		return GLERET("BlitGL(): Could not get a TexInfo!");
 20.1952 +
 20.1953 +	/* Set up blending */
 20.1954 +	if(src->flags & (SDL_SRCALPHA | SDL_SRCCOLORKEY))
 20.1955 +	{
 20.1956 +		glSDL_blendfunc(this, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 20.1957 +		glSDL_do_blend(this, 1);
 20.1958 +	}
 20.1959 +	else
 20.1960 +		glSDL_do_blend(this, 0);
 20.1961 +
 20.1962 +	/* Enable texturing */
 20.1963 +	glSDL_do_texture(this, 1);
 20.1964 +
 20.1965 +	/* Calculate texcoords */
 20.1966 +	if(!srcrect)
 20.1967 +		srcrect = &txi->virt;
 20.1968 +	x1 = (float)srcrect->x;
 20.1969 +	y1 = (float)srcrect->y;
 20.1970 +
 20.1971 +	/* Calculate screen coords. */
 20.1972 +	if(dstrect)
 20.1973 +	{
 20.1974 +		d.x = dstrect->x;
 20.1975 +		d.y = dstrect->y;
 20.1976 +		d.w = (int)(srcrect->w * (float)txi->lw / (float)txi->virt.w);
 20.1977 +		d.h = (int)(srcrect->h * (float)txi->lh / (float)txi->virt.h);
 20.1978 +	}
 20.1979 +	else
 20.1980 +	{
 20.1981 +		d.x = 0;
 20.1982 +		d.y = 0;
 20.1983 +		d.w = (int)(srcrect->w * (float)txi->lw / (float)txi->virt.w);
 20.1984 +		d.h = (int)(srcrect->h * (float)txi->lh / (float)txi->virt.h);
 20.1985 +	}
 20.1986 +
 20.1987 +	/*
 20.1988 +	 * Note that we actually *prevent* the use of "full surface alpha"
 20.1989 +	 * and alpha channel in combination - to stay SDL 2D compatible.
 20.1990 +	 */
 20.1991 +	if ((src->flags & SDL_SRCALPHA)&&(src->format->Amask))
 20.1992 +		alpha = 255;
 20.1993 +	else
 20.1994 +		alpha = src->format->alpha;
 20.1995 +	
 20.1996 +	/* Render! */
 20.1997 +	switch(txi->tilemode)
 20.1998 +	{
 20.1999 +		case GLSDL_TM_SINGLE:
 20.2000 +			glSDL_BlitGL_single(this, txi, x1, y1,
 20.2001 +					&d,
 20.2002 +					alpha);
 20.2003 +			break;
 20.2004 +		case GLSDL_TM_HORIZONTAL:
 20.2005 +			glSDL_BlitGL_htile(this, txi, x1, y1,
 20.2006 +					&d,
 20.2007 +					alpha);
 20.2008 +			break;
 20.2009 +		case GLSDL_TM_VERTICAL:
 20.2010 +			glSDL_BlitGL_vtile(this, txi, x1, y1,
 20.2011 +					&d,
 20.2012 +					alpha);
 20.2013 +			break;
 20.2014 +		case GLSDL_TM_HUGE:
 20.2015 +			glSDL_BlitGL_hvtile(this, src, txi, x1, y1,
 20.2016 +					&d,
 20.2017 +					alpha);
 20.2018 +			break;
 20.2019 +	}
 20.2020 +
 20.2021 +	if(txi->temporary)
 20.2022 +		glSDL_FreeTexInfo(this, txi);
 20.2023 +
 20.2024 +	return 0;
 20.2025 +}
 20.2026 +
 20.2027 +
 20.2028 +static int glSDL_HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect,
 20.2029 +		SDL_Surface *dst, SDL_Rect *dstrect)
 20.2030 +{
 20.2031 +	SDL_Surface *vs;
 20.2032 +
 20.2033 +	if(!src)
 20.2034 +		return GLERET("HWAccelBlit(): No src surface!");
 20.2035 +	if(!dst)
 20.2036 +		return GLERET("HWAccelBlit(): No dst surface!");
 20.2037 +
 20.2038 +	/*
 20.2039 +	 * Figure out what to do:
 20.2040 +	 *      screen->screen:         glSDL_BlitFromGL() + glSDL_BlitGL()
 20.2041 +	 *      surface->screen:        glSDL_BlitGL()
 20.2042 +	 *      screen->surface:        glSDL_BlitFromGL()
 20.2043 +	 *      surface->surface:       glSDL_SoftBlit()
 20.2044 +	 */
 20.2045 +	vs = SDL_VideoSurface;
 20.2046 +	if(src == vs)
 20.2047 +	{
 20.2048 +		if(dst == vs)
 20.2049 +		{
 20.2050 +			/*
 20.2051 +FIXME: Try glCopyPixels() instead...
 20.2052 +			 */
 20.2053 +			glSDL_BlitFromGL(current_video, srcrect, vs, dstrect);
 20.2054 +			return glSDL_BlitGL(current_video, vs,
 20.2055 +					srcrect, dstrect);
 20.2056 +		}
 20.2057 +		else
 20.2058 +		{
 20.2059 +			return glSDL_BlitFromGL(current_video, srcrect,
 20.2060 +					dst, dstrect);
 20.2061 +		}
 20.2062 +	}
 20.2063 +	else
 20.2064 +	{
 20.2065 +		if(dst == vs)
 20.2066 +		{
 20.2067 +			return glSDL_BlitGL(current_video, src,
 20.2068 +					srcrect, dstrect);
 20.2069 +		}
 20.2070 +		else
 20.2071 +		{
 20.2072 +			glSDL_Invalidate(dst, dstrect);
 20.2073 +			glSDL_SoftBlit(src, srcrect, dst, dstrect);
 20.2074 +			return 0;
 20.2075 +		}
 20.2076 +	}
 20.2077 +}
 20.2078 +
 20.2079 +
 20.2080 +static int glSDL_FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color)
 20.2081 +{
 20.2082 +	SDL_Surface *vs = SDL_VideoSurface;
 20.2083 +	int dx1, dy1, dx2, dy2;
 20.2084 +	Uint32 r, g, b;
 20.2085 +	Uint8 br,bg,bb;
 20.2086 +
 20.2087 +	/*
 20.2088 +	 * Some ugly reverse conversion for compatibility...
 20.2089 +	 * (We must do this before losing the dst pointer,
 20.2090 +	 * as the pixel formats of the screen and
 20.2091 +	 * SDL_VideoSurface may differ!)
 20.2092 +	 */
 20.2093 +
 20.2094 +	if (dst->format->palette)
 20.2095 +	{
 20.2096 +		/* this a paletted color */
 20.2097 +		SDL_GetRGB(color,dst->format,&br,&bg,&bb);
 20.2098 +	}
 20.2099 +	else
 20.2100 +	{
 20.2101 +		/* this a RGB color */
 20.2102 +		r = color & dst->format->Rmask;
 20.2103 +		r = r >> dst->format->Rshift;
 20.2104 +		r = r << dst->format->Rloss;
 20.2105 +		br = r;
 20.2106 +
 20.2107 +		g = color & dst->format->Gmask;
 20.2108 +		g = g >> dst->format->Gshift;
 20.2109 +		g = g << dst->format->Gloss;
 20.2110 +		bg = g;
 20.2111 +
 20.2112 +		b = color & dst->format->Bmask;
 20.2113 +		b = b >> dst->format->Bshift;
 20.2114 +		b = b << dst->format->Bloss;
 20.2115 +		bb = b;
 20.2116 +	}
 20.2117 +
 20.2118 +	if(vs != dst)
 20.2119 +	{
 20.2120 +		/* draw a rect offscreen */
 20.2121 +		glSDL_Invalidate(dst, dstrect);
 20.2122 +		/* software-fill the surface by faking it as a SW_SURFACE */
 20.2123 +		dst->flags&=~SDL_HWSURFACE;
 20.2124 +		SDL_FillRect(dst,dstrect,color);
 20.2125 +		dst->flags|=SDL_HWSURFACE;
 20.2126 +	}
 20.2127 +	else
 20.2128 +	{
 20.2129 +		/* draw a rect onscreen */
 20.2130 +		glSDL_do_texture(this, 0);
 20.2131 +		glSDL_do_blend(this, 0);
 20.2132 +
 20.2133 +		dx1 = dstrect->x;
 20.2134 +		dy1 = dstrect->y;
 20.2135 +		dx2 = dx1 + dstrect->w;
 20.2136 +		dy2 = dy1 + dstrect->h;
 20.2137 +
 20.2138 +		this->glBegin(GL_TRIANGLE_FAN);
 20.2139 +		this->glColor3ub(br, bg, bb);
 20.2140 +		this->glVertex2i(dx1, dy1);
 20.2141 +		this->glVertex2i(dx2, dy1);
 20.2142 +		this->glVertex2i(dx2, dy2);
 20.2143 +		this->glVertex2i(dx1, dy2);
 20.2144 +		this->glEnd();
 20.2145 +	}
 20.2146 +	return 0;
 20.2147 +}
 20.2148 +
 20.2149 +static int glSDL_CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst)
 20.2150 +{
 20.2151 +	src->flags |= SDL_HWACCEL;
 20.2152 +	src->map->hw_blit = glSDL_HWAccelBlit;
 20.2153 +	return 1;
 20.2154 +}
 20.2155 +
 20.2156 +
 20.2157 +static SDL_Surface *glSDL_DisplayFormat(SDL_Surface *surface)
 20.2158 +{
 20.2159 +	SDL_Surface *tmp;
 20.2160 +	int use_rgba = (surface->flags & SDL_SRCCOLORKEY) ||
 20.2161 +		((surface->flags & SDL_SRCALPHA) &&
 20.2162 +		 surface->format->Amask);
 20.2163 +#ifdef DEBUG_GLSDL
 20.2164 +	fprintf(stderr,"#### glSDL_DisplayFormat()\n");
 20.2165 +#endif
 20.2166 +	if(use_rgba)
 20.2167 +		tmp = glSDL_ConvertSurface(surface, RGBAfmt, SDL_SWSURFACE);
 20.2168 +	else
 20.2169 +		tmp = glSDL_ConvertSurface(surface, RGBfmt, SDL_SWSURFACE);
 20.2170 +	if(!tmp)
 20.2171 +	{
 20.2172 +		GLERR("glSDL_DisplayFormat() could not convert surface!");
 20.2173 +		return NULL;
 20.2174 +	}
 20.2175 +	SDL_SetAlpha(tmp, 0, 0);
 20.2176 +
 20.2177 +	if(surface->flags & SDL_SRCCOLORKEY)
 20.2178 +	{
 20.2179 +		/*
 20.2180 +		 * We drop colorkey data here, but we have to,
 20.2181 +		 * or we'll run into trouble when converting,
 20.2182 +		 * in particular from indexed color formats.
 20.2183 +		 */
 20.2184 +		SDL_SetColorKey(tmp, SDL_SRCCOLORKEY,
 20.2185 +				surface->format->colorkey);
 20.2186 +		glSDL_key2alpha(tmp);
 20.2187 +		SDL_SetColorKey(tmp, 0, 0);
 20.2188 +	}
 20.2189 +
 20.2190 +	return tmp;
 20.2191 +}
 20.2192 +
 20.2193 +
 20.2194 +static SDL_Surface *glSDL_DisplayFormatAlpha(SDL_Surface *surface)
 20.2195 +{
 20.2196 +	SDL_Surface *s, *tmp;
 20.2197 +	tmp = glSDL_ConvertSurface(surface, RGBAfmt, SDL_SWSURFACE);
 20.2198 +#ifdef DEBUG_GLSDL
 20.2199 +	fprintf(stderr,"#### glSDL_DisplayFormatAlpha()\n");
 20.2200 +#endif
 20.2201 +	if(!tmp)
 20.2202 +		return NULL;
 20.2203 +
 20.2204 +	SDL_SetAlpha(tmp, 0, 0);
 20.2205 +	SDL_SetColorKey(tmp, 0, 0);
 20.2206 +	s = glSDL_CreateRGBASurface(surface->w, surface->h);
 20.2207 +	if(!s)
 20.2208 +	{
 20.2209 +		SDL_FreeSurface(tmp);
 20.2210 +		return NULL;
 20.2211 +	}
 20.2212 +	glSDL_SoftBlit(tmp, NULL, s, NULL);
 20.2213 +	SDL_FreeSurface(tmp);
 20.2214 +
 20.2215 +	if(surface->flags & SDL_SRCCOLORKEY)
 20.2216 +	{
 20.2217 +		SDL_SetColorKey(s, SDL_SRCCOLORKEY,
 20.2218 +				surface->format->colorkey);
 20.2219 +		glSDL_key2alpha(s);
 20.2220 +		SDL_SetColorKey(s, 0, 0);
 20.2221 +	}
 20.2222 +
 20.2223 +	if(surface->flags & SDL_SRCALPHA)
 20.2224 +		SDL_SetAlpha(s, SDL_SRCALPHA,
 20.2225 +				surface->format->alpha);
 20.2226 +	return s;
 20.2227 +}
 20.2228 +
 20.2229 +
 20.2230 +/*----------------------------------------------------------
 20.2231 +  glSDL specific API extensions
 20.2232 +  ----------------------------------------------------------*/
 20.2233 +
 20.2234 +static void glSDL_Invalidate(SDL_Surface *surface, SDL_Rect *area)
 20.2235 +{
 20.2236 +	private_hwdata *txi;
 20.2237 +	if(!surface)
 20.2238 +		return;
 20.2239 +	txi = glSDL_GetTexInfo(surface);
 20.2240 +	if(!txi)
 20.2241 +		return;
 20.2242 +	if(!area)
 20.2243 +	{
 20.2244 +		txi->invalid_area.x = 0;
 20.2245 +		txi->invalid_area.y = 0;
 20.2246 +		txi->invalid_area.w = surface->w;
 20.2247 +		txi->invalid_area.h = surface->h;
 20.2248 +		return;
 20.2249 +	}
 20.2250 +	txi->invalid_area = *area;
 20.2251 +}
 20.2252 +
 20.2253 +
 20.2254 +static void glSDL_SetLogicSize(_THIS, SDL_Surface *surface, int w, int h)
 20.2255 +{
 20.2256 +	SDL_Rect r;
 20.2257 +	private_hwdata *txi;
 20.2258 +	if(!IS_GLSDL_SURFACE(surface))
 20.2259 +		return;
 20.2260 +
 20.2261 +	txi = glSDL_GetTexInfo(surface);
 20.2262 +
 20.2263 +	txi->lw = w;
 20.2264 +	txi->lh = h;
 20.2265 +
 20.2266 +	if(SDL_VideoSurface != surface)
 20.2267 +		return;
 20.2268 +
 20.2269 +	r.x = r.y = 0;
 20.2270 +	r.w = w;
 20.2271 +	r.h = h;
 20.2272 +	glSDL_SetClipRect(this, surface, &r);
 20.2273 +
 20.2274 +	this->glMatrixMode(GL_MODELVIEW);
 20.2275 +	this->glLoadIdentity();
 20.2276 +	this->glTranslated(0.0f, 0.0f, 0.0f);
 20.2277 +
 20.2278 +	this->glDisable(GL_DEPTH_TEST);
 20.2279 +	this->glDisable(GL_CULL_FACE);
 20.2280 +
 20.2281 +	glSDL_reset();
 20.2282 +}
 20.2283 +
 20.2284 +static int glSDL_InitTexture(_THIS, SDL_Surface *datasurf, private_hwdata *txi, int tex)
 20.2285 +{
 20.2286 +	this->glGenTextures(1, (GLuint *)&txi->texture[tex]);
 20.2287 +	this->glBindTexture(GL_TEXTURE_2D, txi->texture[tex]);
 20.2288 +	glstate.texture = txi->texture[tex];
 20.2289 +	this->glPixelStorei(GL_UNPACK_ROW_LENGTH, datasurf->pitch /
 20.2290 +			datasurf->format->BytesPerPixel);
 20.2291 +	this->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 20.2292 +	this->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 20.2293 +	this->glTexImage2D(GL_TEXTURE_2D, 0,
 20.2294 +			datasurf->format->Amask ? GL_RGBA8 : GL_RGB8,
 20.2295 +			txi->texsize, txi->texsize, 0,
 20.2296 +			datasurf->format->Amask ? GL_RGBA : GL_RGB,
 20.2297 +			GL_UNSIGNED_BYTE, NULL);
 20.2298 +#ifdef DEBUG_GLSDL		
 20.2299 +	glSDL_print_glerror(this, 1);
 20.2300 +#endif
 20.2301 +	return 0;
 20.2302 +}
 20.2303 +
 20.2304 +
 20.2305 +/* Image tiled horizontally (wide surface), or not at all */
 20.2306 +static int glSDL_UploadHoriz(_THIS, SDL_Surface *datasurf, private_hwdata *txi)
 20.2307 +{
 20.2308 +	int bpp = datasurf->format->BytesPerPixel;
 20.2309 +	int res;
 20.2310 +	int tex = 0;
 20.2311 +	int fromx = 0;
 20.2312 +	int toy = txi->texsize;	/* To init first texture */
 20.2313 +	while(1)
 20.2314 +	{
 20.2315 +		int thistw = datasurf->w - fromx;
 20.2316 +		if(thistw > txi->tilew)
 20.2317 +			thistw = txi->tilew;
 20.2318 +		else if(thistw <= 0)
 20.2319 +			break;
 20.2320 +		if(toy + txi->tileh > txi->texsize)
 20.2321 +		{
 20.2322 +			toy = 0;
 20.2323 +			res = glSDL_InitTexture(this, datasurf, txi, tex);
 20.2324 +			if(res < 0)
 20.2325 +				return res;
 20.2326 +			++tex;
 20.2327 +		}
 20.2328 +		this->glTexSubImage2D(GL_TEXTURE_2D, 0, 0, toy,
 20.2329 +				thistw, txi->tileh,
 20.2330 +				datasurf->format->Amask ? GL_RGBA : GL_RGB,
 20.2331 +				GL_UNSIGNED_BYTE,
 20.2332 +				(char *)datasurf->pixels + bpp * fromx);
 20.2333 +#ifdef DEBUG_GLSDL		
 20.2334 +		glSDL_print_glerror(this, 2);
 20.2335 +#endif
 20.2336 +		fromx += txi->tilew;
 20.2337 +		toy += txi->tileh;
 20.2338 +	}
 20.2339 +	return 0;
 20.2340 +}
 20.2341 +
 20.2342 +
 20.2343 +/* Image tiled vertically (tall surface) */
 20.2344 +static int glSDL_UploadVert(_THIS, SDL_Surface *datasurf, private_hwdata *txi)
 20.2345 +{
 20.2346 +	int res;
 20.2347 +	int tex = 0;
 20.2348 +	int fromy = 0;
 20.2349 +	int tox = txi->texsize;	/* To init first texture */
 20.2350 +	while(1)
 20.2351 +	{
 20.2352 +		int thisth = datasurf->h - fromy;
 20.2353 +		if(thisth > txi->tileh)
 20.2354 +			thisth = txi->tileh;
 20.2355 +		else if(thisth <= 0)
 20.2356 +			break;
 20.2357 +		if(tox + txi->tilew > txi->texsize)
 20.2358 +		{
 20.2359 +			tox = 0;
 20.2360 +			res = glSDL_InitTexture(this, datasurf, txi, tex);
 20.2361 +			if(res < 0)
 20.2362 +				return res;
 20.2363 +			++tex;
 20.2364 +		}
 20.2365 +		this->glTexSubImage2D(GL_TEXTURE_2D, 0, tox, 0,
 20.2366 +				txi->tilew, thisth,
 20.2367 +				datasurf->format->Amask ? GL_RGBA : GL_RGB,
 20.2368 +				GL_UNSIGNED_BYTE,
 20.2369 +				(char *)datasurf->pixels + datasurf->pitch * fromy);
 20.2370 +#ifdef DEBUG_GLSDL		
 20.2371 +		glSDL_print_glerror(this, 3);
 20.2372 +#endif
 20.2373 +		fromy += txi->tileh;
 20.2374 +		tox += txi->tilew;
 20.2375 +	}
 20.2376 +	return 0;
 20.2377 +}
 20.2378 +
 20.2379 +
 20.2380 +/* Image tiled two-way (huge surface) */
 20.2381 +static int glSDL_UploadHuge(_THIS, SDL_Surface *datasurf, private_hwdata *txi)
 20.2382 +{
 20.2383 +	int bpp = datasurf->format->BytesPerPixel;
 20.2384 +	int res;
 20.2385 +	int tex = 0;
 20.2386 +	int y = 0;
 20.2387 +	while(y < datasurf->h)
 20.2388 +	{
 20.2389 +		int x;
 20.2390 +		int thisth = datasurf->h - y;
 20.2391 +		if(thisth > txi->tileh)
 20.2392 +			thisth = txi->tileh;
 20.2393 +		x = 0;
 20.2394 +		while(x < datasurf->w)
 20.2395 +		{
 20.2396 +			int thistw = datasurf->w - x;
 20.2397 +			if(thistw > txi->tilew)
 20.2398 +				thistw = txi->tilew;
 20.2399 +			res = glSDL_InitTexture(this, datasurf, txi, tex++);
 20.2400 +			if(res < 0)
 20.2401 +				return res;
 20.2402 +			this->glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
 20.2403 +					thistw, thisth,
 20.2404 +					datasurf->format->Amask ? GL_RGBA : GL_RGB,
 20.2405 +					GL_UNSIGNED_BYTE,
 20.2406 +					(char *)datasurf->pixels +
 20.2407 +					datasurf->pitch * y + bpp * x);
 20.2408 +#ifdef DEBUG_GLSDL		
 20.2409 +			fprintf(stderr,"glTexSubImage(x = %d, y = %d, w = %d, h = %d)\n",
 20.2410 +					x, y, thistw, thisth);
 20.2411 +			glSDL_print_glerror(this, 4);
 20.2412 +#endif
 20.2413 +			x += txi->tilew;
 20.2414 +		}
 20.2415 +		y += txi->tileh;
 20.2416 +	}
 20.2417 +	return 0;
 20.2418 +}
 20.2419 +
 20.2420 +
 20.2421 +/* Upload all textures for a surface. */
 20.2422 +static int glSDL_UploadTextures(_THIS, SDL_Surface *datasurf, private_hwdata *txi)
 20.2423 +{
 20.2424 +	switch(txi->tilemode)
 20.2425 +	{
 20.2426 +	  case GLSDL_TM_SINGLE:
 20.2427 +	  case GLSDL_TM_HORIZONTAL:
 20.2428 +		glSDL_UploadHoriz(this, datasurf, txi);
 20.2429 +		break;
 20.2430 +	  case GLSDL_TM_VERTICAL:
 20.2431 +		glSDL_UploadVert(this, datasurf, txi);
 20.2432 +		break;
 20.2433 +	  case GLSDL_TM_HUGE:
 20.2434 +		glSDL_UploadHuge(this, datasurf, txi);
 20.2435 +		break;
 20.2436 +	}
 20.2437 +	return 0;
 20.2438 +}
 20.2439 +
 20.2440 +
 20.2441 +/*
 20.2442 + * IMPORTANT:
 20.2443 + *	This function will try various ways of giving you
 20.2444 + *	a TexInfo, and will succeed most of the time.
 20.2445 + *
 20.2446 + *	However, the TexInfo returned may be temporary,
 20.2447 + *	(as opposed to connected to 'surface'). A temporary
 20.2448 + *	TexInfo must be used only once and then thrown away,
 20.2449 + *	since it means that glSDL cannot track changes in
 20.2450 + *	the pixel data of 'texture'.
 20.2451 + */
 20.2452 +static private_hwdata *glSDL_UploadSurface(_THIS, SDL_Surface *surface)
 20.2453 +{
 20.2454 +	int i;
 20.2455 +	int converted = 0;
 20.2456 +	private_hwdata *txi = glSDL_GetTexInfo(surface);
 20.2457 +
 20.2458 +	if(IS_GLSDL_SURFACE(surface))
 20.2459 +	{
 20.2460 +		/*
 20.2461 +		 * Ok, this is a glSDL surface, and it *might* be
 20.2462 +		 * in texture memory already. If so, it may need
 20.2463 +		 * an update.
 20.2464 +		 */
 20.2465 +		if(txi->invalid_area.w)
 20.2466 +		{
 20.2467 +			glSDL_UnloadTexture(this, txi);
 20.2468 +		}
 20.2469 +		else
 20.2470 +		{
 20.2471 +			int missing = 0;
 20.2472 +			if(txi->textures)
 20.2473 +			{
 20.2474 +				for(i = 0; i < txi->textures; ++i)
 20.2475 +					if(GLSDL_NOTEX == txi->texture[i])
 20.2476 +					{
 20.2477 +						missing = 1;
 20.2478 +						break;
 20.2479 +					}
 20.2480 +				if(!missing)
 20.2481 +					return txi;	/* They're already there! */
 20.2482 +			}
 20.2483 +		}
 20.2484 +	}
 20.2485 +	else
 20.2486 +	{
 20.2487 +		/*
 20.2488 +		 * Nope, this isn't (yet) a glSDL surface. Let's
 20.2489 +		 * try to either make it one, or set up a temporary
 20.2490 +		 * TexInfo for it, valid for only one blit.
 20.2491 +		 */
 20.2492 +		if( (surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE )
 20.2493 +		{
 20.2494 +			txi = glSDL_AddTexInfo(this, surface);
 20.2495 +			if(!txi)
 20.2496 +			{
 20.2497 +				GLERR("UploadSurface(): Could not add TexInfo!");
 20.2498 +				return NULL;
 20.2499 +			}
 20.2500 +			surface->flags |= SDL_HWSURFACE;
 20.2501 +			surface->flags |= SDL_HWACCEL;
 20.2502 +		}
 20.2503 +		else
 20.2504 +		{
 20.2505 +			/* 
 20.2506 +			 * FIXME
 20.2507 +			 * here if the surface is small enough, it's a good 
 20.2508 +			 * candidate for a blit using glDrawPixels instead 
 20.2509 +			 * of a texture blit
 20.2510 +			 */
 20.2511 +			txi = glSDL_CreateTempTexInfo(this, surface);
 20.2512 +			if(!txi)
 20.2513 +			{
 20.2514 +				GLERR("UploadSurface(): Could not create temp TexInfo!");
 20.2515 +				return NULL;
 20.2516 +			}
 20.2517 +		}
 20.2518 +	}
 20.2519 +
 20.2520 +	if(txi->texsize > maxtexsize)
 20.2521 +	{
 20.2522 +		/* This surface wasn't tiled properly... */
 20.2523 +		if(txi->temporary)
 20.2524 +			glSDL_FreeTexInfo(this, txi);
 20.2525 +		GLERR("UploadSurface(): Too large texture!");
 20.2526 +		return NULL;
 20.2527 +	}
 20.2528 +
 20.2529 +	/*
 20.2530 +	 * Kludge: Convert if not of preferred RGB or RGBA format.
 20.2531 +	 *
 20.2532 +	 *	Conversion should only be done when *really* needed.
 20.2533 +	 *	That is, it should rarely have to be done with OpenGL
 20.2534 +	 *	1.2+.
 20.2535 +	 *
 20.2536 +	 *	Besides, any surface that's been SDL_DisplayFormat()ed
 20.2537 +	 *	should already be in the best known OpenGL format -
 20.2538 +	 *	preferably one that makes DMA w/o conversion possible.
 20.2539 +	 */
 20.2540 +	if(!glSDL_FormatIsOk(surface))
 20.2541 +	{
 20.2542 +#ifdef DEBUG_GLSDL		
 20.2543 +		fprintf(stderr, "glSDL: WARNING: On-the-fly conversion performed!\n");
 20.2544 +#endif
 20.2545 +		converted = 1;
 20.2546 +		/* NOTE: We forget about the original surface here. */
 20.2547 +		if(surface->format->Amask)
 20.2548 +			surface = glSDL_DisplayFormatAlpha(surface);
 20.2549 +		else
 20.2550 +			surface = glSDL_DisplayFormat(surface);
 20.2551 +		if(!surface)
 20.2552 +		{
 20.2553 +			GLERR("UploadSurface(): Could not convert surface!");
 20.2554 +			if(txi->temporary)
 20.2555 +				glSDL_FreeTexInfo(this, txi);
 20.2556 +			return NULL;
 20.2557 +		}
 20.2558 +	}
 20.2559 +
 20.2560 +	glSDL_UploadTextures(this, surface, txi);
 20.2561 +
 20.2562 +	if(converted)
 20.2563 +		SDL_FreeSurface(surface);
 20.2564 +
 20.2565 +	return txi;
 20.2566 +}
 20.2567 +
 20.2568 +
 20.2569 +static void glSDL_UnloadTexture(_THIS, private_hwdata *txi)
 20.2570 +{
 20.2571 +	int i;
 20.2572 +	for(i = 0; i < txi->textures; ++i)
 20.2573 +		if(txi->texture[i] != GLSDL_NOTEX)
 20.2574 +			this->glDeleteTextures(1, &txi->texture[i]);
 20.2575 +	SDL_memset(&txi->invalid_area, 0, sizeof(txi->invalid_area));
 20.2576 +}
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/src/video/glsdl/SDL_glsdl.h	Mon May 01 06:58:33 2006 +0000
    21.3 @@ -0,0 +1,38 @@
    21.4 +/*
    21.5 +    SDL - Simple DirectMedia Layer
    21.6 +    Copyright (C) 1997-2006 Sam Lantinga
    21.7 +
    21.8 +    This library is free software; you can redistribute it and/or
    21.9 +    modify it under the terms of the GNU Lesser General Public
   21.10 +    License as published by the Free Software Foundation; either
   21.11 +    version 2.1 of the License, or (at your option) any later version.
   21.12 +
   21.13 +    This library is distributed in the hope that it will be useful,
   21.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   21.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   21.16 +    Lesser General Public License for more details.
   21.17 +
   21.18 +    You should have received a copy of the GNU Lesser General Public
   21.19 +    License along with this library; if not, write to the Free Software
   21.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   21.21 +
   21.22 +    Sam Lantinga
   21.23 +    slouken@libsdl.org
   21.24 +*/
   21.25 +#include "SDL_config.h"
   21.26 +
   21.27 +/*
   21.28 + * glSDL "SDL-over-OpenGL" video driver implemented by
   21.29 + * David Olofson <david@olofson.net> and
   21.30 + * Stephane Marchesin <stephane.marchesin@wanadoo.fr>
   21.31 + */
   21.32 +
   21.33 +#ifndef _SDL_gl_h
   21.34 +#define _SDL_gl_h
   21.35 +
   21.36 +#include "../SDL_sysvideo.h"
   21.37 +
   21.38 +/* Hidden "this" pointer for the video functions */
   21.39 +#define _THIS	SDL_VideoDevice *this
   21.40 +
   21.41 +#endif /* _SDL_gl_h */
    22.1 --- a/src/video/maccommon/SDL_macevents.c	Fri Apr 28 16:55:41 2006 +0000
    22.2 +++ b/src/video/maccommon/SDL_macevents.c	Mon May 01 06:58:33 2006 +0000
    22.3 @@ -382,7 +382,7 @@
    22.4  	  case updateEvt: {
    22.5  		BeginUpdate(SDL_Window);
    22.6  	#if SDL_VIDEO_OPENGL
    22.7 -		if (SDL_VideoSurface->flags & SDL_OPENGL)
    22.8 +		if (SDL_VideoSurface->flags & SDL_INTERNALOPENGL)
    22.9  			SDL_GL_SwapBuffers();
   22.10  		else
   22.11  	#endif
    23.1 --- a/src/video/macdsp/SDL_dspvideo.c	Fri Apr 28 16:55:41 2006 +0000
    23.2 +++ b/src/video/macdsp/SDL_dspvideo.c	Mon May 01 06:58:33 2006 +0000
    23.3 @@ -722,7 +722,7 @@
    23.4  {
    23.5  			
    23.6  		
    23.7 -	 if ( current->flags & SDL_OPENGL )  { 
    23.8 +	 if ( current->flags & SDL_INTERNALOPENGL )  { 
    23.9  	   Mac_GL_Quit (this);	   	
   23.10  	}
   23.11  		
   23.12 @@ -918,14 +918,14 @@
   23.13  	}
   23.14  	
   23.15      
   23.16 -	if ( (current->flags & SDL_HWSURFACE) || (current->flags & SDL_OPENGL) )
   23.17 +	if ( (current->flags & SDL_HWSURFACE) || (current->flags & SDL_INTERNALOPENGL) )
   23.18  		DSpContext_SetVBLProc (dsp_context, DSp_VBLProc, NULL);
   23.19      #endif
   23.20  	
   23.21  	if (bpp == 8)	
   23.22  	   current->flags |= SDL_HWPALETTE;
   23.23  	
   23.24 -	if (flags & SDL_OPENGL) {
   23.25 +	if (flags & SDL_INTERNALOPENGL) {
   23.26  		   
   23.27  	   Rect rect;
   23.28  	   RGBColor rgb = { 0.0, 0.0, 0.0 };
   23.29 @@ -960,7 +960,7 @@
   23.30  	      return NULL;
   23.31  	   }
   23.32  	   	   	   	   
   23.33 -	   current->flags |= SDL_OPENGL;	
   23.34 +	   current->flags |= SDL_INTERNALOPENGL;	
   23.35  	}
   23.36  	
   23.37  	return current; 
    24.1 --- a/src/video/macrom/SDL_romvideo.c	Fri Apr 28 16:55:41 2006 +0000
    24.2 +++ b/src/video/macrom/SDL_romvideo.c	Mon May 01 06:58:33 2006 +0000
    24.3 @@ -583,9 +583,9 @@
    24.4  	SelectWindow(SDL_Window);
    24.5  
    24.6  	/* Handle OpenGL support */
    24.7 -	if ( flags & SDL_OPENGL ) {
    24.8 +	if ( flags & SDL_INTERNALOPENGL ) {
    24.9  		if ( Mac_GL_Init(this) == 0 ) {
   24.10 -			current->flags |= SDL_OPENGL;
   24.11 +			current->flags |= SDL_INTERNALOPENGL;
   24.12  		} else {
   24.13  			current = NULL;
   24.14  		}
    25.1 --- a/src/video/photon/SDL_ph_image.c	Fri Apr 28 16:55:41 2006 +0000
    25.2 +++ b/src/video/photon/SDL_ph_image.c	Mon May 01 06:58:33 2006 +0000
    25.3 @@ -315,7 +315,7 @@
    25.4  
    25.5      if (ph_SetupOpenGLContext(this, screen->w, screen->h, screen->format->BitsPerPixel, screen->flags)!=0)
    25.6      {
    25.7 -        screen->flags &= ~SDL_OPENGL;
    25.8 +        screen->flags &= ~SDL_INTERNALOPENGL;
    25.9          return -1;
   25.10      }
   25.11     
   25.12 @@ -328,7 +328,7 @@
   25.13  {
   25.14  
   25.15  #if SDL_VIDEO_OPENGL
   25.16 -    if ((screen->flags & SDL_OPENGL)==SDL_OPENGL)
   25.17 +    if (screen->flags & SDL_INTERNALOPENGL)
   25.18      {
   25.19          if (oglctx)
   25.20          {
   25.21 @@ -486,7 +486,7 @@
   25.22      ph_DestroyImage(this, screen);
   25.23      
   25.24  #if SDL_VIDEO_OPENGL
   25.25 -    if ((flags & SDL_OPENGL)==SDL_OPENGL)
   25.26 +    if (flags & SDL_INTERNALOPENGL)
   25.27      {
   25.28          setupresult=ph_SetupOpenGLImage(this, screen);
   25.29      }
    26.1 --- a/src/video/photon/SDL_ph_modes.c	Fri Apr 28 16:55:41 2006 +0000
    26.2 +++ b/src/video/photon/SDL_ph_modes.c	Mon May 01 06:58:33 2006 +0000
    26.3 @@ -309,7 +309,7 @@
    26.4  
    26.5          if (this->screen)
    26.6          {
    26.7 -            if ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL)
    26.8 +            if (this->screen->flags & SDL_INTERNALOPENGL)
    26.9              {
   26.10  #if !SDL_VIDEO_OPENGL || (_NTO_VERSION < 630)
   26.11                  return 0; /* 6.3.0 */
   26.12 @@ -345,7 +345,7 @@
   26.13         
   26.14      if (currently_fullscreen)
   26.15      {
   26.16 -        if ((this->screen) && ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL))
   26.17 +        if ((this->screen) && (this->screen->flags & SDL_INTERNALOPENGL))
   26.18          {
   26.19  #if !SDL_VIDEO_OPENGL || (_NTO_VERSION < 630)
   26.20              return 0;
    27.1 --- a/src/video/photon/SDL_ph_mouse.c	Fri Apr 28 16:55:41 2006 +0000
    27.2 +++ b/src/video/photon/SDL_ph_mouse.c	Mon May 01 06:58:33 2006 +0000
    27.3 @@ -126,10 +126,10 @@
    27.4      }
    27.5  
    27.6      /* looks like photon can't draw mouse cursor in direct mode */
    27.7 -    if ((this->screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)
    27.8 +    if (this->screen->flags & SDL_FULLSCREEN)
    27.9      {
   27.10           /* disable the fake mouse in the fullscreen OpenGL mode */
   27.11 -         if ((this->screen->flags & SDL_OPENGL) == SDL_OPENGL)
   27.12 +         if (this->screen->flags & SDL_INTERNALOPENGL)
   27.13           {
   27.14               cursor=NULL;
   27.15           }
    28.1 --- a/src/video/photon/SDL_ph_video.c	Fri Apr 28 16:55:41 2006 +0000
    28.2 +++ b/src/video/photon/SDL_ph_video.c	Mon May 01 06:58:33 2006 +0000
    28.3 @@ -475,12 +475,12 @@
    28.4          return NULL;
    28.5      }
    28.6  
    28.7 -    if ((current->flags & SDL_OPENGL)==SDL_OPENGL)
    28.8 +    if (current->flags & SDL_INTERNALOPENGL)
    28.9      {
   28.10  #if !SDL_VIDEO_OPENGL
   28.11          /* if no built-in OpenGL support */
   28.12          SDL_SetError("ph_SetVideoMode(): no OpenGL support, you need to recompile SDL.\n");
   28.13 -        current->flags &= ~SDL_OPENGL;
   28.14 +        current->flags &= ~SDL_INTERNALOPENGL;
   28.15          return NULL;
   28.16  #endif /* SDL_VIDEO_OPENGL */
   28.17      }
    29.1 --- a/src/video/qtopia/SDL_sysvideo.cc	Fri Apr 28 16:55:41 2006 +0000
    29.2 +++ b/src/video/qtopia/SDL_sysvideo.cc	Mon May 01 06:58:33 2006 +0000
    29.3 @@ -296,7 +296,7 @@
    29.4      } else {
    29.5        SDL_SetError("Unsupported resolution, %dx%d\n", width, height);
    29.6      }
    29.7 -    if ( flags & SDL_OPENGL ) {
    29.8 +    if ( flags & SDL_INTERNALOPENGL ) {
    29.9        SDL_SetError("OpenGL not supported");
   29.10        return(NULL);
   29.11      } 
    30.1 --- a/src/video/quartz/SDL_QuartzVideo.m	Fri Apr 28 16:55:41 2006 +0000
    30.2 +++ b/src/video/quartz/SDL_QuartzVideo.m	Mon May 01 06:58:33 2006 +0000
    30.3 @@ -379,7 +379,7 @@
    30.4              Release the OpenGL context
    30.5              Do this first to avoid trash on the display before fade
    30.6          */
    30.7 -        if ( mode_flags & SDL_OPENGL ) {
    30.8 +        if ( mode_flags & SDL_INTERNALOPENGL ) {
    30.9          
   30.10              QZ_TearDownOpenGL (this);
   30.11              CGLSetFullScreen (NULL);
   30.12 @@ -406,7 +406,7 @@
   30.13          window_view = nil;
   30.14  
   30.15          /* Release the OpenGL context */
   30.16 -        if ( mode_flags & SDL_OPENGL )
   30.17 +        if ( mode_flags & SDL_INTERNALOPENGL )
   30.18              QZ_TearDownOpenGL (this);
   30.19      }
   30.20  
   30.21 @@ -512,7 +512,7 @@
   30.22          current->flags |= SDL_HWPALETTE;
   30.23  
   30.24      /* Setup OpenGL for a fullscreen context */
   30.25 -    if (flags & SDL_OPENGL) {
   30.26 +    if (flags & SDL_INTERNALOPENGL) {
   30.27  
   30.28          CGLError err;
   30.29          CGLContextObj ctx;
   30.30 @@ -535,7 +535,7 @@
   30.31  
   30.32          [ gl_context flushBuffer ];
   30.33  
   30.34 -        current->flags |= SDL_OPENGL;
   30.35 +        current->flags |= SDL_INTERNALOPENGL;
   30.36      }
   30.37  
   30.38      /* If we don't hide menu bar, it will get events and interrupt the program */
   30.39 @@ -609,8 +609,8 @@
   30.40              QZ_UnsetVideoMode (this, TRUE);
   30.41          }
   30.42          else if ( ((mode_flags ^ flags) & (SDL_NOFRAME|SDL_RESIZABLE)) ||
   30.43 -                  (mode_flags & SDL_OPENGL) || 
   30.44 -                  (flags & SDL_OPENGL) ) {
   30.45 +                  (mode_flags & SDL_INTERNALOPENGL) || 
   30.46 +                  (flags & SDL_INTERNALOPENGL) ) {
   30.47              QZ_UnsetVideoMode (this, TRUE);
   30.48          }
   30.49      }
   30.50 @@ -708,7 +708,7 @@
   30.51      }
   30.52  
   30.53      /* For OpenGL, we bind the context to a subview */
   30.54 -    if ( flags & SDL_OPENGL ) {
   30.55 +    if ( flags & SDL_INTERNALOPENGL ) {
   30.56  
   30.57          if ( ! QZ_SetupOpenGL (this, *bpp, flags) ) {
   30.58              if (fade_token != kCGDisplayFadeReservationInvalidToken) {
   30.59 @@ -725,7 +725,7 @@
   30.60          [ window_view release ];
   30.61          [ gl_context makeCurrentContext];
   30.62          [ qz_window makeKeyAndOrderFront:nil ];
   30.63 -        current->flags |= SDL_OPENGL;
   30.64 +        current->flags |= SDL_INTERNALOPENGL;
   30.65      }
   30.66      /* For 2D, we set the subview to an NSQuickDrawView */
   30.67      else {
    31.1 --- a/src/video/quartz/SDL_QuartzWM.m	Fri Apr 28 16:55:41 2006 +0000
    31.2 +++ b/src/video/quartz/SDL_QuartzWM.m	Mon May 01 06:58:33 2006 +0000
    31.3 @@ -147,7 +147,7 @@
    31.4          *p = [ window_view convertPoint:*p toView: nil ];
    31.5          
    31.6          /* We need a workaround in OpenGL mode */
    31.7 -        if ( SDL_VideoSurface->flags & SDL_OPENGL ) {
    31.8 +        if ( SDL_VideoSurface->flags & SDL_INTERNALOPENGL ) {
    31.9              p->y = [window_view frame].size.height - p->y;
   31.10          }
   31.11      }
   31.12 @@ -165,7 +165,7 @@
   31.13          *p = [ window_view convertPoint:*p fromView: nil ];
   31.14          
   31.15          /* We need a workaround in OpenGL mode */
   31.16 -        if ( SDL_VideoSurface != NULL && (SDL_VideoSurface->flags & SDL_OPENGL) ) {
   31.17 +        if ( SDL_VideoSurface != NULL && (SDL_VideoSurface->flags & SDL_INTERNALOPENGL) ) {
   31.18              p->y = [window_view frame].size.height - p->y;
   31.19          }
   31.20      }
    32.1 --- a/src/video/quartz/SDL_QuartzWindow.m	Fri Apr 28 16:55:41 2006 +0000
    32.2 +++ b/src/video/quartz/SDL_QuartzWindow.m	Mon May 01 06:58:33 2006 +0000
    32.3 @@ -55,7 +55,7 @@
    32.4  /* we override these methods to fix the miniaturize animation/dock icon bug */
    32.5  - (void)miniaturize:(id)sender
    32.6  {
    32.7 -    if (SDL_VideoSurface->flags & SDL_OPENGL) {
    32.8 +    if (SDL_VideoSurface->flags & SDL_INTERNALOPENGL) {
    32.9      
   32.10          /* 
   32.11              Future: Grab framebuffer and put into NSImage
   32.12 @@ -86,7 +86,7 @@
   32.13       SDL_VideoDevice *this = (SDL_VideoDevice*)current_video;
   32.14      
   32.15      /* make sure pixels are fully opaque */
   32.16 -    if (! ( SDL_VideoSurface->flags & SDL_OPENGL ) )
   32.17 +    if (! ( SDL_VideoSurface->flags & SDL_INTERNALOPENGL ) )
   32.18          QZ_SetPortAlphaOpaque ();
   32.19      
   32.20      /* save current visible SDL surface */
   32.21 @@ -126,7 +126,7 @@
   32.22          SDL_PrivateResize (newViewFrame.size.width, newViewFrame.size.height);
   32.23  
   32.24          /* If not OpenGL, we have to update the pixels and pitch */
   32.25 -        if ( ! ( SDL_VideoSurface->flags & SDL_OPENGL ) ) {
   32.26 +        if ( ! ( SDL_VideoSurface->flags & SDL_INTERNALOPENGL ) ) {
   32.27              
   32.28              CGrafPtr thePort = [ window_view qdPort ];
   32.29              LockPortBits ( thePort );
   32.30 @@ -164,7 +164,7 @@
   32.31      if ( this ) {
   32.32      
   32.33          /* make sure pixels are fully opaque */
   32.34 -        if (! ( SDL_VideoSurface->flags & SDL_OPENGL ) )
   32.35 +        if (! ( SDL_VideoSurface->flags & SDL_INTERNALOPENGL ) )
   32.36              QZ_SetPortAlphaOpaque ();
   32.37            
   32.38          /* save current visible SDL surface */
    33.1 --- a/src/video/wincommon/SDL_lowvideo.h	Fri Apr 28 16:55:41 2006 +0000
    33.2 +++ b/src/video/wincommon/SDL_lowvideo.h	Mon May 01 06:58:33 2006 +0000
    33.3 @@ -51,17 +51,17 @@
    33.4  #define WINDIB_FULLSCREEN()						\
    33.5  (									\
    33.6  	SDL_VideoSurface &&						\
    33.7 -	((SDL_VideoSurface->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) && \
    33.8 -	(((SDL_VideoSurface->flags & SDL_OPENGL   ) == SDL_OPENGL    ) || \
    33.9 -	((SDL_strcmp(this->name, "windib") == 0) || \
   33.10 -	 (SDL_strcmp(this->name, "gapi") == 0))) \
   33.11 +	(SDL_VideoSurface->flags & SDL_FULLSCREEN) &&			\
   33.12 +	((SDL_VideoSurface->flags & SDL_INTERNALOPENGL) ||		\
   33.13 +	((SDL_strcmp(this->name, "windib") == 0) ||			\
   33.14 +	 (SDL_strcmp(this->name, "gapi") == 0)))			\
   33.15  )
   33.16  #define DDRAW_FULLSCREEN() 						\
   33.17  (									\
   33.18  	SDL_VideoSurface &&						\
   33.19 -	((SDL_VideoSurface->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) && \
   33.20 -	((SDL_VideoSurface->flags & SDL_OPENGL    ) != SDL_OPENGL    ) && \
   33.21 -	(SDL_strcmp(this->name, "directx") == 0)				\
   33.22 +	(SDL_VideoSurface->flags & SDL_FULLSCREEN) &&			\
   33.23 +	(SDL_VideoSurface->flags & SDL_INTERNALOPENGL) &&		\
   33.24 +	(SDL_strcmp(this->name, "directx") == 0)			\
   33.25  )
   33.26  
   33.27  #define DINPUT_FULLSCREEN()	DDRAW_FULLSCREEN()
    34.1 --- a/src/video/wincommon/SDL_sysevents.c	Fri Apr 28 16:55:41 2006 +0000
    34.2 +++ b/src/video/wincommon/SDL_sysevents.c	Mon May 01 06:58:33 2006 +0000
    34.3 @@ -684,7 +684,7 @@
    34.4  
    34.5  			hdc = BeginPaint(SDL_Window, &ps);
    34.6  			if ( current_video->screen &&
    34.7 -			     !(current_video->screen->flags & SDL_OPENGL) ) {
    34.8 +			     !(current_video->screen->flags & SDL_INTERNALOPENGL) ) {
    34.9  				WIN_WinPAINT(current_video, hdc);
   34.10  			}
   34.11  			EndPaint(SDL_Window, &ps);
    35.1 --- a/src/video/windib/SDL_dibvideo.c	Fri Apr 28 16:55:41 2006 +0000
    35.2 +++ b/src/video/windib/SDL_dibvideo.c	Mon May 01 06:58:33 2006 +0000
    35.3 @@ -484,7 +484,7 @@
    35.4  	Uint32 Rmask, Gmask, Bmask;
    35.5  
    35.6  	/* Clean up any GL context that may be hanging around */
    35.7 -	if ( current->flags & SDL_OPENGL ) {
    35.8 +	if ( current->flags & SDL_INTERNALOPENGL ) {
    35.9  		WIN_GL_ShutDown(this);
   35.10  	}
   35.11  	SDL_resizing = 1;
   35.12 @@ -686,7 +686,7 @@
   35.13  	if ( screen_bmp != NULL ) {
   35.14  		DeleteObject(screen_bmp);
   35.15  	}
   35.16 -	if ( ! (flags & SDL_OPENGL) ) {
   35.17 +	if ( ! (flags & SDL_INTERNALOPENGL) ) {
   35.18  		BOOL is16bitmode = (video->format->BytesPerPixel == 2);
   35.19  
   35.20  		/* Suss out the bitmap info header */
   35.21 @@ -814,11 +814,11 @@
   35.22  	SDL_resizing = 0;
   35.23  
   35.24  	/* Set up for OpenGL */
   35.25 -	if ( flags & SDL_OPENGL ) {
   35.26 +	if ( flags & SDL_INTERNALOPENGL ) {
   35.27  		if ( WIN_GL_SetupWindow(this) < 0 ) {
   35.28  			return(NULL);
   35.29  		}
   35.30 -		video->flags |= SDL_OPENGL;
   35.31 +		video->flags |= SDL_INTERNALOPENGL;
   35.32  	}
   35.33  
   35.34  	/* JC 14 Mar 2006
   35.35 @@ -1035,7 +1035,7 @@
   35.36  				ShowWindow(SDL_Window, SW_HIDE);
   35.37  			}
   35.38  #endif
   35.39 -			if ( this->screen->flags & SDL_OPENGL ) {
   35.40 +			if ( this->screen->flags & SDL_INTERNALOPENGL ) {
   35.41  				WIN_GL_ShutDown(this);
   35.42  			}
   35.43  			this->screen->pixels = NULL;
    36.1 --- a/src/video/windx5/SDL_dx5events.c	Fri Apr 28 16:55:41 2006 +0000
    36.2 +++ b/src/video/windx5/SDL_dx5events.c	Mon May 01 06:58:33 2006 +0000
    36.3 @@ -299,7 +299,7 @@
    36.4  	}
    36.5  
    36.6  	/* If we are in windowed mode, Windows is taking care of the mouse */
    36.7 -	if (  (SDL_PublicSurface->flags & SDL_OPENGL) ||
    36.8 +	if (  (SDL_PublicSurface->flags & SDL_INTERNALOPENGL) ||
    36.9  	     !(SDL_PublicSurface->flags & SDL_FULLSCREEN) ) {
   36.10  		return;
   36.11  	}
    37.1 --- a/src/video/windx5/SDL_dx5video.c	Fri Apr 28 16:55:41 2006 +0000
    37.2 +++ b/src/video/windx5/SDL_dx5video.c	Mon May 01 06:58:33 2006 +0000
    37.3 @@ -1031,19 +1031,19 @@
    37.4  
    37.5  #ifndef NO_CHANGEDISPLAYSETTINGS
    37.6  	/* Unset any previous OpenGL fullscreen mode */
    37.7 -	if ( (current->flags & (SDL_OPENGL|SDL_FULLSCREEN)) ==
    37.8 -	                       (SDL_OPENGL|SDL_FULLSCREEN) ) {
    37.9 +	if ( (current->flags & (SDL_INTERNALOPENGL|SDL_FULLSCREEN)) ==
   37.10 +	                       (SDL_INTERNALOPENGL|SDL_FULLSCREEN) ) {
   37.11  		ChangeDisplaySettings(NULL, 0);
   37.12  	}
   37.13  #endif
   37.14  
   37.15  	/* Clean up any GL context that may be hanging around */
   37.16 -	if ( current->flags & SDL_OPENGL ) {
   37.17 +	if ( current->flags & SDL_INTERNALOPENGL ) {
   37.18  		WIN_GL_ShutDown(this);
   37.19  	}
   37.20  
   37.21  	/* If we are setting a GL mode, use GDI, not DirectX (yuck) */
   37.22 -	if ( flags & SDL_OPENGL ) {
   37.23 +	if ( flags & SDL_INTERNALOPENGL ) {
   37.24  		Uint32 Rmask, Gmask, Bmask;
   37.25  
   37.26  		/* Recalculate the bitmasks if necessary */
   37.27 @@ -1215,7 +1215,7 @@
   37.28  		if ( WIN_GL_SetupWindow(this) < 0 ) {
   37.29  			return(NULL);
   37.30  		}
   37.31 -		video->flags |= SDL_OPENGL;
   37.32 +		video->flags |= SDL_INTERNALOPENGL;
   37.33  		return(video);
   37.34  	}
   37.35  
   37.36 @@ -2361,13 +2361,13 @@
   37.37  	/* If we're fullscreen GL, we need to reset the display */
   37.38  	if ( this->screen != NULL ) {
   37.39  #ifndef NO_CHANGEDISPLAYSETTINGS
   37.40 -		if ( (this->screen->flags & (SDL_OPENGL|SDL_FULLSCREEN)) ==
   37.41 -		                            (SDL_OPENGL|SDL_FULLSCREEN) ) {
   37.42 +		if ( (this->screen->flags & (SDL_INTERNALOPENGL|SDL_FULLSCREEN)) ==
   37.43 +		                            (SDL_INTERNALOPENGL|SDL_FULLSCREEN) ) {
   37.44  			ChangeDisplaySettings(NULL, 0);
   37.45  			ShowWindow(SDL_Window, SW_HIDE);
   37.46  		}
   37.47  #endif
   37.48 -		if ( this->screen->flags & SDL_OPENGL ) {
   37.49 +		if ( this->screen->flags & SDL_INTERNALOPENGL ) {
   37.50  			WIN_GL_ShutDown(this);
   37.51  		}
   37.52  	}
    38.1 --- a/src/video/x11/SDL_x11events.c	Fri Apr 28 16:55:41 2006 +0000
    38.2 +++ b/src/video/x11/SDL_x11events.c	Mon May 01 06:58:33 2006 +0000
    38.3 @@ -562,7 +562,7 @@
    38.4  			}
    38.5  		    } else {
    38.6  			/* OpenGL windows need to know about the change */
    38.7 -			if ( SDL_VideoSurface->flags & SDL_OPENGL ) {
    38.8 +			if ( SDL_VideoSurface->flags & SDL_INTERNALOPENGL ) {
    38.9  				SDL_PrivateExpose();
   38.10  			}
   38.11  		    }
    39.1 --- a/src/video/x11/SDL_x11image.c	Fri Apr 28 16:55:41 2006 +0000
    39.2 +++ b/src/video/x11/SDL_x11image.c	Mon May 01 06:58:33 2006 +0000
    39.3 @@ -185,7 +185,7 @@
    39.4  	int retval;
    39.5  
    39.6  	X11_DestroyImage(this, screen);
    39.7 -        if ( flags & SDL_OPENGL ) {  /* No image when using GL */
    39.8 +        if ( flags & SDL_INTERNALOPENGL ) {  /* No image when using GL */
    39.9          	retval = 0;
   39.10          } else {
   39.11  		retval = X11_SetupImage(this, screen);
    40.1 --- a/src/video/x11/SDL_x11modes.c	Fri Apr 28 16:55:41 2006 +0000
    40.2 +++ b/src/video/x11/SDL_x11modes.c	Mon May 01 06:58:33 2006 +0000
    40.3 @@ -914,7 +914,7 @@
    40.4      /* We may need to refresh the screen at this point (no backing store)
    40.5         We also don't get an event, which is why we explicitly refresh. */
    40.6      if ( this->screen ) {
    40.7 -        if ( this->screen->flags & SDL_OPENGL ) {
    40.8 +        if ( this->screen->flags & SDL_INTERNALOPENGL ) {
    40.9              SDL_PrivateExpose();
   40.10          } else {
   40.11              X11_RefreshDisplay(this);
   40.12 @@ -976,7 +976,7 @@
   40.13      /* We may need to refresh the screen at this point (no backing store)
   40.14         We also don't get an event, which is why we explicitly refresh. */
   40.15      if ( this->screen ) {
   40.16 -        if ( this->screen->flags & SDL_OPENGL ) {
   40.17 +        if ( this->screen->flags & SDL_INTERNALOPENGL ) {
   40.18              SDL_PrivateExpose();
   40.19          } else {
   40.20              X11_RefreshDisplay(this);
    41.1 --- a/src/video/x11/SDL_x11video.c	Fri Apr 28 16:55:41 2006 +0000
    41.2 +++ b/src/video/x11/SDL_x11video.c	Mon May 01 06:58:33 2006 +0000
    41.3 @@ -585,7 +585,7 @@
    41.4  {
    41.5  	/* Clean up OpenGL */
    41.6  	if ( screen ) {
    41.7 -		screen->flags &= ~SDL_OPENGL;
    41.8 +		screen->flags &= ~SDL_INTERNALOPENGL;
    41.9  	}
   41.10  	X11_GL_Shutdown(this);
   41.11  
   41.12 @@ -791,7 +791,7 @@
   41.13  	}
   41.14  
   41.15  	/* find out which visual we are going to use */
   41.16 -	if ( flags & SDL_OPENGL ) {
   41.17 +	if ( flags & SDL_INTERNALOPENGL ) {
   41.18  		XVisualInfo *vi;
   41.19  
   41.20  		vi = X11_GL_GetVisual(this);
   41.21 @@ -904,7 +904,7 @@
   41.22  
   41.23  	/* Create (or use) the X11 display window */
   41.24  	if ( !SDL_windowid ) {
   41.25 -		if ( flags & SDL_OPENGL ) {
   41.26 +		if ( flags & SDL_INTERNALOPENGL ) {
   41.27  			if ( X11_GL_CreateWindow(this, w, h) < 0 ) {
   41.28  				return(-1);
   41.29  			}
   41.30 @@ -927,11 +927,11 @@
   41.31  					| PointerMotionMask | ExposureMask ));
   41.32  	}
   41.33  	/* Create the graphics context here, once we have a window */
   41.34 -	if ( flags & SDL_OPENGL ) {
   41.35 +	if ( flags & SDL_INTERNALOPENGL ) {
   41.36  		if ( X11_GL_CreateContext(this) < 0 ) {
   41.37  			return(-1);
   41.38  		} else {
   41.39 -			screen->flags |= SDL_OPENGL;
   41.40 +			screen->flags |= SDL_INTERNALOPENGL;
   41.41  		}
   41.42  	} else {
   41.43  		XGCValues gcv;
   41.44 @@ -946,7 +946,7 @@
   41.45  	}
   41.46  
   41.47  	/* Set our colormaps when not setting a GL mode */
   41.48 -	if ( ! (flags & SDL_OPENGL) ) {
   41.49 +	if ( ! (flags & SDL_INTERNALOPENGL) ) {
   41.50  		XSetWindowColormap(SDL_Display, SDL_Window, SDL_XColorMap);
   41.51  		if( !SDL_windowid ) {
   41.52  		    XSetWindowColormap(SDL_Display, FSwindow, SDL_XColorMap);
   41.53 @@ -1063,7 +1063,7 @@
   41.54  
   41.55  	/* Set up the X11 window */
   41.56  	saved_flags = current->flags;
   41.57 -	if ( (SDL_Window) && ((saved_flags&SDL_OPENGL) == (flags&SDL_OPENGL))
   41.58 +	if ( (SDL_Window) && ((saved_flags&SDL_INTERNALOPENGL) == (flags&SDL_INTERNALOPENGL))
   41.59  	      && (bpp == current->format->BitsPerPixel)
   41.60            && ((saved_flags&SDL_NOFRAME) == (flags&SDL_NOFRAME)) ) {
   41.61  		if (X11_ResizeWindow(this, current, width, height, flags) < 0) {
   41.62 @@ -1079,7 +1079,7 @@
   41.63  
   41.64  	/* Set up the new mode framebuffer */
   41.65  	if ( ((current->w != width) || (current->h != height)) ||
   41.66 -             ((saved_flags&SDL_OPENGL) != (flags&SDL_OPENGL)) ) {
   41.67 +             ((saved_flags&SDL_INTERNALOPENGL) != (flags&SDL_INTERNALOPENGL)) ) {
   41.68  		current->w = width;
   41.69  		current->h = height;
   41.70  		current->pitch = SDL_CalculatePitch(current);
    42.1 --- a/src/video/xbios/SDL_xbios.c	Fri Apr 28 16:55:41 2006 +0000
    42.2 +++ b/src/video/xbios/SDL_xbios.c	Mon May 01 06:58:33 2006 +0000
    42.3 @@ -574,7 +574,7 @@
    42.4  	XBIOS_screens[0]=(void *) (( (long) XBIOS_screensmem[0]+256) & 0xFFFFFF00UL);
    42.5  
    42.6  #if SDL_VIDEO_OPENGL
    42.7 -	if (flags & SDL_OPENGL) {
    42.8 +	if (flags & SDL_INTERNALOPENGL) {
    42.9  		if (this->gl_config.double_buffer) {
   42.10  			flags |= SDL_DOUBLEBUF;
   42.11  		}
   42.12 @@ -618,14 +618,14 @@
   42.13  	XBIOS_fbnum = 0;
   42.14  
   42.15  #if SDL_VIDEO_OPENGL
   42.16 -	if (flags & SDL_OPENGL) {
   42.17 +	if (flags & SDL_INTERNALOPENGL) {
   42.18  		if (!SDL_AtariGL_Init(this, current)) {
   42.19  			XBIOS_FreeBuffers(this);
   42.20  			SDL_SetError("Can not create OpenGL context");
   42.21  			return NULL;
   42.22  		}
   42.23  
   42.24 -		modeflags |= SDL_OPENGL;
   42.25 +		modeflags |= SDL_INTERNALOPENGL;
   42.26  	}
   42.27  #endif
   42.28  
    43.1 --- a/test/testblitspeed.c	Fri Apr 28 16:55:41 2006 +0000
    43.2 +++ b/test/testblitspeed.c	Mon May 01 06:58:33 2006 +0000
    43.3 @@ -116,7 +116,6 @@
    43.4          append_sdl_surface_flag(surface, f, sizeof (f), SDL_DOUBLEBUF);
    43.5          append_sdl_surface_flag(surface, f, sizeof (f), SDL_FULLSCREEN);
    43.6          append_sdl_surface_flag(surface, f, sizeof (f), SDL_OPENGL);
    43.7 -        append_sdl_surface_flag(surface, f, sizeof (f), SDL_OPENGLBLIT);
    43.8          append_sdl_surface_flag(surface, f, sizeof (f), SDL_RESIZABLE);
    43.9          append_sdl_surface_flag(surface, f, sizeof (f), SDL_NOFRAME);
   43.10          append_sdl_surface_flag(surface, f, sizeof (f), SDL_HWACCEL);