- if (format == GL_ALPHA) {
- for (unsigned i = 0; i < width * height; ++i) {
- out_data[i] = temp[i * 4 + 3];
- }
- } else if (format == GL_BLUE) {
- for (unsigned i = 0; i < width * height; ++i) {
- out_data[i] = temp[i * 4 + 2];
+ }
+
+ GLenum bufs[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 };
+ glDrawBuffers(num_outputs, bufs);
+
+ chain.render_to_fbo(fbo, width, height);
+
+ T *data[3] = { out_data, out_data2, out_data3 };
+
+ glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+ check_error();
+ for (unsigned i = 0; i < num_outputs; ++i) {
+ T *ptr = data[i];
+ glReadBuffer(GL_COLOR_ATTACHMENT0 + i);
+ if (!epoxy_is_desktop_gl() && (format == GL_RED || format == GL_BLUE || format == GL_ALPHA)) {
+ // GLES will only read GL_RGBA.
+ T *temp = new T[width * height * 4];
+ glReadPixels(0, 0, width, height, GL_RGBA, internal_format, temp);
+ check_error();
+ if (format == GL_ALPHA) {
+ for (unsigned i = 0; i < width * height; ++i) {
+ ptr[i] = temp[i * 4 + 3];
+ }
+ } else if (format == GL_BLUE) {
+ for (unsigned i = 0; i < width * height; ++i) {
+ ptr[i] = temp[i * 4 + 2];
+ }
+ } else {
+ for (unsigned i = 0; i < width * height; ++i) {
+ ptr[i] = temp[i * 4];
+ }