@@ -1974,6 +1974,12 @@ RendererCanvasRenderRD::RendererCanvasRenderRD() {
19741974 default_canvas_texture = texture_storage->canvas_texture_allocate ();
19751975 texture_storage->canvas_texture_initialize (default_canvas_texture);
19761976
1977+ RendererRD::TextureStorage::CanvasTextureInfo info = RendererRD::TextureStorage::get_singleton ()->canvas_texture_get_info (default_canvas_texture, default_filter, default_repeat, false , false );
1978+ default_texture_info.diffuse = info.diffuse ;
1979+ default_texture_info.normal = info.normal ;
1980+ default_texture_info.specular = info.specular ;
1981+ default_texture_info.sampler = info.sampler ;
1982+
19771983 state.shadow_texture_size = GLOBAL_GET (" rendering/2d/shadow_atlas/size" );
19781984
19791985 // create functions for shader and material
@@ -2219,7 +2225,7 @@ void RendererCanvasRenderRD::_render_batch_items(RenderTarget p_to_render_target
22192225 RD::get_singleton ()->draw_list_bind_uniform_set (draw_list, state.default_transforms_uniform_set , TRANSFORMS_UNIFORM_SET );
22202226
22212227 Item *current_clip = nullptr ;
2222- state.current_tex_uniform_set = RID ();
2228+ state.current_batch_uniform_set = RID ();
22232229
22242230 for (uint32_t i = 0 ; i <= state.current_batch_index ; i++) {
22252231 Batch *current_batch = &state.canvas_instance_batches [i];
@@ -2337,11 +2343,11 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar
23372343 instance_data->world [i] = world[i];
23382344 }
23392345
2340- instance_data->flags = base_flags | r_current_batch->tex_flags ; // Reset on each command for safety, keep canvas texture binding config.
2346+ instance_data->flags = base_flags | r_current_batch->tex_info . flags ; // Reset on each command for safety, keep canvas texture binding config.
23412347
2342- instance_data->color_texture_pixel_size [0 ] = r_current_batch->tex_texpixel_size .width ;
2343- instance_data->color_texture_pixel_size [1 ] = r_current_batch->tex_texpixel_size .height ;
2344- instance_data->specular_shininess = r_current_batch->tex_specular_shininess ;
2348+ instance_data->color_texture_pixel_size [0 ] = r_current_batch->tex_info . texpixel_size .width ;
2349+ instance_data->color_texture_pixel_size [1 ] = r_current_batch->tex_info . texpixel_size .height ;
2350+ instance_data->specular_shininess = r_current_batch->tex_info . specular_shininess ;
23452351
23462352 return instance_data;
23472353 };
@@ -2373,10 +2379,10 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar
23732379 bool has_msdf = bool (rect->flags & CANVAS_RECT_MSDF );
23742380 TextureState tex_state (rect->texture , texture_filter, texture_repeat, has_msdf, use_linear_colors);
23752381
2376- if (tex_state != r_current_batch->tex_state ) {
2382+ if (tex_state != r_current_batch->tex_info . state ) {
23772383 r_current_batch = _new_batch (r_batch_broken);
2378- r_current_batch->set_tex_state ( tex_state) ;
2379- _prepare_batch_texture (r_current_batch, rect->texture );
2384+ r_current_batch->tex_info . state = tex_state;
2385+ _prepare_batch_texture_info (r_current_batch, rect->texture );
23802386 }
23812387
23822388 Color modulated = rect->modulate * base_color;
@@ -2399,7 +2405,7 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar
23992405 Rect2 dst_rect;
24002406
24012407 if (rect->texture .is_valid ()) {
2402- src_rect = (rect->flags & CANVAS_RECT_REGION ) ? Rect2 (rect->source .position * r_current_batch->tex_texpixel_size , rect->source .size * r_current_batch->tex_texpixel_size ) : Rect2 (0 , 0 , 1 , 1 );
2408+ src_rect = (rect->flags & CANVAS_RECT_REGION ) ? Rect2 (rect->source .position * r_current_batch->tex_info . texpixel_size , rect->source .size * r_current_batch->tex_info . texpixel_size ) : Rect2 (0 , 0 , 1 , 1 );
24032409 dst_rect = Rect2 (rect->rect .position , rect->rect .size );
24042410
24052411 if (dst_rect.size .width < 0 ) {
@@ -2484,10 +2490,10 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar
24842490 }
24852491
24862492 TextureState tex_state (np->texture , texture_filter, texture_repeat, false , use_linear_colors);
2487- if (tex_state != r_current_batch->tex_state ) {
2493+ if (tex_state != r_current_batch->tex_info . state ) {
24882494 r_current_batch = _new_batch (r_batch_broken);
2489- r_current_batch->set_tex_state ( tex_state) ;
2490- _prepare_batch_texture (r_current_batch, np->texture );
2495+ r_current_batch->tex_info . state = tex_state;
2496+ _prepare_batch_texture_info (r_current_batch, np->texture );
24912497 }
24922498
24932499 InstanceData *instance_data = new_instance_data ();
@@ -2499,7 +2505,7 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar
24992505 src_rect = Rect2 (0 , 0 , 1 , 1 );
25002506 } else {
25012507 if (np->source != Rect2 ()) {
2502- src_rect = Rect2 (np->source .position .x * r_current_batch->tex_texpixel_size . width , np->source .position .y * r_current_batch->tex_texpixel_size . height , np->source .size .x * r_current_batch->tex_texpixel_size . width , np->source .size .y * r_current_batch->tex_texpixel_size .height );
2508+ src_rect = Rect2 (np->source .position .x * r_current_batch->tex_info . texpixel_size . width , np->source .position .y * r_current_batch->tex_info . texpixel_size . height , np->source .size .x * r_current_batch->tex_info . texpixel_size . width , np->source .size .y * r_current_batch->tex_info . texpixel_size .height );
25032509 instance_data->color_texture_pixel_size [0 ] = 1.0 / np->source .size .width ;
25042510 instance_data->color_texture_pixel_size [1 ] = 1.0 / np->source .size .height ;
25052511 } else {
@@ -2553,10 +2559,10 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar
25532559 r_current_batch->command = c;
25542560
25552561 TextureState tex_state (polygon->texture , texture_filter, texture_repeat, false , use_linear_colors);
2556- if (tex_state != r_current_batch->tex_state ) {
2562+ if (tex_state != r_current_batch->tex_info . state ) {
25572563 r_current_batch = _new_batch (r_batch_broken);
2558- r_current_batch->set_tex_state ( tex_state) ;
2559- _prepare_batch_texture (r_current_batch, polygon->texture );
2564+ r_current_batch->tex_info . state = tex_state;
2565+ _prepare_batch_texture_info (r_current_batch, polygon->texture );
25602566 }
25612567
25622568 // pipeline variant
@@ -2596,10 +2602,10 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar
25962602 r_current_batch->pipeline_variant = variant[primitive->point_count - 1 ];
25972603
25982604 TextureState tex_state (primitive->texture , texture_filter, texture_repeat, false , use_linear_colors);
2599- if (tex_state != r_current_batch->tex_state ) {
2605+ if (tex_state != r_current_batch->tex_info . state ) {
26002606 r_current_batch = _new_batch (r_batch_broken);
2601- r_current_batch->set_tex_state ( tex_state) ;
2602- _prepare_batch_texture (r_current_batch, primitive->texture );
2607+ r_current_batch->tex_info . state = tex_state;
2608+ _prepare_batch_texture_info (r_current_batch, primitive->texture );
26032609 }
26042610 }
26052611
@@ -2657,8 +2663,8 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar
26572663 if (c->type == Item::Command::TYPE_MESH ) {
26582664 const Item::CommandMesh *m = static_cast <const Item::CommandMesh *>(c);
26592665 TextureState tex_state (m->texture , texture_filter, texture_repeat, false , use_linear_colors);
2660- r_current_batch->set_tex_state ( tex_state) ;
2661- _prepare_batch_texture (r_current_batch, m->texture );
2666+ r_current_batch->tex_info . state = tex_state;
2667+ _prepare_batch_texture_info (r_current_batch, m->texture );
26622668 instance_data = new_instance_data ();
26632669
26642670 r_current_batch->mesh_instance_count = 1 ;
@@ -2680,8 +2686,8 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar
26802686 }
26812687
26822688 TextureState tex_state (mm->texture , texture_filter, texture_repeat, false , use_linear_colors);
2683- r_current_batch->set_tex_state ( tex_state) ;
2684- _prepare_batch_texture (r_current_batch, mm->texture );
2689+ r_current_batch->tex_info . state = tex_state;
2690+ _prepare_batch_texture_info (r_current_batch, mm->texture );
26852691 instance_data = new_instance_data ();
26862692
26872693 instance_data->flags |= 1 ; // multimesh, trails disabled
@@ -2698,8 +2704,8 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar
26982704
26992705 const Item::CommandParticles *pt = static_cast <const Item::CommandParticles *>(c);
27002706 TextureState tex_state (pt->texture , texture_filter, texture_repeat, false , use_linear_colors);
2701- r_current_batch->set_tex_state ( tex_state) ;
2702- _prepare_batch_texture (r_current_batch, pt->texture );
2707+ r_current_batch->tex_info . state = tex_state;
2708+ _prepare_batch_texture_info (r_current_batch, pt->texture );
27032709
27042710 instance_data = new_instance_data ();
27052711
@@ -2795,7 +2801,20 @@ void RendererCanvasRenderRD::_render_batch(RD::DrawListID p_draw_list, PipelineV
27952801
27962802 ERR_FAIL_NULL (p_batch->command );
27972803
2798- _bind_canvas_texture (p_draw_list, p_batch->tex_uniform_set );
2804+ {
2805+ RD ::Uniform u_diffuse (RD ::UNIFORM_TYPE_TEXTURE , 0 , p_batch->tex_info .diffuse );
2806+ RD ::Uniform u_normal (RD ::UNIFORM_TYPE_TEXTURE , 1 , p_batch->tex_info .normal );
2807+ RD ::Uniform u_specular (RD ::UNIFORM_TYPE_TEXTURE , 2 , p_batch->tex_info .specular );
2808+ RD ::Uniform u_sampler (RD ::UNIFORM_TYPE_SAMPLER , 3 , p_batch->tex_info .sampler );
2809+ RD ::Uniform u_instance_data (RD ::UNIFORM_TYPE_STORAGE_BUFFER , 4 , state.canvas_instance_data_buffers [state.current_data_buffer_index ].instance_buffers [p_batch->instance_buffer_index ]);
2810+
2811+ RID uniform_set = uniform_set_cache->get_cache (shader.default_version_rd_shader , BATCH_UNIFORM_SET , u_diffuse, u_normal, u_specular, u_sampler, u_instance_data);
2812+
2813+ if (state.current_batch_uniform_set != uniform_set) {
2814+ state.current_batch_uniform_set = uniform_set;
2815+ RD::get_singleton ()->draw_list_bind_uniform_set (p_draw_list, uniform_set, BATCH_UNIFORM_SET );
2816+ }
2817+ }
27992818
28002819 switch (p_batch->command_type ) {
28012820 case Item::Command::TYPE_RECT :
@@ -2810,13 +2829,6 @@ void RendererCanvasRenderRD::_render_batch(RD::DrawListID p_draw_list, PipelineV
28102829 PushConstant push_constant;
28112830 push_constant.base_instance_index = p_batch->start ;
28122831 RD::get_singleton ()->draw_list_set_push_constant (p_draw_list, &push_constant, sizeof (PushConstant));
2813-
2814- RD ::Uniform u_instance_data (RD ::UNIFORM_TYPE_STORAGE_BUFFER , 0 , state.canvas_instance_data_buffers [state.current_data_buffer_index ].instance_buffers [p_batch->instance_buffer_index ]);
2815- RD::get_singleton ()->draw_list_bind_uniform_set (
2816- p_draw_list,
2817- uniform_set_cache->get_cache (shader.default_version_rd_shader , INSTANCE_DATA_UNIFORM_SET , u_instance_data),
2818- INSTANCE_DATA_UNIFORM_SET );
2819-
28202832 RD::get_singleton ()->draw_list_bind_index_array (p_draw_list, shader.quad_index_array );
28212833 RD::get_singleton ()->draw_list_draw (p_draw_list, true , p_batch->instance_count );
28222834
@@ -2839,13 +2851,6 @@ void RendererCanvasRenderRD::_render_batch(RD::DrawListID p_draw_list, PipelineV
28392851 PushConstant push_constant;
28402852 push_constant.base_instance_index = p_batch->start ;
28412853 RD::get_singleton ()->draw_list_set_push_constant (p_draw_list, &push_constant, sizeof (PushConstant));
2842-
2843- RD ::Uniform u_instance_data (RD ::UNIFORM_TYPE_STORAGE_BUFFER , 0 , state.canvas_instance_data_buffers [state.current_data_buffer_index ].instance_buffers [p_batch->instance_buffer_index ]);
2844- RD::get_singleton ()->draw_list_bind_uniform_set (
2845- p_draw_list,
2846- uniform_set_cache->get_cache (shader.default_version_rd_shader , INSTANCE_DATA_UNIFORM_SET , u_instance_data),
2847- INSTANCE_DATA_UNIFORM_SET );
2848-
28492854 RD::get_singleton ()->draw_list_bind_vertex_array (p_draw_list, pb->vertex_array );
28502855 if (pb->indices .is_valid ()) {
28512856 RD::get_singleton ()->draw_list_bind_index_array (p_draw_list, pb->indices );
@@ -2868,13 +2873,6 @@ void RendererCanvasRenderRD::_render_batch(RD::DrawListID p_draw_list, PipelineV
28682873 PushConstant push_constant;
28692874 push_constant.base_instance_index = p_batch->start ;
28702875 RD::get_singleton ()->draw_list_set_push_constant (p_draw_list, &push_constant, sizeof (PushConstant));
2871-
2872- RD ::Uniform u_instance_data (RD ::UNIFORM_TYPE_STORAGE_BUFFER , 0 , state.canvas_instance_data_buffers [state.current_data_buffer_index ].instance_buffers [p_batch->instance_buffer_index ]);
2873- RD::get_singleton ()->draw_list_bind_uniform_set (
2874- p_draw_list,
2875- uniform_set_cache->get_cache (shader.default_version_rd_shader , INSTANCE_DATA_UNIFORM_SET , u_instance_data),
2876- INSTANCE_DATA_UNIFORM_SET );
2877-
28782876 RD::get_singleton ()->draw_list_bind_index_array (p_draw_list, primitive_arrays.index_array [MIN (3u , primitive->point_count ) - 1 ]);
28792877 uint32_t instance_count = p_batch->instance_count ;
28802878 RD::get_singleton ()->draw_list_draw (p_draw_list, true , instance_count);
@@ -2934,12 +2932,6 @@ void RendererCanvasRenderRD::_render_batch(RD::DrawListID p_draw_list, PipelineV
29342932 break ;
29352933 }
29362934
2937- RD ::Uniform u_instance_data (RD ::UNIFORM_TYPE_STORAGE_BUFFER , 0 , state.canvas_instance_data_buffers [state.current_data_buffer_index ].instance_buffers [p_batch->instance_buffer_index ]);
2938- RD::get_singleton ()->draw_list_bind_uniform_set (
2939- p_draw_list,
2940- uniform_set_cache->get_cache (shader.default_version_rd_shader , INSTANCE_DATA_UNIFORM_SET , u_instance_data),
2941- INSTANCE_DATA_UNIFORM_SET );
2942-
29432935 uint32_t surf_count = mesh_storage->mesh_get_surface_count (mesh);
29442936 static const PipelineVariant variant[RS ::PRIMITIVE_MAX ] = { PIPELINE_VARIANT_ATTRIBUTE_POINTS , PIPELINE_VARIANT_ATTRIBUTE_LINES , PIPELINE_VARIANT_ATTRIBUTE_LINES_STRIP , PIPELINE_VARIANT_ATTRIBUTE_TRIANGLES , PIPELINE_VARIANT_ATTRIBUTE_TRIANGLE_STRIP };
29452937
@@ -3046,60 +3038,46 @@ void RendererCanvasRenderRD::_allocate_instance_buffer() {
30463038 state.canvas_instance_data_buffers [state.current_data_buffer_index ].instance_buffers .push_back (buf);
30473039}
30483040
3049- void RendererCanvasRenderRD::_prepare_batch_texture (Batch *p_current_batch, RID p_texture) const {
3041+ void RendererCanvasRenderRD::_prepare_batch_texture_info (Batch *p_current_batch, RID p_texture) const {
30503042 if (p_texture.is_null ()) {
30513043 p_texture = default_canvas_texture;
30523044 }
30533045
3054- Color specular_shininess;
3055- bool use_normal;
3056- bool use_specular;
3057- Size2i size;
3058- bool success = RendererRD::TextureStorage::get_singleton ()->canvas_texture_get_uniform_set (
3059- p_texture,
3060- p_current_batch->tex_state .texture_filter (),
3061- p_current_batch->tex_state .texture_repeat (),
3062- shader.default_version_rd_shader ,
3063- CANVAS_TEXTURE_UNIFORM_SET ,
3064- p_current_batch->tex_state .linear_colors (),
3065- p_current_batch->tex_uniform_set ,
3066- size,
3067- specular_shininess,
3068- use_normal,
3069- use_specular,
3070- p_current_batch->tex_state .texture_is_data ());
3046+ RendererRD::TextureStorage::CanvasTextureInfo info =
3047+ RendererRD::TextureStorage::get_singleton ()->canvas_texture_get_info (
3048+ p_texture,
3049+ p_current_batch->tex_info .state .texture_filter (),
3050+ p_current_batch->tex_info .state .texture_repeat (),
3051+ p_current_batch->tex_info .state .linear_colors (),
3052+ p_current_batch->tex_info .state .texture_is_data ());
3053+
30713054 // something odd happened
3072- if (!success ) {
3073- _prepare_batch_texture (p_current_batch, default_canvas_texture);
3055+ if (info. is_null () ) {
3056+ _prepare_batch_texture_info (p_current_batch, default_canvas_texture);
30743057 return ;
30753058 }
30763059
3077- // cache values to be copied to instance data
3078- if (specular_shininess. a < 0.999 ) {
3079- p_current_batch->tex_flags |= FLAGS_DEFAULT_SPECULAR_MAP_USED ;
3080- }
3060+ p_current_batch-> tex_info . diffuse = info. diffuse ;
3061+ p_current_batch-> tex_info . normal = info. normal ;
3062+ p_current_batch->tex_info . specular = info. specular ;
3063+ p_current_batch-> tex_info . sampler = info. sampler ;
30813064
3082- if (use_normal) {
3083- p_current_batch->tex_flags |= FLAGS_DEFAULT_NORMAL_MAP_USED ;
3065+ // cache values to be copied to instance data
3066+ if (info.specular_color .a < 0.999 ) {
3067+ p_current_batch->tex_info .flags |= FLAGS_DEFAULT_SPECULAR_MAP_USED ;
30843068 }
30853069
3086- uint8_t a = uint8_t (CLAMP (specular_shininess.a * 255.0 , 0.0 , 255.0 ));
3087- uint8_t b = uint8_t (CLAMP (specular_shininess.b * 255.0 , 0.0 , 255.0 ));
3088- uint8_t g = uint8_t (CLAMP (specular_shininess.g * 255.0 , 0.0 , 255.0 ));
3089- uint8_t r = uint8_t (CLAMP (specular_shininess.r * 255.0 , 0.0 , 255.0 ));
3090- p_current_batch->tex_specular_shininess = uint32_t (a) << 24 | uint32_t (b) << 16 | uint32_t (g) << 8 | uint32_t (r);
3091-
3092- p_current_batch->tex_texpixel_size = Vector2 (1.0 / float (size.width ), 1.0 / float (size.height ));
3093- }
3094-
3095- void RendererCanvasRenderRD::_bind_canvas_texture (RD ::DrawListID p_draw_list, RID p_uniform_set) {
3096- if (state.current_tex_uniform_set == p_uniform_set) {
3097- return ;
3070+ if (info.use_normal ) {
3071+ p_current_batch->tex_info .flags |= FLAGS_DEFAULT_NORMAL_MAP_USED ;
30983072 }
30993073
3100- state.current_tex_uniform_set = p_uniform_set;
3074+ uint8_t a = uint8_t (CLAMP (info.specular_color .a * 255.0 , 0.0 , 255.0 ));
3075+ uint8_t b = uint8_t (CLAMP (info.specular_color .b * 255.0 , 0.0 , 255.0 ));
3076+ uint8_t g = uint8_t (CLAMP (info.specular_color .g * 255.0 , 0.0 , 255.0 ));
3077+ uint8_t r = uint8_t (CLAMP (info.specular_color .r * 255.0 , 0.0 , 255.0 ));
3078+ p_current_batch->tex_info .specular_shininess = uint32_t (a) << 24 | uint32_t (b) << 16 | uint32_t (g) << 8 | uint32_t (r);
31013079
3102- RD::get_singleton ()-> draw_list_bind_uniform_set (p_draw_list, p_uniform_set, CANVAS_TEXTURE_UNIFORM_SET );
3080+ p_current_batch-> tex_info . texpixel_size = Vector2 ( 1.0 / float (info. size . width ), 1.0 / float (info. size . height ) );
31033081}
31043082
31053083RendererCanvasRenderRD::~RendererCanvasRenderRD () {
0 commit comments