Home -> IStateBufferLayout
Declaration
class IStateBufferLayout;Description
The IStateBufferLayout interface defines the layout of a state buffer for use in a shader program. As state buffers generally contain multiple fields, which are mapped into the shader program as a large block of data, it is necessary to know the sizes and locations of the individual fields within the buffer, and their associated names, in order to allow these fields to be individually written to through the SetStateValue method of the IStateBuffer class.
There are two ways to initialize an IStateBufferLayout object. The preferred way is to build the state buffer layout from the shader program itself. After creating an IStateBufferLayout object, it can be passed directly into the LoadStateBufferLayoutFromShader method on an IShaderProgram object. This uses shader reflection to determine the full layout of the state buffer from the structure that is defined in the shader itself. This is the best approach, as it is simple for the application to do, and it allows the shader programs and the renderer maximum flexibility in how the state buffer is laid out. The alternate approach is for the application to define the contents of the state buffer manually, using the state layout building methods listed below. Fields must be added in the order they are defined, with each field being appended using the standard buffer layout rules for the renderer that was loaded. For Direct3D renderers, this uses the formally defined Packing Rules for Constant Variables. For OpenGL, the "std140" layout rules are used, as found in Section 7.6.2.2 of the OpenGL 4.5 Specification.
Warning
Please note if you are using GLSL as your shader language and defining your own manually built layouts, there is a specific warning not to use vec3 types. See following note from the official OpenGL wiki:
"Implementations sometimes get the std140 layout wrong for vec3 components. You are advised to manually pad your structures/arrays out and avoid using vec3 at all."
Although specific vendors and driver versions are not named, this advice should be followed when using the GLSL shader language and manually built state buffer layouts, to avoid compatibility problems.
Enumerations
| Name | Description | |
|---|---|---|
| DataType |
Identifies the scalar type of fields, vectors, and matrices appended during manual state buffer layout construction.
|
Members
Initialization methods
| Name | Description | |
|---|---|---|
| Delete |
Schedules the object for deletion. After calling this method, the object will be destroyed after the current
frame completes drawing.
|
State layout building methods
| Name | Description | |
|---|---|---|
| BeginLayoutDefinition |
Starts the process of constructing a state buffer layout
|
|
| AppendField |
Appends a scalar field to the state buffer layout
|
|
| AppendVector |
Appends a vector field to the state buffer layout
|
|
| AppendMatrix |
Appends a matrix field to the state buffer layout
|
|
| ConstructStateLayout |
Completes the process of constructing a state buffer layout
|