GLIP-Lib
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Classes | Public Member Functions | Public Attributes | Static Public Attributes | List of all members
Glip::CoreGL::ShaderSource Class Reference

Shader source code and infos. More...

#include <ShaderSource.hpp>

Inheritance diagram for Glip::CoreGL::ShaderSource:
Inheritance graph

Classes

class  LineInfo
 Information about a specific line in ShaderSource. More...
 

Public Member Functions

 ShaderSource (const std::string &src, const std::string &_sourceName="", int startLine=1, const std::map< int, LineInfo > &_linesInfo=std::map< int, LineInfo >())
 Constructor of ShaderSource, load from a standard string or a file. More...
 
 ShaderSource (const ShaderSource &ss)
 ShaderSource Construtor. More...
 
ShaderSourceoperator= (const ShaderSource &c)
 Copy operator. More...
 
bool empty (void) const
 Test if the source is empty. More...
 
const std::string & getSource (void) const
 Returns the source as a standard string. More...
 
const std::string & getSourceName (void) const
 Return the name of the source : the one given with the constructor if any, the filename if it was loaded from a file or a blank string otherwise. More...
 
const char * getSourceCstr (void) const
 Returns the source as a characters table. More...
 
int getNumLines (void) const
 Get the number of lines in this source. More...
 
std::string getLine (int l, bool withNewLine=true) const
 Get a specific line from the source. More...
 
LineInfo getLineInfo (int l) const
 Get information about the line at the given index. More...
 
Exception errorLog (const std::string &log) const
 Add some source code information to the output shader compilation log. More...
 
bool requiresCompatibility (void) const
 Returns true if this Shader is using gl_FragColor and no out vec4 variables (e.g. Mesa <9.0 compatibility for Intel Core I7 with HD Graphics (>2nd Generation)); no call to glBindFragDataLocation is needed). If true, the input vars are indexed on their order of appearance in the shader source. More...
 
int getVersion (void) const
 Returns the shader version defined in the source (with #version) as an integer. More...
 
const std::vector< std::string > & getInputVars (void) const
 Return a vector containing the name of all the input textures (uniform sampler*). More...
 
const std::vector< std::string > & getOutputVars (void) const
 Return a vector containing the name of all the output textures (uniform {vec2, vec3, vec4, ...}). More...
 
const std::vector< std::string > & getUniformVars (void) const
 Return a vector containing the name of all the uniform variables which are not 2D samplers. More...
 
const std::vector< GLenum > & getUniformTypes (void) const
 Return a vector containing the type of the uniform variables which are not 2D samplers (see http://www.opengl.org/sdk/docs/man/xhtml/glGetActiveUniform.xml for a table of possible values). More...
 

Public Attributes

std::map< int, LineInfolinesInfo
 Map containing information about specific lines of this source. The key represent the line number starting at 1.
 

Static Public Attributes

static std::string portNameForFragColor = "outputTexture"
 Name for the port mapping to gl_FragColor, if used.
 

Detailed Description

Shader source code and infos.

Loading a shader from a standard string or a file :

// From a file :
ShaderSource src("./Filters/game.glsl");
// From a string, which must contain at least one new line character '\n' :
ShaderSource src(myShader);

The shader source will be parsed to find input and output ports name. In the case that you are using gl_FragColor, the name of the output port will be the one contained by string ShaderSource::portNameForFragColor.

Constructor & Destructor Documentation

ShaderSource::ShaderSource ( const std::string &  src,
const std::string &  _sourceName = "",
int  _startLine = 1,
const std::map< int, LineInfo > &  _linesInfo = std::map<int,LineInfo>() 
)

Constructor of ShaderSource, load from a standard string or a file.

Parameters
srcSource data (must have at least one '
') or filename (without '
').
_sourceNameName of the source.
_startLineCorrection added to the debugger info (also if loaded from a Layout File for example).
_linesInfoSpecific information about lines, see ShaderSource::linesInfo and ShaderSource::LineInfo.

If the source name is left blank and the src parameter is actually a filename, it will be copied as the source name.

ShaderSource::ShaderSource ( const ShaderSource ss)

ShaderSource Construtor.

Parameters
ssSource code of the shader, as a copy.

Member Function Documentation

bool ShaderSource::empty ( void  ) const

Test if the source is empty.

Returns
True if the source is empty.
Exception ShaderSource::errorLog ( const std::string &  log) const

Add some source code information to the output shader compilation log.

Parameters
logInput log to be mixed with source code.
Returns
Enhanced log.
const std::vector< std::string > & ShaderSource::getInputVars ( void  ) const

Return a vector containing the name of all the input textures (uniform sampler*).

Returns
A vector of standard string.
std::string ShaderSource::getLine ( int  l,
bool  withNewLine = true 
) const

Get a specific line from the source.

Parameters
lThe line index. The indices start at 1.
withNewLineSet to true if the returned string must contain the new-line character.
Returns
A string containing the right excerpt, or an empty line if the index is out of bounds.
ShaderSource::LineInfo ShaderSource::getLineInfo ( int  l) const

Get information about the line at the given index.

Parameters
lThe line index. The indices start at 1.

See ShaderSource::linesInfo on how to supply specific line information.

Returns
A ShaderSource::LineInfo containing the required information, especially the real line number.
int ShaderSource::getNumLines ( void  ) const

Get the number of lines in this source.

Returns
The number of lines in the source.
const std::vector< std::string > & ShaderSource::getOutputVars ( void  ) const

Return a vector containing the name of all the output textures (uniform {vec2, vec3, vec4, ...}).

Returns
A vector of standard string.
const std::string & ShaderSource::getSource ( void  ) const

Returns the source as a standard string.

Returns
A standard string.
const char * ShaderSource::getSourceCstr ( void  ) const

Returns the source as a characters table.

Returns
A const char* string (including \0).
const std::string & ShaderSource::getSourceName ( void  ) const

Return the name of the source : the one given with the constructor if any, the filename if it was loaded from a file or a blank string otherwise.

Returns
A standard string.
const std::vector< GLenum > & ShaderSource::getUniformTypes ( void  ) const

Return a vector containing the type of the uniform variables which are not 2D samplers (see http://www.opengl.org/sdk/docs/man/xhtml/glGetActiveUniform.xml for a table of possible values).

Returns
A vector of GLenum.
const std::vector< std::string > & ShaderSource::getUniformVars ( void  ) const

Return a vector containing the name of all the uniform variables which are not 2D samplers.

Returns
A vector of standard string.
int ShaderSource::getVersion ( void  ) const

Returns the shader version defined in the source (with #version) as an integer.

Returns
Returns the version as an integer (e.g. 130 for 1.30) or 0 if no version was defined.
ShaderSource & ShaderSource::operator= ( const ShaderSource c)

Copy operator.

Parameters
cSource.
Returns
A reference to this.
bool ShaderSource::requiresCompatibility ( void  ) const

Returns true if this Shader is using gl_FragColor and no out vec4 variables (e.g. Mesa <9.0 compatibility for Intel Core I7 with HD Graphics (>2nd Generation)); no call to glBindFragDataLocation is needed). If true, the input vars are indexed on their order of appearance in the shader source.

Returns
Returns true if this Shader is using gl_FragColor and no out vec4 variables.

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