SurgSim::Graphics::OsgProgram Class Reference

OSG-based implementation of a graphics shader. More...

`#include <SurgSim/Graphics/OsgProgram.h>`

Inheritance diagram for SurgSim::Graphics::OsgProgram:

## Public Member Functions

| OsgProgram ()
| Constructor. More...
bool | hasVertexShader () const override
void | clearVertexShader () override
| Removes the vertex shader, returning that portion of the shader program to fixed-function. More...
bool | loadVertexShader (const std::string &filePath) override
| Loads the vertex shader source code from a file. More...
void | setVertexShaderSource (const std::string &source) override
| Set the vertex shader source code. More...
bool | getVertexShaderSource (std::string *source) const override
| Gets the vertex shader source code. More...
bool | hasGeometryShader () const override
void | clearGeometryShader () override
| Removes the geometry shader, returning that portion of the shader program to fixed-function. More...
bool | loadGeometryShader (const std::string &filePath) override
| Loads the geometry shader source code from a file. More...
void | setGeometryShaderSource (const std::string &source) override
| Set the geometry shader source code. More...
bool | getGeometryShaderSource (std::string *source) const override
| Gets the geometry shader source code. More...
bool | hasFragmentShader () const override
void | clearFragmentShader () override
bool | loadFragmentShader (const std::string &filePath) override
| Loads the fragment shader source code from a file. More...
void | setFragmentShaderSource (const std::string &source) override
| Set the fragment shader source code. More...
bool | getFragmentShaderSource (std::string *source) const override
| Gets the fragment shader source code. More...
void | setGlobalScope (bool val) override
| When this is set to true, this shader should be used instead of other shaders that might apply, depending on the hierarchy that is set out. More...
bool | isGlobalScope () const override
| Query if this shader is of global scope. More...
osg::ref_ptr< osg::Program > | getOsgProgram () const
void | addToStateSet (osg::StateSet *stateSet)
| Adds this shader to the OSG state set. More...
void | removeFromStateSet (osg::StateSet *stateSet)
| Removes this uniform from the OSG state set. More...
Public Member Functions inherited from SurgSim::Graphics::Program
virtual | ~Program ()=0
| Destructor. More...
virtual void | clear ()
| Clears the entire shader, returning to fixed-function pipeline. More...

## Private Types

enum | ShaderType { SHADER_TYPE_VERTEX = 0, SHADER_TYPE_FRAGMENT, SHADER_TYPE_GEOMETRY, SHADER_TYPE_COUNT }

## Private Member Functions

bool | hasShader (int shaderType) const
| Check whether there is a shader in use for the given type. More...
void | clearShader (int shaderType)
| Removes the geometry shader, returning that portion of the shader program to fixed-function. More...
bool | loadShaderSource (const std::string &filePath, int shaderType)
| Loads the shader source code from a file. More...
virtual void | setShaderSource (const std::string &source, int shaderType)
| Set the shader source code. More...
virtual bool | getShaderSource (int shaderType, std::string *source) const
| Gets the shader source code. More...
osg::ref_ptr< osg::Shader > | getOrCreateOsgShader (int shaderType)
| Fetches the appropriate shader if it exists, creates it otherwise. More...

## Private Attributes

osg::ref_ptr< osg::Program > | m_program
| OSG program attribute. More...
std::array< osg::ref_ptr< osg::Shader >, SHADER_TYPE_COUNT > | m_osgShaders
| Storage of the osg objects. More...
bool | m_globalScope
| Is the shader supposed to be used globally. More...

## Detailed Description

OSG-based implementation of a graphics shader.

Wraps an osg::Program which manages the geometry, vertex, and fragment shaders. The osg::Program is added to the osg::StateSet of an osg::Node to use the shaders for the rendering of that node's geometry.

## Member Enumeration Documentation

## ShaderType

enum SurgSim::Graphics::OsgProgram::ShaderType

private

Enumerator
SHADER_TYPE_VERTEX |
SHADER_TYPE_FRAGMENT |
SHADER_TYPE_GEOMETRY |
SHADER_TYPE_COUNT |

## Constructor & Destructor Documentation

## OsgProgram()

SurgSim::Graphics::OsgProgram::OsgProgram | ( |  | ) |

Constructor.

Postcondition
  No shader code is set, so the fixed-function pipeline is used.

## Member Function Documentation

## addToStateSet()

void SurgSim::Graphics::OsgProgram::addToStateSet | ( | osg::StateSet * | stateSet | ) |

Adds this shader to the OSG state set.

Parameters

  stateSet | OSG state set

## clearFragmentShader()

void SurgSim::Graphics::OsgProgram::clearFragmentShader | ( |  | ) |

override virtual

Returns
  the fragment shader, returning that portion of the shader program to fixed-function.

Implements SurgSim::Graphics::Program.

## clearGeometryShader()

void SurgSim::Graphics::OsgProgram::clearGeometryShader | ( |  | ) |

override virtual

Removes the geometry shader, returning that portion of the shader program to fixed-function.

Implements SurgSim::Graphics::Program.

## clearShader()

void SurgSim::Graphics::OsgProgram::clearShader | ( | int | shaderType | ) |

private

Removes the geometry shader, returning that portion of the shader program to fixed-function.

Parameters

  shaderType | Type of the shader

## clearVertexShader()

void SurgSim::Graphics::OsgProgram::clearVertexShader | ( |  | ) |

override virtual

Removes the vertex shader, returning that portion of the shader program to fixed-function.

Implements SurgSim::Graphics::Program.

## getFragmentShaderSource()

bool SurgSim::Graphics::OsgProgram::getFragmentShaderSource | ( | std::string * | source | ) | const

override virtual

Gets the fragment shader source code.

Returns
  Shader source code

Implements SurgSim::Graphics::Program.

## getGeometryShaderSource()

bool SurgSim::Graphics::OsgProgram::getGeometryShaderSource | ( | std::string * | source | ) | const

override virtual

Gets the geometry shader source code.

Returns
  Shader source code

Implements SurgSim::Graphics::Program.

## getOrCreateOsgShader()

osg::ref_ptr< osg::Shader > SurgSim::Graphics::OsgProgram::getOrCreateOsgShader | ( | int | shaderType | ) |

private

Fetches the appropriate shader if it exists, creates it otherwise.

Parameters

  shaderType | Type of the shader

Returns
  the shader with the given type

## getOsgProgram()

osg::ref_ptr< osg::Program > SurgSim::Graphics::OsgProgram::getOsgProgram | ( |  | ) | const

Returns
  the OSG program attribute

## getShaderSource()

bool SurgSim::Graphics::OsgProgram::getShaderSource | ( | int | shaderType,
|  | std::string * | source
| ) |  | const

private virtual

Gets the shader source code.

Returns
  Shader source code

## getVertexShaderSource()

bool SurgSim::Graphics::OsgProgram::getVertexShaderSource | ( | std::string * | source | ) | const

override virtual

Gets the vertex shader source code.

Returns
  Shader source code

Implements SurgSim::Graphics::Program.

## hasFragmentShader()

bool SurgSim::Graphics::OsgProgram::hasFragmentShader | ( |  | ) | const

override virtual

Returns
  true if the fragment shader has been set, otherwise false.

Implements SurgSim::Graphics::Program.

## hasGeometryShader()

bool SurgSim::Graphics::OsgProgram::hasGeometryShader | ( |  | ) | const

override virtual

Returns
  true if the geometry shader has been set, otherwise false.

Implements SurgSim::Graphics::Program.

## hasShader()

bool SurgSim::Graphics::OsgProgram::hasShader | ( | int | shaderType | ) | const

private

Check whether there is a shader in use for the given type.

Parameters

  shaderType | Type of the shader

Returns
  true if the shader has been set, otherwise false.

## hasVertexShader()

bool SurgSim::Graphics::OsgProgram::hasVertexShader | ( |  | ) | const

override virtual

Returns
  true if the vertex shader has been set, otherwise false.

Implements SurgSim::Graphics::Program.

## isGlobalScope()

bool SurgSim::Graphics::OsgProgram::isGlobalScope | ( |  | ) | const

override virtual

Query if this shader is of global scope.

Returns
  true if global scope, false if not.

Implements SurgSim::Graphics::Program.

## loadFragmentShader()

bool SurgSim::Graphics::OsgProgram::loadFragmentShader | ( | const std::string & | filePath | ) |

override virtual

Loads the fragment shader source code from a file.

Parameters

  filePath | Path to file containing shader source code

Returns
  True if the source is successfully loaded, otherwise false.

Implements SurgSim::Graphics::Program.

## loadGeometryShader()

bool SurgSim::Graphics::OsgProgram::loadGeometryShader | ( | const std::string & | filePath | ) |

override virtual

Loads the geometry shader source code from a file.

Parameters

  filePath | Path to file containing shader source code

Returns
  True if the source is successfully loaded, otherwise false.

Implements SurgSim::Graphics::Program.

## loadShaderSource()

bool SurgSim::Graphics::OsgProgram::loadShaderSource | ( | const std::string & | filePath,
|  | int | shaderType
| ) |  |

private

Loads the shader source code from a file.

Parameters

  filePath | Path to file containing shader source code
  shaderType | Type of the shader

Returns
  True if the source is successfully loaded, otherwise false.

## loadVertexShader()

bool SurgSim::Graphics::OsgProgram::loadVertexShader | ( | const std::string & | filePath | ) |

override virtual

Loads the vertex shader source code from a file.

Parameters

  filePath | Path to file containing shader source code

Returns
  True if the source is successfully loaded, otherwise false.

Implements SurgSim::Graphics::Program.

## removeFromStateSet()

void SurgSim::Graphics::OsgProgram::removeFromStateSet | ( | osg::StateSet * | stateSet | ) |

Removes this uniform from the OSG state set.

Parameters

  stateSet | OSG state set

## setFragmentShaderSource()

void SurgSim::Graphics::OsgProgram::setFragmentShaderSource | ( | const std::string & | source | ) |

override virtual

Set the fragment shader source code.

Parameters

  source | Shader source code

Implements SurgSim::Graphics::Program.

## setGeometryShaderSource()

void SurgSim::Graphics::OsgProgram::setGeometryShaderSource | ( | const std::string & | source | ) |

override virtual

Set the geometry shader source code.

Parameters

  source | Shader source code

Implements SurgSim::Graphics::Program.

## setGlobalScope()

void SurgSim::Graphics::OsgProgram::setGlobalScope | ( | bool | val | ) |

override virtual

When this is set to true, this shader should be used instead of other shaders that might apply, depending on the hierarchy that is set out.

E.g if this shader is on a camera, the shaders that occur in a group attached to that camera will be overridden. This will usually be used in conjunction with

See also
  RenderPass.

Parameters

  val | If true the shader should override shaders in lower levels.

Implements SurgSim::Graphics::Program.

## setShaderSource()

void SurgSim::Graphics::OsgProgram::setShaderSource | ( | const std::string & | source,
|  | int | shaderType
| ) |  |

private virtual

Set the shader source code.

Parameters

  source | Shader source code
  shaderType | Type of the shader

## setVertexShaderSource()

void SurgSim::Graphics::OsgProgram::setVertexShaderSource | ( | const std::string & | source | ) |

override virtual

Set the vertex shader source code.

Parameters

  source | Shader source code

Implements SurgSim::Graphics::Program.

## Member Data Documentation

## m_globalScope

bool SurgSim::Graphics::OsgProgram::m_globalScope

private

Is the shader supposed to be used globally.

## m_osgShaders

std::array<osg::ref_ptr<osg::Shader>, SHADER_TYPE_COUNT> SurgSim::Graphics::OsgProgram::m_osgShaders

private

Storage of the osg objects.

## m_program

osg::ref_ptr<osg::Program> SurgSim::Graphics::OsgProgram::m_program

private

OSG program attribute.

The documentation for this class was generated from the following files:

- SurgSim/Graphics/OsgProgram.h
- SurgSim/Graphics/OsgProgram.cpp