mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-12 14:18:31 +09:00
[Fix] (Diligent/Framebuffer): Correct GL_FRAMEBUFFER target handling.
This commit is contained in:
@@ -333,24 +333,10 @@ namespace MG_GL::GL {
|
|||||||
MG_Util::Debug::LogE("Framebuffer bind error: %s", MG_Util::Debug::GLEnumToString(result));
|
MG_Util::Debug::LogE("Framebuffer bind error: %s", MG_Util::Debug::GLEnumToString(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget,
|
void AttachTexture2DToFramebuffer(GLuint fbo, GLuint texture, GLenum attachment, GLint level) {
|
||||||
GLuint texture, GLint level) {
|
auto it = MG_Diligent::g_FramebufferMap.find(fbo);
|
||||||
MG_Util::Debug::LogD("glFramebufferTexture2D, target: %s, attach: %s, textarget: %s, tex: %u, level: %d",
|
|
||||||
MG_Util::Debug::GLEnumToString(target),
|
|
||||||
MG_Util::Debug::GLEnumToString(attachment),
|
|
||||||
MG_Util::Debug::GLEnumToString(textarget),
|
|
||||||
texture, level);
|
|
||||||
|
|
||||||
GLuint currentFB = MG_State_T::framebufferState->currentBindings_[target];
|
|
||||||
|
|
||||||
GLenum result = MG_State::AttachTexture2DToFramebuffer(
|
|
||||||
target, attachment, textarget, texture, level
|
|
||||||
);
|
|
||||||
|
|
||||||
if (result == GL_NO_ERROR) {
|
|
||||||
auto it = MG_Diligent::g_FramebufferMap.find(currentFB);
|
|
||||||
if (it == MG_Diligent::g_FramebufferMap.end()) {
|
if (it == MG_Diligent::g_FramebufferMap.end()) {
|
||||||
MG_Util::Debug::LogE("Framebuffer %u not found in map", currentFB);
|
MG_Util::Debug::LogE("Framebuffer %u not found in map", fbo);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,6 +369,14 @@ namespace MG_GL::GL {
|
|||||||
if (index < fbInfo.ColorRTVs.size() && fbInfo.ColorRTVs[index]) {
|
if (index < fbInfo.ColorRTVs.size() && fbInfo.ColorRTVs[index]) {
|
||||||
fbInfo.ColorRTVs[index]->Release();
|
fbInfo.ColorRTVs[index]->Release();
|
||||||
fbInfo.ColorRTVs[index] = nullptr;
|
fbInfo.ColorRTVs[index] = nullptr;
|
||||||
|
bool allNull = true;
|
||||||
|
for (const auto& rtv : fbInfo.ColorRTVs) {
|
||||||
|
if (rtv != nullptr) {
|
||||||
|
allNull = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (allNull) fbInfo.ColorRTVs.clear();
|
||||||
MG_Util::Debug::LogD("Released color attachment %zu", index);
|
MG_Util::Debug::LogD("Released color attachment %zu", index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -408,6 +402,7 @@ namespace MG_GL::GL {
|
|||||||
|
|
||||||
if (fbInfo.pDepthStencilRTV) {
|
if (fbInfo.pDepthStencilRTV) {
|
||||||
fbInfo.pDepthStencilRTV->Release();
|
fbInfo.pDepthStencilRTV->Release();
|
||||||
|
fbInfo.pDepthStencilRTV = nullptr;
|
||||||
MG_Util::Debug::LogD("Released existing depth/stencil attachment");
|
MG_Util::Debug::LogD("Released existing depth/stencil attachment");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -432,6 +427,7 @@ namespace MG_GL::GL {
|
|||||||
|
|
||||||
if (fbInfo.ColorRTVs[index]) {
|
if (fbInfo.ColorRTVs[index]) {
|
||||||
fbInfo.ColorRTVs[index]->Release();
|
fbInfo.ColorRTVs[index]->Release();
|
||||||
|
fbInfo.ColorRTVs[index] = nullptr;
|
||||||
MG_Util::Debug::LogD("Released existing color attachment %zu", index);
|
MG_Util::Debug::LogD("Released existing color attachment %zu", index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -445,8 +441,51 @@ namespace MG_GL::GL {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MG_Util::Debug::LogD("FramebufferTexture2D completed successfully");
|
void FramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget,
|
||||||
|
GLuint texture, GLint level) {
|
||||||
|
MG_Util::Debug::LogD("glFramebufferTexture2D, target: %s, attach: %s, textarget: %s, tex: %u, level: %d",
|
||||||
|
MG_Util::Debug::GLEnumToString(target),
|
||||||
|
MG_Util::Debug::GLEnumToString(attachment),
|
||||||
|
MG_Util::Debug::GLEnumToString(textarget),
|
||||||
|
texture,
|
||||||
|
level);
|
||||||
|
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]);
|
||||||
|
|
||||||
|
GLenum result = MG_State::AttachTexture2DToFramebuffer(
|
||||||
|
target, attachment, textarget, texture, level
|
||||||
|
);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
AttachTexture2DToFramebuffer(fboToModify,
|
||||||
|
texture, attachment, level);
|
||||||
|
|
||||||
|
MG_Util::Debug::LogD("FramebufferTexture2D completed successfully for target %s (FBO %u).", MG_Util::Debug::GLEnumToString(target), fboToModify);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MG_State::SetError(result);
|
MG_State::SetError(result);
|
||||||
|
|||||||
Reference in New Issue
Block a user