Replace a ton of custom texture clipping code with a single call to OpenGL scissor test.
git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@3380 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
720fc7fcec
commit
441f4038e4
|
@ -21,7 +21,6 @@
|
|||
#include "ivi.h"
|
||||
|
||||
static UDWORD videoBufferDepth = 32, videoBufferWidth = 640, videoBufferHeight = 480;
|
||||
extern iSurface *psRendSurface;
|
||||
|
||||
BOOL pie_SetVideoBufferDepth(UDWORD depth)
|
||||
{
|
||||
|
@ -55,323 +54,3 @@ UDWORD pie_GetVideoBufferHeight(void)
|
|||
{
|
||||
return(videoBufferHeight);
|
||||
}
|
||||
|
||||
void pie_Set2DClip(int x0, int y0, int x1, int y1)
|
||||
{
|
||||
psRendSurface->clip.left = x0;
|
||||
psRendSurface->clip.top = y0;
|
||||
psRendSurface->clip.right = x1;
|
||||
psRendSurface->clip.bottom = y1;
|
||||
}
|
||||
|
||||
static void pie_ClipUV(CLIP_VERTEX *s1, CLIP_VERTEX *s2, CLIP_VERTEX *clip, Sint32 t)
|
||||
{
|
||||
clip->u = s1->u + ((t * (s2->u - s1->u)) >> iV_DIVSHIFT);
|
||||
clip->v = s1->v + ((t * (s2->v - s1->v)) >> iV_DIVSHIFT);
|
||||
clip->pos.z = s1->pos.z + ((t * (s2->pos.z - s1->pos.z)) >> iV_DIVSHIFT);
|
||||
|
||||
clip->light.byte.r = s1->light.byte.r + ((t * (s2->light.byte.r - s1->light.byte.r)) >> iV_DIVSHIFT);
|
||||
clip->light.byte.g = s1->light.byte.g + ((t * (s2->light.byte.g - s1->light.byte.g)) >> iV_DIVSHIFT);
|
||||
clip->light.byte.b = s1->light.byte.b + ((t * (s2->light.byte.b - s1->light.byte.b)) >> iV_DIVSHIFT);
|
||||
clip->light.byte.a = s1->light.byte.a + ((t * (s2->light.byte.a - s1->light.byte.a)) >> iV_DIVSHIFT);
|
||||
}
|
||||
|
||||
static int pie_ClipXT(CLIP_VERTEX *s1, CLIP_VERTEX *s2, CLIP_VERTEX *clip)
|
||||
{
|
||||
int n = 1, dx;
|
||||
Sint32 t;
|
||||
|
||||
if (s2->pos.x >= s1->pos.x)
|
||||
{
|
||||
if (s1->pos.x < psRendSurface->clip.left)
|
||||
{
|
||||
if (s2->pos.x <= psRendSurface->clip.left)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
dx = s2->pos.x - s1->pos.x;
|
||||
|
||||
if (dx != 0)
|
||||
{
|
||||
clip->pos.y = s1->pos.y + (s2->pos.y - s1->pos.y) * (psRendSurface->clip.left - s1->pos.x) / dx;
|
||||
}
|
||||
else
|
||||
{
|
||||
clip->pos.y = s1->pos.y;
|
||||
}
|
||||
|
||||
clip->pos.x = psRendSurface->clip.left;
|
||||
|
||||
// clip uv
|
||||
t = ((clip->pos.x - s1->pos.x) << iV_DIVSHIFT) / dx;
|
||||
pie_ClipUV(s1, s2, clip, t);
|
||||
}
|
||||
else
|
||||
{
|
||||
*clip = *s1;
|
||||
}
|
||||
|
||||
if (s2->pos.x > psRendSurface->clip.right)
|
||||
{
|
||||
if (s1->pos.x > psRendSurface->clip.right)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
clip++;
|
||||
dx = s2->pos.x - s1->pos.x;
|
||||
|
||||
if (dx != 0)
|
||||
{
|
||||
clip->pos.y = s2->pos.y - (s2->pos.y - s1->pos.y) * (s2->pos.x - psRendSurface->clip.right) / dx;
|
||||
}
|
||||
else
|
||||
{
|
||||
clip->pos.y = s2->pos.y;
|
||||
}
|
||||
|
||||
clip->pos.x = psRendSurface->clip.right;
|
||||
|
||||
// clip uv
|
||||
t = ((clip->pos.x - s1->pos.x) << iV_DIVSHIFT) / dx;
|
||||
pie_ClipUV(s1, s2, clip, t);
|
||||
|
||||
n = 2;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s1->pos.x > psRendSurface->clip.right)
|
||||
{
|
||||
if (s2->pos.x >= psRendSurface->clip.right)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
dx = s1->pos.x - s2->pos.x;
|
||||
|
||||
if (dx != 0)
|
||||
{
|
||||
clip->pos.y = s1->pos.y - (s1->pos.y - s2->pos.y) * (s1->pos.x - psRendSurface->clip.right) / dx;
|
||||
}
|
||||
else
|
||||
{
|
||||
clip->pos.y = s1->pos.y;
|
||||
}
|
||||
|
||||
clip->pos.x = psRendSurface->clip.right;
|
||||
|
||||
// clip uv
|
||||
t = ((clip->pos.x - s1->pos.x) << iV_DIVSHIFT) / dx;
|
||||
pie_ClipUV(s1, s2, clip, t);
|
||||
}
|
||||
else
|
||||
{
|
||||
*clip = *s1;
|
||||
}
|
||||
|
||||
if (s2->pos.x < psRendSurface->clip.left)
|
||||
{
|
||||
if (s1->pos.x < psRendSurface->clip.left)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
clip++;
|
||||
dx = s1->pos.x - s2->pos.x;
|
||||
|
||||
if (dx != 0)
|
||||
{
|
||||
clip->pos.y = s2->pos.y + (s1->pos.y - s2->pos.y) * (psRendSurface->clip.left - s2->pos.x) / dx;
|
||||
}
|
||||
else
|
||||
{
|
||||
clip->pos.y = s2->pos.y;
|
||||
}
|
||||
|
||||
clip->pos.x = psRendSurface->clip.left;
|
||||
|
||||
// clip uv
|
||||
t = ((clip->pos.x - s1->pos.x)<<iV_DIVSHIFT) / dx;
|
||||
pie_ClipUV(s1, s2, clip, t);
|
||||
|
||||
n = 2;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
||||
static int pie_ClipYT(CLIP_VERTEX *s1, CLIP_VERTEX *s2, CLIP_VERTEX *clip)
|
||||
{
|
||||
int n = 1, dy;
|
||||
Sint32 t;
|
||||
|
||||
if (s2->pos.y >= s1->pos.y)
|
||||
{
|
||||
if (s1->pos.y < psRendSurface->clip.top)
|
||||
{
|
||||
if (s2->pos.y <= psRendSurface->clip.top)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
dy = s2->pos.y - s1->pos.y;
|
||||
|
||||
if (dy != 0)
|
||||
{
|
||||
clip->pos.x = s1->pos.x + (s2->pos.x - s1->pos.x) * (psRendSurface->clip.top - s1->pos.y) / dy;
|
||||
}
|
||||
else
|
||||
{
|
||||
clip->pos.x = s1->pos.x;
|
||||
}
|
||||
|
||||
clip->pos.y = psRendSurface->clip.top;
|
||||
|
||||
// clip uv
|
||||
t = ((clip->pos.y - s1->pos.y) << iV_DIVSHIFT) / dy;
|
||||
pie_ClipUV(s1, s2, clip, t);
|
||||
}
|
||||
else
|
||||
{
|
||||
*clip = *s1;
|
||||
}
|
||||
|
||||
if (s2->pos.y > psRendSurface->clip.bottom)
|
||||
{
|
||||
if (s1->pos.y > psRendSurface->clip.bottom)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
clip++;
|
||||
|
||||
dy = s2->pos.y - s1->pos.y;
|
||||
|
||||
if (dy != 0)
|
||||
{
|
||||
clip->pos.x = s2->pos.x - (s2->pos.x - s1->pos.x) * (s2->pos.y - psRendSurface->clip.bottom) / dy;
|
||||
}
|
||||
else
|
||||
{
|
||||
clip->pos.x = s2->pos.x;
|
||||
}
|
||||
|
||||
clip->pos.y = psRendSurface->clip.bottom;
|
||||
|
||||
t = ((clip->pos.y - s1->pos.y) << iV_DIVSHIFT) / dy;
|
||||
pie_ClipUV(s1, s2, clip, t);
|
||||
|
||||
n = 2;
|
||||
}
|
||||
|
||||
return n;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s1->pos.y > psRendSurface->clip.bottom)
|
||||
{
|
||||
if (s2->pos.y >= psRendSurface->clip.bottom)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
dy = s1->pos.y - s2->pos.y;
|
||||
|
||||
if (dy != 0)
|
||||
{
|
||||
clip->pos.x = s1->pos.x - (s1->pos.x - s2->pos.x) * (s1->pos.y - psRendSurface->clip.bottom) / dy;
|
||||
}
|
||||
else
|
||||
{
|
||||
clip->pos.x = s1->pos.x;
|
||||
}
|
||||
|
||||
clip->pos.y = psRendSurface->clip.bottom;
|
||||
|
||||
// clip uv
|
||||
t = ((clip->pos.y - s1->pos.y) << iV_DIVSHIFT) / dy;
|
||||
pie_ClipUV(s1, s2, clip, t);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
*clip = *s1;
|
||||
}
|
||||
|
||||
if (s2->pos.y < psRendSurface->clip.top)
|
||||
{
|
||||
if (s1->pos.y < psRendSurface->clip.top)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
clip++;
|
||||
|
||||
dy = s1->pos.y - s2->pos.y;
|
||||
|
||||
if (dy != 0)
|
||||
{
|
||||
clip->pos.x = s2->pos.x + (s1->pos.x - s2->pos.x) * (psRendSurface->clip.top - s2->pos.y) / dy;
|
||||
}
|
||||
else
|
||||
{
|
||||
clip->pos.x = s2->pos.x;
|
||||
}
|
||||
|
||||
clip->pos.y = psRendSurface->clip.top;
|
||||
|
||||
t = ((clip->pos.y - s1->pos.y) << iV_DIVSHIFT) / dy;
|
||||
pie_ClipUV(s1, s2, clip, t);
|
||||
|
||||
n = 2;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
||||
int pie_ClipTextured(int npoints, CLIP_VERTEX *points, CLIP_VERTEX *clip)
|
||||
{
|
||||
static CLIP_VERTEX xclip[iV_POLY_MAX_POINTS+4];
|
||||
CLIP_VERTEX *p0, *p1;
|
||||
int n1, n, i;
|
||||
|
||||
p0 = &points[0];
|
||||
p1 = &points[1];
|
||||
|
||||
for (i = 0, n1 = 0; i < npoints; i++, p0++, p1++)
|
||||
{
|
||||
if (i == (npoints-1))
|
||||
{
|
||||
p1 = &points[0];
|
||||
}
|
||||
|
||||
// FIXME MAGIC
|
||||
if ((p0->pos.x == 1<<15) || (p0->pos.y == -1<<15))//check for invalid points jps19aug97
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
n1 += pie_ClipXT(p0, p1, &xclip[n1]);
|
||||
}
|
||||
|
||||
p0 = &xclip[0];
|
||||
p1 = &xclip[1];
|
||||
|
||||
for (i = 0, n = 0; i < n1; p0++, p1++, i++)
|
||||
{
|
||||
if (i == (n1-1))
|
||||
{
|
||||
p1 = &xclip[0];
|
||||
}
|
||||
n += pie_ClipYT(p0, p1, &clip[n]);
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
|
|
@ -41,8 +41,6 @@
|
|||
*/
|
||||
/***************************************************************************/
|
||||
|
||||
#define CLIP_BORDER 0
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Vector3i pos;
|
||||
|
@ -55,8 +53,7 @@ typedef struct
|
|||
* Global ProtoTypes
|
||||
*/
|
||||
/***************************************************************************/
|
||||
extern void pie_Set2DClip(int x0, int y0, int x1, int y1);
|
||||
extern int pie_ClipTextured(int npoints, CLIP_VERTEX *points, CLIP_VERTEX *clip);
|
||||
|
||||
extern BOOL pie_SetVideoBufferDepth(UDWORD depth);
|
||||
extern BOOL pie_SetVideoBufferWidth(UDWORD width);
|
||||
extern BOOL pie_SetVideoBufferHeight(UDWORD height);
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
/***************************************************************************/
|
||||
|
||||
#include "lib/framework/frame.h"
|
||||
#include "lib/framework/frameint.h"
|
||||
|
||||
#include <SDL_opengl.h>
|
||||
|
||||
|
@ -50,8 +51,7 @@
|
|||
void pie_DrawViewingWindow(Vector3i *v, UDWORD x1, UDWORD y1, UDWORD x2, UDWORD y2, PIELIGHT colour)
|
||||
{
|
||||
CLIP_VERTEX pieVrts[pie_MAX_VERTICES_PER_POLYGON];
|
||||
CLIP_VERTEX clippedVrts[pie_MAX_VERTICES_PER_POLYGON + 2]; // no idea why + 2 but fixes crash - Per
|
||||
SDWORD clip, i;
|
||||
SDWORD i;
|
||||
|
||||
pie_SetTexturePage(-1);
|
||||
pie_SetRendMode(REND_ALPHA_FLAT);
|
||||
|
@ -79,32 +79,27 @@ void pie_DrawViewingWindow(Vector3i *v, UDWORD x1, UDWORD y1, UDWORD x2, UDWORD
|
|||
pieVrts[3].pos.x = v[3].x;
|
||||
pieVrts[3].pos.y = v[3].y;
|
||||
|
||||
pie_Set2DClip(x1,y1,x2-1,y2-1);
|
||||
clip = pie_ClipTextured(4, &pieVrts[0], &clippedVrts[0]);
|
||||
ASSERT(clip <= pie_MAX_VERTICES_PER_POLYGON + 2, "clip index exceeds clippedVrts array"); // see above
|
||||
pie_Set2DClip(CLIP_BORDER,CLIP_BORDER,psRendSurface->width-CLIP_BORDER,psRendSurface->height-CLIP_BORDER);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glScissor(x1, screenHeight - y2, x2 - x1, y2 - y1);
|
||||
|
||||
if (clip >= 3)
|
||||
{
|
||||
glColor4ub(colour.byte.r, colour.byte.g, colour.byte.b, colour.byte.a >> 1);
|
||||
glColor4ub(colour.byte.r, colour.byte.g, colour.byte.b, colour.byte.a >> 1);
|
||||
glBegin(GL_TRIANGLE_FAN);
|
||||
for (i = 0; i < 5; i++)
|
||||
{
|
||||
glVertex2f(pieVrts[i].pos.x, pieVrts[i].pos.y);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
glBegin(GL_TRIANGLE_FAN);
|
||||
for (i = 0; i < clip; i++)
|
||||
{
|
||||
glVertex2f(clippedVrts[i].pos.x, clippedVrts[i].pos.y);
|
||||
}
|
||||
glEnd();
|
||||
glColor4ub(colour.byte.r, colour.byte.g, colour.byte.b, colour.byte.a);
|
||||
glBegin(GL_LINE_STRIP);
|
||||
for (i = 0; i < 5; i++)
|
||||
{
|
||||
glVertex2f(pieVrts[i].pos.x, pieVrts[i].pos.y);
|
||||
}
|
||||
glVertex2f(pieVrts[0].pos.x, pieVrts[0].pos.y);
|
||||
glEnd();
|
||||
|
||||
glColor4ub(colour.byte.r, colour.byte.g, colour.byte.b, colour.byte.a);
|
||||
|
||||
glBegin(GL_LINE_STRIP);
|
||||
for (i = 0; i < clip; i++)
|
||||
{
|
||||
glVertex2f(clippedVrts[i].pos.x, clippedVrts[i].pos.y);
|
||||
}
|
||||
glVertex2f(clippedVrts[0].pos.x, clippedVrts[0].pos.y);
|
||||
glEnd();
|
||||
}
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------------- */
|
||||
|
|
|
@ -35,7 +35,6 @@
|
|||
#include "lib/ivis_common/piedef.h"
|
||||
#include "lib/ivis_common/tex.h"
|
||||
#include "lib/ivis_common/piestate.h"
|
||||
#include "lib/ivis_common/pieclip.h"
|
||||
#include "lib/ivis_common/piepalette.h"
|
||||
// FIXME Direct iVis implementation include!
|
||||
#include "lib/ivis_opengl/piematrix.h"
|
||||
|
@ -183,9 +182,6 @@ static TERRAIN_VERTEX tileScreenInfo[LAND_YGRD][LAND_XGRD];
|
|||
/* Records the present X and Y values for the current mouse tile (in tiles */
|
||||
SDWORD mouseTileX, mouseTileY;
|
||||
|
||||
/* Offsets for the screen being shrunk/expanded - how far in, how far down */
|
||||
UDWORD xOffset = CLIP_BORDER, yOffset = CLIP_BORDER;
|
||||
|
||||
/* Do we want the radar to be rendered */
|
||||
BOOL radarOnScreen=FALSE;
|
||||
|
||||
|
@ -452,9 +448,6 @@ static void displayTerrain(void)
|
|||
{
|
||||
tileZ = 8000;
|
||||
|
||||
/* SetUpClipping window - to below the backdrop */
|
||||
pie_Set2DClip( xOffset, yOffset, psRendSurface->width-xOffset, psRendSurface->height-yOffset );
|
||||
|
||||
/* We haven't yet located which tile mouse is over */
|
||||
mouseLocated = FALSE;
|
||||
|
||||
|
@ -1412,7 +1405,6 @@ void displayProximityMsgs( void )
|
|||
y = ((BASE_OBJECT *)psProxDisp->psMessage->pViewData)->pos.y;
|
||||
}
|
||||
/* Is the Message worth rendering? */
|
||||
//if(clipXY(pViewProximity->pos.x,pViewProximity->pos.y))
|
||||
if(clipXY(x,y))
|
||||
{
|
||||
renderProximityMsg(psProxDisp);
|
||||
|
|
|
@ -91,7 +91,6 @@ extern BOOL init3DView(void);
|
|||
extern void initViewPosition(void);
|
||||
extern iView player;
|
||||
extern UDWORD distance;
|
||||
extern UDWORD xOffset,yOffset;
|
||||
extern BOOL selectAttempt;
|
||||
extern BOOL draggingTile;
|
||||
extern struct iIMDShape *g_imd;
|
||||
|
|
|
@ -2236,12 +2236,10 @@ void OpenButtonRender(UWORD XPos,UWORD YPos,UWORD Width,UWORD Height)
|
|||
ButYPos = YPos;
|
||||
ButWidth = Width;
|
||||
ButHeight = Height;
|
||||
pie_Set2DClip(XPos,YPos,(UWORD)(XPos+Width),(UWORD)(YPos+Height));
|
||||
}
|
||||
|
||||
void CloseButtonRender(void)
|
||||
{
|
||||
pie_Set2DClip(CLIP_BORDER,CLIP_BORDER,psRendSurface->width-CLIP_BORDER,psRendSurface->height-CLIP_BORDER);
|
||||
}
|
||||
|
||||
|
||||
|
@ -2251,12 +2249,10 @@ void ClearButton(BOOL Down,UDWORD Size, UDWORD buttonType)
|
|||
{
|
||||
if(Down)
|
||||
{
|
||||
// pie_ImageFileID(IntImages,(UWORD)(IMAGE_BUT0_DOWN+(Size*2)+(buttonType*6)),ButXPos,ButYPos);
|
||||
pie_ImageFileID(IntImages,(UWORD)(IMAGE_BUT0_DOWN+(buttonType*2)),ButXPos,ButYPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
// pie_ImageFileID(IntImages,(UWORD)(IMAGE_BUT0_UP+(Size*2)+(buttonType*6)),ButXPos,ButYPos);
|
||||
pie_ImageFileID(IntImages,(UWORD)(IMAGE_BUT0_UP+(buttonType*2)),ButXPos,ButYPos);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue