Panda3D
 All Classes Functions Variables Enumerations
geomVertexArrayFormat.I
00001 // Filename: geomVertexArrayFormat.I
00002 // Created by:  drose (06Mar05)
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: GeomVertexArrayFormat::is_registered
00018 //       Access: Published
00019 //  Description: Returns true if this format has been registered,
00020 //               false if it has not.  It may not be used for a Geom
00021 //               until it has been registered, but once registered, it
00022 //               may no longer be modified.
00023 ////////////////////////////////////////////////////////////////////
00024 INLINE bool GeomVertexArrayFormat::
00025 is_registered() const {
00026   return _is_registered;
00027 }
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 //     Function: GeomVertexArrayFormat::register_format
00031 //       Access: Published, Static
00032 //  Description: Adds the indicated format to the registry, if there
00033 //               is not an equivalent format already there; in either
00034 //               case, returns the pointer to the equivalent format
00035 //               now in the registry.
00036 //
00037 //               This is similar to
00038 //               GeomVertexFormat::register_format(), except that you
00039 //               generally need not call it explicitly.  Calling
00040 //               GeomVertexFormat::register_format() automatically
00041 //               registers all of the nested array formats.
00042 ////////////////////////////////////////////////////////////////////
00043 INLINE CPT(GeomVertexArrayFormat) GeomVertexArrayFormat::
00044 register_format(const GeomVertexArrayFormat *format) {
00045   return get_registry()->register_format((GeomVertexArrayFormat *)format);
00046 }
00047 
00048 ////////////////////////////////////////////////////////////////////
00049 //     Function: GeomVertexArrayFormat::get_stride
00050 //       Access: Published
00051 //  Description: Returns the total number of bytes reserved in the
00052 //               array for each vertex.
00053 ////////////////////////////////////////////////////////////////////
00054 INLINE int GeomVertexArrayFormat::
00055 get_stride() const {
00056   return _stride;
00057 }
00058 
00059 ////////////////////////////////////////////////////////////////////
00060 //     Function: GeomVertexArrayFormat::set_stride
00061 //       Access: Published
00062 //  Description: Changes the total number of bytes reserved in the
00063 //               array for each vertex.  You may not reduce this below
00064 //               get_total_bytes(), but you may increase it
00065 //               arbitrarily.
00066 ////////////////////////////////////////////////////////////////////
00067 INLINE void GeomVertexArrayFormat::
00068 set_stride(int stride) {
00069   nassertv(!_is_registered);
00070   nassertv(_stride >= _total_bytes);
00071   _stride = stride;
00072 }
00073 
00074 ////////////////////////////////////////////////////////////////////
00075 //     Function: GeomVertexArrayFormat::get_pad_to
00076 //       Access: Published
00077 //  Description: Returns the byte divisor to which the data record
00078 //               must be padded to meet hardware limitations.  For
00079 //               instance, if this is 4, the stride will be
00080 //               automatically rounded up to the next multiple of 4
00081 //               bytes.  This value is automatically increased as
00082 //               needed to ensure the individual numeric components in
00083 //               the array are word-aligned.
00084 ////////////////////////////////////////////////////////////////////
00085 INLINE int GeomVertexArrayFormat::
00086 get_pad_to() const {
00087   return _pad_to;
00088 }
00089 
00090 ////////////////////////////////////////////////////////////////////
00091 //     Function: GeomVertexArrayFormat::set_pad_to
00092 //       Access: Published
00093 //  Description: Explicitly sets the byte divisor to which the data
00094 //               record must be padded to meet hardware limitations.
00095 //               See get_pad_to().  Normally it is not necessary to
00096 //               call this unless you have some specific requirements
00097 //               for row-to-row data alignment.  Note that this value
00098 //               may be automatically increased at each subsequent
00099 //               call to add_column().
00100 ////////////////////////////////////////////////////////////////////
00101 INLINE void GeomVertexArrayFormat::
00102 set_pad_to(int pad_to) {
00103   nassertv(pad_to >= 1);
00104 
00105   _pad_to = pad_to;
00106   _stride = ((_stride + _pad_to - 1) / _pad_to) * _pad_to;
00107 }
00108 
00109 ////////////////////////////////////////////////////////////////////
00110 //     Function: GeomVertexArrayFormat::get_total_bytes
00111 //       Access: Published
00112 //  Description: Returns the total number of bytes used by the data
00113 //               types within the format, including gaps between
00114 //               elements.
00115 ////////////////////////////////////////////////////////////////////
00116 INLINE int GeomVertexArrayFormat::
00117 get_total_bytes() const {
00118   return _total_bytes;
00119 }
00120 
00121 ////////////////////////////////////////////////////////////////////
00122 //     Function: GeomVertexArrayFormat::get_num_columns
00123 //       Access: Published
00124 //  Description: Returns the number of different columns in the
00125 //               array.
00126 ////////////////////////////////////////////////////////////////////
00127 INLINE int GeomVertexArrayFormat::
00128 get_num_columns() const {
00129   return (int)_columns.size();
00130 }
00131 
00132 ////////////////////////////////////////////////////////////////////
00133 //     Function: GeomVertexArrayFormat::get_column
00134 //       Access: Published
00135 //  Description: Returns the ith column of the array.
00136 ////////////////////////////////////////////////////////////////////
00137 INLINE const GeomVertexColumn *GeomVertexArrayFormat::
00138 get_column(int i) const {
00139   nassertr(i >= 0 && i < (int)_columns.size(), NULL);
00140   consider_sort_columns();
00141   return _columns[i];
00142 }
00143 
00144 ////////////////////////////////////////////////////////////////////
00145 //     Function: GeomVertexArrayFormat::has_column
00146 //       Access: Published
00147 //  Description: Returns true if the array has the named column,
00148 //               false otherwise.
00149 ////////////////////////////////////////////////////////////////////
00150 INLINE bool GeomVertexArrayFormat::
00151 has_column(const InternalName *name) const {
00152   return (get_column(name) != (GeomVertexColumn *)NULL);
00153 }
00154 
00155 ////////////////////////////////////////////////////////////////////
00156 //     Function: GeomVertexArrayFormat::get_registry
00157 //       Access: Private
00158 //  Description: Returns the global registry object.
00159 ////////////////////////////////////////////////////////////////////
00160 INLINE GeomVertexArrayFormat::Registry *GeomVertexArrayFormat::
00161 get_registry() {
00162   if (_registry == (Registry *)NULL) {
00163     make_registry();
00164   }
00165   return _registry;
00166 }
00167 
00168 ////////////////////////////////////////////////////////////////////
00169 //     Function: GeomVertexArrayFormat::consider_sort_columns
00170 //       Access: Private
00171 //  Description: Resorts the _columns vector if necessary.
00172 ////////////////////////////////////////////////////////////////////
00173 INLINE void GeomVertexArrayFormat::
00174 consider_sort_columns() const {
00175   if (_columns_unsorted) {
00176     ((GeomVertexArrayFormat *)this)->sort_columns();
00177   }
00178 }
00179 
00180 INLINE ostream &
00181 operator << (ostream &out, const GeomVertexArrayFormat &obj) {
00182   obj.output(out);
00183   return out;
00184 }
 All Classes Functions Variables Enumerations