diff options
Diffstat (limited to 'ui.cpp')
-rw-r--r-- | ui.cpp | 36 |
1 files changed, 27 insertions, 9 deletions
@@ -147,16 +147,23 @@ void UI::init(Device* dev, Arena* a, Texture_Id at, Shader_Id sh) { Buffer_Flags::vertex_buffer | Buffer_Flags::cpu_readwrite ); + config_buf = device->create_buffer( + sizeof(UI_CBuffer), + Buffer_Flags::constant_buffer | + Buffer_Flags::cpu_readwrite + ); sp = &dev->get_shader(sh); vertex_format = sp->vf; shader_info.vert_binding = sp->binding_index("verts"); shader_info.atlas_binding = sp->descriptor_binding("atlas"); + shader_info.config_binding = sp->descriptor_binding("config_buffer"); sampler = create_clamped_point(device); } void UI::destroy() { device->destroy_texture(atlas); device->destroy_buffer(mesh); + device->destroy_buffer(config_buf); device->destroy_sampler(sampler); } @@ -200,7 +207,7 @@ int UI::render_label(const Label* l, int off) { int x = l->x; int y = l->y; const char* c; - float o = 10.0f * ndc[0]; + float o = 10.0f; Vertex* verts = (Vertex*)device->map_buffer( mesh, off * sizeof(Vertex), @@ -213,22 +220,22 @@ int UI::render_label(const Label* l, int off) { uo, uo + w }; verts[i] = Vertex { - (float)x * ndc[0], (float)y * ndc[1], uv[0], 0.0f, 1.0f, 1.0f, 1.0f, 1.0f + (float)x, (float)y, uv[0], 0.0f, 1.0f, 1.0f, 1.0f, 1.0f }; verts[i + 1] = Vertex { - (float)x * ndc[0], (float)y * ndc[1] + o, uv[0], 1.0f, 1.0f, 1.0f, 1.0f, 1.0f + (float)x, (float)y + o, uv[0], 1.0f, 1.0f, 1.0f, 1.0f, 1.0f }; verts[i + 2] = Vertex { - (float)x * ndc[0] + o, (float)y * ndc[1] + o, uv[1], 1.0f, 1.0f, 1.0f, 1.0f, 1.0f + (float)x + o, (float)y + o, uv[1], 1.0f, 1.0f, 1.0f, 1.0f, 1.0f }; verts[i + 3] = Vertex { - (float)x * ndc[0], (float)y * ndc[1], uv[0], 0.0f, 1.0f, 1.0f, 1.0f, 1.0f + (float)x, (float)y, uv[0], 0.0f, 1.0f, 1.0f, 1.0f, 1.0f }; verts[i + 4] = Vertex { - (float)x * ndc[0] + o, (float)y * ndc[1], uv[1], 0.0f, 1.0f, 1.0f, 1.0f, 1.0f + (float)x + o, (float)y, uv[1], 0.0f, 1.0f, 1.0f, 1.0f, 1.0f }; verts[i + 5] = Vertex { - (float)x * ndc[0] + o, (float)y * ndc[1] + o, uv[1], 1.0f, 1.0f, 1.0f, 1.0f, 1.0f + (float)x + o, (float)y + o, uv[1], 1.0f, 1.0f, 1.0f, 1.0f, 1.0f }; x += 10; } @@ -240,8 +247,18 @@ void UI::render(Arena* s, Texture_Id target) { Element* e = tree; int vc = 0; Texture& t = device->get_texture(target); - ndc[0] = 4.0f / (float)t.w; - ndc[1] = 4.0f / (float)t.h; + UI_CBuffer* config = (UI_CBuffer*)device->map_buffer( + config_buf, + 0, + sizeof(UI_CBuffer) + ); + config->projection = m4f::orth( + 0.0f, (float)t.w, + 0.0f, (float)t.h, + -1.0f, + 1.0f + ); + device->unmap_buffer(config_buf); for (; e; e = e->next) { switch (e->type) { case Element::Type::label: @@ -258,6 +275,7 @@ void UI::render(Arena* s, Texture_Id target) { pb.begin(device); pb.shader(shader); pb.vertex_format(vertex_format); + pb.cbuffer(shader_info.config_binding, config_buf); pb.texture(shader_info.atlas_binding, atlas, sampler); Pipeline& pip = pb.build(); |