Skip to content

Commit

Permalink
Clean up R_SetClipRect.
Browse files Browse the repository at this point in the history
  • Loading branch information
skullernet committed Mar 14, 2013
1 parent baff433 commit 0fbfe3c
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 218 deletions.
9 changes: 1 addition & 8 deletions inc/refresh/refresh.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 3 additions & 11 deletions src/client/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)

/*
================
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -965,7 +958,6 @@ static void Con_DrawSolidConsole(void)

// restore rendering parameters
R_ClearColor();
R_SetClipRect(DRAW_CLIP_DISABLED, NULL);
}

//=============================================================================
Expand Down
18 changes: 0 additions & 18 deletions src/client/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -2010,33 +2010,19 @@ static void SCR_DrawLayout(void)

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

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();
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 4 additions & 8 deletions src/client/ui/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

/*
Expand Down
4 changes: 0 additions & 4 deletions src/client/ui/playerconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 2 additions & 15 deletions src/client/ui/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/client/ui/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
70 changes: 25 additions & 45 deletions src/refresh/gl/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/refresh/gl/gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions src/refresh/gl/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Loading

0 comments on commit 0fbfe3c

Please sign in to comment.