16 #ifndef SURGSIM_GRAPHICS_OSGTEXTUREUNIFORM_INL_H
17 #define SURGSIM_GRAPHICS_OSGTEXTUREUNIFORM_INL_H
41 osg::Uniform::Type osgUniformType = getOsgUniformType<std::shared_ptr<T>>();
42 SURGSIM_ASSERT(osgUniformType != osg::Uniform::UNDEFINED) <<
"Failed to get OSG uniform type!";
51 if (m_stateset !=
nullptr)
53 m_stateset->setTextureAttributeAndModes(m_unit, m_texture->getOsgTexture(), osg::StateAttribute::ON);
66 SURGSIM_ASSERT(m_stateset ==
nullptr) <<
"Unexpected addToStateSet for OsgTextureUniform.";
68 const osg::StateSet::TextureAttributeList& textures = stateSet->getTextureAttributeList();
72 int availableUnit = m_minimumTextureUnit;
73 if (textures.size() > m_minimumTextureUnit)
75 for (
auto it = textures.begin() + m_minimumTextureUnit; it != textures.end(); ++it)
85 m_unit = availableUnit;
87 SURGSIM_ASSERT(m_texture !=
nullptr) <<
"Tried to add this uniform without a valid Texture";
88 stateSet->setTextureAttributeAndModes(m_unit, m_texture->getOsgTexture(),
89 osg::StateAttribute::ON);
90 SURGSIM_ASSERT(m_uniform->set(static_cast<int>(m_unit))) <<
"Failed to set OSG texture uniform unit!" <<
91 " Uniform: " << getName() <<
" unit: " << m_unit;
92 stateSet->addUniform(m_uniform);
93 m_stateset = stateSet;
99 SURGSIM_ASSERT(m_stateset != stateSet) <<
"Unexpected Remove for OsgTextureUniform";
100 stateSet->removeTextureAttribute(m_unit, m_texture->getOsgTexture());
101 stateSet->removeUniform(m_uniform);
102 m_stateset =
nullptr;
108 SURGSIM_ASSERT(m_unit == -1) <<
"Can't set minimumTextureUnit after the unit has been assigned.";
109 m_minimumTextureUnit = unit;
115 return m_minimumTextureUnit;
121 #endif // SURGSIM_GRAPHICS_OSGTEXTUREUNIFORM_INL_H
Definition: DriveElementFromInputBehavior.cpp:27
#define SURGSIM_ASSERT(condition)
Assert that condition is true.
Definition: Assert.h:77
virtual void set(const std::shared_ptr< T > &value)
Sets the value of the uniform.
Definition: OsgTextureUniform-inl.h:48
virtual void removeFromStateSet(osg::StateSet *stateSet)
Removes this uniform from the OSG state set.
Definition: OsgTextureUniform-inl.h:97
OsgTextureUniform(const std::string &name)
Constructor.
Definition: OsgTextureUniform-inl.h:35
void setMinimumTextureUnit(size_t unit)
This is the texture unit from where the search for a free texture unit will start.
Definition: OsgTextureUniform-inl.h:106
The header that provides the assertion API.
virtual const std::shared_ptr< T > & get() const
Returns the value of the uniform.
Definition: OsgTextureUniform-inl.h:58
OSG implementation of graphics uniform with a texture value.
Definition: OsgTextureUniform.h:30
virtual void addToStateSet(osg::StateSet *stateSet)
Adds this uniform to the OSG state set.
Definition: OsgTextureUniform-inl.h:64
#define SURGSIM_ADD_RW_PROPERTY(class, type, property, getter, setter)
A macro to register getter and setter for a property that is readable and writeable, order of getter and setter agrees with 'RW'.
Definition: Accessible.h:199
size_t getMinimumTextureUnit() const
Definition: OsgTextureUniform-inl.h:113