Turn vulkan_write_quad_vbo into macro

This commit is contained in:
twinaphex 2020-08-27 02:29:32 +02:00
parent 9672d9b12f
commit b4d26aca9c
3 changed files with 76 additions and 71 deletions

View File

@ -1124,10 +1124,12 @@ void vulkan_draw_quad(vk_t *vk, const struct vk_draw_quad *quad)
6 * sizeof(struct vk_vertex), &range)) 6 * sizeof(struct vk_vertex), &range))
return; return;
vulkan_write_quad_vbo((struct vk_vertex*)range.data, {
0.0f, 0.0f, 1.0f, 1.0f, struct vk_vertex *pv = (struct vk_vertex*)range.data;
0.0f, 0.0f, 1.0f, 1.0f, const struct vk_color *color = &quad->color;
&quad->color);
VULKAN_WRITE_QUAD_VBO(pv, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, color);
}
vkCmdBindVertexBuffers(vk->cmd, 0, 1, vkCmdBindVertexBuffers(vk->cmd, 0, 1,
&range.buffer, &range.offset); &range.buffer, &range.offset);

View File

@ -582,63 +582,60 @@ static INLINE unsigned vulkan_format_to_bpp(VkFormat format)
} }
} }
static INLINE void vulkan_write_quad_vbo(struct vk_vertex *pv, #define VULKAN_WRITE_QUAD_VBO(pv, _x, _y, _width, _height, _tex_x, _tex_y, _tex_width, _tex_height, color) \
float x, float y, float width, float height, { \
float tex_x, float tex_y, float tex_width, float tex_height, float r = color->r; \
const struct vk_color *color) float g = color->g; \
{ float b = color->b; \
float r = color->r; float a = color->a; \
float g = color->g; pv[0].x = (_x) + 0.0f * (_width); \
float b = color->b; pv[0].y = (_y) + 0.0f * (_height); \
float a = color->a; pv[0].tex_x = (_tex_x) + 0.0f * (_tex_width); \
pv[0].x = x + 0.0f * width; pv[0].tex_y = (_tex_y) + 0.0f * (_tex_height); \
pv[0].y = y + 0.0f * height; pv[0].color.r = r; \
pv[0].tex_x = tex_x + 0.0f * tex_width; pv[0].color.g = g; \
pv[0].tex_y = tex_y + 0.0f * tex_height; pv[0].color.b = b; \
pv[0].color.r = r; pv[0].color.a = a; \
pv[0].color.g = g; pv[1].x = (_x) + 0.0f * (_width); \
pv[0].color.b = b; pv[1].y = (_y) + 1.0f * (_height); \
pv[0].color.a = a; pv[1].tex_x = (_tex_x) + 0.0f * (_tex_width); \
pv[1].x = x + 0.0f * width; pv[1].tex_y = (_tex_y) + 1.0f * (_tex_height); \
pv[1].y = y + 1.0f * height; pv[1].color.r = r; \
pv[1].tex_x = tex_x + 0.0f * tex_width; pv[1].color.g = g; \
pv[1].tex_y = tex_y + 1.0f * tex_height; pv[1].color.b = b; \
pv[1].color.r = r; pv[1].color.a = a; \
pv[1].color.g = g; pv[2].x = (_x) + 1.0f * (_width); \
pv[1].color.b = b; pv[2].y = (_y) + 0.0f * (_height); \
pv[1].color.a = a; pv[2].tex_x = (_tex_x) + 1.0f * (_tex_width); \
pv[2].x = x + 1.0f * width; pv[2].tex_y = (_tex_y) + 0.0f * (_tex_height); \
pv[2].y = y + 0.0f * height; pv[2].color.r = r; \
pv[2].tex_x = tex_x + 1.0f * tex_width; pv[2].color.g = g; \
pv[2].tex_y = tex_y + 0.0f * tex_height; pv[2].color.b = b; \
pv[2].color.r = r; pv[2].color.a = a; \
pv[2].color.g = g; pv[3].x = (_x) + 1.0f * (_width); \
pv[2].color.b = b; pv[3].y = (_y) + 1.0f * (_height); \
pv[2].color.a = a; pv[3].tex_x = (_tex_x) + 1.0f * (_tex_width); \
pv[3].x = x + 1.0f * width; pv[3].tex_y = (_tex_y) + 1.0f * (_tex_height); \
pv[3].y = y + 1.0f * height; pv[3].color.r = r; \
pv[3].tex_x = tex_x + 1.0f * tex_width; pv[3].color.g = g; \
pv[3].tex_y = tex_y + 1.0f * tex_height; pv[3].color.b = b; \
pv[3].color.r = r; pv[3].color.a = a; \
pv[3].color.g = g; pv[4].x = (_x) + 1.0f * (_width); \
pv[3].color.b = b; pv[4].y = (_y) + 0.0f * (_height); \
pv[3].color.a = a; pv[4].tex_x = (_tex_x) + 1.0f * (_tex_width); \
pv[4].x = x + 1.0f * width; pv[4].tex_y = (_tex_y) + 0.0f * (_tex_height); \
pv[4].y = y + 0.0f * height; pv[4].color.r = r; \
pv[4].tex_x = tex_x + 1.0f * tex_width; pv[4].color.g = g; \
pv[4].tex_y = tex_y + 0.0f * tex_height; pv[4].color.b = b; \
pv[4].color.r = r; pv[4].color.a = a; \
pv[4].color.g = g; pv[5].x = (_x) + 0.0f * (_width); \
pv[4].color.b = b; pv[5].y = (_y) + 1.0f * (_height); \
pv[4].color.a = a; pv[5].tex_x = (_tex_x) + 0.0f * (_tex_width); \
pv[5].x = x + 0.0f * width; pv[5].tex_y = (_tex_y) + 1.0f * (_tex_height); \
pv[5].y = y + 1.0f * height; pv[5].color.r = r; \
pv[5].tex_x = tex_x + 0.0f * tex_width; pv[5].color.g = g; \
pv[5].tex_y = tex_y + 1.0f * tex_height; pv[5].color.b = b; \
pv[5].color.r = r; pv[5].color.a = a; \
pv[5].color.g = g;
pv[5].color.b = b;
pv[5].color.a = a;
} }
struct vk_buffer vulkan_create_buffer( struct vk_buffer vulkan_create_buffer(

View File

@ -210,16 +210,22 @@ static void vulkan_raster_font_render_line(
width = glyph->width; width = glyph->width;
height = glyph->height; height = glyph->height;
vulkan_write_quad_vbo(font->pv + font->vertices, {
(x + (off_x + delta_x) * scale) * inv_win_width, struct vk_vertex *pv = font->pv + font->vertices;
(y + (off_y + delta_y) * scale) * inv_win_height, float _x = (x + (off_x + delta_x) * scale)
width * scale * inv_win_width, * inv_win_width;
height * scale * inv_win_height, float _y = (y + (off_y + delta_y) * scale)
tex_x * inv_tex_size_x, * inv_win_height;
tex_y * inv_tex_size_y, float _width = width * scale * inv_win_width;
width * inv_tex_size_x, float _height = height * scale * inv_win_height;
height * inv_tex_size_y, float _tex_x = tex_x * inv_tex_size_x;
&vk_color); float _tex_y = tex_y * inv_tex_size_y;
float _tex_width = width * inv_tex_size_x;
float _tex_height = height * inv_tex_size_y;
const struct vk_color *color = &vk_color;
VULKAN_WRITE_QUAD_VBO(pv, _x, _y, _width, _height, _tex_x, _tex_y, _tex_width, _tex_height, color);
}
font->vertices += 6; font->vertices += 6;