@@ -122,7 +122,7 @@ namespace Ogre {
122
122
HBL_WRITE_ONLY
123
123
124
124
};
125
- Buffer (size_t sizeInBytes, int usage) : mSizeInBytes (sizeInBytes), mUsage (usage) {}
125
+ Buffer (size_t sizeInBytes, int usage) : mSizeInBytes (sizeInBytes), mUsage (usage), mIsLocked ( false ) {}
126
126
127
127
virtual ~Buffer () {}
128
128
/* * Reads data from the buffer and places it in the memory pointed to by pDest.
@@ -131,7 +131,7 @@ namespace Ogre {
131
131
@param pDest The area of memory in which to place the data, must be large enough to
132
132
accommodate the data!
133
133
*/
134
- virtual void readData (size_t offset, size_t length, void * pDest) = 0;
134
+ virtual void readData (size_t offset, size_t length, void * pDest) /* const */ = 0;
135
135
/* * Writes data to the buffer from an area of system memory; note that you must
136
136
ensure that your buffer is big enough.
137
137
@param offset The byte offset from the start of the buffer to start writing
@@ -152,8 +152,26 @@ namespace Ogre {
152
152
@param length Length of the data to copy, in bytes.
153
153
@param discardWholeBuffer If true, will discard the entire contents of this buffer before copying
154
154
*/
155
- virtual void copyData (HardwareBuffer& srcBuffer, size_t srcOffset, size_t dstOffset, size_t length,
156
- bool discardWholeBuffer = false ) = 0;
155
+ virtual void copyData (HardwareBuffer& _srcBuffer, size_t srcOffset, size_t dstOffset, size_t length,
156
+ bool discardWholeBuffer = false )
157
+ {
158
+ auto & srcBuffer = (Buffer&)_srcBuffer; // backward compat
159
+ const void * srcData = srcBuffer.lock (srcOffset, length, HBL_READ_ONLY);
160
+ this ->writeData (dstOffset, length, srcData, discardWholeBuffer);
161
+ srcBuffer.unlock ();
162
+ }
163
+
164
+ /* * Copy all data from another buffer into this one.
165
+ @remarks
166
+ Normally these buffers should be of identical size, but if they're
167
+ not, the routine will use the smallest of the two sizes.
168
+ */
169
+ void copyData (HardwareBuffer& _srcBuffer)
170
+ {
171
+ auto & srcBuffer = (Buffer&)_srcBuffer; // backward compat
172
+ size_t sz = std::min (getSizeInBytes (), srcBuffer.getSizeInBytes ());
173
+ copyData (_srcBuffer, 0 , 0 , sz, true );
174
+ }
157
175
158
176
/* * Lock the buffer for (potentially) reading / writing.
159
177
@param offset The byte offset from the start of the buffer to lock
@@ -181,15 +199,15 @@ namespace Ogre {
181
199
virtual void unlock () = 0;
182
200
183
201
// / Returns whether or not this buffer is currently locked.
184
- virtual bool isLocked () const = 0;
185
-
202
+ virtual bool isLocked () const { return mIsLocked ; }
186
203
// / Returns the size of this buffer in bytes
187
204
size_t getSizeInBytes (void ) const { return mSizeInBytes ; }
188
205
// / Returns the Usage flags with which this buffer was created
189
206
int getUsage (void ) const { return mUsage ; }
190
207
protected:
191
208
size_t mSizeInBytes ;
192
209
int mUsage ;
210
+ bool mIsLocked ;
193
211
};
194
212
195
213
@@ -248,10 +266,9 @@ namespace Ogre {
248
266
HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE = HBU_CPU_TO_GPU,
249
267
};
250
268
protected:
251
- bool mIsLocked ;
252
269
size_t mLockStart ;
253
270
size_t mLockSize ;
254
- std::unique_ptr<HardwareBuffer > mShadowBuffer ;
271
+ std::unique_ptr<Buffer > mShadowBuffer ;
255
272
bool mSystemMemory ;
256
273
bool mUseShadowBuffer ;
257
274
bool mShadowUpdated ;
@@ -265,7 +282,7 @@ namespace Ogre {
265
282
public:
266
283
// / Constructor, to be called by HardwareBufferManager only
267
284
HardwareBuffer (Usage usage, bool systemMemory, bool useShadowBuffer)
268
- : Buffer(0 , usage), mIsLocked ( false ), mLockStart (0 ), mLockSize (0 ), mSystemMemory (systemMemory),
285
+ : Buffer(0 , usage), mLockStart (0 ), mLockSize (0 ), mSystemMemory (systemMemory),
269
286
mUseShadowBuffer (useShadowBuffer), mShadowUpdated(false ),
270
287
mSuppressHardwareUpdate(false )
271
288
{
@@ -330,57 +347,18 @@ namespace Ogre {
330
347
331
348
}
332
349
333
- /* * Copy data from another buffer into this one.
334
- @remarks
335
- Note that the source buffer must not be created with the
336
- usage HBU_WRITE_ONLY otherwise this will fail.
337
- @param srcBuffer The buffer from which to read the copied data
338
- @param srcOffset Offset in the source buffer at which to start reading
339
- @param dstOffset Offset in the destination buffer to start writing
340
- @param length Length of the data to copy, in bytes.
341
- @param discardWholeBuffer If true, will discard the entire contents of this buffer before copying
342
- */
343
- void copyData (HardwareBuffer& srcBuffer, size_t srcOffset, size_t dstOffset, size_t length,
344
- bool discardWholeBuffer = false ) override
345
- {
346
- const void *srcData = srcBuffer.lock (
347
- srcOffset, length, HBL_READ_ONLY);
348
- this ->writeData (dstOffset, length, srcData, discardWholeBuffer);
349
- srcBuffer.unlock ();
350
- }
351
-
352
- /* * Copy all data from another buffer into this one.
353
- @remarks
354
- Normally these buffers should be of identical size, but if they're
355
- not, the routine will use the smallest of the two sizes.
356
- */
357
- virtual void copyData (HardwareBuffer& srcBuffer)
358
- {
359
- size_t sz = std::min (getSizeInBytes (), srcBuffer.getSizeInBytes ());
360
- copyData (srcBuffer, 0 , 0 , sz, true );
361
- }
362
-
363
350
// / Updates the real buffer from the shadow buffer, if required
364
351
virtual void _updateFromShadow (void )
365
352
{
366
353
if (mUseShadowBuffer && mShadowUpdated && !mSuppressHardwareUpdate )
367
354
{
368
- // Do this manually to avoid locking problems
369
- const void *srcData = mShadowBuffer ->lockImpl (
370
- mLockStart , mLockSize , HBL_READ_ONLY);
371
355
// Lock with discard if the whole buffer was locked, otherwise w/o
372
- LockOptions lockOpt;
373
- if (mLockStart == 0 && mLockSize == mSizeInBytes )
374
- lockOpt = HBL_DISCARD;
375
- else
376
- lockOpt = HBL_WRITE_ONLY;
377
-
378
- void *destData = this ->lockImpl (
379
- mLockStart , mLockSize , lockOpt);
356
+ LockOptions lockOpt = mLockSize == mSizeInBytes ? HBL_DISCARD : HBL_WRITE_ONLY;
357
+ // Do this manually to avoid locking problems
358
+ void * destData = this ->lockImpl (mLockStart , mLockSize , lockOpt);
380
359
// Copy shadow to real
381
- memcpy (destData, srcData, mLockSize );
360
+ mShadowBuffer -> readData ( mLockStart , mLockSize , destData );
382
361
this ->unlockImpl ();
383
- mShadowBuffer ->unlockImpl ();
384
362
mShadowUpdated = false ;
385
363
}
386
364
}
0 commit comments