diff options
author | quou <quou@disroot.org> | 2025-01-19 21:04:51 +1100 |
---|---|---|
committer | quou <quou@disroot.org> | 2025-01-19 21:04:51 +1100 |
commit | 74e8d3f0278a65fdf86a1185fec8a6016e628e88 (patch) | |
tree | 660dd28a07296d74e3caf0f6adde0336235be1c0 /ui.hpp | |
parent | 7b6bda1188cf80ffc85b16e099d7811c92dbd7ac (diff) |
render UI in software
Diffstat (limited to 'ui.hpp')
-rw-r--r-- | ui.hpp | 124 |
1 files changed, 44 insertions, 80 deletions
@@ -3,16 +3,12 @@ #include "app.hpp" #include "maths.hpp" -#include "video.hpp" #include <new> struct Arena; +struct Heap; struct UI { - struct Vertex { - float x, y, u, v, r, g, b, a; - }; - struct Colour { uint8_t r, g, b, a; Colour(unsigned rgb, uint8_t a = 0xff); @@ -29,109 +25,77 @@ struct UI { Rect(int x, int y, int w, int h); void clip(const Rect& other); + void clip_src(const Rect& other, Rect& src); void shrink(int a); bool contains(int px, int py); }; - struct Vertex_Buffer { + struct Renderer { + static constexpr int grid_size = 16; + static constexpr int cmd_buf_size = 1024 * 8; + Rect bound; Rect clip; - bool dirty; - Staged_Buffer buf; - Buffer_Id indices; - int start, usage; - - void init(Device* dev); - void init_indices(Device* dev); - void destroy(UI* ui); - void update_buffer(Context& ctx); - void reset(const Rect& clip); - void set_clip(const Rect& clip); - - void add_quad( - UI* ui, - int x, - int y, - int w, - int h, - float u0, - float v0, - float u1, - float v1, - Colour col - ); - void add_rect( - UI* ui, - int x, - int y, - int w, - int h, - Colour col - ); - void add_char(UI* ui, int x, int y, char ch, Colour col); - void add_text( - UI* ui, - int x, - int y, - const char* txt, - Colour col - ); - void draw( - UI* ui, - Context& ctx, - Pipeline& pip, - Render_Pass& rp - ); - Vertex_Buffer* next; - }; + Colour* pixels; + Heap* arena; + uint8_t cmd_buf[cmd_buf_size]; + int cmd_buf_ptr; + int grid_cell_size[2]; + uint64_t grid_a[grid_size * grid_size]; + uint64_t grid_b[grid_size * grid_size]; + uint64_t* grid; + + struct Cmd { + enum { + RECT, + TEXT, + CLIP + }; + int type, size; + Colour col; + Rect r; + }; + + void blit_rect(int x, int y, int w, int h, Colour col); + void blit_char(char ch, int x, int y, Colour col); + + Cmd* add_cmd(int size); + void commit_cmd(Cmd* c); + void add_rect(int x, int y, int w, int h, Colour col); + void add_text(int x, int y, const char* txt, Colour col); + void reset(const Rect& cl); + void set_clip(const Rect& r); + void clear(const Rect& r); + void flush(int x, int y); + void flush(); + void resize(int w, int h); + void init(Heap* heap, int w, int h); + } ren; struct Element; Heap* heap; - Device* device; const App* app; - Texture_Id atlas; - Shader_Id shader; - Vertex_Format_Id vertex_format; - Sampler_Id sampler; - Staged_Buffer cbuffer; - Vertex_Buffer mesh; - Pipeline* pipeline; - Render_Pass* render_pass; Element* root, * hot, * hovered, * active; Rect area; bool layout_dirty; - struct UI_CBuffer { - m4f projection; - }; - struct { - int vert_binding; - int atlas_binding; - int config_binding; - } shader_info; - static int text_width(const char* t); static int text_height(const char* t); static UI* create( - Device* dev, const App* app, - Arena* a, - Shader_Id sh + Arena* a ); void init( - Device* dev, const App* app, - Heap* h, - Texture_Id atlas, - Shader_Id sh + Heap* h ); void destroy(); void layout(int w, int h); void text_input(const char* buf); void update(Arena* s); - void render(Arena* s, Texture_Id target); + void render(Arena* s); void draw_container(const Rect& r, Colour c); void draw_containeri(const Rect& r, Colour c); |