Panda3D
 All Classes Functions Variables Enumerations
textureContext.I
1 // Filename: textureContext.I
2 // Created by: drose (07Oct99)
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: TextureContext::Constructor
18 // Access: Public
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE TextureContext::
22 TextureContext(PreparedGraphicsObjects *pgo, Texture *tex, int view) :
23  BufferContext(&pgo->_texture_residency),
24  AdaptiveLruPage(0),
25  _texture(tex),
26  _view(view)
27 {
28 }
29 
30 ////////////////////////////////////////////////////////////////////
31 // Function: TextureContext::get_texture
32 // Access: Public
33 // Description: Returns the pointer to the associated Texture
34 // object.
35 ////////////////////////////////////////////////////////////////////
37 get_texture() const {
38  return _texture;
39 }
40 
41 ////////////////////////////////////////////////////////////////////
42 // Function: TextureContext::get_view
43 // Access: Public
44 // Description: Returns the specific view of a multiview texture this
45 // context represents. In the usual case, with a
46 // non-multiview texture, this will be 0.
47 ////////////////////////////////////////////////////////////////////
48 INLINE int TextureContext::
49 get_view() const {
50  return _view;
51 }
52 
53 
54 ////////////////////////////////////////////////////////////////////
55 // Function: TextureContext::was_modified
56 // Access: Public
57 // Description: Returns true if the texture properties or image have
58 // been modified since the last time mark_loaded() was
59 // called.
60 ////////////////////////////////////////////////////////////////////
61 INLINE bool TextureContext::
62 was_modified() const {
64 }
65 
66 ////////////////////////////////////////////////////////////////////
67 // Function: TextureContext::was_properties_modified
68 // Access: Public
69 // Description: Returns true if the texture properties (unrelated to
70 // the image) have been modified since the last time
71 // mark_loaded() was called.
72 ////////////////////////////////////////////////////////////////////
73 INLINE bool TextureContext::
75  return _properties_modified != _texture->get_properties_modified();
76 }
77 
78 ////////////////////////////////////////////////////////////////////
79 // Function: TextureContext::was_image_modified
80 // Access: Public
81 // Description: Returns true if the texture image has been modified
82 // since the last time mark_loaded() was called.
83 ////////////////////////////////////////////////////////////////////
84 INLINE bool TextureContext::
86  return _image_modified != _texture->get_image_modified();
87 }
88 
89 ////////////////////////////////////////////////////////////////////
90 // Function: TextureContext::was_simple_image_modified
91 // Access: Public
92 // Description: Returns true if the texture's "simple" image has been
93 // modified since the last time mark_simple_loaded() was
94 // called.
95 ////////////////////////////////////////////////////////////////////
96 INLINE bool TextureContext::
98  return _simple_image_modified != _texture->get_simple_image_modified();
99 }
100 
101 ////////////////////////////////////////////////////////////////////
102 // Function: TextureContext::get_properties_modified
103 // Access: Published
104 // Description: Returns a sequence number which is guaranteed to
105 // change at least every time the texture properties
106 // (unrelated to the image) are modified.
107 ////////////////////////////////////////////////////////////////////
110  return _properties_modified;
111 }
112 
113 ////////////////////////////////////////////////////////////////////
114 // Function: TextureContext::get_image_modified
115 // Access: Published
116 // Description: Returns a sequence number which is guaranteed to
117 // change at least every time the texture image data
118 // (including mipmap levels) are modified.
119 ////////////////////////////////////////////////////////////////////
122  return _image_modified;
123 }
124 
125 ////////////////////////////////////////////////////////////////////
126 // Function: TextureContext::get_simple_image_modified
127 // Access: Published
128 // Description: Returns a sequence number which is guaranteed to
129 // change at least every time the texture's "simple"
130 // image data is modified.
131 ////////////////////////////////////////////////////////////////////
134  return _simple_image_modified;
135 }
136 
137 ////////////////////////////////////////////////////////////////////
138 // Function: TextureContext::update_data_size_bytes
139 // Access: Public
140 // Description: Should be called (usually by a derived class) when
141 // the on-card size of this object has changed.
142 ////////////////////////////////////////////////////////////////////
143 INLINE void TextureContext::
144 update_data_size_bytes(size_t new_data_size_bytes) {
145  BufferContext::update_data_size_bytes(new_data_size_bytes);
146  AdaptiveLruPage::set_lru_size(new_data_size_bytes);
147 }
148 
149 ////////////////////////////////////////////////////////////////////
150 // Function: TextureContext::mark_loaded
151 // Access: Public
152 // Description: Should be called after the texture has been loaded
153 // into graphics memory, this updates the internal flags
154 // for changed_size() and modified().
155 ////////////////////////////////////////////////////////////////////
156 INLINE void TextureContext::
158  // _data_size_bytes = _data->get_texture_size_bytes();
159  _properties_modified = _texture->get_properties_modified();
160  _image_modified = _texture->get_image_modified();
161  update_modified(max(_properties_modified, _image_modified));
162 
163  // Assume the texture is now resident.
164  set_resident(true);
165 }
166 
167 ////////////////////////////////////////////////////////////////////
168 // Function: TextureContext::mark_simple_loaded
169 // Access: Public
170 // Description: Should be called after the texture's "simple" image
171 // has been loaded into graphics memory.
172 ////////////////////////////////////////////////////////////////////
173 INLINE void TextureContext::
175  _properties_modified = _texture->get_properties_modified();
176  _simple_image_modified = _texture->get_simple_image_modified();
177  update_modified(max(_properties_modified, _simple_image_modified));
178 
179  // The texture's not exactly resident now, but some part of it is.
180  set_resident(true);
181 }
182 
183 ////////////////////////////////////////////////////////////////////
184 // Function: TextureContext::mark_unloaded
185 // Access: Public
186 // Description: Should be called after the texture has been forced
187 // out of texture memory.
188 ////////////////////////////////////////////////////////////////////
189 INLINE void TextureContext::
191  _properties_modified = UpdateSeq::old();
192  _image_modified = UpdateSeq::old();
193  _simple_image_modified = UpdateSeq::old();
195 
196  set_resident(false);
197 }
198 
199 ////////////////////////////////////////////////////////////////////
200 // Function: TextureContext::mark_needs_reload
201 // Access: Public
202 // Description: Should be called to indicate the texture should be
203 // reloaded at the nearest opportunity.
204 ////////////////////////////////////////////////////////////////////
205 INLINE void TextureContext::
207  _image_modified = UpdateSeq::old();
208 }
UpdateSeq get_properties_modified() const
Returns a sequence number which is guaranteed to change at least every time the texture properties (u...
UpdateSeq get_simple_image_modified() const
Returns a sequence number which is guaranteed to change at least every time the texture's "simple" im...
Definition: texture.I:2164
bool was_modified() const
Returns true if the texture properties or image have been modified since the last time mark_loaded() ...
This is a base class for those kinds of SavedContexts that occupy an easily-measured (and substantial...
Definition: bufferContext.h:41
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition: texture.h:75
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
void mark_needs_reload()
Should be called to indicate the texture should be reloaded at the nearest opportunity.
Texture * get_texture() const
Returns the pointer to the associated Texture object.
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_simple_image_modified() const
Returns true if the texture's "simple" image has been modified since the last time mark_simple_loaded...
UpdateSeq get_image_modified() const
Returns a sequence number which is guaranteed to change at least every time the texture image data (i...
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
UpdateSeq get_image_modified() const
Returns a sequence number which is guaranteed to change at least every time the texture image data (i...
Definition: texture.I:2151
static UpdateSeq old()
Returns an UpdateSeq in the 'old' state.
Definition: updateSeq.I:42
bool was_image_modified() const
Returns true if the texture image has been modified 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...
bool was_properties_modified() const
Returns true if the texture properties (unrelated to the image) have been modified since the last tim...
void mark_loaded()
Should be called after the texture has been loaded into graphics memory, this updates the internal fl...
int get_view() const
Returns the specific view of a multiview texture this context represents.
void update_modified(UpdateSeq new_modified)
Should be called (usually by a derived class) when the modified counter for this object has changed...
UpdateSeq get_properties_modified() const
Returns a sequence number which is guaranteed to change at least every time the texture properties (u...
Definition: texture.I:2138
void mark_unloaded()
Should be called after the texture has been forced out of texture memory.
This is a sequence number that increments monotonically.
Definition: updateSeq.h:43
void mark_simple_loaded()
Should be called after the texture's "simple" image has been loaded into graphics memory...
UpdateSeq get_simple_image_modified() const
Returns a sequence number which is guaranteed to change at least every time the texture's "simple" im...