Skip to content
Permalink
Browse files

gobj: make ram image when writing texture with clear color to 6.44 bam

This makes it possible to write textures with clear colors to .bam files even when the default bam version of 6.44 is selected.  The clear color is converted automatically to a filled RAM image.

Third part of the fix for #844
  • Loading branch information
rdb committed Mar 18, 2020
1 parent 707b4fb commit eeeea274a472c1b9ef61b115f7cdf9b0212e6d80
Showing with 25 additions and 5 deletions.
  1. +25 −5 panda/src/gobj/texture.cxx
@@ -10055,11 +10055,31 @@ do_write_datagram_rawdata(CData *cdata, BamWriter *manager, Datagram &me) {
me.add_uint8(cdata->_component_type);
me.add_uint8(cdata->_component_width);
me.add_uint8(cdata->_ram_image_compression);
me.add_uint8(cdata->_ram_images.size());
for (size_t n = 0; n < cdata->_ram_images.size(); ++n) {
me.add_uint32(cdata->_ram_images[n]._page_size);
me.add_uint32(cdata->_ram_images[n]._image.size());
me.append_data(cdata->_ram_images[n]._image, cdata->_ram_images[n]._image.size());

if (cdata->_ram_images.empty() && cdata->_has_clear_color &&
manager->get_file_minor_ver() < 45) {
// For older .bam versions that don't support clear colors, make up a RAM
// image.
int image_size = do_get_expected_ram_image_size(cdata);
me.add_uint8(1);
me.add_uint32(do_get_expected_ram_page_size(cdata));
me.add_uint32(image_size);

// Fill the image with the clear color.
unsigned char pixel[16];
const int pixel_size = do_get_clear_data(cdata, pixel);
nassertv(pixel_size > 0);

for (int i = 0; i < image_size; i += pixel_size) {
me.append_data(pixel, pixel_size);
}
} else {
me.add_uint8(cdata->_ram_images.size());
for (size_t n = 0; n < cdata->_ram_images.size(); ++n) {
me.add_uint32(cdata->_ram_images[n]._page_size);
me.add_uint32(cdata->_ram_images[n]._image.size());
me.append_data(cdata->_ram_images[n]._image, cdata->_ram_images[n]._image.size());
}
}
}

0 comments on commit eeeea27

Please sign in to comment.
You can’t perform that action at this time.