OsgProgram.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_OSGPROGRAM_H
#define SURGSIM_GRAPHICS_OSGPROGRAM_H
#include "SurgSim/Graphics/Program.h"
#include <osg/Program>
#include <osg/StateSet>
#include <string>
#include <memory>
#include <array>
namespace SurgSim
{
namespace Framework
{
class ApplicationData;
}
namespace Graphics
{
class OsgProgram : public Program
{
public:
OsgProgram();
bool hasVertexShader() const override;
void clearVertexShader() override;
bool loadVertexShader(const std::string& filePath) override;
void setVertexShaderSource(const std::string& source) override;
bool getVertexShaderSource(std::string* source) const override;
bool hasGeometryShader() const override;
void clearGeometryShader() override;
bool loadGeometryShader(const std::string& filePath) override;
void setGeometryShaderSource(const std::string& source) override;
bool getGeometryShaderSource(std::string* source) const override;
bool hasFragmentShader() const override;
void clearFragmentShader() override;
bool loadFragmentShader(const std::string& filePath) override;
void setFragmentShaderSource(const std::string& source) override;
bool getFragmentShaderSource(std::string* source) const override;
void setGlobalScope(bool val) override;
bool isGlobalScope() const override;
osg::ref_ptr<osg::Program> getOsgProgram() const;
void addToStateSet(osg::StateSet* stateSet);
void removeFromStateSet(osg::StateSet* stateSet);
private:
osg::ref_ptr<osg::Program> m_program;
// Type of shader, internal use only
enum ShaderType
{
SHADER_TYPE_VERTEX = 0,
SHADER_TYPE_FRAGMENT,
SHADER_TYPE_GEOMETRY,
SHADER_TYPE_COUNT
};
std::array<osg::ref_ptr<osg::Shader>, SHADER_TYPE_COUNT> m_osgShaders;
bool hasShader(int shaderType) const;
void clearShader(int shaderType);
bool loadShaderSource(const std::string& filePath, int shaderType);
virtual void setShaderSource(const std::string& source, int shaderType);
virtual bool getShaderSource(int shaderType, std::string* source) const;
osg::ref_ptr<osg::Shader> getOrCreateOsgShader(int shaderType);
bool m_globalScope;
};
std::shared_ptr<SurgSim::Graphics::OsgProgram> loadProgram(const SurgSim::Framework::ApplicationData& data,
const std::string& name);
std::shared_ptr<SurgSim::Graphics::OsgProgram> loadProgram(const SurgSim::Framework::ApplicationData& data,
const std::string& vertexShaderName, const std::string& fragmentShaderName);
}; // namespace Graphics
}; // namespace SurgSim
#endif // SURGSIM_GRAPHICS_OSGPROGRAM_H
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Framework::ApplicationData
Enable searching for files in a given list of paths, give access to the current directory and wrap bo...
Definition: ApplicationData.h:39
SurgSim::Graphics::OsgProgram::SHADER_TYPE_FRAGMENT
Definition: OsgProgram.h:103
SurgSim::Graphics::OsgProgram::ShaderType
ShaderType
Definition: OsgProgram.h:100
SurgSim::Graphics::OsgProgram
OSG-based implementation of a graphics shader.
Definition: OsgProgram.h:43
SurgSim::Graphics::OsgProgram::m_program
osg::ref_ptr< osg::Program > m_program
OSG program attribute.
Definition: OsgProgram.h:97
SurgSim::Graphics::OsgProgram::SHADER_TYPE_GEOMETRY
Definition: OsgProgram.h:104
SurgSim::Graphics::Program
Base class that defines the interface for graphics programs.
Definition: Program.h:39
Program.h
SurgSim::Graphics::OsgProgram::m_osgShaders
std::array< osg::ref_ptr< osg::Shader >, SHADER_TYPE_COUNT > m_osgShaders
Storage of the osg objects.
Definition: OsgProgram.h:109
SurgSim::Graphics::OsgProgram::m_globalScope
bool m_globalScope
Is the shader supposed to be used globally.
Definition: OsgProgram.h:141
SurgSim::Graphics::loadProgram
std::shared_ptr< OsgProgram > loadProgram(const SurgSim::Framework::ApplicationData &data, const std::string &name)
Utility function, load a program from a set of shader files.
Definition: OsgProgram.cpp:217