Game Development Reference
In-Depth Information
D3DX11CompileFromMemory() to let Direct3D11 compile the shader. The para-
meters you need to send into this function are
n pSrcData : A pointer to the shader in memory
n SrcDataLen : The size of the shader in bytes
n pFileName : The name of the shader file, which will help with debugging
n pDefines : Shader defines, which we have set to NULL
n pInclude : Shader includes, which we have set to NULL
n pFunctionName : The name of the entry point function
n pProfile : A string that defines the shader model
n Flags1 : Shader compile flags, which are set at the beginning of the function
n Flags2 : Effect compile flags, which we have set to zero
n pPump : A pointer to a thread pump interface, which is NULL
n ppShader : Where the compiled shader will be stored
n ppErrorMsgs : Where error messages will be stored
n pHResult : A pointer to store a return value if pPump is defined
For our simple shaders, most of the advanced parameters can be set to NULL. One
that deserves a little more attention, however, is pProfile .Justasinreleasesofsoft-
ware, each major revision of HLSL brought new capabilities. When you write a shader,
you write to a specific model, and you tell the shader compiler which model it needs
to run on. If you specify vertex shader model 4.0 with vs_4_0 as the pProfile
parameter, and you
'
ve used anything in the shader that requires shader model 5, the
compile will fail.
Moreover, if you want to specify a version of Direct3D, such as 9.1 or 10.0, you can
append this to the pProfile string. For example, if you want to set the shader com-
piler to compile a vertex shader for model 4.0 with a Direct3D level of 9.1, you would
set the pProfile string to vs_4_0_level_9_1 .
C++ Helper Class for the Vertex Shader
Having a compiled shader isn
t get data to it from your game,
so it makes some sense to design a helper class for the shader. Here
'
t much good if you can
'
'
s the helper class
for the vertex shader you saw earlier:
class GameCode4_Hlsl_VertexShader
{
 
 
Search WWH ::




Custom Search