diff --git a/MG/MG_GL/Implementations/EGL/Diligent/EGL_impl.cpp b/MG/MG_GL/Implementations/EGL/Diligent/EGL_impl.cpp index 23dde847..0b36c447 100644 --- a/MG/MG_GL/Implementations/EGL/Diligent/EGL_impl.cpp +++ b/MG/MG_GL/Implementations/EGL/Diligent/EGL_impl.cpp @@ -26,7 +26,7 @@ namespace MG_Diligent { MG_Global::unordered_map g_UniformBufferMap; Diligent::IBuffer* g_TriangleFanIndexBuffer = nullptr; GLuint g_NextResourceId = 0; - bool IsInRenderPass = false; +// bool IsInRenderPass = false; bool initialized = false; void BuildInputLayout(GLuint program, VertexArrayState& vaState, @@ -142,13 +142,13 @@ namespace MG_Diligent { } hash_combine(hash, fbInfo.ColorRTVs.size()); - if (!fbInfo.pRenderPass) { +// if (!fbInfo.pRenderPass) { for (const auto& rtv : fbInfo.ColorRTVs) { if (rtv) { hash_combine(hash, rtv->GetDesc().Format); } } - } +// } hash_combine(hash, fbInfo.DepthStencilFormat); auto& programObj = MG_State_T::programState->programs_[MG_State_T::programState->currentProgram_]; @@ -198,17 +198,18 @@ namespace MG_Diligent { PSOCreateInfo.GraphicsPipeline.InputLayout.LayoutElements = programInfo.inputLayout.data(); PSOCreateInfo.GraphicsPipeline.InputLayout.NumElements = programInfo.inputLayout.size(); - if (fbInfo.pRenderPass) { - PSOCreateInfo.GraphicsPipeline.pRenderPass = fbInfo.pRenderPass; - } else { - PSOCreateInfo.GraphicsPipeline.pRenderPass = g_FramebufferMap[0].pRenderPass; // Default render pass - } +// if (fbInfo.pRenderPass) { +// PSOCreateInfo.GraphicsPipeline.pRenderPass = fbInfo.pRenderPass; +// } else { +// PSOCreateInfo.GraphicsPipeline.pRenderPass = g_FramebufferMap[0].pRenderPass; // Default render pass +// } PSOCreateInfo.GraphicsPipeline.PrimitiveTopology = GLPrimitiveTopologyToDiligent(primitiveTopology); - if (fbInfo.pRenderPass) { - PSOCreateInfo.GraphicsPipeline.NumRenderTargets = 0; - } else { +// if (fbInfo.pRenderPass) { +// PSOCreateInfo.GraphicsPipeline.NumRenderTargets = 0; +// } else + { PSOCreateInfo.GraphicsPipeline.NumRenderTargets = fbInfo.ColorRTVs.size(); if (PSOCreateInfo.GraphicsPipeline.NumRenderTargets == 0) { PSOCreateInfo.GraphicsPipeline.NumRenderTargets = 1; @@ -225,7 +226,7 @@ namespace MG_Diligent { } } - PSOCreateInfo.GraphicsPipeline.DSVFormat = Diligent::TEX_FORMAT_UNKNOWN; + PSOCreateInfo.GraphicsPipeline.DSVFormat = fbInfo.DepthStencilFormat; Diligent::BlendStateDesc &blendDesc = PSOCreateInfo.GraphicsPipeline.BlendDesc; blendDesc.IndependentBlendEnable = false; @@ -245,7 +246,7 @@ namespace MG_Diligent { (commonState.colorMask[3] ? Diligent::COLOR_MASK_ALPHA : 0)); MG_Util::Debug::LogD("Configured Blend State:"); - MG_Util::Debug::LogD(" Using explicit render pass: %s", fbInfo.pRenderPass ? "true" : "false"); +// MG_Util::Debug::LogD(" Using explicit render pass: %s", fbInfo.pRenderPass ? "true" : "false"); MG_Util::Debug::LogD(" NumRenderTargets: %u", PSOCreateInfo.GraphicsPipeline.NumRenderTargets); MG_Util::Debug::LogD(" IndependentBlendEnable: %s", blendDesc.IndependentBlendEnable ? "true" : "false"); MG_Util::Debug::LogD(" RenderTargets[0].BlendEnable: %s", blendDesc.RenderTargets[0].BlendEnable ? "true" : "false"); @@ -804,13 +805,13 @@ namespace MG_EGL::Diligent { RPDesc.SubpassCount = 1; RPDesc.pSubpasses = Subpasses; - MG_Util::Debug::LogD("Creating default render pass"); - MG_Diligent::g_pDevice->CreateRenderPass(RPDesc, &MG_Diligent::g_FramebufferMap[0].pRenderPass); - if (MG_Diligent::g_FramebufferMap[0].pRenderPass) { - MG_Util::Debug::LogD("Default render pass created: %p", MG_Diligent::g_FramebufferMap[0].pRenderPass); - } else { - MG_Util::Debug::LogE("Failed to create default render pass"); - } +// MG_Util::Debug::LogD("Creating default render pass"); +// MG_Diligent::g_pDevice->CreateRenderPass(RPDesc, &MG_Diligent::g_FramebufferMap[0].pRenderPass); +// if (MG_Diligent::g_FramebufferMap[0].pRenderPass) { +// MG_Util::Debug::LogD("Default render pass created: %p", MG_Diligent::g_FramebufferMap[0].pRenderPass); +// } else { +// MG_Util::Debug::LogE("Failed to create default render pass"); +// } } EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, NativeWindowType window, @@ -896,34 +897,34 @@ namespace MG_EGL::Diligent { EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface draw) { MG_Util::Debug::LogD("Flushing context"); - if (MG_Diligent::IsInRenderPass) { - MG_Util::Debug::LogD("Ending current render pass."); - MG_Diligent::g_pContext->EndRenderPass(); - MG_Diligent::IsInRenderPass = false; - MG_Util::Debug::LogD("Current render pass ended."); - } else { - MG_Util::Debug::LogD("No active render pass to end."); - } +// if (MG_Diligent::IsInRenderPass) { +// MG_Util::Debug::LogD("Ending current render pass."); +// MG_Diligent::g_pContext->EndRenderPass(); +// MG_Diligent::IsInRenderPass = false; +// MG_Util::Debug::LogD("Current render pass ended."); +// } else { +// MG_Util::Debug::LogD("No active render pass to end."); +// } MG_Diligent::g_pContext->Flush(); MG_Util::Debug::LogD("Presenting swap chain"); MG_Diligent::g_pSwapChain->Present(); MG_GL::GL::UpdateDefaultFramebuffer(); - if (MG_Diligent::IsInRenderPass) { - MG_Util::Debug::LogD("Ending current render pass."); - MG_Diligent::g_pContext->EndRenderPass(); - MG_Diligent::IsInRenderPass = false; - MG_Util::Debug::LogD("Current render pass ended."); - } else { - MG_Util::Debug::LogD("No active render pass to end."); - } +// if (MG_Diligent::IsInRenderPass) { +// MG_Util::Debug::LogD("Ending current render pass."); +// MG_Diligent::g_pContext->EndRenderPass(); +// MG_Diligent::IsInRenderPass = false; +// MG_Util::Debug::LogD("Current render pass ended."); +// } else { +// MG_Util::Debug::LogD("No active render pass to end."); +// } MG_Diligent::g_pContext->Flush(); MG_Util::Debug::LogD("Finishing frame"); MG_Diligent::g_pContext->FinishFrame(); auto& fbInfo = MG_Diligent::g_FramebufferMap[0]; - if (fbInfo.pRenderPass && fbInfo.pFramebuffer) { +// if (/*fbInfo.pRenderPass &&*/ fbInfo.pFramebuffer) { MG_Util::Debug::LogD("Setting render targets: %zu color attachments", fbInfo.ColorRTVs.size()); MG_Diligent::g_pContext->SetRenderTargets( static_cast(fbInfo.ColorRTVs.size()), @@ -942,14 +943,14 @@ namespace MG_EGL::Diligent { DefaultClearValues[1].DepthStencil.Depth = 1.0f; DefaultClearValues[1].DepthStencil.Stencil = 0; - MG_Util::Debug::LogD("Beginning render pass: pass=%p, fb=%p", fbInfo.pRenderPass, fbInfo.pFramebuffer); - MG_Diligent::g_pContext->BeginRenderPass( - ::Diligent::BeginRenderPassAttribs{ fbInfo.pRenderPass, fbInfo.pFramebuffer, - 2, DefaultClearValues, - ::Diligent::RESOURCE_STATE_TRANSITION_MODE_TRANSITION} - ); - MG_Diligent::IsInRenderPass = true; - } +// MG_Util::Debug::LogD("Beginning render pass: pass=%p, fb=%p", fbInfo.pRenderPass, fbInfo.pFramebuffer); +// MG_Diligent::g_pContext->BeginRenderPass( +// ::Diligent::BeginRenderPassAttribs{ fbInfo.pRenderPass, fbInfo.pFramebuffer, +// 2, DefaultClearValues, +// ::Diligent::RESOURCE_STATE_TRANSITION_MODE_TRANSITION} +// ); +// MG_Diligent::IsInRenderPass = true; +// } // const auto& SCDesc = MG_Diligent::g_pSwapChain->GetDesc(); // MG_Util::Debug::LogD("Setting viewport: width=%d, height=%d", SCDesc.Width, SCDesc.Height); diff --git a/MG/MG_GL/Implementations/EGL/Diligent/EGL_impl.h b/MG/MG_GL/Implementations/EGL/Diligent/EGL_impl.h index 2fc06fd7..7b78513d 100644 --- a/MG/MG_GL/Implementations/EGL/Diligent/EGL_impl.h +++ b/MG/MG_GL/Implementations/EGL/Diligent/EGL_impl.h @@ -19,8 +19,8 @@ namespace MG_Diligent { struct GLFramebufferInfo { - Diligent::IFramebuffer* pFramebuffer = nullptr; - Diligent::IRenderPass* pRenderPass = nullptr; +// Diligent::IFramebuffer* pFramebuffer = nullptr; +// Diligent::IRenderPass* pRenderPass = nullptr; std::vector ColorRTVs; Diligent::ITextureView* pDepthStencilRTV = nullptr; Diligent::TEXTURE_FORMAT DepthStencilFormat = Diligent::TEX_FORMAT_UNKNOWN; @@ -231,7 +231,7 @@ namespace MG_Diligent { std::vector& inputLayout); extern bool initialized; - extern bool IsInRenderPass; +// extern bool IsInRenderPass; extern GLuint g_NextResourceId; } diff --git a/MG/MG_GL/Implementations/GL/Common/GL_Common.cpp b/MG/MG_GL/Implementations/GL/Common/GL_Common.cpp index 8607da02..a9ea46e0 100644 --- a/MG/MG_GL/Implementations/GL/Common/GL_Common.cpp +++ b/MG/MG_GL/Implementations/GL/Common/GL_Common.cpp @@ -24,27 +24,27 @@ namespace MG_GL::GL { MG_Diligent::GLFramebufferInfo& fbInfo = it->second; auto& commonState = *MG_State_T::commonState; - if (MG_Diligent::IsInRenderPass) { - MG_Util::Debug::LogD("Ending render pass before clear operation"); - MG_Diligent::g_pContext->EndRenderPass(); - MG_Diligent::IsInRenderPass = false; - } +// if (MG_Diligent::IsInRenderPass) { +// MG_Util::Debug::LogD("Ending render pass before clear operation"); +// MG_Diligent::g_pContext->EndRenderPass(); +// MG_Diligent::IsInRenderPass = false; +// } - MG_Util::Debug::LogD("Beginning render pass for clear operation"); +// MG_Util::Debug::LogD("Beginning render pass for clear operation"); - if (!fbInfo.pRenderPass) { - MG_GL::GL::CreateRenderPassAndFramebuffer(drawFramebuffer, - *MG_State_T::framebufferState->GetCurrentFBO(GL_DRAW_FRAMEBUFFER), fbInfo); - } - Diligent::BeginRenderPassAttribs beginAttribs; - beginAttribs.pRenderPass = fbInfo.pRenderPass; - beginAttribs.pFramebuffer = fbInfo.pFramebuffer; - beginAttribs.StateTransitionMode = Diligent::RESOURCE_STATE_TRANSITION_MODE_TRANSITION; - beginAttribs.ClearValueCount = 0; - beginAttribs.pClearValues = nullptr; +// if (!fbInfo.pRenderPass) { +// MG_GL::GL::CreateRenderPassAndFramebuffer(drawFramebuffer, +// *MG_State_T::framebufferState->GetCurrentFBO(GL_DRAW_FRAMEBUFFER), fbInfo); +// } +// Diligent::BeginRenderPassAttribs beginAttribs; +// beginAttribs.pRenderPass = fbInfo.pRenderPass; +// beginAttribs.pFramebuffer = fbInfo.pFramebuffer; +// beginAttribs.StateTransitionMode = Diligent::RESOURCE_STATE_TRANSITION_MODE_TRANSITION; +// beginAttribs.ClearValueCount = 0; +// beginAttribs.pClearValues = nullptr; - MG_Diligent::g_pContext->BeginRenderPass(beginAttribs); - MG_Diligent::IsInRenderPass = true; +// MG_Diligent::g_pContext->BeginRenderPass(beginAttribs); +// MG_Diligent::IsInRenderPass = true; if (mask & GL_COLOR_BUFFER_BIT) { for (size_t i = 0; i < fbInfo.ColorRTVs.size(); ++i) { @@ -76,9 +76,9 @@ namespace MG_GL::GL { } } - MG_Util::Debug::LogD("Ending render pass after clear operation"); - MG_Diligent::g_pContext->EndRenderPass(); - MG_Diligent::IsInRenderPass = false; +// MG_Util::Debug::LogD("Ending render pass after clear operation"); +// MG_Diligent::g_pContext->EndRenderPass(); +// MG_Diligent::IsInRenderPass = false; } void Enable(GLenum cap) { diff --git a/MG/MG_GL/Implementations/GL/Drawing/GL_Drawing.cpp b/MG/MG_GL/Implementations/GL/Drawing/GL_Drawing.cpp index d5297a0e..e06f2f55 100644 --- a/MG/MG_GL/Implementations/GL/Drawing/GL_Drawing.cpp +++ b/MG/MG_GL/Implementations/GL/Drawing/GL_Drawing.cpp @@ -5,9 +5,9 @@ #include "GL_Drawing.h" namespace MG_GL::GL { - void CreateRenderPassAndFramebuffer(GLuint framebuffer, - const FramebufferObject& fbo, - MG_Diligent::GLFramebufferInfo& fbInfo); +// void CreateRenderPassAndFramebuffer(GLuint framebuffer, +// const FramebufferObject& fbo, +// MG_Diligent::GLFramebufferInfo& fbInfo); bool IsSamplerType(GLenum type) { switch (type) { @@ -357,59 +357,59 @@ namespace MG_GL::GL { } } - void EnsureRenderPassActive() { - MG_Util::Debug::LogD("EnsureRenderPassActive called."); - if (MG_Diligent::IsInRenderPass) { - MG_Util::Debug::LogD("Render pass is already active."); - return; - } - - MG_Util::Debug::LogD("Render pass is not active, attempting to begin one."); - GLuint drawFB = MG_State_T::framebufferState->currentBindings_[GL_DRAW_FRAMEBUFFER]; - if (drawFB == 0) { - MG_Util::Debug::LogD("drawFB is 0, using default framebuffer (0)."); - drawFB = 0; - } - - auto it = MG_Diligent::g_FramebufferMap.find(drawFB); - if (it == MG_Diligent::g_FramebufferMap.end()) { - MG_Util::Debug::LogE("Framebuffer %u not found in g_FramebufferMap.", drawFB); - return; - } - - MG_Util::Debug::LogD("Found framebuffer %u in g_FramebufferMap.", drawFB); - MG_Diligent::GLFramebufferInfo& fbInfo = it->second; - - if (!fbInfo.pRenderPass || !fbInfo.pFramebuffer) { - MG_Util::Debug::LogD("RenderPass or Framebuffer not yet created for FBO %u. Creating now.", drawFB); - FramebufferObject* pFBO = MG_State_T::framebufferState->GetCurrentFBO(GL_DRAW_FRAMEBUFFER); - if (!pFBO) { - MG_Util::Debug::LogE("No current FBO found for GL_DRAW_FRAMEBUFFER when trying to create RenderPass/Framebuffer."); - return; - } - CreateRenderPassAndFramebuffer(drawFB, *pFBO, fbInfo); - if (!fbInfo.pRenderPass || !fbInfo.pFramebuffer) { - MG_Util::Debug::LogE("Failed to create RenderPass or Framebuffer for FBO %u.", drawFB); - return; - } - MG_Util::Debug::LogD("Successfully created RenderPass and Framebuffer for FBO %u.", drawFB); - } - - MG_Util::Debug::LogD("Proceeding to begin render pass for FBO %u.", drawFB); - if (fbInfo.pRenderPass && fbInfo.pFramebuffer) { - Diligent::BeginRenderPassAttribs beginRenderPassAttribs; - beginRenderPassAttribs.pFramebuffer = fbInfo.pFramebuffer; - beginRenderPassAttribs.pRenderPass = fbInfo.pRenderPass; - beginRenderPassAttribs.StateTransitionMode = Diligent::RESOURCE_STATE_TRANSITION_MODE_TRANSITION; - beginRenderPassAttribs.ClearValueCount = fbInfo.ClearValues.size(); - beginRenderPassAttribs.pClearValues = fbInfo.ClearValues.data(); - - MG_Diligent::g_pContext->BeginRenderPass(beginRenderPassAttribs); - MG_Diligent::IsInRenderPass = true; - } else { - MG_Util::Debug::LogE("RenderPass or Framebuffer not yet created for FBO %u.", drawFB); - } - } +// void EnsureRenderPassActive() { +// MG_Util::Debug::LogD("EnsureRenderPassActive called."); +// if (MG_Diligent::IsInRenderPass) { +// MG_Util::Debug::LogD("Render pass is already active."); +// return; +// } +// +// MG_Util::Debug::LogD("Render pass is not active, attempting to begin one."); +// GLuint drawFB = MG_State_T::framebufferState->currentBindings_[GL_DRAW_FRAMEBUFFER]; +// if (drawFB == 0) { +// MG_Util::Debug::LogD("drawFB is 0, using default framebuffer (0)."); +// drawFB = 0; +// } +// +// auto it = MG_Diligent::g_FramebufferMap.find(drawFB); +// if (it == MG_Diligent::g_FramebufferMap.end()) { +// MG_Util::Debug::LogE("Framebuffer %u not found in g_FramebufferMap.", drawFB); +// return; +// } +// +// MG_Util::Debug::LogD("Found framebuffer %u in g_FramebufferMap.", drawFB); +// MG_Diligent::GLFramebufferInfo& fbInfo = it->second; +// +// if (!fbInfo.pRenderPass || !fbInfo.pFramebuffer) { +// MG_Util::Debug::LogD("RenderPass or Framebuffer not yet created for FBO %u. Creating now.", drawFB); +// FramebufferObject* pFBO = MG_State_T::framebufferState->GetCurrentFBO(GL_DRAW_FRAMEBUFFER); +// if (!pFBO) { +// MG_Util::Debug::LogE("No current FBO found for GL_DRAW_FRAMEBUFFER when trying to create RenderPass/Framebuffer."); +// return; +// } +// CreateRenderPassAndFramebuffer(drawFB, *pFBO, fbInfo); +// if (!fbInfo.pRenderPass || !fbInfo.pFramebuffer) { +// MG_Util::Debug::LogE("Failed to create RenderPass or Framebuffer for FBO %u.", drawFB); +// return; +// } +// MG_Util::Debug::LogD("Successfully created RenderPass and Framebuffer for FBO %u.", drawFB); +// } +// +// MG_Util::Debug::LogD("Proceeding to begin render pass for FBO %u.", drawFB); +// if (fbInfo.pRenderPass && fbInfo.pFramebuffer) { +// Diligent::BeginRenderPassAttribs beginRenderPassAttribs; +// beginRenderPassAttribs.pFramebuffer = fbInfo.pFramebuffer; +// beginRenderPassAttribs.pRenderPass = fbInfo.pRenderPass; +// beginRenderPassAttribs.StateTransitionMode = Diligent::RESOURCE_STATE_TRANSITION_MODE_TRANSITION; +// beginRenderPassAttribs.ClearValueCount = fbInfo.ClearValues.size(); +// beginRenderPassAttribs.pClearValues = fbInfo.ClearValues.data(); +// +// MG_Diligent::g_pContext->BeginRenderPass(beginRenderPassAttribs); +// MG_Diligent::IsInRenderPass = true; +// } else { +// MG_Util::Debug::LogE("RenderPass or Framebuffer not yet created for FBO %u.", drawFB); +// } +// } template void generate_triangle_fan_indices(std::vector& out_data, const void* in_indices, size_t count) { @@ -427,14 +427,14 @@ namespace MG_GL::GL { } void PrepareForDraw(GLenum mode, GLsizei* pCount, GLenum type, const void*& pIndices) { - if (MG_Diligent::IsInRenderPass) { - MG_Util::Debug::LogD("Ending current render pass."); - MG_Diligent::g_pContext->EndRenderPass(); - MG_Diligent::IsInRenderPass = false; - MG_Util::Debug::LogD("Current render pass ended."); - } else { - MG_Util::Debug::LogD("No active render pass to end."); - } +// if (MG_Diligent::IsInRenderPass) { +// MG_Util::Debug::LogD("Ending current render pass."); +// MG_Diligent::g_pContext->EndRenderPass(); +// MG_Diligent::IsInRenderPass = false; +// MG_Util::Debug::LogD("Current render pass ended."); +// } else { +// MG_Util::Debug::LogD("No active render pass to end."); +// } GLuint program = MG_State::GetCurrentProgram(); if (program == 0) { @@ -728,10 +728,10 @@ namespace MG_GL::GL { MG_Util::Debug::LogD(" FirstIndexLocation: %u", drawAttrs.FirstIndexLocation); MG_Util::Debug::LogD(" FirstInstanceLocation: %u", drawAttrs.FirstInstanceLocation); - EnsureRenderPassActive(); +// EnsureRenderPassActive(); MG_Diligent::g_pContext->DrawIndexed(drawAttrs); - MG_Diligent::g_pContext->EndRenderPass(); - MG_Diligent::IsInRenderPass = false; +// MG_Diligent::g_pContext->EndRenderPass(); +// MG_Diligent::IsInRenderPass = false; MG_Util::Debug::LogD("DrawIndexed completed."); } @@ -769,10 +769,10 @@ namespace MG_GL::GL { MG_Util::Debug::LogD(" FirstIndexLocation: %u", drawAttrs.FirstIndexLocation); MG_Util::Debug::LogD(" FirstInstanceLocation: %u", drawAttrs.FirstInstanceLocation); - EnsureRenderPassActive(); +// EnsureRenderPassActive(); MG_Diligent::g_pContext->DrawIndexed(drawAttrs); - MG_Diligent::g_pContext->EndRenderPass(); - MG_Diligent::IsInRenderPass = false; +// MG_Diligent::g_pContext->EndRenderPass(); +// MG_Diligent::IsInRenderPass = false; MG_Util::Debug::LogD("DrawIndexed (BaseVertex) completed."); } @@ -998,10 +998,10 @@ namespace MG_GL::GL { MG_Util::Debug::LogD(" BaseVertex: %d", item.BaseVertex); } - EnsureRenderPassActive(); +// EnsureRenderPassActive(); MG_Diligent::g_pContext->MultiDrawIndexed(drawAttrs); - MG_Diligent::g_pContext->EndRenderPass(); - MG_Diligent::IsInRenderPass = false; +// MG_Diligent::g_pContext->EndRenderPass(); +// MG_Diligent::IsInRenderPass = false; MG_Util::Debug::LogD("MultiDrawIndexed completed."); } diff --git a/MG/MG_GL/Implementations/GL/Framebuffer/GL_Framebuffer.cpp b/MG/MG_GL/Implementations/GL/Framebuffer/GL_Framebuffer.cpp index afbba3d7..db2a438f 100644 --- a/MG/MG_GL/Implementations/GL/Framebuffer/GL_Framebuffer.cpp +++ b/MG/MG_GL/Implementations/GL/Framebuffer/GL_Framebuffer.cpp @@ -6,15 +6,15 @@ namespace MG_GL::GL { void ReleaseFramebufferResources(MG_Diligent::GLFramebufferInfo& fbInfo) { - if (fbInfo.pFramebuffer) { - fbInfo.pFramebuffer->Release(); - fbInfo.pFramebuffer = nullptr; - } +// if (fbInfo.pFramebuffer) { +// fbInfo.pFramebuffer->Release(); +// fbInfo.pFramebuffer = nullptr; +// } - if (fbInfo.pRenderPass) { - fbInfo.pRenderPass->Release(); - fbInfo.pRenderPass = nullptr; - } +// if (fbInfo.pRenderPass) { +// fbInfo.pRenderPass->Release(); +// fbInfo.pRenderPass = nullptr; +// } } void CreateRenderPassAndFramebuffer(GLuint framebuffer, @@ -52,115 +52,115 @@ namespace MG_GL::GL { return; } - Diligent::RenderPassDesc RPDesc; - std::vector Attachments; - std::vector Subpasses; - std::vector ColorRefs; +// Diligent::RenderPassDesc RPDesc; +// std::vector Attachments; +// std::vector Subpasses; +// std::vector ColorRefs; +// +// for (size_t i = 0; i < fbInfo.ColorRTVs.size(); ++i) { +// if (fbInfo.ColorRTVs[i]) { +// Diligent::RenderPassAttachmentDesc ColorAttachment; +// ColorAttachment.Format = framebuffer != 0 ? fbInfo.ColorRTVs[i]->GetDesc().Format: +// MG_Diligent::g_pSwapChain->GetDesc().ColorBufferFormat; +// ColorAttachment.SampleCount = 1; +// ColorAttachment.InitialState = Diligent::RESOURCE_STATE_RENDER_TARGET; +// ColorAttachment.FinalState = Diligent::RESOURCE_STATE_RENDER_TARGET; +// ColorAttachment.LoadOp = Diligent::ATTACHMENT_LOAD_OP_LOAD; +// ColorAttachment.StoreOp = Diligent::ATTACHMENT_STORE_OP_STORE; +// Attachments.push_back(ColorAttachment); +// +// Diligent::AttachmentReference ColorRef; +// ColorRef.AttachmentIndex = static_cast(Attachments.size() - 1); +// ColorRef.State = Diligent::RESOURCE_STATE_RENDER_TARGET; +// ColorRefs.push_back(ColorRef); +// MG_Util::Debug::LogD("CreateRenderPassAndFramebuffer: Added color attachment %zu", i); +// } +// } - for (size_t i = 0; i < fbInfo.ColorRTVs.size(); ++i) { - if (fbInfo.ColorRTVs[i]) { - Diligent::RenderPassAttachmentDesc ColorAttachment; - ColorAttachment.Format = framebuffer != 0 ? fbInfo.ColorRTVs[i]->GetDesc().Format: - MG_Diligent::g_pSwapChain->GetDesc().ColorBufferFormat; - ColorAttachment.SampleCount = 1; - ColorAttachment.InitialState = Diligent::RESOURCE_STATE_RENDER_TARGET; - ColorAttachment.FinalState = Diligent::RESOURCE_STATE_RENDER_TARGET; - ColorAttachment.LoadOp = Diligent::ATTACHMENT_LOAD_OP_LOAD; - ColorAttachment.StoreOp = Diligent::ATTACHMENT_STORE_OP_STORE; - Attachments.push_back(ColorAttachment); +// Diligent::AttachmentReference DepthRef; +// if (fbInfo.pDepthStencilRTV) { +// Diligent::RenderPassAttachmentDesc DepthAttachment; +// DepthAttachment.Format = fbInfo.DepthStencilFormat; +// DepthAttachment.SampleCount = 1; +// DepthAttachment.InitialState = Diligent::RESOURCE_STATE_DEPTH_WRITE; +// DepthAttachment.FinalState = Diligent::RESOURCE_STATE_DEPTH_WRITE; +// DepthAttachment.LoadOp = Diligent::ATTACHMENT_LOAD_OP_LOAD; +// DepthAttachment.StoreOp = Diligent::ATTACHMENT_STORE_OP_STORE; +// DepthAttachment.StencilLoadOp = Diligent::ATTACHMENT_LOAD_OP_LOAD; +// DepthAttachment.StencilStoreOp = Diligent::ATTACHMENT_STORE_OP_STORE; +// Attachments.push_back(DepthAttachment); +// +// DepthRef.AttachmentIndex = static_cast(Attachments.size() - 1); +// DepthRef.State = Diligent::RESOURCE_STATE_DEPTH_WRITE; +// MG_Util::Debug::LogD("CreateRenderPassAndFramebuffer: Added depth/stencil attachment"); +// } - Diligent::AttachmentReference ColorRef; - ColorRef.AttachmentIndex = static_cast(Attachments.size() - 1); - ColorRef.State = Diligent::RESOURCE_STATE_RENDER_TARGET; - ColorRefs.push_back(ColorRef); - MG_Util::Debug::LogD("CreateRenderPassAndFramebuffer: Added color attachment %zu", i); - } - } +// Diligent::SubpassDesc Subpass; +// Subpass.RenderTargetAttachmentCount = static_cast(ColorRefs.size()); +// Subpass.pRenderTargetAttachments = ColorRefs.empty() ? nullptr : ColorRefs.data(); +// Subpass.pDepthStencilAttachment = fbInfo.pDepthStencilRTV ? &DepthRef : nullptr; +// Subpasses.push_back(Subpass); +// +// RPDesc.AttachmentCount = static_cast(Attachments.size()); +// RPDesc.pAttachments = Attachments.empty() ? nullptr : Attachments.data(); +// RPDesc.SubpassCount = static_cast(Subpasses.size()); +// RPDesc.pSubpasses = Subpasses.data(); +// +// MG_Util::Debug::LogD("CreateRenderPassAndFramebuffer: Creating RenderPass with %u attachments and %u subpasses.", +// RPDesc.AttachmentCount, RPDesc.SubpassCount); +// +// MG_Diligent::g_pDevice->CreateRenderPass(RPDesc, &fbInfo.pRenderPass); +// if (!fbInfo.pRenderPass) { +// MG_Util::Debug::LogE("CreateRenderPassAndFramebuffer: Failed to create RenderPass."); +// return; +// } +// MG_Util::Debug::LogD("CreateRenderPassAndFramebuffer: RenderPass created successfully."); - Diligent::AttachmentReference DepthRef; - if (fbInfo.pDepthStencilRTV) { - Diligent::RenderPassAttachmentDesc DepthAttachment; - DepthAttachment.Format = fbInfo.DepthStencilFormat; - DepthAttachment.SampleCount = 1; - DepthAttachment.InitialState = Diligent::RESOURCE_STATE_DEPTH_WRITE; - DepthAttachment.FinalState = Diligent::RESOURCE_STATE_DEPTH_WRITE; - DepthAttachment.LoadOp = Diligent::ATTACHMENT_LOAD_OP_LOAD; - DepthAttachment.StoreOp = Diligent::ATTACHMENT_STORE_OP_STORE; - DepthAttachment.StencilLoadOp = Diligent::ATTACHMENT_LOAD_OP_LOAD; - DepthAttachment.StencilStoreOp = Diligent::ATTACHMENT_STORE_OP_STORE; - Attachments.push_back(DepthAttachment); +// Diligent::FramebufferDesc FBDesc; +// FBDesc.Name = "Framebuffer"; +//// FBDesc.pRenderPass = fbInfo.pRenderPass; +// FBDesc.AttachmentCount = static_cast(Attachments.size()); +// +// std::vector FBAtachments(Attachments.size()); +// for (size_t i = 0; i < ColorRefs.size(); ++i) { +// if (i < fbInfo.ColorRTVs.size() && fbInfo.ColorRTVs[i]) { +// FBAtachments[i] = fbInfo.ColorRTVs[i]; +// } +// } +// +// if (fbInfo.pDepthStencilRTV) { +// FBAtachments[ColorRefs.size()] = fbInfo.pDepthStencilRTV; +// } - DepthRef.AttachmentIndex = static_cast(Attachments.size() - 1); - DepthRef.State = Diligent::RESOURCE_STATE_DEPTH_WRITE; - MG_Util::Debug::LogD("CreateRenderPassAndFramebuffer: Added depth/stencil attachment"); - } - - Diligent::SubpassDesc Subpass; - Subpass.RenderTargetAttachmentCount = static_cast(ColorRefs.size()); - Subpass.pRenderTargetAttachments = ColorRefs.empty() ? nullptr : ColorRefs.data(); - Subpass.pDepthStencilAttachment = fbInfo.pDepthStencilRTV ? &DepthRef : nullptr; - Subpasses.push_back(Subpass); - - RPDesc.AttachmentCount = static_cast(Attachments.size()); - RPDesc.pAttachments = Attachments.empty() ? nullptr : Attachments.data(); - RPDesc.SubpassCount = static_cast(Subpasses.size()); - RPDesc.pSubpasses = Subpasses.data(); - - MG_Util::Debug::LogD("CreateRenderPassAndFramebuffer: Creating RenderPass with %u attachments and %u subpasses.", - RPDesc.AttachmentCount, RPDesc.SubpassCount); - - MG_Diligent::g_pDevice->CreateRenderPass(RPDesc, &fbInfo.pRenderPass); - if (!fbInfo.pRenderPass) { - MG_Util::Debug::LogE("CreateRenderPassAndFramebuffer: Failed to create RenderPass."); - return; - } - MG_Util::Debug::LogD("CreateRenderPassAndFramebuffer: RenderPass created successfully."); - - Diligent::FramebufferDesc FBDesc; - FBDesc.Name = "Framebuffer"; - FBDesc.pRenderPass = fbInfo.pRenderPass; - FBDesc.AttachmentCount = static_cast(Attachments.size()); - - std::vector FBAtachments(Attachments.size()); - for (size_t i = 0; i < ColorRefs.size(); ++i) { - if (i < fbInfo.ColorRTVs.size() && fbInfo.ColorRTVs[i]) { - FBAtachments[i] = fbInfo.ColorRTVs[i]; - } - } - - if (fbInfo.pDepthStencilRTV) { - FBAtachments[ColorRefs.size()] = fbInfo.pDepthStencilRTV; - } - - FBDesc.ppAttachments = FBAtachments.data(); - FBDesc.Width = width; - FBDesc.Height = height; - FBDesc.NumArraySlices = 1; - - MG_Util::Debug::LogD("CreateRenderPassAndFramebuffer: FramebufferDesc Details:"); - MG_Util::Debug::LogD(" Name: %s", FBDesc.Name ? FBDesc.Name : "N/A"); - MG_Util::Debug::LogD(" pRenderPass: %p", FBDesc.pRenderPass); - MG_Util::Debug::LogD(" AttachmentCount: %u", FBDesc.AttachmentCount); - for (Diligent::Uint32 i = 0; i < FBDesc.AttachmentCount; ++i) { - if (FBDesc.ppAttachments && FBDesc.ppAttachments[i]) { - Diligent::ITexture* pTexture = FBDesc.ppAttachments[i]->GetTexture(); - if (pTexture) { - const auto& texDesc = pTexture->GetDesc(); - MG_Util::Debug::LogD(" Attachment %u: Texture '%s', Dim: %ux%u", - i, texDesc.Name ? texDesc.Name : "N/A", texDesc.Width, texDesc.Height); - } else { - MG_Util::Debug::LogW(" Attachment %u: TextureView's texture is nullptr", i); - } - } else if (!FBDesc.ppAttachments) { - MG_Util::Debug::LogW(" FBDesc.ppAttachments is nullptr. Cannot access attachment %u.", i); - } else { - MG_Util::Debug::LogD(" Attachment %u: nullptr", i); - } - } - MG_Util::Debug::LogD(" Width: %u", FBDesc.Width); - MG_Util::Debug::LogD(" Height: %u", FBDesc.Height); - MG_Util::Debug::LogD(" NumArraySlices: %u", FBDesc.NumArraySlices); - MG_Util::Debug::LogD(" fbInfo.pFramebuffer: %p", fbInfo.pFramebuffer); +// FBDesc.ppAttachments = FBAtachments.data(); +// FBDesc.Width = width; +// FBDesc.Height = height; +// FBDesc.NumArraySlices = 1; +// +// MG_Util::Debug::LogD("CreateRenderPassAndFramebuffer: FramebufferDesc Details:"); +// MG_Util::Debug::LogD(" Name: %s", FBDesc.Name ? FBDesc.Name : "N/A"); +// MG_Util::Debug::LogD(" pRenderPass: %p", FBDesc.pRenderPass); +// MG_Util::Debug::LogD(" AttachmentCount: %u", FBDesc.AttachmentCount); +// for (Diligent::Uint32 i = 0; i < FBDesc.AttachmentCount; ++i) { +// if (FBDesc.ppAttachments && FBDesc.ppAttachments[i]) { +// Diligent::ITexture* pTexture = FBDesc.ppAttachments[i]->GetTexture(); +// if (pTexture) { +// const auto& texDesc = pTexture->GetDesc(); +// MG_Util::Debug::LogD(" Attachment %u: Texture '%s', Dim: %ux%u", +// i, texDesc.Name ? texDesc.Name : "N/A", texDesc.Width, texDesc.Height); +// } else { +// MG_Util::Debug::LogW(" Attachment %u: TextureView's texture is nullptr", i); +// } +// } else if (!FBDesc.ppAttachments) { +// MG_Util::Debug::LogW(" FBDesc.ppAttachments is nullptr. Cannot access attachment %u.", i); +// } else { +// MG_Util::Debug::LogD(" Attachment %u: nullptr", i); +// } +// } +// MG_Util::Debug::LogD(" Width: %u", FBDesc.Width); +// MG_Util::Debug::LogD(" Height: %u", FBDesc.Height); +// MG_Util::Debug::LogD(" NumArraySlices: %u", FBDesc.NumArraySlices); +// MG_Util::Debug::LogD(" fbInfo.pFramebuffer: %p", fbInfo.pFramebuffer); fbInfo.ClearValues.clear(); for (size_t i = 0; i < fbInfo.ColorRTVs.size(); ++i) { @@ -179,12 +179,12 @@ namespace MG_GL::GL { fbInfo.ClearValues.push_back(clearValue); } - MG_Diligent::g_pDevice->CreateFramebuffer(FBDesc, &fbInfo.pFramebuffer); - if (!fbInfo.pFramebuffer) { - MG_Util::Debug::LogE("CreateRenderPassAndFramebuffer: Failed to create Framebuffer."); - return; - } - MG_Util::Debug::LogD("CreateRenderPassAndFramebuffer: Framebuffer created successfully."); +// MG_Diligent::g_pDevice->CreateFramebuffer(FBDesc, &fbInfo.pFramebuffer); +// if (!fbInfo.pFramebuffer) { +// MG_Util::Debug::LogE("CreateRenderPassAndFramebuffer: Failed to create Framebuffer."); +// return; +// } +// MG_Util::Debug::LogD("CreateRenderPassAndFramebuffer: Framebuffer created successfully."); } void UpdateDefaultFramebuffer() { @@ -249,13 +249,13 @@ namespace MG_GL::GL { if (it != MG_Diligent::g_FramebufferMap.end()) { MG_Diligent::GLFramebufferInfo& fbInfo = it->second; - if (fbInfo.pFramebuffer) { - fbInfo.pFramebuffer->Release(); - } +// if (fbInfo.pFramebuffer) { +// fbInfo.pFramebuffer->Release(); +// } - if (fbInfo.pRenderPass) { - fbInfo.pRenderPass->Release(); - } +// if (fbInfo.pRenderPass) { +// fbInfo.pRenderPass->Release(); +// } for (auto& rtv : fbInfo.ColorRTVs) { if (rtv) rtv->Release(); @@ -279,14 +279,14 @@ namespace MG_GL::GL { if (result == GL_NO_ERROR) { MG_Util::Debug::LogD("BindFramebuffer: MG_State::BindFramebuffer successful."); - if (MG_Diligent::IsInRenderPass) { - MG_Util::Debug::LogD("BindFramebuffer: Ending current render pass."); - MG_Diligent::g_pContext->EndRenderPass(); - MG_Diligent::IsInRenderPass = false; - MG_Util::Debug::LogD("BindFramebuffer: Current render pass ended."); - } else { - MG_Util::Debug::LogD("BindFramebuffer: No active render pass to end."); - } +// if (MG_Diligent::IsInRenderPass) { +// MG_Util::Debug::LogD("BindFramebuffer: Ending current render pass."); +// MG_Diligent::g_pContext->EndRenderPass(); +// MG_Diligent::IsInRenderPass = false; +// MG_Util::Debug::LogD("BindFramebuffer: Current render pass ended."); +// } else { +// MG_Util::Debug::LogD("BindFramebuffer: No active render pass to end."); +// } if (framebuffer == 0) { @@ -309,13 +309,13 @@ namespace MG_GL::GL { MG_Diligent::GLFramebufferInfo& fbInfo = it->second; - if (!fbInfo.pRenderPass || !fbInfo.pFramebuffer) { - MG_Util::Debug::LogD("BindFramebuffer: RenderPass or Framebuffer not yet created for framebuffer %u. Creating now.", framebuffer); - CreateRenderPassAndFramebuffer(framebuffer, pFBO ? *pFBO : FramebufferObject(), fbInfo); - MG_Util::Debug::LogD("BindFramebuffer: RenderPass and Framebuffer creation attempted for framebuffer %u.", framebuffer); - } else { - MG_Util::Debug::LogD("BindFramebuffer: RenderPass and Framebuffer already exist for framebuffer %u.", framebuffer); - } +// if (/*!fbInfo.pRenderPass || */!fbInfo.pFramebuffer) { +// MG_Util::Debug::LogD("BindFramebuffer: RenderPass or Framebuffer not yet created for framebuffer %u. Creating now.", framebuffer); +// CreateRenderPassAndFramebuffer(framebuffer, pFBO ? *pFBO : FramebufferObject(), fbInfo); +// MG_Util::Debug::LogD("BindFramebuffer: RenderPass and Framebuffer creation attempted for framebuffer %u.", framebuffer); +// } else { +// MG_Util::Debug::LogD("BindFramebuffer: RenderPass and Framebuffer already exist for framebuffer %u.", framebuffer); +// } MG_Util::Debug::LogD("BindFramebuffer: Setting render targets. ColorRTVs count: %zu, DepthStencilRTV: %p", fbInfo.ColorRTVs.size(), fbInfo.pDepthStencilRTV); @@ -342,16 +342,16 @@ namespace MG_GL::GL { MG_Diligent::GLFramebufferInfo& fbInfo = it->second; - if (fbInfo.pFramebuffer) { - fbInfo.pFramebuffer->Release(); - fbInfo.pFramebuffer = nullptr; - MG_Util::Debug::LogD("Released existing framebuffer"); - } - if (fbInfo.pRenderPass) { - fbInfo.pRenderPass->Release(); - fbInfo.pRenderPass = nullptr; - MG_Util::Debug::LogD("Released existing render pass"); - } +// if (fbInfo.pFramebuffer) { +// fbInfo.pFramebuffer->Release(); +// fbInfo.pFramebuffer = nullptr; +// MG_Util::Debug::LogD("Released existing framebuffer"); +// } +// if (fbInfo.pRenderPass) { +// fbInfo.pRenderPass->Release(); +// fbInfo.pRenderPass = nullptr; +// MG_Util::Debug::LogD("Released existing render pass"); +// } if (texture == 0) { MG_Util::Debug::LogD("Unbinding attachment: %s", MG_Util::Debug::GLEnumToString(attachment)); @@ -515,12 +515,12 @@ namespace MG_GL::GL { void BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter) { - if (MG_Diligent::IsInRenderPass) { - MG_Util::Debug::LogD("Ending current render pass."); - MG_Diligent::g_pContext->EndRenderPass(); - MG_Diligent::IsInRenderPass = false; - MG_Util::Debug::LogD("Current render pass ended."); - } +// if (MG_Diligent::IsInRenderPass) { +// MG_Util::Debug::LogD("Ending current render pass."); +// MG_Diligent::g_pContext->EndRenderPass(); +// MG_Diligent::IsInRenderPass = false; +// MG_Util::Debug::LogD("Current render pass ended."); +// } GLuint readFB = MG_State_T::framebufferState->currentBindings_[GL_READ_FRAMEBUFFER]; GLuint drawFB = MG_State_T::framebufferState->currentBindings_[GL_DRAW_FRAMEBUFFER]; diff --git a/MG/MG_GL/Implementations/GL/Texture/GL_Texture.cpp b/MG/MG_GL/Implementations/GL/Texture/GL_Texture.cpp index 8852700f..b232446e 100644 --- a/MG/MG_GL/Implementations/GL/Texture/GL_Texture.cpp +++ b/MG/MG_GL/Implementations/GL/Texture/GL_Texture.cpp @@ -648,10 +648,10 @@ namespace MG_GL::GL { MG_Util::Debug::LogD("TexSubImage2D: Updating region [%d,%d]-[%d,%d] at level %d, %d bytes", xoffset, yoffset, xoffset+width, yoffset+height, level, width * height * GetBytesPerPixel(format, type)); - if (MG_Diligent::IsInRenderPass) { - MG_Diligent::g_pContext->EndRenderPass(); - MG_Diligent::IsInRenderPass = false; - } +// if (MG_Diligent::IsInRenderPass) { +// MG_Diligent::g_pContext->EndRenderPass(); +// MG_Diligent::IsInRenderPass = false; +// } MG_Diligent::g_pContext->UpdateTexture( pTexture,