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
21 * DEALINGS IN THE SOFTWARE.
26 * \brief Test texturing from an ATC miptree of a real image.
28 * Copied from identical ETC1 test.
30 * This test uses two data files. The file waffles-compressed-atc-64x32.ktx
31 * contains a full miptree in GL_ATC_RGB_AMD format of a 2D texture of
32 * waffles and fruit [1]. The base level size is 64x32 pixels. The file
33 * waffles-decompressed-rgba-64x32.ktx contains a parallel miptree in GL_RGBA
34 * format. Each of its RGBA images was obtained by decompressing the corresponding
35 * ATC image with AMD's Compressonator tool [2].
37 * This test draws each miplevel i of the ATC texture such that the image's
38 * lower left corner is at (x=0, y=sum(height of miplevel j for j=0 to i-1)),
39 * and it draws each miplevel of the RGB texture to the right of its
40 * corresponding ATC image. Then it compares that the images are identical.
42 * [1] The reference image is located at http://people.freedesktop.org/~chadversary/permalink/2012-07-09/1574cff2-d091-4421-a3cf-b56c7943d060.jpg.
43 * [2] https://github.com/GPUOpen-Tools/Compressonator
45 * Compressonator tool is not perfect:
46 * -RGBA is used for the decompressed image because the tool is buggy with RGB.
47 * -red/blue swapped when decompressing ATC (used script to swap red/blue back for test image)
48 * -7th 1x1 mipmap isn't generated (num_levels 6 instead of 7)
51 #include "piglit-util-gl.h"
52 #include "piglit_ktx.h"
55 #define level0_width 64
56 #define level0_height 32
58 #define num_vertices 4
60 static const int window_width
= 2 * level0_width
;
61 static const int window_height
= 2 * level0_height
;
63 PIGLIT_GL_TEST_CONFIG_BEGIN
65 config
.supports_gl_es_version
= 20;
67 config
.window_width
= window_width
;
68 config
.window_height
= window_height
;
69 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
71 PIGLIT_GL_TEST_CONFIG_END
76 /* Texture objects. */
77 static GLuint compressed_tex
;
78 static GLuint decompressed_tex
;
81 * The \a filename is relative to the current test's source directory.
83 * A new texture is created and returned in \a tex_name.
86 load_texture(const char *filename
, GLuint
*tex_name
)
88 struct piglit_ktx
*ktx
;
89 const struct piglit_ktx_info
*info
;
93 piglit_join_paths(filepath
, sizeof(filepath
), 5,
97 "amd_compressed_atc_texture",
100 ktx
= piglit_ktx_read_file(filepath
);
102 piglit_report_result(PIGLIT_FAIL
);
104 info
= piglit_ktx_get_info(ktx
);
105 assert(info
->num_miplevels
== num_levels
);
106 assert(info
->target
== GL_TEXTURE_2D
);
107 assert(info
->pixel_width
== level0_width
);
108 assert(info
->pixel_height
== level0_height
);
111 ok
= piglit_ktx_load_texture(ktx
, tex_name
, NULL
);
113 piglit_report_result(PIGLIT_FAIL
);
115 piglit_ktx_destroy(ktx
);
119 piglit_init(int argc
, char **argv
)
121 static const char compressed_filename
[] = "waffles-compressed-atc-64x32.ktx";
122 static const char decompressed_filename
[] = "waffles-decompressed-rgba-64x32.ktx";
124 const char vs_source
[] =
127 "uniform vec2 window_pixel_size;\n"
128 "uniform vec2 level_pixel_size;\n"
129 "uniform vec2 pixel_offset;\n"
131 "// vertex is some corner of the unit square [0,1]^2 \n"
132 "attribute vec2 vertex;\n"
133 "varying vec2 tex_coord;\n"
137 " vec2 pos = vertex;\n"
138 " pos *= level_pixel_size;\n"
139 " pos += pixel_offset;\n"
140 " pos /= 0.5 * window_pixel_size;\n"
141 " pos -= vec2(1, 1);\n"
142 " gl_Position = vec4(pos.xy, 0.0, 1.0);\n"
144 " tex_coord = vertex;\n"
147 const char fs_source
[] =
149 "precision highp float;\n"
151 "uniform sampler2D tex;\n"
152 "varying vec2 tex_coord;\n"
156 " vec4 t = texture2D(tex, tex_coord);\n"
157 " gl_FragColor = vec4(t.rgb, 1.0);\n"
160 /* Draw a square triangle strip. */
161 const GLfloat vertices
[2 * num_vertices
] = {
171 piglit_require_extension("GL_AMD_compressed_ATC_texture");
173 load_texture(compressed_filename
, &compressed_tex
);
174 load_texture(decompressed_filename
, &decompressed_tex
);
176 glClearColor(1.0, 0.0, 0.0, 1.0);
177 glViewport(0, 0, window_width
, window_height
);
179 prog
= piglit_build_simple_program(vs_source
, fs_source
);
182 vertex_loc
= glGetAttribLocation(prog
, "vertex");
183 glGenBuffers(1, &vertex_buf
);
184 glBindBuffer(GL_ARRAY_BUFFER
, vertex_buf
);
185 glEnableVertexAttribArray(vertex_loc
);
186 glVertexAttribPointer(vertex_loc
, 2, GL_FLOAT
, GL_FALSE
, 0, NULL
);
187 glBufferData(GL_ARRAY_BUFFER
, sizeof(vertices
), vertices
,
190 glUniform1i(glGetUniformLocation(prog
, "tex"), 0);
191 glActiveTexture(GL_TEXTURE0
);
192 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST_MIPMAP_NEAREST
);
193 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
195 glUniform2f(glGetUniformLocation(prog
, "window_pixel_size"),
196 window_width
, window_height
);
211 GLint pixel_offset_loc
= glGetUniformLocation(prog
, "pixel_offset");
212 GLint level_pixel_size_loc
= glGetUniformLocation(prog
, "level_pixel_size");
215 int level_width
= level0_width
;
216 int level_height
= level0_height
;
221 glClear(GL_COLOR_BUFFER_BIT
);
223 for (level
= 0; level
< num_levels
; ++level
) {
224 glUniform2f(level_pixel_size_loc
,
226 (float) level_height
);
228 /* Draw miplevel of compressed texture. */
229 glBindTexture(GL_TEXTURE_2D
, compressed_tex
);
230 glUniform2f(pixel_offset_loc
, 0, y_offset
);
231 glDrawArrays(GL_TRIANGLE_FAN
, 0, num_vertices
);
233 /* Draw miplevel of decompressed texture. */
234 glBindTexture(GL_TEXTURE_2D
, decompressed_tex
);
235 glUniform2f(pixel_offset_loc
, level0_width
, y_offset
);
236 glDrawArrays(GL_TRIANGLE_FAN
, 0, num_vertices
);
238 y_offset
+= level_height
;
239 minify(&level_width
);
240 minify(&level_height
);
243 pass
= piglit_probe_rect_halves_equal_rgba(0, 0, window_width
, window_height
);
244 piglit_present_results();
246 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;