Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | Namespace Members | Class Members | Related Pages

VertexAttribBinding Class Reference
[XEngineCore Library]

List of all members.

Detailed Description

A vertex attribute binding binds an attribute, specified via a vertex buffer stream index and via its index in a vertex format, to an input variable name used in a vertex shader (or in the fixed-function pipeline). In other words, a vertex attribute binding represents and defines the connection between the vertex data stored in the vertex buffers and the graphics pipeline. It gives the various vertex attributes of a vertex stored in vertex buffers a meaning.

Since XEngine supports multiple vertex buffer streams, an object of this class can store vertex attribute bindings not only for one but for multiple vertex formats. Each vertex format gets an associated stream index and defines the format of the vertex buffers that can be used for that particular vertex buffer stream when calling one of the RenderContext::Draw methods.

This stream concept allows for splitting up the vertex attributes that make up a vertex and storing them in different vertex buffers. For example, one buffer might contain the vertex position, set to stream 0, and the primary vertex color and texture coordinate sets, set to stream 1. Now if the position changes from frame to frame, only the vertex buffer for stream 0 must be locked and changed.

A binding does not necessarily have to bind all the vertex attributes described by the vertex format for a particular vertex buffer stream. The not bound vertex attributes will simply be ignored and cannot be used by the vertex shader. This enables re-use of vertex buffers with different vertex shaders, which is especially important for multi-pass rendering.

Fixed-Function Vertex Shaders

Also the vertex shaders using the fixed-function pipeline require a vertex attribute binding. However, this binding is a bit more restrictive than when using the programmable pipeline. Firstly, the vertex attributes need to be specified in a certain order and need to be packed tightly (so it is not permissible to not bind an attribute; however, vertex buffer streams might contain not used vertex attributes at the end). Secondly, the data type for each attribute is pre-determined and cannot be changed by the application. Thirdly, there are default variable names to which the vertex attributes must be bound to. For a list of available vertex attributes and their data types for the fixed-function pipeline, look at the documentation of the VertexFormat class.

The default bindings for the fixed-function pipeline have the following names and they cannot be bound in any other order than specified here:

TexCoord[n] specifies n sets of texture coordinates, where n is implementation-specific and begins with 0. n specifies the texture sampler stage that is supposed to be fed with the texture coordinates. The texture coordinate sets do not have to be ordered by texture sampler stage number. So this is a perfectly legal binding for the fixed-function pipeline

Position - Normal - TexCoord[5] - TexCoord[0] - TexCoord[2]

but the following isn't, because of the wrong order of the normal and the primary color

Position - PrimaryColor - Normal

If you use one of the pre-defined VertexTypeXXX classes offered by XEngine, such as VertexTypeNormal, you can call VertexTypeNormal::GetVertexAttribBinding to get an appropriate binding object for them.

Note that fixed-function shaders can also use multiple vertex buffer streams, if desired. However, the order of the vertex attributes must still be the same as given above. Multiple vertex buffer streams can be used to split up the vertex attributes into multiple vertex buffers. The following is a legal binding for a fixed-function vertex shader that uses multiple streams

Stream 1: Position - Normal
Stream 3: PrimaryColor - TexCoord[0]

but the following is not a legal binding because the order of the vertex attributes is incorrect

Stream 1: Position - PrimaryColor
Stream 3: Normal - TexCoord[0]

Warning:
Note that it is not possible to specify multiple bindings for a single vertex attribute. So it's, for example, not possible to specify a binding that binds the second vertex attribute to TexCoord[0] and to TexCoord[1]. You'll get an assert in the debug build of the library, if you try to do this. If you want to use one set of per-vertex texture coordinates for multiple texture accesses, you have to write a vertex shader that copies the texture coordinates to multiple output texture coordinates registers or manually copy the set of texture coordinates in the vertex buffers.


Public Types

typedef std::map< size_t,
wxString > 
BindingsMap
 Associative container type that is used to store the bindings. It maps a vertex attribute index to the bound name.
typedef std::map< size_t,
std::pair< VertexFormat,
BindingsMap > > 
StreamToBindingsMap
 Associative container type that stores the stream bindings. The stream index is mapped to the vertex format and the bindings used by the stream.

Public Member Functions

 VertexAttribBinding ()
 Default constructor that creates an empty vertey attribute binding.
 VertexAttribBinding (const VertexFormat &format)
 Constructor for a vertex attribute binding that takes the vertex format of vertex buffer stream 0 as parameter.
 VertexAttribBinding (const VertexFormat &format0, const VertexFormat &format1)
 Constructor for a vertex attribute binding that takes the vertex format of vertex buffer streams 0 and 1 as parameter.
void AddStream (size_t streamIndex, const VertexFormat &format)
 Adds a new stream to this vertex attribute binding using the given vertex format.
void AddBinding (size_t vertexAttribIndex, const wxString &vertexAttribName, size_t streamIndex=0)
 Binds a particular vertex attribute to a variable name.
const VertexFormatGetVertexFormat (size_t streamIndex=0) const
 Returns the vertex format for which this binding is valid for a particular vertex buffer stream.
size_t GetStreamCount () const
 Returns the number of vertex buffer streams used in this vertex attribute binding.
bool UsesStream (size_t streamIndex) const
 Returns true, if the given stream index is used in this vertex attribute binding.
template<typename OutputIteratorT>
void GetUsedStreams (OutputIteratorT it) const
 Returns the streams used in this binding using the given size_t output iterator.
wxString GetBinding (size_t vertexAttribIndex, size_t streamIndex=0) const
 Returns the variable name a vertex attribute is bound to by this binding.
size_t GetBindingCount (size_t streamIndex=0) const
 Returns the number of bindings for the given stream index.
const BindingsMapGetBindings (size_t streamIndex=0) const
 Returns all bindings stored in this object for the given vertex buffer stream.
bool IsValidFixedFunctionBinding () const
 Returns true if this binding is valid for the fixed-function pipeline.


Constructor & Destructor Documentation

VertexAttribBinding  ) 
 

Default constructor that creates an empty vertey attribute binding.

VertexAttribBinding const VertexFormat format  )  [explicit]
 

Constructor for a vertex attribute binding that takes the vertex format of vertex buffer stream 0 as parameter

VertexAttribBinding const VertexFormat format0,
const VertexFormat format1
 

Constructor for a vertex attribute binding that takes the vertex format of vertex buffer streams 0 and 1 as parameter.


Member Function Documentation

void AddBinding size_t  vertexAttribIndex,
const wxString &  vertexAttribName,
size_t  streamIndex = 0
 

Binds a particular vertex attribute of a specific vertex buffer stream to a variable name.

void AddStream size_t  streamIndex,
const VertexFormat format
 

Adds a new stream to this vertex attribute binding using the given vertex format. The given stream index must not yet be used by this binding.

wxString GetBinding size_t  vertexAttribIndex,
size_t  streamIndex = 0
const
 

Returns the variable name a vertex attribute is bound to by this binding for the given vertex buffer stream. Returns an empty string if there is no binding for the given vertex attribute or vertex buffer stream index.

size_t GetBindingCount size_t  streamIndex = 0  )  const
 

Returns the number of bindings for the given stream index.

const VertexAttribBinding::BindingsMap & GetBindings size_t  streamIndex = 0  )  const
 

Returns all bindings stored in this object for the given vertex buffer stream.

size_t GetStreamCount  )  const
 

Returns the number of vertex buffer streams used in this vertex attribute binding.

void GetUsedStreams OutputIteratorT  it  )  const
 

Returns the streams used in this binding using the given output iterator which must accept values of type size_t that represent the stream indices of the streams used in this binding.

const VertexFormat & GetVertexFormat size_t  streamIndex = 0  )  const
 

Returns the vertex format for which this binding is valid for a particular vertex buffer stream.

bool IsValidFixedFunctionBinding  )  const
 

Returns true if this binding is valid for the fixed-function pipeline. Mostly used for debugging purposes inside the engine.

bool UsesStream size_t  streamIndex  )  const
 

Returns true, if the given stream index is used in this vertex attribute binding.


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