Allow setAlphaScale() to override properly from below

This commit is contained in:
David Rose 2005-08-04 17:52:11 +00:00
parent 98c32d4e43
commit 47c1d1e360
5 changed files with 80 additions and 1 deletions

View File

@ -101,6 +101,41 @@ issue(GraphicsStateGuardianBase *gsg) const {
gsg->issue_color_scale(this);
}
////////////////////////////////////////////////////////////////////
// Function: ColorScaleAttrib::lower_attrib_can_override
// Access: Public, Virtual
// Description: Intended to be overridden by derived RenderAttrib
// types to specify how two consecutive RenderAttrib
// objects of the same type interact.
//
// This should return false if a RenderAttrib on a
// higher node will compose into a RenderAttrib on a
// lower node that has a higher override value, or false
// if the lower RenderAttrib will completely replace the
// state.
//
// The default behavior is false: normally, a
// RenderAttrib in the graph cannot completely override
// a RenderAttrib above it, regardless of its override
// value--instead, the two attribs are composed. But
// for some kinds of RenderAttribs, it is useful to
// allow this kind of override.
//
// This method only handles the one special case of a
// lower RenderAttrib with a higher override value. If
// the higher RenderAttrib has a higher override value,
// it always completely overrides. And if both
// RenderAttribs have the same override value, they are
// always composed.
////////////////////////////////////////////////////////////////////
bool ColorScaleAttrib::
lower_attrib_can_override() const {
// A ColorScaleAttrib doesn't compose through an override. This
// allows us to meaningfully set an override on a lower node, which
// prevents any color scales from coming in from above.
return true;
}
////////////////////////////////////////////////////////////////////
// Function: ColorScaleAttrib::output
// Access: Public, Virtual

View File

@ -49,6 +49,7 @@ PUBLISHED:
public:
virtual void issue(GraphicsStateGuardianBase *gsg) const;
virtual bool lower_attrib_can_override() const;
virtual void output(ostream &out) const;
protected:

View File

@ -105,6 +105,38 @@ void RenderAttrib::
issue(GraphicsStateGuardianBase *) const {
}
////////////////////////////////////////////////////////////////////
// Function: RenderAttrib::lower_attrib_can_override
// Access: Public, Virtual
// Description: Intended to be overridden by derived RenderAttrib
// types to specify how two consecutive RenderAttrib
// objects of the same type interact.
//
// This should return false if a RenderAttrib on a
// higher node will compose into a RenderAttrib on a
// lower node that has a higher override value, or false
// if the lower RenderAttrib will completely replace the
// state.
//
// The default behavior is false: normally, a
// RenderAttrib in the graph cannot completely override
// a RenderAttrib above it, regardless of its override
// value--instead, the two attribs are composed. But
// for some kinds of RenderAttribs, it is useful to
// allow this kind of override.
//
// This method only handles the one special case of a
// lower RenderAttrib with a higher override value. If
// the higher RenderAttrib has a higher override value,
// it always completely overrides. And if both
// RenderAttribs have the same override value, they are
// always composed.
////////////////////////////////////////////////////////////////////
bool RenderAttrib::
lower_attrib_can_override() const {
return false;
}
////////////////////////////////////////////////////////////////////
// Function: RenderAttrib::output
// Access: Published, Virtual

View File

@ -68,6 +68,7 @@ public:
INLINE CPT(RenderAttrib) invert_compose(const RenderAttrib *other) const;
INLINE CPT(RenderAttrib) make_default() const;
virtual void issue(GraphicsStateGuardianBase *gsg) const;
virtual bool lower_attrib_can_override() const;
INLINE bool always_reissue() const;

View File

@ -1190,9 +1190,19 @@ do_compose(const RenderState *other) const {
const Attribute &a = (*ai);
const Attribute &b = (*bi);
if (b._override < a._override) {
// A overrides.
// A, the higher RenderAttrib, overrides.
*result = *ai;
} else if (a._override < b._override &&
a._attrib->lower_attrib_can_override()) {
// B, the lower RenderAttrib, overrides. This is a special
// case; normally, a lower RenderAttrib does not override a
// higher one, even if it has a higher override value. But
// certain kinds of RenderAttribs redefine
// lower_attrib_can_override() to return true, allowing this
// override.
*result = *bi;
} else {
// Either they have the same override value, or B is higher.
// In either case, the result is the composition of the two,