Shader

Functions

CID

GetClassID

void *

As

const void *

As

class T_As

As

class T_As

As

Shader

Shader *

Clone

RED_RC

UpdateFrom

~Shader

RED_RC

GetOperationStream

Detailed Description

class Shader : public RED::Object, public RED::IChunkSaver

Master shader class. Defines the way elements are rendered.

@related The Shading Pipeline, Registering and Adding a Shader to a Material Pass, class RED::IMaterial, class RED::RenderShader, class RED::StateShader, class RED::RenderCode

Shaders are objects involved during the construction of a material for the rendering of shapes in a scene. A shape owns one single material that defines the way it’ll be rendered and react to lighting.

There are two kind of shaders beyond the Shader class, which is a generic object:

  • The RED::RenderShader: this shader defines the rendering operations to perform. This shader uses vertex and pixel programs and define the way they are configured.

  • The RED::StateShader: this shader defines a render state to apply to the processing of the forthcoming shaders. For example, change in the blending equation, disarm of z-buffer testing or any other state management operation are managed through it.

Shaders are assembled in lists defining the rendering sequences of a material. As explained in the \ref bk_buildingmaterials book, there are three basic rendering sequences: pre-lighting, lighting and post-lighting, so a given material may have three separate shader lists (plus other special lists for dedicated shading purposes).

Shaders can’t be shared amongst materials, but can be shared amongst passes in the same material. Materials can be shared by many shapes.

RED::RenderShader and RED::StateShader shaders classes instances support platform selection, which enables the same shader to behave in a way that is specific to a given graphical hardware.

Subclassed by RED::RenderShader, RED::StateShader

Public Functions

virtual void *As(const RED::CID &iCID)

Converts the object to an instance of the given type.

Parameters

iCID – Requested class.

Returns

An object pointer of the given class on success, NULL otherwise.

virtual const void *As(const RED::CID &iCID) const

Converts the object to an instance of the given type.

Parameters

iCID – Requested class.

Returns

An object pointer of the given class on success, NULL otherwise.

template<class T_As>
inline T_As *As()
template<class T_As>
inline const T_As *As() const
Shader()

Constructor.

virtual Shader *Clone() const = 0

Object duplication.

This method must return a full copy of ‘this’.

Returns

A duplicate of ‘this’.

virtual RED_RC UpdateFrom(const RED::Object &iShader, const RED::State &iState, int iSrcStateNumber) = 0

Updates the instance with the content of the given one.

Parameters
  • iShader – Pointer to the source shader.

  • iState – Transaction parameter.

  • iSrcStateNumber – Transaction at which the source shader must be evaluated.

Returns

RED_OK on success,

RED_ALLOC_FAILURE on memory allocation error,

RED_FAILED otherwise.

virtual ~Shader()

Destructor.

virtual RED_RC GetOperationStream(const RED::Object *iCaller, RED::Vector<int> &ioStream, RED::HARDWARE_PLATFORM iPlatformId) const

Gets the operation stream of a shader.

Internal RED usage method. Writes down the shader stream.

Parameters
  • iCaller – Pointer to the method caller.

  • ioStream – Stream to write to.

  • iPlatformId – Target hardware platform identifier.

Returns

RED_OK when the shader write all its streams,

RED_ALLOC_FAILURE if an internal allocation did fail,

RED_FAIL otherwise.

Public Static Functions

static inline RED::CID GetClassID()