Skip to content

Instantly share code, notes, and snippets.

@vinjn
Created August 16, 2012 04:19
Show Gist options
  • Save vinjn/3366792 to your computer and use it in GitHub Desktop.
Save vinjn/3366792 to your computer and use it in GitHub Desktop.
Direct3D Programming Tip #9: Use The Managed Resource Pool
//http://legalizeadulthood.wordpress.com/2009/10/12/direct3d-programming-tip-9-use-the-managed-resource-pool/
template <typename Index>
class index_lock
{
public:
// lock in constructor, unlock in destructor
index_lock(IDirect3DIndexBuffer9 *ib,
DWORD flags = 0,
UINT offset = 0,
UINT size = 0)
: m_ib(ib)
{
void *data = 0;
THR(m_ib->Lock(offset, size, &data, flags));
m_data = static_cast<Index *>(data);
}
~index_lock()
{
const HRESULT hr = m_ib->Unlock();
assert(SUCCEEDED(hr));
}
// type safe accessors to vertex data
const Index *data() const { return m_data; }
Index *data() { return m_data; }
private:
IDirect3DIndexBuffer9Ptr m_ib;
Index *m_data;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment