diff options
| author | aura <nw@moneybot.cc> | 2026-03-10 05:18:33 +0100 |
|---|---|---|
| committer | aura <nw@moneybot.cc> | 2026-03-10 05:18:33 +0100 |
| commit | 30151d75dddd651faa1b27148a052ced7d0f190a (patch) | |
| tree | 30b9374d59ecdd83296f7a2b7aa008340b95daf5 /src/gui | |
| parent | 31b77ed2e0c037e5718b9ecd06d3941600cc8815 (diff) | |
2d batch rendering
Diffstat (limited to 'src/gui')
| -rw-r--r-- | src/gui/base.cpp | 26 | ||||
| -rw-r--r-- | src/gui/base.h | 9 | ||||
| -rw-r--r-- | src/gui/window.cpp | 8 |
3 files changed, 22 insertions, 21 deletions
diff --git a/src/gui/base.cpp b/src/gui/base.cpp index 1e8a493..79299de 100644 --- a/src/gui/base.cpp +++ b/src/gui/base.cpp @@ -37,8 +37,8 @@ void gui_end() { } void gui_draw( GAME_DATA* game ) { - _gui.gl2d = game->shaders.gl2d; - _gui.gl2d_font = game->shaders.gl2d; + _gui.batch = game->render.batch_2d; + gl_batch_empty( _gui.batch ); _gui.windows.each( fn( GUI_WINDOW** w ) { GUI_WINDOW* wnd = *w; @@ -46,6 +46,8 @@ void gui_draw( GAME_DATA* game ) { wnd->draw_fn( wnd ); } ); + + gl_batch_draw( _gui.batch ); } void gui_input( GAME_DATA* game ) { @@ -59,10 +61,10 @@ void gui_input( GAME_DATA* game ) { } void gui_onframe( GAME_DATA* game ) { _profiled - gui_run_callbacks(); - gui_input( game ); gui_draw( game ); + + gui_run_callbacks(); } void gui_free( GUI_BASE* node ) { @@ -254,15 +256,15 @@ void gui_base_input_fn( void* ptr ) { } void gui_draw_frect( I32 x, I32 y, I32 w, I32 h, CLR col ) { - gl_2d_frect( _gui.gl2d, { (F32)x, (F32)y }, { (F32)w, (F32)h }, col ); + gl_2d_frect( _gui.batch, { (F32)x, (F32)y }, { (F32)w, (F32)h }, col ); } void gui_draw_rect( I32 x, I32 y, I32 w, I32 h, CLR col ) { - gl_2d_rect( _gui.gl2d, { (F32)x, (F32)y }, { (F32)w, (F32)h }, col ); + gl_2d_rect( _gui.batch, { (F32)x, (F32)y }, { (F32)w, (F32)h }, col ); } void gui_draw_line( I32 x0, I32 y0, I32 x1, I32 y1, CLR col ) { - gl_2d_line( _gui.gl2d, { (F32)x0, (F32)y0 }, { (F32)x1, (F32)y1 }, col ); + gl_2d_line( _gui.batch, { (F32)x0, (F32)y0 }, { (F32)x1, (F32)y1 }, col ); } GL_FONT* gui_font_from_idx( U32 fnt ) { @@ -292,7 +294,7 @@ void gui_draw_str_internal( I32 x, I32 y, U8 align, U32 fnt, CLR col, const char case ALIGN_C: x -= (I32)( w * 0.5f ); break; } - gl_font_draw( pfnt, _gui.gl2d_font, { (F32)x, (F32)y }, str, col ); + gl_font_draw( pfnt, _gui.batch, { (F32)x, (F32)y }, str, col ); } void gui_draw_str( I32 x, I32 y, U8 align, U32 fnt, CLR col, const char* fmt, ... ) { @@ -326,7 +328,7 @@ void gui_draw_get_str_bounds( I32* w, I32* h, U32 fnt, const char *fmt, ... ) { void gui_draw_get_clip( I32 *x, I32 *y, I32 *w, I32 *h ) { VEC2 start, dim; - gl_get_clip( _gui.gl2d->gl, &start, &dim ); + gl_get_clip( _gui.batch->gl, &start, &dim ); if( x ) *x = (I32)start.x; if( y ) *y = (I32)start.y; @@ -341,11 +343,11 @@ void gui_draw_set_clip( I32 x, I32 y, I32 w, I32 h ) { dim.x = (F32)w; dim.y = (F32)h; - gl_set_clip( _gui.gl2d->gl, start, dim ); + gl_set_clip( _gui.batch->gl, start, dim ); } void gui_draw_reset_clip() { - gl_reset_clip( _gui.gl2d->gl ); + gl_reset_clip( _gui.batch->gl ); } void gui_draw_push_clip( I32 x, I32 y, I32 w, I32 h ) { @@ -397,7 +399,7 @@ U8 gui_key_down( U8 key ) { } F32 gui_frametime() { - return _gui.gl2d->gl->frametime; + return _gui.batch->gl->frametime; } F32 gui_time() { diff --git a/src/gui/base.h b/src/gui/base.h index 73816a7..e62c66a 100644 --- a/src/gui/base.h +++ b/src/gui/base.h @@ -1,6 +1,6 @@ #pragma once -#include "../util/color.h" -#include "../util/allocator.h" +#include "../render/gl_2d.h" +#include <functional> // ======================================= [ colorscheme ] ======================================== @@ -46,7 +46,7 @@ extern U8 gui_is_fg_window( struct GUI_BASE* node ); // 1 if pa // ======================================= [ components ] ========================================= -typedef void( *GUI_CALLBACK )( void* ptr ); +using GUI_CALLBACK = std::function<void( void* )>; struct GUI_LIST_ENTRY { I32 val; char title[256]; @@ -320,8 +320,7 @@ struct __gui_internal { } fonts; // draw stuff below - struct GL_SHADER_PROGRAM* gl2d; - struct GL_SHADER_PROGRAM* gl2d_font; + GL_BATCH2D* batch; }; void __gui_internal_vectorinput_init( diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 0183d8c..500cb3d 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -83,12 +83,12 @@ void gui_title_input_fn( void* ptr ) { w->x = mx - t->xoff; w->y = my - t->yoff; - if( w->x > _gui.gl2d->gl->canvas_size[0] - 5 ) - w->x = _gui.gl2d->gl->canvas_size[0] - 5; + if( w->x > _gui.batch->gl->canvas_size[0] - 5 ) + w->x = _gui.batch->gl->canvas_size[0] - 5; if( w->x + w->w < 5 ) w->x = 5 - w->w; - if( w->y > _gui.gl2d->gl->canvas_size[1] - 5 ) - w->y = _gui.gl2d->gl->canvas_size[1] - 5; + if( w->y > _gui.batch->gl->canvas_size[1] - 5 ) + w->y = _gui.batch->gl->canvas_size[1] - 5; if( w->y + w->h < 5 ) w->y = 5 - w->h; } |
