diff --git a/src/main/cpp/gl/drawing.c b/src/main/cpp/gl/drawing.c index 44f674a..1f7d101 100644 --- a/src/main/cpp/gl/drawing.c +++ b/src/main/cpp/gl/drawing.c @@ -35,73 +35,4 @@ void glMultiDrawElements(GLenum mode,const GLsizei * count,GLenum type,const voi ); } } -} - -void glDrawBuffer(GLenum buffer) { - LOG() - - LOAD_GLES(glDrawBuffers, void, GLsizei n, const GLenum *bufs) - - GLint currentFBO; - glGetIntegerv(GL_FRAMEBUFFER_BINDING, ¤tFBO); - - if (currentFBO == 0) { // 默认帧缓冲 - GLenum buffers[1] = {GL_NONE}; - switch (buffer) { - case GL_FRONT: - case GL_BACK: - case GL_NONE: - buffers[0] = buffer; - gles_glDrawBuffers(1, buffers); - break; - default: - // 生成错误:GL_INVALID_ENUM - break; - } - } else { // FBO场景 - GLint maxAttachments; - glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxAttachments); - - if (buffer == GL_NONE) { - GLenum *buffers = (GLenum *)alloca(maxAttachments * sizeof(GLenum)); - for (int i = 0; i < maxAttachments; i++) { - buffers[i] = GL_NONE; - } - gles_glDrawBuffers(maxAttachments, buffers); - } else if (buffer >= GL_COLOR_ATTACHMENT0 && - buffer < GL_COLOR_ATTACHMENT0 + maxAttachments) { - GLenum *buffers = (GLenum *)alloca(maxAttachments * sizeof(GLenum)); - for (int i = 0; i < maxAttachments; i++) { - buffers[i] = (i == (buffer - GL_COLOR_ATTACHMENT0)) ? buffer : GL_NONE; - } - gles_glDrawBuffers(maxAttachments, buffers); - } else { - // 生成错误:GL_INVALID_ENUM - } - } -} - -void glDrawBuffers(GLsizei n, const GLenum *bufs) { - LOG() - - LOG_D("glDrawBuffers(%d, %p), [0]=0x%x", n, bufs, n ? bufs[0] : 0) - - GLenum new_bufs[n]; - - for (int i = 0; i < n; i++) { - if (bufs[i] >= GL_COLOR_ATTACHMENT0 && bufs[i] <= GL_COLOR_ATTACHMENT0 + getMaxDrawBuffers()) { - GLenum target_attachment = GL_COLOR_ATTACHMENT0 + i; - new_bufs[i] = target_attachment; - if (bufs[i] == target_attachment) - continue; - rebind_framebuffer(bufs[i], target_attachment); - } else { - new_bufs[i] = bufs[i]; - } - } - - LOAD_GLES(glDrawBuffers, void, GLsizei n, const GLenum *bufs) - gles_glDrawBuffers(n, new_bufs); - - CHECK_GL_ERROR } \ No newline at end of file diff --git a/src/main/cpp/gl/drawing.h b/src/main/cpp/gl/drawing.h index dfc9ebb..c25901e 100644 --- a/src/main/cpp/gl/drawing.h +++ b/src/main/cpp/gl/drawing.h @@ -21,10 +21,6 @@ GLAPI GLAPIENTRY void glMultiDrawElementsBaseVertex( GLenum mode, GLsizei *counts, GLenum type, const void * const *indices, GLsizei primcount, const GLint * basevertex); -GLAPI GLAPIENTRY void glDrawBuffer(GLenum buf); - -GLAPI GLAPIENTRY void glDrawBuffers(GLsizei n, const GLenum *bufs); - GLAPI GLAPIENTRY void glMultiDrawElements(GLenum mode,const GLsizei * count,GLenum type,const void * const * indices,GLsizei primcount); #endif //MOBILEGLUES_DRAWING_H diff --git a/src/main/cpp/gl/framebuffer.c b/src/main/cpp/gl/framebuffer.c index d180d06..cad4019 100644 --- a/src/main/cpp/gl/framebuffer.c +++ b/src/main/cpp/gl/framebuffer.c @@ -95,5 +95,74 @@ void glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, LOAD_GLES(glFramebufferTexture2D, void, GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) gles_glFramebufferTexture2D(target, attachment, textarget, texture, level); + CHECK_GL_ERROR +} + +void glDrawBuffer(GLenum buffer) { + LOG() + + LOAD_GLES(glDrawBuffers, void, GLsizei n, const GLenum *bufs) + + GLint currentFBO; + glGetIntegerv(GL_FRAMEBUFFER_BINDING, ¤tFBO); + + if (currentFBO == 0) { // 默认帧缓冲 + GLenum buffers[1] = {GL_NONE}; + switch (buffer) { + case GL_FRONT: + case GL_BACK: + case GL_NONE: + buffers[0] = buffer; + gles_glDrawBuffers(1, buffers); + break; + default: + // 生成错误:GL_INVALID_ENUM + break; + } + } else { // FBO场景 + GLint maxAttachments; + glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxAttachments); + + if (buffer == GL_NONE) { + GLenum *buffers = (GLenum *)alloca(maxAttachments * sizeof(GLenum)); + for (int i = 0; i < maxAttachments; i++) { + buffers[i] = GL_NONE; + } + gles_glDrawBuffers(maxAttachments, buffers); + } else if (buffer >= GL_COLOR_ATTACHMENT0 && + buffer < GL_COLOR_ATTACHMENT0 + maxAttachments) { + GLenum *buffers = (GLenum *)alloca(maxAttachments * sizeof(GLenum)); + for (int i = 0; i < maxAttachments; i++) { + buffers[i] = (i == (buffer - GL_COLOR_ATTACHMENT0)) ? buffer : GL_NONE; + } + gles_glDrawBuffers(maxAttachments, buffers); + } else { + // 生成错误:GL_INVALID_ENUM + } + } +} + +void glDrawBuffers(GLsizei n, const GLenum *bufs) { + LOG() + + LOG_D("glDrawBuffers(%d, %p), [0]=0x%x", n, bufs, n ? bufs[0] : 0) + + GLenum new_bufs[n]; + + for (int i = 0; i < n; i++) { + if (bufs[i] >= GL_COLOR_ATTACHMENT0 && bufs[i] <= GL_COLOR_ATTACHMENT0 + getMaxDrawBuffers()) { + GLenum target_attachment = GL_COLOR_ATTACHMENT0 + i; + new_bufs[i] = target_attachment; + if (bufs[i] == target_attachment) + continue; + rebind_framebuffer(bufs[i], target_attachment); + } else { + new_bufs[i] = bufs[i]; + } + } + + LOAD_GLES(glDrawBuffers, void, GLsizei n, const GLenum *bufs) + gles_glDrawBuffers(n, new_bufs); + CHECK_GL_ERROR } \ No newline at end of file diff --git a/src/main/cpp/gl/framebuffer.h b/src/main/cpp/gl/framebuffer.h index c8207a6..ad56463 100644 --- a/src/main/cpp/gl/framebuffer.h +++ b/src/main/cpp/gl/framebuffer.h @@ -29,4 +29,8 @@ 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 glDrawBuffer(GLenum buf); + +GLAPI GLAPIENTRY void glDrawBuffers(GLsizei n, const GLenum *bufs); + #endif //MOBILEGLUES_FRAMEBUFFER_H