RAII/lock_guard for Ogre's custom lock/unlock interfaces?

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
garbage_collector
Gnoblar
Posts: 4
Joined: Mon Apr 09, 2018 1:35 pm

RAII/lock_guard for Ogre's custom lock/unlock interfaces?

Post by garbage_collector »

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:

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();
Post Reply