diff --git a/panda/src/pgraph/Sources.pp b/panda/src/pgraph/Sources.pp index 51e0bdb0fa..838adc49b4 100644 --- a/panda/src/pgraph/Sources.pp +++ b/panda/src/pgraph/Sources.pp @@ -79,6 +79,7 @@ occluderNode.I occluderNode.h \ pandaNode.I pandaNode.h \ pandaNodeChain.I pandaNodeChain.h \ + paramNodePath.I paramNodePath.h \ planeNode.I planeNode.h \ polylightEffect.I polylightEffect.h \ polylightNode.I polylightNode.h \ @@ -184,6 +185,7 @@ occluderNode.cxx \ pandaNode.cxx \ pandaNodeChain.cxx \ + paramNodePath.cxx \ planeNode.cxx \ polylightEffect.cxx \ polylightNode.cxx \ @@ -286,6 +288,7 @@ pandaNode.I pandaNode.h \ pandaNode_ext.h pandaNode_ext.cxx \ pandaNodeChain.I pandaNodeChain.h \ + paramNodePath.I paramNodePath.h \ planeNode.I planeNode.h \ polylightEffect.I polylightEffect.h \ polylightNode.I polylightNode.h \ diff --git a/panda/src/pgraph/config_pgraph.cxx b/panda/src/pgraph/config_pgraph.cxx index 18b85ea77c..a79eb0c23d 100644 --- a/panda/src/pgraph/config_pgraph.cxx +++ b/panda/src/pgraph/config_pgraph.cxx @@ -60,6 +60,7 @@ #include "nodePath.h" #include "nodePathComponent.h" #include "pandaNode.h" +#include "paramNodePath.h" #include "planeNode.h" #include "polylightEffect.h" #include "polylightNode.h" @@ -436,6 +437,7 @@ init_libpgraph() { NodePathComponent::init_type(); PandaNode::init_type(); PandaNodePipelineReader::init_type(); + ParamNodePath::init_type(); PlaneNode::init_type(); PolylightNode::init_type(); PolylightEffect::init_type(); diff --git a/panda/src/pgraph/nodePath.h b/panda/src/pgraph/nodePath.h index f03580f255..d84519547d 100644 --- a/panda/src/pgraph/nodePath.h +++ b/panda/src/pgraph/nodePath.h @@ -38,6 +38,7 @@ #include "pta_LVecBase3.h" #include "pta_LVecBase2.h" #include "stl_compares.h" +#include "shaderInput.h" class NodePathCollection; class FindApproxPath; @@ -1008,9 +1009,6 @@ private: INLINE ostream &operator << (ostream &out, const NodePath &node_path); -// We have to put this down here, to work around a circular include. -#include "shaderInput.h" - #include "nodePath.I" #endif diff --git a/panda/src/pgraph/p3pgraph_composite3.cxx b/panda/src/pgraph/p3pgraph_composite3.cxx index b539fefcee..5b88a55d2f 100644 --- a/panda/src/pgraph/p3pgraph_composite3.cxx +++ b/panda/src/pgraph/p3pgraph_composite3.cxx @@ -21,6 +21,7 @@ #include "occluderNode.cxx" #include "pandaNode.cxx" #include "pandaNodeChain.cxx" +#include "paramNodePath.cxx" #include "planeNode.cxx" #include "polylightEffect.cxx" #include "polylightNode.cxx" diff --git a/panda/src/pgraph/paramNodePath.I b/panda/src/pgraph/paramNodePath.I new file mode 100644 index 0000000000..8d52ac5ad6 --- /dev/null +++ b/panda/src/pgraph/paramNodePath.I @@ -0,0 +1,60 @@ +// Filename: paramNodePath.I +// Created by: rdb (25Feb15) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: ParamNodePath::Constructor +// Access: Published +// Description: Creates a new ParamNodePath storing the given +// node path object. +//////////////////////////////////////////////////////////////////// +INLINE ParamNodePath:: +ParamNodePath(const NodePath &node_path) : + _node_path(node_path) +{ +} + +#ifdef USE_MOVE_SEMANTICS +//////////////////////////////////////////////////////////////////// +// Function: ParamNodePath::Move Constructor +// Access: Published +// Description: Creates a new ParamNodePath storing the given +// node path object. +//////////////////////////////////////////////////////////////////// +INLINE ParamNodePath:: +ParamNodePath(NodePath &&node_path) NOEXCEPT : + _node_path(move(node_path)) +{ +} +#endif // USE_MOVE_SEMANTICS + +//////////////////////////////////////////////////////////////////// +// Function: ParamNodePath::get_value_type +// Access: Published, Virtual +// Description: Returns NodePath::get_class_type(). +//////////////////////////////////////////////////////////////////// +INLINE TypeHandle ParamNodePath:: +get_value_type() const { + return NodePath::get_class_type(); +} + +//////////////////////////////////////////////////////////////////// +// Function: ParamNodePath::get_value +// Access: Published +// Description: Retrieves the NodePath stored in the parameter. +//////////////////////////////////////////////////////////////////// +INLINE const NodePath &ParamNodePath:: +get_value() const { + return _node_path; +} diff --git a/panda/src/pgraph/paramNodePath.cxx b/panda/src/pgraph/paramNodePath.cxx new file mode 100644 index 0000000000..00fb5be24a --- /dev/null +++ b/panda/src/pgraph/paramNodePath.cxx @@ -0,0 +1,108 @@ +// Filename: paramNodePath.cxx +// Created by: rdb (25Feb15) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "paramNodePath.h" +#include "dcast.h" +#include "pandaNode.h" + +TypeHandle ParamNodePath::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: ParamNodePath::output +// Access: Published, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +void ParamNodePath:: +output(ostream &out) const { + out << "node path " << _node_path; +} + +//////////////////////////////////////////////////////////////////// +// Function: ParamNodePath::register_with_read_factory +// Access: Public, Static +// Description: Tells the BamReader how to create objects of type +// ParamValue. +//////////////////////////////////////////////////////////////////// +void ParamNodePath:: +register_with_read_factory() { + BamReader::get_factory()->register_factory(get_class_type(), make_from_bam); +} + +//////////////////////////////////////////////////////////////////// +// Function: ParamNodePath::write_datagram +// Access: Public, Virtual +// Description: Writes the contents of this object to the datagram +// for shipping out to a Bam file. +//////////////////////////////////////////////////////////////////// +void ParamNodePath:: +write_datagram(BamWriter *manager, Datagram &dg) { + ParamValueBase::write_datagram(manager, dg); + + // We can't store a NodePath, so we store a pointer to the + // underlying node, and pray that there is an unambiguous path + // from the root to it. + if (_node_path.is_empty()) { + manager->write_pointer(dg, NULL); + } else { + manager->write_pointer(dg, _node_path.node()); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: ParamNodePath::complete_pointers +// Access: Public, Virtual +// Description: Receives an array of pointers, one for each time +// manager->read_pointer() was called in fillin(). +// Returns the number of pointers processed. +//////////////////////////////////////////////////////////////////// +int ParamNodePath:: +complete_pointers(TypedWritable **p_list, BamReader *manager) { + int pi = ParamValueBase::complete_pointers(p_list, manager); + _node_path = NodePath(DCAST(PandaNode, p_list[pi++])); + + return pi; +} + +//////////////////////////////////////////////////////////////////// +// Function: ParamNodePath::make_from_bam +// Access: Protected, Static +// Description: This function is called by the BamReader's factory +// when a new object of type ParamValue is encountered +// in the Bam file. It should create the ParamValue +// and extract its information from the file. +//////////////////////////////////////////////////////////////////// +TypedWritable *ParamNodePath:: +make_from_bam(const FactoryParams ¶ms) { + ParamNodePath *param = new ParamNodePath; + DatagramIterator scan; + BamReader *manager; + + parse_params(params, scan, manager); + param->fillin(scan, manager); + + return param; +} + +//////////////////////////////////////////////////////////////////// +// Function: ParamNodePath::fillin +// Access: Protected +// Description: This internal function is called by make_from_bam to +// read in all of the relevant data from the BamFile for +// the new ParamValue. +//////////////////////////////////////////////////////////////////// +void ParamNodePath:: +fillin(DatagramIterator &scan, BamReader *manager) { + ParamValueBase::fillin(scan, manager); + manager->read_pointer(scan); +} diff --git a/panda/src/pgraph/paramNodePath.h b/panda/src/pgraph/paramNodePath.h new file mode 100644 index 0000000000..f1634c49ba --- /dev/null +++ b/panda/src/pgraph/paramNodePath.h @@ -0,0 +1,75 @@ +// Filename: paramNodePath.h +// Created by: rdb (25Feb15) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PARAMNODEPATH_H +#define PARAMNODEPATH_H + +#include "pandabase.h" +#include "paramValue.h" +#include "nodePath.h" + +//////////////////////////////////////////////////////////////////// +// Class : ParamNodePath +// Description : A class object for storing a NodePath as a parameter. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDA_GOBJ ParamNodePath : public ParamValueBase { +protected: + INLINE ParamNodePath() {}; + +PUBLISHED: + INLINE ParamNodePath(const NodePath &node_path); + +#ifdef USE_MOVE_SEMANTICS + INLINE ParamNodePath(NodePath &&node_path) NOEXCEPT; +#endif + + INLINE virtual TypeHandle get_value_type() const; + INLINE const NodePath &get_value() const; + + virtual void output(ostream &out) const; + +private: + NodePath _node_path; + +public: + static void register_with_read_factory(); + virtual void write_datagram(BamWriter *manager, Datagram &dg); + virtual int complete_pointers(TypedWritable **plist, + BamReader *manager); + +protected: + static TypedWritable *make_from_bam(const FactoryParams ¶ms); + void fillin(DatagramIterator &scan, BamReader *manager); + +public: + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() {init_type(); return get_class_type();} + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + ParamValueBase::init_type(); + register_type(_type_handle, "ParamNodePath", + ParamValueBase::get_class_type()); + } + +private: + static TypeHandle _type_handle; +}; + +#include "paramNodePath.I" + +#endif diff --git a/panda/src/pgraph/shaderInput.I b/panda/src/pgraph/shaderInput.I index b75724abea..c7aed1de80 100644 --- a/panda/src/pgraph/shaderInput.I +++ b/panda/src/pgraph/shaderInput.I @@ -119,23 +119,6 @@ ShaderInput(CPT_InternalName name, ParamValueBase *param, int priority) : { } -//////////////////////////////////////////////////////////////////// -// Function: ShaderInput::Constructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE ShaderInput:: -ShaderInput(CPT_InternalName name, const NodePath &np, int priority) : - _name(MOVE(name)), - _type(M_nodepath), - _priority(priority), - _stored_nodepath(np), - _bind_layer(0), - _bind_level(0), - _access(A_read) -{ -} - //////////////////////////////////////////////////////////////////// // Function: ShaderInput::Constructor // Access: Published @@ -678,16 +661,6 @@ get_texture() const { return DCAST(Texture, _value); } -//////////////////////////////////////////////////////////////////// -// Function: ShaderInput::get_nodepath -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE const NodePath &ShaderInput:: -get_nodepath() const { - return _stored_nodepath; -} - //////////////////////////////////////////////////////////////////// // Function: ShaderInput::get_vector // Access: Published diff --git a/panda/src/pgraph/shaderInput.cxx b/panda/src/pgraph/shaderInput.cxx index a456d77900..8ab7ef3b1a 100644 --- a/panda/src/pgraph/shaderInput.cxx +++ b/panda/src/pgraph/shaderInput.cxx @@ -13,6 +13,7 @@ //////////////////////////////////////////////////////////////////// #include "shaderInput.h" +#include "paramNodePath.h" TypeHandle ShaderInput::_type_handle; @@ -32,13 +33,40 @@ get_blank() { return blank; } +//////////////////////////////////////////////////////////////////// +// Function: ShaderInput::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +ShaderInput:: +ShaderInput(CPT_InternalName name, const NodePath &np, int priority) : + _name(MOVE(name)), + _type(M_nodepath), + _priority(priority), + _value(new ParamNodePath(np)), + _bind_layer(0), + _bind_level(0), + _access(A_read) +{ +} + +//////////////////////////////////////////////////////////////////// +// Function: ShaderInput::get_nodepath +// Access: Published +// Description: Warning: no error checking is done. This *will* +// crash if get_value_type() is not M_nodepath. +//////////////////////////////////////////////////////////////////// +const NodePath &ShaderInput:: +get_nodepath() const { + return DCAST(ParamNodePath, _value)->get_value(); +} + //////////////////////////////////////////////////////////////////// // Function: ShaderInput::register_with_read_factory // Access: Public, Static -// Description: +// Description: //////////////////////////////////////////////////////////////////// void ShaderInput:: register_with_read_factory() { // IMPLEMENT ME } - diff --git a/panda/src/pgraph/shaderInput.h b/panda/src/pgraph/shaderInput.h index fed3aebe5c..26c7e2e375 100644 --- a/panda/src/pgraph/shaderInput.h +++ b/panda/src/pgraph/shaderInput.h @@ -19,7 +19,6 @@ #include "pandabase.h" #include "typedWritableReferenceCount.h" #include "pointerTo.h" -#include "nodePath.h" #include "internalName.h" #include "paramValue.h" #include "pta_float.h" @@ -53,7 +52,6 @@ PUBLISHED: static const ShaderInput *get_blank(); INLINE ShaderInput(CPT_InternalName name, int priority=0); - INLINE ShaderInput(CPT_InternalName name, const NodePath &np, int priority=0); INLINE ShaderInput(CPT_InternalName name, Texture *tex, int priority=0); INLINE ShaderInput(CPT_InternalName name, Texture *tex, const SamplerState &sampler, int priority=0); INLINE ShaderInput(CPT_InternalName name, Texture *tex, bool read, bool write, int z=-1, int n=0, int priority=0); @@ -90,6 +88,8 @@ PUBLISHED: INLINE ShaderInput(CPT_InternalName name, const LVecBase3i &vec, int priority=0); INLINE ShaderInput(CPT_InternalName name, const LVecBase2i &vec, int priority=0); + ShaderInput(CPT_InternalName name, const NodePath &np, int priority=0); + enum ShaderInputType { M_invalid = 0, M_texture, @@ -105,11 +105,12 @@ PUBLISHED: INLINE int get_value_type() const; INLINE int get_priority() const; INLINE Texture *get_texture() const; - INLINE const NodePath &get_nodepath() const; INLINE const LVecBase4 &get_vector() const; INLINE const Shader::ShaderPtrData &get_ptr() const; INLINE const SamplerState &get_sampler() const; + const NodePath &get_nodepath() const; + public: INLINE ParamValueBase *get_param() const; @@ -118,7 +119,6 @@ public: private: SamplerState _sampler; LVecBase4 _stored_vector; - NodePath _stored_nodepath; Shader::ShaderPtrData _stored_ptr; CPT_InternalName _name; PT(TypedWritableReferenceCount) _value;