static bool test_glColorMaskIndexed(const GLenum drawbufs[4]) { static const float color_masked_red[4] = {1, 0, CLEAR_COLOR, CLEAR_COLOR}; static const float color_masked_green[4] = {CLEAR_COLOR, 1, 0, CLEAR_COLOR}; static const float color_masked_blue[4] = {CLEAR_COLOR, CLEAR_COLOR, 1, 1}; static const float color_masked_yellow[4] = {1, 1, CLEAR_COLOR, 1}; static const float *colors_masked[] = { color_masked_red, color_masked_green, color_masked_blue, color_masked_yellow, }; glColorMaskIndexedEXT(0, 1, 1, 0, 0); glColorMaskIndexedEXT(1, 0, 1, 1, 0); glColorMaskIndexedEXT(2, 0, 0, 1, 1); glColorMaskIndexedEXT(3, 1, 1, 0, 1); glUseProgram(prog_write_all_different); piglit_draw_rect(-1, -1, 2, 2); glUseProgram(0); glColorMask(1, 1, 1, 1); return probe_buffers(drawbufs, colors_masked); }
enum piglit_result piglit_display(void) { GLboolean pass = GL_TRUE; GLuint tex0, tex1, fb; GLenum status; float white[] = {1, 1, 1, 1}; float green[] = {0, 1, 0, 0}; float blue[] = {0, 0, 1, 0}; const GLenum attachments[] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, }; piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE); glGenFramebuffersEXT(1, &fb); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); tex0 = attach_texture(0); tex1 = attach_texture(1); glDrawBuffersARB(2, attachments); status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { fprintf(stderr, "fbo incomplete (status = 0x%04x)\n", status); piglit_report_result(PIGLIT_SKIP); } /* Clear to black */ glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); /* Mask only green in RT 0, blue in RT 1, then try to draw in white */ glColorMaskIndexedEXT(0, GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE); glColorMaskIndexedEXT(1, GL_FALSE, GL_FALSE, GL_TRUE, GL_FALSE); if (test_clear) { glClearColor(1.0, 1.0, 1.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); } else { glColor4fv(white); piglit_draw_rect(0, 0, piglit_width, piglit_height); } glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); /* Draw the two textures to halves of the window. */ glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glBindTexture(GL_TEXTURE_2D, tex0); piglit_draw_rect_tex(0, 0, piglit_width / 2, piglit_height, 0, 0, 1, 1); glBindTexture(GL_TEXTURE_2D, tex1); piglit_draw_rect_tex(piglit_width / 2, 0, piglit_width, piglit_height, 0, 0, 1, 1); glDisable(GL_TEXTURE_2D); glDeleteTextures(1, &tex0); glDeleteTextures(1, &tex1); glDeleteFramebuffersEXT(1, &fb); pass = pass && piglit_probe_rect_rgb(0, 0, piglit_width/2, piglit_height, green); pass = pass && piglit_probe_rect_rgb(piglit_width/2, 0, piglit_width/2, piglit_height, blue); piglit_present_results(); return pass ? PIGLIT_PASS : PIGLIT_FAIL; }
static void Display(void) { GLubyte *buffer = malloc(Width * Height * 4); static const GLenum buffers[2] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT }; glUseProgram(Program); glEnable(GL_DEPTH_TEST); /* draw to user framebuffer */ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FBobject); /* Clear color buffer 0 (blue) */ glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); glClear(GL_COLOR_BUFFER_BIT); /* Clear color buffer 1 (1 - blue) */ glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT); glClear(GL_COLOR_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT); /* draw to two buffers w/ fragment shader */ glDrawBuffersARB(2, buffers); /* different color masks for each buffer */ if (1) { glColorMaskIndexedEXT(0, GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE); glColorMaskIndexedEXT(1, GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE); } glPushMatrix(); glRotatef(Xrot, 1, 0, 0); glRotatef(Yrot, 0, 1, 0); glPushMatrix(); glTranslatef(1, 0, 0); glutSolidTorus(1.0, 2.0, 10, 20); glPopMatrix(); glPushMatrix(); glTranslatef(-1, 0, 0); glRotatef(90, 1, 0, 0); glutSolidTorus(1.0, 2.0, 10, 20); glPopMatrix(); glPopMatrix(); /* restore default color masks */ glColorMaskIndexedEXT(0, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glColorMaskIndexedEXT(1, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); /* read from user framebuffer */ /* left half = colorbuffer 0 */ glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); glPixelStorei(GL_PACK_ROW_LENGTH, Width); glPixelStorei(GL_PACK_SKIP_PIXELS, 0); glReadPixels(0, 0, Width / 2, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); /* right half = colorbuffer 1 */ glReadBuffer(GL_COLOR_ATTACHMENT1_EXT); glPixelStorei(GL_PACK_SKIP_PIXELS, Width / 2); glReadPixels(Width / 2, 0, Width - Width / 2, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); /* draw to window */ glUseProgram(0); glDisable(GL_DEPTH_TEST); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); glWindowPos2iARB(0, 0); glDrawPixels(Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); free(buffer); glutSwapBuffers(); CheckError(__LINE__); }