13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#ifndef _RRVERTEXATTRIB_HPP
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define _RRVERTEXATTRIB_HPP
33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*-------------------------------------------------------------------------
43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program Reference Renderer
53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * -----------------------------------------------
63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project
83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License");
103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License.
113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at
123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *      http://www.apache.org/licenses/LICENSE-2.0
143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software
163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS,
173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and
193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License.
203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*!
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Vertex attribute fetch.
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "rrDefs.hpp"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "rrGenericVector.hpp"
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuVector.hpp"
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace rr
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum VertexAttribType
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Can only be read as floats
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_FLOAT = 0,
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_HALF,
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_FIXED,
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_DOUBLE,
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Can only be read as floats, will be normalized
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_NONPURE_UNORM8,
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_NONPURE_UNORM16,
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_NONPURE_UNORM32,
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_NONPURE_UNORM_2_10_10_10_REV,			//!< Packed format, only size = 4 is allowed
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Clamped formats, GLES3-style conversion: max{c / (2^(b-1) - 1), -1 }
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_NONPURE_SNORM8_CLAMP,
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_NONPURE_SNORM16_CLAMP,
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_NONPURE_SNORM32_CLAMP,
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_NONPURE_SNORM_2_10_10_10_REV_CLAMP,	//!< Packed format, only size = 4 is allowed
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Scaled formats, GLES2-style conversion: (2c + 1) / (2^b - 1)
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_NONPURE_SNORM8_SCALE,
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_NONPURE_SNORM16_SCALE,
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_NONPURE_SNORM32_SCALE,
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_NONPURE_SNORM_2_10_10_10_REV_SCALE,	//!< Packed format, only size = 4 is allowed
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// can only be read as float, will not be normalized
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_NONPURE_UINT8,
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_NONPURE_UINT16,
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_NONPURE_UINT32,
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_NONPURE_INT8,
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_NONPURE_INT16,
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_NONPURE_INT32,
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_NONPURE_UINT_2_10_10_10_REV,	//!< Packed format, only size = 4 is allowed
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_NONPURE_INT_2_10_10_10_REV,	//!< Packed format, only size = 4 is allowed
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// can only be read as integers
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_PURE_UINT8,
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_PURE_UINT16,
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_PURE_UINT32,
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_PURE_INT8,
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_PURE_INT16,
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_PURE_INT32,
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// reordered formats of GL_ARB_vertex_array_bgra
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_NONPURE_UNORM8_BGRA,
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_NONPURE_UNORM_2_10_10_10_REV_BGRA,
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_NONPURE_SNORM_2_10_10_10_REV_CLAMP_BGRA,
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_NONPURE_SNORM_2_10_10_10_REV_SCALE_BGRA,
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// can be read as anything
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_DONT_CARE,					//!< Do not enforce type checking when reading GENERIC attribute. Used for current client side attributes.
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VERTEXATTRIBTYPE_LAST
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*!
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Vertex attribute slot
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Vertex attribute type specifies component type for attribute and it
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * includes signed & normalized bits as well.
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Attribute size specifies how many components there are per vertex.
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * If size is 0, no components are fetched, ie. vertex attribute slot
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * is disabled.
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Divisor specifies the rate at which vertex attribute advances. If it is
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * zero, attribute is advanced per vertex. If divisor is non-zero, attribute
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * advances once per instanceDivisor instances.
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Pointer is used if not null, otherwise generic attribute is used instead
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * and in such case only DONT_CARE is valid attribute type.
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct VertexAttrib
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VertexAttribType	type;				//!< Attribute component type.
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					size;				//!< Number of components, valid range is [0,4].
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					stride;				//!< Number of bytes two consecutive elements differ by. Zero works as in GL. Valid range is [0, inf).
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					instanceDivisor;	//!< Vertex attribute divisor.
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const void*			pointer;			//!< Data pointer.
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GenericVec4			generic;			//!< Generic attribute, used if pointer is null.
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VertexAttrib (void)
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: type				(VERTEXATTRIBTYPE_FLOAT)
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, size				(0)
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, stride			(0)
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, instanceDivisor	(0)
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, pointer			(DE_NULL)
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool		isValidVertexAttrib		(const VertexAttrib& vertexAttrib);
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// \todo [2013-04-01 pyry] Queries: isReadFloatValid(), isReadIntValid() ...
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid		readVertexAttrib		(tcu::Vec4& dst, const VertexAttrib& vertexAttrib, const int instanceNdx, const int vertexNdx);
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid		readVertexAttrib		(tcu::IVec4& dst, const VertexAttrib& vertexAttrib, const int instanceNdx, const int vertexNdx);
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid		readVertexAttrib		(tcu::UVec4& dst, const VertexAttrib& vertexAttrib, const int instanceNdx, const int vertexNdx);
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Helpers that return by value (trivial for compiler to optimize).
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline tcu::Vec4 readVertexAttribFloat (const VertexAttrib& vertexAttrib, const int instanceNdx, const int vertexNdx)
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Vec4 v;
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	readVertexAttrib(v, vertexAttrib, instanceNdx, vertexNdx);
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return v;
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline tcu::IVec4 readVertexAttribInt (const VertexAttrib& vertexAttrib, const int instanceNdx, const int vertexNdx)
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::IVec4 v;
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	readVertexAttrib(v, vertexAttrib, instanceNdx, vertexNdx);
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return v;
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline tcu::UVec4 readVertexAttribUint (const VertexAttrib& vertexAttrib, const int instanceNdx, const int vertexNdx)
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::UVec4 v;
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	readVertexAttrib(v, vertexAttrib, instanceNdx, vertexNdx);
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return v;
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // rr
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif // _RRVERTEXATTRIB_HPP
161