13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*-------------------------------------------------------------------------
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program OpenGL (ES) Module
33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * -----------------------------------------------
43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project
63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License");
83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License.
93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at
103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *      http://www.apache.org/licenses/LICENSE-2.0
123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software
143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS,
153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and
173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License.
183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*!
203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file
213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Vertex array and buffer tests
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glsVertexArrayTests.hpp"
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deRandom.h"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp"
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuPixelFormat.hpp"
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuRGBA.hpp"
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuSurface.hpp"
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuVector.hpp"
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp"
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuRenderTarget.hpp"
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuStringTemplate.hpp"
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuImageCompare.hpp"
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluPixelTransfer.hpp"
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluCallLogWrapper.hpp"
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "sglrContext.hpp"
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "sglrReferenceContext.hpp"
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "sglrGLContext.hpp"
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deMath.h"
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deStringUtil.hpp"
47d6148171f88da1301f053e2e0236afc69416137cJarkko Pöyry#include "deArrayUtil.hpp"
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <cstring>
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <cmath>
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <vector>
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <sstream>
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <limits>
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <algorithm>
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwDefs.hpp"
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp"
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gls
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::TestLog;
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing namespace glw; // GL types
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystd::string Array::targetToString(Target target)
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const char* targets[] =
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"element_array",	// TARGET_ELEMENT_ARRAY = 0,
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"array"				// TARGET_ARRAY,
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7506beb4d23816942e7ccc49c81530bb8702a6f336Jarkko Pöyry	return de::getSizedArrayElement<Array::TARGET_LAST>(targets, (int)target);
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystd::string Array::inputTypeToString(InputType type)
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const char* types[] =
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"float",			// INPUTTYPE_FLOAT = 0,
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"fixed",			// INPUTTYPE_FIXED,
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"double",			// INPUTTYPE_DOUBLE
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"byte",				// INPUTTYPE_BYTE,
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"short",			// INPUTTYPE_SHORT,
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"unsigned_byte",	// INPUTTYPE_UNSIGNED_BYTE,
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"unsigned_short",	// INPUTTYPE_UNSIGNED_SHORT,
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"int",						// INPUTTYPE_INT,
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"unsigned_int",				// INPUTTYPE_UNSIGNED_INT,
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"half",						// INPUTTYPE_HALF,
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"usigned_int2_10_10_10",	// INPUTTYPE_UNSIGNED_INT_2_10_10_10,
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"int2_10_10_10"				// INPUTTYPE_INT_2_10_10_10,
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9906beb4d23816942e7ccc49c81530bb8702a6f336Jarkko Pöyry	return de::getSizedArrayElement<Array::INPUTTYPE_LAST>(types, (int)type);
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystd::string Array::outputTypeToString(OutputType type)
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const char* types[] =
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"float",		// OUTPUTTYPE_FLOAT = 0,
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"vec2",			// OUTPUTTYPE_VEC2,
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"vec3",			// OUTPUTTYPE_VEC3,
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"vec4",			// OUTPUTTYPE_VEC4,
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"int",			// OUTPUTTYPE_INT,
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"uint",			// OUTPUTTYPE_UINT,
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"ivec2",		// OUTPUTTYPE_IVEC2,
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"ivec3",		// OUTPUTTYPE_IVEC3,
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"ivec4",		// OUTPUTTYPE_IVEC4,
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"uvec2",		// OUTPUTTYPE_UVEC2,
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"uvec3",		// OUTPUTTYPE_UVEC3,
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"uvec4",		// OUTPUTTYPE_UVEC4,
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12306beb4d23816942e7ccc49c81530bb8702a6f336Jarkko Pöyry	return de::getSizedArrayElement<Array::OUTPUTTYPE_LAST>(types, (int)type);
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystd::string Array::usageTypeToString(Usage usage)
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const char* usages[] =
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"dynamic_draw",	// USAGE_DYNAMIC_DRAW = 0,
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"static_draw",	// USAGE_STATIC_DRAW,
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"stream_draw",	// USAGE_STREAM_DRAW,
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"stream_read",	// USAGE_STREAM_READ,
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"stream_copy",	// USAGE_STREAM_COPY,
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"static_read",	// USAGE_STATIC_READ,
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"static_copy",	// USAGE_STATIC_COPY,
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"dynamic_read",	// USAGE_DYNAMIC_READ,
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"dynamic_copy",	// USAGE_DYNAMIC_COPY,
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14406beb4d23816942e7ccc49c81530bb8702a6f336Jarkko Pöyry	return de::getSizedArrayElement<Array::USAGE_LAST>(usages, (int)usage);
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystd::string	Array::storageToString (Storage storage)
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const char* storages[] =
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"user_ptr",	// STORAGE_USER = 0,
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"buffer"	// STORAGE_BUFFER,
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15506beb4d23816942e7ccc49c81530bb8702a6f336Jarkko Pöyry	return de::getSizedArrayElement<Array::STORAGE_LAST>(storages, (int)storage);
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystd::string Array::primitiveToString (Primitive primitive)
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const char* primitives[] =
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"points",			// PRIMITIVE_POINTS ,
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"triangles",		// PRIMITIVE_TRIANGLES,
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"triangle_fan",		// PRIMITIVE_TRIANGLE_FAN,
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"triangle_strip"	// PRIMITIVE_TRIANGLE_STRIP,
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16806beb4d23816942e7ccc49c81530bb8702a6f336Jarkko Pöyry	return de::getSizedArrayElement<Array::PRIMITIVE_LAST>(primitives, (int)primitive);
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyryint Array::inputTypeSize (InputType type)
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const int size[] =
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
175c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry		(int)sizeof(float),			// INPUTTYPE_FLOAT = 0,
176c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry		(int)sizeof(deInt32),		// INPUTTYPE_FIXED,
177c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry		(int)sizeof(double),		// INPUTTYPE_DOUBLE
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
179c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry		(int)sizeof(deInt8),		// INPUTTYPE_BYTE,
180c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry		(int)sizeof(deInt16),		// INPUTTYPE_SHORT,
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
182c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry		(int)sizeof(deUint8),		// INPUTTYPE_UNSIGNED_BYTE,
183c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry		(int)sizeof(deUint16),		// INPUTTYPE_UNSIGNED_SHORT,
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
185c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry		(int)sizeof(deInt32),		// INPUTTYPE_INT,
186c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry		(int)sizeof(deUint32),		// INPUTTYPE_UNSIGNED_INT,
187c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry		(int)sizeof(deFloat16),		// INPUTTYPE_HALF,
188c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry		(int)sizeof(deUint32) / 4,	// INPUTTYPE_UNSIGNED_INT_2_10_10_10,
189c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry		(int)sizeof(deUint32) / 4	// INPUTTYPE_INT_2_10_10_10,
1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19206beb4d23816942e7ccc49c81530bb8702a6f336Jarkko Pöyry	return de::getSizedArrayElement<Array::INPUTTYPE_LAST>(size, (int)type);
1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic bool inputTypeIsFloatType (Array::InputType type)
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (type == Array::INPUTTYPE_FLOAT)
1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return true;
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (type == Array::INPUTTYPE_FIXED)
2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return true;
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (type == Array::INPUTTYPE_DOUBLE)
2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return true;
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (type == Array::INPUTTYPE_HALF)
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return true;
2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return false;
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic bool outputTypeIsFloatType (Array::OutputType type)
2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (type == Array::OUTPUTTYPE_FLOAT
2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		|| type == Array::OUTPUTTYPE_VEC2
2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		|| type == Array::OUTPUTTYPE_VEC3
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		|| type == Array::OUTPUTTYPE_VEC4)
2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return true;
2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return false;
2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<class T>
2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline T getRandom (deRandom& rnd, T min, T max);
2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<>
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline GLValue::Float getRandom (deRandom& rnd, GLValue::Float min, GLValue::Float max)
2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (max < min)
2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return min;
2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return GLValue::Float::create(min + deRandom_getFloat(&rnd) * (max.to<float>() - min.to<float>()));
2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<>
2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline GLValue::Short getRandom (deRandom& rnd, GLValue::Short min, GLValue::Short max)
2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (max < min)
2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return min;
2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
237c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry	return GLValue::Short::create((min == max ? min : (deInt16)(min + (deRandom_getUint32(&rnd) % (max.to<int>() - min.to<int>())))));
2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<>
2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline GLValue::Ushort getRandom (deRandom& rnd, GLValue::Ushort min, GLValue::Ushort max)
2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (max < min)
2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return min;
2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
246c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry	return GLValue::Ushort::create((min == max ? min : (deUint16)(min + (deRandom_getUint32(&rnd) % (max.to<int>() - min.to<int>())))));
2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<>
2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline GLValue::Byte getRandom (deRandom& rnd, GLValue::Byte min, GLValue::Byte max)
2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (max < min)
2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return min;
2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
255c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry	return GLValue::Byte::create((min == max ? min : (deInt8)(min + (deRandom_getUint32(&rnd) % (max.to<int>() - min.to<int>())))));
2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<>
2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline GLValue::Ubyte getRandom (deRandom& rnd, GLValue::Ubyte min, GLValue::Ubyte max)
2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (max < min)
2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return min;
2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
264c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry	return GLValue::Ubyte::create((min == max ? min : (deUint8)(min + (deRandom_getUint32(&rnd) % (max.to<int>() - min.to<int>())))));
2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<>
2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline GLValue::Fixed getRandom (deRandom& rnd, GLValue::Fixed min, GLValue::Fixed max)
2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (max < min)
2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return min;
2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return GLValue::Fixed::create((min == max ? min : min + (deRandom_getUint32(&rnd) % (max.to<deUint32>() - min.to<deUint32>()))));
2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<>
2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline GLValue::Half getRandom (deRandom& rnd, GLValue::Half min, GLValue::Half max)
2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (max < min)
2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return min;
2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float fMax = max.to<float>();
2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float fMin = min.to<float>();
2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLValue::Half h = GLValue::Half::create(fMin + deRandom_getFloat(&rnd) * (fMax - fMin));
2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return h;
2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<>
2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline GLValue::Int getRandom (deRandom& rnd, GLValue::Int min, GLValue::Int max)
2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (max < min)
2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return min;
2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return GLValue::Int::create((min == max ? min : min + (deRandom_getUint32(&rnd) % (max.to<deUint32>() - min.to<deUint32>()))));
2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<>
2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline GLValue::Uint getRandom (deRandom& rnd, GLValue::Uint min, GLValue::Uint max)
2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (max < min)
3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return min;
3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return GLValue::Uint::create((min == max ? min : min + (deRandom_getUint32(&rnd) % (max.to<deUint32>() - min.to<deUint32>()))));
3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<>
3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline GLValue::Double getRandom (deRandom& rnd, GLValue::Double min, GLValue::Double max)
3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (max < min)
3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return min;
3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return GLValue::Double::create(min + deRandom_getFloat(&rnd) * (max.to<float>() - min.to<float>()));
3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Minimum difference required between coordinates
3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<class T>
3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline T minValue (void);
3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<>
3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline GLValue::Float minValue (void)
3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return GLValue::Float::create(4 * 1.0f);
3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<>
3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline GLValue::Short minValue (void)
3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return GLValue::Short::create(4 * 256);
3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<>
3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline GLValue::Ushort minValue (void)
3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return GLValue::Ushort::create(4 * 256);
3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<>
3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline GLValue::Byte minValue (void)
3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return GLValue::Byte::create(4 * 1);
3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<>
3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline GLValue::Ubyte minValue (void)
3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return GLValue::Ubyte::create(4 * 2);
3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<>
3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline GLValue::Fixed minValue (void)
3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return GLValue::Fixed::create(4 * 512);
3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<>
3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline GLValue::Int minValue (void)
3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return GLValue::Int::create(4 * 16777216);
3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<>
3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline GLValue::Uint minValue (void)
3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return GLValue::Uint::create(4 * 16777216);
3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<>
3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline GLValue::Half minValue (void)
3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return GLValue::Half::create(4 * 1.0f);
3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<>
3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline GLValue::Double minValue (void)
3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return GLValue::Double::create(4 * 1.0f);
3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<class T>
3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline T abs (T val);
3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<>
3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline GLValue::Fixed abs (GLValue::Fixed val)
3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return GLValue::Fixed::create(0x7FFFu & val.getValue());
3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<>
3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline GLValue::Ubyte abs (GLValue::Ubyte val)
3903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return val;
3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<>
3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline GLValue::Byte abs (GLValue::Byte val)
3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return GLValue::Byte::create(0x7Fu & val.getValue());
3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<>
4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline GLValue::Ushort abs (GLValue::Ushort val)
4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return val;
4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<>
4073c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline GLValue::Short abs (GLValue::Short val)
4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return GLValue::Short::create(0x7FFFu & val.getValue());
4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<>
4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline GLValue::Float abs (GLValue::Float val)
4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return GLValue::Float::create(std::fabs(val.to<float>()));
4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<>
4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline GLValue::Uint abs (GLValue::Uint val)
4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return val;
4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<>
4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline GLValue::Int abs (GLValue::Int val)
4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return GLValue::Int::create(0x7FFFFFFFu & val.getValue());
4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<>
4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline GLValue::Half abs (GLValue::Half val)
4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return GLValue::Half::create(std::fabs(val.to<float>()));
4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<>
4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline GLValue::Double abs (GLValue::Double val)
4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return GLValue::Double::create(std::fabs(val.to<float>()));
4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<class T>
44313db3557aa1b5809f50cb214e848866f3e80db6cJarkko Pöyrystatic inline void alignmentSafeAssignment (char* dst, T val)
4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::memcpy(dst, &val, sizeof(T));
4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4483c827367444ee418f129b2c238299f49d3264554Jarkko PoyryContextArray::ContextArray (Storage storage, sglr::Context& context)
4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: m_storage			(storage)
4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_ctx				(context)
4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_glBuffer		(0)
4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_bound			(false)
4533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_attribNdx		(0)
4543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_size			(0)
4553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_data			(DE_NULL)
4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_componentCount	(1)
4573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_target			(Array::TARGET_ARRAY)
4583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_inputType		(Array::INPUTTYPE_FLOAT)
4593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_outputType		(Array::OUTPUTTYPE_VEC4)
4603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_normalize		(false)
4613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_stride			(0)
4623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_offset			(0)
4633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_storage == STORAGE_BUFFER)
4653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_ctx.genBuffers(1, &m_glBuffer);
4673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glGenBuffers()");
4683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4713c827367444ee418f129b2c238299f49d3264554Jarkko PoyryContextArray::~ContextArray	(void)
4723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_storage == STORAGE_BUFFER)
4743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_ctx.deleteBuffers(1, &m_glBuffer);
4763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glDeleteBuffers()");
4773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (m_storage == STORAGE_USER)
4793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		delete[] m_data;
4803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
4813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(false);
4823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4843c827367444ee418f129b2c238299f49d3264554Jarkko PoyryArray* ContextArrayPack::getArray (int i)
4853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return m_arrays.at(i);
4873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4893c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ContextArray::data (Target target, int size, const char* ptr, Usage usage)
4903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_size = size;
4923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_target = target;
4933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_storage == STORAGE_BUFFER)
4953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_ctx.bindBuffer(targetToGL(target), m_glBuffer);
4973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glBindBuffer()");
4983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_ctx.bufferData(targetToGL(target), size, ptr, usageToGL(usage));
5003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glBufferData()");
5013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (m_storage == STORAGE_USER)
5033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_data)
5053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			delete[] m_data;
5063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_data = new char[size];
5083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		std::memcpy(m_data, ptr, size);
5093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
5113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(false);
5123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5143c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ContextArray::subdata (Target target, int offset, int size, const char* ptr)
5153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_target = target;
5173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_storage == STORAGE_BUFFER)
5193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_ctx.bindBuffer(targetToGL(target), m_glBuffer);
5213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glBindBuffer()");
5223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_ctx.bufferSubData(targetToGL(target), offset, size, ptr);
5243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glBufferSubData()");
5253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (m_storage == STORAGE_USER)
5273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		std::memcpy(m_data + offset, ptr, size);
5283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
5293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(false);
5303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5323c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ContextArray::bind (int attribNdx, int offset, int size, InputType inputType, OutputType outType, bool normalized, int stride)
5333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_attribNdx			= attribNdx;
5353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_bound				= true;
5363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_componentCount	= size;
5373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_inputType			= inputType;
5383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_outputType		= outType;
5393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_normalize			= normalized;
5403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_stride			= stride;
5413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_offset			= offset;
5423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5443c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ContextArray::bindIndexArray (Array::Target target)
5453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_storage == STORAGE_USER)
5473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (m_storage == STORAGE_BUFFER)
5503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_ctx.bindBuffer(targetToGL(target), m_glBuffer);
5523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5553c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ContextArray::glBind (deUint32 loc)
5563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_storage == STORAGE_BUFFER)
5583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_ctx.bindBuffer(targetToGL(m_target), m_glBuffer);
5603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glBindBuffer()");
5613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (!inputTypeIsFloatType(m_inputType))
5633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
5643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Input is not float type
5653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (outputTypeIsFloatType(m_outputType))
5673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
5683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				// Output type is float type
5693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_ctx.vertexAttribPointer(loc, m_componentCount, inputTypeToGL(m_inputType), m_normalize, m_stride, (GLvoid*)((GLintptr)m_offset));
5703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glVertexAttribPointer()");
5713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
5723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else
5733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
5743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				// Output type is int type
5753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_ctx.vertexAttribIPointer(loc, m_componentCount, inputTypeToGL(m_inputType), m_stride, (GLvoid*)((GLintptr)m_offset));
5763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glVertexAttribIPointer()");
5773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
5783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
5793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
5803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
5813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Input type is float type
5823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Output type must be float type
5843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(m_outputType == OUTPUTTYPE_FLOAT || m_outputType == OUTPUTTYPE_VEC2 || m_outputType == OUTPUTTYPE_VEC3 || m_outputType == OUTPUTTYPE_VEC4);
5853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_ctx.vertexAttribPointer(loc, m_componentCount, inputTypeToGL(m_inputType), m_normalize, m_stride, (GLvoid*)((GLintptr)m_offset));
5873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glVertexAttribPointer()");
5883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
5893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_ctx.bindBuffer(targetToGL(m_target), 0);
5913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (m_storage == STORAGE_USER)
5933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_ctx.bindBuffer(targetToGL(m_target), 0);
5953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glBindBuffer()");
5963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (!inputTypeIsFloatType(m_inputType))
5983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
5993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Input is not float type
6003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (outputTypeIsFloatType(m_outputType))
6023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
6033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				// Output type is float type
6043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_ctx.vertexAttribPointer(loc, m_componentCount, inputTypeToGL(m_inputType), m_normalize, m_stride, m_data + m_offset);
6053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glVertexAttribPointer()");
6063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
6073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else
6083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
6093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				// Output type is int type
6103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_ctx.vertexAttribIPointer(loc, m_componentCount, inputTypeToGL(m_inputType), m_stride, m_data + m_offset);
6113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glVertexAttribIPointer()");
6123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
6133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
6143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
6153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
6163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Input type is float type
6173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Output type must be float type
6193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(m_outputType == OUTPUTTYPE_FLOAT || m_outputType == OUTPUTTYPE_VEC2 || m_outputType == OUTPUTTYPE_VEC3 || m_outputType == OUTPUTTYPE_VEC4);
6203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_ctx.vertexAttribPointer(loc, m_componentCount, inputTypeToGL(m_inputType), m_normalize, m_stride, m_data + m_offset);
6223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glVertexAttribPointer()");
6233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
6243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
6253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
6263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(false);
6273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
6283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6293c827367444ee418f129b2c238299f49d3264554Jarkko PoyryGLenum ContextArray::targetToGL (Array::Target target)
6303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const GLenum targets[] =
6323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
6333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_ELEMENT_ARRAY_BUFFER,	// TARGET_ELEMENT_ARRAY = 0,
6343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_ARRAY_BUFFER				// TARGET_ARRAY,
6353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
6363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
63706beb4d23816942e7ccc49c81530bb8702a6f336Jarkko Pöyry	return de::getSizedArrayElement<Array::TARGET_LAST>(targets, (int)target);
6383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
6393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6403c827367444ee418f129b2c238299f49d3264554Jarkko PoyryGLenum ContextArray::usageToGL (Array::Usage usage)
6413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const GLenum usages[] =
6433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
6443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_DYNAMIC_DRAW,	// USAGE_DYNAMIC_DRAW = 0,
6453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_STATIC_DRAW,		// USAGE_STATIC_DRAW,
6463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_STREAM_DRAW,		// USAGE_STREAM_DRAW,
6473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_STREAM_READ,		// USAGE_STREAM_READ,
6493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_STREAM_COPY,		// USAGE_STREAM_COPY,
6503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_STATIC_READ,		// USAGE_STATIC_READ,
6523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_STATIC_COPY,		// USAGE_STATIC_COPY,
6533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_DYNAMIC_READ,	// USAGE_DYNAMIC_READ,
6553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_DYNAMIC_COPY		// USAGE_DYNAMIC_COPY,
6563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
6573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
65806beb4d23816942e7ccc49c81530bb8702a6f336Jarkko Pöyry	return de::getSizedArrayElement<Array::USAGE_LAST>(usages, (int)usage);
6593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
6603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6613c827367444ee418f129b2c238299f49d3264554Jarkko PoyryGLenum ContextArray::inputTypeToGL (Array::InputType type)
6623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const GLenum types[] =
6643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
6653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_FLOAT,				// INPUTTYPE_FLOAT = 0,
6663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_FIXED,				// INPUTTYPE_FIXED,
6673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_DOUBLE,				// INPUTTYPE_DOUBLE
6683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_BYTE,				// INPUTTYPE_BYTE,
6693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_SHORT,				// INPUTTYPE_SHORT,
6703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_UNSIGNED_BYTE,		// INPUTTYPE_UNSIGNED_BYTE,
6713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_UNSIGNED_SHORT,		// INPUTTYPE_UNSIGNED_SHORT,
6723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_INT,					// INPUTTYPE_INT,
6743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_UNSIGNED_INT,		// INPUTTYPE_UNSIGNED_INT,
6753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_HALF_FLOAT,			// INPUTTYPE_HALF,
6763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_UNSIGNED_INT_2_10_10_10_REV, // INPUTTYPE_UNSIGNED_INT_2_10_10_10,
6773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_INT_2_10_10_10_REV			// INPUTTYPE_INT_2_10_10_10,
6783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
6793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
68006beb4d23816942e7ccc49c81530bb8702a6f336Jarkko Pöyry	return de::getSizedArrayElement<Array::INPUTTYPE_LAST>(types, (int)type);
6813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
6823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6833c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystd::string ContextArray::outputTypeToGLType (Array::OutputType type)
6843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const char* types[] =
6863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
6873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"float",		// OUTPUTTYPE_FLOAT = 0,
6883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"vec2",			// OUTPUTTYPE_VEC2,
6893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"vec3",			// OUTPUTTYPE_VEC3,
6903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"vec4",			// OUTPUTTYPE_VEC4,
6913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"int",			// OUTPUTTYPE_INT,
6933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"uint",			// OUTPUTTYPE_UINT,
6943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"ivec2",		// OUTPUTTYPE_IVEC2,
6963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"ivec3",		// OUTPUTTYPE_IVEC3,
6973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"ivec4",		// OUTPUTTYPE_IVEC4,
6983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"uvec2",		// OUTPUTTYPE_UVEC2,
7003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"uvec3",		// OUTPUTTYPE_UVEC3,
7013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"uvec4",		// OUTPUTTYPE_UVEC4,
7023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
7033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
70406beb4d23816942e7ccc49c81530bb8702a6f336Jarkko Pöyry	return de::getSizedArrayElement<Array::OUTPUTTYPE_LAST>(types, (int)type);
7053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
7063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7073c827367444ee418f129b2c238299f49d3264554Jarkko PoyryGLenum ContextArray::primitiveToGL (Array::Primitive primitive)
7083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
70906beb4d23816942e7ccc49c81530bb8702a6f336Jarkko Pöyry	static const GLenum primitives[] =
7103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
7113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_POINTS,			// PRIMITIVE_POINTS = 0,
7123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_TRIANGLES,		// PRIMITIVE_TRIANGLES,
7133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_TRIANGLE_FAN,	// PRIMITIVE_TRIANGLE_FAN,
7143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_TRIANGLE_STRIP	// PRIMITIVE_TRIANGLE_STRIP,
7153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
7163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
71706beb4d23816942e7ccc49c81530bb8702a6f336Jarkko Pöyry	return de::getSizedArrayElement<Array::PRIMITIVE_LAST>(primitives, (int)primitive);
7183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
7193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7203c827367444ee418f129b2c238299f49d3264554Jarkko PoyryContextArrayPack::ContextArrayPack (glu::RenderContext& renderCtx, sglr::Context& drawContext)
7213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: m_renderCtx	(renderCtx)
7223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_ctx			(drawContext)
7233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_program		(DE_NULL)
7243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_screen		(std::min(512, renderCtx.getRenderTarget().getWidth()), std::min(512, renderCtx.getRenderTarget().getHeight()))
7253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
7263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
7273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7283c827367444ee418f129b2c238299f49d3264554Jarkko PoyryContextArrayPack::~ContextArrayPack (void)
7293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
7303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (std::vector<ContextArray*>::iterator itr = m_arrays.begin(); itr != m_arrays.end(); itr++)
7313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		delete *itr;
7323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_program;
7343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
7353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7363c827367444ee418f129b2c238299f49d3264554Jarkko Poyryint ContextArrayPack::getArrayCount (void)
7373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
7383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return (int)m_arrays.size();
7393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
7403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7413c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ContextArrayPack::newArray (Array::Storage storage)
7423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
7433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_arrays.push_back(new ContextArray(storage, m_ctx));
7443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
7453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7463c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ContextShaderProgram : public sglr::ShaderProgram
7473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
7483c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
7493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry												ContextShaderProgram		(const glu::RenderContext& ctx, const std::vector<ContextArray*>& arrays);
7503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void										shadeVertices				(const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const;
7523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void										shadeFragments				(rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const;
7533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7543c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
7553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static std::string							genVertexSource				(const glu::RenderContext& ctx, const std::vector<ContextArray*>& arrays);
7563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static std::string							genFragmentSource			(const glu::RenderContext& ctx);
7573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static rr::GenericVecType					mapOutputType				(const Array::OutputType& type);
7583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static int									getComponentCount			(const Array::OutputType& type);
7593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static sglr::pdec::ShaderProgramDeclaration createProgramDeclaration	(const glu::RenderContext& ctx, const std::vector<ContextArray*>& arrays);
7613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<int>							m_componentCount;
7633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<rr::GenericVecType>				m_attrType;
7643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
7653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7663c827367444ee418f129b2c238299f49d3264554Jarkko PoyryContextShaderProgram::ContextShaderProgram (const glu::RenderContext& ctx, const std::vector<ContextArray*>& arrays)
7673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: sglr::ShaderProgram	(createProgramDeclaration(ctx, arrays))
7683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_componentCount		(arrays.size())
7693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_attrType			(arrays.size())
7703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
7713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int arrayNdx = 0; arrayNdx < (int)arrays.size(); arrayNdx++)
7723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
7733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_componentCount[arrayNdx]	= getComponentCount(arrays[arrayNdx]->getOutputType());
7743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_attrType[arrayNdx]		= mapOutputType(arrays[arrayNdx]->getOutputType());
7753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
7763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
7773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7783c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T>
7793c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid calcShaderColorCoord (tcu::Vec2& coord, tcu::Vec3& color, const tcu::Vector<T, 4>& attribValue, bool isCoordinate, int numComponents)
7803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
7813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (isCoordinate)
7823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		switch (numComponents)
7833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
7845f40053fac3cbba8a029ce5685d8519c3668e89eJarkko Pöyry			case 1:	coord = tcu::Vec2((float)attribValue.x(),							(float)attribValue.x());							break;
7855f40053fac3cbba8a029ce5685d8519c3668e89eJarkko Pöyry			case 2:	coord = tcu::Vec2((float)attribValue.x(),							(float)attribValue.y());							break;
7865f40053fac3cbba8a029ce5685d8519c3668e89eJarkko Pöyry			case 3:	coord = tcu::Vec2((float)attribValue.x() + (float)attribValue.z(),	(float)attribValue.y());							break;
7875f40053fac3cbba8a029ce5685d8519c3668e89eJarkko Pöyry			case 4:	coord = tcu::Vec2((float)attribValue.x() + (float)attribValue.z(),	(float)attribValue.y() + (float)attribValue.w());	break;
7883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			default:
7903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				DE_ASSERT(false);
7913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
7923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
7933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
7943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		switch (numComponents)
7953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
7963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case 1:
7973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				color = color * (float)attribValue.x();
7983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
7993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case 2:
8015f40053fac3cbba8a029ce5685d8519c3668e89eJarkko Pöyry				color.x() = color.x() * (float)attribValue.x();
8025f40053fac3cbba8a029ce5685d8519c3668e89eJarkko Pöyry				color.y() = color.y() * (float)attribValue.y();
8033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
8043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case 3:
8065f40053fac3cbba8a029ce5685d8519c3668e89eJarkko Pöyry				color.x() = color.x() * (float)attribValue.x();
8075f40053fac3cbba8a029ce5685d8519c3668e89eJarkko Pöyry				color.y() = color.y() * (float)attribValue.y();
8085f40053fac3cbba8a029ce5685d8519c3668e89eJarkko Pöyry				color.z() = color.z() * (float)attribValue.z();
8093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
8103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case 4:
8125f40053fac3cbba8a029ce5685d8519c3668e89eJarkko Pöyry				color.x() = color.x() * (float)attribValue.x() * (float)attribValue.w();
8135f40053fac3cbba8a029ce5685d8519c3668e89eJarkko Pöyry				color.y() = color.y() * (float)attribValue.y() * (float)attribValue.w();
8145f40053fac3cbba8a029ce5685d8519c3668e89eJarkko Pöyry				color.z() = color.z() * (float)attribValue.z() * (float)attribValue.w();
8153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
8163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			default:
8183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				DE_ASSERT(false);
8193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
8203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
8213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
8223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8233c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ContextShaderProgram::shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const
8243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
8253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float	u_coordScale = getUniformByName("u_coordScale").value.f;
8263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float u_colorScale = getUniformByName("u_colorScale").value.f;
8273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
8293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
8303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const size_t varyingLocColor = 0;
8313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		rr::VertexPacket& packet = *packets[packetNdx];
8333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Calc output color
8353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::Vec2 coord = tcu::Vec2(1.0, 1.0);
8363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::Vec3 color = tcu::Vec3(1.0, 1.0, 1.0);
8373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int attribNdx = 0; attribNdx < (int)m_attrType.size(); attribNdx++)
8393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
8403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const int numComponents = m_componentCount[attribNdx];
8413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			switch (m_attrType[attribNdx])
8433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
8443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case rr::GENERICVECTYPE_FLOAT:	calcShaderColorCoord(coord, color, rr::readVertexAttribFloat(inputs[attribNdx], packet.instanceNdx, packet.vertexNdx), attribNdx == 0, numComponents);	break;
8453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case rr::GENERICVECTYPE_INT32:	calcShaderColorCoord(coord, color, rr::readVertexAttribInt	(inputs[attribNdx], packet.instanceNdx, packet.vertexNdx), attribNdx == 0, numComponents);	break;
8463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case rr::GENERICVECTYPE_UINT32:	calcShaderColorCoord(coord, color, rr::readVertexAttribUint	(inputs[attribNdx], packet.instanceNdx, packet.vertexNdx), attribNdx == 0, numComponents);	break;
8473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				default:
8483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					DE_ASSERT(false);
8493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
8503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
8513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Transform position
8533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
8543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			packet.position = tcu::Vec4(u_coordScale * coord.x(), u_coordScale * coord.y(), 1.0f, 1.0f);
8553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
8563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Pass color to FS
8583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
8593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			packet.outputs[varyingLocColor] = tcu::Vec4(u_colorScale * color.x(), u_colorScale * color.y(), u_colorScale * color.z(), 1.0f);
8603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
8613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
8623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
8633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8643c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ContextShaderProgram::shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const
8653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
8663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const size_t varyingLocColor = 0;
8673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Triangles are flashaded
8693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Vec4 color = rr::readTriangleVarying<float>(packets[0], context, varyingLocColor, 0);
8703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
8723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
8733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, color);
8743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
8753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8763c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystd::string ContextShaderProgram::genVertexSource (const glu::RenderContext& ctx, const std::vector<ContextArray*>& arrays)
8773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
8783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::stringstream vertexShaderTmpl;
8793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::map<std::string, std::string> params;
8803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (glu::isGLSLVersionSupported(ctx.getType(), glu::GLSL_VERSION_300_ES))
8823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
8833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["VTX_IN"]		= "in";
8843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["VTX_OUT"]		= "out";
8853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["FRAG_IN"]		= "in";
8863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["FRAG_COLOR"]	= "dEQP_FragColor";
8873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["VTX_HDR"]		= "#version 300 es\n";
8883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["FRAG_HDR"]		= "#version 300 es\nlayout(location = 0) out mediump vec4 dEQP_FragColor;\n";
8893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
8903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (glu::isGLSLVersionSupported(ctx.getType(), glu::GLSL_VERSION_100_ES))
8913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
8923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["VTX_IN"]		= "attribute";
8933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["VTX_OUT"]		= "varying";
8943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["FRAG_IN"]		= "varying";
8953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["FRAG_COLOR"]	= "gl_FragColor";
8963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["VTX_HDR"]		= "";
8973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["FRAG_HDR"]		= "";
8983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
8993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (glu::isGLSLVersionSupported(ctx.getType(), glu::GLSL_VERSION_330))
9003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
9013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["VTX_IN"]		= "in";
9023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["VTX_OUT"]		= "out";
9033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["FRAG_IN"]		= "in";
9043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["FRAG_COLOR"]	= "dEQP_FragColor";
9053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["VTX_HDR"]		= "#version 330\n";
9063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["FRAG_HDR"]		= "#version 330\nlayout(location = 0) out mediump vec4 dEQP_FragColor;\n";
9073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
9083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
9093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(DE_FALSE);
9103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vertexShaderTmpl << "${VTX_HDR}";
9123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int arrayNdx = 0; arrayNdx < (int)arrays.size(); arrayNdx++)
9143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
9153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		vertexShaderTmpl
9163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< "${VTX_IN} highp " <<  ContextArray::outputTypeToGLType(arrays[arrayNdx]->getOutputType()) << " a_" << arrays[arrayNdx]->getAttribNdx() << ";\n";
9173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
9183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vertexShaderTmpl <<
9203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"uniform highp float u_coordScale;\n"
9213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"uniform highp float u_colorScale;\n"
9223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"${VTX_OUT} mediump vec4 v_color;\n"
9233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"void main(void)\n"
9243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"{\n"
9253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"\tgl_PointSize = 1.0;\n"
9263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"\thighp vec2 coord = vec2(1.0, 1.0);\n"
9273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"\thighp vec3 color = vec3(1.0, 1.0, 1.0);\n";
9283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int arrayNdx = 0; arrayNdx < (int)arrays.size(); arrayNdx++)
9303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
9313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (arrays[arrayNdx]->getAttribNdx() == 0)
9323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
9333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			switch (arrays[arrayNdx]->getOutputType())
9343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
9353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case (Array::OUTPUTTYPE_FLOAT):
9363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					vertexShaderTmpl <<
9373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"\tcoord = vec2(a_0);\n";
9383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					break;
9393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case (Array::OUTPUTTYPE_VEC2):
9413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					vertexShaderTmpl <<
9423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"\tcoord = a_0.xy;\n";
9433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					break;
9443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case (Array::OUTPUTTYPE_VEC3):
9463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					vertexShaderTmpl <<
9473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"\tcoord = a_0.xy;\n"
9483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"\tcoord.x = coord.x + a_0.z;\n";
9493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					break;
9503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case (Array::OUTPUTTYPE_VEC4):
9523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					vertexShaderTmpl <<
9533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"\tcoord = a_0.xy;\n"
9543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"\tcoord += a_0.zw;\n";
9553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					break;
9563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case (Array::OUTPUTTYPE_IVEC2):
9583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case (Array::OUTPUTTYPE_UVEC2):
9593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					vertexShaderTmpl <<
9603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"\tcoord = vec2(a_0.xy);\n";
9613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					break;
9623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case (Array::OUTPUTTYPE_IVEC3):
9643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case (Array::OUTPUTTYPE_UVEC3):
9653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					vertexShaderTmpl <<
9663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"\tcoord = vec2(a_0.xy);\n"
9673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"\tcoord.x = coord.x + float(a_0.z);\n";
9683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					break;
9693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case (Array::OUTPUTTYPE_IVEC4):
9713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case (Array::OUTPUTTYPE_UVEC4):
9723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					vertexShaderTmpl <<
9733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"\tcoord = vec2(a_0.xy);\n"
9743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"\tcoord += vec2(a_0.zw);\n";
9753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					break;
9763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				default:
9783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					DE_ASSERT(false);
9793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					break;
9803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
9813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			continue;
9823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
9833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		switch (arrays[arrayNdx]->getOutputType())
9853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
9863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case (Array::OUTPUTTYPE_FLOAT):
9873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				vertexShaderTmpl <<
9883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					"\tcolor = color * a_" << arrays[arrayNdx]->getAttribNdx() << ";\n";
9893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
9903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case (Array::OUTPUTTYPE_VEC2):
9923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				vertexShaderTmpl <<
9933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					"\tcolor.rg = color.rg * a_" << arrays[arrayNdx]->getAttribNdx() << ".xy;\n";
9943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
9953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case (Array::OUTPUTTYPE_VEC3):
9973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				vertexShaderTmpl <<
9983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					"\tcolor = color.rgb * a_" << arrays[arrayNdx]->getAttribNdx() << ".xyz;\n";
9993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
10003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case (Array::OUTPUTTYPE_VEC4):
10023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				vertexShaderTmpl <<
10033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					"\tcolor = color.rgb * a_" << arrays[arrayNdx]->getAttribNdx() << ".xyz * a_" << arrays[arrayNdx]->getAttribNdx() << ".w;\n";
10043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
10053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			default:
10073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				DE_ASSERT(false);
10083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
10093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
10103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
10113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vertexShaderTmpl <<
10133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"\tv_color = vec4(u_colorScale * color, 1.0);\n"
10143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"\tgl_Position = vec4(u_coordScale * coord, 1.0, 1.0);\n"
10153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"}\n";
10163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return tcu::StringTemplate(vertexShaderTmpl.str().c_str()).specialize(params);
10183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
10193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10203c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystd::string ContextShaderProgram::genFragmentSource (const glu::RenderContext& ctx)
10213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
10223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::map<std::string, std::string> params;
10233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (glu::isGLSLVersionSupported(ctx.getType(), glu::GLSL_VERSION_300_ES))
10253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
10263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["VTX_IN"]		= "in";
10273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["VTX_OUT"]		= "out";
10283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["FRAG_IN"]		= "in";
10293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["FRAG_COLOR"]	= "dEQP_FragColor";
10303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["VTX_HDR"]		= "#version 300 es\n";
10313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["FRAG_HDR"]		= "#version 300 es\nlayout(location = 0) out mediump vec4 dEQP_FragColor;\n";
10323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
10333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (glu::isGLSLVersionSupported(ctx.getType(), glu::GLSL_VERSION_100_ES))
10343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
10353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["VTX_IN"]		= "attribute";
10363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["VTX_OUT"]		= "varying";
10373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["FRAG_IN"]		= "varying";
10383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["FRAG_COLOR"]	= "gl_FragColor";
10393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["VTX_HDR"]		= "";
10403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["FRAG_HDR"]		= "";
10413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
10423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (glu::isGLSLVersionSupported(ctx.getType(), glu::GLSL_VERSION_330))
10433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
10443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["VTX_IN"]		= "in";
10453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["VTX_OUT"]		= "out";
10463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["FRAG_IN"]		= "in";
10473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["FRAG_COLOR"]	= "dEQP_FragColor";
10483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["VTX_HDR"]		= "#version 330\n";
10493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params["FRAG_HDR"]		= "#version 330\nlayout(location = 0) out mediump vec4 dEQP_FragColor;\n";
10503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
10513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
10523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(DE_FALSE);
10533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const char* fragmentShaderTmpl =
10553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"${FRAG_HDR}"
10563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"${FRAG_IN} mediump vec4 v_color;\n"
10573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"void main(void)\n"
10583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"{\n"
10593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"\t${FRAG_COLOR} = v_color;\n"
10603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"}\n";
10613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return tcu::StringTemplate(fragmentShaderTmpl).specialize(params);
10633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
10643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10653c827367444ee418f129b2c238299f49d3264554Jarkko Poyryrr::GenericVecType ContextShaderProgram::mapOutputType (const Array::OutputType& type)
10663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
10673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (type)
10683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
10693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case (Array::OUTPUTTYPE_FLOAT):
10703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case (Array::OUTPUTTYPE_VEC2):
10713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case (Array::OUTPUTTYPE_VEC3):
10723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case (Array::OUTPUTTYPE_VEC4):
10733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return rr::GENERICVECTYPE_FLOAT;
10743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case (Array::OUTPUTTYPE_INT):
10763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case (Array::OUTPUTTYPE_IVEC2):
10773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case (Array::OUTPUTTYPE_IVEC3):
10783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case (Array::OUTPUTTYPE_IVEC4):
10793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return rr::GENERICVECTYPE_INT32;
10803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case (Array::OUTPUTTYPE_UINT):
10823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case (Array::OUTPUTTYPE_UVEC2):
10833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case (Array::OUTPUTTYPE_UVEC3):
10843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case (Array::OUTPUTTYPE_UVEC4):
10853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return rr::GENERICVECTYPE_UINT32;
10863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
10883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
10893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return rr::GENERICVECTYPE_LAST;
10903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
10913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
10923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10933c827367444ee418f129b2c238299f49d3264554Jarkko Poyryint ContextShaderProgram::getComponentCount (const Array::OutputType& type)
10943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
10953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (type)
10963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
10973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case (Array::OUTPUTTYPE_FLOAT):
10983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case (Array::OUTPUTTYPE_INT):
10993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case (Array::OUTPUTTYPE_UINT):
11003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return 1;
11013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case (Array::OUTPUTTYPE_VEC2):
11033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case (Array::OUTPUTTYPE_IVEC2):
11043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case (Array::OUTPUTTYPE_UVEC2):
11053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return 2;
11063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case (Array::OUTPUTTYPE_VEC3):
11083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case (Array::OUTPUTTYPE_IVEC3):
11093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case (Array::OUTPUTTYPE_UVEC3):
11103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return 3;
11113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case (Array::OUTPUTTYPE_VEC4):
11133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case (Array::OUTPUTTYPE_IVEC4):
11143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case (Array::OUTPUTTYPE_UVEC4):
11153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return 4;
11163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
11183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
11193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return 0;
11203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
11213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
11223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11233c827367444ee418f129b2c238299f49d3264554Jarkko Poyrysglr::pdec::ShaderProgramDeclaration ContextShaderProgram::createProgramDeclaration (const glu::RenderContext& ctx, const std::vector<ContextArray*>& arrays)
11243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
11253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sglr::pdec::ShaderProgramDeclaration decl;
11263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int arrayNdx = 0; arrayNdx < (int)arrays.size(); arrayNdx++)
11283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		decl << sglr::pdec::VertexAttribute(std::string("a_") + de::toString(arrayNdx), mapOutputType(arrays[arrayNdx]->getOutputType()));
11293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	decl << sglr::pdec::VertexToFragmentVarying(rr::GENERICVECTYPE_FLOAT);
11313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	decl << sglr::pdec::FragmentOutput(rr::GENERICVECTYPE_FLOAT);
11323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	decl << sglr::pdec::VertexSource(genVertexSource(ctx, arrays));
11343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	decl << sglr::pdec::FragmentSource(genFragmentSource(ctx));
11353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	decl << sglr::pdec::Uniform("u_coordScale", glu::TYPE_FLOAT);
11373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	decl << sglr::pdec::Uniform("u_colorScale", glu::TYPE_FLOAT);
11383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return decl;
11403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
11413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11423c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ContextArrayPack::updateProgram (void)
11433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
11443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_program;
11453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_program = new ContextShaderProgram(m_renderCtx, m_arrays);
11463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
11473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11483c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ContextArrayPack::render (Array::Primitive primitive, int firstVertex, int vertexCount, bool useVao, float coordScale, float colorScale)
11493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
11503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32 program = 0;
11513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32 vaoId = 0;
11523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	updateProgram();
11543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_ctx.viewport(0, 0, m_screen.getWidth(), m_screen.getHeight());
11563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_ctx.clearColor(0.0, 0.0, 0.0, 1.0);
11573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_ctx.clear(GL_COLOR_BUFFER_BIT);
11583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	program = m_ctx.createProgram(m_program);
11603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_ctx.useProgram(program);
11623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glUseProgram()");
11633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_ctx.uniform1f(m_ctx.getUniformLocation(program, "u_coordScale"), coordScale);
11653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_ctx.uniform1f(m_ctx.getUniformLocation(program, "u_colorScale"), colorScale);
11663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (useVao)
11683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
11693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_ctx.genVertexArrays(1, &vaoId);
11703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_ctx.bindVertexArray(vaoId);
11713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
11723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int arrayNdx = 0; arrayNdx < (int)m_arrays.size(); arrayNdx++)
11743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
11753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_arrays[arrayNdx]->isBound())
11763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
11773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			std::stringstream attribName;
11783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			attribName << "a_" << m_arrays[arrayNdx]->getAttribNdx();
11793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint32 loc = m_ctx.getAttribLocation(program, attribName.str().c_str());
11813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_ctx.enableVertexAttribArray(loc);
11823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glEnableVertexAttribArray()");
11833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_arrays[arrayNdx]->glBind(loc);
11853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
11863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
11873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT((firstVertex % 6) == 0);
11893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_ctx.drawArrays(ContextArray::primitiveToGL(primitive), firstVertex, vertexCount - firstVertex);
11903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glDrawArrays()");
11913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int arrayNdx = 0; arrayNdx < (int)m_arrays.size(); arrayNdx++)
11933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
11943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_arrays[arrayNdx]->isBound())
11953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
11963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			std::stringstream attribName;
11973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			attribName << "a_" << m_arrays[arrayNdx]->getAttribNdx();
11983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint32 loc = m_ctx.getAttribLocation(program, attribName.str().c_str());
12003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_ctx.disableVertexAttribArray(loc);
12023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glDisableVertexAttribArray()");
12033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
12043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
12053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (useVao)
12073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_ctx.deleteVertexArrays(1, &vaoId);
12083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_ctx.deleteProgram(program);
12103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_ctx.useProgram(0);
12113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_ctx.readPixels(m_screen, 0, 0, m_screen.getWidth(), m_screen.getHeight());
12123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
12133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// GLValue
12153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12163c827367444ee418f129b2c238299f49d3264554Jarkko PoyryGLValue GLValue::getMaxValue (Array::InputType type)
12173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
12183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLValue rangesHi[(int)Array::INPUTTYPE_LAST];
12193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	rangesHi[(int)Array::INPUTTYPE_FLOAT]			= GLValue(Float::create(127.0f));
12213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	rangesHi[(int)Array::INPUTTYPE_DOUBLE]			= GLValue(Double::create(127.0f));
12223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	rangesHi[(int)Array::INPUTTYPE_BYTE]			= GLValue(Byte::create(127));
12233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	rangesHi[(int)Array::INPUTTYPE_UNSIGNED_BYTE]	= GLValue(Ubyte::create(255));
12243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	rangesHi[(int)Array::INPUTTYPE_UNSIGNED_SHORT]	= GLValue(Ushort::create(65530));
12253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	rangesHi[(int)Array::INPUTTYPE_SHORT]			= GLValue(Short::create(32760));
12263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	rangesHi[(int)Array::INPUTTYPE_FIXED]			= GLValue(Fixed::create(32760));
12273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	rangesHi[(int)Array::INPUTTYPE_INT]				= GLValue(Int::create(2147483647));
12283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	rangesHi[(int)Array::INPUTTYPE_UNSIGNED_INT]	= GLValue(Uint::create(4294967295u));
12293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	rangesHi[(int)Array::INPUTTYPE_HALF]			= GLValue(Half::create(256.0f));
12303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return rangesHi[(int)type];
12323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
12333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12343c827367444ee418f129b2c238299f49d3264554Jarkko PoyryGLValue GLValue::getMinValue (Array::InputType type)
12353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
12363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLValue rangesLo[(int)Array::INPUTTYPE_LAST];
12373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	rangesLo[(int)Array::INPUTTYPE_FLOAT]			= GLValue(Float::create(-127.0f));
12393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	rangesLo[(int)Array::INPUTTYPE_DOUBLE]			= GLValue(Double::create(-127.0f));
12403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	rangesLo[(int)Array::INPUTTYPE_BYTE]			= GLValue(Byte::create(-127));
12413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	rangesLo[(int)Array::INPUTTYPE_UNSIGNED_BYTE]	= GLValue(Ubyte::create(0));
12423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	rangesLo[(int)Array::INPUTTYPE_UNSIGNED_SHORT]	= GLValue(Ushort::create(0));
12433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	rangesLo[(int)Array::INPUTTYPE_SHORT]			= GLValue(Short::create(-32760));
12443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	rangesLo[(int)Array::INPUTTYPE_FIXED]			= GLValue(Fixed::create(-32760));
12453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	rangesLo[(int)Array::INPUTTYPE_INT]				= GLValue(Int::create(-2147483647));
12463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	rangesLo[(int)Array::INPUTTYPE_UNSIGNED_INT]	= GLValue(Uint::create(0));
12473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	rangesLo[(int)Array::INPUTTYPE_HALF]			= GLValue(Half::create(-256.0f));
12483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return rangesLo[(int)type];
12503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
12513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12523c827367444ee418f129b2c238299f49d3264554Jarkko Poyryfloat GLValue::toFloat (void) const
12533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
12543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (type)
12553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
12563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_FLOAT:
12573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return fl.getValue();
12583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
12593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_BYTE:
12613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return b.getValue();
12623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
12633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_UNSIGNED_BYTE:
12653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return ub.getValue();
12663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
12673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_SHORT:
12693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return s.getValue();
12703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
12713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_UNSIGNED_SHORT:
12733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return us.getValue();
12743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
12753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_FIXED:
12773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
12783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			int maxValue = 65536;
12793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return (float)(double(2 * fi.getValue() + 1) / (maxValue - 1));
12803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
12823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
12833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_UNSIGNED_INT:
12853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return (float)ui.getValue();
12863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
12873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_INT:
12893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return (float)i.getValue();
12903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
12913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_HALF:
12933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return h.to<float>();
12943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
12953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_DOUBLE:
12973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return (float)d.getValue();
12983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
12993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
13013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
13023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return 0.0f;
13033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
13043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
13053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
13063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13073c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass RandomArrayGenerator
13083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
13093c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
13103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static char*	generateArray			(int seed, GLValue min, GLValue max, int count, int componentCount, int stride, Array::InputType type);
13118ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi	static char*	generateQuads			(int seed, int count, int componentCount, int offset, int stride, Array::Primitive primitive, Array::InputType type, GLValue min, GLValue max, float gridSize);
13123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static char*	generatePerQuad			(int seed, int count, int componentCount, int stride, Array::Primitive primitive, Array::InputType type, GLValue min, GLValue max);
13133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13143c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
13153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	template<typename T>
13168ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi	static char*	createQuads		(int seed, int count, int componentCount, int offset, int stride, Array::Primitive primitive, T min, T max, float gridSize);
13173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	template<typename T>
13183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static char*	createPerQuads	(int seed, int count, int componentCount, int stride, Array::Primitive primitive, T min, T max);
13193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static char*	createQuadsPacked (int seed, int count, int componentCount, int offset, int stride, Array::Primitive primitive);
13203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static void		setData			(char* data, Array::InputType type, deRandom& rnd, GLValue min, GLValue max);
13213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
13223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13233c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RandomArrayGenerator::setData (char* data, Array::InputType type, deRandom& rnd, GLValue min, GLValue max)
13243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
13253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (type)
13263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
13273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_FLOAT:
13283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
13293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			alignmentSafeAssignment<float>(data, getRandom<GLValue::Float>(rnd, min.fl, max.fl));
13303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
13313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
13323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_DOUBLE:
13343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
13353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			alignmentSafeAssignment<double>(data, getRandom<GLValue::Float>(rnd, min.fl, max.fl));
13363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
13373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
13383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_SHORT:
13403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
13413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			alignmentSafeAssignment<deInt16>(data, getRandom<GLValue::Short>(rnd, min.s, max.s));
13423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
13433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
13443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_UNSIGNED_SHORT:
13463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
13473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			alignmentSafeAssignment<deUint16>(data, getRandom<GLValue::Ushort>(rnd, min.us, max.us));
13483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
13493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
13503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_BYTE:
13523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
13533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			alignmentSafeAssignment<deInt8>(data, getRandom<GLValue::Byte>(rnd, min.b, max.b));
13543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
13553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
13563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_UNSIGNED_BYTE:
13583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
13593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			alignmentSafeAssignment<deUint8>(data, getRandom<GLValue::Ubyte>(rnd, min.ub, max.ub));
13603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
13613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
13623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_FIXED:
13643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
13653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			alignmentSafeAssignment<deInt32>(data, getRandom<GLValue::Fixed>(rnd, min.fi, max.fi));
13663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
13673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
13683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_INT:
13703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
13713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			alignmentSafeAssignment<deInt32>(data, getRandom<GLValue::Int>(rnd, min.i, max.i));
13723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
13733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
13743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_UNSIGNED_INT:
13763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
13773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			alignmentSafeAssignment<deUint32>(data, getRandom<GLValue::Uint>(rnd, min.ui, max.ui));
13783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
13793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
13803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_HALF:
13823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
13833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			alignmentSafeAssignment<deFloat16>(data, getRandom<GLValue::Half>(rnd, min.h, max.h).getValue());
13843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
13853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
13863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
13883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
13893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
13903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
13913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
13923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13933c827367444ee418f129b2c238299f49d3264554Jarkko Poyrychar* RandomArrayGenerator::generateArray (int seed, GLValue min, GLValue max, int count, int componentCount, int stride, Array::InputType type)
13943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
13953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	char* data = NULL;
13963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deRandom rnd;
13983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deRandom_init(&rnd, seed);
13993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (stride == 0)
14013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		stride = componentCount * Array::inputTypeSize(type);
14023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	data = new char[stride * count];
14043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int vertexNdx = 0; vertexNdx < count; vertexNdx++)
14063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
14073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int componentNdx = 0; componentNdx < componentCount; componentNdx++)
14083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
14093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			setData(&(data[vertexNdx * stride + Array::inputTypeSize(type) * componentNdx]), type, rnd, min, max);
14103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
14113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
14123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return data;
14143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
14153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14168ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvichar* RandomArrayGenerator::generateQuads (int seed, int count, int componentCount, int offset, int stride, Array::Primitive primitive, Array::InputType type, GLValue min, GLValue max, float gridSize)
14173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
14183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	char* data = DE_NULL;
14193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (type)
14213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
14223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_FLOAT:
14238ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi			data = createQuads<GLValue::Float>(seed, count, componentCount, offset, stride, primitive, min.fl, max.fl, gridSize);
14243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
14253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_FIXED:
14278ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi			data = createQuads<GLValue::Fixed>(seed, count, componentCount, offset, stride, primitive, min.fi, max.fi, gridSize);
14283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
14293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_DOUBLE:
14318ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi			data = createQuads<GLValue::Double>(seed, count, componentCount, offset, stride, primitive, min.d, max.d, gridSize);
14323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
14333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_BYTE:
14358ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi			data = createQuads<GLValue::Byte>(seed, count, componentCount, offset, stride, primitive, min.b, max.b, gridSize);
14363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
14373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_SHORT:
14398ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi			data = createQuads<GLValue::Short>(seed, count, componentCount, offset, stride, primitive, min.s, max.s, gridSize);
14403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
14413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_UNSIGNED_BYTE:
14438ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi			data = createQuads<GLValue::Ubyte>(seed, count, componentCount, offset, stride, primitive, min.ub, max.ub, gridSize);
14443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
14453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_UNSIGNED_SHORT:
14478ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi			data = createQuads<GLValue::Ushort>(seed, count, componentCount, offset, stride, primitive, min.us, max.us, gridSize);
14483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
14493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_UNSIGNED_INT:
14518ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi			data = createQuads<GLValue::Uint>(seed, count, componentCount, offset, stride, primitive, min.ui, max.ui, gridSize);
14523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
14533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_INT:
14558ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi			data = createQuads<GLValue::Int>(seed, count, componentCount, offset, stride, primitive, min.i, max.i, gridSize);
14563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
14573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_HALF:
14598ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi			data = createQuads<GLValue::Half>(seed, count, componentCount, offset, stride, primitive, min.h, max.h, gridSize);
14603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
14613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_INT_2_10_10_10:
14633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_UNSIGNED_INT_2_10_10_10:
14643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			data = createQuadsPacked(seed, count, componentCount, offset, stride, primitive);
14653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
14663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
14683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
14693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
14703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
14713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return data;
14733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
14743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14753c827367444ee418f129b2c238299f49d3264554Jarkko Poyrychar* RandomArrayGenerator::createQuadsPacked (int seed, int count, int componentCount, int offset, int stride, Array::Primitive primitive)
14763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
14773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(componentCount == 4);
14783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(componentCount);
14793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int quadStride = 0;
14803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (stride == 0)
14823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		stride = sizeof(deUint32);
14833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (primitive)
14853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
14863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::PRIMITIVE_TRIANGLES:
14873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			quadStride = stride * 6;
14883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
14893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
14913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
14923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
14933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
14943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	char* const _data		= new char[offset + quadStride * (count - 1) + stride * 5 + componentCount * Array::inputTypeSize(Array::INPUTTYPE_INT_2_10_10_10)]; // last element must be fully in the array
14963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	char* const resultData	= _data + offset;
14973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const deUint32 max		= 1024;
14993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const deUint32 min		= 10;
15003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const deUint32 max2		= 4;
15013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deRandom rnd;
15033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deRandom_init(&rnd,  seed);
15043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (primitive)
15063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
15073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::PRIMITIVE_TRIANGLES:
15083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
15093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int quadNdx = 0; quadNdx < count; quadNdx++)
15103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
15113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				deUint32 x1	= min + deRandom_getUint32(&rnd) % (max - min);
15123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				deUint32 x2	= min + deRandom_getUint32(&rnd) % (max - x1);
15133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				deUint32 y1	= min + deRandom_getUint32(&rnd) % (max - min);
15153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				deUint32 y2	= min + deRandom_getUint32(&rnd) % (max - y1);
15163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				deUint32 z	= min + deRandom_getUint32(&rnd) % (max - min);
15183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				deUint32 w	= deRandom_getUint32(&rnd) % max2;
15193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				deUint32 val1 = (w << 30) | (z << 20) | (y1 << 10) | x1;
15213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				deUint32 val2 = (w << 30) | (z << 20) | (y1 << 10) | x2;
15223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				deUint32 val3 = (w << 30) | (z << 20) | (y2 << 10) | x1;
15233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				deUint32 val4 = (w << 30) | (z << 20) | (y2 << 10) | x1;
15253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				deUint32 val5 = (w << 30) | (z << 20) | (y1 << 10) | x2;
15263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				deUint32 val6 = (w << 30) | (z << 20) | (y2 << 10) | x2;
15273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				alignmentSafeAssignment<deUint32>(&(resultData[quadNdx * quadStride + stride * 0]), val1);
15293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				alignmentSafeAssignment<deUint32>(&(resultData[quadNdx * quadStride + stride * 1]), val2);
15303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				alignmentSafeAssignment<deUint32>(&(resultData[quadNdx * quadStride + stride * 2]), val3);
15313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				alignmentSafeAssignment<deUint32>(&(resultData[quadNdx * quadStride + stride * 3]), val4);
15323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				alignmentSafeAssignment<deUint32>(&(resultData[quadNdx * quadStride + stride * 4]), val5);
15333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				alignmentSafeAssignment<deUint32>(&(resultData[quadNdx * quadStride + stride * 5]), val6);
15343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
15353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
15373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
15383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
15403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
15413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
15423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
15433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return _data;
15453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
15463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15473c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T>
15488ed28c1e05f2325dc4b20c8f471067b29188c82fMika IsojärviT roundTo (const T& step, const T& value)
15498ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi{
15508ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi	return value - (value % step);
15518ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi}
15528ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi
15538ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvitemplate<typename T>
15548ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvichar* RandomArrayGenerator::createQuads (int seed, int count, int componentCount, int offset, int stride, Array::Primitive primitive, T min, T max, float gridSize)
15553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
15563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int componentStride = sizeof(T);
15573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int quadStride = 0;
15583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (stride == 0)
15603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		stride = componentCount * componentStride;
15618ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi
15623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(stride >= componentCount * componentStride);
15633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (primitive)
15653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
15663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::PRIMITIVE_TRIANGLES:
15673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			quadStride = stride * 6;
15683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
15693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
15713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
15723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
15733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
15743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	char* resultData = new char[offset + quadStride * count];
15763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	char* _data = resultData;
15773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	resultData = resultData + offset;
15783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deRandom rnd;
15803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deRandom_init(&rnd,  seed);
15813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (primitive)
15833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
15843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::PRIMITIVE_TRIANGLES:
15853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
15868ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi			const T	minQuadSize	= T::fromFloat(deFloatAbs(max.template to<float>() - min.template to<float>()) * gridSize);
15878ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi			const T	minDiff		= minValue<T>() > minQuadSize
15888ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi								? minValue<T>()
15898ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi								: minQuadSize;
15908ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi
15913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int quadNdx = 0; quadNdx < count; ++quadNdx)
15923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
15933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				T x1, x2;
15943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				T y1, y2;
15953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				T z, w;
15963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				// attempt to find a good (i.e not extremely small) quad
15983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				for (int attemptNdx = 0; attemptNdx < 4; ++attemptNdx)
15993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
16008ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi					x1 = roundTo(minDiff, getRandom<T>(rnd, min, max));
16018ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi					x2 = roundTo(minDiff, getRandom<T>(rnd, minDiff, abs<T>(max - x1)));
16023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16038ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi					y1 = roundTo(minDiff, getRandom<T>(rnd, min, max));
16048ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi					y2 = roundTo(minDiff, getRandom<T>(rnd, minDiff, abs<T>(max - y1)));
16053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16068ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi					z = (componentCount > 2) ? roundTo(minDiff, (getRandom<T>(rnd, min, max))) : (T::create(0));
16078ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi					w = (componentCount > 3) ? roundTo(minDiff, (getRandom<T>(rnd, min, max))) : (T::create(1));
16083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					// no additional components, all is good
16103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					if (componentCount <= 2)
16113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						break;
16123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					// The result quad is too thin?
16148ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi					if ((deFloatAbs(x2.template to<float>() + z.template to<float>()) < minDiff.template to<float>()) ||
16158ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi						(deFloatAbs(y2.template to<float>() + w.template to<float>()) < minDiff.template to<float>()))
16163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						continue;
16173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					// all ok
16193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					break;
16203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
16213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				alignmentSafeAssignment<T>(&(resultData[quadNdx * quadStride]), x1);
16233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				alignmentSafeAssignment<T>(&(resultData[quadNdx * quadStride + componentStride]), y1);
16243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				alignmentSafeAssignment<T>(&(resultData[quadNdx * quadStride + stride]), x1 + x2);
16263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				alignmentSafeAssignment<T>(&(resultData[quadNdx * quadStride + stride + componentStride]), y1);
16273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				alignmentSafeAssignment<T>(&(resultData[quadNdx * quadStride + stride * 2]), x1);
16293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				alignmentSafeAssignment<T>(&(resultData[quadNdx * quadStride + stride * 2 + componentStride]), y1 + y2);
16303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				alignmentSafeAssignment<T>(&(resultData[quadNdx * quadStride + stride * 3]), x1);
16323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				alignmentSafeAssignment<T>(&(resultData[quadNdx * quadStride + stride * 3 + componentStride]), y1 + y2);
16333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				alignmentSafeAssignment<T>(&(resultData[quadNdx * quadStride + stride * 4]), x1 + x2);
16353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				alignmentSafeAssignment<T>(&(resultData[quadNdx * quadStride + stride * 4 + componentStride]), y1);
16363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				alignmentSafeAssignment<T>(&(resultData[quadNdx * quadStride + stride * 5]), x1 + x2);
16383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				alignmentSafeAssignment<T>(&(resultData[quadNdx * quadStride + stride * 5 + componentStride]), y1 + y2);
16393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (componentCount > 2)
16413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
16423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					for (int i = 0; i < 6; i++)
16433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						alignmentSafeAssignment<T>(&(resultData[quadNdx * quadStride + stride * i + componentStride * 2]), z);
16443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
16453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (componentCount > 3)
16473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
16483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					for (int i = 0; i < 6; i++)
16493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						alignmentSafeAssignment<T>(&(resultData[quadNdx * quadStride + stride * i + componentStride * 3]), w);
16503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
16513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
16523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
16543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
16553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
16573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
16583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
16593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
16603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return _data;
16623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
16633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16643c827367444ee418f129b2c238299f49d3264554Jarkko Poyrychar* RandomArrayGenerator::generatePerQuad (int seed, int count, int componentCount, int stride, Array::Primitive primitive, Array::InputType type, GLValue min, GLValue max)
16653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
16663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	char* data = DE_NULL;
16673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (type)
16693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
16703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_FLOAT:
16713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			data = createPerQuads<GLValue::Float>(seed, count, componentCount, stride, primitive, min.fl, max.fl);
16723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
16733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_FIXED:
16753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			data = createPerQuads<GLValue::Fixed>(seed, count, componentCount, stride, primitive, min.fi, max.fi);
16763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
16773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_DOUBLE:
16793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			data = createPerQuads<GLValue::Double>(seed, count, componentCount, stride, primitive, min.d, max.d);
16803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
16813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_BYTE:
16833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			data = createPerQuads<GLValue::Byte>(seed, count, componentCount, stride, primitive, min.b, max.b);
16843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
16853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_SHORT:
16873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			data = createPerQuads<GLValue::Short>(seed, count, componentCount, stride, primitive, min.s, max.s);
16883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
16893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_UNSIGNED_BYTE:
16913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			data = createPerQuads<GLValue::Ubyte>(seed, count, componentCount, stride, primitive, min.ub, max.ub);
16923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
16933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_UNSIGNED_SHORT:
16953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			data = createPerQuads<GLValue::Ushort>(seed, count, componentCount, stride, primitive, min.us, max.us);
16963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
16973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_UNSIGNED_INT:
16993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			data = createPerQuads<GLValue::Uint>(seed, count, componentCount, stride, primitive, min.ui, max.ui);
17003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
17013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_INT:
17033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			data = createPerQuads<GLValue::Int>(seed, count, componentCount, stride, primitive, min.i, max.i);
17043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
17053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::INPUTTYPE_HALF:
17073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			data = createPerQuads<GLValue::Half>(seed, count, componentCount, stride, primitive, min.h, max.h);
17083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
17093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
17113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
17123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
17133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
17143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return data;
17163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
17173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17183c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T>
17193c827367444ee418f129b2c238299f49d3264554Jarkko Poyrychar* RandomArrayGenerator::createPerQuads (int seed, int count, int componentCount, int stride, Array::Primitive primitive, T min, T max)
17203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
17213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deRandom rnd;
17223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deRandom_init(&rnd, seed);
17233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int componentStride = sizeof(T);
17253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (stride == 0)
17273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		stride = componentStride * componentCount;
17283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int quadStride = 0;
17303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (primitive)
17323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
17333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::PRIMITIVE_TRIANGLES:
17343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			quadStride = stride * 6;
17353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
17363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
17383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
17393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
17403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
17413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	char* data = new char[count * quadStride];
17433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int quadNdx = 0; quadNdx < count; quadNdx++)
17453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
17463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int componentNdx = 0; componentNdx < componentCount; componentNdx++)
17473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
17483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			T val = getRandom<T>(rnd, min, max);
17493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			alignmentSafeAssignment<T>(data + quadNdx * quadStride + stride * 0 + componentStride * componentNdx, val);
17513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			alignmentSafeAssignment<T>(data + quadNdx * quadStride + stride * 1 + componentStride * componentNdx, val);
17523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			alignmentSafeAssignment<T>(data + quadNdx * quadStride + stride * 2 + componentStride * componentNdx, val);
17533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			alignmentSafeAssignment<T>(data + quadNdx * quadStride + stride * 3 + componentStride * componentNdx, val);
17543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			alignmentSafeAssignment<T>(data + quadNdx * quadStride + stride * 4 + componentStride * componentNdx, val);
17553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			alignmentSafeAssignment<T>(data + quadNdx * quadStride + stride * 5 + componentStride * componentNdx, val);
17563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
17573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
17583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return data;
17603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
17613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// VertexArrayTest
17633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17643c827367444ee418f129b2c238299f49d3264554Jarkko PoyryVertexArrayTest::VertexArrayTest (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const char* name ,const char* desc)
17653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCase			(testCtx, name, desc)
17663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_renderCtx		(renderCtx)
17673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_refBuffers		(DE_NULL)
17683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_refContext		(DE_NULL)
17693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_glesContext		(DE_NULL)
17703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_glArrayPack		(DE_NULL)
17713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_rrArrayPack		(DE_NULL)
17723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_isOk			(false)
1773c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry	, m_maxDiffRed		(deCeilFloatToInt32(256.0f * (2.0f / (float)(1 << m_renderCtx.getRenderTarget().getPixelFormat().redBits))))
1774c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry	, m_maxDiffGreen	(deCeilFloatToInt32(256.0f * (2.0f / (float)(1 << m_renderCtx.getRenderTarget().getPixelFormat().greenBits))))
1775c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry	, m_maxDiffBlue		(deCeilFloatToInt32(256.0f * (2.0f / (float)(1 << m_renderCtx.getRenderTarget().getPixelFormat().blueBits))))
17763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
17773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
17783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17793c827367444ee418f129b2c238299f49d3264554Jarkko PoyryVertexArrayTest::~VertexArrayTest (void)
17803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
17813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deinit();
17823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
17833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17843c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid VertexArrayTest::init (void)
17853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
17863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int						renderTargetWidth	= de::min(512, m_renderCtx.getRenderTarget().getWidth());
17873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int						renderTargetHeight	= de::min(512, m_renderCtx.getRenderTarget().getHeight());
17883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sglr::ReferenceContextLimits	limits				(m_renderCtx);
17893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_glesContext		= new sglr::GLContext(m_renderCtx, m_testCtx.getLog(), sglr::GLCONTEXT_LOG_CALLS | sglr::GLCONTEXT_LOG_PROGRAMS, tcu::IVec4(0, 0, renderTargetWidth, renderTargetHeight));
17913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_refBuffers		= new sglr::ReferenceContextBuffers(m_renderCtx.getRenderTarget().getPixelFormat(), 0, 0, renderTargetWidth, renderTargetHeight);
17933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_refContext		= new sglr::ReferenceContext(limits, m_refBuffers->getColorbuffer(), m_refBuffers->getDepthbuffer(), m_refBuffers->getStencilbuffer());
17943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_glArrayPack		= new ContextArrayPack(m_renderCtx, *m_glesContext);
17963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_rrArrayPack		= new ContextArrayPack(m_renderCtx, *m_refContext);
17973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
17983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17993c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid VertexArrayTest::deinit (void)
18003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
18013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_glArrayPack;
18023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_rrArrayPack;
18033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_refBuffers;
18043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_refContext;
18053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_glesContext;
18063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_glArrayPack	= DE_NULL;
18083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_rrArrayPack	= DE_NULL;
18093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_refBuffers	= DE_NULL;
18103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_refContext	= DE_NULL;
18113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_glesContext	= DE_NULL;
18123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
18133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18143c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid VertexArrayTest::compare (void)
18153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
18163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::Surface&	ref		= m_rrArrayPack->getSurface();
18173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::Surface&	screen	= m_glArrayPack->getSurface();
18183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_renderCtx.getRenderTarget().getNumSamples() > 1)
18203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
18213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// \todo [mika] Improve compare when using multisampling
18223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << tcu::TestLog::Message << "Warning: Comparision of result from multisample render targets are not as stricts as without multisampling. Might produce false positives!" << tcu::TestLog::EndMessage;
18233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_isOk = tcu::fuzzyCompare(m_testCtx.getLog(), "Compare Results", "Compare Results", ref.getAccess(), screen.getAccess(), 1.5f, tcu::COMPARE_LOG_RESULT);
18243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
18253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
18263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
18273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::RGBA		threshold	(m_maxDiffRed, m_maxDiffGreen, m_maxDiffBlue, 255);
18283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::Surface	error		(ref.getWidth(), ref.getHeight());
18293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_isOk = true;
18313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1832545d74e83cff0800c8d65adf1812768745b7ec60Mika Isojärvi		for (int y = 0; y < ref.getHeight(); y++)
18333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1834545d74e83cff0800c8d65adf1812768745b7ec60Mika Isojärvi			for (int x = 0; x < ref.getWidth(); x++)
18353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
18363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				tcu::RGBA	refPixel		= ref.getPixel(x, y);
18373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				tcu::RGBA	screenPixel		= screen.getPixel(x, y);
18383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				bool		isOkPixel		= false;
18393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1840545d74e83cff0800c8d65adf1812768745b7ec60Mika Isojärvi				if (y == 0 || y + 1 == ref.getHeight() || x == 0 || x + 1 == ref.getWidth())
1841545d74e83cff0800c8d65adf1812768745b7ec60Mika Isojärvi				{
1842545d74e83cff0800c8d65adf1812768745b7ec60Mika Isojärvi					// Don't check borders since the pixel neighborhood is undefined
1843545d74e83cff0800c8d65adf1812768745b7ec60Mika Isojärvi					error.setPixel(x, y, tcu::RGBA(screenPixel.getRed(), (screenPixel.getGreen() + 255) / 2, screenPixel.getBlue(), 255));
1844545d74e83cff0800c8d65adf1812768745b7ec60Mika Isojärvi					continue;
1845545d74e83cff0800c8d65adf1812768745b7ec60Mika Isojärvi				}
1846545d74e83cff0800c8d65adf1812768745b7ec60Mika Isojärvi
18473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				// Don't do comparisons for this pixel if it belongs to a one-pixel-thin part (i.e. it doesn't have similar-color neighbors in both x and y directions) in both result and reference.
18483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				// This fixes some false negatives.
18493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				bool		refThin			= (!tcu::compareThreshold(refPixel, ref.getPixel(x-1, y  ), threshold) && !tcu::compareThreshold(refPixel, ref.getPixel(x+1, y  ), threshold)) ||
18503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											  (!tcu::compareThreshold(refPixel, ref.getPixel(x  , y-1), threshold) && !tcu::compareThreshold(refPixel, ref.getPixel(x  , y+1), threshold));
18513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				bool		screenThin		= (!tcu::compareThreshold(screenPixel, screen.getPixel(x-1, y  ), threshold) && !tcu::compareThreshold(screenPixel, screen.getPixel(x+1, y  ), threshold)) ||
18523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											  (!tcu::compareThreshold(screenPixel, screen.getPixel(x  , y-1), threshold) && !tcu::compareThreshold(screenPixel, screen.getPixel(x  , y+1), threshold));
18533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (refThin && screenThin)
18553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					isOkPixel = true;
18563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				else
18573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
18583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					for (int dy = -1; dy < 2 && !isOkPixel; dy++)
18593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					{
18603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						for (int dx = -1; dx < 2 && !isOkPixel; dx++)
18613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						{
18623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							// Check reference pixel against screen pixel
18633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							{
18643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								tcu::RGBA	screenCmpPixel	= screen.getPixel(x+dx, y+dy);
1865c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry								deUint8		r				= (deUint8)deAbs32(refPixel.getRed()	- screenCmpPixel.getRed());
1866c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry								deUint8		g				= (deUint8)deAbs32(refPixel.getGreen()	- screenCmpPixel.getGreen());
1867c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry								deUint8		b				= (deUint8)deAbs32(refPixel.getBlue()	- screenCmpPixel.getBlue());
18683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								if (r <= m_maxDiffRed && g <= m_maxDiffGreen && b <= m_maxDiffBlue)
18703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									isOkPixel = true;
18713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							}
18723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							// Check screen pixels against reference pixel
18743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							{
18753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								tcu::RGBA	refCmpPixel		= ref.getPixel(x+dx, y+dy);
1876c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry								deUint8		r				= (deUint8)deAbs32(refCmpPixel.getRed()		- screenPixel.getRed());
1877c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry								deUint8		g				= (deUint8)deAbs32(refCmpPixel.getGreen()	- screenPixel.getGreen());
1878c8e526bfc2141e1cb7a269483fb55dc2a8e77c11Jarkko Pöyry								deUint8		b				= (deUint8)deAbs32(refCmpPixel.getBlue()	- screenPixel.getBlue());
18793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								if (r <= m_maxDiffRed && g <= m_maxDiffGreen && b <= m_maxDiffBlue)
18813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									isOkPixel = true;
18823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							}
18833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						}
18843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					}
18853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
18863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (isOkPixel)
18883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					error.setPixel(x, y, tcu::RGBA(screen.getPixel(x, y).getRed(), (screen.getPixel(x, y).getGreen() + 255) / 2, screen.getPixel(x, y).getBlue(), 255));
18893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				else
18903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
18913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					error.setPixel(x, y, tcu::RGBA(255, 0, 0, 255));
18923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					m_isOk = false;
18933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
18943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
18953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
18963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::TestLog& log = m_testCtx.getLog();
18983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (!m_isOk)
18993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
19003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			log << TestLog::Message << "Image comparison failed, threshold = (" << m_maxDiffRed << ", " << m_maxDiffGreen << ", " << m_maxDiffBlue << ")" << TestLog::EndMessage;
19013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			log << TestLog::ImageSet("Compare result", "Result of rendering")
19023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< TestLog::Image("Result",		"Result",		screen)
19033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< TestLog::Image("Reference",	"Reference",	ref)
19043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< TestLog::Image("ErrorMask",	"Error mask",	error)
19053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< TestLog::EndImageSet;
19063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
19073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
19083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
19093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			log << TestLog::ImageSet("Compare result", "Result of rendering")
19103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< TestLog::Image("Result", "Result", screen)
19113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< TestLog::EndImageSet;
19123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
19133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
19143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
19153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// MultiVertexArrayTest
19173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19183c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMultiVertexArrayTest::Spec::ArraySpec::ArraySpec(Array::InputType inputType_, Array::OutputType outputType_, Array::Storage storage_, Array::Usage usage_, int componentCount_, int offset_, int stride_, bool normalize_, GLValue min_, GLValue max_)
19193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: inputType		(inputType_)
19203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, outputType	(outputType_)
19213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, storage		(storage_)
19223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, usage			(usage_)
19233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, componentCount(componentCount_)
19243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, offset		(offset_)
19253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, stride		(stride_)
19263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, normalize		(normalize_)
19273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, min			(min_)
19283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, max			(max_)
19293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
19303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
19313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19323c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystd::string MultiVertexArrayTest::Spec::getName (void) const
19333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
19343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::stringstream name;
19353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (size_t ndx = 0; ndx < arrays.size(); ++ndx)
19373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
19383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const ArraySpec& array = arrays[ndx];
19393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (arrays.size() > 1)
19413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			name << "array" << ndx << "_";
19423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		name
19443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< Array::storageToString(array.storage) << "_"
19453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< array.offset << "_"
19463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< array.stride << "_"
19473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< Array::inputTypeToString((Array::InputType)array.inputType);
19483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (array.inputType != Array::INPUTTYPE_UNSIGNED_INT_2_10_10_10 && array.inputType != Array::INPUTTYPE_INT_2_10_10_10)
19493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			name << array.componentCount;
19503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		name
19513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< "_"
19523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (array.normalize ? "normalized_" : "")
19533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< Array::outputTypeToString(array.outputType) << "_"
19543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< Array::usageTypeToString(array.usage) << "_";
19553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
19563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (first)
19583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		name << "first" << first << "_";
19593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (primitive)
19613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
19623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::PRIMITIVE_TRIANGLES:
19633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			name << "quads_";
19643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
19653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::PRIMITIVE_POINTS:
19663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			name << "points_";
19673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
19683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
19703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
19713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
19723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
19733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	name << drawCount;
19753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return name.str();
19773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
19783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19793c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystd::string MultiVertexArrayTest::Spec::getDesc (void) const
19803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
19813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::stringstream desc;
19823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (size_t ndx = 0; ndx < arrays.size(); ++ndx)
19843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
19853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const ArraySpec& array = arrays[ndx];
19863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		desc
19883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< "Array " << ndx << ": "
19893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< "Storage in " << Array::storageToString(array.storage) << ", "
19903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< "stride " << array.stride << ", "
19913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< "input datatype " << Array::inputTypeToString((Array::InputType)array.inputType) << ", "
19923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< "input component count " << array.componentCount << ", "
19933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (array.normalize ? "normalized, " : "")
19943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< "used as " << Array::outputTypeToString(array.outputType) << ", ";
19953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
19963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	desc
19983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "drawArrays(), "
19993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "first " << first << ", "
20003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< drawCount;
20013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (primitive)
20033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
20043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::PRIMITIVE_TRIANGLES:
20053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			desc << "quads ";
20063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
20073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case Array::PRIMITIVE_POINTS:
20083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			desc << "points";
20093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
20103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
20123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
20133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
20143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
20153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return desc.str();
20183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
20193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20203c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMultiVertexArrayTest::MultiVertexArrayTest (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const Spec& spec, const char* name, const char* desc)
20213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: VertexArrayTest	(testCtx, renderCtx, name, desc)
20223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_spec			(spec)
20233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_iteration		(0)
20243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
20253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
20263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20273c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMultiVertexArrayTest::~MultiVertexArrayTest	(void)
20283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
20293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
20303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20313c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMultiVertexArrayTest::IterateResult MultiVertexArrayTest::iterate (void)
20323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
20333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_iteration == 0)
20343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
20353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const size_t	primitiveSize		= (m_spec.primitive == Array::PRIMITIVE_TRIANGLES) ? (6) : (1); // in non-indexed draw Triangles means rectangles
20363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		float			coordScale			= 1.0f;
20373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		float			colorScale			= 1.0f;
20383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const bool		useVao				= m_renderCtx.getType().getProfile() == glu::PROFILE_CORE;
20393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Log info
20413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << TestLog::Message << m_spec.getDesc() << TestLog::EndMessage;
20423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Color and Coord scale
20443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
20453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// First array is always position
20463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
20473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				Spec::ArraySpec arraySpec = m_spec.arrays[0];
20483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (arraySpec.inputType == Array::INPUTTYPE_UNSIGNED_INT_2_10_10_10)
20493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
20503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					if (arraySpec.normalize)
20513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						coordScale = 1.0f;
20523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					else
20533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						coordScale = 1.0 / 1024.0;
20543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
20553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				else if (arraySpec.inputType == Array::INPUTTYPE_INT_2_10_10_10)
20563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
20573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					if (arraySpec.normalize)
20583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						coordScale = 1.0f;
20593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					else
20603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						coordScale = 1.0 / 512.0;
20613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
20623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				else
20633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					coordScale = (arraySpec.normalize && !inputTypeIsFloatType(arraySpec.inputType) ? 1.0f : float(0.9 / double(arraySpec.max.toFloat())));
20643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (arraySpec.outputType == Array::OUTPUTTYPE_VEC3 || arraySpec.outputType == Array::OUTPUTTYPE_VEC4
20663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					|| arraySpec.outputType == Array::OUTPUTTYPE_IVEC3 || arraySpec.outputType == Array::OUTPUTTYPE_IVEC4
20673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					|| arraySpec.outputType == Array::OUTPUTTYPE_UVEC3 || arraySpec.outputType == Array::OUTPUTTYPE_UVEC4)
20683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						coordScale = coordScale * 0.5f;
20693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
20703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// And other arrays are color-like
20723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int arrayNdx = 1; arrayNdx < (int)m_spec.arrays.size(); arrayNdx++)
20733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
20743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				Spec::ArraySpec arraySpec	= m_spec.arrays[arrayNdx];
20753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				colorScale *= (arraySpec.normalize && !inputTypeIsFloatType(arraySpec.inputType) ? 1.0f : float(1.0 / double(arraySpec.max.toFloat())));
20773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (arraySpec.outputType == Array::OUTPUTTYPE_VEC4)
20783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					colorScale *= (arraySpec.normalize && !inputTypeIsFloatType(arraySpec.inputType) ? 1.0f : float(1.0 / double(arraySpec.max.toFloat())));
20793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
20803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
20813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Data
20833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int arrayNdx = 0; arrayNdx < (int)m_spec.arrays.size(); arrayNdx++)
20843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
20853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			Spec::ArraySpec arraySpec		= m_spec.arrays[arrayNdx];
20863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const int		seed			= int(arraySpec.inputType) + 10 * int(arraySpec.outputType) + 100 * int(arraySpec.storage) + 1000 * int(m_spec.primitive) + 10000 * int(arraySpec.usage) + int(m_spec.drawCount) + 12 * int(arraySpec.componentCount) + int(arraySpec.stride) + int(arraySpec.normalize);
20873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const char*		data			= DE_NULL;
20883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const size_t	stride			= (arraySpec.stride == 0) ? (arraySpec.componentCount * Array::inputTypeSize(arraySpec.inputType)) : (arraySpec.stride);
20893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const size_t	bufferSize		= arraySpec.offset + stride * (m_spec.drawCount * primitiveSize - 1) + arraySpec.componentCount  * Array::inputTypeSize(arraySpec.inputType);
20908ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi			// Snap values to at least 3x3 grid
20918ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi			const float		gridSize		= 3.0f / (float)(de::min(m_renderCtx.getRenderTarget().getWidth(), m_renderCtx.getRenderTarget().getHeight()) - 1);
20923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			switch (m_spec.primitive)
20943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
20953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	//			case Array::PRIMITIVE_POINTS:
20963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	//				data = RandomArrayGenerator::generateArray(seed, arraySpec.min, arraySpec.max, arraySpec.count, arraySpec.componentCount, arraySpec.stride, arraySpec.inputType);
20973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	//				break;
20983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case Array::PRIMITIVE_TRIANGLES:
20993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					if (arrayNdx == 0)
21003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					{
21018ed28c1e05f2325dc4b20c8f471067b29188c82fMika Isojärvi						data = RandomArrayGenerator::generateQuads(seed, m_spec.drawCount, arraySpec.componentCount, arraySpec.offset, arraySpec.stride, m_spec.primitive, arraySpec.inputType, arraySpec.min, arraySpec.max, gridSize);
21023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					}
21033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					else
21043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					{
21053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						DE_ASSERT(arraySpec.offset == 0); // \note [jarkko] it just hasn't been implemented
21063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						data = RandomArrayGenerator::generatePerQuad(seed, m_spec.drawCount, arraySpec.componentCount, arraySpec.stride, m_spec.primitive, arraySpec.inputType, arraySpec.min, arraySpec.max);
21073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					}
21083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					break;
21093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				default:
21113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					DE_ASSERT(false);
21123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					break;
21133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
21143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_glArrayPack->newArray(arraySpec.storage);
21163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_rrArrayPack->newArray(arraySpec.storage);
21173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_glArrayPack->getArray(arrayNdx)->data(Array::TARGET_ARRAY, (int)bufferSize, data, arraySpec.usage);
21193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_rrArrayPack->getArray(arrayNdx)->data(Array::TARGET_ARRAY, (int)bufferSize, data, arraySpec.usage);
21203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_glArrayPack->getArray(arrayNdx)->bind(arrayNdx, arraySpec.offset, arraySpec.componentCount, arraySpec.inputType, arraySpec.outputType, arraySpec.normalize, arraySpec.stride);
21223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_rrArrayPack->getArray(arrayNdx)->bind(arrayNdx, arraySpec.offset, arraySpec.componentCount, arraySpec.inputType, arraySpec.outputType, arraySpec.normalize, arraySpec.stride);
21233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			delete [] data;
21253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
21263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		try
21283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
21293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_glArrayPack->render(m_spec.primitive, m_spec.first, m_spec.drawCount * (int)primitiveSize, useVao, coordScale, colorScale);
21303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_rrArrayPack->render(m_spec.primitive, m_spec.first, m_spec.drawCount * (int)primitiveSize, useVao, coordScale, colorScale);
21313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
21323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		catch (glu::Error& err)
21333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
21343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// GL Errors are ok if the mode is not properly aligned
21353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.getLog() << TestLog::Message << "Got error: " << err.what() << TestLog::EndMessage;
21373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (isUnalignedBufferOffsetTest())
21393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_testCtx.setTestResult(QP_TEST_RESULT_COMPATIBILITY_WARNING, "Failed to draw with unaligned buffers.");
21403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else if (isUnalignedBufferStrideTest())
21413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_testCtx.setTestResult(QP_TEST_RESULT_COMPATIBILITY_WARNING, "Failed to draw with unaligned stride.");
21423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else
21433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				throw;
21443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return STOP;
21463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
21473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_iteration++;
21493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return CONTINUE;
21503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
21513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (m_iteration == 1)
21523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
21533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		compare();
21543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_isOk)
21563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
21573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
21583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
21593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
21603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
21613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (isUnalignedBufferOffsetTest())
21623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_testCtx.setTestResult(QP_TEST_RESULT_COMPATIBILITY_WARNING, "Failed to draw with unaligned buffers.");
21633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else if (isUnalignedBufferStrideTest())
21643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_testCtx.setTestResult(QP_TEST_RESULT_COMPATIBILITY_WARNING, "Failed to draw with unaligned stride.");
21653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else
21663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Image comparison failed.");
21673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
21683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_iteration++;
21703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return STOP;
21713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
21723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
21733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
21743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(false);
21753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return STOP;
21763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
21773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
21783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21793c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool MultiVertexArrayTest::isUnalignedBufferOffsetTest (void) const
21803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
21813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Buffer offsets should be data type size aligned
21823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (size_t i = 0; i < m_spec.arrays.size(); ++i)
21833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
21843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_spec.arrays[i].storage == Array::STORAGE_BUFFER)
21853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
21863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const bool inputTypePacked = m_spec.arrays[i].inputType == Array::INPUTTYPE_UNSIGNED_INT_2_10_10_10 || m_spec.arrays[i].inputType == Array::INPUTTYPE_INT_2_10_10_10;
21873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			int dataTypeSize = Array::inputTypeSize(m_spec.arrays[i].inputType);
21893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (inputTypePacked)
21903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				dataTypeSize = 4;
21913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (m_spec.arrays[i].offset % dataTypeSize != 0)
21933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				return true;
21943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
21953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
21963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return false;
21983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
21993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
22003c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool MultiVertexArrayTest::isUnalignedBufferStrideTest (void) const
22013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
22023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Buffer strides should be data type size aligned
22033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (size_t i = 0; i < m_spec.arrays.size(); ++i)
22043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
22053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_spec.arrays[i].storage == Array::STORAGE_BUFFER)
22063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
22073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const bool inputTypePacked = m_spec.arrays[i].inputType == Array::INPUTTYPE_UNSIGNED_INT_2_10_10_10 || m_spec.arrays[i].inputType == Array::INPUTTYPE_INT_2_10_10_10;
22083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
22093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			int dataTypeSize = Array::inputTypeSize(m_spec.arrays[i].inputType);
22103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (inputTypePacked)
22113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				dataTypeSize = 4;
22123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
22133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (m_spec.arrays[i].stride % dataTypeSize != 0)
22143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				return true;
22153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
22163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
22173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
22183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return false;
22193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
22203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
22213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gls
22223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp
2223