Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 48 additions & 8 deletions source/platform/ctr/gl/gl_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,42 @@ void Draw_FillByColor (int x, int y, int w, int h, int r, int g, int b, int a)
}
//=============================================================================

/*
=============
Batch_FillByColor

Fills a box of pixels with a single color (batched variant)
=============
*/
static qboolean is_batching_fill = qfalse;
void Batch_FillByColor (int x, int y, int w, int h, int r, int g, int b, int a)
{
if (!is_batching_fill) {
is_batching_fill = qtrue;
glDisable (GL_TEXTURE_2D);
glEnable (GL_BLEND); //johnfitz -- for alpha
glDisable (GL_ALPHA_TEST); //johnfitz -- for alpha
glColor4f ((float)(r/255.0f), (float)(g/255.0f), (float)(b/255.0f), (float)(a/255.0f));
glBegin (GL_QUADS);
}

glVertex2f (x,y);
glVertex2f (x+w, y);
glVertex2f (x+w, y+h);
glVertex2f (x, y+h);
}

void Draw_BatchedFill() {
if (is_batching_fill) {
glEnd ();
glColor4f (1,1,1,1);
glDisable (GL_BLEND); //johnfitz -- for alpha
glEnable(GL_ALPHA_TEST); //johnfitz -- for alpha
glEnable (GL_TEXTURE_2D);
is_batching_fill = qfalse;
}
}

byte *StringToRGB (char *s)
{
byte *col;
Expand Down Expand Up @@ -1154,19 +1190,21 @@ void Draw_Crosshair (void)

x_value = (vid.width - 3)/2.0f - crosshair_offset_step;
y_value = (vid.height - 1)/2.0f;
Draw_FillByColor(x_value, y_value, 3, 1, 255, (int)col, (int)col, (int)crosshair_opacity);
Batch_FillByColor(x_value, y_value, 3, 1, 255, (int)col, (int)col, (int)crosshair_opacity);

x_value = (vid.width - 3)/2.0f + crosshair_offset_step;
y_value = (vid.height - 1)/2.0f;
Draw_FillByColor(x_value, y_value, 3, 1, 255, (int)col, (int)col, (int)crosshair_opacity);
Batch_FillByColor(x_value, y_value, 3, 1, 255, (int)col, (int)col, (int)crosshair_opacity);

x_value = (vid.width - 1)/2.0f;
y_value = (vid.height - 3)/2.0f - crosshair_offset_step;
Draw_FillByColor(x_value, y_value, 1, 3, 255, (int)col, (int)col, (int)crosshair_opacity);
Batch_FillByColor(x_value, y_value, 1, 3, 255, (int)col, (int)col, (int)crosshair_opacity);

x_value = (vid.width - 1)/2.0f;
y_value = (vid.height - 3)/2.0f + crosshair_offset_step;
Draw_FillByColor(x_value, y_value, 1, 3, 255, (int)col, (int)col, (int)crosshair_opacity);
Batch_FillByColor(x_value, y_value, 1, 3, 255, (int)col, (int)col, (int)crosshair_opacity);

Draw_BatchedFill();
}
// Area of Effect (o)
else if (crosshair.value == 2) {
Expand All @@ -1190,19 +1228,21 @@ void Draw_Crosshair (void)

x_value = (vid.width - 3)/2.0f - crosshair_offset_step;
y_value = (vid.height - 1)/2.0f;
Draw_FillByColor(x_value, y_value, 3, 1, 255, 255, 255, 255);
Batch_FillByColor(x_value, y_value, 3, 1, 255, 255, 255, 255);

x_value = (vid.width - 3)/2.0f + crosshair_offset_step;
y_value = (vid.height - 1)/2.0f;
Draw_FillByColor(x_value, y_value, 3, 1, 255, 255, 255, 255);
Batch_FillByColor(x_value, y_value, 3, 1, 255, 255, 255, 255);

x_value = (vid.width - 1)/2.0f;
y_value = (vid.height - 3)/2.0f - crosshair_offset_step;
Draw_FillByColor(x_value, y_value, 1, 3, 255, 255, 255, 255);
Batch_FillByColor(x_value, y_value, 1, 3, 255, 255, 255, 255);

x_value = (vid.width - 1)/2.0f;
y_value = (vid.height - 3)/2.0f + crosshair_offset_step;
Draw_FillByColor(x_value, y_value, 1, 3, 255, 255, 255, 255);
Batch_FillByColor(x_value, y_value, 1, 3, 255, 255, 255, 255);

Draw_BatchedFill();
}
}

Expand Down
102 changes: 72 additions & 30 deletions source/platform/psp/gu/gu_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,41 @@ void Draw_FillByColor (int x, int y, int w, int h, int r, int g, int b, int a)
sceGuEnable(GU_TEXTURE_2D);
}

/*
=============
Draw_FillByColorBatched

Fills multiple boxes of pixels with a single color
=============
*/
void Draw_FillByColorBatched (int *x, int *y, int *w, int *h, int r, int g, int b, int a, int num)
{
unsigned int c = GU_RGBA(r, g, b, a);

struct vertex
{
short x, y, z;
};

vertex* const vertices = static_cast<vertex*>(sceGuGetMemory(sizeof(vertex) * (2 * num)));

for (int i = 0; i < num; i++) {
vertices[i * 2].x = x[i];
vertices[i * 2].y = y[i];
vertices[i * 2].z = 0;

vertices[i * 2 + 1].x = x[i] + w[i];
vertices[i * 2 + 1].y = y[i] + h[i];
vertices[i * 2 + 1].z = 0;
}

sceGuDisable(GU_TEXTURE_2D);
sceGuColor(c);
sceGuDrawArray(GU_SPRITES, GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2 * num, 0, vertices);
sceGuColor(0xffffffff);
sceGuEnable(GU_TEXTURE_2D);
}

void Draw_Fill (int x, int y, int w, int h, int c)
{
struct vertex
Expand Down Expand Up @@ -1396,10 +1431,12 @@ void Draw_Crosshair (void)
Draw_Pic (112, 7, sniper_scope);

// And its borders
Draw_FillByColor(0, 0, 480, 7, 0, 0, 0, 255); // Top
Draw_FillByColor(0, 263, 480, 9, 0, 0, 0, 255); // Bottom
Draw_FillByColor(0, 7, 112, 256, 0, 0, 0, 255); // Left
Draw_FillByColor(368, 7, 112, 256, 0, 0, 0, 255); // Right
int x[4], y[4], w[4], h[4];
x[0] = 0; y[0] = 0; w[0] = 480; y[0] = 7; // Top
x[1] = 0; y[1] = 263; w[1] = 480; y[1] = 9; // Bottom
x[2] = 0; y[2] = 7; w[2] = 112; y[2] = 256; // Left
x[3] = 368; y[3] = 7; w[3] = 112; y[3] = 256; // Right
Draw_FillByColorBatched(x, y, w, h, 0, 0, 0, 255, 4);
}

if (Hitmark_Time > sv.time)
Expand Down Expand Up @@ -1441,7 +1478,6 @@ void Draw_Crosshair (void)
}
}

int x_value, y_value;
int x_center, y_center;
int crosshair_offset;

Expand All @@ -1461,26 +1497,29 @@ void Draw_Crosshair (void)
}

crosshair_offset_step += (crosshair_offset - crosshair_offset_step) * 0.5;


int x[4], y[4], w[4], h[4];
// Left
x_value = x_center - crosshair_offset_step;
y_value = y_center;
Draw_FillByColor(x_value, y_value, 3, 1, 255, (int)col, (int)col, (int)crosshair_opacity);
x[0] = x_center - crosshair_offset_step;
y[0] = y_center;
w[0] = 3; h[0] = 1;

// Right
x_value = x_center + crosshair_offset_step - 3;
y_value = y_center;
Draw_FillByColor(x_value, y_value, 3, 1, 255, (int)col, (int)col, (int)crosshair_opacity);
x[1] = x_center + crosshair_offset_step - 3;
y[1] = y_center;
w[1] = 3; h[1] = 1;

// Top
x_value = x_center;
y_value = y_center - crosshair_offset_step;
Draw_FillByColor(x_value, y_value, 1, 3, 255, (int)col, (int)col, (int)crosshair_opacity);
x[2] = x_center;
y[2] = y_center - crosshair_offset_step;
w[2] = 1; h[2] = 3;

// Bottom
x_value = x_center;
y_value = y_center + crosshair_offset_step - 3;
Draw_FillByColor(x_value, y_value, 1, 3, 255, (int)col, (int)col, (int)crosshair_opacity);
x[3] = x_center;
y[3] = y_center + crosshair_offset_step - 3;
w[3] = 1; h[3] = 3;

Draw_FillByColorBatched(x, y, w, h, 255, (int)col, (int)col, (int)crosshair_opacity, 4);
}
// Area of Effect (o)
else if (crosshair.value == 2) {
Expand All @@ -1505,25 +1544,28 @@ void Draw_Crosshair (void)
crosshair_offset = 12 + cur_spread;
crosshair_offset_step += (crosshair_offset - crosshair_offset_step) * 0.5;

int x[4], y[4], w[4], h[4];
// Left
x_value = x_center - crosshair_offset_step;
y_value = y_center;
Draw_FillByColor(x_value, y_value, 3, 1, 255, 255, 255, 255);
x[0] = x_center - crosshair_offset_step;
y[0] = y_center;
w[0] = 3; h[0] = 1;

// Right
x_value = x_center + crosshair_offset_step - 2;
y_value = y_center;
Draw_FillByColor(x_value, y_value, 3, 1, 255, 255, 255, 255);
x[1] = x_center + crosshair_offset_step - 2;
y[1] = y_center;
w[1] = 3; h[1] = 1;

// Top
x_value = x_center;
y_value = y_center - crosshair_offset_step;
Draw_FillByColor(x_value, y_value, 1, 3, 255, 255, 255, 255);
x[2] = x_center;
y[2] = y_center - crosshair_offset_step;
w[2] = 1; h[2] = 3;

// Bottom
x_value = x_center;
y_value = y_center + crosshair_offset_step - 3;
Draw_FillByColor(x_value, y_value, 1, 3, 255, 255, 255, 255);
x[3] = x_center;
y[3] = y_center + crosshair_offset_step - 3;
w[3] = 1; h[3] = 3;

Draw_FillByColorBatched(x, y, w, h, 255, 255, 255, 255, 4);
}
}

Expand Down