Inviwo
0.9.10.1
Inviwo documentation
|
#include <shaderobject.h>
Classes | |
struct | InDeclaration |
struct | OutDeclaration |
Public Types | |
using | Callback = std::function< void(ShaderObject *)> |
Public Member Functions | |
ShaderObject (ShaderType shaderType, std::shared_ptr< const ShaderResource > resource) | |
ShaderObject (std::shared_ptr< const ShaderResource > resource) | |
ShaderObject (ShaderType shaderType, std::string fileName) | |
ShaderObject (std::string fileName) | |
ShaderObject (GLenum shaderType, std::string fileName) | |
ShaderObject (const ShaderObject &rhs) | |
ShaderObject (ShaderObject &&rhs) noexcept | |
ShaderObject & | operator= (const ShaderObject &that) |
ShaderObject & | operator= (ShaderObject &&that) noexcept |
GLuint | getID () const |
std::string | getFileName () const |
std::shared_ptr< const ShaderResource > | getResource () const |
const std::vector< std::shared_ptr< const ShaderResource > > & | getResources () const |
ShaderType | getShaderType () const |
void | preprocess () |
void | upload () |
void | compile () |
void | build () |
bool | isReady () const |
void | addShaderDefine (const std::string &name, const std::string &value="") |
void | removeShaderDefine (const std::string &name) |
void | setShaderDefine (const std::string &name, bool shouldAdd, const std::string &value="") |
bool | hasShaderDefine (const std::string &name) const |
void | clearShaderDefines () |
void | addShaderExtension (const std::string &extName, bool enabled) |
void | removeShaderExtension (const std::string &extName) |
bool | hasShaderExtension (const std::string &extName) const |
void | clearShaderExtensions () |
void | addOutDeclaration (const std::string &name, int location=-1, const std::string &type="vec4") |
adds an additional output specifier to the shader The given name will be added as More... | |
void | addOutDeclaration (const OutDeclaration &decl) |
void | clearOutDeclarations () |
const std::vector< OutDeclaration > & | getOutDeclarations () const |
void | addInDeclaration (const std::string &name, int location=-1, const std::string &type="vec4") |
adds an additional input specifier to the shader The given name will be added as More... | |
void | addInDeclaration (const InDeclaration &decl) |
void | clearInDeclarations () |
const std::vector< InDeclaration > & | getInDeclarations () const |
void | addStandardFragmentOutDeclarations () |
void | addStandardVertexInDeclarations () |
std::pair< std::string, size_t > | resolveLine (size_t line) const |
std::string | print (bool showSource=false, bool preprocess=true) const |
template<typename T > | |
std::shared_ptr< Callback > | onChange (T &&callback) |
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
A fragment shader will by default have the following out declarations: out vec4 FragData0; (location 0) out vev4 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.
void inviwo::ShaderObject::addInDeclaration | ( | const std::string & | name, |
int | location = -1 , |
||
const std::string & | 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
name | identifier of the output specifier |
location | index location of the output (< MAX_RENDER_TARGETS) |
type | type used for the output specifier |
void inviwo::ShaderObject::addOutDeclaration | ( | const std::string & | name, |
int | location = -1 , |
||
const std::string & | 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
name | identifier of the output specifier |
location | index location of the output (< MAX_RENDER_TARGETS) |
type | type used for the output specifier |
void inviwo::ShaderObject::addShaderDefine | ( | const std::string & | name, |
const std::string & | value = "" |
||
) |
Add a define to the shader as #define name value
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 vev4 PickingData; (location 1)
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)
void inviwo::ShaderObject::removeShaderDefine | ( | const std::string & | name | ) |
Remove a previously added define
void inviwo::ShaderObject::setShaderDefine | ( | const std::string & | name, |
bool | shouldAdd, | ||
const std::string & | value = "" |
||
) |
Adds or removed a define with name 'name'
name | Name of the definition. |
shouldAdd | If true the define is added with name and value, otherwise the define is removed |
value | Value of definition. |