bool test_fbo_attachment_targets(GLenum texOneType, GLenum texTwoType, GLenum expectedFbStatus) { bool pass = true; GLuint fbo, texture[2]; glGenTextures(2, texture); glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); /* Setup texture one */ texture[0] = create_bind_texture(texOneType); attach_texture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texOneType, texture[0]); /* Setup texture two */ texture[1] = create_bind_texture(texTwoType); attach_texture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, texTwoType, texture[1]); if(!piglit_check_gl_error(GL_NO_ERROR)) piglit_report_result(PIGLIT_FAIL); /* Check for expected fb status */ pass = CheckFramebufferStatus(expectedFbStatus) && pass; /* Clean up */ glBindFramebuffer(GL_FRAMEBUFFER, piglit_winsys_fbo); glDeleteFramebuffers(1, &fbo); glDeleteTextures(2, texture); return pass; }
void piglit_init(int argc, char **argv) { GLuint tex0, fb; GLenum status; piglit_require_extension("GL_ARB_ES2_compatibility"); glGenFramebuffersEXT(1, &fb); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); tex0 = attach_texture(0); glDrawBuffer(GL_COLOR_ATTACHMENT0); glReadBuffer(GL_COLOR_ATTACHMENT0); 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); } glDrawBuffer(GL_COLOR_ATTACHMENT1); status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); if (status == GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER) { fprintf(stderr, "fbo incomplete draw buffer\n"); piglit_report_result(PIGLIT_FAIL); } glReadBuffer(GL_COLOR_ATTACHMENT1); status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); if (status == GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER) { fprintf(stderr, "fbo incomplete read buffer\n"); piglit_report_result(PIGLIT_FAIL); } if (!piglit_check_gl_error(GL_NO_ERROR)) piglit_report_result(PIGLIT_FAIL); glDeleteTextures(1, &tex0); piglit_report_result(PIGLIT_PASS); }
enum piglit_result piglit_display(void) { GLboolean pass = GL_TRUE; GLuint tex0, tex1, fb; GLenum status; 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 blue. The first buffer will have no blending and * get overwritten green, and the second will be blended ZERO, * ONE leaving the blue in place. */ glClearColor(0.0, 0.0, 1.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glBlendFunc(GL_ZERO, GL_ONE); glDisableIndexedEXT(GL_BLEND, 0); glEnableIndexedEXT(GL_BLEND, 1); glColor4fv(green); piglit_draw_rect(0, 0, piglit_width, piglit_height); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo); glDisable(GL_BLEND); /* 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; }
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; }
enum piglit_result piglit_display(void) { GLboolean pass = GL_TRUE; GLuint tex0, tex1, fb; GLenum status; 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 render targets (textures) to red */ glClearColor(1.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glMultiTexCoord4fv(GL_TEXTURE0, result0); glMultiTexCoord4fv(GL_TEXTURE1, result1); glEnable(GL_FRAGMENT_PROGRAM_ARB); piglit_draw_rect(0, 0, piglit_width, piglit_height); glDisable(GL_FRAGMENT_PROGRAM_ARB); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); /* Draw the two green 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 / 2, piglit_height, 0, 0, 1, 1); glDisable(GL_TEXTURE_2D); glDeleteTextures(1, &tex0); glDeleteTextures(1, &tex1); glDeleteFramebuffersEXT(1, &fb); pass = pass && piglit_probe_rect_rgba(0, 0, piglit_width / 2, piglit_height, result0); pass = pass && piglit_probe_rect_rgba(piglit_width / 2, 0, piglit_width / 2, piglit_height, result1); glutSwapBuffers(); return pass ? PIGLIT_PASS : PIGLIT_FAIL; }
static void generate_and_display_drawbuffers(int count) { GLuint tex[MAX_TARGETS], fb, fs, vs, prog; GLenum attachments[MAX_TARGETS], status; char *fs_count_source; int i; int colors_uniform; glGenFramebuffersEXT(1, &fb); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); for (i = 0; i < count; i++) { tex[i] = attach_texture(i); attachments[i] = GL_COLOR_ATTACHMENT0 + i; } 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); } glDrawBuffersARB(count, attachments); /* Clear all to red so we see if the shader rendering happens. */ glClearColor(1.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); /* Build the shader that writes different color to each buffer. */ vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_source); fs_count_source = malloc(strlen(fs_source) + 5); sprintf(fs_count_source, fs_source, count); fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_count_source); free(fs_count_source); prog = piglit_link_simple_program(vs, fs); glUseProgram(prog); if (!piglit_check_gl_error(GL_NO_ERROR)) piglit_report_result(PIGLIT_FAIL); colors_uniform = glGetUniformLocation(prog, "colors"); glUniform4fv(colors_uniform, MAX_TARGETS, (GLfloat *) colors); /* Now render to all the color buffers. */ piglit_draw_rect(-1, -1, 2, 2); /* OK, now draw each of these textures to the winsys framebuffer. */ glUseProgram(0); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo); piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glEnable(GL_TEXTURE_2D); /* draw row of boxes, each with the color from texture/target[i] */ for (i = 0; i < count; i++) { glBindTexture(GL_TEXTURE_2D, tex[i]); piglit_draw_rect_tex(16 * i, 16 * (count - 1), 16, 16, 0, 0, 1, 1); } glDisable(GL_TEXTURE_2D); for (i = 0; i < count; i++) { glDeleteTextures(1, &tex[i]); } glDeleteFramebuffersEXT(1, &fb); }
static void generate_and_display_drawbuffers(int count) { GLuint tex[16], fb, fs, vs, prog; GLenum attachments[16], status; int i; char fs_output_line[256]; char fs_full_source[1024]; glGenFramebuffersEXT(1, &fb); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); for (i = 0; i < count; i++) { tex[i] = attach_texture(i); attachments[i] = GL_COLOR_ATTACHMENT0 + i; } 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); } glDrawBuffersARB(count, attachments); /* Clear all to 0.25 so we see if the shader rendering happens. */ glClearColor(clear_value, clear_value, clear_value, clear_value); glClear(GL_COLOR_BUFFER_BIT); /* Build the shader that spams green to all outputs. */ vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_source); strcpy(fs_full_source, fs_source_start); for (i = 0; i < count; i++) { sprintf(fs_output_line, fs_source_output, i, output_values[i * 4], output_values[(i * 4) + 1], output_values[(i * 4) + 2], output_values[(i * 4) + 3]); strcat(fs_full_source, fs_output_line); } strcat(fs_full_source, fs_source_end); assert(strlen(fs_full_source) + 1 < sizeof(fs_full_source) / sizeof(fs_full_source[0])); fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_full_source); prog = piglit_link_simple_program(vs, fs); glUseProgram(prog); glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE); glBlendEquation(GL_FUNC_ADD); /* Now render to all the color buffers. */ piglit_draw_rect(-1, -1, 2, 2); glDisable(GL_BLEND); /* OK, now draw each of these textures to the winsys framebuffer. */ glUseProgram(0); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glEnable(GL_TEXTURE_2D); for (i = 0; i < count; i++) { glBindTexture(GL_TEXTURE_2D, tex[i]); piglit_draw_rect_tex(16 * i, 16 * (count - 1), 16, 16, 0, 0, 1, 1); } glDisable(GL_TEXTURE_2D); for (i = 0; i < count; i++) { glDeleteTextures(1, &tex[i]); } glDeleteFramebuffersEXT(1, &fb); }
static void generate_and_display_drawbuffers(int count) { GLuint tex[16], fb, fs, vs, prog; GLenum attachments[16], status, error; char *fs_count_source; int i; glGenFramebuffersEXT(1, &fb); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); for (i = 0; i < count; i++) { tex[i] = attach_texture(i); attachments[i] = GL_COLOR_ATTACHMENT0 + i; } 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); } glDrawBuffersARB(count, attachments); /* Clear all to red so we see if the shader rendering happens. */ glClearColor(1.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); /* Build the shader that spams green to all outputs. */ vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_source); fs_count_source = malloc(strlen(fs_source) + 5); sprintf(fs_count_source, fs_source, count); fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_count_source); free(fs_count_source); prog = piglit_link_simple_program(vs, fs); glUseProgram(prog); error = glGetError(); if (error) { fprintf(stderr, "glUseProgram error: 0x%x\n", error); piglit_report_result(PIGLIT_FAIL); } /* Now render to all the color buffers. */ piglit_draw_rect(-1, -1, 2, 2); /* OK, now draw each of these textures to the winsys framebuffer. */ glUseProgram(0); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glEnable(GL_TEXTURE_2D); for (i = 0; i < count; i++) { glBindTexture(GL_TEXTURE_2D, tex[i]); piglit_draw_rect_tex(16 * i, 16 * (count - 1), 16, 16, 0, 0, 1, 1); } glDisable(GL_TEXTURE_2D); for (i = 0; i < count; i++) { glDeleteTextures(1, &tex[i]); } glDeleteFramebuffersEXT(1, &fb); }