[Fix] (DiligentEngine): Fix some miscellaneous issues.

This commit is contained in:
BZLZHH
2025-06-08 01:57:13 +08:00
parent 979d31407f
commit 848f110658
3 changed files with 45 additions and 12 deletions
@@ -64,6 +64,7 @@ namespace MG_Diligent {
PSOCreateInfo.GraphicsPipeline.PrimitiveTopology = Diligent::PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
/*
PSOCreateInfo.GraphicsPipeline.NumRenderTargets = fbInfo.ColorRTVs.size();
for (size_t i = 0; i < fbInfo.ColorRTVs.size(); ++i) {
if (fbInfo.ColorRTVs[i]) {
@@ -73,12 +74,9 @@ namespace MG_Diligent {
PSOCreateInfo.GraphicsPipeline.RTVFormats[i] = Diligent::TEX_FORMAT_RGBA8_UNORM;
}
}
*/
if (fbInfo.DepthStencilFormat != Diligent::TEX_FORMAT_UNKNOWN) {
PSOCreateInfo.GraphicsPipeline.DSVFormat = fbInfo.DepthStencilFormat;
} else {
PSOCreateInfo.GraphicsPipeline.DSVFormat = Diligent::TEX_FORMAT_D32_FLOAT;
}
PSOCreateInfo.GraphicsPipeline.DSVFormat = Diligent::TEX_FORMAT_UNKNOWN;
Diligent::BlendStateDesc &blendDesc = PSOCreateInfo.GraphicsPipeline.BlendDesc;
blendDesc.IndependentBlendEnable = false;
@@ -672,11 +670,28 @@ 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.");
}
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.");
}
MG_Diligent::g_pContext->Flush();
MG_Util::Debug::LogD("Finishing frame");
MG_Diligent::g_pContext->FinishFrame();
@@ -691,14 +706,23 @@ namespace MG_EGL::Diligent {
::Diligent::RESOURCE_STATE_TRANSITION_MODE_TRANSITION
);
static ::Diligent::OptimizedClearValue DefaultClearValues[2];
DefaultClearValues[0].Format = fbInfo.ColorRTVs[0]->GetDesc().Format;
DefaultClearValues[0].Color[0] = 0.0f;
DefaultClearValues[0].Color[1] = 0.0f;
DefaultClearValues[0].Color[2] = 0.0f;
DefaultClearValues[0].Color[3] = 1.0f;
DefaultClearValues[1].Format = fbInfo.DepthStencilFormat;
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,
::Diligent::RESOURCE_STATE_TRANSITION_MODE_TRANSITION
}
);
::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);
@@ -380,6 +380,14 @@ namespace MG_GL::GL {
}
void DrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices) {
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();
MG_Util::Debug::LogD("DrawElements called with mode: %d, count: %d, type: %d, program: %u", mode, count, type, program);
if (program == 0) {
@@ -499,7 +507,6 @@ namespace MG_GL::GL {
EnsureRenderPassActive();
MG_Diligent::g_pContext->DrawIndexed(drawAttrs);
MG_Diligent::g_pContext->EndRenderPass();
MG_Diligent::IsInRenderPass = false;
MG_Util::Debug::LogD("DrawIndexed completed.");
@@ -260,6 +260,8 @@ namespace MG_GL::GL {
if (MG_Diligent::g_ShaderMap.find(shaderId) == MG_Diligent::g_ShaderMap.end() || MG_Diligent::g_ShaderMap[shaderId] == nullptr) {
GLenum shaderType = shaderObj.type;
std::string sourceStr = shaderSources[shaderId];
MG_Util::Debug::LogD("Shader ID: %u, type: %s\nConverted source:\n%s",
shaderId, MG_Util::Debug::GLEnumToString(shaderType), sourceStr.c_str());
Diligent::ShaderCreateInfo ShaderCI;
ShaderCI.Source = sourceStr.c_str();