@@ -164,16 +164,6 @@ TextureGLES::TextureGLES(std::shared_ptr<ReactorGLES> reactor,
164164 return ;
165165 }
166166
167- // One storage-tracking entry per slice: 6 for a cube, the layer count for an
168- // array, 1 otherwise.
169- const auto & tracked_desc = GetTextureDescriptor ();
170- size_t slice_count = 1u ;
171- if (tracked_desc.type == TextureType::kTextureCube ) {
172- slice_count = 6u ;
173- } else if (tracked_desc.type == TextureType::kTexture2DArray ) {
174- slice_count = tracked_desc.array_layer_count ;
175- }
176- slice_mip_initialized_.resize (slice_count);
177167 // Ensure the texture doesn't exceed device capabilities.
178168 const auto tex_size = GetTextureDescriptor ().size ;
179169 const auto max_size =
@@ -340,29 +330,30 @@ bool TextureGLES::OnSetContents(std::shared_ptr<const fml::Mapping> mapping,
340330 // requested layer (slice) of the already-allocated base mip level.
341331 if (format.is_compressed ) {
342332 gl.CompressedTexSubImage3D (
343- texture_target, // target
344- 0u , // LOD level
345- 0u , // x offset
346- 0u , // y offset
347- static_cast <GLint>(slice), // z offset (layer)
348- size.width , // width
349- size.height , // height
350- 1 , // depth (one layer)
351- format.internal_format , // format
352- image_size, // image size
353- tex_data); // data
333+ /* target= */ texture_target, //
334+ /* level= */ 0u , //
335+ /* xoffset= */ 0u , //
336+ /* yoffset= */ 0u , //
337+ /* zoffset= */ static_cast <GLint>(slice), //
338+ /* width= */ size.width , //
339+ /* height= */ size.height , //
340+ /* depth= */ 1 , //
341+ /* format= */ format .internal_format , //
342+ /* image_size= */ image_size , //
343+ /* data= */ tex_data); //
354344 } else {
355- gl.TexSubImage3D (texture_target, // target
356- 0u , // LOD level
357- 0u , // x offset
358- 0u , // y offset
359- static_cast <GLint>(slice), // z offset (layer)
360- size.width , // width
361- size.height , // height
362- 1 , // depth (one layer)
363- format.external_format , // format
364- format.type , // type
365- tex_data); // data
345+ gl.TexSubImage3D (
346+ /* target=*/ texture_target, //
347+ /* level=*/ 0u , //
348+ /* xoffset=*/ 0u , //
349+ /* yoffset=*/ 0u , //
350+ /* zoffset=*/ static_cast <GLint>(slice), //
351+ /* width=*/ size.width , //
352+ /* height=*/ size.height , //
353+ /* depth=*/ 1 , //
354+ /* format=*/ format.external_format , //
355+ /* type=*/ format.type , //
356+ /* data=*/ tex_data); //
366357 }
367358 } else if (format.is_compressed ) {
368359 gl.CompressedTexImage2D (texture_target, // target
@@ -525,21 +516,21 @@ void TextureGLES::InitializeContentsIfNecessary() {
525516 // glTexImage3D call; individual layers are then filled with
526517 // glTexSubImage3D. Non-zero mip levels are allocated lazily.
527518 gl.BindTexture (GL_TEXTURE_2D_ARRAY , handle.value ());
528- gl.TexImage3D (GL_TEXTURE_2D_ARRAY , // target
529- 0u , // LOD level
530- gles_format->internal_format , // internal
531- size.width , // width
532- size.height , // height
533- desc.array_layer_count , // depth/layers
534- 0u , // border
535- gles_format->external_format , // format
536- gles_format->type , // type
537- nullptr // data
519+ gl.TexImage3D (
520+ /* target=*/ GL_TEXTURE_2D_ARRAY , //
521+ /* level=*/ 0u , //
522+ /* internal_format=*/ gles_format->internal_format , //
523+ /* width=*/ size.width , //
524+ /* height=*/ size.height , //
525+ /* depth=*/ desc.array_layer_count , //
526+ /* border=*/ 0u , //
527+ /* format=*/ gles_format->external_format , //
528+ /* type=*/ gles_format->type , //
529+ /* data=*/ nullptr //
538530 );
539- for (size_t layer = 0 ;
540- layer < static_cast <size_t >(desc.array_layer_count ); ++layer) {
541- MarkSliceMipLevelInitialized (layer, 0 );
542- }
531+ // glTexImage3D allocated every layer of the base level at once, so a
532+ // single entry covers the whole level.
533+ MarkSliceMipLevelInitialized (0 , 0 );
543534 } else {
544535 // 2D / multisampled. External-OES textures are always wrapped, so
545536 // they returned at the is_wrapped_ check above. Only the base mip
@@ -760,24 +751,27 @@ bool TextureGLES::EnsureSliceMipLevelStorage(size_t slice, size_t mip_level) {
760751 static_cast <GLsizei>(std::max<int64_t >(1 , size.height >> mip_level));
761752
762753 if (desc.type == TextureType::kTexture2DArray ) {
763- // glTexImage3D allocates this mip level for every layer at once, so mark
764- // all layers initialized for this level.
754+ // glTexImage3D allocates this mip level for every layer at once, so a
755+ // single entry (slice 0) tracks the whole level regardless of which layer
756+ // was requested. Guard on that entry so a request for a non-zero layer
757+ // does not re-allocate and orphan already-uploaded layers.
758+ if (IsSliceMipLevelInitialized (0 , mip_level)) {
759+ return true ;
760+ }
765761 gl.BindTexture (GL_TEXTURE_2D_ARRAY , handle.value ());
766- gl.TexImage3D (GL_TEXTURE_2D_ARRAY , // target
767- static_cast <GLint>(mip_level), // LOD level
768- gles_format->internal_format , // internal
769- mip_width, // width
770- mip_height, // height
771- desc.array_layer_count , // depth/layers
772- 0u , // border
773- gles_format->external_format , // format
774- gles_format->type , // type
775- nullptr // data
762+ gl.TexImage3D (
763+ /* target=*/ GL_TEXTURE_2D_ARRAY , //
764+ /* level=*/ static_cast <GLint>(mip_level), //
765+ /* internal_format=*/ gles_format->internal_format , //
766+ /* width=*/ mip_width, //
767+ /* height=*/ mip_height, //
768+ /* depth=*/ desc.array_layer_count , //
769+ /* border=*/ 0u , //
770+ /* format=*/ gles_format->external_format , //
771+ /* type=*/ gles_format->type , //
772+ /* data=*/ nullptr //
776773 );
777- for (size_t layer = 0 ; layer < static_cast <size_t >(desc.array_layer_count );
778- ++layer) {
779- MarkSliceMipLevelInitialized (layer, mip_level);
780- }
774+ MarkSliceMipLevelInitialized (0 , mip_level);
781775 return true ;
782776 }
783777
0 commit comments