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  esextcTextureBufferParameters.cpp
26  * \brief Texture Buffer GetTexLevelParameter and GetIntegerv test (Test 6)
27  */ /*-------------------------------------------------------------------*/
28 
29 #include "esextcTextureBufferParameters.hpp"
30 #include "gluContextInfo.hpp"
31 #include "gluDefs.hpp"
32 #include "glwEnums.hpp"
33 #include "glwFunctions.hpp"
34 #include "tcuTestLog.hpp"
35 #include <stddef.h>
36 
37 namespace glcts
38 {
39 
40 const glw::GLuint TextureBufferParameters::m_n_texels_phase_one = 128;
41 const glw::GLuint TextureBufferParameters::m_n_texels_phase_two = 256;
42 
43 /** Constructor
44  *
45  * @param context     Test context
46  * @param name        Test case's name
47  * @param description Test case's description
48  **/
TextureBufferParameters(Context & context,const ExtParameters & extParams,const char * name,const char * description)49 TextureBufferParameters::TextureBufferParameters(Context &context, const ExtParameters &extParams, const char *name,
50                                                  const char *description)
51     : TestCaseBase(context, extParams, name, description)
52     , m_tbo_id(0)
53     , m_to_id(0)
54 {
55 }
56 
57 /** Initializes all GLES objects and reference values for the test. */
initTest(void)58 void TextureBufferParameters::initTest(void)
59 {
60     /* Skip if required extensions are not supported. */
61     if (!m_is_texture_buffer_supported)
62     {
63         throw tcu::NotSupportedError(TEXTURE_BUFFER_EXTENSION_NOT_SUPPORTED, "", __FILE__, __LINE__);
64     }
65 
66     m_internal_formats[GL_R8]       = sizeof(glw::GLubyte) * 1 /* components */;
67     m_internal_formats[GL_R16F]     = sizeof(glw::GLhalf) * 1 /* components */;
68     m_internal_formats[GL_R32F]     = sizeof(glw::GLfloat) * 1 /* components */;
69     m_internal_formats[GL_R8I]      = sizeof(glw::GLbyte) * 1 /* components */;
70     m_internal_formats[GL_R16I]     = sizeof(glw::GLshort) * 1 /* components */;
71     m_internal_formats[GL_R32I]     = sizeof(glw::GLint) * 1 /* components */;
72     m_internal_formats[GL_R8UI]     = sizeof(glw::GLubyte) * 1 /* components */;
73     m_internal_formats[GL_R16UI]    = sizeof(glw::GLushort) * 1 /* components */;
74     m_internal_formats[GL_R32UI]    = sizeof(glw::GLuint) * 1 /* components */;
75     m_internal_formats[GL_RG8]      = sizeof(glw::GLubyte) * 2 /* components */;
76     m_internal_formats[GL_RG16F]    = sizeof(glw::GLhalf) * 2 /* components */;
77     m_internal_formats[GL_RG32F]    = sizeof(glw::GLfloat) * 2 /* components */;
78     m_internal_formats[GL_RG8I]     = sizeof(glw::GLbyte) * 2 /* components */;
79     m_internal_formats[GL_RG16I]    = sizeof(glw::GLshort) * 2 /* components */;
80     m_internal_formats[GL_RG32I]    = sizeof(glw::GLint) * 2 /* components */;
81     m_internal_formats[GL_RG8UI]    = sizeof(glw::GLubyte) * 2 /* components */;
82     m_internal_formats[GL_RG16UI]   = sizeof(glw::GLushort) * 2 /* components */;
83     m_internal_formats[GL_RG32UI]   = sizeof(glw::GLuint) * 2 /* components */;
84     m_internal_formats[GL_RGB32F]   = sizeof(glw::GLfloat) * 3 /* components */;
85     m_internal_formats[GL_RGB32I]   = sizeof(glw::GLint) * 3 /* components */;
86     m_internal_formats[GL_RGB32UI]  = sizeof(glw::GLuint) * 3 /* components */;
87     m_internal_formats[GL_RGBA8]    = sizeof(glw::GLubyte) * 4 /* components */;
88     m_internal_formats[GL_RGBA16F]  = sizeof(glw::GLhalf) * 4 /* components */;
89     m_internal_formats[GL_RGBA32F]  = sizeof(glw::GLfloat) * 4 /* components */;
90     m_internal_formats[GL_RGBA8I]   = sizeof(glw::GLbyte) * 4 /* components */;
91     m_internal_formats[GL_RGBA16I]  = sizeof(glw::GLshort) * 4 /* components */;
92     m_internal_formats[GL_RGBA32I]  = sizeof(glw::GLint) * 4 /* components */;
93     m_internal_formats[GL_RGBA8UI]  = sizeof(glw::GLubyte) * 4 /* components */;
94     m_internal_formats[GL_RGBA16UI] = sizeof(glw::GLushort) * 4 /* components */;
95     m_internal_formats[GL_RGBA32UI] = sizeof(glw::GLuint) * 4 /* components */;
96 
97     /* Retrieve GLES entry points. */
98     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
99 
100     gl.genTextures(1, &m_to_id);
101     GLU_EXPECT_NO_ERROR(gl.getError(), "Could not generate texture object!");
102 
103     gl.bindTexture(m_glExtTokens.TEXTURE_BUFFER, m_to_id);
104     GLU_EXPECT_NO_ERROR(gl.getError(), "Could not bind texture object!");
105 
106     gl.genBuffers(1, &m_tbo_id);
107     GLU_EXPECT_NO_ERROR(gl.getError(), "Could not generate buffer object!");
108 
109     gl.bindBuffer(m_glExtTokens.TEXTURE_BUFFER, m_tbo_id);
110     GLU_EXPECT_NO_ERROR(gl.getError(), "Could not bind buffer object!");
111 }
112 
113 /** Deinitializes GLES objects created during the test */
deinit(void)114 void TextureBufferParameters::deinit(void)
115 {
116     /* Retrieve GLES entry points. */
117     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
118 
119     /* Reset GLES state */
120     gl.bindTexture(m_glExtTokens.TEXTURE_BUFFER, 0);
121     gl.bindBuffer(m_glExtTokens.TEXTURE_BUFFER, 0);
122 
123     /* Delete GLEs objects */
124     if (m_to_id != 0)
125     {
126         gl.deleteTextures(1, &m_to_id);
127         m_to_id = 0;
128     }
129 
130     if (m_tbo_id != 0)
131     {
132         gl.deleteBuffers(1, &m_tbo_id);
133         m_tbo_id = 0;
134     }
135 
136     /* Deinitialize base class */
137     TestCaseBase::deinit();
138 }
139 
140 /** Executes the test.
141  *
142  *  Sets the test result to QP_TEST_RESULT_FAIL if the test failed, QP_TEST_RESULT_PASS otherwise.
143  *
144  *  Note the function throws exception should an error occur!
145  *
146  *  @return STOP if the test has finished, CONTINUE to indicate iterate should be called once again.
147  **/
iterate(void)148 tcu::TestNode::IterateResult TextureBufferParameters::iterate(void)
149 {
150     /* Initialization */
151     initTest();
152 
153     /* Retrieve GLEs entry points. */
154     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
155 
156     glw::GLboolean test_passed = true;
157 
158     /* Check GL_TEXTURE_BINDING_BUFFER_EXT */
159     test_passed = test_passed && queryTextureBufferBinding(m_to_id);
160 
161     /* Check GL_TEXTURE_BUFFER_BINDING_EXT */
162     test_passed = test_passed && queryTextureBindingBuffer(m_tbo_id);
163 
164     /* For each GL_TEXTURE_INTERNAL_FORMAT */
165     for (InternalFormatsMap::iterator iter = m_internal_formats.begin(); iter != m_internal_formats.end(); ++iter)
166     {
167         std::vector<glw::GLubyte> data_phase_one(m_n_texels_phase_one * iter->second, 0);
168         gl.bufferData(m_glExtTokens.TEXTURE_BUFFER, m_n_texels_phase_one * iter->second, &data_phase_one[0],
169                       GL_STATIC_READ);
170         GLU_EXPECT_NO_ERROR(gl.getError(), "Could not allocate buffer object's data store!");
171 
172         gl.texBuffer(m_glExtTokens.TEXTURE_BUFFER, iter->first, m_tbo_id);
173         GLU_EXPECT_NO_ERROR(gl.getError(), "Could not set buffer object as data source for texture buffer!");
174 
175         /* Check GL_TEXTURE_BUFFER_DATA_STORE_BINDING_EXT */
176         test_passed = test_passed && queryTextureBufferDataStoreBinding(m_tbo_id);
177 
178         /* Check GL_TEXTURE_INTERNAL_FORMAT */
179         test_passed = test_passed && queryTextureInternalFormat(iter->first);
180 
181         /* Check GL_TEXTURE_BUFFER_OFFSET_EXT */
182         test_passed = test_passed && queryTextureBufferOffset(0);
183 
184         /* Ckeck GL_TEXTURE_BUFFER_SIZE_EXT */
185         test_passed = test_passed && queryTextureBufferSize(m_n_texels_phase_one * iter->second);
186 
187         /* Ckeck wrong lod level */
188         test_passed = test_passed && queryTextureInvalidLevel();
189 
190         /* Get texture buffer offset alignment */
191         glw::GLint offset_alignment = 0;
192         gl.getIntegerv(m_glExtTokens.TEXTURE_BUFFER_OFFSET_ALIGNMENT, &offset_alignment);
193         GLU_EXPECT_NO_ERROR(gl.getError(), "Could not get texture buffer offset alignment!");
194 
195         /* Resize buffer object */
196         std::vector<glw::GLubyte> data_phase_two(m_n_texels_phase_two * iter->second + offset_alignment, 0);
197         gl.bufferData(m_glExtTokens.TEXTURE_BUFFER, m_n_texels_phase_two * iter->second + offset_alignment,
198                       &data_phase_two[0], GL_STATIC_READ);
199         GLU_EXPECT_NO_ERROR(gl.getError(), "Could not allocate buffer object's data store!");
200 
201         /* Check GL_TEXTURE_BUFFER_OFFSET_EXT */
202         test_passed = test_passed && queryTextureBufferOffset(0);
203 
204         /* Check GL_TEXTURE_BUFFER_SIZE_EXT */
205         test_passed = test_passed && queryTextureBufferSize(m_n_texels_phase_two * iter->second + offset_alignment);
206 
207         gl.texBufferRange(m_glExtTokens.TEXTURE_BUFFER, iter->first, m_tbo_id, offset_alignment,
208                           m_n_texels_phase_two * iter->second);
209         GLU_EXPECT_NO_ERROR(gl.getError(), "Could not set buffer object as data source for texture buffer!");
210 
211         /* Check GL_TEXTURE_BUFFER_OFFSET_EXT */
212         test_passed = test_passed && queryTextureBufferOffset(offset_alignment);
213 
214         /* Check GL_TEXTURE_BUFFER_SIZE_EXT */
215         test_passed = test_passed && queryTextureBufferSize(m_n_texels_phase_two * iter->second);
216 
217         gl.texBuffer(m_glExtTokens.TEXTURE_BUFFER, iter->first, 0);
218         GLU_EXPECT_NO_ERROR(gl.getError(), "Could not reset buffer object binding!");
219     }
220 
221     if (test_passed)
222     {
223         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
224     }
225     else
226     {
227         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
228     }
229 
230     return STOP;
231 }
232 
233 /** Query GL_TEXTURE_BUFFER_BINDING_EXT and compare with the expected value.
234  *
235  *  Note - the function throws exception should an error occur!
236  *
237  *  @param expected     Expected value used for comparison.
238  *
239  *  @return true  if the comparison has passed,
240  *          false if the comparison has failed.
241  **/
queryTextureBindingBuffer(glw::GLint expected)242 glw::GLboolean TextureBufferParameters::queryTextureBindingBuffer(glw::GLint expected)
243 {
244     /* Retrieve GLES entry points. */
245     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
246 
247     glw::GLint result          = -1;
248     glw::GLboolean test_passed = true;
249 
250     gl.getIntegerv(m_glExtTokens.TEXTURE_BUFFER_BINDING, &result);
251     GLU_EXPECT_NO_ERROR(gl.getError(), "Could not query value of GL_TEXTURE_BUFFER_BINDING_EXT");
252 
253     if (result != expected)
254     {
255         test_passed = false;
256 
257         m_testCtx.getLog() << tcu::TestLog::Message << "glGetIntegerv(GL_TEXTURE_BINDING_BUFFER_EXT) returned "
258                            << result << " which is not equal to expected buffer object id == " << expected << ".\n"
259                            << tcu::TestLog::EndMessage;
260     }
261 
262     return test_passed;
263 }
264 
265 /** Query GL_TEXTURE_BINDING_BUFFER_EXT and compare with the expected value.
266  *
267  *  Note - the function throws exception should an error occur!
268  *
269  *  @param expected     Expected value used for comparison.
270  *
271  *  @return true  if the comparison has passed,
272  *          false if the comparison has failed.
273  **/
queryTextureBufferBinding(glw::GLint expected)274 glw::GLboolean TextureBufferParameters::queryTextureBufferBinding(glw::GLint expected)
275 {
276     /* Retrieve GLES entry points. */
277     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
278 
279     glw::GLint result          = -1;
280     glw::GLboolean test_passed = true;
281 
282     gl.getIntegerv(m_glExtTokens.TEXTURE_BINDING_BUFFER, &result);
283     GLU_EXPECT_NO_ERROR(gl.getError(), "Could not query value of GL_TEXTURE_BINDING_BUFFER_EXT");
284 
285     if (result != expected)
286     {
287         test_passed = false;
288 
289         m_testCtx.getLog() << tcu::TestLog::Message << "glGetIntegerv(GL_TEXTURE_BUFFER_BINDING_EXT) returned "
290                            << result << " which is not equal to expected texture object id == " << expected << ".\n"
291                            << tcu::TestLog::EndMessage;
292     }
293 
294     return test_passed;
295 }
296 
297 /** Query GL_TEXTURE_BUFFER_DATA_STORE_BINDING_EXT and compare with the expected value.
298  *
299  *  Note - the function throws exception should an error occur!
300  *
301  *  @param expected     Expected value used for comparison.
302  *
303  *  @return true  if the comparison has passed,
304  *          false if the comparison has failed.
305  **/
queryTextureBufferDataStoreBinding(glw::GLint expected)306 glw::GLboolean TextureBufferParameters::queryTextureBufferDataStoreBinding(glw::GLint expected)
307 {
308     /* Retrieve GLES entry points. */
309     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
310 
311     glw::GLint result          = -1;
312     glw::GLboolean test_passed = true;
313 
314     gl.getTexLevelParameteriv(m_glExtTokens.TEXTURE_BUFFER, 0, m_glExtTokens.TEXTURE_BUFFER_DATA_STORE_BINDING,
315                               &result);
316     GLU_EXPECT_NO_ERROR(gl.getError(), "Could not query value of GL_TEXTURE_BUFFER_DATA_STORE_BINDING_EXT");
317 
318     if (result != expected)
319     {
320         test_passed = false;
321 
322         m_testCtx.getLog() << tcu::TestLog::Message
323                            << "glGetTexLevelParameteriv(GL_TEXTURE_BUFFER_DATA_STORE_BINDING_EXT) returned " << result
324                            << " which is not equal to expected buffer object id == " << expected << ".\n"
325                            << tcu::TestLog::EndMessage;
326     }
327 
328     return test_passed;
329 }
330 
331 /** Query GL_TEXTURE_BUFFER_OFFSET_EXT and compare with the expected value.
332  *
333  *  Note - the function throws exception should an error occur!
334  *
335  *  @param expected     Expected value used for comparison.
336  *
337  *  @return true  if the comparison has passed,
338  *          false if the comparison has failed.
339  **/
queryTextureBufferOffset(glw::GLint expected)340 glw::GLboolean TextureBufferParameters::queryTextureBufferOffset(glw::GLint expected)
341 {
342     /* Retrieve GLES entry points. */
343     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
344 
345     glw::GLint result          = -1;
346     glw::GLboolean test_passed = true;
347 
348     gl.getTexLevelParameteriv(m_glExtTokens.TEXTURE_BUFFER, 0, m_glExtTokens.TEXTURE_BUFFER_OFFSET, &result);
349     GLU_EXPECT_NO_ERROR(gl.getError(), "Could not query value of GL_TEXTURE_BUFFER_OFFSET_EXT");
350 
351     if (result != expected)
352     {
353         test_passed = false;
354 
355         m_testCtx.getLog() << tcu::TestLog::Message
356                            << "glGetTexLevelParameteriv(GL_TEXTURE_BUFFER_OFFSET_EXT) returned " << result
357                            << " which is not equal to expected offset " << expected << ".\n"
358                            << tcu::TestLog::EndMessage;
359     }
360 
361     return test_passed;
362 }
363 
364 /** Query GL_TEXTURE_BUFFER_SIZE_EXT and compare with the expected value.
365  *
366  *  Note - the function throws exception should an error occur!
367  *
368  *  @param expected     Expected value used for comparison.
369  *
370  *  @return true  if the comparison has passed,
371  *          false if the comparison has failed.
372  **/
queryTextureBufferSize(glw::GLint expected)373 glw::GLboolean TextureBufferParameters::queryTextureBufferSize(glw::GLint expected)
374 {
375     /* Retrieve GLES entry points. */
376     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
377 
378     glw::GLint result          = -1;
379     glw::GLboolean test_passed = true;
380 
381     gl.getTexLevelParameteriv(m_glExtTokens.TEXTURE_BUFFER, 0, m_glExtTokens.TEXTURE_BUFFER_SIZE, &result);
382     GLU_EXPECT_NO_ERROR(gl.getError(), "Could not query value of GL_TEXTURE_BUFFER_SIZE_EXT");
383 
384     if (result != expected)
385     {
386         test_passed = false;
387 
388         m_testCtx.getLog() << tcu::TestLog::Message << "glGetTexLevelParameteriv(GL_TEXTURE_BUFFER_SIZE_EXT) returned "
389                            << result << " which is not equal to expected size " << expected << ".\n"
390                            << tcu::TestLog::EndMessage;
391     }
392 
393     return test_passed;
394 }
395 
396 /** Query GL_TEXTURE_INTERNAL_FORMAT and compare with the expected value.
397  *
398  *  Note - the function throws exception should an error occur!
399  *
400  *  @param expected     Expected value used for comparison.
401  *
402  *  @return true  if the comparison has passed,
403  *          false if the comparison has failed.
404  **/
queryTextureInternalFormat(glw::GLint expected)405 glw::GLboolean TextureBufferParameters::queryTextureInternalFormat(glw::GLint expected)
406 {
407     /* Retrieve GLES entry points. */
408     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
409 
410     glw::GLint result          = -1;
411     glw::GLboolean test_passed = true;
412 
413     gl.getTexLevelParameteriv(m_glExtTokens.TEXTURE_BUFFER, 0, GL_TEXTURE_INTERNAL_FORMAT, &result);
414     GLU_EXPECT_NO_ERROR(gl.getError(), "Could not query value of GL_TEXTURE_INTERNAL_FORMAT");
415 
416     if (result != expected)
417     {
418         test_passed = false;
419 
420         m_testCtx.getLog() << tcu::TestLog::Message << "glGetTexLevelParameteriv(GL_TEXTURE_INTERNAL_FORMAT) returned "
421                            << result << " which is not equal to expected internal format " << expected
422                            << tcu::TestLog::EndMessage;
423     }
424 
425     return test_passed;
426 }
427 
428 /** Query GL_TEXTURE_BUFFER_SIZE_EXT with invalid texture level
429  *   and checks for GL_INVALID_VALUE error.
430  *
431  *  Note - the function throws exception should an error occur!
432  *
433  *  @return true  if the GL_INVALID_VALUE error was generated,
434  *          false if the GL_INVALID_VALUE error was not generated.
435  **/
queryTextureInvalidLevel()436 glw::GLboolean TextureBufferParameters::queryTextureInvalidLevel()
437 {
438     /* Retrieve GLES entry points. */
439     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
440 
441     glw::GLint result          = -1;
442     glw::GLboolean test_passed = true;
443 
444     gl.getTexLevelParameteriv(m_glExtTokens.TEXTURE_BUFFER, 1, m_glExtTokens.TEXTURE_BUFFER_SIZE, &result);
445     glw::GLenum error_code = gl.getError();
446 
447     if (error_code != GL_INVALID_VALUE)
448     {
449         test_passed = false;
450 
451         m_testCtx.getLog() << tcu::TestLog::Message
452                            << "glGetTexLevelParameteriv() called for GL_TEXTURE_BUFFER_EXT texture target "
453                            << "with lod level different than 0 did not generate an GL_INVALID_VALUE error.\n"
454                            << tcu::TestLog::EndMessage;
455     }
456 
457     return test_passed;
458 }
459 
460 } /* namespace glcts */
461