OsgMaterial.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013-2016, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_GRAPHICS_OSGMATERIAL_H
#define SURGSIM_GRAPHICS_OSGMATERIAL_H
#include <boost/any.hpp>
#include <osg/Material>
#include <osg/StateSet>
#include <set>
#include "SurgSim/Graphics/Material.h"
namespace SurgSim
{
namespace Graphics
{
class MaterialFace;
class OsgProgram;
class OsgUniformBase;
class OsgMaterial : public Material
{
public:
explicit OsgMaterial(const std::string& name);
SURGSIM_CLASSNAME(SurgSim::Graphics::OsgMaterial);
void addUniform(std::shared_ptr<UniformBase> uniform) override;
void addUniform(const std::string& type, const std::string& name) override;
void addUniform(const std::string& type, const std::string& name, const boost::any& value);
bool removeUniform(std::shared_ptr<UniformBase> uniform) override;
bool removeUniform(const std::string& name) override;
size_t getNumUniforms() const override;
std::shared_ptr<UniformBase> getUniform(size_t index) const override;
std::shared_ptr<UniformBase> getUniform(const std::string& name) const override;
bool hasUniform(const std::string& name) const override;
bool setProgram(std::shared_ptr<Program> program) override;
std::shared_ptr<Program> getProgram() const override;
void clearProgram() override;
osg::ref_ptr<osg::StateSet> getOsgStateSet() const;
bool doInitialize() override;
bool doWakeUp() override;
private:
osg::ref_ptr<osg::StateSet> m_stateSet;
std::vector<std::shared_ptr<OsgUniformBase>> m_uniforms;
std::shared_ptr<OsgProgram> m_program;
};
std::shared_ptr<OsgMaterial> buildMaterial(
const std::string& vertexShaderName,
const std::string& fragmentShaderName);
}; // namespace Graphics
}; // namespace SurgSim
#endif // SURGSIM_GRAPHICS_OSGMATERIAL_H
SurgSim::Graphics::OsgMaterial::getNumUniforms
size_t getNumUniforms() const override
Returns the number of uniforms in this material.
Definition: OsgMaterial.cpp:111
SurgSim::Graphics::OsgMaterial::getProgram
std::shared_ptr< Program > getProgram() const override
Gets the program used by this material.
Definition: OsgMaterial.cpp:182
SurgSim::Graphics::OsgMaterial::m_stateSet
osg::ref_ptr< osg::StateSet > m_stateSet
OSG state set which provides material properties in the scenegraph.
Definition: OsgMaterial.h:102
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
Material.h
SurgSim::Graphics::OsgMaterial::removeUniform
bool removeUniform(std::shared_ptr< UniformBase > uniform) override
Removes a uniform from this material.
Definition: OsgMaterial.cpp:84
SurgSim::Graphics::OsgMaterial::m_program
std::shared_ptr< OsgProgram > m_program
Shader used by this material.
Definition: OsgMaterial.h:108
SurgSim::Graphics::OsgMaterial::m_uniforms
std::vector< std::shared_ptr< OsgUniformBase > > m_uniforms
Uniforms used by this material.
Definition: OsgMaterial.h:105
SurgSim::Graphics::Material
Base class that defines the interface for graphics materials.
Definition: Material.h:39
SurgSim::Graphics::OsgMaterial::setProgram
bool setProgram(std::shared_ptr< Program > program) override
Sets the shader used by this material.
Definition: OsgMaterial.cpp:163
SurgSim::Graphics::OsgMaterial::doWakeUp
bool doWakeUp() override
Interface to be implemented by derived classes.
Definition: OsgMaterial.cpp:205
SurgSim::Graphics::OsgMaterial::addUniform
void addUniform(std::shared_ptr< UniformBase > uniform) override
Adds a uniform to this material.
Definition: OsgMaterial.cpp:46
SurgSim::Graphics::OsgMaterial::SURGSIM_CLASSNAME
SURGSIM_CLASSNAME(SurgSim::Graphics::OsgMaterial)
SurgSim::Graphics::OsgMaterial::getUniform
std::shared_ptr< UniformBase > getUniform(size_t index) const override
Gets a uniform in this material.
Definition: OsgMaterial.cpp:116
SurgSim::Graphics::buildMaterial
std::shared_ptr< OsgMaterial > buildMaterial(const std::string &vertexShaderName, const std::string &fragmentShaderName)
Utility function to build the material.
Definition: OsgMaterial.cpp:215
SurgSim::Graphics::OsgMaterial::hasUniform
bool hasUniform(const std::string &name) const override
Checks if this material has a uniform with the given name.
Definition: OsgMaterial.cpp:158
SurgSim::Graphics::OsgMaterial::getOsgStateSet
osg::ref_ptr< osg::StateSet > getOsgStateSet() const
Definition: OsgMaterial.cpp:210
SurgSim::Graphics::OsgMaterial::clearProgram
void clearProgram() override
Removes the shader from the material, falling back to fixed-function pipeline.
Definition: OsgMaterial.cpp:187
SurgSim::Graphics::OsgMaterial::OsgMaterial
OsgMaterial(const std::string &name)
Constructor.
Definition: OsgMaterial.cpp:39
SurgSim::Graphics::OsgMaterial
OSG-based implementation of a graphics material.
Definition: OsgMaterial.h:45
SurgSim::Graphics::OsgMaterial::doInitialize
bool doInitialize() override
Interface to be implemented by derived classes.
Definition: OsgMaterial.cpp:196