static void
test_depth24(EGLDisplay dpy, EGLContext ctx)
{
	const float depth1 = 0.25;
	const float depth2 = 0.75;

	bool pass = true;
	GLuint fb1, fb2;

	create_framebuffers(dpy, ctx, &fb1, &fb2, GL_DEPTH_COMPONENT24);

	/* Clear rb1 to depth1. Check that rb2 has depth1. */
	glBindFramebuffer(GL_FRAMEBUFFER, fb1);
	glClearBufferfv(GL_DEPTH, 0, &depth1);
	glBindFramebuffer(GL_FRAMEBUFFER, fb2);
	pass &= piglit_probe_rect_depth(0, 0, width, height, depth1);
	pass &= piglit_check_gl_error(GL_NO_ERROR);

	/* Clear rb2 to depth2. Check that rb1 has depth2. */
	glBindFramebuffer(GL_FRAMEBUFFER, fb2);
	glClearBufferfv(GL_DEPTH, 0, &depth2);
	glBindFramebuffer(GL_FRAMEBUFFER, fb1);
	pass &= piglit_probe_rect_depth(0, 0, width, height, depth2);
	pass &= piglit_check_gl_error(GL_NO_ERROR);

	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
}
void
piglit_init(int argc, char **argv)
{
	GLuint tex;
	GLuint fb;
	GLenum status;
	bool pass;

	piglit_require_extension("GL_ARB_framebuffer_object");
	piglit_require_extension("GL_ARB_ES2_compatibility");

	/* Create a depth-only FBO.
	 */
	glGenTextures(1, &tex);
	glBindTexture(GL_TEXTURE_2D, tex);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 32, 32, 0,
		     GL_DEPTH_COMPONENT, GL_FLOAT, NULL);

	glGenFramebuffers(1, &fb);
	glBindFramebuffer(GL_FRAMEBUFFER, fb);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
			       GL_TEXTURE_2D, tex, 0);

	if (!piglit_check_gl_error(GL_NO_ERROR))
		piglit_report_result(PIGLIT_FAIL);

	status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
	if (status != GL_FRAMEBUFFER_COMPLETE) {
		fprintf(stderr, "FBO erroneously incomplete: 0x%04x\n",
			status);
		piglit_report_result(PIGLIT_FAIL);
	}

	/* Clear the depth buffer to a known value.
	 */
	printf("Clearing depth buffer to 0.0...\n");
	glClearDepth(0.0);
	glClear(GL_DEPTH_BUFFER_BIT);
	pass = piglit_probe_rect_depth(0, 0, piglit_width, piglit_height, 0.0);

	/* Clear the depth buffer and the color buffer to different values.
	 */
	printf("Clearing depth buffer to 0.5...\n");
	glClearDepth(0.5);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	pass = piglit_probe_rect_depth(0, 0, piglit_width, piglit_height, 0.5)
		&& pass;

	if (!piglit_check_gl_error(GL_NO_ERROR))
		piglit_report_result(PIGLIT_FAIL);

	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
}
Example #3
0
bool
probe_texture_layered_depth(GLuint texture, int x, int y, int z,
			    int w, int h, int d, float *expected)
{
	GLint prev_read_fbo;
	GLint prev_draw_fbo;

	GLuint fbo;
	int k;

	glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &prev_draw_fbo);
	glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &prev_read_fbo);

	glGenFramebuffers(1, &fbo);
	glBindFramebuffer(GL_FRAMEBUFFER, fbo);

	for(k = 0; k < d; k++ ) {
		glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
					  texture, 0, k+z);

		if (!piglit_probe_rect_depth(x, y, w, h, expected[k])) {
			printf("Layer: %i\n", z + k);
			return false;
		}
	}

	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, prev_draw_fbo);
	glBindFramebuffer(GL_READ_FRAMEBUFFER, prev_read_fbo);

	glDeleteFramebuffers(1, &fbo);
	return true;
}
static GLboolean
verify_depth_rect(int start_x, int start_y, int w, int h)
{
	float zero  = 0;
	float darkgrey = 0.3;
	float grey  = 0.6;
	float one = 1;

	if (!piglit_probe_rect_depth(start_x, start_y, w / 2, h / 2, zero))
		return GL_FALSE;
	if (!piglit_probe_rect_depth(start_x + w/2, start_y, w/2, h/2, darkgrey))
		return GL_FALSE;
	if (!piglit_probe_rect_depth(start_x, start_y + h/2, w/2, h/2, grey))
		return GL_FALSE;
	if (!piglit_probe_rect_depth(start_x + w/2, start_y + h/2, w/2, h/2, one))
		return GL_FALSE;

	return GL_TRUE;
}
Example #5
0
enum piglit_result
test_clearing(void)
{
   static const GLfloat purple[] = {1.0, 0.0, 1.0};
   static const GLfloat blue[] = {0.0, 0.0, 1.0};
   static const GLfloat green[] = {0.0, 1.0, 0.0};
   GLenum err;
   GLboolean pass = GL_TRUE;

   while (glGetError() != GL_NO_ERROR)
      ;

   /* Front buffer. */
   glDrawBuffer(GL_FRONT);
   glClearBufferfv(GL_COLOR, 0, purple);
   err = glGetError();
   if (err) {
      printf("%s: glClearBufferfv(GL_FRONT) generated error 0x%x.\n", Prog, err);
      return PIGLIT_FAIL;
   }

   glReadBuffer(GL_FRONT);
   if (!piglit_probe_rect_rgb(0, 0, piglit_width, piglit_height, purple)) {
      printf("  from glClearBufferfv(GL_FRONT) failed.\n");
      pass = GL_FALSE;
   }

   /* Back buffer. */
   glDrawBuffer(GL_BACK);
   glClearBufferfv(GL_COLOR, 0, blue);
   err = glGetError();
   if (err) {
      printf("%s: glClearBufferfv(GL_BACK) generated error 0x%x.\n", Prog, err);
      return PIGLIT_FAIL;
   }

   glReadBuffer(GL_BACK);
   if (!piglit_probe_rect_rgb(0, 0, piglit_width, piglit_height, blue)) {
      printf("  from glClearBufferfv(GL_BACK) failed.\n");
      pass = GL_FALSE;
   }

   /* Front and back buffer. */
   glDrawBuffer(GL_FRONT_AND_BACK);
   glClearBufferfv(GL_COLOR, 0, green);
   err = glGetError();
   if (err) {
      printf("%s: glClearBufferfv(GL_FRONT_AND_BACK) generated error 0x%x.\n", Prog, err);
      return PIGLIT_FAIL;
   }

   glReadBuffer(GL_FRONT);
   if (!piglit_probe_rect_rgb(0, 0, piglit_width, piglit_height, green)) {
      printf("  the front buffer from glClearBufferfv(GL_FRONT_AND_BACK) failed.\n");
      pass = GL_FALSE;
   }

   glReadBuffer(GL_BACK);
   if (!piglit_probe_rect_rgb(0, 0, piglit_width, piglit_height, green)) {
      printf("  the back buffer from glClearBufferfv(GL_FRONT_AND_BACK) failed.\n");
      pass = GL_FALSE;
   }

   /* Depth & Stencil */
   glClearBufferfi(GL_DEPTH_STENCIL, 0, 0.5, 3);
   err = glGetError();
   if (err) {
      printf("%s: glClearBufferfi() generated error 0x%x.\n", Prog, err);
      return PIGLIT_FAIL;
   }

   if (!piglit_probe_rect_depth(0, 0, piglit_width, piglit_height, 0.5)) {
      printf("  from glClearBufferfi() failed.\n");
      pass = GL_FALSE;
   }

   if (!piglit_probe_rect_stencil(0, 0, piglit_width, piglit_height, 3)) {
      printf("  from glClearBufferfi() failed.\n");
      pass = GL_FALSE;
   }

   return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
bool
do_blit_test(bool use_es2, bool from_missing_to_complete)
{
    GLuint rb[3];
    GLuint fb[2];
    GLenum status;
    GLenum err;
    const unsigned src = from_missing_to_complete ? 0 : 1;
    const unsigned dst = 1 - src;
    const char *const names[] = {
        "buffer with missing attachment",
        "complete buffer"
    };
    bool pass = true;

    printf("Testing blit from %s to %s...\n", names[src], names[dst]);

    /* Create a depth-only FBO and a depth/color FBO.
     */
    glGenRenderbuffers(ARRAY_SIZE(rb), rb);

    glBindRenderbuffer(GL_RENDERBUFFER, rb[0]);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24,
                          piglit_width, piglit_height);
    glBindRenderbuffer(GL_RENDERBUFFER, rb[1]);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24,
                          piglit_width, piglit_height);
    glBindRenderbuffer(GL_RENDERBUFFER, rb[2]);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA,
                          piglit_width, piglit_height);

    glGenFramebuffers(ARRAY_SIZE(fb), fb);
    glBindFramebuffer(GL_FRAMEBUFFER, fb[0]);
    glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
                              GL_RENDERBUFFER, rb[0]);
    if (!use_es2) {
        glDrawBuffer(GL_NONE);
        glReadBuffer(GL_NONE);
    }

    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fb[1]);
    glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
                              GL_RENDERBUFFER, rb[1]);
    glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                              GL_RENDERBUFFER, rb[2]);

    err = glGetError();
    if (err != 0) {
        fprintf(stderr, "Unexpected GL error state 0x%04x\n", err);
        return false;
    }

    /* Check completeness of the source surface.
     */
    glBindFramebuffer(GL_READ_FRAMEBUFFER, fb[src]);
    status = glCheckFramebufferStatus(GL_READ_FRAMEBUFFER);
    if (status != GL_FRAMEBUFFER_COMPLETE) {
        fprintf(stderr, "Read FBO erroneously incomplete: 0x%04x\n",
                status);
        return false;
    }

    /* In the source surface, clear the depth buffer and draw a single
     * rectangle with a constant depth value.  The depth test setting here
     * is correct.
     */
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fb[src]);
    glClearDepth(0.0);
    glClear(GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_ALWAYS);

    piglit_draw_rect_z(0.5, -0.5, -0.5, 1.0, 1.0);

    /* Check completeness of the destination surface.
     */
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fb[dst]);
    status = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER);

    if (status != GL_FRAMEBUFFER_COMPLETE) {
        fprintf(stderr, "Draw FBO erroneously incomplete: 0x%04x\n",
                status);
        return false;
    }

    glBlitFramebuffer(0, 0, piglit_width, piglit_height,
                      0, 0, piglit_width, piglit_height,
                      GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT,
                      GL_NEAREST);
    err = glGetError();
    if (err != 0) {
        fprintf(stderr, "Unexpected GL error state 0x%04x\n", err);
        return false;
    }

    /* Probe depth values from the destination buffer to make sure the
     * depth part of the blit actually happened.
     */
    glBindFramebuffer(GL_READ_FRAMEBUFFER, fb[dst]);
    pass = piglit_probe_rect_depth(0.25 * piglit_width,
                                   0.25 * piglit_height,
                                   0.4 * piglit_width,
                                   0.4 * piglit_height,
                                   0.75);
    pass = piglit_probe_rect_depth(0,
                                   0,
                                   piglit_width,
                                   0.2 * piglit_height,
                                   0.0)
           && pass;

    glBindFramebuffer(GL_READ_FRAMEBUFFER, piglit_winsys_fbo);
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
    glDeleteFramebuffers(ARRAY_SIZE(fb), fb);
    glDeleteRenderbuffers(ARRAY_SIZE(rb), rb);

    return pass;
}
Example #7
0
PIGLIT_GL_TEST_CONFIG_END

enum piglit_result
piglit_display(void)
{
	GLint i, j;
	GLuint width = 16, height = 16;
	GLint x = 12, y = 12;
	GLfloat buf[IMAGE_WIDTH][IMAGE_HEIGHT];
	GLfloat depth_val = 0.75, stencil_val = 2.0;
	GLfloat green[4] = {0.0, 1.0, 0.0, 0.0};
	bool pass = true;

	glClearColor(0.0, 0.0, 0.0, 1.0);
	glClear(GL_COLOR_BUFFER_BIT);

	glColor4fv(green);
	piglit_draw_rect(0, 0, width, height);

	glRasterPos2i(x, y);
	glCopyPixels(0, 0, width, height, GL_COLOR);
	pass = pass && piglit_probe_rect_rgba(x, y, width, height, green);

	/* Initialize depth data */
	for (i = 0; i < IMAGE_HEIGHT; i++) {
		for(j = 0; j < IMAGE_WIDTH; j++)
			buf[i][j] = depth_val;
	}

	glClearDepth(0.0);
	glClear(GL_DEPTH_BUFFER_BIT);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_ALWAYS);

	glRasterPos2i(0, 0);
	glDrawPixels(width, height,
		     GL_DEPTH_COMPONENT, GL_FLOAT, buf);
	glRasterPos2i(x, y);
	glCopyPixels(0, 0, width, height, GL_DEPTH);
	pass = piglit_probe_rect_depth(x, y, width, height, depth_val)
	       && pass;

	/* Initialize stencil data */
	for (i = 0; i < IMAGE_HEIGHT; i++) {
		for(j = 0; j < IMAGE_WIDTH; j++)
			buf[i][j] = stencil_val;
	}

	glClearStencil(0.0);
	glClear(GL_STENCIL_BUFFER_BIT);

	glRasterPos2i(0, 0);
	glDrawPixels(width, height,
		     GL_STENCIL_INDEX, GL_FLOAT, buf);
	glRasterPos2i(x, y);
	glCopyPixels(0, 0, width, height, GL_STENCIL);
	pass = piglit_probe_rect_stencil(x, y, width, height, stencil_val)
	       && pass;

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}