From 2d836697b0ce577a43b554d44b209c48c500f3cf Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 10 Nov 2019 19:20:10 +0100 Subject: [PATCH] glgsg: fix issue extracting texture data for multiview textures --- .../glstuff/glGraphicsStateGuardian_src.cxx | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index abb6d2e71a..b510d9d4b9 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -14270,7 +14270,17 @@ do_extract_texture_data(CLP(TextureContext) *gtc) { return false; } - tex->set_ram_image(image, compression, page_size); + int num_views = tex->get_num_views(); + if (num_views == 1) { + // Replace the entire image, since we are modifying the only view. + tex->set_ram_image(image, compression, page_size); + } else { + // We're only modifying a single view, so we can't stomp all over the + // existing content. + PTA_uchar ram_image = tex->modify_ram_image(); + nassertr(ram_image.size() == image.size() * num_views, false); + memcpy(ram_image.p() + image.size() * gtc->get_view(), image.p(), image.size()); + } if (gtc->_uses_mipmaps) { // Also get the mipmap levels. @@ -14286,7 +14296,12 @@ do_extract_texture_data(CLP(TextureContext) *gtc) { type, compression, n)) { return false; } - tex->set_ram_mipmap_image(n, image, page_size); + if (num_views == 1) { + tex->set_ram_mipmap_image(n, image, page_size); + } else { + PTA_uchar ram_mipmap_image = tex->modify_ram_mipmap_image(n); + memcpy(ram_mipmap_image.p() + image.size() * gtc->get_view(), image.p(), image.size()); + } } } @@ -14350,13 +14365,13 @@ extract_texture_image(PTA_uchar &image, size_t &page_size, #ifndef OPENGLES } else if (target == GL_TEXTURE_BUFFER) { // In the case of a buffer texture, we need to get it from the buffer. - image = PTA_uchar::empty_array(tex->get_expected_ram_mipmap_image_size(n)); + image = PTA_uchar::empty_array(tex->get_expected_ram_mipmap_view_size(n)); _glGetBufferSubData(target, 0, image.size(), image.p()); #endif } else if (compression == Texture::CM_off) { // An uncompressed 1-d, 2-d, or 3-d texture. - image = PTA_uchar::empty_array(tex->get_expected_ram_mipmap_image_size(n)); + image = PTA_uchar::empty_array(tex->get_expected_ram_mipmap_view_size(n)); GLenum external_format = get_external_image_format(tex); GLenum pixel_type = get_component_type(type); glGetTexImage(target, n, external_format, pixel_type, image.p());