From 47de3542f6ff1154152275ddadfbabbc938a7651 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 26 Jan 2016 11:15:22 +0100 Subject: [PATCH 1/5] Apply tobspr's texture memory calculation fixes to 1.9 branch --- .../glstuff/glGraphicsStateGuardian_src.cxx | 2 ++ panda/src/gobj/texture.cxx | 23 ++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 429d2e9db8..de97d8cf79 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -10854,6 +10854,8 @@ upload_texture(CLP(TextureContext) *gtc, bool force, bool uses_mipmaps) { gtc->_width = width; gtc->_height = height; gtc->_depth = depth; + gtc->update_data_size_bytes(get_texture_memory_size(gtc)); + needs_reload = false; } } else { diff --git a/panda/src/gobj/texture.cxx b/panda/src/gobj/texture.cxx index 4131da068c..539195dcfd 100644 --- a/panda/src/gobj/texture.cxx +++ b/panda/src/gobj/texture.cxx @@ -489,7 +489,7 @@ read(const Filename &fullpath, const Filename &alpha_fullpath, size_t Texture:: estimate_texture_memory() const { CDReader cdata(_cycler); - size_t pixels = cdata->_x_size * cdata->_y_size; + size_t pixels = cdata->_x_size * cdata->_y_size * cdata->_z_size; size_t bpp = 4; switch (cdata->_format) { @@ -503,22 +503,25 @@ estimate_texture_memory() const { case Texture::F_blue: case Texture::F_luminance: case Texture::F_sluminance: + case Texture::F_r8i: bpp = 1; break; case Texture::F_luminance_alpha: case Texture::F_luminance_alphamask: case Texture::F_sluminance_alpha: + case Texture::F_rgba4: + case Texture::F_rgb5: + case Texture::F_rgba5: bpp = 2; break; case Texture::F_rgba: - case Texture::F_rgba4: case Texture::F_rgbm: case Texture::F_rgb: - case Texture::F_rgb5: - case Texture::F_rgba5: case Texture::F_srgb: + // Most of the above formats have only 3 bytes, but they are most likely to + // get padded by the driver bpp = 4; break; @@ -536,9 +539,15 @@ estimate_texture_memory() const { break; case Texture::F_depth_component: + case Texture::F_depth_component16: bpp = 2; break; + case Texture::F_depth_component24: // Gets padded + case Texture::F_depth_component32: + bpp = 4; + break; + case Texture::F_rgba12: case Texture::F_rgb12: bpp = 8; @@ -552,7 +561,6 @@ estimate_texture_memory() const { break; case Texture::F_r16: - case Texture::F_r8i: case Texture::F_rg8i: bpp = 2; break; @@ -564,15 +572,14 @@ estimate_texture_memory() const { break; case Texture::F_r32i: - bpp = 4; - break; - case Texture::F_r32: bpp = 4; break; + case Texture::F_rg32: bpp = 8; break; + case Texture::F_rgb32: bpp = 12; break; From a55d915aeaf5f88faa332b9afb3f66434b7c6bf2 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 26 Jan 2016 11:17:57 +0100 Subject: [PATCH 2/5] Add missing CDistributedSmoothNodeBase import --- direct/src/distributed/DistributedSmoothNodeBase.py | 1 + 1 file changed, 1 insertion(+) diff --git a/direct/src/distributed/DistributedSmoothNodeBase.py b/direct/src/distributed/DistributedSmoothNodeBase.py index c8338fa8c9..c4c2309a9e 100755 --- a/direct/src/distributed/DistributedSmoothNodeBase.py +++ b/direct/src/distributed/DistributedSmoothNodeBase.py @@ -3,6 +3,7 @@ from ClockDelta import * from direct.task import Task from direct.showbase.PythonUtil import randFloat, Enum +from panda3d.direct import CDistributedSmoothNodeBase class DummyTaskClass: def setDelay(self, blah): From ea368dd5592828277d967336ba90e3c8d639c790 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 26 Jan 2016 11:32:51 +0100 Subject: [PATCH 3/5] Bam reader robustness; allow threaded bam reading from Python --- panda/src/pgraph/pandaNode.cxx | 3 +++ panda/src/putil/bamReader.cxx | 25 +++++++++++++++++++++++++ panda/src/putil/bamReader.h | 6 +++--- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/panda/src/pgraph/pandaNode.cxx b/panda/src/pgraph/pandaNode.cxx index d4c683f7ad..e7bd9d80c7 100644 --- a/panda/src/pgraph/pandaNode.cxx +++ b/panda/src/pgraph/pandaNode.cxx @@ -4465,6 +4465,9 @@ complete_pointers(TypedWritable **p_list, BamReader *manager) { set_fancy_bit(FB_effects, !_effects->is_empty()); set_fancy_bit(FB_tag, !_tag_data.empty()); + // Mark the bounds stale. + ++_next_update; + return pi; } diff --git a/panda/src/putil/bamReader.cxx b/panda/src/putil/bamReader.cxx index 1230bbc9a6..1dca417c6f 100644 --- a/panda/src/putil/bamReader.cxx +++ b/panda/src/putil/bamReader.cxx @@ -142,6 +142,12 @@ init() { _file_stdfloat_double = scan.get_bool(); } + if (scan.get_current_index() > header.get_length()) { + bam_cat.error() + << "Bam header is too short.\n"; + return false; + } + return true; } @@ -1230,6 +1236,12 @@ p_read_object() { int object_id = read_object_id(scan); + if (scan.get_current_index() > dg.get_length()) { + bam_cat.error() + << "Found truncated datagram in bam stream\n"; + return 0; + } + // There are two cases (not counting the special _remove_flag case, // above). Either this is a new object definition, or this is a // reference to an object that was previously defined. @@ -1271,6 +1283,12 @@ p_read_object() { created_obj._ptr->fillin(scan, this); _now_creating = was_creating; + if (scan.get_remaining_size() > 0) { + bam_cat.warning() + << "Skipping " << scan.get_remaining_size() << " remaining bytes " + << "in datagram containing type " << type << "\n"; + } + } else { // We are receiving a new object. Now we can call the factory // to create the object. @@ -1371,6 +1389,13 @@ p_read_object() { } } } + + // Sanity check that we read the expected number of bytes. + if (scan.get_current_index() > dg.get_length()) { + bam_cat.error() + << "End of datagram reached while reading bam object " + << type << ": " << (void *)created_obj._ptr << "\n"; + } } return object_id; diff --git a/panda/src/putil/bamReader.h b/panda/src/putil/bamReader.h index 30a9dd157c..f70bb4e9b9 100644 --- a/panda/src/putil/bamReader.h +++ b/panda/src/putil/bamReader.h @@ -143,9 +143,9 @@ PUBLISHED: INLINE const LoaderOptions &get_loader_options() const; INLINE void set_loader_options(const LoaderOptions &options); - - TypedWritable *read_object(); - bool read_object(TypedWritable *&ptr, ReferenceCount *&ref_ptr); + + BLOCKING TypedWritable *read_object(); + BLOCKING bool read_object(TypedWritable *&ptr, ReferenceCount *&ref_ptr); INLINE bool is_eof() const; bool resolve(); From d574dd4b0b03c24038ab261eb7e9b0c9b1e58594 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 26 Jan 2016 11:39:19 +0100 Subject: [PATCH 4/5] Fix texture format selection in FrameBufferProperties --- panda/src/display/frameBufferProperties.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/panda/src/display/frameBufferProperties.cxx b/panda/src/display/frameBufferProperties.cxx index d5cc37a97a..b8e1b41f66 100644 --- a/panda/src/display/frameBufferProperties.cxx +++ b/panda/src/display/frameBufferProperties.cxx @@ -720,7 +720,7 @@ setup_color_texture(Texture *tex) const { { 1, 1, 1, 1, 0, false, Texture::F_rgb }, { 1, 1, 1, 1, 1, false, Texture::F_rgba }, { 24, 8, 8, 8, 0, false, Texture::F_rgb8 }, - { 24, 8, 8, 8, 8, false, Texture::F_rgba8 }, + { 32, 8, 8, 8, 8, false, Texture::F_rgba8 }, { 16, 16, 0, 0, 0, true, Texture::F_r16 }, { 32, 16, 16, 0, 0, true, Texture::F_rg16 }, { 48, 16, 16, 16, 0, true, Texture::F_rgb16 }, From 375baaaabd2897b95d149d549bdf01827bb9b8b5 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 26 Jan 2016 11:39:50 +0100 Subject: [PATCH 5/5] Fix constant reloading of texture when using gl-ignore-mipmaps --- panda/src/glstuff/glGraphicsStateGuardian_src.cxx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index de97d8cf79..89aa92092f 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -10526,9 +10526,13 @@ apply_sampler(GLuint unit, const SamplerState &sampler, TextureContext *tc) { } } - if (sampler.uses_mipmaps() && !gtc->_uses_mipmaps) { + if (sampler.uses_mipmaps() && !gtc->_uses_mipmaps && !gl_ignore_mipmaps) { // The texture wasn't created with mipmaps, but we are trying // to sample it with mipmaps. We will need to reload it. + GLCAT.info() + << "reloading texture " << gtc->get_texture()->get_name() + << " with mipmaps\n"; + apply_texture(tc); gtc->mark_needs_reload(); bool okflag = upload_texture(gtc, false, true);