From 21436b4f4d276d1d635a4b616f7898fc7218c390 Mon Sep 17 00:00:00 2001 From: Josh Yelon Date: Sat, 15 Dec 2007 07:05:20 +0000 Subject: [PATCH] Added 'auto' flag to ShaderAttrib --- panda/src/pgraph/nodePath.cxx | 23 +++++++++++++++++++++++ panda/src/pgraph/nodePath.h | 1 + panda/src/pgraph/shaderAttrib.I | 13 +++++++++++++ panda/src/pgraph/shaderAttrib.cxx | 21 +++++++++++++++++++++ panda/src/pgraph/shaderAttrib.h | 6 +++++- 5 files changed, 63 insertions(+), 1 deletion(-) diff --git a/panda/src/pgraph/nodePath.cxx b/panda/src/pgraph/nodePath.cxx index 1fb6a2f113..75c448557a 100644 --- a/panda/src/pgraph/nodePath.cxx +++ b/panda/src/pgraph/nodePath.cxx @@ -3203,6 +3203,29 @@ set_shader_off(int priority) { set_shader(NULL, priority); } +//////////////////////////////////////////////////////////////////// +// Function: NodePath::set_shader_auto +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void NodePath:: +set_shader_auto(int priority) { + nassertv_always(!is_empty()); + + const RenderAttrib *attrib = + node()->get_attrib(ShaderAttrib::get_class_type()); + if (attrib != (const RenderAttrib *)NULL) { + priority = max(priority, + node()->get_state()->get_override(ShaderAttrib::get_class_type())); + const ShaderAttrib *sa = DCAST(ShaderAttrib, attrib); + node()->set_attrib(sa->set_shader_auto(priority)); + } else { + // Create a new ShaderAttrib for this node. + CPT(ShaderAttrib) sa = DCAST(ShaderAttrib, ShaderAttrib::make()); + node()->set_attrib(sa->set_shader_auto(priority)); + } +} + //////////////////////////////////////////////////////////////////// // Function: NodePath::clear_shader // Access: Published diff --git a/panda/src/pgraph/nodePath.h b/panda/src/pgraph/nodePath.h index 792f9432a5..f40eb81496 100644 --- a/panda/src/pgraph/nodePath.h +++ b/panda/src/pgraph/nodePath.h @@ -572,6 +572,7 @@ PUBLISHED: void set_shader(const Shader *sha, int priority = 0); void set_shader_off(int priority = 0); + void set_shader_auto(int priority = 0); void clear_shader(); void set_shader_input(const ShaderInput *inp); void set_shader_input(InternalName *id, Texture *tex, int priority=0); diff --git a/panda/src/pgraph/shaderAttrib.I b/panda/src/pgraph/shaderAttrib.I index f4523eb1ab..6a362f573f 100755 --- a/panda/src/pgraph/shaderAttrib.I +++ b/panda/src/pgraph/shaderAttrib.I @@ -35,6 +35,7 @@ INLINE ShaderAttrib:: ShaderAttrib(const ShaderAttrib ©) : _shader(copy._shader), _shader_priority(copy._shader_priority), + _auto_shader(copy._auto_shader), _has_shader(copy._has_shader), _inputs(copy._inputs) { @@ -51,6 +52,18 @@ has_shader() const { return _has_shader; } +//////////////////////////////////////////////////////////////////// +// Function: ShaderAttrib::auto_shader +// Access: Published +// Description: If true, then this ShaderAttrib does not contain an +// explicit shader - instead, it requests the automatic +// generation of a shader. +//////////////////////////////////////////////////////////////////// +INLINE bool ShaderAttrib:: +auto_shader() const { + return _auto_shader; +} + //////////////////////////////////////////////////////////////////// // Function: ShaderAttrib::get_shader_priority // Access: Published diff --git a/panda/src/pgraph/shaderAttrib.cxx b/panda/src/pgraph/shaderAttrib.cxx index 0b7b23d4e9..5876683ec0 100755 --- a/panda/src/pgraph/shaderAttrib.cxx +++ b/panda/src/pgraph/shaderAttrib.cxx @@ -42,6 +42,7 @@ make_off() { ShaderAttrib *attrib = new ShaderAttrib; attrib->_shader = (Shader*)NULL; attrib->_shader_priority = 0; + attrib->_auto_shader = false; attrib->_has_shader = true; _off_attrib = return_new(attrib); } @@ -61,6 +62,7 @@ make() { ShaderAttrib *attrib = new ShaderAttrib; attrib->_shader = (Shader*)NULL; attrib->_shader_priority = 0; + attrib->_auto_shader = false; attrib->_has_shader = false; _null_attrib = return_new(attrib); } @@ -77,6 +79,7 @@ set_shader(const Shader *s, int priority) const { ShaderAttrib *result = new ShaderAttrib(*this); result->_shader = s; result->_shader_priority = priority; + result->_auto_shader = false; result->_has_shader = true; return return_new(result); } @@ -91,6 +94,22 @@ set_shader_off(int priority) const { ShaderAttrib *result = new ShaderAttrib(*this); result->_shader = NULL; result->_shader_priority = priority; + result->_auto_shader = false; + result->_has_shader = true; + return return_new(result); +} + +//////////////////////////////////////////////////////////////////// +// Function: ShaderAttrib::set_shader_auto +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +CPT(RenderAttrib) ShaderAttrib:: +set_shader_auto(int priority) const { + ShaderAttrib *result = new ShaderAttrib(*this); + result->_shader = NULL; + result->_shader_priority = priority; + result->_auto_shader = true; result->_has_shader = true; return return_new(result); } @@ -105,6 +124,7 @@ clear_shader() const { ShaderAttrib *result = new ShaderAttrib(*this); result->_shader = NULL; result->_shader_priority = 0; + result->_auto_shader = false; result->_has_shader = false; return return_new(result); } @@ -437,6 +457,7 @@ compose_impl(const RenderAttrib *other) const { (over->_shader_priority >= attr->_shader_priority)) { attr->_shader = over->_shader; attr->_shader_priority = over->_shader_priority; + attr->_auto_shader = over->_auto_shader; attr->_has_shader = over->_has_shader; } } diff --git a/panda/src/pgraph/shaderAttrib.h b/panda/src/pgraph/shaderAttrib.h index fc1748db24..fab7fe8e72 100755 --- a/panda/src/pgraph/shaderAttrib.h +++ b/panda/src/pgraph/shaderAttrib.h @@ -39,12 +39,14 @@ private: PUBLISHED: static CPT(RenderAttrib) make(); static CPT(RenderAttrib) make_off(); - + INLINE bool has_shader() const; + INLINE bool auto_shader() const; INLINE int get_shader_priority() const; CPT(RenderAttrib) set_shader(const Shader *s, int priority=0) const; CPT(RenderAttrib) set_shader_off(int priority=0) const; + CPT(RenderAttrib) set_shader_auto(int priority=0) const; CPT(RenderAttrib) clear_shader() const; CPT(RenderAttrib) set_shader_input(const ShaderInput *inp) const; CPT(RenderAttrib) set_shader_input(InternalName *id, Texture *tex, int priority=0) const; @@ -79,8 +81,10 @@ protected: virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const; private: + CPT(Shader) _shader; int _shader_priority; + bool _auto_shader; bool _has_shader; typedef pmap < CPT(InternalName), CPT(ShaderInput) > Inputs; Inputs _inputs;