Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/pgraph/renderState.I

Go to the documentation of this file.
00001 // Filename: renderState.I
00002 // Created by:  drose (21Feb02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 
00020 ////////////////////////////////////////////////////////////////////
00021 //     Function: RenderState::Composition::Constructor
00022 //       Access: Public
00023 //  Description: 
00024 ////////////////////////////////////////////////////////////////////
00025 INLINE RenderState::Composition::
00026 Composition() {
00027 }
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 //     Function: RenderState::Composition::Copy Constructor
00031 //       Access: Public
00032 //  Description: 
00033 ////////////////////////////////////////////////////////////////////
00034 INLINE RenderState::Composition::
00035 Composition(const RenderState::Composition &copy) :
00036   _result(copy._result)
00037 {
00038 }
00039 
00040 ////////////////////////////////////////////////////////////////////
00041 //     Function: RenderState::Attribute::Constructor
00042 //       Access: Public
00043 //  Description:
00044 ////////////////////////////////////////////////////////////////////
00045 INLINE RenderState::Attribute::
00046 Attribute(const RenderAttrib *attrib, int override) :
00047   _type(attrib->get_type()),
00048   _attrib(attrib),
00049   _override(override)
00050 {
00051 }
00052 
00053 ////////////////////////////////////////////////////////////////////
00054 //     Function: RenderState::Attribute::Constructor
00055 //       Access: Public
00056 //  Description: This constructor is only used when reading the
00057 //               RenderState from a bam file.  At this point, the
00058 //               attribute pointer is unknown.
00059 ////////////////////////////////////////////////////////////////////
00060 INLINE RenderState::Attribute::
00061 Attribute(int override) :
00062   _override(override)
00063 {
00064 }
00065 
00066 ////////////////////////////////////////////////////////////////////
00067 //     Function: RenderState::Attribute::Constructor
00068 //       Access: Public
00069 //  Description: This constructor makes an invalid Attribute with no
00070 //               RenderAttrib pointer; its purpose is just to make an
00071 //               object we can use to look up a particular type in the
00072 //               Attribute set.
00073 ////////////////////////////////////////////////////////////////////
00074 INLINE RenderState::Attribute::
00075 Attribute(TypeHandle type) :
00076   _type(type),
00077   _attrib(NULL),
00078   _override(0)
00079 {
00080 }
00081 
00082 ////////////////////////////////////////////////////////////////////
00083 //     Function: RenderState::Attribute::Copy Constructor
00084 //       Access: Public
00085 //  Description:
00086 ////////////////////////////////////////////////////////////////////
00087 INLINE RenderState::Attribute::
00088 Attribute(const Attribute &copy) :
00089   _type(copy._type),
00090   _attrib(copy._attrib),
00091   _override(copy._override)
00092 {
00093 }
00094 
00095 ////////////////////////////////////////////////////////////////////
00096 //     Function: RenderState::Attribute::Copy Assignment Operator
00097 //       Access: Public
00098 //  Description:
00099 ////////////////////////////////////////////////////////////////////
00100 INLINE void RenderState::Attribute::
00101 operator = (const Attribute &copy) {
00102   _type = copy._type;
00103   _attrib = copy._attrib;
00104   _override = copy._override;
00105 }
00106 
00107 ////////////////////////////////////////////////////////////////////
00108 //     Function: RenderState::Attribute::operator <
00109 //       Access: Public
00110 //  Description: This is used by the Attributes set to uniquify
00111 //               RenderAttributes by type.  Only one RenderAttrib of a
00112 //               given type is allowed in the set.  This ordering must
00113 //               also match the ordering reported by compare_to().
00114 ////////////////////////////////////////////////////////////////////
00115 INLINE bool RenderState::Attribute::
00116 operator < (const Attribute &other) const {
00117   return _type < other._type;
00118 }
00119 
00120 ////////////////////////////////////////////////////////////////////
00121 //     Function: RenderState::Attribute::compare_to
00122 //       Access: Public
00123 //  Description: Provides an indication of whether a particular
00124 //               attribute is equivalent to another one, for purposes
00125 //               of generating unique RenderStates.  This should
00126 //               compare all properties of the Attribute, but it is
00127 //               important that the type is compared first, to be
00128 //               consistent with the ordering defined by operator <.
00129 ////////////////////////////////////////////////////////////////////
00130 INLINE int RenderState::Attribute::
00131 compare_to(const Attribute &other) const {
00132   if (_type != other._type) {
00133     return _type.get_index() - other._type.get_index();
00134   }
00135   if (_attrib != other._attrib) {
00136     return _attrib < other._attrib ? -1 : 1;
00137   }
00138   return _override - other._override;
00139 }
00140 
00141 ////////////////////////////////////////////////////////////////////
00142 //     Function: RenderState::is_empty
00143 //       Access: Published
00144 //  Description: Returns true if the state is empty, false otherwise.
00145 ////////////////////////////////////////////////////////////////////
00146 INLINE bool RenderState::
00147 is_empty() const {
00148   return _attributes.empty();
00149 }
00150 
00151 ////////////////////////////////////////////////////////////////////
00152 //     Function: RenderState::get_num_attribs
00153 //       Access: Published
00154 //  Description: Returns the number of separate attributes indicated
00155 //               in the state.
00156 ////////////////////////////////////////////////////////////////////
00157 INLINE int RenderState::
00158 get_num_attribs() const {
00159   return _attributes.size();
00160 }
00161 
00162 ////////////////////////////////////////////////////////////////////
00163 //     Function: RenderState::get_attrib
00164 //       Access: Published
00165 //  Description: Returns the nth attribute in the state.
00166 ////////////////////////////////////////////////////////////////////
00167 INLINE const RenderAttrib *RenderState::
00168 get_attrib(int n) const {
00169   nassertr(n >= 0 && n < (int)_attributes.size(), NULL);
00170   return _attributes[n]._attrib;
00171 }
00172 
00173 ////////////////////////////////////////////////////////////////////
00174 //     Function: RenderState::get_override
00175 //       Access: Published
00176 //  Description: Returns the override associated with the nth
00177 //               attribute in the state.
00178 ////////////////////////////////////////////////////////////////////
00179 INLINE int RenderState::
00180 get_override(int n) const {
00181   nassertr(n >= 0 && n < (int)_attributes.size(), 0);
00182   return _attributes[n]._override;
00183 }
00184 
00185 ////////////////////////////////////////////////////////////////////
00186 //     Function: RenderState::get_bin_index
00187 //       Access: Public
00188 //  Description: Returns the bin index indicated by the CullBinAttrib,
00189 //               if any, associated by this state (or the default bin
00190 //               index if there is no CullBinAttrib).  This function
00191 //               is provided as an optimization for determining this
00192 //               at render time.
00193 ////////////////////////////////////////////////////////////////////
00194 INLINE int RenderState::
00195 get_bin_index() const {
00196   if ((_flags & F_checked_bin_index) == 0) {
00197     // We pretend this function is const, even though it transparently
00198     // modifies the internal bin_index cache.
00199     ((RenderState *)this)->determine_bin_index();
00200   }
00201   return _bin_index;
00202 }
00203 
00204 ////////////////////////////////////////////////////////////////////
00205 //     Function: RenderState::get_draw_order
00206 //       Access: Public
00207 //  Description: Returns the draw order indicated by the
00208 //               CullBinAttrib, if any, associated by this state (or 0
00209 //               if there is no CullBinAttrib).  See get_bin_index().
00210 ////////////////////////////////////////////////////////////////////
00211 INLINE int RenderState::
00212 get_draw_order() const {
00213   if ((_flags & F_checked_bin_index) == 0) {
00214     // We pretend this function is const, even though it transparently
00215     // modifies the internal draw_order cache.
00216     ((RenderState *)this)->determine_bin_index();
00217   }
00218   return _draw_order;
00219 }
00220 
00221 ////////////////////////////////////////////////////////////////////
00222 //     Function: RenderState::get_fog
00223 //       Access: Public
00224 //  Description: This function is provided as an optimization, to
00225 //               speed up the render-time checking for the existance
00226 //               of a FogAttrib on this state.  It returns a
00227 //               pointer to the FogAttrib, if there is one, or
00228 //               NULL if there is not.
00229 ////////////////////////////////////////////////////////////////////
00230 INLINE const FogAttrib *RenderState::
00231 get_fog() const {
00232   if ((_flags & F_checked_fog) == 0) {
00233     // We pretend this function is const, even though it transparently
00234     // modifies the internal fog cache.
00235     ((RenderState *)this)->determine_fog();
00236   }
00237   return _fog;
00238 }
00239 
00240 ////////////////////////////////////////////////////////////////////
00241 //     Function: RenderState::get_bin
00242 //       Access: Public
00243 //  Description: This function is provided as an optimization, to
00244 //               speed up the render-time checking for the existance
00245 //               of a BinAttrib on this state.  It returns a
00246 //               pointer to the BinAttrib, if there is one, or
00247 //               NULL if there is not.
00248 ////////////////////////////////////////////////////////////////////
00249 INLINE const CullBinAttrib *RenderState::
00250 get_bin() const {
00251   if ((_flags & F_checked_bin) == 0) {
00252     // We pretend this function is const, even though it transparently
00253     // modifies the internal bin cache.
00254     ((RenderState *)this)->determine_bin();
00255   }
00256   return _bin;
00257 }
00258 
00259 ////////////////////////////////////////////////////////////////////
00260 //     Function: RenderState::get_transparency
00261 //       Access: Public
00262 //  Description: This function is provided as an optimization, to
00263 //               speed up the render-time checking for the existance
00264 //               of a TransparencyAttrib on this state.  It returns a
00265 //               pointer to the TransparencyAttrib, if there is one,
00266 //               or NULL if there is not.
00267 ////////////////////////////////////////////////////////////////////
00268 INLINE const TransparencyAttrib *RenderState::
00269 get_transparency() const {
00270   if ((_flags & F_checked_transparency) == 0) {
00271     // We pretend this function is const, even though it transparently
00272     // modifies the internal transparency cache.
00273     ((RenderState *)this)->determine_transparency();
00274   }
00275   return _transparency;
00276 }
00277 
00278 ////////////////////////////////////////////////////////////////////
00279 //     Function: RenderState::set_destructing
00280 //       Access: Private
00281 //  Description: This function should only be called from the
00282 //               destructor; it indicates that this RenderState
00283 //               object is beginning destruction.  It is only used as
00284 //               a sanity check, and is only meaningful when NDEBUG is
00285 //               not defined.
00286 ////////////////////////////////////////////////////////////////////
00287 INLINE void RenderState::
00288 set_destructing() {
00289 #ifndef NDEBUG
00290   _flags |= F_is_destructing;
00291 #endif
00292 }
00293 
00294 ////////////////////////////////////////////////////////////////////
00295 //     Function: RenderState::is_destructing
00296 //       Access: Private
00297 //  Description: Returns true if the RenderState object is
00298 //               currently within its destructor
00299 //               (i.e. set_destructing() has been called).  This is
00300 //               only used as a sanity check, and is only meaningful
00301 //               when NDEBUG is not defined.
00302 ////////////////////////////////////////////////////////////////////
00303 INLINE bool RenderState::
00304 is_destructing() const {
00305 #ifndef NDEBUG
00306   return (_flags & F_is_destructing) != 0;
00307 #else
00308   return false;
00309 #endif
00310 }

Generated on Fri May 2 00:42:19 2003 for Panda by doxygen1.3