glFrameAllocatorLockableHelper.h
Engine/source/gfx/gl/util/glFrameAllocatorLockableHelper.h
Classes:
class
Helper class for simulate lock/unlock on gfx buffers using FrameAllocator.
Detailed Description
1 2#ifndef GL_FRAMEALLOCATOR_LOCKABLE_HELPER_H 3#define GL_FRAMEALLOCATOR_LOCKABLE_HELPER_H 4 5#include "core/frameAllocator.h" 6 7/// Helper class for simulate lock/unlock on gfx buffers using FrameAllocator 8class FrameAllocatorLockableHelper 9{ 10public: 11 FrameAllocatorLockableHelper() 12 : mFrameAllocatorMark(0), 13 mFrameAllocatorPtr(NULL) 14#if TORQUE_DEBUG 15 , mFrameAllocatorMarkGuard(0) 16#endif 17 { 18 19 } 20 21 U8* lock(const U32 size) 22 { 23 AssertFatal(!mFrameAllocatorMark && !mFrameAllocatorPtr, ""); 24 mFrameAllocatorMark = FrameAllocator::getWaterMark(); 25 mFrameAllocatorPtr = (U8*)FrameAllocator::alloc( size ); 26#if TORQUE_DEBUG 27 mFrameAllocatorMarkGuard = FrameAllocator::getWaterMark(); 28#endif 29 30 return mFrameAllocatorPtr; 31 } 32 33 void unlock() 34 { 35#if TORQUE_DEBUG 36 AssertFatal(mFrameAllocatorMarkGuard == FrameAllocator::getWaterMark(), ""); 37#endif 38 FrameAllocator::setWaterMark(mFrameAllocatorMark); 39 mFrameAllocatorMark = 0; 40 mFrameAllocatorPtr = NULL; 41 } 42 43 U8* getlockedPtr() const { return mFrameAllocatorPtr; } 44 45protected: 46 U32 mFrameAllocatorMark; 47 U8 *mFrameAllocatorPtr; 48 49#if TORQUE_DEBUG 50 U32 mFrameAllocatorMarkGuard; 51#endif 52}; 53 54#endif //GL_FRAMEALLOCATOR_LOCKABLE_HELPER_H 55