This commit is contained in:
Tungstend 2025-02-07 00:34:57 +08:00
parent eafaf1c453
commit fdbc27510e

View File

@ -19,14 +19,12 @@ GLint getMaxDrawBuffers() {
return MAX_DRAW_BUFFERS; return MAX_DRAW_BUFFERS;
} }
void rebind_framebuffer(GLenum old_attachment, GLenum target_attachment, bool draw) { void rebind_framebuffer(GLenum old_attachment, GLenum target_attachment) {
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 (rebindTarget == GL_DRAW_FRAMEBUFFER) if (bound_framebuffer->current_target == 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;
@ -37,7 +35,7 @@ void rebind_framebuffer(GLenum old_attachment, GLenum target_attachment, bool dr
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(rebindTarget, target_attachment, attachment.textarget, attachment.texture, attachment.level); gles_glFramebufferTexture2D(bound_framebuffer->current_target, target_attachment, attachment.textarget, attachment.texture, attachment.level);
} }
void glBindFramebuffer(GLenum target, GLuint framebuffer) { void glBindFramebuffer(GLenum target, GLuint framebuffer) {
@ -155,7 +153,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, true); rebind_framebuffer(bufs[i], target_attachment);
} else { } else {
new_bufs[i] = bufs[i]; new_bufs[i] = bufs[i];
} }