Panda3D
textureContext.I
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 textureContext.I
10  * @author drose
11  * @date 1999-10-07
12  */
13 
14 /**
15  *
16  */
17 INLINE TextureContext::
18 TextureContext(PreparedGraphicsObjects *pgo, Texture *tex, int view) :
19  BufferContext(&pgo->_texture_residency, tex),
20  AdaptiveLruPage(0),
21  _view(view)
22 {
23 }
24 
25 /**
26  * Returns the pointer to the associated Texture object.
27  */
29 get_texture() const {
30  return (Texture *)_object;
31 }
32 
33 /**
34  * Returns the specific view of a multiview texture this context represents.
35  * In the usual case, with a non-multiview texture, this will be 0.
36  */
37 INLINE int TextureContext::
38 get_view() const {
39  return _view;
40 }
41 
42 
43 /**
44  * Returns true if the texture properties or image have been modified since
45  * the last time mark_loaded() was called.
46  */
47 INLINE bool TextureContext::
48 was_modified() const {
50 }
51 
52 /**
53  * Returns true if the texture properties (unrelated to the image) have been
54  * modified since the last time mark_loaded() was called.
55  */
56 INLINE bool TextureContext::
58  return _properties_modified != get_texture()->get_properties_modified();
59 }
60 
61 /**
62  * Returns true if the texture image has been modified since the last time
63  * mark_loaded() was called.
64  */
65 INLINE bool TextureContext::
67  return _image_modified != get_texture()->get_image_modified();
68 }
69 
70 /**
71  * Returns true if the texture's "simple" image has been modified since the
72  * last time mark_simple_loaded() was called.
73  */
74 INLINE bool TextureContext::
76  return _simple_image_modified != get_texture()->get_simple_image_modified();
77 }
78 
79 /**
80  * Returns a sequence number which is guaranteed to change at least every time
81  * the texture properties (unrelated to the image) are modified.
82  */
85  return _properties_modified;
86 }
87 
88 /**
89  * Returns a sequence number which is guaranteed to change at least every time
90  * the texture image data (including mipmap levels) are modified.
91  */
94  return _image_modified;
95 }
96 
97 /**
98  * Returns a sequence number which is guaranteed to change at least every time
99  * the texture's "simple" image data is modified.
100  */
103  return _simple_image_modified;
104 }
105 
106 /**
107  * Should be called (usually by a derived class) when the on-card size of this
108  * object has changed.
109  */
110 INLINE void TextureContext::
111 update_data_size_bytes(size_t new_data_size_bytes) {
112  BufferContext::update_data_size_bytes(new_data_size_bytes);
113  AdaptiveLruPage::set_lru_size(new_data_size_bytes);
114 }
115 
116 /**
117  * Should be called after the texture has been loaded into graphics memory,
118  * this updates the internal flags for changed_size() and modified().
119  */
120 INLINE void TextureContext::
122  // _data_size_bytes = _data->get_texture_size_bytes();
123  _properties_modified = get_texture()->get_properties_modified();
124  _image_modified = get_texture()->get_image_modified();
125  update_modified(std::max(_properties_modified, _image_modified));
126 
127  // Assume the texture is now resident.
128  set_resident(true);
129 }
130 
131 /**
132  * Should be called after the texture's "simple" image has been loaded into
133  * graphics memory.
134  */
135 INLINE void TextureContext::
137  _properties_modified = get_texture()->get_properties_modified();
138  _simple_image_modified = get_texture()->get_simple_image_modified();
139  update_modified(std::max(_properties_modified, _simple_image_modified));
140 
141  // The texture's not exactly resident now, but some part of it is.
142  set_resident(true);
143 }
144 
145 /**
146  * Should be called after the texture has been forced out of texture memory.
147  */
148 INLINE void TextureContext::
150  _properties_modified = UpdateSeq::old();
151  _image_modified = UpdateSeq::old();
152  _simple_image_modified = UpdateSeq::old();
153  update_modified(UpdateSeq::old());
154 
155  set_resident(false);
156 }
157 
158 /**
159  * Should be called to indicate the texture should be reloaded at the nearest
160  * opportunity.
161  */
162 INLINE void TextureContext::
164  _image_modified = UpdateSeq::old();
165 }
Texture * get_texture() const
Returns the pointer to the associated Texture object.
bool was_image_modified() const
Returns true if the texture image has been modified since the last time mark_loaded() was called.
UpdateSeq get_simple_image_modified() const
Returns a sequence number which is guaranteed to change at least every time the texture's "simple" im...
int get_view() const
Returns the specific view of a multiview texture this context represents.
bool was_properties_modified() const
Returns true if the texture properties (unrelated to the image) have been modified since the last tim...
This is a base class for those kinds of SavedContexts that occupy an easily-measured (and substantial...
Definition: bufferContext.h:38
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition: texture.h:71
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:176
get_properties_modified
Returns a sequence number which is guaranteed to change at least every time the texture properties (u...
Definition: texture.h:516
void mark_needs_reload()
Should be called to indicate the texture should be reloaded at the nearest opportunity.
UpdateSeq get_image_modified() const
Returns a sequence number which is guaranteed to change at least every time the texture image data (i...
bool was_simple_image_modified() const
Returns true if the texture's "simple" image has been modified since the last time mark_simple_loaded...
A table of objects that are saved within the graphics context for reference by handle later.
UpdateSeq get_properties_modified() const
Returns a sequence number which is guaranteed to change at least every time the texture properties (u...
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.
void set_resident(bool flag)
Changes the resident flag associated with this object.
Definition: bufferContext.I:81
One atomic piece that may be managed by a AdaptiveLru chain.
Definition: adaptiveLru.h:135
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.
void mark_loaded()
Should be called after the texture has been loaded into graphics memory, this updates the internal fl...
get_image_modified
Returns a sequence number which is guaranteed to change at least every time the texture image data (i...
Definition: texture.h:517
get_simple_image_modified
Returns a sequence number which is guaranteed to change at least every time the texture's "simple" im...
Definition: texture.h:518
void update_modified(UpdateSeq new_modified)
Should be called (usually by a derived class) when the modified counter for this object has changed.
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:37
void mark_simple_loaded()
Should be called after the texture's "simple" image has been loaded into graphics memory.
bool was_modified() const
Returns true if the texture properties or image have been modified since the last time mark_loaded() ...