Panda3D
 All Classes Functions Variables Enumerations
geomVertexReader.h
00001 // Filename: geomVertexReader.h
00002 // Created by:  drose (25Mar05)
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 #ifndef GEOMVERTEXREADER_H
00016 #define GEOMVERTEXREADER_H
00017 
00018 #include "pandabase.h"
00019 #include "geomVertexData.h"
00020 #include "geomVertexColumn.h"
00021 #include "internalName.h"
00022 #include "luse.h"
00023 #include "pointerTo.h"
00024 
00025 ////////////////////////////////////////////////////////////////////
00026 //       Class : GeomVertexReader
00027 // Description : This object provides a high-level interface for
00028 //               quickly reading a sequence of numeric values from a
00029 //               vertex table. 
00030 //
00031 //               It is particularly optimized for reading a single
00032 //               column of data values for a series of vertices,
00033 //               without changing columns between each number.
00034 //               Although you can also use one GeomVertexReader to
00035 //               read across the columns if it is convenient, by
00036 //               calling set_column() repeatedly at each vertex, it is
00037 //               faster to read down the columns, and to use a
00038 //               different GeomVertexReader for each column.
00039 //
00040 //               Note that a GeomVertexReader does not keep a
00041 //               reference count to the actual vertex data buffer (it
00042 //               grabs the current data buffer from the GeomVertexData
00043 //               whenever set_column() is called).  This means that it
00044 //               is important not to keep a GeomVertexReader object
00045 //               around over a long period of time in which the data
00046 //               buffer is likely to be deallocated; it is intended
00047 //               for making a quick pass over the data in one session.
00048 //
00049 //               It also means that you should create any
00050 //               GeomVertexWriters *before* creating GeomVertexReaders
00051 //               on the same data, since the writer itself might cause
00052 //               the vertex buffer to be deallocated.  Better yet, use
00053 //               a GeomVertexRewriter if you are going to create both
00054 //               of them anyway.
00055 ////////////////////////////////////////////////////////////////////
00056 class EXPCL_PANDA_GOBJ GeomVertexReader : public GeomEnums {
00057 PUBLISHED:
00058   INLINE GeomVertexReader(Thread *current_thread = Thread::get_current_thread());
00059   INLINE GeomVertexReader(const GeomVertexData *vertex_data,
00060                           Thread *current_thread = Thread::get_current_thread());
00061   INLINE GeomVertexReader(const GeomVertexData *vertex_data,
00062                           const string &name,
00063                           Thread *current_thread = Thread::get_current_thread());
00064   INLINE GeomVertexReader(const GeomVertexData *vertex_data,
00065                           const InternalName *name,
00066                           Thread *current_thread = Thread::get_current_thread());
00067   INLINE GeomVertexReader(const GeomVertexArrayData *array_data,
00068                           Thread *current_thread = Thread::get_current_thread());
00069   INLINE GeomVertexReader(const GeomVertexArrayData *array_data, 
00070                           int column,
00071                           Thread *current_thread = Thread::get_current_thread());
00072 
00073 public:
00074   INLINE GeomVertexReader(const GeomVertexDataPipelineReader *data_reader,
00075                           const InternalName *name,
00076                           bool force = true);
00077 
00078 PUBLISHED:
00079   INLINE GeomVertexReader(const GeomVertexReader &copy);
00080   INLINE void operator = (const GeomVertexReader &copy);
00081   INLINE ~GeomVertexReader();
00082 
00083   INLINE const GeomVertexData *get_vertex_data() const;
00084   INLINE const GeomVertexArrayData *get_array_data() const;
00085   INLINE const GeomVertexArrayDataHandle *get_array_handle() const;
00086   INLINE size_t get_stride() const;
00087   INLINE Thread *get_current_thread() const;
00088 
00089   INLINE void set_force(bool force);
00090   INLINE bool get_force() const;
00091 
00092   INLINE bool set_column(int column);
00093   INLINE bool set_column(const string &name);
00094   INLINE bool set_column(const InternalName *name);
00095   bool set_column(int array, const GeomVertexColumn *column);
00096 
00097   INLINE void clear();
00098   INLINE bool has_column() const;
00099   INLINE int get_array() const;
00100   INLINE const GeomVertexColumn *get_column() const;
00101 
00102   INLINE void set_row_unsafe(int row);
00103   INLINE void set_row(int row);
00104 
00105   INLINE int get_start_row() const;
00106   INLINE int get_read_row() const;
00107   INLINE bool is_at_end() const;
00108 
00109   INLINE float get_data1f();
00110   INLINE const LVecBase2f &get_data2f();
00111   INLINE const LVecBase3f &get_data3f();
00112   INLINE const LVecBase4f &get_data4f();
00113 
00114   INLINE double get_data1d();
00115   INLINE const LVecBase2d &get_data2d();
00116   INLINE const LVecBase3d &get_data3d();
00117   INLINE const LVecBase4d &get_data4d();
00118 
00119   INLINE PN_stdfloat get_data1();
00120   INLINE const LVecBase2 &get_data2();
00121   INLINE const LVecBase3 &get_data3();
00122   INLINE const LVecBase4 &get_data4();
00123 
00124   INLINE int get_data1i();
00125   INLINE const int *get_data2i();
00126   INLINE const int *get_data3i();
00127   INLINE const int *get_data4i();
00128 
00129   void output(ostream &out) const;
00130 
00131 protected:
00132   INLINE GeomVertexColumn::Packer *get_packer() const;
00133 
00134 private:
00135   void initialize();
00136 
00137   INLINE bool set_pointer(int row);
00138   INLINE void quick_set_pointer(int row);
00139   INLINE const unsigned char *inc_pointer();
00140 
00141   bool set_vertex_column(int array, const GeomVertexColumn *column,
00142                          const GeomVertexDataPipelineReader *data_reader);
00143   bool set_array_column(const GeomVertexColumn *column);
00144 
00145   // It is important that we only store *one* of the following two
00146   // pointers.  If we are storing a GeomVertexData/array index, we
00147   // must not keep a pointer to the particular ArrayData we are
00148   // working on (if we do, it may result in an extra copy of the data
00149   // due to holding the reference count).
00150   CPT(GeomVertexData) _vertex_data;
00151   int _array;
00152   CPT(GeomVertexArrayData) _array_data;
00153 
00154   Thread *_current_thread;
00155   GeomVertexColumn::Packer *_packer;
00156   int _stride;
00157 
00158   CPT(GeomVertexArrayDataHandle) _handle;
00159   const unsigned char *_pointer_begin;
00160   const unsigned char *_pointer_end;
00161   const unsigned char *_pointer;
00162 
00163   int _start_row;
00164   bool _force;
00165 
00166 #ifndef NDEBUG
00167   // This is defined just for the benefit of having something non-NULL
00168   // to return from a nassertr() call.
00169   static const unsigned char empty_buffer[100];
00170 #endif
00171 };
00172 
00173 INLINE ostream &
00174 operator << (ostream &out, const GeomVertexReader &reader) {
00175   reader.output(out);
00176   return out;
00177 }
00178 
00179 #include "geomVertexReader.I"
00180 
00181 #endif
 All Classes Functions Variables Enumerations