From 52c0e2759edffa0edcc467f58be0b8715922abdb Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 16 Mar 2021 18:45:27 +0100 Subject: [PATCH 01/14] glgsg: Fix copy-to-texture/ram for multisample FBO Should read from resolved FBO, not from multisample FBO Fixes #1129 --- panda/src/glstuff/glGraphicsBuffer_src.cxx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/panda/src/glstuff/glGraphicsBuffer_src.cxx b/panda/src/glstuff/glGraphicsBuffer_src.cxx index 7413fef56e..ff28f4c192 100644 --- a/panda/src/glstuff/glGraphicsBuffer_src.cxx +++ b/panda/src/glstuff/glGraphicsBuffer_src.cxx @@ -1937,6 +1937,9 @@ resolve_multisamples() { #endif report_my_gl_errors(); + // Bind the regular FBO as read buffer for the sake of copy_to_textures. + glgsg->_glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, fbo); + #ifndef OPENGLES if (_have_any_color) { glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); From 1c754738bd44be0410f1451266c1bb548dcd7cf1 Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 21 Mar 2021 13:00:08 +0100 Subject: [PATCH 02/14] physics: Prevent adding same Physical to more than one PhysicalNode Also silently ignore if the same Physical is added to the same PhysicalNode more than once. --- panda/src/physics/physicalNode.I | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/panda/src/physics/physicalNode.I b/panda/src/physics/physicalNode.I index 407cf52f5a..0808fd51a2 100644 --- a/panda/src/physics/physicalNode.I +++ b/panda/src/physics/physicalNode.I @@ -42,10 +42,14 @@ get_num_physicals() const { } /** - + * Adds a Physical to this PhysicalNode. If it is already added to this node, + * does nothing. It is an error to add a Physical to multiple PhysicalNodes. */ INLINE void PhysicalNode:: add_physical(Physical *physical) { - _physicals.push_back(physical); - physical->_physical_node = this; + if (physical->_physical_node != this) { + nassertv(physical->_physical_node == nullptr); + _physicals.push_back(physical); + physical->_physical_node = this; + } } From b6a118448dce974d25c1d5ae4043baa6dfe12db0 Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 21 Mar 2021 14:35:28 +0100 Subject: [PATCH 03/14] physics: Warn when copying PhysicalNode with physicals attached We can't currently support this because a Physical can have only one PhysicalNode associated. --- panda/src/physics/physicalNode.cxx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/panda/src/physics/physicalNode.cxx b/panda/src/physics/physicalNode.cxx index 0fcabeeb8a..1fcd1ce903 100644 --- a/panda/src/physics/physicalNode.cxx +++ b/panda/src/physics/physicalNode.cxx @@ -14,7 +14,11 @@ #include "physicalNode.h" #include "physicsManager.h" +#include + // static stuff. +static std::atomic_flag warned_copy_physical_node = ATOMIC_FLAG_INIT; + TypeHandle PhysicalNode::_type_handle; /** @@ -55,6 +59,12 @@ PhysicalNode:: */ PandaNode *PhysicalNode:: make_copy() const { + if (!_physicals.empty() && !warned_copy_physical_node.test_and_set()) { + // This is a problem, because a Physical can only be on one PhysicalNode. + //FIXME: Figure out a solution. + physics_cat.warning() + << "Detected attempt to copy PhysicalNode object with physicals.\n"; + } return new PhysicalNode(*this); } From 74910ff310dc3d769151336fd642d1f3c17622a8 Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 21 Mar 2021 14:36:14 +0100 Subject: [PATCH 04/14] physics: Don't assert destructing This could have been produced with make_copy(), which can create a situation where the Physical objects don't have the same node associated -- see b6a118448dce974d25c1d5ae4043baa6dfe12db0 --- panda/src/physics/physicalNode.cxx | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/panda/src/physics/physicalNode.cxx b/panda/src/physics/physicalNode.cxx index 1fcd1ce903..bda2dd9140 100644 --- a/panda/src/physics/physicalNode.cxx +++ b/panda/src/physics/physicalNode.cxx @@ -43,13 +43,12 @@ PhysicalNode(const PhysicalNode ©) : */ PhysicalNode:: ~PhysicalNode() { - PhysicalsVector::iterator it; - for (it = _physicals.begin(); it != _physicals.end(); ++it) { - Physical *physical = *it; - nassertd(physical->_physical_node == this) continue; - physical->_physical_node = nullptr; - if (physical->_physics_manager != nullptr) { - physical->_physics_manager->remove_physical(physical); + for (Physical *physical : _physicals) { + if (physical->_physical_node == this) { + physical->_physical_node = nullptr; + if (physical->_physics_manager != nullptr) { + physical->_physics_manager->remove_physical(physical); + } } } } From f1782d73e5d6e943d0d75ded07fb7cb7cac6115b Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 21 Mar 2021 14:39:31 +0100 Subject: [PATCH 05/14] physics: Fix crash in PhysicsNode::add_physicals_from() --- panda/src/physics/physicalNode.cxx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/panda/src/physics/physicalNode.cxx b/panda/src/physics/physicalNode.cxx index bda2dd9140..18858b6201 100644 --- a/panda/src/physics/physicalNode.cxx +++ b/panda/src/physics/physicalNode.cxx @@ -72,13 +72,12 @@ make_copy() const { */ void PhysicalNode:: add_physicals_from(const PhysicalNode &other) { - pvector< PT(Physical) >::iterator last = _physicals.end() - 1; - + size_t num_physicals = _physicals.size(); _physicals.insert(_physicals.end(), other._physicals.begin(), other._physicals.end()); - for (; last != _physicals.end(); last++) { - (*last)->_physical_node = this; + for (size_t i = num_physicals; i < _physicals.size(); ++i) { + _physicals[i]->_physical_node = this; } } From db2936a318c528e475d9f2efbea76c122dc1718f Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 21 Mar 2021 14:39:57 +0100 Subject: [PATCH 06/14] physics: Slight code cleanup in PhysicalNode::clear() --- panda/src/physics/physicalNode.I | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/panda/src/physics/physicalNode.I b/panda/src/physics/physicalNode.I index 0808fd51a2..d4d7e6c879 100644 --- a/panda/src/physics/physicalNode.I +++ b/panda/src/physics/physicalNode.I @@ -16,12 +16,11 @@ */ INLINE void PhysicalNode:: clear() { - PhysicalsVector::iterator it; - for (it = _physicals.begin(); it != _physicals.end(); ++it) { - nassertd((*it)->_physical_node == this) continue; - (*it)->_physical_node = nullptr; + for (Physical *physical : _physicals) { + nassertd(physical->_physical_node == this) continue; + physical->_physical_node = nullptr; } - _physicals.erase(_physicals.begin(), _physicals.end()); + _physicals.clear(); } /** From f450aa5edfa048d45266a60e4e5cfd1a42482bf7 Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 21 Mar 2021 14:40:10 +0100 Subject: [PATCH 07/14] physics: Add additional properties --- panda/src/physics/physical.h | 4 ++++ panda/src/physics/physicsObject.h | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/panda/src/physics/physical.h b/panda/src/physics/physical.h index fd3b9c343a..c101376a38 100644 --- a/panda/src/physics/physical.h +++ b/panda/src/physics/physical.h @@ -64,14 +64,18 @@ PUBLISHED: INLINE int get_num_linear_forces() const; INLINE PT(LinearForce) get_linear_force(int index) const; MAKE_SEQ(get_linear_forces, get_num_linear_forces, get_linear_force); + MAKE_SEQ_PROPERTY(linear_forces, get_num_linear_forces, get_linear_force); INLINE int get_num_angular_forces() const; INLINE PT(AngularForce) get_angular_force(int index) const; MAKE_SEQ(get_angular_forces, get_num_angular_forces, get_angular_force); + MAKE_SEQ_PROPERTY(angular_forces, get_num_angular_forces, get_angular_force); INLINE void set_viscosity(PN_stdfloat viscosity); INLINE PN_stdfloat get_viscosity() const; + MAKE_PROPERTY(viscosity, get_viscosity); const PhysicsObjectCollection get_objects() const; + MAKE_PROPERTY(objects, get_objects); virtual void output(std::ostream &out = std::cout) const; virtual void write_physics_objects( diff --git a/panda/src/physics/physicsObject.h b/panda/src/physics/physicsObject.h index a5b8c8897f..851430b1c5 100644 --- a/panda/src/physics/physicsObject.h +++ b/panda/src/physics/physicsObject.h @@ -99,6 +99,18 @@ PUBLISHED: virtual void output(std::ostream &out) const; virtual void write(std::ostream &out, int indent=0) const; +PUBLISHED: + MAKE_PROPERTY(active, get_active, set_active); + MAKE_PROPERTY(mass, get_mass, set_mass); + MAKE_PROPERTY(position, get_position, set_position); + MAKE_PROPERTY(last_position, get_last_position, set_last_position); + MAKE_PROPERTY(velocity, get_velocity, set_velocity); + MAKE_PROPERTY(implicit_velocity, get_implicit_velocity); + MAKE_PROPERTY(terminal_velocity, get_terminal_velocity, set_terminal_velocity); + MAKE_PROPERTY(oriented, get_oriented, set_oriented); + MAKE_PROPERTY(orientation, get_orientation, set_orientation); + MAKE_PROPERTY(rotation, get_rotation, set_rotation); + private: // physical LPoint3 _position; // aka _center_of_mass From b5c78e803570f4427e596bbc8c13505fa9ad4a7f Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 21 Mar 2021 14:55:00 +0100 Subject: [PATCH 08/14] Update BACKERS.md --- BACKERS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/BACKERS.md b/BACKERS.md index 1c5a10d555..86fc18b77d 100644 --- a/BACKERS.md +++ b/BACKERS.md @@ -24,6 +24,7 @@ This is a list of all the people who are contributing financially to Panda3D. I * Sam Edwards * Max Voss * Hawkheart +* Dan Mlodecki ## Enthusiasts From 2531f09024299282729c01eb240977f797fe435f Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 21 Mar 2021 14:55:46 +0100 Subject: [PATCH 09/14] makepanda: Don't enable X11 on Android --- makepanda/makepanda.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makepanda/makepanda.py b/makepanda/makepanda.py index 1b243ea73e..c457a7fe12 100755 --- a/makepanda/makepanda.py +++ b/makepanda/makepanda.py @@ -1129,7 +1129,7 @@ if (COMPILER=="GCC"): # CgGL is covered by the Cg framework, and we don't need X11 components on OSX if not PkgSkip("NVIDIACG") and not RUNTIME: SmartPkgEnable("CGGL", "", ("CgGL"), "Cg/cgGL.h", thirdparty_dir = "nvidiacg") - if not RUNTIME: + if not RUNTIME and GetTarget() != "android": SmartPkgEnable("X11", "x11", "X11", ("X11", "X11/Xlib.h", "X11/XKBlib.h")) if GetHost() != "darwin": From 1654860f36e315af2a1100c53cbdcf132dab5e09 Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 21 Mar 2021 15:50:00 +0100 Subject: [PATCH 10/14] makepanda: Rename aarch64 thirdparty dir to arm64 for consistency --- makepanda/makepandacore.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/makepanda/makepandacore.py b/makepanda/makepandacore.py index c6dd9f0e91..b82b840027 100644 --- a/makepanda/makepandacore.py +++ b/makepanda/makepandacore.py @@ -1338,22 +1338,22 @@ def GetThirdpartyDir(): THIRDPARTYDIR = base + "/darwin-libs-a/" elif (target == 'linux'): - if (target_arch.startswith("arm")): + if target_arch in ("aarch64", "arm64"): + THIRDPARTYDIR = base + "/linux-libs-arm64/" + elif target_arch.startswith("arm"): THIRDPARTYDIR = base + "/linux-libs-arm/" elif (target_arch in ("x86_64", "amd64")): THIRDPARTYDIR = base + "/linux-libs-x64/" - elif target_arch == "aarch64": - THIRDPARTYDIR = base + "/linux-libs-aarch64/" else: THIRDPARTYDIR = base + "/linux-libs-a/" elif (target == 'freebsd'): - if (target_arch.startswith("arm")): + if target_arch in ("aarch64", "arm64"): + THIRDPARTYDIR = base + "/freebsd-libs-arm64/" + elif target_arch.startswith("arm"): THIRDPARTYDIR = base + "/freebsd-libs-arm/" elif (target_arch in ("x86_64", "amd64")): THIRDPARTYDIR = base + "/freebsd-libs-x64/" - elif target_arch == "aarch64": - THIRDPARTYDIR = base + "/freebsd-libs-aarch64/" else: THIRDPARTYDIR = base + "/freebsd-libs-a/" From c1fbb70c6d791aa470de5cd6e0cf9b056da3458e Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 21 Mar 2021 16:55:19 +0100 Subject: [PATCH 11/14] display: Temporary fix for base.win.properties.size et al Previously, calling that without storing a temporary object would cause the WindowProperties to go out of scope and the return value to point to random memory. --- panda/src/display/windowProperties.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/panda/src/display/windowProperties.h b/panda/src/display/windowProperties.h index 0d9b162c6c..82dcbb5358 100644 --- a/panda/src/display/windowProperties.h +++ b/panda/src/display/windowProperties.h @@ -68,7 +68,11 @@ PUBLISHED: INLINE void set_origin(const LPoint2i &origin); INLINE void set_origin(int x_origin, int y_origin); +#ifdef CPPPARSER + INLINE LPoint2i get_origin() const; +#else INLINE const LPoint2i &get_origin() const; +#endif INLINE int get_x_origin() const; INLINE int get_y_origin() const; INLINE bool has_origin() const; @@ -77,7 +81,11 @@ PUBLISHED: INLINE void set_size(const LVector2i &size); INLINE void set_size(int x_size, int y_size); +#ifdef CPPPARSER + INLINE LVector2i get_size() const; +#else INLINE const LVector2i &get_size() const; +#endif INLINE int get_x_size() const; INLINE int get_y_size() const; INLINE bool has_size() const; @@ -92,7 +100,11 @@ PUBLISHED: set_mouse_mode, clear_mouse_mode); INLINE void set_title(const std::string &title); +#ifdef CPPPARSER + INLINE std::string get_title() const; +#else INLINE const std::string &get_title() const; +#endif INLINE bool has_title() const; INLINE void clear_title(); MAKE_PROPERTY2(title, has_title, get_title, set_title, clear_title); @@ -151,14 +163,22 @@ PUBLISHED: set_cursor_hidden, clear_cursor_hidden); INLINE void set_icon_filename(const Filename &icon_filename); +#ifdef CPPPARSER + INLINE Filename get_icon_filename() const; +#else INLINE const Filename &get_icon_filename() const; +#endif INLINE bool has_icon_filename() const; INLINE void clear_icon_filename(); MAKE_PROPERTY2(icon_filename, has_icon_filename, get_icon_filename, set_icon_filename, clear_icon_filename); INLINE void set_cursor_filename(const Filename &cursor_filename); +#ifdef CPPPARSER + INLINE Filename get_cursor_filename() const; +#else INLINE const Filename &get_cursor_filename() const; +#endif INLINE bool has_cursor_filename() const; INLINE void clear_cursor_filename(); MAKE_PROPERTY2(cursor_filename, has_cursor_filename, get_cursor_filename, From fe29aab56815b9016cb3612a77fd0dcadffcc539 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 22 Mar 2021 10:05:03 +0100 Subject: [PATCH 12/14] dgui: Reset DirectOptionMenu highlighted index when replacing items Not doing this causes issues if the item list is replaced by an item callback, since that means the unhighlight callback is never fired. Fixes #1125 --- direct/src/gui/DirectOptionMenu.py | 1 + 1 file changed, 1 insertion(+) diff --git a/direct/src/gui/DirectOptionMenu.py b/direct/src/gui/DirectOptionMenu.py index fe417cfd9f..d598e81e20 100644 --- a/direct/src/gui/DirectOptionMenu.py +++ b/direct/src/gui/DirectOptionMenu.py @@ -114,6 +114,7 @@ class DirectOptionMenu(DirectButton): ) # Make sure it is on top of all the other gui widgets self.popupMenu.setBin('gui-popup', 0) + self.highlightedIndex = None if not self['items']: return # Create a new component for each item From 40b94c1f9776e42c59ef95140f2a4a5fab3030d8 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 22 Mar 2021 11:35:03 +0100 Subject: [PATCH 13/14] gobj: Fix GeomPrimitive::offset_vertices() with strip cut index This was called, among other things, by the egg-unify process, which could ruin the strip cut index. At the same time, I've reimplemented the indexed case for offset_vertices() to make it a little bit more efficient. Fixes #1122 --- panda/src/gobj/geomPrimitive.cxx | 46 +++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/panda/src/gobj/geomPrimitive.cxx b/panda/src/gobj/geomPrimitive.cxx index 6529de2f80..ca51d95079 100644 --- a/panda/src/gobj/geomPrimitive.cxx +++ b/panda/src/gobj/geomPrimitive.cxx @@ -442,18 +442,50 @@ offset_vertices(int offset) { consider_elevate_index_type(cdata, cdata->_max_vertex + offset); - int strip_cut_index = get_strip_cut_index(cdata->_index_type); + { + GeomVertexArrayDataHandle handle(cdata->_vertices.get_write_pointer(), + Thread::get_current_thread()); - GeomVertexRewriter index(do_modify_vertices(cdata), 0); - while (!index.is_at_end()) { - int vertex = index.get_data1i(); + size_t num_rows = (size_t)handle.get_num_rows(); + unsigned char *ptr = handle.get_write_pointer(); + switch (cdata->_index_type) { + case GeomEnums::NT_uint8: + for (size_t i = 0; i < num_rows; ++i) { + uint8_t &v = ((uint8_t *)ptr)[i]; + if (v != 0xff) { + v += offset; + } + } + break; - if (vertex != strip_cut_index) { - index.set_data1i(vertex + offset); + case GeomEnums::NT_uint16: + for (size_t i = 0; i < num_rows; ++i) { + uint16_t &v = ((uint16_t *)ptr)[i]; + if (v != 0xffff) { + v += offset; + } + } + break; + + case GeomEnums::NT_uint32: + for (size_t i = 0; i < num_rows; ++i) { + uint32_t &v = ((uint32_t *)ptr)[i]; + if (v != 0xffffffff) { + v += offset; + } + } + break; + + default: + nassert_raise("unsupported index type"); + break; } } - } else { + cdata->_modified = Geom::get_next_modified(); + cdata->_got_minmax = false; + } + else { CDWriter cdata(_cycler, true); cdata->_first_vertex += offset; From 8f55d32cb15ece3b825fc3c36c6763a3db50e9e3 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 22 Mar 2021 15:37:43 +0100 Subject: [PATCH 14/14] glgsg: Workaround for Cg shader issue with multiple GSGs Fixes #1117 --- panda/src/glstuff/glCgShaderContext_src.cxx | 15 ++---- .../glstuff/glGraphicsStateGuardian_src.cxx | 48 +++++++++++++++++-- .../src/glstuff/glGraphicsStateGuardian_src.h | 8 +++- 3 files changed, 54 insertions(+), 17 deletions(-) diff --git a/panda/src/glstuff/glCgShaderContext_src.cxx b/panda/src/glstuff/glCgShaderContext_src.cxx index 1691d10ca7..c0a3b7d284 100644 --- a/panda/src/glstuff/glCgShaderContext_src.cxx +++ b/panda/src/glstuff/glCgShaderContext_src.cxx @@ -49,18 +49,9 @@ CLP(CgShaderContext)(CLP(GraphicsStateGuardian) *glgsg, Shader *s) : ShaderConte nassertv(s->get_language() == Shader::SL_Cg); // Get a Cg context for this GSG. - CGcontext context = glgsg->_cg_context; - if (context == 0) { - // The GSG doesn't have a Cg context yet. Create one. - glgsg->_cg_context = context = cgCreateContext(); - -#if CG_VERSION_NUM >= 3100 - // This just sounds like a good thing to do. - cgGLSetContextGLSLVersion(context, cgGLDetectGLSLVersion()); - if (glgsg->_shader_caps._active_vprofile == CG_PROFILE_GLSLV) { - cgGLSetContextOptimalOptions(context, CG_PROFILE_GLSLC); - } -#endif + CGcontext context = glgsg->get_cg_context(); + if (context == nullptr) { + return; } // Ask the shader to compile itself for us and to give us the resulting Cg diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index bd6112107a..2e997a8587 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -93,6 +93,11 @@ PStatCollector CLP(GraphicsStateGuardian)::_fbo_bind_pcollector("Draw:Bind FBO") PStatCollector CLP(GraphicsStateGuardian)::_check_error_pcollector("Draw:Check errors"); PStatCollector CLP(GraphicsStateGuardian)::_check_residency_pcollector("*:PStats:Check residency"); +#if defined(HAVE_CG) && !defined(OPENGLES) +AtomicAdjust::Integer CLP(GraphicsStateGuardian)::_num_gsgs_with_cg_contexts = 0; +pvector CLP(GraphicsStateGuardian)::_destroyed_cg_contexts; +#endif + // The following noop functions are assigned to the corresponding glext // function pointers in the class, in case the functions are not defined by // the GL, just so it will always be safe to call the extension functions. @@ -527,7 +532,7 @@ CLP(GraphicsStateGuardian)(GraphicsEngine *engine, GraphicsPipe *pipe) : _shader_point_size = false; #endif -#ifdef HAVE_CG +#if defined(HAVE_CG) && !defined(OPENGLES) _cg_context = 0; #endif @@ -11556,13 +11561,48 @@ set_state_and_transform(const RenderState *target, void CLP(GraphicsStateGuardian):: free_pointers() { #if defined(HAVE_CG) && !defined(OPENGLES) - if (_cg_context != 0) { - cgDestroyContext(_cg_context); - _cg_context = 0; + if (_cg_context) { + _destroyed_cg_contexts.push_back(_cg_context); + _cg_context = nullptr; + + // Don't destroy the Cg context until the last GSG that uses Cg has been + // destroyed. This works around a Cg bug, see #1117. + if (!AtomicAdjust::dec(_num_gsgs_with_cg_contexts)) { + for (CGcontext context : _destroyed_cg_contexts) { + cgDestroyContext(context); + } + _destroyed_cg_contexts.clear(); + } } #endif } +/** + * Returns a Cg context for this GSG. + */ +#if defined(HAVE_CG) && !defined(OPENGLES) +CGcontext CLP(GraphicsStateGuardian):: +get_cg_context() { + CGcontext context = _cg_context; + if (context == nullptr) { + context = cgCreateContext(); + +#if CG_VERSION_NUM >= 3100 + // This just sounds like a good thing to do. + cgGLSetContextGLSLVersion(context, cgGLDetectGLSLVersion()); + if (_shader_caps._active_vprofile == CG_PROFILE_GLSLV) { + cgGLSetContextOptimalOptions(context, CG_PROFILE_GLSLC); + } +#endif + + AtomicAdjust::inc(_num_gsgs_with_cg_contexts); + _cg_context = context; + } + + return context; +} +#endif + /** * This is called by set_state_and_transform() when the texture state has * changed. diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.h b/panda/src/glstuff/glGraphicsStateGuardian_src.h index b3974522ea..02e22961ce 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.h +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.h @@ -506,6 +506,10 @@ protected: virtual void free_pointers(); +#if defined(HAVE_CG) && !defined(OPENGLES) + CGcontext get_cg_context(); +#endif + #ifndef OPENGLES_1 INLINE void enable_vertex_attrib_array(GLuint index); INLINE void disable_vertex_attrib_array(GLuint index); @@ -689,8 +693,10 @@ protected: GLfloat _max_line_width; -#ifdef HAVE_CG +#if defined(HAVE_CG) && !defined(OPENGLES) CGcontext _cg_context; + static AtomicAdjust::Integer _num_gsgs_with_cg_contexts; + static pvector _destroyed_cg_contexts; #endif #ifdef SUPPORT_IMMEDIATE_MODE