Graphics Reference
In-Depth Information
state belong to the ID3DllDeviceContext interface. We will review each of these avail-
able resources and see how they are used in the context of the vertex shader stage.
The Shader Program
The first, and probably the most important state of the vertex shader stage is the shader pro-
gram itself. The process for compiling a shader and creating a shader object from it is de-
scribed in detail in Chapter 6, so we will assume here that a compiled shader has been used
to create a valid vertex shader object. An application can, and normally does, create more
than one vertex shader object for use in rendering various objects. To configure the vertex
shader stage with the desired shader program, the application must use the ID3DllDevice
Context:: VSSetShader method. Listing 3.8 shows an example of how this is performed.
// pNextShader must be initialized to the desired shader object.
ID3DllVer-texShader* pNextShader = pShaderl;
m_pCorttext->VSSetShader( pNextShader, 0 , 0 );
Listing 3.8. Setting a vertex shader program.
The method to set the desired shader object requires three arguments. The first is a
pointer to the shader object to bind to the stage. The second and third parameters are used to
pass an array of shader class instances to be used in the shader program. These class instances
are objects that can be used to provide a portion of a shader program with an external object,
and are intended to reduce the number of individual shader objects needed to support a wide
variety of similar rendering scenarios. 7 There is also a corresponding ID3DllDeviceContext
: :VSGetShader method, which can be used to retrieve the shader and class instance objects
that are currently bound to the vertex shader stage. This can be useful to read an existing
shader object setting, so that it can be restored after an interim operation is performed.
Constant Buffers
The next configuration that the application can provide to the vertex shader program is
an array of constant buffers. Constant buffers are described in detail in Chapter 2. These
are essentially buffer resources that the application loads with parameters that are made
available to the shader program, which can use the data directly within the HLSL code.
This is used to communicate parameters to the shader program that will remain the same
throughout a pipeline execution—hence the name constant buffers. The process for filling
a constant buffer with data is also described in detail in Chapter 2, so we will focus here on
7
These class instances are described briefly in Chapter 6, but are not discussed in great detail. The reader is
referred to the DXSDK documentation for further guidance on how to use these objects.
Search WWH ::




Custom Search