Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Updated to 1.3.0, SDL_OPENGLBLIT is no longer supported
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Apr 27, 2006
1 parent 3f5a825 commit 190fe3e
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 361 deletions.
1 change: 1 addition & 0 deletions TODO
Expand Up @@ -2,6 +2,7 @@
Wish list for the 1.3 development branch:
http://bugzilla.libsdl.org/

* Support querying and setting refresh rate with video modes
* Add mousewheel events (new unified event architecture?)
* DirectInput joystick support needs to be implemented
* Be able to enumerate and select available audio and video drivers
Expand Down
8 changes: 4 additions & 4 deletions configure.in
Expand Up @@ -15,10 +15,10 @@ dnl Set various version strings - taken gratefully from the GTk sources
# set SDL_BINARY_AGE and SDL_INTERFACE_AGE to 0.
#
SDL_MAJOR_VERSION=1
SDL_MINOR_VERSION=2
SDL_MICRO_VERSION=10
SDL_INTERFACE_AGE=3
SDL_BINARY_AGE=10
SDL_MINOR_VERSION=3
SDL_MICRO_VERSION=0
SDL_INTERFACE_AGE=0
SDL_BINARY_AGE=0
SDL_VERSION=$SDL_MAJOR_VERSION.$SDL_MINOR_VERSION.$SDL_MICRO_VERSION

AC_SUBST(SDL_MAJOR_VERSION)
Expand Down
4 changes: 2 additions & 2 deletions include/SDL_version.h
Expand Up @@ -36,8 +36,8 @@ extern "C" {
/* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL
*/
#define SDL_MAJOR_VERSION 1
#define SDL_MINOR_VERSION 2
#define SDL_PATCHLEVEL 10
#define SDL_MINOR_VERSION 3
#define SDL_PATCHLEVEL 0

typedef struct SDL_version {
Uint8 major;
Expand Down
10 changes: 1 addition & 9 deletions include/SDL_video.h
Expand Up @@ -124,7 +124,7 @@ typedef struct SDL_Surface {
#define SDL_DOUBLEBUF 0x40000000 /* Set up double-buffered video mode */
#define SDL_FULLSCREEN 0x80000000 /* Surface is a full screen display */
#define SDL_OPENGL 0x00000002 /* Create an OpenGL rendering context */
#define SDL_OPENGLBLIT 0x0000000A /* Create an OpenGL rendering context and use it for blitting */
#define SDL_OPENGLBLIT_OBSOLETE 0x0000000A /* Obsolete, do not use! */
#define SDL_RESIZABLE 0x00000010 /* This video mode may be resized */
#define SDL_NOFRAME 0x00000020 /* No window caption or edge frame */
/* Used internally (read-only) */
Expand Down Expand Up @@ -807,14 +807,6 @@ extern DECLSPEC int SDLCALL SDL_GL_GetAttribute(SDL_GLattr attr, int* value);
*/
extern DECLSPEC void SDLCALL SDL_GL_SwapBuffers(void);

/*
* Internal functions that should not be called unless you have read
* and understood the source code for these functions.
*/
extern DECLSPEC void SDLCALL SDL_GL_UpdateRects(int numrects, SDL_Rect* rects);
extern DECLSPEC void SDLCALL SDL_GL_Lock(void);
extern DECLSPEC void SDLCALL SDL_GL_Unlock(void);

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* These functions allow interaction with the window manager, if any. */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Expand Down
3 changes: 0 additions & 3 deletions src/main/macos/exports/SDL.x
Expand Up @@ -178,9 +178,6 @@
SDL_GL_SetAttribute
SDL_GL_GetAttribute
SDL_GL_SwapBuffers
SDL_GL_UpdateRects
SDL_GL_Lock
SDL_GL_Unlock
SDL_WM_SetCaption
SDL_WM_GetCaption
SDL_WM_SetIcon
Expand Down
244 changes: 7 additions & 237 deletions src/video/SDL_video.c
Expand Up @@ -131,12 +131,8 @@ SDL_VideoDevice *current_video = NULL;
/* Various local functions */
int SDL_VideoInit(const char *driver_name, Uint32 flags);
void SDL_VideoQuit(void);
void SDL_GL_UpdateRectsLock(SDL_VideoDevice* this, int numrects, SDL_Rect* rects);

static SDL_GrabMode SDL_WM_GrabInputOff(void);
#if SDL_VIDEO_OPENGL
static int lock_count = 0;
#endif


/*
Expand Down Expand Up @@ -577,6 +573,12 @@ SDL_Surface * SDL_SetVideoMode (int width, int height, int bpp, Uint32 flags)
int is_opengl;
SDL_GrabMode saved_grab;

/* Handle obsolete flags */
if ( (flags & SDL_OPENGLBLIT_OBSOLETE) == SDL_OPENGLBLIT_OBSOLETE ) {
SDL_SetError("SDL_OPENGLBLIT is no longer supported");
return(NULL);
}

/* Start up the video driver, if necessary..
WARNING: This is the only function protected this way!
*/
Expand Down Expand Up @@ -748,7 +750,7 @@ SDL_Surface * SDL_SetVideoMode (int width, int height, int bpp, Uint32 flags)

#if SDL_VIDEO_OPENGL
/* Load GL symbols (before MakeCurrent, where we need glGetString). */
if ( flags & (SDL_OPENGL | SDL_OPENGLBLIT) ) {
if ( flags & SDL_OPENGL ) {

#if defined(__QNXNTO__) && (_NTO_VERSION < 630)
#define __SDL_NOGETPROCADDR__
Expand Down Expand Up @@ -782,89 +784,6 @@ SDL_Surface * SDL_SetVideoMode (int width, int height, int bpp, Uint32 flags)
}
}

/* Set up a fake SDL surface for OpenGL "blitting" */
if ( (flags & SDL_OPENGLBLIT) == SDL_OPENGLBLIT ) {
/* Load GL functions for performing the texture updates */
#if SDL_VIDEO_OPENGL

/* Create a software surface for blitting */
#ifdef GL_VERSION_1_2
/* If the implementation either supports the packed pixels
extension, or implements the core OpenGL 1.2 API, it will
support the GL_UNSIGNED_SHORT_5_6_5 texture format.
*/
if ( (bpp == 16) &&
(SDL_strstr((const char *)video->glGetString(GL_EXTENSIONS), "GL_EXT_packed_pixels") ||
(SDL_atof((const char *)video->glGetString(GL_VERSION)) >= 1.2f))
) {
video->is_32bit = 0;
SDL_VideoSurface = SDL_CreateRGBSurface(
flags,
width,
height,
16,
31 << 11,
63 << 5,
31,
0
);
}
else
#endif /* OpenGL 1.2 */
{
video->is_32bit = 1;
SDL_VideoSurface = SDL_CreateRGBSurface(
flags,
width,
height,
32,
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
0x000000FF,
0x0000FF00,
0x00FF0000,
0xFF000000
#else
0xFF000000,
0x00FF0000,
0x0000FF00,
0x000000FF
#endif
);
}
if ( ! SDL_VideoSurface ) {
return(NULL);
}
SDL_VideoSurface->flags = mode->flags | SDL_OPENGLBLIT;

/* Free the original video mode surface (is this safe?) */
SDL_FreeSurface(mode);

/* Set the surface completely opaque & white by default */
SDL_memset( SDL_VideoSurface->pixels, 255, SDL_VideoSurface->h * SDL_VideoSurface->pitch );
video->glGenTextures( 1, &video->texture );
video->glBindTexture( GL_TEXTURE_2D, video->texture );
video->glTexImage2D(
GL_TEXTURE_2D,
0,
video->is_32bit ? GL_RGBA : GL_RGB,
256,
256,
0,
video->is_32bit ? GL_RGBA : GL_RGB,
#ifdef GL_VERSION_1_2
video->is_32bit ? GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT_5_6_5,
#else
GL_UNSIGNED_BYTE,
#endif
NULL);

video->UpdateRects = SDL_GL_UpdateRectsLock;
#else
SDL_SetError("Somebody forgot to #define SDL_VIDEO_OPENGL");
return(NULL);
#endif
}

/* Create a shadow surface if necessary */
/* There are three conditions under which we create a shadow surface:
1. We need a particular bits-per-pixel that we didn't get.
Expand Down Expand Up @@ -1511,155 +1430,6 @@ void SDL_GL_SwapBuffers(void)
}
}

/* Update rects with locking */
void SDL_GL_UpdateRectsLock(SDL_VideoDevice* this, int numrects, SDL_Rect *rects)
{
SDL_GL_Lock();
SDL_GL_UpdateRects(numrects, rects);
SDL_GL_Unlock();
}

/* Update rects without state setting and changing (the caller is responsible for it) */
void SDL_GL_UpdateRects(int numrects, SDL_Rect *rects)
{
#if SDL_VIDEO_OPENGL
SDL_VideoDevice *this = current_video;
SDL_Rect update, tmp;
int x, y, i;

for ( i = 0; i < numrects; i++ )
{
tmp.y = rects[i].y;
tmp.h = rects[i].h;
for ( y = 0; y <= rects[i].h / 256; y++ )
{
tmp.x = rects[i].x;
tmp.w = rects[i].w;
for ( x = 0; x <= rects[i].w / 256; x++ )
{
update.x = tmp.x;
update.y = tmp.y;
update.w = tmp.w;
update.h = tmp.h;

if ( update.w > 256 )
update.w = 256;

if ( update.h > 256 )
update.h = 256;

this->glFlush();
this->glTexSubImage2D(
GL_TEXTURE_2D,
0,
0,
0,
update.w,
update.h,
this->is_32bit? GL_RGBA : GL_RGB,
#ifdef GL_VERSION_1_2
this->is_32bit ? GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT_5_6_5,
#else
GL_UNSIGNED_BYTE,
#endif
(Uint8 *)this->screen->pixels +
this->screen->format->BytesPerPixel * update.x +
update.y * this->screen->pitch );

this->glFlush();
/*
* Note the parens around the function name:
* This is because some OpenGL implementations define glTexCoord etc
* as macros, and we don't want them expanded here.
*/
this->glBegin(GL_TRIANGLE_STRIP);
(this->glTexCoord2f)( 0.0, 0.0 );
(this->glVertex2i)( update.x, update.y );
(this->glTexCoord2f)( (float)(update.w / 256.0), 0.0 );
(this->glVertex2i)( update.x + update.w, update.y );
(this->glTexCoord2f)( 0.0, (float)(update.h / 256.0) );
(this->glVertex2i)( update.x, update.y + update.h );
(this->glTexCoord2f)( (float)(update.w / 256.0), (float)(update.h / 256.0) );
(this->glVertex2i)( update.x + update.w , update.y + update.h );
this->glEnd();

tmp.x += 256;
tmp.w -= 256;
}
tmp.y += 256;
tmp.h -= 256;
}
}
#endif
}

/* Lock == save current state */
void SDL_GL_Lock()
{
#if SDL_VIDEO_OPENGL
lock_count--;
if (lock_count==-1)
{
SDL_VideoDevice *this = current_video;

this->glPushAttrib( GL_ALL_ATTRIB_BITS ); /* TODO: narrow range of what is saved */
#ifdef GL_CLIENT_PIXEL_STORE_BIT
this->glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT );
#endif

this->glEnable(GL_TEXTURE_2D);
this->glEnable(GL_BLEND);
this->glDisable(GL_FOG);
this->glDisable(GL_ALPHA_TEST);
this->glDisable(GL_DEPTH_TEST);
this->glDisable(GL_SCISSOR_TEST);
this->glDisable(GL_STENCIL_TEST);
this->glDisable(GL_CULL_FACE);

this->glBindTexture( GL_TEXTURE_2D, this->texture );
this->glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );

this->glPixelStorei( GL_UNPACK_ROW_LENGTH, this->screen->pitch / this->screen->format->BytesPerPixel );
this->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
(this->glColor4f)(1.0, 1.0, 1.0, 1.0); /* Solaris workaround */

this->glViewport(0, 0, this->screen->w, this->screen->h);
this->glMatrixMode(GL_PROJECTION);
this->glPushMatrix();
this->glLoadIdentity();

this->glOrtho(0.0, (GLdouble) this->screen->w, (GLdouble) this->screen->h, 0.0, 0.0, 1.0);

this->glMatrixMode(GL_MODELVIEW);
this->glPushMatrix();
this->glLoadIdentity();
}
#endif
}

/* Unlock == restore saved state */
void SDL_GL_Unlock()
{
#if SDL_VIDEO_OPENGL
lock_count++;
if (lock_count==0)
{
SDL_VideoDevice *this = current_video;

this->glPopMatrix();
this->glMatrixMode(GL_PROJECTION);
this->glPopMatrix();

this->glPopClientAttrib();
this->glPopAttrib();
}
#endif
}

/*
* Sets/Gets the title and icon text of the display window, if any.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/video/cybergfx/SDL_cgxvideo.c
Expand Up @@ -598,7 +598,7 @@ void CGX_DestroyWindow(_THIS, SDL_Surface *screen)

/* Clean up OpenGL */
if ( screen ) {
screen->flags &= ~(SDL_OPENGL|SDL_OPENGLBLIT);
screen->flags &= ~SDL_OPENGL;
}

if ( screen && (screen->flags & SDL_FULLSCREEN) ) {
Expand Down
5 changes: 1 addition & 4 deletions src/video/quartz/SDL_QuartzVideo.m
Expand Up @@ -1353,10 +1353,7 @@ static void QZ_DrawResizeIcon (_THIS, RgnHandle dirtyRegion) {

static void QZ_UpdateRects (_THIS, int numRects, SDL_Rect *rects) {

if (SDL_VideoSurface->flags & SDL_OPENGLBLIT) {
QZ_GL_SwapBuffers (this);
}
else if ( [ qz_window isMiniaturized ] ) {
if ( [ qz_window isMiniaturized ] ) {

/* Do nothing if miniaturized */
}
Expand Down
2 changes: 1 addition & 1 deletion src/video/x11/SDL_x11video.c
Expand Up @@ -585,7 +585,7 @@ static void X11_DestroyWindow(_THIS, SDL_Surface *screen)
{
/* Clean up OpenGL */
if ( screen ) {
screen->flags &= ~(SDL_OPENGL|SDL_OPENGLBLIT);
screen->flags &= ~SDL_OPENGL;
}
X11_GL_Shutdown(this);

Expand Down
2 changes: 1 addition & 1 deletion test/configure.in
Expand Up @@ -60,7 +60,7 @@ AC_SUBST(EXE)
AC_SUBST(MATHLIB)

dnl Check for SDL
SDL_VERSION=1.2.10
SDL_VERSION=1.3.0
AM_PATH_SDL($SDL_VERSION,
:,
AC_MSG_ERROR([*** SDL version $SDL_VERSION not found!])
Expand Down

0 comments on commit 190fe3e

Please sign in to comment.