|
|
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]
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 VertexFormat & | GetVertexFormat (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 BindingsMap & | GetBindings (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. | |
|
|
Default constructor that creates an empty vertey attribute binding. |
|
|
Constructor for a vertex attribute binding that takes the vertex format of vertex buffer stream 0 as parameter |
|
||||||||||||
|
Constructor for a vertex attribute binding that takes the vertex format of vertex buffer streams 0 and 1 as parameter. |
|
||||||||||||||||
|
Binds a particular vertex attribute of a specific vertex buffer stream to a variable name. |
|
||||||||||||
|
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. |
|
||||||||||||
|
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. |
|
|
Returns the number of bindings for the given stream index. |
|
|
Returns all bindings stored in this object for the given vertex buffer stream. |
|
|
Returns the number of vertex buffer streams used in this vertex attribute binding. |
|
|
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. |
|
|
Returns the vertex format for which this binding is valid for a particular vertex buffer stream. |
|
|
Returns true if this binding is valid for the fixed-function pipeline. Mostly used for debugging purposes inside the engine. |
|
|
Returns true, if the given stream index is used in this vertex attribute binding. |
|
Copyright © by Martin Ecker |