1#ifndef _GLSDRAWTEST_HPP
2#define _GLSDRAWTEST_HPP
3/*-------------------------------------------------------------------------
4 * drawElements Quality Program OpenGL (ES) Module
5 * -----------------------------------------------
6 *
7 * Copyright 2014 The Android Open Source Project
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 *      http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 *
21 *//*!
22 * \file
23 * \brief Draw tests
24 *//*--------------------------------------------------------------------*/
25
26#include "tcuTestCase.hpp"
27#include "tcuResultCollector.hpp"
28#include "gluRenderContext.hpp"
29
30namespace sglr
31{
32
33class ReferenceContextBuffers;
34class ReferenceContext;
35class Context;
36
37} // sglr
38
39namespace deqp
40{
41namespace gls
42{
43
44class AttributePack;
45
46struct DrawTestSpec
47{
48	enum Target
49	{
50		TARGET_ELEMENT_ARRAY = 0,
51		TARGET_ARRAY,
52
53		TARGET_LAST
54	};
55
56	enum InputType
57	{
58		INPUTTYPE_FLOAT = 0,
59		INPUTTYPE_FIXED,
60		INPUTTYPE_DOUBLE,
61
62		INPUTTYPE_BYTE,
63		INPUTTYPE_SHORT,
64
65		INPUTTYPE_UNSIGNED_BYTE,
66		INPUTTYPE_UNSIGNED_SHORT,
67
68		INPUTTYPE_INT,
69		INPUTTYPE_UNSIGNED_INT,
70		INPUTTYPE_HALF,
71		INPUTTYPE_UNSIGNED_INT_2_10_10_10,
72		INPUTTYPE_INT_2_10_10_10,
73
74		INPUTTYPE_LAST
75	};
76
77	enum OutputType
78	{
79		OUTPUTTYPE_FLOAT = 0,
80		OUTPUTTYPE_VEC2,
81		OUTPUTTYPE_VEC3,
82		OUTPUTTYPE_VEC4,
83
84		OUTPUTTYPE_INT,
85		OUTPUTTYPE_UINT,
86
87		OUTPUTTYPE_IVEC2,
88		OUTPUTTYPE_IVEC3,
89		OUTPUTTYPE_IVEC4,
90
91		OUTPUTTYPE_UVEC2,
92		OUTPUTTYPE_UVEC3,
93		OUTPUTTYPE_UVEC4,
94
95		OUTPUTTYPE_LAST
96	};
97
98	enum Usage
99	{
100		USAGE_DYNAMIC_DRAW = 0,
101		USAGE_STATIC_DRAW,
102		USAGE_STREAM_DRAW,
103
104		USAGE_STREAM_READ,
105		USAGE_STREAM_COPY,
106
107		USAGE_STATIC_READ,
108		USAGE_STATIC_COPY,
109
110		USAGE_DYNAMIC_READ,
111		USAGE_DYNAMIC_COPY,
112
113		USAGE_LAST
114	};
115
116	enum Storage
117	{
118		STORAGE_USER = 0,
119		STORAGE_BUFFER,
120
121		STORAGE_LAST
122	};
123
124	enum Primitive
125	{
126		PRIMITIVE_POINTS = 0,
127		PRIMITIVE_TRIANGLES,
128		PRIMITIVE_TRIANGLE_FAN,
129		PRIMITIVE_TRIANGLE_STRIP,
130		PRIMITIVE_LINES,
131		PRIMITIVE_LINE_STRIP,
132		PRIMITIVE_LINE_LOOP,
133
134		PRIMITIVE_LINES_ADJACENCY,
135		PRIMITIVE_LINE_STRIP_ADJACENCY,
136		PRIMITIVE_TRIANGLES_ADJACENCY,
137		PRIMITIVE_TRIANGLE_STRIP_ADJACENCY,
138
139		PRIMITIVE_LAST
140	};
141
142	enum IndexType
143	{
144		INDEXTYPE_BYTE = 0,
145		INDEXTYPE_SHORT,
146		INDEXTYPE_INT,
147
148		INDEXTYPE_LAST
149	};
150
151	enum DrawMethod
152	{
153		DRAWMETHOD_DRAWARRAYS = 0,
154		DRAWMETHOD_DRAWARRAYS_INSTANCED,
155		DRAWMETHOD_DRAWARRAYS_INDIRECT,
156		DRAWMETHOD_DRAWELEMENTS,
157		DRAWMETHOD_DRAWELEMENTS_RANGED,
158		DRAWMETHOD_DRAWELEMENTS_INSTANCED,
159		DRAWMETHOD_DRAWELEMENTS_INDIRECT,
160		DRAWMETHOD_DRAWELEMENTS_BASEVERTEX,
161		DRAWMETHOD_DRAWELEMENTS_INSTANCED_BASEVERTEX,
162		DRAWMETHOD_DRAWELEMENTS_RANGED_BASEVERTEX,
163
164		DRAWMETHOD_LAST
165	};
166
167	enum CompatibilityTestType
168	{
169		COMPATIBILITY_NONE = 0,
170		COMPATIBILITY_UNALIGNED_OFFSET,
171		COMPATIBILITY_UNALIGNED_STRIDE,
172
173		COMPATIBILITY_LAST
174	};
175
176	static std::string			targetToString		(Target target);
177	static std::string			inputTypeToString	(InputType type);
178	static std::string			outputTypeToString	(OutputType type);
179	static std::string			usageTypeToString	(Usage usage);
180	static std::string			storageToString		(Storage storage);
181	static std::string			primitiveToString	(Primitive primitive);
182	static std::string			indexTypeToString	(IndexType type);
183	static std::string			drawMethodToString	(DrawMethod method);
184	static int					inputTypeSize		(InputType type);
185	static int					indexTypeSize		(IndexType type);
186
187	struct AttributeSpec
188	{
189		static AttributeSpec	createAttributeArray	(InputType inputType, OutputType outputType, Storage storage, Usage usage, int componentCount, int offset, int stride, bool normalize, int instanceDivisor);
190		static AttributeSpec	createDefaultAttribute	(InputType inputType, OutputType outputType, int componentCount);	//!< allowed inputType values: INPUTTYPE_INT, INPUTTYPE_UNSIGNED_INT, INPUTTYPE_FLOAT
191
192		InputType				inputType;
193		OutputType				outputType;
194		Storage					storage;
195		Usage					usage;
196		int 					componentCount;
197		int						offset;
198		int						stride;
199		bool					normalize;
200		int						instanceDivisor;				//!< used only if drawMethod = Draw*Instanced
201		bool					useDefaultAttribute;
202
203		bool					additionalPositionAttribute;	//!< treat this attribute as position attribute. Attribute at index 0 is alway treated as such. False by default
204		bool					bgraComponentOrder;				//!< component order of this attribute is bgra, valid only for 4-component targets. False by default.
205
206								AttributeSpec			(void);
207
208		int						hash					(void) const;
209		bool					valid					(glu::ApiType apiType) const;
210		bool					isBufferAligned			(void) const;
211		bool					isBufferStrideAligned	(void) const;
212	};
213
214	std::string 				getName				(void) const;
215	std::string					getDesc				(void) const;
216	std::string					getMultilineDesc	(void) const;
217
218	glu::ApiType				apiType;			//!< needed in spec validation
219	Primitive					primitive;
220	int							primitiveCount;		//!< number of primitives to draw (per instance)
221
222	DrawMethod					drawMethod;
223	IndexType					indexType;			//!< used only if drawMethod = DrawElements*
224	int							indexPointerOffset;	//!< used only if drawMethod = DrawElements*
225	Storage						indexStorage;		//!< used only if drawMethod = DrawElements*
226	int							first;				//!< used only if drawMethod = DrawArrays*
227	int							indexMin;			//!< used only if drawMethod = Draw*Ranged
228	int							indexMax;			//!< used only if drawMethod = Draw*Ranged
229	int							instanceCount;		//!< used only if drawMethod = Draw*Instanced or Draw*Indirect
230	int							indirectOffset;		//!< used only if drawMethod = Draw*Indirect
231	int							baseVertex;			//!< used only if drawMethod = DrawElementsIndirect or *BaseVertex
232
233	std::vector<AttributeSpec>	attribs;
234
235								DrawTestSpec		(void);
236
237	int							hash				(void) const;
238	bool						valid				(void) const;
239	CompatibilityTestType		isCompatibilityTest	(void) const;
240};
241
242class DrawTest : public tcu::TestCase
243{
244public:
245									DrawTest				(tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const DrawTestSpec& spec, const char* name, const char* desc);
246									DrawTest				(tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const char* name, const char* desc);
247	virtual							~DrawTest				(void);
248
249	void							addIteration			(const DrawTestSpec& spec, const char* description = DE_NULL);
250
251private:
252	void							init					(void);
253	void							deinit					(void);
254	IterateResult					iterate					(void);
255
256	bool							compare					(gls::DrawTestSpec::Primitive primitiveType);
257	float							getCoordScale			(const DrawTestSpec& spec) const;
258	float							getColorScale			(const DrawTestSpec& spec) const;
259
260	glu::RenderContext&				m_renderCtx;
261
262	sglr::ReferenceContextBuffers*	m_refBuffers;
263	sglr::ReferenceContext*			m_refContext;
264	sglr::Context*					m_glesContext;
265
266	AttributePack*					m_glArrayPack;
267	AttributePack*					m_rrArrayPack;
268
269	int								m_maxDiffRed;
270	int								m_maxDiffGreen;
271	int								m_maxDiffBlue;
272
273	std::vector<DrawTestSpec>		m_specs;
274	std::vector<std::string>		m_iteration_descriptions;
275	int								m_iteration;
276	tcu::ResultCollector			m_result;
277};
278
279} // gls
280} // deqp
281
282#endif // _GLSDRAWTEST_HPP
283