Add support for rect gradients
This commit is contained in:
parent
73d8628c88
commit
e742e595a4
@ -19,11 +19,16 @@ STRUCT(RenderRect)
|
||||
u32 y1;
|
||||
};
|
||||
|
||||
STRUCT(RectColors)
|
||||
{
|
||||
F32Vec4 v[4];
|
||||
};
|
||||
|
||||
STRUCT(RectDraw)
|
||||
{
|
||||
RenderRect vertex;
|
||||
RenderRect texture;
|
||||
Color color;
|
||||
RectColors colors;
|
||||
u32 texture_index;
|
||||
};
|
||||
|
||||
@ -33,7 +38,7 @@ STRUCT(RectVertex)
|
||||
f32 y;
|
||||
f32 uv_x;
|
||||
f32 uv_y;
|
||||
F32Vec4 color;
|
||||
RectColors colors;
|
||||
u32 texture_index;
|
||||
u32 reserved[3];
|
||||
};
|
||||
|
@ -11,7 +11,7 @@ struct Vertex {
|
||||
float y;
|
||||
float uv_x;
|
||||
float uv_y;
|
||||
vec4 color;
|
||||
vec4 colors[4];
|
||||
uint texture_index;
|
||||
uint r[3];
|
||||
};
|
||||
@ -37,8 +37,8 @@ void main()
|
||||
//output data
|
||||
gl_Position = vec4(2 * v.x / width - 1, 2 * v.y / height - 1, 0, 1);
|
||||
out_uv = vec2(v.uv_x, v.uv_y);
|
||||
out_color = v.color;
|
||||
out_color = v.colors[gl_VertexIndex % 4];
|
||||
out_texture_index = v.texture_index;
|
||||
//debugPrintfEXT("Position: (%f, %f)\n", v.x, v.y);
|
||||
//debugPrintfEXT("Vertex index: (%u)\n", gl_VertexIndex);
|
||||
//debugPrintfEXT("UV: (%f, %f)\n", v.uv_x, v.uv_y);
|
||||
}
|
||||
|
@ -2207,7 +2207,7 @@ void window_render_rect(RenderWindow* window, RectDraw draw)
|
||||
.y = draw.vertex.y0,
|
||||
.uv_x = draw.texture.x0,
|
||||
.uv_y = draw.texture.y0,
|
||||
.color = draw.color,
|
||||
.colors = draw.colors,
|
||||
.texture_index = draw.texture_index,
|
||||
},
|
||||
(RectVertex) {
|
||||
@ -2215,7 +2215,7 @@ void window_render_rect(RenderWindow* window, RectDraw draw)
|
||||
.y = draw.vertex.y0,
|
||||
.uv_x = draw.texture.x1,
|
||||
.uv_y = draw.texture.y0,
|
||||
.color = draw.color,
|
||||
.colors = draw.colors,
|
||||
.texture_index = draw.texture_index,
|
||||
},
|
||||
(RectVertex) {
|
||||
@ -2223,7 +2223,7 @@ void window_render_rect(RenderWindow* window, RectDraw draw)
|
||||
.y = draw.vertex.y1,
|
||||
.uv_x = draw.texture.x0,
|
||||
.uv_y = draw.texture.y1,
|
||||
.color = draw.color,
|
||||
.colors = draw.colors,
|
||||
.texture_index = draw.texture_index,
|
||||
},
|
||||
(RectVertex) {
|
||||
@ -2231,7 +2231,7 @@ void window_render_rect(RenderWindow* window, RectDraw draw)
|
||||
.y = draw.vertex.y1,
|
||||
.uv_x = draw.texture.x1,
|
||||
.uv_y = draw.texture.y1,
|
||||
.color = draw.color,
|
||||
.colors = draw.colors,
|
||||
.texture_index = draw.texture_index,
|
||||
},
|
||||
};
|
||||
@ -2256,6 +2256,11 @@ void window_render_text(Renderer* renderer, RenderWindow* window, String string,
|
||||
auto height = texture_atlas->ascent - texture_atlas->descent;
|
||||
auto texture_index = texture_atlas->texture.value;
|
||||
|
||||
// TODO: support gradient
|
||||
RectColors colors = {
|
||||
.v = { color, color, color, color }
|
||||
};
|
||||
|
||||
for (u64 i = 0; i < string.length; i += 1)
|
||||
{
|
||||
auto ch = string.pointer[i];
|
||||
@ -2273,7 +2278,7 @@ void window_render_text(Renderer* renderer, RenderWindow* window, String string,
|
||||
.y = pos_y,
|
||||
.uv_x = (f32)uv_x,
|
||||
.uv_y = (f32)uv_y,
|
||||
.color = color,
|
||||
.colors = colors,
|
||||
.texture_index = texture_index,
|
||||
},
|
||||
(RectVertex) {
|
||||
@ -2281,7 +2286,7 @@ void window_render_text(Renderer* renderer, RenderWindow* window, String string,
|
||||
.y = pos_y,
|
||||
.uv_x = (f32)(uv_x + uv_width),
|
||||
.uv_y = (f32)uv_y,
|
||||
.color = color,
|
||||
.colors = colors,
|
||||
.texture_index = texture_index,
|
||||
},
|
||||
(RectVertex) {
|
||||
@ -2289,7 +2294,7 @@ void window_render_text(Renderer* renderer, RenderWindow* window, String string,
|
||||
.y = pos_y + character->height,
|
||||
.uv_x = (f32)uv_x,
|
||||
.uv_y = (f32)(uv_y + uv_height),
|
||||
.color = color,
|
||||
.colors = colors,
|
||||
.texture_index = texture_index,
|
||||
},
|
||||
(RectVertex) {
|
||||
@ -2297,7 +2302,7 @@ void window_render_text(Renderer* renderer, RenderWindow* window, String string,
|
||||
.y = pos_y + character->height,
|
||||
.uv_x = (f32)(uv_x + uv_width),
|
||||
.uv_y = (f32)(uv_y + uv_height),
|
||||
.color = color,
|
||||
.colors = colors,
|
||||
.texture_index = texture_index,
|
||||
},
|
||||
};
|
||||
|
@ -734,7 +734,7 @@ void ui_draw()
|
||||
if (widget->flags.draw_background)
|
||||
{
|
||||
window_render_rect(window, (RectDraw) {
|
||||
.color = widget->background_color,
|
||||
.colors = (RectColors) { .v = { Color4(1, 1, 1, 1), Color4(1, 1, 1, 1), widget->background_color, widget->background_color } },
|
||||
.vertex = render_rect(widget->rect),
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user