ref: a5c09b67f75bfd2ce127bccc59ceedc8e9708db1
parent: f6fe0537ed424851bc86836b0f27279cd939259a
author: Clownacy <Clownacy@users.noreply.github.com>
date: Mon Jun 29 18:13:03 EDT 2020
Wii U renderer cleanup
--- a/src/Backends/Rendering/WiiU.cpp
+++ b/src/Backends/Rendering/WiiU.cpp
@@ -102,14 +102,16 @@
static RenderBackend_Surface *last_source_surface;
static RenderBackend_Surface *last_destination_surface;
-static VertexBufferSlot* GetVertexBufferSlot(unsigned int slots_needed)
+static VertexBufferSlot* GetVertexBufferSlot(void)
{
+ ++current_vertex_buffer_slot;
+
// Check if buffer needs expanding
- if (current_vertex_buffer_slot + slots_needed > local_vertex_buffer_size)
+ if (current_vertex_buffer_slot > local_vertex_buffer_size)
{
local_vertex_buffer_size = 1;
- while (current_vertex_buffer_slot + slots_needed > local_vertex_buffer_size)
+ while (current_vertex_buffer_slot > local_vertex_buffer_size)
local_vertex_buffer_size <<= 1;
VertexBufferSlot *realloc_result = (VertexBufferSlot*)realloc(local_vertex_buffer, local_vertex_buffer_size * sizeof(VertexBufferSlot));
@@ -125,9 +127,7 @@
}
}
- current_vertex_buffer_slot += slots_needed;
-
- return &local_vertex_buffer[current_vertex_buffer_slot - slots_needed];
+ return &local_vertex_buffer[current_vertex_buffer_slot - 1];
}
static void FlushVertexBuffer(void)
@@ -357,27 +357,27 @@
// Make sure the buffers aren't currently being used before we modify them
GX2DrawDone();
- Vertex *vertex_pointer = (Vertex*)GX2RLockBufferEx(&vertex_buffer, (GX2RResourceFlags)0);
+ VertexBufferSlot *vertex_buffer_slot = (VertexBufferSlot*)GX2RLockBufferEx(&vertex_buffer, (GX2RResourceFlags)0);
// Set buffer to (4:3) full-screen
- vertex_pointer[0].position.x = -1.0f;
- vertex_pointer[0].position.y = -1.0f;
- vertex_pointer[1].position.x = 1.0f;
- vertex_pointer[1].position.y = -1.0f;
- vertex_pointer[2].position.x = 1.0f;
- vertex_pointer[2].position.y = 1.0f;
- vertex_pointer[3].position.x = -1.0f;
- vertex_pointer[3].position.y = 1.0f;
+ vertex_buffer_slot->vertices[0].position.x = -1.0f;
+ vertex_buffer_slot->vertices[0].position.y = -1.0f;
+ vertex_buffer_slot->vertices[1].position.x = 1.0f;
+ vertex_buffer_slot->vertices[1].position.y = -1.0f;
+ vertex_buffer_slot->vertices[2].position.x = 1.0f;
+ vertex_buffer_slot->vertices[2].position.y = 1.0f;
+ vertex_buffer_slot->vertices[3].position.x = -1.0f;
+ vertex_buffer_slot->vertices[3].position.y = 1.0f;
// Set buffer to full-texture
- vertex_pointer[0].texture.x = 0.0f;
- vertex_pointer[0].texture.y = 1.0f;
- vertex_pointer[1].texture.x = 1.0f;
- vertex_pointer[1].texture.y = 1.0f;
- vertex_pointer[2].texture.x = 1.0f;
- vertex_pointer[2].texture.y = 0.0f;
- vertex_pointer[3].texture.x = 0.0f;
- vertex_pointer[3].texture.y = 0.0f;
+ vertex_buffer_slot->vertices[0].texture.x = 0.0f;
+ vertex_buffer_slot->vertices[0].texture.y = 1.0f;
+ vertex_buffer_slot->vertices[1].texture.x = 1.0f;
+ vertex_buffer_slot->vertices[1].texture.y = 1.0f;
+ vertex_buffer_slot->vertices[2].texture.x = 1.0f;
+ vertex_buffer_slot->vertices[2].texture.y = 0.0f;
+ vertex_buffer_slot->vertices[3].texture.x = 0.0f;
+ vertex_buffer_slot->vertices[3].texture.y = 0.0f;
GX2RUnlockBufferEx(&vertex_buffer, (GX2RResourceFlags)0);
@@ -620,7 +620,7 @@
GX2RSetAttributeBuffer(&vertex_buffer, 1, sizeof(Vertex), offsetof(Vertex, texture));
}
- VertexBufferSlot *vertex_buffer_slot = GetVertexBufferSlot(1);
+ VertexBufferSlot *vertex_buffer_slot = GetVertexBufferSlot();
if (vertex_buffer_slot != NULL)
{
@@ -701,7 +701,7 @@
GX2RSetAttributeBuffer(&vertex_buffer, 0, sizeof(Vertex), offsetof(Vertex, position));
}
- VertexBufferSlot *vertex_buffer_slot = GetVertexBufferSlot(1);
+ VertexBufferSlot *vertex_buffer_slot = GetVertexBufferSlot();
if (vertex_buffer_slot != NULL)
{
@@ -823,7 +823,7 @@
// Make sure the buffers aren't currently being used before we modify them
GX2DrawDone();
- Vertex *vertex_pointer = (Vertex*)GX2RLockBufferEx(&vertex_buffer, (GX2RResourceFlags)0);
+ VertexBufferSlot *vertex_buffer_slot = (VertexBufferSlot*)GX2RLockBufferEx(&vertex_buffer, (GX2RResourceFlags)0);
// Set vertex position buffer
const float destination_left = x;
@@ -831,35 +831,35 @@
const float destination_right = x + glyph->width;
const float destination_bottom = y + glyph->height;
- vertex_pointer[0].position.x = destination_left;
- vertex_pointer[0].position.y = destination_top;
- vertex_pointer[1].position.x = destination_right;
- vertex_pointer[1].position.y = destination_top;
- vertex_pointer[2].position.x = destination_right;
- vertex_pointer[2].position.y = destination_bottom;
- vertex_pointer[3].position.x = destination_left;
- vertex_pointer[3].position.y = destination_bottom;
+ vertex_buffer_slot->vertices[0].position.x = destination_left;
+ vertex_buffer_slot->vertices[0].position.y = destination_top;
+ vertex_buffer_slot->vertices[1].position.x = destination_right;
+ vertex_buffer_slot->vertices[1].position.y = destination_top;
+ vertex_buffer_slot->vertices[2].position.x = destination_right;
+ vertex_buffer_slot->vertices[2].position.y = destination_bottom;
+ vertex_buffer_slot->vertices[3].position.x = destination_left;
+ vertex_buffer_slot->vertices[3].position.y = destination_bottom;
for (unsigned int i = 0; i < 4; ++i)
{
- vertex_pointer[i].position.x /= glyph_destination_surface->width;
- vertex_pointer[i].position.x *= 2.0f;
- vertex_pointer[i].position.x -= 1.0f;
+ vertex_buffer_slot->vertices[i].position.x /= glyph_destination_surface->width;
+ vertex_buffer_slot->vertices[i].position.x *= 2.0f;
+ vertex_buffer_slot->vertices[i].position.x -= 1.0f;
- vertex_pointer[i].position.y /= glyph_destination_surface->height;
- vertex_pointer[i].position.y *= -2.0f;
- vertex_pointer[i].position.y += 1.0f;
+ vertex_buffer_slot->vertices[i].position.y /= glyph_destination_surface->height;
+ vertex_buffer_slot->vertices[i].position.y *= -2.0f;
+ vertex_buffer_slot->vertices[i].position.y += 1.0f;
}
// Set texture coordinate buffer
- vertex_pointer[0].texture.x = 0.0f;
- vertex_pointer[0].texture.y = 0.0f;
- vertex_pointer[1].texture.x = 1.0f;
- vertex_pointer[1].texture.y = 0.0f;
- vertex_pointer[2].texture.x = 1.0f;
- vertex_pointer[2].texture.y = 1.0f;
- vertex_pointer[3].texture.x = 0.0f;
- vertex_pointer[3].texture.y = 1.0f;
+ vertex_buffer_slot->vertices[0].texture.x = 0.0f;
+ vertex_buffer_slot->vertices[0].texture.y = 0.0f;
+ vertex_buffer_slot->vertices[1].texture.x = 1.0f;
+ vertex_buffer_slot->vertices[1].texture.y = 0.0f;
+ vertex_buffer_slot->vertices[2].texture.x = 1.0f;
+ vertex_buffer_slot->vertices[2].texture.y = 1.0f;
+ vertex_buffer_slot->vertices[3].texture.x = 0.0f;
+ vertex_buffer_slot->vertices[3].texture.y = 1.0f;
GX2RUnlockBufferEx(&vertex_buffer, (GX2RResourceFlags)0);