Panda3D
|
00001 // Filename: vertexDataBuffer.I 00002 // Created by: drose (14May07) 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: VertexDataBuffer::Constructor 00018 // Access: Public 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE VertexDataBuffer:: 00022 VertexDataBuffer() : 00023 _resident_data(NULL), 00024 _size(0) 00025 { 00026 } 00027 00028 //////////////////////////////////////////////////////////////////// 00029 // Function: VertexDataBuffer::Constructor 00030 // Access: Public 00031 // Description: 00032 //////////////////////////////////////////////////////////////////// 00033 INLINE VertexDataBuffer:: 00034 VertexDataBuffer(size_t size) : 00035 _resident_data(NULL), 00036 _size(0) 00037 { 00038 do_unclean_realloc(size); 00039 } 00040 00041 //////////////////////////////////////////////////////////////////// 00042 // Function: VertexDataBuffer::Copy Constructor 00043 // Access: Public 00044 // Description: 00045 //////////////////////////////////////////////////////////////////// 00046 INLINE VertexDataBuffer:: 00047 VertexDataBuffer(const VertexDataBuffer ©) : 00048 _resident_data(NULL), 00049 _size(0) 00050 { 00051 (*this) = copy; 00052 } 00053 00054 //////////////////////////////////////////////////////////////////// 00055 // Function: VertexDataBuffer::Destructor 00056 // Access: Public 00057 // Description: 00058 //////////////////////////////////////////////////////////////////// 00059 INLINE VertexDataBuffer:: 00060 ~VertexDataBuffer() { 00061 clear(); 00062 } 00063 00064 //////////////////////////////////////////////////////////////////// 00065 // Function: VertexDataBuffer::get_read_pointer 00066 // Access: Public 00067 // Description: Returns a read-only pointer to the raw data, or NULL 00068 // if the data is not currently resident. If the data 00069 // is not currently resident, this will implicitly 00070 // request it to become resident soon. 00071 // 00072 // If force is true, this method will never return NULL, 00073 // but may block until the data is available. 00074 //////////////////////////////////////////////////////////////////// 00075 INLINE const unsigned char *VertexDataBuffer:: 00076 get_read_pointer(bool force) const { 00077 LightMutexHolder holder(_lock); 00078 00079 if (_resident_data != (unsigned char *)NULL || _size == 0) { 00080 return _resident_data; 00081 } 00082 00083 nassertr(_block != (VertexDataBlock *)NULL, NULL); 00084 00085 // We don't necessarily need to page the buffer all the way into 00086 // independent status; it's sufficient just to return the block's 00087 // pointer, which will force its page to resident status. 00088 return _block->get_pointer(force); 00089 } 00090 00091 //////////////////////////////////////////////////////////////////// 00092 // Function: VertexDataBuffer::get_write_pointer 00093 // Access: Public 00094 // Description: Returns a writable pointer to the raw data. 00095 //////////////////////////////////////////////////////////////////// 00096 INLINE unsigned char *VertexDataBuffer:: 00097 get_write_pointer() { 00098 LightMutexHolder holder(_lock); 00099 00100 if (_resident_data == (unsigned char *)NULL && _size != 0) { 00101 do_page_in(); 00102 } 00103 return _resident_data; 00104 } 00105 00106 //////////////////////////////////////////////////////////////////// 00107 // Function: VertexDataBuffer::get_size 00108 // Access: Public 00109 // Description: Returns the number of bytes in the buffer. 00110 //////////////////////////////////////////////////////////////////// 00111 INLINE size_t VertexDataBuffer:: 00112 get_size() const { 00113 return _size; 00114 } 00115 00116 //////////////////////////////////////////////////////////////////// 00117 // Function: VertexDataBuffer::clean_realloc 00118 // Access: Public 00119 // Description: Changes the size of the buffer, preserving its data 00120 // (except for any data beyond the new end of the 00121 // buffer, if the buffer is being reduced). If the 00122 // buffer is expanded, the new data is uninitialized. 00123 //////////////////////////////////////////////////////////////////// 00124 INLINE void VertexDataBuffer:: 00125 clean_realloc(size_t size) { 00126 LightMutexHolder holder(_lock); 00127 do_clean_realloc(size); 00128 } 00129 00130 //////////////////////////////////////////////////////////////////// 00131 // Function: VertexDataBuffer::unclean_realloc 00132 // Access: Public 00133 // Description: Changes the size of the buffer, without regard to 00134 // preserving its data. The buffer may contain random 00135 // data after this call. 00136 //////////////////////////////////////////////////////////////////// 00137 INLINE void VertexDataBuffer:: 00138 unclean_realloc(size_t size) { 00139 LightMutexHolder holder(_lock); 00140 do_unclean_realloc(size); 00141 } 00142 00143 //////////////////////////////////////////////////////////////////// 00144 // Function: VertexDataBuffer::clear 00145 // Access: Public 00146 // Description: Empties the buffer and sets its size to 0. 00147 //////////////////////////////////////////////////////////////////// 00148 INLINE void VertexDataBuffer:: 00149 clear() { 00150 unclean_realloc(0); 00151 } 00152 00153 //////////////////////////////////////////////////////////////////// 00154 // Function: VertexDataBuffer::page_out 00155 // Access: Public 00156 // Description: Moves the buffer out of independent memory and puts 00157 // it on a page in the indicated book. The buffer may 00158 // still be directly accessible as long as its page 00159 // remains resident. Any subsequent attempt to rewrite 00160 // the buffer will implicitly move it off of the page 00161 // and back into independent memory. 00162 //////////////////////////////////////////////////////////////////// 00163 INLINE void VertexDataBuffer:: 00164 page_out(VertexDataBook &book) { 00165 LightMutexHolder holder(_lock); 00166 do_page_out(book); 00167 } 00168 00169 //////////////////////////////////////////////////////////////////// 00170 // Function: VertexDataBuffer::swap 00171 // Access: Public 00172 // Description: Swaps the data buffers between this one and the other 00173 // one. 00174 //////////////////////////////////////////////////////////////////// 00175 INLINE void VertexDataBuffer:: 00176 swap(VertexDataBuffer &other) { 00177 LightMutexHolder holder(_lock); 00178 LightMutexHolder holder2(other._lock); 00179 00180 unsigned char *resident_data = _resident_data; 00181 size_t size = _size; 00182 PT(VertexDataBlock) block = _block; 00183 00184 _resident_data = other._resident_data; 00185 _size = other._size; 00186 _block = other._block; 00187 00188 other._resident_data = resident_data; 00189 other._size = size; 00190 other._block = block; 00191 }