| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #include "BsGpuParamBlock.h"
- #include "BsGpuParamDesc.h"
- #include "BsGpuParamBlockBuffer.h"
- #include "BsHardwareBufferManager.h"
- #include "BsException.h"
- namespace BansheeEngine
- {
- GpuParamBlock::GpuParamBlock(UINT32 size)
- :mDirty(true), mData(nullptr), mSize(size)
- {
- mData = (UINT8*)bs_alloc<ScratchAlloc>(mSize);
- memset(mData, 0, mSize);
- }
- GpuParamBlock::GpuParamBlock(GpuParamBlock* otherBlock)
- {
- mSize = otherBlock->mSize;
- mData = (UINT8*)bs_alloc<ScratchAlloc>(mSize);
- write(0, otherBlock->getData(), otherBlock->getSize());
- mDirty = otherBlock->mDirty;
- }
- GpuParamBlock::~GpuParamBlock()
- {
- if(mData != nullptr)
- bs_free<ScratchAlloc>(mData);
- }
- void GpuParamBlock::write(UINT32 offset, const void* data, UINT32 size)
- {
- #if BS_DEBUG_MODE
- if(offset < 0 || (offset + size) > mSize)
- {
- BS_EXCEPT(InvalidParametersException, "Wanted range is out of buffer bounds. " \
- "Available range: 0 .. " + toString(mSize) + ". " \
- "Wanted range: " + toString(offset) + " .. " + toString(offset + size) + ".");
- }
- #endif
- memcpy(mData + offset, data, size);
- mDirty = true;
- }
- void GpuParamBlock::read(UINT32 offset, void* data, UINT32 size)
- {
- #if BS_DEBUG_MODE
- if(offset < 0 || (offset + size) > mSize)
- {
- BS_EXCEPT(InvalidParametersException, "Wanted range is out of buffer bounds. " \
- "Available range: 0 .. " + toString(mSize) + ". " \
- "Wanted range: " + toString(offset) + " .. " + toString(offset + size) + ".");
- }
- #endif
- memcpy(data, mData + offset, size);
- }
- void GpuParamBlock::zeroOut(UINT32 offset, UINT32 size)
- {
- #if BS_DEBUG_MODE
- if(offset < 0 || (offset + size) > mSize)
- {
- BS_EXCEPT(InvalidParametersException, "Wanted range is out of buffer bounds. " \
- "Available range: 0 .. " + toString(mSize) + ". " \
- "Wanted range: " + toString(offset) + " .. " + toString(offset + size) + ".");
- }
- #endif
- memset(mData + offset, 0, size);
- mDirty = true;
- }
- void GpuParamBlock::uploadToBuffer(const GpuParamBlockBufferPtr& buffer)
- {
- buffer->writeData(mData);
- mDirty = false;
- }
- }
|