enum piglit_result piglit_display(void) { bool pass = true; glClear(GL_COLOR_BUFFER_BIT); for (int i = 0; true; ++i) { glUniform1i(render_pass_loc, i); if (i%2) piglit_draw_rect(0, -1, 1, 2); else piglit_draw_rect(-1, -1, 1, 2); if (i >= 5) break; glTextureBarrier(); } unsigned color = 1; color *= 2; color += 2; color ^= 1023; color <<= 2; const unsigned expected_left[] = { color, 0, 0, 1 }; color %= 32; const unsigned expected_right[] = { color, 0, 0, 1 }; pass = piglit_probe_rect_rgba_uint(0, 0, width / 2, height, expected_left) && pass; pass = piglit_probe_rect_rgba_uint(width / 2, 0, width / 2, height, expected_right) && pass; pass = piglit_check_gl_error(GL_NO_ERROR) && pass; return pass ? PIGLIT_PASS : PIGLIT_FAIL; }
PIGLIT_GL_TEST_CONFIG_END enum piglit_result piglit_display(void) { bool pass = true; float green[4] = {0.0, 1.0, 0.0, 0.0}; float vertex_data[] = { -0.5, -0.5, 0.5, -0.5, 0.0, 0.5, 0.0, 0.0 }; glDisable(GL_RASTERIZER_DISCARD); glColor4f(0.0, 1.0, 0.0, 0.0); piglit_draw_rect(-1, -1, 2, 2); glEnable(GL_RASTERIZER_DISCARD); glColor4f(1.0, 0.0, 0.0, 0.0); piglit_draw_rect(-1, -1, 2, 2); glVertexPointer(2, GL_FLOAT, 0, vertex_data); glEnableClientState(GL_VERTEX_ARRAY); glDrawArrays(GL_LINE_LOOP, 0, 3); glDrawArrays(GL_POINTS, 3, 1); pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, green); piglit_present_results(); return pass ? PIGLIT_PASS : PIGLIT_FAIL; }
static enum piglit_result test_readpixels(void) { /* Clear stencil to 0xfe. */ glClearStencil(0xfefe); glClear(GL_STENCIL_BUFFER_BIT); /* Initialize stencil. */ glEnable(GL_STENCIL_TEST); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); glStencilFunc(GL_ALWAYS, 0x3333 & mask, ~0); piglit_draw_rect(-1, -1, 1, 1); glStencilFunc(GL_ALWAYS, 0x6666 & mask, ~0); piglit_draw_rect(0, -1, 1, 1); glStencilFunc(GL_ALWAYS, 0x9999 & mask, ~0); piglit_draw_rect(-1, 0, 1, 1); glStencilFunc(GL_ALWAYS, 0xbbbb & mask, ~0); piglit_draw_rect(0, 0, 1, 1); glDisable(GL_STENCIL_TEST); return compare_stencil(); }
static enum piglit_result test_copy(void) { /* Clear stencil to 0xfe. */ glClearStencil(0xfefe); glClear(GL_STENCIL_BUFFER_BIT); /* Initialize stencil. */ glEnable(GL_STENCIL_TEST); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); /* Set the upper-right corner to 0x3333 and copy the content to the lower-left one. */ glStencilFunc(GL_ALWAYS, 0x3333 & mask, ~0); piglit_draw_rect(0, 0, 1, 1); if (test == BLIT) glBlitFramebufferEXT(BUF_SIZE/2+1, BUF_SIZE/2+1, BUF_SIZE, BUF_SIZE, 0, 0, BUF_SIZE/2, BUF_SIZE/2, GL_STENCIL_BUFFER_BIT, GL_NEAREST); else glCopyPixels(BUF_SIZE/2+1, BUF_SIZE/2+1, BUF_SIZE/2, BUF_SIZE/2, GL_STENCIL); /* Initialize the other corners. */ glStencilFunc(GL_ALWAYS, 0x6666 & mask, ~0); piglit_draw_rect(0, -1, 1, 1); glStencilFunc(GL_ALWAYS, 0x9999 & mask, ~0); piglit_draw_rect(-1, 0, 1, 1); glStencilFunc(GL_ALWAYS, 0xbbbb & mask, ~0); piglit_draw_rect(0, 0, 1, 1); glDisable(GL_STENCIL_TEST); return compare_stencil(); }
enum piglit_result piglit_display(void) { GLboolean pass = GL_TRUE; static const float green[] = {0.0, 1.0, 0.0, 0.0}; static const float blue[] = {0.0, 0.0, 1.0, 0.0}; glClearColor(1.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glFogfv(GL_FOG_COLOR, green); piglit_draw_rect(-1, -1, 1, 2); glFogfv(GL_FOG_COLOR, blue); piglit_draw_rect(0, -1, 1, 2); pass &= piglit_probe_rect_rgba(0, 0, piglit_width / 2, piglit_height, green); pass &= piglit_probe_rect_rgba(piglit_width / 2, 0, piglit_width / 2, piglit_height, blue); glutSwapBuffers(); return pass ? PIGLIT_PASS : PIGLIT_FAIL; }
enum piglit_result piglit_display(void) { GLboolean pass = GL_TRUE; static float red[] = {1.0, 0.0, 0.0, 0.0}; static float green[] = {0.0, 1.0, 0.0, 0.0}; static float blue[] = {0.0, 0.0, 1.0, 0.0}; /* whole window gray -- none should be visible */ glClearColor(0.5, 0.5, 0.5, 0.0); glClear(GL_COLOR_BUFFER_BIT); /* Clear stencil to 0, which will be drawn green */ glClearStencil(0); glClear(GL_STENCIL_BUFFER_BIT); /* quad at 10, 10 that will be drawn blue. */ glEnable(GL_SCISSOR_TEST); glScissor(10, 10, 10, 10); glClearStencil(1); glClear(GL_STENCIL_BUFFER_BIT); /* 0-sized quad at 10, 30 that shouldn't be drawn (red) */ glScissor(10, 30, 0, 0); glClearStencil(2); glClear(GL_STENCIL_BUFFER_BIT); glDisable(GL_SCISSOR_TEST); glEnable(GL_STENCIL_TEST); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); /* First quad -- stencil == 0 gets green */ glStencilFunc(GL_EQUAL, 0, ~0); glColor4fv(green); piglit_draw_rect(0, 0, piglit_width, piglit_height); /* Second quad -- stencil == 1 gets blue */ glStencilFunc(GL_EQUAL, 1, ~0); glColor4fv(blue); piglit_draw_rect(0, 0, piglit_width, piglit_height); /* Last quad -- stencil == 2 gets red (shouldn't occur!) */ glStencilFunc(GL_EQUAL, 2, ~0); glColor4fv(red); piglit_draw_rect(0, 0, piglit_width, piglit_height); pass &= piglit_probe_rect_rgb(0, 0, piglit_width, 10, green); pass &= piglit_probe_rect_rgb(0, 10, 10, 10, green); pass &= piglit_probe_rect_rgb(10, 10, 10, 10, blue); pass &= piglit_probe_rect_rgb(20, 10, piglit_width-20, 10, green); pass &= piglit_probe_rect_rgb(0, 20, piglit_width, piglit_height - 20, green); glutSwapBuffers(); return pass ? PIGLIT_PASS : PIGLIT_FAIL; }
PIGLIT_GL_TEST_CONFIG_END enum piglit_result piglit_display(void) { static const char *vs_source = "#version 140\n" "in vec4 piglit_vertex;\n" "void main()\n" "{\n" " gl_Position = piglit_vertex;\n" "}\n"; static const char *fs_source = "#version 140\n" "uniform samplerBuffer s;\n" "void main()\n" "{\n" " gl_FragColor = texelFetch(s, 0);\n" "}\n"; bool pass = true; GLuint tex, bo; GLuint prog; float green[] = {0, 1, 0, 0}; float blue[] = {0, 0, 1, 0}; uint8_t g_rgba8[] = {0x00, 0xff, 0x00, 0x00}; uint8_t b_rgba8[] = {0x00, 0x00, 0xff, 0x00}; prog = piglit_build_simple_program(vs_source, fs_source); glUseProgram(prog); glGenBuffers(1, &bo); glBindBuffer(GL_TEXTURE_BUFFER, bo); /* Make the buffer bigger than the data to trigger the driver * code path we want. */ glBufferData(GL_TEXTURE_BUFFER, 4096, NULL, GL_STREAM_DRAW); glBufferSubData(GL_TEXTURE_BUFFER, 0, sizeof(g_rgba8), g_rgba8); glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_BUFFER, tex); glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA8, bo); piglit_draw_rect(-1, -1, 1, 2); glBufferSubData(GL_TEXTURE_BUFFER, 0, sizeof(b_rgba8), b_rgba8); piglit_draw_rect(0, -1, 1, 2); pass = pass && piglit_probe_rect_rgba(0, 0, piglit_width / 2, piglit_height, green); pass = pass && piglit_probe_rect_rgba(piglit_width / 2, 0, piglit_width / 2, piglit_height, blue); piglit_present_results(); return pass ? PIGLIT_PASS : PIGLIT_FAIL; }
/** * Common functionality needed by hiz_run_test_stencil_read_fbo() and * hiz_run_test_stencil_read_window(). */ static bool hiz_run_test_stencil_read_common() { static const float *expected_colors[9] = { hiz_grey, hiz_blue, hiz_grey, hiz_green, hiz_blue, hiz_grey, hiz_green, hiz_green, hiz_grey, }; static const unsigned expected_stencil[9] = { 4, 5, 4, 5, 6, 4, 5, 5, 3, }; const float dx = piglit_width / 3.0; const float dy = piglit_height / 3.0; /* Set up depth state. */ glDisable(GL_DEPTH_TEST); glClearDepth(hiz_clear_z); /* Set up stencil state. */ glEnable(GL_STENCIL_TEST); glClearStencil(3); /* 3 is a good canary. */ glStencilFunc(GL_LESS, 3, ~0); glStencilOp(GL_INCR, GL_INCR, GL_INCR); glClearColor(hiz_grey[0], hiz_grey[1], hiz_grey[2], hiz_grey[3]); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glViewport(0, 0, piglit_width, piglit_height); piglit_ortho_projection(piglit_width, piglit_height, false); /* Draw rect 1. */ glColor4fv(hiz_grey); piglit_draw_rect(0 * dx, 0 * dy, /* x, y */ 2 * dx, 3 * dy); /* w, h */ /* Draw rect 2. */ glColor4fv(hiz_green); piglit_draw_rect(0 * dx, 0 * dy, /* x, y */ 2 * dx, 2 * dy); /* w, h */ /* Draw rect 3. */ glColor4fv(hiz_blue); piglit_draw_rect(1 * dx, 1 * dy, /* x, y */ 2 * dx, 2 * dy); /* w, h */ if (!piglit_check_gl_error(0)) return false; if (!hiz_probe_color_buffer(expected_colors)) return false; return hiz_probe_stencil_buffer(expected_stencil); }
static GLuint create_texcube(void) { GLuint tex, fb; GLenum status; int layer; glGenTextures(1, &tex); glBindTexture(target, tex); glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); if (test_array) glTexStorage3D(target, TEX_LEVELS, format, TEX_SIZE, TEX_SIZE, num_layers); else glTexStorage2D(target, TEX_LEVELS, format, TEX_SIZE, TEX_SIZE); glGenFramebuffers(1, &fb); glBindFramebuffer(GL_FRAMEBUFFER, fb); for (layer = 0; layer < num_layers; layer++) { if (test_array) glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex, 0, layer); else glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer, tex, 0); status = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (status != GL_FRAMEBUFFER_COMPLETE) { load_texcube(); goto done; } glViewport(0, 0, TEX_SIZE, TEX_SIZE); piglit_ortho_projection(TEX_SIZE, TEX_SIZE, GL_FALSE); glColor4fv(colors[(layer + 0) % NUM_COLORS]); piglit_draw_rect(0, 0, TEX_HALF, TEX_HALF); glColor4fv(colors[(layer + 2) % NUM_COLORS]); piglit_draw_rect(TEX_HALF, 0, TEX_HALF, TEX_HALF); glColor4fv(colors[(layer + 4) % NUM_COLORS]); piglit_draw_rect(0, TEX_HALF, TEX_HALF, TEX_HALF); glColor4fv(colors[(layer + 6) % NUM_COLORS]); piglit_draw_rect(TEX_HALF, TEX_HALF, TEX_HALF, TEX_HALF); } done: glGenerateMipmap(target); glDeleteFramebuffers(1, &fb); return tex; }
static int create_fbo(void) { GLuint tex, fb; GLenum status; int i, dim; glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_2D, tex); for (i = 0, dim = TEX_WIDTH; dim >0; i++, dim /= 2) { glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA, dim, dim, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); } if (!piglit_check_gl_error(GL_NO_ERROR)) piglit_report_result(PIGLIT_FAIL); glGenFramebuffersEXT(1, &fb); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tex, 0); if (!piglit_check_gl_error(GL_NO_ERROR)) piglit_report_result(PIGLIT_FAIL); status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { fprintf(stderr, "FBO incomplete\n"); goto done; } glViewport(0, 0, TEX_WIDTH, TEX_HEIGHT); piglit_ortho_projection(TEX_WIDTH, TEX_HEIGHT, GL_FALSE); glColor4fv(red); piglit_draw_rect(0, 0, TEX_WIDTH / 2, TEX_HEIGHT / 2); glColor4fv(green); piglit_draw_rect(TEX_WIDTH / 2, 0, TEX_WIDTH, TEX_HEIGHT / 2); glColor4fv(blue); piglit_draw_rect(0, TEX_HEIGHT / 2, TEX_WIDTH/2, TEX_HEIGHT); glColor4fv(white); piglit_draw_rect(TEX_WIDTH / 2, TEX_HEIGHT / 2, TEX_WIDTH, TEX_HEIGHT); glScissor(10, 10, 10, 10); glEnable(GL_SCISSOR_TEST); glGenerateMipmapEXT(GL_TEXTURE_2D); glDisable(GL_SCISSOR_TEST); done: glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo); glDeleteFramebuffersEXT(1, &fb); return tex; }
static GLuint create_array_fbo_2d(void) { GLuint tex, fb; GLenum status; int i, dim; int layer; glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_2D_ARRAY_EXT, tex); if (!piglit_check_gl_error(GL_NO_ERROR)) piglit_report_result(PIGLIT_FAIL); for (i = 0, dim = TEX_WIDTH; dim >0; i++, dim /= 2) { glTexImage3D(GL_TEXTURE_2D_ARRAY_EXT, i, format, dim, dim, num_layers, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); } if (!piglit_check_gl_error(GL_NO_ERROR)) piglit_report_result(PIGLIT_FAIL); glGenFramebuffersEXT(1, &fb); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); for (layer = 0; layer < num_layers; layer++) { glFramebufferTextureLayer(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, tex, 0, layer); if (!piglit_check_gl_error(GL_NO_ERROR)) piglit_report_result(PIGLIT_FAIL); status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { load_texture_2d_array(); goto done; } glViewport(0, 0, TEX_WIDTH, TEX_HEIGHT); piglit_ortho_projection(TEX_WIDTH, TEX_HEIGHT, GL_FALSE); glColor4fv(layer_color[layer]); piglit_draw_rect(0, 0, TEX_WIDTH / 2, TEX_HEIGHT / 2); glColor4fv(green); piglit_draw_rect(TEX_WIDTH / 2, 0, TEX_WIDTH, TEX_HEIGHT / 2); glColor4fv(blue); piglit_draw_rect(0, TEX_HEIGHT / 2, TEX_WIDTH/2, TEX_HEIGHT); glColor4fv(white); piglit_draw_rect(TEX_WIDTH / 2, TEX_HEIGHT / 2, TEX_WIDTH, TEX_HEIGHT); } done: glGenerateMipmapEXT(GL_TEXTURE_2D_ARRAY_EXT); glDeleteFramebuffersEXT(1, &fb); return tex; }
static int create_fbo(void) { GLuint tex, copied_tex, fb; GLenum status; int i, dim; int draw_w = TEX_WIDTH / 2, draw_h = TEX_HEIGHT / 2; glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_2D, tex); for (i = 0, dim = TEX_WIDTH; dim >0; i++, dim /= 2) { glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA, dim, dim, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); } assert(glGetError() == 0); /* Draw into the second level. */ glGenFramebuffersEXT(1, &fb); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tex, 1); assert(glGetError() == 0); status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { fprintf(stderr, "FBO incomplete\n"); piglit_report_result(PIGLIT_SKIP); } glViewport(0, 0, draw_w, draw_h); piglit_ortho_projection(draw_w, draw_h, GL_FALSE); glColor4fv(red); piglit_draw_rect(0, 0, draw_w / 2, draw_h / 2); glColor4fv(green); piglit_draw_rect(draw_w / 2, 0, draw_w, draw_h / 2); glColor4fv(blue); piglit_draw_rect(0, draw_h / 2, draw_w/2, draw_h); glColor4fv(white); piglit_draw_rect(draw_w / 2, draw_h / 2, draw_w, draw_h); glGenTextures(1, &copied_tex); glBindTexture(GL_TEXTURE_2D, copied_tex); glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, draw_w, draw_h, 0); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo); glDeleteFramebuffersEXT(1, &fb); glDeleteTextures(1, &tex); return copied_tex; }
/* If multiple queries are issued on the same target and id prior to calling * GetQueryObject[u]iVARB, the result returned will always be from the last * query issued. The results from any queries before the last one will be lost * if the results are not retrieved before starting a new query on the same * target and id. */ static bool conformOQ_GetObjivAval_multi1(GLuint id) { GLint ready; GLuint passed = 0; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(-1.0, 1.0, -1.0, 1.0, 0.0, 25.0); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glTranslatef(0.0, 0.0, -10.0); /* draw the occluder (red) */ glColorMask(1, 1, 1, 1); glDepthMask(GL_TRUE); glColor3f(1, 0, 0); piglit_draw_rect(-0.5, 0.5, 0.5, -0.5); glPushMatrix(); glTranslatef(0.0, 0.0, -5.0); glColorMask(0, 0, 0, 0); glDepthMask(GL_FALSE); /* draw the 1st box (green) which is occluded by the occluder partly */ glBeginQueryARB(GL_SAMPLES_PASSED_ARB, id); glColor3f(0, 1, 0); piglit_draw_rect(-0.51, 0.51, 0.51, -0.51); glEndQueryARB(GL_SAMPLES_PASSED_ARB); /* draw the 2nd box (blue) which is occluded by the occluder throughly */ glBeginQueryARB(GL_SAMPLES_PASSED_ARB, id); glColor3f(0, 0, 1); piglit_draw_rect(-0.4, 0.4, 0.4, -0.4); glEndQueryARB(GL_SAMPLES_PASSED_ARB); glPopMatrix(); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); do { glGetQueryObjectivARB(id, GL_QUERY_RESULT_AVAILABLE_ARB, &ready); } while (!ready); glGetQueryObjectuivARB(id, GL_QUERY_RESULT_ARB, &passed); /* 'passed' should be zero */ return passed > 0 ? false : true; }
PIGLIT_GL_TEST_CONFIG_END static bool run_test(bool scissor_clear) { GLuint query; GLint result = -1; piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE); glClearColor(0.0, 1.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glGenQueries(1, &query); glBeginQuery(GL_SAMPLES_PASSED, query); /* Render 64 pixels. This should affect the query */ piglit_draw_rect(0, 0, 8, 8); /* Clear the framebuffer. This shouldn't affect the query */ glClearColor(0.0, 0.0, 1.0, 0.0); if (scissor_clear) { glScissor(0, 0, piglit_width / 2, piglit_height / 2); glEnable(GL_SCISSOR_TEST); } glClear(GL_COLOR_BUFFER_BIT); if (scissor_clear) { glDisable(GL_SCISSOR_TEST); } /* Render another 64 pixels. This should continue adding to * the query */ piglit_draw_rect(4, 0, 8, 8); glEndQuery(GL_SAMPLES_PASSED); glGetQueryObjectiv(query, GL_QUERY_RESULT, &result); glDeleteQueries(1, &query); piglit_present_results(); if (result != 128) { printf("Failure: \n"); printf(" Occlusion query resulted in %d samples " "(expected 128)\n", result); printf(" Scissor enabled? %s\n", scissor_clear ? "yes" : "no"); return false; } else { return true; } }
static int create_fbo(void) { GLuint tex, fb; GLenum status; int i, dim; glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_2D, tex); for (i = 0, dim = TEX_WIDTH; dim >0; i++, dim /= 2) { glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA, dim, dim, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); } assert(glGetError() == 0); glGenFramebuffersEXT(1, &fb); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tex, 0); assert(glGetError() == 0); status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { fprintf(stderr, "FBO incomplete\n"); goto done; } glViewport(0, 0, TEX_WIDTH, TEX_HEIGHT); piglit_ortho_projection(TEX_WIDTH, TEX_HEIGHT, GL_FALSE); glColor4fv(red); piglit_draw_rect(0, 0, TEX_WIDTH / 2, TEX_HEIGHT / 2); glColor4fv(green); piglit_draw_rect(TEX_WIDTH / 2, 0, TEX_WIDTH, TEX_HEIGHT / 2); glColor4fv(blue); piglit_draw_rect(0, TEX_HEIGHT / 2, TEX_WIDTH/2, TEX_HEIGHT); glColor4fv(white); piglit_draw_rect(TEX_WIDTH / 2, TEX_HEIGHT / 2, TEX_WIDTH, TEX_HEIGHT); /* Bind back to the (small) window to trigger the bug */ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo); glGenerateMipmapEXT(GL_TEXTURE_2D); done: glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo); glDeleteFramebuffersEXT(1, &fb); return tex; }
static int create_fbo(void) { GLuint tex, copied_tex, fb; GLenum status; glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_2D, tex); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEX_WIDTH, TEX_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); if (!piglit_check_gl_error(GL_NO_ERROR)) piglit_report_result(PIGLIT_FAIL); glGenFramebuffersEXT(1, &fb); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tex, 0); if (!piglit_check_gl_error(GL_NO_ERROR)) piglit_report_result(PIGLIT_FAIL); status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { fprintf(stderr, "FBO incomplete\n"); piglit_report_result(PIGLIT_SKIP); } glViewport(0, 0, TEX_WIDTH, TEX_HEIGHT); piglit_ortho_projection(TEX_WIDTH, TEX_HEIGHT, GL_FALSE); glColor4fv(red); piglit_draw_rect(0, 0, TEX_WIDTH / 2, TEX_HEIGHT / 2); glColor4fv(green); piglit_draw_rect(TEX_WIDTH / 2, 0, TEX_WIDTH, TEX_HEIGHT / 2); glColor4fv(blue); piglit_draw_rect(0, TEX_HEIGHT / 2, TEX_WIDTH/2, TEX_HEIGHT); glColor4fv(white); piglit_draw_rect(TEX_WIDTH / 2, TEX_HEIGHT / 2, TEX_WIDTH, TEX_HEIGHT); glGenTextures(1, &copied_tex); glBindTexture(GL_TEXTURE_2D, copied_tex); glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, TEX_WIDTH, TEX_HEIGHT, 0); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo); glDeleteFramebuffersEXT(1, &fb); glDeleteTextures(1, &tex); return copied_tex; }
enum piglit_result piglit_display(void) { static const float green[3] = { 0.0, 1.0, 0.0 }; static const float blue[3] = { 0.0, 0.0, 1.0 }; enum piglit_result result = PIGLIT_PASS; float x = 10.0; glClear(GL_COLOR_BUFFER_BIT); glColor3fv(blue); /* Bind the separately linked vertex shader and the separately linked * fragment shader using the new interfaces. This should produce a * green box. */ glUseShaderProgramEXT(GL_VERTEX_SHADER, prog[0]); glUseShaderProgramEXT(GL_FRAGMENT_SHADER, prog[1]); piglit_draw_rect(x, 10, 10, 10); if (!piglit_probe_pixel_rgb(x + 5, 15, green)) result = PIGLIT_FAIL; x += 20.0; /* Bind the vertex shader that is already linked with a fragment * shader and the separately linked fragment shader using the new * interfaces. This should produce a green box. * * If the linked optimized away the vertex shader writes to * gl_FrontColor (because the fragment shader in prog[2] does not use * it), this will produce incorrect results. */ glUseProgram(prog[2]); glUseShaderProgramEXT(GL_FRAGMENT_SHADER, prog[1]); piglit_draw_rect(x, 10, 10, 10); if (!piglit_probe_pixel_rgb(x + 5, 15, green)) result = PIGLIT_FAIL; x += 20.0; /* Unbind any program from the vertex shader stage so that fixed * function is used. This should produce the same results as the * vertex shader except that fixed-function outputs blue. */ glUseShaderProgramEXT(GL_VERTEX_SHADER, 0); piglit_draw_rect(x, 10, 10, 10); if (!piglit_probe_pixel_rgb(x + 5, 15, blue)) result = PIGLIT_FAIL; if (!piglit_automatic) glutSwapBuffers(); return result; }
static GLuint create_array_fbo_1d(void) { GLuint tex, fb; GLenum status; int i, dim; int layer; if (format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT) return 0; glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_1D_ARRAY_EXT, tex); assert(glGetError() == 0); for (i = 0, dim = TEX_WIDTH; dim >0; i++, dim /= 2) { glTexImage2D(GL_TEXTURE_1D_ARRAY_EXT, i, format, dim, num_layers, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); } assert(glGetError() == 0); glGenFramebuffersEXT(1, &fb); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); for (layer = 0; layer < num_layers; layer++) { glFramebufferTextureLayer(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, tex, 0, layer); assert(glGetError() == 0); status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { load_texture_1d_array(); goto done; } glViewport(0, 0, TEX_WIDTH, 1); piglit_ortho_projection(TEX_WIDTH, 1, GL_FALSE); glColor4fv(layer_color[layer]); piglit_draw_rect(0, 0, TEX_WIDTH / 2, 1); glColor4fv(layer_color[(layer + 1) % 4]); piglit_draw_rect(TEX_WIDTH / 2, 0, TEX_WIDTH, 1); } done: glDeleteFramebuffersEXT(1, &fb); glGenerateMipmapEXT(GL_TEXTURE_1D_ARRAY_EXT); return tex; }
static void blend(const float *src, const float *src1, const float *dst, GLenum blendsrc, GLenum blenddst, GLenum blendop) { glUniform4fv(uniform_src0, 1, dst); piglit_draw_rect(0, 0, piglit_width, piglit_height); glEnable(GL_BLEND); glBlendEquation(blendop); glBlendFunc(blendsrc, blenddst); glUniform4fv(uniform_src0, 1, src); glUniform4fv(uniform_src1, 1, src1); piglit_draw_rect(0, 0, piglit_width, piglit_height); glDisable(GL_BLEND); }
PIGLIT_GL_TEST_CONFIG_END enum piglit_result piglit_display(void) { bool pass = true; float green[4] = {0.0, 1.0, 0.0, 0.0}; GLuint q; GLuint list; list = glGenLists(1); glNewList(list, GL_COMPILE); glClearColor(0.5, 0.5, 0.5, 0.5); glClear(GL_COLOR_BUFFER_BIT); glGenQueries(1, &q); /* Generate query pass: draw bottom half of screen. */ glColor4f(0.0, 1.0, 0.0, 0.0); glBeginQuery(GL_SAMPLES_PASSED, q); piglit_draw_rect(-1, -1, 2, 1); glEndQuery(GL_SAMPLES_PASSED); /* Conditional render that should draw top half of screen. */ glBeginConditionalRenderNV(q, GL_QUERY_WAIT_NV); piglit_draw_rect(-1, 0, 2, 1); glEndConditionalRenderNV(); /* Generate query fail */ glBeginQuery(GL_SAMPLES_PASSED, q); glEndQuery(GL_SAMPLES_PASSED); /* Conditional render that should not draw full screen. */ glBeginConditionalRenderNV(q, GL_QUERY_WAIT_NV); glColor4f(1.0, 0.0, 0.0, 0.0); piglit_draw_rect(-1, -1, 2, 2); glEndConditionalRenderNV(); glEndList(); glCallList(list); pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, green); piglit_present_results(); glDeleteQueries(1, &q); return pass ? PIGLIT_PASS : PIGLIT_FAIL; }
PIGLIT_GL_TEST_CONFIG_END static void blend(const float *rect, const float *src, const float *dst, const float *blendcol, GLenum blendsrc, GLenum blenddst) { glColor4fv(dst); piglit_draw_rect(rect[0], rect[1], rect[2], rect[3]); glEnable(GL_BLEND); glBlendFunc(blendsrc, blenddst); if (blendcol) glBlendColor(blendcol[0], blendcol[1], blendcol[2], blendcol[3]); glColor4fv(src); piglit_draw_rect(rect[0], rect[1], rect[2], rect[3]); glDisable(GL_BLEND); }
static void * thread2_func(void *arg) { get_lock_for_step(2); glXMakeCurrent(dpy, win, ctx); glColor4f(0.0, 1.0, 0.0, 1.0); piglit_draw_rect(30, 10, 10, 10); pthread_mutex_unlock(&mutex); get_lock_for_step(4); piglit_draw_rect(50, 10, 10, 10); pthread_mutex_unlock(&mutex); return NULL; }
static int create_1d_fbo(void) { GLuint tex, fb; GLenum status; glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_1D, tex); glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, BUF_WIDTH, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); assert(glGetError() == 0); glGenFramebuffersEXT(1, &fb); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); glFramebufferTexture1DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_1D, tex, 0); assert(glGetError() == 0); status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { fprintf(stderr, "FBO incomplete\n"); goto done; } glViewport(0, 0, BUF_WIDTH, 1); piglit_ortho_projection(BUF_WIDTH, 1, GL_FALSE); /* left side: red */ glColor4f(1.0, 0.0, 0.0, 0.0); piglit_draw_rect(0, 0, BUF_WIDTH / 2, 1); /* right side: green */ glColor4f(0.0, 1.0, 0.0, 0.0); piglit_draw_rect(BUF_WIDTH / 2, 0, BUF_WIDTH, 1); done: glDeleteFramebuffersEXT(1, &fb); return tex; }
static enum piglit_result test_drawpixels(void) { int x, y; GLushort drawbuf[BUF_SIZE*BUF_SIZE]; for (y = 0; y < BUF_SIZE; y++) { for (x = 0; x < BUF_SIZE; x++) { if (y < BUF_SIZE/2) drawbuf[y*BUF_SIZE+x] = (x < BUF_SIZE/2 ? ~0x3333 : ~0x6666) & mask; else drawbuf[y*BUF_SIZE+x] = (x < BUF_SIZE/2 ? ~0x9999 : ~0xbbbb) & mask; } } /* Clear stencil to 0xfe. */ glClearStencil(0xfefe); glClear(GL_STENCIL_BUFFER_BIT); /* Draw pixels. */ glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glDrawPixels(BUF_SIZE, BUF_SIZE, GL_STENCIL_INDEX, GL_UNSIGNED_SHORT, drawbuf); /* Invert bits. */ glEnable(GL_STENCIL_TEST); glStencilOp(GL_KEEP, GL_KEEP, GL_INVERT); piglit_draw_rect(-1, -1, 2, 2); glDisable(GL_STENCIL_TEST); return compare_stencil(); }
/** * Helper function to draw a quad and check the results for divX*divY areas * on the screen. */ static bool draw_check_pixels(void) { bool pass = true; int i, j; GLfloat w = (GLfloat) piglit_width / (GLfloat) divX; GLfloat h = (GLfloat) piglit_height / (GLfloat) divY; /* draw single quad, expanded to divX*divY quads via geometry shader */ piglit_draw_rect(-1, -1, 2, 2); piglit_present_results(); /* check rendering results: greyscale RGB == 1.0 / (index +1)*/ for (i = 0; i < divX; i++) { for (j = 0; j < divY; j++) { GLfloat expected[4]; int p; expected[0] = expected[1] = expected[2] = 1.0 / (GLfloat) (1 + j + i*divY); expected[3] = 1.0; p = piglit_probe_rect_rgba(i * w + 1, j * h + 1, w-2, h-2, expected); if (!p) { printf("Wrong color for viewport i,j %d %d\n", i, j); pass = false; } } } return pass; }
enum piglit_result piglit_display(void) { static const float gray[] = { 0.5, 0.5, 0.5, 1.0 }; static const float green[] = { 0.0, 1.0, 0.0, 0.0 }; static const float red[] = { 1.0, 0.0, 0.0, 0.0 }; bool pass = true; glProgramUniform4fv(vs, loc_vs, 1, red); glProgramUniform4fv(fs, loc_fs, 1, green); glClearColor(gray[0], gray[1], gray[2], gray[3]); glClear(GL_COLOR_BUFFER_BIT); piglit_draw_rect(-1, -1, 1, 2); pass = piglit_probe_rect_rgb(0, 0, piglit_width / 2, piglit_height, gray) && pass; pass = piglit_probe_rect_rgb(piglit_width / 2, 0, piglit_width / 2, piglit_height, green) && pass; piglit_present_results(); pass = piglit_check_gl_error(0) && pass; return pass ? PIGLIT_PASS : PIGLIT_FAIL; }
enum piglit_result piglit_display(void) { static const GLfloat color[4] = { 0.0, 1.0, 0.0, 0.0 }; enum piglit_result result = PIGLIT_PASS; unsigned i; glClear(GL_COLOR_BUFFER_BIT); glEnable(GL_FRAGMENT_PROGRAM_ARB); glEnable(GL_VERTEX_PROGRAM_ARB); glColor4f(1.0, 0.6, 0.3, 0.1); glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vert_prog); for (i = 0; i < ARRAY_SIZE(progs); i++) { const int x = 1 + (i * (BOX_SIZE + 1)); glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, progs[i]); piglit_draw_rect(x, 1, BOX_SIZE, BOX_SIZE); if (!piglit_probe_pixel_rgb(x + (BOX_SIZE / 2), 1 + (BOX_SIZE / 2), color)) { result = PIGLIT_FAIL; } } glutSwapBuffers(); return result; }
PIGLIT_GL_TEST_CONFIG_END enum piglit_result piglit_display(void) { static GLboolean logged = GL_FALSE; GLboolean pass = GL_TRUE; GLenum err; glClearColor(0.5, 0.5, 0.5, 0.0); glClear(GL_COLOR_BUFFER_BIT); piglit_draw_rect(-1.0, -1.0, 2.0, 2.0); err = glGetError(); if (err != GL_INVALID_OPERATION) { if (!logged) { printf("Unexpected OpenGL error state 0x%04x with bad " "vertex program at draw (expected 0x%04x).\n", err, GL_INVALID_OPERATION); logged = GL_TRUE; } pass = GL_FALSE; } return pass ? PIGLIT_PASS : PIGLIT_FAIL; }
enum piglit_result piglit_display(void) { static const float green[3] = { 0.0, 1.0, 0.0 }; static const float blue[3] = { 0.0, 0.0, 1.0 }; enum piglit_result result = PIGLIT_PASS; glClear(GL_COLOR_BUFFER_BIT); glColor3fv(blue); /* Bind the separately linked vertex shader and the separately linked * fragment shader using the new interfaces. This should produce a * green box. */ glUseShaderProgramEXT(GL_VERTEX_SHADER, prog[0]); glUseShaderProgramEXT(GL_FRAGMENT_SHADER, prog[1]); piglit_draw_rect(10, 10, 10, 10); if (!piglit_probe_pixel_rgb(15, 15, green)) result = PIGLIT_FAIL; if (!piglit_automatic) piglit_present_results(); return result; }
PIGLIT_GL_TEST_CONFIG_END enum piglit_result piglit_display(void) { bool pass = true; float green[4] = {0.0, 1.0, 0.0, 0.0}; /* Clear red. */ glClearColor(1.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); /* Draw top half of screen green. */ glColor4f(0.0, 1.0, 0.0, 0.0); piglit_draw_rect(-1, 0, 2, 1); /* Discard a copy over the bottom red over the top green. */ glEnable(GL_RASTERIZER_DISCARD); glRasterPos2i(-1, 0); glCopyPixels(0, 0, piglit_width, piglit_height / 2, GL_COLOR); /* Don't discard a copy of the green over the remaining red. */ glDisable(GL_RASTERIZER_DISCARD); glRasterPos2i(-1, -1); glCopyPixels(0, piglit_height / 2, piglit_width, piglit_height / 2, GL_COLOR); pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, green); piglit_present_results(); return pass ? PIGLIT_PASS : PIGLIT_FAIL; }