Panda3D

vertexDataBuffer.h

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).  In this state, _reserved_size might
00037 //               be greater than or equal to _size.
00038 //
00039 //               paged - the buffer's memory is owned by a
00040 //               VertexDataBlock.  That block might itself be
00041 //               resident, compressed, or paged to disk.  If it is
00042 //               resident, the memory may still be accessed directly
00043 //               from the block.  However, this memory is considered
00044 //               read-only.  In this state, _reserved_size will always
00045 //               equal _size.
00046 //
00047 //               VertexDataBuffers start out in independent state.
00048 //               They get moved to paged state when their owning
00049 //               GeomVertexArrayData objects get evicted from the
00050 //               _independent_lru.  They can get moved back to
00051 //               independent state if they are modified
00052 //               (e.g. get_write_pointer() or realloc() is called).
00053 //
00054 //               The idea is to keep the highly dynamic and
00055 //               frequently-modified VertexDataBuffers resident in
00056 //               easy-to-access memory, while collecting the static
00057 //               and rarely accessed VertexDataBuffers together onto
00058 //               pages, where they may be written to disk as a block
00059 //               when necessary.
00060 ////////////////////////////////////////////////////////////////////
00061 class EXPCL_PANDA_GOBJ VertexDataBuffer {
00062 public:
00063   INLINE VertexDataBuffer();
00064   INLINE VertexDataBuffer(size_t size);
00065   INLINE VertexDataBuffer(const VertexDataBuffer &copy);
00066   void operator = (const VertexDataBuffer &copy);
00067   INLINE ~VertexDataBuffer();
00068 
00069   INLINE const unsigned char *get_read_pointer(bool force) const;
00070   INLINE unsigned char *get_write_pointer();
00071 
00072   INLINE size_t get_size() const;
00073   INLINE size_t get_reserved_size() const;
00074   INLINE void set_size(size_t size);
00075   INLINE void clean_realloc(size_t reserved_size);
00076   INLINE void unclean_realloc(size_t reserved_size);
00077   INLINE void clear();
00078 
00079   INLINE void page_out(VertexDataBook &book);
00080 
00081   void swap(VertexDataBuffer &other);
00082 
00083 private:
00084   void do_clean_realloc(size_t size);
00085   void do_unclean_realloc(size_t size);
00086 
00087   void do_page_out(VertexDataBook &book);
00088   void do_page_in();
00089 
00090   unsigned char *_resident_data;
00091   size_t _size;
00092   size_t _reserved_size;
00093   PT(VertexDataBlock) _block;
00094   LightMutex _lock;
00095 
00096 public:
00097   static TypeHandle get_class_type() {
00098     return _type_handle;
00099   }
00100   static void init_type() {
00101     register_type(_type_handle, "VertexDataBuffer");
00102   }
00103 
00104 private:
00105   static TypeHandle _type_handle;
00106 };
00107 
00108 #include "vertexDataBuffer.I"
00109 
00110 #endif
 All Classes Functions Variables Enumerations