summaryrefslogtreecommitdiff
path: root/src/editor
diff options
context:
space:
mode:
authoraura <nw@moneybot.cc>2026-03-10 05:18:33 +0100
committeraura <nw@moneybot.cc>2026-03-10 05:18:33 +0100
commit30151d75dddd651faa1b27148a052ced7d0f190a (patch)
tree30b9374d59ecdd83296f7a2b7aa008340b95daf5 /src/editor
parent31b77ed2e0c037e5718b9ecd06d3941600cc8815 (diff)
2d batch rendering
Diffstat (limited to 'src/editor')
-rw-r--r--src/editor/editor_infobox.cpp2
-rw-r--r--src/editor/texturepicker.cpp12
-rw-r--r--src/editor/view2d.cpp8
-rw-r--r--src/editor/view3d.cpp76
4 files changed, 58 insertions, 40 deletions
diff --git a/src/editor/editor_infobox.cpp b/src/editor/editor_infobox.cpp
index 931d9ea..9f9060d 100644
--- a/src/editor/editor_infobox.cpp
+++ b/src/editor/editor_infobox.cpp
@@ -92,7 +92,7 @@ static void gui_editor_infobox_draw_assets( GUI_EDITOR_INFOBOX* box, I32 panel_x
gui_draw_frect( tx + 1, ty + 1, EDITOR_ASSETS_THUMB - 2, EDITOR_ASSETS_THUMB - 2, ui_clr.bg_alt );
gui_draw_str( tx + EDITOR_ASSETS_THUMB / 2, ty + 4, ALIGN_C, FNT_JPN12, ui_clr.txt, "m" );
} else if( p->tex ) {
- gl_2d_textured_frect( _gui.gl2d_font, { (F32)(tx + 1), (F32)(ty + 1) }, { (F32)(EDITOR_ASSETS_THUMB - 2), (F32)(EDITOR_ASSETS_THUMB - 2) }, p->tex );
+ gl_2d_textured_frect( _gui.batch, { (F32)(tx + 1), (F32)(ty + 1) }, { (F32)(EDITOR_ASSETS_THUMB - 2), (F32)(EDITOR_ASSETS_THUMB - 2) }, p->tex );
} else {
gui_draw_frect( tx + 1, ty + 1, EDITOR_ASSETS_THUMB - 2, EDITOR_ASSETS_THUMB - 2, p->clr );
}
diff --git a/src/editor/texturepicker.cpp b/src/editor/texturepicker.cpp
index a24e955..621f0c2 100644
--- a/src/editor/texturepicker.cpp
+++ b/src/editor/texturepicker.cpp
@@ -90,7 +90,7 @@ void gui_editor_texturepicker_draw_files( GUI_EDITOR_TEXTUREPICKER* wnd ) {
gui_draw_frect( tx - 1, ty - 1, size + 2, size + 2, clr );
gui_draw_frect( tx, ty, size, size, clr );
gl_2d_textured_frect(
- _gui.gl2d_font,
+ _gui.batch,
{ (F32)tx, (F32)ty },
{ (F32)size, (F32)size },
tex,
@@ -144,7 +144,7 @@ void gui_editor_texturepicker_draw_fn( void* ptr ) {
void gui_editor_textureview_delete_textures( GUI_EDITOR_TEXTUREPICKER* wnd ) {
wnd->textures.each( fn( GL_TEX2D** ptr ) {
GL_TEX2D* tex = *ptr;
- gl_texture_destroy( _gui.gl2d->gl, tex );
+ gl_texture_destroy( _gui.batch->gl, tex );
} );
wnd->textures.clear();
@@ -155,7 +155,7 @@ void gui_editor_texturepicker_load_texture( void* ptr ) {
FILE_ENTRY* f = &wnd->files[wnd->curload];
const char* name = assets_abspath( f->name );
- GL_TEX2D* tex = gl_texture_from_file( _gui.gl2d->gl, name );
+ GL_TEX2D* tex = gl_texture_from_file( _gui.batch->gl, name );
if( !tex ) {
dlog( "gui_editor_textureview_create_textures() : error creating texture %s", name );
return;
@@ -170,7 +170,7 @@ void gui_editor_texturepicker_load_texture( void* ptr ) {
void gui_editor_textureview_create_textures( GUI_EDITOR_TEXTUREPICKER* wnd ) {
wnd->curload = 0;
- GL_TEX2D* emptytex = gl_texture_create( _gui.gl2d->gl, "" );
+ GL_TEX2D* emptytex = gl_texture_create( _gui.batch->gl, "" );
strcpy( emptytex->name, "none" );
emptytex->width = emptytex->height = 1;
@@ -189,7 +189,7 @@ void gui_editor_textureview_accept( GUI_EDITOR_TEXTUREPICKER* wnd ) {
if( !isnone && tex == wnd->curselect )
return;
- gl_texture_destroy( _gui.gl2d->gl, tex );
+ gl_texture_destroy( _gui.batch->gl, tex );
} );
if( !isnone ) {
@@ -198,7 +198,7 @@ void gui_editor_textureview_accept( GUI_EDITOR_TEXTUREPICKER* wnd ) {
GL_TEX2D* tex = map_find_texture( editor->map, name );
*wnd->target = tex;
- gl_texture_destroy( _gui.gl2d->gl, wnd->curselect );
+ gl_texture_destroy( _gui.batch->gl, wnd->curselect );
} else {
*wnd->target = wnd->curselect;
}
diff --git a/src/editor/view2d.cpp b/src/editor/view2d.cpp
index 7b97687..8dbe42c 100644
--- a/src/editor/view2d.cpp
+++ b/src/editor/view2d.cpp
@@ -530,9 +530,9 @@ void gui_editor_2dview_draw_polygons( GUI_EDITOR_2DVIEW* view, I32 x, I32 y ) {
} );
if( props->tex )
- gl_2d_textured_polygon( _gui.gl2d_font, vertices.data, vertices.size, props->tex );
+ gl_2d_textured_polygon( _gui.batch, vertices.data, vertices.size, props->tex );
else
- gl_2d_polygon( _gui.gl2d, vertices.data, vertices.size );
+ gl_2d_polygon( _gui.batch, vertices.data, vertices.size );
}
else {
for( U32 i = 0; i < p->vertices.size; ++i ) {
@@ -632,7 +632,7 @@ void gui_editor_2dview_draw_sprites( GUI_EDITOR_2DVIEW* view, I32 x, I32 y ) {
else {
gl_2d_frect(
- _gui.gl2d,
+ _gui.batch,
{ (F32)((I32)pos.x - w/2), (F32)((I32)pos.y - h/2) },
{ (F32)w, (F32)h },
s->clr
@@ -640,7 +640,7 @@ void gui_editor_2dview_draw_sprites( GUI_EDITOR_2DVIEW* view, I32 x, I32 y ) {
}
if( s->tex ) {
gl_2d_textured_frect(
- _gui.gl2d_font,
+ _gui.batch,
{ (F32)((I32)pos.x - w/2), (F32)((I32)pos.y - h/2) },
{ (F32)w, (F32)h },
s->tex,
diff --git a/src/editor/view3d.cpp b/src/editor/view3d.cpp
index 292760a..cdec211 100644
--- a/src/editor/view3d.cpp
+++ b/src/editor/view3d.cpp
@@ -1,5 +1,7 @@
#include "editor.h"
+#include "../render/gl_2d_font.h"
+
#include "../game/objlist.h"
#include "../game/world/draw.h"
#include "../game/world/bsp_draw.h"
@@ -14,37 +16,43 @@ void gui_editor_3dview_draw_showpos( GUI_EDITOR_3DVIEW* view ) {
VEC3 pos = objl->pl->pos;
F32 speed = vec_len( objl->pl->velocity );
-
- gui_draw_str(
- x + view->w - 2, y + 2,
- ALIGN_R,
- FNT_JPN12,
- ui_clr.txt,
- "pos: %.02f %.02f %.02f (%.02f)",
- pos.x, pos.y, pos.z, speed
+ STR posstr = STR( "pos: %.02f %.02f %.02f (%.02f)", pos.x, pos.y, pos.z, speed );
+ STR rotstr = STR( "rot: %.02f %.02f", objl->pl->rot.y, objl->pl->rot.x );
+
+ VEC2 posdim = gl_font_dim( _gui.fonts.jpn12.glfnt, posstr );
+ VEC2 rotdim = gl_font_dim( _gui.fonts.jpn12.glfnt, rotstr );
+
+ gl_font_draw(
+ _gui.fonts.jpn12.glfnt,
+ _gui.batch->shader,
+ VEC2( x + view->w - 2 - posdim.x, y + 2 ),
+ posstr,
+ ui_clr.txt
);
-
- gui_draw_str(
- x + view->w - 2, y + 18,
- ALIGN_R,
- FNT_JPN12,
- ui_clr.txt,
- "rot: %.02f %.02f",
- objl->pl->rot.y,
- objl->pl->rot.x
+ gl_font_draw(
+ _gui.fonts.jpn12.glfnt,
+ _gui.batch->shader,
+ VEC2( x + view->w - 2 - rotdim.x, y + 18 ),
+ rotstr,
+ ui_clr.txt
);
-
if( input.mouselock ) {
- gui_draw_str(
- x + 2, y + 2,
- ALIGN_L,
- FNT_JPN12,
- ui_clr.txt,
- "[capturing mouse]"
+ gl_font_draw(
+ _gui.fonts.jpn12.glfnt,
+ _gui.batch->shader,
+ VEC2( x + 2, y + 2 ),
+ "[capturing mouse]",
+ ui_clr.txt
);
}
}
+struct WORLD_DRAW_CB_DATA {
+ VEC2 wnd;
+ VEC2 winsize;
+ GUI_EDITOR_3DVIEW* view;
+};
+
void gui_editor_3dview_draw_fn( void* ptr ) {
GUI_EDITOR_3DVIEW* view = (GUI_EDITOR_3DVIEW*)ptr;
@@ -59,14 +67,25 @@ void gui_editor_3dview_draw_fn( void* ptr ) {
VEC2 wnd = { (F32)x, (F32)y };
VEC2 winsize = { (F32)view->w, (F32)view->h };
+ static WORLD_DRAW_CB_DATA data;
+ data = { wnd, winsize, view };
CLR col = gui_is_fg_window( view )? ui_clr.border : ui_clr.border_inactive;
gui_draw_frect( x-1, y-1, view->w+2, view->h+2, col );
gui_draw_frect( x, y, view->w, view->h, CLR::BLACK() );
- if( editor->drawbsp && editor->map->bsp )
- bsp_draw( editor->map->bsp, editor->game, wnd, winsize );
- else
- world_draw( editor->game, objl->world, wnd, winsize );
+ if( editor->drawbsp && editor->map->bsp ) {
+ gui_push_callback( &data, fn( void* data ) {
+ WORLD_DRAW_CB_DATA* d = (WORLD_DRAW_CB_DATA*)data;
+ bsp_draw( editor->map->bsp, editor->game, d->wnd, d->winsize );
+ gui_editor_3dview_draw_showpos( d->view);
+ } );
+ } else {
+ gui_push_callback( &data, fn( void* data ) {
+ WORLD_DRAW_CB_DATA* d = (WORLD_DRAW_CB_DATA*)data;
+ world_draw( editor->game, objl->world, d->wnd, d->winsize );
+ gui_editor_3dview_draw_showpos( d->view );
+ } );
+ }
gui_draw_push_clip( x, y, view->w, view->h );
view->children.each( fn( GUI_BASE** childptr ) {
@@ -77,7 +96,6 @@ void gui_editor_3dview_draw_fn( void* ptr ) {
else dlog( "gui_view_draw_fn(): child %p no draw_fn\n", child );
} );
gui_draw_pop_clip();
- gui_editor_3dview_draw_showpos( view );
}
void gui_editor_3dview_input_fn( void* ptr ) {