本文整理汇总了C++中microsoft::wrl::ComPtr::SetDevice方法的典型用法代码示例。如果您正苦于以下问题:C++ ComPtr::SetDevice方法的具体用法?C++ ComPtr::SetDevice怎么用?C++ ComPtr::SetDevice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类microsoft::wrl::ComPtr
的用法示例。
在下文中一共展示了ComPtr::SetDevice方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: defined
// Initialize hardware-dependent resources.
void Scenario1ImageSource::CreateDeviceResources()
{
// This flag adds support for surfaces with a different color channel ordering
// than the API default. It is required for compatibility with Direct2D.
UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
#if defined(_DEBUG)
// If the project is in a debug build, enable debugging via SDK Layers.
creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
// This array defines the set of DirectX hardware feature levels this app will support.
// Note the ordering should be preserved.
// Don't forget to declare your application's minimum required feature level in its
// description. All applications are assumed to support 9.1 unless otherwise stated.
const D3D_FEATURE_LEVEL featureLevels[] =
{
D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
D3D_FEATURE_LEVEL_9_3,
D3D_FEATURE_LEVEL_9_2,
D3D_FEATURE_LEVEL_9_1,
};
// Create the Direct3D 11 API device object.
DX::ThrowIfFailed(
D3D11CreateDevice(
nullptr, // Specify nullptr to use the default adapter.
D3D_DRIVER_TYPE_HARDWARE,
nullptr,
creationFlags, // Set debug and Direct2D compatibility flags.
featureLevels, // List of feature levels this app can support.
ARRAYSIZE(featureLevels),
D3D11_SDK_VERSION, // Always set this to D3D11_SDK_VERSION for Windows Store apps.
&m_d3dDevice, // Returns the Direct3D device created.
nullptr,
nullptr
)
);
// Get the Direct3D 11.1 API device.
ComPtr<IDXGIDevice> dxgiDevice;
DX::ThrowIfFailed(
m_d3dDevice.As(&dxgiDevice)
);
// Create the Direct2D device object and a corresponding context.
DX::ThrowIfFailed(
D2D1CreateDevice(
dxgiDevice.Get(),
nullptr,
&m_d2dDevice
)
);
DX::ThrowIfFailed(
m_d2dDevice->CreateDeviceContext(
D2D1_DEVICE_CONTEXT_OPTIONS_NONE,
&m_d2dContext
)
);
// Set DPI to the display's current DPI.
SetDpi(DisplayInformation::GetForCurrentView()->LogicalDpi);
// Query for ISurfaceImageSourceNative interface.
Microsoft::WRL::ComPtr<ISurfaceImageSourceNative> sisNative;
DX::ThrowIfFailed(
reinterpret_cast<IUnknown*>(this)->QueryInterface(IID_PPV_ARGS(&sisNative))
);
// Associate the DXGI device with the SurfaceImageSource.
DX::ThrowIfFailed(
sisNative->SetDevice(dxgiDevice.Get())
);
}
示例2: CreateDeviceResources
// Initialize hardware-dependent resources.
void LineGraph::CreateDeviceResources()
{
// This flag adds support for surfaces with a different color channel ordering
// than the API default.
UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
#if defined(_DEBUG)
// If the project is in a debug build, enable debugging via SDK Layers.
creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
// This array defines the set of DirectX hardware feature levels this app will support.
// Note the ordering should be preserved.
// Don't forget to declare your application's minimum required feature level in its
// description. All applications are assumed to support 9.1 unless otherwise stated.
const D3D_FEATURE_LEVEL featureLevels[] =
{
D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
D3D_FEATURE_LEVEL_9_3,
D3D_FEATURE_LEVEL_9_2,
D3D_FEATURE_LEVEL_9_1,
};
// Create the DX11 API device object, and get a corresponding context.
ThrowIfFailed(
D3D11CreateDevice(
nullptr, // Specify nullptr to use the default adapter.
D3D_DRIVER_TYPE_HARDWARE,
nullptr,
creationFlags, // Set debug and Direct2D compatibility flags.
featureLevels, // List of feature levels this app can support.
ARRAYSIZE(featureLevels),
D3D11_SDK_VERSION, // Always set this to D3D11_SDK_VERSION for Windows Store apps.
&m_d3dDevice, // Returns the Direct3D device created.
nullptr,
&m_d3dContext // Returns the device immediate context.
)
);
// Get the Direct3D 11.1 API device.
ComPtr<IDXGIDevice> dxgiDevice;
ThrowIfFailed(
m_d3dDevice.As(&dxgiDevice)
);
// Query for ISurfaceImageSourceNative interface.
Microsoft::WRL::ComPtr<ISurfaceImageSourceNative> sisNative;
ThrowIfFailed(
reinterpret_cast<IUnknown*>(this)->QueryInterface(IID_PPV_ARGS(&sisNative))
);
// Associate the DXGI device with the SurfaceImageSource.
ThrowIfFailed(
sisNative->SetDevice(dxgiDevice.Get())
);
BasicReaderWriter^ reader = ref new BasicReaderWriter();
// Load the vertex shader.
auto vsBytecode = reader->ReadData("VisualizationTools\\SimpleVertexShader.cso");
ThrowIfFailed(
m_d3dDevice->CreateVertexShader(
vsBytecode->Data,
vsBytecode->Length,
nullptr,
&m_vertexShader
)
);
// Create input layout for vertex shader.
const D3D11_INPUT_ELEMENT_DESC vertexDesc[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "COLOR", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};
ThrowIfFailed(
m_d3dDevice->CreateInputLayout(
vertexDesc,
ARRAYSIZE(vertexDesc),
vsBytecode->Data,
vsBytecode->Length,
&m_inputLayout
)
);
// Load the pixel shader.
auto psBytecode = reader->ReadData("VisualizationTools\\SimplePixelShader.cso");
ThrowIfFailed(
m_d3dDevice->CreatePixelShader(
psBytecode->Data,
psBytecode->Length,
nullptr,
&m_pixelShader
)
);
//.........这里部分代码省略.........