@@ -143,7 +143,7 @@ namespace Ogre {
143
143
HBL_WRITE_ONLY
144
144
145
145
};
146
- Buffer (size_t sizeInBytes, Usage usage) : mSizeInBytes (sizeInBytes), mUsage (usage) {}
146
+ Buffer (size_t sizeInBytes, Usage usage) : mSizeInBytes (sizeInBytes), mUsage (usage), mIsLocked ( false ) {}
147
147
148
148
virtual ~Buffer () {}
149
149
/* * Reads data from the buffer and places it in the memory pointed to by pDest.
@@ -152,7 +152,7 @@ namespace Ogre {
152
152
@param pDest The area of memory in which to place the data, must be large enough to
153
153
accommodate the data!
154
154
*/
155
- virtual void readData (size_t offset, size_t length, void * pDest) = 0;
155
+ virtual void readData (size_t offset, size_t length, void * pDest) /* const */ = 0;
156
156
/* * Writes data to the buffer from an area of system memory; note that you must
157
157
ensure that your buffer is big enough.
158
158
@param offset The byte offset from the start of the buffer to start writing
@@ -173,8 +173,26 @@ namespace Ogre {
173
173
@param length Length of the data to copy, in bytes.
174
174
@param discardWholeBuffer If true, will discard the entire contents of this buffer before copying
175
175
*/
176
- virtual void copyData (HardwareBuffer& srcBuffer, size_t srcOffset, size_t dstOffset, size_t length,
177
- bool discardWholeBuffer = false ) = 0;
176
+ virtual void copyData (HardwareBuffer& _srcBuffer, size_t srcOffset, size_t dstOffset, size_t length,
177
+ bool discardWholeBuffer = false )
178
+ {
179
+ auto & srcBuffer = (Buffer&)_srcBuffer; // backward compat
180
+ const void * srcData = srcBuffer.lock (srcOffset, length, HBL_READ_ONLY);
181
+ this ->writeData (dstOffset, length, srcData, discardWholeBuffer);
182
+ srcBuffer.unlock ();
183
+ }
184
+
185
+ /* * Copy all data from another buffer into this one.
186
+ @remarks
187
+ Normally these buffers should be of identical size, but if they're
188
+ not, the routine will use the smallest of the two sizes.
189
+ */
190
+ void copyData (HardwareBuffer& _srcBuffer)
191
+ {
192
+ auto & srcBuffer = (Buffer&)_srcBuffer; // backward compat
193
+ size_t sz = std::min (getSizeInBytes (), srcBuffer.getSizeInBytes ());
194
+ copyData (_srcBuffer, 0 , 0 , sz, true );
195
+ }
178
196
179
197
/* * Lock the buffer for (potentially) reading / writing.
180
198
@param offset The byte offset from the start of the buffer to lock
@@ -202,15 +220,15 @@ namespace Ogre {
202
220
virtual void unlock () = 0;
203
221
204
222
// / Returns whether or not this buffer is currently locked.
205
- virtual bool isLocked () const = 0;
206
-
223
+ virtual bool isLocked () const { return mIsLocked ; }
207
224
// / Returns the size of this buffer in bytes
208
225
size_t getSizeInBytes (void ) const { return mSizeInBytes ; }
209
226
// / Returns the Usage flags with which this buffer was created
210
227
Usage getUsage (void ) const { return mUsage ; }
211
228
protected:
212
229
size_t mSizeInBytes ;
213
230
Usage mUsage ;
231
+ bool mIsLocked ;
214
232
};
215
233
216
234
/* * Abstract class defining common features of hardware buffers.
@@ -247,10 +265,9 @@ namespace Ogre {
247
265
class _OgreExport HardwareBuffer : public Buffer
248
266
{
249
267
protected:
250
- bool mIsLocked ;
251
268
size_t mLockStart ;
252
269
size_t mLockSize ;
253
- std::unique_ptr<HardwareBuffer > mShadowBuffer ;
270
+ std::unique_ptr<Buffer > mShadowBuffer ;
254
271
bool mSystemMemory ;
255
272
bool mUseShadowBuffer ;
256
273
bool mShadowUpdated ;
@@ -264,7 +281,7 @@ namespace Ogre {
264
281
public:
265
282
// / Constructor, to be called by HardwareBufferManager only
266
283
HardwareBuffer (Usage usage, bool systemMemory, bool useShadowBuffer)
267
- : Buffer(0 , usage), mIsLocked ( false ), mLockStart (0 ), mLockSize (0 ), mSystemMemory (systemMemory),
284
+ : Buffer(0 , usage), mLockStart (0 ), mLockSize (0 ), mSystemMemory (systemMemory),
268
285
mUseShadowBuffer (useShadowBuffer), mShadowUpdated(false ),
269
286
mSuppressHardwareUpdate(false )
270
287
{
@@ -333,58 +350,19 @@ namespace Ogre {
333
350
}
334
351
335
352
}
336
-
337
- /* * Copy data from another buffer into this one.
338
- @remarks
339
- Note that the source buffer must not be created with the
340
- usage HBU_WRITE_ONLY otherwise this will fail.
341
- @param srcBuffer The buffer from which to read the copied data
342
- @param srcOffset Offset in the source buffer at which to start reading
343
- @param dstOffset Offset in the destination buffer to start writing
344
- @param length Length of the data to copy, in bytes.
345
- @param discardWholeBuffer If true, will discard the entire contents of this buffer before copying
346
- */
347
- void copyData (HardwareBuffer& srcBuffer, size_t srcOffset, size_t dstOffset, size_t length,
348
- bool discardWholeBuffer = false ) override
349
- {
350
- const void *srcData = srcBuffer.lock (
351
- srcOffset, length, HBL_READ_ONLY);
352
- this ->writeData (dstOffset, length, srcData, discardWholeBuffer);
353
- srcBuffer.unlock ();
354
- }
355
-
356
- /* * Copy all data from another buffer into this one.
357
- @remarks
358
- Normally these buffers should be of identical size, but if they're
359
- not, the routine will use the smallest of the two sizes.
360
- */
361
- virtual void copyData (HardwareBuffer& srcBuffer)
362
- {
363
- size_t sz = std::min (getSizeInBytes (), srcBuffer.getSizeInBytes ());
364
- copyData (srcBuffer, 0 , 0 , sz, true );
365
- }
366
353
367
354
// / Updates the real buffer from the shadow buffer, if required
368
355
virtual void _updateFromShadow (void )
369
356
{
370
357
if (mUseShadowBuffer && mShadowUpdated && !mSuppressHardwareUpdate )
371
358
{
372
- // Do this manually to avoid locking problems
373
- const void *srcData = mShadowBuffer ->lockImpl (
374
- mLockStart , mLockSize , HBL_READ_ONLY);
375
359
// Lock with discard if the whole buffer was locked, otherwise w/o
376
- LockOptions lockOpt;
377
- if (mLockStart == 0 && mLockSize == mSizeInBytes )
378
- lockOpt = HBL_DISCARD;
379
- else
380
- lockOpt = HBL_WRITE_ONLY;
381
-
382
- void *destData = this ->lockImpl (
383
- mLockStart , mLockSize , lockOpt);
360
+ LockOptions lockOpt = mLockSize == mSizeInBytes ? HBL_DISCARD : HBL_WRITE_ONLY;
361
+ // Do this manually to avoid locking problems
362
+ void * destData = this ->lockImpl (mLockStart , mLockSize , lockOpt);
384
363
// Copy shadow to real
385
- memcpy (destData, srcData, mLockSize );
364
+ mShadowBuffer -> readData ( mLockStart , mLockSize , destData );
386
365
this ->unlockImpl ();
387
- mShadowBuffer ->unlockImpl ();
388
366
mShadowUpdated = false ;
389
367
}
390
368
}
0 commit comments