2 * Copyright (c) 2013 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
25 * @file interpolateAtCentroid-centroid.c
27 * Test ARB_gpu_shader5 interpolateAtCentroid builtin interaction with centroid varyings
29 * Tests that interpolateAtCentroid(x) == x, if x is declared centroid.
31 * R, 1-G channels are interesting; a correct implementation should produce
32 * (0,1,0) in all pixels.
34 * We require 3.2, so the following assumptions are made:
35 * - MAX_SAMPLES >= 4 (although we dont require exactly 4 samples; if only an
36 * 8x mode is supported, the test should still work)
37 * - GLSL 1.50 and Multisample textures are supported.
41 #include "piglit-util-gl.h"
43 PIGLIT_GL_TEST_CONFIG_BEGIN
45 config
.supports_gl_core_version
= 32;
47 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGB
;
48 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
50 PIGLIT_GL_TEST_CONFIG_END
52 GLuint ms_fbo
, vao
, bo
;
53 GLint draw_prog
, test_prog
;
55 float green
[] = { 0, 1, 0 };
56 float verts
[][2] = { { -1, -1 }, { 1, -1 }, { -1, 1 }, { 1, 1 }, };
57 #define GAIN "5" /* multiplier for absolute difference; make the error more visible. */
64 glViewport(0, 0, 64, 64);
66 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, ms_fbo
);
67 glUseProgram(draw_prog
);
68 glDrawArrays(GL_TRIANGLE_STRIP
, 0, 4);
70 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, piglit_winsys_fbo
);
71 glUseProgram(test_prog
);
72 glDrawArrays(GL_TRIANGLE_STRIP
, 0, 4);
74 pass
= piglit_probe_rect_rgb(0, 0, 64, 64, green
) && pass
;
76 piglit_present_results();
78 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
83 piglit_init(int argc
, char**argv
)
86 piglit_require_extension("GL_ARB_gpu_shader5");
88 glGenFramebuffers(1, &ms_fbo
);
89 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, ms_fbo
);
90 glGenTextures(1, &tex
);
91 glBindTexture(GL_TEXTURE_2D_MULTISAMPLE
, tex
);
92 glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE
, 4,
93 GL_RGBA
, 64, 64, GL_TRUE
);
94 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
,
95 GL_TEXTURE_2D_MULTISAMPLE
, tex
, 0);
97 if (!piglit_check_gl_error(GL_NO_ERROR
)) {
98 printf("fbo setup failed.\n");
99 piglit_report_result(PIGLIT_SKIP
);
102 draw_prog
= piglit_build_simple_program(
105 "centroid out vec2 test;\n"
107 " gl_Position = vec4(p, 0, 1);\n"
112 "#extension GL_ARB_gpu_shader5: require\n"
113 "centroid in vec2 test;\n"
115 " gl_FragColor = vec4(" GAIN
" * abs(\n"
116 " interpolateAtCentroid(test) - test), 0, 1);\n"
119 printf("draw_prog compile/link failed\n");
120 piglit_report_result(PIGLIT_FAIL
);
123 test_prog
= piglit_build_simple_program(
127 " gl_Position = vec4(p, 0, 1);\n"
131 "uniform sampler2DMS s;\n"
134 " texelFetch(s, ivec2(gl_FragCoord.xy), 0) +\n"
135 " texelFetch(s, ivec2(gl_FragCoord.xy), 1) +\n"
136 " texelFetch(s, ivec2(gl_FragCoord.xy), 2) +\n"
137 " texelFetch(s, ivec2(gl_FragCoord.xy), 3);\n"
138 " gl_FragColor = vec4(temp.x, 1-temp.y, temp.z, temp.w);\n"
141 printf("test_prog compile/link failed\n");
142 piglit_report_result(PIGLIT_FAIL
);
145 glUseProgram(test_prog
);
146 glUniform1i(glGetUniformLocation(test_prog
, "s"), 0);
148 if (!piglit_check_gl_error(GL_NO_ERROR
)) {
149 printf("shader setup failed\n");
150 piglit_report_result(PIGLIT_SKIP
);
153 glGenVertexArrays(1, &vao
);
154 glBindVertexArray(vao
);
156 glEnableVertexAttribArray(0);
157 glGenBuffers(1, &bo
);
158 glBindBuffer(GL_ARRAY_BUFFER
, bo
);
159 glBufferData(GL_ARRAY_BUFFER
, sizeof(verts
), verts
, GL_STATIC_DRAW
);
160 glVertexAttribPointer(0, 2, GL_FLOAT
, GL_FALSE
, 0, (GLvoid
const *)0);