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

This class holds the GPU-related information needed to build a shader program from a specific processor. More...

#include <OpenColorIO.h>

+ Inheritance diagram for OCIO_NAMESPACE::GpuShaderDesc:

Classes

struct  UniformData
 

Public Member Functions

GpuShaderCreatorRcPtr clone () const override
 
virtual unsigned getNumUniforms () const noexcept=0
 
virtual const char * getUniform (unsigned index, UniformData &data) const =0
 Returns name of uniform and data as parameter. More...
 
virtual unsigned getNumTextures () const noexcept=0
 
virtual void getTexture (unsigned index, const char *&textureName, const char *&samplerName, unsigned &width, unsigned &height, TextureType &channel, Interpolation &interpolation) const =0
 
virtual void getTextureValues (unsigned index, const float *&values) const =0
 
virtual unsigned getNum3DTextures () const noexcept=0
 
virtual void get3DTexture (unsigned index, const char *&textureName, const char *&samplerName, unsigned &edgelen, Interpolation &interpolation) const =0
 
virtual void get3DTextureValues (unsigned index, const float *&values) const =0
 
const char * getShaderText () const noexcept
 Get the complete OCIO shader program. More...
 
 GpuShaderDesc (const GpuShaderDesc &)=delete
 
GpuShaderDescoperator= (const GpuShaderDesc &)=delete
 
virtual ~GpuShaderDesc ()
 Do not use (needed only for pybind11). More...
 
- Public Member Functions inherited from OCIO_NAMESPACE::GpuShaderCreator
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...
 

Static Public Member Functions

static GpuShaderDescRcPtr CreateShaderDesc ()
 Create the default shader description. More...
 

Protected Member Functions

 GpuShaderDesc ()
 
- Protected Member Functions inherited from OCIO_NAMESPACE::GpuShaderCreator
 GpuShaderCreator ()
 
Impl * getImpl ()
 
const Impl * getImpl () const
 

Additional Inherited Members

- Public Types inherited from OCIO_NAMESPACE::GpuShaderCreator
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...
 
- Protected Attributes inherited from OCIO_NAMESPACE::GpuShaderCreator
Impl * m_impl
 

Detailed Description

This class holds the GPU-related information needed to build a shader program from a specific processor.

This class defines the interface and there are two implementations provided. The "legacy" mode implements the OCIO v1 approach of baking certain ops in order to have at most one 3D-LUT. The "generic" mode is the v2 default and allows all the ops to be processed as-is, without baking, like the CPU renderer. Custom implementations could be written to accommodate the GPU needs of a specific client app.

The complete fragment shader program is decomposed in two main parts: the OCIO shader program for the color processing and the client shader program which consumes the pixel color processing.

The OCIO shader program is fully described by the GpuShaderDesc independently from the client shader program. The only critical point is the agreement on the OCIO function shader name.

To summarize, the complete shader program is:

////////////////////////////////////////////////////////////////////////
// //
// The complete fragment shader program //
// //
////////////////////////////////////////////////////////////////////////
// //
// ////////////////////////////////////////////////////////////// //
// // // //
// // The OCIO shader program // //
// // // //
// ////////////////////////////////////////////////////////////// //
// // // //
// // // All global declarations // //
// // uniform sampled3D tex3; // //
// // // //
// // // All helper methods // //
// // vec3 computePos(vec3 color) // //
// // { // //
// // vec3 coords = color; // //
// // ... // //
// // return coords; // //
// // } // //
// // // //
// // // The OCIO shader function // //
// // vec4 OCIODisplay(in vec4 inColor) // //
// // { // //
// // vec4 outColor = inColor; // //
// // ... // //
// // outColor.rbg // //
// // = texture3D(tex3, computePos(inColor.rgb)).rgb; // //
// // ... // //
// // return outColor; // //
// // } // //
// // // //
// ////////////////////////////////////////////////////////////// //
// //
// ////////////////////////////////////////////////////////////// //
// // // //
// // The client shader program // //
// // // //
// ////////////////////////////////////////////////////////////// //
// // // //
// // uniform sampler2D image; // //
// // // //
// // void main() // //
// // { // //
// // vec4 inColor = texture2D(image, gl_TexCoord[0].st); // //
// // ... // //
// // vec4 outColor = OCIODisplay(inColor); // //
// // ... // //
// // gl_FragColor = outColor; // //
// // } // //
// // // //
// ////////////////////////////////////////////////////////////// //
// //
////////////////////////////////////////////////////////////////////////

Usage Example: Building a GPU shader

This example is based on the code in: src/apps/ociodisplay/main.cpp

// Get the processor
//
OCIO::ConstConfigRcPtr config = OCIO::Config::CreateFromEnv();
= config->getProcessor("ACES - ACEScg", "Output - sRGB");
// Step 1: Create a GPU shader description
//
// The two potential scenarios are:
//
// 1. Instantiate the generic shader description. The color processor
// is used as-is (i.e. without any baking step) and could contain
// any number of 1D & 3D luts.
//
// This is the default OCIO v2 behavior and allows a much better
// match between the CPU and GPU renderers.
//
OCIO::GpuShaderDescRcPtr shaderDesc = OCIO::GpuShaderDesc::Create();
//
// 2. Instantiate a custom shader description.
//
// Writing a custom shader description is a way to tailor the shaders
// to the needs of a given client program. This involves writing a
// new class inheriting from the pure virtual class GpuShaderDesc.
//
// Please refer to the GenericGpuShaderDesc class for an example.
//
OCIO::GpuShaderDescRcPtr shaderDesc = MyCustomGpuShader::Create();
shaderDesc->setLanguage(OCIO::GPU_LANGUAGE_GLSL_1_2);
shaderDesc->setFunctionName("OCIODisplay");
// Step 2: Collect the shader program information for a specific processor
//
processor->extractGpuShaderInfo(shaderDesc);
// Step 3: Create a helper to build the shader. Here we use a helper for
// OpenGL but there will also be helpers for other languages.
//
OpenGLBuilderRcPtr oglBuilder = OpenGLBuilder::Create(shaderDesc);
// Step 4: Allocate & upload all the LUTs
//
oglBuilder->allocateAllTextures();
// Step 5: Build the complete fragment shader program using
// g_fragShaderText which is the client shader program.
//
g_programId = oglBuilder->buildProgram(g_fragShaderText);
// Step 6: Enable the fragment shader program, and all needed textures
//
glUseProgram(g_programId);
glUniform1i(glGetUniformLocation(g_programId, "tex1"), 1); // image texture
oglBuilder->useAllTextures(g_programId); // LUT textures
// Step 7: Update uniforms from dynamic property instances.
m_oglBuilder->useAllUniforms();

Definition at line 3070 of file OpenColorIO.h.

Constructor & Destructor Documentation

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

Do not use (needed only for pybind11).

OCIO_NAMESPACE::GpuShaderDesc::GpuShaderDesc ( )
protected

Member Function Documentation

GpuShaderCreatorRcPtr OCIO_NAMESPACE::GpuShaderDesc::clone ( ) const
overridevirtual
static GpuShaderDescRcPtr OCIO_NAMESPACE::GpuShaderDesc::CreateShaderDesc ( )
static

Create the default shader description.

virtual void OCIO_NAMESPACE::GpuShaderDesc::get3DTexture ( unsigned  index,
const char *&  textureName,
const char *&  samplerName,
unsigned &  edgelen,
Interpolation interpolation 
) const
pure virtual
virtual void OCIO_NAMESPACE::GpuShaderDesc::get3DTextureValues ( unsigned  index,
const float *&  values 
) const
pure virtual
virtual unsigned OCIO_NAMESPACE::GpuShaderDesc::getNum3DTextures ( ) const
pure virtualnoexcept
virtual unsigned OCIO_NAMESPACE::GpuShaderDesc::getNumTextures ( ) const
pure virtualnoexcept
virtual unsigned OCIO_NAMESPACE::GpuShaderDesc::getNumUniforms ( ) const
pure virtualnoexcept
const char* OCIO_NAMESPACE::GpuShaderDesc::getShaderText ( ) const
noexcept

Get the complete OCIO shader program.

virtual void OCIO_NAMESPACE::GpuShaderDesc::getTexture ( unsigned  index,
const char *&  textureName,
const char *&  samplerName,
unsigned &  width,
unsigned &  height,
TextureType channel,
Interpolation interpolation 
) const
pure virtual
virtual void OCIO_NAMESPACE::GpuShaderDesc::getTextureValues ( unsigned  index,
const float *&  values 
) const
pure virtual
virtual const char* OCIO_NAMESPACE::GpuShaderDesc::getUniform ( unsigned  index,
UniformData data 
) const
pure virtual

Returns name of uniform and data as parameter.

GpuShaderDesc& OCIO_NAMESPACE::GpuShaderDesc::operator= ( const GpuShaderDesc )
delete

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