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