Panda3D
|
00001 // Filename: geomVertexColumn.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: GeomVertexColumn::Default Constructor 00018 // Access: Private 00019 // Description: Creates an invalid column. Used on when constructing 00020 // from a bam file. 00021 //////////////////////////////////////////////////////////////////// 00022 INLINE GeomVertexColumn:: 00023 GeomVertexColumn() : 00024 _packer(NULL) 00025 { 00026 } 00027 00028 //////////////////////////////////////////////////////////////////// 00029 // Function: GeomVertexColumn::Constructor 00030 // Access: Published 00031 // Description: 00032 //////////////////////////////////////////////////////////////////// 00033 INLINE GeomVertexColumn:: 00034 GeomVertexColumn(InternalName *name, int num_components, 00035 NumericType numeric_type, Contents contents, 00036 int start) : 00037 _name(name), 00038 _num_components(num_components), 00039 _numeric_type(numeric_type), 00040 _contents(contents), 00041 _start(start), 00042 _packer(NULL) 00043 { 00044 setup(); 00045 } 00046 00047 //////////////////////////////////////////////////////////////////// 00048 // Function: GeomVertexColumn::Copy Constructor 00049 // Access: Published 00050 // Description: 00051 //////////////////////////////////////////////////////////////////// 00052 INLINE GeomVertexColumn:: 00053 GeomVertexColumn(const GeomVertexColumn ©) : 00054 _name(copy._name), 00055 _num_components(copy._num_components), 00056 _numeric_type(copy._numeric_type), 00057 _contents(copy._contents), 00058 _start(copy._start), 00059 _packer(NULL) 00060 { 00061 setup(); 00062 } 00063 00064 //////////////////////////////////////////////////////////////////// 00065 // Function: GeomVertexColumn::Destructor 00066 // Access: Published 00067 // Description: 00068 //////////////////////////////////////////////////////////////////// 00069 INLINE GeomVertexColumn:: 00070 ~GeomVertexColumn() { 00071 delete _packer; 00072 } 00073 00074 //////////////////////////////////////////////////////////////////// 00075 // Function: GeomVertexColumn::get_name 00076 // Access: Published 00077 // Description: Returns the name of this particular data field, 00078 // e.g. "vertex" or "normal". The name may be a 00079 // user-defined string, or it may be one of the standard 00080 // system-defined field types. Only the system-defined 00081 // field types are used for the actual rendering. 00082 //////////////////////////////////////////////////////////////////// 00083 INLINE InternalName *GeomVertexColumn:: 00084 get_name() const { 00085 return _name; 00086 } 00087 00088 //////////////////////////////////////////////////////////////////// 00089 // Function: GeomVertexColumn::get_num_components 00090 // Access: Published 00091 // Description: Returns the number of components of the column: 00092 // the number of instances of the NumericType in each 00093 // element. This is usually, but not always, the same 00094 // thing as get_num_values(). 00095 //////////////////////////////////////////////////////////////////// 00096 INLINE int GeomVertexColumn:: 00097 get_num_components() const { 00098 return _num_components; 00099 } 00100 00101 //////////////////////////////////////////////////////////////////// 00102 // Function: GeomVertexColumn::get_num_values 00103 // Access: Published 00104 // Description: Returns the number of numeric values of the column: 00105 // the number of distinct numeric values that go into 00106 // each element. This is usually, but not always, the 00107 // same thing as get_num_components(); the difference is 00108 // in the case of a composite numeric type like 00109 // NT_packed_dcba, which has four numeric values per 00110 // component. 00111 //////////////////////////////////////////////////////////////////// 00112 INLINE int GeomVertexColumn:: 00113 get_num_values() const { 00114 return _num_values; 00115 } 00116 00117 //////////////////////////////////////////////////////////////////// 00118 // Function: GeomVertexColumn::get_numeric_type 00119 // Access: Published 00120 // Description: Returns the token representing the numeric type of 00121 // the data storage. 00122 //////////////////////////////////////////////////////////////////// 00123 INLINE GeomVertexColumn::NumericType GeomVertexColumn:: 00124 get_numeric_type() const { 00125 return _numeric_type; 00126 } 00127 00128 //////////////////////////////////////////////////////////////////// 00129 // Function: GeomVertexColumn::get_contents 00130 // Access: Published 00131 // Description: Returns the token representing the semantic meaning of 00132 // the stored value. 00133 //////////////////////////////////////////////////////////////////// 00134 INLINE GeomVertexColumn::Contents GeomVertexColumn:: 00135 get_contents() const { 00136 return _contents; 00137 } 00138 00139 //////////////////////////////////////////////////////////////////// 00140 // Function: GeomVertexColumn::get_start 00141 // Access: Published 00142 // Description: Returns the byte within the array record at which 00143 // this column starts. This can be set to non-zero 00144 // to implement interleaved arrays. 00145 //////////////////////////////////////////////////////////////////// 00146 INLINE int GeomVertexColumn:: 00147 get_start() const { 00148 return _start; 00149 } 00150 00151 //////////////////////////////////////////////////////////////////// 00152 // Function: GeomVertexColumn::get_component_bytes 00153 // Access: Published 00154 // Description: Returns the number of bytes used by each component 00155 // (that is, by one element of the numeric type). 00156 //////////////////////////////////////////////////////////////////// 00157 INLINE int GeomVertexColumn:: 00158 get_component_bytes() const { 00159 return _component_bytes; 00160 } 00161 00162 //////////////////////////////////////////////////////////////////// 00163 // Function: GeomVertexColumn::get_total_bytes 00164 // Access: Published 00165 // Description: Returns the number of bytes used by each element of 00166 // the column: component_bytes * num_components. 00167 //////////////////////////////////////////////////////////////////// 00168 INLINE int GeomVertexColumn:: 00169 get_total_bytes() const { 00170 return _total_bytes; 00171 } 00172 00173 //////////////////////////////////////////////////////////////////// 00174 // Function: GeomVertexColumn::has_homogeneous_coord 00175 // Access: Published 00176 // Description: Returns true if this Contents type is one that 00177 // includes a homogeneous coordinate in the fourth 00178 // component, or false otherwise. If this is true, 00179 // correct operation on the vertex data may require 00180 // scaling by the homogeneous coordinate from time to 00181 // time (but in general this is handled automatically if 00182 // you use the 3-component or smaller forms of 00183 // get_data() and set_data()). 00184 //////////////////////////////////////////////////////////////////// 00185 INLINE bool GeomVertexColumn:: 00186 has_homogeneous_coord() const { 00187 switch (_contents) { 00188 case C_point: 00189 case C_texcoord: 00190 return true; 00191 00192 default: 00193 return false; 00194 } 00195 } 00196 00197 //////////////////////////////////////////////////////////////////// 00198 // Function: GeomVertexColumn::overlaps_with 00199 // Access: Published 00200 // Description: Returns true if this column overlaps with any of 00201 // the bytes in the indicated range, false if it does 00202 // not. 00203 //////////////////////////////////////////////////////////////////// 00204 INLINE bool GeomVertexColumn:: 00205 overlaps_with(int start_byte, int num_bytes) const { 00206 return (_start < start_byte + num_bytes && 00207 _start + _total_bytes > start_byte); 00208 } 00209 00210 //////////////////////////////////////////////////////////////////// 00211 // Function: GeomVertexColumn::is_bytewise_equivalent 00212 // Access: Published 00213 // Description: Returns true if the data store of this column is 00214 // exactly the same as that of the other, irrespective 00215 // of name or start position within the record. 00216 //////////////////////////////////////////////////////////////////// 00217 INLINE bool GeomVertexColumn:: 00218 is_bytewise_equivalent(const GeomVertexColumn &other) const { 00219 // Not sure if the contents are relevant, but let's say that they 00220 // are. 00221 return (_num_components == other._num_components && 00222 _numeric_type == other._numeric_type && 00223 _contents == other._contents); 00224 } 00225 00226 //////////////////////////////////////////////////////////////////// 00227 // Function: GeomVertexColumn::is_packed_argb 00228 // Access: Public 00229 // Description: Returns true if this column is the standard 00230 // DirectX representation of 4-component color: C_color, 00231 // in NT_packed_dabc, with 1 component (4 values). 00232 //////////////////////////////////////////////////////////////////// 00233 INLINE bool GeomVertexColumn:: 00234 is_packed_argb() const { 00235 return (_num_components == 1 && 00236 _numeric_type == NT_packed_dabc && 00237 _contents == C_color); 00238 } 00239 00240 //////////////////////////////////////////////////////////////////// 00241 // Function: GeomVertexColumn::is_uint8_rgba 00242 // Access: Public 00243 // Description: Returns true if this column is the standard 00244 // OpenGL representation of 4-component color: C_color, 00245 // in NT_uint8, with 4 components. 00246 //////////////////////////////////////////////////////////////////// 00247 INLINE bool GeomVertexColumn:: 00248 is_uint8_rgba() const { 00249 return (_num_components == 4 && 00250 _numeric_type == NT_uint8 && 00251 _contents == C_color); 00252 } 00253 00254 //////////////////////////////////////////////////////////////////// 00255 // Function: GeomVertexColumn::compare_to 00256 // Access: Public 00257 // Description: This is used to unquify columns, and hence 00258 // formats, for the GeomVertexFormat registry. 00259 //////////////////////////////////////////////////////////////////// 00260 INLINE int GeomVertexColumn:: 00261 compare_to(const GeomVertexColumn &other) const { 00262 if (_name != other._name) { 00263 return _name < other._name ? -1 : 1; 00264 } 00265 if (_num_components != other._num_components) { 00266 return _num_components - other._num_components; 00267 } 00268 if (_numeric_type != other._numeric_type) { 00269 return (int)_numeric_type - (int)other._numeric_type; 00270 } 00271 if (_contents != other._contents) { 00272 return (int)_contents - (int)other._contents; 00273 } 00274 if (_start != other._start) { 00275 return _start - other._start; 00276 } 00277 return 0; 00278 } 00279 00280 //////////////////////////////////////////////////////////////////// 00281 // Function: GeomVertexColumn::operator == 00282 // Access: Public 00283 // Description: Returns true if the two columns are exactly 00284 // equivalent, false otherwise. 00285 //////////////////////////////////////////////////////////////////// 00286 INLINE bool GeomVertexColumn:: 00287 operator == (const GeomVertexColumn &other) const { 00288 return compare_to(other) == 0; 00289 } 00290 00291 //////////////////////////////////////////////////////////////////// 00292 // Function: GeomVertexColumn::operator != 00293 // Access: Public 00294 // Description: 00295 //////////////////////////////////////////////////////////////////// 00296 INLINE bool GeomVertexColumn:: 00297 operator != (const GeomVertexColumn &other) const { 00298 return compare_to(other) != 0; 00299 } 00300 00301 //////////////////////////////////////////////////////////////////// 00302 // Function: GeomVertexColumn::operator < 00303 // Access: Public 00304 // Description: This is used to put columns in order within a 00305 // particular GeomVertexArrayFormat. Note that it is 00306 // *not* in the same space as operator == and operator 00307 // !=. 00308 //////////////////////////////////////////////////////////////////// 00309 INLINE bool GeomVertexColumn:: 00310 operator < (const GeomVertexColumn &other) const { 00311 if (_start != other._start) { 00312 return _start < other._start; 00313 } 00314 if (_total_bytes < other._total_bytes) { 00315 return _total_bytes < other._total_bytes; 00316 } 00317 return 0; 00318 } 00319 00320 INLINE ostream & 00321 operator << (ostream &out, const GeomVertexColumn &obj) { 00322 obj.output(out); 00323 return out; 00324 } 00325 00326 //////////////////////////////////////////////////////////////////// 00327 // Function: GeomVertexColumn::Packer::maybe_scale_color 00328 // Access: Public 00329 // Description: Converts an integer (typically a uint8) value to a 00330 // floating-point value. If the contents value 00331 // indicates this is a color value, scales it into the 00332 // range 0..1 per convention; otherwise leaves it alone. 00333 //////////////////////////////////////////////////////////////////// 00334 INLINE float GeomVertexColumn::Packer:: 00335 maybe_scale_color(unsigned int value) { 00336 if (_column->get_contents() == C_color) { 00337 return (float)value / 255.0f; 00338 } else { 00339 return (float)value; 00340 } 00341 } 00342 00343 //////////////////////////////////////////////////////////////////// 00344 // Function: GeomVertexColumn::Packer::maybe_scale_color 00345 // Access: Public 00346 // Description: Converts a pair of integers into the _v2 member. See 00347 // one-parameter maybe_scale_color() for more info. 00348 //////////////////////////////////////////////////////////////////// 00349 INLINE void GeomVertexColumn::Packer:: 00350 maybe_scale_color(unsigned int a, unsigned int b) { 00351 if (_column->get_contents() == C_color) { 00352 _v2.set((float)a / 255.0f, 00353 (float)b / 255.0f); 00354 } else { 00355 _v2.set((float)a, (float)b); 00356 } 00357 } 00358 00359 //////////////////////////////////////////////////////////////////// 00360 // Function: GeomVertexColumn::Packer::maybe_scale_color 00361 // Access: Public 00362 // Description: Converts a pair of integers into the _v3 member. See 00363 // one-parameter maybe_scale_color() for more info. 00364 //////////////////////////////////////////////////////////////////// 00365 INLINE void GeomVertexColumn::Packer:: 00366 maybe_scale_color(unsigned int a, unsigned int b, unsigned int c) { 00367 if (_column->get_contents() == C_color) { 00368 _v3.set((float)a / 255.0f, 00369 (float)b / 255.0f, 00370 (float)c / 255.0f); 00371 } else { 00372 _v3.set((float)a, (float)b, (float)c); 00373 } 00374 } 00375 00376 //////////////////////////////////////////////////////////////////// 00377 // Function: GeomVertexColumn::Packer::maybe_scale_color 00378 // Access: Public 00379 // Description: Converts a pair of integers into the _v4 member. See 00380 // one-parameter maybe_scale_color() for more info. 00381 //////////////////////////////////////////////////////////////////// 00382 INLINE void GeomVertexColumn::Packer:: 00383 maybe_scale_color(unsigned int a, unsigned int b, unsigned int c, 00384 unsigned int d) { 00385 if (_column->get_contents() == C_color) { 00386 _v4.set((float)a / 255.0f, 00387 (float)b / 255.0f, 00388 (float)c / 255.0f, 00389 (float)d / 255.0f); 00390 } else { 00391 _v4.set((float)a, (float)b, (float)c, (float)d); 00392 } 00393 } 00394 00395 00396 //////////////////////////////////////////////////////////////////// 00397 // Function: GeomVertexColumn::Packer::maybe_unscale_color 00398 // Access: Public 00399 // Description: Converts a floating-point value to a uint8 value. If 00400 // the contents value indicates this is a color value, 00401 // scales it into the range 0..255 per convention; 00402 // otherwise leaves it alone. 00403 //////////////////////////////////////////////////////////////////// 00404 INLINE unsigned int GeomVertexColumn::Packer:: 00405 maybe_unscale_color(float data) { 00406 if (_column->get_contents() == C_color) { 00407 return (unsigned int)(data * 255.0f); 00408 } else { 00409 return (unsigned int)data; 00410 } 00411 } 00412 00413 //////////////////////////////////////////////////////////////////// 00414 // Function: GeomVertexColumn::Packer::maybe_unscale_color 00415 // Access: Public 00416 // Description: Converts an LVecBase2f into a pair of uint8 00417 // values. See one-parameter maybe_unscale_color() for 00418 // more info. 00419 //////////////////////////////////////////////////////////////////// 00420 INLINE void GeomVertexColumn::Packer:: 00421 maybe_unscale_color(const LVecBase2f &data) { 00422 if (_column->get_contents() == C_color) { 00423 _a = (unsigned int)(data[0] * 255.0f); 00424 _b = (unsigned int)(data[1] * 255.0f); 00425 } else { 00426 _a = (unsigned int)data[0]; 00427 _b = (unsigned int)data[1]; 00428 } 00429 } 00430 00431 //////////////////////////////////////////////////////////////////// 00432 // Function: GeomVertexColumn::Packer::maybe_unscale_color 00433 // Access: Public 00434 // Description: Converts an LVecBase3f into a pair of uint8 00435 // values. See one-parameter maybe_unscale_color() for 00436 // more info. 00437 //////////////////////////////////////////////////////////////////// 00438 INLINE void GeomVertexColumn::Packer:: 00439 maybe_unscale_color(const LVecBase3f &data) { 00440 if (_column->get_contents() == C_color) { 00441 _a = (unsigned int)(data[0] * 255.0f); 00442 _b = (unsigned int)(data[1] * 255.0f); 00443 _c = (unsigned int)(data[2] * 255.0f); 00444 } else { 00445 _a = (unsigned int)data[0]; 00446 _b = (unsigned int)data[1]; 00447 _c = (unsigned int)data[2]; 00448 } 00449 } 00450 00451 //////////////////////////////////////////////////////////////////// 00452 // Function: GeomVertexColumn::Packer::maybe_unscale_color 00453 // Access: Public 00454 // Description: Converts an LVecBase4f into a pair of uint8 00455 // values. See one-parameter maybe_unscale_color() for 00456 // more info. 00457 //////////////////////////////////////////////////////////////////// 00458 INLINE void GeomVertexColumn::Packer:: 00459 maybe_unscale_color(const LVecBase4f &data) { 00460 if (_column->get_contents() == C_color) { 00461 _a = (unsigned int)(data[0] * 255.0f); 00462 _b = (unsigned int)(data[1] * 255.0f); 00463 _c = (unsigned int)(data[2] * 255.0f); 00464 _d = (unsigned int)(data[3] * 255.0f); 00465 } else { 00466 _a = (unsigned int)data[0]; 00467 _b = (unsigned int)data[1]; 00468 _c = (unsigned int)data[2]; 00469 _d = (unsigned int)data[3]; 00470 } 00471 }