00001 // Filename: bufferContext.I 00002 // Created by: drose (16Mar06) 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: BufferContext::get_data_size_bytes 00018 // Access: Public 00019 // Description: Returns the number of bytes previously reported for 00020 // the data object. This is used to track changes in 00021 // the data object's allocated size; if it changes from 00022 // this, we need to create a new buffer. This is also 00023 // used to track memory utilization in PStats. 00024 //////////////////////////////////////////////////////////////////// 00025 INLINE size_t BufferContext:: 00026 get_data_size_bytes() const { 00027 return _data_size_bytes; 00028 } 00029 00030 //////////////////////////////////////////////////////////////////// 00031 // Function: BufferContext::get_modified 00032 // Access: Public 00033 // Description: Returns the UpdateSeq that was recorded the last time 00034 // mark_loaded() was called. 00035 //////////////////////////////////////////////////////////////////// 00036 INLINE UpdateSeq BufferContext:: 00037 get_modified() const { 00038 return _modified; 00039 } 00040 00041 //////////////////////////////////////////////////////////////////// 00042 // Function: BufferContext::get_active 00043 // Access: Public 00044 // Description: Returns the active flag associated with this object. 00045 // An object is considered "active" if it was rendered 00046 // in the current frame. 00047 //////////////////////////////////////////////////////////////////// 00048 INLINE bool BufferContext:: 00049 get_active() const { 00050 return (_residency_state & BufferResidencyTracker::S_active) != 0; 00051 } 00052 00053 //////////////////////////////////////////////////////////////////// 00054 // Function: BufferContext::get_resident 00055 // Access: Public 00056 // Description: Returns the resident flag associated with this 00057 // object. An object is considered "resident" if it 00058 // appears to be resident in texture memory. 00059 //////////////////////////////////////////////////////////////////// 00060 INLINE bool BufferContext:: 00061 get_resident() const { 00062 return (_residency_state & BufferResidencyTracker::S_resident) != 0; 00063 } 00064 00065 //////////////////////////////////////////////////////////////////// 00066 // Function: BufferContext::set_active 00067 // Access: Public 00068 // Description: Changes the active flag associated with this object. 00069 // An object is considered "active" if it was rendered 00070 // in the current frame. 00071 //////////////////////////////////////////////////////////////////// 00072 INLINE void BufferContext:: 00073 set_active(bool flag) { 00074 if (flag) { 00075 _residency_state |= BufferResidencyTracker::S_active; 00076 // Assume that rendering the object automatically makes it 00077 // resident. 00078 _residency_state |= BufferResidencyTracker::S_resident; 00079 } else { 00080 _residency_state &= ~BufferResidencyTracker::S_active; 00081 } 00082 set_owning_chain(&_residency->_chains[_residency_state]); 00083 } 00084 00085 //////////////////////////////////////////////////////////////////// 00086 // Function: BufferContext::set_resident 00087 // Access: Public 00088 // Description: Changes the resident flag associated with this 00089 // object. An object is considered "resident" if it 00090 // appears to be resident in texture memory. 00091 //////////////////////////////////////////////////////////////////// 00092 INLINE void BufferContext:: 00093 set_resident(bool flag) { 00094 if (flag) { 00095 _residency_state |= BufferResidencyTracker::S_resident; 00096 } else { 00097 _residency_state &= ~BufferResidencyTracker::S_resident; 00098 } 00099 set_owning_chain(&_residency->_chains[_residency_state]); 00100 } 00101 00102 //////////////////////////////////////////////////////////////////// 00103 // Function: BufferContext::get_next 00104 // Access: Public 00105 // Description: This can be used along with 00106 // BufferContextChain::get_first() to walk through the 00107 // list of objects stored on a tracker. 00108 //////////////////////////////////////////////////////////////////// 00109 INLINE BufferContext *BufferContext:: 00110 get_next() const { 00111 nassertr(_owning_chain != (BufferContextChain *)NULL, NULL); 00112 if ((BufferContextChain *)_next == _owning_chain) { 00113 return NULL; 00114 } 00115 return (BufferContext *)_next; 00116 } 00117 00118 //////////////////////////////////////////////////////////////////// 00119 // Function: BufferContext::update_data_size_bytes 00120 // Access: Public 00121 // Description: Should be called (usually by a derived class) when 00122 // the on-card size of this object has changed. 00123 //////////////////////////////////////////////////////////////////// 00124 INLINE void BufferContext:: 00125 update_data_size_bytes(size_t new_data_size_bytes) { 00126 if (_owning_chain != (BufferContextChain *)NULL) { 00127 _owning_chain->adjust_bytes((int)new_data_size_bytes - (int)_data_size_bytes); 00128 } 00129 _data_size_bytes = new_data_size_bytes; 00130 } 00131 00132 //////////////////////////////////////////////////////////////////// 00133 // Function: BufferContext::update_modified 00134 // Access: Public 00135 // Description: Should be called (usually by a derived class) when 00136 // the modified counter for this object has changed. 00137 //////////////////////////////////////////////////////////////////// 00138 INLINE void BufferContext:: 00139 update_modified(UpdateSeq new_modified) { 00140 _modified = new_modified; 00141 }