28 #ifndef __HardwareBuffer__
29 #define __HardwareBuffer__
108 HBU_STATIC_WRITE_ONLY = 5,
114 HBU_DYNAMIC_WRITE_ONLY = 6,
116 HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE = 14
153 virtual void* lockImpl(
size_t offset,
size_t length,
LockOptions options) = 0;
155 virtual void unlockImpl(
void) = 0;
160 : mUsage(usage), mIsLocked(false), mSystemMemory(systemMemory),
161 mUseShadowBuffer(useShadowBuffer), mShadowBuffer(NULL), mShadowUpdated(false),
162 mSuppressHardwareUpdate(false)
165 if (useShadowBuffer && usage == HBU_DYNAMIC)
167 mUsage = HBU_DYNAMIC_WRITE_ONLY;
169 else if (useShadowBuffer && usage == HBU_STATIC)
171 mUsage = HBU_STATIC_WRITE_ONLY;
183 assert(!isLocked() &&
"Cannot lock this buffer, it is already locked!");
186 if ((length + offset) > mSizeInBytes)
189 "Lock request out of bounds.",
190 "HardwareBuffer::lock");
192 else if (mUseShadowBuffer)
194 if (options != HBL_READ_ONLY)
198 mShadowUpdated =
true;
201 ret = mShadowBuffer->lock(offset, length, options);
206 ret = lockImpl(offset, length, options);
220 return this->lock(0, mSizeInBytes, options);
236 assert(isLocked() &&
"Cannot unlock this buffer, it is not locked!");
239 if (mUseShadowBuffer && mShadowBuffer->isLocked())
241 mShadowBuffer->unlock();
260 virtual void readData(
size_t offset,
size_t length,
void* pDest) = 0;
269 virtual void writeData(
size_t offset,
size_t length,
const void* pSource,
270 bool discardWholeBuffer =
false) = 0;
283 size_t dstOffset,
size_t length,
bool discardWholeBuffer =
false)
285 const void *srcData = srcBuffer.
lock(
286 srcOffset, length, HBL_READ_ONLY);
287 this->writeData(dstOffset, length, srcData, discardWholeBuffer);
298 size_t sz = std::min(getSizeInBytes(), srcBuffer.
getSizeInBytes());
299 copyData(srcBuffer, 0, 0, sz,
true);
305 if (mUseShadowBuffer && mShadowUpdated && !mSuppressHardwareUpdate)
308 const void *srcData = mShadowBuffer->lockImpl(
309 mLockStart, mLockSize, HBL_READ_ONLY);
312 if (mLockStart == 0 && mLockSize == mSizeInBytes)
313 lockOpt = HBL_DISCARD;
315 lockOpt = HBL_NORMAL;
317 void *destData = this->lockImpl(
318 mLockStart, mLockSize, lockOpt);
320 memcpy(destData, srcData, mLockSize);
322 mShadowBuffer->unlockImpl();
323 mShadowUpdated =
false;
337 return mIsLocked || (mUseShadowBuffer && mShadowBuffer->isLocked());
341 mSuppressHardwareUpdate = suppress;
size_t getSizeInBytes(void) const
Returns the size of this buffer in bytes.
bool mSuppressHardwareUpdate
virtual void * lock(size_t offset, size_t length, LockOptions options)
Lock the buffer for (potentially) reading / writing.
HardwareBuffer(Usage usage, bool systemMemory, bool useShadowBuffer)
Constructor, to be called by HardwareBufferManager only.
virtual void copyData(HardwareBuffer &srcBuffer, size_t srcOffset, size_t dstOffset, size_t length, bool discardWholeBuffer=false)
Copy data from another buffer into this one.
Discards the entire buffer while locking; this allows optimisation to be performed because synchronis...
void * lock(LockOptions options)
Lock the entire buffer for (potentially) reading / writing.
HardwareBuffer * mShadowBuffer
LockOptions
Locking options.
virtual ~HardwareBuffer()
Normal mode, ie allows read/write and contents are preserved.
bool isLocked(void) const
Returns whether or not this buffer is currently locked.
#define OGRE_EXCEPT(num, desc, src)
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
void suppressHardwareUpdate(bool suppress)
Pass true to suppress hardware upload of shadow buffer changes.
bool hasShadowBuffer(void) const
Returns whether this buffer has a system memory shadow for quicker reading.
Usage
Enums describing buffer usage; not mutually exclusive.
Usage getUsage(void) const
Returns the Usage flags with which this buffer was created.
virtual void unlock(void)
Releases the lock on this buffer.
Lock the buffer for reading only.
virtual void copyData(HardwareBuffer &srcBuffer)
Copy all data from another buffer into this one.
Abstract class defining common features of hardware buffers.
bool isSystemMemory(void) const
Returns whether this buffer is held in system memory.
virtual void _updateFromShadow(void)
Updates the real buffer from the shadow buffer, if required.