2 * Copyright © 2012 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27 * Verify that the implementation produces correct values for the GLSL
28 * dFdx() and dFdy() functions, both in fbos and in the default
31 * Note: the reason that we test both fbos and the default framebuffer
32 * in the same test is that some implementations (e.g. Mesa/i965) need
33 * to compile the dFdy() function differently depending whether we are
34 * rendering to an FBO or to the default framebuffer; testing both in
35 * the same test allows us to verify that the implementation
36 * recompiles the shader if necessary.
38 * This test draws a pair of squares in which dFdx and dFdy are
39 * expected to both be 1.0. It colors the rectangles red=0.5*dFdx and
40 * green=0.5*dFdy, so the expected color is (0.5, 0.5, 0, 0). The
41 * left rectangle is drawn in the default framebuffer; the right
42 * rectangle is drawn in an FBO and then blitted to the default
46 #include "piglit-util-gl.h"
48 PIGLIT_GL_TEST_CONFIG_BEGIN
50 config
.supports_gl_compat_version
= 10;
52 config
.window_width
= 256;
53 config
.window_height
= 128;
54 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGB
;
55 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
57 PIGLIT_GL_TEST_CONFIG_END
59 static const int fbo_width
= 128, fbo_height
= 128;
64 static const char *vert
=
67 " gl_Position = gl_Vertex;\n"
70 static const char *frag
=
73 " gl_FragColor = vec4(0.5*dFdx(gl_FragCoord.x),\n"
74 " 0.5*dFdy(gl_FragCoord.y), 0.0, 0.0);\n"
83 glGenRenderbuffers(1, &rb
);
84 glBindRenderbuffer(GL_RENDERBUFFER
, rb
);
85 glRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA
, fbo_width
, fbo_height
);
86 glGenFramebuffers(1, &fbo
);
87 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, fbo
);
88 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
,
90 status
= glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT
);
92 if (!piglit_check_gl_error(GL_NO_ERROR
))
93 piglit_report_result(PIGLIT_FAIL
);
96 case GL_FRAMEBUFFER_UNSUPPORTED
:
97 printf("Framebuffer unsupported\n");
98 piglit_report_result(PIGLIT_SKIP
);
100 case GL_FRAMEBUFFER_COMPLETE
:
103 printf("Framebuffer incomplete\n");
104 piglit_report_result(PIGLIT_FAIL
);
110 piglit_init(int argc
, char **argv
)
114 piglit_require_gl_version(20);
115 piglit_require_extension("GL_ARB_framebuffer_object");
117 vs
= piglit_compile_shader_text(GL_VERTEX_SHADER
, vert
);
118 fs
= piglit_compile_shader_text(GL_FRAGMENT_SHADER
, frag
);
119 prog
= piglit_link_simple_program(vs
, fs
);
127 float expected
[3] = { 0.5, 0.5, 0.0 };
128 GLboolean pass
= GL_TRUE
;
132 /* Draw a square to the left half of the window */
133 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, piglit_winsys_fbo
);
134 glViewport(0, 0, piglit_width
, piglit_height
);
135 piglit_draw_rect(-1, -1, 1, 2);
137 /* Draw a square to the FBO */
138 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, fbo
);
139 glViewport(0, 0, fbo_width
, fbo_height
);
140 piglit_draw_rect(-1, -1, 2, 2);
142 /* Blit the square from the FBO to the right half of the window */
143 glBindFramebuffer(GL_READ_FRAMEBUFFER
, fbo
);
144 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, piglit_winsys_fbo
);
145 glBlitFramebuffer(0, 0, fbo_width
, fbo_height
,
146 piglit_width
/2, 0, piglit_width
, piglit_height
,
147 GL_COLOR_BUFFER_BIT
, GL_NEAREST
);
149 /* Check that both squares have the correct color */
150 glBindFramebuffer(GL_READ_FRAMEBUFFER
, piglit_winsys_fbo
);
151 pass
= piglit_probe_rect_rgb(0, 0, piglit_width
, piglit_height
,
154 piglit_present_results();
156 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;