28#ifndef __HardwareBuffer__
29#define __HardwareBuffer__
171 else if (useShadowBuffer && usage ==
HBU_STATIC)
185 assert(!
isLocked() &&
"Cannot lock this buffer, it is already locked!");
191 "Lock request out of bounds.",
192 "HardwareBuffer::lock");
208 ret =
lockImpl(offset, length, options);
238 assert(
isLocked() &&
"Cannot unlock this buffer, it is not locked!");
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(
289 this->
writeData(dstOffset, length, srcData, discardWholeBuffer);
301 copyData(srcBuffer, 0, 0, sz,
true);
367 pData =
pBuf->lock(offset, length, options);
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 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.
virtual void * lock(size_t offset, size_t length, LockOptions options)
Lock the buffer for (potentially) reading / writing.
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.
Usage getUsage(void) const
Returns the Usage flags with which this buffer was created.
HardwareBuffer * mShadowBuffer
virtual void * lockImpl(size_t offset, size_t length, LockOptions options)=0
Internal implementation of lock()
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.
@ HBL_WRITE_ONLY
Lock the buffer for writing only.
void * lock(LockOptions options)
Lock the entire buffer for (potentially) reading / writing.
Usage
Enums describing buffer usage; not mutually exclusive.
@ HBU_DISCARDABLE
Indicates that the application will be refilling the contents of the buffer regularly (not just updat...
@ HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE
Combination of HBU_DYNAMIC, HBU_WRITE_ONLY and HBU_DISCARDABLE.
@ HBU_WRITE_ONLY
Indicates the application will never read the contents of the buffer back, it will only ever write da...
@ HBU_STATIC_WRITE_ONLY
Combination of HBU_STATIC and HBU_WRITE_ONLY.
@ HBU_STATIC
Static buffer which the application rarely modifies once created.
@ HBU_DYNAMIC_WRITE_ONLY
Combination of HBU_DYNAMIC and HBU_WRITE_ONLY.
@ HBU_DYNAMIC
Indicates the application would like to modify this buffer with the CPU fairly often.
#define OGRE_EXCEPT(code, desc, src)
RenderSysAllocatedObject BufferAlloc
HardwareBufferLockGuard(const T &p, size_t offset, size_t length, HardwareBuffer::LockOptions options)
~HardwareBufferLockGuard()
const HardwareIndexBufferSharedPtr & pBuf
HardwareBufferLockGuard(const T &p, HardwareBuffer::LockOptions options)