|
8 | 8 | #include "FSR1/FSR1.h" |
9 | 9 |
|
10 | 10 | #define DEBUG 0 |
11 | | -struct attachment_t { |
12 | | - GLenum textarget; |
13 | | - GLuint texture; |
14 | | - GLint level; |
15 | | -}; |
16 | | -struct framebuffer_t { |
17 | | - bool initialized = false; |
18 | | - attachment_t* color_attachments = nullptr; |
19 | | - attachment_t depth_attachment = {0}; |
20 | | - attachment_t stencil_attachment = {0}; |
21 | | -}; |
| 11 | + |
22 | 12 | static GLint MAX_COLOR_ATTACHMENTS = 0; |
23 | 13 | static GLint MAX_DRAW_BUFFERS = 0; |
24 | | -static GLuint current_draw_fbo = 0; |
25 | | -static GLuint current_read_fbo = 0; |
26 | | -static std::vector<framebuffer_t> framebuffers; |
| 14 | +GLuint current_draw_fbo = 0; |
| 15 | +GLuint current_read_fbo = 0; |
| 16 | +std::vector<framebuffer_t> framebuffers; |
27 | 17 | void ensure_max_attachments() { |
28 | 18 | if (MAX_COLOR_ATTACHMENTS == 0) { |
29 | 19 | GLES.glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &MAX_COLOR_ATTACHMENTS); |
@@ -96,32 +86,59 @@ void glFramebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLin |
96 | 86 | GLES.glFramebufferTexture(target, attachment, texture, level); |
97 | 87 | } |
98 | 88 | void glDrawBuffer(GLenum buffer) { |
99 | | - GLint currentFBO; |
100 | | - GLES.glGetIntegerv(GL_FRAMEBUFFER_BINDING, ¤tFBO); |
101 | | - if (currentFBO == 0) { |
| 89 | + LOG() |
| 90 | + LOG_D("glDrawBuffer %d", buffer) |
| 91 | + |
| 92 | +// GLint currentFBO; |
| 93 | +// GLES.glGetIntegerv(GL_FRAMEBUFFER_BINDING, ¤tFBO); |
| 94 | + if (current_draw_fbo == 0) { |
102 | 95 | GLenum buffers[] = {buffer}; |
103 | | - GLES.glDrawBuffers(1, buffers); |
| 96 | + glDrawBuffers(1, buffers); |
104 | 97 | } else { |
105 | 98 | GLint maxAttachments; |
106 | 99 | GLES.glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxAttachments); |
107 | 100 |
|
108 | 101 | if (buffer == GL_NONE) { |
| 102 | + framebuffers[current_draw_fbo].color_attachments_all_none = true; |
109 | 103 | std::vector<GLenum> buffers(maxAttachments, GL_NONE); |
110 | | - GLES.glDrawBuffers(maxAttachments, buffers.data()); |
| 104 | + glDrawBuffers(maxAttachments, buffers.data()); |
111 | 105 | } else if (buffer >= GL_COLOR_ATTACHMENT0 && buffer < GL_COLOR_ATTACHMENT0 + maxAttachments) { |
| 106 | + framebuffers[current_draw_fbo].color_attachments_all_none = false; |
112 | 107 | std::vector<GLenum> buffers(maxAttachments, GL_NONE); |
113 | 108 | buffers[buffer - GL_COLOR_ATTACHMENT0] = buffer; |
114 | | - GLES.glDrawBuffers(maxAttachments, buffers.data()); |
| 109 | + glDrawBuffers(maxAttachments, buffers.data()); |
115 | 110 | } |
116 | 111 | } |
| 112 | + CHECK_GL_ERROR; |
117 | 113 | } |
118 | 114 | void glDrawBuffers(GLsizei n, const GLenum* bufs) { |
| 115 | + LOG() |
119 | 116 | if (current_draw_fbo == 0) { |
120 | 117 | GLES.glDrawBuffers(n, bufs); |
121 | 118 | return; |
122 | 119 | } |
123 | | - std::vector<GLenum> new_bufs(n); |
| 120 | + |
124 | 121 | framebuffer_t& fbo = framebuffers[current_draw_fbo]; |
| 122 | + |
| 123 | + bool all_none = true; |
| 124 | + for (int i = 0; i < n; ++i) { |
| 125 | + if (bufs[i] != GL_NONE) { |
| 126 | + all_none = false; |
| 127 | + break; |
| 128 | + } |
| 129 | + } |
| 130 | + |
| 131 | + if (all_none) { |
| 132 | + LOG_D("glDrawBuffers, fb %d all_none true", current_draw_fbo) |
| 133 | + fbo.color_attachments_all_none = true; |
| 134 | + GLES.glDrawBuffers(n, bufs); |
| 135 | + return; |
| 136 | + } else { |
| 137 | + LOG_D("glDrawBuffers, fb %d all_none false", current_draw_fbo) |
| 138 | + fbo.color_attachments_all_none = false; |
| 139 | + } |
| 140 | + |
| 141 | + std::vector<GLenum> new_bufs(n); |
125 | 142 | for (int i = 0; i < n; i++) { |
126 | 143 | if (bufs[i] >= GL_COLOR_ATTACHMENT0 && bufs[i] < GL_COLOR_ATTACHMENT0 + MAX_COLOR_ATTACHMENTS) { |
127 | 144 | GLenum logical_attachment = bufs[i]; |
|
0 commit comments