1414#include "font_manager.h"
1515#include "sprite_submit.h"
1616#include "material_util.h"
17+ #include "render_bindings.h"
1718
1819#define BATCHN 4096
1920
@@ -40,7 +41,7 @@ struct buffer_data {
4041struct material_text {
4142 sg_pipeline pip ;
4243 sg_buffer inst ;
43- sg_bindings * bind ;
44+ struct soluna_render_bindings * bind ;
4445 vs_params_t * uniform ;
4546 struct sr_buffer * srbuffer ;
4647 struct font_manager * font ;
@@ -97,19 +98,27 @@ lmateraial_text_submit(lua_State *L) {
9798 return 0 ;
9899}
99100
100- static void
101- draw_text (struct material_text * m , uint32_t color , int count ) {
101+ static inline void
102+ draw_text (struct material_text * m , uint32_t color , int count , int ex ) {
102103 m -> fs_uniform .color = color ;
103104 sg_apply_uniforms (UB_vs_params , & (sg_range ){ m -> uniform , sizeof (vs_params_t ) });
104105 sg_apply_uniforms (UB_fs_params , & (sg_range ){ & m -> fs_uniform , sizeof (fs_params_t ) });
105- sg_apply_bindings (m -> bind );
106- sg_draw (0 , 4 , count );
107-
108- m -> bind -> vertex_buffer_offsets [0 ] += count * sizeof (struct inst_object );
106+ if (ex ) {
107+ sg_apply_bindings (& m -> bind -> bindings );
108+ sg_draw_ex (0 , 4 , count , 0 , m -> bind -> base );
109+ } else {
110+ size_t base = m -> bind -> base * sizeof (struct inst_object );
111+ m -> bind -> bindings .vertex_buffer_offsets [0 ] += base ;
112+ sg_apply_bindings (& m -> bind -> bindings );
113+ sg_draw (0 , 4 , count );
114+ m -> bind -> bindings .vertex_buffer_offsets [0 ] -= base ;
115+ }
116+
117+ m -> bind -> base += count ;
109118}
110119
111- static int
112- lmateraial_text_draw (lua_State * L ) {
120+ static inline int
121+ lmateraial_text_draw_ (lua_State * L , int ex ) {
113122 struct material_text * m = (struct material_text * )luaL_checkudata (L , 1 , "SOLUNA_MATERIAL_TEXT" );
114123 struct draw_primitive * prim = lua_touserdata (L , 2 );
115124 int prim_n = luaL_checkinteger (L , 3 );
@@ -130,21 +139,31 @@ lmateraial_text_draw(lua_State *L) {
130139 color = t -> color ;
131140 count = 1 ;
132141 } else if (t -> color != color ) {
133- draw_text (m , color , count );
142+ draw_text (m , color , count , ex );
134143 color = t -> color ;
135144 count = 1 ;
136145 } else {
137146 ++ count ;
138147 }
139148 }
140149 }
141- draw_text (m , color , count );
150+ draw_text (m , color , count , ex );
142151
143152 m -> uniform -> texsize = texsize ;
144153
145154 return 0 ;
146155}
147156
157+ static int
158+ lmateraial_text_draw (lua_State * L ) {
159+ return lmateraial_text_draw_ (L , 0 );
160+ }
161+
162+ static int
163+ lmateraial_text_draw_ex (lua_State * L ) {
164+ return lmateraial_text_draw_ (L , 1 );
165+ }
166+
148167static void
149168init_pipeline (struct material_text * m ) {
150169 sg_shader shd = sg_make_shader (texquad_shader_desc (sg_query_backend ()));
@@ -205,7 +224,7 @@ lnew_material_text_normal(lua_State *L) {
205224 luaL_Reg l [] = {
206225 { "__index" , NULL },
207226 { "submit" , lmateraial_text_submit },
208- { "draw" , lmateraial_text_draw },
227+ { "draw" , DRAWFUNC ( lmateraial_text_draw ) },
209228 { NULL , NULL },
210229 };
211230 luaL_setfuncs (L , l , 0 );
0 commit comments