Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Classes | Public Member Functions | List of all members
BIAS::SimpleMultiPassFragmentShader Class Reference

this class collects a number of shaders and textures uniquely identified by their names shader uniforms can be set by addressing the shaders by their names textures a shader reads from and writes to can be spezified by setting input and output textures addressing the textures through their names calling Execute with a vector of shader names as parameter executes all shaders on the gpu in the order given by the shader names vector More...

#include <OpenGLFramework/SpecializedBatches/SimpleMultiPassFragmentShader.hh>

Public Member Functions

void AddFragmentShader (const std::string &shader_source, const std::string &shader_name)
 adds an fragment shader with name shader_name and shader source code shader_source More...
 
void AddFragmentShaderFromFile (const std::string &shader_path, const std::string &shader_name)
 adds an fragment shader with name shader_name from file shader_path to the shader_source More...
 
void ClearPostAction (const std::string &shaderName)
 
void CopyChannelsToImage (const std::string &texture_name, GLenum format, ImageBase &image)
 copies texture with the texture_name to image More...
 
void CopyToImage (const std::string &texture_name, ImageBase &image)
 copies texture with the texture_name to image More...
 
void CreateTexture (int width, int height, ImageBase::EStorageType storageType, ImageBase::EColorModel colorModel, const std::string &texture_name, GLenum minFilter=GL_NEAREST, GLenum magFilter=GL_NEAREST, GLenum wrapS=GL_CLAMP, GLenum wrapT=GL_CLAMP, int mipmap=0)
 creates new texture with name texture_name (for example storageType ImageBase::ST_float, colorModel ImageBase::CM_Grey creates a 1 channel float texture) More...
 
void CreateTexture (int width, int height, GLenum internalFormat, const std::string &texture_name, GLenum minFilter=GL_NEAREST, GLenum magFilter=GL_NEAREST, GLenum wrapS=GL_CLAMP, GLenum wrapT=GL_CLAMP, int mipmap=0)
 
void Destroy ()
 resets this object More...
 
void DisableColorClearance (const std::string &shaderName)
 Disables the clearence of the output when rendered into. More...
 
void DisableDepthClearance (const std::string &shaderName)
 Disables the clearence of the output when rendered into. More...
 
void EnableColorClearance (const std::string &shaderName, float red=0.0f, float green=0.0f, float blue=0.0f, float alpha=0.0f)
 Enables the clearence of the output, each time when rendered into. More...
 
void EnableDepthClearance (const std::string &shaderName, float depth=1.0f)
 Enables the clearence of the output, each time when rendered into. More...
 
void EvaluateOnlyLine (const unsigned int referenceWidth, const unsigned int referenceHeight, const unsigned int posY, const unsigned int hw)
 Instead of processing a whole image, the fragment shaders are run only on a region around an image line. More...
 
void EvaluateOnlyPatches (const unsigned int referenceWidth, const unsigned int referenceHeight, const std::vector< unsigned int > &posX, const std::vector< unsigned int > &posY, const unsigned int hw)
 Instead ogf processing a whole image, the fragment shaders are run only on a set of symmetric patches. More...
 
void Execute (const std::vector< std::string > &shader_names, unsigned int iter_number=1)
 executes all shaders with names in shader_names vector in the given order (iter_number)-times More...
 
glfFramebufferObjectGetFBO ()
 
FramebufferSetupPoolGetFramebufferSetupPool ()
 
Texture2DPoolGetTexture2DPool ()
 
void Init (bool createGLContext=true)
 initializes openGL context (if createGLContext = true) and some internal variables, must be called first More...
 
void LoadTexture (const ImageBase &image, const std::string &texture_name, GLenum minFilter=GL_NEAREST, GLenum magFilter=GL_NEAREST, GLenum wrapS=GL_CLAMP, GLenum wrapT=GL_CLAMP, GLenum internalFormat=0, int mipmap=0)
 loads an image as texture with name texture_name More...
 
void ResetPostAction (const std::string &shaderName)
 
void SetDepthTest (const std::string &shaderName, const bool enabled, GLenum depthFunc)
 Sets the depth test for the particular shader execution. More...
 
void SetInputTextures (const std::string &shader_name, const std::vector< std::string > &samplers2D, const std::vector< std::string > &texture_names)
 sets all textures from vector texture_names as input textures the vector sampler2D holds the names of the textures in shader source code each texture_names[i] will be bind to the shader uniform sampler2D variable with name sampler2D[i] More...
 
void SetInputTextures (const std::string &shaderName, const std::string &uniformVarName, const std::string &texturePoolName)
 Asociated the texture from texture pool with name <texturePoolName>, with the uniform sampler named <uniformName> in shader source of shader <sahderName>. More...
 
void SetOutputTexture (const std::string &shader_name, const std::string &texture_name, const std::string &depthTextureName="")
 sets a texture with name texture_name as output texture for the shader shader_name More...
 
void SetOutputTextures (const std::string &shader_name, const std::vector< std::string > &texture_names, const std::string &depthTextureName="")
 sets all textures from vector texture_names as output textures for the shader shader_name More...
 
void SetPostAction (const std::string &shaderName, const SMPFSActionInterface &postAction)
 Sets an action that is performed after the respective shader has run. More...
 
template<class StorageType >
void SetShaderVariable (const std::string &shader_name, const std::string &var_name, StorageType value)
 sets the value of uniform shader variable var_name for shader shader_name if the variable type is sampler2D then an glfException is thrown use SetOutput/InputTextures to set this variablews More...
 
 SimpleMultiPassFragmentShader ()
 standard constructor More...
 

Detailed Description

this class collects a number of shaders and textures uniquely identified by their names shader uniforms can be set by addressing the shaders by their names textures a shader reads from and writes to can be spezified by setting input and output textures addressing the textures through their names calling Execute with a vector of shader names as parameter executes all shaders on the gpu in the order given by the shader names vector

Usage Example: SimpleMultiPassFragmentShader smpfs; smpfs.Init(); // init pBuffer context. Init(false) requires glContext to be created manually

smpfs.AddFragmentShader(shader_source, "ShaderName"); // shader_source is a string

smpfs.LoadTexture(...) or smpfs.CreateTexture(...)

smpfs.SetShaderVariable(...) // set uniform variables if required; textures not allowed

smpfs.SetInputTextures("ShaderName", ...) and smpfs.SetOutputTextures("ShaderName", ...)

for (...) { smpfs.Execute(...); smpfs.SetShaderVariable(...); //change uniform variables }

smpfs.CopyToImage(string("VariableName"), image); //get result from texture

Author
frick

Definition at line 86 of file SimpleMultiPassFragmentShader.hh.

Constructor & Destructor Documentation

SimpleMultiPassFragmentShader::SimpleMultiPassFragmentShader ( )

standard constructor

Definition at line 13 of file SimpleMultiPassFragmentShader.cpp.

Member Function Documentation

void SimpleMultiPassFragmentShader::AddFragmentShader ( const std::string &  shader_source,
const std::string &  shader_name 
)

adds an fragment shader with name shader_name and shader source code shader_source

Definition at line 105 of file SimpleMultiPassFragmentShader.cpp.

void SimpleMultiPassFragmentShader::AddFragmentShaderFromFile ( const std::string &  shader_path,
const std::string &  shader_name 
)

adds an fragment shader with name shader_name from file shader_path to the shader_source

Definition at line 81 of file SimpleMultiPassFragmentShader.cpp.

void SimpleMultiPassFragmentShader::ClearPostAction ( const std::string &  shaderName)

Definition at line 499 of file SimpleMultiPassFragmentShader.cpp.

void SimpleMultiPassFragmentShader::CopyChannelsToImage ( const std::string &  texture_name,
GLenum  format,
ImageBase image 
)

copies texture with the texture_name to image

Definition at line 410 of file SimpleMultiPassFragmentShader.cpp.

References BIAS::glfTexture2D::CopyChannelsToImage().

void SimpleMultiPassFragmentShader::CopyToImage ( const std::string &  texture_name,
ImageBase image 
)

copies texture with the texture_name to image

Definition at line 395 of file SimpleMultiPassFragmentShader.cpp.

References BIAS::glfTexture2D::CopyToImage().

void SimpleMultiPassFragmentShader::CreateTexture ( int  width,
int  height,
ImageBase::EStorageType  storageType,
ImageBase::EColorModel  colorModel,
const std::string &  texture_name,
GLenum  minFilter = GL_NEAREST,
GLenum  magFilter = GL_NEAREST,
GLenum  wrapS = GL_CLAMP,
GLenum  wrapT = GL_CLAMP,
int  mipmap = 0 
)

creates new texture with name texture_name (for example storageType ImageBase::ST_float, colorModel ImageBase::CM_Grey creates a 1 channel float texture)

Definition at line 171 of file SimpleMultiPassFragmentShader.cpp.

void SimpleMultiPassFragmentShader::CreateTexture ( int  width,
int  height,
GLenum  internalFormat,
const std::string &  texture_name,
GLenum  minFilter = GL_NEAREST,
GLenum  magFilter = GL_NEAREST,
GLenum  wrapS = GL_CLAMP,
GLenum  wrapT = GL_CLAMP,
int  mipmap = 0 
)

Definition at line 154 of file SimpleMultiPassFragmentShader.cpp.

void SimpleMultiPassFragmentShader::Destroy ( )

resets this object

Definition at line 57 of file SimpleMultiPassFragmentShader.cpp.

void SimpleMultiPassFragmentShader::DisableColorClearance ( const std::string &  shaderName)

Disables the clearence of the output when rendered into.

Per default the clearance is enabled.

Author
bartczak 03/2009

Definition at line 604 of file SimpleMultiPassFragmentShader.cpp.

References BIAS::FramebufferSetup::DisableColorClearance(), and BIAS::FramebufferSetupPool::GetSetup().

void SimpleMultiPassFragmentShader::DisableDepthClearance ( const std::string &  shaderName)

Disables the clearence of the output when rendered into.

Per default the clearance is enabled.

Author
bartczak 03/2009

Definition at line 616 of file SimpleMultiPassFragmentShader.cpp.

References BIAS::FramebufferSetup::DisableDepthClearance(), and BIAS::FramebufferSetupPool::GetSetup().

void SimpleMultiPassFragmentShader::EnableColorClearance ( const std::string &  shaderName,
float  red = 0.0f,
float  green = 0.0f,
float  blue = 0.0f,
float  alpha = 0.0f 
)

Enables the clearence of the output, each time when rendered into.

Is per default enabled with the given default parameters.

Author
bartczak 03/2009

Definition at line 579 of file SimpleMultiPassFragmentShader.cpp.

References BIAS::FramebufferSetup::EnableColorClearance(), and BIAS::FramebufferSetupPool::GetSetup().

void SimpleMultiPassFragmentShader::EnableDepthClearance ( const std::string &  shaderName,
float  depth = 1.0f 
)

Enables the clearence of the output, each time when rendered into.

Is per default enabled with the given default parameters.

Author
bartczak 03/2009

Definition at line 592 of file SimpleMultiPassFragmentShader.cpp.

References BIAS::FramebufferSetup::EnableDepthClearance(), and BIAS::FramebufferSetupPool::GetSetup().

void SimpleMultiPassFragmentShader::EvaluateOnlyLine ( const unsigned int  referenceWidth,
const unsigned int  referenceHeight,
const unsigned int  posY,
const unsigned int  hw 
)

Instead of processing a whole image, the fragment shaders are run only on a region around an image line.

Parameters
referenceWidththe lines are calculated relative to this target resolution width.
referenceHeightthe lines are calculated relative to this target resolution height.
posythe line's y position.
hwthe half window size around the lines y position.
Attention
This has to be changed for every target resolution.
Call after init.
Author
bartczak 08/2010

Definition at line 658 of file SimpleMultiPassFragmentShader.cpp.

References BIAS::Primitives::AddRelativeQuadPatchOverImageLine().

void SimpleMultiPassFragmentShader::EvaluateOnlyPatches ( const unsigned int  referenceWidth,
const unsigned int  referenceHeight,
const std::vector< unsigned int > &  posX,
const std::vector< unsigned int > &  posY,
const unsigned int  hw 
)

Instead ogf processing a whole image, the fragment shaders are run only on a set of symmetric patches.

Parameters
referenceWidththe patches are calculated relative to this target resolution width.
referenceHeightthe patches are calculated relative to this target resolution height.
posXthe patche's center x position relative to width.
posXthe patche's center y position relative to height.
hwthe patche's half window size.
Attention
This has to be changed for every target resolution.
Call after init.
Author
bartczak 01/2010

Definition at line 646 of file SimpleMultiPassFragmentShader.cpp.

References BIAS::Primitives::AddRelativeQuadPatches().

void SimpleMultiPassFragmentShader::Execute ( const std::vector< std::string > &  shader_names,
unsigned int  iter_number = 1 
)
glfFramebufferObject* BIAS::SimpleMultiPassFragmentShader::GetFBO ( )
inline

Definition at line 243 of file SimpleMultiPassFragmentShader.hh.

FramebufferSetupPool& BIAS::SimpleMultiPassFragmentShader::GetFramebufferSetupPool ( )
inline

Definition at line 242 of file SimpleMultiPassFragmentShader.hh.

Texture2DPool& BIAS::SimpleMultiPassFragmentShader::GetTexture2DPool ( )
inline

Definition at line 241 of file SimpleMultiPassFragmentShader.hh.

void SimpleMultiPassFragmentShader::Init ( bool  createGLContext = true)
void SimpleMultiPassFragmentShader::LoadTexture ( const ImageBase image,
const std::string &  texture_name,
GLenum  minFilter = GL_NEAREST,
GLenum  magFilter = GL_NEAREST,
GLenum  wrapS = GL_CLAMP,
GLenum  wrapT = GL_CLAMP,
GLenum  internalFormat = 0,
int  mipmap = 0 
)

loads an image as texture with name texture_name

Definition at line 138 of file SimpleMultiPassFragmentShader.cpp.

void SimpleMultiPassFragmentShader::ResetPostAction ( const std::string &  shaderName)

Definition at line 490 of file SimpleMultiPassFragmentShader.cpp.

void SimpleMultiPassFragmentShader::SetDepthTest ( const std::string &  shaderName,
const bool  enabled,
GLenum  depthFunc 
)

Sets the depth test for the particular shader execution.

It is not required that the shader already exists, if not used the shaders use the default behaviour implemented in glfDepthBufferMode.

Author
bartczak 03/2009

Definition at line 627 of file SimpleMultiPassFragmentShader.cpp.

void SimpleMultiPassFragmentShader::SetInputTextures ( const std::string &  shader_name,
const std::vector< std::string > &  samplers2D,
const std::vector< std::string > &  texture_names 
)

sets all textures from vector texture_names as input textures the vector sampler2D holds the names of the textures in shader source code each texture_names[i] will be bind to the shader uniform sampler2D variable with name sampler2D[i]

Definition at line 188 of file SimpleMultiPassFragmentShader.cpp.

void SimpleMultiPassFragmentShader::SetInputTextures ( const std::string &  shaderName,
const std::string &  uniformVarName,
const std::string &  texturePoolName 
)

Asociated the texture from texture pool with name <texturePoolName>, with the uniform sampler named <uniformName> in shader source of shader <sahderName>.

Definition at line 232 of file SimpleMultiPassFragmentShader.cpp.

void SimpleMultiPassFragmentShader::SetOutputTexture ( const std::string &  shader_name,
const std::string &  texture_name,
const std::string &  depthTextureName = "" 
)

sets a texture with name texture_name as output texture for the shader shader_name

Definition at line 315 of file SimpleMultiPassFragmentShader.cpp.

References BIAS::FramebufferSetup::ClearColorAttachments(), BIAS::FramebufferSetup::Execute(), BIAS::FramebufferSetup::SetColorAttachment(), and BIAS::FramebufferSetup::SetDepthAttachment().

void SimpleMultiPassFragmentShader::SetOutputTextures ( const std::string &  shader_name,
const std::vector< std::string > &  texture_names,
const std::string &  depthTextureName = "" 
)

sets all textures from vector texture_names as output textures for the shader shader_name

Definition at line 358 of file SimpleMultiPassFragmentShader.cpp.

References BIAS::FramebufferSetup::Execute(), and BIAS::FramebufferSetup::SetDepthAttachment().

void SimpleMultiPassFragmentShader::SetPostAction ( const std::string &  shaderName,
const SMPFSActionInterface postAction 
)

Sets an action that is performed after the respective shader has run.

Shader does not have to exist.

Definition at line 484 of file SimpleMultiPassFragmentShader.cpp.

template<class StorageType >
template BIASOpenGLFramework_EXPORT void SimpleMultiPassFragmentShader::SetShaderVariable< Vector< float > > ( const std::string &  shader_name,
const std::string &  var_name,
StorageType  value 
)

sets the value of uniform shader variable var_name for shader shader_name if the variable type is sampler2D then an glfException is thrown use SetOutput/InputTextures to set this variablews

Definition at line 123 of file SimpleMultiPassFragmentShader.cpp.


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