Wildvine Engine
Referencia Doxygen del codigo propio de Wildvine Engine.
Cargando...
Buscando...
Nada coincide
DepthStencilView.cpp
Ir a la documentación de este archivo.
1
6#include "DepthStencilView.h"
7#include "Device.h"
8#include "DeviceContext.h"
9#include "Texture.h"
10
11HRESULT
12DepthStencilView::init(Device& device, Texture& depthStencil, DXGI_FORMAT format) {
13 if (!device.m_device) {
14 ERROR("DepthStencilView", "init", "Device is null.");
15 }
16 if (!depthStencil.m_texture) {
17 ERROR("DepthStencilView", "init", "Texture is null.");
18 return E_FAIL;
19 }
20
21 // Config depth stencil view description
22 D3D11_DEPTH_STENCIL_VIEW_DESC descDSV;
23 memset(&descDSV, 0, sizeof(descDSV));
24 descDSV.Format = format;
25 descDSV.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS;
26 descDSV.Texture2D.MipSlice = 0;
27
28 // Create depth stencil view
29 HRESULT hr = device.m_device->CreateDepthStencilView(depthStencil.m_texture,
30 &descDSV,
32
33 if (FAILED(hr)) {
34 ERROR("DepthStencilView", "init",
35 ("Failed to create depth stencil view. HRESULT: " + std::to_string(hr)).c_str());
36 return hr;
37 }
38
39 return S_OK;
40}
41
42HRESULT
44 Texture& depthStencil,
45 DXGI_FORMAT format,
46 D3D11_DSV_DIMENSION viewDimension) {
47 if (!device.m_device) {
48 ERROR("DepthStencilView", "init", "Device is null.");
49 return E_POINTER;
50 }
51 if (!depthStencil.m_texture) {
52 ERROR("DepthStencilView", "init", "Texture is null.");
53 return E_FAIL;
54 }
55
56 D3D11_DEPTH_STENCIL_VIEW_DESC descDSV{};
57 descDSV.Format = format;
58 descDSV.ViewDimension = viewDimension;
59
60 if (viewDimension == D3D11_DSV_DIMENSION_TEXTURE2D) {
61 descDSV.Texture2D.MipSlice = 0;
62 }
63
64 HRESULT hr = device.m_device->CreateDepthStencilView(
65 depthStencil.m_texture,
66 &descDSV,
68 );
69
70 if (FAILED(hr)) {
71 ERROR("DepthStencilView", "init",
72 ("Failed to create depth stencil view. HRESULT: " + std::to_string(hr)).c_str());
73 return hr;
74 }
75
76 return S_OK;
77}
78
79void
81 if (!deviceContext.m_deviceContext) {
82 ERROR("DepthStencilView", "render", "Device context is null.");
83 return;
84 }
85
86 // Clear depth stencil view
87 deviceContext.m_deviceContext->ClearDepthStencilView(m_depthStencilView,
88 D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL,
89 1.0f,
90 0);
91}
92
93void
97
Declara la API de DepthStencilView dentro del subsistema Core.
Declara la API de DeviceContext dentro del subsistema Core.
Declara la API de Device dentro del subsistema Core.
#define SAFE_RELEASE(x)
#define ERROR(classObj, method, errorMSG)
Declara la API de Texture dentro del subsistema Core.
void destroy()
Libera el recurso asociado al ID3D11DepthStencilView.
HRESULT init(Device &device, Texture &depthStencil, DXGI_FORMAT format)
Inicializa el ID3D11DepthStencilView a partir de una textura de profundidad.
void render(DeviceContext &deviceContext)
Asigna la vista de profundidad/esténcil al pipeline de render.
ID3D11DepthStencilView * m_depthStencilView
Vista de profundidad/esténcil de Direct3D 11.
ID3D11DeviceContext * m_deviceContext
Puntero al contexto inmediato de Direct3D 11.
Encapsula un ID3D11Device y facilita la creación de recursos gráficos en Direct3D 11.
Definition Device.h:21
ID3D11Device * m_device
Puntero al dispositivo Direct3D 11.
Definition Device.h:146
Encapsula una textura 2D en Direct3D 11, incluyendo su recurso y vista como Shader Resource.
Definition Texture.h:24
ID3D11Texture2D * m_texture
Recurso base de la textura en GPU.
Definition Texture.h:163