Loading...
Searching...
No Matches
HioGlslfx Class Reference

A class representing the config and shader source of a glslfx file. More...

#include <glslfx.h>

Public Member Functions

HIO_API HioGlslfx ()
 Create an invalid glslfx object.
 
HIO_API HioGlslfx (std::string const &filePath, TfToken const &technique=HioGlslfxTokens->defVal)
 Create a glslfx object from a file.
 
HIO_API HioGlslfx (std::istream &is, TfToken const &technique=HioGlslfxTokens->defVal)
 Create a glslfx object from a stream.
 
HIO_API HioGlslfxConfig::Parameters GetParameters () const
 Return the parameters specified in the configuration.
 
HIO_API HioGlslfxConfig::Textures GetTextures () const
 Return the textures specified in the configuration.
 
HIO_API HioGlslfxConfig::Attributes GetAttributes () const
 Return the attributes specified in the configuration.
 
HIO_API HioGlslfxConfig::MetadataDictionary GetMetadata () const
 Return the metadata specified in the configuration.
 
HIO_API bool IsValid (std::string *reason=NULL) const
 Returns true if this is a valid glslfx file.
 
HIO_API VtDictionary GetLayoutAsDictionary (const TfTokenVector &shaderStageKeys, std::string *errorStr) const
 Get the layout config as a VtDictionary parsed from the JSON layout config corresponding to the shader source associated with the given keys.
 
HIO_API std::string GetSource (const TfToken &shaderStageKey) const
 Get the shader source associated with given key.
 
const std::string & GetFilePath () const
 Get the original file name passed to the constructor.
 
const std::set< std::string > & GetFiles () const
 Return set of all files processed for this glslfx object.
 
size_t GetHash () const
 Return the computed hash value based on the string.
 
Access to commonly used shader sources.
HIO_API std::string GetSurfaceSource () const
 Get the surface source string.
 
HIO_API std::string GetDisplacementSource () const
 Get the displacement source string.
 
HIO_API std::string GetVolumeSource () const
 Get the volume source string.
 

Static Public Member Functions

static HIO_API std::vector< std::string > ExtractImports (const std::string &filename)
 Extract imported files from the specified glslfx file.
 

Detailed Description

A class representing the config and shader source of a glslfx file.

a HioGlslfx object is constructed by providing the path of a file whose contents look something like this:

-- glslfx version 0.1
-- configuration
{
'textures' : {
'texture_1':{
'documentation' : 'a useful texture.',
},
'texture_2':{
'documentation' : 'another useful texture.',
},
},
'parameters': {
'param_1' : {
'default' : 1.0,
'documentation' : 'the first parameter'
},
'param_2' : {
'default' : [1.0, 1.0, 1.0],
'documentation' : 'a vec3f parameter'
},
'param_3' : {
'default' : 2.0
},
'param_4' : {
'default' : True
},
'param_5' : {
'default' : [1.0, 1.0, 1.0],
'role' : 'color'
'documentation' : 'specifies a color for use in the shader'
},
},
'parameterOrder': ['param_1',
'param_2',
'param_3',
'param_4',
'param_5'],
'techniques': {
'default': {
'fragmentShader': {
'source': [ 'MyFragment' ]
}
},
'metal': {
'fragmentShader': {
'source': [ 'MyFragment.Metal' ]
}
}
}
}
-- glsl MyFragment
uniform float param_1;
uniform float param_2;
uniform float param_3;
uniform float param_4;
uniform float param_5;
void main()
{
// ...
// glsl code which consumes the various uniforms, and perhaps sets
// gl_FragColor = someOutputColor;
// ...
}

Definition at line 150 of file glslfx.h.

Constructor & Destructor Documentation

◆ HioGlslfx() [1/3]

HIO_API HioGlslfx ( )

Create an invalid glslfx object.

◆ HioGlslfx() [2/3]

HIO_API HioGlslfx ( std::string const &  filePath,
TfToken const &  technique = HioGlslfxTokens->defVal 
)

Create a glslfx object from a file.

◆ HioGlslfx() [3/3]

HIO_API HioGlslfx ( std::istream &  is,
TfToken const &  technique = HioGlslfxTokens->defVal 
)

Create a glslfx object from a stream.

Member Function Documentation

◆ ExtractImports()

static HIO_API std::vector< std::string > ExtractImports ( const std::string &  filename)
static

Extract imported files from the specified glslfx file.

The returned paths are as-authored, in the order of declaration, with possible duplicates. This function is not recursive – it only extracts imports from the specified filename.

◆ GetAttributes()

HIO_API HioGlslfxConfig::Attributes GetAttributes ( ) const

Return the attributes specified in the configuration.

◆ GetDisplacementSource()

HIO_API std::string GetDisplacementSource ( ) const

Get the displacement source string.

◆ GetFilePath()

const std::string & GetFilePath ( ) const
inline

Get the original file name passed to the constructor.

Definition at line 218 of file glslfx.h.

◆ GetFiles()

const std::set< std::string > & GetFiles ( ) const
inline

Return set of all files processed for this glslfx object.

This includes the original file given to the constructor as well as any other files that were imported. This set will only contain files that exist.

Definition at line 224 of file glslfx.h.

◆ GetHash()

size_t GetHash ( ) const
inline

Return the computed hash value based on the string.

Definition at line 227 of file glslfx.h.

◆ GetLayoutAsDictionary()

HIO_API VtDictionary GetLayoutAsDictionary ( const TfTokenVector shaderStageKeys,
std::string *  errorStr 
) const

Get the layout config as a VtDictionary parsed from the JSON layout config corresponding to the shader source associated with the given keys.

◆ GetMetadata()

HIO_API HioGlslfxConfig::MetadataDictionary GetMetadata ( ) const

Return the metadata specified in the configuration.

◆ GetParameters()

HIO_API HioGlslfxConfig::Parameters GetParameters ( ) const

Return the parameters specified in the configuration.

◆ GetSource()

HIO_API std::string GetSource ( const TfToken shaderStageKey) const

Get the shader source associated with given key.

◆ GetSurfaceSource()

HIO_API std::string GetSurfaceSource ( ) const

Get the surface source string.

◆ GetTextures()

HIO_API HioGlslfxConfig::Textures GetTextures ( ) const

Return the textures specified in the configuration.

◆ GetVolumeSource()

HIO_API std::string GetVolumeSource ( ) const

Get the volume source string.

◆ IsValid()

HIO_API bool IsValid ( std::string *  reason = NULL) const

Returns true if this is a valid glslfx file.


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