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