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
155 virtual void* lockImpl(
size_t offset,
size_t length,
LockOptions options) = 0;
157 virtual void unlockImpl(
void) = 0;
162 : mUsage(usage), mIsLocked(false), mLockStart(0), mLockSize(0), mSystemMemory(systemMemory),
163 mUseShadowBuffer(useShadowBuffer), mShadowBuffer(NULL), mShadowUpdated(false),
164 mSuppressHardwareUpdate(false)
167 if (useShadowBuffer && usage == HBU_DYNAMIC)
169 mUsage = HBU_DYNAMIC_WRITE_ONLY;
171 else if (useShadowBuffer && usage == HBU_STATIC)
173 mUsage = HBU_STATIC_WRITE_ONLY;
185 assert(!isLocked() &&
"Cannot lock this buffer, it is already locked!");
188 if ((length + offset) > mSizeInBytes)
191 "Lock request out of bounds.",
192 "HardwareBuffer::lock");
194 else if (mUseShadowBuffer)
196 if (options != HBL_READ_ONLY)
200 mShadowUpdated =
true;
203 ret = mShadowBuffer->
lock(offset, length, options);
208 ret = lockImpl(offset, length, options);
222 return this->lock(0, mSizeInBytes, options);
238 assert(isLocked() &&
"Cannot unlock this buffer, it is not locked!");
241 if (mUseShadowBuffer && mShadowBuffer->
isLocked())
262 virtual void readData(
size_t offset,
size_t length,
void* pDest) = 0;
271 virtual void writeData(
size_t offset,
size_t length,
const void* pSource,
272 bool discardWholeBuffer =
false) = 0;
285 size_t dstOffset,
size_t length,
bool discardWholeBuffer =
false)
287 const void *srcData = srcBuffer.
lock(
288 srcOffset, length, HBL_READ_ONLY);
289 this->writeData(dstOffset, length, srcData, discardWholeBuffer);
300 size_t sz = std::min(getSizeInBytes(), srcBuffer.
getSizeInBytes());
301 copyData(srcBuffer, 0, 0, sz,
true);
307 if (mUseShadowBuffer && mShadowUpdated && !mSuppressHardwareUpdate)
310 const void *srcData = mShadowBuffer->
lockImpl(
311 mLockStart, mLockSize, HBL_READ_ONLY);
314 if (mLockStart == 0 && mLockSize == mSizeInBytes)
315 lockOpt = HBL_DISCARD;
317 lockOpt = HBL_NORMAL;
319 void *destData = this->lockImpl(
320 mLockStart, mLockSize, lockOpt);
322 memcpy(destData, srcData, mLockSize);
325 mShadowUpdated =
false;
339 return mIsLocked || (mUseShadowBuffer && mShadowBuffer->
isLocked());
343 mSuppressHardwareUpdate = suppress;
362 pData = pBuf->lock(options);
367 pData = pBuf->lock(offset, length, options);
bool isSystemMemory(void) const
Returns whether this buffer is held in system memory.
virtual void * lock(size_t offset, size_t length, LockOptions options)
Lock the buffer for (potentially) reading / writing.
Lock the buffer for reading only.
bool hasShadowBuffer(void) const
Returns whether this buffer has a system memory shadow for quicker reading.
virtual void unlock(void)
Releases the lock on this buffer.
HardwareBufferLockGuard(const T &p, size_t offset, size_t length, HardwareBuffer::LockOptions options)
bool mSuppressHardwareUpdate
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.
size_t getSizeInBytes(void) const
Returns the size of this buffer in bytes.
Usage getUsage(void) const
Returns the Usage flags with which this buffer was created.
~HardwareBufferLockGuard()
virtual void * lockImpl(size_t offset, size_t length, LockOptions options)=0
Internal implementation of lock()
As HBL_DISCARD, except the application guarantees not to overwrite any region of the buffer which has...
HardwareBuffer(Usage usage, bool systemMemory, bool useShadowBuffer)
Constructor, to be called by HardwareBufferManager only.
Usage
Enums describing buffer usage; not mutually exclusive.
Abstract class defining common features of hardware buffers.
HardwareBuffer * mShadowBuffer
virtual void unlockImpl(void)=0
Internal implementation of unlock()
Normal mode, ie allows read/write and contents are preserved.
LockOptions
Locking options.
#define OGRE_EXCEPT(num, desc, src)
void suppressHardwareUpdate(bool suppress)
Pass true to suppress hardware upload of shadow buffer changes.
HardwareBufferLockGuard(const T &p, HardwareBuffer::LockOptions options)
virtual void copyData(HardwareBuffer &srcBuffer)
Copy all 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.
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
virtual void _updateFromShadow(void)
Updates the real buffer from the shadow buffer, if required.
bool isLocked(void) const
Returns whether or not this buffer is currently locked.
virtual ~HardwareBuffer()