2 * Copyright (c) 2014 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 copying from
28 * a sRGBA texture to another RGBA texture using ARB_copy_image
29 * followed by a GetTexImage() on the RGBA texture results in
30 * swapping of red and blue channels.
33 * -- Present in : Nvidia GTX 650, driver - 319.32
38 #include "piglit-util-gl.h"
40 PIGLIT_GL_TEST_CONFIG_BEGIN
41 config
.supports_gl_compat_version
= 15;
42 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
;
43 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
44 PIGLIT_GL_TEST_CONFIG_END
49 #define TEX_NUMPIXELS (TEX_WIDTH * TEX_HEIGHT)
51 #define RED 0xFF0000FF
52 #define GRAY 0x7F7F7FFF
58 GLenum target
= GL_TEXTURE_2D
;
59 GLuint texData
[TEX_NUMPIXELS
];
60 GLuint texRGBA
, texSRGBA
, i
;
63 for (i
= 0; i
< TEX_NUMPIXELS
; ++i
) {
67 /* Create sRGBA texture */
68 glGenTextures(1, &texSRGBA
);
69 glActiveTextureARB(GL_TEXTURE0
);
70 glBindTexture(target
, texSRGBA
);
71 glTexStorage2D(target
, 1, GL_SRGB8_ALPHA8
, TEX_WIDTH
, TEX_HEIGHT
);
72 glTexSubImage2D(target
, 0, 0, 0, TEX_WIDTH
, TEX_HEIGHT
,
73 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8
, texData
);
75 /* Create RGB texture */
76 glGenTextures(1, &texRGBA
);
77 glBindTexture(target
, texRGBA
);
78 glTexStorage2D(target
, 1, GL_RGBA8
, TEX_WIDTH
, TEX_HEIGHT
);
80 /* Copy data from sRGBA to RGBA texture using arb_copy_image */
81 glCopyImageSubData(texSRGBA
, target
, 0, 0, 0, 0,
82 texRGBA
, target
, 0, 0, 0, 0,
83 TEX_WIDTH
, TEX_HEIGHT
, 1);
85 /* reset texData to gray */
86 for (i
= 0; i
< TEX_NUMPIXELS
; ++i
) {
90 /* Get tex image data from the RGBA texture */
91 glGetTexImage(target
, 0, GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8
, texData
);
93 if (texData
[0] != RED
) {
94 printf("Expected 0x%08x but found 0x%08x \n",
97 glDeleteTextures(1, &texSRGBA
);
98 glDeleteTextures(1, &texRGBA
);
102 /* should have been no errors */
103 if (!piglit_check_gl_error(GL_NO_ERROR
))
106 /* if we get here, we passed */
107 glDeleteTextures(1, &texSRGBA
);
108 glDeleteTextures(1, &texRGBA
);
116 bool pass
= test_srgb_copy();
118 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
123 piglit_init(int argc
, char *argv
[])
125 piglit_require_extension("GL_ARB_copy_image");
126 piglit_require_extension("GL_ARB_texture_storage");
127 piglit_require_extension("GL_EXT_texture_sRGB");