Fix cinematic bars not rendering properly on consoles

This commit is contained in:
UnknownShadow200 2025-10-04 08:09:31 +10:00
parent 4bf2e4ed83
commit 68d6711d84
3 changed files with 50 additions and 16 deletions

View File

@ -486,6 +486,13 @@ void Gfx_Draw2DTexture(const struct Texture* tex, PackedCol color);
/* Fills out the vertices for rendering a 2D coloured texture */
void Gfx_Make2DQuad(const struct Texture* tex, PackedCol color, struct VertexTextured** vertices);
/* Builds 4 vertices for a 2D flat coloured rectangle */
struct VertexColoured* Gfx_Build2DFlat(int x, int y, int width, int height,
PackedCol color, struct VertexColoured* v);
/* Builds 4 vertices for a 2D flat vertical gradient rectangle */
struct VertexColoured* Gfx_Build2DGradient(int x, int y, int width, int height,
PackedCol top, PackedCol bottom, struct VertexColoured* v);
/* Switches state to be suitable for drawing 2D graphics */
/* NOTE: This means turning off fog/depth test, changing matrices, etc.*/
void Gfx_Begin2D(int width, int height);

View File

@ -25,6 +25,7 @@ static cc_uint8 priorities[GUI_MAX_SCREENS];
#ifdef CC_BUILD_DUALSCREEN
static struct Texture touchBgTex;
#endif
static GfxResourceID bars_VB;
/*########################################################################################################################*
*----------------------------------------------------------Gui------------------------------------------------------------*
@ -316,24 +317,39 @@ void Gui_ShowPauseMenu(void) {
#endif
}
void Gui_ShowCinematicBars() {
int screenWidth = Window_Main.Width;
#define BARS_VB_COUNT 4 * 2
static void ShowCinematicBars() {
struct VertexColoured* v;
int screenWidth = Window_Main.Width;
int screenHeight = Window_Main.Height;
PackedCol color;
int count;
// Ensure bar size is clamped between 0 and 1
if (Gui.BarSize < 0.0f) Gui.BarSize = 0.0f;
if (Gui.BarSize > 1.0f) Gui.BarSize = 1.0f;
if (!bars_VB) bars_VB = Gfx_CreateDynamicVb(VERTEX_FORMAT_COLOURED, BARS_VB_COUNT);
if (!bars_VB) return;
count = Gui.BarSize == 1.0f ? 4 : BARS_VB_COUNT;
color = Gui.CinematicBarColor;
v = (struct VertexColoured*)Gfx_LockDynamicVb(bars_VB, VERTEX_FORMAT_COLOURED, count);
// If bar size is 1, just draw 1 rectangle instead of 2
if (Gui.BarSize == 1.0f) {
Gfx_Draw2DGradient(0, 0, screenWidth, screenHeight, Gui.CinematicBarColor, Gui.CinematicBarColor);
v = Gfx_Build2DGradient(0, 0, screenWidth, screenHeight, color, color, v);
} else {
// Calculate the height of each bar based on the bar size
int barHeight = (int)(screenHeight * Gui.BarSize / 2.0f);
Gfx_Draw2DGradient(0, 0, screenWidth, barHeight, Gui.CinematicBarColor, Gui.CinematicBarColor);
Gfx_Draw2DGradient(0, screenHeight - barHeight, screenWidth, barHeight, Gui.CinematicBarColor, Gui.CinematicBarColor);
v = Gfx_Build2DGradient(0, 0, screenWidth, barHeight, color, color, v);
v = Gfx_Build2DGradient(0, screenHeight - barHeight, screenWidth, barHeight, color, color, v);
}
Gfx_UnlockDynamicVb(bars_VB);
Gfx_SetVertexFormat(VERTEX_FORMAT_COLOURED);
Gfx_DrawVb_IndexedTris(count);
}
void Gui_RenderGui(float delta) {
@ -345,7 +361,7 @@ void Gui_RenderGui(float delta) {
Texture_Render(&touchBgTex);
#endif
if (Gui.BarSize > 0) Gui_ShowCinematicBars();
if (Gui.BarSize > 0) ShowCinematicBars();
/* Draw back to front so highest priority screen is on top */
for (i = Gui.ScreensCount - 1; i >= 0; i--)
@ -700,6 +716,7 @@ static void OnTextChanged(void* obj, const cc_string* str) {
static void OnContextLost(void* obj) {
LoseAllScreens();
Gfx_DeleteDynamicVb(&bars_VB);
if (Gfx.ManagedTextures) return;
Gfx_DeleteTexture(&Gui.GuiTex);

View File

@ -180,11 +180,7 @@ void Gfx_Draw2DFlat(int x, int y, int width, int height, PackedCol color) {
Gfx_SetVertexFormat(VERTEX_FORMAT_COLOURED);
v = (struct VertexColoured*)Gfx_LockDynamicVb(Gfx_quadVb, VERTEX_FORMAT_COLOURED, 4);
v->x = (float)x; v->y = (float)y; v->z = 0; v->Col = color; v++;
v->x = (float)(x + width); v->y = (float)y; v->z = 0; v->Col = color; v++;
v->x = (float)(x + width); v->y = (float)(y + height); v->z = 0; v->Col = color; v++;
v->x = (float)x; v->y = (float)(y + height); v->z = 0; v->Col = color; v++;
v = Gfx_Build2DFlat(x, y, width, height, color, v);
Gfx_UnlockDynamicVb(Gfx_quadVb);
Gfx_DrawVb_IndexedTris(4);
@ -195,11 +191,7 @@ void Gfx_Draw2DGradient(int x, int y, int width, int height, PackedCol top, Pack
Gfx_SetVertexFormat(VERTEX_FORMAT_COLOURED);
v = (struct VertexColoured*)Gfx_LockDynamicVb(Gfx_quadVb, VERTEX_FORMAT_COLOURED, 4);
v->x = (float)x; v->y = (float)y; v->z = 0; v->Col = top; v++;
v->x = (float)(x + width); v->y = (float)y; v->z = 0; v->Col = top; v++;
v->x = (float)(x + width); v->y = (float)(y + height); v->z = 0; v->Col = bottom; v++;
v->x = (float)x; v->y = (float)(y + height); v->z = 0; v->Col = bottom; v++;
v = Gfx_Build2DGradient(x, y, width, height, top, bottom, v);
Gfx_UnlockDynamicVb(Gfx_quadVb);
Gfx_DrawVb_IndexedTris(4);
@ -218,6 +210,24 @@ void Gfx_Draw2DTexture(const struct Texture* tex, PackedCol color) {
}
#endif
struct VertexColoured* Gfx_Build2DFlat(int x, int y, int width, int height,
PackedCol color, struct VertexColoured* v) {
v->x = (float)x; v->y = (float)y; v->z = 0; v->Col = color; v++;
v->x = (float)(x + width); v->y = (float)y; v->z = 0; v->Col = color; v++;
v->x = (float)(x + width); v->y = (float)(y + height); v->z = 0; v->Col = color; v++;
v->x = (float)x; v->y = (float)(y + height); v->z = 0; v->Col = color; v++;
return v;
}
struct VertexColoured* Gfx_Build2DGradient(int x, int y, int width, int height,
PackedCol top, PackedCol bottom, struct VertexColoured* v) {
v->x = (float)x; v->y = (float)y; v->z = 0; v->Col = top; v++;
v->x = (float)(x + width); v->y = (float)y; v->z = 0; v->Col = top; v++;
v->x = (float)(x + width); v->y = (float)(y + height); v->z = 0; v->Col = bottom; v++;
v->x = (float)x; v->y = (float)(y + height); v->z = 0; v->Col = bottom; v++;
return v;
}
void Gfx_Make2DQuad(const struct Texture* tex, PackedCol color, struct VertexTextured** vertices) {
float x1 = (float)tex->x, x2 = (float)(tex->x + tex->width);
float y1 = (float)tex->y, y2 = (float)(tex->y + tex->height);