16 #ifndef SURGSIM_GRAPHICS_OSGTEXTUREUNIFORM_INL_H 17 #define SURGSIM_GRAPHICS_OSGTEXTUREUNIFORM_INL_H 19 #include <osg/PointSprite> 22 #include "SurgSim/Graphics/OsgTexture.h" 23 #include "SurgSim/Graphics/OsgTexture1d.h" 24 #include "SurgSim/Graphics/OsgTexture2d.h" 25 #include "SurgSim/Graphics/OsgTexture3d.h" 26 #include "SurgSim/Graphics/OsgTextureCubeMap.h" 27 #include "SurgSim/Graphics/OsgTextureRectangle.h" 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 return SurgSim::Graphics::getGlslType<T>();
142 #endif // SURGSIM_GRAPHICS_OSGTEXTUREUNIFORM_INL_H Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
Definition: MockObjects.h:47
#define SURGSIM_ASSERT(condition)
Assert that condition is true.
Definition: Assert.h:77
OsgTextureUniform(const std::string &name)
Constructor.
Definition: OsgTextureUniform-inl.h:37
The header that provides the assertion API.
OSG implementation of graphics uniform with a texture value.
Definition: OsgTextureUniform.h:30