Wildvine Engine
Referencia Doxygen del codigo propio de Wildvine Engine.
Cargando...
Buscando...
Nada coincide
DeviceContext.cpp
Ir a la documentación de este archivo.
1
6#include "DeviceContext.h"
7
8void
12
13void
14DeviceContext::RSSetViewports(unsigned int NumViewports,
15 const D3D11_VIEWPORT* pViewports) {
16 if (!pViewports) {
17 ERROR("DeviceContext", "RSSetViewports", "pViewports is nullptr");
18 return;
19 }
20 m_deviceContext->RSSetViewports(NumViewports, pViewports);
21}
22
23void
25 unsigned int NumViews,
26 ID3D11ShaderResourceView* const* ppShaderResourceViews) {
27 if (!ppShaderResourceViews) {
28 ERROR("DeviceContext", "PSSetShaderResources", "ppShaderResourceViews is nullptr");
29 return;
30 }
31 m_deviceContext->PSSetShaderResources(StartSlot, NumViews, ppShaderResourceViews);
32}
33
34void
35DeviceContext::IASetInputLayout(ID3D11InputLayout* pInputLayout) {
36 if (!pInputLayout) {
37 ERROR("DeviceContext", "IASetInputLayout", "pInputLayout is nullptr");
38 return;
39 }
40 m_deviceContext->IASetInputLayout(pInputLayout);
41}
42
43void
44DeviceContext::VSSetShader(ID3D11VertexShader* pVertexShader,
45 ID3D11ClassInstance* const* ppClassInstances,
46 unsigned int NumClassInstances) {
47 if (!pVertexShader) {
48 ERROR("DeviceContext", "VSSetShader", "pVertexShader is nullptr");
49 return;
50 }
51 m_deviceContext->VSSetShader(pVertexShader, ppClassInstances, NumClassInstances);
52}
53
54void
55DeviceContext::PSSetShader(ID3D11PixelShader* pPixelShader,
56 ID3D11ClassInstance* const* ppClassInstances,
57 unsigned int NumClassInstances) {
58 if (!pPixelShader) {
59 ERROR("DeviceContext", "PSSetShader", "pPixelShader is nullptr");
60 return;
61 }
62 m_deviceContext->PSSetShader(pPixelShader, ppClassInstances, NumClassInstances);
63}
64
65void
66DeviceContext::UpdateSubresource(ID3D11Resource* pDstResource,
67 unsigned int DstSubresource,
68 const D3D11_BOX* pDstBox,
69 const void* pSrcData,
70 unsigned int SrcRowPitch,
71 unsigned int SrcDepthPitch) {
72 if (!pDstResource || !pSrcData) {
73 ERROR("DeviceContext", "UpdateSubresource",
74 "Invalid arguments: pDstResource or pSrcData is nullptr");
75 return;
76 }
77 m_deviceContext->UpdateSubresource(pDstResource,
78 DstSubresource,
79 pDstBox,
80 pSrcData,
81 SrcRowPitch,
82 SrcDepthPitch);
83}
84
85void
86DeviceContext::IASetVertexBuffers(unsigned int StartSlot,
87 unsigned int NumBuffers,
88 ID3D11Buffer* const* ppVertexBuffers,
89 const unsigned int* pStrides,
90 const unsigned int* pOffsets) {
91 if (!ppVertexBuffers || !pStrides || !pOffsets) {
92 ERROR("DeviceContext", "IASetVertexBuffers",
93 "Invalid arguments: ppVertexBuffers, pStrides, or pOffsets is nullptr");
94 return;
95 }
96 m_deviceContext->IASetVertexBuffers(StartSlot,
97 NumBuffers,
98 ppVertexBuffers,
99 pStrides,
100 pOffsets);
101}
102
103void
104DeviceContext::IASetIndexBuffer(ID3D11Buffer* pIndexBuffer,
105 DXGI_FORMAT Format,
106 unsigned int Offset) {
107 if (!pIndexBuffer) {
108 ERROR("DeviceContext", "IASetIndexBuffer", "pIndexBuffer is nullptr");
109 return;
110 }
111 m_deviceContext->IASetIndexBuffer(pIndexBuffer, Format, Offset);
112}
113
114void
115DeviceContext::PSSetSamplers(unsigned int StartSlot,
116 unsigned int NumSamplers,
117 ID3D11SamplerState* const* ppSamplers) {
118 if (!ppSamplers) {
119 ERROR("DeviceContext", "PSSetSamplers", "ppSamplers is nullptr");
120 return;
121 }
122 m_deviceContext->PSSetSamplers(StartSlot, NumSamplers, ppSamplers);
123}
124
125void
126DeviceContext::RSSetState(ID3D11RasterizerState* pRasterizerState) {
127 if (!pRasterizerState) {
128 ERROR("DeviceContext", "RSSetState", "pRasterizerState is nullptr");
129 return;
130 }
131 m_deviceContext->RSSetState(pRasterizerState);
132}
133
134void
135DeviceContext::OMSetBlendState(ID3D11BlendState* pBlendState,
136 const float BlendFactor[4],
137 unsigned int SampleMask) {
138 if (!pBlendState) {
139 ERROR("DeviceContext", "OMSetBlendState", "pBlendState is nullptr");
140 return;
141 }
142 m_deviceContext->OMSetBlendState(pBlendState, BlendFactor, SampleMask);
143}
144
145void
147 ID3D11RenderTargetView* const* ppRenderTargetViews,
148 ID3D11DepthStencilView* pDepthStencilView) {
149 // Validar los parámetros
150 if (!ppRenderTargetViews && !pDepthStencilView) {
151 ERROR("DeviceContext", "OMSetRenderTargets",
152 "Both ppRenderTargetViews and pDepthStencilView are nullptr");
153 return;
154 }
155
156 if (NumViews > 0 && !ppRenderTargetViews) {
157 ERROR("DeviceContext", "OMSetRenderTargets",
158 "ppRenderTargetViews is nullptr, but NumViews > 0");
159 return;
160 }
161
162 // Asignar los render targets y el depth stencil
163 m_deviceContext->OMSetRenderTargets(NumViews, ppRenderTargetViews, pDepthStencilView);
164}
165
166void
167DeviceContext::IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY Topology) {
168 // Validar el parámetro Topology
169 if (Topology == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED) {
170 ERROR("DeviceContext", "IASetPrimitiveTopology",
171 "Topology is D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED");
172 return;
173 }
174
175 // Asignar la topología al Input Assembler
176 m_deviceContext->IASetPrimitiveTopology(Topology);
177}
178
179void
180DeviceContext::ClearRenderTargetView(ID3D11RenderTargetView* pRenderTargetView,
181 const float ColorRGBA[4]) {
182 // Validar parámetros
183 if (!pRenderTargetView) {
184 ERROR("DeviceContext", "ClearRenderTargetView", "pRenderTargetView is nullptr");
185 return;
186 }
187 if (!ColorRGBA) {
188 ERROR("DeviceContext", "ClearRenderTargetView", "ColorRGBA is nullptr");
189 return;
190 }
191
192 // Limpiar el render target
193 m_deviceContext->ClearRenderTargetView(pRenderTargetView, ColorRGBA);
194}
195
196void
197DeviceContext::ClearDepthStencilView(ID3D11DepthStencilView* pDepthStencilView,
198 unsigned int ClearFlags,
199 float Depth,
200 UINT8 Stencil) {
201 // Validar parámetros
202 if (!pDepthStencilView) {
203 ERROR("DeviceContext", "ClearDepthStencilView",
204 "pDepthStencilView is nullptr");
205 return;
206 }
207
208 // Validar banderas de limpieza
209 if ((ClearFlags & (D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL)) == 0) {
210 ERROR("DeviceContext", "ClearDepthStencilView",
211 "Invalid ClearFlags: must include D3D11_CLEAR_DEPTH or D3D11_CLEAR_STENCIL");
212 return;
213 }
214
215 // Limpiar el depth stencil
216 m_deviceContext->ClearDepthStencilView(pDepthStencilView, ClearFlags, Depth, Stencil);
217}
218
219void
221 unsigned int NumBuffers,
222 ID3D11Buffer* const* ppConstantBuffers) {
223 // Validar parámetros
224 if (!ppConstantBuffers) {
225 ERROR("DeviceContext", "VSSetConstantBuffers", "ppConstantBuffers is nullptr");
226 return;
227 }
228
229 // Asignar los constant buffers al vertex shader
230 m_deviceContext->VSSetConstantBuffers(StartSlot, NumBuffers, ppConstantBuffers);
231}
232
233void
235 unsigned int NumBuffers,
236 ID3D11Buffer* const* ppConstantBuffers) {
237 // Validar parámetros
238 if (!ppConstantBuffers) {
239 ERROR("DeviceContext", "PSSetConstantBuffers", "ppConstantBuffers is nullptr");
240 return;
241 }
242
243 // Asignar los constant buffers al pixel shader
244 m_deviceContext->PSSetConstantBuffers(StartSlot, NumBuffers, ppConstantBuffers);
245}
246
247void
248DeviceContext::DrawIndexed(unsigned int IndexCount,
249 unsigned int StartIndexLocation,
250 int BaseVertexLocation) {
251 // Validar parámetros
252 if (IndexCount == 0) {
253 ERROR("DeviceContext", "DrawIndexed", "IndexCount is zero");
254 return;
255 }
256
257 // Ejecutar el dibujo
258 m_deviceContext->DrawIndexed(IndexCount, StartIndexLocation, BaseVertexLocation);
259}
260
261
Declara la API de DeviceContext dentro del subsistema Core.
#define SAFE_RELEASE(x)
#define ERROR(classObj, method, errorMSG)
void RSSetState(ID3D11RasterizerState *pRasterizerState)
Configura el Rasterizer State actual.
void DrawIndexed(unsigned int IndexCount, unsigned int StartIndexLocation, int BaseVertexLocation)
Envía un comando de dibujado de primitivas indexadas.
void OMSetBlendState(ID3D11BlendState *pBlendState, const float BlendFactor[4], unsigned int SampleMask)
Asigna un Blend State al Output Merger.
void PSSetShaderResources(unsigned int StartSlot, unsigned int NumViews, ID3D11ShaderResourceView *const *ppShaderResourceViews)
Asigna Shader Resource Views a la etapa de Pixel Shader.
void IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY Topology)
Define la topología de primitivas a renderizar.
void destroy()
Libera el recurso ID3D11DeviceContext.
void PSSetConstantBuffers(unsigned int StartSlot, unsigned int NumBuffers, ID3D11Buffer *const *ppConstantBuffers)
Asigna constant buffers a la etapa de Pixel Shader.
void RSSetViewports(unsigned int NumViewports, const D3D11_VIEWPORT *pViewports)
Configura los viewports en la etapa de rasterización.
void PSSetShader(ID3D11PixelShader *pPixelShader, ID3D11ClassInstance *const *ppClassInstances, unsigned int NumClassInstances)
Asigna un Pixel Shader al pipeline.
ID3D11DeviceContext * m_deviceContext
Puntero al contexto inmediato de Direct3D 11.
void VSSetConstantBuffers(unsigned int StartSlot, unsigned int NumBuffers, ID3D11Buffer *const *ppConstantBuffers)
Asigna constant buffers a la etapa de Vertex Shader.
void IASetIndexBuffer(ID3D11Buffer *pIndexBuffer, DXGI_FORMAT Format, unsigned int Offset)
Asigna un Index Buffer a la etapa de ensamblado de entrada.
void ClearDepthStencilView(ID3D11DepthStencilView *pDepthStencilView, unsigned int ClearFlags, float Depth, UINT8 Stencil)
Limpia un Depth Stencil View.
void OMSetRenderTargets(unsigned int NumViews, ID3D11RenderTargetView *const *ppRenderTargetViews, ID3D11DepthStencilView *pDepthStencilView)
Asigna Render Targets y Depth Stencil al Output Merger.
void UpdateSubresource(ID3D11Resource *pDstResource, unsigned int DstSubresource, const D3D11_BOX *pDstBox, const void *pSrcData, unsigned int SrcRowPitch, unsigned int SrcDepthPitch)
Copia datos desde CPU hacia un recurso en GPU.
void VSSetShader(ID3D11VertexShader *pVertexShader, ID3D11ClassInstance *const *ppClassInstances, unsigned int NumClassInstances)
Asigna un Vertex Shader al pipeline.
void IASetVertexBuffers(unsigned int StartSlot, unsigned int NumBuffers, ID3D11Buffer *const *ppVertexBuffers, const unsigned int *pStrides, const unsigned int *pOffsets)
Asigna buffers de vértices a la etapa de ensamblado de entrada.
void PSSetSamplers(unsigned int StartSlot, unsigned int NumSamplers, ID3D11SamplerState *const *ppSamplers)
Asigna Sampler States a la etapa de Pixel Shader.
void IASetInputLayout(ID3D11InputLayout *pInputLayout)
Define el Input Layout activo en la etapa de ensamblado de entrada.
void ClearRenderTargetView(ID3D11RenderTargetView *pRenderTargetView, const float ColorRGBA[4])
Limpia un Render Target con un color dado.