Panda3D
|
00001 // Filename: geomVertexWriter.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 GEOMVERTEXWRITER_H 00016 #define GEOMVERTEXWRITER_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 : GeomVertexWriter 00027 // Description : This object provides a high-level interface for 00028 // quickly writing a sequence of numeric values from a 00029 // vertex table. 00030 // 00031 // This object can be used both to replace existing 00032 // vertices in the table, or to extend the table with 00033 // new vertices. The set_data*() family of methods can 00034 // only be used to replace existing data; it is an error 00035 // to allow these to run past the end of the data. The 00036 // add_data*() family of methods, on the other hand, can 00037 // be used to replace existing data or add new data; if 00038 // you call set_row() into the middle of existing 00039 // data the add_data*() methods will behave like the 00040 // corresponding set_data*(), but if they run past the 00041 // end of existing data they will quietly add new 00042 // vertices. 00043 // 00044 // Like GeomVertexReader, the writer is particularly 00045 // optimized for writing a single column of data values 00046 // for a series of vertices, without changing columns 00047 // between each number. Although you can also use one 00048 // GeomVertexWriter to write across the columns if it is 00049 // convenient, by calling set_column() repeatedly at 00050 // each vertex, it is faster to write down the columns, 00051 // and to use a different GeomVertexWriter for each 00052 // column. 00053 // 00054 // Note that, like a GeomVertexReader, a 00055 // GeomVertexWriter does not keep a reference count to 00056 // the actual vertex data buffer. This means that it is 00057 // important not to keep a GeomVertexWriter object 00058 // around over a long period of time in which the data 00059 // buffer is likely to be deallocated; it is intended 00060 // for making a quick pass over the data in one session. 00061 // 00062 // It also means that you should create any 00063 // GeomVertexWriters *before* creating GeomVertexReaders 00064 // on the same data, since the writer itself might cause 00065 // the vertex buffer to be deallocated. Better yet, use 00066 // a GeomVertexRewriter if you are going to create both 00067 // of them anyway. 00068 //////////////////////////////////////////////////////////////////// 00069 class EXPCL_PANDA_GOBJ GeomVertexWriter : public GeomEnums { 00070 PUBLISHED: 00071 INLINE GeomVertexWriter(Thread *current_thread = Thread::get_current_thread()); 00072 INLINE GeomVertexWriter(GeomVertexData *vertex_data, 00073 Thread *current_thread = Thread::get_current_thread()); 00074 INLINE GeomVertexWriter(GeomVertexData *vertex_data, 00075 const string &name, 00076 Thread *current_thread = Thread::get_current_thread()); 00077 INLINE GeomVertexWriter(GeomVertexData *vertex_data, 00078 const InternalName *name, 00079 Thread *current_thread = Thread::get_current_thread()); 00080 INLINE GeomVertexWriter(GeomVertexArrayData *array_data, 00081 Thread *current_thread = Thread::get_current_thread()); 00082 INLINE GeomVertexWriter(GeomVertexArrayData *array_data, 00083 int column, 00084 Thread *current_thread = Thread::get_current_thread()); 00085 00086 public: 00087 INLINE GeomVertexWriter(GeomVertexDataPipelineWriter *data_writer, 00088 const InternalName *name); 00089 00090 PUBLISHED: 00091 INLINE GeomVertexWriter(const GeomVertexWriter ©); 00092 INLINE void operator = (const GeomVertexWriter ©); 00093 INLINE ~GeomVertexWriter(); 00094 00095 INLINE GeomVertexData *get_vertex_data() const; 00096 INLINE GeomVertexArrayData *get_array_data() const; 00097 INLINE GeomVertexArrayDataHandle *get_array_handle() const; 00098 INLINE size_t get_stride() const; 00099 INLINE Thread *get_current_thread() const; 00100 00101 INLINE bool set_column(int column); 00102 INLINE bool set_column(const string &name); 00103 INLINE bool set_column(const InternalName *name); 00104 bool set_column(int array, const GeomVertexColumn *column); 00105 INLINE void clear(); 00106 bool reserve_num_rows(int num_rows); 00107 00108 INLINE bool has_column() const; 00109 INLINE int get_array() const; 00110 INLINE const GeomVertexColumn *get_column() const; 00111 00112 INLINE void set_row_unsafe(int row); 00113 INLINE void set_row(int row); 00114 00115 INLINE int get_start_row() const; 00116 INLINE int get_write_row() const; 00117 INLINE bool is_at_end() const; 00118 00119 INLINE void set_data1f(float data); 00120 INLINE void set_data2f(float x, float y); 00121 INLINE void set_data2f(const LVecBase2f &data); 00122 INLINE void set_data3f(float x, float y, float z); 00123 INLINE void set_data3f(const LVecBase3f &data); 00124 INLINE void set_data4f(float x, float y, float z, float w); 00125 INLINE void set_data4f(const LVecBase4f &data); 00126 00127 INLINE void set_data1d(double data); 00128 INLINE void set_data2d(double x, double y); 00129 INLINE void set_data2d(const LVecBase2d &data); 00130 INLINE void set_data3d(double x, double y, double z); 00131 INLINE void set_data3d(const LVecBase3d &data); 00132 INLINE void set_data4d(double x, double y, double z, double w); 00133 INLINE void set_data4d(const LVecBase4d &data); 00134 00135 INLINE void set_data1(PN_stdfloat data); 00136 INLINE void set_data2(PN_stdfloat x, PN_stdfloat y); 00137 INLINE void set_data2(const LVecBase2 &data); 00138 INLINE void set_data3(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z); 00139 INLINE void set_data3(const LVecBase3 &data); 00140 INLINE void set_data4(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z, PN_stdfloat w); 00141 INLINE void set_data4(const LVecBase4 &data); 00142 00143 INLINE void set_data1i(int data); 00144 INLINE void set_data2i(int a, int b); 00145 INLINE void set_data2i(const int data[2]); 00146 INLINE void set_data3i(int a, int b, int c); 00147 INLINE void set_data3i(const int data[3]); 00148 INLINE void set_data4i(int a, int b, int c, int d); 00149 INLINE void set_data4i(const int data[4]); 00150 00151 INLINE void add_data1f(float data); 00152 INLINE void add_data2f(float x, float y); 00153 INLINE void add_data2f(const LVecBase2f &data); 00154 INLINE void add_data3f(float x, float y, float z); 00155 INLINE void add_data3f(const LVecBase3f &data); 00156 INLINE void add_data4f(float x, float y, float z, float w); 00157 INLINE void add_data4f(const LVecBase4f &data); 00158 00159 INLINE void add_data1d(double data); 00160 INLINE void add_data2d(double x, double y); 00161 INLINE void add_data2d(const LVecBase2d &data); 00162 INLINE void add_data3d(double x, double y, double z); 00163 INLINE void add_data3d(const LVecBase3d &data); 00164 INLINE void add_data4d(double x, double y, double z, double w); 00165 INLINE void add_data4d(const LVecBase4d &data); 00166 00167 INLINE void add_data1(PN_stdfloat data); 00168 INLINE void add_data2(PN_stdfloat x, PN_stdfloat y); 00169 INLINE void add_data2(const LVecBase2 &data); 00170 INLINE void add_data3(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z); 00171 INLINE void add_data3(const LVecBase3 &data); 00172 INLINE void add_data4(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z, PN_stdfloat w); 00173 INLINE void add_data4(const LVecBase4 &data); 00174 00175 INLINE void add_data1i(int data); 00176 INLINE void add_data2i(int a, int b); 00177 INLINE void add_data2i(const int data[2]); 00178 INLINE void add_data3i(int a, int b, int c); 00179 INLINE void add_data3i(const int data[3]); 00180 INLINE void add_data4i(int a, int b, int c, int d); 00181 INLINE void add_data4i(const int data[4]); 00182 00183 void output(ostream &out) const; 00184 00185 protected: 00186 INLINE GeomVertexColumn::Packer *get_packer() const; 00187 00188 private: 00189 class Writer; 00190 00191 void initialize(); 00192 00193 INLINE void set_pointer(int row); 00194 INLINE void quick_set_pointer(int row); 00195 INLINE unsigned char *inc_pointer(); 00196 INLINE unsigned char *inc_add_pointer(); 00197 00198 bool set_vertex_column(int array, const GeomVertexColumn *column, 00199 GeomVertexDataPipelineWriter *data_writer); 00200 bool set_array_column(const GeomVertexColumn *column); 00201 00202 // It is important that we only store *one* of the following two 00203 // pointers. If we are storing a GeomVertexData/array index, we 00204 // must not keep a pointer to the particular ArrayData we are 00205 // working on (if we do, it may result in an extra copy of the data 00206 // due to holding the reference count). 00207 PT(GeomVertexData) _vertex_data; 00208 int _array; 00209 PT(GeomVertexArrayData) _array_data; 00210 00211 Thread *_current_thread; 00212 GeomVertexColumn::Packer *_packer; 00213 int _stride; 00214 00215 PT(GeomVertexArrayDataHandle) _handle; 00216 unsigned char *_pointer_begin; 00217 unsigned char *_pointer_end; 00218 unsigned char *_pointer; 00219 00220 int _start_row; 00221 00222 #ifndef NDEBUG 00223 // This is defined just for the benefit of having something non-NULL 00224 // to return from a nassertr() call. 00225 static unsigned char empty_buffer[100]; 00226 #endif 00227 }; 00228 00229 INLINE ostream & 00230 operator << (ostream &out, const GeomVertexWriter &writer) { 00231 writer.output(out); 00232 return out; 00233 } 00234 00235 #include "geomVertexWriter.I" 00236 00237 #endif