From 9a53a3bf3194ed9559722e465c660dd24b7ec5df Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 24 Oct 2022 13:43:29 +0200 Subject: [PATCH 1/7] cppparser: Fix an instance of pvector being used instead of `std::vector` Also see #539 (but doesn't fully resolve this case because DSearchPath also uses pvector) [skip ci] --- dtool/src/cppparser/cppPreprocessor.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dtool/src/cppparser/cppPreprocessor.h b/dtool/src/cppparser/cppPreprocessor.h index 3102386fee..92986cf4c8 100644 --- a/dtool/src/cppparser/cppPreprocessor.h +++ b/dtool/src/cppparser/cppPreprocessor.h @@ -72,10 +72,10 @@ public: typedef std::map Manifests; Manifests _manifests; - typedef pvector ManifestStack; + typedef std::vector ManifestStack; std::map _manifest_stack; - pvector _quote_include_kind; + std::vector _quote_include_kind; DSearchPath _quote_include_path; DSearchPath _angle_include_path; bool _noangles; From cc24b5373d3b9bc71a5b10a8725581dabfd90b5c Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 25 Oct 2022 11:34:10 +0200 Subject: [PATCH 2/7] pgraph: Fix `PandaNode::_nested_vertices` not updating properly The problem was that `PandaNode::update_cached()` queries the node's `_internal_vertices` *before* calling `get_internal_bounds()` (which is what actually calculates it). --- panda/src/pgraph/pandaNode.cxx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/panda/src/pgraph/pandaNode.cxx b/panda/src/pgraph/pandaNode.cxx index 2c0c89d099..241758971a 100644 --- a/panda/src/pgraph/pandaNode.cxx +++ b/panda/src/pgraph/pandaNode.cxx @@ -3262,8 +3262,6 @@ update_cached(bool update_bounds, int pipeline_stage, PandaNode::CDLockedStageRe // Also get the list of the node's children. Children children(cdata); - int num_vertices = cdata->_internal_vertices; - // Now that we've got all the data we need from the node, we can release // the lock. _cycler.release_read_stage(pipeline_stage, cdata.take_pointer()); @@ -3303,6 +3301,7 @@ update_cached(bool update_bounds, int pipeline_stage, PandaNode::CDLockedStageRe } // Now expand those contents to include all of our children. + int child_vertices = 0; for (int i = 0; i < num_children; ++i) { PandaNode *child = children.get_child(i); @@ -3398,7 +3397,7 @@ update_cached(bool update_bounds, int pipeline_stage, PandaNode::CDLockedStageRe all_box = false; } } - num_vertices += child_cdataw->_nested_vertices; + child_vertices += child_cdataw->_nested_vertices; } } else { @@ -3453,7 +3452,7 @@ update_cached(bool update_bounds, int pipeline_stage, PandaNode::CDLockedStageRe all_box = false; } } - num_vertices += child_cdata->_nested_vertices; + child_vertices += child_cdata->_nested_vertices; } } } @@ -3503,7 +3502,7 @@ update_cached(bool update_bounds, int pipeline_stage, PandaNode::CDLockedStageRe cdataw->_off_clip_planes = off_clip_planes; if (update_bounds) { - cdataw->_nested_vertices = num_vertices; + cdataw->_nested_vertices = cdataw->_internal_vertices + child_vertices; CPT(TransformState) transform = get_transform(current_thread); PT(GeometricBoundingVolume) gbv; From ef9c9fa20ec434f396743f2938258f076f9fee79 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 25 Oct 2022 12:08:06 +0200 Subject: [PATCH 3/7] bullet: Fix `BulletWheel::empty()` referencing local objects --- panda/src/bullet/bulletWheel.I | 14 -------------- panda/src/bullet/bulletWheel.cxx | 13 +++++++++++++ panda/src/bullet/bulletWheel.h | 2 +- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/panda/src/bullet/bulletWheel.I b/panda/src/bullet/bulletWheel.I index 0523ba9727..1e54d62d1b 100644 --- a/panda/src/bullet/bulletWheel.I +++ b/panda/src/bullet/bulletWheel.I @@ -26,17 +26,3 @@ INLINE BulletWheelRaycastInfo:: ~BulletWheelRaycastInfo() { } - -/** - * Named constructor intended to be used for asserts with have to return a - * concrete value. - */ -INLINE BulletWheel BulletWheel:: -empty() { - - btWheelInfoConstructionInfo ci {}; - btWheelInfo info(ci); - - return BulletWheel(info); -} - diff --git a/panda/src/bullet/bulletWheel.cxx b/panda/src/bullet/bulletWheel.cxx index 21a6eefd76..afeaffa785 100644 --- a/panda/src/bullet/bulletWheel.cxx +++ b/panda/src/bullet/bulletWheel.cxx @@ -23,6 +23,19 @@ BulletWheel(btWheelInfo &info) : _info(info) { } +/** + * Named constructor intended to be used for asserts with have to return a + * concrete value. + */ +BulletWheel BulletWheel:: +empty() { + + static btWheelInfoConstructionInfo ci {}; + static btWheelInfo info(ci); + + return BulletWheel(info); +} + /** * */ diff --git a/panda/src/bullet/bulletWheel.h b/panda/src/bullet/bulletWheel.h index 414ecd94f3..41564fd9d5 100644 --- a/panda/src/bullet/bulletWheel.h +++ b/panda/src/bullet/bulletWheel.h @@ -143,7 +143,7 @@ PUBLISHED: public: BulletWheel(btWheelInfo &info); - INLINE static BulletWheel empty(); + static BulletWheel empty(); private: btWheelInfo &_info; From 693b4d3fb386f6cbebe04d30665b6cba460ebc42 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 25 Oct 2022 12:08:38 +0200 Subject: [PATCH 4/7] bullet: Fix `BulletAllHitsRayResult::empty()` compiler warning --- panda/src/bullet/bulletAllHitsRayResult.I | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/panda/src/bullet/bulletAllHitsRayResult.I b/panda/src/bullet/bulletAllHitsRayResult.I index d2da8644b5..e8ad767b16 100644 --- a/panda/src/bullet/bulletAllHitsRayResult.I +++ b/panda/src/bullet/bulletAllHitsRayResult.I @@ -18,10 +18,7 @@ INLINE BulletAllHitsRayResult BulletAllHitsRayResult:: empty() { - btVector3 from; - btVector3 to; - - return BulletAllHitsRayResult(from, to, CollideMask::all_on()); + return BulletAllHitsRayResult(btVector3(0, 0, 0), btVector3(0, 0, 0), CollideMask::all_on()); } /** From 1a72311243c44912141a4279f962f2a3b20510ef Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 25 Oct 2022 12:10:44 +0200 Subject: [PATCH 5/7] bullet: Fix LMatrix3<>btMatrix3x3 conversion functions --- panda/src/bullet/bullet_utils.cxx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/panda/src/bullet/bullet_utils.cxx b/panda/src/bullet/bullet_utils.cxx index 74ee184594..eb27186446 100644 --- a/panda/src/bullet/bullet_utils.cxx +++ b/panda/src/bullet/bullet_utils.cxx @@ -60,8 +60,9 @@ LPoint3 btVector3_to_LPoint3(const btVector3 &p) { */ btMatrix3x3 LMatrix3_to_btMatrix3x3(const LMatrix3 &m) { + LMatrix4 m4(m); btMatrix3x3 result; - result.setFromOpenGLSubMatrix((const btScalar *)m.get_data()); + result.setFromOpenGLSubMatrix((const btScalar *)m4.get_data()); return result; } @@ -70,11 +71,11 @@ btMatrix3x3 LMatrix3_to_btMatrix3x3(const LMatrix3 &m) { */ LMatrix3 btMatrix3x3_to_LMatrix3(const btMatrix3x3 &m) { - btScalar cells[9]; + btScalar cells[12]; m.getOpenGLSubMatrix(cells); return LMatrix3((PN_stdfloat)cells[0], (PN_stdfloat)cells[1], (PN_stdfloat)cells[2], - (PN_stdfloat)cells[3], (PN_stdfloat)cells[4], (PN_stdfloat)cells[5], - (PN_stdfloat)cells[6], (PN_stdfloat)cells[7], (PN_stdfloat)cells[8]); + (PN_stdfloat)cells[4], (PN_stdfloat)cells[5], (PN_stdfloat)cells[6], + (PN_stdfloat)cells[8], (PN_stdfloat)cells[9], (PN_stdfloat)cells[10]); } /** From 4d2a45f1242c0676a76a9c08efda990acf0b47e1 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 25 Oct 2022 16:25:50 +0200 Subject: [PATCH 6/7] glgsg: Fix multisample FBOs with MRT blitting aux target into color target --- panda/src/glstuff/glGraphicsBuffer_src.cxx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/panda/src/glstuff/glGraphicsBuffer_src.cxx b/panda/src/glstuff/glGraphicsBuffer_src.cxx index 957f40772a..b66be51b3c 100644 --- a/panda/src/glstuff/glGraphicsBuffer_src.cxx +++ b/panda/src/glstuff/glGraphicsBuffer_src.cxx @@ -2007,11 +2007,22 @@ resolve_multisamples() { } } +#ifndef OPENGLES + if (_have_any_color) { + glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); + glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); + } else { + glDrawBuffer(GL_NONE); + glReadBuffer(GL_NONE); + } +#endif + if (do_depth_blit) { glgsg->_glBlitFramebuffer(0, 0, _rb_size_x, _rb_size_y, 0, 0, _rb_size_x, _rb_size_y, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST); - } else { + } + else if (_have_any_color) { glgsg->_glBlitFramebuffer(0, 0, _rb_size_x, _rb_size_y, 0, 0, _rb_size_x, _rb_size_y, GL_COLOR_BUFFER_BIT, GL_NEAREST); From a71b417aecc9f23d093af13e63f8d17caa7de87c Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 25 Oct 2022 16:26:30 +0200 Subject: [PATCH 7/7] filter: Add "MSAA" filter to CommonFilters This provides an easy way to enable MSAA for the offscreen color buffer only without having to enable it on the main window. When using this filter, it is important to have framebuffer-multisample turned off in Config.prc. --- direct/src/filter/CommonFilters.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/direct/src/filter/CommonFilters.py b/direct/src/filter/CommonFilters.py index ce4b9078c8..c5313d0662 100644 --- a/direct/src/filter/CommonFilters.py +++ b/direct/src/filter/CommonFilters.py @@ -26,7 +26,7 @@ from .filterCopy import COPY from .filterDown4 import DOWN_4 from panda3d.core import LVecBase4, LPoint2 from panda3d.core import Filename -from panda3d.core import AuxBitplaneAttrib +from panda3d.core import AuxBitplaneAttrib, AntialiasAttrib from panda3d.core import Texture, Shader, ATSNone from panda3d.core import FrameBufferProperties from panda3d.core import getDefaultCoordinateSystem, CS_zup_right, CS_zup_left @@ -189,11 +189,22 @@ class CommonFilters: fbprops.setSrgbColor(False) clamping = False + if "MSAA" in configuration: + if fbprops is None: + fbprops = FrameBufferProperties() + fbprops.setMultisamples(configuration["MSAA"].samples) + self.finalQuad = self.manager.renderSceneInto(textures = self.textures, auxbits=auxbits, fbprops=fbprops, clamping=clamping) if (self.finalQuad == None): self.cleanup() return False + if "MSAA" in configuration: + camNode = self.manager.camera.node() + state = camNode.getInitialState() + state.setAttrib(AntialiasAttrib.make(AntialiasAttrib.M_multisample)) + camNode.setInitialState(state) + if ("BlurSharpen" in configuration): blur0=self.textures["blur0"] blur1=self.textures["blur1"] @@ -454,6 +465,19 @@ class CommonFilters: if task != None: return task.cont + def setMSAA(self, samples): + fullrebuild = "MSAA" not in self.configuration or self.configuration["MSAA"].samples != samples + newconfig = FilterConfig() + newconfig.samples = samples + self.configuration["MSAA"] = newconfig + return self.reconfigure(fullrebuild, "MSAA") + + def delMSAA(self): + if "MSAA" in self.configuration: + del self.configuration["MSAA"] + return self.reconfigure(True, "MSAA") + return True + def setCartoonInk(self, separation=1, color=(0, 0, 0, 1)): fullrebuild = (("CartoonInk" in self.configuration) == False) newconfig = FilterConfig() @@ -673,6 +697,8 @@ class CommonFilters: return True #snake_case alias: + set_msaa = setMSAA + del_msaa = delMSAA del_cartoon_ink = delCartoonInk set_half_pixel_shift = setHalfPixelShift del_half_pixel_shift = delHalfPixelShift