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
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.
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
45 #define TEX_HEIGHT 256
47 static const float colors
[][3] = {
58 static const char *sh_tex
=
59 "uniform samplerCube tex;"
62 " gl_FragColor = textureCube(tex, gl_TexCoord[0].xyz);"
65 static const char *sh_texgrad
=
66 "#extension GL_ARB_shader_texture_lod : enable\n"
67 "uniform samplerCube tex;"
70 " gl_FragColor = textureCubeGradARB(tex, gl_TexCoord[0].xyz,"
71 " dFdx(gl_TexCoord[0].xyz),"
72 " dFdy(gl_TexCoord[0].xyz));"
75 static GLint prog_tex
, prog_texgrad
;
77 void piglit_init(int argc
, char **argv
)
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
,
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
,
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],
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
);
143 glFrustum(-0.1, 0.1, -0.1, 0.1, 0.1, 1000.0);
145 glMatrixMode(GL_MODELVIEW
);
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()
162 glTexCoord3f(-0.5, -0.5, 1);
164 glTexCoord3f(0.5, -0.5, 1);
166 glTexCoord3f(0.5, 0.5, 1);
168 glTexCoord3f(-0.5, 0.5, 1);
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
);
185 glViewport(piglit_width
/2, 0, piglit_width
/2, piglit_height
);
186 glUseProgram(prog_texgrad
);
189 if (!piglit_probe_rect_halves_equal_rgba(0, 0, piglit_width
, piglit_height
))
192 piglit_present_results();
194 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;