mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-10 21:28:32 +09:00
[Fix] (MG_Backend/DirectVulkan): fix null dereference crash in VkClearManager
This commit is contained in:
+1
-1
@@ -4,7 +4,7 @@ project("MobileGL")
|
|||||||
|
|
||||||
option(MOBILEGL_BUILD_TEST "Build MobileGL tests" ON )
|
option(MOBILEGL_BUILD_TEST "Build MobileGL tests" ON )
|
||||||
option(MOBILEGL_BUILD_BENCHMARK "Build MobileGL benchmarks" ON )
|
option(MOBILEGL_BUILD_BENCHMARK "Build MobileGL benchmarks" ON )
|
||||||
option(MOBILEGL_FORCE_RELEASE_OPT "Enable Release optimization flags in Debug build" ON )
|
option(MOBILEGL_FORCE_RELEASE_OPT "Enable Release optimization flags in Debug build" OFF)
|
||||||
option(MOBILEGL_ENABLE_TRACY "Enable tracy for profiling" OFF)
|
option(MOBILEGL_ENABLE_TRACY "Enable tracy for profiling" OFF)
|
||||||
|
|
||||||
if (ANDROID)
|
if (ANDROID)
|
||||||
|
|||||||
@@ -12,6 +12,20 @@
|
|||||||
#include "MG_Util/Converters/MGToStr/TextureEnumConverter.h"
|
#include "MG_Util/Converters/MGToStr/TextureEnumConverter.h"
|
||||||
|
|
||||||
namespace MobileGL::MG_Backend::DirectVulkan {
|
namespace MobileGL::MG_Backend::DirectVulkan {
|
||||||
|
static SharedPtr<MG_State::GLState::ITextureObject> GetClearableAttachmentTexture(
|
||||||
|
const MG_State::GLState::FramebufferObject& drawFbo, FramebufferAttachmentType attachmentType) {
|
||||||
|
if (attachmentType == FramebufferAttachmentType::None) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto& attachment = drawFbo.GetAttachment(attachmentType);
|
||||||
|
if (!attachment.IsTexture() || attachment.IsRenderbuffer()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return attachment.GetTexture();
|
||||||
|
}
|
||||||
|
|
||||||
Bool VkClearManager::Initialize() {
|
Bool VkClearManager::Initialize() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -26,39 +40,47 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
auto& drawbufs = drawFbo.GetDrawBuffers();
|
auto& drawbufs = drawFbo.GetDrawBuffers();
|
||||||
// This should automatically work on default & offscreen FBO
|
// This should automatically work on default & offscreen FBO
|
||||||
for (auto drawbuf: drawbufs) {
|
for (auto drawbuf: drawbufs) {
|
||||||
if (drawbuf == FramebufferAttachmentType::None ||
|
auto texture = GetClearableAttachmentTexture(drawFbo, drawbuf);
|
||||||
drawFbo.GetAttachment(drawbuf).IsRenderbuffer())
|
if (!texture) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
QueueClear({
|
QueueClear({
|
||||||
.mask = GL_COLOR_BUFFER_BIT,
|
.mask = GL_COLOR_BUFFER_BIT,
|
||||||
.color = clearPayload.color
|
.color = clearPayload.color
|
||||||
}, drawFbo.GetAttachment(drawbuf).GetTexture());
|
}, texture);
|
||||||
|
|
||||||
MGLOG_D("%s: %s (texture %d) - color = (%.2f, %.2f, %.2f, %.2f)", __func__,
|
MGLOG_D("%s: %s (texture %d) - color = (%.2f, %.2f, %.2f, %.2f)", __func__,
|
||||||
MG_Util::ConvertFramebufferAttachmentTypeToString(drawbuf).c_str(),
|
MG_Util::ConvertFramebufferAttachmentTypeToString(drawbuf).c_str(),
|
||||||
drawFbo.GetAttachment(drawbuf).GetTexture()->GetExternalIndex(),
|
texture->GetExternalIndex(),
|
||||||
clearPayload.color[0], clearPayload.color[1], clearPayload.color[2], clearPayload.color[3]);
|
clearPayload.color[0], clearPayload.color[1], clearPayload.color[2], clearPayload.color[3]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mask & GL_DEPTH_BUFFER_BIT &&
|
if (mask & GL_DEPTH_BUFFER_BIT) {
|
||||||
!drawFbo.GetAttachment(FramebufferAttachmentType::Depth).IsRenderbuffer()) {
|
auto texture = GetClearableAttachmentTexture(drawFbo, FramebufferAttachmentType::Depth);
|
||||||
QueueClear({
|
if (texture) {
|
||||||
.mask = GL_DEPTH_BUFFER_BIT,
|
QueueClear({
|
||||||
.depth = clearPayload.depth,
|
.mask = GL_DEPTH_BUFFER_BIT,
|
||||||
}, drawFbo.GetAttachment(FramebufferAttachmentType::Depth).GetTexture());
|
.depth = clearPayload.depth,
|
||||||
MGLOG_D("%s: Depth (texture %d) - depth = (%.2f)", __func__,
|
}, texture);
|
||||||
drawFbo.GetAttachment(FramebufferAttachmentType::Depth).GetTexture()->GetExternalIndex(), clearPayload.depth);
|
|
||||||
|
MGLOG_D("%s: Depth (texture %d) - depth = (%.2f)", __func__,
|
||||||
|
texture->GetExternalIndex(), clearPayload.depth);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mask & GL_STENCIL_BUFFER_BIT &&
|
if (mask & GL_STENCIL_BUFFER_BIT) {
|
||||||
!drawFbo.GetAttachment(FramebufferAttachmentType::Stencil).IsRenderbuffer()) {
|
auto texture = GetClearableAttachmentTexture(drawFbo, FramebufferAttachmentType::Stencil);
|
||||||
QueueClear({
|
if (texture) {
|
||||||
.mask = GL_STENCIL_BUFFER_BIT,
|
QueueClear({
|
||||||
.stencil = clearPayload.stencil,
|
.mask = GL_STENCIL_BUFFER_BIT,
|
||||||
}, drawFbo.GetAttachment(FramebufferAttachmentType::Stencil).GetTexture());
|
.stencil = clearPayload.stencil,
|
||||||
MGLOG_D("%s: Stencil (texture %d) - stencil = (%u)", __func__,
|
}, texture);
|
||||||
drawFbo.GetAttachment(FramebufferAttachmentType::Stencil).GetTexture()->GetExternalIndex(), clearPayload.stencil);
|
|
||||||
|
MGLOG_D("%s: Stencil (texture %d) - stencil = (%u)", __func__,
|
||||||
|
texture->GetExternalIndex(), clearPayload.stencil);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user