• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _RRVERTEXPACKET_HPP
2 #define _RRVERTEXPACKET_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 packet and Vertex packet allocator
24  *//*--------------------------------------------------------------------*/
25 
26 #include "rrDefs.hpp"
27 #include "rrGenericVector.hpp"
28 #include "tcuVector.hpp"
29 
30 #include <vector>
31 
32 namespace rr
33 {
34 
35 class VertexPacketAllocator;
36 
37 /*--------------------------------------------------------------------*//*!
38  * \brief Vertex packet
39  *
40  * Vertex packet contains inputs and outputs for vertex shading.
41  *
42  * Inputs consist of per-vertex vertex and instance indices. Attribute
43  * list that can be accessed using those indices is provided as separate
44  * pointer for VS.
45  *
46  * Outputs include position, optional point size, and list of generic
47  * outputs that shader can write to. Number of VS outputs is specified
48  * in ProgramInfo.
49  *
50  * VertexPacket instance must be created by VertexPacketAllocator as
51  * outputs must be allocated memory after the instance.
52  *//*--------------------------------------------------------------------*/
53 struct VertexPacket
54 {
55 	// Inputs.
56 	int				instanceNdx;	//!< Instance index.
57 	int				vertexNdx;		//!< Vertex index.
58 
59 	// Outputs.
60 	tcu::Vec4		position;		//!< Transformed position - must be written always.
61 	float			pointSize;		//!< Point size, required when rendering points.
62 	int				primitiveID;	//!< Geometry shader output
63 
64 	GenericVec4		outputs[1];		//!< Generic vertex shader outputs - passed to subsequent shader stages. Array length is the number of outputs.
65 	// --- DO NOT ADD ANY MEMBER VARIABLES AFTER OUTPUTS, OUTPUTS IS VARIABLE-SIZED --- //
66 
67 private:
68 	// Allow creation and destruction only for Allocator
69 					VertexPacket	(void);
70 					VertexPacket	(const VertexPacket&);  // disabled, non-copyable
71 					~VertexPacket	(void);
72 
73 	// Assignment cannot work without knowing the output array length => prevent assignment
74 	VertexPacket&	operator=		(const VertexPacket&);  // disabled, non-copyable
75 
76 
77 	friend class VertexPacketAllocator;
78 } DE_WARN_UNUSED_TYPE;
79 
80 
81 /*--------------------------------------------------------------------*//*!
82  * \brief Vertex packet allocator
83  *
84  * Allocates vertex packets.
85  *
86  * Vertex packet must have enough space allocated for its outputs.
87  *
88  * All memory allocated for vertex packets is released when VertexPacketAllocator
89  * is destroyed. Allocated vertex packets should not be accessed after
90  * allocator is destroyed.
91  *
92  * alloc and allocArray will throw bad_alloc if allocation fails.
93  *//*--------------------------------------------------------------------*/
94 class VertexPacketAllocator
95 {
96 public:
97 								VertexPacketAllocator	(const size_t numberOfVertexOutputs);
98 								~VertexPacketAllocator	(void);
99 
100 	std::vector<VertexPacket*>	allocArray				(size_t count); // throws bad_alloc
101 	VertexPacket*				alloc					(void);			// throws bad_alloc
102 
getNumVertexOutputs(void) const103 	inline size_t				getNumVertexOutputs		(void) const	{ return m_numberOfVertexOutputs; }
104 
105 private:
106 								VertexPacketAllocator	(const VertexPacketAllocator&); // disabled, non-copyable
107 	VertexPacketAllocator&		operator=				(const VertexPacketAllocator&); // disabled, non-copyable
108 
109 	const size_t				m_numberOfVertexOutputs;
110 	std::vector<deInt8*>		m_allocations;
111 	std::vector<VertexPacket*>	m_singleAllocPool;
112 } DE_WARN_UNUSED_TYPE;
113 
114 } // rr
115 
116 #endif // _RRVERTEXPACKET_HPP
117