summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Nazarov <skuller@skuller.net>2013-03-13 19:53:52 +0400
committerAndrey Nazarov <skuller@skuller.net>2013-03-14 20:53:32 +0400
commit0fbfe3ceb793830aa7a96bdc1b2d605a2fa8491c (patch)
tree1650418e8d0121d8ea942492f5e601d0b28007eb
parentbaff433b6a2347ba3b052c6d54027634ea90175e (diff)
Clean up R_SetClipRect.
-rw-r--r--inc/refresh/refresh.h9
-rw-r--r--src/client/console.c14
-rw-r--r--src/client/screen.c18
-rw-r--r--src/client/ui/menu.c12
-rw-r--r--src/client/ui/playerconfig.c4
-rw-r--r--src/client/ui/ui.c17
-rw-r--r--src/client/ui/ui.h1
-rw-r--r--src/refresh/gl/draw.c70
-rw-r--r--src/refresh/gl/gl.h6
-rw-r--r--src/refresh/gl/state.c5
-rw-r--r--src/refresh/sw/draw.c165
-rw-r--r--src/refresh/sw/main.c2
12 files changed, 105 insertions, 218 deletions
diff --git a/inc/refresh/refresh.h b/inc/refresh/refresh.h
index d1b1f2b..173c423 100644
--- a/inc/refresh/refresh.h
+++ b/inc/refresh/refresh.h
@@ -142,13 +142,6 @@ typedef struct {
extern refcfg_t r_config;
-#define DRAW_CLIP_DISABLED 0
-#define DRAW_CLIP_LEFT 0x00000004
-#define DRAW_CLIP_RIGHT 0x00000008
-#define DRAW_CLIP_TOP 0x00000010
-#define DRAW_CLIP_BOTTOM 0x00000020
-#define DRAW_CLIP_MASK 0x0000003C
-
typedef struct {
int left, right, top, bottom;
} clipRect_t;
@@ -209,7 +202,7 @@ void R_LightPoint(vec3_t origin, vec3_t light);
void R_ClearColor(void);
void R_SetAlpha(float clpha);
void R_SetColor(uint32_t color);
-void R_SetClipRect(int flags, const clipRect_t *clip);
+void R_SetClipRect(const clipRect_t *clip);
void R_SetScale(float *scale);
void R_DrawChar(int x, int y, int flags, int ch, qhandle_t font);
int R_DrawString(int x, int y, int flags, size_t maxChars,
diff --git a/src/client/console.c b/src/client/console.c
index 6ac17a0..eb1eeeb 100644
--- a/src/client/console.c
+++ b/src/client/console.c
@@ -682,7 +682,7 @@ static int Con_DrawLine(int v, int line, float alpha)
con.charsetImage);
}
-#define CON_PRESTEP (10 + CHAR_HEIGHT * 2)
+#define CON_PRESTEP (CHAR_HEIGHT * 3 + CHAR_HEIGHT / 4)
/*
================
@@ -771,7 +771,6 @@ static void Con_DrawSolidConsole(void)
char buffer[CON_LINEWIDTH];
int vislines;
float alpha;
- clipRect_t clip;
int widths[2];
vislines = con.vidHeight * con.currentHeight;
@@ -787,12 +786,6 @@ static void Con_DrawSolidConsole(void)
R_SetAlpha(alpha * Cvar_ClampValue(con_alpha, 0, 1));
}
- clip.left = 0;
- clip.top = 0;
- clip.right = 0;
- clip.bottom = 0;
- R_SetClipRect(DRAW_CLIP_TOP, &clip);
-
// draw the background
if (cls.state < ca_active || (cls.key_dest & KEY_MENU) || con_alpha->value) {
R_DrawStretchPic(0, vislines - con.vidHeight,
@@ -875,7 +868,7 @@ static void Con_DrawSolidConsole(void)
cls.download.percent, cls.download.position / 1000);
// draw it
- y = vislines - 10;
+ y = vislines - CON_PRESTEP + CHAR_HEIGHT * 2;
R_DrawString(CHAR_WIDTH, y, 0, CON_LINEWIDTH, buffer, con.charsetImage);
} else if (cls.state == ca_loading) {
// draw loading state
@@ -904,7 +897,7 @@ static void Con_DrawSolidConsole(void)
Q_snprintf(buffer, sizeof(buffer), "Loading %s...", text);
// draw it
- y = vislines - 10;
+ y = vislines - CON_PRESTEP + CHAR_HEIGHT * 2;
R_DrawString(CHAR_WIDTH, y, 0, CON_LINEWIDTH, buffer, con.charsetImage);
}
}
@@ -965,7 +958,6 @@ static void Con_DrawSolidConsole(void)
// restore rendering parameters
R_ClearColor();
- R_SetClipRect(DRAW_CLIP_DISABLED, NULL);
}
//=============================================================================
diff --git a/src/client/screen.c b/src/client/screen.c
index 752794e..5dd9fba 100644
--- a/src/client/screen.c
+++ b/src/client/screen.c
@@ -2010,11 +2010,7 @@ draw:
static void SCR_Draw2D(void)
{
-#if USE_REF == REF_SOFT
- clipRect_t rc;
-#else
float scale;
-#endif
if (scr_draw2d->integer <= 0)
return; // turn off for screenshots
@@ -2022,21 +2018,11 @@ static void SCR_Draw2D(void)
if (cls.key_dest & KEY_MENU)
return;
-#if USE_REF == REF_SOFT
- // avoid DoS by making sure nothing is drawn out of bounds
- rc.left = 0;
- rc.top = 0;
- rc.right = scr.hud_width;
- rc.bottom = scr.hud_height;
-
- R_SetClipRect(DRAW_CLIP_MASK, &rc);
-#else
scale = 1.0f / Cvar_ClampValue(scr_scale, 1, 9);
R_SetScale(&scale);
scr.hud_height *= scale;
scr.hud_width *= scale;
-#endif
// crosshair has its own color and alpha
SCR_DrawCrosshair();
@@ -2071,11 +2057,7 @@ static void SCR_Draw2D(void)
SCR_DrawDebugPmove();
#endif
-#if USE_REF == REF_SOFT
- R_SetClipRect(DRAW_CLIP_DISABLED, NULL);
-#else
R_SetScale(NULL);
-#endif
}
static void SCR_DrawActive(void)
diff --git a/src/client/ui/menu.c b/src/client/ui/menu.c
index da9d29f..1bc3374 100644
--- a/src/client/ui/menu.c
+++ b/src/client/ui/menu.c
@@ -1258,8 +1258,8 @@ static void MenuList_DrawString(int x, int y, int flags,
rc.left = x;
rc.right = x + column->width - 1;
- rc.top = 0;
- rc.bottom = 0;
+ rc.top = y + 1;
+ rc.bottom = y + CHAR_HEIGHT + 1;
if ((column->uiFlags & UI_CENTER) == UI_CENTER) {
x += column->width / 2 - 1;
@@ -1269,13 +1269,9 @@ static void MenuList_DrawString(int x, int y, int flags,
x += MLIST_PRESTEP;
}
- R_SetClipRect(DRAW_CLIP_RIGHT | DRAW_CLIP_LEFT, &rc);
+ R_SetClipRect(&rc);
UI_DrawString(x, y + 1, column->uiFlags | flags, string);
-#if USE_REF == REF_SOFT
- R_SetClipRect(DRAW_CLIP_MASK, &uis.clipRect);
-#else
- R_SetClipRect(DRAW_CLIP_DISABLED, NULL);
-#endif
+ R_SetClipRect(NULL);
}
/*
diff --git a/src/client/ui/playerconfig.c b/src/client/ui/playerconfig.c
index d4c9355..280916a 100644
--- a/src/client/ui/playerconfig.c
+++ b/src/client/ui/playerconfig.c
@@ -130,11 +130,7 @@ static void Draw(menuFrameWork_t *self)
R_RenderFrame(&m_player.refdef);
-#if USE_REF == REF_SOFT
- R_SetClipRect(DRAW_CLIP_MASK, &uis.clipRect);
-#else
R_SetScale(&uis.scale);
-#endif
}
static void Size(menuFrameWork_t *self)
diff --git a/src/client/ui/ui.c b/src/client/ui/ui.c
index 8ff73fb..b63f436 100644
--- a/src/client/ui/ui.c
+++ b/src/client/ui/ui.c
@@ -99,16 +99,11 @@ static void UI_Resize(void)
int i;
#if USE_REF == REF_SOFT
- uis.clipRect.left = 0;
- uis.clipRect.top = 0;
- uis.clipRect.right = r_config.width;
- uis.clipRect.bottom = r_config.height;
uis.scale = 1;
uis.width = r_config.width;
uis.height = r_config.height;
#else
- Cvar_ClampValue(ui_scale, 1, 9);
- uis.scale = 1 / ui_scale->value;
+ uis.scale = 1 / Cvar_ClampValue(ui_scale, 1, 9);
uis.width = r_config.width * uis.scale;
uis.height = r_config.height * uis.scale;
#endif
@@ -436,11 +431,7 @@ void UI_Draw(int realtime)
}
R_ClearColor();
-#if USE_REF == REF_SOFT
- R_SetClipRect(DRAW_CLIP_MASK, &uis.clipRect);
-#else
R_SetScale(&uis.scale);
-#endif
if (1) {
// draw top menu
@@ -479,12 +470,8 @@ void UI_Draw(int realtime)
S_StartLocalSound("misc/menu1.wav");
}
-#if USE_REF == REF_SOFT
- R_SetClipRect(DRAW_CLIP_DISABLED, NULL);
-#else
- R_SetScale(NULL);
-#endif
R_ClearColor();
+ R_SetScale(NULL);
}
void UI_StartSound(menuSound_t sound)
diff --git a/src/client/ui/ui.h b/src/client/ui/ui.h
index fff4071..cd7fb60 100644
--- a/src/client/ui/ui.h
+++ b/src/client/ui/ui.h
@@ -271,7 +271,6 @@ void PlayerModel_Free(void);
typedef struct uiStatic_s {
qboolean initialized;
int realtime;
- clipRect_t clipRect;
int width, height; // scaled
float scale;
int menuDepth;
diff --git a/src/refresh/gl/draw.c b/src/refresh/gl/draw.c
index cd54d1a..9eba703 100644
--- a/src/refresh/gl/draw.c
+++ b/src/refresh/gl/draw.c
@@ -109,66 +109,46 @@ void R_SetColor(uint32_t color)
draw.colors[1].u8[3] = draw.colors[0].u8[3];
}
-void R_SetClipRect(int flags, const clipRect_t *clip)
+void R_SetClipRect(const clipRect_t *clip)
{
clipRect_t rc;
float scale;
- if ((draw.flags & DRAW_CLIP_MASK) == flags) {
- return;
- }
-
GL_Flush2D();
- if (flags == DRAW_CLIP_DISABLED) {
- qglDisable(GL_SCISSOR_TEST);
- draw.flags &= ~DRAW_CLIP_MASK;
+ if (!clip) {
+clear:
+ if (draw.scissor) {
+ qglDisable(GL_SCISSOR_TEST);
+ draw.scissor = qfalse;
+ }
return;
}
scale = 1 / draw.scale;
- rc.left = 0;
- rc.top = 0;
- if (flags & DRAW_CLIP_LEFT) {
- rc.left = clip->left * scale;
- if (rc.left < 0) {
- rc.left = 0;
- }
- }
- if (flags & DRAW_CLIP_TOP) {
- rc.top = clip->top * scale;
- if (rc.top < 0) {
- rc.top = 0;
- }
- }
-
- rc.right = r_config.width;
- rc.bottom = r_config.height;
- if (flags & DRAW_CLIP_RIGHT) {
- rc.right = clip->right * scale;
- if (rc.right > r_config.width) {
- rc.right = r_config.width;
- }
- }
- if (flags & DRAW_CLIP_BOTTOM) {
- rc.bottom = clip->bottom * scale;
- if (rc.bottom > r_config.height) {
- rc.bottom = r_config.height;
- }
- }
-
- if (rc.right < rc.left) {
- rc.right = rc.left;
- }
- if (rc.bottom < rc.top) {
- rc.bottom = rc.top;
- }
+ rc.left = clip->left * scale;
+ rc.top = clip->top * scale;
+ rc.right = clip->right * scale;
+ rc.bottom = clip->bottom * scale;
+
+ if (rc.left < 0)
+ rc.left = 0;
+ if (rc.top < 0)
+ rc.top = 0;
+ if (rc.right > r_config.width)
+ rc.right = r_config.width;
+ if (rc.bottom > r_config.height)
+ rc.bottom = r_config.height;
+ if (rc.right < rc.left)
+ goto clear;
+ if (rc.bottom < rc.top)
+ goto clear;
qglEnable(GL_SCISSOR_TEST);
qglScissor(rc.left, r_config.height - rc.bottom,
rc.right - rc.left, rc.bottom - rc.top);
- draw.flags = (draw.flags & ~DRAW_CLIP_MASK) | flags;
+ draw.scissor = qtrue;
}
void R_SetScale(float *scale)
diff --git a/src/refresh/gl/gl.h b/src/refresh/gl/gl.h
index e412ecd..f0234d9 100644
--- a/src/refresh/gl/gl.h
+++ b/src/refresh/gl/gl.h
@@ -385,9 +385,9 @@ void GL_DisableOutlines(void);
*
*/
typedef struct {
- color_t colors[2]; // 0 - actual color, 1 - transparency (for text drawing)
- int flags;
- float scale;
+ color_t colors[2]; // 0 - actual color, 1 - transparency (for text drawing)
+ qboolean scissor;
+ float scale;
} drawStatic_t;
extern drawStatic_t draw;
diff --git a/src/refresh/gl/state.c b/src/refresh/gl/state.c
index 3d8c6b4..f73ad4a 100644
--- a/src/refresh/gl/state.c
+++ b/src/refresh/gl/state.c
@@ -268,12 +268,11 @@ void GL_Setup2D(void)
draw.colors[0].u32 = U32_WHITE;
draw.colors[1].u32 = U32_WHITE;
- if (draw.flags & DRAW_CLIP_MASK) {
+ if (draw.scissor) {
qglDisable(GL_SCISSOR_TEST);
+ draw.scissor = qfalse;
}
- draw.flags = 0;
-
qglMatrixMode(GL_MODELVIEW);
qglLoadIdentity();
}
diff --git a/src/refresh/sw/draw.c b/src/refresh/sw/draw.c
index 706c21e..9bd9b51 100644
--- a/src/refresh/sw/draw.c
+++ b/src/refresh/sw/draw.c
@@ -88,9 +88,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
} while (count)
typedef struct {
- color_t colors[2];
- clipRect_t clipRect;
- int flags;
+ color_t colors[2];
+ clipRect_t clip;
} drawStatic_t;
static drawStatic_t draw;
@@ -107,6 +106,10 @@ void R_InitDraw(void)
memset(&draw, 0, sizeof(draw));
draw.colors[0].u32 = U32_WHITE;
draw.colors[1].u32 = U32_WHITE;
+ draw.clip.left = 0;
+ draw.clip.top = 0;
+ draw.clip.right = r_config.width;
+ draw.clip.bottom = r_config.height;
}
void R_ClearColor(void)
@@ -127,15 +130,31 @@ void R_SetColor(uint32_t color)
draw.colors[1].u8[3] = draw.colors[0].u8[3];
}
-void R_SetClipRect(int flags, const clipRect_t *clip)
+void R_SetClipRect(const clipRect_t *clip)
{
- draw.flags &= ~DRAW_CLIP_MASK;
-
- if (flags == DRAW_CLIP_DISABLED) {
+ if (!clip) {
+clear:
+ draw.clip.left = 0;
+ draw.clip.top = 0;
+ draw.clip.right = r_config.width;
+ draw.clip.bottom = r_config.height;
return;
}
- draw.flags |= flags;
- draw.clipRect = *clip;
+
+ draw.clip = *clip;
+
+ if (draw.clip.left < 0)
+ draw.clip.left = 0;
+ if (draw.clip.top < 0)
+ draw.clip.top = 0;
+ if (draw.clip.right > r_config.width)
+ draw.clip.right = r_config.width;
+ if (draw.clip.bottom > r_config.height)
+ draw.clip.bottom = r_config.height;
+ if (draw.clip.right < draw.clip.left)
+ goto clear;
+ if (draw.clip.bottom < draw.clip.top)
+ goto clear;
}
/*
@@ -149,60 +168,30 @@ static void R_DrawStretchData(int x, int y, int w, int h, int xx, int yy,
byte *srcpixels, *dstpixels, *dst, *src;
int v, u;
int ustep, vstep;
- int skipv, skipu;
- int width, height;
+ int skipv = 0, skipu = 0;
+ int width = w, height = h;
int count;
byte *_src;
int tmp[4];
- skipv = skipu = 0;
- width = w;
- height = h;
-
- if (draw.flags & DRAW_CLIP_MASK) {
- clipRect_t *clip = &draw.clipRect;
-
- if (draw.flags & DRAW_CLIP_LEFT) {
- if (x < clip->left) {
- skipu = clip->left - x;
- if (w <= skipu) {
- return;
- }
- w -= skipu;
- x = clip->left;
- }
- }
-
- if (draw.flags & DRAW_CLIP_RIGHT) {
- if (x >= clip->right) {
- return;
- }
- if (x + w > clip->right) {
- w = clip->right - x;
- }
- }
-
- if (draw.flags & DRAW_CLIP_TOP) {
- if (y < clip->top) {
- skipv = clip->top - y;
- if (h <= skipv) {
- return;
- }
- h -= skipv;
- y = clip->top;
- }
- }
-
- if (draw.flags & DRAW_CLIP_BOTTOM) {
- if (y >= clip->bottom) {
- return;
- }
- if (y + h > clip->bottom) {
- h = clip->bottom - y;
- }
- }
+ if (x < draw.clip.left) {
+ skipu = draw.clip.left - x;
+ w -= skipu;
+ x = draw.clip.left;
+ }
+ if (y < draw.clip.top) {
+ skipv = draw.clip.top - y;
+ h -= skipv;
+ y = draw.clip.top;
}
+ if (x + w > draw.clip.right)
+ w = draw.clip.right - x;
+ if (y + h > draw.clip.bottom)
+ h = draw.clip.bottom - y;
+ if (w <= 0 || h <= 0)
+ return;
+
srcpixels = data + yy * pitch + xx * TEX_BYTES;
dstpixels = vid.buffer + y * vid.rowbytes + x * VID_BYTES;
@@ -302,55 +291,27 @@ static void R_DrawFixedData(int x, int y, int w, int h,
{
byte *srcpixels, *dstpixels;
byte *dst, *src;
- int skipv, skipu;
+ int skipv = 0, skipu = 0;
int count;
int tmp[4];
- skipv = skipu = 0;
-
- if (draw.flags & DRAW_CLIP_MASK) {
- clipRect_t *clip = &draw.clipRect;
-
- if (draw.flags & DRAW_CLIP_LEFT) {
- if (x < clip->left) {
- skipu = clip->left - x;
- if (w <= skipu) {
- return;
- }
- w -= skipu;
- x = clip->left;
- }
- }
-
- if (draw.flags & DRAW_CLIP_RIGHT) {
- if (x >= clip->right) {
- return;
- }
- if (x + w > clip->right) {
- w = clip->right - x;
- }
- }
-
- if (draw.flags & DRAW_CLIP_TOP) {
- if (y < clip->top) {
- skipv = clip->top - y;
- if (h <= skipv) {
- return;
- }
- h -= skipv;
- y = clip->top;
- }
- }
-
- if (draw.flags & DRAW_CLIP_BOTTOM) {
- if (y >= clip->bottom) {
- return;
- }
- if (y + h > clip->bottom) {
- h = clip->bottom - y;
- }
- }
+ if (x < draw.clip.left) {
+ skipu = draw.clip.left - x;
+ w -= skipu;
+ x = draw.clip.left;
}
+ if (y < draw.clip.top) {
+ skipv = draw.clip.top - y;
+ h -= skipv;
+ y = draw.clip.top;
+ }
+
+ if (x + w > draw.clip.right)
+ w = draw.clip.right - x;
+ if (y + h > draw.clip.bottom)
+ h = draw.clip.bottom - y;
+ if (w <= 0 || h <= 0)
+ return;
srcpixels = data + skipv * pitch + skipu * TEX_BYTES;
dstpixels = vid.buffer + y * vid.rowbytes + x * VID_BYTES;
diff --git a/src/refresh/sw/main.c b/src/refresh/sw/main.c
index 1316f12..467170c 100644
--- a/src/refresh/sw/main.c
+++ b/src/refresh/sw/main.c
@@ -235,6 +235,8 @@ void R_ModeChanged(int width, int height, int flags, int rowbytes, void *pixels)
r_config.height = vid.height;
r_config.flags = flags;
+ R_SetClipRect(NULL);
+
sw_surfcacheoverride = Cvar_Get("sw_surfcacheoverride", "0", 0);
D_FlushCaches();