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
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
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
46 #define TEX_HEIGHT 256
48 static const float colors
[][3] = {
59 static const char *sh_tex
=
60 "uniform sampler2D tex;"
63 " gl_FragColor = texture2D(tex, gl_TexCoord[0].xy);"
66 static const char *sh_texgrad
=
67 "#extension GL_ARB_shader_texture_lod : enable\n"
68 "uniform sampler2D tex;"
71 " gl_FragColor = texture2DGradARB(tex, gl_TexCoord[0].xy,"
72 " dFdx(gl_TexCoord[0].xy),"
73 " dFdy(gl_TexCoord[0].xy));"
76 static GLint prog_tex
, prog_texgrad
;
78 void piglit_init(int argc
, char **argv
)
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
,
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
,
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],
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
);
139 glFrustum(-0.1, 0.1, -0.1, 0.1, 0.1, 1000.0);
141 glMatrixMode(GL_MODELVIEW
);
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()
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
);
181 glViewport(piglit_width
/2, 0, piglit_width
/2, piglit_height
);
182 glUseProgram(prog_texgrad
);
185 if (!piglit_probe_rect_halves_equal_rgba(0, 0, piglit_width
, piglit_height
))
188 piglit_present_results();
190 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;