RAII/lock_guard for Ogre's custom lock/unlock interfaces?
Posted: Thu Apr 19, 2018 8:42 am
Ogre has lock()/unlock() api for some resources. Is there a recommended way of wrapping these up into something similar to std::lock_guard<std::mutex> for ensuring that unlock is always called? (without using try-catch)
Maybe there is a variant of lock_guard already in the standard library or boost that supports custom lock/unlock functions? (similar to how smart pointers support custom delete operations)
E.g. one common scenario is to lock a texture buffer to write to from CPU:
Maybe there is a variant of lock_guard already in the standard library or boost that supports custom lock/unlock functions? (similar to how smart pointers support custom delete operations)
E.g. one common scenario is to lock a texture buffer to write to from CPU:
Code: Select all
Ogre::HardwarePixelBufferSharedPtr pixelBuffer = texture->getBuffer();
pixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD);
const Ogre::PixelBox& pixelBox = pixelBuffer->getCurrentLock();
// do some writing to pixelBox.data...
pixelBuffer->unlock();