Inviwo 0.9.12-pre
Inviwo documentation
Loading...
Searching...
No Matches
inviwo::ShaderObject Class Reference

#include <modules/opengl/shader/shaderobject.h>

Classes

struct  InDeclaration
struct  OutDeclaration

Public Types

using Callback = std::function<void(ShaderObject*)>
enum class  ExtensionBehavior { Enable , Require , Warn , Disable }
using ShaderDefines = std::map<std::string, std::string, std::less<>>

Public Member Functions

void addInDeclaration (const InDeclaration &decl)
void addInDeclaration (std::string_view name, int location=-1, std::string_view type="vec4")
 adds an additional input specifier to the shader The given name will be added as
void addOutDeclaration (const OutDeclaration &decl)
void addOutDeclaration (std::string_view name, int location=-1, std::string_view type="vec4")
 adds an additional output specifier to the shader The given name will be added as
void addSegment (ShaderSegment segment)
void addShaderDefine (std::string_view name, std::string_view value="")
void addShaderExtension (std::string_view extName, bool enabled)
void addShaderExtension (std::string_view extName, ExtensionBehavior behavior)
void addStandardFragmentOutDeclarations ()
void addStandardVertexInDeclarations ()
void build ()
void clearInDeclarations ()
void clearOutDeclarations ()
void clearSegments ()
void clearShaderDefines ()
void clearShaderExtensions ()
void compile ()
void create ()
std::string getFileName () const
GLuint getID () const
const std::vector< InDeclaration > & getInDeclarations () const
const std::vector< OutDeclaration > & getOutDeclarations () const
std::shared_ptr< const ShaderResourcegetResource () const
const std::vector< std::shared_ptr< const ShaderResource > > & getResources () const
const ShaderDefines & getShaderDefines () const
ShaderType getShaderType () const
bool hasShaderDefine (std::string_view name) const
bool hasShaderExtension (std::string_view extName) const
bool isReady () const
template<typename T>
std::shared_ptr< Callback > onChange (T &&callback)
ShaderObject & operator= (const ShaderObject &that)=delete
ShaderObject & operator= (ShaderObject &&that) noexcept
void preprocess ()
std::string print (bool showSource=false, bool preprocess=true)
void removeSegments (std::string_view segementName)
void removeShaderDefine (std::string_view name)
void removeShaderExtension (std::string_view extName)
std::pair< std::string, size_t > resolveLine (size_t line) const
void setResource (std::shared_ptr< const ShaderResource >)
void setShaderDefine (std::string_view name, bool shouldAdd, std::string_view value="")
void setShaderDefines (ShaderDefines shaderDefines)
void setShaderExtension (std::string_view extName, ExtensionBehavior behavior, bool shouldAdd)
 ShaderObject (const ShaderObject &rhs)=delete
 ShaderObject (GLenum shaderType, std::string_view fileName)
 ShaderObject (ShaderObject &&rhs) noexcept
 ShaderObject (ShaderType shaderType, std::shared_ptr< const ShaderResource > resource)
 ShaderObject (ShaderType shaderType, std::string_view fileName)
 ShaderObject (std::shared_ptr< const ShaderResource > resource)
 ShaderObject (std::string_view fileName)
void upload ()

Detailed Description

A wrapper for an OpenGL shader object. Handles loading sources from shader resources, either files or stings. Pre-processes the sources resolving all include with help of the shader manager. Keeps a lookup table of from which include each line originates. Handles a list of defines, that can be added or removed

See also
addShaderDefine Handles a list of shader extensions
addShaderExtension Handles a list of input declarations
addInDeclaration Handles a list of output declarations
addOutDeclaration

A fragment shader will by default have the following out declarations: out vec4 FragData0; (location 0) out vec4 PickingData; (location 1) and a vertex shader will by default have the following in declarations: in vec4 in_Vertex; (location 0) in vec3 in_Normal; (location 1) in vec4 in_Color; (location 2) in vec3 in_TexCoord; (location 3) The defaults can be removed by calling clearOutDeclarations or clearInDeclarations respectively.

Member Function Documentation

◆ addInDeclaration()

void inviwo::ShaderObject::addInDeclaration ( std::string_view name,
int location = -1,
std::string_view type = "vec4" )

adds an additional input specifier to the shader The given name will be added as

in __type__ __name__;

The shader will call glBindAttribLocation for each of the input declarations before linking the shader

Parameters
nameidentifier of the output specifier
locationindex location of the output (< MAX_RENDER_TARGETS)
typetype used for the output specifier

◆ addOutDeclaration()

void inviwo::ShaderObject::addOutDeclaration ( std::string_view name,
int location = -1,
std::string_view type = "vec4" )

adds an additional output specifier to the shader The given name will be added as

out __type__ __name__;

The shader will call glBindFragDataLocation for each of the output declarations before linking the shader

Parameters
nameidentifier of the output specifier
locationindex location of the output (< MAX_RENDER_TARGETS)
typetype used for the output specifier

◆ addSegment()

void inviwo::ShaderObject::addSegment ( ShaderSegment segment)

Add a ShaderSegement to be inserted into the shader

◆ addShaderDefine()

void inviwo::ShaderObject::addShaderDefine ( std::string_view name,
std::string_view value = "" )

Add a define to the shader as #define name value

◆ addStandardFragmentOutDeclarations()

void inviwo::ShaderObject::addStandardFragmentOutDeclarations ( )

Adds the default fragment out declarations to the list of out declarations. This function is automatically called in the constructor for a fragment shader. If clearOutDeclarations is called then they will be removed and one would have to manually call this function to re-add them if needed. The defaults are: out vec4 FragData0; (location 0) out vec4 PickingData; (location 1)

◆ addStandardVertexInDeclarations()

void inviwo::ShaderObject::addStandardVertexInDeclarations ( )

Adds the default vertex in declarations to the list of in declarations. This function is automatically called in the constructor for a vertex shader. If clearInDeclarations is called then they will be removed and one would have to manually call this function to re-add them if needed. The defaults are: in vec4 in_Vertex; (location 0) in vec3 in_Normal; (location 1) in vec4 in_Color; (location 2) in vec3 in_TexCoord; (location 3)

◆ clearSegments()

void inviwo::ShaderObject::clearSegments ( )

Clear all added ShaderSegment

◆ removeSegments()

void inviwo::ShaderObject::removeSegments ( std::string_view segementName)

Remove a ShaderSegement with name 'segementName'

◆ removeShaderDefine()

void inviwo::ShaderObject::removeShaderDefine ( std::string_view name)

Remove a previously added define

◆ setShaderDefine()

void inviwo::ShaderObject::setShaderDefine ( std::string_view name,
bool shouldAdd,
std::string_view value = "" )

Adds or removed a define with name 'name'

Parameters
nameName of the definition.
shouldAddIf true the define is added with name and value, otherwise the define is removed
valueValue of definition.

The documentation for this class was generated from the following file:
  • modules/opengl/include/modules/opengl/shader/shaderobject.h