make ellipses work (thanks krizej!!!)
This commit is contained in:
parent
78cca6becd
commit
88aed48fa7
5 changed files with 28 additions and 10 deletions
|
@ -5,13 +5,15 @@ int PTK_COMPONENT_TYPE_ELLIPSE = 3;
|
|||
layout(location = 0) in vec2 position;
|
||||
layout(location = 1) in vec3 fragColor;
|
||||
layout(location = 2) flat in int shapeType;
|
||||
layout(location = 3) flat in vec2 radii;
|
||||
layout(location = 3) in vec2 uv;
|
||||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
void main() {
|
||||
if (shapeType == PTK_COMPONENT_TYPE_ELLIPSE && length(position) <= 0.5) {
|
||||
discard;
|
||||
if (shapeType == PTK_COMPONENT_TYPE_ELLIPSE) {
|
||||
if (length(uv - vec2(0.5)) > 0.5) {
|
||||
discard;
|
||||
}
|
||||
}
|
||||
outColor = vec4(fragColor, 1.0);
|
||||
}
|
||||
|
|
|
@ -8,17 +8,19 @@ layout(binding = 0) uniform UniformBufferObject {
|
|||
layout(location = 0) in vec2 inPosition;
|
||||
layout(location = 1) in vec3 inColor;
|
||||
layout(location = 2) in int inShapeType;
|
||||
layout(location = 3) in vec2 inRadii;
|
||||
layout(location = 3) in vec2 inUv;
|
||||
|
||||
layout(location = 0) out vec2 outPosition;
|
||||
layout(location = 1) out vec3 fragColor;
|
||||
layout(location = 2) out int outShapeType;
|
||||
layout(location = 3) out vec2 outRadii;
|
||||
layout(location = 3) out vec2 outUv;
|
||||
|
||||
void main() {
|
||||
vec2 normalized = ((inPosition / ubo.initialWindowSize) - 0.5) * 2.0;
|
||||
gl_Position = vec4(normalized, 0.0, 1.0);
|
||||
|
||||
fragColor = inColor;
|
||||
outPosition = normalized;
|
||||
outShapeType = inShapeType;
|
||||
outUv = inUv;
|
||||
}
|
||||
|
|
|
@ -10,18 +10,26 @@ PTK_VEC(PtkHandle) m_components;
|
|||
|
||||
PTK_VEC(Vertex) g_vertices;
|
||||
|
||||
static const vec2 uvs[] = {
|
||||
{0, 0},
|
||||
{0, 1},
|
||||
{1, 0},
|
||||
{1, 1},
|
||||
};
|
||||
|
||||
void vk_components_init(void) {
|
||||
m_components = PTK_VEC_NEW(PtkHandle, 1);
|
||||
|
||||
g_vertices = PTK_VEC_NEW(Vertex, 1);
|
||||
}
|
||||
|
||||
void _vk_triangle(PtkTriangle *triangle, PtkComponentType type) {
|
||||
void _vk_triangle(PtkTriangle *triangle, PtkComponentType type, size_t uvs_offset) {
|
||||
for (size_t i = 0; i < 3; ++i) {
|
||||
Vertex v;
|
||||
memcpy(v.pos, triangle->vertices[i], sizeof(vec2));
|
||||
memcpy(v.color, triangle->color, sizeof(vec3));
|
||||
v.shape_type = type;
|
||||
memcpy(v.uv, uvs[i + uvs_offset], sizeof(vec2));
|
||||
|
||||
PTK_VEC_ADD(Vertex, g_vertices, v);
|
||||
}
|
||||
|
@ -30,7 +38,7 @@ void _vk_triangle(PtkTriangle *triangle, PtkComponentType type) {
|
|||
void vk_triangle(PtkTriangle *triangle) {
|
||||
PTK_VEC_ADD(PtkHandle, m_components, triangle);
|
||||
|
||||
_vk_triangle(triangle, PTK_COMPONENT_TYPE_TRIANGLE);
|
||||
_vk_triangle(triangle, PTK_COMPONENT_TYPE_TRIANGLE, 0);
|
||||
vk_transfer_vertex_data();
|
||||
}
|
||||
|
||||
|
@ -44,7 +52,7 @@ void _vk_rect(PtkRect *rect, PtkComponentType type) {
|
|||
memcpy(t1_positions[2], &(vec2){ rect->top_left[0], rect->top_left[1] + rect->size[1] }, sizeof(vec2));
|
||||
PtkTriangle *t1 = (PtkTriangle *)ptk_triangle((vec2 *)t1_positions, rect->color);
|
||||
|
||||
_vk_triangle(t1, type);
|
||||
_vk_triangle(t1, type, 0);
|
||||
|
||||
vec2 t2_positions[3];
|
||||
// bottom left
|
||||
|
@ -55,7 +63,7 @@ void _vk_rect(PtkRect *rect, PtkComponentType type) {
|
|||
memcpy(t2_positions[2], &(vec2){ rect->top_left[0] + rect->size[0], rect->top_left[1] + rect->size[1] }, sizeof(vec2));
|
||||
PtkTriangle *t2 = (PtkTriangle *)ptk_triangle((vec2 *)t2_positions, rect->color);
|
||||
|
||||
_vk_triangle(t2, type);
|
||||
_vk_triangle(t2, type, 1);
|
||||
vk_transfer_vertex_data();
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ typedef struct {
|
|||
vec2 pos;
|
||||
vec3 color;
|
||||
PtkComponentType shape_type;
|
||||
vec2 radii;
|
||||
vec2 uv;
|
||||
} Vertex;
|
||||
|
||||
PTK_VEC_DEFINE(Vertex);
|
||||
|
|
|
@ -105,6 +105,12 @@ PTK_VEC(VkVertexInputAttributeDescription) m_vertex_attribute_descriptions = PTK
|
|||
.format = VK_FORMAT_R32_SINT,
|
||||
.offset = offsetof(Vertex, shape_type),
|
||||
},
|
||||
(VkVertexInputAttributeDescription){
|
||||
.location = 3,
|
||||
.binding = 0,
|
||||
.format = VK_FORMAT_R32G32_SINT,
|
||||
.offset = offsetof(Vertex, uv),
|
||||
},
|
||||
});
|
||||
|
||||
static VkBuffer m_vertex_buffer;
|
||||
|
|
Loading…
Reference in a new issue