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) :
00023   BufferContext(&pgo->_texture_residency),
00024   AdaptiveLruPage(0),
00025   _texture(tex)
00026 {
00027 }
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 //     Function: TextureContext::get_texture
00031 //       Access: Public
00032 //  Description: Returns the pointer to the associated Texture
00033 //               object.
00034 ////////////////////////////////////////////////////////////////////
00035 INLINE Texture *TextureContext::
00036 get_texture() const {
00037   return _texture;
00038 }
00039 
00040 
00041 ////////////////////////////////////////////////////////////////////
00042 //     Function: TextureContext::was_modified
00043 //       Access: Public
00044 //  Description: Returns true if the texture properties or image have
00045 //               been modified since the last time mark_loaded() was
00046 //               called.
00047 ////////////////////////////////////////////////////////////////////
00048 INLINE bool TextureContext::
00049 was_modified() const {
00050   return was_properties_modified() || was_image_modified();
00051 }
00052 
00053 ////////////////////////////////////////////////////////////////////
00054 //     Function: TextureContext::was_properties_modified
00055 //       Access: Public
00056 //  Description: Returns true if the texture properties (unrelated to
00057 //               the image) have been modified since the last time
00058 //               mark_loaded() was called.
00059 ////////////////////////////////////////////////////////////////////
00060 INLINE bool TextureContext::
00061 was_properties_modified() const {
00062   return _properties_modified != _texture->get_properties_modified();
00063 }
00064 
00065 ////////////////////////////////////////////////////////////////////
00066 //     Function: TextureContext::was_image_modified
00067 //       Access: Public
00068 //  Description: Returns true if the texture image has been modified
00069 //               since the last time mark_loaded() was called.
00070 ////////////////////////////////////////////////////////////////////
00071 INLINE bool TextureContext::
00072 was_image_modified() const {
00073   return _image_modified != _texture->get_image_modified();
00074 }
00075 
00076 ////////////////////////////////////////////////////////////////////
00077 //     Function: TextureContext::was_simple_image_modified
00078 //       Access: Public
00079 //  Description: Returns true if the texture's "simple" image has been
00080 //               modified since the last time mark_simple_loaded() was
00081 //               called.
00082 ////////////////////////////////////////////////////////////////////
00083 INLINE bool TextureContext::
00084 was_simple_image_modified() const {
00085   return _simple_image_modified != _texture->get_simple_image_modified();
00086 }
00087 
00088 ////////////////////////////////////////////////////////////////////
00089 //     Function: TextureContext::update_data_size_bytes
00090 //       Access: Public
00091 //  Description: Should be called (usually by a derived class) when
00092 //               the on-card size of this object has changed.
00093 ////////////////////////////////////////////////////////////////////
00094 INLINE void TextureContext::
00095 update_data_size_bytes(size_t new_data_size_bytes) {
00096   BufferContext::update_data_size_bytes(new_data_size_bytes);
00097   AdaptiveLruPage::set_lru_size(new_data_size_bytes);
00098 }
00099 
00100 ////////////////////////////////////////////////////////////////////
00101 //     Function: TextureContext::mark_loaded
00102 //       Access: Public
00103 //  Description: Should be called after the texture has been loaded
00104 //               into graphics memory, this updates the internal flags
00105 //               for changed_size() and modified().
00106 ////////////////////////////////////////////////////////////////////
00107 INLINE void TextureContext::
00108 mark_loaded() {
00109   //  _data_size_bytes = _data->get_texture_size_bytes();
00110   _properties_modified = _texture->get_properties_modified();
00111   _image_modified = _texture->get_image_modified();
00112   update_modified(max(_properties_modified, _image_modified));
00113 
00114   // Assume the texture is now resident.
00115   set_resident(true);
00116 }
00117 
00118 ////////////////////////////////////////////////////////////////////
00119 //     Function: TextureContext::mark_simple_loaded
00120 //       Access: Public
00121 //  Description: Should be called after the texture's "simple" image
00122 //               has been loaded into graphics memory.
00123 ////////////////////////////////////////////////////////////////////
00124 INLINE void TextureContext::
00125 mark_simple_loaded() {
00126   _properties_modified = _texture->get_properties_modified();
00127   _simple_image_modified = _texture->get_simple_image_modified();
00128   update_modified(max(_properties_modified, _simple_image_modified));
00129 
00130   // The texture's not exactly resident now, but some part of it is.
00131   set_resident(true);
00132 }
00133 
00134 ////////////////////////////////////////////////////////////////////
00135 //     Function: TextureContext::mark_unloaded
00136 //       Access: Public
00137 //  Description: Should be called after the texture has been forced
00138 //               out of texture memory.
00139 ////////////////////////////////////////////////////////////////////
00140 INLINE void TextureContext::
00141 mark_unloaded() {
00142   _properties_modified = UpdateSeq::old();
00143   _image_modified = UpdateSeq::old();
00144   _simple_image_modified = UpdateSeq::old();
00145   update_modified(UpdateSeq::old());
00146 
00147   set_resident(false);
00148 }
00149 
00150 ////////////////////////////////////////////////////////////////////
00151 //     Function: TextureContext::mark_needs_reload
00152 //       Access: Public
00153 //  Description: Should be called to indicate the texture should be
00154 //               reloaded at the nearest opportunity.
00155 ////////////////////////////////////////////////////////////////////
00156 INLINE void TextureContext::
00157 mark_needs_reload() {
00158   _image_modified = UpdateSeq::old();
00159 }
 All Classes Functions Variables Enumerations