actually use the index buffer properly
This commit is contained in:
parent
35cf6c593d
commit
7c63947056
1 changed files with 50 additions and 23 deletions
|
@ -27,13 +27,13 @@ void vk_init_vertices(void) {
|
|||
g_indices = PTK_LIST_NEW(uint32_t, 0);
|
||||
}
|
||||
|
||||
void triangle(const PtkTriangle *triangle, const size_t uvs_offset) {
|
||||
void triangle(const PtkTriangle *triangle) {
|
||||
for (size_t i = 0; i < 3; ++i) {
|
||||
Vertex v = {
|
||||
.pos = triangle->vertices[i],
|
||||
.color = triangle->color,
|
||||
.shape_type = triangle->type,
|
||||
.uv = uvs[i + uvs_offset],
|
||||
.uv = uvs[i],
|
||||
};
|
||||
|
||||
uint32_t old_vertex_count = g_vertices.size;
|
||||
|
@ -48,29 +48,55 @@ void rect(const PtkRect *rect) {
|
|||
const float w = rect->size.w;
|
||||
const float h = rect->size.h;
|
||||
|
||||
PtkPos t1_positions[3];
|
||||
// top left
|
||||
t1_positions[0] = (PtkPos){ .x = x, .y = y };
|
||||
// top right
|
||||
t1_positions[1] = (PtkPos){ .x = x + w, .y = y };
|
||||
// bottom left
|
||||
t1_positions[2] = (PtkPos){ .x = x, .y = y + h };
|
||||
PtkTriangle *t1 = (PtkTriangle *)ptk_triangle((PtkPos *)t1_positions, rect->color);
|
||||
t1->type = rect->type;
|
||||
uint32_t top_right_index = g_vertices.size;
|
||||
uint32_t bottom_left_index = g_vertices.size + 1;
|
||||
|
||||
triangle(t1, 0);
|
||||
Vertex top_right = {
|
||||
.pos = (PtkPos){ .x = x + w, .y = y },
|
||||
.color = rect->color,
|
||||
.shape_type = rect->type,
|
||||
.uv = uvs[2],
|
||||
};
|
||||
|
||||
PtkPos t2_positions[3];
|
||||
// top right
|
||||
t2_positions[0] = (PtkPos){ .x = x + w, .y = y };
|
||||
// bottom left
|
||||
t2_positions[1] = (PtkPos){ .x = x, .y = y + h };
|
||||
// bottom right
|
||||
t2_positions[2] = (PtkPos){ .x = x + w, .y = y + h };
|
||||
PtkTriangle *t2 = (PtkTriangle *)ptk_triangle((PtkPos *)t2_positions, rect->color);
|
||||
t2->type = rect->type;
|
||||
Vertex bottom_left = {
|
||||
.pos = (PtkPos){ .x = x, .y = y + h },
|
||||
.color = rect->color,
|
||||
.shape_type = rect->type,
|
||||
.uv = uvs[1],
|
||||
};
|
||||
|
||||
triangle(t2, 1);
|
||||
PTK_LIST_ADD(Vertex, g_vertices, top_right);
|
||||
PTK_LIST_ADD(Vertex, g_vertices, bottom_left);
|
||||
|
||||
uint32_t top_left_index = g_vertices.size;
|
||||
|
||||
Vertex top_left = {
|
||||
.pos = (PtkPos){ .x = x, .y = y },
|
||||
.color = rect->color,
|
||||
.shape_type = rect->type,
|
||||
.uv = uvs[0],
|
||||
};
|
||||
|
||||
PTK_LIST_ADD(Vertex, g_vertices, top_left);
|
||||
|
||||
uint32_t bottom_right_index = g_vertices.size;
|
||||
|
||||
Vertex bottom_right = {
|
||||
.pos = (PtkPos){ .x = x + w, .y = y + h },
|
||||
.color = rect->color,
|
||||
.shape_type = rect->type,
|
||||
.uv = uvs[3],
|
||||
};
|
||||
|
||||
PTK_LIST_ADD(Vertex, g_vertices, bottom_right);
|
||||
|
||||
PTK_LIST_ADD(uint32_t, g_indices, top_left_index);
|
||||
PTK_LIST_ADD(uint32_t, g_indices, top_right_index);
|
||||
PTK_LIST_ADD(uint32_t, g_indices, bottom_left_index);
|
||||
|
||||
PTK_LIST_ADD(uint32_t, g_indices, top_right_index);
|
||||
PTK_LIST_ADD(uint32_t, g_indices, bottom_left_index);
|
||||
PTK_LIST_ADD(uint32_t, g_indices, bottom_right_index);
|
||||
}
|
||||
|
||||
void ellipse(const PtkEllipse *ellipse) {
|
||||
|
@ -95,7 +121,7 @@ void component(PtkHandle c) {
|
|||
|
||||
switch (c->type) {
|
||||
case PTK_COMPONENT_TYPE_TRIANGLE: {
|
||||
triangle((PtkTriangle *)c, 0);
|
||||
triangle((PtkTriangle *)c);
|
||||
} break;
|
||||
case PTK_COMPONENT_TYPE_RECT: {
|
||||
rect((PtkRect *)c);
|
||||
|
@ -119,6 +145,7 @@ void vk_init_components(PtkHandle root) {
|
|||
void vk_update_components(void) {
|
||||
PTK_LIST_CLEAR(m_components);
|
||||
PTK_LIST_CLEAR(g_vertices);
|
||||
PTK_LIST_CLEAR(g_indices);
|
||||
component(m_root_component);
|
||||
vk_transfer_vertex_data();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue