Panda3D

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 Thread *get_current_thread() const;
00086 
00087   INLINE void set_force(bool force);
00088   INLINE bool get_force() const;
00089 
00090   INLINE bool set_column(int column);
00091   INLINE bool set_column(const string &name);
00092   INLINE bool set_column(const InternalName *name);
00093   bool set_column(int array, const GeomVertexColumn *column);
00094 
00095   INLINE void clear();
00096   INLINE bool has_column() const;
00097   INLINE int get_array() const;
00098   INLINE const GeomVertexColumn *get_column() const;
00099 
00100   INLINE void set_row(int row);
00101 
00102   INLINE int get_start_row() const;
00103   INLINE int get_read_row() const;
00104   INLINE bool is_at_end() const;
00105 
00106   INLINE float get_data1f();
00107   INLINE const LVecBase2f &get_data2f();
00108   INLINE const LVecBase3f &get_data3f();
00109   INLINE const LVecBase4f &get_data4f();
00110 
00111   INLINE int get_data1i();
00112   INLINE const int *get_data2i();
00113   INLINE const int *get_data3i();
00114   INLINE const int *get_data4i();
00115 
00116   void output(ostream &out) const;
00117 
00118 protected:
00119   INLINE GeomVertexColumn::Packer *get_packer() const;
00120 
00121 private:
00122   void initialize();
00123 
00124   INLINE bool set_pointer(int row);
00125   INLINE void quick_set_pointer(int row);
00126   INLINE const unsigned char *inc_pointer();
00127 
00128   bool set_vertex_column(int array, const GeomVertexColumn *column,
00129                          const GeomVertexDataPipelineReader *data_reader);
00130   bool set_array_column(const GeomVertexColumn *column);
00131 
00132   // It is important that we only store *one* of the following two
00133   // pointers.  If we are storing a GeomVertexData/array index, we
00134   // must not keep a pointer to the particular ArrayData we are
00135   // working on (if we do, it may result in an extra copy of the data
00136   // due to holding the reference count).
00137   CPT(GeomVertexData) _vertex_data;
00138   int _array;
00139   CPT(GeomVertexArrayData) _array_data;
00140 
00141   Thread *_current_thread;
00142   GeomVertexColumn::Packer *_packer;
00143   int _stride;
00144 
00145   CPT(GeomVertexArrayDataHandle) _handle;
00146   const unsigned char *_pointer_begin;
00147   const unsigned char *_pointer_end;
00148   const unsigned char *_pointer;
00149 
00150   int _start_row;
00151   bool _force;
00152 
00153 #ifndef NDEBUG
00154   // This is defined just for the benefit of having something non-NULL
00155   // to return from a nassertr() call.
00156   static const unsigned char empty_buffer[100];
00157 #endif
00158 };
00159 
00160 INLINE ostream &
00161 operator << (ostream &out, const GeomVertexReader &reader) {
00162   reader.output(out);
00163   return out;
00164 }
00165 
00166 #include "geomVertexReader.I"
00167 
00168 #endif
 All Classes Functions Variables Enumerations