Wildvine Engine
Referencia Doxygen del codigo propio de Wildvine Engine.
Cargando...
Buscando...
Nada coincide
EditorViewportPass.cpp
Ir a la documentación de este archivo.
1
7#include "Device.h"
8#include "DeviceContext.h"
9
10HRESULT EditorViewportPass::init(Device& device, unsigned int width, unsigned int height)
11{
12 return createResources(device, width, height);
13}
14
15HRESULT EditorViewportPass::resize(Device& device, unsigned int width, unsigned int height)
16{
17 if (width < 64) width = 64;
18 if (height < 64) height = 64;
19
20 if (width == m_width && height == m_height && isValid())
21 return S_OK;
22
23 return createResources(device, width, height);
24}
25
26HRESULT EditorViewportPass::createResources(Device& device, unsigned int width, unsigned int height)
27{
28 destroy();
29
30 if (width == 0) width = 1;
31 if (height == 0) height = 1;
32
33 m_width = width;
34 m_height = height;
35
36 HRESULT hr = S_OK;
37
38 // 1) Color texture offscreen
40 device,
41 width,
42 height,
43 DXGI_FORMAT_R8G8B8A8_UNORM,
44 D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE,
45 1,
46 0
47 );
48 if (FAILED(hr)) return hr;
49
50 // 2) RTV sobre esa textura (NO multisample view)
51 hr = m_rtv.init(
52 device,
54 D3D11_RTV_DIMENSION_TEXTURE2D,
55 DXGI_FORMAT_R8G8B8A8_UNORM
56 );
57 if (FAILED(hr)) return hr;
58
59 // 3) SRV separado para ImGui
60 hr = m_colorSRV.init(device, m_colorTexture, DXGI_FORMAT_R8G8B8A8_UNORM);
61 if (FAILED(hr)) return hr;
62
63 // 4) Depth texture
65 device,
66 width,
67 height,
68 DXGI_FORMAT_D24_UNORM_S8_UINT,
69 D3D11_BIND_DEPTH_STENCIL,
70 1,
71 0
72 );
73 if (FAILED(hr)) return hr;
74
75 // 5) DSV sobre esa depth texture (NO multisample view)
76 hr = m_dsv.init(
77 device,
79 DXGI_FORMAT_D24_UNORM_S8_UINT,
80 D3D11_DSV_DIMENSION_TEXTURE2D
81 );
82 if (FAILED(hr)) return hr;
83
84 return S_OK;
85}
86
87void EditorViewportPass::begin(DeviceContext& deviceContext, const float clearColor[4])
88{
89 m_rtv.render(deviceContext, m_dsv, 1, clearColor);
90}
91
93{
94 std::swap(m_colorTexture, other.m_colorTexture);
95 std::swap(m_colorSRV, other.m_colorSRV);
96 std::swap(m_rtv, other.m_rtv);
97 std::swap(m_depthTexture, other.m_depthTexture);
98 std::swap(m_dsv, other.m_dsv);
99 std::swap(m_width, other.m_width);
100 std::swap(m_height, other.m_height);
101}
102
104{
105 m_dsv.render(deviceContext);
106}
107
109{
110 D3D11_VIEWPORT vp{};
111 vp.TopLeftX = 0.0f;
112 vp.TopLeftY = 0.0f;
113 vp.Width = static_cast<float>(m_width);
114 vp.Height = static_cast<float>(m_height);
115 vp.MinDepth = 0.0f;
116 vp.MaxDepth = 1.0f;
117
118 deviceContext.m_deviceContext->RSSetViewports(1, &vp);
119}
120
122{
123 m_dsv.destroy();
126 m_rtv.destroy();
128
129 m_width = 1;
130 m_height = 1;
131}
132
Declara la API de DeviceContext dentro del subsistema Core.
Declara la API de Device dentro del subsistema Core.
Declara la API de EditorViewportPass dentro del subsistema Utilities.
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.
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
HRESULT createResources(Device &device, unsigned int width, unsigned int height)
HRESULT init(Device &device, unsigned int width, unsigned int height)
void swap(EditorViewportPass &other)
RenderTargetView m_rtv
DepthStencilView m_dsv
void setViewport(DeviceContext &deviceContext)
void begin(DeviceContext &deviceContext, const float clearColor[4])
void clearDepth(DeviceContext &deviceContext)
HRESULT resize(Device &device, unsigned int width, unsigned int height)
void destroy()
Libera el recurso ID3D11RenderTargetView.
HRESULT init(Device &device, Texture &backBuffer, DXGI_FORMAT Format)
Inicializa el Render Target View desde el back buffer.
void render(DeviceContext &deviceContext, DepthStencilView &depthStencilView, unsigned int numViews, const float ClearColor[4])
Limpia y asigna el RTV junto con un Depth Stencil View.
HRESULT init(Device &device, const std::string &textureName, ExtensionType extensionType)
Inicializa una textura cargada desde archivo.
Definition Texture.cpp:182
void destroy()
Libera los recursos de la textura.
Definition Texture.cpp:327