2 * Copyright © 2011 VMware, Inc.
3 * Copyright © 2014 Intel Corporation
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
22 * DEALINGS IN THE SOFTWARE.
27 * Test glTextureSubImage*D. This is pretty trivial, since it only uses
28 * glTextureSubImage*D with offsets of 0 and the width, height, and depth of
29 * the full image. Moreover, it doesn't test varying depths for the 3D case.
30 * But since DSA functions share backends with the non-DSA ones, we really
31 * only need to test entry points here.
33 #include "piglit-util-gl.h"
36 #include "dsa-utils.h"
38 PIGLIT_GL_TEST_CONFIG_BEGIN
40 config
.supports_gl_core_version
= 31;
41 config
.supports_gl_compat_version
= 20;
43 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
|
44 PIGLIT_GL_VISUAL_DOUBLE
;
45 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
47 PIGLIT_GL_TEST_CONFIG_END
50 random_image_data(int width
, int height
, int depth
)
53 GLubyte
*img
= malloc(4 * width
* height
* depth
* sizeof(GLubyte
));
54 for (i
= 0; i
< 4 * width
* height
* depth
; ++i
) {
55 img
[i
] = rand() % 256;
58 } /* random_image_data */
61 static GLubyte
*refImg
;
63 static enum piglit_result
64 subtest(GLenum target
)
70 prog
= dsa_create_program(target
);
72 /* Draw the reference image. */
73 glCreateTextures(target
, 1, &tex
);
74 glTextureParameteri(tex
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
75 glTextureParameteri(tex
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
76 if (target
== GL_TEXTURE_1D
) {
77 glTextureStorage1D(tex
, 1, GL_RGBA8
, piglit_width
);
78 glTextureSubImage1D(tex
, 0, 0, piglit_width
, GL_RGBA
,
79 GL_UNSIGNED_BYTE
, refImg
);
80 } else if (target
== GL_TEXTURE_2D
) {
81 glTextureStorage2D(tex
, 1, GL_RGBA8
, piglit_width
,
83 glTextureSubImage2D(tex
, 0, 0, 0, piglit_width
, piglit_height
,
84 GL_RGBA
, GL_UNSIGNED_BYTE
, refImg
);
85 } else if (target
== GL_TEXTURE_3D
) {
86 glTextureStorage3D(tex
, 1, GL_RGBA8
, piglit_width
,
87 piglit_height
, depth
);
88 glTextureSubImage3D(tex
, 0, 0, 0, 0,
89 piglit_width
, piglit_height
, 1,
90 GL_RGBA
, GL_UNSIGNED_BYTE
,
95 glBindTextureUnit(0, tex
);
96 glClear(GL_COLOR_BUFFER_BIT
);
97 piglit_draw_rect_tex(-1.0, -1.0, 2.0, 2.0, 0.0, 0.0, 1.0, 1.0);
98 if (target
== GL_TEXTURE_1D
) {
99 pass
= piglit_probe_image_ubyte(0, 0, piglit_width
, 1,
103 pass
= piglit_probe_image_ubyte(0, 0, piglit_width
,
110 glDeleteProgram(prog
);
112 if (!piglit_automatic
)
113 piglit_present_results();
115 piglit_report_subtest_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
,
116 "%s", piglit_get_gl_enum_name(target
));
117 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
123 static const GLenum targets
[] = {
129 enum piglit_result result
= PIGLIT_PASS
;
130 enum piglit_result subtest_result
;
132 /* Loop over 1/2/3D texture targets */
133 for (i
= 0; i
< ARRAY_SIZE(targets
); i
++) {
134 subtest_result
= subtest(targets
[i
]);
135 if (subtest_result
!= PIGLIT_PASS
)
136 result
= PIGLIT_FAIL
;
144 piglit_init(int argc
, char **argv
)
146 piglit_require_extension("GL_ARB_direct_state_access");
147 piglit_require_extension("GL_ARB_texture_storage");
151 /* Make the image data for testing. */
152 refImg
= random_image_data(piglit_width
, piglit_height
, depth
);