HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OCIO_NAMESPACE::GpuShaderCreator Class Referenceabstract

#include <OpenColorIO.h>

+ Inheritance diagram for OCIO_NAMESPACE::GpuShaderCreator:

Public Types

enum  TextureType { TEXTURE_RED_CHANNEL, TEXTURE_RGB_CHANNEL }
 
typedef std::function< double()> DoubleGetter
 Function returning a double, used by uniforms. GPU converts double to float. More...
 
typedef std::function< bool()> BoolGetter
 Function returning a bool, used by uniforms. More...
 
typedef std::function< const
Float3 &()> 
Float3Getter
 Functions returning a Float3, used by uniforms. More...
 
typedef std::function< int()> SizeGetter
 Function returning an int, used by uniforms. More...
 
typedef std::function< const
float *()> 
VectorFloatGetter
 Function returning a float *, used by uniforms. More...
 
typedef std::function< const
int *()> 
VectorIntGetter
 Function returning an int *, used by uniforms. More...
 

Public Member Functions

virtual GpuShaderCreatorRcPtr clone () const =0
 
const char * getUniqueID () const noexcept
 
void setUniqueID (const char *uid) noexcept
 
GpuLanguage getLanguage () const noexcept
 
void setLanguage (GpuLanguage lang) noexcept
 Set the shader program language. More...
 
const char * getFunctionName () const noexcept
 
void setFunctionName (const char *name) noexcept
 
const char * getPixelName () const noexcept
 
void setPixelName (const char *name) noexcept
 Set the pixel name variable holding the color values. More...
 
const char * getResourcePrefix () const noexcept
 
void setResourcePrefix (const char *prefix) noexcept
 Set a prefix to the resource name. More...
 
virtual const char * getCacheID () const noexcept
 
virtual void begin (const char *uid)
 Start to collect the shader data. More...
 
virtual void end ()
 End to collect the shader data. More...
 
virtual void setTextureMaxWidth (unsigned maxWidth)=0
 Some graphic cards could have 1D & 2D textures with size limitations. More...
 
virtual unsigned getTextureMaxWidth () const noexcept=0
 
unsigned getNextResourceIndex () noexcept
 
virtual bool addUniform (const char *name, const DoubleGetter &getDouble)=0
 
virtual bool addUniform (const char *name, const BoolGetter &getBool)=0
 
virtual bool addUniform (const char *name, const Float3Getter &getFloat3)=0
 
virtual bool addUniform (const char *name, const SizeGetter &getSize, const VectorFloatGetter &getVectorFloat)=0
 
virtual bool addUniform (const char *name, const SizeGetter &getSize, const VectorIntGetter &getVectorInt)=0
 
void addDynamicProperty (DynamicPropertyRcPtr &prop)
 Adds the property (used internally). More...
 
unsigned getNumDynamicProperties () const noexcept
 Dynamic Property related methods. More...
 
DynamicPropertyRcPtr getDynamicProperty (unsigned index) const
 
bool hasDynamicProperty (DynamicPropertyType type) const
 
DynamicPropertyRcPtr getDynamicProperty (DynamicPropertyType type) const
 
virtual void addTexture (const char *textureName, const char *samplerName, unsigned width, unsigned height, TextureType channel, Interpolation interpolation, const float *values)=0
 
virtual void add3DTexture (const char *textureName, const char *samplerName, unsigned edgelen, Interpolation interpolation, const float *values)=0
 
virtual void addToDeclareShaderCode (const char *shaderCode)
 
virtual void addToHelperShaderCode (const char *shaderCode)
 
virtual void addToFunctionHeaderShaderCode (const char *shaderCode)
 
virtual void addToFunctionShaderCode (const char *shaderCode)
 
virtual void addToFunctionFooterShaderCode (const char *shaderCode)
 
virtual void createShaderText (const char *shaderDeclarations, const char *shaderHelperMethods, const char *shaderFunctionHeader, const char *shaderFunctionBody, const char *shaderFunctionFooter)
 Create the OCIO shader program. More...
 
virtual void finalize ()
 
 GpuShaderCreator (const GpuShaderCreator &)=delete
 
GpuShaderCreatoroperator= (const GpuShaderCreator &)=delete
 
virtual ~GpuShaderCreator ()
 Do not use (needed only for pybind11). More...
 

Protected Member Functions

 GpuShaderCreator ()
 
Impl * getImpl ()
 
const Impl * getImpl () const
 

Protected Attributes

Impl * m_impl
 

Detailed Description

Inherit from the class to fully customize the implementation of a GPU shader program from a color transformation.

When no customizations are needed and the intermediate in-memory step is acceptable then the GpuShaderDesc is a better choice.

Note
To better decouple the DynamicProperties from their GPU implementation, the code provides several addUniform() methods i.e. one per access function types. For example, an ExposureContrastTransform instance owns three DynamicProperties and they are all implemented by a double. When creating the GPU fragment shader program, the addUniform() with GpuShaderCreator::DoubleGetter is called when property is dynamic, up to three times.

An OCIO shader program could contain:

  • A declaration part e.g., uniform sampled3D tex3;
  • Some helper methods
  • The OCIO shader function may be broken down as:
    • The function header e.g., void OCIODisplay(in vec4 inColor) {
    • The function body e.g., vec4 outColor.rgb = texture3D(tex3, inColor.rgb).rgb;
    • The function footer e.g., return outColor; }

Usage Example:

Below is a code snippet to highlight the different parts of the OCIO shader program.

// All global declarations
uniform sampled3D tex3;
// All helper methods
vec3 computePosition(vec3 color)
{
vec3 coords = color;
// Some processing...
return coords;
}
// The shader function
vec4 OCIODisplay(in vec4 inColor) //
{ // Function Header
vec4 outColor = inColor; //
outColor.rgb = texture3D(tex3, computePosition(inColor.rgb)).rgb;
return outColor; // Function Footer
} //

Definition at line 3014 of file OpenColorIO.h.

Member Typedef Documentation

typedef std::function<bool()> OCIO_NAMESPACE::GpuShaderCreator::BoolGetter

Function returning a bool, used by uniforms.

Definition at line 3066 of file OpenColorIO.h.

typedef std::function<double()> OCIO_NAMESPACE::GpuShaderCreator::DoubleGetter

Function returning a double, used by uniforms. GPU converts double to float.

Definition at line 3064 of file OpenColorIO.h.

Functions returning a Float3, used by uniforms.

Definition at line 3068 of file OpenColorIO.h.

Function returning an int, used by uniforms.

Definition at line 3070 of file OpenColorIO.h.

Function returning a float *, used by uniforms.

Definition at line 3072 of file OpenColorIO.h.

Function returning an int *, used by uniforms.

Definition at line 3074 of file OpenColorIO.h.

Member Enumeration Documentation

Enumerator
TEXTURE_RED_CHANNEL 

Only need a red channel texture.

TEXTURE_RGB_CHANNEL 

Need a RGB texture.

Definition at line 3107 of file OpenColorIO.h.

Constructor & Destructor Documentation

OCIO_NAMESPACE::GpuShaderCreator::GpuShaderCreator ( const GpuShaderCreator )
delete
virtual OCIO_NAMESPACE::GpuShaderCreator::~GpuShaderCreator ( )
virtual

Do not use (needed only for pybind11).

OCIO_NAMESPACE::GpuShaderCreator::GpuShaderCreator ( )
protected

Member Function Documentation

virtual void OCIO_NAMESPACE::GpuShaderCreator::add3DTexture ( const char *  textureName,
const char *  samplerName,
unsigned  edgelen,
Interpolation  interpolation,
const float values 
)
pure virtual

Add a 3D texture with RGB channel type.

Note
The 'values' parameter contains the 3D LUT data which must be used as-is as the dimension and origin are hard-coded in the fragment shader program. So, it means one GPU 3D texture per entry.
void OCIO_NAMESPACE::GpuShaderCreator::addDynamicProperty ( DynamicPropertyRcPtr prop)

Adds the property (used internally).

virtual void OCIO_NAMESPACE::GpuShaderCreator::addTexture ( const char *  textureName,
const char *  samplerName,
unsigned  width,
unsigned  height,
TextureType  channel,
Interpolation  interpolation,
const float values 
)
pure virtual

Add a 2D texture (1D texture if height equals 1).

Note
The 'values' parameter contains the LUT data which must be used as-is as the dimensions and origin are hard-coded in the fragment shader program. So, it means one GPU texture per entry.
virtual void OCIO_NAMESPACE::GpuShaderCreator::addToDeclareShaderCode ( const char *  shaderCode)
virtual
virtual void OCIO_NAMESPACE::GpuShaderCreator::addToFunctionFooterShaderCode ( const char *  shaderCode)
virtual
virtual void OCIO_NAMESPACE::GpuShaderCreator::addToFunctionHeaderShaderCode ( const char *  shaderCode)
virtual
virtual void OCIO_NAMESPACE::GpuShaderCreator::addToFunctionShaderCode ( const char *  shaderCode)
virtual
virtual void OCIO_NAMESPACE::GpuShaderCreator::addToHelperShaderCode ( const char *  shaderCode)
virtual
virtual bool OCIO_NAMESPACE::GpuShaderCreator::addUniform ( const char *  name,
const DoubleGetter getDouble 
)
pure virtual
virtual bool OCIO_NAMESPACE::GpuShaderCreator::addUniform ( const char *  name,
const BoolGetter getBool 
)
pure virtual
virtual bool OCIO_NAMESPACE::GpuShaderCreator::addUniform ( const char *  name,
const Float3Getter getFloat3 
)
pure virtual
virtual bool OCIO_NAMESPACE::GpuShaderCreator::addUniform ( const char *  name,
const SizeGetter getSize,
const VectorFloatGetter getVectorFloat 
)
pure virtual
virtual bool OCIO_NAMESPACE::GpuShaderCreator::addUniform ( const char *  name,
const SizeGetter getSize,
const VectorIntGetter getVectorInt 
)
pure virtual
virtual void OCIO_NAMESPACE::GpuShaderCreator::begin ( const char *  uid)
virtual

Start to collect the shader data.

virtual GpuShaderCreatorRcPtr OCIO_NAMESPACE::GpuShaderCreator::clone ( ) const
pure virtual
virtual void OCIO_NAMESPACE::GpuShaderCreator::createShaderText ( const char *  shaderDeclarations,
const char *  shaderHelperMethods,
const char *  shaderFunctionHeader,
const char *  shaderFunctionBody,
const char *  shaderFunctionFooter 
)
virtual

Create the OCIO shader program.

Note
The OCIO shader program is decomposed to allow a specific implementation to change some parts. Some product integrations add the color processing within a client shader program, imposing constraints requiring this flexibility.
virtual void OCIO_NAMESPACE::GpuShaderCreator::end ( )
virtual

End to collect the shader data.

virtual void OCIO_NAMESPACE::GpuShaderCreator::finalize ( )
virtual
virtual const char* OCIO_NAMESPACE::GpuShaderCreator::getCacheID ( ) const
virtualnoexcept
DynamicPropertyRcPtr OCIO_NAMESPACE::GpuShaderCreator::getDynamicProperty ( unsigned  index) const
DynamicPropertyRcPtr OCIO_NAMESPACE::GpuShaderCreator::getDynamicProperty ( DynamicPropertyType  type) const

Dynamic properties allow changes once the fragment shader program has been created. The steps are to get the appropriate DynamicProperty instance, and then change its value.

const char* OCIO_NAMESPACE::GpuShaderCreator::getFunctionName ( ) const
noexcept
Impl* OCIO_NAMESPACE::GpuShaderCreator::getImpl ( )
inlineprotected

Definition at line 3174 of file OpenColorIO.h.

const Impl* OCIO_NAMESPACE::GpuShaderCreator::getImpl ( ) const
inlineprotected

Definition at line 3175 of file OpenColorIO.h.

GpuLanguage OCIO_NAMESPACE::GpuShaderCreator::getLanguage ( ) const
noexcept
unsigned OCIO_NAMESPACE::GpuShaderCreator::getNextResourceIndex ( )
noexcept

To avoid global texture sampler and uniform name clashes always append an increasing index to the resource name.

unsigned OCIO_NAMESPACE::GpuShaderCreator::getNumDynamicProperties ( ) const
noexcept

Dynamic Property related methods.

const char* OCIO_NAMESPACE::GpuShaderCreator::getPixelName ( ) const
noexcept
const char* OCIO_NAMESPACE::GpuShaderCreator::getResourcePrefix ( ) const
noexcept
Note
Some applications require that textures, uniforms, and helper methods be uniquely named because several processor instances could coexist.
virtual unsigned OCIO_NAMESPACE::GpuShaderCreator::getTextureMaxWidth ( ) const
pure virtualnoexcept
const char* OCIO_NAMESPACE::GpuShaderCreator::getUniqueID ( ) const
noexcept
bool OCIO_NAMESPACE::GpuShaderCreator::hasDynamicProperty ( DynamicPropertyType  type) const
GpuShaderCreator& OCIO_NAMESPACE::GpuShaderCreator::operator= ( const GpuShaderCreator )
delete
void OCIO_NAMESPACE::GpuShaderCreator::setFunctionName ( const char *  name)
noexcept
void OCIO_NAMESPACE::GpuShaderCreator::setLanguage ( GpuLanguage  lang)
noexcept

Set the shader program language.

void OCIO_NAMESPACE::GpuShaderCreator::setPixelName ( const char *  name)
noexcept

Set the pixel name variable holding the color values.

void OCIO_NAMESPACE::GpuShaderCreator::setResourcePrefix ( const char *  prefix)
noexcept

Set a prefix to the resource name.

virtual void OCIO_NAMESPACE::GpuShaderCreator::setTextureMaxWidth ( unsigned  maxWidth)
pure virtual

Some graphic cards could have 1D & 2D textures with size limitations.

void OCIO_NAMESPACE::GpuShaderCreator::setUniqueID ( const char *  uid)
noexcept

Member Data Documentation

Impl* OCIO_NAMESPACE::GpuShaderCreator::m_impl
protected

Definition at line 3172 of file OpenColorIO.h.


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