Added 'auto' flag to ShaderAttrib

This commit is contained in:
Josh Yelon 2007-12-15 07:05:20 +00:00
parent 0cd1b7a065
commit 21436b4f4d
5 changed files with 63 additions and 1 deletions

View File

@ -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

View File

@ -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);

View File

@ -35,6 +35,7 @@ INLINE ShaderAttrib::
ShaderAttrib(const ShaderAttrib &copy) :
_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

View File

@ -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;
}
}

View File

@ -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;