Panda3D

textureContext.I

00001 // Filename: textureContext.I
00002 // Created by:  drose (07Oct99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 
00016 ////////////////////////////////////////////////////////////////////
00017 //     Function: TextureContext::Constructor
00018 //       Access: Public
00019 //  Description:
00020 ////////////////////////////////////////////////////////////////////
00021 INLINE TextureContext::
00022 TextureContext(PreparedGraphicsObjects *pgo, Texture *tex, int view) :
00023   BufferContext(&pgo->_texture_residency),
00024   AdaptiveLruPage(0),
00025   _texture(tex),
00026   _view(view)
00027 {
00028 }
00029 
00030 ////////////////////////////////////////////////////////////////////
00031 //     Function: TextureContext::get_texture
00032 //       Access: Public
00033 //  Description: Returns the pointer to the associated Texture
00034 //               object.
00035 ////////////////////////////////////////////////////////////////////
00036 INLINE Texture *TextureContext::
00037 get_texture() const {
00038   return _texture;
00039 }
00040 
00041 ////////////////////////////////////////////////////////////////////
00042 //     Function: TextureContext::get_view
00043 //       Access: Public
00044 //  Description: Returns the specific view of a multiview texture this
00045 //               context represents.  In the usual case, with a
00046 //               non-multiview texture, this will be 0.
00047 ////////////////////////////////////////////////////////////////////
00048 INLINE int TextureContext::
00049 get_view() const {
00050   return _view;
00051 }
00052 
00053 
00054 ////////////////////////////////////////////////////////////////////
00055 //     Function: TextureContext::was_modified
00056 //       Access: Public
00057 //  Description: Returns true if the texture properties or image have
00058 //               been modified since the last time mark_loaded() was
00059 //               called.
00060 ////////////////////////////////////////////////////////////////////
00061 INLINE bool TextureContext::
00062 was_modified() const {
00063   return was_properties_modified() || was_image_modified();
00064 }
00065 
00066 ////////////////////////////////////////////////////////////////////
00067 //     Function: TextureContext::was_properties_modified
00068 //       Access: Public
00069 //  Description: Returns true if the texture properties (unrelated to
00070 //               the image) have been modified since the last time
00071 //               mark_loaded() was called.
00072 ////////////////////////////////////////////////////////////////////
00073 INLINE bool TextureContext::
00074 was_properties_modified() const {
00075   return _properties_modified != _texture->get_properties_modified();
00076 }
00077 
00078 ////////////////////////////////////////////////////////////////////
00079 //     Function: TextureContext::was_image_modified
00080 //       Access: Public
00081 //  Description: Returns true if the texture image has been modified
00082 //               since the last time mark_loaded() was called.
00083 ////////////////////////////////////////////////////////////////////
00084 INLINE bool TextureContext::
00085 was_image_modified() const {
00086   return _image_modified != _texture->get_image_modified();
00087 }
00088 
00089 ////////////////////////////////////////////////////////////////////
00090 //     Function: TextureContext::was_simple_image_modified
00091 //       Access: Public
00092 //  Description: Returns true if the texture's "simple" image has been
00093 //               modified since the last time mark_simple_loaded() was
00094 //               called.
00095 ////////////////////////////////////////////////////////////////////
00096 INLINE bool TextureContext::
00097 was_simple_image_modified() const {
00098   return _simple_image_modified != _texture->get_simple_image_modified();
00099 }
00100 
00101 ////////////////////////////////////////////////////////////////////
00102 //     Function: TextureContext::update_data_size_bytes
00103 //       Access: Public
00104 //  Description: Should be called (usually by a derived class) when
00105 //               the on-card size of this object has changed.
00106 ////////////////////////////////////////////////////////////////////
00107 INLINE void TextureContext::
00108 update_data_size_bytes(size_t new_data_size_bytes) {
00109   BufferContext::update_data_size_bytes(new_data_size_bytes);
00110   AdaptiveLruPage::set_lru_size(new_data_size_bytes);
00111 }
00112 
00113 ////////////////////////////////////////////////////////////////////
00114 //     Function: TextureContext::mark_loaded
00115 //       Access: Public
00116 //  Description: Should be called after the texture has been loaded
00117 //               into graphics memory, this updates the internal flags
00118 //               for changed_size() and modified().
00119 ////////////////////////////////////////////////////////////////////
00120 INLINE void TextureContext::
00121 mark_loaded() {
00122   //  _data_size_bytes = _data->get_texture_size_bytes();
00123   _properties_modified = _texture->get_properties_modified();
00124   _image_modified = _texture->get_image_modified();
00125   update_modified(max(_properties_modified, _image_modified));
00126 
00127   // Assume the texture is now resident.
00128   set_resident(true);
00129 }
00130 
00131 ////////////////////////////////////////////////////////////////////
00132 //     Function: TextureContext::mark_simple_loaded
00133 //       Access: Public
00134 //  Description: Should be called after the texture's "simple" image
00135 //               has been loaded into graphics memory.
00136 ////////////////////////////////////////////////////////////////////
00137 INLINE void TextureContext::
00138 mark_simple_loaded() {
00139   _properties_modified = _texture->get_properties_modified();
00140   _simple_image_modified = _texture->get_simple_image_modified();
00141   update_modified(max(_properties_modified, _simple_image_modified));
00142 
00143   // The texture's not exactly resident now, but some part of it is.
00144   set_resident(true);
00145 }
00146 
00147 ////////////////////////////////////////////////////////////////////
00148 //     Function: TextureContext::mark_unloaded
00149 //       Access: Public
00150 //  Description: Should be called after the texture has been forced
00151 //               out of texture memory.
00152 ////////////////////////////////////////////////////////////////////
00153 INLINE void TextureContext::
00154 mark_unloaded() {
00155   _properties_modified = UpdateSeq::old();
00156   _image_modified = UpdateSeq::old();
00157   _simple_image_modified = UpdateSeq::old();
00158   update_modified(UpdateSeq::old());
00159 
00160   set_resident(false);
00161 }
00162 
00163 ////////////////////////////////////////////////////////////////////
00164 //     Function: TextureContext::mark_needs_reload
00165 //       Access: Public
00166 //  Description: Should be called to indicate the texture should be
00167 //               reloaded at the nearest opportunity.
00168 ////////////////////////////////////////////////////////////////////
00169 INLINE void TextureContext::
00170 mark_needs_reload() {
00171   _image_modified = UpdateSeq::old();
00172 }
 All Classes Functions Variables Enumerations