Cg Toolkit Cg 3.1 Toolkit Documentation
Cg / Runtime / CgD3D11 / cgD3D11SetDevice

Name

cgD3D11SetDevice - set the D3D device

Synopsis

#include <Cg/cgD3D11.h>

HRESULT cgD3D11SetDevice( CGcontext context,
                          ID3D11Device * device );

Parameters

context
The context in which to set the current device.
device
Pointer to an ID3D11Device interface that the expanded interface will use for any D3D-specific routine it may call. This parameter can be NULL to free all D3D resources used by the expanded interface and remove its reference to the D3D device.

Return Values

Returns D3D_OK if the function succeeds.

Returns the D3D failure code if the function fails due to a D3D call.

Description

cgD3D11SetDevice informs the expanded interface of the new D3D device. This will destroy any D3D resources for programs previously loaded with cgD3D11LoadProgram and use the new D3D device to recreate them. The expanded interface will increment the reference count to the D3D device, so this function must eventually be called with NULL to release that reference so D3D can be properly shut down.

If device is NULL, all D3D resources for programs previously loaded with cgD3D11LoadProgram are destroyed. However, these programs are still considered managed by the expanded interface, so if a new D3D device is set later these programs will be recreated using the new D3D device.

If a new device is being set, all D3D resources for programs previously loaded with cgD3D11LoadProgram are rebuilt using the new device. All shadowed parameters for these programs are maintained across D3D device changes except texture parameters. Since textures in D3D are bound to a particular D3D device, these resources cannot be saved across device changes. When these textures are recreated for the new D3D device, they must be re-bound to the sampler parameter.

Note that calling cgD3D11SetDevice(NULL) does not destroy any core runtime resources (CGprograms, CGparameters, etc.) used by the expanded interface. These must be destroyed seperately using cgDestroyProgram and cgDestroyContext.

Examples

// pDev is an ID3D11Device interface initialized elsewhere
...
cgD3D11SetDevice(pDev);

Errors

E_FAIL is returned if a D3D function returns an error.

History

cgD3D11SetDevice was introduced in Cg 3.0.

See Also

cgD3D11GetDevice, cgDestroyProgram, cgDestroyContext, cgD3D11LoadProgram


Cg Toolkit | Cg Toolkit | Download | Release Archive | Profiles | Reference | Books | Discussions |


Cg Runtime CgD3D11

cgD3D11BindProgram
cgD3D11CreateBufferFromObject
cgD3D11CreateBuffer
cgD3D11GetBufferByIndex
cgD3D11GetBufferObject
cgD3D11GetCompiledProgram
cgD3D11GetDevice
cgD3D11GetIASignatureByPass
cgD3D11GetLastError
cgD3D11GetLatestDomainProfile
cgD3D11GetLatestGeometryProfile
cgD3D11GetLatestHullProfile
cgD3D11GetLatestPixelProfile
cgD3D11GetLatestVertexProfile
cgD3D11GetManageTextureParameters
cgD3D11GetOptimalOptions
cgD3D11GetProgramErrors
cgD3D11IsProfileSupported
cgD3D11IsProgramLoaded
cgD3D11LoadProgram
cgD3D11RegisterStates
cgD3D11SetDevice
cgD3D11SetManageTextureParameters
cgD3D11SetSamplerStateParameter
cgD3D11SetTextureParameter
cgD3D11SetTextureSamplerStateParameter
cgD3D11TranslateCGerror
cgD3D11TranslateHRESULT
cgD3D11TypeToSize
cgD3D11UnbindProgram
cgD3D11UnloadProgram