|
|
|
|
|
|
|
|
34 |
|
|
static UINT GetFlag(void) noexcept { return D3D10_BIND_VERTEX_BUFFER; } |
|
|
|
|
|
... |
|
|
42 |
|
|
static UINT GetFlag(void) noexcept { return D3D10_BIND_INDEX_BUFFER; } |
|
|
|
|
|
... |
|
|
49 |
|
|
static UINT GetFlag(void) noexcept { return D3D10_BIND_CONSTANT_BUFFER; } |
|
|
|
|
|
... |
|
|
65 |
|
|
return [=](void) |
|
|
|
|
|
... |
|
|
67 |
|
|
constexpr UINT stride = sizeof(T); |
|
|
68 |
|
|
constexpr UINT offset = 0; |
|
|
69 |
|
|
_pDevice->IASetVertexBuffers(0, 1, |
|
|
|
|
|
... |
|
|
71 |
|
|
}; |
|
|
|
|
|
... |
|
|
80 |
|
|
return [=](void) |
|
|
|
|
|
... |
|
|
82 |
|
|
const auto IsDirty = _cbMapper(nullptr); |
|
|
83 |
|
|
if (IsDirty) |
|
|
|
|
|
... |
|
|
85 |
|
|
T * pData = nullptr; |
|
|
86 |
|
|
DX_CHECK _pBuffer->Map(D3D10_MAP_WRITE_NO_OVERWRITE, 0, (void**)&pData); |
|
|
87 |
|
|
_cbMapper(pData); |
|
|
88 |
|
|
_pBuffer->Unmap(); |
|
|
|
|
|
... |
|
|
91 |
|
|
constexpr UINT stride = sizeof(T); |
|
|
92 |
|
|
constexpr UINT offset = 0; |
|
|
93 |
|
|
_pDevice->IASetVertexBuffers(0, 1, |
|
|
|
|
|
... |
|
|
95 |
|
|
}; |
|
|
|
|
|
... |
|
|
104 |
|
|
D3D10_BUFFER_DESC bd = { 0 }; |
|
|
105 |
|
|
bd.Usage = D3D10_USAGE_DEFAULT; |
|
|
106 |
|
|
bd.ByteWidth = static_cast(sizeof(T) * _Count); |
|
|
107 |
|
|
bd.BindFlags = Support<::std::remove_const::type>::GetFlag(); |
|
|
|
|
|
... |
|
|
109 |
|
|
D3D10_SUBRESOURCE_DATA InitData = { 0 }; |
|
|
110 |
|
|
InitData.pSysMem = _pData; |
|
|
|
|
|
... |
|
|
112 |
|
|
const D3D10_SUBRESOURCE_DATA * const pInitData = |
|
|
|
|
|
... |
|
|
115 |
|
|
ComPtr_t pBuffer; |
|
|
116 |
|
|
DX_CHECK _pDevice->CreateBuffer(&bd, pInitData, &pBuffer); |
|
|
117 |
|
|
return pBuffer; |
|
|
|
|
|
... |
|
|
126 |
|
|
D3D10_BUFFER_DESC bd = { 0 }; |
|
|
127 |
|
|
bd.Usage = D3D10_USAGE_DYNAMIC; |
|
|
128 |
|
|
bd.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; |
|
|
129 |
|
|
bd.ByteWidth = static_cast(sizeof(T) * _Count); |
|
|
130 |
|
|
bd.BindFlags = Support<::std::remove_const::type>::GetFlag(); |
|
|
|
|
|
... |
|
|
132 |
|
|
D3D10_SUBRESOURCE_DATA InitData = { 0 }; |
|
|
133 |
|
|
InitData.pSysMem = _pData; |
|
|
|
|
|
... |
|
|
135 |
|
|
const D3D10_SUBRESOURCE_DATA * const pInitData = |
|
|
|
|
|
... |
|
|
138 |
|
|
ComPtr_t pBuffer; |
|
|
139 |
|
|
DX_CHECK _pDevice->CreateBuffer(&bd, pInitData, &pBuffer); |
|
|
140 |
|
|
return pBuffer; |
|
|
|
|
|
... |
|
|
148 |
|
|
const auto pBuffer = Create(_pDevice, _pData, _Count); |
|
|
149 |
|
|
_pDevice->VSSetConstantBuffers(Support::Index, 1, pBuffer.GetAddressOf()); |
|
|
150 |
|
|
_pDevice->PSSetConstantBuffers(Support::Index, 1, pBuffer.GetAddressOf()); |
|
|
151 |
|
|
return pBuffer; |
|
|
|
|
|
... |
|
|
157 |
|
|
return [=](const ComponentPtr_t & _pComponent) |
|
|
|
|
|
... |
|
|
159 |
|
|
const Component::Buffer BufferData{ *_pComponent }; |
|
|
|
|
|
... |
|
|
161 |
|
|
return GetRender(_pDevice, |
|
|
|
|
|
... |
|
|
163 |
|
|
}; |
|
|
|
|
|
... |
|
|
171 |
|
|
return [=](const ComponentPtr_t & _pComponent) |
|
|
|
|
|
... |
|
|
173 |
|
|
const Component::Buffer BufferData{ *_pComponent }; |
|
|
|
|
|
... |
|
|
175 |
|
|
return GetRender(_pDevice, |
|
|
|
|
|
... |
|
|
177 |
|
|
}; |
|
|
|
|
|
... |
|
|
188 |
|
|
ComPtr_t pDevice; |
|
|
189 |
|
|
m_pBuffer->GetDevice(&pDevice); |
|
|
|
|
|
... |
|
|
191 |
|
|
pDevice->UpdateSubresource(m_pBuffer.Get(), 0, NULL, &m_Data, 0, 0); |
|
|
|
|
|
... |
|
|
199 |
|
|
m_pBuffer{ Buffer::CreateConstant(_pDevice, &m_Data) } |
|
|
|
|
|
... |
|
|
208 |
|
|
constexpr UINT DeviceFlags = |
|
|
|
|
|
... |
|
|
211 |
|
|
DXGI_SWAP_CHAIN_DESC sd = { 0 }; |
|
|
212 |
|
|
sd.BufferCount = 2; |
|
|
213 |
|
|
sd.OutputWindow = ::covellite::any_cast(_Data.Handle); |
|
|
214 |
|
|
sd.Windowed = _Data.IsFullScreen ? FALSE : TRUE; |
|
|
215 |
|
|
sd.SampleDesc.Count = 1; |
|
|
216 |
|
|
sd.SampleDesc.Quality = 0; |
|
|
217 |
|
|
sd.BufferDesc.Width = 0; |
|
|
218 |
|
|
sd.BufferDesc.Height = 0; |
|
|
219 |
|
|
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; |
|
|
220 |
|
|
sd.BufferDesc.RefreshRate.Numerator = 60; |
|
|
221 |
|
|
sd.BufferDesc.RefreshRate.Denominator = 1; |
|
|
222 |
|
|
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; |
|
|
|
|
|
... |
|
|
224 |
|
|
DX_CHECK D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_HARDWARE, |
|
|
|
|
|
... |
|
|
227 |
|
|
D3D10_RASTERIZER_DESC RasterizerDesc = { 0 }; |
|
|
228 |
|
|
RasterizerDesc.FillMode = D3D10_FILL_SOLID; |
|
|
229 |
|
|
RasterizerDesc.CullMode = D3D10_CULL_BACK; |
|
|
230 |
|
|
RasterizerDesc.FrontCounterClockwise = TRUE; |
|
|
231 |
|
|
RasterizerDesc.DepthClipEnable = TRUE; |
|
|
|
|
|
... |
|
|
233 |
|
|
DX_CHECK m_pDevice->CreateRasterizerState( |
|
|
|
|
|
... |
|
|
236 |
|
|
SetViewport(static_cast(_Data.ClientRect.Width), |
|
|
|
|
|
... |
|
|
239 |
|
|
MakeConstants(m_pDevice); |
|
|
|
|
|
... |
|
|
242 |
|
|
DirectX10::~DirectX10(void) = default; |
|
|
|
|
|
... |
|
|
246 |
|
|
return uT("DirectX 10"); |
|
|
|
|
|
... |
|
|
251 |
|
|
m_pSwapChain->Present(0, 0); |
|
|
|
|
|
... |
|
|
253 |
|
|
GraphicApi::PresentFrame(); |
|
|
|
|
|
... |
|
|
258 |
|
|
SetViewport(static_cast(_ClientRect.Width), static_cast(_ClientRect.Height)); |
|
|
|
|
|
... |
|
|
266 |
|
|
const auto pCamera = _pComponent; |
|
|
|
|
|
... |
|
|
268 |
|
|
const fnViewportSize_t GetScaleViewportSize = [=](void) |
|
|
|
|
|
... |
|
|
270 |
|
|
DXGI_SWAP_CHAIN_DESC Desc = { 0 }; |
|
|
271 |
|
|
DX_CHECK m_pSwapChain->GetDesc(&Desc); |
|
|
|
|
|
... |
|
|
273 |
|
|
const float Scale = (*pCamera)[uT("scale")]; |
|
|
274 |
|
|
const auto Width = static_cast(Scale * Desc.BufferDesc.Width); |
|
|
275 |
|
|
const auto Height = static_cast(Scale * Desc.BufferDesc.Height); |
|
|
|
|
|
... |
|
|
277 |
|
|
return Size_t{ Width, Height }; |
|
|
278 |
|
|
}; |
|
|
|
|
|
... |
|
|
280 |
|
|
const fnViewportSize_t GetWindowViewportSize = [=](void) |
|
|
|
|
|
... |
|
|
282 |
|
|
DXGI_SWAP_CHAIN_DESC Desc = { 0 }; |
|
|
283 |
|
|
DX_CHECK m_pSwapChain->GetDesc(&Desc); |
|
|
|
|
|
... |
|
|
285 |
|
|
return Size_t{ Desc.BufferDesc.Width, Desc.BufferDesc.Height }; |
|
|
286 |
|
|
}; |
|
|
|
|
|
... |
|
|
288 |
|
|
const fnViewportSize_t GetUserViewportSize = [=](void) |
|
|
|
|
|
... |
|
|
290 |
|
|
const int Width = (*pCamera)[uT("width")]; |
|
|
291 |
|
|
const int Height = (*pCamera)[uT("height")]; |
|
|
|
|
|
... |
|
|
293 |
|
|
return Size_t{ static_cast(Width), static_cast(Height) }; |
|
|
294 |
|
|
}; |
|
|
|
|
|
... |
|
|
296 |
|
|
const auto IsScaleViewportSize = |
|
|
|
|
|
... |
|
|
298 |
|
|
const auto IsUserViewportSize = |
|
|
|
|
|
... |
|
|
302 |
|
|
const auto GetViewportSize = |
|
|
|
|
|
... |
|
|
307 |
|
|
const auto SetDefaultRenderTarget = [=](void) |
|
|
|
|
|
... |
|
|
309 |
|
|
m_CurrentRenderTargets = { m_pScreenRenderTargetView.Get() }; |
|
|
310 |
|
|
m_pCurrentDepthStencilView = m_pScreenDepthStencilView; |
|
|
|
|
|
... |
|
|
312 |
|
|
m_pDevice->OMSetRenderTargets(static_cast(m_CurrentRenderTargets.size()), |
|
|
|
|
|
... |
|
|
315 |
|
|
m_pDevice->RSSetState(m_pDefaultRasterizerState.Get()); |
|
|
|
|
|
... |
|
|
317 |
|
|
D3D10_VIEWPORT ViewPort = { 0 }; |
|
|
318 |
|
|
ViewPort.TopLeftX = 0; |
|
|
319 |
|
|
ViewPort.TopLeftY = 0; |
|
|
320 |
|
|
::std::tie(ViewPort.Width, ViewPort.Height) = GetViewportSize(); |
|
|
321 |
|
|
ViewPort.MinDepth = 0.0f; |
|
|
322 |
|
|
ViewPort.MaxDepth = 1.0f; |
|
|
323 |
|
|
m_pDevice->RSSetViewports(1, &ViewPort); |
|
|
324 |
|
|
}; |
|
|
|
|
|
... |
|
|
326 |
|
|
const auto DisableBlendRender = CreateBlendState(false); |
|
|
327 |
|
|
const auto DisableDepthRender = GetDepthState(false, false, false); |
|
|
|
|
|
... |
|
|
329 |
|
|
const auto ServiceComponents = |
|
|
|
|
|
... |
|
|
336 |
|
|
const Render_t CameraOrthographic = [=](void) |
|
|
|
|
|
... |
|
|
338 |
|
|
SetDefaultRenderTarget(); |
|
|
339 |
|
|
DisableBlendRender(); |
|
|
340 |
|
|
DisableDepthRender(); |
|
|
|
|
|
... |
|
|
342 |
|
|
UINT ViewportCount = 1; |
|
|
343 |
|
|
D3D10_VIEWPORT Viewport = { 0 }; |
|
|
344 |
|
|
m_pDevice->RSGetViewports(&ViewportCount, &Viewport); |
|
|
|
|
|
... |
|
|
346 |
|
|
const Component::Position Pos{ *ServiceComponents[0] }; |
|
|
|
|
|
... |
|
|
348 |
|
|
auto & CameraMatrices = m_pConstants->Get<::Camera>(); |
|
|
|
|
|
... |
|
|
350 |
|
|
CameraMatrices.Projection = ::glm::transpose(::glm::ortho( |
|
|
|
|
|
... |
|
|
355 |
|
|
const auto View = ::glm::identity<::glm::mat4>(); |
|
|
356 |
|
|
CameraMatrices.View = ::glm::transpose(View); |
|
|
357 |
|
|
CameraMatrices.ViewInverse = ::glm::transpose(::glm::inverse(View)); |
|
|
358 |
|
|
m_pConstants->Update<::Camera>(); |
|
|
|
|
|
... |
|
|
360 |
|
|
(*_pComponent)[uT("view")] = CameraMatrices.View; |
|
|
361 |
|
|
(*_pComponent)[uT("projection")] = CameraMatrices.Projection; |
|
|
362 |
|
|
}; |
|
|
|
|
|
... |
|
|
364 |
|
|
const Render_t CameraPerspective = [=](void) |
|
|
|
|
|
... |
|
|
366 |
|
|
SetDefaultRenderTarget(); |
|
|
367 |
|
|
DisableBlendRender(); |
|
|
368 |
|
|
DisableDepthRender(); |
|
|
|
|
|
... |
|
|
370 |
|
|
UINT ViewportCount = 1; |
|
|
371 |
|
|
D3D10_VIEWPORT Viewport = { 0 }; |
|
|
372 |
|
|
m_pDevice->RSGetViewports(&ViewportCount, &Viewport); |
|
|
|
|
|
... |
|
|
374 |
|
|
auto & CameraMatrices = m_pConstants->Get<::Camera>(); |
|
|
|
|
|
... |
|
|
378 |
|
|
const auto AngleY = (float)(*_pComponent)[uT("fov")].Default(90.0f) * |
|
|
|
|
|
... |
|
|
380 |
|
|
const float zNear = (*_pComponent)[uT("znear")].Default(0.01f); |
|
|
381 |
|
|
const float zFar = (*_pComponent)[uT("zfar")].Default(200.0f); |
|
|
|
|
|
... |
|
|
383 |
|
|
CameraMatrices.Projection = ::glm::transpose(::glm::perspectiveFovRH(AngleY, |
|
|
|
|
|
... |
|
|
389 |
|
|
const Component::Position Look{ *ServiceComponents[0] }; |
|
|
|
|
|
... |
|
|
394 |
|
|
const float Distance = (*_pComponent)[uT("distance")].Default(0.0f); |
|
|
|
|
|
... |
|
|
399 |
|
|
const Component::Position Rot{ *ServiceComponents[1] }; |
|
|
|
|
|
... |
|
|
401 |
|
|
::glm::mat4 Transform = ::glm::identity<::glm::mat4>(); |
|
|
|
|
|
... |
|
|
403 |
|
|
Transform = ::glm::translate(Transform, |
|
|
|
|
|
... |
|
|
405 |
|
|
Transform = ::glm::rotate(Transform, |
|
|
|
|
|
... |
|
|
407 |
|
|
Transform = ::glm::rotate(Transform, |
|
|
|
|
|
... |
|
|
409 |
|
|
Transform = ::glm::rotate(Transform, |
|
|
|
|
|
... |
|
|
412 |
|
|
return Transform * ::glm::vec4{ Distance + 0.1f, 0.0f, 0.0f, 1.0f }; |
|
|
413 |
|
|
}; |
|
|
|
|
|
... |
|
|
415 |
|
|
const auto View = ::glm::lookAtRH( |
|
|
|
|
|
... |
|
|
420 |
|
|
CameraMatrices.View = ::glm::transpose(View); |
|
|
421 |
|
|
CameraMatrices.ViewInverse = ::glm::transpose(::glm::inverse(View)); |
|
|
422 |
|
|
m_pConstants->Update<::Camera>(); |
|
|
|
|
|
... |
|
|
424 |
|
|
(*_pComponent)[uT("view")] = CameraMatrices.View; |
|
|
425 |
|
|
(*_pComponent)[uT("projection")] = CameraMatrices.Projection; |
|
|
426 |
|
|
}; |
|
|
|
|
|
... |
|
|
428 |
|
|
return (_pComponent->Kind == uT("Perspective")) ? |
|
|
|
|
|
... |
|
|
441 |
|
|
int m_Width = 0; |
|
|
442 |
|
|
int m_Height = 0; |
|
|
|
|
|
... |
|
|
457 |
|
|
const Component::Texture TextureData{ *m_pDataTexture, uT("albedo") }; |
|
|
|
|
|
... |
|
|
459 |
|
|
m_pTexture = (TextureData.Destination != uT("depth")) ? |
|
|
|
|
|
... |
|
|
463 |
|
|
m_Width = _Width; |
|
|
464 |
|
|
m_Height = _Height; |
|
|
|
|
|
... |
|
|
466 |
|
|
if (TextureData.IsMapping) |
|
|
|
|
|
... |
|
|
468 |
|
|
m_pReadTexture = MakeRGBACopy(_pDevice, _Width, _Height); |
|
|
|
|
|
... |
|
|
474 |
|
|
const Component::Texture TextureData{ *m_pDataTexture, uT("albedo") }; |
|
|
|
|
|
... |
|
|
476 |
|
|
m_Width = TextureData.Width; |
|
|
477 |
|
|
m_Height = TextureData.Height; |
|
|
|
|
|
... |
|
|
479 |
|
|
m_pTexture = (TextureData.IsUsingMipmapping) ? |
|
|
|
|
|
... |
|
|
488 |
|
|
m_Width = _Width; |
|
|
489 |
|
|
m_Height = _Height; |
|
|
|
|
|
... |
|
|
491 |
|
|
D3D10_TEXTURE2D_DESC textureDesc = { 0 }; |
|
|
492 |
|
|
textureDesc.Width = _Width; |
|
|
493 |
|
|
textureDesc.Height = _Height; |
|
|
494 |
|
|
textureDesc.MipLevels = 1; |
|
|
495 |
|
|
textureDesc.ArraySize = 1; |
|
|
496 |
|
|
textureDesc.Format = m_Format; |
|
|
497 |
|
|
textureDesc.Usage = D3D10_USAGE_STAGING; |
|
|
|
|
|
... |
|
|
500 |
|
|
textureDesc.CPUAccessFlags = D3D10_CPU_ACCESS_READ; |
|
|
501 |
|
|
textureDesc.SampleDesc.Count = 1; |
|
|
502 |
|
|
textureDesc.SampleDesc.Quality = 0; |
|
|
|
|
|
... |
|
|
504 |
|
|
ComPtr_t pTexture; |
|
|
505 |
|
|
DX_CHECK _pDevice->CreateTexture2D(&textureDesc, nullptr, &pTexture); |
|
|
506 |
|
|
return pTexture; |
|
|
|
|
|
... |
|
|
514 |
|
|
D3D10_TEXTURE2D_DESC textureDesc = { 0 }; |
|
|
515 |
|
|
textureDesc.Width = static_cast(_TextureData.Width); |
|
|
516 |
|
|
textureDesc.Height = static_cast(_TextureData.Height); |
|
|
517 |
|
|
textureDesc.MipLevels = 1; |
|
|
518 |
|
|
textureDesc.ArraySize = 1; |
|
|
519 |
|
|
textureDesc.Format = m_Format; |
|
|
520 |
|
|
textureDesc.Usage = D3D10_USAGE_DEFAULT; |
|
|
521 |
|
|
textureDesc.BindFlags = D3D10_BIND_SHADER_RESOURCE; |
|
|
522 |
|
|
textureDesc.MiscFlags = 0; |
|
|
523 |
|
|
textureDesc.SampleDesc.Count = 1; |
|
|
524 |
|
|
textureDesc.SampleDesc.Quality = 0; |
|
|
|
|
|
... |
|
|
526 |
|
|
ComPtr_t pTexture; |
|
|
527 |
|
|
DX_CHECK _pDevice->CreateTexture2D(&textureDesc, nullptr, &pTexture); |
|
|
|
|
|
... |
|
|
529 |
|
|
_pDevice->UpdateSubresource(pTexture.Get(), 0, NULL, |
|
|
|
|
|
... |
|
|
532 |
|
|
D3D10_SHADER_RESOURCE_VIEW_DESC srvDesc = { 0 }; |
|
|
533 |
|
|
srvDesc.Format = textureDesc.Format; |
|
|
534 |
|
|
srvDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D; |
|
|
535 |
|
|
srvDesc.Texture2D.MipLevels = textureDesc.MipLevels; |
|
|
|
|
|
... |
|
|
537 |
|
|
DX_CHECK _pDevice->CreateShaderResourceView(pTexture.Get(), |
|
|
|
|
|
... |
|
|
539 |
|
|
return pTexture; |
|
|
|
|
|
... |
|
|
546 |
|
|
D3D10_TEXTURE2D_DESC textureDesc = { 0 }; |
|
|
547 |
|
|
textureDesc.Width = static_cast(_TextureData.Width); |
|
|
548 |
|
|
textureDesc.Height = static_cast(_TextureData.Height); |
|
|
549 |
|
|
textureDesc.MipLevels = 0; // full set of subtextures |
|
|
550 |
|
|
textureDesc.ArraySize = 1; |
|
|
551 |
|
|
textureDesc.Format = m_Format; |
|
|
552 |
|
|
textureDesc.Usage = D3D10_USAGE_DEFAULT; |
|
|
553 |
|
|
textureDesc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE; |
|
|
554 |
|
|
textureDesc.MiscFlags = D3D10_RESOURCE_MISC_GENERATE_MIPS; |
|
|
555 |
|
|
textureDesc.SampleDesc.Count = 1; |
|
|
556 |
|
|
textureDesc.SampleDesc.Quality = 0; |
|
|
|
|
|
... |
|
|
558 |
|
|
ComPtr_t pTexture; |
|
|
559 |
|
|
DX_CHECK _pDevice->CreateTexture2D(&textureDesc, nullptr, &pTexture); |
|
|
|
|
|
... |
|
|
561 |
|
|
_pDevice->UpdateSubresource(pTexture.Get(), 0, NULL, |
|
|
|
|
|
... |
|
|
564 |
|
|
D3D10_SHADER_RESOURCE_VIEW_DESC srvDesc = { 0 }; |
|
|
565 |
|
|
srvDesc.Format = m_Format; |
|
|
566 |
|
|
srvDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D; |
|
|
567 |
|
|
srvDesc.Texture2D.MipLevels = static_cast(-1); |
|
|
|
|
|
... |
|
|
569 |
|
|
DX_CHECK _pDevice->CreateShaderResourceView(pTexture.Get(), |
|
|
|
|
|
... |
|
|
572 |
|
|
_pDevice->GenerateMips(m_pShaderResourceView.Get()); |
|
|
573 |
|
|
return pTexture; |
|
|
|
|
|
... |
|
|
582 |
|
|
const auto CreateTextureTargetAndSource = [=](void) |
|
|
|
|
|
... |
|
|
584 |
|
|
(*m_pDataTexture)[uT("width")] = (int)_Width; |
|
|
585 |
|
|
(*m_pDataTexture)[uT("height")] = (int)_Height; |
|
|
|
|
|
... |
|
|
587 |
|
|
D3D10_TEXTURE2D_DESC textureDesc = { 0 }; |
|
|
588 |
|
|
textureDesc.Width = _Width; |
|
|
589 |
|
|
textureDesc.Height = _Height; |
|
|
590 |
|
|
textureDesc.MipLevels = 1; //0 - full set of subtextures |
|
|
591 |
|
|
textureDesc.ArraySize = 1; |
|
|
592 |
|
|
textureDesc.Format = m_Format; |
|
|
593 |
|
|
textureDesc.Usage = D3D10_USAGE_DEFAULT; |
|
|
594 |
|
|
textureDesc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE; |
|
|
595 |
|
|
textureDesc.MiscFlags = 0; |
|
|
596 |
|
|
textureDesc.SampleDesc.Count = 1; |
|
|
597 |
|
|
textureDesc.SampleDesc.Quality = 0; |
|
|
|
|
|
... |
|
|
599 |
|
|
ComPtr_t pTexture; |
|
|
600 |
|
|
DX_CHECK _pDevice->CreateTexture2D(&textureDesc, nullptr, &pTexture); |
|
|
601 |
|
|
return pTexture; |
|
|
602 |
|
|
}; |
|
|
|
|
|
... |
|
|
604 |
|
|
const auto CreateShaderResourceView = [=](auto _pTexture) |
|
|
|
|
|
... |
|
|
606 |
|
|
D3D10_SHADER_RESOURCE_VIEW_DESC srvDesc = { 0 }; |
|
|
607 |
|
|
srvDesc.Format = m_Format; |
|
|
608 |
|
|
srvDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D; |
|
|
609 |
|
|
srvDesc.Texture2D.MipLevels = 1; |
|
|
|
|
|
... |
|
|
611 |
|
|
ComPtr_t pShaderResourceView; |
|
|
612 |
|
|
DX_CHECK _pDevice->CreateShaderResourceView(_pTexture.Get(), |
|
|
|
|
|
... |
|
|
614 |
|
|
return pShaderResourceView; |
|
|
615 |
|
|
}; |
|
|
|
|
|
... |
|
|
617 |
|
|
const auto CreateRenderTargetView = [=](auto _pTexture) |
|
|
|
|
|
... |
|
|
619 |
|
|
D3D10_RENDER_TARGET_VIEW_DESC Desc = { 0 }; |
|
|
620 |
|
|
Desc.Format = m_Format; |
|
|
621 |
|
|
Desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D; |
|
|
|
|
|
... |
|
|
623 |
|
|
ComPtr_t pRenderTargetView; |
|
|
624 |
|
|
DX_CHECK _pDevice->CreateRenderTargetView(_pTexture.Get(), |
|
|
|
|
|
... |
|
|
626 |
|
|
return pRenderTargetView; |
|
|
627 |
|
|
}; |
|
|
|
|
|
... |
|
|
629 |
|
|
const auto pTexture = CreateTextureTargetAndSource(); |
|
|
630 |
|
|
m_pRenderTargetView = CreateRenderTargetView(pTexture); |
|
|
631 |
|
|
m_pShaderResourceView = CreateShaderResourceView(pTexture); |
|
|
632 |
|
|
return pTexture; |
|
|
|
|
|
... |
|
|
640 |
|
|
const auto CreateDepthTargetAndSource = [=](void) |
|
|
|
|
|
... |
|
|
642 |
|
|
(*m_pDataTexture)[uT("width")] = (int)_Width; |
|
|
643 |
|
|
(*m_pDataTexture)[uT("height")] = (int)_Height; |
|
|
|
|
|
... |
|
|
645 |
|
|
D3D10_TEXTURE2D_DESC textureDesc = { 0 }; |
|
|
646 |
|
|
textureDesc.Width = _Width; |
|
|
647 |
|
|
textureDesc.Height = _Height; |
|
|
648 |
|
|
textureDesc.MipLevels = 1; //0 - full set of subtextures |
|
|
649 |
|
|
textureDesc.ArraySize = 1; |
|
|
650 |
|
|
textureDesc.Format = DXGI_FORMAT_R24G8_TYPELESS; |
|
|
651 |
|
|
textureDesc.Usage = D3D10_USAGE_DEFAULT; |
|
|
652 |
|
|
textureDesc.BindFlags = D3D10_BIND_DEPTH_STENCIL | D3D10_BIND_SHADER_RESOURCE; |
|
|
653 |
|
|
textureDesc.MiscFlags = 0; |
|
|
654 |
|
|
textureDesc.SampleDesc.Count = 1; |
|
|
655 |
|
|
textureDesc.SampleDesc.Quality = 0; |
|
|
|
|
|
... |
|
|
657 |
|
|
ComPtr_t pTexture; |
|
|
658 |
|
|
DX_CHECK _pDevice->CreateTexture2D(&textureDesc, nullptr, &pTexture); |
|
|
659 |
|
|
return pTexture; |
|
|
660 |
|
|
}; |
|
|
|
|
|
... |
|
|
662 |
|
|
const auto CreateDeptShaderResourceView = [=](auto _pTexture) |
|
|
|
|
|
... |
|
|
664 |
|
|
D3D10_SHADER_RESOURCE_VIEW_DESC srvDesc = { 0 }; |
|
|
665 |
|
|
srvDesc.Format = DXGI_FORMAT_R24_UNORM_X8_TYPELESS; |
|
|
666 |
|
|
srvDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D; |
|
|
667 |
|
|
srvDesc.Texture2D.MipLevels = 1; |
|
|
|
|
|
... |
|
|
669 |
|
|
ComPtr_t pShaderResourceView; |
|
|
670 |
|
|
DX_CHECK _pDevice->CreateShaderResourceView(_pTexture.Get(), |
|
|
|
|
|
... |
|
|
672 |
|
|
return pShaderResourceView; |
|
|
673 |
|
|
}; |
|
|
|
|
|
... |
|
|
675 |
|
|
const auto CreateDepthStencilView = [=](auto _pTexture) |
|
|
|
|
|
... |
|
|
677 |
|
|
D3D10_DEPTH_STENCIL_VIEW_DESC Desc = { 0 }; |
|
|
678 |
|
|
Desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; |
|
|
679 |
|
|
Desc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D; |
|
|
|
|
|
... |
|
|
681 |
|
|
ComPtr_t pDepthStencilView; |
|
|
682 |
|
|
DX_CHECK _pDevice->CreateDepthStencilView(_pTexture.Get(), |
|
|
|
|
|
... |
|
|
684 |
|
|
return pDepthStencilView; |
|
|
685 |
|
|
}; |
|
|
|
|
|
... |
|
|
687 |
|
|
const auto pTexture = CreateDepthTargetAndSource(); |
|
|
688 |
|
|
m_pDepthStencilView = CreateDepthStencilView(pTexture); |
|
|
689 |
|
|
m_pShaderResourceView = CreateDeptShaderResourceView(pTexture); |
|
|
690 |
|
|
return pTexture; |
|
|
|
|
|
... |
|
|
695 |
|
|
const int Index = (*_pData)[uT("index")].Default(-1); |
|
|
696 |
|
|
if (Index >= 0) return static_cast(Index); |
|
|
|
|
|
... |
|
|
698 |
|
|
static const ::std::vector Destinations = |
|
|
|
|
|
... |
|
|
708 |
|
|
const String_t Destination = |
|
|
|
|
|
... |
|
|
711 |
|
|
const auto itDestination = |
|
|
|
|
|
... |
|
|
713 |
|
|
if (itDestination == Destinations.cend()) |
|
|
|
|
|
... |
|
|
715 |
|
|
throw STD_EXCEPTION << "Unexpected destination texture: " << Destination; |
|
|
|
|
|
... |
|
|
718 |
|
|
return static_cast( |
|
|
|
|
|
... |
|
|
720 |
|
|
}; |
|
|
|
|
|
... |
|
|
724 |
|
|
const int Capacity = (*_pData)[uT("capacity")].Default(8); |
|
|
|
|
|
... |
|
|
726 |
|
|
return |
|
|
|
|
|
... |
|
|
734 |
|
|
m_pDataTexture{ _pDataTexture }, |
|
|
735 |
|
|
m_iDestination{ GetDestinationIndex(_pDataTexture) }, |
|
|
736 |
|
|
m_Format{ GetFormat(_pDataTexture) } |
|
|
|
|
|
... |
|
|
744 |
|
|
~Texture(void) = default; |
|
|
|
|
|
... |
|
|
749 |
|
|
const auto pBkSurface = _pComponent; |
|
|
|
|
|
... |
|
|
751 |
|
|
const auto GetViewportSize = [=](void) |
|
|
|
|
|
... |
|
|
755 |
|
|
D3D10_VIEWPORT ViewPort = { 0 }; |
|
|
756 |
|
|
UINT NumViewports = 1u; |
|
|
757 |
|
|
m_pDevice->RSGetViewports(&NumViewports, &ViewPort); |
|
|
|
|
|
... |
|
|
759 |
|
|
(*pBkSurface)[uT("width")] = static_cast(ViewPort.Width); |
|
|
760 |
|
|
(*pBkSurface)[uT("height")] = static_cast(ViewPort.Height); |
|
|
|
|
|
... |
|
|
762 |
|
|
return Size_t{ ViewPort.Width, ViewPort.Height }; |
|
|
763 |
|
|
}; |
|
|
|
|
|
... |
|
|
765 |
|
|
const auto [Width, Height] = GetViewportSize(); |
|
|
|
|
|
... |
|
|
767 |
|
|
const auto pBkSurfaceTextures = |
|
|
|
|
|
... |
|
|
772 |
|
|
auto pTexture = ::std::make_shared(_pDataTexture); |
|
|
773 |
|
|
pTexture->MakeTarget(m_pDevice, Width, Height); |
|
|
774 |
|
|
(*_pDataTexture)[uT("entity")] = pTexture; |
|
|
|
|
|
... |
|
|
776 |
|
|
pBkSurfaceTextures->push_back(pTexture); |
|
|
777 |
|
|
}; |
|
|
|
|
|
... |
|
|
779 |
|
|
CapturingServiceComponent::Process(_pComponent, |
|
|
|
|
|
... |
|
|
784 |
|
|
return [=](void) |
|
|
|
|
|
... |
|
|
786 |
|
|
const auto [Width, Height] = GetViewportSize(); |
|
|
|
|
|
... |
|
|
788 |
|
|
m_CurrentRenderTargets.clear(); |
|
|
|
|
|
... |
|
|
790 |
|
|
for (auto & pTexture : *pBkSurfaceTextures) |
|
|
|
|
|
... |
|
|
792 |
|
|
if (pTexture->m_Width != Width || pTexture->m_Height != Height) |
|
|
|
|
|
... |
|
|
794 |
|
|
pTexture->MakeTarget(m_pDevice, Width, Height); |
|
|
|
|
|
... |
|
|
797 |
|
|
if (pTexture->m_pRenderTargetView) |
|
|
|
|
|
... |
|
|
799 |
|
|
m_CurrentRenderTargets.push_back(pTexture->m_pRenderTargetView.Get()); |
|
|
|
|
|
... |
|
|
802 |
|
|
if (pTexture->m_pDepthStencilView) |
|
|
|
|
|
... |
|
|
804 |
|
|
m_pCurrentDepthStencilView = pTexture->m_pDepthStencilView; |
|
|
|
|
|
... |
|
|
807 |
|
|
ID3D10ShaderResourceView * NullResourceView[1] = { nullptr }; |
|
|
808 |
|
|
m_pDevice->PSSetShaderResources( |
|
|
|
|
|
... |
|
|
812 |
|
|
if (m_CurrentRenderTargets.empty()) |
|
|
|
|
|
... |
|
|
814 |
|
|
m_CurrentRenderTargets = { nullptr }; |
|
|
|
|
|
... |
|
|
817 |
|
|
m_pDevice->OMSetRenderTargets( |
|
|
|
|
|
... |
|
|
820 |
|
|
}; |
|
|
|
|
|
... |
|
|
827 |
|
|
D3D10_SAMPLER_DESC sampDesc = { 0 }; |
|
|
828 |
|
|
sampDesc.Filter = D3D10_FILTER_ANISOTROPIC; |
|
|
829 |
|
|
sampDesc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP; |
|
|
830 |
|
|
sampDesc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP; |
|
|
831 |
|
|
sampDesc.AddressW = D3D10_TEXTURE_ADDRESS_WRAP; |
|
|
832 |
|
|
sampDesc.ComparisonFunc = D3D10_COMPARISON_NEVER; |
|
|
833 |
|
|
sampDesc.MinLOD = 0; |
|
|
834 |
|
|
sampDesc.MaxLOD = D3D10_FLOAT32_MAX; |
|
|
|
|
|
... |
|
|
836 |
|
|
ComPtr_t pSamplerState; |
|
|
837 |
|
|
DX_CHECK m_pDevice->CreateSamplerState(&sampDesc, &pSamplerState); |
|
|
|
|
|
... |
|
|
839 |
|
|
return [=](void) |
|
|
|
|
|
... |
|
|
841 |
|
|
m_pDevice->PSSetSamplers(0, 1, pSamplerState.GetAddressOf()); |
|
|
842 |
|
|
}; |
|
|
843 |
|
|
}; |
|
|
|
|
|
... |
|
|
847 |
|
|
const Component::Scissor ScissorData{ *_pComponent }; |
|
|
|
|
|
... |
|
|
849 |
|
|
D3D10_RASTERIZER_DESC RasterizerDesc = { 0 }; |
|
|
850 |
|
|
RasterizerDesc.FillMode = D3D10_FILL_SOLID; |
|
|
851 |
|
|
RasterizerDesc.CullMode = D3D10_CULL_BACK; |
|
|
852 |
|
|
RasterizerDesc.FrontCounterClockwise = TRUE; |
|
|
853 |
|
|
RasterizerDesc.DepthClipEnable = TRUE; |
|
|
854 |
|
|
RasterizerDesc.ScissorEnable = (ScissorData.IsEnabled) ? TRUE : FALSE; |
|
|
|
|
|
... |
|
|
856 |
|
|
ComPtr_t pScissor; |
|
|
857 |
|
|
DX_CHECK m_pDevice->CreateRasterizerState(&RasterizerDesc, &pScissor); |
|
|
|
|
|
... |
|
|
859 |
|
|
const auto pScissorRect = CapturingServiceComponent::Get(_pComponent, |
|
|
|
|
|
... |
|
|
862 |
|
|
Render_t ScissorEnabled = [=](void) |
|
|
|
|
|
... |
|
|
864 |
|
|
const Component::Scissor ScissorData{ *pScissorRect }; |
|
|
|
|
|
... |
|
|
867 |
|
|
rect.left = ScissorData.Left; |
|
|
868 |
|
|
rect.right = ScissorData.Right; |
|
|
869 |
|
|
rect.top = ScissorData.Top; |
|
|
870 |
|
|
rect.bottom = ScissorData.Bottom; |
|
|
|
|
|
... |
|
|
872 |
|
|
m_pDevice->RSSetScissorRects(1, &rect); |
|
|
873 |
|
|
m_pDevice->RSSetState(pScissor.Get()); |
|
|
874 |
|
|
}; |
|
|
|
|
|
... |
|
|
876 |
|
|
Render_t ScissorDisabled = [=](void) |
|
|
|
|
|
... |
|
|
878 |
|
|
m_pDevice->RSSetState(pScissor.Get()); |
|
|
879 |
|
|
}; |
|
|
|
|
|
... |
|
|
881 |
|
|
return (ScissorData.IsEnabled) ? ScissorEnabled : ScissorDisabled; |
|
|
882 |
|
|
}; |
|
|
|
|
|
... |
|
|
886 |
|
|
const Component::Rasterizer RasterizerData{ *_pComponent }; |
|
|
|
|
|
... |
|
|
888 |
|
|
D3D10_RASTERIZER_DESC RasterizerDesc = { 0 }; |
|
|
889 |
|
|
RasterizerDesc.FillMode = D3D10_FILL_SOLID; |
|
|
890 |
|
|
RasterizerDesc.FrontCounterClockwise = TRUE; |
|
|
891 |
|
|
RasterizerDesc.DepthClipEnable = TRUE; |
|
|
|
|
|
... |
|
|
894 |
|
|
RasterizerDesc.CullMode = |
|
|
|
|
|
... |
|
|
900 |
|
|
ComponentPtr_t pScissorRect; |
|
|
|
|
|
... |
|
|
904 |
|
|
pScissorRect = _pDataRect; |
|
|
905 |
|
|
RasterizerDesc.ScissorEnable = TRUE; |
|
|
906 |
|
|
}; |
|
|
|
|
|
... |
|
|
908 |
|
|
CapturingServiceComponent::Process(_pComponent, |
|
|
|
|
|
... |
|
|
913 |
|
|
ComPtr_t pRasterizerState; |
|
|
914 |
|
|
DX_CHECK m_pDevice->CreateRasterizerState(&RasterizerDesc, &pRasterizerState); |
|
|
|
|
|
... |
|
|
916 |
|
|
Render_t Result; |
|
|
|
|
|
... |
|
|
918 |
|
|
if (pScissorRect == nullptr) |
|
|
|
|
|
... |
|
|
920 |
|
|
Result = [=](void) |
|
|
|
|
|
... |
|
|
922 |
|
|
m_pDevice->RSSetState(pRasterizerState.Get()); |
|
|
923 |
|
|
}; |
|
|
|
|
|
... |
|
|
927 |
|
|
Result = [=](void) |
|
|
|
|
|
... |
|
|
929 |
|
|
const Component::Scissor ScissorData{ *pScissorRect }; |
|
|
|
|
|
... |
|
|
932 |
|
|
rect.left = ScissorData.Left; |
|
|
933 |
|
|
rect.right = ScissorData.Right; |
|
|
934 |
|
|
rect.top = ScissorData.Top; |
|
|
935 |
|
|
rect.bottom = ScissorData.Bottom; |
|
|
|
|
|
... |
|
|
937 |
|
|
m_pDevice->RSSetScissorRects(1, &rect); |
|
|
938 |
|
|
m_pDevice->RSSetState(pRasterizerState.Get()); |
|
|
939 |
|
|
}; |
|
|
|
|
|
... |
|
|
942 |
|
|
return Result; |
|
|
943 |
|
|
}; |
|
|
|
|
|
... |
|
|
947 |
|
|
return GetDepthState( |
|
|
|
|
|
... |
|
|
951 |
|
|
}; |
|
|
|
|
|
... |
|
|
955 |
|
|
const auto ARGBtoFloat4 = [](const uint32_t _HexColor) |
|
|
|
|
|
... |
|
|
957 |
|
|
return ::std::vector |
|
|
|
|
|
... |
|
|
964 |
|
|
}; |
|
|
|
|
|
... |
|
|
966 |
|
|
const auto BackgroundColor = |
|
|
|
|
|
... |
|
|
969 |
|
|
return [=](void) |
|
|
|
|
|
... |
|
|
971 |
|
|
for (auto * pRenderTargetView : m_CurrentRenderTargets) |
|
|
|
|
|
... |
|
|
973 |
|
|
m_pDevice->ClearRenderTargetView( |
|
|
|
|
|
... |
|
|
976 |
|
|
}; |
|
|
977 |
|
|
}; |
|
|
|
|
|
... |
|
|
979 |
|
|
const auto CreateAlphaTestState = [](void) |
|
|
|
|
|
... |
|
|
981 |
|
|
return nullptr; |
|
|
982 |
|
|
}; |
|
|
|
|
|
... |
|
|
986 |
|
|
{ uT("Blend"), [this](void) { return CreateBlendState(true); } }, |
|
|
|
|
|
... |
|
|
995 |
|
|
return Creators[_pComponent->Kind](); |
|
|
|
|
|
... |
|
|
1002 |
|
|
const auto pDataTexture = CapturingServiceComponent::Get(_pComponent, |
|
|
|
|
|
... |
|
|
1005 |
|
|
Texture::Ptr_t pTexture = (*pDataTexture)[uT("entity")].Default(Texture::Ptr_t{}); |
|
|
1006 |
|
|
if (pTexture == nullptr) |
|
|
|
|
|
... |
|
|
1008 |
|
|
pTexture = ::std::make_shared(pDataTexture); |
|
|
1009 |
|
|
pTexture->MakeRGBASource(m_pDevice); |
|
|
|
|
|
... |
|
|
1013 |
|
|
(*pDataTexture)[uT("entity")] = Texture::Ptr_t{}; |
|
|
|
|
|
... |
|
|
1016 |
|
|
if (pTexture->m_pReadTexture == nullptr) |
|
|
|
|
|
... |
|
|
1018 |
|
|
return [=](void) |
|
|
|
|
|
... |
|
|
1020 |
|
|
m_pDevice->PSSetShaderResources(pTexture->m_iDestination, 1, |
|
|
|
|
|
... |
|
|
1022 |
|
|
}; |
|
|
|
|
|
... |
|
|
1025 |
|
|
const BufferMapper_t cbBufferMapper = |
|
|
|
|
|
... |
|
|
1028 |
|
|
return [=](void) |
|
|
|
|
|
... |
|
|
1030 |
|
|
if (cbBufferMapper(nullptr)) |
|
|
|
|
|
... |
|
|
1032 |
|
|
const auto pTextureCopy = pTexture->m_pReadTexture; |
|
|
|
|
|
... |
|
|
1034 |
|
|
m_pDevice->CopyResource(pTextureCopy.Get(), pTexture->m_pTexture.Get()); |
|
|
|
|
|
... |
|
|
1036 |
|
|
D3D10_MAPPED_TEXTURE2D mappedTex = { 0 }; |
|
|
1037 |
|
|
DX_CHECK pTextureCopy->Map(0, D3D10_MAP_READ, 0, &mappedTex); |
|
|
1038 |
|
|
cbBufferMapper(mappedTex.pData); |
|
|
1039 |
|
|
pTextureCopy->Unmap(0); |
|
|
|
|
|
... |
|
|
1042 |
|
|
m_pDevice->PSSetShaderResources(pTexture->m_iDestination, 1, |
|
|
|
|
|
... |
|
|
1044 |
|
|
}; |
|
|
|
|
|
... |
|
|
1051 |
|
|
const auto pShaderDataComponent = CapturingServiceComponent::Get(_pComponent, |
|
|
|
|
|
... |
|
|
1054 |
|
|
const auto ShaderData = Component::Shader{ *pShaderDataComponent, ::Default }; |
|
|
|
|
|
... |
|
|
1056 |
|
|
::std::string Define = |
|
|
|
|
|
... |
|
|
1061 |
|
|
const auto HeaderShaderText = ::Predefined + ::Data + |
|
|
|
|
|
... |
|
|
1063 |
|
|
auto ShaderText = ShaderData.Data; |
|
|
1064 |
|
|
auto Entry = ShaderData.Entry; |
|
|
|
|
|
... |
|
|
1066 |
|
|
if (ShaderData.Kind == uT("Pixel")) |
|
|
|
|
|
... |
|
|
1068 |
|
|
Define = |
|
|
|
|
|
... |
|
|
1073 |
|
|
if (ShaderData.ReturnType != "void") |
|
|
|
|
|
... |
|
|
1075 |
|
|
const auto PixelMain = ShaderData.ReturnType + " psMain(Pixel _Value)" + |
|
|
|
|
|
... |
|
|
1080 |
|
|
Entry = "psMain"; |
|
|
1081 |
|
|
ShaderText += DirectX::Shader::Convert(PixelMain); |
|
|
|
|
|
... |
|
|
1085 |
|
|
const auto pCompiledShader = DirectX::Shader::Compile( |
|
|
|
|
|
... |
|
|
1092 |
|
|
ComPtr_t pVertexLayout; |
|
|
1093 |
|
|
DX_CHECK m_pDevice->CreateInputLayout( |
|
|
|
|
|
... |
|
|
1098 |
|
|
ComPtr_t pVertexShader; |
|
|
1099 |
|
|
DX_CHECK m_pDevice->CreateVertexShader(pCompiledShader->GetBufferPointer(), |
|
|
|
|
|
... |
|
|
1102 |
|
|
return [=](void) |
|
|
|
|
|
... |
|
|
1104 |
|
|
m_pDevice->IASetInputLayout(pVertexLayout.Get()); |
|
|
1105 |
|
|
m_pDevice->VSSetShader(pVertexShader.Get()); |
|
|
1106 |
|
|
}; |
|
|
1107 |
|
|
}; |
|
|
|
|
|
... |
|
|
1118 |
|
|
for (UINT i = 0; i < static_cast(ShaderData.Instance.size()); i++) |
|
|
|
|
|
... |
|
|
1120 |
|
|
const auto Type = ShaderData.Instance[i]; |
|
|
1121 |
|
|
const auto Format = |
|
|
|
|
|
... |
|
|
1125 |
|
|
const auto Size = i * 4 * static_cast( |
|
|
|
|
|
... |
|
|
1130 |
|
|
LayoutDesc.push_back( |
|
|
|
|
|
... |
|
|
1136 |
|
|
return CreateVertexShader(LayoutDesc); |
|
|
1137 |
|
|
}; |
|
|
|
|
|
... |
|
|
1141 |
|
|
ComPtr_t pPixelShader; |
|
|
1142 |
|
|
DX_CHECK m_pDevice->CreatePixelShader(pCompiledShader->GetBufferPointer(), |
|
|
|
|
|
... |
|
|
1145 |
|
|
return [=](void) |
|
|
|
|
|
... |
|
|
1147 |
|
|
m_pDevice->PSSetShader(pPixelShader.Get()); |
|
|
1148 |
|
|
}; |
|
|
1149 |
|
|
}; |
|
|
|
|
|
... |
|
|
1157 |
|
|
return Creators[ShaderData.Kind](); |
|
|
|
|
|
... |
|
|
1162 |
|
|
const auto pBufferData = CapturingServiceComponent::Get(_pBuffer, |
|
|
|
|
|
... |
|
|
1165 |
|
|
if ((*pBufferData)[uT("content")].IsType>()) |
|
|
|
|
|
... |
|
|
1169 |
|
|
const BufferMapper_t & cbBufferMapper = |
|
|
|
|
|
... |
|
|
1172 |
|
|
return (cbBufferMapper == nullptr) ? |
|
|
|
|
|
... |
|
|
1176 |
|
|
else if ((*_pBuffer)[uT("mapper")].IsType &>()) |
|
|
|
|
|
... |
|
|
1180 |
|
|
const BufferMap_t cbBufferMapper = |
|
|
|
|
|
... |
|
|
1182 |
|
|
if (!cbBufferMapper) |
|
|
|
|
|
... |
|
|
1184 |
|
|
throw STD_EXCEPTION << "Unexpected empty mapper: " << _pBuffer->Id; |
|
|
|
|
|
... |
|
|
1187 |
|
|
const ::std::size_t BufferSize = (*pBufferData)[uT("size")].Default((::std::size_t)0); |
|
|
1188 |
|
|
if (BufferSize == 0) |
|
|
|
|
|
... |
|
|
1190 |
|
|
throw STD_EXCEPTION << "Unexpected zero size: " << _pBuffer->Id; |
|
|
|
|
|
... |
|
|
1193 |
|
|
const auto pData = |
|
|
|
|
|
... |
|
|
1195 |
|
|
const auto pBuffer = |
|
|
|
|
|
... |
|
|
1198 |
|
|
return [=](void) |
|
|
|
|
|
... |
|
|
1200 |
|
|
cbBufferMapper(pData->data()); |
|
|
|
|
|
... |
|
|
1202 |
|
|
constexpr auto BufferIndex = |
|
|
|
|
|
... |
|
|
1207 |
|
|
m_pDevice->VSSetConstantBuffers(BufferIndex, 1, pBuffer.GetAddressOf()); |
|
|
1208 |
|
|
m_pDevice->PSSetConstantBuffers(BufferIndex, 1, pBuffer.GetAddressOf()); |
|
|
|
|
|
... |
|
|
1210 |
|
|
m_pDevice->UpdateSubresource(pBuffer.Get(), 0, NULL, pData->data(), 0, 0); |
|
|
1211 |
|
|
}; |
|
|
|
|
|
... |
|
|
1214 |
|
|
return nullptr; |
|
|
|
|
|
... |
|
|
1219 |
|
|
const auto PreRender = |
|
|
|
|
|
... |
|
|
1226 |
|
|
return [=](void) |
|
|
|
|
|
... |
|
|
1228 |
|
|
PreRender(); |
|
|
1229 |
|
|
m_pConstants->Update<::Object>(); |
|
|
1230 |
|
|
}; |
|
|
|
|
|
... |
|
|
1238 |
|
|
ComponentPtr_t pIndexBufferData = _pBuffer; |
|
|
1239 |
|
|
ComponentPtr_t pInstanceBufferData = nullptr; |
|
|
|
|
|
... |
|
|
1243 |
|
|
if ((*_pBufferData)[uT("content")].IsType>()) |
|
|
|
|
|
... |
|
|
1245 |
|
|
pIndexBufferData = _pBufferData; |
|
|
|
|
|
... |
|
|
1247 |
|
|
else if ((*_pBufferData)[uT("mapper")].IsType()) |
|
|
|
|
|
... |
|
|
1249 |
|
|
pInstanceBufferData = _pBufferData; |
|
|
|
|
|
... |
|
|
1251 |
|
|
else if ((*_pBufferData)[uT("mapper")].IsType()) |
|
|
|
|
|
... |
|
|
1253 |
|
|
pInstanceBufferData = _pBufferData; |
|
|
|
|
|
... |
|
|
1257 |
|
|
throw STD_EXCEPTION << "Unexpected buffer data component."; |
|
|
|
|
|
... |
|
|
1259 |
|
|
}; |
|
|
|
|
|
... |
|
|
1261 |
|
|
CapturingServiceComponent::Process(_pBuffer, |
|
|
|
|
|
... |
|
|
1266 |
|
|
const Component::Buffer IndexBufferData{ *pIndexBufferData }; |
|
|
|
|
|
... |
|
|
1268 |
|
|
const auto pIndexBuffer = |
|
|
|
|
|
... |
|
|
1270 |
|
|
const auto IndexCount = static_cast(IndexBufferData.Data.size()); |
|
|
|
|
|
... |
|
|
1272 |
|
|
if (pInstanceBufferData == nullptr) |
|
|
|
|
|
... |
|
|
1274 |
|
|
return [=](void) |
|
|
|
|
|
... |
|
|
1276 |
|
|
m_pDevice->IASetIndexBuffer(pIndexBuffer.Get(), DXGI_FORMAT_R32_UINT, 0); |
|
|
1277 |
|
|
m_pDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST); |
|
|
1278 |
|
|
m_pDevice->DrawIndexed(IndexCount, 0, 0); |
|
|
1279 |
|
|
}; |
|
|
|
|
|
... |
|
|
1282 |
|
|
const ::std::size_t BufferSize = (*pInstanceBufferData)[uT("size")]; |
|
|
1283 |
|
|
const ::std::size_t MaxInstanceCount = (*pInstanceBufferData)[uT("count")]; |
|
|
1284 |
|
|
const auto Stride = static_cast(BufferSize / MaxInstanceCount); |
|
|
|
|
|
... |
|
|
1286 |
|
|
if (BufferSize % 16 != 0) |
|
|
|
|
|
... |
|
|
1288 |
|
|
throw STD_EXCEPTION << _pBuffer->Id << ": size % 16 != 0"; |
|
|
|
|
|
... |
|
|
1291 |
|
|
if (BufferSize % MaxInstanceCount != 0) |
|
|
|
|
|
... |
|
|
1293 |
|
|
throw STD_EXCEPTION << _pBuffer->Id << ": size % count != 0"; |
|
|
|
|
|
... |
|
|
1296 |
|
|
const auto pInstanceBuffer = |
|
|
|
|
|
... |
|
|
1299 |
|
|
if ((*pInstanceBufferData)[uT("mapper")].IsType()) |
|
|
|
|
|
... |
|
|
1301 |
|
|
const BufferMapperSize_t cbBufferMapper = |
|
|
|
|
|
... |
|
|
1304 |
|
|
return [=](void) |
|
|
|
|
|
... |
|
|
1306 |
|
|
::std::size_t InstanceCount = MaxInstanceCount; |
|
|
|
|
|
... |
|
|
1308 |
|
|
const auto IsDirty = cbBufferMapper(nullptr, InstanceCount); |
|
|
1309 |
|
|
if (IsDirty) |
|
|
|
|
|
... |
|
|
1311 |
|
|
void * pData = nullptr; |
|
|
1312 |
|
|
DX_CHECK pInstanceBuffer->Map(D3D10_MAP_WRITE_NO_OVERWRITE, 0, &pData); |
|
|
1313 |
|
|
cbBufferMapper(pData, InstanceCount); |
|
|
1314 |
|
|
pInstanceBuffer->Unmap(); |
|
|
|
|
|
... |
|
|
1316 |
|
|
InstanceCount = ::std::min(InstanceCount, MaxInstanceCount); |
|
|
|
|
|
... |
|
|
1319 |
|
|
constexpr UINT Offset = 0; |
|
|
1320 |
|
|
m_pDevice->IASetVertexBuffers( |
|
|
|
|
|
... |
|
|
1322 |
|
|
m_pDevice->IASetIndexBuffer( |
|
|
|
|
|
... |
|
|
1324 |
|
|
m_pDevice->IASetPrimitiveTopology( |
|
|
|
|
|
... |
|
|
1326 |
|
|
m_pDevice->DrawIndexedInstanced( |
|
|
|
|
|
... |
|
|
1328 |
|
|
}; |
|
|
|
|
|
... |
|
|
1331 |
|
|
const BufferMapperMaxSize_t cbBufferMapper = |
|
|
|
|
|
... |
|
|
1334 |
|
|
return [=](void) |
|
|
|
|
|
... |
|
|
1336 |
|
|
const auto IsDirty = cbBufferMapper(nullptr); |
|
|
1337 |
|
|
if (IsDirty) |
|
|
|
|
|
... |
|
|
1339 |
|
|
void * pData = nullptr; |
|
|
1340 |
|
|
DX_CHECK pInstanceBuffer->Map(D3D10_MAP_WRITE_NO_OVERWRITE, 0, &pData); |
|
|
1341 |
|
|
cbBufferMapper(pData); |
|
|
1342 |
|
|
pInstanceBuffer->Unmap(); |
|
|
|
|
|
... |
|
|
1345 |
|
|
constexpr UINT Offset = 0; |
|
|
1346 |
|
|
m_pDevice->IASetVertexBuffers( |
|
|
|
|
|
... |
|
|
1348 |
|
|
m_pDevice->IASetIndexBuffer( |
|
|
|
|
|
... |
|
|
1350 |
|
|
m_pDevice->IASetPrimitiveTopology( |
|
|
|
|
|
... |
|
|
1352 |
|
|
m_pDevice->DrawIndexedInstanced( |
|
|
|
|
|
... |
|
|
1354 |
|
|
}; |
|
|
|
|
|
... |
|
|
1359 |
|
|
if (m_pScreenRenderTargetView) |
|
|
|
|
|
... |
|
|
1362 |
|
|
m_pScreenRenderTargetView.Reset(); |
|
|
|
|
|
... |
|
|
1365 |
|
|
m_pSwapChain->ResizeBuffers(2, _Width, _Height, |
|
|
|
|
|
... |
|
|
1370 |
|
|
ComPtr_t pBackBuffer; |
|
|
1371 |
|
|
DX_CHECK m_pSwapChain->GetBuffer(0, |
|
|
|
|
|
... |
|
|
1374 |
|
|
DX_CHECK m_pDevice->CreateRenderTargetView(pBackBuffer.Get(), NULL, |
|
|
|
|
|
... |
|
|
1377 |
|
|
D3D10_TEXTURE2D_DESC descDepth = { 0 }; |
|
|
1378 |
|
|
descDepth.Width = _Width; |
|
|
1379 |
|
|
descDepth.Height = _Height; |
|
|
1380 |
|
|
descDepth.MipLevels = 1; |
|
|
1381 |
|
|
descDepth.ArraySize = 1; |
|
|
1382 |
|
|
descDepth.Format = DXGI_FORMAT_D32_FLOAT; |
|
|
1383 |
|
|
descDepth.SampleDesc.Count = 1; |
|
|
1384 |
|
|
descDepth.SampleDesc.Quality = 0; |
|
|
1385 |
|
|
descDepth.Usage = D3D10_USAGE_DEFAULT; |
|
|
1386 |
|
|
descDepth.BindFlags = D3D10_BIND_DEPTH_STENCIL; |
|
|
|
|
|
... |
|
|
1388 |
|
|
ComPtr_t pDepthBuffer; |
|
|
1389 |
|
|
DX_CHECK m_pDevice->CreateTexture2D(&descDepth, NULL, &pDepthBuffer); |
|
|
|
|
|
... |
|
|
1391 |
|
|
D3D10_DEPTH_STENCIL_VIEW_DESC descDSV = { 0 }; |
|
|
1392 |
|
|
descDSV.Format = descDepth.Format; |
|
|
1393 |
|
|
descDSV.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D; |
|
|
|
|
|
... |
|
|
1395 |
|
|
DX_CHECK m_pDevice->CreateDepthStencilView(pDepthBuffer.Get(), |
|
|
|
|
|
... |
|
|
1401 |
|
|
ComPtr_t pBlendState; |
|
|
|
|
|
... |
|
|
1403 |
|
|
if (_IsEnabled) |
|
|
|
|
|
... |
|
|
1405 |
|
|
D3D10_BLEND_DESC BlendDesc = { 0 }; |
|
|
1406 |
|
|
BlendDesc.AlphaToCoverageEnable = FALSE; |
|
|
1407 |
|
|
BlendDesc.BlendEnable[0] = TRUE; |
|
|
1408 |
|
|
BlendDesc.BlendEnable[1] = TRUE; |
|
|
1409 |
|
|
BlendDesc.BlendEnable[2] = TRUE; |
|
|
1410 |
|
|
BlendDesc.BlendEnable[3] = TRUE; |
|
|
1411 |
|
|
BlendDesc.BlendEnable[4] = TRUE; |
|
|
1412 |
|
|
BlendDesc.BlendEnable[5] = TRUE; |
|
|
1413 |
|
|
BlendDesc.BlendEnable[6] = TRUE; |
|
|
1414 |
|
|
BlendDesc.BlendEnable[7] = TRUE; |
|
|
1415 |
|
|
BlendDesc.SrcBlend = D3D10_BLEND_SRC_ALPHA; |
|
|
1416 |
|
|
BlendDesc.DestBlend = D3D10_BLEND_INV_SRC_ALPHA; |
|
|
1417 |
|
|
BlendDesc.BlendOp = D3D10_BLEND_OP_ADD; |
|
|
1418 |
|
|
BlendDesc.SrcBlendAlpha = D3D10_BLEND_ONE; |
|
|
1419 |
|
|
BlendDesc.DestBlendAlpha = D3D10_BLEND_ZERO; |
|
|
1420 |
|
|
BlendDesc.BlendOpAlpha = D3D10_BLEND_OP_ADD; |
|
|
1421 |
|
|
BlendDesc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL; |
|
|
1422 |
|
|
BlendDesc.RenderTargetWriteMask[1] = D3D10_COLOR_WRITE_ENABLE_ALL; |
|
|
1423 |
|
|
BlendDesc.RenderTargetWriteMask[2] = D3D10_COLOR_WRITE_ENABLE_ALL; |
|
|
1424 |
|
|
BlendDesc.RenderTargetWriteMask[3] = D3D10_COLOR_WRITE_ENABLE_ALL; |
|
|
1425 |
|
|
BlendDesc.RenderTargetWriteMask[4] = D3D10_COLOR_WRITE_ENABLE_ALL; |
|
|
1426 |
|
|
BlendDesc.RenderTargetWriteMask[5] = D3D10_COLOR_WRITE_ENABLE_ALL; |
|
|
1427 |
|
|
BlendDesc.RenderTargetWriteMask[6] = D3D10_COLOR_WRITE_ENABLE_ALL; |
|
|
1428 |
|
|
BlendDesc.RenderTargetWriteMask[7] = D3D10_COLOR_WRITE_ENABLE_ALL; |
|
|
|
|
|
... |
|
|
1430 |
|
|
DX_CHECK m_pDevice->CreateBlendState(&BlendDesc, &pBlendState); |
|
|
|
|
|
... |
|
|
1433 |
|
|
return [=](void) |
|
|
|
|
|
... |
|
|
1435 |
|
|
const FLOAT BlendFactor[] = { 0.0f, 0.0f, 0.0f, 0.0f }; |
|
|
1436 |
|
|
m_pDevice->OMSetBlendState(pBlendState.Get(), BlendFactor, 0xFFFFFFFF); |
|
|
1437 |
|
|
}; |
|
|
|
|
|
... |
|
|
1445 |
|
|
if (!_IsEnabled) |
|
|
|
|
|
... |
|
|
1447 |
|
|
return [=](void) |
|
|
|
|
|
... |
|
|
1449 |
|
|
m_pDevice->OMSetRenderTargets(static_cast(m_CurrentRenderTargets.size()), |
|
|
|
|
|
... |
|
|
1451 |
|
|
}; |
|
|
|
|
|
... |
|
|
1454 |
|
|
D3D10_DEPTH_STENCIL_DESC dsDesc = { 0 }; |
|
|
1455 |
|
|
dsDesc.DepthEnable = true; |
|
|
1456 |
|
|
dsDesc.DepthWriteMask = _IsOverwrite ? |
|
|
|
|
|
... |
|
|
1458 |
|
|
dsDesc.DepthFunc = D3D10_COMPARISON_GREATER; |
|
|
1459 |
|
|
dsDesc.StencilEnable = false; |
|
|
|
|
|
... |
|
|
1461 |
|
|
ComPtr_t pDSState; |
|
|
1462 |
|
|
DX_CHECK m_pDevice->CreateDepthStencilState(&dsDesc, &pDSState); |
|
|
|
|
|
... |
|
|
1464 |
|
|
const Render_t RenderDepthEnabled = [=](void) |
|
|
|
|
|
... |
|
|
1466 |
|
|
m_pDevice->OMSetRenderTargets(static_cast(m_CurrentRenderTargets.size()), |
|
|
|
|
|
... |
|
|
1468 |
|
|
m_pDevice->OMSetDepthStencilState(pDSState.Get(), 1); |
|
|
1469 |
|
|
}; |
|
|
|
|
|
... |
|
|
1471 |
|
|
const Render_t RenderDepthClear = [=](void) |
|
|
|
|
|
... |
|
|
1473 |
|
|
m_pDevice->OMSetRenderTargets(static_cast(m_CurrentRenderTargets.size()), |
|
|
|
|
|
... |
|
|
1475 |
|
|
m_pDevice->OMSetDepthStencilState(pDSState.Get(), 1); |
|
|
1476 |
|
|
m_pDevice->ClearDepthStencilView(m_pCurrentDepthStencilView.Get(), |
|
|
|
|
|
... |
|
|
1478 |
|
|
}; |
|
|
|
|
|
... |
|
|
1480 |
|
|
return _IsClear ? RenderDepthClear : RenderDepthEnabled; |
|
|
|
|
|
... |
|
|
1485 |
|
|
::std::deque PreRenders; |
|
|
|
|
|
... |
|
|
1489 |
|
|
PreRenders.push_front([=](void) |
|
|
|
|
|
... |
|
|
1491 |
|
|
auto & World = m_pConstants->Get<::Object>().World; |
|
|
|
|
|
... |
|
|
1493 |
|
|
const Component::Position Position{ *_pPosition }; |
|
|
|
|
|
... |
|
|
1495 |
|
|
World = ::glm::translate(World, |
|
|
|
|
|
... |
|
|
1497 |
|
|
}); |
|
|
1498 |
|
|
}; |
|
|
|
|
|
... |
|
|
1502 |
|
|
PreRenders.push_front([=](void) |
|
|
|
|
|
... |
|
|
1504 |
|
|
auto & World = m_pConstants->Get<::Object>().World; |
|
|
|
|
|
... |
|
|
1506 |
|
|
const Component::Rotation Rotation{ *_pRotation }; |
|
|
|
|
|
... |
|
|
1508 |
|
|
World = ::glm::rotate(World, Rotation.Z, ::glm::vec3{ 0.0f, 0.0f, 1.0f }); |
|
|
1509 |
|
|
World = ::glm::rotate(World, Rotation.Y, ::glm::vec3{ 0.0f, 1.0f, 0.0f }); |
|
|
1510 |
|
|
World = ::glm::rotate(World, Rotation.X, ::glm::vec3{ 1.0f, 0.0f, 0.0f }); |
|
|
1511 |
|
|
}); |
|
|
1512 |
|
|
}; |
|
|
|
|
|
... |
|
|
1516 |
|
|
PreRenders.push_front([=](void) |
|
|
|
|
|
... |
|
|
1518 |
|
|
auto & World = m_pConstants->Get<::Object>().World; |
|
|
|
|
|
... |
|
|
1520 |
|
|
const Component::Scale Scale{ *_pScale }; |
|
|
|
|
|
... |
|
|
1522 |
|
|
World = ::glm::scale(World, ::glm::vec3{ Scale.X, Scale.Y, Scale.Z }); |
|
|
1523 |
|
|
}); |
|
|
1524 |
|
|
}; |
|
|
|
|
|
... |
|
|
1526 |
|
|
PreRenders.push_front([=](void) |
|
|
|
|
|
... |
|
|
1528 |
|
|
m_pConstants->Get<::Object>().World = |
|
|
|
|
|
... |
|
|
1530 |
|
|
}); |
|
|
|
|
|
... |
|
|
1532 |
|
|
CapturingServiceComponent::Process(_pComponent, |
|
|
|
|
|
... |
|
|
1539 |
|
|
PreRenders.push_front([=](void) |
|
|
|
|
|
... |
|
|
1541 |
|
|
m_pConstants->Get<::Object>().World = ::glm::identity<::glm::mat4>(); |
|
|
1542 |
|
|
}); |
|
|
|
|
|
... |
|
|
1544 |
|
|
return [PreRenders](void) |
|
|
|
|
|
... |
|
|
1546 |
|
|
for (auto & Render : PreRenders) Render(); |
|
|
1547 |
|
|
}; |
|
|
|
|
|
... |
|
|
1552 |
|
|
CreateBasePreRenderGeometry(_pComponent)(); |
|
|
1553 |
|
|
const auto World = m_pConstants->Get<::Object>().World; |
|
|
|
|
|
... |
|
|
1555 |
|
|
return [=](void) |
|
|
|
|
|
... |
|
|
1557 |
|
|
m_pConstants->Get<::Object>().World = World; |
|
|
1558 |
|
|
}; |
|
|
|
|
|
... |
|
|
1563 |
|
|
::std::deque PreRenders; |
|
|
|
|
|
... |
|
|
1567 |
|
|
PreRenders.push_front([=](void) |
|
|
|
|
|
... |
|
|
1569 |
|
|
auto & World = m_pConstants->Get<::Object>().World; |
|
|
|
|
|
... |
|
|
1571 |
|
|
const Component::Position Position{ *_pPosition }; |
|
|
|
|
|
... |
|
|
1573 |
|
|
World = ::glm::translate(World, |
|
|
|
|
|
... |
|
|
1575 |
|
|
}); |
|
|
1576 |
|
|
}; |
|
|
|
|
|
... |
|
|
1578 |
|
|
PreRenders.push_front([=](void) |
|
|
|
|
|
... |
|
|
1580 |
|
|
m_pConstants->Get<::Object>().World = |
|
|
|
|
|
... |
|
|
1582 |
|
|
}); |
|
|
|
|
|
... |
|
|
1584 |
|
|
CapturingServiceComponent::Process(_pComponent, |
|
|
|
|
|
... |
|
|
1587 |
|
|
PreRenders.push_front([=](void) |
|
|
|
|
|
... |
|
|
1589 |
|
|
auto & World = m_pConstants->Get<::Object>().World; |
|
|
|
|
|
... |
|
|
1592 |
|
|
World = m_pConstants->Get<::Camera>().View; |
|
|
|
|
|
... |
|
|
1594 |
|
|
World[0][3] = 0.0f; |
|
|
1595 |
|
|
World[1][3] = 0.0f; |
|
|
1596 |
|
|
World[2][3] = 0.0f; |
|
|
1597 |
|
|
World[3][0] = 0.0f; |
|
|
1598 |
|
|
World[3][1] = 0.0f; |
|
|
1599 |
|
|
World[3][2] = 0.0f; |
|
|
1600 |
|
|
World[3][3] = 1.0f; |
|
|
1601 |
|
|
}); |
|
|
|
|
|
... |
|
|
1603 |
|
|
return [PreRenders](void) |
|
|
|
|
|
... |
|
|
1605 |
|
|
for (auto & Render : PreRenders) Render(); |
|
|
1606 |
|
|
}; |
|
|
|
|
|
|