Skip to content

Commit 07412f1

Browse files
suicvneWohlstand
authored andcommitted
[VITA] Add supported for drawing unfilled rects. Useful for Editor & recent additions to power state & joystick UI
1 parent 7674f1f commit 07412f1

File tree

3 files changed

+50
-25
lines changed

3 files changed

+50
-25
lines changed

src/vita/frm_main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,13 +823,13 @@ void FrmMain::renderRect(int x, int y, int w, int h, float red, float green, flo
823823
(void)filled;
824824
// TODO: Filled or not?
825825
PGE_RectF rect = __NormalizeToGL(x + viewport_offset_x, y + viewport_offset_y, w, h, ScreenW, ScreenH);
826-
Vita_DrawRectColor(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, red, green, blue, alpha);
826+
Vita_DrawRectColor(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, red, green, blue, alpha, filled);
827827
}
828828

829829
void FrmMain::renderRectBR(int _left, int _top, int _right, int _bottom, float red, float green, float blue, float alpha)
830830
{
831831
PGE_RectF rect = __NormalizeToGL(_left + viewport_offset_x, _top + viewport_offset_y, _right - _left, _bottom - _top, ScreenW, ScreenH);
832-
Vita_DrawRectColor(rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, red, green, blue, alpha);
832+
Vita_DrawRectColor(rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, red, green, blue, alpha, true);
833833
}
834834

835835
void FrmMain::renderTexturePrivate(float xDst, float yDst, float wDst, float hDst,

src/vita/vgl_renderer.c

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ static const GLuint VERTEX_SIZE = VERTEX_POS_SIZE + VERTEX_TEXCOORD_SIZE + VERTE
6060
// ARRAYS OF PENDING DRAW CALLS (DrawCall _vgl_pending_calls[MAX_VERTICES];)
6161
static char __vgl_repaint_inprog = 0;
6262

63+
// Filled by default
64+
static char _curBufferFillState[MAX_VERTICES] = {1};
65+
6366
static DrawCall *_curBufferA;
6467
static DrawCall *_curBufferB;
6568

@@ -241,29 +244,45 @@ _Vita_WriteVertices4xColor(DrawCall *drawCall,
241244
float rgba0[4],
242245
float rgba1[4],
243246
float rgba2[4],
244-
float rgba3[4])
247+
float rgba3[4],
248+
char filled)
245249
{
246250
if(drawCall == nullptr) return;
247251

252+
// we haven't incremented until we call "Vita_DoneWithDrawCall()"
253+
// so we can set this here.
254+
_curBufferFillState[_vgl_pending_offset] = filled;
255+
256+
// filled order?
257+
// x, y
258+
//
259+
// v0
248260
drawCall->verts[0].x = x;
249261
drawCall->verts[0].y = y;
250262
drawCall->verts[0].s = n_src_x; // Tex Coord X
251263
drawCall->verts[0].v = n_src_y; // Tex Coord Y
252-
264+
265+
// v1
253266
drawCall->verts[1].x = x;
254267
drawCall->verts[1].y = y + hDst;
255-
drawCall->verts[1].s = n_src_x; // Tex Coord X
268+
drawCall->verts[1].s = n_src_x; // Tex Coord X
256269
drawCall->verts[1].v = n_src_y2; // Tex Coord Y
257-
258-
drawCall->verts[2].x = x + wDst;
259-
drawCall->verts[2].y = y;
260-
drawCall->verts[2].s = n_src_x2; // Tex Coord X
261-
drawCall->verts[2].v = n_src_y; // Tex Coord Y
262270

263-
drawCall->verts[3].x = x + wDst;
264-
drawCall->verts[3].y = y + hDst;
265-
drawCall->verts[3].s = n_src_x2; // Tex Coord X
266-
drawCall->verts[3].v = n_src_y2; // Tex Coord Y
271+
// If we're not drawing filled, then we need to swap
272+
// the last two vertices to ensure proper draw order.
273+
const int c = filled ? 2 : 3,
274+
d = filled ? 3 : 2;
275+
// v2
276+
drawCall->verts[c].x = x + wDst;
277+
drawCall->verts[c].y = y;
278+
drawCall->verts[c].s = n_src_x2; // Tex Coord X
279+
drawCall->verts[c].v = n_src_y; // Tex Coord Y
280+
281+
// v3
282+
drawCall->verts[d].x = x + wDst;
283+
drawCall->verts[d].y = y + hDst;
284+
drawCall->verts[d].s = n_src_x2; // Tex Coord X
285+
drawCall->verts[d].v = n_src_y2; // Tex Coord Y
267286

268287
drawCall->verts[0]._r = rgba0[0];
269288
drawCall->verts[0]._g = rgba0[1];
@@ -311,7 +330,7 @@ _Vita_WriteVertices(DrawCall *drawCall,
311330
_Vita_WriteVertices4xColor(drawCall,
312331
x, y, wDst, hDst,
313332
n_src_x, n_src_x2, n_src_y, n_src_y2,
314-
rgba0, rgba0, rgba0, rgba0);
333+
rgba0, rgba0, rgba0, rgba0, true);
315334
}
316335

317336
static inline GLuint Vita_GetVertexBufferID() { return _vertexBufferID; }
@@ -387,14 +406,15 @@ void Vita_DrawRect4xColor(float x, float y,
387406
float rgba0[4],
388407
float rgba1[4],
389408
float rgba2[4],
390-
float rgba3[4])
409+
float rgba3[4],
410+
char filled)
391411
{
392412
DrawCall *_curDrawCall = _Vita_GetAvailableDrawCall();
393413

394414
for(int i = 0; i < 4; i++)
395415
_curDrawCall->verts[i].obj_ptr = 0;
396416

397-
_Vita_WriteVertices4xColor(_curDrawCall, x, y, wDst, hDst, 0.f, 1.f, 0.f, 1.f, rgba0, rgba1, rgba2, rgba3);
417+
_Vita_WriteVertices4xColor(_curDrawCall, x, y, wDst, hDst, 0.f, 1.f, 0.f, 1.f, rgba0, rgba1, rgba2, rgba3, filled);
398418

399419
_Vita_DoneWithDrawCall();
400420
}
@@ -409,10 +429,11 @@ void Vita_DrawRectColor(float x, float y,
409429
float _r,
410430
float _g,
411431
float _b,
412-
float _a)
432+
float _a,
433+
char filled)
413434
{
414435
float rgba0[4] = {_r, _g, _b, _a};
415-
Vita_DrawRect4xColor(x, y, wDst, hDst, rgba0, rgba0, rgba0, rgba0);
436+
Vita_DrawRect4xColor(x, y, wDst, hDst, rgba0, rgba0, rgba0, rgba0, filled);
416437
}
417438

418439
/**
@@ -447,7 +468,7 @@ void Vita_DrawRectColorExData(float x, float y,
447468
// _curDrawCall->piv_x = x + (wDst * .5f);
448469
// _curDrawCall->piv_y = y + (hDst * .5f);
449470

450-
_Vita_WriteVertices4xColor(_curDrawCall, x, y, wDst, hDst, 1.f, 1.f, 1.f, 1.f, rgba0, rgba0, rgba0, rgba0);
471+
_Vita_WriteVertices4xColor(_curDrawCall, x, y, wDst, hDst, 1.f, 1.f, 1.f, 1.f, rgba0, rgba0, rgba0, rgba0, true);
451472

452473
_Vita_DoneWithDrawCall();
453474

@@ -840,6 +861,9 @@ int initGLAdv()
840861
memset(_curBufferA, 0, _vgl_pending_total_size);
841862
memset(_curBufferB, 0, _vgl_pending_total_size);
842863

864+
// 1 to indicate filled by default
865+
memset(_curBufferFillState, 1, MAX_VERTICES);
866+
843867
_vgl_pending_calls = _curBufferA;
844868
_vgl_current_write_buffer = _curBufferB;
845869

@@ -1103,7 +1127,7 @@ void Vita_Repaint()
11031127
// This is a "hack around".
11041128
// Ideally, I'd be able to batch this all at once.
11051129
GLuint i;
1106-
GLuint _curBoundTex = -1;
1130+
GLuint _curBoundTex = 0;
11071131
GLuint _curReqTex = 0;
11081132
int totalTextureSwaps = 0;
11091133
DrawCall _curDrawCall;
@@ -1182,7 +1206,7 @@ void Vita_Repaint()
11821206
}
11831207

11841208
// draw
1185-
glDrawArrays(GL_TRIANGLE_STRIP, i * VERTICES_PER_PRIM, VERTICES_PER_PRIM);
1209+
glDrawArrays( _curBufferFillState[i] == 1 ? GL_TRIANGLE_STRIP : GL_LINE_LOOP, i * VERTICES_PER_PRIM, VERTICES_PER_PRIM);
11861210
}
11871211
#if DEBUG_BUILD
11881212
if(last_frame_time_s != 0)

src/vita/vgl_renderer.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ void Vita_DrawRectColor(float x, float y,
193193
float _r,
194194
float _g,
195195
float _b,
196-
float _a
197-
);
196+
float _a,
197+
char filled);
198198

199199
/**
200200
* Vita_DrawRect4xColor():
@@ -206,7 +206,8 @@ void Vita_DrawRect4xColor(float x, float y,
206206
float rgba0[4],
207207
float rgba1[4],
208208
float rgba2[4],
209-
float rgba3[4]
209+
float rgba3[4],
210+
char filled
210211
);
211212

212213
/**

0 commit comments

Comments
 (0)