Move TFB_BoundingBox out of SDL domain

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3464 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2009-12-22 18:55:41 +00:00
parent f84ec2d4c1
commit 0ebc5dc6fb
10 changed files with 76 additions and 68 deletions
+8 -8
View File
@@ -302,14 +302,6 @@ SOURCE=..\..\src\libs\graphics\sdl\3do_getbody.c
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=..\..\src\libs\graphics\sdl\bbox.c
# End Source File
# Begin Source File
SOURCE=..\..\src\libs\graphics\sdl\bbox.h
# End Source File
# Begin Source File
SOURCE=..\..\src\libs\graphics\sdl\biadv2x.c SOURCE=..\..\src\libs\graphics\sdl\biadv2x.c
# End Source File # End Source File
# Begin Source File # Begin Source File
@@ -407,6 +399,14 @@ SOURCE=..\..\src\libs\graphics\sdl\triscan2x.c
# End Group # End Group
# Begin Source File # Begin Source File
SOURCE=..\..\src\libs\graphics\bbox.c
# End Source File
# Begin Source File
SOURCE=..\..\src\libs\graphics\bbox.h
# End Source File
# Begin Source File
SOURCE=..\..\src\libs\graphics\boxint.c SOURCE=..\..\src\libs\graphics\boxint.c
# End Source File # End Source File
# Begin Source File # Begin Source File
+1 -1
View File
@@ -1,5 +1,5 @@
uqm_SUBDIRS="sdl" uqm_SUBDIRS="sdl"
uqm_CFILES="boxint.c clipline.c cmap.c context.c drawable.c filegfx.c uqm_CFILES="boxint.c clipline.c cmap.c context.c drawable.c filegfx.c
dcqueue.c bbox.c dcqueue.c
font.c frame.c gfx_common.c intersec.c loaddisp.c font.c frame.c gfx_common.c intersec.c loaddisp.c
pixmap.c resgfx.c tfb_draw.c tfb_prim.c widgets.c" pixmap.c resgfx.c tfb_draw.c tfb_prim.c widgets.c"
@@ -15,30 +15,53 @@
*/ */
#include "port.h" #include "port.h"
#include SDL_INCLUDE(SDL.h) #include "libs/graphics/bbox.h"
#include "bbox.h"
TFB_BoundingBox TFB_BBox; TFB_BoundingBox TFB_BBox;
int maxWidth;
int maxHeight;
void
TFB_BBox_Init (int width, int height)
{
maxWidth = width;
maxHeight = height;
TFB_BBox.clip.extent.width = width;
TFB_BBox.clip.extent.height = height;
}
void void
TFB_BBox_Reset (void) TFB_BBox_Reset (void)
{ {
TFB_BBox.valid = 0; TFB_BBox.valid = 0;
TFB_BBox.clip.corner.x = 0;
TFB_BBox.clip.corner.y = 0;
TFB_BBox.clip.extent.width = ScreenWidth;
TFB_BBox.clip.extent.height = ScreenHeight;
} }
void void
TFB_BBox_GetClipRect (TFB_Canvas c) TFB_BBox_SetClipRect (const RECT *r)
{ {
SDL_Rect r; if (!r)
SDL_GetClipRect ((SDL_Surface *)c, &r); { /* No clipping -- full rect */
TFB_BBox.clip.corner.x = r.x; TFB_BBox.clip.corner.x = 0;
TFB_BBox.clip.corner.y = r.y; TFB_BBox.clip.corner.y = 0;
TFB_BBox.clip.extent.width = r.w; TFB_BBox.clip.extent.width = maxWidth;
TFB_BBox.clip.extent.height = r.h; TFB_BBox.clip.extent.height = maxHeight;
return;
}
TFB_BBox.clip = *r;
/* Make sure the cliprect is sane */
if (TFB_BBox.clip.corner.x < 0)
TFB_BBox.clip.corner.x = 0;
if (TFB_BBox.clip.corner.y < 0)
TFB_BBox.clip.corner.y = 0;
if (TFB_BBox.clip.corner.x + TFB_BBox.clip.extent.width > maxWidth)
TFB_BBox.clip.extent.width = maxWidth - TFB_BBox.clip.corner.x;
if (TFB_BBox.clip.corner.y + TFB_BBox.clip.extent.height > maxHeight)
TFB_BBox.clip.extent.height = maxHeight - TFB_BBox.clip.corner.y;
} }
void void
@@ -49,22 +72,6 @@ TFB_BBox_RegisterPoint (int x, int y)
int x2 = TFB_BBox.clip.corner.x + TFB_BBox.clip.extent.width - 1; int x2 = TFB_BBox.clip.corner.x + TFB_BBox.clip.extent.width - 1;
int y2 = TFB_BBox.clip.corner.y + TFB_BBox.clip.extent.height - 1; int y2 = TFB_BBox.clip.corner.y + TFB_BBox.clip.extent.height - 1;
/* Make sure the cliprect is sane */
if (x1 < 0) x1 = TFB_BBox.clip.corner.x = 0;
if (y1 < 0) y1 = TFB_BBox.clip.corner.y = 0;
if (x2 >= ScreenWidth)
{
TFB_BBox.clip.extent.width = ScreenWidth - x1;
x2 = ScreenWidth - 1;
}
if (y2 >= ScreenHeight)
{
TFB_BBox.clip.extent.height = ScreenHeight - y1;
y2 = ScreenHeight - 1;
}
/* Constrain coordinates */ /* Constrain coordinates */
if (x < x1) x = x1; if (x < x1) x = x1;
if (x >= x2) x = x2; if (x >= x2) x = x2;
@@ -105,16 +112,22 @@ TFB_BBox_RegisterPoint (int x, int y)
} }
void void
TFB_BBox_RegisterRect (RECT *r) TFB_BBox_RegisterRect (const RECT *r)
{ {
/* RECT will still register as a corner point of the cliprect even
* if it does not intersect with the cliprect at all. This is not
* a problem, as more is not less. */
TFB_BBox_RegisterPoint (r->corner.x, r->corner.y); TFB_BBox_RegisterPoint (r->corner.x, r->corner.y);
TFB_BBox_RegisterPoint (r->corner.x + r->extent.width, r->corner.y + r->extent.height); TFB_BBox_RegisterPoint (r->corner.x + r->extent.width - 1,
r->corner.y + r->extent.height - 1);
} }
void void
TFB_BBox_RegisterCanvas (TFB_Canvas c, int x, int y) TFB_BBox_RegisterCanvas (TFB_Canvas c, int x, int y)
{ {
SDL_Surface *s = (SDL_Surface *)c; RECT r;
TFB_BBox_RegisterPoint (x, y); r.corner.x = x;
TFB_BBox_RegisterPoint (x + s->w, y + s->h); r.corner.y = y;
TFB_DrawCanvas_GetExtent (c, &r.extent);
TFB_BBox_RegisterRect (&r);
} }
@@ -14,12 +14,11 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#ifndef BBOX_H_INCL__
#define BBOX_H_INCL__
#include "libs/gfxlib.h" #include "libs/gfxlib.h"
#include "libs/graphics/tfb_draw.h" #include "libs/graphics/tfb_draw.h"
#include "libs/graphics/gfx_common.h"
#ifndef _BBOX_H_
#define _BBOX_H_
/* Bounding Box operations. These operations are NOT synchronized. /* Bounding Box operations. These operations are NOT synchronized.
* However, they should only be accessed by TFB_FlushGraphics and * However, they should only be accessed by TFB_FlushGraphics and
@@ -37,10 +36,11 @@ typedef struct {
extern TFB_BoundingBox TFB_BBox; extern TFB_BoundingBox TFB_BBox;
void TFB_BBox_RegisterPoint (int x, int y); void TFB_BBox_RegisterPoint (int x, int y);
void TFB_BBox_RegisterRect (RECT *r); void TFB_BBox_RegisterRect (const RECT *r);
void TFB_BBox_RegisterCanvas (TFB_Canvas c, int x, int y); void TFB_BBox_RegisterCanvas (TFB_Canvas c, int x, int y);
void TFB_BBox_Init (int width, int height);
void TFB_BBox_Reset (void); void TFB_BBox_Reset (void);
void TFB_BBox_GetClipRect (TFB_Canvas c); void TFB_BBox_SetClipRect (const RECT *r);
#endif #endif /* BBOX_H_INCL__ */
+1 -4
View File
@@ -231,10 +231,7 @@ TFB_EnqueueDrawCommand (TFB_DrawCommand* DrawCommand)
if (scissor_rect.extent.width) if (scissor_rect.extent.width)
{ {
DC.Type = TFB_DRAWCOMMANDTYPE_SCISSORENABLE; DC.Type = TFB_DRAWCOMMANDTYPE_SCISSORENABLE;
DC.data.scissor.x = scissor_rect.corner.x; DC.data.scissor.rect = scissor_rect;
DC.data.scissor.y = scissor_rect.corner.y;
DC.data.scissor.w = scissor_rect.extent.width;
DC.data.scissor.h = scissor_rect.extent.height;
} }
else else
{ {
+1 -1
View File
@@ -100,7 +100,7 @@ typedef struct tfb_dc_copyimg
typedef struct tfb_dc_scissor typedef struct tfb_dc_scissor
{ {
int x, y, w, h; RECT rect;
} TFB_DrawCommand_Scissor; } TFB_DrawCommand_Scissor;
typedef struct tfb_dc_setmip typedef struct tfb_dc_setmip
+1 -1
View File
@@ -4,4 +4,4 @@ uqm_CFILES="3do_blt.c 3do_funcs.c 3do_getbody.c opengl.c
scalers.c 2xscalers.c scalers.c 2xscalers.c
2xscalers_mmx.c 2xscalers_sse.c 2xscalers_3dnow.c 2xscalers_mmx.c 2xscalers_sse.c 2xscalers_3dnow.c
nearest2x.c bilinear2x.c biadv2x.c triscan2x.c hq2x.c nearest2x.c bilinear2x.c biadv2x.c triscan2x.c hq2x.c
canvas.c bbox.c sdluio.c rotozoom.c" canvas.c sdluio.c rotozoom.c"
+1 -1
View File
@@ -19,7 +19,7 @@
#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 "libs/graphics/bbox.h"
#include "scalers.h" #include "scalers.h"
#include "options.h" #include "options.h"
#include "libs/log.h" #include "libs/log.h"
+1 -1
View File
@@ -18,7 +18,7 @@
#ifdef GFXMODULE_SDL #ifdef GFXMODULE_SDL
#include "pure.h" #include "pure.h"
#include "bbox.h" #include "libs/graphics/bbox.h"
#include "scalers.h" #include "scalers.h"
#include "libs/log.h" #include "libs/log.h"
+8 -10
View File
@@ -29,7 +29,7 @@
#include "libs/graphics/cmap.h" #include "libs/graphics/cmap.h"
#include "libs/input/sdl/input.h" #include "libs/input/sdl/input.h"
// for ProcessInputEvent() // for ProcessInputEvent()
#include "bbox.h" #include "libs/graphics/bbox.h"
#include "port.h" #include "port.h"
#include "libs/uio.h" #include "libs/uio.h"
#include "libs/log.h" #include "libs/log.h"
@@ -174,6 +174,7 @@ TFB_InitGraphics (int driver, int flags, int width, int height)
Init_DrawCommandQueue (); Init_DrawCommandQueue ();
TFB_DrawCanvas_Initialize (); TFB_DrawCanvas_Initialize ();
TFB_BBox_Init (ScreenWidth, ScreenHeight);
RenderingCond = CreateCondVar ("DCQ empty", RenderingCond = CreateCondVar ("DCQ empty",
SYNC_CLASS_TOPLEVEL | SYNC_CLASS_VIDEO); SYNC_CLASS_TOPLEVEL | SYNC_CLASS_VIDEO);
@@ -660,7 +661,6 @@ TFB_FlushGraphics (void) // Only call from main thread!!
} }
TFB_BBox_Reset (); TFB_BBox_Reset ();
TFB_BBox_GetClipRect (SDL_Screens[0]);
done = FALSE; done = FALSE;
while (!done) while (!done)
@@ -794,19 +794,17 @@ TFB_FlushGraphics (void) // Only call from main thread!!
case TFB_DRAWCOMMANDTYPE_SCISSORENABLE: case TFB_DRAWCOMMANDTYPE_SCISSORENABLE:
{ {
SDL_Rect r; SDL_Rect r;
r.x = TFB_BBox.clip.corner.x = DC.data.scissor.x; r.x = DC.data.scissor.rect.corner.x;
r.y = TFB_BBox.clip.corner.y = DC.data.scissor.y; r.y = DC.data.scissor.rect.corner.y;
r.w = TFB_BBox.clip.extent.width = DC.data.scissor.w; r.w = DC.data.scissor.rect.extent.width;
r.h = TFB_BBox.clip.extent.height = DC.data.scissor.h; r.h = DC.data.scissor.rect.extent.height;
SDL_SetClipRect (SDL_Screens[0], &r); SDL_SetClipRect (SDL_Screens[0], &r);
TFB_BBox_SetClipRect (&DC.data.scissor.rect);
break; break;
} }
case TFB_DRAWCOMMANDTYPE_SCISSORDISABLE: case TFB_DRAWCOMMANDTYPE_SCISSORDISABLE:
SDL_SetClipRect (SDL_Screens[0], NULL); SDL_SetClipRect (SDL_Screens[0], NULL);
TFB_BBox.clip.corner.x = 0; TFB_BBox_SetClipRect (NULL);
TFB_BBox.clip.corner.y = 0;
TFB_BBox.clip.extent.width = ScreenWidth;
TFB_BBox.clip.extent.height = ScreenHeight;
break; break;
case TFB_DRAWCOMMANDTYPE_COPYTOIMAGE: case TFB_DRAWCOMMANDTYPE_COPYTOIMAGE:
{ {