@@ -14270,7 +14270,17 @@ do_extract_texture_data(CLP(TextureContext) *gtc) {
1427014270 return false ;
1427114271 }
1427214272
14273- tex->set_ram_image (image, compression, page_size);
14273+ int num_views = tex->get_num_views ();
14274+ if (num_views == 1 ) {
14275+ // Replace the entire image, since we are modifying the only view.
14276+ tex->set_ram_image (image, compression, page_size);
14277+ } else {
14278+ // We're only modifying a single view, so we can't stomp all over the
14279+ // existing content.
14280+ PTA_uchar ram_image = tex->modify_ram_image ();
14281+ nassertr (ram_image.size () == image.size () * num_views, false );
14282+ memcpy (ram_image.p () + image.size () * gtc->get_view (), image.p (), image.size ());
14283+ }
1427414284
1427514285 if (gtc->_uses_mipmaps ) {
1427614286 // Also get the mipmap levels.
@@ -14286,7 +14296,12 @@ do_extract_texture_data(CLP(TextureContext) *gtc) {
1428614296 type, compression, n)) {
1428714297 return false ;
1428814298 }
14289- tex->set_ram_mipmap_image (n, image, page_size);
14299+ if (num_views == 1 ) {
14300+ tex->set_ram_mipmap_image (n, image, page_size);
14301+ } else {
14302+ PTA_uchar ram_mipmap_image = tex->modify_ram_mipmap_image (n);
14303+ memcpy (ram_mipmap_image.p () + image.size () * gtc->get_view (), image.p (), image.size ());
14304+ }
1429014305 }
1429114306 }
1429214307
@@ -14350,13 +14365,13 @@ extract_texture_image(PTA_uchar &image, size_t &page_size,
1435014365#ifndef OPENGLES
1435114366 } else if (target == GL_TEXTURE_BUFFER) {
1435214367 // In the case of a buffer texture, we need to get it from the buffer.
14353- image = PTA_uchar::empty_array (tex->get_expected_ram_mipmap_image_size (n));
14368+ image = PTA_uchar::empty_array (tex->get_expected_ram_mipmap_view_size (n));
1435414369 _glGetBufferSubData (target, 0 , image.size (), image.p ());
1435514370#endif
1435614371
1435714372 } else if (compression == Texture::CM_off) {
1435814373 // An uncompressed 1-d, 2-d, or 3-d texture.
14359- image = PTA_uchar::empty_array (tex->get_expected_ram_mipmap_image_size (n));
14374+ image = PTA_uchar::empty_array (tex->get_expected_ram_mipmap_view_size (n));
1436014375 GLenum external_format = get_external_image_format (tex);
1436114376 GLenum pixel_type = get_component_type (type);
1436214377 glGetTexImage (target, n, external_format, pixel_type, image.p ());
0 commit comments