Biadapt and biadv scaling now works in OpenGL mode too; separated scaling

code from pure.c to 2xscalers.c


git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@674 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
gewlitys
2003-02-05 01:18:34 +00:00
parent ffcf8c68dc
commit 54e97e3bca
7 changed files with 2749 additions and 2633 deletions
+1
View File
@@ -1,4 +1,5 @@
Changes towards version 0.2: Changes towards version 0.2:
- Biadapt and biadv scalers now work in OpenGL mode too -Mika
- Fixed lockup when fastforwarding through orz comm -PBlue - Fixed lockup when fastforwarding through orz comm -PBlue
- A new windows installer is now in builds/win32_install -PBlue - A new windows installer is now in builds/win32_install -PBlue
- Added '-a' switch to go between OpenAL and MixSDL at runtime -PBlue - Added '-a' switch to go between OpenAL and MixSDL at runtime -PBlue
+8
View File
@@ -152,6 +152,14 @@ SOURCE=..\sc2code\libs\file\temp.c
# PROP Default_Filter "" # PROP Default_Filter ""
# Begin Source File # Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\2xscalers.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\2xscalers.h
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\3do_blt.c SOURCE=..\sc2code\libs\graphics\sdl\3do_blt.c
# End Source File # End Source File
# Begin Source File # Begin Source File
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,27 @@
//Copyright Paul Reiche, Fred Ford. 1992-2002
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _2XSCALERS_H_
#define _2XSCALERS_H_
void Scale_PrepYUV (void);
void Scale_Nearest (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r);
void Scale_BilinearFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r);
void Scale_BiAdaptFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r);
void Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r);
#endif
+1 -1
View File
@@ -1,3 +1,3 @@
uqm_CFILES="3do_blt.c 3do_funcs.c 3do_getbody.c dcqueue.c opengl.c uqm_CFILES="3do_blt.c 3do_funcs.c 3do_getbody.c dcqueue.c opengl.c
primitives.c pure.c rndzoom.c rotozoom.c sdl_common.c oscilloscope.c primitives.c pure.c rndzoom.c rotozoom.c sdl_common.c oscilloscope.c
canvas.c bbox.c" canvas.c bbox.c 2xscalers.c"
+85 -25
View File
@@ -19,8 +19,12 @@
#if defined (GFXMODULE_SDL) && defined (HAVE_OPENGL) #if defined (GFXMODULE_SDL) && defined (HAVE_OPENGL)
#include "libs/graphics/sdl/opengl.h" #include "libs/graphics/sdl/opengl.h"
#include "bbox.h"
#include "2xscalers.h"
static SDL_Surface *format_conv_surf; static SDL_Surface *format_conv_surf;
static SDL_Surface *scaled_display;
static SDL_Surface *scaled_transition;
static int ScreenFilterMode; static int ScreenFilterMode;
static unsigned int DisplayTexture; static unsigned int DisplayTexture;
@@ -40,18 +44,17 @@ static BOOLEAN upload_transitiontexture = FALSE;
#define A_MASK 0xff000000 #define A_MASK 0xff000000
#endif #endif
static SDL_Surface * static SDL_Surface *
Create_Screen () Create_Screen ()
{ {
SDL_Surface *result = SDL_CreateRGBSurface(SDL_SWSURFACE, ScreenWidth, ScreenHeight, 32, SDL_Surface *result = SDL_CreateRGBSurface(SDL_SWSURFACE, ScreenWidth, ScreenHeight, 32,
R_MASK, G_MASK, B_MASK, 0x00000000); R_MASK, G_MASK, B_MASK, 0x00000000);
if (result == NULL) if (result == NULL)
{ {
fprintf (stderr, "Couldn't create screen buffer: %s\n", SDL_GetError()); fprintf (stderr, "Couldn't create screen buffer: %s\n", SDL_GetError());
exit (-1); exit (-1);
} }
return result; return result;
} }
@@ -59,13 +62,11 @@ int
TFB_GL_InitGraphics (int driver, int flags, int width, int height, int bpp) TFB_GL_InitGraphics (int driver, int flags, int width, int height, int bpp)
{ {
char VideoName[256]; char VideoName[256];
int videomode_flags; int i, videomode_flags, texture_width, texture_height;
int i;
GraphicsDriver = driver; GraphicsDriver = driver;
fprintf (stderr, "Initializing SDL (OpenGL).\n"); fprintf (stderr, "Initializing SDL (OpenGL).\n");
if ((SDL_Init (SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) == -1)) if ((SDL_Init (SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) == -1))
{ {
fprintf (stderr, "Could not initialize SDL: %s.\n", SDL_GetError()); fprintf (stderr, "Could not initialize SDL: %s.\n", SDL_GetError());
@@ -74,7 +75,6 @@ TFB_GL_InitGraphics (int driver, int flags, int width, int height, int bpp)
SDL_VideoDriverName (VideoName, sizeof (VideoName)); SDL_VideoDriverName (VideoName, sizeof (VideoName));
fprintf (stderr, "SDL driver used: %s\n", VideoName); fprintf (stderr, "SDL driver used: %s\n", VideoName);
fprintf (stderr, "SDL initialized.\n"); fprintf (stderr, "SDL initialized.\n");
fprintf (stderr, "Initializing Screen.\n"); fprintf (stderr, "Initializing Screen.\n");
@@ -84,10 +84,6 @@ TFB_GL_InitGraphics (int driver, int flags, int width, int height, int bpp)
ScreenHeightActual = height; ScreenHeightActual = height;
switch (bpp) { switch (bpp) {
case 8:
fprintf (stderr, "bpp of 8 not supported under OpenGL\n");
exit(-1);
case 15: case 15:
SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 5); SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 5); SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 5);
@@ -111,6 +107,8 @@ TFB_GL_InitGraphics (int driver, int flags, int width, int height, int bpp)
SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 8);
break; break;
default:
break;
} }
SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, bpp); SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, bpp);
@@ -122,7 +120,6 @@ TFB_GL_InitGraphics (int driver, int flags, int width, int height, int bpp)
SDL_Video = SDL_SetVideoMode (ScreenWidthActual, ScreenHeightActual, SDL_Video = SDL_SetVideoMode (ScreenWidthActual, ScreenHeightActual,
bpp, videomode_flags); bpp, videomode_flags);
if (SDL_Video == NULL) if (SDL_Video == NULL)
{ {
fprintf (stderr, "Couldn't set OpenGL %ix%ix%i video mode: %s\n", fprintf (stderr, "Couldn't set OpenGL %ix%ix%i video mode: %s\n",
@@ -150,14 +147,44 @@ TFB_GL_InitGraphics (int driver, int flags, int width, int height, int bpp)
format_conv_surf = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0, 32, format_conv_surf = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0, 32,
R_MASK, G_MASK, B_MASK, A_MASK); R_MASK, G_MASK, B_MASK, A_MASK);
if (format_conv_surf == NULL) if (format_conv_surf == NULL)
{ {
fprintf (stderr, "Couldn't create format_conv_surf: %s\n", SDL_GetError()); fprintf (stderr, "Couldn't create format_conv_surf: %s\n", SDL_GetError());
exit(-1); exit(-1);
} }
if (GfxFlags & TFB_GFXFLAGS_SCALE_BILINEAR || GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPT || if (GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPT ||
GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPTADV)
{
scaled_display = SDL_CreateRGBSurface(SDL_SWSURFACE, ScreenWidth * 2,
ScreenHeight * 2, 32, R_MASK, G_MASK, B_MASK, 0x00000000);
if (scaled_display == NULL)
{
fprintf (stderr, "Couldn't create scaled_display: %s\n", SDL_GetError());
exit(-1);
}
scaled_transition = SDL_CreateRGBSurface(SDL_SWSURFACE, ScreenWidth * 2,
ScreenHeight * 2, 32, R_MASK, G_MASK, B_MASK, 0x00000000);
if (scaled_transition == NULL)
{
fprintf (stderr, "Couldn't create scaled_transition: %s\n", SDL_GetError());
exit(-1);
}
texture_width = 1024;
texture_height = 512;
}
else
{
texture_width = 512;
texture_height = 256;
}
// pre-compute the RGB->YUV transformations
Scale_PrepYUV();
if (GfxFlags & TFB_GFXFLAGS_SCALE_BILINEAR ||
GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPT ||
GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPTADV) GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPTADV)
ScreenFilterMode = GL_LINEAR; ScreenFilterMode = GL_LINEAR;
else else
@@ -181,14 +208,14 @@ TFB_GL_InitGraphics (int driver, int flags, int width, int height, int bpp)
glPixelStorei (GL_UNPACK_ALIGNMENT, 1); glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, 512, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, texture_width, texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
glGenTextures (1, &TransitionTexture); glGenTextures (1, &TransitionTexture);
glBindTexture (GL_TEXTURE_2D, TransitionTexture); glBindTexture (GL_TEXTURE_2D, TransitionTexture);
glPixelStorei (GL_UNPACK_ALIGNMENT, 1); glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, 512, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, texture_width, texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
return 0; return 0;
} }
@@ -207,7 +234,6 @@ TFB_GL_ScanLines (void)
glEnable (GL_BLEND); glEnable (GL_BLEND);
glBlendFunc (GL_DST_COLOR, GL_ZERO); glBlendFunc (GL_DST_COLOR, GL_ZERO);
glColor3f (0.85f, 0.85f, 0.85f); glColor3f (0.85f, 0.85f, 0.85f);
for (y = 0; y < ScreenHeightActual; y += 2) for (y = 0; y < ScreenHeightActual; y += 2)
{ {
glBegin (GL_LINES); glBegin (GL_LINES);
@@ -218,7 +244,6 @@ TFB_GL_ScanLines (void)
glBlendFunc (GL_DST_COLOR, GL_ONE); glBlendFunc (GL_DST_COLOR, GL_ONE);
glColor3f (0.2f, 0.2f, 0.2f); glColor3f (0.2f, 0.2f, 0.2f);
for (y = 1; y < ScreenHeightActual; y += 2) for (y = 1; y < ScreenHeightActual; y += 2)
{ {
glBegin (GL_LINES); glBegin (GL_LINES);
@@ -232,19 +257,14 @@ void
TFB_GL_DrawQuad (void) TFB_GL_DrawQuad (void)
{ {
glBegin (GL_TRIANGLE_FAN); glBegin (GL_TRIANGLE_FAN);
glTexCoord2f (0, 0); glTexCoord2f (0, 0);
glVertex2i (0, 0); glVertex2i (0, 0);
glTexCoord2f (ScreenWidth / 512.0f, 0); glTexCoord2f (ScreenWidth / 512.0f, 0);
glVertex2i (ScreenWidthActual, 0); glVertex2i (ScreenWidthActual, 0);
glTexCoord2f (ScreenWidth / 512.0f, ScreenHeight / 256.0f); glTexCoord2f (ScreenWidth / 512.0f, ScreenHeight / 256.0f);
glVertex2i (ScreenWidthActual, ScreenHeightActual); glVertex2i (ScreenWidthActual, ScreenHeightActual);
glTexCoord2f (0, ScreenHeight / 256.0f); glTexCoord2f (0, ScreenHeight / 256.0f);
glVertex2i (0, ScreenHeightActual); glVertex2i (0, ScreenHeightActual);
glEnd (); glEnd ();
} }
@@ -257,7 +277,6 @@ TFB_GL_SwapBuffers (void)
glMatrixMode (GL_PROJECTION); glMatrixMode (GL_PROJECTION);
glLoadIdentity (); glLoadIdentity ();
glOrtho (0,ScreenWidthActual,ScreenHeightActual, 0, -1, 1); glOrtho (0,ScreenWidthActual,ScreenHeightActual, 0, -1, 1);
glMatrixMode (GL_MODELVIEW); glMatrixMode (GL_MODELVIEW);
glLoadIdentity (); glLoadIdentity ();
@@ -265,15 +284,36 @@ TFB_GL_SwapBuffers (void)
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, ScreenFilterMode); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, ScreenFilterMode);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, ScreenFilterMode); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, ScreenFilterMode);
glEnable (GL_TEXTURE_2D); glEnable (GL_TEXTURE_2D);
glDisable (GL_BLEND); glDisable (GL_BLEND);
glColor4f (1, 1, 1, 1); glColor4f (1, 1, 1, 1);
if (GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPT ||
GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPTADV)
{
SDL_Rect updated;
updated.x = TFB_BBox.region.corner.x;
updated.y = TFB_BBox.region.corner.y;
updated.w = TFB_BBox.region.extent.width;
updated.h = TFB_BBox.region.extent.height;
if (GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPT)
Scale_BiAdaptFilter (SDL_Screen, scaled_display, &updated);
else if (GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPTADV)
Scale_BiAdaptAdvFilter (SDL_Screen, scaled_display, &updated);
SDL_LockSurface (scaled_display);
glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, ScreenWidth * 2, ScreenHeight * 2,
GL_RGBA, GL_UNSIGNED_BYTE, scaled_display->pixels);
SDL_UnlockSurface (scaled_display);
}
else
{
SDL_LockSurface (SDL_Screen); SDL_LockSurface (SDL_Screen);
glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, ScreenWidth, ScreenHeight, glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, ScreenWidth, ScreenHeight,
GL_RGBA, GL_UNSIGNED_BYTE, SDL_Screen->pixels); GL_RGBA, GL_UNSIGNED_BYTE, SDL_Screen->pixels);
SDL_UnlockSurface (SDL_Screen); SDL_UnlockSurface (SDL_Screen);
}
TFB_GL_DrawQuad (); TFB_GL_DrawQuad ();
@@ -286,11 +326,31 @@ TFB_GL_SwapBuffers (void)
glBindTexture(GL_TEXTURE_2D, TransitionTexture); glBindTexture(GL_TEXTURE_2D, TransitionTexture);
if (upload_transitiontexture) if (upload_transitiontexture)
{
if (GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPT ||
GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPTADV)
{
SDL_Rect updated;
updated.x = updated.y = 0;
updated.w = ScreenWidth;
updated.h = ScreenHeight;
if (GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPT)
Scale_BiAdaptFilter (TransitionScreen, scaled_transition, &updated);
else if (GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPTADV)
Scale_BiAdaptAdvFilter (TransitionScreen, scaled_transition, &updated);
SDL_LockSurface (scaled_transition);
glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, ScreenWidth * 2, ScreenHeight * 2,
GL_RGBA, GL_UNSIGNED_BYTE, scaled_transition->pixels);
SDL_UnlockSurface (scaled_transition);
}
else
{ {
SDL_LockSurface (TransitionScreen); SDL_LockSurface (TransitionScreen);
glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, ScreenWidth, ScreenHeight, glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, ScreenWidth, ScreenHeight,
GL_RGBA, GL_UNSIGNED_BYTE, TransitionScreen->pixels); GL_RGBA, GL_UNSIGNED_BYTE, TransitionScreen->pixels);
SDL_UnlockSurface (TransitionScreen); SDL_UnlockSurface (TransitionScreen);
}
upload_transitiontexture = FALSE; upload_transitiontexture = FALSE;
} }
@@ -337,7 +397,7 @@ TFB_GL_SwapBuffers (void)
TFB_GL_DrawQuad (); TFB_GL_DrawQuad ();
} }
if (scanlines) if (GfxFlags & TFB_GFXFLAGS_SCANLINES)
TFB_GL_ScanLines (); TFB_GL_ScanLines ();
SDL_GL_SwapBuffers (); SDL_GL_SwapBuffers ();
File diff suppressed because it is too large Load Diff