Ejemplo n.º 1
0
SwapChain::SwapChain(Device& device, Window& window)
    : device_(device),
      window_(window)
{
    MEMBER_LOG_STRING_TAG(L"SwapChain");

    MEMBER_LOG << L"Initializing for window: " << window_.GetWindowProperties().name;

    dxgiSwapChainDesc_.BufferDesc.Width = window.GetWindowProperties().dimensions.GetHeight();
    dxgiSwapChainDesc_.BufferDesc.Height = window.GetWindowProperties().dimensions.GetWidth();
    
    // TODO: Add custom refresh rate
    dxgiSwapChainDesc_.BufferDesc.RefreshRate.Numerator = 0;
    dxgiSwapChainDesc_.BufferDesc.RefreshRate.Denominator = 0;

    // TODO: Add custom formatting
    dxgiSwapChainDesc_.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    dxgiSwapChainDesc_.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_PROGRESSIVE;
    dxgiSwapChainDesc_.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;

    // TODO: Add multi sampling options
    dxgiSwapChainDesc_.SampleDesc.Count = 1;
    dxgiSwapChainDesc_.SampleDesc.Quality = 0;

    dxgiSwapChainDesc_.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    dxgiSwapChainDesc_.BufferCount = 2;
    dxgiSwapChainDesc_.OutputWindow = window.GetHWnd();

    // Set this to true now, change actual fullscreen state on resize
    dxgiSwapChainDesc_.Windowed = TRUE;
    dxgiSwapChainDesc_.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
    dxgiSwapChainDesc_.Flags = 0;

    e_throw_com_ret_error(device.GetDXGIFactory()
        .CreateSwapChain(&device.GetD3DDevice(),
                          &dxgiSwapChainDesc_,
                          ReceiveCOM(dxgiSwapChain_)), "IDXGIFactory::CreateSwapChain");

    // Finish setup in Resize
    Resize(window.GetWindowProperties().dimensions);
}
Ejemplo n.º 2
0
boost::intrusive_ptr<ID3D11InputLayout> VertexBufferGroup::CreateInputLayout(Device& device, const VertexShader& validationShader, const VertexBufferVec& buffers)
{
    if(buffers.size() >= D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT)
        e_throw(VertexBufferGroupException() << error_description_info("Maximum VertexBufferGroup size is " + D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT));

    std::vector<D3D11_INPUT_ELEMENT_DESC> bufferDesc;

    for(unsigned int i = 0; i < buffers.size(); ++i)
    {
        for(const auto& layout : buffers[i]->GetBufferLayout())
        {
            D3D11_INPUT_ELEMENT_DESC desc =
            {
                layout.semanticName.c_str(),
                layout.semanticIndex,
                layout.format,
                i,
                layout.alignedByteOffset,
                D3D11_INPUT_PER_VERTEX_DATA,
                0
            };

            bufferDesc.push_back(desc);
        }
    }

    boost::intrusive_ptr<ID3D11InputLayout> inputLayout;
    e_throw_com_ret_error(device.GetD3DDevice()
        .CreateInputLayout(&bufferDesc[0],
                           static_cast<UINT>(bufferDesc.size()),
                           &validationShader.GetShaderData()[0],
                           validationShader.GetShaderData().size(),
                           ReceiveCOM(inputLayout)), "ID3D11Device::CreateInputLayout");

    return inputLayout;
}