[692] | 1 | <html> |
---|
| 2 | <head> |
---|
| 3 | <title>OgreHardwareBuffer.h Source File - OGRE Documentation</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
---|
| 4 | <link type="text/css" rel="stylesheet" href="style.css"> |
---|
| 5 | </head> |
---|
| 6 | |
---|
| 7 | <body> |
---|
| 8 | <!-- Generated by Doxygen 1.3.6 --> |
---|
| 9 | <div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Class List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="namespacemembers.html">Namespace Members</a> | <a class="qindex" href="functions.html">Class Members</a> | <a class="qindex" href="globals.html">File Members</a> | <a class="qindex" href="pages.html">Related Pages</a></div> |
---|
| 10 | <h1>OgreHardwareBuffer.h</h1><a href="OgreHardwareBuffer_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/*</span> |
---|
| 11 | 00002 <span class="comment">-----------------------------------------------------------------------------</span> |
---|
| 12 | 00003 <span class="comment">This source file is part of OGRE</span> |
---|
| 13 | 00004 <span class="comment"> (Object-oriented Graphics Rendering Engine)</span> |
---|
| 14 | 00005 <span class="comment">For the latest info, see http://www.ogre3d.org/</span> |
---|
| 15 | 00006 <span class="comment"></span> |
---|
| 16 | 00007 <span class="comment">Copyright (c) 2000-2005 The OGRE Team</span> |
---|
| 17 | 00008 <span class="comment">Also see acknowledgements in Readme.html</span> |
---|
| 18 | 00009 <span class="comment"></span> |
---|
| 19 | 00010 <span class="comment">This program is free software; you can redistribute it and/or modify it under</span> |
---|
| 20 | 00011 <span class="comment">the terms of the GNU Lesser General Public License as published by the Free Software</span> |
---|
| 21 | 00012 <span class="comment">Foundation; either version 2 of the License, or (at your option) any later</span> |
---|
| 22 | 00013 <span class="comment">version.</span> |
---|
| 23 | 00014 <span class="comment"></span> |
---|
| 24 | 00015 <span class="comment">This program is distributed in the hope that it will be useful, but WITHOUT</span> |
---|
| 25 | 00016 <span class="comment">ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS</span> |
---|
| 26 | 00017 <span class="comment">FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.</span> |
---|
| 27 | 00018 <span class="comment"></span> |
---|
| 28 | 00019 <span class="comment">You should have received a copy of the GNU Lesser General Public License along with</span> |
---|
| 29 | 00020 <span class="comment">this program; if not, write to the Free Software Foundation, Inc., 59 Temple</span> |
---|
| 30 | 00021 <span class="comment">Place - Suite 330, Boston, MA 02111-1307, USA, or go to</span> |
---|
| 31 | 00022 <span class="comment">http://www.gnu.org/copyleft/lesser.txt.</span> |
---|
| 32 | 00023 <span class="comment">-----------------------------------------------------------------------------</span> |
---|
| 33 | 00024 <span class="comment">*/</span> |
---|
| 34 | 00025 <span class="preprocessor">#ifndef __HardwareBuffer__</span> |
---|
| 35 | 00026 <span class="preprocessor"></span><span class="preprocessor">#define __HardwareBuffer__</span> |
---|
| 36 | 00027 <span class="preprocessor"></span> |
---|
| 37 | 00028 <span class="comment">// Precompiler options</span> |
---|
| 38 | 00029 <span class="preprocessor">#include "<a class="code" href="OgrePrerequisites_8h.html">OgrePrerequisites.h</a>"</span> |
---|
| 39 | 00030 |
---|
| 40 | 00031 <span class="keyword">namespace </span>Ogre { |
---|
| 41 | 00032 |
---|
| 42 | <a name="l00064"></a><a class="code" href="classOgre_1_1HardwareBuffer.html">00064</a> <span class="keyword">class </span><a class="code" href="OgrePlatform_8h.html#a16">_OgreExport</a> HardwareBuffer |
---|
| 43 | 00065 { |
---|
| 44 | 00066 |
---|
| 45 | 00067 <span class="keyword">public</span>: |
---|
| 46 | <a name="l00069"></a><a class="code" href="classOgre_1_1HardwareBuffer.html#Ogre_1_1HardwareVertexBufferw11">00069</a> <span class="keyword">enum</span> Usage |
---|
| 47 | 00070 { |
---|
| 48 | 00074 HBU_STATIC = 1, |
---|
| 49 | 00080 HBU_DYNAMIC = 2, |
---|
| 50 | 00087 HBU_WRITE_ONLY = 4, |
---|
| 51 | 00096 HBU_DISCARDABLE = 8, |
---|
| 52 | 00098 HBU_STATIC_WRITE_ONLY = 5, |
---|
| 53 | 00104 HBU_DYNAMIC_WRITE_ONLY = 6, |
---|
| 54 | 00106 HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE = 14 |
---|
| 55 | 00107 |
---|
| 56 | 00108 |
---|
| 57 | 00109 }; |
---|
| 58 | <a name="l00111"></a><a class="code" href="classOgre_1_1HardwareBuffer.html#Ogre_1_1HardwareVertexBufferw12">00111</a> <span class="keyword">enum</span> LockOptions |
---|
| 59 | 00112 { |
---|
| 60 | 00114 HBL_NORMAL, |
---|
| 61 | 00119 HBL_DISCARD, |
---|
| 62 | 00123 HBL_READ_ONLY, |
---|
| 63 | 00127 HBL_NO_OVERWRITE |
---|
| 64 | 00128 |
---|
| 65 | 00129 }; |
---|
| 66 | 00130 <span class="keyword">protected</span>: |
---|
| 67 | <a name="l00131"></a><a class="code" href="classOgre_1_1HardwareBuffer.html#Ogre_1_1HardwareVertexBufferp2">00131</a> size_t mSizeInBytes; |
---|
| 68 | <a name="l00132"></a><a class="code" href="classOgre_1_1HardwareBuffer.html#Ogre_1_1HardwareVertexBufferp3">00132</a> Usage mUsage; |
---|
| 69 | <a name="l00133"></a><a class="code" href="classOgre_1_1HardwareBuffer.html#Ogre_1_1HardwareVertexBufferp4">00133</a> <span class="keywordtype">bool</span> mIsLocked; |
---|
| 70 | <a name="l00134"></a><a class="code" href="classOgre_1_1HardwareBuffer.html#Ogre_1_1HardwareVertexBufferp5">00134</a> size_t mLockStart; |
---|
| 71 | <a name="l00135"></a><a class="code" href="classOgre_1_1HardwareBuffer.html#Ogre_1_1HardwareVertexBufferp6">00135</a> size_t mLockSize; |
---|
| 72 | <a name="l00136"></a><a class="code" href="classOgre_1_1HardwareBuffer.html#Ogre_1_1HardwareVertexBufferp7">00136</a> <span class="keywordtype">bool</span> mSystemMemory; |
---|
| 73 | <a name="l00137"></a><a class="code" href="classOgre_1_1HardwareBuffer.html#Ogre_1_1HardwareVertexBufferp8">00137</a> <span class="keywordtype">bool</span> mUseShadowBuffer; |
---|
| 74 | <a name="l00138"></a><a class="code" href="classOgre_1_1HardwareBuffer.html#Ogre_1_1HardwareVertexBufferp9">00138</a> HardwareBuffer* mpShadowBuffer; |
---|
| 75 | <a name="l00139"></a><a class="code" href="classOgre_1_1HardwareBuffer.html#Ogre_1_1HardwareVertexBufferp10">00139</a> <span class="keywordtype">bool</span> mShadowUpdated; |
---|
| 76 | <a name="l00140"></a><a class="code" href="classOgre_1_1HardwareBuffer.html#Ogre_1_1HardwareVertexBufferp11">00140</a> <span class="keywordtype">bool</span> mSuppressHardwareUpdate; |
---|
| 77 | 00141 |
---|
| 78 | 00143 <span class="keyword">virtual</span> <span class="keywordtype">void</span>* lockImpl(size_t offset, size_t length, LockOptions options) = 0; |
---|
| 79 | 00145 <span class="keyword">virtual</span> <span class="keywordtype">void</span> unlockImpl(<span class="keywordtype">void</span>) = 0; |
---|
| 80 | 00146 |
---|
| 81 | 00147 <span class="keyword">public</span>: |
---|
| 82 | <a name="l00149"></a><a class="code" href="classOgre_1_1HardwareBuffer.html#Ogre_1_1HardwareBuffera0">00149</a> HardwareBuffer(Usage usage, <span class="keywordtype">bool</span> systemMemory, <span class="keywordtype">bool</span> useShadowBuffer) |
---|
| 83 | 00150 : mUsage(usage), mIsLocked(false), mSystemMemory(systemMemory), |
---|
| 84 | 00151 mUseShadowBuffer(useShadowBuffer), mpShadowBuffer(NULL), mShadowUpdated(false), |
---|
| 85 | 00152 mSuppressHardwareUpdate(false) |
---|
| 86 | 00153 { |
---|
| 87 | 00154 <span class="comment">// If use shadow buffer, upgrade to WRITE_ONLY on hardware side</span> |
---|
| 88 | 00155 <span class="keywordflow">if</span> (useShadowBuffer && usage == HBU_DYNAMIC) |
---|
| 89 | 00156 { |
---|
| 90 | 00157 mUsage = HBU_DYNAMIC_WRITE_ONLY; |
---|
| 91 | 00158 } |
---|
| 92 | 00159 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (useShadowBuffer && usage == HBU_STATIC) |
---|
| 93 | 00160 { |
---|
| 94 | 00161 mUsage = HBU_STATIC_WRITE_ONLY; |
---|
| 95 | 00162 } |
---|
| 96 | 00163 } |
---|
| 97 | <a name="l00164"></a><a class="code" href="classOgre_1_1HardwareBuffer.html#Ogre_1_1HardwareBuffera1">00164</a> <span class="keyword">virtual</span> ~HardwareBuffer() {} |
---|
| 98 | <a name="l00171"></a><a class="code" href="classOgre_1_1HardwareBuffer.html#Ogre_1_1HardwareVertexBuffera4">00171</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span>* lock(size_t offset, size_t length, LockOptions options) |
---|
| 99 | 00172 { |
---|
| 100 | 00173 assert(!isLocked() && <span class="stringliteral">"Cannot lock this buffer, it is already locked!"</span>); |
---|
| 101 | 00174 <span class="keywordtype">void</span>* ret; |
---|
| 102 | 00175 <span class="keywordflow">if</span> (mUseShadowBuffer) |
---|
| 103 | 00176 { |
---|
| 104 | 00177 <span class="keywordflow">if</span> (options != HBL_READ_ONLY) |
---|
| 105 | 00178 { |
---|
| 106 | 00179 <span class="comment">// we have to assume a read / write lock so we use the shadow buffer</span> |
---|
| 107 | 00180 <span class="comment">// and tag for sync on unlock()</span> |
---|
| 108 | 00181 mShadowUpdated = <span class="keyword">true</span>; |
---|
| 109 | 00182 } |
---|
| 110 | 00183 |
---|
| 111 | 00184 ret = mpShadowBuffer->lock(offset, length, options); |
---|
| 112 | 00185 } |
---|
| 113 | 00186 <span class="keywordflow">else</span> |
---|
| 114 | 00187 { |
---|
| 115 | 00188 <span class="comment">// Lock the real buffer if there is no shadow buffer </span> |
---|
| 116 | 00189 ret = lockImpl(offset, length, options); |
---|
| 117 | 00190 mIsLocked = <span class="keyword">true</span>; |
---|
| 118 | 00191 } |
---|
| 119 | 00192 mLockStart = offset; |
---|
| 120 | 00193 mLockSize = length; |
---|
| 121 | 00194 <span class="keywordflow">return</span> ret; |
---|
| 122 | 00195 } |
---|
| 123 | 00196 |
---|
| 124 | <a name="l00201"></a><a class="code" href="classOgre_1_1HardwareBuffer.html#Ogre_1_1HardwareVertexBuffera5">00201</a> <span class="keywordtype">void</span>* lock(LockOptions options) |
---|
| 125 | 00202 { |
---|
| 126 | 00203 <span class="keywordflow">return</span> this->lock(0, mSizeInBytes, options); |
---|
| 127 | 00204 } |
---|
| 128 | <a name="l00217"></a><a class="code" href="classOgre_1_1HardwareBuffer.html#Ogre_1_1HardwareVertexBuffera6">00217</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> unlock(<span class="keywordtype">void</span>) |
---|
| 129 | 00218 { |
---|
| 130 | 00219 assert(isLocked() && <span class="stringliteral">"Cannot unlock this buffer, it is not locked!"</span>); |
---|
| 131 | 00220 |
---|
| 132 | 00221 <span class="comment">// If we used the shadow buffer this time...</span> |
---|
| 133 | 00222 <span class="keywordflow">if</span> (mUseShadowBuffer && mpShadowBuffer->isLocked()) |
---|
| 134 | 00223 { |
---|
| 135 | 00224 mpShadowBuffer->unlock(); |
---|
| 136 | 00225 <span class="comment">// Potentially update the 'real' buffer from the shadow buffer</span> |
---|
| 137 | 00226 _updateFromShadow(); |
---|
| 138 | 00227 } |
---|
| 139 | 00228 <span class="keywordflow">else</span> |
---|
| 140 | 00229 { |
---|
| 141 | 00230 <span class="comment">// Otherwise, unlock the real one</span> |
---|
| 142 | 00231 unlockImpl(); |
---|
| 143 | 00232 mIsLocked = <span class="keyword">false</span>; |
---|
| 144 | 00233 } |
---|
| 145 | 00234 |
---|
| 146 | 00235 } |
---|
| 147 | 00236 |
---|
| 148 | 00243 <span class="keyword">virtual</span> <span class="keywordtype">void</span> readData(size_t offset, size_t length, <span class="keywordtype">void</span>* pDest) = 0; |
---|
| 149 | 00252 <span class="keyword">virtual</span> <span class="keywordtype">void</span> writeData(size_t offset, size_t length, <span class="keyword">const</span> <span class="keywordtype">void</span>* pSource, |
---|
| 150 | 00253 <span class="keywordtype">bool</span> discardWholeBuffer = <span class="keyword">false</span>) = 0; |
---|
| 151 | 00254 |
---|
| 152 | <a name="l00265"></a><a class="code" href="classOgre_1_1HardwareBuffer.html#Ogre_1_1HardwareVertexBuffera9">00265</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> copyData(HardwareBuffer& srcBuffer, size_t srcOffset, |
---|
| 153 | 00266 size_t dstOffset, size_t length, <span class="keywordtype">bool</span> discardWholeBuffer = <span class="keyword">false</span>) |
---|
| 154 | 00267 { |
---|
| 155 | 00268 <span class="keyword">const</span> <span class="keywordtype">void</span> *srcData = srcBuffer.<a class="code" href="classOgre_1_1HardwareBuffer.html#Ogre_1_1HardwareVertexBuffera4">lock</a>( |
---|
| 156 | 00269 srcOffset, length, HBL_READ_ONLY); |
---|
| 157 | 00270 this->writeData(dstOffset, length, srcData, discardWholeBuffer); |
---|
| 158 | 00271 srcBuffer.<a class="code" href="classOgre_1_1HardwareBuffer.html#Ogre_1_1HardwareVertexBuffera6">unlock</a>(); |
---|
| 159 | 00272 } |
---|
| 160 | 00273 |
---|
| 161 | <a name="l00275"></a><a class="code" href="classOgre_1_1HardwareBuffer.html#Ogre_1_1HardwareVertexBuffera10">00275</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> _updateFromShadow(<span class="keywordtype">void</span>) |
---|
| 162 | 00276 { |
---|
| 163 | 00277 <span class="keywordflow">if</span> (mUseShadowBuffer && mShadowUpdated && !mSuppressHardwareUpdate) |
---|
| 164 | 00278 { |
---|
| 165 | 00279 <span class="comment">// Do this manually to avoid locking problems</span> |
---|
| 166 | 00280 <span class="keyword">const</span> <span class="keywordtype">void</span> *srcData = mpShadowBuffer->lockImpl( |
---|
| 167 | 00281 mLockStart, mLockSize, HBL_READ_ONLY); |
---|
| 168 | 00282 <span class="comment">// Lock with discard if the whole buffer was locked, otherwise normal</span> |
---|
| 169 | 00283 LockOptions lockOpt; |
---|
| 170 | 00284 <span class="keywordflow">if</span> (mLockStart == 0 && mLockSize == mSizeInBytes) |
---|
| 171 | 00285 lockOpt = HBL_DISCARD; |
---|
| 172 | 00286 <span class="keywordflow">else</span> |
---|
| 173 | 00287 lockOpt = HBL_NORMAL; |
---|
| 174 | 00288 |
---|
| 175 | 00289 <span class="keywordtype">void</span> *destData = this->lockImpl( |
---|
| 176 | 00290 mLockStart, mLockSize, lockOpt); |
---|
| 177 | 00291 <span class="comment">// Copy shadow to real</span> |
---|
| 178 | 00292 memcpy(destData, srcData, mLockSize); |
---|
| 179 | 00293 this->unlockImpl(); |
---|
| 180 | 00294 mpShadowBuffer->unlockImpl(); |
---|
| 181 | 00295 mShadowUpdated = <span class="keyword">false</span>; |
---|
| 182 | 00296 } |
---|
| 183 | 00297 } |
---|
| 184 | 00298 |
---|
| 185 | <a name="l00300"></a><a class="code" href="classOgre_1_1HardwareBuffer.html#Ogre_1_1HardwareVertexBuffera11">00300</a> size_t getSizeInBytes(<span class="keywordtype">void</span>)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> mSizeInBytes; } |
---|
| 186 | <a name="l00302"></a><a class="code" href="classOgre_1_1HardwareBuffer.html#Ogre_1_1HardwareVertexBuffera12">00302</a> Usage getUsage(<span class="keywordtype">void</span>)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> mUsage; } |
---|
| 187 | <a name="l00304"></a><a class="code" href="classOgre_1_1HardwareBuffer.html#Ogre_1_1HardwareVertexBuffera13">00304</a> <span class="keywordtype">bool</span> isSystemMemory(<span class="keywordtype">void</span>)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> mSystemMemory; } |
---|
| 188 | <a name="l00306"></a><a class="code" href="classOgre_1_1HardwareBuffer.html#Ogre_1_1HardwareVertexBuffera14">00306</a> <span class="keywordtype">bool</span> hasShadowBuffer(<span class="keywordtype">void</span>)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> mUseShadowBuffer; } |
---|
| 189 | <a name="l00308"></a><a class="code" href="classOgre_1_1HardwareBuffer.html#Ogre_1_1HardwareVertexBuffera15">00308</a> <span class="keywordtype">bool</span> isLocked(<span class="keywordtype">void</span>)<span class="keyword"> const </span>{ |
---|
| 190 | 00309 <span class="keywordflow">return</span> mIsLocked || (mUseShadowBuffer && mpShadowBuffer->isLocked()); |
---|
| 191 | 00310 } |
---|
| 192 | <a name="l00312"></a><a class="code" href="classOgre_1_1HardwareBuffer.html#Ogre_1_1HardwareVertexBuffera16">00312</a> <span class="keywordtype">void</span> suppressHardwareUpdate(<span class="keywordtype">bool</span> suppress) { |
---|
| 193 | 00313 mSuppressHardwareUpdate = suppress; |
---|
| 194 | 00314 <span class="keywordflow">if</span> (!suppress) |
---|
| 195 | 00315 _updateFromShadow(); |
---|
| 196 | 00316 } |
---|
| 197 | 00317 |
---|
| 198 | 00318 |
---|
| 199 | 00319 |
---|
| 200 | 00320 |
---|
| 201 | 00321 |
---|
| 202 | 00322 }; |
---|
| 203 | 00323 } |
---|
| 204 | 00324 <span class="preprocessor">#endif</span> |
---|
| 205 | 00325 <span class="preprocessor"></span> |
---|
| 206 | 00326 |
---|
| 207 | </pre></div><hr> |
---|
| 208 | <p> |
---|
| 209 | Copyright © 2000-2005 by The OGRE Team<br /> |
---|
| 210 | <!--Creative Commons License--><a rel="license" href="http://creativecommons.org/licenses/by-sa/2.5/"><img alt="Creative Commons License" border="0" src="http://creativecommons.org/images/public/somerights20.png"/></a><br/> |
---|
| 211 | This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/2.5/">Creative Commons Attribution-ShareAlike 2.5 License</a>.<br/> |
---|
| 212 | <!--/Creative Commons License--><!-- <rdf:RDF xmlns="http://web.resource.org/cc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> |
---|
| 213 | <Work rdf:about=""> |
---|
| 214 | <license rdf:resource="http://creativecommons.org/licenses/by-sa/2.5/" /> |
---|
| 215 | <dc:type rdf:resource="http://purl.org/dc/dcmitype/Text" /> |
---|
| 216 | </Work> |
---|
| 217 | <License rdf:about="http://creativecommons.org/licenses/by-sa/2.5/"><permits rdf:resource="http://web.resource.org/cc/Reproduction"/><permits rdf:resource="http://web.resource.org/cc/Distribution"/><requires rdf:resource="http://web.resource.org/cc/Notice"/><requires rdf:resource="http://web.resource.org/cc/Attribution"/><permits rdf:resource="http://web.resource.org/cc/DerivativeWorks"/><requires rdf:resource="http://web.resource.org/cc/ShareAlike"/></License></rdf:RDF> --> |
---|
| 218 | |
---|
| 219 | Last modified Sun Mar 12 14:37:42 2006 |
---|
| 220 | </p> |
---|
| 221 | </body> |
---|
| 222 | </html> |
---|