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 esextcTextureCubeMapArrayTex3DValidation.cpp
26 * \brief texture_cube_map_array extenstion - Tex3DValidation (Test 4)
27 */ /*-------------------------------------------------------------------*/
28
29 #include "esextcTextureCubeMapArrayTex3DValidation.hpp"
30
31 #include "gluContextInfo.hpp"
32 #include "gluStrUtil.hpp"
33 #include "glwEnums.hpp"
34 #include "glwFunctions.hpp"
35 #include "tcuTestLog.hpp"
36 #include <cmath>
37
38 namespace glcts
39 {
40
41 /** Constructor
42 *
43 * @param context Test context
44 * @param name Test case's name
45 * @param description Test case's description
46 **/
TextureCubeMapArrayTex3DValidation(Context & context,const ExtParameters & extParams,const char * name,const char * description)47 TextureCubeMapArrayTex3DValidation::TextureCubeMapArrayTex3DValidation(Context& context, const ExtParameters& extParams,
48 const char* name, const char* description)
49 : TestCaseBase(context, extParams, name, description), m_to_id(0)
50 {
51 /* Nothing to be done here */
52 }
53
54 /** Deinitializes GLES objects created during the test.
55 *
56 */
deinit()57 void TextureCubeMapArrayTex3DValidation::deinit()
58 {
59 deleteTexture();
60
61 /* Deinitialize base class */
62 TestCaseBase::deinit();
63 }
64
65 /** Executes the test.
66 *
67 * Sets the test result to QP_TEST_RESULT_FAIL if the test failed, QP_TEST_RESULT_PASS otherwise.
68 *
69 * Note the function throws exception should an error occur!
70 *
71 * @return STOP if the test has finished, CONTINUE to indicate iterate() should be called once again.
72 **/
iterate()73 tcu::TestCase::IterateResult TextureCubeMapArrayTex3DValidation::iterate()
74 {
75 /* Check if GL_EXT_texture_cube_map_array extension is supported */
76 if (!m_is_texture_cube_map_array_supported)
77 {
78 throw tcu::NotSupportedError(TEXTURE_CUBE_MAP_ARRAY_EXTENSION_NOT_SUPPORTED, "", __FILE__, __LINE__);
79 }
80
81 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
82 bool result = true;
83
84 /* Check if GL_INVALID_VALUE is not set if width and height are equal */
85 const glw::GLint correctWidth = 4;
86 const glw::GLint correctHeight = 4;
87 const glw::GLint correctDepth = 6;
88
89 createTexture();
90 gl.texImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, 0 /* level */, GL_RGBA8 /* internalformat*/, correctWidth, correctHeight,
91 correctDepth, 0 /* border */, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
92
93 if (!checkError(GL_NO_ERROR, "glTexImage3D() call failed when called with valid arguments - "))
94 {
95 result = false;
96 }
97
98 gl.texStorage3D(GL_TEXTURE_CUBE_MAP_ARRAY, 1, /* levels */
99 GL_RGBA8, /* internalformat*/
100 correctWidth, correctHeight, correctDepth);
101
102 if (!checkError(GL_NO_ERROR, "glTexStorage3D() call failed when called with valid arguments - "))
103 {
104 result = false;
105 }
106
107 deleteTexture();
108 createTexture();
109
110 /* Check if GL_INVALID_VALUE is set if width and height are not equal*/
111 const glw::GLint incorrectWidth = 4;
112 const glw::GLint incorrectHeight = 3;
113
114 gl.texImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, 0, /* level */
115 GL_RGBA8, /* internalformat*/
116 incorrectWidth, incorrectHeight, correctDepth, 0, /* border */
117 GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
118
119 if (!checkError(GL_INVALID_VALUE, "glTexImage3D() call generated an invalid error code when width != height - "))
120 {
121 result = false;
122 }
123
124 gl.texStorage3D(GL_TEXTURE_CUBE_MAP_ARRAY, 1, /* levels */
125 GL_RGBA8, /* internalformat*/
126 incorrectWidth, incorrectHeight, correctDepth);
127
128 if (!checkError(GL_INVALID_VALUE, "glTexStorage3D() call generated an invalid error code "
129 "when width != height - "))
130 {
131 result = false;
132 }
133
134 deleteTexture();
135 createTexture();
136
137 /* Check if GL_INVALID_VALUE is set if depth is not a multiple of six */
138 const glw::GLint incorrectDepth = 7;
139
140 gl.texImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, 0, /* level */
141 GL_RGBA8, /* internalformat */
142 correctWidth, correctHeight, incorrectDepth, 0, /* border */
143 GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
144
145 if (!checkError(GL_INVALID_VALUE, "glTexImage3D() call generated an invalid error code"
146 " when depth was not a multiple of six - "))
147 {
148 result = false;
149 }
150
151 deleteTexture();
152 createTexture();
153
154 gl.texStorage3D(GL_TEXTURE_CUBE_MAP_ARRAY, 1, /* levels */
155 GL_RGBA8, /* internalformat*/
156 correctWidth, correctHeight, incorrectDepth);
157
158 if (!checkError(GL_INVALID_VALUE, "glTexStorage3D() call generated an invalid error "
159 "code when depth was not a multiple of six - "))
160 {
161 result = false;
162 }
163
164 deleteTexture();
165 createTexture();
166
167 /* Check if GL_INVALID_OPERATION is set if levels argument is greater than floor(log2(max(width, height))) + 1*/
168 const glw::GLfloat maxTextureSize = (glw::GLfloat)de::max(correctWidth, correctHeight);
169 const glw::GLint maxLevels = (glw::GLint)floor(log(maxTextureSize) / log(2.0f)) + 1;
170
171 gl.texStorage3D(GL_TEXTURE_CUBE_MAP_ARRAY, maxLevels + 1, /* levels */
172 GL_RGBA8, /* internalformat*/
173 correctWidth, correctHeight, correctDepth);
174
175 if (!checkError(GL_INVALID_OPERATION, "glTexStorage3D() call generated an invalid error code when levels argument "
176 "was greater than floor(log2(max(width, height))) + 1 - "))
177 {
178 result = false;
179 }
180
181 deleteTexture();
182
183 /* Set Test Result */
184 if (result)
185 {
186 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
187 }
188 else
189 {
190 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
191 }
192
193 return STOP;
194 }
195
196 /** Check if user-specified error is reported by ES implementation.
197 *
198 * @param expectedError anticipated error code.
199 * @param message Message to be logged in case the error codes differ.
200 * Must not be NULL.
201 *
202 * @return returns true if error return by glGetError() is equal expectedError, false otherwise
203 */
checkError(glw::GLint expectedError,const char * message)204 bool TextureCubeMapArrayTex3DValidation::checkError(glw::GLint expectedError, const char* message)
205 {
206 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
207 glw::GLint error = gl.getError();
208 bool result = true;
209
210 if (error != expectedError)
211 {
212 m_testCtx.getLog() << tcu::TestLog::Message << message << " Expected error: " << glu::getErrorStr(expectedError)
213 << " Current error: " << glu::getErrorStr(error) << tcu::TestLog::EndMessage;
214 result = false;
215 }
216
217 return result;
218 }
219
220 /** Generates a texture object and binds it to GL_TEXTURE_CUBE_MAP_ARRAY_EXT texture
221 * target.
222 *
223 */
createTexture()224 void TextureCubeMapArrayTex3DValidation::createTexture()
225 {
226 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
227
228 gl.genTextures(1, &m_to_id);
229 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures() call failed");
230
231 gl.bindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, m_to_id);
232 GLU_EXPECT_NO_ERROR(gl.getError(),
233 "Error binding the texture object to GL_TEXTURE_CUBE_MAP_ARRAY_EXT texture target!");
234 }
235
236 /** Delete a texture object that is being used by the test at
237 * the time of the call.
238 *
239 **/
deleteTexture()240 void TextureCubeMapArrayTex3DValidation::deleteTexture()
241 {
242 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
243
244 if (m_is_texture_cube_map_array_supported)
245 {
246 /* Unbind any bound texture to GL_TEXTURE_CUBE_MAP_ARRAY_EXT target */
247 gl.bindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, 0);
248 GLU_EXPECT_NO_ERROR(gl.getError(),
249 "glBindTexture() call failed for GL_TEXTURE_CUBE_MAP_ARRAY_EXT texture target");
250 }
251
252 /* Delete texture object */
253 if (m_to_id != 0)
254 {
255 gl.deleteTextures(1, &m_to_id);
256 GLU_EXPECT_NO_ERROR(gl.getError(), "glDeleteTextures() call failed");
257
258 m_to_id = 0;
259 }
260 }
261
262 } /* glcts */
263