2 * Copyright (c) 2013 VMware, Inc.
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NON-INFRINGEMENT. IN NO EVENT SHALL VMWARE AND/OR THEIR SUPPLIERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * This test exercises an NVIDIA driver bug where reading back
28 * a texture image via an sRGBA view returns invalid texel data.
32 #include "piglit-util-gl.h"
34 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config
.supports_gl_compat_version
= 15;
36 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
;
37 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
38 PIGLIT_GL_TEST_CONFIG_END
43 #define TEX_NUMPIXELS (TEX_WIDTH * TEX_HEIGHT)
45 #define RED 0xFF0000FF
46 #define GRAY 0x7F7F7FFF
50 test_srgb_view(GLenum view_format
)
52 GLenum target
= GL_TEXTURE_2D
;
53 GLuint texData
[TEX_NUMPIXELS
];
57 for (i
= 0; i
< TEX_NUMPIXELS
; ++i
) {
61 /* Create RGBA texture */
62 glGenTextures(1, &tex
);
63 glActiveTextureARB(GL_TEXTURE0
);
64 glBindTexture(target
, tex
);
65 glTexStorage2D(target
, 1, GL_RGBA8
, TEX_WIDTH
, TEX_HEIGHT
);
66 glTexSubImage2D(target
, 0, 0, 0, TEX_WIDTH
, TEX_HEIGHT
,
67 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8
, texData
);
69 /* Create sRGB texture view */
70 glGenTextures(1, &view
);
71 glTextureView(view
, target
, tex
, view_format
, 0, 1, 0, 1);
72 glBindTexture(target
, view
);
73 glTexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, 0);
75 /* reset texData to gray */
76 for (i
= 0; i
< TEX_NUMPIXELS
; ++i
) {
80 /* Get tex image data from the view */
81 glGetTexImage(target
, 0, GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8
, texData
);
83 if (texData
[0] != RED
) {
84 printf("Wrong color for %s texture view.\n",
85 piglit_get_gl_enum_name(view_format
));
86 printf("Expected 0x%08x but found 0x%08x \n",
91 /* should have been no errors */
92 if (!piglit_check_gl_error(GL_NO_ERROR
))
95 /* if we get here, we passed */
96 glDeleteTextures(1, &view
);
97 glDeleteTextures(1, &tex
);
107 pass
= test_srgb_view(GL_RGBA8
) && pass
;
108 pass
= test_srgb_view(GL_SRGB8_ALPHA8
) && pass
;
110 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
115 piglit_init(int argc
, char *argv
[])
117 piglit_require_extension("GL_ARB_texture_storage");
118 piglit_require_extension("GL_ARB_texture_view");
119 piglit_require_extension("GL_EXT_texture_sRGB");