Panda3D

renderAttrib.I

00001 // Filename: renderAttrib.I
00002 // Created by:  drose (21Feb02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 
00016 ////////////////////////////////////////////////////////////////////
00017 //     Function: RenderAttrib::compose
00018 //       Access: Published
00019 //  Description: Returns a new RenderAttrib object that represents the
00020 //               composition of this attrib with the other attrib.  In
00021 //               most cases, this is the same as the other attrib; a
00022 //               compose b produces b.  Some kinds of attributes, like
00023 //               a TextureTransform, for instance, might produce a new
00024 //               result: a compose b produces c.
00025 ////////////////////////////////////////////////////////////////////
00026 INLINE CPT(RenderAttrib) RenderAttrib::
00027 compose(const RenderAttrib *other) const {
00028   return compose_impl(other);
00029 }
00030 
00031 ////////////////////////////////////////////////////////////////////
00032 //     Function: RenderAttrib::invert_compose
00033 //       Access: Published
00034 //  Description: Returns a new RenderAttrib object that represents the
00035 //               composition of the inverse of this attrib with the
00036 //               other attrib.  In most cases, this is the same as the
00037 //               other attrib; !a compose b produces b.  Some kinds of
00038 //               attributes, like a TextureTransform, for instance,
00039 //               might produce a new result: !a compose b produces c.
00040 //
00041 //               This is similar to compose() except that the source
00042 //               attrib is inverted first.  This is used to compute
00043 //               the relative attribute for one node as viewed from
00044 //               some other node, which is especially useful for
00045 //               transform-type attributes.
00046 ////////////////////////////////////////////////////////////////////
00047 INLINE CPT(RenderAttrib) RenderAttrib::
00048 invert_compose(const RenderAttrib *other) const {
00049   return invert_compose_impl(other);
00050 }
00051 
00052 ////////////////////////////////////////////////////////////////////
00053 //     Function: RenderAttrib::always_reissue
00054 //       Access: Public
00055 //  Description: Returns true if the RenderAttrib should be reissued
00056 //               to the GSG with every state change, even if it is the
00057 //               same pointer as it was before; or false for the
00058 //               normal case, to reissue only when the RenderAttrib
00059 //               pointer changes.
00060 ////////////////////////////////////////////////////////////////////
00061 INLINE bool RenderAttrib::
00062 always_reissue() const {
00063   return _always_reissue;
00064 }
00065 
00066 ////////////////////////////////////////////////////////////////////
00067 //     Function: RenderAttrib::compare_to
00068 //       Access: Published
00069 //  Description: Provides an arbitrary ordering among all unique
00070 //               RenderAttribs, so we can store the essentially
00071 //               different ones in a big set and throw away the rest.
00072 //
00073 //               This method is not needed outside of the RenderAttrib
00074 //               class because all equivalent RenderAttrib objects are
00075 //               guaranteed to share the same pointer; thus, a pointer
00076 //               comparison is always sufficient.
00077 ////////////////////////////////////////////////////////////////////
00078 INLINE int RenderAttrib::
00079 compare_to(const RenderAttrib &other) const {
00080   // First, we compare the types; if they are of different types then
00081   // they sort differently.
00082   TypeHandle type = get_type();
00083   TypeHandle other_type = other.get_type();
00084   if (type != other_type) {
00085     return type.get_index() - other_type.get_index();
00086   }
00087 
00088   // We only call compare_to_impl() if they have the same type.
00089   return compare_to_impl(&other);
00090 }
00091 
00092 ////////////////////////////////////////////////////////////////////
00093 //     Function: RenderAttrib::get_hash
00094 //       Access: Published
00095 //  Description: Returns a suitable hash value for phash_map.
00096 ////////////////////////////////////////////////////////////////////
00097 INLINE size_t RenderAttrib::
00098 get_hash() const {
00099   size_t hash = get_hash_impl();
00100 
00101   // The type is also added to the hash.
00102   hash = int_hash::add_hash(hash, get_type().get_index());
00103   return hash;
00104 }
00105 
00106 ////////////////////////////////////////////////////////////////////
00107 //     Function: RenderAttrib::get_unique
00108 //       Access: Published
00109 //  Description: Returns the pointer to the unique RenderAttrib in
00110 //               the cache that is equivalent to this one.  This may
00111 //               be the same pointer as this object, or it may be a
00112 //               different pointer; but it will be an equivalent
00113 //               object, and it will be a shared pointer.  This may be
00114 //               called from time to time to improve cache benefits.
00115 ////////////////////////////////////////////////////////////////////
00116 INLINE CPT(RenderAttrib) RenderAttrib::
00117 get_unique() const {
00118   return return_unique((RenderAttrib *)this);
00119 }
00120 
00121 ////////////////////////////////////////////////////////////////////
00122 //     Function: RenderAttrib::get_auto_shader_attrib
00123 //       Access: Published
00124 //  Description: Returns the variant of this RenderAttrib that's most
00125 //               relevant for associating with an auto-generated
00126 //               shader.  This should be a new RenderAttrib of the
00127 //               same type as this one, with any superfluous data set
00128 //               to neutral.  Only the parts of the attrib that
00129 //               contribute to the shader should be reflected in the
00130 //               returned attrib.  The idea is to associate the
00131 //               auto-generated shader with the most neutral form of
00132 //               all states, to allow it to be shared across as many
00133 //               RenderState objects as possible.
00134 //
00135 //               If this RenderAttrib is completely irrelevant to the
00136 //               auto-shader, this should return NULL to indicate that
00137 //               the attrib won't be assocaited with the shader at
00138 //               all.  In this case the attrib does not contribute to
00139 //               the shader meaningfully.
00140 ////////////////////////////////////////////////////////////////////
00141 INLINE CPT(RenderAttrib) RenderAttrib::
00142 get_auto_shader_attrib(const RenderState *state) const {
00143   return get_auto_shader_attrib_impl(state);
00144 }
00145 
00146 ////////////////////////////////////////////////////////////////////
00147 //     Function: RenderAttrib::register_slot
00148 //       Access: Public, Static
00149 //  Description: Adds the indicated TypeHandle to the registry, if it
00150 //               is not there already, and returns a unique slot
00151 //               number.  See RenderAttribRegistry.
00152 ////////////////////////////////////////////////////////////////////
00153 INLINE int RenderAttrib::
00154 register_slot(TypeHandle type_handle, int sort,
00155               RenderAttribRegistry::MakeDefaultFunc *make_default_func) {
00156   RenderAttribRegistry *reg = RenderAttribRegistry::get_global_ptr();
00157   return reg->register_slot(type_handle, sort, make_default_func);
00158 }
 All Classes Functions Variables Enumerations