2025-07-10 13:29:03 +03:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include <renderer/dx/framebuffers.hpp>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#include <renderer/dx/shared_context.hpp>
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 13:28:41 +03:30
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-11 00:05:48 +03:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								namespace lt {
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 13:28:41 +03:30
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								dxFramebuffer::dxFramebuffer(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    const FramebufferSpecification &specification,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    Ref<dxSharedContext> sharedContext
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								)
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 14:23:01 +03:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    : m_context(sharedContext)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    , m_specification(specification)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    , m_render_target_view(nullptr)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    , m_color_attachment(nullptr)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    , m_depth_stencil_attachment(nullptr)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    , m_shader_resource_view(nullptr)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    , m_depth_stencil_view(nullptr)
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 13:28:41 +03:30
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-06 14:02:50 +03:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									auto hr = HRESULT {};
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 13:28:41 +03:30
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-06 14:02:50 +03:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									auto t2dDesc = D3D11_TEXTURE2D_DESC {};
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 13:28:41 +03:30
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									t2dDesc.Width = specification.width;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									t2dDesc.Height = specification.height;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									t2dDesc.MipLevels = 1;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									t2dDesc.ArraySize = 1;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									t2dDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									t2dDesc.SampleDesc.Count = 1u;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									t2dDesc.SampleDesc.Quality = 0u;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									t2dDesc.Usage = D3D11_USAGE_DEFAULT;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									t2dDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									t2dDesc.CPUAccessFlags = NULL;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									t2dDesc.MiscFlags = NULL;
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 15:36:53 +03:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									dxc(m_context->get_device()->CreateTexture2D(&t2dDesc, nullptr, &m_color_attachment));
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 13:28:41 +03:30
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-06 14:02:50 +03:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									auto srvDesc = D3D11_SHADER_RESOURCE_VIEW_DESC {};
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 13:28:41 +03:30
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									srvDesc.Format = t2dDesc.Format;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									srvDesc.Texture2D.MipLevels = 1;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									srvDesc.Texture2D.MostDetailedMip = 0;
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-11 14:05:59 +03:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									dxc(m_context->get_device()->CreateShaderResourceView(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									    m_color_attachment.Get(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									    &srvDesc,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									    &m_shader_resource_view
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									));
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 13:28:41 +03:30
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-06 14:02:50 +03:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									auto rtvDesc = D3D11_RENDER_TARGET_VIEW_DESC {};
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 13:28:41 +03:30
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									rtvDesc.Format = t2dDesc.Format;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									rtvDesc.Texture2D.MipSlice = 0u;
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 15:36:53 +03:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									dxc(m_context->get_device()
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 14:23:01 +03:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									        ->CreateRenderTargetView(m_color_attachment.Get(), &rtvDesc, &m_render_target_view));
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 13:28:41 +03:30
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 15:36:53 +03:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void dxFramebuffer::bind_as_target(const glm::vec4 &clearColor)
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 13:28:41 +03:30
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									FLOAT color[] = {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										clearColor.r,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										clearColor.g,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										clearColor.b,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										clearColor.a,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 15:36:53 +03:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									m_context->get_device_context()
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 14:23:01 +03:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									    ->OMSetRenderTargets(1u, m_render_target_view.GetAddressOf(), nullptr);
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 15:36:53 +03:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									m_context->get_device_context()->ClearRenderTargetView(m_render_target_view.Get(), color);
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 13:28:41 +03:30
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-06 14:02:50 +03:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									auto viewport = D3D11_VIEWPORT {};
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 13:28:41 +03:30
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									viewport.TopLeftX = 0;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									viewport.TopLeftY = 0;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 14:23:01 +03:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									viewport.Width = m_specification.width;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									viewport.Height = m_specification.height;
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 13:28:41 +03:30
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									viewport.MinDepth = 0.0f;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									viewport.MaxDepth = 1.0f;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									// set viewport
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 15:36:53 +03:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									m_context->get_device_context()->RSSetViewports(1u, &viewport);
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 13:28:41 +03:30
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 15:36:53 +03:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void dxFramebuffer::bind_as_resource()
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 13:28:41 +03:30
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-06 16:30:38 +03:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									log_err("NO_IMPLEMENT");
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 13:28:41 +03:30
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 15:36:53 +03:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void dxFramebuffer::resize(const glm::uvec2 &size)
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 13:28:41 +03:30
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 14:23:01 +03:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									m_specification.width = std::clamp(size.x, 1u, 16384u);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									m_specification.height = std::clamp(size.y, 1u, 16384u);
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 13:28:41 +03:30
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-06 14:02:50 +03:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									auto textureDesc = D3D11_TEXTURE2D_DESC {};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									auto rtvDesc = D3D11_RENDER_TARGET_VIEW_DESC {};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									auto srvDesc = D3D11_SHADER_RESOURCE_VIEW_DESC {};
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 13:28:41 +03:30
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 14:23:01 +03:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									m_color_attachment->GetDesc(&textureDesc);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									m_render_target_view->GetDesc(&rtvDesc);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									m_shader_resource_view->GetDesc(&srvDesc);
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 13:28:41 +03:30
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 14:23:01 +03:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									textureDesc.Width = m_specification.width;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									textureDesc.Height = m_specification.height;
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 13:28:41 +03:30
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-06 14:02:50 +03:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									auto hr = HRESULT {};
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 15:36:53 +03:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									dxc(m_context->get_device()->CreateTexture2D(&textureDesc, nullptr, &m_color_attachment));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									dxc(m_context->get_device()
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 14:23:01 +03:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									        ->CreateRenderTargetView(m_color_attachment.Get(), &rtvDesc, &m_render_target_view));
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-11 14:05:59 +03:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									dxc(m_context->get_device()->CreateShaderResourceView(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									    m_color_attachment.Get(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									    &srvDesc,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									    &m_shader_resource_view
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									));
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-05 13:28:41 +03:30
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-07-11 00:05:48 +03:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								} // namespace lt
							 |