2 * Copyright © 2012 Intel Corporation
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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * 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, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23 * Author: Neil Roberts <neil@linux.intel.com>
26 /** @file ext_unpack_subimage.c
28 * Test GL_EXT_unpack_subimage.
31 #include "piglit-util-gl.h"
33 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config
.supports_gl_es_version
= 20;
37 config
.window_width
= 100;
38 config
.window_height
= 100;
39 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
41 PIGLIT_GL_TEST_CONFIG_END
43 static GLboolean extension_supported
;
44 static GLboolean pass
;
48 /* Row 0. This is skipped if the extension is available,
49 otherwise it makes the top and bottom texel */
50 0xff, 0x00, 0x00, 0xff, /* red */
51 0x00, 0xff, 0x00, 0xff, /* green */
53 0x00, 0x00, 0x00, 0xff,
54 0x00, 0x00, 0x00, 0xff,
56 0x00, 0x00, 0x00, 0xff,
57 0x00, 0x00, 0x00, 0xff,
59 0x00, 0x00, 0x00, 0xff,
60 0x00, 0x00, 0x00, 0xff,
61 /* Row 4. This is the first row used if the extension is
63 /* The first pixel is skipped */
64 0x00, 0x00, 0x00, 0xff,
65 /* This texel becomes the top texel */
66 0x00, 0x00, 0xff, 0xff, /* blue */
67 /* Row 5. first texel not used */
68 0x00, 0x00, 0x00, 0x00,
69 /* second texel becomes the bottom texel */
70 0x00, 0xff, 0xff, 0xff /* cyan */
75 "attribute vec4 piglit_vertex;\n"
76 "attribute vec4 piglit_texcoord;\n"
77 "varying vec2 tex_coord;\n"
79 "gl_Position = piglit_vertex;\n"
80 "tex_coord = piglit_texcoord.xy;\n"
85 "uniform sampler2D tex; /* defaults to 0 */\n"
86 "precision highp float;\n"
87 "varying vec2 tex_coord;\n"
89 "gl_FragColor = texture2D(tex, tex_coord);\n"
96 static const float red
[] = { 1, 0, 0, 1 };
97 static const float green
[] = { 0, 1, 0, 1 };
98 static const float blue
[] = { 0, 0, 1, 1 };
99 static const float cyan
[] = { 0, 1, 1, 1 };
101 GLenum expected_error
;
105 extension_supported
=
106 piglit_is_extension_supported("GL_EXT_unpack_subimage") ||
107 (piglit_is_gles() && piglit_get_gl_version() >= 3);
109 expected_error
= extension_supported
? GL_NO_ERROR
: GL_INVALID_ENUM
;
111 if (!piglit_automatic
) {
112 if (extension_supported
)
113 printf("GL_EXT_unpack_subimage is supported\n");
115 printf("GL_EXT_unpack_subimage is not supported\n");
118 piglit_reset_gl_error();
119 if (!piglit_automatic
)
120 printf("Trying GL_UNPACK_ROW_LENGTH\n");
121 glPixelStorei(GL_UNPACK_ROW_LENGTH
, 2);
122 pass
= piglit_check_gl_error(expected_error
) && pass
;
124 piglit_reset_gl_error();
125 if (!piglit_automatic
)
126 printf("Trying GL_UNPACK_SKIP_PIXELS\n");
127 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, 1);
128 pass
= piglit_check_gl_error(expected_error
) && pass
;
130 piglit_reset_gl_error();
131 if (!piglit_automatic
)
132 printf("Trying GL_UNPACK_SKIP_ROWS\n");
133 glPixelStorei(GL_UNPACK_SKIP_ROWS
, 4);
134 pass
= piglit_check_gl_error(expected_error
) && pass
;
136 glClear(GL_COLOR_BUFFER_BIT
);
138 /* Try creating a texture with the unpacking parameters we've set */
139 glGenTextures(1, &tex
);
140 glBindTexture(GL_TEXTURE_2D
, tex
);
141 glTexImage2D(GL_TEXTURE_2D
,
143 GL_RGBA
, /* internalFormat */
147 GL_RGBA
, /* format */
148 GL_UNSIGNED_BYTE
, /* type */
150 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
151 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
153 program
= piglit_build_simple_program(vertex_shader
, fragment_shader
);
154 glUseProgram(program
);
156 piglit_draw_rect_tex(-1, -1, 2, 2,
159 if (extension_supported
) {
160 pass
&= piglit_probe_pixel_rgba(piglit_width
/ 2,
163 pass
&= piglit_probe_pixel_rgba(piglit_width
/ 2,
164 piglit_height
* 3 / 4,
167 pass
&= piglit_probe_pixel_rgba(piglit_width
/ 2,
170 pass
&= piglit_probe_pixel_rgba(piglit_width
/ 2,
171 piglit_height
* 3 / 4,
175 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
179 piglit_init(int argc
, char **argv
)