Go to the documentation of this file.
16 #ifndef SURGSIM_GRAPHICS_OSGTEXTUREUNIFORM_INL_H
17 #define SURGSIM_GRAPHICS_OSGTEXTUREUNIFORM_INL_H
19 #include <osg/PointSprite>
41 MinimumTextureUnit, getMinimumTextureUnit, setMinimumTextureUnit);
43 osg::Uniform::Type osgUniformType = getOsgUniformType<std::shared_ptr<T>>();
44 SURGSIM_ASSERT(osgUniformType != osg::Uniform::UNDEFINED) <<
"Failed to get OSG uniform type!";
45 SURGSIM_ASSERT(m_uniform->setType(osgUniformType)) <<
"Failed to set OSG uniform type!";
46 m_uniform->setNumElements(1);
53 if (m_stateset !=
nullptr)
55 m_stateset->setTextureAttributeAndModes(m_unit, m_texture->getOsgTexture(), osg::StateAttribute::ON);
62 m_unit = value.as<
int>();
74 SURGSIM_ASSERT(m_stateset ==
nullptr) <<
"Unexpected addToStateSet for OsgTextureUniform " << getName() <<
".";
76 const osg::StateSet::TextureAttributeList& textures = stateSet->getTextureAttributeList();
80 int availableUnit = m_minimumTextureUnit;
81 if (textures.size() > m_minimumTextureUnit)
83 for (
auto it = textures.begin() + m_minimumTextureUnit; it != textures.end(); ++it)
93 m_unit = availableUnit;
95 SURGSIM_ASSERT(m_texture !=
nullptr) <<
"Tried to add uniform " << getName() <<
" without a valid Texture";
96 if(m_texture->isPointSprite())
98 osg::PointSprite* sprite =
new osg::PointSprite();
99 stateSet->setTextureAttributeAndModes(m_unit, sprite, osg::StateAttribute::ON);
100 stateSet->setMode(GL_VERTEX_PROGRAM_POINT_SIZE, osg::StateAttribute::ON);
102 stateSet->setTextureAttributeAndModes(m_unit, m_texture->getOsgTexture(),
103 osg::StateAttribute::ON);
104 SURGSIM_ASSERT(m_uniform->set(
static_cast<int>(m_unit))) <<
"Failed to set OSG texture uniform unit!" <<
105 " Uniform: " << getName() <<
" unit: " << m_unit;
106 stateSet->addUniform(m_uniform);
107 m_stateset = stateSet;
113 SURGSIM_ASSERT(m_stateset != stateSet) <<
"Unexpected Remove for OsgTextureUniform";
114 stateSet->removeTextureAttribute(m_unit, m_texture->getOsgTexture());
115 stateSet->removeUniform(m_uniform);
116 m_stateset =
nullptr;
122 SURGSIM_ASSERT(m_unit == -1) <<
"Can't set minimumTextureUnit after the unit has been assigned.";
123 m_minimumTextureUnit = unit;
129 return m_minimumTextureUnit;
135 #endif // SURGSIM_GRAPHICS_OSGTEXTUREUNIFORM_INL_H
#define SURGSIM_ASSERT(condition)
Assert that condition is true.
Definition: Assert.h:77
#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,...
Definition: Accessible.h:213
OsgTextureUniform(const std::string &name)
Constructor.
Definition: OsgTextureUniform-inl.h:37
virtual void addToStateSet(osg::StateSet *stateSet)
Adds this uniform to the OSG state set.
Definition: OsgTextureUniform-inl.h:72
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:120
virtual void removeFromStateSet(osg::StateSet *stateSet)
Removes this uniform from the OSG state set.
Definition: OsgTextureUniform-inl.h:111
The header that provides the assertion API.
Definition: CompoundShapeToGraphics.cpp:30
virtual void set(const std::shared_ptr< T > &value)
Sets the value of the uniform.
Definition: OsgTextureUniform-inl.h:50
size_t getMinimumTextureUnit() const
Definition: OsgTextureUniform-inl.h:127
virtual const std::shared_ptr< T > & get() const
Returns the value of the uniform.
Definition: OsgTextureUniform-inl.h:66
string(TOUPPER ${DEVICE} DEVICE_UPPER_CASE) option(BUILD_DEVICE_$
Definition: CMakeLists.txt:38
OSG implementation of graphics uniform with a texture value.
Definition: OsgTextureUniform.h:31