本文整理汇总了C++中DevicePtr::CreateBlendState方法的典型用法代码示例。如果您正苦于以下问题:C++ DevicePtr::CreateBlendState方法的具体用法?C++ DevicePtr::CreateBlendState怎么用?C++ DevicePtr::CreateBlendState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DevicePtr
的用法示例。
在下文中一共展示了DevicePtr::CreateBlendState方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Initialize
GDK_IMETHODIMP DirectionalLightShader::Initialize(_In_ Renderer* pRenderer)
{
HRESULT hr = S_OK;
DevicePtr spDevice = pRenderer->GetDevice();
stde::com_ptr<IStream> spStream;
uint64 length = 0;
// TODO: Fill in real material table. For now let's just
// assume material 0xffffffff is the directional light, and that we support it well
AddSupportedMaterial(0xffffffff, 100);
CHECKHR(FileStream::Create(L"DirectionalLight.hlsl", true, &spStream));
length = FileStream::GetLength(spStream);
ISTRUE(length > 0, E_FAIL);
{
std::vector<byte> buffer(length);
ULONG cbRead = 0;
stde::com_ptr<ID3DBlob> spCode, spErrors;
D3D11_BUFFER_DESC bufferDesc = {0};
D3D11_INPUT_ELEMENT_DESC inputElem = {0};
D3D11_BLEND_DESC blendDesc = {0};
std::vector<D3D11_INPUT_ELEMENT_DESC> inputElems;
DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#ifdef _DEBUG
dwShaderFlags |= D3DCOMPILE_DEBUG;
#endif
CHECKHR(spStream->Read(buffer.data(), buffer.size(), &cbRead));
hr = D3DCompile(buffer.data(), buffer.size(), nullptr, nullptr, nullptr, "vsFullscreenQuad", "vs_4_0", dwShaderFlags, 0, &spCode, &spErrors);
if (FAILED(hr))
{
DebugOut("Error compiling shader:\n\n%s\n", static_cast<PSTR>(spErrors->GetBufferPointer()));
CHECKHR(hr);
}
CHECKHR(spDevice->CreateVertexShader(spCode->GetBufferPointer(), spCode->GetBufferSize(), nullptr, &_spQuadVertexShader));
// Store off the shader code for input layout construction later
SetShaderCode(spCode);
spCode = nullptr;
spErrors = nullptr;
hr = D3DCompile(buffer.data(), buffer.size(), nullptr, nullptr, nullptr, "psDirectionalLight", "ps_4_0", dwShaderFlags, 0, &spCode, &spErrors);
if (FAILED(hr))
{
DebugOut("Error compiling shader:\n\n%s\n", static_cast<PSTR>(spErrors->GetBufferPointer()));
CHECKHR(hr);
}
CHECKHR(spDevice->CreatePixelShader(spCode->GetBufferPointer(), spCode->GetBufferSize(), nullptr, &_spPixelShader));
// build constant buffers
bufferDesc.Usage = D3D11_USAGE_DEFAULT;
bufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
bufferDesc.ByteWidth = sizeof(_frameConstants);
bufferDesc.StructureByteStride = sizeof(_frameConstants);
CHECKHR(spDevice->CreateBuffer(&bufferDesc, nullptr, &_spFrameConstantBuffer));
{
std::string name("DirectionalLightShader::FrameConstantBuffer");
_spFrameConstantBuffer->SetPrivateData(WKPDID_D3DDebugObjectName, name.size(), name.c_str());
}
// Fill in the screen size (only needed once for now, unless we support dynamic resize)
_frameConstants.ScreenSize.Set(
pRenderer->GetSettings().DefaultView.ScreenWidth,
pRenderer->GetSettings().DefaultView.ScreenHeight);
bufferDesc.Usage = D3D11_USAGE_DEFAULT;
bufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
bufferDesc.ByteWidth = sizeof(_lightConstants);
bufferDesc.StructureByteStride = sizeof(_lightConstants);
CHECKHR(spDevice->CreateBuffer(&bufferDesc, nullptr, &_spLightConstantBuffer));
{
std::string name("DirectionalLightShader::LightConstantBuffer");
_spFrameConstantBuffer->SetPrivateData(WKPDID_D3DDebugObjectName, name.size(), name.c_str());
}
blendDesc.RenderTarget[0].BlendEnable = TRUE;
blendDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
blendDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
blendDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
blendDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
blendDesc.RenderTarget[0].DestBlend = D3D11_BLEND_DEST_ALPHA;
blendDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_DEST_ALPHA;
blendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
CHECKHR(spDevice->CreateBlendState(&blendDesc, &_spBlendState));
}
EXIT
return hr;
}