2 * Copyright (c) 2011 Red Hat Inc.
3 * derived from texture-rg - Copyright (c) 2010 VMware, Inc.
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the 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,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NON-INFRINGEMENT. IN NO EVENT SHALL VMWARE AND/OR THEIR SUPPLIERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 * Tests for a regression on r200 AL upload
29 * https://bugs.freedesktop.org/show_bug.cgi?id=34280
32 #include "piglit-util-gl.h"
34 PIGLIT_GL_TEST_CONFIG_BEGIN
36 config
.supports_gl_compat_version
= 10;
38 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DOUBLE
;
39 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
41 PIGLIT_GL_TEST_CONFIG_END
43 static const char *TestName
= "texture-al";
45 static GLint TexWidth
= 128, TexHeight
= 128;
49 GLenum IntFormat
, BaseFormat
;
54 static const struct format_info IntFormats
[] = {
55 { GL_ALPHA
, GL_ALPHA
, 1.0 },
56 { GL_ALPHA
, GL_LUMINANCE_ALPHA
, 1.0 },
57 { GL_LUMINANCE_ALPHA
, GL_LUMINANCE_ALPHA
, 1.0 },
58 { GL_LUMINANCE_ALPHA
, GL_ALPHA
, 0.0 },
61 #define NUM_INT_FORMATS (sizeof(IntFormats) / sizeof(IntFormats[0]))
65 check_error(const char *file
, int line
)
67 GLenum err
= glGetError();
69 fprintf(stderr
, "%s: error 0x%x at %s:%d\n", TestName
, err
, file
, line
);
77 fill_texture_image(GLint w
, GLint h
, GLint comps
, GLubyte
*buf
)
80 for (i
= 0; i
< h
; i
++) {
81 for (j
= 0; j
< w
; j
++) {
82 for (k
= 0; k
< comps
; k
++) {
85 /* left/right = red gradient */
86 val
= (int) (255 * j
/ (float) (w
- 1));
89 /* up/down = green gradient */
90 val
= (int) (255 * i
/ (float) (h
- 1));
100 test_teximage_formats(void)
107 glGenTextures(1, &tex
);
108 glBindTexture(GL_TEXTURE_2D
, tex
);
109 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
110 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
111 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
112 glEnable(GL_TEXTURE_2D
);
114 image
= (GLubyte
*) malloc(TexWidth
* TexHeight
* 2 * sizeof(GLubyte
));
116 for (i
= 0; i
< NUM_INT_FORMATS
; i
++) {
117 const struct format_info
*info
= &IntFormats
[i
];
118 const GLuint comps
= (info
->BaseFormat
== GL_ALPHA
) ? 1 : 2;
119 GLfloat expected
[4], result
[4];
120 GLfloat error
= 2.0 / 255.0; /* XXX fix */
122 fill_texture_image(TexWidth
, TexHeight
, comps
, image
);
124 glTexImage2D(GL_TEXTURE_2D
, 0, info
->IntFormat
,
125 TexWidth
, TexHeight
, 0,
126 info
->BaseFormat
, GL_UNSIGNED_BYTE
, image
);
128 if (check_error(__FILE__
, __LINE__
)) {
129 fprintf(stderr
, "%s: Error in glTexImage2D for "
130 "internalFormat = %s, baseFormat = %s\n", TestName
,
131 piglit_get_gl_enum_name(info
->IntFormat
),
132 piglit_get_gl_enum_name(info
->BaseFormat
));
138 glGetTexLevelParameteriv(GL_TEXTURE_2D
, 0,
139 GL_TEXTURE_INTERNAL_FORMAT
, &f
);
140 assert(f
== info
->IntFormat
);
143 glClear(GL_COLOR_BUFFER_BIT
);
145 glTexCoord2f(0, 0); glVertex2f(0, 0);
146 glTexCoord2f(1, 0); glVertex2f(TexWidth
, 0);
147 glTexCoord2f(1, 1); glVertex2f(TexWidth
, TexHeight
);
148 glTexCoord2f(0, 1); glVertex2f(0, TexHeight
);
151 /* setup expected polygon color */
152 expected
[0] = info
->expected0
;
157 /* test center pixel */
158 result
[0] = result
[1] = result
[2] = 0.0;
160 glReadPixels(TexWidth
/2, TexHeight
/2, 1, 1, GL_LUMINANCE_ALPHA
, GL_FLOAT
, result
);
162 if (check_error(__FILE__
, __LINE__
)) {
163 fprintf(stderr
, "%s: Error in glReadPixels(format = GL_LA)\n",
168 if (fabsf(result
[0] - expected
[0]) > error
||
169 fabsf(result
[1] - expected
[1]) > error
||
170 fabsf(result
[2] - expected
[2]) > error
||
171 fabsf(result
[3] - expected
[3]) > error
) {
172 fprintf(stderr
, "%s: failure with internalFormat %s, "
173 "baseFormat %s:\n", TestName
,
174 piglit_get_gl_enum_name(info
->IntFormat
),
175 piglit_get_gl_enum_name(info
->BaseFormat
));
176 fprintf(stderr
, " expected color = %g, %g, %g, %g\n",
177 expected
[0], expected
[1], expected
[2], expected
[3]);
178 fprintf(stderr
, " result color = %g, %g, %g, %g\n",
179 result
[0], result
[1], result
[2], result
[3]);
183 piglit_present_results();
188 glDisable(GL_TEXTURE_2D
);
195 test_drawpixels_formats(void)
198 GLfloat result
[4], expected
[4];
199 GLfloat error
= 2.0 / 255.0; /* XXX fix */
201 image
= (GLubyte
*) malloc(TexWidth
* TexHeight
* 2 * sizeof(GLubyte
));
203 fill_texture_image(TexWidth
, TexHeight
, 2, image
);
205 glWindowPos2iARB(0, 0);
206 glDrawPixels(TexWidth
, TexHeight
, GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, image
);
208 if (check_error(__FILE__
, __LINE__
)) {
209 fprintf(stderr
, "%s: Error in glDrawPixels(format = GL_LA)\n",
214 /* test center pixel */
215 result
[0] = result
[1] = result
[2] = 0.0;
217 glReadPixels(TexWidth
/2, TexHeight
/2, 1, 1, GL_LUMINANCE_ALPHA
, GL_FLOAT
, result
);
224 if (fabsf(result
[0] - expected
[0]) > error
||
225 fabsf(result
[1] - expected
[1]) > error
||
226 fabsf(result
[2] - expected
[2]) > error
||
227 fabsf(result
[3] - expected
[3]) > error
) {
228 fprintf(stderr
, "%s: glDrawPixels failure with format GL_LA:\n", TestName
);
229 fprintf(stderr
, " expected color = %g, %g, %g, %g\n",
230 expected
[0], expected
[1], expected
[2], expected
[3]);
231 fprintf(stderr
, " result color = %g, %g, %g, %g\n",
232 result
[0], result
[1], result
[2], result
[3]);
246 if (test_teximage_formats() && test_drawpixels_formats())
254 piglit_init(int argc
, char **argv
)
256 piglit_require_extension("GL_ARB_window_pos");
257 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);