Brad G. Kyer - 2007-03-21

would it make it simpler and less error prone for situations to provide a "BinderGuard" class
i.e.

class FramebufferObject
{
public:
/// blah....

public:
    struct BinderGuard {
        BinderGuard(FramebufferObject &aRef)
            ref(aRef)
        {
            ref._GuardedBind();
        };

        ~BinderGuard() {
            ref._GuardedUnbind();
        };
    private:
        FramebufferObject& ref; 
    };

/// blah...
};

And anywhere the pair was used one could simply do:

void DerivedFBO::some_method(blah) {
    FramebufferObject::BinderGuard myGuard(*this);

    /// blah...

};

This way regardless of any bad action taken within a method it will properly unbind.