@@ -230,6 +230,32 @@ TextureStorage::TextureStorage() {
230230 sdf_shader.shader_version = sdf_shader.shader .version_create ();
231231 }
232232
233+ // Initialize texture placeholder data for the `texture_*_placeholder_initialize()` methods.
234+
235+ constexpr int placeholder_size = 4 ;
236+ texture_2d_placeholder = Image::create_empty (placeholder_size, placeholder_size, false , Image::FORMAT_RGBA8);
237+ // Draw a magenta/black checkerboard pattern.
238+ for (int i = 0 ; i < placeholder_size * placeholder_size; i++) {
239+ const int x = i % placeholder_size;
240+ const int y = i / placeholder_size;
241+ texture_2d_placeholder->set_pixel (x, y, (x + y) % 2 == 0 ? Color (1 , 0 , 1 ) : Color (0 , 0 , 0 ));
242+ }
243+
244+ texture_2d_array_placeholder.push_back (texture_2d_placeholder);
245+
246+ for (int i = 0 ; i < 6 ; i++) {
247+ cubemap_placeholder.push_back (texture_2d_placeholder);
248+ }
249+
250+ Ref<Image> texture_2d_placeholder_rotated;
251+ texture_2d_placeholder_rotated.instantiate ();
252+ texture_2d_placeholder_rotated->copy_from (texture_2d_placeholder);
253+ texture_2d_placeholder_rotated->rotate_90 (CLOCKWISE);
254+ for (int i = 0 ; i < 4 ; i++) {
255+ // Alternate checkerboard pattern on odd layers (by using a copy that is rotated 90 degrees).
256+ texture_3d_placeholder.push_back (i % 2 == 0 ? texture_2d_placeholder : texture_2d_placeholder_rotated);
257+ }
258+
233259#ifdef GL_API_ENABLED
234260 if (RasterizerGLES3::is_gles_over_gl ()) {
235261 glEnable (GL_PROGRAM_POINT_SIZE);
@@ -1014,46 +1040,19 @@ void TextureStorage::texture_proxy_update(RID p_texture, RID p_proxy_to) {
10141040}
10151041
10161042void TextureStorage::texture_2d_placeholder_initialize (RID p_texture) {
1017- // this could be better optimized to reuse an existing image , done this way
1018- // for now to get it working
1019- Ref<Image> image = Image::create_empty (4 , 4 , false , Image::FORMAT_RGBA8);
1020- image->fill (Color (1 , 0 , 1 , 1 ));
1021-
1022- texture_2d_initialize (p_texture, image);
1043+ texture_2d_initialize (p_texture, texture_2d_placeholder);
10231044}
10241045
1025- void TextureStorage::texture_2d_layered_placeholder_initialize (RID p_texture, RenderingServer::TextureLayeredType p_layered_type) {
1026- // this could be better optimized to reuse an existing image , done this way
1027- // for now to get it working
1028- Ref<Image> image = Image::create_empty (4 , 4 , false , Image::FORMAT_RGBA8);
1029- image->fill (Color (1 , 0 , 1 , 1 ));
1030-
1031- Vector<Ref<Image>> images;
1046+ void TextureStorage::texture_2d_layered_placeholder_initialize (RID p_texture, RS::TextureLayeredType p_layered_type) {
10321047 if (p_layered_type == RS::TEXTURE_LAYERED_2D_ARRAY) {
1033- images. push_back (image );
1048+ texture_2d_layered_initialize (p_texture, texture_2d_array_placeholder, p_layered_type );
10341049 } else {
1035- // cube
1036- for (int i = 0 ; i < 6 ; i++) {
1037- images.push_back (image);
1038- }
1050+ texture_2d_layered_initialize (p_texture, cubemap_placeholder, p_layered_type);
10391051 }
1040-
1041- texture_2d_layered_initialize (p_texture, images, p_layered_type);
10421052}
10431053
10441054void TextureStorage::texture_3d_placeholder_initialize (RID p_texture) {
1045- // this could be better optimized to reuse an existing image , done this way
1046- // for now to get it working
1047- Ref<Image> image = Image::create_empty (4 , 4 , false , Image::FORMAT_RGBA8);
1048- image->fill (Color (1 , 0 , 1 , 1 ));
1049-
1050- Vector<Ref<Image>> images;
1051- // cube
1052- for (int i = 0 ; i < 4 ; i++) {
1053- images.push_back (image);
1054- }
1055-
1056- texture_3d_initialize (p_texture, Image::FORMAT_RGBA8, 4 , 4 , 4 , false , images);
1055+ texture_3d_initialize (p_texture, Image::FORMAT_RGBA8, 4 , 4 , 4 , false , texture_3d_placeholder);
10571056}
10581057
10591058Ref<Image> TextureStorage::texture_2d_get (RID p_texture) const {
0 commit comments