Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Create the depth/stencil texture. We create two views here. One for the DepthStencilView,
- //and the other for binding to shaders. This could crash if we are using any sort of multisampling in DX10.
- //DX10.1 allows us to bind a multisampled DepthView to a Shader resource, but DX10 does not.
- ID3D10Texture2D* depthStencilTexture;
- D3D10_TEXTURE2D_DESC depthStencilTexDesc;
- depthStencilTexDesc.Width = engineParams.BackbufferWidth;
- depthStencilTexDesc.Height = engineParams.BackbufferHeight;
- depthStencilTexDesc.MipLevels = 1;
- depthStencilTexDesc.ArraySize = 1;
- //Setting the format as DXGI_FORMAT_R32_TYPELESS allows us to
- //delay setting of the actual format until a bit later. This is necessary
- //as this texture will be regestered under two different formats. One as
- //DXGI_FORMAT_D32_FLOAT for the depthStencilView, and the other as DXGI_FORMAT_R32_FLOAT
- //for the shaderResourceView.
- depthStencilTexDesc.Format = DXGI_FORMAT_R32_TYPELESS;
- depthStencilTexDesc.Usage = D3D10_USAGE_DEFAULT;
- //The bind must be set to D3D10_BIND_SHADER_RESOURCE to allow the depth buffer to be
- //bound as a shader input.
- depthStencilTexDesc.BindFlags = D3D10_BIND_DEPTH_STENCIL | D3D10_BIND_SHADER_RESOURCE;
- depthStencilTexDesc.SampleDesc.Count = engineParams.MultisampleCount;
- depthStencilTexDesc.SampleDesc.Quality = engineParams.MultisampleQuality;
- depthStencilTexDesc.CPUAccessFlags = 0;
- depthStencilTexDesc.MiscFlags = 0;
- //Create our texture.
- HRESULT texResult = GraphicsManager::GraphicsDevice->CreateTexture2D(&depthStencilTexDesc, NULL, &depthStencilTexture);
- //Check for errors.
- if(FAILED(texResult)){
- MessageBox(0, L"Creating the DepthStencilTexture failed!", 0, 0);
- return false;
- }
- //Here we specify the details of the depth stencil view.
- //This is the view that we will attach to our DepthStencil buffer.
- //Note that we set the format to D32 to specify a 32bit depth buffer.
- D3D10_DEPTH_STENCIL_VIEW_DESC depthDesc;
- ZeroMemory(&depthDesc, sizeof(depthDesc));
- depthDesc.Format = DXGI_FORMAT_D32_FLOAT;
- depthDesc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
- depthDesc.Texture2D.MipSlice = 0;
- HRESULT viewResult = GraphicsManager::GraphicsDevice->CreateDepthStencilView(depthStencilTexture, &depthDesc, &GraphicsManager::DepthStencilView);
- if(FAILED(viewResult)){
- MessageBox(0, L"Creating the DepthStencilView failed!", 0, 0);
- return false;
- }
- //Specify the details of the shader resource view. This is the view that
- //we will attach to our shader.
- D3D10_SHADER_RESOURCE_VIEW_DESC resDesc;
- ZeroMemory(&resDesc, sizeof(resDesc));
- resDesc.Format = DXGI_FORMAT_R32_FLOAT;
- resDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
- resDesc.Texture2D.MostDetailedMip = 0;
- resDesc.Texture2D.MipLevels = 1;
- viewResult = GraphicsManager::GraphicsDevice->CreateShaderResourceView(depthStencilTexture, &resDesc, &GraphicsManager::DepthStencilShaderResourceView);
- if(FAILED(viewResult)){
- MessageBox(0, L"Creating the DepthStencilShaderResourceView failed!", 0, 0);
- return false;
- }
- //Free our texture.
- depthStencilTexture->Release();
- //Bind our views to the graphics device.
- GraphicsManager::GraphicsDevice->OMSetRenderTargets(1, &GraphicsManager::RenderTargetView, GraphicsManager::DepthStencilView);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement