| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- #include "CmGpuResourceData.h"
- #include "CmGpuResourceDataRTTI.h"
- #include "CmRenderSystem.h"
- #include "CmException.h"
- namespace CamelotFramework
- {
- GpuResourceData::GpuResourceData()
- :mData(nullptr), mLocked(false), mOwnsData(false)
- {
- }
- GpuResourceData::GpuResourceData(const GpuResourceData& copy)
- {
- mData = copy.mData;
- mLocked = copy.mLocked; // TODO - This should be shared by all copies pointing to the same data?
- mOwnsData = false;
- }
- GpuResourceData::~GpuResourceData()
- {
- freeInternalBuffer();
- }
- UINT8* GpuResourceData::getData() const
- {
- #if !CM_FORCE_SINGLETHREADED_RENDERING
- if(mLocked)
- {
- if(CM_THREAD_CURRENT_ID != RenderSystem::instance().getRenderThreadId())
- CM_EXCEPT(InternalErrorException, "You are not allowed to access buffer data from non-render thread when the buffer is locked.");
- }
- #endif
- return mData;
- }
- void GpuResourceData::allocateInternalBuffer()
- {
- allocateInternalBuffer(getInternalBufferSize());
- }
- void GpuResourceData::allocateInternalBuffer(UINT32 size)
- {
- #if !CM_FORCE_SINGLETHREADED_RENDERING
- if(mLocked)
- {
- if(CM_THREAD_CURRENT_ID != RenderSystem::instance().getRenderThreadId())
- CM_EXCEPT(InternalErrorException, "You are not allowed to access buffer data from non-render thread when the buffer is locked.");
- }
- #endif
- freeInternalBuffer();
- mData = CM_NEW_BYTES(size, ScratchAlloc);
- mOwnsData = true;
- }
- void GpuResourceData::freeInternalBuffer()
- {
- if(mData == nullptr || !mOwnsData)
- return;
- #if !CM_FORCE_SINGLETHREADED_RENDERING
- if(mLocked)
- {
- if(CM_THREAD_CURRENT_ID != RenderSystem::instance().getRenderThreadId())
- CM_EXCEPT(InternalErrorException, "You are not allowed to access buffer data from non-render thread when the buffer is locked.");
- }
- #endif
- CM_DELETE_BYTES(mData, ScratchAlloc);
- mData = nullptr;
- }
- void GpuResourceData::setExternalBuffer(UINT8* data)
- {
- #if !CM_FORCE_SINGLETHREADED_RENDERING
- if(mLocked)
- {
- if(CM_THREAD_CURRENT_ID != RenderSystem::instance().getRenderThreadId())
- CM_EXCEPT(InternalErrorException, "You are not allowed to access buffer data from non-render thread when the buffer is locked.");
- }
- #endif
- freeInternalBuffer();
- mData = data;
- mOwnsData = false;
- }
- void GpuResourceData::lock() const
- {
- mLocked = true;
- }
- void GpuResourceData::unlock() const
- {
- mLocked = false;
- }
- /************************************************************************/
- /* SERIALIZATION */
- /************************************************************************/
- RTTITypeBase* GpuResourceData::getRTTIStatic()
- {
- return GpuResourceDataRTTI::instance();
- }
- RTTITypeBase* GpuResourceData::getRTTI() const
- {
- return GpuResourceData::getRTTIStatic();
- }
- }
|