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