Home | History | Annotate | Download | only in referencerenderer
      1 #ifndef _RRVERTEXATTRIB_HPP
      2 #define _RRVERTEXATTRIB_HPP
      3 /*-------------------------------------------------------------------------
      4  * drawElements Quality Program Reference Renderer
      5  * -----------------------------------------------
      6  *
      7  * Copyright 2014 The Android Open Source Project
      8  *
      9  * Licensed under the Apache License, Version 2.0 (the "License");
     10  * you may not use this file except in compliance with the License.
     11  * You may obtain a copy of the License at
     12  *
     13  *      http://www.apache.org/licenses/LICENSE-2.0
     14  *
     15  * Unless required by applicable law or agreed to in writing, software
     16  * distributed under the License is distributed on an "AS IS" BASIS,
     17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     18  * See the License for the specific language governing permissions and
     19  * limitations under the License.
     20  *
     21  *//*!
     22  * \file
     23  * \brief Vertex attribute fetch.
     24  *//*--------------------------------------------------------------------*/
     25 
     26 #include "rrDefs.hpp"
     27 #include "rrGenericVector.hpp"
     28 #include "tcuVector.hpp"
     29 
     30 namespace rr
     31 {
     32 
     33 enum VertexAttribType
     34 {
     35 	// Can only be read as floats
     36 	VERTEXATTRIBTYPE_FLOAT = 0,
     37 	VERTEXATTRIBTYPE_HALF,
     38 	VERTEXATTRIBTYPE_FIXED,
     39 	VERTEXATTRIBTYPE_DOUBLE,
     40 
     41 	// Can only be read as floats, will be normalized
     42 	VERTEXATTRIBTYPE_NONPURE_UNORM8,
     43 	VERTEXATTRIBTYPE_NONPURE_UNORM16,
     44 	VERTEXATTRIBTYPE_NONPURE_UNORM32,
     45 	VERTEXATTRIBTYPE_NONPURE_UNORM_2_10_10_10_REV,			//!< Packed format, only size = 4 is allowed
     46 
     47 	// Clamped formats, GLES3-style conversion: max{c / (2^(b-1) - 1), -1 }
     48 	VERTEXATTRIBTYPE_NONPURE_SNORM8_CLAMP,
     49 	VERTEXATTRIBTYPE_NONPURE_SNORM16_CLAMP,
     50 	VERTEXATTRIBTYPE_NONPURE_SNORM32_CLAMP,
     51 	VERTEXATTRIBTYPE_NONPURE_SNORM_2_10_10_10_REV_CLAMP,	//!< Packed format, only size = 4 is allowed
     52 
     53 	// Scaled formats, GLES2-style conversion: (2c + 1) / (2^b - 1)
     54 	VERTEXATTRIBTYPE_NONPURE_SNORM8_SCALE,
     55 	VERTEXATTRIBTYPE_NONPURE_SNORM16_SCALE,
     56 	VERTEXATTRIBTYPE_NONPURE_SNORM32_SCALE,
     57 	VERTEXATTRIBTYPE_NONPURE_SNORM_2_10_10_10_REV_SCALE,	//!< Packed format, only size = 4 is allowed
     58 
     59 	// can only be read as float, will not be normalized
     60 	VERTEXATTRIBTYPE_NONPURE_UINT8,
     61 	VERTEXATTRIBTYPE_NONPURE_UINT16,
     62 	VERTEXATTRIBTYPE_NONPURE_UINT32,
     63 
     64 	VERTEXATTRIBTYPE_NONPURE_INT8,
     65 	VERTEXATTRIBTYPE_NONPURE_INT16,
     66 	VERTEXATTRIBTYPE_NONPURE_INT32,
     67 
     68 	VERTEXATTRIBTYPE_NONPURE_UINT_2_10_10_10_REV,	//!< Packed format, only size = 4 is allowed
     69 	VERTEXATTRIBTYPE_NONPURE_INT_2_10_10_10_REV,	//!< Packed format, only size = 4 is allowed
     70 
     71 	// can only be read as integers
     72 	VERTEXATTRIBTYPE_PURE_UINT8,
     73 	VERTEXATTRIBTYPE_PURE_UINT16,
     74 	VERTEXATTRIBTYPE_PURE_UINT32,
     75 
     76 	VERTEXATTRIBTYPE_PURE_INT8,
     77 	VERTEXATTRIBTYPE_PURE_INT16,
     78 	VERTEXATTRIBTYPE_PURE_INT32,
     79 
     80 	// reordered formats of GL_ARB_vertex_array_bgra
     81 	VERTEXATTRIBTYPE_NONPURE_UNORM8_BGRA,
     82 	VERTEXATTRIBTYPE_NONPURE_UNORM_2_10_10_10_REV_BGRA,
     83 	VERTEXATTRIBTYPE_NONPURE_SNORM_2_10_10_10_REV_CLAMP_BGRA,
     84 	VERTEXATTRIBTYPE_NONPURE_SNORM_2_10_10_10_REV_SCALE_BGRA,
     85 
     86 	// can be read as anything
     87 	VERTEXATTRIBTYPE_DONT_CARE,					//!< Do not enforce type checking when reading GENERIC attribute. Used for current client side attributes.
     88 
     89 	VERTEXATTRIBTYPE_LAST
     90 };
     91 
     92 /*--------------------------------------------------------------------*//*!
     93  * \brief Vertex attribute slot
     94  *
     95  * Vertex attribute type specifies component type for attribute and it
     96  * includes signed & normalized bits as well.
     97  *
     98  * Attribute size specifies how many components there are per vertex.
     99  * If size is 0, no components are fetched, ie. vertex attribute slot
    100  * is disabled.
    101  *
    102  * Divisor specifies the rate at which vertex attribute advances. If it is
    103  * zero, attribute is advanced per vertex. If divisor is non-zero, attribute
    104  * advances once per instanceDivisor instances.
    105  *
    106  * Pointer is used if not null, otherwise generic attribute is used instead
    107  * and in such case only DONT_CARE is valid attribute type.
    108  *//*--------------------------------------------------------------------*/
    109 struct VertexAttrib
    110 {
    111 	VertexAttribType	type;				//!< Attribute component type.
    112 	int					size;				//!< Number of components, valid range is [0,4].
    113 	int					stride;				//!< Number of bytes two consecutive elements differ by. Zero works as in GL. Valid range is [0, inf).
    114 	int					instanceDivisor;	//!< Vertex attribute divisor.
    115 	const void*			pointer;			//!< Data pointer.
    116 	GenericVec4			generic;			//!< Generic attribute, used if pointer is null.
    117 
    118 	VertexAttrib (void)
    119 		: type				(VERTEXATTRIBTYPE_FLOAT)
    120 		, size				(0)
    121 		, stride			(0)
    122 		, instanceDivisor	(0)
    123 		, pointer			(DE_NULL)
    124 	{
    125 	}
    126 
    127 	VertexAttrib (VertexAttribType type_, int size_, int stride_, int instanceDivisor_, const void* pointer_)
    128 		: type				(type_)
    129 		, size				(size_)
    130 		, stride			(stride_)
    131 		, instanceDivisor	(instanceDivisor_)
    132 		, pointer			(pointer_)
    133 	{
    134 	}
    135 
    136 	template<typename ScalarType>
    137 	explicit VertexAttrib (const tcu::Vector<ScalarType, 4>& generic_)
    138 		: type				(VERTEXATTRIBTYPE_DONT_CARE)
    139 		, size				(0)
    140 		, stride			(0)
    141 		, instanceDivisor	(0)
    142 		, pointer			(DE_NULL)
    143 		, generic			(generic_)
    144 	{
    145 	}
    146 } DE_WARN_UNUSED_TYPE;
    147 
    148 bool		isValidVertexAttrib		(const VertexAttrib& vertexAttrib);
    149 // \todo [2013-04-01 pyry] Queries: isReadFloatValid(), isReadIntValid() ...
    150 
    151 void		readVertexAttrib		(tcu::Vec4& dst, const VertexAttrib& vertexAttrib, const int instanceNdx, const int vertexNdx);
    152 void		readVertexAttrib		(tcu::IVec4& dst, const VertexAttrib& vertexAttrib, const int instanceNdx, const int vertexNdx);
    153 void		readVertexAttrib		(tcu::UVec4& dst, const VertexAttrib& vertexAttrib, const int instanceNdx, const int vertexNdx);
    154 
    155 // Helpers that return by value (trivial for compiler to optimize).
    156 
    157 inline tcu::Vec4 readVertexAttribFloat (const VertexAttrib& vertexAttrib, const int instanceNdx, const int vertexNdx)
    158 {
    159 	tcu::Vec4 v;
    160 	readVertexAttrib(v, vertexAttrib, instanceNdx, vertexNdx);
    161 	return v;
    162 }
    163 
    164 inline tcu::IVec4 readVertexAttribInt (const VertexAttrib& vertexAttrib, const int instanceNdx, const int vertexNdx)
    165 {
    166 	tcu::IVec4 v;
    167 	readVertexAttrib(v, vertexAttrib, instanceNdx, vertexNdx);
    168 	return v;
    169 }
    170 
    171 inline tcu::UVec4 readVertexAttribUint (const VertexAttrib& vertexAttrib, const int instanceNdx, const int vertexNdx)
    172 {
    173 	tcu::UVec4 v;
    174 	readVertexAttrib(v, vertexAttrib, instanceNdx, vertexNdx);
    175 	return v;
    176 }
    177 
    178 } // rr
    179 
    180 #endif // _RRVERTEXATTRIB_HPP
    181