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 esextcTextureBufferBufferParameters.cpp
26 * \brief GetBufferParameteriv and GetBufferPointerv test (Test 9)
27 */ /*-------------------------------------------------------------------*/
28
29 #include "esextcTextureBufferBufferParameters.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 /* Size of buffer object's data store */
41 const glw::GLint TextureBufferBufferParameters::m_bo_size =
42 256 /* number of texels */ * sizeof(glw::GLubyte) /* size of one texel */;
43
44 /** Constructor
45 *
46 * @param context Test context
47 * @param name Test case's name
48 * @param description Test case's description
49 **/
TextureBufferBufferParameters(Context & context,const ExtParameters & extParams,const char * name,const char * description)50 TextureBufferBufferParameters::TextureBufferBufferParameters(Context &context, const ExtParameters &extParams,
51 const char *name, const char *description)
52 : TestCaseBase(context, extParams, name, description)
53 , m_bo_id(0)
54 , m_buffer_pointer(DE_NULL)
55 {
56 }
57
58 /** Deinitializes all GLES objects created for the test. */
deinit(void)59 void TextureBufferBufferParameters::deinit(void)
60 {
61 /* Retrieve GLES entry points. */
62 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
63
64 /* Reset GLES state */
65 gl.bindBuffer(m_glExtTokens.TEXTURE_BUFFER, 0);
66 gl.unmapBuffer(m_glExtTokens.TEXTURE_BUFFER);
67 gl.getError();
68 m_buffer_pointer = DE_NULL;
69
70 /* Delete GLES objects */
71 if (m_bo_id != 0)
72 {
73 gl.deleteBuffers(1, &m_bo_id);
74 m_bo_id = 0;
75 }
76
77 /* Deinitialize base class */
78 TestCaseBase::deinit();
79 }
80
81 /** Initializes all GLES objects and reference values for the test. */
initTest(void)82 void TextureBufferBufferParameters::initTest(void)
83 {
84 /* Skip if required extensions are not supported. */
85 if (!m_is_texture_buffer_supported)
86 {
87 throw tcu::NotSupportedError(TEXTURE_BUFFER_EXTENSION_NOT_SUPPORTED, "", __FILE__, __LINE__);
88 }
89
90 /* Retrieve GLES entry points. */
91 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
92
93 gl.genBuffers(1, &m_bo_id);
94 GLU_EXPECT_NO_ERROR(gl.getError(), "Could not generate buffer object!");
95
96 gl.bindBuffer(m_glExtTokens.TEXTURE_BUFFER, m_bo_id);
97 GLU_EXPECT_NO_ERROR(gl.getError(), "Could not bind buffer object!");
98 }
99
100 /** Query the data using glGetBufferParameteriv and compare against expected_data.
101 *
102 * @param target buffer target
103 * @param pname queried parameter name
104 * @param expected_data expected return from OpenGL
105 *
106 * @return true if queried data is equal to expected_data, false otherwise.
107 */
queryBufferParameteriv(glw::GLenum target,glw::GLenum pname,glw::GLint expected_data)108 glw::GLboolean TextureBufferBufferParameters::queryBufferParameteriv(glw::GLenum target, glw::GLenum pname,
109 glw::GLint expected_data)
110 {
111 /* Retrieve GLES entry points. */
112 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
113
114 glw::GLint result = -1;
115 glw::GLboolean test_passed = true;
116
117 gl.getBufferParameteriv(target, pname, &result);
118 GLU_EXPECT_NO_ERROR(gl.getError(), "Could not query for value of buffer object's parameter!");
119
120 if (result != expected_data)
121 {
122 test_passed = false;
123
124 m_testCtx.getLog() << tcu::TestLog::Message << "glGetBufferParameteriv(pname == " << pname << ") returned "
125 << result << " which is not equal to expected value " << expected_data << "."
126 << tcu::TestLog::EndMessage;
127 }
128
129 return test_passed;
130 }
131
132 /** Query the data using glGetBufferParameteri64v and compare against expected_data.
133 *
134 * @param target buffer target
135 * @param pname queried parameter name
136 * @param expected_data expected return from OpenGL
137 *
138 * @return true if queried data is equal to expected_data, false otherwise.
139 */
queryBufferParameteri64v(glw::GLenum target,glw::GLenum pname,glw::GLint64 expected_data)140 glw::GLboolean TextureBufferBufferParameters::queryBufferParameteri64v(glw::GLenum target, glw::GLenum pname,
141 glw::GLint64 expected_data)
142 {
143 /* Retrieve GLES entry points. */
144 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
145
146 glw::GLint64 result = -1;
147 glw::GLboolean test_passed = true;
148
149 gl.getBufferParameteri64v(target, pname, &result);
150 GLU_EXPECT_NO_ERROR(gl.getError(), "Could not query for value of buffer object's parameter!");
151
152 if (result != expected_data)
153 {
154 test_passed = false;
155
156 m_testCtx.getLog() << tcu::TestLog::Message << "glGetBufferParameteri64v(pname == " << pname << ") returned "
157 << result << " which is not equal to expected value " << expected_data << "."
158 << tcu::TestLog::EndMessage;
159 }
160
161 return test_passed;
162 }
163
164 /** Query the mapped pointer using glGetBufferPointerv and compare against expected_pointer.
165 *
166 * @param target buffer target
167 * @param pname queried parameter name
168 * @param expected_pointer expected return pointer from OpenGL
169 *
170 * @return true if queried pointer is equal to expected_params, false otherwise.
171 */
queryBufferPointerv(glw::GLenum target,glw::GLenum pname,glw::GLvoid * expected_pointer)172 glw::GLboolean TextureBufferBufferParameters::queryBufferPointerv(glw::GLenum target, glw::GLenum pname,
173 glw::GLvoid *expected_pointer)
174 {
175 /* Retrieve GLES entry points. */
176 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
177
178 glw::GLvoid *result_pointer = DE_NULL;
179 glw::GLboolean test_passed = true;
180
181 gl.getBufferPointerv(target, pname, &result_pointer);
182 GLU_EXPECT_NO_ERROR(gl.getError(), "Could not get the mapped buffer's pointer using getBufferPointerv!");
183
184 if (result_pointer != expected_pointer)
185 {
186 test_passed = false;
187
188 m_testCtx.getLog() << tcu::TestLog::Message << "glGetBufferPointerv(pname == " << pname << ") returned pointer "
189 << result_pointer << " which is not equal to expected pointer " << expected_pointer << "."
190 << tcu::TestLog::EndMessage;
191 }
192
193 return test_passed;
194 }
195
196 /** Executes the test.
197 *
198 * Sets the test result to QP_TEST_RESULT_FAIL if the test failed, QP_TEST_RESULT_PASS otherwise.
199 *
200 * Note the function throws exception should an error occur!
201 *
202 * @return STOP if the test has finished, CONTINUE to indicate iterate should be called once again.
203 **/
iterate(void)204 tcu::TestNode::IterateResult TextureBufferBufferParameters::iterate(void)
205 {
206 /* Retrieve GLES entry points. */
207 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
208
209 /* Initialization */
210 initTest();
211
212 glw::GLboolean test_passed = true;
213
214 /* Query GL_BUFFER_SIZE without buffer object's data store initialized */
215 test_passed =
216 queryBufferParameteriv(m_glExtTokens.TEXTURE_BUFFER, GL_BUFFER_SIZE, 0 /* expected size */) && test_passed;
217 test_passed =
218 queryBufferParameteri64v(m_glExtTokens.TEXTURE_BUFFER, GL_BUFFER_SIZE, 0 /* expected size */) && test_passed;
219
220 gl.bufferData(m_glExtTokens.TEXTURE_BUFFER, m_bo_size, DE_NULL, GL_STATIC_READ);
221 GLU_EXPECT_NO_ERROR(gl.getError(), "Could not initialize buffer object's data store!");
222
223 /* Query GL_BUFFER_SIZE with buffer object's data store initialized */
224 test_passed = queryBufferParameteriv(m_glExtTokens.TEXTURE_BUFFER, GL_BUFFER_SIZE, m_bo_size /* expected size */) &&
225 test_passed;
226 test_passed = queryBufferParameteri64v(m_glExtTokens.TEXTURE_BUFFER, GL_BUFFER_SIZE,
227 (glw::GLint64)m_bo_size /* expected size */) &&
228 test_passed;
229
230 /* Query GL_BUFFER_USAGE */
231 test_passed = queryBufferParameteriv(m_glExtTokens.TEXTURE_BUFFER, GL_BUFFER_USAGE, GL_STATIC_READ) && test_passed;
232
233 /* Query GL_BUFFER_MAP... pnames without buffer object's data store being mapped */
234 test_passed = queryBufferParameteriv(m_glExtTokens.TEXTURE_BUFFER, GL_BUFFER_MAPPED, GL_FALSE) && test_passed;
235
236 test_passed = queryBufferParameteriv(m_glExtTokens.TEXTURE_BUFFER, GL_BUFFER_MAP_OFFSET, 0 /* expected offset */) &&
237 test_passed;
238 test_passed =
239 queryBufferParameteri64v(m_glExtTokens.TEXTURE_BUFFER, GL_BUFFER_MAP_OFFSET, 0 /* expected offset */) &&
240 test_passed;
241
242 test_passed = queryBufferParameteriv(m_glExtTokens.TEXTURE_BUFFER, GL_BUFFER_MAP_LENGTH, 0 /* expected size */) &&
243 test_passed;
244 test_passed = queryBufferParameteri64v(m_glExtTokens.TEXTURE_BUFFER, GL_BUFFER_MAP_LENGTH, 0 /* expected size */) &&
245 test_passed;
246
247 test_passed =
248 queryBufferPointerv(m_glExtTokens.TEXTURE_BUFFER, GL_BUFFER_MAP_POINTER, (glw::GLvoid *)DE_NULL) && test_passed;
249
250 /* Mapping whole buffer object's data store */
251 m_buffer_pointer = (glw::GLubyte *)gl.mapBufferRange(m_glExtTokens.TEXTURE_BUFFER, 0, m_bo_size, GL_MAP_READ_BIT);
252 GLU_EXPECT_NO_ERROR(gl.getError(), "Could not map buffer object's data store to client's address space!");
253
254 /* Query GL_BUFFER_MAP... pnames with buffer object's data store being mapped */
255 test_passed = queryBufferParameteriv(m_glExtTokens.TEXTURE_BUFFER, GL_BUFFER_MAPPED, GL_TRUE) && test_passed;
256
257 test_passed = queryBufferParameteriv(m_glExtTokens.TEXTURE_BUFFER, GL_BUFFER_MAP_OFFSET, 0 /* expected offset */) &&
258 test_passed;
259 test_passed =
260 queryBufferParameteri64v(m_glExtTokens.TEXTURE_BUFFER, GL_BUFFER_MAP_OFFSET, 0 /* expected offset */) &&
261 test_passed;
262
263 test_passed =
264 queryBufferParameteriv(m_glExtTokens.TEXTURE_BUFFER, GL_BUFFER_MAP_LENGTH, m_bo_size /* expected size */) &&
265 test_passed;
266 test_passed = queryBufferParameteri64v(m_glExtTokens.TEXTURE_BUFFER, GL_BUFFER_MAP_LENGTH,
267 (glw::GLint64)m_bo_size /* expected size */) &&
268 test_passed;
269
270 test_passed =
271 queryBufferParameteriv(m_glExtTokens.TEXTURE_BUFFER, GL_BUFFER_ACCESS_FLAGS, GL_MAP_READ_BIT) && test_passed;
272
273 test_passed =
274 queryBufferPointerv(m_glExtTokens.TEXTURE_BUFFER, GL_BUFFER_MAP_POINTER, (glw::GLvoid *)m_buffer_pointer) &&
275 test_passed;
276
277 /* Unmapping buffer object's data store */
278 m_buffer_pointer = DE_NULL;
279 gl.unmapBuffer(m_glExtTokens.TEXTURE_BUFFER);
280 GLU_EXPECT_NO_ERROR(gl.getError(), "Unmapping buffer failed");
281
282 /* Mapping part of buffer object's data store */
283 m_buffer_pointer = (glw::GLubyte *)gl.mapBufferRange(m_glExtTokens.TEXTURE_BUFFER, m_bo_size / 2 /* offset */,
284 m_bo_size / 2 /* size */, GL_MAP_WRITE_BIT);
285 GLU_EXPECT_NO_ERROR(gl.getError(), "Could not map buffer object's data store to client's address space!");
286
287 /* Query GL_BUFFER_MAP... pnames with buffer object's data store being mapped */
288 test_passed = queryBufferParameteriv(m_glExtTokens.TEXTURE_BUFFER, GL_BUFFER_MAPPED, GL_TRUE) && test_passed;
289
290 test_passed = queryBufferParameteriv(m_glExtTokens.TEXTURE_BUFFER, GL_BUFFER_MAP_OFFSET,
291 (m_bo_size / 2) /* expected offset */) &&
292 test_passed;
293 test_passed = queryBufferParameteri64v(m_glExtTokens.TEXTURE_BUFFER, GL_BUFFER_MAP_OFFSET,
294 (glw::GLint64)(m_bo_size / 2) /* expected offset */) &&
295 test_passed;
296
297 test_passed = queryBufferParameteriv(m_glExtTokens.TEXTURE_BUFFER, GL_BUFFER_MAP_LENGTH,
298 (m_bo_size / 2) /* expected size */) &&
299 test_passed;
300 test_passed = queryBufferParameteri64v(m_glExtTokens.TEXTURE_BUFFER, GL_BUFFER_MAP_LENGTH,
301 (glw::GLint64)(m_bo_size / 2) /* expected size */) &&
302 test_passed;
303
304 test_passed =
305 queryBufferParameteriv(m_glExtTokens.TEXTURE_BUFFER, GL_BUFFER_ACCESS_FLAGS, GL_MAP_WRITE_BIT) && test_passed;
306
307 test_passed =
308 queryBufferPointerv(m_glExtTokens.TEXTURE_BUFFER, GL_BUFFER_MAP_POINTER, (glw::GLvoid *)m_buffer_pointer) &&
309 test_passed;
310
311 /* Unmapping buffer object's data store */
312 m_buffer_pointer = DE_NULL;
313 gl.unmapBuffer(m_glExtTokens.TEXTURE_BUFFER);
314 GLU_EXPECT_NO_ERROR(gl.getError(), "Unmapping buffer failed");
315
316 if (test_passed)
317 {
318 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
319 }
320 else
321 {
322 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
323 }
324
325 return STOP;
326 }
327
328 } /* namespace glcts */
329