2 * Copyright (c) 2010 VMware, Inc.
3 * Copyright © 2011 Intel Corporation
5 * Permission is hereby , 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
27 * Test that we can make and render from an array texture with
28 * GL_MAX_TEXTURE_LAYERS layers.
31 #include "piglit-util-gl.h"
33 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config
.supports_gl_compat_version
= 10;
37 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
38 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
40 PIGLIT_GL_TEST_CONFIG_END
42 int height
= 100, ybase
= 0;
44 /* We'll set each 1x1 texture slice to a different color. */
45 static GLfloat colors
[][4] = {
56 static const char *fs_source
=
57 "#extension GL_EXT_texture_array : enable \n"
58 "uniform sampler2DArray tex;\n"
59 "uniform int layer;\n"
62 " gl_FragColor = texture2DArray(tex, vec3(0.0, 0.0, layer)); \n"
65 static GLint max_layers
;
66 static GLint layer_loc
;
69 bind_2d_array_texture(void)
75 data
= malloc(max_layers
* 4 * sizeof(float));
77 for (i
= 0; i
< max_layers
; i
++) {
78 data
[i
* 4 + 0] = colors
[i
% ARRAY_SIZE(colors
)][0];
79 data
[i
* 4 + 1] = colors
[i
% ARRAY_SIZE(colors
)][1];
80 data
[i
* 4 + 2] = colors
[i
% ARRAY_SIZE(colors
)][2];
81 data
[i
* 4 + 3] = colors
[i
% ARRAY_SIZE(colors
)][3];
84 glGenTextures(1, &tex
);
86 glBindTexture(GL_TEXTURE_2D_ARRAY
, tex
);
88 glTexImage3D(GL_TEXTURE_2D_ARRAY
, 0, GL_RGBA
,
89 1, 1, max_layers
, /* w, h, d */
91 GL_RGBA
, GL_FLOAT
, data
);
93 glTexParameteri(GL_TEXTURE_2D_ARRAY
, GL_TEXTURE_MIN_FILTER
,
95 glTexParameteri(GL_TEXTURE_2D_ARRAY
, GL_TEXTURE_MAG_FILTER
,
105 glClear(GL_COLOR_BUFFER_BIT
);
107 piglit_ortho_projection(piglit_width
, piglit_height
, false);
109 for (layer
= 0; layer
< max_layers
; layer
++) {
110 int x
= layer
% piglit_width
;
111 int y
= layer
/ piglit_width
;
113 glUniform1i(layer_loc
, layer
);
114 piglit_draw_rect(x
, y
, 1, 1);
118 for (layer
= 0; layer
< max_layers
; layer
++) {
119 int x
= layer
% piglit_width
;
120 int y
= layer
/ piglit_width
;
121 float *color
= colors
[layer
% ARRAY_SIZE(colors
)];
124 piglit_probe_rect_rgba(x
, y
, 1, 1, color
);
127 piglit_present_results();
129 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
134 piglit_init(int argc
, char **argv
)
138 piglit_require_extension("GL_EXT_texture_array");
140 glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS
, &max_layers
);
142 if (max_layers
>= piglit_width
* piglit_height
)
143 max_layers
= piglit_width
* piglit_height
;
145 printf("Testing %d texture layers\n", max_layers
);
147 /* Make shader programs */
148 prog
= piglit_build_simple_program(NULL
, fs_source
);
151 layer_loc
= glGetUniformLocation(prog
, "layer");
152 assert(layer_loc
!= -1);
154 bind_2d_array_texture();