Panda3D
|
00001 // Filename: vertexDataBuffer.h 00002 // Created by: drose (14May07) 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 VERTEXDATABUFFER_H 00016 #define VERTEXDATABUFFER_H 00017 00018 #include "pandabase.h" 00019 #include "vertexDataBook.h" 00020 #include "vertexDataBlock.h" 00021 #include "pointerTo.h" 00022 #include "virtualFile.h" 00023 #include "pStatCollector.h" 00024 #include "lightMutex.h" 00025 #include "lightMutexHolder.h" 00026 00027 //////////////////////////////////////////////////////////////////// 00028 // Class : VertexDataBuffer 00029 // Description : A block of bytes that stores the actual raw vertex 00030 // data referenced by a GeomVertexArrayData object. 00031 // 00032 // At any point, a buffer may be in any of two states: 00033 // 00034 // independent - the buffer's memory is resident, and 00035 // owned by the VertexDataBuffer object itself (in 00036 // _resident_data). 00037 // 00038 // paged - the buffer's memory is owned by a 00039 // VertexDataBlock. That block might itself be 00040 // resident, compressed, or paged to disk. If it is 00041 // resident, the memory may still be accessed directly 00042 // from the block. However, this memory is considered 00043 // read-only. 00044 // 00045 // VertexDataBuffers start out in independent state. 00046 // They get moved to paged state when their owning 00047 // GeomVertexArrayData objects get evicted from the 00048 // _independent_lru. They can get moved back to 00049 // independent state if they are modified 00050 // (e.g. get_write_pointer() or realloc() is called). 00051 // 00052 // The idea is to keep the highly dynamic and 00053 // frequently-modified VertexDataBuffers resident in 00054 // easy-to-access memory, while collecting the static 00055 // and rarely accessed VertexDataBuffers together onto 00056 // pages, where they may be written to disk as a block 00057 // when necessary. 00058 //////////////////////////////////////////////////////////////////// 00059 class EXPCL_PANDA_GOBJ VertexDataBuffer { 00060 public: 00061 INLINE VertexDataBuffer(); 00062 INLINE VertexDataBuffer(size_t size); 00063 INLINE VertexDataBuffer(const VertexDataBuffer ©); 00064 void operator = (const VertexDataBuffer ©); 00065 INLINE ~VertexDataBuffer(); 00066 00067 INLINE const unsigned char *get_read_pointer(bool force) const; 00068 INLINE unsigned char *get_write_pointer(); 00069 00070 INLINE size_t get_size() const; 00071 INLINE void clean_realloc(size_t size); 00072 INLINE void unclean_realloc(size_t size); 00073 INLINE void clear(); 00074 00075 INLINE void page_out(VertexDataBook &book); 00076 00077 INLINE void swap(VertexDataBuffer &other); 00078 00079 private: 00080 void do_clean_realloc(size_t size); 00081 void do_unclean_realloc(size_t size); 00082 00083 void do_page_out(VertexDataBook &book); 00084 void do_page_in(); 00085 00086 unsigned char *_resident_data; 00087 size_t _size; 00088 PT(VertexDataBlock) _block; 00089 LightMutex _lock; 00090 00091 public: 00092 static TypeHandle get_class_type() { 00093 return _type_handle; 00094 } 00095 static void init_type() { 00096 register_type(_type_handle, "VertexDataBuffer"); 00097 } 00098 00099 private: 00100 static TypeHandle _type_handle; 00101 }; 00102 00103 #include "vertexDataBuffer.I" 00104 00105 #endif