Panda3D
indexBufferContext.I
1 // Filename: indexBufferContext.I
2 // Created by: drose (17Mar05)
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 
16 ////////////////////////////////////////////////////////////////////
17 // Function: IndexBufferContext::Constructor
18 // Access: Public
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE IndexBufferContext::
22 IndexBufferContext(PreparedGraphicsObjects *pgo, GeomPrimitive *data) :
23  BufferContext(&pgo->_ibuffer_residency),
24  AdaptiveLruPage(0),
25  _data(data)
26 {
27 }
28 
29 ////////////////////////////////////////////////////////////////////
30 // Function: IndexBufferContext::get_data
31 // Access: Public
32 // Description: Returns the pointer to the client-side array data
33 // object.
34 ////////////////////////////////////////////////////////////////////
36 get_data() const {
37  return _data;
38 }
39 
40 ////////////////////////////////////////////////////////////////////
41 // Function: IndexBufferContext::changed_size
42 // Access: Public
43 // Description: Returns true if the data has changed size since the
44 // last time mark_loaded() was called.
45 ////////////////////////////////////////////////////////////////////
46 INLINE bool IndexBufferContext::
48  nassertr(reader->get_object() == _data, false);
49  return get_data_size_bytes() != (size_t)reader->get_data_size_bytes();
50 }
51 
52 ////////////////////////////////////////////////////////////////////
53 // Function: IndexBufferContext::changed_usage_hint
54 // Access: Public
55 // Description: Returns true if the data has changed its usage hint
56 // since the last time mark_loaded() was called.
57 ////////////////////////////////////////////////////////////////////
58 INLINE bool IndexBufferContext::
60  nassertr(reader->get_object() == _data, false);
61  return _usage_hint != reader->get_usage_hint();
62 }
63 
64 ////////////////////////////////////////////////////////////////////
65 // Function: IndexBufferContext::was_modified
66 // Access: Public
67 // Description: Returns true if the data has been modified since the
68 // last time mark_loaded() was called.
69 ////////////////////////////////////////////////////////////////////
70 INLINE bool IndexBufferContext::
72  nassertr(reader->get_object() == _data, false);
73  return get_modified() != reader->get_modified();
74 }
75 
76 ////////////////////////////////////////////////////////////////////
77 // Function: IndexBufferContext::update_data_size_bytes
78 // Access: Public
79 // Description: Should be called (usually by a derived class) when
80 // the on-card size of this object has changed.
81 ////////////////////////////////////////////////////////////////////
82 INLINE void IndexBufferContext::
83 update_data_size_bytes(size_t new_data_size_bytes) {
84  BufferContext::update_data_size_bytes(new_data_size_bytes);
85  AdaptiveLruPage::set_lru_size(new_data_size_bytes);
86 }
87 
88 ////////////////////////////////////////////////////////////////////
89 // Function: IndexBufferContext::mark_loaded
90 // Access: Public
91 // Description: Should be called after the IndexBufferContext has been
92 // loaded into graphics memory, this updates the
93 // internal flags for changed_size() and modified().
94 ////////////////////////////////////////////////////////////////////
95 INLINE void IndexBufferContext::
97  nassertv(reader->get_object() == _data);
99  update_modified(reader->get_modified());
100  _usage_hint = reader->get_usage_hint();
101 
102  // Assume the buffer is now resident.
103  set_resident(true);
104 }
105 
106 ////////////////////////////////////////////////////////////////////
107 // Function: IndexBufferContext::mark_unloaded
108 // Access: Public
109 // Description: Should be called after the buffer has been forced
110 // out of graphics memory.
111 ////////////////////////////////////////////////////////////////////
112 INLINE void IndexBufferContext::
115  set_resident(false);
116 }
UpdateSeq get_modified() const
Returns the UpdateSeq that was recorded the last time mark_loaded() was called.
Definition: bufferContext.I:37
This is a base class for those kinds of SavedContexts that occupy an easily-measured (and substantial...
Definition: bufferContext.h:41
This is an abstract base class for a family of classes that represent the fundamental geometry primit...
Definition: geomPrimitive.h:63
void set_lru_size(size_t lru_size)
Specifies the size of this page, presumably in bytes, although any unit is possible.
Definition: adaptiveLru.I:220
A table of objects that are saved within the graphics context for reference by handle later...
void update_data_size_bytes(size_t new_data_size_bytes)
Should be called (usually by a derived class) when the on-card size of this object has changed...
bool was_modified(const GeomPrimitivePipelineReader *reader) const
Returns true if the data has been modified since the last time mark_loaded() was called.
bool changed_usage_hint(const GeomPrimitivePipelineReader *reader) const
Returns true if the data has changed its usage hint since the last time mark_loaded() was called...
void set_resident(bool flag)
Changes the resident flag associated with this object.
Definition: bufferContext.I:93
One atomic piece that may be managed by a AdaptiveLru chain.
Definition: adaptiveLru.h:145
size_t get_data_size_bytes() const
Returns the number of bytes previously reported for the data object.
Definition: bufferContext.I:26
void mark_unloaded()
Should be called after the buffer has been forced out of graphics memory.
static UpdateSeq old()
Returns an UpdateSeq in the 'old' state.
Definition: updateSeq.I:42
void mark_loaded(const GeomPrimitivePipelineReader *reader)
Should be called after the IndexBufferContext has been loaded into graphics memory, this updates the internal flags for changed_size() and modified().
GeomPrimitive * get_data() const
Returns the pointer to the client-side array data object.
void update_modified(UpdateSeq new_modified)
Should be called (usually by a derived class) when the modified counter for this object has changed...
int get_data_size_bytes() const
Returns the number of bytes stored in the vertices array.
Encapsulates the data from a GeomPrimitive, pre-fetched for one stage of the pipeline.
bool changed_size(const GeomPrimitivePipelineReader *reader) const
Returns true if the data has changed size since the last time mark_loaded() was called.
void update_data_size_bytes(size_t new_data_size_bytes)
Should be called (usually by a derived class) when the on-card size of this object has changed...