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
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;
367 pData =
pBuf->lock(offset, length, options);
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Abstract class defining common features of hardware buffers.
virtual void copyData(HardwareBuffer &srcBuffer)
Copy all data from another buffer into this one.
bool isSystemMemory(void) const
Returns whether this buffer is held in system memory.
virtual ~HardwareBuffer()
virtual void _updateFromShadow(void)
Updates the real buffer from the shadow buffer, if required.
bool hasShadowBuffer(void) const
Returns whether this buffer has a system memory shadow for quicker reading.
HardwareBuffer(Usage usage, bool systemMemory, bool useShadowBuffer)
Constructor, to be called by HardwareBufferManager only.
bool mSuppressHardwareUpdate
virtual void readData(size_t offset, size_t length, void *pDest)=0
Reads data from the buffer and places it in the memory pointed to by pDest.
virtual void * lockImpl(size_t offset, size_t length, LockOptions options)=0
Internal implementation of lock()
virtual void unlock(void)
Releases the lock on this buffer.
void suppressHardwareUpdate(bool suppress)
Pass true to suppress hardware upload of shadow buffer changes.
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.
bool isLocked(void) const
Returns whether or not this buffer is currently locked.
virtual void unlockImpl(void)=0
Internal implementation of unlock()
virtual void writeData(size_t offset, size_t length, const void *pSource, bool discardWholeBuffer=false)=0
Writes data to the buffer from an area of system memory; note that you must ensure that your buffer i...
size_t getSizeInBytes(void) const
Returns the size of this buffer in bytes.
void * lock(LockOptions options)
Lock the entire buffer for (potentially) reading / writing.
Usage getUsage(void) const
Returns the Usage flags with which this buffer was created.
HardwareBuffer * mShadowBuffer
LockOptions
Locking options.
@ HBL_DISCARD
Discards the entire buffer while locking; this allows optimisation to be performed because synchronis...
@ HBL_NO_OVERWRITE
As HBL_DISCARD, except the application guarantees not to overwrite any region of the buffer which has...
@ HBL_READ_ONLY
Lock the buffer for reading only.
@ HBL_NORMAL
Normal mode, ie allows read/write and contents are preserved.
virtual void * lock(size_t offset, size_t length, LockOptions options)
Lock the buffer for (potentially) reading / writing.
Usage
Enums describing buffer usage; not mutually exclusive.
#define OGRE_EXCEPT(num, desc, src)
HardwareBufferLockGuard(const T &p, size_t offset, size_t length, HardwareBuffer::LockOptions options)
~HardwareBufferLockGuard()
HardwareBufferLockGuard(const T &p, HardwareBuffer::LockOptions options)