Graphics Reference
In-Depth Information
class DirectionalLight
{
float3 Color;
float3 Direction;
float3 GetLighting( float3 Position, float3 Normal )
{
return saturate( dot( Normal, Direction) ) * Color;
}
};
cbuffer Classlnstances : register( cb0 )
{
DirectionalLight DLightlnstance;
}
Listing 6.19. Declaring a class instance.
6.6.2 Linking Classes to Interfaces
At runtime, applications employing dynamic shader linkage must specify which class will
be used to implement an interface used by a shader program. The first step is to create an
ID3D11ClassLinkage interface, which is done by calling ID3DllDevice: :CreateClass
Linkage. Once the class linkage interface is created, it can be bound to an instance of a shader
program. This is done by passing the ID3D11Class Linkage interface as the pClassLinkage
parameter of CreateVertexShader, CreateHullShader, CreateDomainShader,
CreateGeometryShader, CreatePixelShader, or CreateComputeShader. Listing 6.20
demonstrates this process for a pixel shader.
ID3D10Blob* compiledShader;
ID3D10Blob* errorMessages;
HRESULT hr = D3DXllCompileFromFile( filePath, NULL, NULL, "PSMain",
"ps_5_0", 0, 0, NULL, &compiledShader,
&errorMessages, NULL );
ID3DllClassLinkage* classLinkage = NULL;
if ( SUCCEEDED( hr ) )
{
device->CreateClassLinkage( SclassLinkage );
device- >CreatePixelShader( compiledShader- >GetBufferPointer (),
compiledShader- >GetBufferSize(),
classLinkage,
&pixelShader );
}
Listing 6.20. Creating and binding a class linkage.
Search WWH ::




Custom Search