3DCoat  3D-COAT 4.9.xx
3DCoat is the one application that has all the tools you need to take your 3D idea from a block of digital clay all the way to a production ready, fully textured organic or hard surface model.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
scalc::ShaderCalc Class Reference

This class used to perform shader-based calculations The usual pattern of usage: More...

#include <ShaderCalc.h>

Public Member Functions

template<class Type >
void toGpu (const char *name, cList< Type > &array, comms::cFormat::Enum format)
 Pass the input array for the calculations. More...
 
void AssignShader (const char *name)
 Assign the shader for the calculations. Don't call it often, it results in shader compiling. More...
 
void Assign (const char *id, int value)
 pass the variable into the shader More...
 
void AddSampler (const char *name, int TextureID)
 Add external texture to be used as the sampler in the shader calculations. More...
 
texInfo * Output (const char *name, cPtrDiff AmountOfElements, comms::cFormat::Enum format)
 Reserve the space for the output of the calculations. More...
 
void Execute (const char *OutputTextureName)
 Execute the shader over the chosen render target. More...
 
template<class Type >
void fromGpu (const char *name, cList< Type > &array)
 retrieve the result of the calculation More...
 
void ReturnTexturesToCommonPool ()
 return all used textures to the pool for the further usage but keep all inner structures for the fast re-use. Use it at the end of calculation cycle More...
 
void FreeTextures ()
 return all used textures to the pool for the further usage, clear textures array More...
 

Detailed Description

This class used to perform shader-based calculations The usual pattern of usage:

ShaderCalc sc;
///...fill array...
sc.toGpu("array", array, comms::cFormat::Enum::Rgba8);// refer te array as "uniform sampler2D array" in the shader
sc.output("result", 10000, comms::cFormat::Enum::Rgba8);// the output array, 10000 is just expected output size
sc.AssignShader("shader_name");// the path to shader (without glsl extension) relative tp data/Shaders/
sc.Execute("result");// the output render target created previously
sc.fromGpu("result", out);// we will get 10000 elements there
sc.ReturnTexturesToCommonPool();// allow future ShaderCalc calls use same textures for input/output
+ Inheritance diagram for scalc::ShaderCalc:

Member Function Documentation

void scalc::ShaderCalc::AddSampler ( const char *  name,
int  TextureID 
)

Add external texture to be used as the sampler in the shader calculations.

Parameters
nameThe name of the sampler to refer in the shader
TextureIDthe external texture ID

Referenced by scalc::VolumeObjectCellsGPU::PassAlpha().

void scalc::ShaderCalc::Assign ( const char *  id,
int  value 
)

pass the variable into the shader

Parameters
idthe uniform variable name to refer in shader
valuethe value to pass

Referenced by scalc::VolumeObjectCellsGPU::AddCells(), scalc::VolumeObjectCellsGPU::PassTrajectory(), and scalc::VolumeObjectCellsGPU::TrajectoryOverGPU().

void scalc::ShaderCalc::AssignShader ( const char *  name)

Assign the shader for the calculations. Don't call it often, it results in shader compiling.

Parameters
namethat path to file relative to the data/Shaders/

Referenced by scalc::VolumeObjectCellsGPU::Operate().

void scalc::ShaderCalc::Execute ( const char *  OutputTextureName)

Execute the shader over the chosen render target.

Parameters
OutputTextureNamethe name of the output render targed, should be reserved preliminary withe the ReserveLinearOutputCapacity

Referenced by scalc::VolumeObjectCellsGPU::Operate().

void scalc::ShaderCalc::FreeTextures ( )

return all used textures to the pool for the further usage, clear textures array

References scalc::TexPool::returnToPool().

template<class Type >
void scalc::ShaderCalc::fromGpu ( const char *  name,
cList< Type > &  array 
)

retrieve the result of the calculation

Template Parameters
Typethe type of the array element
Parameters
namename of the render target
arraythe resulting array

Referenced by scalc::VolumeObjectCellsGPU::BackToCells().

ShaderCalc::texInfo * scalc::ShaderCalc::Output ( const char *  name,
cPtrDiff  AmountOfElements,
comms::cFormat::Enum  format 
)

Reserve the space for the output of the calculations.

Parameters
namethe name of the render target, it will be referred in the Execute
AmountOfElementsthe size of output array to be calculated
formatthe output texture format
Returns

References scalc::TexPool::returnToPool().

Referenced by scalc::VolumeObjectCellsGPU::AddCells().

void scalc::ShaderCalc::ReturnTexturesToCommonPool ( )

return all used textures to the pool for the further usage but keep all inner structures for the fast re-use. Use it at the end of calculation cycle

References scalc::TexPool::returnToPool().

Referenced by scalc::VolumeObjectCellsGPU::BackToCells().

template<class Type >
void scalc::ShaderCalc::toGpu ( const char *  name,
cList< Type > &  array,
comms::cFormat::Enum  format 
)

Pass the input array for the calculations.

Template Parameters
Typethe array element type
Parameters
namename to be referred in the shader
arraythe array to pass into the shader
formatthe data format

Referenced by scalc::VolumeObjectCellsGPU::AddCells(), and scalc::VolumeObjectCellsGPU::PassTrajectory().


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