Added ApplyTextureModeProxy for temporarily applying a texture mode

This commit is contained in:
Robert Osfield 2016-09-02 17:00:00 +01:00
parent 53cdacd926
commit aa0c8fdefd

View File

@ -352,6 +352,26 @@ class OSG_EXPORT State : public Referenced
bool _need_to_apply_value; bool _need_to_apply_value;
}; };
struct ApplyTextureModeProxy
{
inline ApplyTextureModeProxy(osg::State& state, unsigned int unit, GLenum mode, bool value):_state(state), _unit(unit), _mode(mode)
{
_previous_value = _state.getLastAppliedTextureModeValue(_unit, _mode);
_need_to_apply_value = (_previous_value!=value);
if (_need_to_apply_value) _state.applyTextureMode(_unit, _mode, value);
}
inline ~ApplyTextureModeProxy()
{
if (_need_to_apply_value) _state.applyTextureMode(_unit, _mode, _previous_value);
}
osg::State& _state;
unsigned int _unit;
GLenum _mode;
bool _previous_value;
bool _need_to_apply_value;
};
/** Apply an OpenGL mode if required. This is a wrapper around /** Apply an OpenGL mode if required. This is a wrapper around
* \c glEnable() and \c glDisable(), that just actually calls these * \c glEnable() and \c glDisable(), that just actually calls these
* functions if the \c enabled flag is different than the current * functions if the \c enabled flag is different than the current