2006-07-18 23:21:48 +08:00
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2003-01-22 00:45:36 +08:00
*
2005-02-02 23:08:55 +08:00
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
2003-01-22 00:45:36 +08:00
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
2005-02-02 23:08:55 +08:00
*
2003-01-22 00:45:36 +08:00
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2005-02-02 23:08:55 +08:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2003-01-22 00:45:36 +08:00
* OpenSceneGraph Public License for more details.
*/
2001-10-04 23:12:57 +08:00
2001-01-11 00:32:10 +08:00
#ifndef OSG_STATE
#define OSG_STATE 1
#include <osg/Export>
2001-09-20 05:08:56 +08:00
#include <osg/StateSet>
#include <osg/Matrix>
2005-04-04 18:08:15 +08:00
#include <osg/Uniform>
2007-05-01 14:28:20 +08:00
#include <osg/BufferObject>
2010-02-19 05:18:49 +08:00
#include <osg/Observer>
2010-11-11 00:58:58 +08:00
#include <osg/Timer>
2001-09-20 05:08:56 +08:00
2010-06-25 01:15:27 +08:00
#include <osg/ShaderComposer>
2001-09-22 10:42:08 +08:00
#include <osg/FrameStamp>
2001-12-22 06:48:19 +08:00
#include <osg/DisplaySettings>
2002-06-03 23:39:41 +08:00
#include <osg/Polytope>
2003-06-24 23:40:09 +08:00
#include <osg/Viewport>
2009-10-17 00:26:27 +08:00
#include <osg/GLBeginEndAdapter>
2009-10-21 19:18:13 +08:00
#include <osg/ArrayDispatchers>
2011-02-03 20:42:23 +08:00
#include <osg/GraphicsCostEstimator>
2001-09-22 10:42:08 +08:00
2010-12-02 22:13:54 +08:00
#include <iosfwd>
2001-09-20 05:08:56 +08:00
#include <vector>
#include <map>
2005-05-04 05:46:47 +08:00
#include <set>
2005-04-04 18:08:15 +08:00
#include <string>
2001-01-11 00:32:10 +08:00
2002-08-16 04:27:33 +08:00
#ifndef GL_FOG_COORDINATE_ARRAY
#ifdef GL_FOG_COORDINATE_ARRAY_EXT
#define GL_FOG_COORDINATE_ARRAY GL_FOG_COORDINATE_ARRAY_EXT
#else
2009-09-23 02:45:24 +08:00
#define GL_FOG_COORDINATE_ARRAY 0x8457
2002-08-16 04:27:33 +08:00
#endif
#endif
#ifndef GL_SECONDARY_COLOR_ARRAY
2002-10-17 18:04:11 +08:00
#ifdef GL_SECONDARY_COLOR_ARRAY_EXT
2002-08-16 04:27:33 +08:00
#define GL_SECONDARY_COLOR_ARRAY GL_SECONDARY_COLOR_ARRAY_EXT
#else
2009-09-23 02:45:24 +08:00
#define GL_SECONDARY_COLOR_ARRAY 0x845E
2002-08-16 04:27:33 +08:00
#endif
#endif
2002-07-12 05:08:02 +08:00
2010-11-11 18:53:23 +08:00
#if !defined(GL_EXT_timer_query) && !defined(OSG_GL3_AVAILABLE)
#ifdef _WIN32
typedef __int64 GLint64EXT;
typedef unsigned __int64 GLuint64EXT;
#else
typedef long long int GLint64EXT;
typedef unsigned long long int GLuint64EXT;
#endif
#endif
2005-01-08 03:00:40 +08:00
namespace osg {
2005-02-02 23:08:55 +08:00
/** macro for use with osg::StateAttribute::apply methods for detecting and
2010-04-24 00:35:44 +08:00
* reporting OpenGL error messages.*/
2001-09-20 05:08:56 +08:00
#define OSG_GL_DEBUG(message) \
if (state.getFineGrainedErrorDetection()) \
{ \
GLenum errorNo = glGetError(); \
if (errorNo!=GL_NO_ERROR) \
{ \
osg::notify(WARN)<<"Warning: detected OpenGL error '"<<gluErrorString(errorNo)<<" "<<message<<endl; \
}\
}
2005-07-20 23:55:07 +08:00
2006-09-19 04:54:48 +08:00
// forward declare GraphicsContext, View and State
2005-07-20 23:55:07 +08:00
class GraphicsContext;
2009-10-21 22:09:12 +08:00
class VertexAttribAlias
{
public:
VertexAttribAlias():
_location(0) {}
VertexAttribAlias(const VertexAttribAlias& rhs):
_location(rhs._location),
_glName(rhs._glName),
_osgName(rhs._osgName),
_declaration(rhs._declaration) {}
VertexAttribAlias(GLuint location, const std::string glName, const std::string osgName, const std::string& declaration):
_location(location),
_glName(glName),
_osgName(osgName),
_declaration(declaration) {}
GLuint _location;
std::string _glName;
std::string _osgName;
std::string _declaration;
};
2006-06-08 20:09:51 +08:00
/** Encapsulates the current applied OpenGL modes, attributes and vertex arrays settings,
2010-04-24 00:35:44 +08:00
* implements lazy state updating and provides accessors for querying the current state.
* The venerable Red Book says that "OpenGL is a state machine", and this class
* represents the OpenGL state in OSG. Furthermore, \c State also has other
* important features:
* - It works as a stack of states (see \c pushStateSet() and
* \c popStateSet()). Manipulating this stack of OpenGL states manually is
* seldom needed, since OSG does this in the most common situations.
* - It implements lazy state updating. This means that, if one requests a
* state change and that particular state is already in the requested state,
* no OpenGL call will be made. This ensures that the OpenGL pipeline is not
* stalled by unnecessary state changes.
* - It allows to query the current OpenGL state without calls to \c glGet*(),
* which typically stall the graphics pipeline (see, for instance,
* \c captureCurrentState() and \c getModelViewMatrix()).
*/
2009-01-26 23:16:24 +08:00
class OSG_EXPORT State : public Referenced, public Observer
2001-01-11 00:32:10 +08:00
{
public :
2005-02-02 23:08:55 +08:00
2001-09-20 05:08:56 +08:00
State();
2005-07-20 23:55:07 +08:00
2009-09-23 02:45:24 +08:00
/** Set the graphics context associated with that owns this State object.*/
2005-07-20 23:55:07 +08:00
void setGraphicsContext(GraphicsContext* context) { _graphicsContext = context; }
2009-09-23 02:45:24 +08:00
/** Get the graphics context associated with that owns this State object.*/
2005-07-20 23:55:07 +08:00
GraphicsContext* getGraphicsContext() { return _graphicsContext; }
2009-09-23 02:45:24 +08:00
/** Get the const graphics context associated with that owns this State object.*/
2005-07-20 23:55:07 +08:00
const GraphicsContext* getGraphicsContext() const { return _graphicsContext; }
2009-09-23 02:45:24 +08:00
2005-07-20 23:55:07 +08:00
/** Set the current OpenGL context uniqueID.
Note, it is the application developers responsibility to
set up unique ID for each OpenGL context. This value is
then used by osg::StateAttribute's and osg::Drawable's to
help manage OpenGL display list and texture binds appropriate
for each context, the contextID simply acts as an index in local
arrays that they maintain for the purpose.
Typical settings for contextID are 0,1,2,3... up to the maximum
number of graphics contexts you have set up.
By default contextID is 0.*/
inline void setContextID(unsigned int contextID) { _contextID=contextID; }
/** Get the current OpenGL context unique ID.*/
inline unsigned int getContextID() const { return _contextID; }
2001-09-20 05:08:56 +08:00
2010-06-25 01:15:27 +08:00
2010-07-06 00:32:58 +08:00
/* Set whether shader composition is enabled.*/
void setShaderCompositionEnabled(bool flag) { _shaderCompositionEnabled = flag; }
/* Get whether shader composition is enabled.*/
bool getShaderCompositionEnabled() const { return _shaderCompositionEnabled; }
2010-06-25 01:15:27 +08:00
/** Set the ShaderComposor object that implements shader composition.*/
void setShaderComposer(ShaderComposer* sc) { _shaderComposer = sc; }
/** Get the ShaderComposor object.*/
ShaderComposer* getShaderComposer() { return _shaderComposer.get(); }
/** Get the const ShaderComposor object.*/
const ShaderComposer* getShaderComposer() const { return _shaderComposer.get(); }
2010-07-06 18:55:54 +08:00
/** Get the unform list in which to inject any uniforms that StateAttribute::apply(State&) methods provide.*/
StateSet::UniformList& getCurrentShaderCompositionUniformList() { return _currentShaderCompositionUniformList; }
/** Convinience method for StateAttribute:::apply(State&) methods to pass on their uniforms to osg::State so it can apply them at the appropriate point.*/
void applyShaderCompositionUniform(const osg::Uniform* uniform, StateAttribute::OverrideValue value=StateAttribute::ON)
{
StateSet::RefUniformPair& up = _currentShaderCompositionUniformList[uniform->getName()];
up.first = const_cast<Uniform*>(uniform);
up.second = value;
}
2010-06-25 01:15:27 +08:00
2004-09-14 01:19:05 +08:00
/** Push stateset onto state stack.*/
2001-09-20 05:08:56 +08:00
void pushStateSet(const StateSet* dstate);
2004-09-14 01:19:05 +08:00
/** Pop stateset off state stack.*/
2001-09-20 05:08:56 +08:00
void popStateSet();
2009-09-23 02:45:24 +08:00
2004-09-03 03:10:33 +08:00
/** pop all statesets off state stack, ensuring it is empty ready for the next frame.
2010-04-24 00:35:44 +08:00
* Note, to return OpenGL to default state, one should do any state.popAllStatSets(); state.apply().*/
2003-09-11 05:22:47 +08:00
void popAllStateSets();
2007-04-16 20:18:56 +08:00
/** Insert stateset onto state stack.*/
void insertStateSet(unsigned int pos,const StateSet* dstate);
/** Pop stateset off state stack.*/
void removeStateSet(unsigned int pos);
2009-09-23 02:45:24 +08:00
2007-01-27 19:13:01 +08:00
/** Get the number of StateSet's on the StateSet stack.*/
2009-01-30 18:55:28 +08:00
unsigned int getStateSetStackSize() { return static_cast<unsigned int>(_stateStateStack.size()); }
2009-09-23 02:45:24 +08:00
2007-01-27 19:13:01 +08:00
/** Pop StateSet's for the StateSet stack till its size equals the specified size.*/
void popStateSetStackToSize(unsigned int size) { while (_stateStateStack.size()>size) popStateSet(); }
typedef std::vector<const StateSet*> StateSetStack;
/** Get the StateSet stack.*/
StateSetStack& getStateSetStack() { return _stateStateStack; }
2009-09-23 02:45:24 +08:00
2003-09-11 05:22:47 +08:00
2004-09-14 01:19:05 +08:00
/** Copy the modes and attributes which capture the current state.*/
2001-10-23 06:02:47 +08:00
void captureCurrentState(StateSet& stateset) const;
2001-09-20 05:08:56 +08:00
/** reset the state object to an empty stack.*/
void reset();
2005-02-02 23:08:55 +08:00
2009-10-17 00:26:27 +08:00
2003-06-24 23:40:09 +08:00
inline const Viewport* getCurrentViewport() const
{
return static_cast<const Viewport*>(getLastAppliedAttribute(osg::StateAttribute::VIEWPORT));
}
2005-02-02 23:08:55 +08:00
2001-09-20 05:08:56 +08:00
2003-08-25 21:31:31 +08:00
void setInitialViewMatrix(const osg::RefMatrix* matrix);
2003-07-23 05:03:59 +08:00
inline const osg::Matrix& getInitialViewMatrix() const { return *_initialViewMatrix; }
2003-08-25 21:06:15 +08:00
inline const osg::Matrix& getInitialInverseViewMatrix() const { return _initialInverseViewMatrix; }
2003-07-23 05:03:59 +08:00
2009-10-17 00:26:27 +08:00
void applyProjectionMatrix(const osg::RefMatrix* matrix);
2009-10-09 21:39:11 +08:00
2009-10-17 00:26:27 +08:00
inline const osg::Matrix& getProjectionMatrix() const { return *_projection; }
2009-10-09 21:39:11 +08:00
2009-10-17 00:26:27 +08:00
void applyModelViewMatrix(const osg::RefMatrix* matrix);
2010-06-01 21:33:58 +08:00
void applyModelViewMatrix(const osg::Matrix&);
2002-03-30 01:26:40 +08:00
2009-10-17 00:26:27 +08:00
const osg::Matrix& getModelViewMatrix() const { return *_modelView; }
2002-03-30 01:26:40 +08:00
2009-10-11 14:05:19 +08:00
void setUseModelViewAndProjectionUniforms(bool flag) { _useModelViewAndProjectionUniforms = flag; }
bool getUseModelViewAndProjectionUniforms() const { return _useModelViewAndProjectionUniforms; }
2009-10-17 00:26:27 +08:00
void updateModelViewAndProjectionMatrixUniforms();
2009-10-09 21:39:11 +08:00
void applyModelViewAndProjectionUniformsIfRequired();
osg::Uniform* getModelViewMatrixUniform() { return _modelViewMatrixUniform.get(); }
osg::Uniform* getProjectionMatrixUniform() { return _projectionMatrixUniform.get(); }
osg::Uniform* getModelViewProjectionMatrixUniform() { return _modelViewProjectionMatrixUniform.get(); }
2009-10-17 00:26:27 +08:00
osg::Uniform* getNormalMatrixUniform() { return _normalMatrixUniform.get(); }
2009-10-09 21:39:11 +08:00
2002-03-30 01:26:40 +08:00
2002-06-03 23:39:41 +08:00
Polytope getViewFrustum() const;
2001-09-20 05:08:56 +08:00
2009-10-21 22:09:12 +08:00
2009-10-17 00:26:27 +08:00
void setUseVertexAttributeAliasing(bool flag) { _useVertexAttributeAliasing = flag; }
bool getUseVertexAttributeAliasing() const { return _useVertexAttributeAliasing ; }
2009-10-21 22:09:12 +08:00
typedef std::vector<VertexAttribAlias> VertexAttribAliasList;
const VertexAttribAlias& getVertexAlias() { return _vertexAlias; }
const VertexAttribAlias& getNormalAlias() { return _normalAlias; }
const VertexAttribAlias& getColorAlias() { return _colorAlias; }
const VertexAttribAlias& getSecondaryColorAlias() { return _secondaryColorAlias; }
const VertexAttribAlias& getFogCoordAlias() { return _fogCoordAlias; }
const VertexAttribAliasList& getTexCoordAliasList() { return _texCoordAliasList; }
2009-10-17 00:26:27 +08:00
const Program::AttribBindingList& getAttributeBindingList() { return _attributeBindingList; }
bool convertVertexShaderSourceToOsgBuiltIns(std::string& source) const;
2002-05-21 16:59:26 +08:00
/** Apply stateset.*/
2001-09-20 05:08:56 +08:00
void apply(const StateSet* dstate);
2005-02-02 23:08:55 +08:00
/** Updates the OpenGL state so that it matches the \c StateSet at the
2010-04-24 00:35:44 +08:00
* top of the stack of <tt>StateSet</tt>s maintained internally by a
* \c State.
*/
2001-09-20 05:08:56 +08:00
void apply();
2002-05-21 16:59:26 +08:00
2010-07-06 00:32:58 +08:00
/** Apply any shader composed state.*/
void applyShaderComposition();
2002-05-21 16:59:26 +08:00
2006-02-22 22:31:13 +08:00
/** Set whether a particular OpenGL mode is valid in the current graphics context.
2010-04-24 00:35:44 +08:00
* Use to disable OpenGL modes that are not supported by current graphics drivers/context.*/
2006-02-22 22:31:13 +08:00
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.
2010-04-24 00:35:44 +08:00
* Use to disable OpenGL modes that are not supported by current graphics drivers/context.*/
2006-02-22 22:31:13 +08:00
inline bool getModeValidity(StateAttribute::GLMode mode)
{
ModeStack& ms = _modeMap[mode];
return ms.valid;
}
2004-08-07 17:42:19 +08:00
inline void setGlobalDefaultModeValue(StateAttribute::GLMode mode,bool enabled)
{
ModeStack& ms = _modeMap[mode];
ms.global_default_value = enabled;
}
inline bool getGlobalDefaultModeValue(StateAttribute::GLMode mode)
{
return _modeMap[mode].global_default_value;
}
2005-02-02 23:08:55 +08:00
/** Apply an OpenGL mode if required. This is a wrapper around
2010-04-24 00:35:44 +08:00
* \c glEnable() and \c glDisable(), that just actually calls these
* functions if the \c enabled flag is different than the current
* state.
* @return \c true if the state was actually changed. \c false
* otherwise. Notice that a \c false return does not indicate
* an error, it just means that the mode was already set to the
* same value as the \c enabled parameter.
2005-02-02 23:08:55 +08:00
*/
2002-09-02 20:31:35 +08:00
inline bool applyMode(StateAttribute::GLMode mode,bool enabled)
2002-05-21 16:59:26 +08:00
{
2002-05-22 18:04:28 +08:00
ModeStack& ms = _modeMap[mode];
2005-02-02 23:08:55 +08:00
ms.changed = true;
2002-05-22 18:04:28 +08:00
return applyMode(mode,enabled,ms);
2002-05-21 16:59:26 +08:00
}
2004-08-07 17:42:19 +08:00
inline void setGlobalDefaultTextureModeValue(unsigned int unit, StateAttribute::GLMode mode,bool enabled)
{
ModeMap& modeMap = getOrCreateTextureModeMap(unit);
ModeStack& ms = modeMap[mode];
ms.global_default_value = enabled;
}
inline bool getGlobalDefaultTextureModeValue(unsigned int unit, StateAttribute::GLMode mode)
{
ModeMap& modeMap = getOrCreateTextureModeMap(unit);
ModeStack& ms = modeMap[mode];
return ms.global_default_value;
}
2002-09-02 20:31:35 +08:00
inline bool applyTextureMode(unsigned int unit, StateAttribute::GLMode mode,bool enabled)
2002-07-07 22:40:41 +08:00
{
2010-01-08 00:49:12 +08:00
ModeMap& modeMap = getOrCreateTextureModeMap(unit);
ModeStack& ms = modeMap[mode];
ms.changed = true;
return applyModeOnTexUnit(unit,mode,enabled,ms);
2002-07-07 22:40:41 +08:00
}
2002-05-21 16:59:26 +08:00
2004-08-07 17:42:19 +08:00
inline void setGlobalDefaultAttribute(const StateAttribute* attribute)
{
2004-10-13 19:15:50 +08:00
AttributeStack& as = _attributeMap[attribute->getTypeMemberPair()];
2004-08-07 17:42:19 +08:00
as.global_default_attribute = attribute;
}
2004-10-13 19:15:50 +08:00
inline const StateAttribute* getGlobalDefaultAttribute(StateAttribute::Type type, unsigned int member=0)
2004-08-07 17:42:19 +08:00
{
2004-10-13 19:15:50 +08:00
AttributeStack& as = _attributeMap[StateAttribute::TypeMemberPair(type,member)];
2004-08-07 17:42:19 +08:00
return as.global_default_attribute.get();
}
2002-05-21 16:59:26 +08:00
/** Apply an attribute if required. */
2002-09-02 20:31:35 +08:00
inline bool applyAttribute(const StateAttribute* attribute)
2002-05-21 16:59:26 +08:00
{
2004-10-13 19:15:50 +08:00
AttributeStack& as = _attributeMap[attribute->getTypeMemberPair()];
2002-05-22 18:04:28 +08:00
as.changed = true;
return applyAttribute(attribute,as);
2002-05-21 16:59:26 +08:00
}
2004-08-07 17:42:19 +08:00
inline void setGlobalDefaultTextureAttribute(unsigned int unit, const StateAttribute* attribute)
{
AttributeMap& attributeMap = getOrCreateTextureAttributeMap(unit);
2004-10-13 19:15:50 +08:00
AttributeStack& as = attributeMap[attribute->getTypeMemberPair()];
2004-08-07 17:42:19 +08:00
as.global_default_attribute = attribute;
}
2004-10-13 19:15:50 +08:00
inline const StateAttribute* getGlobalDefaultTextureAttribute(unsigned int unit, StateAttribute::Type type, unsigned int member = 0)
2004-08-07 17:42:19 +08:00
{
AttributeMap& attributeMap = getOrCreateTextureAttributeMap(unit);
2004-10-13 19:15:50 +08:00
AttributeStack& as = attributeMap[StateAttribute::TypeMemberPair(type,member)];
2004-08-07 17:42:19 +08:00
return as.global_default_attribute.get();
}
2002-09-02 20:31:35 +08:00
inline bool applyTextureAttribute(unsigned int unit, const StateAttribute* attribute)
2002-07-07 22:40:41 +08:00
{
2010-01-08 00:49:12 +08:00
AttributeMap& attributeMap = getOrCreateTextureAttributeMap(unit);
AttributeStack& as = attributeMap[attribute->getTypeMemberPair()];
as.changed = true;
return applyAttributeOnTexUnit(unit,attribute,as);
2002-07-07 22:40:41 +08:00
}
2005-02-02 23:08:55 +08:00
2002-05-21 16:59:26 +08:00
/** Mode has been set externally, update state to reflect this setting.*/
2002-09-02 20:31:35 +08:00
void haveAppliedMode(StateAttribute::GLMode mode,StateAttribute::GLModeValue value);
2005-02-02 23:08:55 +08:00
2002-05-21 16:59:26 +08:00
/** Mode has been set externally, therefore dirty the associated mode in osg::State
2010-04-24 00:35:44 +08:00
* so it is applied on next call to osg::State::apply(..)*/
2002-09-02 20:31:35 +08:00
void haveAppliedMode(StateAttribute::GLMode mode);
2002-03-21 20:00:10 +08:00
2002-05-21 16:59:26 +08:00
/** Attribute has been applied externally, update state to reflect this setting.*/
2002-03-21 20:36:05 +08:00
void haveAppliedAttribute(const StateAttribute* attribute);
2002-03-21 20:00:10 +08:00
2010-04-24 00:35:44 +08:00
/** Attribute has been applied externally,
* and therefore this attribute type has been dirtied
* and will need to be re-applied on next osg::State.apply(..).
* note, if you have an osg::StateAttribute which you have applied externally
* then use the have_applied(attribute) method as this will cause the osg::State to
* track the current state more accurately and enable lazy state updating such
* that only changed state will be applied.*/
2004-10-13 19:15:50 +08:00
void haveAppliedAttribute(StateAttribute::Type type, unsigned int member=0);
2001-09-20 05:08:56 +08:00
2009-09-23 02:45:24 +08:00
/** Get whether the current specified mode is enabled (true) or disabled (false).*/
2002-09-02 20:31:35 +08:00
bool getLastAppliedMode(StateAttribute::GLMode mode) const;
2005-02-02 23:08:55 +08:00
2009-09-23 02:45:24 +08:00
/** Get the current specified attribute, return NULL if one has not yet been applied.*/
2004-10-13 19:15:50 +08:00
const StateAttribute* getLastAppliedAttribute(StateAttribute::Type type, unsigned int member=0) const;
2005-02-02 23:08:55 +08:00
2002-07-07 22:40:41 +08:00
/** texture Mode has been set externally, update state to reflect this setting.*/
2002-09-02 20:31:35 +08:00
void haveAppliedTextureMode(unsigned int unit, StateAttribute::GLMode mode,StateAttribute::GLModeValue value);
2005-02-02 23:08:55 +08:00
2002-07-07 22:40:41 +08:00
/** texture Mode has been set externally, therefore dirty the associated mode in osg::State
2010-04-24 00:35:44 +08:00
* so it is applied on next call to osg::State::apply(..)*/
2002-09-02 20:31:35 +08:00
void haveAppliedTextureMode(unsigned int unit, StateAttribute::GLMode mode);
2002-07-07 22:40:41 +08:00
/** texture Attribute has been applied externally, update state to reflect this setting.*/
void haveAppliedTextureAttribute(unsigned int unit, const StateAttribute* attribute);
2005-02-02 23:08:55 +08:00
/** texture Attribute has been applied externally,
2010-04-24 00:35:44 +08:00
* and therefore this attribute type has been dirtied
* and will need to be re-applied on next osg::State.apply(..).
* note, if you have an osg::StateAttribute which you have applied externally
* then use the have_applied(attribute) method as this will the osg::State to
* track the current state more accurately and enable lazy state updating such
* that only changed state will be applied.*/
2004-10-13 19:15:50 +08:00
void haveAppliedTextureAttribute(unsigned int unit, StateAttribute::Type type, unsigned int member=0);
2002-07-07 22:40:41 +08:00
2005-02-02 23:08:55 +08:00
/** Get whether the current specified texture mode is enabled (true) or disabled (false).*/
2002-09-02 20:31:35 +08:00
bool getLastAppliedTextureMode(unsigned int unit, StateAttribute::GLMode mode) const;
2005-02-02 23:08:55 +08:00
/** Get the current specified texture attribute, return NULL if one has not yet been applied.*/
2004-10-13 19:15:50 +08:00
const StateAttribute* getLastAppliedTextureAttribute(unsigned int unit, StateAttribute::Type type, unsigned int member=0) const;
2002-07-07 22:40:41 +08:00
2003-01-19 23:28:08 +08:00
/** Dirty the modes previously applied in osg::State.*/
void dirtyAllModes();
/** Dirty the modes attributes previously applied in osg::State.*/
void dirtyAllAttributes();
2004-09-14 01:19:05 +08:00
/** disable the vertex, normal, color, tex coords, secondary color, fog coord and index arrays.*/
2002-09-13 21:50:58 +08:00
void disableAllVertexArrays();
2004-09-03 03:10:33 +08:00
/** dirty the vertex, normal, color, tex coords, secondary color, fog coord and index arrays.*/
2002-09-13 21:50:58 +08:00
void dirtyAllVertexArrays();
2002-07-07 22:40:41 +08:00
2002-11-19 18:56:59 +08:00
2009-10-02 04:19:42 +08:00
void setCurrentVertexBufferObject(osg::GLBufferObject* vbo) { _currentVBO = vbo; }
const GLBufferObject* getCurrentVertexBufferObject() { return _currentVBO; }
inline void bindVertexBufferObject(osg::GLBufferObject* vbo)
2007-05-01 14:28:20 +08:00
{
if (vbo == _currentVBO) return;
2009-10-02 04:19:42 +08:00
if (vbo->isDirty()) vbo->compileBuffer();
2009-10-03 17:25:23 +08:00
else vbo->bindBuffer();
2007-05-01 14:28:20 +08:00
_currentVBO = vbo;
}
inline void unbindVertexBufferObject()
{
if (!_currentVBO) return;
_glBindBuffer(GL_ARRAY_BUFFER_ARB,0);
_currentVBO = 0;
}
2009-10-02 04:19:42 +08:00
void setCurrentElementBufferObject(osg::GLBufferObject* ebo) { _currentEBO = ebo; }
const GLBufferObject* getCurrentElementBufferObject() { return _currentEBO; }
2007-05-01 14:28:20 +08:00
2009-10-02 04:19:42 +08:00
inline void bindElementBufferObject(osg::GLBufferObject* ebo)
2007-05-01 14:28:20 +08:00
{
if (ebo == _currentEBO) return;
2009-10-02 04:19:42 +08:00
if (ebo->isDirty()) ebo->compileBuffer();
2009-10-03 17:25:23 +08:00
else ebo->bindBuffer();
2007-05-01 14:28:20 +08:00
_currentEBO = ebo;
}
inline void unbindElementBufferObject()
{
if (!_currentEBO) return;
_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB,0);
_currentEBO = 0;
}
2009-10-02 04:19:42 +08:00
void setCurrentPixelBufferObject(osg::GLBufferObject* pbo) { _currentPBO = pbo; }
const GLBufferObject* getCurrentPixelBufferObject() { return _currentPBO; }
2007-05-01 14:28:20 +08:00
2009-10-02 04:19:42 +08:00
inline void bindPixelBufferObject(osg::GLBufferObject* pbo)
2007-05-01 14:28:20 +08:00
{
if (pbo == _currentPBO) return;
2009-10-02 04:19:42 +08:00
if (pbo->isDirty()) pbo->compileBuffer();
2009-10-03 17:25:23 +08:00
else pbo->bindBuffer();
2007-05-01 14:28:20 +08:00
_currentPBO = pbo;
}
inline void unbindPixelBufferObject()
{
if (!_currentPBO) return;
2009-09-23 02:45:24 +08:00
2007-05-01 14:28:20 +08:00
_glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB,0);
_currentPBO = 0;
}
2009-09-23 02:45:24 +08:00
2009-11-12 20:18:33 +08:00
typedef std::vector<GLushort> Indices;
Indices _quadIndices[6];
2009-11-18 20:50:03 +08:00
void drawQuads(GLint first, GLsizei count, GLsizei primCount=0);
2009-09-23 02:45:24 +08:00
2009-01-06 22:55:49 +08:00
inline void glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
{
if (primcount>=1 && _glDrawArraysInstanced!=0) _glDrawArraysInstanced(mode, first, count, primcount);
else glDrawArrays(mode, first, count);
}
2009-09-23 02:45:24 +08:00
2009-01-06 22:55:49 +08:00
inline void glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount )
{
if (primcount>=1 && _glDrawElementsInstanced!=0) _glDrawElementsInstanced(mode, count, type, indices, primcount);
else glDrawElements(mode, count, type, indices);
}
2007-05-01 14:28:20 +08:00
2009-10-17 00:26:27 +08:00
inline void Vertex(float x, float y, float z, float w=1.0f)
{
2009-10-25 19:52:01 +08:00
#if defined(OSG_GL_VERTEX_FUNCS_AVAILABLE) && !defined(OSG_GLES1_AVAILABLE)
2009-10-17 00:26:27 +08:00
if (_useVertexAttributeAliasing) _glVertexAttrib4f( _vertexAlias._location, x,y,z,w);
else glVertex4f(x,y,z,w);
2009-10-25 19:52:01 +08:00
#else
_glVertexAttrib4f( _vertexAlias._location, x,y,z,w);
#endif
2009-10-17 00:26:27 +08:00
}
inline void Color(float r, float g, float b, float a=1.0f)
{
2009-10-25 19:52:01 +08:00
#ifdef OSG_GL_VERTEX_FUNCS_AVAILABLE
2009-10-17 00:26:27 +08:00
if (_useVertexAttributeAliasing) _glVertexAttrib4f( _colorAlias._location, r,g,b,a);
else glColor4f(r,g,b,a);
2009-10-25 19:52:01 +08:00
#else
_glVertexAttrib4f( _colorAlias._location, r,g,b,a);
#endif
2009-10-17 00:26:27 +08:00
}
void Normal(float x, float y, float z)
{
2009-10-25 19:52:01 +08:00
#ifdef OSG_GL_VERTEX_FUNCS_AVAILABLE
2009-10-17 00:26:27 +08:00
if (_useVertexAttributeAliasing) _glVertexAttrib4f( _normalAlias._location, x,y,z,0.0);
else glNormal3f(x,y,z);
2009-10-25 19:52:01 +08:00
#else
_glVertexAttrib4f( _normalAlias._location, x,y,z,0.0);
#endif
2009-10-17 00:26:27 +08:00
}
2009-10-21 03:34:24 +08:00
void TexCoord(float x, float y=0.0f, float z=0.0f, float w=1.0f)
2009-10-17 00:26:27 +08:00
{
2009-10-25 19:52:01 +08:00
#if !defined(OSG_GLES1_AVAILABLE)
#ifdef OSG_GL_VERTEX_FUNCS_AVAILABLE
if (_useVertexAttributeAliasing) _glVertexAttrib4f( _texCoordAliasList[0]._location, x,y,z,w);
else glTexCoord4f(x,y,z,w);
#else
_glVertexAttrib4f( _texCoordAliasList[0]._location, x,y,z,w);
#endif
#endif
2009-10-17 00:26:27 +08:00
}
2009-10-21 03:34:24 +08:00
void MultiTexCoord(unsigned int unit, float x, float y=0.0f, float z=0.0f, float w=1.0f)
2009-10-17 00:26:27 +08:00
{
2009-10-25 19:52:01 +08:00
#if !defined(OSG_GLES1_AVAILABLE)
#ifdef OSG_GL_VERTEX_FUNCS_AVAILABLE
if (_useVertexAttributeAliasing) _glVertexAttrib4f( _texCoordAliasList[unit]._location, x,y,z,w);
else _glMultiTexCoord4f(GL_TEXTURE0+unit,x,y,z,w);
#else
_glVertexAttrib4f( _texCoordAliasList[unit]._location, x,y,z,w);
#endif
#endif
2009-10-17 00:26:27 +08:00
}
void VerteAttrib(unsigned int location, float x, float y=0.0f, float z=0.0f, float w=0.0f)
{
_glVertexAttrib4f( location, x,y,z,w);
}
/** Mark all the vertex attributes as being disabled but leave the disabling till a later call to applyDisablingOfVertexAttributes.*/
void lazyDisablingOfVertexAttributes();
/** Disable all the vertex attributes that have been marked as to be disabled.*/
void applyDisablingOfVertexAttributes();
2009-10-25 19:52:01 +08:00
/** Wrapper around glInterleavedArrays(..).
* also resets the internal array points and modes within osg::State to keep the other
* vertex array operations consistent. */
void setInterleavedArrays( GLenum format, GLsizei stride, const GLvoid* pointer);
2009-10-17 00:26:27 +08:00
2007-05-01 14:28:20 +08:00
/** Set the vertex pointer using an osg::Array, and manage any VBO that are required.*/
inline void setVertexPointer(const Array* array)
{
if (array)
{
2009-10-02 04:19:42 +08:00
GLBufferObject* vbo = array->getOrCreateGLBufferObject(_contextID);
2007-05-01 14:28:20 +08:00
if (vbo)
2009-09-23 02:45:24 +08:00
{
2007-05-01 14:28:20 +08:00
bindVertexBufferObject(vbo);
2009-10-02 04:19:42 +08:00
setVertexPointer(array->getDataSize(),array->getDataType(),0,(const GLvoid *)(vbo->getOffset(array->getBufferIndex())));
2007-05-01 14:28:20 +08:00
}
else
{
unbindVertexBufferObject();
setVertexPointer(array->getDataSize(),array->getDataType(),0,array->getDataPointer());
}
}
}
2002-11-19 18:56:59 +08:00
2002-07-07 22:40:41 +08:00
/** wrapper around glEnableClientState(GL_VERTEX_ARRAY);glVertexPointer(..);
2010-04-24 00:35:44 +08:00
* note, only updates values that change.*/
2002-07-07 22:40:41 +08:00
inline void setVertexPointer( GLint size, GLenum type,
2010-04-24 00:35:44 +08:00
GLsizei stride, const GLvoid *ptr )
2002-07-07 22:40:41 +08:00
{
2009-10-25 19:52:01 +08:00
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
2009-10-17 00:26:27 +08:00
if (_useVertexAttributeAliasing)
2002-07-07 22:40:41 +08:00
{
2009-10-17 00:26:27 +08:00
setVertexAttribPointer(_vertexAlias._location, size, type, GL_FALSE, stride, ptr);
2002-07-07 22:40:41 +08:00
}
2009-10-17 00:26:27 +08:00
else
2002-07-07 22:40:41 +08:00
{
2009-10-17 00:26:27 +08:00
if (!_vertexArray._enabled || _vertexArray._dirty)
{
_vertexArray._enabled = true;
glEnableClientState(GL_VERTEX_ARRAY);
}
//if (_vertexArray._pointer!=ptr || _vertexArray._dirty)
{
_vertexArray._pointer=ptr;
glVertexPointer( size, type, stride, ptr );
}
_vertexArray._lazy_disable = false;
_vertexArray._dirty = false;
2002-07-07 22:40:41 +08:00
}
2009-10-25 19:52:01 +08:00
#else
setVertexAttribPointer(_vertexAlias._location, size, type, GL_FALSE, stride, ptr);
#endif
2002-07-07 22:40:41 +08:00
}
2005-02-02 23:08:55 +08:00
2004-09-03 03:10:33 +08:00
/** wrapper around glDisableClientState(GL_VERTEX_ARRAY).
2010-04-24 00:35:44 +08:00
* note, only updates values that change.*/
2002-07-07 22:40:41 +08:00
inline void disableVertexPointer()
{
2009-10-25 19:52:01 +08:00
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
2009-10-17 00:26:27 +08:00
if (_useVertexAttributeAliasing)
2002-07-07 22:40:41 +08:00
{
2009-10-17 00:26:27 +08:00
disableVertexAttribPointer(_vertexAlias._location);
}
else
{
if (_vertexArray._enabled || _vertexArray._dirty)
{
_vertexArray._lazy_disable = false;
_vertexArray._enabled = false;
_vertexArray._dirty = false;
glDisableClientState(GL_VERTEX_ARRAY);
}
2002-07-07 22:40:41 +08:00
}
2009-10-25 19:52:01 +08:00
#else
2010-04-24 00:35:44 +08:00
disableVertexAttribPointer(_vertexAlias._location);
2009-10-25 19:52:01 +08:00
#endif
2002-07-07 22:40:41 +08:00
}
2002-09-13 21:50:58 +08:00
inline void dirtyVertexPointer()
{
2009-10-25 19:52:01 +08:00
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
2009-10-17 00:26:27 +08:00
if (_useVertexAttributeAliasing)
{
dirtyVertexAttribPointer(_vertexAlias._location);
}
else
{
_vertexArray._pointer = 0;
_vertexArray._dirty = true;
}
2009-10-25 19:52:01 +08:00
#else
dirtyVertexAttribPointer(_vertexAlias._location);
#endif
2002-09-13 21:50:58 +08:00
}
2007-05-01 14:28:20 +08:00
/** Set the normal pointer using an osg::Array, and manage any VBO that are required.*/
inline void setNormalPointer(const Array* array)
{
if (array)
{
2009-10-02 04:19:42 +08:00
GLBufferObject* vbo = array->getOrCreateGLBufferObject(_contextID);
2007-05-01 14:28:20 +08:00
if (vbo)
2009-09-23 02:45:24 +08:00
{
2007-05-01 14:28:20 +08:00
bindVertexBufferObject(vbo);
2009-10-02 04:19:42 +08:00
setNormalPointer(array->getDataType(),0,(const GLvoid *)(vbo->getOffset(array->getBufferIndex())));
2007-05-01 14:28:20 +08:00
}
else
{
unbindVertexBufferObject();
setNormalPointer(array->getDataType(),0,array->getDataPointer());
}
}
}
2002-07-07 22:40:41 +08:00
/** wrapper around glEnableClientState(GL_NORMAL_ARRAY);glNormalPointer(..);
2010-04-24 00:35:44 +08:00
* note, only updates values that change.*/
2002-07-07 22:40:41 +08:00
inline void setNormalPointer( GLenum type, GLsizei stride,
2010-04-24 00:35:44 +08:00
const GLvoid *ptr )
2002-07-07 22:40:41 +08:00
{
2009-10-25 19:52:01 +08:00
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
2009-10-17 00:26:27 +08:00
if (_useVertexAttributeAliasing)
2002-07-07 22:40:41 +08:00
{
2009-10-17 00:26:27 +08:00
setVertexAttribPointer(_normalAlias._location, 3, type, GL_FALSE, stride, ptr);
2002-07-07 22:40:41 +08:00
}
2009-10-17 00:26:27 +08:00
else
2002-07-07 22:40:41 +08:00
{
2009-10-17 00:26:27 +08:00
if (!_normalArray._enabled || _normalArray._dirty)
{
_normalArray._enabled = true;
glEnableClientState(GL_NORMAL_ARRAY);
}
//if (_normalArray._pointer!=ptr || _normalArray._dirty)
{
_normalArray._pointer=ptr;
glNormalPointer( type, stride, ptr );
}
_normalArray._lazy_disable = false;
_normalArray._dirty = false;
2002-07-07 22:40:41 +08:00
}
2009-10-25 19:52:01 +08:00
#else
setVertexAttribPointer(_normalAlias._location, 3, type, GL_FALSE, stride, ptr);
#endif
2002-07-07 22:40:41 +08:00
}
/** wrapper around glDisableClientState(GL_NORMAL_ARRAY);
2010-04-24 00:35:44 +08:00
* note, only updates values that change.*/
2002-07-07 22:40:41 +08:00
inline void disableNormalPointer()
{
2009-10-25 19:52:01 +08:00
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
2009-10-17 00:26:27 +08:00
if (_useVertexAttributeAliasing)
2002-07-07 22:40:41 +08:00
{
2009-10-17 00:26:27 +08:00
disableVertexAttribPointer(_normalAlias._location);
}
else
{
if (_normalArray._enabled || _normalArray._dirty)
{
_normalArray._lazy_disable = false;
_normalArray._enabled = false;
_normalArray._dirty = false;
glDisableClientState(GL_NORMAL_ARRAY);
}
2002-07-07 22:40:41 +08:00
}
2009-10-25 19:52:01 +08:00
#else
disableVertexAttribPointer(_normalAlias._location);
#endif
2002-07-07 22:40:41 +08:00
}
2002-09-13 21:50:58 +08:00
inline void dirtyNormalPointer()
{
2009-10-25 19:52:01 +08:00
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
2009-10-17 00:26:27 +08:00
if (_useVertexAttributeAliasing)
{
dirtyVertexAttribPointer(_normalAlias._location);
}
else
{
_normalArray._pointer = 0;
_normalArray._dirty = true;
}
2009-10-25 19:52:01 +08:00
#else
dirtyVertexAttribPointer(_normalAlias._location);
#endif
2002-09-13 21:50:58 +08:00
}
2007-05-01 14:28:20 +08:00
/** Set the color pointer using an osg::Array, and manage any VBO that are required.*/
inline void setColorPointer(const Array* array)
{
if (array)
{
2009-10-02 04:19:42 +08:00
GLBufferObject* vbo = array->getOrCreateGLBufferObject(_contextID);
2007-05-01 14:28:20 +08:00
if (vbo)
2009-09-23 02:45:24 +08:00
{
2007-05-01 14:28:20 +08:00
bindVertexBufferObject(vbo);
2009-10-02 04:19:42 +08:00
setColorPointer(array->getDataSize(),array->getDataType(),0,(const GLvoid *)(vbo->getOffset(array->getBufferIndex())));
2007-05-01 14:28:20 +08:00
}
else
{
unbindVertexBufferObject();
setColorPointer(array->getDataSize(),array->getDataType(),0,array->getDataPointer());
}
}
}
2002-07-07 22:40:41 +08:00
/** wrapper around glEnableClientState(GL_COLOR_ARRAY);glColorPointer(..);
2010-04-24 00:35:44 +08:00
* note, only updates values that change.*/
2002-07-07 22:40:41 +08:00
inline void setColorPointer( GLint size, GLenum type,
2010-04-24 00:35:44 +08:00
GLsizei stride, const GLvoid *ptr )
2002-07-07 22:40:41 +08:00
{
2009-10-25 19:52:01 +08:00
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
2009-10-17 00:26:27 +08:00
if (_useVertexAttributeAliasing)
2002-07-07 22:40:41 +08:00
{
2009-10-17 00:26:27 +08:00
setVertexAttribPointer(_colorAlias._location, size, type, GL_FALSE, stride, ptr);
2002-07-07 22:40:41 +08:00
}
2009-10-17 00:26:27 +08:00
else
2002-07-07 22:40:41 +08:00
{
2009-10-17 00:26:27 +08:00
if (!_colorArray._enabled || _colorArray._dirty)
{
_colorArray._enabled = true;
glEnableClientState(GL_COLOR_ARRAY);
}
//if (_colorArray._pointer!=ptr || _colorArray._dirty)
{
_colorArray._pointer=ptr;
glColorPointer( size, type, stride, ptr );
}
_colorArray._lazy_disable = false;
_colorArray._dirty = false;
2002-07-07 22:40:41 +08:00
}
2009-10-25 19:52:01 +08:00
#else
setVertexAttribPointer(_colorAlias._location, size, type, GL_FALSE, stride, ptr);
#endif
2002-07-07 22:40:41 +08:00
}
/** wrapper around glDisableClientState(GL_COLOR_ARRAY);
2010-04-24 00:35:44 +08:00
* note, only updates values that change.*/
2002-07-07 22:40:41 +08:00
inline void disableColorPointer()
{
2009-10-25 19:52:01 +08:00
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
2009-10-17 00:26:27 +08:00
if (_useVertexAttributeAliasing)
2002-07-07 22:40:41 +08:00
{
2009-10-17 00:26:27 +08:00
disableVertexAttribPointer(_colorAlias._location);
}
else
{
if (_colorArray._enabled || _colorArray._dirty)
{
_colorArray._lazy_disable = false;
_colorArray._enabled = false;
_colorArray._dirty = false;
glDisableClientState(GL_COLOR_ARRAY);
}
2002-07-07 22:40:41 +08:00
}
2009-10-25 19:52:01 +08:00
#else
disableVertexAttribPointer(_colorAlias._location);
#endif
2002-07-07 22:40:41 +08:00
}
2002-09-13 21:50:58 +08:00
inline void dirtyColorPointer()
2005-02-02 23:08:55 +08:00
{
2009-10-25 19:52:01 +08:00
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
2009-10-17 00:26:27 +08:00
if (_useVertexAttributeAliasing)
{
dirtyVertexAttribPointer(_colorAlias._location);
}
else
{
_colorArray._pointer = 0;
_colorArray._dirty = true;
}
2009-10-25 19:52:01 +08:00
#else
dirtyVertexAttribPointer(_colorAlias._location);
#endif
2002-09-13 21:50:58 +08:00
}
2002-11-13 19:09:55 +08:00
2003-06-30 05:41:57 +08:00
inline bool isSecondaryColorSupported() const { return _isSecondaryColorSupportResolved?_isSecondaryColorSupported:computeSecondaryColorSupported(); }
2002-11-13 19:09:55 +08:00
2007-05-01 14:28:20 +08:00
/** Set the secondary color pointer using an osg::Array, and manage any VBO that are required.*/
inline void setSecondaryColorPointer(const Array* array)
{
if (array)
{
2009-10-02 04:19:42 +08:00
GLBufferObject* vbo = array->getOrCreateGLBufferObject(_contextID);
2007-05-01 14:28:20 +08:00
if (vbo)
2009-09-23 02:45:24 +08:00
{
2007-05-01 14:28:20 +08:00
bindVertexBufferObject(vbo);
2009-10-02 04:19:42 +08:00
setSecondaryColorPointer(array->getDataSize(),array->getDataType(),0,(const GLvoid *)(vbo->getOffset(array->getBufferIndex())));
2007-05-01 14:28:20 +08:00
}
else
{
unbindVertexBufferObject();
setSecondaryColorPointer(array->getDataSize(),array->getDataType(),0,array->getDataPointer());
}
}
}
2002-08-16 04:27:33 +08:00
/** wrapper around glEnableClientState(GL_SECONDARY_COLOR_ARRAY);glSecondayColorPointer(..);
2010-04-24 00:35:44 +08:00
* note, only updates values that change.*/
2002-08-16 04:27:33 +08:00
void setSecondaryColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *ptr );
/** wrapper around glDisableClientState(GL_SECONDARY_COLOR_ARRAY);
2010-04-24 00:35:44 +08:00
* note, only updates values that change.*/
2002-08-16 04:27:33 +08:00
inline void disableSecondaryColorPointer()
{
2009-10-25 19:52:01 +08:00
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
2009-10-17 00:26:27 +08:00
if (_useVertexAttributeAliasing)
2002-08-16 04:27:33 +08:00
{
2009-10-17 00:26:27 +08:00
disableVertexAttribPointer(_secondaryColorAlias._location);
}
else
{
if (_secondaryColorArray._enabled || _secondaryColorArray._dirty)
{
_secondaryColorArray._lazy_disable = false;
_secondaryColorArray._enabled = false;
_secondaryColorArray._dirty = false;
if (isSecondaryColorSupported()) glDisableClientState(GL_SECONDARY_COLOR_ARRAY);
}
2002-08-16 04:27:33 +08:00
}
2009-10-25 19:52:01 +08:00
#else
disableVertexAttribPointer(_secondaryColorAlias._location);
#endif
2002-08-16 04:27:33 +08:00
}
2002-09-13 21:50:58 +08:00
inline void dirtySecondaryColorPointer()
{
2009-10-25 19:52:01 +08:00
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
2009-10-17 00:26:27 +08:00
if (_useVertexAttributeAliasing)
{
dirtyVertexAttribPointer(_secondaryColorAlias._location);
}
else
{
_secondaryColorArray._pointer = 0;
_secondaryColorArray._dirty = true;
}
2009-10-25 19:52:01 +08:00
#else
dirtyVertexAttribPointer(_secondaryColorAlias._location);
#endif
2002-09-13 21:50:58 +08:00
}
2002-11-13 19:09:55 +08:00
inline bool isFogCoordSupported() const { return _isFogCoordSupportResolved?_isFogCoordSupported:computeFogCoordSupported(); }
2007-05-01 14:28:20 +08:00
/** Set the fog coord pointer using an osg::Array, and manage any VBO that are required.*/
inline void setFogCoordPointer(const Array* array)
{
if (array)
{
2009-10-02 04:19:42 +08:00
GLBufferObject* vbo = array->getOrCreateGLBufferObject(_contextID);
2007-05-01 14:28:20 +08:00
if (vbo)
2009-09-23 02:45:24 +08:00
{
2007-05-01 14:28:20 +08:00
bindVertexBufferObject(vbo);
2009-10-02 04:19:42 +08:00
setFogCoordPointer(array->getDataType(),0,(const GLvoid *)(vbo->getOffset(array->getBufferIndex())));
2007-05-01 14:28:20 +08:00
}
else
{
unbindVertexBufferObject();
setFogCoordPointer(array->getDataType(),0,array->getDataPointer());
}
}
}
2002-08-16 04:27:33 +08:00
/** wrapper around glEnableClientState(GL_FOG_COORDINATE_ARRAY);glFogCoordPointer(..);
2010-04-24 00:35:44 +08:00
* note, only updates values that change.*/
2002-08-16 04:27:33 +08:00
void setFogCoordPointer( GLenum type, GLsizei stride, const GLvoid *ptr );
/** wrapper around glDisableClientState(GL_FOG_COORDINATE_ARRAY);
2010-04-24 00:35:44 +08:00
* note, only updates values that change.*/
2002-08-16 04:27:33 +08:00
inline void disableFogCoordPointer()
{
2009-10-25 19:52:01 +08:00
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
2009-10-17 00:26:27 +08:00
if (_useVertexAttributeAliasing)
{
disableVertexAttribPointer(_fogCoordAlias._location);
}
else
2002-08-16 04:27:33 +08:00
{
2009-10-17 00:26:27 +08:00
if (_fogArray._enabled || _fogArray._dirty)
{
_fogArray._lazy_disable = false;
_fogArray._enabled = false;
_fogArray._dirty = false;
if (isFogCoordSupported()) glDisableClientState(GL_FOG_COORDINATE_ARRAY);
}
2002-08-16 04:27:33 +08:00
}
2009-10-25 19:52:01 +08:00
#else
disableVertexAttribPointer(_fogCoordAlias._location);
#endif
2002-08-16 04:27:33 +08:00
}
2002-09-13 21:50:58 +08:00
inline void dirtyFogCoordPointer()
{
2009-10-25 19:52:01 +08:00
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
2009-10-17 00:26:27 +08:00
if (_useVertexAttributeAliasing)
{
dirtyVertexAttribPointer(_fogCoordAlias._location);
}
else
{
_fogArray._pointer = 0;
_fogArray._dirty = true;
}
2009-10-25 19:52:01 +08:00
#else
dirtyVertexAttribPointer(_fogCoordAlias._location);
#endif
2002-09-13 21:50:58 +08:00
}
2002-08-16 04:27:33 +08:00
2007-05-01 14:28:20 +08:00
/** Set the tex coord pointer using an osg::Array, and manage any VBO that are required.*/
inline void setTexCoordPointer(unsigned int unit, const Array* array)
{
if (array)
{
2009-10-02 04:19:42 +08:00
GLBufferObject* vbo = array->getOrCreateGLBufferObject(_contextID);
2007-05-01 14:28:20 +08:00
if (vbo)
2009-09-23 02:45:24 +08:00
{
2007-05-01 14:28:20 +08:00
bindVertexBufferObject(vbo);
2009-10-02 04:19:42 +08:00
setTexCoordPointer(unit, array->getDataSize(),array->getDataType(),0, (const GLvoid *)(vbo->getOffset(array->getBufferIndex())));
2007-05-01 14:28:20 +08:00
}
else
{
unbindVertexBufferObject();
setTexCoordPointer(unit, array->getDataSize(),array->getDataType(),0,array->getDataPointer());
}
}
}
2002-07-07 22:40:41 +08:00
/** wrapper around glEnableClientState(GL_TEXTURE_COORD_ARRAY);glTexCoordPointer(..);
2010-04-24 00:35:44 +08:00
* note, only updates values that change.*/
2002-07-07 22:40:41 +08:00
inline void setTexCoordPointer( unsigned int unit,
2003-05-07 21:13:13 +08:00
GLint size, GLenum type,
GLsizei stride, const GLvoid *ptr )
2002-07-07 22:40:41 +08:00
{
2009-10-25 19:52:01 +08:00
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
2009-10-17 00:26:27 +08:00
if (_useVertexAttributeAliasing)
2002-07-07 22:40:41 +08:00
{
2009-10-17 00:26:27 +08:00
setVertexAttribPointer(_texCoordAliasList[unit]._location, size, type, GL_FALSE, stride, ptr);
}
else
{
if (setClientActiveTextureUnit(unit))
2002-07-07 22:40:41 +08:00
{
2009-10-17 00:26:27 +08:00
if ( unit >= _texCoordArrayList.size()) _texCoordArrayList.resize(unit+1);
EnabledArrayPair& eap = _texCoordArrayList[unit];
if (!eap._enabled || eap._dirty)
{
eap._enabled = true;
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
//if (eap._pointer!=ptr || eap._dirty)
{
glTexCoordPointer( size, type, stride, ptr );
eap._pointer = ptr;
}
eap._lazy_disable = false;
eap._dirty = false;
2002-07-07 22:40:41 +08:00
}
}
2009-10-25 19:52:01 +08:00
#else
setVertexAttribPointer(_texCoordAliasList[unit]._location, size, type, GL_FALSE, stride, ptr);
#endif
2002-07-07 22:40:41 +08:00
}
2003-05-07 21:13:13 +08:00
2002-07-07 22:40:41 +08:00
/** wrapper around glDisableClientState(GL_TEXTURE_COORD_ARRAY);
2010-04-24 00:35:44 +08:00
* note, only updates values that change.*/
2002-07-07 22:40:41 +08:00
inline void disableTexCoordPointer( unsigned int unit )
{
2009-10-25 19:52:01 +08:00
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
2009-10-17 00:26:27 +08:00
if (_useVertexAttributeAliasing)
2002-07-07 22:40:41 +08:00
{
2009-10-17 00:26:27 +08:00
disableVertexAttribPointer(_texCoordAliasList[unit]._location);
}
else
{
if (setClientActiveTextureUnit(unit))
2002-07-07 22:40:41 +08:00
{
2009-10-17 00:26:27 +08:00
if ( unit >= _texCoordArrayList.size()) _texCoordArrayList.resize(unit+1);
EnabledArrayPair& eap = _texCoordArrayList[unit];
if (eap._enabled || eap._dirty)
{
eap._lazy_disable = false;
eap._enabled = false;
eap._dirty = false;
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
2002-07-07 22:40:41 +08:00
}
}
2009-10-25 19:52:01 +08:00
#else
disableVertexAttribPointer(_texCoordAliasList[unit]._location);
#endif
2002-07-07 22:40:41 +08:00
}
2002-09-13 21:50:58 +08:00
inline void dirtyTexCoordPointer( unsigned int unit )
{
2009-10-25 19:52:01 +08:00
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
2009-10-17 00:26:27 +08:00
if (_useVertexAttributeAliasing)
{
dirtyVertexAttribPointer(_texCoordAliasList[unit]._location);
}
else
{
if ( unit >= _texCoordArrayList.size()) return; // _texCoordArrayList.resize(unit+1);
EnabledArrayPair& eap = _texCoordArrayList[unit];
eap._pointer = 0;
eap._dirty = true;
}
2009-10-25 19:52:01 +08:00
#else
dirtyVertexAttribPointer(_texCoordAliasList[unit]._location);
#endif
2002-09-13 21:50:58 +08:00
}
2002-07-15 18:03:59 +08:00
inline void disableTexCoordPointersAboveAndIncluding( unsigned int unit )
{
2009-10-25 19:52:01 +08:00
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
2009-10-17 00:26:27 +08:00
if (_useVertexAttributeAliasing)
2002-07-15 18:03:59 +08:00
{
2009-10-17 00:26:27 +08:00
disableVertexAttribPointersAboveAndIncluding(_texCoordAliasList[unit]._location);
}
else
{
while (unit<_texCoordArrayList.size())
2002-07-15 18:03:59 +08:00
{
2009-10-17 00:26:27 +08:00
EnabledArrayPair& eap = _texCoordArrayList[unit];
if (eap._enabled || eap._dirty)
2002-07-15 18:03:59 +08:00
{
2009-10-17 00:26:27 +08:00
if (setClientActiveTextureUnit(unit))
{
eap._lazy_disable = false;
eap._enabled = false;
eap._dirty = false;
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
2002-07-15 18:03:59 +08:00
}
2009-10-17 00:26:27 +08:00
++unit;
2002-07-15 18:03:59 +08:00
}
}
2009-10-25 19:52:01 +08:00
#else
disableVertexAttribPointersAboveAndIncluding(_texCoordAliasList[unit]._location);
#endif
2002-07-15 18:03:59 +08:00
}
2002-07-07 22:40:41 +08:00
2002-09-13 21:50:58 +08:00
inline void dirtyTexCoordPointersAboveAndIncluding( unsigned int unit )
{
2009-10-25 19:52:01 +08:00
#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
2009-10-17 00:26:27 +08:00
if (_useVertexAttributeAliasing)
2002-09-13 21:50:58 +08:00
{
2009-10-17 00:26:27 +08:00
dirtyVertexAttribPointersAboveAndIncluding(_texCoordAliasList[unit]._location);
}
else
{
while (unit<_texCoordArrayList.size())
{
EnabledArrayPair& eap = _texCoordArrayList[unit];
eap._pointer = 0;
eap._dirty = true;
++unit;
}
2002-09-13 21:50:58 +08:00
}
2009-10-25 19:52:01 +08:00
#else
dirtyVertexAttribPointersAboveAndIncluding(_texCoordAliasList[unit]._location);
#endif
2002-09-13 21:50:58 +08:00
}
2005-03-25 19:07:48 +08:00
/** Set the current texture unit, return true if selected,
2010-04-24 00:35:44 +08:00
* false if selection failed such as when multi texturing is not supported.
* note, only updates values that change.*/
2010-01-08 00:49:12 +08:00
inline bool setActiveTextureUnit( unsigned int unit );
2010-04-24 00:35:44 +08:00
2005-03-25 19:07:48 +08:00
/** Get the current texture unit.*/
unsigned int getActiveTextureUnit() const { return _currentActiveTextureUnit; }
2002-07-07 22:40:41 +08:00
2005-03-25 19:07:48 +08:00
/** Set the current tex coord array texture unit, return true if selected,
2010-04-24 00:35:44 +08:00
* false if selection failed such as when multi texturing is not supported.
* note, only updates values that change.*/
2005-03-25 19:07:48 +08:00
bool setClientActiveTextureUnit( unsigned int unit );
/** Get the current tex coord array texture unit.*/
unsigned int getClientActiveTextureUnit() const { return _currentClientActiveTextureUnit; }
2005-02-02 23:08:55 +08:00
2007-05-01 14:28:20 +08:00
/** Set the vertex attrib pointer using an osg::Array, and manage any VBO that are required.*/
inline void setVertexAttribPointer(unsigned int unit, const Array* array, GLboolean normalized)
{
if (array)
{
2009-10-02 04:19:42 +08:00
GLBufferObject* vbo = array->getOrCreateGLBufferObject(_contextID);
2007-05-01 14:28:20 +08:00
if (vbo)
2009-09-23 02:45:24 +08:00
{
2007-05-01 14:28:20 +08:00
bindVertexBufferObject(vbo);
2009-10-02 04:19:42 +08:00
setVertexAttribPointer(unit, array->getDataSize(),array->getDataType(),normalized,0,(const GLvoid *)(vbo->getOffset(array->getBufferIndex())));
2007-05-01 14:28:20 +08:00
}
else
{
unbindVertexBufferObject();
setVertexAttribPointer(unit, array->getDataSize(),array->getDataType(),normalized,0,array->getDataPointer());
}
}
}
2003-05-07 21:13:13 +08:00
/** wrapper around glEnableVertexAttribArrayARB(index);glVertexAttribPointerARB(..);
2010-04-24 00:35:44 +08:00
* note, only updates values that change.*/
2003-05-09 21:07:06 +08:00
void setVertexAttribPointer( unsigned int index,
2010-04-24 00:35:44 +08:00
GLint size, GLenum type, GLboolean normalized,
GLsizei stride, const GLvoid *ptr );
2005-02-02 23:08:55 +08:00
2003-05-07 21:13:13 +08:00
/** wrapper around DisableVertexAttribArrayARB(index);
2010-04-24 00:35:44 +08:00
* note, only updates values that change.*/
2003-05-09 21:07:06 +08:00
void disableVertexAttribPointer( unsigned int index );
2005-02-02 23:08:55 +08:00
2003-05-09 21:07:06 +08:00
void disableVertexAttribPointersAboveAndIncluding( unsigned int index );
2005-02-02 23:08:55 +08:00
2009-10-17 00:26:27 +08:00
inline void dirtyVertexAttribPointer( unsigned int index )
{
if (index<_vertexAttribArrayList.size())
{
EnabledArrayPair& eap = _vertexAttribArrayList[index];
eap._pointer = 0;
eap._dirty = true;
}
}
2003-05-07 21:13:13 +08:00
inline void dirtyVertexAttribPointersAboveAndIncluding( unsigned int index )
{
while (index<_vertexAttribArrayList.size())
{
EnabledArrayPair& eap = _vertexAttribArrayList[index];
eap._pointer = 0;
eap._dirty = true;
++index;
}
}
2003-06-30 05:41:57 +08:00
bool isVertexBufferObjectSupported() const { return _isVertexBufferObjectSupportResolved?_isVertexBufferObjectSupported:computeVertexBufferObjectSupported(); }
2003-05-07 21:13:13 +08:00
2009-01-26 23:16:24 +08:00
inline void setLastAppliedProgramObject(const Program::PerContextProgram* program)
{
if (_lastAppliedProgramObject!=program)
{
2009-09-23 02:45:24 +08:00
_lastAppliedProgramObject = program;
2009-01-26 23:16:24 +08:00
if (program && _appliedProgramObjectSet.count(program)==0)
{
2009-09-23 02:45:24 +08:00
_appliedProgramObjectSet.insert(program);
2009-01-26 23:16:24 +08:00
program->addObserver(this);
}
}
}
inline const Program::PerContextProgram* getLastAppliedProgramObject() const { return _lastAppliedProgramObject; }
2005-04-13 20:00:28 +08:00
2010-11-25 20:30:38 +08:00
inline GLint getUniformLocation( unsigned int uniformNameID ) const { return _lastAppliedProgramObject ? _lastAppliedProgramObject->getUniformLocation(uniformNameID) : -1; }
2011-01-12 01:18:44 +08:00
/**
* Alternative version of getUniformLocation( unsigned int uniformNameID )
* retrofited into OSG for backward compatibility with osgCal,
* after uniform ids were refactored from std::strings to GLints in OSG version 2.9.10.
*
* Drawbacks: This method is not particularly fast. It has to access mutexed static
* map of uniform ids. So don't overuse it or your app performance will suffer.
*/
inline GLint getUniformLocation( const std::string & uniformName ) const { return _lastAppliedProgramObject ? _lastAppliedProgramObject->getUniformLocation(uniformName) : -1; }
2005-05-13 04:35:15 +08:00
inline GLint getAttribLocation( const std::string& name ) const { return _lastAppliedProgramObject ? _lastAppliedProgramObject->getAttribLocation(name) : -1; }
2005-04-13 20:00:28 +08:00
2009-05-12 13:49:36 +08:00
typedef std::pair<const StateAttribute*,StateAttribute::OverrideValue> AttributePair;
typedef std::vector<AttributePair> AttributeVec;
AttributeVec& getAttributeVec( const osg::StateAttribute* attribute )
{
AttributeStack& as = _attributeMap[ attribute->getTypeMemberPair() ];
return as.attributeVec;
}
2005-02-02 23:08:55 +08:00
2001-09-22 10:42:08 +08:00
/** Set the frame stamp for the current frame.*/
inline void setFrameStamp(FrameStamp* fs) { _frameStamp = fs; }
2004-09-14 01:19:05 +08:00
/** Get the frame stamp for the current frame.*/
2007-08-02 19:02:47 +08:00
inline FrameStamp* getFrameStamp() { return _frameStamp.get(); }
/** Get the const frame stamp for the current frame.*/
2001-09-22 10:42:08 +08:00
inline const FrameStamp* getFrameStamp() const { return _frameStamp.get(); }
2005-02-02 23:08:55 +08:00
2004-09-03 03:10:33 +08:00
/** Set the DisplaySettings. Note, nothing is applied, the visual settings are just
2010-04-24 00:35:44 +08:00
* used in the State object to pass the current visual settings to Drawables
* during rendering. */
2001-12-22 06:48:19 +08:00
inline void setDisplaySettings(DisplaySettings* vs) { _displaySettings = vs; }
2005-02-02 23:08:55 +08:00
2001-12-22 06:48:19 +08:00
/** Get the DisplaySettings */
inline const DisplaySettings* getDisplaySettings() const { return _displaySettings.get(); }
2001-12-19 08:38:23 +08:00
2005-02-02 23:08:55 +08:00
2003-03-11 23:25:49 +08:00
/** Set flag for early termination of the draw traversal.*/
void setAbortRenderingPtr(bool* abortPtr) { _abortRenderingPtr = abortPtr; }
2005-02-02 23:08:55 +08:00
/** Get flag for early termination of the draw traversal,
2010-04-24 00:35:44 +08:00
* if true steps should be taken to complete rendering early.*/
2003-03-11 23:25:49 +08:00
bool getAbortRendering() const { return _abortRenderingPtr!=0?(*_abortRenderingPtr):false; }
2007-01-30 06:44:29 +08:00
struct DynamicObjectRenderingCompletedCallback : public osg::Referenced
{
virtual void completed(osg::State*) = 0;
};
2009-09-23 02:45:24 +08:00
2007-01-30 06:44:29 +08:00
/** Set the callback to be called when the dynamic object count hits 0.*/
void setDynamicObjectRenderingCompletedCallback(DynamicObjectRenderingCompletedCallback* cb){ _completeDynamicObjectRenderingCallback = cb; }
2009-09-23 02:45:24 +08:00
2007-01-30 06:44:29 +08:00
/** Get the callback to be called when the dynamic object count hits 0.*/
DynamicObjectRenderingCompletedCallback* getDynamicObjectRenderingCompletedCallback() { return _completeDynamicObjectRenderingCallback.get(); }
2009-09-23 02:45:24 +08:00
2007-01-30 06:44:29 +08:00
/** Set the number of dynamic objects that will be rendered in this graphics context this frame.*/
void setDynamicObjectCount(unsigned int count, bool callCallbackOnZero = false)
{
if (_dynamicObjectCount != count)
{
_dynamicObjectCount = count;
if (_dynamicObjectCount==0 && callCallbackOnZero && _completeDynamicObjectRenderingCallback.valid())
{
_completeDynamicObjectRenderingCallback->completed(this);
}
}
}
/** Get the number of dynamic objects that will be rendered in this graphics context this frame.*/
unsigned int getDynamicObjectCount() const { return _dynamicObjectCount; }
2010-04-24 00:35:44 +08:00
/** Decrement the number of dynamic objects left to render this frame, and once the count goes to zero call the
* DynamicObjectRenderingCompletedCallback to inform of completion.*/
2007-01-30 06:44:29 +08:00
inline void decrementDynamicObjectCount()
{
--_dynamicObjectCount;
if (_dynamicObjectCount==0 && _completeDynamicObjectRenderingCallback.valid())
{
_completeDynamicObjectRenderingCallback->completed(this);
}
2009-09-23 02:45:24 +08:00
}
void setMaxTexturePoolSize(unsigned int size);
unsigned int getMaxTexturePoolSize() const { return _maxTexturePoolSize; }
2009-10-03 17:25:23 +08:00
void setMaxBufferObjectPoolSize(unsigned int size);
unsigned int getMaxBufferObjectPoolSize() const { return _maxBufferObjectPoolSize; }
2007-01-30 06:44:29 +08:00
2005-04-30 04:56:20 +08:00
enum CheckForGLErrors
{
2009-09-23 02:45:24 +08:00
/** NEVER_CHECK_GL_ERRORS hints that OpenGL need not be checked for, this
2005-04-30 04:56:20 +08:00
is the fastest option since checking for errors does incurr a small overhead.*/
NEVER_CHECK_GL_ERRORS,
/** ONCE_PER_FRAME means that OpenGl errors will be checked for once per
frame, the overhead is still small, but at least OpenGL errors that are occurring
will be caught, the reporting isn't fine grained enough for debugging purposes.*/
ONCE_PER_FRAME,
/** ONCE_PER_ATTRIBUTE means that OpenGL errors will be checked for after
every attribute is applied, allow errors to be directly associated with
particular operations which makes debugging much easier.*/
ONCE_PER_ATTRIBUTE
};
/** Set whether and how often OpenGL errors should be checked for.*/
void setCheckForGLErrors(CheckForGLErrors check) { _checkGLErrors = check; }
/** Get whether and how often OpenGL errors should be checked for.*/
CheckForGLErrors getCheckForGLErrors() const { return _checkGLErrors; }
2003-01-22 00:45:36 +08:00
bool checkGLErrors(const char* str) const;
bool checkGLErrors(StateAttribute::GLMode mode) const;
bool checkGLErrors(const StateAttribute* attribute) const;
2002-03-19 05:56:00 +08:00
2010-07-11 01:14:59 +08:00
/** print out the internal details of osg::State - useful for debugging.*/
void print(std::ostream& fout) const;
2007-05-01 14:28:20 +08:00
/** Initialize extension used by osg:::State.*/
void initializeExtensionProcs();
2009-01-26 23:16:24 +08:00
virtual void objectDeleted(void* object);
2011-02-03 20:42:23 +08:00
/** Get the GL adapter object used to map OpenGL 1.0 glBegin/glEnd usage to vertex arrays.*/
2009-10-17 00:26:27 +08:00
inline GLBeginEndAdapter& getGLBeginEndAdapter() { return _glBeginEndAdapter; }
2011-02-03 20:42:23 +08:00
/** Get the helper class for dispatching osg::Arrays as OpenGL attribute data.*/
2009-10-21 19:18:13 +08:00
inline ArrayDispatchers& getArrayDispatchers() { return _arrayDispatchers; }
2009-10-17 00:26:27 +08:00
2011-02-03 20:42:23 +08:00
/** Set the helper class that provides applications with estimate on how much different graphics operations will cost.*/
inline void setGraphicsCostEstimator(GraphicsCostEstimator* gce) { _graphicsCostEstimator = gce; }
/** Get the helper class that provides applications with estimate on how much different graphics operations will cost.*/
inline GraphicsCostEstimator* getGraphicsCostEstimator() { return _graphicsCostEstimator.get(); }
/** Get the cont helper class that provides applications with estimate on how much different graphics operations will cost.*/
inline const GraphicsCostEstimator* getGraphicsCostEstimator() const { return _graphicsCostEstimator.get(); }
2010-11-11 00:58:58 +08:00
/** Support for synchronizing the system time and the timestamp
* counter available with ARB_timer_query. Note that State
* doesn't update these values itself.
*/
Timer_t getStartTick() const { return _startTick; }
void setStartTick(Timer_t tick) { _startTick = tick; }
Timer_t getGpuTick() const { return _gpuTick; }
double getGpuTime() const
{
return osg::Timer::instance()->delta_s(_startTick, _gpuTick);
}
GLuint64EXT getGpuTimestamp() const { return _gpuTimestamp; }
void setGpuTimestamp(Timer_t tick, GLuint64EXT timestamp)
{
_gpuTick = tick;
_gpuTimestamp = timestamp;
}
int getTimestampBits() const { return _timestampBits; }
void setTimestampBits(int bits) { _timestampBits = bits; }
/** called by the GraphicsContext just before GraphicsContext::swapBuffersImplementation().*/
virtual void frameCompleted();
2003-01-10 17:25:42 +08:00
protected:
virtual ~State();
2002-03-19 05:56:00 +08:00
2005-07-20 23:55:07 +08:00
GraphicsContext* _graphicsContext;
2001-12-19 08:38:23 +08:00
unsigned int _contextID;
2010-07-02 20:04:20 +08:00
bool _shaderCompositionEnabled;
bool _shaderCompositionDirty;
osg::ref_ptr<ShaderComposer> _shaderComposer;
osg::Program* _currentShaderCompositionProgram;
2010-07-06 18:55:54 +08:00
StateSet::UniformList _currentShaderCompositionUniformList;
2010-06-25 01:15:27 +08:00
2001-12-19 08:38:23 +08:00
ref_ptr<FrameStamp> _frameStamp;
2005-02-02 23:08:55 +08:00
2003-01-10 17:25:42 +08:00
ref_ptr<const RefMatrix> _identity;
2003-07-23 05:03:59 +08:00
ref_ptr<const RefMatrix> _initialViewMatrix;
2003-01-10 17:25:42 +08:00
ref_ptr<const RefMatrix> _projection;
ref_ptr<const RefMatrix> _modelView;
2010-06-01 21:33:58 +08:00
ref_ptr<RefMatrix> _modelViewCache;
2005-02-02 23:08:55 +08:00
2009-10-11 14:05:19 +08:00
bool _useModelViewAndProjectionUniforms;
2009-10-09 21:39:11 +08:00
ref_ptr<Uniform> _modelViewMatrixUniform;
ref_ptr<Uniform> _projectionMatrixUniform;
ref_ptr<Uniform> _modelViewProjectionMatrixUniform;
2009-10-17 00:26:27 +08:00
ref_ptr<Uniform> _normalMatrixUniform;
2009-10-09 21:39:11 +08:00
2003-08-25 21:06:15 +08:00
Matrix _initialInverseViewMatrix;
2001-12-22 06:48:19 +08:00
ref_ptr<DisplaySettings> _displaySettings;
2005-02-02 23:08:55 +08:00
2003-03-11 23:25:49 +08:00
bool* _abortRenderingPtr;
2005-04-30 04:56:20 +08:00
CheckForGLErrors _checkGLErrors;
2003-01-22 00:45:36 +08:00
2009-10-17 00:26:27 +08:00
bool _useVertexAttributeAliasing;
VertexAttribAlias _vertexAlias;
VertexAttribAlias _normalAlias;
VertexAttribAlias _colorAlias;
VertexAttribAlias _secondaryColorAlias;
VertexAttribAlias _fogCoordAlias;
VertexAttribAliasList _texCoordAliasList;
Program::AttribBindingList _attributeBindingList;
void setUpVertexAttribAlias(VertexAttribAlias& alias, GLuint location, const std::string glName, const std::string osgName, const std::string& declaration);
2001-09-20 05:08:56 +08:00
struct ModeStack
{
2005-04-13 20:00:28 +08:00
typedef std::vector<StateAttribute::GLModeValue> ValueVec;
2001-09-20 05:08:56 +08:00
ModeStack()
{
2006-02-22 22:31:13 +08:00
valid = true;
2001-09-20 05:08:56 +08:00
changed = false;
last_applied_value = false;
2001-10-15 22:07:54 +08:00
global_default_value = false;
2001-09-20 05:08:56 +08:00
}
2005-02-02 23:08:55 +08:00
2010-07-11 01:14:59 +08:00
void print(std::ostream& fout) const;
2006-02-22 22:31:13 +08:00
bool valid;
2001-09-20 05:08:56 +08:00
bool changed;
bool last_applied_value;
2001-10-15 22:07:54 +08:00
bool global_default_value;
2001-09-20 05:08:56 +08:00
ValueVec valueVec;
};
struct AttributeStack
{
AttributeStack()
{
changed = false;
last_applied_attribute = 0L;
2010-07-02 20:04:20 +08:00
last_applied_shadercomponent = 0L;
2001-10-15 22:07:54 +08:00
global_default_attribute = 0L;
2010-07-02 20:04:20 +08:00
2001-09-20 05:08:56 +08:00
}
2010-07-11 01:14:59 +08:00
void print(std::ostream& fout) const;
2001-10-15 22:07:54 +08:00
/** apply an attribute if required, passing in attribute and appropriate attribute stack */
2001-09-20 05:08:56 +08:00
bool changed;
const StateAttribute* last_applied_attribute;
2010-07-02 20:04:20 +08:00
const ShaderComponent* last_applied_shadercomponent;
2004-08-07 17:42:19 +08:00
ref_ptr<const StateAttribute> global_default_attribute;
2001-09-20 05:08:56 +08:00
AttributeVec attributeVec;
};
2005-02-02 23:08:55 +08:00
2005-04-13 20:00:28 +08:00
struct UniformStack
{
typedef std::pair<const Uniform*,StateAttribute::OverrideValue> UniformPair;
typedef std::vector<UniformPair> UniformVec;
2005-05-10 21:56:05 +08:00
UniformStack() {}
2005-04-13 20:00:28 +08:00
2010-07-11 01:14:59 +08:00
void print(std::ostream& fout) const;
2005-04-13 20:00:28 +08:00
UniformVec uniformVec;
};
2005-02-02 23:08:55 +08:00
/** Apply an OpenGL mode if required, passing in mode, enable flag and
2010-04-24 00:35:44 +08:00
* appropriate mode stack. This is a wrapper around \c glEnable() and
* \c glDisable(), that just actually calls these functions if the
* \c enabled flag is different than the current state.
* @return \c true if the state was actually changed. \c false
* otherwise. Notice that a \c false return does not indicate
* an error, it just means that the mode was already set to the
* same value as the \c enabled parameter.
2005-02-02 23:08:55 +08:00
*/
2002-09-02 20:31:35 +08:00
inline bool applyMode(StateAttribute::GLMode mode,bool enabled,ModeStack& ms)
2001-09-20 05:08:56 +08:00
{
2006-02-22 22:31:13 +08:00
if (ms.valid && ms.last_applied_value != enabled)
2001-09-20 05:08:56 +08:00
{
ms.last_applied_value = enabled;
if (enabled) glEnable(mode);
else glDisable(mode);
2005-04-30 04:56:20 +08:00
if (_checkGLErrors==ONCE_PER_ATTRIBUTE) checkGLErrors(mode);
2003-01-22 00:45:36 +08:00
2001-09-20 05:08:56 +08:00
return true;
}
else
return false;
}
2010-01-08 00:49:12 +08:00
inline bool applyModeOnTexUnit(unsigned int unit,StateAttribute::GLMode mode,bool enabled,ModeStack& ms)
{
if (ms.valid && ms.last_applied_value != enabled)
{
if (setActiveTextureUnit(unit))
{
ms.last_applied_value = enabled;
if (enabled) glEnable(mode);
else glDisable(mode);
if (_checkGLErrors==ONCE_PER_ATTRIBUTE) checkGLErrors(mode);
return true;
}
else
return false;
}
else
return false;
}
2003-01-22 00:45:36 +08:00
2001-09-20 05:08:56 +08:00
/** apply an attribute if required, passing in attribute and appropriate attribute stack */
2002-09-02 20:31:35 +08:00
inline bool applyAttribute(const StateAttribute* attribute,AttributeStack& as)
2001-09-20 05:08:56 +08:00
{
if (as.last_applied_attribute != attribute)
{
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
if (!as.global_default_attribute.valid()) as.global_default_attribute = dynamic_cast<StateAttribute*>(attribute->cloneType());
2001-10-15 22:07:54 +08:00
2001-09-20 05:08:56 +08:00
as.last_applied_attribute = attribute;
attribute->apply(*this);
2005-02-02 23:08:55 +08:00
2010-07-02 20:04:20 +08:00
const ShaderComponent* sc = attribute->getShaderComponent();
if (as.last_applied_shadercomponent != sc)
{
as.last_applied_shadercomponent = sc;
_shaderCompositionDirty = true;
}
2005-04-30 04:56:20 +08:00
if (_checkGLErrors==ONCE_PER_ATTRIBUTE) checkGLErrors(attribute);
2005-02-02 23:08:55 +08:00
2001-09-20 05:08:56 +08:00
return true;
}
else
return false;
}
2010-01-08 00:49:12 +08:00
inline bool applyAttributeOnTexUnit(unsigned int unit,const StateAttribute* attribute,AttributeStack& as)
{
if (as.last_applied_attribute != attribute)
{
if (setActiveTextureUnit(unit))
{
if (!as.global_default_attribute.valid()) as.global_default_attribute = dynamic_cast<StateAttribute*>(attribute->cloneType());
as.last_applied_attribute = attribute;
attribute->apply(*this);
2010-07-11 01:14:59 +08:00
const ShaderComponent* sc = attribute->getShaderComponent();
if (as.last_applied_shadercomponent != sc)
{
as.last_applied_shadercomponent = sc;
_shaderCompositionDirty = true;
}
2010-01-08 00:49:12 +08:00
if (_checkGLErrors==ONCE_PER_ATTRIBUTE) checkGLErrors(attribute);
return true;
}
else
return false;
}
else
return false;
}
2002-09-02 20:31:35 +08:00
inline bool applyGlobalDefaultAttribute(AttributeStack& as)
2001-10-15 22:07:54 +08:00
{
2001-10-15 22:29:40 +08:00
if (as.last_applied_attribute != as.global_default_attribute.get())
2001-10-15 22:07:54 +08:00
{
2001-10-15 22:29:40 +08:00
as.last_applied_attribute = as.global_default_attribute.get();
2003-01-22 00:45:36 +08:00
if (as.global_default_attribute.valid())
{
as.global_default_attribute->apply(*this);
2010-07-11 01:14:59 +08:00
const ShaderComponent* sc = as.global_default_attribute->getShaderComponent();
if (as.last_applied_shadercomponent != sc)
{
as.last_applied_shadercomponent = sc;
_shaderCompositionDirty = true;
}
2005-04-30 04:56:20 +08:00
if (_checkGLErrors==ONCE_PER_ATTRIBUTE) checkGLErrors(as.global_default_attribute.get());
2003-01-22 00:45:36 +08:00
}
2001-10-15 22:07:54 +08:00
return true;
}
else
return false;
}
2005-02-02 23:08:55 +08:00
2010-01-08 00:49:12 +08:00
inline bool applyGlobalDefaultAttributeOnTexUnit(unsigned int unit,AttributeStack& as)
{
if (as.last_applied_attribute != as.global_default_attribute.get())
{
if (setActiveTextureUnit(unit))
{
as.last_applied_attribute = as.global_default_attribute.get();
if (as.global_default_attribute.valid())
{
as.global_default_attribute->apply(*this);
2010-07-11 01:14:59 +08:00
const ShaderComponent* sc = as.global_default_attribute->getShaderComponent();
if (as.last_applied_shadercomponent != sc)
{
as.last_applied_shadercomponent = sc;
_shaderCompositionDirty = true;
}
2010-01-08 00:49:12 +08:00
if (_checkGLErrors==ONCE_PER_ATTRIBUTE) checkGLErrors(as.global_default_attribute.get());
}
return true;
}
else
return false;
}
else
return false;
}
2002-07-09 17:35:42 +08:00
2004-10-13 19:15:50 +08:00
typedef std::map<StateAttribute::GLMode,ModeStack> ModeMap;
typedef std::vector<ModeMap> TextureModeMapList;
2002-07-07 22:40:41 +08:00
2004-10-13 19:15:50 +08:00
typedef std::map<StateAttribute::TypeMemberPair,AttributeStack> AttributeMap;
typedef std::vector<AttributeMap> TextureAttributeMapList;
2002-07-07 22:40:41 +08:00
2005-04-13 20:00:28 +08:00
typedef std::map<std::string,UniformStack> UniformMap;
2004-10-13 19:15:50 +08:00
typedef std::vector<ref_ptr<const Matrix> > MatrixStack;
2009-09-23 02:45:24 +08:00
2009-01-26 23:16:24 +08:00
typedef std::set<const Program::PerContextProgram* > AppliedProgramObjectSet;
2001-09-20 05:08:56 +08:00
2004-10-13 19:15:50 +08:00
ModeMap _modeMap;
AttributeMap _attributeMap;
2005-04-13 20:00:28 +08:00
UniformMap _uniformMap;
2002-07-09 17:35:42 +08:00
2004-10-13 19:15:50 +08:00
TextureModeMapList _textureModeMapList;
TextureAttributeMapList _textureAttributeMapList;
2005-02-02 23:08:55 +08:00
2005-05-04 05:46:47 +08:00
AppliedProgramObjectSet _appliedProgramObjectSet;
2005-04-13 20:00:28 +08:00
const Program::PerContextProgram* _lastAppliedProgramObject;
2005-04-04 18:08:15 +08:00
2005-04-13 20:00:28 +08:00
StateSetStack _stateStateStack;
2005-02-02 23:08:55 +08:00
2009-09-23 02:45:24 +08:00
unsigned int _maxTexturePoolSize;
2009-10-03 17:25:23 +08:00
unsigned int _maxBufferObjectPoolSize;
2009-09-23 02:45:24 +08:00
2002-07-07 22:40:41 +08:00
struct EnabledArrayPair
{
2009-10-17 00:26:27 +08:00
EnabledArrayPair():_lazy_disable(false),_dirty(true),_enabled(false),_normalized(0),_pointer(0) {}
EnabledArrayPair(const EnabledArrayPair& eap):_lazy_disable(eap._lazy_disable),_dirty(eap._dirty), _enabled(eap._enabled),_normalized(eap._normalized),_pointer(eap._pointer) {}
EnabledArrayPair& operator = (const EnabledArrayPair& eap) { _lazy_disable = eap._lazy_disable;_dirty=eap._dirty; _enabled=eap._enabled; _normalized=eap._normalized;_pointer=eap._pointer; return *this; }
2005-02-02 23:08:55 +08:00
2009-10-17 00:26:27 +08:00
bool _lazy_disable;
2002-09-13 21:50:58 +08:00
bool _dirty;
bool _enabled;
2003-05-07 21:13:13 +08:00
GLboolean _normalized;
2002-09-13 21:50:58 +08:00
const GLvoid* _pointer;
2002-07-07 22:40:41 +08:00
};
2005-02-02 23:08:55 +08:00
2002-07-07 22:40:41 +08:00
typedef std::vector<EnabledArrayPair> EnabledTexCoordArrayList;
2003-05-07 21:13:13 +08:00
typedef std::vector<EnabledArrayPair> EnabledVertexAttribArrayList;
EnabledArrayPair _vertexArray;
EnabledArrayPair _normalArray;
EnabledArrayPair _colorArray;
EnabledArrayPair _secondaryColorArray;
EnabledArrayPair _fogArray;
EnabledTexCoordArrayList _texCoordArrayList;
EnabledVertexAttribArrayList _vertexAttribArrayList;
unsigned int _currentActiveTextureUnit;
unsigned int _currentClientActiveTextureUnit;
2009-10-02 04:19:42 +08:00
GLBufferObject* _currentVBO;
GLBufferObject* _currentEBO;
GLBufferObject* _currentPBO;
2007-05-01 14:28:20 +08:00
2005-02-02 23:08:55 +08:00
2002-07-09 17:35:42 +08:00
inline ModeMap& getOrCreateTextureModeMap(unsigned int unit)
2005-02-02 23:08:55 +08:00
{
2002-07-09 17:35:42 +08:00
if (unit>=_textureModeMapList.size()) _textureModeMapList.resize(unit+1);
return _textureModeMapList[unit];
}
inline AttributeMap& getOrCreateTextureAttributeMap(unsigned int unit)
2005-02-02 23:08:55 +08:00
{
2002-07-09 17:35:42 +08:00
if (unit>=_textureAttributeMapList.size()) _textureAttributeMapList.resize(unit+1);
return _textureAttributeMapList[unit];
}
2005-02-02 23:08:55 +08:00
2002-07-09 17:35:42 +08:00
inline void pushModeList(ModeMap& modeMap,const StateSet::ModeList& modeList);
inline void pushAttributeList(AttributeMap& attributeMap,const StateSet::AttributeList& attributeList);
2005-05-10 21:56:05 +08:00
inline void pushUniformList(UniformMap& uniformMap,const StateSet::UniformList& uniformList);
2005-02-02 23:08:55 +08:00
2002-07-09 17:35:42 +08:00
inline void popModeList(ModeMap& modeMap,const StateSet::ModeList& modeList);
inline void popAttributeList(AttributeMap& attributeMap,const StateSet::AttributeList& attributeList);
2005-05-10 21:56:05 +08:00
inline void popUniformList(UniformMap& uniformMap,const StateSet::UniformList& uniformList);
2002-07-09 17:35:42 +08:00
inline void applyModeList(ModeMap& modeMap,const StateSet::ModeList& modeList);
inline void applyAttributeList(AttributeMap& attributeMap,const StateSet::AttributeList& attributeList);
2005-05-10 21:56:05 +08:00
inline void applyUniformList(UniformMap& uniformMap,const StateSet::UniformList& uniformList);
2005-02-02 23:08:55 +08:00
2002-07-09 17:35:42 +08:00
inline void applyModeMap(ModeMap& modeMap);
inline void applyAttributeMap(AttributeMap& attributeMap);
2005-05-10 21:56:05 +08:00
inline void applyUniformMap(UniformMap& uniformMap);
2002-07-09 17:35:42 +08:00
2010-01-08 00:49:12 +08:00
inline void applyModeListOnTexUnit(unsigned int unit,ModeMap& modeMap,const StateSet::ModeList& modeList);
inline void applyAttributeListOnTexUnit(unsigned int unit,AttributeMap& attributeMap,const StateSet::AttributeList& attributeList);
inline void applyModeMapOnTexUnit(unsigned int unit,ModeMap& modeMap);
inline void applyAttributeMapOnTexUnit(unsigned int unit,AttributeMap& attributeMap);
2002-09-02 20:31:35 +08:00
void haveAppliedMode(ModeMap& modeMap,StateAttribute::GLMode mode,StateAttribute::GLModeValue value);
void haveAppliedMode(ModeMap& modeMap,StateAttribute::GLMode mode);
2002-07-09 17:35:42 +08:00
void haveAppliedAttribute(AttributeMap& attributeMap,const StateAttribute* attribute);
2004-10-13 19:15:50 +08:00
void haveAppliedAttribute(AttributeMap& attributeMap,StateAttribute::Type type, unsigned int member);
2002-09-02 20:31:35 +08:00
bool getLastAppliedMode(const ModeMap& modeMap,StateAttribute::GLMode mode) const;
2004-10-13 19:15:50 +08:00
const StateAttribute* getLastAppliedAttribute(const AttributeMap& attributeMap,StateAttribute::Type type, unsigned int member) const;
2002-07-09 17:35:42 +08:00
2010-06-01 21:33:58 +08:00
void loadModelViewMatrix();
2002-11-13 19:09:55 +08:00
2003-06-30 05:41:57 +08:00
mutable bool _isSecondaryColorSupportResolved;
mutable bool _isSecondaryColorSupported;
2002-11-13 19:09:55 +08:00
bool computeSecondaryColorSupported() const;
mutable bool _isFogCoordSupportResolved;
mutable bool _isFogCoordSupported;
bool computeFogCoordSupported() const;
2003-06-30 05:41:57 +08:00
mutable bool _isVertexBufferObjectSupportResolved;
mutable bool _isVertexBufferObjectSupported;
bool computeVertexBufferObjectSupported() const;
2010-04-29 05:22:44 +08:00
typedef void (GL_APIENTRY * ActiveTextureProc) (GLenum texture);
typedef void (GL_APIENTRY * FogCoordPointerProc) (GLenum type, GLsizei stride, const GLvoid *pointer);
typedef void (GL_APIENTRY * SecondaryColorPointerProc) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
typedef void (GL_APIENTRY * MultiTexCoord4fProc) (GLenum target, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
typedef void (GL_APIENTRY * VertexAttrib4fProc)(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
typedef void (GL_APIENTRY * VertexAttrib4fvProc)(GLuint index, const GLfloat *v);
typedef void (GL_APIENTRY * VertexAttribPointerProc) (unsigned int, GLint, GLenum, GLboolean normalized, GLsizei stride, const GLvoid *pointer);
typedef void (GL_APIENTRY * EnableVertexAttribProc) (unsigned int);
typedef void (GL_APIENTRY * DisableVertexAttribProc) (unsigned int);
typedef void (GL_APIENTRY * BindBufferProc) (GLenum target, GLuint buffer);
typedef void (GL_APIENTRY * DrawArraysInstancedProc)( GLenum mode, GLint first, GLsizei count, GLsizei primcount );
typedef void (GL_APIENTRY * DrawElementsInstancedProc)( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount );
2006-08-03 00:14:17 +08:00
bool _extensionProcsInitialized;
2007-05-15 19:25:14 +08:00
GLint _glMaxTextureCoords;
GLint _glMaxTextureUnits;
2006-08-03 00:14:17 +08:00
ActiveTextureProc _glClientActiveTexture;
ActiveTextureProc _glActiveTexture;
2009-10-17 00:26:27 +08:00
MultiTexCoord4fProc _glMultiTexCoord4f;
VertexAttrib4fProc _glVertexAttrib4f;
VertexAttrib4fvProc _glVertexAttrib4fv;
2006-08-03 00:14:17 +08:00
FogCoordPointerProc _glFogCoordPointer;
SecondaryColorPointerProc _glSecondaryColorPointer;
VertexAttribPointerProc _glVertexAttribPointer;
EnableVertexAttribProc _glEnableVertexAttribArray;
DisableVertexAttribProc _glDisableVertexAttribArray;
2007-05-01 14:28:20 +08:00
BindBufferProc _glBindBuffer;
2009-01-06 22:55:49 +08:00
DrawArraysInstancedProc _glDrawArraysInstanced;
DrawElementsInstancedProc _glDrawElementsInstanced;
2006-08-03 00:14:17 +08:00
2007-01-30 06:44:29 +08:00
unsigned int _dynamicObjectCount;
osg::ref_ptr<DynamicObjectRenderingCompletedCallback> _completeDynamicObjectRenderingCallback;
2009-09-23 02:45:24 +08:00
2009-10-17 00:26:27 +08:00
GLBeginEndAdapter _glBeginEndAdapter;
2009-10-21 19:18:13 +08:00
ArrayDispatchers _arrayDispatchers;
2011-02-03 20:42:23 +08:00
osg::ref_ptr<GraphicsCostEstimator> _graphicsCostEstimator;
2010-11-11 00:58:58 +08:00
Timer_t _startTick;
Timer_t _gpuTick;
GLuint64EXT _gpuTimestamp;
int _timestampBits;
2001-01-11 00:32:10 +08:00
};
2002-07-09 17:35:42 +08:00
inline void State::pushModeList(ModeMap& modeMap,const StateSet::ModeList& modeList)
{
for(StateSet::ModeList::const_iterator mitr=modeList.begin();
mitr!=modeList.end();
++mitr)
{
2004-09-03 03:10:33 +08:00
// get the mode stack for incoming GLmode {mitr->first}.
2002-07-09 17:35:42 +08:00
ModeStack& ms = modeMap[mitr->first];
if (ms.valueVec.empty())
{
2004-09-03 03:10:33 +08:00
// first pair so simply push incoming pair to back.
2002-07-09 17:35:42 +08:00
ms.valueVec.push_back(mitr->second);
}
2005-02-02 23:08:55 +08:00
else if ((ms.valueVec.back() & StateAttribute::OVERRIDE) && !(mitr->second & StateAttribute::PROTECTED)) // check the existing override flag
2002-07-09 17:35:42 +08:00
{
2004-09-03 03:10:33 +08:00
// push existing back since override keeps the previous value.
2002-07-09 17:35:42 +08:00
ms.valueVec.push_back(ms.valueVec.back());
}
2005-02-02 23:08:55 +08:00
else
2002-07-09 17:35:42 +08:00
{
2004-09-03 03:10:33 +08:00
// no override on so simply push incoming pair to back.
2002-07-09 17:35:42 +08:00
ms.valueVec.push_back(mitr->second);
}
ms.changed = true;
}
}
inline void State::pushAttributeList(AttributeMap& attributeMap,const StateSet::AttributeList& attributeList)
{
for(StateSet::AttributeList::const_iterator aitr=attributeList.begin();
aitr!=attributeList.end();
++aitr)
{
2004-09-03 03:10:33 +08:00
// get the attribute stack for incoming type {aitr->first}.
2002-07-09 17:35:42 +08:00
AttributeStack& as = attributeMap[aitr->first];
if (as.attributeVec.empty())
{
2004-09-03 03:10:33 +08:00
// first pair so simply push incoming pair to back.
2002-07-09 17:35:42 +08:00
as.attributeVec.push_back(
2009-05-12 13:49:36 +08:00
AttributePair(aitr->second.first.get(),aitr->second.second));
2002-07-09 17:35:42 +08:00
}
2005-02-02 23:08:55 +08:00
else if ((as.attributeVec.back().second & StateAttribute::OVERRIDE) && !(aitr->second.second & StateAttribute::PROTECTED)) // check the existing override flag
2002-07-09 17:35:42 +08:00
{
2004-09-03 03:10:33 +08:00
// push existing back since override keeps the previous value.
2002-07-09 17:35:42 +08:00
as.attributeVec.push_back(as.attributeVec.back());
}
2005-02-02 23:08:55 +08:00
else
2002-07-09 17:35:42 +08:00
{
2004-09-03 03:10:33 +08:00
// no override on so simply push incoming pair to back.
2002-07-09 17:35:42 +08:00
as.attributeVec.push_back(
2009-05-12 13:49:36 +08:00
AttributePair(aitr->second.first.get(),aitr->second.second));
2002-07-09 17:35:42 +08:00
}
as.changed = true;
}
}
2005-05-10 21:56:05 +08:00
inline void State::pushUniformList(UniformMap& uniformMap,const StateSet::UniformList& uniformList)
{
for(StateSet::UniformList::const_iterator aitr=uniformList.begin();
aitr!=uniformList.end();
++aitr)
{
// get the attribute stack for incoming type {aitr->first}.
UniformStack& us = uniformMap[aitr->first];
if (us.uniformVec.empty())
{
// first pair so simply push incoming pair to back.
us.uniformVec.push_back(
UniformStack::UniformPair(aitr->second.first.get(),aitr->second.second));
}
else if ((us.uniformVec.back().second & StateAttribute::OVERRIDE) && !(aitr->second.second & StateAttribute::PROTECTED)) // check the existing override flag
{
// push existing back since override keeps the previous value.
us.uniformVec.push_back(us.uniformVec.back());
}
else
{
// no override on so simply push incoming pair to back.
us.uniformVec.push_back(
UniformStack::UniformPair(aitr->second.first.get(),aitr->second.second));
}
}
}
2002-07-09 17:35:42 +08:00
inline void State::popModeList(ModeMap& modeMap,const StateSet::ModeList& modeList)
{
for(StateSet::ModeList::const_iterator mitr=modeList.begin();
mitr!=modeList.end();
++mitr)
{
2004-09-03 03:10:33 +08:00
// get the mode stack for incoming GLmode {mitr->first}.
2002-07-09 17:35:42 +08:00
ModeStack& ms = modeMap[mitr->first];
if (!ms.valueVec.empty())
{
ms.valueVec.pop_back();
}
ms.changed = true;
}
}
inline void State::popAttributeList(AttributeMap& attributeMap,const StateSet::AttributeList& attributeList)
{
for(StateSet::AttributeList::const_iterator aitr=attributeList.begin();
aitr!=attributeList.end();
++aitr)
{
2004-09-03 03:10:33 +08:00
// get the attribute stack for incoming type {aitr->first}.
2002-07-09 17:35:42 +08:00
AttributeStack& as = attributeMap[aitr->first];
if (!as.attributeVec.empty())
{
as.attributeVec.pop_back();
}
as.changed = true;
}
}
2005-05-10 21:56:05 +08:00
inline void State::popUniformList(UniformMap& uniformMap,const StateSet::UniformList& uniformList)
{
for(StateSet::UniformList::const_iterator aitr=uniformList.begin();
aitr!=uniformList.end();
++aitr)
{
// get the attribute stack for incoming type {aitr->first}.
UniformStack& us = uniformMap[aitr->first];
if (!us.uniformVec.empty())
{
us.uniformVec.pop_back();
}
}
}
2002-07-09 17:35:42 +08:00
inline void State::applyModeList(ModeMap& modeMap,const StateSet::ModeList& modeList)
{
StateSet::ModeList::const_iterator ds_mitr = modeList.begin();
ModeMap::iterator this_mitr=modeMap.begin();
while (this_mitr!=modeMap.end() && ds_mitr!=modeList.end())
{
if (this_mitr->first<ds_mitr->first)
{
// note GLMode = this_mitr->first
ModeStack& ms = this_mitr->second;
if (ms.changed)
{
ms.changed = false;
if (!ms.valueVec.empty())
{
bool new_value = ms.valueVec.back() & StateAttribute::ON;
applyMode(this_mitr->first,new_value,ms);
}
else
{
// assume default of disabled.
applyMode(this_mitr->first,ms.global_default_value,ms);
}
}
++this_mitr;
}
else if (ds_mitr->first<this_mitr->first)
{
2005-02-02 23:08:55 +08:00
// ds_mitr->first is a new mode, therefore
2002-07-09 17:35:42 +08:00
// need to insert a new mode entry for ds_mistr->first.
ModeStack& ms = modeMap[ds_mitr->first];
bool new_value = ds_mitr->second & StateAttribute::ON;
applyMode(ds_mitr->first,new_value,ms);
// will need to disable this mode on next apply so set it to changed.
ms.changed = true;
++ds_mitr;
}
else
{
2004-09-03 03:10:33 +08:00
// this_mitr & ds_mitr refer to the same mode, check the override
// if any otherwise just apply the incoming mode.
2002-07-09 17:35:42 +08:00
ModeStack& ms = this_mitr->second;
2002-08-05 20:40:24 +08:00
if (!ms.valueVec.empty() && (ms.valueVec.back() & StateAttribute::OVERRIDE) && !(ds_mitr->second & StateAttribute::PROTECTED))
2002-07-09 17:35:42 +08:00
{
2004-09-14 01:19:05 +08:00
// override is on, just treat as a normal apply on modes.
2002-07-09 17:35:42 +08:00
if (ms.changed)
{
ms.changed = false;
bool new_value = ms.valueVec.back() & StateAttribute::ON;
applyMode(this_mitr->first,new_value,ms);
}
}
else
{
2004-09-03 03:10:33 +08:00
// no override on or no previous entry, therefore consider incoming mode.
2002-07-09 17:35:42 +08:00
bool new_value = ds_mitr->second & StateAttribute::ON;
if (applyMode(ds_mitr->first,new_value,ms))
{
ms.changed = true;
}
}
++this_mitr;
++ds_mitr;
}
}
// iterator over the remaining state modes to apply any previous changes.
for(;
this_mitr!=modeMap.end();
++this_mitr)
{
// note GLMode = this_mitr->first
ModeStack& ms = this_mitr->second;
if (ms.changed)
{
ms.changed = false;
if (!ms.valueVec.empty())
{
bool new_value = ms.valueVec.back() & StateAttribute::ON;
applyMode(this_mitr->first,new_value,ms);
}
else
{
// assume default of disabled.
applyMode(this_mitr->first,ms.global_default_value,ms);
}
}
2005-02-02 23:08:55 +08:00
}
2002-07-09 17:35:42 +08:00
2004-09-03 03:10:33 +08:00
// iterator over the remaining incoming modes to apply any new mode.
2002-07-09 17:35:42 +08:00
for(;
ds_mitr!=modeList.end();
++ds_mitr)
{
ModeStack& ms = modeMap[ds_mitr->first];
bool new_value = ds_mitr->second & StateAttribute::ON;
applyMode(ds_mitr->first,new_value,ms);
// will need to disable this mode on next apply so set it to changed.
ms.changed = true;
}
}
2010-01-08 00:49:12 +08:00
inline void State::applyModeListOnTexUnit(unsigned int unit,ModeMap& modeMap,const StateSet::ModeList& modeList)
{
StateSet::ModeList::const_iterator ds_mitr = modeList.begin();
ModeMap::iterator this_mitr=modeMap.begin();
while (this_mitr!=modeMap.end() && ds_mitr!=modeList.end())
{
if (this_mitr->first<ds_mitr->first)
{
// note GLMode = this_mitr->first
ModeStack& ms = this_mitr->second;
if (ms.changed)
{
ms.changed = false;
if (!ms.valueVec.empty())
{
bool new_value = ms.valueVec.back() & StateAttribute::ON;
applyModeOnTexUnit(unit,this_mitr->first,new_value,ms);
}
else
{
// assume default of disabled.
applyModeOnTexUnit(unit,this_mitr->first,ms.global_default_value,ms);
}
}
++this_mitr;
}
else if (ds_mitr->first<this_mitr->first)
{
// ds_mitr->first is a new mode, therefore
// need to insert a new mode entry for ds_mistr->first.
ModeStack& ms = modeMap[ds_mitr->first];
bool new_value = ds_mitr->second & StateAttribute::ON;
applyModeOnTexUnit(unit,ds_mitr->first,new_value,ms);
// will need to disable this mode on next apply so set it to changed.
ms.changed = true;
++ds_mitr;
}
else
{
// this_mitr & ds_mitr refer to the same mode, check the override
// if any otherwise just apply the incoming mode.
ModeStack& ms = this_mitr->second;
if (!ms.valueVec.empty() && (ms.valueVec.back() & StateAttribute::OVERRIDE) && !(ds_mitr->second & StateAttribute::PROTECTED))
{
// override is on, just treat as a normal apply on modes.
if (ms.changed)
{
ms.changed = false;
bool new_value = ms.valueVec.back() & StateAttribute::ON;
applyModeOnTexUnit(unit,this_mitr->first,new_value,ms);
}
}
else
{
// no override on or no previous entry, therefore consider incoming mode.
bool new_value = ds_mitr->second & StateAttribute::ON;
if (applyModeOnTexUnit(unit,ds_mitr->first,new_value,ms))
{
ms.changed = true;
}
}
++this_mitr;
++ds_mitr;
}
}
// iterator over the remaining state modes to apply any previous changes.
for(;
this_mitr!=modeMap.end();
++this_mitr)
{
// note GLMode = this_mitr->first
ModeStack& ms = this_mitr->second;
if (ms.changed)
{
ms.changed = false;
if (!ms.valueVec.empty())
{
bool new_value = ms.valueVec.back() & StateAttribute::ON;
applyModeOnTexUnit(unit,this_mitr->first,new_value,ms);
}
else
{
// assume default of disabled.
applyModeOnTexUnit(unit,this_mitr->first,ms.global_default_value,ms);
}
}
}
// iterator over the remaining incoming modes to apply any new mode.
for(;
ds_mitr!=modeList.end();
++ds_mitr)
{
ModeStack& ms = modeMap[ds_mitr->first];
bool new_value = ds_mitr->second & StateAttribute::ON;
applyModeOnTexUnit(unit,ds_mitr->first,new_value,ms);
// will need to disable this mode on next apply so set it to changed.
ms.changed = true;
}
}
2002-07-09 17:35:42 +08:00
inline void State::applyAttributeList(AttributeMap& attributeMap,const StateSet::AttributeList& attributeList)
{
StateSet::AttributeList::const_iterator ds_aitr=attributeList.begin();
AttributeMap::iterator this_aitr=attributeMap.begin();
while (this_aitr!=attributeMap.end() && ds_aitr!=attributeList.end())
{
if (this_aitr->first<ds_aitr->first)
{
// note attribute type = this_aitr->first
AttributeStack& as = this_aitr->second;
if (as.changed)
{
as.changed = false;
if (!as.attributeVec.empty())
{
const StateAttribute* new_attr = as.attributeVec.back().first;
applyAttribute(new_attr,as);
}
else
{
applyGlobalDefaultAttribute(as);
}
}
++this_aitr;
}
else if (ds_aitr->first<this_aitr->first)
{
2005-02-02 23:08:55 +08:00
// ds_aitr->first is a new attribute, therefore
2004-09-14 01:19:05 +08:00
// need to insert a new attribute entry for ds_aitr->first.
2002-07-09 17:35:42 +08:00
AttributeStack& as = attributeMap[ds_aitr->first];
const StateAttribute* new_attr = ds_aitr->second.first.get();
applyAttribute(new_attr,as);
as.changed = true;
++ds_aitr;
}
else
{
2004-09-03 03:10:33 +08:00
// this_mitr & ds_mitr refer to the same attribute, check the override
// if any otherwise just apply the incoming attribute
2002-07-09 17:35:42 +08:00
AttributeStack& as = this_aitr->second;
2002-08-05 20:40:24 +08:00
if (!as.attributeVec.empty() && (as.attributeVec.back().second & StateAttribute::OVERRIDE) && !(ds_aitr->second.second & StateAttribute::PROTECTED))
2002-07-09 17:35:42 +08:00
{
2005-04-13 20:00:28 +08:00
// override is on, just treat as a normal apply on attribute.
2002-07-09 17:35:42 +08:00
if (as.changed)
{
as.changed = false;
const StateAttribute* new_attr = as.attributeVec.back().first;
applyAttribute(new_attr,as);
}
}
else
{
2005-04-13 20:00:28 +08:00
// no override on or no previous entry, therefore consider incoming attribute.
2002-07-09 17:35:42 +08:00
const StateAttribute* new_attr = ds_aitr->second.first.get();
if (applyAttribute(new_attr,as))
{
as.changed = true;
}
}
++this_aitr;
++ds_aitr;
}
}
2005-04-13 20:00:28 +08:00
// iterator over the remaining state attributes to apply any previous changes.
2002-07-09 17:35:42 +08:00
for(;
this_aitr!=attributeMap.end();
++this_aitr)
{
// note attribute type = this_aitr->first
AttributeStack& as = this_aitr->second;
if (as.changed)
{
as.changed = false;
if (!as.attributeVec.empty())
{
const StateAttribute* new_attr = as.attributeVec.back().first;
applyAttribute(new_attr,as);
}
else
{
applyGlobalDefaultAttribute(as);
}
}
2005-02-02 23:08:55 +08:00
}
2002-07-09 17:35:42 +08:00
2005-04-13 20:00:28 +08:00
// iterator over the remaining incoming attribute to apply any new attribute.
2002-07-09 17:35:42 +08:00
for(;
ds_aitr!=attributeList.end();
++ds_aitr)
{
2005-02-02 23:08:55 +08:00
// ds_aitr->first is a new attribute, therefore
2004-09-14 01:19:05 +08:00
// need to insert a new attribute entry for ds_aitr->first.
2002-07-09 17:35:42 +08:00
AttributeStack& as = attributeMap[ds_aitr->first];
const StateAttribute* new_attr = ds_aitr->second.first.get();
applyAttribute(new_attr,as);
// will need to update this attribute on next apply so set it to changed.
as.changed = true;
}
}
2010-01-08 00:49:12 +08:00
inline void State::applyAttributeListOnTexUnit(unsigned int unit,AttributeMap& attributeMap,const StateSet::AttributeList& attributeList)
{
StateSet::AttributeList::const_iterator ds_aitr=attributeList.begin();
AttributeMap::iterator this_aitr=attributeMap.begin();
while (this_aitr!=attributeMap.end() && ds_aitr!=attributeList.end())
{
if (this_aitr->first<ds_aitr->first)
{
// note attribute type = this_aitr->first
AttributeStack& as = this_aitr->second;
if (as.changed)
{
as.changed = false;
if (!as.attributeVec.empty())
{
const StateAttribute* new_attr = as.attributeVec.back().first;
applyAttributeOnTexUnit(unit,new_attr,as);
}
else
{
applyGlobalDefaultAttributeOnTexUnit(unit,as);
}
}
++this_aitr;
}
else if (ds_aitr->first<this_aitr->first)
{
// ds_aitr->first is a new attribute, therefore
// need to insert a new attribute entry for ds_aitr->first.
AttributeStack& as = attributeMap[ds_aitr->first];
const StateAttribute* new_attr = ds_aitr->second.first.get();
applyAttributeOnTexUnit(unit,new_attr,as);
as.changed = true;
++ds_aitr;
}
else
{
// this_mitr & ds_mitr refer to the same attribute, check the override
// if any otherwise just apply the incoming attribute
AttributeStack& as = this_aitr->second;
if (!as.attributeVec.empty() && (as.attributeVec.back().second & StateAttribute::OVERRIDE) && !(ds_aitr->second.second & StateAttribute::PROTECTED))
{
// override is on, just treat as a normal apply on attribute.
if (as.changed)
{
as.changed = false;
const StateAttribute* new_attr = as.attributeVec.back().first;
applyAttributeOnTexUnit(unit,new_attr,as);
}
}
else
{
// no override on or no previous entry, therefore consider incoming attribute.
const StateAttribute* new_attr = ds_aitr->second.first.get();
if (applyAttributeOnTexUnit(unit,new_attr,as))
{
as.changed = true;
}
}
++this_aitr;
++ds_aitr;
}
}
// iterator over the remaining state attributes to apply any previous changes.
for(;
this_aitr!=attributeMap.end();
++this_aitr)
{
// note attribute type = this_aitr->first
AttributeStack& as = this_aitr->second;
if (as.changed)
{
as.changed = false;
if (!as.attributeVec.empty())
{
const StateAttribute* new_attr = as.attributeVec.back().first;
applyAttributeOnTexUnit(unit,new_attr,as);
}
else
{
applyGlobalDefaultAttributeOnTexUnit(unit,as);
}
}
}
// iterator over the remaining incoming attribute to apply any new attribute.
for(;
ds_aitr!=attributeList.end();
++ds_aitr)
{
// ds_aitr->first is a new attribute, therefore
// need to insert a new attribute entry for ds_aitr->first.
AttributeStack& as = attributeMap[ds_aitr->first];
const StateAttribute* new_attr = ds_aitr->second.first.get();
applyAttributeOnTexUnit(unit,new_attr,as);
// will need to update this attribute on next apply so set it to changed.
as.changed = true;
}
}
2005-05-10 21:56:05 +08:00
inline void State::applyUniformList(UniformMap& uniformMap,const StateSet::UniformList& uniformList)
{
if (!_lastAppliedProgramObject) return;
StateSet::UniformList::const_iterator ds_aitr=uniformList.begin();
UniformMap::iterator this_aitr=uniformMap.begin();
while (this_aitr!=uniformMap.end() && ds_aitr!=uniformList.end())
{
if (this_aitr->first<ds_aitr->first)
{
// note attribute type = this_aitr->first
UniformStack& as = this_aitr->second;
if (!as.uniformVec.empty())
{
_lastAppliedProgramObject->apply(*as.uniformVec.back().first);
}
++this_aitr;
}
else if (ds_aitr->first<this_aitr->first)
{
_lastAppliedProgramObject->apply(*(ds_aitr->second.first.get()));
++ds_aitr;
}
else
{
// this_mitr & ds_mitr refer to the same attribute, check the override
// if any otherwise just apply the incoming attribute
UniformStack& as = this_aitr->second;
if (!as.uniformVec.empty() && (as.uniformVec.back().second & StateAttribute::OVERRIDE) && !(ds_aitr->second.second & StateAttribute::PROTECTED))
{
// override is on, just treat as a normal apply on uniform.
_lastAppliedProgramObject->apply(*as.uniformVec.back().first);
}
else
{
// no override on or no previous entry, therefore consider incoming attribute.
_lastAppliedProgramObject->apply(*(ds_aitr->second.first.get()));
}
++this_aitr;
++ds_aitr;
}
}
// iterator over the remaining state attributes to apply any previous changes.
for(;
this_aitr!=uniformMap.end();
++this_aitr)
{
// note attribute type = this_aitr->first
UniformStack& as = this_aitr->second;
if (!as.uniformVec.empty())
{
_lastAppliedProgramObject->apply(*as.uniformVec.back().first);
}
}
// iterator over the remaining incoming attribute to apply any new attribute.
for(;
ds_aitr!=uniformList.end();
++ds_aitr)
{
_lastAppliedProgramObject->apply(*(ds_aitr->second.first.get()));
}
}
2002-07-09 17:35:42 +08:00
inline void State::applyModeMap(ModeMap& modeMap)
{
for(ModeMap::iterator mitr=modeMap.begin();
mitr!=modeMap.end();
++mitr)
{
// note GLMode = mitr->first
ModeStack& ms = mitr->second;
if (ms.changed)
{
ms.changed = false;
if (!ms.valueVec.empty())
{
bool new_value = ms.valueVec.back() & StateAttribute::ON;
applyMode(mitr->first,new_value,ms);
}
else
{
// assume default of disabled.
applyMode(mitr->first,ms.global_default_value,ms);
}
2005-02-02 23:08:55 +08:00
2002-07-09 17:35:42 +08:00
}
2005-02-02 23:08:55 +08:00
}
2002-07-09 17:35:42 +08:00
}
2010-01-08 00:49:12 +08:00
inline void State::applyModeMapOnTexUnit(unsigned int unit,ModeMap& modeMap)
{
for(ModeMap::iterator mitr=modeMap.begin();
mitr!=modeMap.end();
++mitr)
{
// note GLMode = mitr->first
ModeStack& ms = mitr->second;
if (ms.changed)
{
ms.changed = false;
if (!ms.valueVec.empty())
{
bool new_value = ms.valueVec.back() & StateAttribute::ON;
applyModeOnTexUnit(unit,mitr->first,new_value,ms);
}
else
{
// assume default of disabled.
applyModeOnTexUnit(unit,mitr->first,ms.global_default_value,ms);
}
}
}
}
2002-07-09 17:35:42 +08:00
inline void State::applyAttributeMap(AttributeMap& attributeMap)
{
for(AttributeMap::iterator aitr=attributeMap.begin();
aitr!=attributeMap.end();
++aitr)
{
AttributeStack& as = aitr->second;
if (as.changed)
{
as.changed = false;
if (!as.attributeVec.empty())
{
const StateAttribute* new_attr = as.attributeVec.back().first;
applyAttribute(new_attr,as);
}
else
{
applyGlobalDefaultAttribute(as);
}
2005-02-02 23:08:55 +08:00
2002-07-09 17:35:42 +08:00
}
2005-02-02 23:08:55 +08:00
}
2002-07-09 17:35:42 +08:00
}
2010-01-08 00:49:12 +08:00
inline void State::applyAttributeMapOnTexUnit(unsigned int unit,AttributeMap& attributeMap)
{
for(AttributeMap::iterator aitr=attributeMap.begin();
aitr!=attributeMap.end();
++aitr)
{
AttributeStack& as = aitr->second;
if (as.changed)
{
as.changed = false;
if (!as.attributeVec.empty())
{
const StateAttribute* new_attr = as.attributeVec.back().first;
applyAttributeOnTexUnit(unit,new_attr,as);
}
else
{
applyGlobalDefaultAttributeOnTexUnit(unit,as);
}
}
}
}
2005-05-10 21:56:05 +08:00
inline void State::applyUniformMap(UniformMap& uniformMap)
{
if (!_lastAppliedProgramObject) return;
for(UniformMap::iterator aitr=uniformMap.begin();
aitr!=uniformMap.end();
++aitr)
{
UniformStack& as = aitr->second;
if (!as.uniformVec.empty())
{
_lastAppliedProgramObject->apply(*as.uniformVec.back().first);
}
}
}
2010-01-08 00:49:12 +08:00
inline bool State::setActiveTextureUnit( unsigned int unit )
{
if (unit!=_currentActiveTextureUnit)
{
if (_glActiveTexture && unit < (unsigned int)(maximum(_glMaxTextureCoords,_glMaxTextureUnits)) )
{
_glActiveTexture(GL_TEXTURE0+unit);
_currentActiveTextureUnit = unit;
}
else
{
return unit==0;
}
}
return true;
}
2006-09-19 04:54:48 +08:00
2002-02-03 20:33:41 +08:00
}
2001-01-11 00:32:10 +08:00
#endif