Added support for OpenGL mode black listing to provide better support

for extension checking and invalidation of OpenGL modes associated with
extensions.
This commit is contained in:
Robert Osfield
2006-02-22 14:31:13 +00:00
parent bd68d96106
commit 32b929a493
10 changed files with 110 additions and 11 deletions

View File

@@ -46,6 +46,8 @@ public:
return true;
}
virtual bool checkValididityOfAssociatedModes(osg::State&) const;
virtual bool isTextureAttribute() const { return true; }
virtual void apply(osg::State& state) const;

View File

@@ -201,6 +201,22 @@ class OSG_EXPORT State : public Referenced
void apply();
/** Set whether a particular OpenGL mode is valid in the current graphics context.
* Use to disable OpenGL modes that are not supported by current graphics drivers/context.*/
inline void setModeValidity(StateAttribute::GLMode mode,bool valid)
{
ModeStack& ms = _modeMap[mode];
ms.valid = valid;
}
/** Get whether a particular OpenGL mode is valid in the current graphics context.
* Use to disable OpenGL modes that are not supported by current graphics drivers/context.*/
inline bool getModeValidity(StateAttribute::GLMode mode)
{
ModeStack& ms = _modeMap[mode];
return ms.valid;
}
inline void setGlobalDefaultModeValue(StateAttribute::GLMode mode,bool enabled)
{
ModeStack& ms = _modeMap[mode];
@@ -775,11 +791,13 @@ class OSG_EXPORT State : public Referenced
ModeStack()
{
valid = true;
changed = false;
last_applied_value = false;
global_default_value = false;
}
bool valid;
bool changed;
bool last_applied_value;
bool global_default_value;
@@ -828,7 +846,7 @@ class OSG_EXPORT State : public Referenced
*/
inline bool applyMode(StateAttribute::GLMode mode,bool enabled,ModeStack& ms)
{
if (ms.last_applied_value != enabled)
if (ms.valid && ms.last_applied_value != enabled)
{
ms.last_applied_value = enabled;

View File

@@ -270,6 +270,14 @@ class OSG_EXPORT StateAttribute : public Object
return false;
}
/** Check the modes associated with this StateAttribute are supported by current OpenGL drivers,
* and if not set the associated mode in osg::State to be black listed/invalid.
* Return true if all associated modes are valid.*/
virtual bool checkValididityOfAssociatedModes(osg::State&) const
{
// default to no black listed GLMode's associated with use of the StateAttribute.
return true;
}
struct Callback : public virtual osg::Object
{

View File

@@ -410,6 +410,10 @@ class OSG_EXPORT StateSet : public Object
/** Run the event callbacks attached directly to this StateSet or to its children.*/
void runEventCallbacks(osg::NodeVisitor* nv);
/** Check the modes associated with this StateSet are supported by current OpenGL drivers,
* and if not set the associated mode in osg::State to be black listed/invalid.
* Return true if any modes have been black listed.*/
bool checkValididityOfAssociatedModes(State& state) const;
/** call compile on all StateAttributes contained within this StateSet.*/
void compileGLObjects(State& state) const;

View File

@@ -40,7 +40,8 @@ class OSGUTIL_EXPORT GLObjectsVisitor : public osg::NodeVisitor
RELEASE_DISPLAY_LISTS = 0x10,
RELEASE_STATE_ATTRIBUTES = 0x20,
SWITCH_ON_VERTEX_BUFFER_OBJECTS = 0x40,
SWITCH_OFF_VERTEX_BUFFER_OBJECTS = 0x80
SWITCH_OFF_VERTEX_BUFFER_OBJECTS = 0x80,
CHECK_BLACK_LISTED_MODES = 0xA0
};
typedef unsigned int Mode;
@@ -50,7 +51,15 @@ class OSGUTIL_EXPORT GLObjectsVisitor : public osg::NodeVisitor
* display list/texture objects etc. Default mode is to compile
* GL objects.
*/
GLObjectsVisitor(Mode mode=COMPILE_DISPLAY_LISTS|COMPILE_STATE_ATTRIBUTES);
GLObjectsVisitor(Mode mode=COMPILE_DISPLAY_LISTS|COMPILE_STATE_ATTRIBUTES|CHECK_BLACK_LISTED_MODES);
virtual void reset()
{
_drawablesAppliedSet.clear();
_stateSetAppliedSet.clear();
}
/** Set the operational mode of what operations to do on the scene graph.*/
void setMode(Mode mode) { _mode = mode; }
@@ -84,9 +93,13 @@ class OSGUTIL_EXPORT GLObjectsVisitor : public osg::NodeVisitor
protected:
Mode _mode;
typedef std::set<osg::Drawable*> DrawableAppliedSet;
typedef std::set<osg::StateSet*> StatesSetAppliedSet;
osg::ref_ptr<osg::State> _state;
Mode _mode;
osg::ref_ptr<osg::State> _state;
DrawableAppliedSet _drawablesAppliedSet;
StatesSetAppliedSet _stateSetAppliedSet;
};