class RED::RenderCode

Input specification of a RED::RenderShader. More...

#include <REDRenderCode.h>

Inherits: IChunkSaver and Object.

Public functions:

RenderCode ( )
virtual ~RenderCode ( )
virtual void *As ( const RED::CID & iCID )
virtual const void *As ( const RED::CID & iCID ) const
template< class T_As > const T_As *As ( ) const
template< class T_As > T_As *As ( )
voidBindChannel ( RED_VSH_INPUT iShaderInput, RED::MESH_CHANNEL iChannel )
RED_RCBindChannelAsLocal ( int iLocal, RED::MESH_CHANNEL iChannel )
voidClearChannelLocalBindings ( )
const int *GetChannelLocalBindings ( ) const
int *GetChannelLocalBindings ( )
unsigned intGetChannelLocalBindingsCount ( ) const
intGetShaderInput ( RED_VSH_INPUT iShaderInput ) const
boolHasModelMatrix ( ) const
boolHasModelViewMatrix ( ) const
boolHasModelViewProjectionMatrix ( ) const
boolHasViewMatrix ( ) const
IMPLEMENT_CHUNKINTERPRETER ( )
boolIsChannelNormalized ( RED_VSH_INPUT iShaderInput ) const
boolIsGenericGLSLBindings ( ) const
voidReset ( )
virtual RED_RCSave ( RED::IStream * iStream, StreamingPolicy & iPolicy, int iState = -1 ) const
voidSetGenericGLSLBindings ( bool iGeneric )
voidSetModelMatrix ( bool iRequest )
voidSetModelViewMatrix ( bool iRequest )
voidSetModelViewProjectionMatrix ( bool iRequest )
voidSetNormalizedChannel ( RED_VSH_INPUT iShaderInput, bool iOnOff = true )
voidSetViewMatrix ( bool iRequest )

Public static functions:

static RED::CIDGetClassID ( )

Protected variables:

bool_glsl_generic
bool_hdmv
bool_hdmvp
bool_iocs2wcs
bool_iwcs2vcs
int_meshaslocal [RED_RCODE_MAX_LOCAL_BINDINGS]
unsigned int_nb_meshaslocal
bool_normalized [RED_VSH_NB_INPUTS]
int_vshinput [RED_VSH_NB_INPUTS]

Detailed description:

Input specification of a RED::RenderShader.

This class performs the mapping between geometrical inputs and vertex shader inputs. We have two categories of shader inputs that are handled in the class:

We use the following definitions to classify matrices:

Some well known matrices are expressed this way:

Input matrices are sent to the vertex shader program using the following bindings (ARB or GLSL):

Matrices described above are high definition matrices, which are double precision concatenations of all the matrices that compose the transformation pipeline, before being loaded to the OpenGL layer.

The modelview matrix and the modelview projection matrices are enabled by default. The model matrix and the view matrices are disabled by default.

The legacy OpenGL pipeline matrix are still accessible in shaders. These matrices have a lower accuracy compared to matrices emitted by the RED::RenderCode and accessible by shaders using them:

The matrix transformations stages

A vertex shader input channel must be set to an output of a geometrical data of a shape to be rendered. For instance, the RED::MCL_VERTEX vertex array of a geometry must be bound to the RED_VSH_VERTEX input channel of a vertex program for the positions of the geometry to be sent to the program. A value of (-1) indicates that the vertex shader input is not bound to any geometrical output of the engine.

The RenderCode features a specific binding mechanism usable only for all ray-traced indirect lighting calculations: mesh input channels can be bound as program locals for the processing of indirect rays. This mechanism aims at overcoming the limited number of interpolation channels provided by the hardware that is often outnumbered by indirect shaders.

GLSL bindings can be modified for some hardware. See RED::RenderCode::SetGenericGLSLBindings.

Functions documentation

Default construction method.

Destructor.

public virtual void * RED::RenderCode::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.

Reimplements: RED::Object::As.

public virtual const void * RED::RenderCode::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.

Reimplements: RED::Object::As.

template< class T_As > public const T_As * RED::RenderCode::As() const

Template version of the as const method.

Simply set T to be the class you want to retrieve an interface to.

Returns:

A pointer to a const instance of class T on success, NULL otherwise.

Reimplements: RED::Object::As.

template< class T_As > public T_As * RED::RenderCode::As()

Template version of the as method.

Simply set T to be the class you want to retrieve an interface to.

Returns:

A pointer to an instance of class T on success, NULL otherwise.

Reimplements: RED::Object::As.

Binds a geometrical data channel on a vertex shader's channel.

This method specify which geometrical channel of the input geometry is to be bound as a vertex attribute of the vertex shader.

An example of use of this function can be found in the Writing a custom rendering shader in ARB tutorial.

Parameters:

iShaderInput:Vertex shader input to bind.
iChannel:Geometrical data channel source of the information.

Binds a channel as program local parameter.

This method only works for the rendering of indirect lighting passes. It binds the specified mesh input channel directly as a set of three constants accessible directly at the pixel shader stage.

The reason behind this mechanism is the fact that there's only a limited number of interpolation channels available between a vertex program and a pixel program. Because we replicate each data channel three times for each vertex of a triangle, we quickly overload the number of available interpolation channels.

iChannel triangle data of rendered meshes will be bound at iLocal, iLocal+1 and iLocal+2 for all indirect lighting passes. The method stacks all channel binding orders so that the same channel can be bound twice or more on program locals.

Parameters:

iLocal:'program.local' slots that are to be used for the binding of iChannel. We use three consecutive slots iLocal, iLocal+1 and iLocal+2.
iChannel:Mesh input channel to bind.

Returns:

RED_OK if the operation has succeeded,
RED_BAD_PARAM if the method has received an invalid parameter,
RED_ALLOC_FAILURE if an internal allocation has failed,
RED_FAIL if we exceed the maximal number of possible local bindings.

Removes all mesh data channels local bindings.

Returns the list of local channel bindings.

Returns:

A list of (channel,local) bindings. Each integer in the list is encoded using (channel + (local << 16)).

Returns the list of local channel bindings.

Returns:

A list of (channel,local) bindings. Each integer in the list is encoded using (channel + (local << 16)).

Returns the number of local channel bindings.

Returns:

The number of channel binding orders as program locals.

Returns the vertex shader input binding.

This method returns the geometrical channel that is bound to a given vertex shader attribute entry.

Parameters:

iShaderInput:The queried vertex shader input.

Returns:

-1 if we have no data bound to this channel, or a value in the RED::MESH_CHANNEL enum.

Do we use the model matrix in our shader?

Returns:

true if we use that matrix, false otherwise.

Do we use the modelview matrix in our shader?

Returns:

true if we use that matrix, false otherwise.

Do we use the modelview projection matrix in our shader?

Returns:

true if we use that matrix, false otherwise.
public bool RED::RenderCode::HasViewMatrix() const

Do we use the view matrix in our shader?

Returns:

true if we use that matrix, false otherwise.

Is the given channel normalized?

Parameters:

iShaderInput:The channel id.

Returns:

true if the corresponding channel is normalized, false otherwise.

Returns:

true if generic GLSL bindings are in use everywhere, false otherwise.

Re-initializes a RenderCode.

Set all values back to "no bind" (-1), disarms all matrix requests.

public virtual RED_RC RED::RenderCode::Save(RED::IStream *iStream,
StreamingPolicy &iPolicy,
intiState = -1
)const

Saves the object content as one or more chunks in the given stream.

Parameters:

iStream:Pointer to the stream where the data must be saved.
iPolicy:Reference to the streaming policy to be used.
iState:Optional state number parameter at which the data to be saved must be retrieved. Default is set to 0 (for current state).

Returns:

RED_OK on success,
RED_FILE_WRITE_ERROR on a file write error (if iStream is a file stream),
RED_ALLOC_FAILURE on a memory allocation error,
RED_FAIL otherwise.

Implements: RED::IChunkSaver::Save.

public void RED::RenderCode::SetGenericGLSLBindings(booliGeneric)

Override legacy GLSL bindings on AMD and INTEL to favor generic attributes bindings.

When running GLSL shaders - by default and to get the broadest range of compatible hardware - REDsdk uses:

  • glVertexAttribPointer calls to bind mesh inputs on NVIDIA hardware.
  • glVertexPointer, glNormalPointer, glTexCoordPointer, ...on AMD and INTEL hardware.

These legacy bindings that can be used to write old style GLSL programs don't allow the use of modern bindings based on 'layout( location = xxx ) in vec4 myValue" on AMD and INTEL graphics. By turning on the iGeneric flag in this method, legacy bindings are replaced by generic attribute bindings allowing the usage of layout declarations across all hardware.

Parameters:

iGeneric:Set to true to force generic bindings across all hardwares, false to keep generic bindings on NVIDIA, and legacy bindings on AMD / INTEL.
public void RED::RenderCode::SetModelMatrix(booliRequest)

Requests the model matrix.

The model matrix is bound to the vertex shader input, if iRequest is true. The model matrix can be accessed as the GL_MATRIX1_ARB bound matrix in OpenGL. Therefore, it can be accessed as 'state.matrix.program[1]' in ARB shaders and as 'gl_TextureMatrix[1]' in GLSL.

This matrix is disabled by default.

The Writing a custom rendering shader using geometry program tutorial contains a good example of how this function works.

Parameters:

iRequest:Ask for that matrix if true.
public void RED::RenderCode::SetModelViewMatrix(booliRequest)

Requests the modelview matrix.

This matrix is the result of the double precision multiplication of the camera view matrix by the current model transformation matrix. The result is double precision and uploaded on the GPU. It can be accessed as the GL_MATRIX3_ARB bound matrix in OpenGL. Therfore it can be accessed as 'state.matrix.program[3]' in ARB shaders and as 'gl_TextureMatrix[3]' in GLSL.

This matrix is enabled by default.

Parameters:

iRequest:Ask for the calculation of that matrix if true.

Requests the modelview projection matrix.

This matrix is the result of the double precision multiplication of the projection matrix by the camera view matrix and by the current model transformation matrix. The result is double precision and uploaded on the GPU. It can be accessed as the GL_MATRIX2_ARB bound matrix in OpenGL. Therefore it can be accessed as 'state.matrix.program[2]' in ARB shaders and as 'gl_TextureMatrix[2]' in GLSL.

This matrix is enabled by default.

Parameters:

iRequest:Ask for the calculation of that matrix if true.
public void RED::RenderCode::SetNormalizedChannel(RED_VSH_INPUTiShaderInput,
booliOnOff = true
)

Forces the data bound to a channel to be normalized.

The default behavior of the RenderCode is to let the data sent for a rendering order unmodified. However, through this method a channel can be normalized: e.g. the length of the vector sent to the GPU is set to 1.
The channel normalization may not be supported for all combinations of vector sizes/formats.

Parameters:

iShaderInput:Shader input channel to be normalized.
iOnOff:Enable or disable the normalization.
public void RED::RenderCode::SetViewMatrix(booliRequest)

Requests the view matrix.

The view matrix is bound to the vertex shader input, if iRequest is true. The view matrix can be accessed as the GL_MATRIX0_ARB bound matrix in OpenGL. Therefore, it can be accessed as 'state.matrix.program[0]' in ARB shaders and as 'gl_TextureMatrix[0]' in GLSL.

This matrix is disabled by default.

The Writing a custom rendering shader using geometry program tutorial contains a good example of how this function works.

Parameters:

iRequest:Ask for that matrix if true.

Variables documentation

GLSL generic binding mode.

protected bool RED::RenderCode::_hdmv

Request the high definition modelview matrix?

Request the high definition modelview projection matrix?

Request the model matrix?

Request the view matrix?

protected int RED::RenderCode::_meshaslocal[RED_RCODE_MAX_LOCAL_BINDINGS]

Mesh channel bindings as program.local list. Encoded as channel + ( local << 16 ).

Number of bindings currently registered in _meshaslocal.

protected bool RED::RenderCode::_normalized[RED_VSH_NB_INPUTS]

List of normalized channels.

protected int RED::RenderCode::_vshinput[RED_VSH_NB_INPUTS]

Vertex shader channels bindings.