2 * Copyright © 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 * 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 DEALINGS
25 * With Nvidia OpenGL drivers, if we create a TextureView from a cubemap
26 * face other than GL_TEXTURE_CUBE_MAP_POSITIVE_X and attach it to an FBO,
27 * we cannot read back the correct data in the original cubemap texture
28 * by glGetTexImage() with a system memory pointer right after a clearing
32 * -- Present in : Nvidia GTX 650, driver - 325.15
37 #include "piglit-util-gl.h"
39 PIGLIT_GL_TEST_CONFIG_BEGIN
41 config
.supports_gl_core_version
= 32;
42 config
.supports_gl_compat_version
= 32;
44 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DOUBLE
;
45 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
47 PIGLIT_GL_TEST_CONFIG_END
52 #define COLOR_RED 0xFF0000FF
53 #define COLOR_GREEN 0x00FF00FF
54 #define COLOR_BLUE 0x0000FFFF
55 #define COLOR_CYAN 0x00FFFFFF
56 #define COLOR_MAGENTA 0xFF00FFFF
57 #define COLOR_YELLOW 0xFFFF00FF
58 #define COLOR_GRAY 0x7F7F7FFF
59 #define CLEAR_COLOR 0x000033FF
60 #define NUM_VERTICES 4
65 test_cubemap_view(void)
67 const GLuint white
= 0xffffffff;
68 const unsigned int colors
[LEVELS
] = {COLOR_RED
, COLOR_GREEN
,
69 COLOR_BLUE
, COLOR_CYAN
,
70 COLOR_CYAN
, COLOR_MAGENTA
};
71 const unsigned int numPixels
= WIDTH
* HEIGHT
;
72 GLuint texData
[WIDTH
* HEIGHT
];
73 GLuint i
, cubeTex
, view
, fbo
, f
;
75 for (i
= 0; i
< numPixels
; ++i
) {
79 /* Create a cubemap textures */
80 glGenTextures(1, &cubeTex
);
81 glActiveTexture(GL_TEXTURE0
);
82 glBindTexture(GL_TEXTURE_CUBE_MAP
, cubeTex
);
83 glTexStorage2D(GL_TEXTURE_CUBE_MAP
, 1, GL_RGBA8
, WIDTH
, HEIGHT
);
85 for (f
= 0; f
< NUM_FACES
; f
++) {
86 for (i
= 0; i
< numPixels
; i
++) {
87 texData
[i
] = colors
[f
];
90 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ f
,
91 0, 0, 0, WIDTH
, HEIGHT
,
92 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8
,
96 /* Create a texture view from the negative X face of the cubemap */
97 glGenTextures(1, &view
);
98 glTextureView(view
, GL_TEXTURE_2D
, cubeTex
, GL_RGBA8
,
99 0, 1, 1 /* -X face */, 1);
100 glBindTexture(GL_TEXTURE_2D
, view
);
101 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_BASE_LEVEL
, 0);
103 if (!piglit_check_gl_error(GL_NO_ERROR
))
107 glGenFramebuffers(1, &fbo
);
108 glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
109 glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
,
110 GL_TEXTURE_2D
, view
, 0);
111 if (glCheckFramebufferStatus(GL_FRAMEBUFFER
) !=
112 GL_FRAMEBUFFER_COMPLETE
) {
113 printf("incomplete framebuffer at line %d\n", __LINE__
);
117 glDrawBuffer(GL_COLOR_ATTACHMENT0
);
118 if (glCheckFramebufferStatus(GL_FRAMEBUFFER
) !=
119 GL_FRAMEBUFFER_COMPLETE
) {
120 printf("incomplete framebuffer at line %d\n", __LINE__
);
125 glViewport(0, 0, WIDTH
, HEIGHT
);
126 glClearColor(((CLEAR_COLOR
>> 24) & 0xFF) / 255.0f
,
127 ((CLEAR_COLOR
>> 16) & 0xFF) / 255.0f
,
128 ((CLEAR_COLOR
>> 8) & 0xFF) / 255.0f
,
129 ((CLEAR_COLOR
) & 0xFF) / 255.0f
);
130 glClear(GL_COLOR_BUFFER_BIT
);
133 glPixelStorei(GL_PACK_ROW_LENGTH
, WIDTH
);
134 glPixelStorei(GL_PACK_ALIGNMENT
, 1);
135 memset(texData
, 0, sizeof(texData
));
136 glGetTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_X
, 0,
137 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8
, texData
);
139 if (texData
[0] != CLEAR_COLOR
) {
140 printf("At pixel (0,0) expected 0x%x but found 0x%x\n",
141 CLEAR_COLOR
, texData
[0]);
143 glDeleteTextures(1, &cubeTex
);
144 glDeleteTextures(1, &view
);
145 glDeleteFramebuffers(1, &fbo
);
149 if (!piglit_check_gl_error(GL_NO_ERROR
))
152 glDeleteTextures(1, &cubeTex
);
153 glDeleteTextures(1, &view
);
154 glDeleteFramebuffers(1, &fbo
);
162 bool pass
= test_cubemap_view();
163 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
168 piglit_init(int argc
, char **argv
)
170 piglit_require_extension("GL_ARB_texture_storage");
171 piglit_require_extension("GL_ARB_texture_view");