[Fix] (MG/Framebuffer): get rid of suspicious GL_FRAMEBUFFER handling

This commit is contained in:
2025-06-23 10:51:24 +08:00
parent 14b1d5a2d1
commit 2f1b06d0f9
2 changed files with 45 additions and 36 deletions
@@ -451,6 +451,12 @@ namespace MG_GL::GL {
MG_Util::Debug::GLEnumToString(textarget),
texture,
level);
if (target == GL_FRAMEBUFFER) {
MG_Util::Debug::LogD("Got target == GL_FRAMEBUFFER, treating as GL_DRAW_FRAMEBUFFER");
target = GL_DRAW_FRAMEBUFFER;
}
MG_Util::Debug::LogD(" Current READ_FRAMEBUFFER binding: %u", MG_State_T::framebufferState->currentBindings_[GL_READ_FRAMEBUFFER]);
MG_Util::Debug::LogD(" Current DRAW_FRAMEBUFFER binding: %u", MG_State_T::framebufferState->currentBindings_[GL_DRAW_FRAMEBUFFER]);
@@ -459,26 +465,27 @@ namespace MG_GL::GL {
);
if (result == GL_NO_ERROR) {
if (target == GL_FRAMEBUFFER) {
if (MG_State_T::framebufferState->currentBindings_[GL_READ_FRAMEBUFFER] == MG_State_T::framebufferState->currentBindings_[GL_DRAW_FRAMEBUFFER]) {
MG_Util::Debug::LogD(" Target is GL_FRAMEBUFFER and READ/DRAW bindings are the same (%u). Applying to GL_DRAW_FRAMEBUFFER.", MG_State_T::framebufferState->currentBindings_[GL_DRAW_FRAMEBUFFER]);
target = GL_DRAW_FRAMEBUFFER;
} else {
MG_Util::Debug::LogD(" Target is GL_FRAMEBUFFER and READ/DRAW bindings differ. Applying to both if non-zero.");
if (MG_State_T::framebufferState->currentBindings_[GL_READ_FRAMEBUFFER] != 0) {
MG_Util::Debug::LogD(" Attaching to READ_FRAMEBUFFER: %u", MG_State_T::framebufferState->currentBindings_[GL_READ_FRAMEBUFFER]);
AttachTexture2DToFramebuffer(MG_State_T::framebufferState->currentBindings_[GL_READ_FRAMEBUFFER],
texture, attachment, level);
}
if (MG_State_T::framebufferState->currentBindings_[GL_DRAW_FRAMEBUFFER] != 0) {
MG_Util::Debug::LogD(" Attaching to DRAW_FRAMEBUFFER: %u", MG_State_T::framebufferState->currentBindings_[GL_DRAW_FRAMEBUFFER]);
AttachTexture2DToFramebuffer(MG_State_T::framebufferState->currentBindings_[GL_DRAW_FRAMEBUFFER],
texture, attachment, level);
}
MG_Util::Debug::LogD("FramebufferTexture2D completed successfully after separate READ/DRAW attachments.");
return;
}
}
// if (target == GL_FRAMEBUFFER) {
// if (MG_State_T::framebufferState->currentBindings_[GL_READ_FRAMEBUFFER] == MG_State_T::framebufferState->currentBindings_[GL_DRAW_FRAMEBUFFER]) {
// MG_Util::Debug::LogD(" Target is GL_FRAMEBUFFER and READ/DRAW bindings are the same (%u). Applying to GL_DRAW_FRAMEBUFFER.",
// MG_State_T::framebufferState->currentBindings_[GL_DRAW_FRAMEBUFFER]);
// target = GL_DRAW_FRAMEBUFFER;
// } else {
// MG_Util::Debug::LogD(" Target is GL_FRAMEBUFFER and READ/DRAW bindings differ. Applying to both if non-zero.");
// if (MG_State_T::framebufferState->currentBindings_[GL_READ_FRAMEBUFFER] != 0) {
// MG_Util::Debug::LogD(" Attaching to READ_FRAMEBUFFER: %u", MG_State_T::framebufferState->currentBindings_[GL_READ_FRAMEBUFFER]);
// AttachTexture2DToFramebuffer(MG_State_T::framebufferState->currentBindings_[GL_READ_FRAMEBUFFER],
// texture, attachment, level);
// }
// if (MG_State_T::framebufferState->currentBindings_[GL_DRAW_FRAMEBUFFER] != 0) {
// MG_Util::Debug::LogD(" Attaching to DRAW_FRAMEBUFFER: %u", MG_State_T::framebufferState->currentBindings_[GL_DRAW_FRAMEBUFFER]);
// AttachTexture2DToFramebuffer(MG_State_T::framebufferState->currentBindings_[GL_DRAW_FRAMEBUFFER],
// texture, attachment, level);
// }
// MG_Util::Debug::LogD("FramebufferTexture2D completed successfully after separate READ/DRAW attachments.");
// return;
// }
// }
GLuint fboToModify = MG_State_T::framebufferState->currentBindings_[target];
MG_Util::Debug::LogD(" Target is %s. Applying to bound FBO: %u",
MG_Util::Debug::GLEnumToString(target), fboToModify);
+18 -16
View File
@@ -60,22 +60,24 @@ GLenum FramebufferState::AttachTexture2D(GLenum target, GLenum attachment,
if (MG_Constants::Framebuffer::VALID_ATTACHMENTS.find(attachment) == MG_Constants::Framebuffer::VALID_ATTACHMENTS.end() ||
MG_Constants::Texture::VALID_TARGETS.find(textarget) == MG_Constants::Texture::VALID_TARGETS.end())
return GL_INVALID_ENUM;
if (target == GL_FRAMEBUFFER) {
if (currentBindings_[GL_READ_FRAMEBUFFER] == currentBindings_[GL_DRAW_FRAMEBUFFER]) {
target = GL_DRAW_FRAMEBUFFER;
} else {
if (currentBindings_[GL_READ_FRAMEBUFFER] != 0) {
GLenum err = AttachTexture2D(GL_READ_FRAMEBUFFER, attachment, textarget, texture, level);
if (err != GL_NO_ERROR)
return err;
}
if (currentBindings_[GL_DRAW_FRAMEBUFFER] != 0) {
GLenum err = AttachTexture2D(GL_DRAW_FRAMEBUFFER, attachment, textarget, texture, level);
if (err != GL_NO_ERROR)
return err;
}
return GL_NO_ERROR;
}
if (target == GL_FRAMEBUFFER) {
target = GL_DRAW_FRAMEBUFFER;
// if (currentBindings_[GL_READ_FRAMEBUFFER] == currentBindings_[GL_DRAW_FRAMEBUFFER]) {
// target = GL_DRAW_FRAMEBUFFER;
// } else {
// if (currentBindings_[GL_READ_FRAMEBUFFER] != 0) {
// GLenum err = AttachTexture2D(GL_READ_FRAMEBUFFER, attachment, textarget, texture, level);
// if (err != GL_NO_ERROR)
// return err;
// }
// if (currentBindings_[GL_DRAW_FRAMEBUFFER] != 0) {
// GLenum err = AttachTexture2D(GL_DRAW_FRAMEBUFFER, attachment, textarget, texture, level);
// if (err != GL_NO_ERROR)
// return err;
// }
// return GL_NO_ERROR;
// }
}
FramebufferObject* fbo = GetCurrentFBO(target);
if (!fbo) return GL_INVALID_OPERATION;