|
The Vish Visualization Shell 0.3
Vish
|
An OpenGL shading program. More...
#include <ocean/GLvish/GLProgram.hpp>
Classes | |
| struct | CannotAssignUniform |
| Exception class if a uniform variable in a shader could not be assigned. More... | |
| struct | Error |
| Local error class to serve as base class for all exceptions that are thrown by GLProgram operations. More... | |
| struct | LinkerError |
| Exception that happens when there was a problem with linking compiled shader programs. More... | |
| struct | NoSuchAttribute |
| Exception thrown when a vertex attribute was not found. More... | |
| struct | NoSuchUniform |
| Exception thrown when a uniform variable was not found. More... | |
| struct | NotSupportedCall |
| Exception class if a GL call is not supported. More... | |
| struct | UninitializedTexture |
| Exception thrown if a texture is supposed to be used that has not been initialized. More... | |
Public Member Functions | |
| bool | activate (const Anemone &) override |
| Anemone::Tentacle Implementation: use this shader. | |
| void | bindFragData (GLuint colorNumber, const char *name) const |
| bool | deactivate (const Anemone &) override |
| Anemone::Tentacle Implementation: disable use of shaders. | |
| GLint | getAttribID (const char *name) const |
| Get the identifier of some attribute as defined in the Program. | |
| GLint | getAttribID (const string &name) const |
| Get the identifier of some attribute variable as defined in the Program. | |
| GLuint | getId () const |
| Get the associated OpenGL ID. | |
| GLProgram () | |
| Constructor. | |
| GLProgram (const string &vertex_code, const string &fragment_code, const string &vertexsrcfilename="* Internal Vertex Shader *", const string &fragmentsrcfilename="* Internal Fragment Shader *", unsigned vertex_lineNo=0, unsigned fragment_lineNo=0) | |
| Construct a program with vertex and fragment shader code. | |
| GLProgram (const string &vertex_code, const string &vertexsrcfilename, unsigned vertex_lineNo, const string &fragment_code, const string &fragmentsrcfilename, unsigned fragment_lineNo) | |
| std::string | InfoLog () const |
| Return verbose compilation info. | |
| bool | isValid () const |
| Validates that this program is ready to use. | |
| void | link (const RenderBasin::Program::Setup &SetupFunction=nullptr, const char *srcfilename="** OpenGL Program Shader Code **", unsigned lineNo=0) |
| Link the program. | |
| void | setAllUniforms (const Anemone &A) const override |
| Setup the internally defined variables. | |
| void | setObjectLabel (const string &Name) const |
| Interfacing glObjectLabel() https://registry.khronos.org/OpenGL-Refpages/gl4/html/glObjectLabel.xhtml. | |
| bool | setUniformValuef (const char *name, float value, bool Silent) const |
| Set a variable in the program to a certain value. | |
| bool | setUniformValuei (const char *name, GLint v0, GLint v1, bool Silent) const |
| void | SetupViewport () const |
| Set a uniform variable int Viewport[4] in the program to contain the current OpenGL view port. | |
| std::pair< WeakPtr< GLProgram >, string > | uniform (const char *name) |
| Return some context on how to address a uniform variable in the shader. | |
| void | use () const override |
| Use the program. | |
| ~GLProgram () | |
| Destructor. | |
Public Member Functions inherited from Wizt::RenderBasin::Program | |
| Program () | |
| Constructor. | |
| bool | SourceHasChanged () const |
| Check if any of the registered source files (mySources) has changed. | |
Public Member Functions inherited from Wizt::Anemone::Tentacle | |
| virtual const char * | getSamplerType () const |
| If this tentacle refers to some texture sampler in a shader, then hereby return the type of this sampler is it occurs in the code. | |
| virtual int | getTextureUnit () const |
| Get the texture unit number which was specified during construction, if positive then it refers to some texture unit that is used in an associated shader. | |
| virtual size_t | memsize () const |
| Return the memory occupied by this buffer if it occupies memory at all. Otherwise, returns 0 (default). | |
| virtual size_t | NumberOfElements () const |
| Returns the number of elements provided and used by this object, if it refers to countable elements. | |
| virtual bool | updateValue (VRenderContext &Context) |
| Possibly update a tentacle from settings in a context. | |
Public Member Functions inherited from MemCore::ReferenceBase< Tentacle > | |
| auto | getObjectCountID () const noexcept |
| Get a unique ID for this object in the given domain. | |
| bool | isIdentical (const WeakPtr< Tentacle, Tentacle > &PossibleSelf) const noexcept |
| Check if this object is identical to the one used by the given pointer. | |
| void | mkAutoDestructive () |
| Marks this object as being automatically destructed, e.g. | |
| refcount_t | refcount () const noexcept |
| The strong reference count. | |
| ReferenceBase (Tentacle *that) noexcept | |
| Constructor, initializes reference counter to zero. | |
| const auto & | self () const |
| Return weak pointer to the object self. | |
| refcount_t | wrefcount () const noexcept |
| The weak reference count. | |
Public Member Functions inherited from Wizt::RenderNamespace::ProgramVariables | |
| ProgramVariables & | merge (const ProgramVariables &, substitutes_t &substitutes, const std::string &src_original, const std::string &src_substitute) |
| Merge a set of program variables into this current one and substitute the variable names by another string thereby. | |
| void | remove (const substitutes_t &substitutes) |
| Remove all variables as given in the set. | |
| template<class T > | |
| void | setMandatoryValue (const std::string &name, const T &t, bool isMandatory=true) |
| Set a value that will raise an exception if that variable is not used in the shader program. | |
| void | setPointValue (const std::string &name, const Eagle::FixedArray< double, 3 > &v) |
| Set an vec3 uniform that is suspect to coordinate shifting. | |
| void | setValue (const std::string &name, const Eagle::FixedArray< double, 2 > &v) |
| Set an vec2 uniform. | |
| void | setValue (const std::string &name, const Eagle::FixedArray< double, 3 > &v) |
| Set an vec3 uniform. | |
| void | setValue (const std::string &name, const Eagle::FixedArray< double, 4 > &v) |
| Set an vec4 uniform. | |
| void | setValue (const std::string &name, const Eagle::FixedArray< float, 4 > &v) |
| Set an vec4 uniform of floats. | |
| void | setValue (const std::string &name, const Eagle::FixedArray< int, 2 > &v) |
| Set an vec2 uniform. | |
| void | setValue (const std::string &name, const Eagle::FixedArray< int, 3 > &v) |
| Set an vec3 uniform. | |
| void | setValue (const std::string &name, const Eagle::Quadratic< 3, float > &M) |
| Set an integer uniform. | |
| void | setValue (const std::string &name, double d) |
| Set a floating point uniform. | |
| void | setValue (const std::string &name, int i) |
| Set an integer uniform. | |
Static Public Member Functions | |
| static void | dont_use_any_shaders () |
| Disable the use of any shaders. | |
| static const char * | VarType (GLenum type) |
| Tell the type of the given variable, as specified by the CannotAssignUniform exception. | |
Additional Inherited Members | |
Public Types inherited from Wizt::RenderBasin::Program | |
| using | Setup = std::function< Parameters(const Parameters &MaximumValues)> |
| The setup function when linking a program, which is given maximum values as possible by the current implementation and needs to specify the actually required values for a given shader. | |
| using | SourceCode_t = std::map< std::string, glsl > |
| Map from filename to source code. | |
| using | Sources_t = std::map< std::string, MemCore::Filetime > |
| File names and file modification/access/creation time. | |
Public Types inherited from MemCore::ReferenceBase< Tentacle > | |
| using | reference_domain_t = Tentacle |
| The type of the base class. | |
| using | SelfPtr_t = WeakPtr< Tentacle, Tentacle > |
| Type for a pointer to this object itself. | |
Public Attributes inherited from Wizt::RenderBasin::Program | |
| Sources_t | mySources |
| List of file names associated with this program and their respective modification times. | |
| bool | SilentlyIgnoreUnknownUniforms |
| Throw a RenderException if a variable is set that is not used in the program. | |
| SourceCode_t | SourceCode |
| For information only, the last complete source code that was used to compile this shader, indexed by an key word for multiple shader types. | |
| NamedTextures_t | Textures |
| A set of named textures to be used in this Program. | |
Public Attributes inherited from Wizt::Anemone::Tentacle | |
| Activity_t | Activity |
| A bit mask telling whether this tentacle should participate in the waving of an Anemone. | |
Public Attributes inherited from Wizt::RenderNamespace::ProgramVariables | |
| FloatValues_t | FloatValues |
| A set of floating point values that will be set for this program. | |
| IntValues_t | IntValues |
| A set of integer values that will be set for this program. | |
| std::map< std::string, Eagle::FixedArray< int, 2 > > | iVec2Values |
| A set of 3D integer vectors that will be set for this program as uniforms. | |
| std::map< std::string, Eagle::FixedArray< int, 3 > > | iVec3Values |
| A set of 3D integer vectors that will be set for this program as uniforms. | |
| std::map< std::string, std::vector< Eagle::Quadratic< 3, float > > > | M33ArrayValues |
| A set of matric values that will be set for this program. | |
| std::map< std::string, Eagle::Quadratic< 3, float > > | M33Values |
| A set of matric values that will be set for this program. | |
| std::map< std::string, Eagle::FixedArray< double, 3 > > | Point3Values |
| A set of 3D vectors that will be set for this program as uniforms. | |
| std::map< std::string, Eagle::FixedArray< double, 2 > > | Vec2Values |
| A set of 2D vectors that will be set for this program as uniforms. | |
| std::map< std::string, Eagle::FixedArray< double, 3 > > | Vec3Values |
| A set of 3D vectors that will be set for this program as uniforms. | |
| std::map< std::string, Eagle::FixedArray< double, 4 > > | Vec4Values |
| A set of 4D vectors that will be set for this program as uniforms. | |
Protected Member Functions inherited from Wizt::RenderBasin::Program | |
| virtual | ~Program ()=0 |
| Destructor. | |
Protected Member Functions inherited from MemCore::ReferenceBase< Tentacle > | |
| virtual void | extremeUnction () |
| A virtual function that will be called just before the object is destroyed. | |
| ReferenceBase & | operator= (const ReferenceBase &R) |
| Protected assignment operator (should not be called). | |
| void | suicide () |
| Delete this. | |
| virtual | ~ReferenceBase () |
| Virtual destructor. | |
An OpenGL shading program.
A most simple way to enable a shader is like this:
The value of a floating point slot may be directly assigned to a uniform shader variable:
An additional function may be applied during assignment:
| Wizt::GLProgram::GLProgram | ( | const string & | vertex_code, |
| const string & | fragment_code, | ||
| const string & | vertexsrcfilename = "* Internal Vertex Shader *", |
||
| const string & | fragmentsrcfilename = "* Internal Fragment Shader *", |
||
| unsigned | vertex_lineNo = 0, |
||
| unsigned | fragment_lineNo = 0 |
||
| ) |
Construct a program with vertex and fragment shader code.
The specified vertex and fragment shader codes are compiled and linked immediatly.
The most trivial vertex shade is this:
The most trivial fragment shader is this:
References GLProgram(), link(), and setObjectLabel().
|
inline |
Constructor with alternative order of arguments such that the
GLSL_SHADER and GLSL_SOURCE macros can be used.
Define the GLSL source like this:
@code
GLSL_SHADER( fragment_shader ) = R"SHADER( #version 450 out vec4 fragmentColor; void main(void) { fragmentColor = vec4(1,0,0,0); } )SHADER" ; and construct the GLProgram like this:
| void Wizt::GLProgram::bindFragData | ( | GLuint | colorNumber, |
| const char * | name | ||
| ) | const |
| GLint Wizt::GLProgram::getAttribID | ( | const char * | name | ) | const |
Get the identifier of some attribute as defined in the Program.
Attributes are values that are provided per vertex and declared in the Program using GSGL like in this following code fragment:
References isValid().
|
inline |
Get the identifier of some attribute variable as defined in the Program.
Attributes are values that are provided per vertex and declared in the Program using GSGL like in this following code fragment:
| bool Wizt::GLProgram::isValid | ( | ) | const |
Validates that this program is ready to use.
http://www.opengl.org/sdk/docs/man/xhtml/glValidateProgram.xml
Referenced by getAttribID().
| bool Wizt::GLProgram::setUniformValuef | ( | const char * | name, |
| float | value, | ||
| bool | Silent | ||
| ) | const |
Set a variable in the program to a certain value.
| name | The variable as given in the program. |
Referenced by setAllUniforms().
| bool Wizt::GLProgram::setUniformValuei | ( | const char * | name, |
| GLint | v0, | ||
| GLint | v1, | ||
| bool | Silent | ||
| ) | const |
Return some context on how to address a uniform variable in the shader.
Used for the >> operator.
References MemCore::ReferenceBase< Tentacle >::self().