1 #ifndef _RRRENDERER_HPP 2 #define _RRRENDERER_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 Reference renderer interface. 24 *//*--------------------------------------------------------------------*/ 25 26 #include "rrDefs.hpp" 27 #include "rrShaders.hpp" 28 #include "rrRenderState.hpp" 29 #include "rrPrimitiveTypes.hpp" 30 #include "rrMultisamplePixelBufferAccess.hpp" 31 #include "tcuTexture.hpp" 32 33 namespace rr 34 { 35 36 class RenderTarget 37 { 38 public: 39 enum 40 { 41 MAX_COLOR_BUFFERS = 4 42 }; 43 RenderTarget(const MultisamplePixelBufferAccess & colorMultisampleBuffer,const MultisamplePixelBufferAccess & depthMultisampleBuffer=MultisamplePixelBufferAccess (),const MultisamplePixelBufferAccess & stencilMultisampleBuffer=MultisamplePixelBufferAccess ())44 RenderTarget (const MultisamplePixelBufferAccess& colorMultisampleBuffer, 45 const MultisamplePixelBufferAccess& depthMultisampleBuffer = MultisamplePixelBufferAccess(), 46 const MultisamplePixelBufferAccess& stencilMultisampleBuffer = MultisamplePixelBufferAccess()) 47 : numColorBuffers (1) 48 , depthBuffer (depthMultisampleBuffer) 49 , stencilBuffer (stencilMultisampleBuffer) 50 { 51 colorBuffers[0] = colorMultisampleBuffer; 52 } 53 54 MultisamplePixelBufferAccess colorBuffers[MAX_COLOR_BUFFERS]; 55 const int numColorBuffers; 56 const MultisamplePixelBufferAccess depthBuffer; 57 const MultisamplePixelBufferAccess stencilBuffer; 58 }; 59 60 struct Program 61 { Programrr::Program62 Program (const VertexShader* vertexShader_, const FragmentShader* fragmentShader_, const GeometryShader* geometryShader_ = DE_NULL) 63 : vertexShader (vertexShader_) 64 , fragmentShader (fragmentShader_) 65 , geometryShader (geometryShader_) 66 { 67 } 68 69 const VertexShader* vertexShader; 70 const FragmentShader* fragmentShader; 71 const GeometryShader* geometryShader; 72 }; 73 74 struct DrawIndices 75 { 76 DrawIndices (const deUint32*, int baseVertex = 0); 77 DrawIndices (const deUint16*, int baseVertex = 0); 78 DrawIndices (const deUint8*, int baseVertex = 0); 79 DrawIndices (const void* ptr, IndexType type, int baseVertex = 0); 80 81 const void* const indices; 82 const IndexType indexType; 83 const int baseVertex; 84 }; 85 86 class PrimitiveList 87 { 88 public: 89 PrimitiveList (PrimitiveType primitiveType, int numElements, const int firstElement); // !< primitive list for drawArrays-like call 90 PrimitiveList (PrimitiveType primitiveType, int numElements, const DrawIndices& indices); // !< primitive list for drawElements-like call 91 92 size_t getIndex (size_t elementNdx) const; 93 bool isRestartIndex (size_t elementNdx, deUint32 restartIndex) const; 94 getNumElements(void) const95 inline size_t getNumElements (void) const { return m_numElements; } getPrimitiveType(void) const96 inline PrimitiveType getPrimitiveType (void) const { return m_primitiveType; } getIndexType(void) const97 inline IndexType getIndexType (void) const { return m_indexType; } 98 99 private: 100 const PrimitiveType m_primitiveType; 101 const size_t m_numElements; 102 const void* const m_indices; // !< if indices is NULL, indices is interpreted as [first (== baseVertex) + 0, first + 1, first + 2, ...] 103 const IndexType m_indexType; 104 const int m_baseVertex; 105 }; 106 107 class DrawCommand 108 { 109 public: DrawCommand(const RenderState & state_,const RenderTarget & renderTarget_,const Program & program_,int numVertexAttribs_,const VertexAttrib * vertexAttribs_,const PrimitiveList & primitives_)110 DrawCommand (const RenderState& state_, const RenderTarget& renderTarget_, const Program& program_, int numVertexAttribs_, const VertexAttrib* vertexAttribs_, const PrimitiveList& primitives_) 111 : state (state_) 112 , renderTarget (renderTarget_) 113 , program (program_) 114 , numVertexAttribs (numVertexAttribs_) 115 , vertexAttribs (vertexAttribs_) 116 , primitives (primitives_) 117 { 118 } 119 120 const RenderState& state; 121 const RenderTarget& renderTarget; 122 const Program& program; 123 124 const int numVertexAttribs; 125 const VertexAttrib* const vertexAttribs; 126 127 const PrimitiveList& primitives; 128 }; 129 130 class Renderer 131 { 132 public: 133 Renderer (void); 134 ~Renderer (void); 135 136 void draw (const DrawCommand& command) const; 137 void drawInstanced (const DrawCommand& command, int numInstances) const; 138 }; 139 140 } // rr 141 142 #endif // _RRRENDERER_HPP 143