only handle GL_DRAW_FRAMEBUFFER when glDrawBuffers call rebind_framebuffer

This commit is contained in:
Tungstend 2025-02-07 00:32:16 +08:00
parent 957381fcee
commit eafaf1c453
2 changed files with 6 additions and 6 deletions

View File

@ -19,12 +19,14 @@ GLint getMaxDrawBuffers() {
return MAX_DRAW_BUFFERS; return MAX_DRAW_BUFFERS;
} }
void rebind_framebuffer(GLenum old_attachment, GLenum target_attachment) { void rebind_framebuffer(GLenum old_attachment, GLenum target_attachment, bool draw) {
if (!bound_framebuffer) if (!bound_framebuffer)
return; return;
GLenum rebindTarget = draw ? GL_DRAW_FRAMEBUFFER : bound_framebuffer->current_target;
struct attachment_t* attach; struct attachment_t* attach;
if (bound_framebuffer->current_target == GL_DRAW_FRAMEBUFFER) if (rebindTarget == GL_DRAW_FRAMEBUFFER)
attach = bound_framebuffer->draw_attachment; attach = bound_framebuffer->draw_attachment;
else else
attach = bound_framebuffer->read_attachment; attach = bound_framebuffer->read_attachment;
@ -35,7 +37,7 @@ void rebind_framebuffer(GLenum old_attachment, GLenum target_attachment) {
struct attachment_t attachment = attach[old_attachment - GL_COLOR_ATTACHMENT0]; struct attachment_t attachment = attach[old_attachment - GL_COLOR_ATTACHMENT0];
LOAD_GLES(glFramebufferTexture2D, void, GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) LOAD_GLES(glFramebufferTexture2D, void, GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
gles_glFramebufferTexture2D(bound_framebuffer->current_target, target_attachment, attachment.textarget, attachment.texture, attachment.level); gles_glFramebufferTexture2D(rebindTarget, target_attachment, attachment.textarget, attachment.texture, attachment.level);
} }
void glBindFramebuffer(GLenum target, GLuint framebuffer) { void glBindFramebuffer(GLenum target, GLuint framebuffer) {
@ -153,7 +155,7 @@ void glDrawBuffers(GLsizei n, const GLenum *bufs) {
if (bufs[i] >= GL_COLOR_ATTACHMENT0 && bufs[i] <= GL_COLOR_ATTACHMENT0 + getMaxDrawBuffers()) { if (bufs[i] >= GL_COLOR_ATTACHMENT0 && bufs[i] <= GL_COLOR_ATTACHMENT0 + getMaxDrawBuffers()) {
GLenum target_attachment = GL_COLOR_ATTACHMENT0 + i; GLenum target_attachment = GL_COLOR_ATTACHMENT0 + i;
new_bufs[i] = target_attachment; new_bufs[i] = target_attachment;
rebind_framebuffer(bufs[i], target_attachment); rebind_framebuffer(bufs[i], target_attachment, true);
} else { } else {
new_bufs[i] = bufs[i]; new_bufs[i] = bufs[i];
} }

View File

@ -21,8 +21,6 @@ struct framebuffer_t {
GLint getMaxDrawBuffers(); GLint getMaxDrawBuffers();
void rebind_framebuffer(GLenum old_attachment, GLenum target_attachment);
GLAPI GLAPIENTRY void glBindFramebuffer(GLenum target, GLuint framebuffer); GLAPI GLAPIENTRY void glBindFramebuffer(GLenum target, GLuint framebuffer);
GLAPI GLAPIENTRY void glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); GLAPI GLAPIENTRY void glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);