Example #1
0
void SkyRenderer::Draw(RenderContext& renderContext,
                       const SceneConstants& sceneConstants)
{
    ID3D11DeviceContext& context = m_graphicsDevice.GetD3DContext();

    //
    //  Update the constant buffer.
    //
    m_constants.viewMatrix = sceneConstants.viewMatrix;
    m_constants.projectionMatrix = sceneConstants.projectionMatrix;

    D3D11_MAPPED_SUBRESOURCE map;
    D3DCHECK(m_graphicsDevice.GetD3DContext().Map(m_constantBuffer.get(),   //  pResource
                                                 0,                         //  Subresource
                                                 D3D11_MAP_WRITE_DISCARD,   //  MapType
                                                 0,                         //  MapFlags
                                                 &map));                    //  pMappedResource
    memcpy(map.pData, &m_constants, sizeof(m_constants));
    m_graphicsDevice.GetD3DContext().Unmap(m_constantBuffer.get(), 0);

    //
    //  Execute the render op.
    //
    ID3D11Buffer* vertexBufferPtr = m_shared->vertexBuffer.get();
    size_t offset = 0,
           stride = sizeof(Vertex);
    ID3D11ShaderResourceView* shaderResourceViewPtrs[] =
    {
        m_shared->skyTextureView.get()
    };
    ID3D11SamplerState* samplerPtr = m_shared->samplerState.get();

    context.IASetVertexBuffers(0, 1, &vertexBufferPtr, &stride, &offset);
    context.IASetIndexBuffer(m_shared->indexBuffer.get(), DXGI_FORMAT_R16_UINT, 0);
    context.IASetInputLayout(m_shared->inputLayout.get());
    context.IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

    ID3D11Buffer* constantBufferPtr = m_constantBuffer.get();
    context.VSSetConstantBuffers(0, 1, &constantBufferPtr);
    context.VSSetShader(m_shared->vertexShader.get(), NULL, 0);

    context.GSSetShader(NULL, NULL, 0);

    context.PSSetShader(m_shared->pixelShader.get(), NULL, 0);
    context.PSSetShaderResources(0, 1, shaderResourceViewPtrs);
    context.PSSetSamplers(0, 1, &samplerPtr);

    renderContext.PushRasterizerState(m_shared->rasterizerState);
    renderContext.PushDepthStencilState(m_shared->depthStencilState);

    context.DrawIndexed(36, 0, 0);

    renderContext.PopRasterizerState();
    renderContext.PopDepthStencilState();
}