ARB_ubo/referenced-by-shader: pass if shader compiler moves UBOs between shaders
[piglit.git] / tests / spec / arb_shader_texture_lod / execution / texgrad.c
blob1390dcff07bd3956f91dc35be3cd7a69b6362420
1 /*
2 * Copyright © 2009 Intel Corporation
3 * Copyright © 2011 Marek Olšák <maraeo@gmail.com>
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
24 * Authors:
25 * Marek Olšák <maraeo@gmail.com>
27 * Based on fbo-clearmipmap by:
28 * Eric Anholt <eric@anholt.net>
32 #include "piglit-util-gl.h"
34 PIGLIT_GL_TEST_CONFIG_BEGIN
36 config.supports_gl_compat_version = 10;
38 config.window_width = 512;
39 config.window_height = 256;
40 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
41 config.khr_no_error_support = PIGLIT_NO_ERRORS;
43 PIGLIT_GL_TEST_CONFIG_END
45 #define TEX_WIDTH 256
46 #define TEX_HEIGHT 256
48 static const float colors[][3] = {
49 {1.0, 0.0, 0.0},
50 {0.0, 1.0, 0.0},
51 {0.0, 0.0, 1.0},
52 {1.0, 1.0, 0.0},
53 {0.0, 1.0, 1.0},
54 {1.0, 0.0, 1.0},
55 {0.5, 0.0, 0.5},
56 {1.0, 1.0, 1.0},
59 static const char *sh_tex =
60 "uniform sampler2D tex;"
61 "void main()"
62 "{"
63 " gl_FragColor = texture2D(tex, gl_TexCoord[0].xy);"
64 "}";
66 static const char *sh_texgrad =
67 "#extension GL_ARB_shader_texture_lod : enable\n"
68 "uniform sampler2D tex;"
69 "void main()"
70 "{"
71 " gl_FragColor = texture2DGradARB(tex, gl_TexCoord[0].xy,"
72 " dFdx(gl_TexCoord[0].xy),"
73 " dFdy(gl_TexCoord[0].xy));"
74 "}";
76 static GLint prog_tex, prog_texgrad;
78 void piglit_init(int argc, char **argv)
80 GLuint tex, fb;
81 GLenum status;
82 int i, dim;
84 piglit_require_fragment_shader();
85 piglit_require_extension("GL_EXT_framebuffer_object");
86 piglit_require_extension("GL_ARB_shader_texture_lod");
88 prog_tex = piglit_build_simple_program(NULL, sh_tex);
89 prog_texgrad = piglit_build_simple_program(NULL, sh_texgrad);
91 glGenTextures(1, &tex);
92 glBindTexture(GL_TEXTURE_2D, tex);
94 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
95 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
97 for (i = 0, dim = TEX_WIDTH; dim >0; i++, dim /= 2) {
98 glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA,
99 dim, dim,
101 GL_RGBA, GL_UNSIGNED_BYTE, NULL);
103 if (!piglit_check_gl_error(GL_NO_ERROR))
104 piglit_report_result(PIGLIT_FAIL);
106 glBindTexture(GL_TEXTURE_2D, 0);
107 glDisable(GL_TEXTURE_2D);
109 glGenFramebuffersEXT(1, &fb);
110 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
112 for (i = 0, dim = TEX_WIDTH; dim >0; i++, dim /= 2) {
113 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
114 GL_COLOR_ATTACHMENT0_EXT,
115 GL_TEXTURE_2D,
116 tex,
119 status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT);
120 if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
121 fprintf(stderr, "FBO incomplete\n");
122 piglit_report_result(PIGLIT_SKIP);
125 glClearColor(colors[i][0],
126 colors[i][1],
127 colors[i][2],
128 0.0);
129 glClear(GL_COLOR_BUFFER_BIT);
131 if (!piglit_check_gl_error(GL_NO_ERROR))
132 piglit_report_result(PIGLIT_FAIL);
134 glDeleteFramebuffersEXT(1, &fb);
135 glBindTexture(GL_TEXTURE_2D, tex);
137 glMatrixMode(GL_PROJECTION);
138 glLoadIdentity();
139 glFrustum(-0.1, 0.1, -0.1, 0.1, 0.1, 1000.0);
141 glMatrixMode(GL_MODELVIEW);
142 glLoadIdentity();
143 glTranslatef(-0.5, -0.5, -1.2);
144 glRotatef(68, 0, 1, 0);
145 glScalef(2000, 1, 1);
147 glEnable(GL_TEXTURE_2D);
148 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
150 piglit_set_tolerance_for_bits(7, 7, 7, 7);
152 printf("Left: texture2D, Right: texture2DGradARB\n");
155 static void draw_quad()
157 glBegin(GL_QUADS);
158 glTexCoord2f(0, 0);
159 glVertex2f(0, 0);
160 glTexCoord2f(1, 0);
161 glVertex2f(1, 0);
162 glTexCoord2f(1, 1);
163 glVertex2f(1, 1);
164 glTexCoord2f(0, 1);
165 glVertex2f(0, 1);
166 glEnd();
169 enum piglit_result piglit_display(void)
171 GLboolean pass = GL_TRUE;
173 glViewport(0, 0, piglit_width, piglit_height);
174 glClearColor(0.5, 0.5, 0.5, 0.5);
175 glClear(GL_COLOR_BUFFER_BIT);
177 glViewport(0, 0, piglit_width/2, piglit_height);
178 glUseProgram(prog_tex);
179 draw_quad();
181 glViewport(piglit_width/2, 0, piglit_width/2, piglit_height);
182 glUseProgram(prog_texgrad);
183 draw_quad();
185 if (!piglit_probe_rect_halves_equal_rgba(0, 0, piglit_width, piglit_height))
186 pass = GL_FALSE;
188 piglit_present_results();
190 return pass ? PIGLIT_PASS : PIGLIT_FAIL;