1e5c31af7Sopenharmony_ci/*-------------------------------------------------------------------------
2e5c31af7Sopenharmony_ci * drawElements Quality Program OpenGL ES 3.0 Module
3e5c31af7Sopenharmony_ci * -------------------------------------------------
4e5c31af7Sopenharmony_ci *
5e5c31af7Sopenharmony_ci * Copyright 2014 The Android Open Source Project
6e5c31af7Sopenharmony_ci *
7e5c31af7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
8e5c31af7Sopenharmony_ci * you may not use this file except in compliance with the License.
9e5c31af7Sopenharmony_ci * You may obtain a copy of the License at
10e5c31af7Sopenharmony_ci *
11e5c31af7Sopenharmony_ci *      http://www.apache.org/licenses/LICENSE-2.0
12e5c31af7Sopenharmony_ci *
13e5c31af7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
14e5c31af7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
15e5c31af7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16e5c31af7Sopenharmony_ci * See the License for the specific language governing permissions and
17e5c31af7Sopenharmony_ci * limitations under the License.
18e5c31af7Sopenharmony_ci *
19e5c31af7Sopenharmony_ci *//*!
20e5c31af7Sopenharmony_ci * \file
21e5c31af7Sopenharmony_ci * \brief Buffer Object Query tests.
22e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/
23e5c31af7Sopenharmony_ci
24e5c31af7Sopenharmony_ci#include "es3fBufferObjectQueryTests.hpp"
25e5c31af7Sopenharmony_ci#include "glsStateQueryUtil.hpp"
26e5c31af7Sopenharmony_ci#include "es3fApiCase.hpp"
27e5c31af7Sopenharmony_ci#include "gluRenderContext.hpp"
28e5c31af7Sopenharmony_ci#include "glwEnums.hpp"
29e5c31af7Sopenharmony_ci#include "glwFunctions.hpp"
30e5c31af7Sopenharmony_ci#include "deRandom.hpp"
31e5c31af7Sopenharmony_ci#include "deMath.h"
32e5c31af7Sopenharmony_ci
33e5c31af7Sopenharmony_ci#include <limits>
34e5c31af7Sopenharmony_ci
35e5c31af7Sopenharmony_ciusing namespace glw; // GLint and other GL types
36e5c31af7Sopenharmony_ciusing deqp::gls::StateQueryUtil::StateQueryMemoryWriteGuard;
37e5c31af7Sopenharmony_ci
38e5c31af7Sopenharmony_ci
39e5c31af7Sopenharmony_cinamespace deqp
40e5c31af7Sopenharmony_ci{
41e5c31af7Sopenharmony_cinamespace gles3
42e5c31af7Sopenharmony_ci{
43e5c31af7Sopenharmony_cinamespace Functional
44e5c31af7Sopenharmony_ci{
45e5c31af7Sopenharmony_cinamespace BufferParamVerifiers
46e5c31af7Sopenharmony_ci{
47e5c31af7Sopenharmony_ci
48e5c31af7Sopenharmony_civoid checkIntEquals (tcu::TestContext& testCtx, GLint got, GLint expected)
49e5c31af7Sopenharmony_ci{
50e5c31af7Sopenharmony_ci	using tcu::TestLog;
51e5c31af7Sopenharmony_ci
52e5c31af7Sopenharmony_ci	if (got != expected)
53e5c31af7Sopenharmony_ci	{
54e5c31af7Sopenharmony_ci		testCtx.getLog() << TestLog::Message << "// ERROR: Expected " << expected << "; got " << got << TestLog::EndMessage;
55e5c31af7Sopenharmony_ci		if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
56e5c31af7Sopenharmony_ci			testCtx.setTestResult(QP_TEST_RESULT_FAIL, "got invalid value");
57e5c31af7Sopenharmony_ci	}
58e5c31af7Sopenharmony_ci}
59e5c31af7Sopenharmony_ci
60e5c31af7Sopenharmony_civoid checkPointerEquals (tcu::TestContext& testCtx, const void* got, const void* expected)
61e5c31af7Sopenharmony_ci{
62e5c31af7Sopenharmony_ci	using tcu::TestLog;
63e5c31af7Sopenharmony_ci
64e5c31af7Sopenharmony_ci	if (got != expected)
65e5c31af7Sopenharmony_ci	{
66e5c31af7Sopenharmony_ci		testCtx.getLog() << TestLog::Message << "// ERROR: Expected " << expected << "; got " << got << TestLog::EndMessage;
67e5c31af7Sopenharmony_ci		if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
68e5c31af7Sopenharmony_ci			testCtx.setTestResult(QP_TEST_RESULT_FAIL, "got invalid value");
69e5c31af7Sopenharmony_ci	}
70e5c31af7Sopenharmony_ci}
71e5c31af7Sopenharmony_ci
72e5c31af7Sopenharmony_ciclass BufferParamVerifier : protected glu::CallLogWrapper
73e5c31af7Sopenharmony_ci{
74e5c31af7Sopenharmony_cipublic:
75e5c31af7Sopenharmony_ci						BufferParamVerifier		(const glw::Functions& gl, tcu::TestLog& log, const char* testNamePostfix);
76e5c31af7Sopenharmony_ci	virtual				~BufferParamVerifier	(); // make GCC happy
77e5c31af7Sopenharmony_ci
78e5c31af7Sopenharmony_ci	const char*			getTestNamePostfix		(void) const;
79e5c31af7Sopenharmony_ci
80e5c31af7Sopenharmony_ci	virtual void		verifyInteger			(tcu::TestContext& testCtx, GLenum target, GLenum name, GLint reference)	= DE_NULL;
81e5c31af7Sopenharmony_ci	virtual void		verifyInteger64			(tcu::TestContext& testCtx, GLenum target, GLenum name, GLint64 reference)	= DE_NULL;
82e5c31af7Sopenharmony_ciprivate:
83e5c31af7Sopenharmony_ci	const char*	const	m_testNamePostfix;
84e5c31af7Sopenharmony_ci};
85e5c31af7Sopenharmony_ci
86e5c31af7Sopenharmony_ciBufferParamVerifier::BufferParamVerifier (const glw::Functions& gl, tcu::TestLog& log, const char* testNamePostfix)
87e5c31af7Sopenharmony_ci	: glu::CallLogWrapper	(gl, log)
88e5c31af7Sopenharmony_ci	, m_testNamePostfix		(testNamePostfix)
89e5c31af7Sopenharmony_ci{
90e5c31af7Sopenharmony_ci	enableLogging(true);
91e5c31af7Sopenharmony_ci}
92e5c31af7Sopenharmony_ci
93e5c31af7Sopenharmony_ciBufferParamVerifier::~BufferParamVerifier ()
94e5c31af7Sopenharmony_ci{
95e5c31af7Sopenharmony_ci}
96e5c31af7Sopenharmony_ci
97e5c31af7Sopenharmony_ciconst char* BufferParamVerifier::getTestNamePostfix (void) const
98e5c31af7Sopenharmony_ci{
99e5c31af7Sopenharmony_ci	return m_testNamePostfix;
100e5c31af7Sopenharmony_ci}
101e5c31af7Sopenharmony_ci
102e5c31af7Sopenharmony_ciclass GetBufferParameterIVerifier : public BufferParamVerifier
103e5c31af7Sopenharmony_ci{
104e5c31af7Sopenharmony_cipublic:
105e5c31af7Sopenharmony_ci			GetBufferParameterIVerifier	(const glw::Functions& gl, tcu::TestLog& log);
106e5c31af7Sopenharmony_ci
107e5c31af7Sopenharmony_ci	void	verifyInteger								(tcu::TestContext& testCtx, GLenum target, GLenum name, GLint reference);
108e5c31af7Sopenharmony_ci	void	verifyInteger64								(tcu::TestContext& testCtx, GLenum target, GLenum name, GLint64 reference);
109e5c31af7Sopenharmony_ci};
110e5c31af7Sopenharmony_ci
111e5c31af7Sopenharmony_ciGetBufferParameterIVerifier::GetBufferParameterIVerifier (const glw::Functions& gl, tcu::TestLog& log)
112e5c31af7Sopenharmony_ci	: BufferParamVerifier(gl, log, "_getbufferparameteri")
113e5c31af7Sopenharmony_ci{
114e5c31af7Sopenharmony_ci}
115e5c31af7Sopenharmony_ci
116e5c31af7Sopenharmony_civoid GetBufferParameterIVerifier::verifyInteger (tcu::TestContext& testCtx, GLenum target, GLenum name, GLint reference)
117e5c31af7Sopenharmony_ci{
118e5c31af7Sopenharmony_ci	using tcu::TestLog;
119e5c31af7Sopenharmony_ci
120e5c31af7Sopenharmony_ci	StateQueryMemoryWriteGuard<GLint> state;
121e5c31af7Sopenharmony_ci	glGetBufferParameteriv(target, name, &state);
122e5c31af7Sopenharmony_ci
123e5c31af7Sopenharmony_ci	if (!state.verifyValidity(testCtx))
124e5c31af7Sopenharmony_ci		return;
125e5c31af7Sopenharmony_ci
126e5c31af7Sopenharmony_ci	if (state != reference)
127e5c31af7Sopenharmony_ci	{
128e5c31af7Sopenharmony_ci		testCtx.getLog() << TestLog::Message << "// ERROR: expected " << reference << "; got " << state << TestLog::EndMessage;
129e5c31af7Sopenharmony_ci
130e5c31af7Sopenharmony_ci		if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
131e5c31af7Sopenharmony_ci			testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
132e5c31af7Sopenharmony_ci	}
133e5c31af7Sopenharmony_ci}
134e5c31af7Sopenharmony_ci
135e5c31af7Sopenharmony_civoid GetBufferParameterIVerifier::verifyInteger64 (tcu::TestContext& testCtx, GLenum target, GLenum name, GLint64 reference)
136e5c31af7Sopenharmony_ci{
137e5c31af7Sopenharmony_ci	using tcu::TestLog;
138e5c31af7Sopenharmony_ci
139e5c31af7Sopenharmony_ci	StateQueryMemoryWriteGuard<GLint> state;
140e5c31af7Sopenharmony_ci	glGetBufferParameteriv(target, name, &state);
141e5c31af7Sopenharmony_ci
142e5c31af7Sopenharmony_ci	if (!state.verifyValidity(testCtx))
143e5c31af7Sopenharmony_ci		return;
144e5c31af7Sopenharmony_ci
145e5c31af7Sopenharmony_ci	// check that the converted value would be in the correct range, otherwise checking wont tell us anything
146e5c31af7Sopenharmony_ci	if (!de::inRange(reference, (GLint64)std::numeric_limits<GLint>::min(), (GLint64)std::numeric_limits<GLint>::max()))
147e5c31af7Sopenharmony_ci		return;
148e5c31af7Sopenharmony_ci
149e5c31af7Sopenharmony_ci	if (state != reference)
150e5c31af7Sopenharmony_ci	{
151e5c31af7Sopenharmony_ci		testCtx.getLog() << TestLog::Message << "// ERROR: expected " << reference << "; got " << state << TestLog::EndMessage;
152e5c31af7Sopenharmony_ci
153e5c31af7Sopenharmony_ci		if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
154e5c31af7Sopenharmony_ci			testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
155e5c31af7Sopenharmony_ci	}
156e5c31af7Sopenharmony_ci}
157e5c31af7Sopenharmony_ci
158e5c31af7Sopenharmony_ciclass GetBufferParameterI64Verifier : public BufferParamVerifier
159e5c31af7Sopenharmony_ci{
160e5c31af7Sopenharmony_cipublic:
161e5c31af7Sopenharmony_ci			GetBufferParameterI64Verifier	(const glw::Functions& gl, tcu::TestLog& log);
162e5c31af7Sopenharmony_ci
163e5c31af7Sopenharmony_ci	void	verifyInteger					(tcu::TestContext& testCtx, GLenum target, GLenum name, GLint reference);
164e5c31af7Sopenharmony_ci	void	verifyInteger64					(tcu::TestContext& testCtx, GLenum target, GLenum name, GLint64 reference);
165e5c31af7Sopenharmony_ci};
166e5c31af7Sopenharmony_ci
167e5c31af7Sopenharmony_ciGetBufferParameterI64Verifier::GetBufferParameterI64Verifier (const glw::Functions& gl, tcu::TestLog& log)
168e5c31af7Sopenharmony_ci	: BufferParamVerifier(gl, log, "_getbufferparameteri64")
169e5c31af7Sopenharmony_ci{
170e5c31af7Sopenharmony_ci}
171e5c31af7Sopenharmony_ci
172e5c31af7Sopenharmony_civoid GetBufferParameterI64Verifier::verifyInteger (tcu::TestContext& testCtx, GLenum target, GLenum name, GLint reference)
173e5c31af7Sopenharmony_ci{
174e5c31af7Sopenharmony_ci	using tcu::TestLog;
175e5c31af7Sopenharmony_ci
176e5c31af7Sopenharmony_ci	StateQueryMemoryWriteGuard<GLint64> state;
177e5c31af7Sopenharmony_ci	glGetBufferParameteri64v(target, name, &state);
178e5c31af7Sopenharmony_ci
179e5c31af7Sopenharmony_ci	if (!state.verifyValidity(testCtx))
180e5c31af7Sopenharmony_ci		return;
181e5c31af7Sopenharmony_ci
182e5c31af7Sopenharmony_ci	if (state != reference)
183e5c31af7Sopenharmony_ci	{
184e5c31af7Sopenharmony_ci		testCtx.getLog() << TestLog::Message << "// ERROR: expected " << reference << "; got " << state << TestLog::EndMessage;
185e5c31af7Sopenharmony_ci
186e5c31af7Sopenharmony_ci		if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
187e5c31af7Sopenharmony_ci			testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
188e5c31af7Sopenharmony_ci	}
189e5c31af7Sopenharmony_ci}
190e5c31af7Sopenharmony_ci
191e5c31af7Sopenharmony_civoid GetBufferParameterI64Verifier::verifyInteger64 (tcu::TestContext& testCtx, GLenum target, GLenum name, GLint64 reference)
192e5c31af7Sopenharmony_ci{
193e5c31af7Sopenharmony_ci	using tcu::TestLog;
194e5c31af7Sopenharmony_ci
195e5c31af7Sopenharmony_ci	StateQueryMemoryWriteGuard<GLint64> state;
196e5c31af7Sopenharmony_ci	glGetBufferParameteri64v(target, name, &state);
197e5c31af7Sopenharmony_ci
198e5c31af7Sopenharmony_ci	if (!state.verifyValidity(testCtx))
199e5c31af7Sopenharmony_ci		return;
200e5c31af7Sopenharmony_ci
201e5c31af7Sopenharmony_ci	if (state != reference)
202e5c31af7Sopenharmony_ci	{
203e5c31af7Sopenharmony_ci		testCtx.getLog() << TestLog::Message << "// ERROR: expected " << reference << "; got " << state << TestLog::EndMessage;
204e5c31af7Sopenharmony_ci
205e5c31af7Sopenharmony_ci		if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
206e5c31af7Sopenharmony_ci			testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
207e5c31af7Sopenharmony_ci	}
208e5c31af7Sopenharmony_ci}
209e5c31af7Sopenharmony_ci
210e5c31af7Sopenharmony_ci
211e5c31af7Sopenharmony_ci} // BufferParamVerifiers
212e5c31af7Sopenharmony_ci
213e5c31af7Sopenharmony_cinamespace
214e5c31af7Sopenharmony_ci{
215e5c31af7Sopenharmony_ci
216e5c31af7Sopenharmony_ciusing namespace BufferParamVerifiers;
217e5c31af7Sopenharmony_ci
218e5c31af7Sopenharmony_ci// Tests
219e5c31af7Sopenharmony_ci
220e5c31af7Sopenharmony_ciclass BufferCase : public ApiCase
221e5c31af7Sopenharmony_ci{
222e5c31af7Sopenharmony_cipublic:
223e5c31af7Sopenharmony_ci	BufferCase (Context& context, BufferParamVerifier* verifier, const char* name, const char* description)
224e5c31af7Sopenharmony_ci		: ApiCase			(context, name, description)
225e5c31af7Sopenharmony_ci		, m_bufferTarget	(0)
226e5c31af7Sopenharmony_ci		, m_verifier		(verifier)
227e5c31af7Sopenharmony_ci		, m_testAllTargets	(false)
228e5c31af7Sopenharmony_ci	{
229e5c31af7Sopenharmony_ci	}
230e5c31af7Sopenharmony_ci
231e5c31af7Sopenharmony_ci	virtual void testBuffer (void) = DE_NULL;
232e5c31af7Sopenharmony_ci
233e5c31af7Sopenharmony_ci	void test (void)
234e5c31af7Sopenharmony_ci	{
235e5c31af7Sopenharmony_ci		const GLenum bufferTargets[] =
236e5c31af7Sopenharmony_ci		{
237e5c31af7Sopenharmony_ci			GL_ARRAY_BUFFER, GL_COPY_READ_BUFFER,
238e5c31af7Sopenharmony_ci			GL_TRANSFORM_FEEDBACK_BUFFER, GL_UNIFORM_BUFFER,
239e5c31af7Sopenharmony_ci
240e5c31af7Sopenharmony_ci			GL_COPY_WRITE_BUFFER, GL_ELEMENT_ARRAY_BUFFER,
241e5c31af7Sopenharmony_ci			GL_PIXEL_PACK_BUFFER, GL_PIXEL_UNPACK_BUFFER
242e5c31af7Sopenharmony_ci		};
243e5c31af7Sopenharmony_ci
244e5c31af7Sopenharmony_ci		// most test need only to be run with a subset of targets
245e5c31af7Sopenharmony_ci		const int targets = m_testAllTargets ? DE_LENGTH_OF_ARRAY(bufferTargets) : 4;
246e5c31af7Sopenharmony_ci
247e5c31af7Sopenharmony_ci		for (int ndx = 0; ndx < targets; ++ndx)
248e5c31af7Sopenharmony_ci		{
249e5c31af7Sopenharmony_ci			m_bufferTarget = bufferTargets[ndx];
250e5c31af7Sopenharmony_ci
251e5c31af7Sopenharmony_ci			GLuint bufferId = 0;
252e5c31af7Sopenharmony_ci			glGenBuffers(1, &bufferId);
253e5c31af7Sopenharmony_ci			glBindBuffer(m_bufferTarget, bufferId);
254e5c31af7Sopenharmony_ci			expectError(GL_NO_ERROR);
255e5c31af7Sopenharmony_ci
256e5c31af7Sopenharmony_ci			testBuffer();
257e5c31af7Sopenharmony_ci
258e5c31af7Sopenharmony_ci			glDeleteBuffers(1, &bufferId);
259e5c31af7Sopenharmony_ci			expectError(GL_NO_ERROR);
260e5c31af7Sopenharmony_ci		}
261e5c31af7Sopenharmony_ci	}
262e5c31af7Sopenharmony_ci
263e5c31af7Sopenharmony_ciprotected:
264e5c31af7Sopenharmony_ci	GLenum					m_bufferTarget;
265e5c31af7Sopenharmony_ci	BufferParamVerifier*	m_verifier;
266e5c31af7Sopenharmony_ci	bool					m_testAllTargets;
267e5c31af7Sopenharmony_ci};
268e5c31af7Sopenharmony_ci
269e5c31af7Sopenharmony_ciclass BufferSizeCase : public BufferCase
270e5c31af7Sopenharmony_ci{
271e5c31af7Sopenharmony_cipublic:
272e5c31af7Sopenharmony_ci	BufferSizeCase (Context& context, BufferParamVerifier* verifier, const char* name, const char* description)
273e5c31af7Sopenharmony_ci		: BufferCase(context, verifier, name, description)
274e5c31af7Sopenharmony_ci	{
275e5c31af7Sopenharmony_ci		m_testAllTargets = true;
276e5c31af7Sopenharmony_ci	}
277e5c31af7Sopenharmony_ci
278e5c31af7Sopenharmony_ci	void testBuffer (void)
279e5c31af7Sopenharmony_ci	{
280e5c31af7Sopenharmony_ci		de::Random rnd(0xabcdef);
281e5c31af7Sopenharmony_ci
282e5c31af7Sopenharmony_ci		m_verifier->verifyInteger64(m_testCtx, m_bufferTarget, GL_BUFFER_SIZE, 0);
283e5c31af7Sopenharmony_ci
284e5c31af7Sopenharmony_ci		const int numIterations = 16;
285e5c31af7Sopenharmony_ci		for (int i = 0; i < numIterations; ++i)
286e5c31af7Sopenharmony_ci		{
287e5c31af7Sopenharmony_ci			const GLint len = rnd.getInt(0, 1024);
288e5c31af7Sopenharmony_ci			glBufferData(m_bufferTarget, len, DE_NULL, GL_STREAM_DRAW);
289e5c31af7Sopenharmony_ci			expectError(GL_NO_ERROR);
290e5c31af7Sopenharmony_ci
291e5c31af7Sopenharmony_ci			m_verifier->verifyInteger64(m_testCtx, m_bufferTarget, GL_BUFFER_SIZE, len);
292e5c31af7Sopenharmony_ci			expectError(GL_NO_ERROR);
293e5c31af7Sopenharmony_ci		}
294e5c31af7Sopenharmony_ci	}
295e5c31af7Sopenharmony_ci};
296e5c31af7Sopenharmony_ci
297e5c31af7Sopenharmony_ciclass BufferUsageCase : public BufferCase
298e5c31af7Sopenharmony_ci{
299e5c31af7Sopenharmony_cipublic:
300e5c31af7Sopenharmony_ci	BufferUsageCase (Context& context, BufferParamVerifier* verifier, const char* name, const char* description)
301e5c31af7Sopenharmony_ci		: BufferCase(context, verifier, name, description)
302e5c31af7Sopenharmony_ci	{
303e5c31af7Sopenharmony_ci	}
304e5c31af7Sopenharmony_ci
305e5c31af7Sopenharmony_ci	void testBuffer (void)
306e5c31af7Sopenharmony_ci	{
307e5c31af7Sopenharmony_ci		m_verifier->verifyInteger(m_testCtx, m_bufferTarget, GL_BUFFER_USAGE, GL_STATIC_DRAW);
308e5c31af7Sopenharmony_ci
309e5c31af7Sopenharmony_ci		const GLenum usages[] =
310e5c31af7Sopenharmony_ci		{
311e5c31af7Sopenharmony_ci			GL_STREAM_DRAW, GL_STREAM_READ,
312e5c31af7Sopenharmony_ci			GL_STREAM_COPY, GL_STATIC_DRAW,
313e5c31af7Sopenharmony_ci			GL_STATIC_READ, GL_STATIC_COPY,
314e5c31af7Sopenharmony_ci			GL_DYNAMIC_DRAW, GL_DYNAMIC_READ,
315e5c31af7Sopenharmony_ci			GL_DYNAMIC_COPY
316e5c31af7Sopenharmony_ci		};
317e5c31af7Sopenharmony_ci
318e5c31af7Sopenharmony_ci		for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(usages); ++ndx)
319e5c31af7Sopenharmony_ci		{
320e5c31af7Sopenharmony_ci			glBufferData(m_bufferTarget, 16, DE_NULL, usages[ndx]);
321e5c31af7Sopenharmony_ci			expectError(GL_NO_ERROR);
322e5c31af7Sopenharmony_ci
323e5c31af7Sopenharmony_ci			m_verifier->verifyInteger(m_testCtx, m_bufferTarget, GL_BUFFER_USAGE, usages[ndx]);
324e5c31af7Sopenharmony_ci			expectError(GL_NO_ERROR);
325e5c31af7Sopenharmony_ci		}
326e5c31af7Sopenharmony_ci	}
327e5c31af7Sopenharmony_ci};
328e5c31af7Sopenharmony_ci
329e5c31af7Sopenharmony_ciclass BufferAccessFlagsCase : public BufferCase
330e5c31af7Sopenharmony_ci{
331e5c31af7Sopenharmony_cipublic:
332e5c31af7Sopenharmony_ci	BufferAccessFlagsCase (Context& context, BufferParamVerifier* verifier, const char* name, const char* description)
333e5c31af7Sopenharmony_ci		: BufferCase(context, verifier, name, description)
334e5c31af7Sopenharmony_ci	{
335e5c31af7Sopenharmony_ci	}
336e5c31af7Sopenharmony_ci
337e5c31af7Sopenharmony_ci	void testBuffer (void)
338e5c31af7Sopenharmony_ci	{
339e5c31af7Sopenharmony_ci		m_verifier->verifyInteger(m_testCtx, m_bufferTarget, GL_BUFFER_ACCESS_FLAGS, 0);
340e5c31af7Sopenharmony_ci
341e5c31af7Sopenharmony_ci		const GLenum accessFlags[] =
342e5c31af7Sopenharmony_ci		{
343e5c31af7Sopenharmony_ci			GL_MAP_READ_BIT,
344e5c31af7Sopenharmony_ci
345e5c31af7Sopenharmony_ci			GL_MAP_WRITE_BIT,
346e5c31af7Sopenharmony_ci			GL_MAP_WRITE_BIT																	| GL_MAP_INVALIDATE_RANGE_BIT,
347e5c31af7Sopenharmony_ci			GL_MAP_WRITE_BIT																									| GL_MAP_INVALIDATE_BUFFER_BIT,
348e5c31af7Sopenharmony_ci			GL_MAP_WRITE_BIT																	| GL_MAP_INVALIDATE_RANGE_BIT	| GL_MAP_INVALIDATE_BUFFER_BIT,
349e5c31af7Sopenharmony_ci
350e5c31af7Sopenharmony_ci			GL_MAP_WRITE_BIT									| GL_MAP_FLUSH_EXPLICIT_BIT,
351e5c31af7Sopenharmony_ci			GL_MAP_WRITE_BIT									| GL_MAP_FLUSH_EXPLICIT_BIT		| GL_MAP_INVALIDATE_RANGE_BIT,
352e5c31af7Sopenharmony_ci			GL_MAP_WRITE_BIT									| GL_MAP_FLUSH_EXPLICIT_BIT										| GL_MAP_INVALIDATE_BUFFER_BIT,
353e5c31af7Sopenharmony_ci			GL_MAP_WRITE_BIT									| GL_MAP_FLUSH_EXPLICIT_BIT		| GL_MAP_INVALIDATE_RANGE_BIT	| GL_MAP_INVALIDATE_BUFFER_BIT,
354e5c31af7Sopenharmony_ci
355e5c31af7Sopenharmony_ci			GL_MAP_WRITE_BIT	| GL_MAP_UNSYNCHRONIZED_BIT,
356e5c31af7Sopenharmony_ci			GL_MAP_WRITE_BIT	| GL_MAP_UNSYNCHRONIZED_BIT										| GL_MAP_INVALIDATE_RANGE_BIT,
357e5c31af7Sopenharmony_ci			GL_MAP_WRITE_BIT	| GL_MAP_UNSYNCHRONIZED_BIT																		| GL_MAP_INVALIDATE_BUFFER_BIT,
358e5c31af7Sopenharmony_ci			GL_MAP_WRITE_BIT	| GL_MAP_UNSYNCHRONIZED_BIT										| GL_MAP_INVALIDATE_RANGE_BIT	| GL_MAP_INVALIDATE_BUFFER_BIT,
359e5c31af7Sopenharmony_ci
360e5c31af7Sopenharmony_ci			GL_MAP_WRITE_BIT	| GL_MAP_UNSYNCHRONIZED_BIT		| GL_MAP_FLUSH_EXPLICIT_BIT,
361e5c31af7Sopenharmony_ci			GL_MAP_WRITE_BIT	| GL_MAP_UNSYNCHRONIZED_BIT		| GL_MAP_FLUSH_EXPLICIT_BIT		| GL_MAP_INVALIDATE_RANGE_BIT,
362e5c31af7Sopenharmony_ci			GL_MAP_WRITE_BIT	| GL_MAP_UNSYNCHRONIZED_BIT		| GL_MAP_FLUSH_EXPLICIT_BIT										| GL_MAP_INVALIDATE_BUFFER_BIT,
363e5c31af7Sopenharmony_ci			GL_MAP_WRITE_BIT	| GL_MAP_UNSYNCHRONIZED_BIT		| GL_MAP_FLUSH_EXPLICIT_BIT		| GL_MAP_INVALIDATE_RANGE_BIT	| GL_MAP_INVALIDATE_BUFFER_BIT,
364e5c31af7Sopenharmony_ci
365e5c31af7Sopenharmony_ci		};
366e5c31af7Sopenharmony_ci
367e5c31af7Sopenharmony_ci		for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(accessFlags); ++ndx)
368e5c31af7Sopenharmony_ci		{
369e5c31af7Sopenharmony_ci			glBufferData(m_bufferTarget, 16, DE_NULL, GL_DYNAMIC_COPY);
370e5c31af7Sopenharmony_ci			glMapBufferRange(m_bufferTarget, 0, 16, accessFlags[ndx]);
371e5c31af7Sopenharmony_ci			expectError(GL_NO_ERROR);
372e5c31af7Sopenharmony_ci
373e5c31af7Sopenharmony_ci			m_verifier->verifyInteger(m_testCtx, m_bufferTarget, GL_BUFFER_ACCESS_FLAGS, accessFlags[ndx]);
374e5c31af7Sopenharmony_ci			expectError(GL_NO_ERROR);
375e5c31af7Sopenharmony_ci
376e5c31af7Sopenharmony_ci			glUnmapBuffer(m_bufferTarget);
377e5c31af7Sopenharmony_ci			expectError(GL_NO_ERROR);
378e5c31af7Sopenharmony_ci		}
379e5c31af7Sopenharmony_ci	}
380e5c31af7Sopenharmony_ci};
381e5c31af7Sopenharmony_ci
382e5c31af7Sopenharmony_ciclass BufferMappedCase : public BufferCase
383e5c31af7Sopenharmony_ci{
384e5c31af7Sopenharmony_cipublic:
385e5c31af7Sopenharmony_ci	BufferMappedCase (Context& context, BufferParamVerifier* verifier, const char* name, const char* description)
386e5c31af7Sopenharmony_ci		: BufferCase(context, verifier, name, description)
387e5c31af7Sopenharmony_ci	{
388e5c31af7Sopenharmony_ci	}
389e5c31af7Sopenharmony_ci
390e5c31af7Sopenharmony_ci	void testBuffer (void)
391e5c31af7Sopenharmony_ci	{
392e5c31af7Sopenharmony_ci		m_verifier->verifyInteger(m_testCtx, m_bufferTarget, GL_BUFFER_MAPPED, GL_FALSE);
393e5c31af7Sopenharmony_ci
394e5c31af7Sopenharmony_ci		glBufferData(m_bufferTarget, 16, DE_NULL, GL_DYNAMIC_COPY);
395e5c31af7Sopenharmony_ci		glMapBufferRange(m_bufferTarget, 0, 16, GL_MAP_WRITE_BIT);
396e5c31af7Sopenharmony_ci		expectError(GL_NO_ERROR);
397e5c31af7Sopenharmony_ci
398e5c31af7Sopenharmony_ci		m_verifier->verifyInteger(m_testCtx, m_bufferTarget, GL_BUFFER_MAPPED, GL_TRUE);
399e5c31af7Sopenharmony_ci		expectError(GL_NO_ERROR);
400e5c31af7Sopenharmony_ci
401e5c31af7Sopenharmony_ci		glUnmapBuffer(m_bufferTarget);
402e5c31af7Sopenharmony_ci		expectError(GL_NO_ERROR);
403e5c31af7Sopenharmony_ci	}
404e5c31af7Sopenharmony_ci};
405e5c31af7Sopenharmony_ci
406e5c31af7Sopenharmony_ciclass BufferOffsetLengthCase : public BufferCase
407e5c31af7Sopenharmony_ci{
408e5c31af7Sopenharmony_cipublic:
409e5c31af7Sopenharmony_ci	BufferOffsetLengthCase (Context& context, BufferParamVerifier* verifier, const char* name, const char* description)
410e5c31af7Sopenharmony_ci		: BufferCase(context, verifier, name, description)
411e5c31af7Sopenharmony_ci	{
412e5c31af7Sopenharmony_ci	}
413e5c31af7Sopenharmony_ci
414e5c31af7Sopenharmony_ci	void testBuffer (void)
415e5c31af7Sopenharmony_ci	{
416e5c31af7Sopenharmony_ci		m_verifier->verifyInteger(m_testCtx, m_bufferTarget, GL_BUFFER_MAP_OFFSET, 0);
417e5c31af7Sopenharmony_ci		m_verifier->verifyInteger(m_testCtx, m_bufferTarget, GL_BUFFER_MAP_LENGTH, 0);
418e5c31af7Sopenharmony_ci
419e5c31af7Sopenharmony_ci		glBufferData(m_bufferTarget, 16, DE_NULL, GL_DYNAMIC_COPY);
420e5c31af7Sopenharmony_ci
421e5c31af7Sopenharmony_ci		const struct BufferRange
422e5c31af7Sopenharmony_ci		{
423e5c31af7Sopenharmony_ci			int offset;
424e5c31af7Sopenharmony_ci			int length;
425e5c31af7Sopenharmony_ci		} ranges[] =
426e5c31af7Sopenharmony_ci		{
427e5c31af7Sopenharmony_ci			{ 0, 16 },
428e5c31af7Sopenharmony_ci			{ 4, 12 },
429e5c31af7Sopenharmony_ci			{ 0, 12 },
430e5c31af7Sopenharmony_ci			{ 8,  8 },
431e5c31af7Sopenharmony_ci		};
432e5c31af7Sopenharmony_ci
433e5c31af7Sopenharmony_ci		for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(ranges); ++ndx)
434e5c31af7Sopenharmony_ci		{
435e5c31af7Sopenharmony_ci			glMapBufferRange(m_bufferTarget, ranges[ndx].offset, ranges[ndx].length, GL_MAP_WRITE_BIT);
436e5c31af7Sopenharmony_ci			expectError(GL_NO_ERROR);
437e5c31af7Sopenharmony_ci
438e5c31af7Sopenharmony_ci			m_verifier->verifyInteger(m_testCtx, m_bufferTarget, GL_BUFFER_MAP_OFFSET, ranges[ndx].offset);
439e5c31af7Sopenharmony_ci			m_verifier->verifyInteger(m_testCtx, m_bufferTarget, GL_BUFFER_MAP_LENGTH, ranges[ndx].length);
440e5c31af7Sopenharmony_ci			expectError(GL_NO_ERROR);
441e5c31af7Sopenharmony_ci
442e5c31af7Sopenharmony_ci			glUnmapBuffer(m_bufferTarget);
443e5c31af7Sopenharmony_ci			expectError(GL_NO_ERROR);
444e5c31af7Sopenharmony_ci		}
445e5c31af7Sopenharmony_ci	}
446e5c31af7Sopenharmony_ci};
447e5c31af7Sopenharmony_ci
448e5c31af7Sopenharmony_ciclass BufferPointerCase : public ApiCase
449e5c31af7Sopenharmony_ci{
450e5c31af7Sopenharmony_cipublic:
451e5c31af7Sopenharmony_ci	BufferPointerCase (Context& context, const char* name, const char* description)
452e5c31af7Sopenharmony_ci		: ApiCase(context, name, description)
453e5c31af7Sopenharmony_ci	{
454e5c31af7Sopenharmony_ci	}
455e5c31af7Sopenharmony_ci
456e5c31af7Sopenharmony_ci	void test (void)
457e5c31af7Sopenharmony_ci	{
458e5c31af7Sopenharmony_ci		GLuint bufferId = 0;
459e5c31af7Sopenharmony_ci		glGenBuffers(1, &bufferId);
460e5c31af7Sopenharmony_ci		glBindBuffer(GL_ARRAY_BUFFER, bufferId);
461e5c31af7Sopenharmony_ci		expectError(GL_NO_ERROR);
462e5c31af7Sopenharmony_ci
463e5c31af7Sopenharmony_ci		StateQueryMemoryWriteGuard<GLvoid*> initialState;
464e5c31af7Sopenharmony_ci		glGetBufferPointerv(GL_ARRAY_BUFFER, GL_BUFFER_MAP_POINTER, &initialState);
465e5c31af7Sopenharmony_ci		initialState.verifyValidity(m_testCtx);
466e5c31af7Sopenharmony_ci		checkPointerEquals(m_testCtx, initialState, 0);
467e5c31af7Sopenharmony_ci
468e5c31af7Sopenharmony_ci		glBufferData(GL_ARRAY_BUFFER, 8, DE_NULL, GL_DYNAMIC_COPY);
469e5c31af7Sopenharmony_ci		GLvoid* mapPointer = glMapBufferRange(GL_ARRAY_BUFFER, 0, 8, GL_MAP_READ_BIT);
470e5c31af7Sopenharmony_ci		expectError(GL_NO_ERROR);
471e5c31af7Sopenharmony_ci
472e5c31af7Sopenharmony_ci		StateQueryMemoryWriteGuard<GLvoid*> mapPointerState;
473e5c31af7Sopenharmony_ci		glGetBufferPointerv(GL_ARRAY_BUFFER, GL_BUFFER_MAP_POINTER, &mapPointerState);
474e5c31af7Sopenharmony_ci		mapPointerState.verifyValidity(m_testCtx);
475e5c31af7Sopenharmony_ci		checkPointerEquals(m_testCtx, mapPointerState, mapPointer);
476e5c31af7Sopenharmony_ci
477e5c31af7Sopenharmony_ci		glDeleteBuffers(1, &bufferId);
478e5c31af7Sopenharmony_ci		expectError(GL_NO_ERROR);
479e5c31af7Sopenharmony_ci	}
480e5c31af7Sopenharmony_ci};
481e5c31af7Sopenharmony_ci
482e5c31af7Sopenharmony_ci} // anonymous
483e5c31af7Sopenharmony_ci
484e5c31af7Sopenharmony_ci#define FOR_EACH_VERIFIER(VERIFIERS, CODE_BLOCK)													\
485e5c31af7Sopenharmony_ci	do {																							\
486e5c31af7Sopenharmony_ci		for (int _verifierNdx = 0; _verifierNdx < DE_LENGTH_OF_ARRAY(VERIFIERS); _verifierNdx++)	\
487e5c31af7Sopenharmony_ci		{																							\
488e5c31af7Sopenharmony_ci			BufferParamVerifier* verifier = (VERIFIERS)[_verifierNdx];								\
489e5c31af7Sopenharmony_ci			CODE_BLOCK;																				\
490e5c31af7Sopenharmony_ci		}																							\
491e5c31af7Sopenharmony_ci	} while (0)
492e5c31af7Sopenharmony_ci
493e5c31af7Sopenharmony_ciBufferObjectQueryTests::BufferObjectQueryTests (Context& context)
494e5c31af7Sopenharmony_ci	: TestCaseGroup		(context, "buffer_object", "Buffer Object Query tests")
495e5c31af7Sopenharmony_ci	, m_verifierInt		(DE_NULL)
496e5c31af7Sopenharmony_ci	, m_verifierInt64	(DE_NULL)
497e5c31af7Sopenharmony_ci{
498e5c31af7Sopenharmony_ci}
499e5c31af7Sopenharmony_ci
500e5c31af7Sopenharmony_ciBufferObjectQueryTests::~BufferObjectQueryTests (void)
501e5c31af7Sopenharmony_ci{
502e5c31af7Sopenharmony_ci	deinit();
503e5c31af7Sopenharmony_ci}
504e5c31af7Sopenharmony_ci
505e5c31af7Sopenharmony_civoid BufferObjectQueryTests::init (void)
506e5c31af7Sopenharmony_ci{
507e5c31af7Sopenharmony_ci	using namespace BufferParamVerifiers;
508e5c31af7Sopenharmony_ci
509e5c31af7Sopenharmony_ci	DE_ASSERT(m_verifierInt == DE_NULL);
510e5c31af7Sopenharmony_ci	DE_ASSERT(m_verifierInt64 == DE_NULL);
511e5c31af7Sopenharmony_ci
512e5c31af7Sopenharmony_ci	m_verifierInt		= new GetBufferParameterIVerifier	(m_context.getRenderContext().getFunctions(), m_context.getTestContext().getLog());
513e5c31af7Sopenharmony_ci	m_verifierInt64		= new GetBufferParameterI64Verifier	(m_context.getRenderContext().getFunctions(), m_context.getTestContext().getLog());
514e5c31af7Sopenharmony_ci	BufferParamVerifier* verifiers[] = {m_verifierInt, m_verifierInt64};
515e5c31af7Sopenharmony_ci
516e5c31af7Sopenharmony_ci	FOR_EACH_VERIFIER(verifiers, addChild(new BufferSizeCase		(m_context, verifier,	(std::string("buffer_size")				+ verifier->getTestNamePostfix()).c_str(), "BUFFER_SIZE")));
517e5c31af7Sopenharmony_ci	FOR_EACH_VERIFIER(verifiers, addChild(new BufferUsageCase		(m_context, verifier,	(std::string("buffer_usage")			+ verifier->getTestNamePostfix()).c_str(), "BUFFER_USAGE")));
518e5c31af7Sopenharmony_ci	FOR_EACH_VERIFIER(verifiers, addChild(new BufferAccessFlagsCase	(m_context, verifier,	(std::string("buffer_access_flags")		+ verifier->getTestNamePostfix()).c_str(), "BUFFER_ACCESS_FLAGS")));
519e5c31af7Sopenharmony_ci	FOR_EACH_VERIFIER(verifiers, addChild(new BufferMappedCase		(m_context, verifier,	(std::string("buffer_mapped")			+ verifier->getTestNamePostfix()).c_str(), "BUFFER_MAPPED")));
520e5c31af7Sopenharmony_ci	FOR_EACH_VERIFIER(verifiers, addChild(new BufferOffsetLengthCase(m_context, verifier,	(std::string("buffer_map_offset_length")+ verifier->getTestNamePostfix()).c_str(), "BUFFER_MAP_OFFSET and BUFFER_MAP_LENGTH")));
521e5c31af7Sopenharmony_ci
522e5c31af7Sopenharmony_ci	addChild(new BufferPointerCase(m_context, "buffer_pointer", "GetBufferPointerv"));
523e5c31af7Sopenharmony_ci}
524e5c31af7Sopenharmony_ci
525e5c31af7Sopenharmony_civoid BufferObjectQueryTests::deinit (void)
526e5c31af7Sopenharmony_ci{
527e5c31af7Sopenharmony_ci	if (m_verifierInt)
528e5c31af7Sopenharmony_ci	{
529e5c31af7Sopenharmony_ci		delete m_verifierInt;
530e5c31af7Sopenharmony_ci		m_verifierInt = NULL;
531e5c31af7Sopenharmony_ci	}
532e5c31af7Sopenharmony_ci	if (m_verifierInt64)
533e5c31af7Sopenharmony_ci	{
534e5c31af7Sopenharmony_ci		delete m_verifierInt64;
535e5c31af7Sopenharmony_ci		m_verifierInt64 = NULL;
536e5c31af7Sopenharmony_ci	}
537e5c31af7Sopenharmony_ci}
538e5c31af7Sopenharmony_ci
539e5c31af7Sopenharmony_ci} // Functional
540e5c31af7Sopenharmony_ci} // gles3
541e5c31af7Sopenharmony_ci} // deqp
542