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  esextcTextureBufferErrors.hpp
26  * \brief TexBufferEXT and TexBufferRangeEXT errors (Test 7)
27  */ /*-------------------------------------------------------------------*/
28 
29 #include "esextcTextureBufferErrors.hpp"
30 #include "gluContextInfo.hpp"
31 #include "gluDefs.hpp"
32 #include "glwEnums.hpp"
33 #include "glwFunctions.hpp"
34 #include "tcuTestLog.hpp"
35 #include <cstddef>
36 
37 namespace glcts
38 {
39 
40 /* Size of buffer object's data store */
41 const glw::GLint TextureBufferErrors::m_bo_size =
42     256 /* number of texels */ * 4 /* number of components */ * sizeof(glw::GLint);
43 
44 /** Constructor
45  *
46  * @param context     Test context
47  * @param name        Test case's name
48  * @param description Test case's description
49  **/
TextureBufferErrors(Context & context,const ExtParameters & extParams,const char * name,const char * description)50 TextureBufferErrors::TextureBufferErrors(Context &context, const ExtParameters &extParams, const char *name,
51                                          const char *description)
52     : TestCaseBase(context, extParams, name, description)
53     , m_bo_id(0)
54     , m_tex_id(0)
55 {
56 }
57 
58 /** Deinitializes all GLES objects created for the test. */
deinit(void)59 void TextureBufferErrors::deinit(void)
60 {
61     /* Retrieve GLES entry points. */
62     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
63 
64     /* Reset GLES state */
65     gl.bindTexture(m_glExtTokens.TEXTURE_BUFFER, 0);
66     gl.bindBuffer(m_glExtTokens.TEXTURE_BUFFER, 0);
67 
68     /* Delete GLES objects */
69     if (m_tex_id != 0)
70     {
71         gl.deleteTextures(1, &m_tex_id);
72         m_tex_id = 0;
73     }
74 
75     if (m_bo_id != 0)
76     {
77         gl.deleteBuffers(1, &m_bo_id);
78         m_bo_id = 0;
79     }
80 
81     /* Deinitialize base class */
82     TestCaseBase::deinit();
83 }
84 
85 /** Initializes all GLES objects and reference values for the test. */
initTest(void)86 void TextureBufferErrors::initTest(void)
87 {
88     /* Skip if required extensions are not supported. */
89     if (!m_is_texture_buffer_supported)
90     {
91         throw tcu::NotSupportedError(TEXTURE_BUFFER_EXTENSION_NOT_SUPPORTED, "", __FILE__, __LINE__);
92     }
93 
94     /* Retrieve GLES entry points. */
95     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
96 
97     gl.genTextures(1, &m_tex_id);
98     GLU_EXPECT_NO_ERROR(gl.getError(), "Could not generate texture object!");
99 
100     gl.bindTexture(m_glExtTokens.TEXTURE_BUFFER, m_tex_id);
101     GLU_EXPECT_NO_ERROR(gl.getError(), "Could not bind texture object!");
102 
103     gl.genBuffers(1, &m_bo_id);
104     GLU_EXPECT_NO_ERROR(gl.getError(), "Could not generate buffer object!");
105 
106     gl.bindBuffer(m_glExtTokens.TEXTURE_BUFFER, m_bo_id);
107     GLU_EXPECT_NO_ERROR(gl.getError(), "Could not bind buffer object!");
108 
109     gl.bufferData(m_glExtTokens.TEXTURE_BUFFER, m_bo_size, DE_NULL, GL_STATIC_READ);
110     GLU_EXPECT_NO_ERROR(gl.getError(), "Could not allocate buffer object's data store");
111 
112     m_texture_targets.push_back(GL_TEXTURE_2D);
113     m_texture_targets.push_back(GL_TEXTURE_2D_ARRAY);
114     m_texture_targets.push_back(GL_TEXTURE_3D);
115     m_texture_targets.push_back(GL_TEXTURE_CUBE_MAP);
116 
117     if (m_is_texture_cube_map_array_supported)
118     {
119         m_texture_targets.push_back(GL_TEXTURE_CUBE_MAP_ARRAY);
120     }
121 
122     if (m_is_texture_storage_multisample_supported)
123     {
124         m_texture_targets.push_back(GL_TEXTURE_2D_MULTISAMPLE);
125     }
126 
127     if (m_is_texture_storage_multisample_2d_array_supported)
128     {
129         m_texture_targets.push_back(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES);
130     }
131 }
132 /** Test if the error code returned by glGetError is the same as expected.
133  *  If the error is different from expected description is logged.
134  *
135  * @param expected_error    GLenum error which is expected
136  * @param description       Log message in the case of failure.
137  *
138  * @return true if error is equal to expected, false otherwise.
139  */
verifyError(const glw::GLenum expected_error,const char * description)140 glw::GLboolean TextureBufferErrors::verifyError(const glw::GLenum expected_error, const char *description)
141 {
142     /* Retrieve GLES entry points. */
143     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
144 
145     glw::GLboolean test_passed = true;
146     glw::GLenum error_code     = gl.getError();
147 
148     if (error_code != expected_error)
149     {
150         test_passed = false;
151 
152         m_testCtx.getLog() << tcu::TestLog::Message << description << tcu::TestLog::EndMessage;
153     }
154 
155     return test_passed;
156 }
157 
158 /** Executes the test.
159  *
160  *  Sets the test result to QP_TEST_RESULT_FAIL if the test failed, QP_TEST_RESULT_PASS otherwise.
161  *
162  *  Note the function throws exception should an error occur!
163  *
164  *  @return STOP if the test has finished, CONTINUE to indicate iterate should be called once again.
165  **/
iterate(void)166 tcu::TestNode::IterateResult TextureBufferErrors::iterate(void)
167 {
168     /* Initialization */
169     initTest();
170 
171     /* Retrieve ES entry/state points. */
172     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
173 
174     glw::GLboolean test_passed = true;
175 
176     /*An INVALID_ENUM error should be generated if target parameter is not TEXTURE_BUFFER_EXT.*/
177     for (TargetsVector::iterator iter = m_texture_targets.begin(); iter != m_texture_targets.end(); ++iter)
178     {
179         gl.texBuffer(*iter, GL_RGBA32I, m_bo_id);
180         test_passed = verifyError(GL_INVALID_ENUM, "Expected GL_INVALID_ENUM was not returned "
181                                                    "when wrong texture target was used in glTexBufferEXT.") &&
182                       test_passed;
183 
184         gl.texBufferRange(*iter, GL_RGBA32I, m_bo_id, 0, m_bo_size);
185         test_passed = verifyError(GL_INVALID_ENUM, "Expected GL_INVALID_ENUM was not returned "
186                                                    "when wrong texture target was used in glTexBufferRangeEXT.") &&
187                       test_passed;
188     }
189 
190     /* An INVALID_ENUM error should be generated if internal format parameter
191      * is not one of the sized internal formats specified in the extension
192      * specification. One of the formats that should generate INVALID_ENUM
193      * error is GL_DEPTH_COMPONENT32F. */
194     gl.texBuffer(m_glExtTokens.TEXTURE_BUFFER, GL_DEPTH_COMPONENT32F, m_bo_id);
195     test_passed = verifyError(GL_INVALID_ENUM, "Expected GL_INVALID_ENUM was not returned "
196                                                "when wrong sized internal format was used "
197                                                "in glTexBufferEXT.") &&
198                   test_passed;
199 
200     gl.texBufferRange(m_glExtTokens.TEXTURE_BUFFER, GL_DEPTH_COMPONENT32F, m_bo_id, 0, m_bo_size);
201     test_passed = verifyError(GL_INVALID_ENUM, "Expected GL_INVALID_ENUM was not returned "
202                                                "when wrong sized internal format was used "
203                                                "in glTexBufferRangeEXT.") &&
204                   test_passed;
205 
206     /* An INVALID_OPERATION error should be generated if buffer parameter
207      * is non-zero, but is not the name of an existing buffer object. */
208     gl.texBuffer(m_glExtTokens.TEXTURE_BUFFER, GL_RGBA32I, m_bo_id + 1);
209     test_passed = verifyError(GL_INVALID_OPERATION, "Expected GL_INVALID_OPERATION was not returned "
210                                                     "when non-existing buffer object was used in glTexBufferEXT.") &&
211                   test_passed;
212 
213     gl.texBufferRange(m_glExtTokens.TEXTURE_BUFFER, GL_RGBA32I, m_bo_id + 1, 0, m_bo_size);
214     test_passed =
215         verifyError(GL_INVALID_OPERATION, "Expected GL_INVALID_OPERATION was not returned "
216                                           "when non-existing buffer object was used in glTexBufferRangeEXT.") &&
217         test_passed;
218 
219     /* INVALID_VALUE error should be generated if offset parameter is negative */
220     gl.texBufferRange(m_glExtTokens.TEXTURE_BUFFER, GL_RGBA32I, m_bo_id, -16, m_bo_size);
221     test_passed = verifyError(GL_INVALID_VALUE, "Expected INVALID_VALUE was not returned "
222                                                 "when negative offset was used in glTexBufferRangeEXT.") &&
223                   test_passed;
224 
225     /* INVALID_VALUE error should be generated if size parameter is less than or equal to zero */
226     gl.texBufferRange(m_glExtTokens.TEXTURE_BUFFER, GL_RGBA32I, m_bo_id, 0, 0);
227     test_passed = verifyError(GL_INVALID_VALUE, "Expected INVALID_VALUE was not returned "
228                                                 "when 0 size was used in glTexBufferRangeEXT.") &&
229                   test_passed;
230 
231     gl.texBufferRange(m_glExtTokens.TEXTURE_BUFFER, GL_RGBA32I, m_bo_id, 0, -1);
232     test_passed = verifyError(GL_INVALID_VALUE, "Expected INVALID_VALUE was not returned "
233                                                 "when negative size was used in glTexBufferRangeEXT.") &&
234                   test_passed;
235 
236     /* INVALID_VALUE error should be generated if offset + size is greater than the value of BUFFER_SIZE */
237     gl.texBufferRange(m_glExtTokens.TEXTURE_BUFFER, GL_RGBA32I, m_bo_id, m_bo_size / 2, m_bo_size);
238     test_passed = verifyError(GL_INVALID_VALUE, "Expected INVALID_VALUE was not returned "
239                                                 "when offset + size is greater than BUFFER_SIZE") &&
240                   test_passed;
241 
242     /* INVALID_VALUE error should be generated if offset parameter is not an integer multiple of
243      * value(TEXTURE_BUFFER_OFFSET_ALIGNMENT_EXT). */
244     glw::GLint texture_buffer_offset_alignment = 0;
245     gl.getIntegerv(m_glExtTokens.TEXTURE_BUFFER_OFFSET_ALIGNMENT, &texture_buffer_offset_alignment);
246 
247     if (texture_buffer_offset_alignment > 1)
248     {
249         gl.texBufferRange(m_glExtTokens.TEXTURE_BUFFER, GL_RGBA32I, m_bo_id, texture_buffer_offset_alignment / 2,
250                           m_bo_size - texture_buffer_offset_alignment / 2);
251         test_passed = verifyError(GL_INVALID_VALUE, "Expected INVALID_VALUE was not returned "
252                                                     "when improperly aligned offset was used "
253                                                     "in glTexBufferRangeEXT.") &&
254                       test_passed;
255     }
256 
257     /* All done */
258     if (test_passed)
259     {
260         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
261     }
262     else
263     {
264         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
265     }
266 
267     return STOP;
268 }
269 
270 } /* namespace glcts */
271