ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_shader_texture_lod / execution / texgradcube.c
blobd0ed36e0118ef4ce42d5f94a0cc6b17aec3fc4ac
1 /*
2 * Copyright (c) 2013 VMware, Inc.
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS AND/OR THEIR
19 * SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
24 * Authors:
25 * Roland Scheidegger <sroland@vmware.com>
27 * Based on arb_shader_texture_lod-texgrad:
28 * Marek Olšák <maraeo@gmail.com>
31 #include "piglit-util-gl.h"
33 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config.supports_gl_compat_version = 10;
37 config.window_width = 512;
38 config.window_height = 256;
39 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
40 config.khr_no_error_support = PIGLIT_NO_ERRORS;
42 PIGLIT_GL_TEST_CONFIG_END
44 #define TEX_WIDTH 256
45 #define TEX_HEIGHT 256
47 static const float colors[][3] = {
48 {1.0, 0.0, 0.0},
49 {0.0, 1.0, 0.0},
50 {0.0, 0.0, 1.0},
51 {1.0, 1.0, 0.0},
52 {0.0, 1.0, 1.0},
53 {1.0, 0.0, 1.0},
54 {0.5, 0.0, 0.5},
55 {1.0, 1.0, 1.0},
58 static const char *sh_tex =
59 "uniform samplerCube tex;"
60 "void main()"
61 "{"
62 " gl_FragColor = textureCube(tex, gl_TexCoord[0].xyz);"
63 "}";
65 static const char *sh_texgrad =
66 "#extension GL_ARB_shader_texture_lod : enable\n"
67 "uniform samplerCube tex;"
68 "void main()"
69 "{"
70 " gl_FragColor = textureCubeGradARB(tex, gl_TexCoord[0].xyz,"
71 " dFdx(gl_TexCoord[0].xyz),"
72 " dFdy(gl_TexCoord[0].xyz));"
73 "}";
75 static GLint prog_tex, prog_texgrad;
77 void piglit_init(int argc, char **argv)
79 GLuint tex, fb;
80 GLenum status;
81 int i, j, dim;
83 piglit_require_GLSL();
84 piglit_require_extension("GL_EXT_framebuffer_object");
85 piglit_require_extension("GL_ARB_shader_texture_lod");
87 prog_tex = piglit_build_simple_program(NULL, sh_tex);
88 prog_texgrad = piglit_build_simple_program(NULL, sh_texgrad);
90 glGenTextures(1, &tex);
91 glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
93 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
94 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
96 for (j = GL_TEXTURE_CUBE_MAP_POSITIVE_X; j <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; j++) {
97 for (i = 0, dim = TEX_WIDTH; dim >0; i++, dim /= 2) {
98 glTexImage2D(j, i, GL_RGBA,
99 dim, dim,
101 GL_RGBA, GL_UNSIGNED_BYTE, NULL);
104 if (!piglit_check_gl_error(GL_NO_ERROR))
105 piglit_report_result(PIGLIT_FAIL);
107 glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
108 glDisable(GL_TEXTURE_CUBE_MAP);
110 glGenFramebuffersEXT(1, &fb);
111 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
113 for (j = GL_TEXTURE_CUBE_MAP_POSITIVE_X; j <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; j++) {
114 for (i = 0, dim = TEX_WIDTH; dim >0; i++, dim /= 2) {
115 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
116 GL_COLOR_ATTACHMENT0_EXT,
118 tex,
121 status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT);
122 if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
123 fprintf(stderr, "FBO incomplete\n");
124 piglit_report_result(PIGLIT_SKIP);
127 glClearColor(colors[i][0],
128 colors[i][1],
129 colors[i][2],
130 0.0);
131 glClear(GL_COLOR_BUFFER_BIT);
133 if (!piglit_check_gl_error(GL_NO_ERROR))
134 piglit_report_result(PIGLIT_FAIL);
138 glDeleteFramebuffersEXT(1, &fb);
139 glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
141 glMatrixMode(GL_PROJECTION);
142 glLoadIdentity();
143 glFrustum(-0.1, 0.1, -0.1, 0.1, 0.1, 1000.0);
145 glMatrixMode(GL_MODELVIEW);
146 glLoadIdentity();
147 glTranslatef(-0.5, -0.5, -1.2);
148 glRotatef(68, 0, 1, 0);
149 glScalef(2000, 1, 1);
151 glEnable(GL_TEXTURE_CUBE_MAP);
152 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
154 piglit_set_tolerance_for_bits(7, 7, 7, 7);
156 printf("Left: textureCube, Right: textureCubeGradARB\n");
159 static void draw_quad()
161 glBegin(GL_QUADS);
162 glTexCoord3f(-0.5, -0.5, 1);
163 glVertex2f(0, 0);
164 glTexCoord3f(0.5, -0.5, 1);
165 glVertex2f(1, 0);
166 glTexCoord3f(0.5, 0.5, 1);
167 glVertex2f(1, 1);
168 glTexCoord3f(-0.5, 0.5, 1);
169 glVertex2f(0, 1);
170 glEnd();
173 enum piglit_result piglit_display(void)
175 GLboolean pass = GL_TRUE;
177 glViewport(0, 0, piglit_width, piglit_height);
178 glClearColor(0.5, 0.5, 0.5, 0.5);
179 glClear(GL_COLOR_BUFFER_BIT);
181 glViewport(0, 0, piglit_width/2, piglit_height);
182 glUseProgram(prog_tex);
183 draw_quad();
185 glViewport(piglit_width/2, 0, piglit_width/2, piglit_height);
186 glUseProgram(prog_texgrad);
187 draw_quad();
189 if (!piglit_probe_rect_halves_equal_rgba(0, 0, piglit_width, piglit_height))
190 pass = GL_FALSE;
192 piglit_present_results();
194 return pass ? PIGLIT_PASS : PIGLIT_FAIL;