1 /*-------------------------------------------------------------------------
2 * OpenGL Conformance Test Suite
3 * -----------------------------
4 *
5 * Copyright (c) 2014-2016 The Khronos Group Inc.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 */ /*!
20 * \file
21 * \brief
22 */ /*-------------------------------------------------------------------*/
23
24 /*!
25 * \file esextcTextureCubeMapArrayFBOIncompleteness.cpp
26 * \brief texture_cube_map_array extenstion - FBO incompleteness (Test 9)
27 */ /*-------------------------------------------------------------------*/
28
29 #include "esextcTextureCubeMapArrayFBOIncompleteness.hpp"
30
31 #include "gluContextInfo.hpp"
32 #include "gluStrUtil.hpp"
33 #include "glwEnums.hpp"
34 #include "glwFunctions.hpp"
35 #include "tcuTestLog.hpp"
36
37 namespace glcts
38 {
39
40 /** Constructor
41 *
42 * @param context Test context
43 * @param name Test case's name
44 * @param description Test case's description
45 **/
TextureCubeMapArrayFBOIncompleteness(Context & context,const ExtParameters & extParams,const char * name,const char * description)46 TextureCubeMapArrayFBOIncompleteness::TextureCubeMapArrayFBOIncompleteness(Context& context,
47 const ExtParameters& extParams,
48 const char* name, const char* description)
49 : TestCaseBase(context, extParams, name, description)
50 , m_fbo_id(0)
51 , m_lots_of_layers_to_id(0)
52 , m_non_layered_to_id(0)
53 , m_small_to_id(0)
54 {
55 /* Nothing to be done here */
56 }
57
58 /** Verifies an expected FBO completeness status is reported for FBO that is currently
59 * bound to GL_DRAW_FRAMEBUFFER FBO binding.
60 *
61 * @param expected_state Anticipated FBO completeness status;
62 * @param message Error message to prepend logged error message.
63 *
64 * @return true if framebuffer state is equal to @param expectedState;
65 * false otherwise
66 */
checkState(glw::GLint expected_state,const char * message)67 glw::GLboolean TextureCubeMapArrayFBOIncompleteness::checkState(glw::GLint expected_state, const char* message)
68 {
69 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
70 glw::GLenum fbo_completeness = gl.checkFramebufferStatus(GL_DRAW_FRAMEBUFFER);
71 glw::GLboolean result = true;
72
73 /* if fboCompleteness is different than expectedState log error */
74 if (fbo_completeness != (glw::GLuint)expected_state)
75 {
76 m_testCtx.getLog() << tcu::TestLog::Message << message << "; FBO should be in "
77 << glu::getErrorStr(expected_state)
78 << " state, but is in : " << glu::getErrorStr(fbo_completeness) << " state"
79 << tcu::TestLog::EndMessage;
80
81 result = false;
82 }
83
84 return result;
85 }
86
87 /** Deinitialize test case
88 *
89 **/
deinit()90 void TextureCubeMapArrayFBOIncompleteness::deinit()
91 {
92 /* Retrieve GL entry point */
93 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
94
95 /* Reset FBO and texture bindings */
96 gl.bindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
97 gl.bindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, 0);
98 gl.bindTexture(GL_TEXTURE_2D, 0);
99
100 /* Release all ES objects the test may have created */
101 if (m_fbo_id != 0)
102 {
103 gl.deleteFramebuffers(1, &m_fbo_id);
104
105 m_fbo_id = 0;
106 }
107
108 if (m_non_layered_to_id != 0)
109 {
110 gl.deleteTextures(1, &m_non_layered_to_id);
111
112 m_non_layered_to_id = 0;
113 }
114
115 if (m_small_to_id != 0)
116 {
117 gl.deleteTextures(1, &m_small_to_id);
118
119 m_small_to_id = 0;
120 }
121
122 if (m_lots_of_layers_to_id != 0)
123 {
124 gl.deleteTextures(1, &m_lots_of_layers_to_id);
125
126 m_lots_of_layers_to_id = 0;
127 }
128
129 /* Call base class' deinit() */
130 TestCaseBase::deinit();
131 }
132
133 /** Initializes all ES objects necessary to execute the test */
initTest()134 void TextureCubeMapArrayFBOIncompleteness::initTest()
135 {
136 /* Check if texture_cube_map_array extension is supported */
137 if (!m_is_texture_cube_map_array_supported)
138 {
139 throw tcu::NotSupportedError(TEXTURE_CUBE_MAP_ARRAY_EXTENSION_NOT_SUPPORTED);
140 }
141
142 /* Retrieve GL entry point */
143 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
144
145 /* Create texture objects.*/
146 gl.genTextures(1, &m_small_to_id);
147 gl.genTextures(1, &m_lots_of_layers_to_id);
148 gl.genTextures(1, &m_non_layered_to_id);
149 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures() call(s) failed");
150
151 /* Create a framebuffer object we will use for the test */
152 gl.genFramebuffers(1, &m_fbo_id);
153 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers() call failed");
154 }
155
156 /** Executes the test.
157 *
158 * Note the function throws exception should an error occur!
159 *
160 * @return Always STOP.
161 **/
iterate()162 tcu::TestCase::IterateResult TextureCubeMapArrayFBOIncompleteness::iterate()
163 {
164 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
165 glw::GLboolean result = true;
166
167 /* Create all ES objects necessary to run the test first */
168 initTest();
169
170 /* Modify the draw framebuffer binding */
171 gl.bindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbo_id);
172 GLU_EXPECT_NO_ERROR(gl.getError(), "Error binding framebuffer object!");
173
174 /* Set up texture storage for small texture */
175 gl.bindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, m_small_to_id);
176 GLU_EXPECT_NO_ERROR(gl.getError(), "Error binding texture object to GL_TEXTURE_CUBE_MAP_ARRAY target.");
177
178 gl.texStorage3D(GL_TEXTURE_CUBE_MAP_ARRAY, m_texture_levels, GL_RGBA8, m_texture_width, m_texture_height,
179 m_small_texture_depth);
180
181 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexStorage3D() call failed.");
182
183 /* Verify that a FBO is considered incomplete, if a non-existing layer
184 * (whose index is larger or equal to the layer count) of a cube-map
185 * array texture is attached to any of the framebuffer's non-layered
186 * attachments.
187 */
188 gl.framebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_small_to_id, 0, /* level */
189 m_small_texture_depth); /* layer */
190
191 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTextureLayer() call failed.");
192
193 result = checkState(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT, "Attachment of an invalid texture layer ");
194
195 /* The remaining parts of the test should only run if EXT_geometry_shader is supported */
196 if (true != m_is_geometry_shader_extension_supported)
197 {
198 m_testCtx.getLog() << tcu::TestLog::Message << "EXT_geometry_shader is not supported, skip remaining tests."
199 << tcu::TestLog::EndMessage;
200 if (result)
201 {
202 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
203 }
204 else
205 {
206 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
207 }
208
209 return STOP;
210 }
211
212 /* In order to check that a framebuffer is considered incomplete if the layer count
213 * of a cube-map array texture that has been bound to a layered framebuffer is
214 * larger than or equal to GL_MAX_FRAMEBUFFER_LAYERS_EXT, we need to create a cube-map
215 * array texture object that we'll use for the purpose of the test */
216 glw::GLint gl_max_framebuffer_layers_ext_value = 0;
217 glw::GLint gl_max_array_texture_layers = 0;
218 glw::GLint required_to_depth = 0;
219
220 gl.getIntegerv(m_glExtTokens.MAX_FRAMEBUFFER_LAYERS, &gl_max_framebuffer_layers_ext_value);
221 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv() failed for GL_MAX_FRAMEBUFFER_LAYERS_EXT pname");
222
223 gl.getIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &gl_max_array_texture_layers);
224 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv() failed for GL_MAX_ARRAY_TEXTURE_LAYERS pname");
225
226 /* Calculate the amount of layers we need our texture object to use. The number has to
227 * be larger than GL_MAX_FRAMEBUFFER_LAYERS_EXT and be a multiple of 6
228 */
229 required_to_depth = ((gl_max_framebuffer_layers_ext_value / 6) + 1) * 6;
230
231 /* Execute only if allowed number of layers for GL_TEXTURE_CUBE_MAP_ARRAY
232 * is greater than GL_MAX_FRAMEBUFFER_LAYERS_EXT
233 */
234 if (required_to_depth <= gl_max_array_texture_layers && required_to_depth > gl_max_framebuffer_layers_ext_value)
235 {
236 /* Bind a new ID to GL_TEXTURE_CUBE_MAP_ARRAY texture target */
237 gl.bindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, m_lots_of_layers_to_id);
238 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture() call failed.");
239
240 /* Configure texture storage */
241 gl.texStorage3D(GL_TEXTURE_CUBE_MAP_ARRAY, m_texture_levels, GL_RGBA8, m_texture_width, m_texture_height,
242 required_to_depth);
243
244 GLU_EXPECT_NO_ERROR(gl.getError(), "Error configuring texture!");
245
246 /* Update the FBO binding */
247 gl.framebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_lots_of_layers_to_id, 0); /* level */
248
249 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTextureEXT() call failed");
250
251 result =
252 checkState(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT, "Attachment of too many layers to a layered framebuffer ");
253 }
254
255 /* Configure storage for a 2D array texture object. We'll need it to verify
256 * that a layered framebuffer is considered incomplete and its status is
257 * reported as GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT, if a single level of
258 * a cube-map array texture AND of a 2D array texture are attached to two
259 * different color attachments of the same framebuffer object.
260 **/
261 gl.bindTexture(GL_TEXTURE_2D_ARRAY, m_non_layered_to_id);
262 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture() call failed");
263
264 gl.texStorage3D(GL_TEXTURE_2D_ARRAY, m_texture_levels, GL_RGBA8, m_texture_width, m_texture_height,
265 m_small_texture_depth);
266
267 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexStorage3D() call failed.");
268
269 /* Configure the FBO attachments */
270 gl.framebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_small_to_id, 0); /* level */
271 gl.framebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, m_non_layered_to_id, 0); /* level */
272
273 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTextureEXT() call(s) failed");
274
275 /* Perform the check */
276 result = checkState(m_glExtTokens.FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS,
277 "Attachment of two textures from different targets to the same FBO ");
278
279 if (result)
280 {
281 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
282 }
283 else
284 {
285 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
286 }
287
288 return STOP;
289 }
290
291 } /* glcts */
292