2 * Copyright © 2010 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
24 /** @file glsl-fs-fragcoord.c
26 * Tests that gl_FragCoord produces the expected output in a fragment shader.
29 #include "piglit-util-gl.h"
34 PIGLIT_GL_TEST_CONFIG_BEGIN
36 config
.supports_gl_compat_version
= 10;
38 config
.window_width
= WIDTH
;
39 config
.window_height
= HEIGHT
;
40 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DOUBLE
;
41 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
43 PIGLIT_GL_TEST_CONFIG_END
48 create_fbo(unsigned width
, unsigned height
, GLuint
*out_tex
)
53 GLenum internal_format
= GL_RGBA
;
55 glGenTextures(1, &tex
);
56 glBindTexture(GL_TEXTURE_2D
, tex
);
57 glTexImage2D(GL_TEXTURE_2D
, 0, internal_format
, width
, height
,
58 0, GL_RGBA
, GL_UNSIGNED_BYTE
, NULL
);
59 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
60 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
61 if (!piglit_check_gl_error(GL_NO_ERROR
))
62 piglit_report_result(PIGLIT_FAIL
);
64 glGenFramebuffersEXT(1, &fb
);
65 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, fb
);
66 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT
, GL_COLOR_ATTACHMENT0_EXT
,
67 GL_TEXTURE_2D
, tex
, 0);
68 if (!piglit_check_gl_error(GL_NO_ERROR
))
69 piglit_report_result(PIGLIT_FAIL
);
71 status
= glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT
);
72 if (status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
73 if (status
== GL_FRAMEBUFFER_UNSUPPORTED_EXT
)
74 printf("FBO with 0x%04x texture is unsupported\n",
77 fprintf(stderr
, "FBO with 0x%04x texture is incomplete"
79 internal_format
, status
);
81 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, piglit_winsys_fbo
);
82 glDeleteFramebuffersEXT(1, &fb
);
83 glDeleteTextures(1, &tex
);
84 piglit_report_result((status
== GL_FRAMEBUFFER_UNSUPPORTED_EXT
)
85 ? PIGLIT_SKIP
: PIGLIT_FAIL
);
98 /* Draw the shader to the fbo. */
99 fb
= create_fbo(WIDTH
, HEIGHT
, &tex
);
100 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, fb
);
101 glViewport(0, 0, WIDTH
, HEIGHT
);
103 glClearColor(1.0, 0.0, 0.0, 0.0);
104 glClear(GL_COLOR_BUFFER_BIT
);
107 piglit_draw_rect(-1, -1, 2, 2);
109 /* Draw the FBO to the screen. */
110 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, piglit_winsys_fbo
);
111 glViewport(0, 0, piglit_width
, piglit_height
);
113 glClearColor(0.0, 0.0, 1.0, 0.0);
114 glClear(GL_COLOR_BUFFER_BIT
);
116 glBindTexture(GL_TEXTURE_2D
, tex
);
117 glEnable(GL_TEXTURE_2D
);
119 piglit_draw_rect_tex(-1, -1, 2, 2,
122 glDisable(GL_TEXTURE_2D
);
123 glDeleteTextures(1, &tex
);
124 glDeleteFramebuffersEXT(1, &fb
);
126 if (!piglit_check_gl_error(GL_NO_ERROR
))
127 piglit_report_result(PIGLIT_FAIL
);
129 float *color
= malloc(piglit_width
* piglit_height
* 3 * sizeof(float));
131 for (y
= 0; y
< piglit_height
; y
++) {
132 for (x
= 0; x
< piglit_width
; x
++) {
133 color
[(y
* piglit_width
+ x
) * 3 + 0] = x
/ 256.0;
134 color
[(y
* piglit_width
+ x
) * 3 + 1] = y
/ 256.0;
135 color
[(y
* piglit_width
+ x
) * 3 + 2] = 0;
139 bool pass
= piglit_probe_image_rgb(0, 0, piglit_width
, piglit_height
, color
);
143 piglit_present_results();
145 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
149 piglit_init(int argc
, char **argv
)
153 piglit_require_gl_version(20);
154 piglit_require_extension("GL_EXT_framebuffer_object");
156 vs
= piglit_compile_shader(GL_VERTEX_SHADER
,
157 "shaders/glsl-mvp.vert");
158 fs
= piglit_compile_shader(GL_FRAGMENT_SHADER
,
159 "shaders/glsl-fs-fragcoord.frag");
161 prog
= piglit_link_simple_program(vs
, fs
);