#include "CommonVertexIndex.hpp" template static void AssignIndices(TNumber indices[6], TNumber startIdx) { // Triangle #1 indices[0] = startIdx + 1; // Top right indices[1] = startIdx + 0; // Top left indices[2] = startIdx + 3; // Bottom left // Triangle #2 indices[3] = startIdx + 1; // Top right indices[4] = startIdx + 3; // Bottom left indices[5] = startIdx + 2; // Bottom right } template static void AssignIndices(TNumber indices[6], TNumber topLeft, TNumber topRight, TNumber bottomRight, TNumber bottomLeft) { // Triangle #1 indices[0] = topRight; indices[1] = topLeft; indices[2] = bottomLeft; // Triangle #2 indices[3] = topRight; indices[4] = bottomLeft; indices[5] = bottomRight; } template static void AssignPositions(TVertex vertices[4], const Rect& rect) { // Top left vertices[0].x = rect.x0(); vertices[0].y = rect.y0(); // Top right vertices[1].x = rect.x1(); vertices[1].y = rect.y0(); // Bottom right vertices[2].x = rect.x1(); vertices[2].y = rect.y1(); // Bottom left vertices[3].x = rect.x0(); vertices[3].y = rect.y1(); } template static void AssignPositions(TVertex vertices[4], glm::vec2 bl, glm::vec2 tr) { // Top left vertices[0].x = bl.x; vertices[0].y = tr.y; // Top right vertices[1].x = tr.x; vertices[1].y = tr.y; // Bottom right vertices[2].x = tr.x; vertices[2].y = bl.y; // Bottom left vertices[3].x = bl.x; vertices[3].y = bl.y; } template static void AssignDepths(TVertex vertices[4], float z) { for (int i = 0; i < 4; ++i) { auto& vert = vertices[i]; vert.z = z; } } template static void AssignTexCoords(TVertex vertices[4], const Subregion& texcoords) { // Top left vertices[0].u = texcoords.u0; vertices[0].v = texcoords.v1; // Top right vertices[1].u = texcoords.u1; vertices[1].v = texcoords.v1; // Bottom right vertices[2].u = texcoords.u1; vertices[2].v = texcoords.v0; // Bottom left vertices[3].u = texcoords.u0; vertices[3].v = texcoords.v0; } template static void AssignColors(TVertex vertices[4], RgbaColor color) { for (int i = 0; i < 4; ++i) { auto& vert = vertices[i]; vert.r = color.r; vert.g = color.g; vert.b = color.b; vert.a = color.a; } } void Index_U16::Assign(uint16_t indices[6], uint16_t startIdx) { ::AssignIndices(indices, startIdx); } void Index_U16::Assign(uint16_t indices[6], uint16_t startIdx, uint16_t topLeft, uint16_t topRight, uint16_t bottomRight, uint16_t bottomLeft) { ::AssignIndices(indices, startIdx + topLeft, startIdx + topRight, startIdx + bottomRight, startIdx + bottomLeft); } void Index_U16::Assign(uint16_t indices[6], uint16_t topLeft, uint16_t topRight, uint16_t bottomRight, uint16_t bottomLeft) { ::AssignIndices(indices, topLeft, topRight, bottomRight, bottomLeft); } void Index_U32::Assign(uint32_t indices[6], uint32_t startIdx) { ::AssignIndices(indices, startIdx); } void Index_U32::Assign(uint32_t indices[6], uint32_t startIdx, uint32_t topLeft, uint32_t topRight, uint32_t bottomRight, uint32_t bottomLeft) { ::AssignIndices(indices, startIdx + topLeft, startIdx + topRight, startIdx + bottomRight, startIdx + bottomLeft); } void Index_U32::Assign(uint32_t indices[6], uint32_t topLeft, uint32_t topRight, uint32_t bottomRight, uint32_t bottomLeft) { ::AssignIndices(indices, topLeft, topRight, bottomRight, bottomLeft); } void Vertex_PC::Assign(Vertex_PC vertices[4], const Rect& rect) { ::AssignPositions(vertices, rect); } void Vertex_PC::Assign(Vertex_PC vertices[4], glm::vec2 bottomLeft, glm::vec2 topRight) { ::AssignPositions(vertices, bottomLeft, topRight); } void Vertex_PC::Assign(Vertex_PC vertices[4], float z) { ::AssignDepths(vertices, z); } void Vertex_PC::Assign(Vertex_PC vertices[4], RgbaColor color) { ::AssignColors(vertices, color); } void Vertex_PTC::Assign(Vertex_PTC vertices[4], const Rect& rect) { ::AssignPositions(vertices, rect); } void Vertex_PTC::Assign(Vertex_PTC vertices[4], glm::vec2 bottomLeft, glm::vec2 topRight) { ::AssignPositions(vertices, bottomLeft, topRight); } void Vertex_PTC::Assign(Vertex_PTC vertices[4], float z) { ::AssignDepths(vertices, z); } void Vertex_PTC::Assign(Vertex_PTC vertices[4], const Subregion& texcoords) { ::AssignTexCoords(vertices, texcoords); } void Vertex_PTC::Assign(Vertex_PTC vertices[4], RgbaColor color) { ::AssignColors(vertices, color); }