Panda3D
 All Classes Functions Variables Enumerations
vertexDataBuffer.h
1 // Filename: vertexDataBuffer.h
2 // Created by: drose (14May07)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef VERTEXDATABUFFER_H
16 #define VERTEXDATABUFFER_H
17 
18 #include "pandabase.h"
19 #include "vertexDataBook.h"
20 #include "vertexDataBlock.h"
21 #include "pointerTo.h"
22 #include "virtualFile.h"
23 #include "pStatCollector.h"
24 #include "lightMutex.h"
25 #include "lightMutexHolder.h"
26 
27 ////////////////////////////////////////////////////////////////////
28 // Class : VertexDataBuffer
29 // Description : A block of bytes that stores the actual raw vertex
30 // data referenced by a GeomVertexArrayData object.
31 //
32 // At any point, a buffer may be in any of two states:
33 //
34 // independent - the buffer's memory is resident, and
35 // owned by the VertexDataBuffer object itself (in
36 // _resident_data). In this state, _reserved_size might
37 // be greater than or equal to _size.
38 //
39 // paged - the buffer's memory is owned by a
40 // VertexDataBlock. That block might itself be
41 // resident, compressed, or paged to disk. If it is
42 // resident, the memory may still be accessed directly
43 // from the block. However, this memory is considered
44 // read-only. In this state, _reserved_size will always
45 // equal _size.
46 //
47 // VertexDataBuffers start out in independent state.
48 // They get moved to paged state when their owning
49 // GeomVertexArrayData objects get evicted from the
50 // _independent_lru. They can get moved back to
51 // independent state if they are modified
52 // (e.g. get_write_pointer() or realloc() is called).
53 //
54 // The idea is to keep the highly dynamic and
55 // frequently-modified VertexDataBuffers resident in
56 // easy-to-access memory, while collecting the static
57 // and rarely accessed VertexDataBuffers together onto
58 // pages, where they may be written to disk as a block
59 // when necessary.
60 ////////////////////////////////////////////////////////////////////
61 class EXPCL_PANDA_GOBJ VertexDataBuffer {
62 public:
63  INLINE VertexDataBuffer();
64  INLINE VertexDataBuffer(size_t size);
65  INLINE VertexDataBuffer(const VertexDataBuffer &copy);
66  void operator = (const VertexDataBuffer &copy);
67  INLINE ~VertexDataBuffer();
68 
69  INLINE const unsigned char *get_read_pointer(bool force) const;
70  INLINE unsigned char *get_write_pointer();
71 
72  INLINE size_t get_size() const;
73  INLINE size_t get_reserved_size() const;
74  INLINE void set_size(size_t size);
75  INLINE void clean_realloc(size_t reserved_size);
76  INLINE void unclean_realloc(size_t reserved_size);
77  INLINE void clear();
78 
79  INLINE void page_out(VertexDataBook &book);
80 
81  void swap(VertexDataBuffer &other);
82 
83 private:
84  void do_clean_realloc(size_t size);
85  void do_unclean_realloc(size_t size);
86 
87  void do_page_out(VertexDataBook &book);
88  void do_page_in();
89 
90  unsigned char *_resident_data;
91  size_t _size;
92  size_t _reserved_size;
93  PT(VertexDataBlock) _block;
94  LightMutex _lock;
95 
96 public:
97  static TypeHandle get_class_type() {
98  return _type_handle;
99  }
100  static void init_type() {
101  register_type(_type_handle, "VertexDataBuffer");
102  }
103 
104 private:
105  static TypeHandle _type_handle;
106 };
107 
108 #include "vertexDataBuffer.I"
109 
110 #endif
A block of bytes that stores the actual raw vertex data referenced by a GeomVertexArrayData object...
A block of bytes that stores the actual raw vertex data referenced by a GeomVertexArrayData object...
A collection of VertexDataPages, which can be used to allocate new VertexDataBlock objects...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
This is a standard, non-reentrant mutex, similar to the Mutex class.
Definition: lightMutex.h:45