当前位置: 首页>>代码示例>>C++>>正文


C++ DevicePtr::CreateBuffer方法代码示例

本文整理汇总了C++中DevicePtr::CreateBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ DevicePtr::CreateBuffer方法的具体用法?C++ DevicePtr::CreateBuffer怎么用?C++ DevicePtr::CreateBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DevicePtr的用法示例。


在下文中一共展示了DevicePtr::CreateBuffer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
开发者ID:rezanour,项目名称:randomoldstuff,代码行数:98,代码来源:DirectionalLightShader.cpp

示例2: Initialize

GDK_METHODIMP SimpleShader::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 0 is the only one, and that we support it well
    AddSupportedMaterial(0, 100);

    CHECKHR(FileStream::Create(L"SimpleShader.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_SAMPLER_DESC samplerDesc;

        ZeroMemory(&samplerDesc, sizeof(samplerDesc));

        std::vector<D3D11_INPUT_ELEMENT_DESC> inputElems;

        DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#ifdef _DEBUG
        // Set the D3DCOMPILE_DEBUG flag to embed debug information in the shaders.
        // Setting this flag improves the shader debugging experience, but still allows 
        // the shaders to be optimized and to run exactly the way they will run in 
        // the release configuration of this program.
        dwShaderFlags |= D3DCOMPILE_DEBUG;
#endif

        CHECKHR(spStream->Read(buffer.data(), buffer.size(), &cbRead));
        hr = D3DCompile(buffer.data(), buffer.size(), nullptr, nullptr, nullptr, "vsSimpleShader", "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, &_spVertexShader));
        // 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, "psSimpleShader", "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("SimpleShader::FrameConstantBuffer");
            _spFrameConstantBuffer->SetPrivateData(WKPDID_D3DDebugObjectName, name.size(), name.c_str());
        }

        bufferDesc.ByteWidth = sizeof(_objectConstants);
        bufferDesc.StructureByteStride = sizeof(_objectConstants);
        CHECKHR(spDevice->CreateBuffer(&bufferDesc, nullptr, &_spObjectConstantBuffer));
        {
            std::string name("SimpleShader::ObjectConstantBuffer");
            _spObjectConstantBuffer->SetPrivateData(WKPDID_D3DDebugObjectName, name.size(), name.c_str());
        }

        samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
        samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
        samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
        samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
        CHECKHR(spDevice->CreateSamplerState(&samplerDesc, &_spLinearSampler));

        samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
        CHECKHR(spDevice->CreateSamplerState(&samplerDesc, &_spPointSampler));
    }

EXIT
    return hr;
}
开发者ID:rezanour,项目名称:randomoldstuff,代码行数:95,代码来源:SimpleShader.cpp


注:本文中的DevicePtr::CreateBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。