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 65 [1]; //!< Generic vertex shader outputs - passed to subsequent shader stages. Array length is the number of outputs. 66 // --- DO NOT ADD ANY MEMBER VARIABLES AFTER OUTPUTS, OUTPUTS IS VARIABLE-SIZED --- // 67 68 private: 69 // Allow creation and destruction only for Allocator 70 VertexPacket(void); 71 VertexPacket(const VertexPacket &); // disabled, non-copyable 72 ~VertexPacket(void); 73 74 // Assignment cannot work without knowing the output array length => prevent assignment 75 VertexPacket &operator=(const VertexPacket &); // disabled, non-copyable 76 77 friend class VertexPacketAllocator; 78 } DE_WARN_UNUSED_TYPE; 79 80 /*--------------------------------------------------------------------*//*! 81 * \brief Vertex packet allocator 82 * 83 * Allocates vertex packets. 84 * 85 * Vertex packet must have enough space allocated for its outputs. 86 * 87 * All memory allocated for vertex packets is released when VertexPacketAllocator 88 * is destroyed. Allocated vertex packets should not be accessed after 89 * allocator is destroyed. 90 * 91 * alloc and allocArray will throw bad_alloc if allocation fails. 92 *//*--------------------------------------------------------------------*/ 93 class VertexPacketAllocator 94 { 95 public: 96 VertexPacketAllocator(const size_t numberOfVertexOutputs); 97 ~VertexPacketAllocator(void); 98 99 std::vector<VertexPacket *> allocArray(size_t count); // throws bad_alloc 100 VertexPacket *alloc(void); // throws bad_alloc 101 getNumVertexOutputs(void) const102 inline size_t getNumVertexOutputs(void) const 103 { 104 return m_numberOfVertexOutputs; 105 } 106 107 private: 108 VertexPacketAllocator(const VertexPacketAllocator &); // disabled, non-copyable 109 VertexPacketAllocator &operator=(const VertexPacketAllocator &); // disabled, non-copyable 110 111 const size_t m_numberOfVertexOutputs; 112 std::vector<int8_t *> m_allocations; 113 std::vector<VertexPacket *> m_singleAllocPool; 114 } DE_WARN_UNUSED_TYPE; 115 116 } // namespace rr 117 118 #endif // _RRVERTEXPACKET_HPP 119