Cortex  10.0.0-a4
Classes | Public Member Functions | List of all members
IECoreGL::Shader Class Reference

A class to represent GLSL shaders. More...

#include <Shader.h>

+ Inheritance diagram for IECoreGL::Shader:

Classes

class  Setup
 

Public Member Functions

 IE_CORE_DECLARERUNTIMETYPEDEXTENSION (IECoreGL::Shader, ShaderTypeId, IECore::RunTimeTyped)
 
 Shader (const std::string &vertexSource, const std::string &fragmentSource)
 
 Shader (const std::string &vertexSource, const std::string &geometrySource, const std::string &fragmentSource)
 
GLuint program () const
 
void uniformParameterNames (std::vector< std::string > &names) const
 
const Parameter * uniformParameter (const std::string &name) const
 
void vertexAttributeNames (std::vector< std::string > &names) const
 Fills the passed vector with the names of all vertex shader parameters.
 
const Parameter * vertexAttribute (const std::string &name) const
 
 IE_CORE_DECLAREPTR (Setup)
 
Source accessors.

These functions return the shader source as passed to the constructor. In the case of an empty string being returned, you can determine the effective source by calling defaultVertexSource() or defaultFragmentSource().

const std::string & vertexSource () const
 
const std::string & geometrySource () const
 
const std::string & fragmentSource () const
 
Standard parameters

Cortex defines a set of standard shader parameters which are used to pass state to the shaders. These functions provide rapid access to the standard parameters if they exist.

Todo:
Pass the matrices and projections via standard parameters to avoid use of deprecated gl_ModelViewMatrix etc.
const Parameter * csParameter () const
 
- Public Member Functions inherited from IECore::RunTimeTyped
 IE_CORE_DECLAREMEMBERPTR (RunTimeTyped)
 
virtual TypeId typeId () const
 
virtual const char * typeName () const
 
virtual bool isInstanceOf (TypeId typeId) const
 
virtual bool isInstanceOf (const char *typeName) const
 
- Public Member Functions inherited from IECore::RefCounted
 IE_CORE_DECLAREMEMBERPTR (RefCounted)
 
void addRef () const
 Add a reference to the current object.
 
void removeRef () const
 Remove a reference from the current object.
 
RefCount refCount () const
 Returns the current reference count.
 

Static Public Member Functions

Common shader sources.

These functions return some common shader sources which may be useful in many situations.

static const std::string & defaultVertexSource ()
 
static const std::string & defaultGeometrySource ()
 
static const std::string & defaultFragmentSource ()
 
static const std::string & constantFragmentSource ()
 This uses fragmentCs as a constant flat color.
 
static const std::string & lambertFragmentSource ()
 This passes fragmentP and fragmentN to ieDiffuse.
 
Built in shaders

These functions provide access to static instances of various simple but useful shaders.

static Shaderconstant ()
 Returns a shader which shades as a constant flat color.
 
static ShaderfacingRatio ()
 Returns a shader which shades as a facing ratio.
 
- Static Public Member Functions inherited from IECore::RunTimeTyped
static TypeId staticTypeId ()
 Returns the TypeId for this class, without needing an instance.
 
static const char * staticTypeName ()
 Returns the type name for this class, without needing an instance.
 
static TypeId baseTypeId ()
 
static const char * baseTypeName ()
 
static bool inheritsFrom (TypeId typeId)
 Returns true if this class inherits from the specified type.
 
static bool inheritsFrom (const char *typeName)
 Returns true if this class inherits from the specified type.
 
static bool inheritsFrom (TypeId type, TypeId baseType)
 Returns true if type inherits from baseType.
 
static bool inheritsFrom (const char *typeName, const char *baseTypeName)
 Returns true if typeName inherits from baseTypeName.
 
static TypeId baseTypeId (TypeId typeId)
 Returns the base type of the given type, or InvalidTypeId if no such base exists.
 
static const std::vector< TypeId > & baseTypeIds (TypeId typeId)
 
static const std::set< TypeId > & derivedTypeIds (TypeId typeId)
 
static TypeId typeIdFromTypeName (const char *typeName)
 
static const char * typeNameFromTypeId (TypeId typeId)
 
static void registerType (TypeId derivedTypeId, const char *derivedTypeName, TypeId baseTypeId)
 Allows external modules to register their own type ids.
 

Additional Inherited Members

- Public Types inherited from IECore::RunTimeTyped
typedef RefCounted BaseClass
 A typedef for the class this class derives from. All RunTimeTyped classes define this typedef.
 
- Public Types inherited from IECore::RefCounted
typedef size_t RefCount
 
- Protected Types inherited from IECore::RunTimeTyped
typedef std::map< TypeId, TypeIdBaseTypeRegistryMap
 
typedef std::map< TypeId, std::vector< TypeId > > BaseTypesRegistryMap
 
typedef std::map< TypeId, std::set< TypeId > > DerivedTypesRegistryMap
 
typedef tbb::spin_rw_mutex Mutex
 
typedef std::map< TypeId, std::string > TypeIdsToTypeNamesMap
 
typedef std::map< std::string, TypeIdTypeNamesToTypeIdsMap
 
- Static Protected Member Functions inherited from IECore::RunTimeTyped
static BaseTypeRegistryMap & baseTypeRegistry ()
 
static DerivedTypesRegistryMap & derivedTypesRegistry ()
 
static BaseTypesRegistryMap & completeBaseTypesRegistry ()
 
static DerivedTypesRegistryMap & completeDerivedTypesRegistry ()
 
static void derivedTypeIdsWalk (TypeId typeId, std::set< TypeId > &)
 
static TypeIdsToTypeNamesMap & typeIdsToTypeNames ()
 
static TypeNamesToTypeIdsMap & typeNamesToTypeIds ()
 
- Static Protected Attributes inherited from IECore::RunTimeTyped
static Mutex g_baseTypeIdsMutex
 
static Mutex g_derivedTypeIdsMutex
 

Detailed Description

A class to represent GLSL shaders.

Constructor & Destructor Documentation

IECoreGL::Shader::Shader ( const std::string &  vertexSource,
const std::string &  fragmentSource 
)

Either vertexSource or fragmentSource may be empty to use a simple default shader for that shader component. Throws a descriptive Exception if the shader fails to compile.

IECoreGL::Shader::Shader ( const std::string &  vertexSource,
const std::string &  geometrySource,
const std::string &  fragmentSource 
)

Either vertexSource or fragmentSource may be empty to use a simple default shader for that shader component. If geometrySource is empty then no geometry shader will be used. Throws a descriptive Exception if the shader fails to compile.

Member Function Documentation

const Parameter* IECoreGL::Shader::csParameter ( ) const

Returns the "uniform vec3 Cs" parameter used to specify constant colours to the shader.

static const std::string& IECoreGL::Shader::defaultFragmentSource ( )
static

Default fragment shader source. This uses fragmentI, fragmentN and fragmentCs to compute a simple facing ratio.

static const std::string& IECoreGL::Shader::defaultGeometrySource ( )
static

Default geometry shader source. This is provided to make a common interface, but is actually just a no-op.

static const std::string& IECoreGL::Shader::defaultVertexSource ( )
static

Default vertex shader source. This takes vertexP, vertexN, vertexuv, vertexCs and Cs inputs and sets fragmentI, fragmentP, fragmentN, fragmentuv and fragmentCs outputs. It also sets equivalent geometry* outputs which may be used by geometry shaders in calculating new values for the corresponding fragment* outputs.

GLuint IECoreGL::Shader::program ( ) const

Returns the GL program this shader represents. Note that this is owned by the Shader, and will be destroyed upon destruction of the Shader - you must not call glDeleteProgram() yourself.

const Parameter* IECoreGL::Shader::uniformParameter ( const std::string &  name) const

Returns the details of the named uniform parameter, or 0 if no such parameter exists. The return value directly references data held within the Shader, and will die when the Shader dies.

void IECoreGL::Shader::uniformParameterNames ( std::vector< std::string > &  names) const

Fills the passed vector with the names of all uniform shader parameters. Structures will use the struct.component convention used in GLSL. Arrays will be returned as a single name, rather than the list array[0], array[n] names used internally in OpenGL.

const Parameter* IECoreGL::Shader::vertexAttribute ( const std::string &  name) const

Returns the details of the named vertex attribute, or 0 if no such parameter exists. The return value directly references data held within the Shader, and will die when the Shader dies.


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