1*35238bceSAndroid Build Coastguard Worker #ifndef _RRRENDERER_HPP 2*35238bceSAndroid Build Coastguard Worker #define _RRRENDERER_HPP 3*35238bceSAndroid Build Coastguard Worker /*------------------------------------------------------------------------- 4*35238bceSAndroid Build Coastguard Worker * drawElements Quality Program Reference Renderer 5*35238bceSAndroid Build Coastguard Worker * ----------------------------------------------- 6*35238bceSAndroid Build Coastguard Worker * 7*35238bceSAndroid Build Coastguard Worker * Copyright 2014 The Android Open Source Project 8*35238bceSAndroid Build Coastguard Worker * 9*35238bceSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 10*35238bceSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 11*35238bceSAndroid Build Coastguard Worker * You may obtain a copy of the License at 12*35238bceSAndroid Build Coastguard Worker * 13*35238bceSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 14*35238bceSAndroid Build Coastguard Worker * 15*35238bceSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 16*35238bceSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 17*35238bceSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18*35238bceSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 19*35238bceSAndroid Build Coastguard Worker * limitations under the License. 20*35238bceSAndroid Build Coastguard Worker * 21*35238bceSAndroid Build Coastguard Worker *//*! 22*35238bceSAndroid Build Coastguard Worker * \file 23*35238bceSAndroid Build Coastguard Worker * \brief Reference renderer interface. 24*35238bceSAndroid Build Coastguard Worker *//*--------------------------------------------------------------------*/ 25*35238bceSAndroid Build Coastguard Worker 26*35238bceSAndroid Build Coastguard Worker #include "rrDefs.hpp" 27*35238bceSAndroid Build Coastguard Worker #include "rrShaders.hpp" 28*35238bceSAndroid Build Coastguard Worker #include "rrRenderState.hpp" 29*35238bceSAndroid Build Coastguard Worker #include "rrPrimitiveTypes.hpp" 30*35238bceSAndroid Build Coastguard Worker #include "rrMultisamplePixelBufferAccess.hpp" 31*35238bceSAndroid Build Coastguard Worker #include "tcuTexture.hpp" 32*35238bceSAndroid Build Coastguard Worker 33*35238bceSAndroid Build Coastguard Worker namespace rr 34*35238bceSAndroid Build Coastguard Worker { 35*35238bceSAndroid Build Coastguard Worker 36*35238bceSAndroid Build Coastguard Worker class RenderTarget 37*35238bceSAndroid Build Coastguard Worker { 38*35238bceSAndroid Build Coastguard Worker public: 39*35238bceSAndroid Build Coastguard Worker enum 40*35238bceSAndroid Build Coastguard Worker { 41*35238bceSAndroid Build Coastguard Worker MAX_COLOR_BUFFERS = 4 42*35238bceSAndroid Build Coastguard Worker }; 43*35238bceSAndroid Build Coastguard Worker 44*35238bceSAndroid Build Coastguard Worker RenderTarget(const MultisamplePixelBufferAccess &colorMultisampleBuffer, 45*35238bceSAndroid Build Coastguard Worker const MultisamplePixelBufferAccess &depthMultisampleBuffer = MultisamplePixelBufferAccess(), 46*35238bceSAndroid Build Coastguard Worker const MultisamplePixelBufferAccess &stencilMultisampleBuffer = MultisamplePixelBufferAccess()); 47*35238bceSAndroid Build Coastguard Worker 48*35238bceSAndroid Build Coastguard Worker int getNumSamples(void) const; 49*35238bceSAndroid Build Coastguard Worker getColorBuffer(int ndx) const50*35238bceSAndroid Build Coastguard Worker const MultisamplePixelBufferAccess &getColorBuffer(int ndx) const 51*35238bceSAndroid Build Coastguard Worker { 52*35238bceSAndroid Build Coastguard Worker DE_ASSERT(de::inRange(ndx, 0, m_numColorBuffers)); 53*35238bceSAndroid Build Coastguard Worker return m_colorBuffers[ndx]; 54*35238bceSAndroid Build Coastguard Worker } getNumColorBuffers(void) const55*35238bceSAndroid Build Coastguard Worker int getNumColorBuffers(void) const 56*35238bceSAndroid Build Coastguard Worker { 57*35238bceSAndroid Build Coastguard Worker return m_numColorBuffers; 58*35238bceSAndroid Build Coastguard Worker } getStencilBuffer(void) const59*35238bceSAndroid Build Coastguard Worker const MultisamplePixelBufferAccess &getStencilBuffer(void) const 60*35238bceSAndroid Build Coastguard Worker { 61*35238bceSAndroid Build Coastguard Worker return m_stencilBuffer; 62*35238bceSAndroid Build Coastguard Worker } getDepthBuffer(void) const63*35238bceSAndroid Build Coastguard Worker const MultisamplePixelBufferAccess &getDepthBuffer(void) const 64*35238bceSAndroid Build Coastguard Worker { 65*35238bceSAndroid Build Coastguard Worker return m_depthBuffer; 66*35238bceSAndroid Build Coastguard Worker } 67*35238bceSAndroid Build Coastguard Worker 68*35238bceSAndroid Build Coastguard Worker private: 69*35238bceSAndroid Build Coastguard Worker MultisamplePixelBufferAccess m_colorBuffers[MAX_COLOR_BUFFERS]; 70*35238bceSAndroid Build Coastguard Worker const int m_numColorBuffers; 71*35238bceSAndroid Build Coastguard Worker const MultisamplePixelBufferAccess m_depthBuffer; 72*35238bceSAndroid Build Coastguard Worker const MultisamplePixelBufferAccess m_stencilBuffer; 73*35238bceSAndroid Build Coastguard Worker } DE_WARN_UNUSED_TYPE; 74*35238bceSAndroid Build Coastguard Worker 75*35238bceSAndroid Build Coastguard Worker struct Program 76*35238bceSAndroid Build Coastguard Worker { Programrr::Program77*35238bceSAndroid Build Coastguard Worker Program(const VertexShader *vertexShader_, const FragmentShader *fragmentShader_, 78*35238bceSAndroid Build Coastguard Worker const GeometryShader *geometryShader_ = DE_NULL) 79*35238bceSAndroid Build Coastguard Worker : vertexShader(vertexShader_) 80*35238bceSAndroid Build Coastguard Worker , fragmentShader(fragmentShader_) 81*35238bceSAndroid Build Coastguard Worker , geometryShader(geometryShader_) 82*35238bceSAndroid Build Coastguard Worker { 83*35238bceSAndroid Build Coastguard Worker } 84*35238bceSAndroid Build Coastguard Worker 85*35238bceSAndroid Build Coastguard Worker const VertexShader *vertexShader; 86*35238bceSAndroid Build Coastguard Worker const FragmentShader *fragmentShader; 87*35238bceSAndroid Build Coastguard Worker const GeometryShader *geometryShader; 88*35238bceSAndroid Build Coastguard Worker } DE_WARN_UNUSED_TYPE; 89*35238bceSAndroid Build Coastguard Worker 90*35238bceSAndroid Build Coastguard Worker struct DrawIndices 91*35238bceSAndroid Build Coastguard Worker { 92*35238bceSAndroid Build Coastguard Worker DrawIndices(const uint32_t *, int baseVertex = 0); 93*35238bceSAndroid Build Coastguard Worker DrawIndices(const uint16_t *, int baseVertex = 0); 94*35238bceSAndroid Build Coastguard Worker DrawIndices(const uint8_t *, int baseVertex = 0); 95*35238bceSAndroid Build Coastguard Worker DrawIndices(const void *ptr, IndexType type, int baseVertex = 0); 96*35238bceSAndroid Build Coastguard Worker 97*35238bceSAndroid Build Coastguard Worker const void *const indices; 98*35238bceSAndroid Build Coastguard Worker const IndexType indexType; 99*35238bceSAndroid Build Coastguard Worker const int baseVertex; 100*35238bceSAndroid Build Coastguard Worker } DE_WARN_UNUSED_TYPE; 101*35238bceSAndroid Build Coastguard Worker 102*35238bceSAndroid Build Coastguard Worker class PrimitiveList 103*35238bceSAndroid Build Coastguard Worker { 104*35238bceSAndroid Build Coastguard Worker public: 105*35238bceSAndroid Build Coastguard Worker PrimitiveList(PrimitiveType primitiveType, int numElements, 106*35238bceSAndroid Build Coastguard Worker const int firstElement); // !< primitive list for drawArrays-like call 107*35238bceSAndroid Build Coastguard Worker PrimitiveList(PrimitiveType primitiveType, int numElements, 108*35238bceSAndroid Build Coastguard Worker const DrawIndices &indices); // !< primitive list for drawElements-like call 109*35238bceSAndroid Build Coastguard Worker 110*35238bceSAndroid Build Coastguard Worker size_t getIndex(size_t elementNdx) const; 111*35238bceSAndroid Build Coastguard Worker bool isRestartIndex(size_t elementNdx, uint32_t restartIndex) const; 112*35238bceSAndroid Build Coastguard Worker getNumElements(void) const113*35238bceSAndroid Build Coastguard Worker inline size_t getNumElements(void) const 114*35238bceSAndroid Build Coastguard Worker { 115*35238bceSAndroid Build Coastguard Worker return m_numElements; 116*35238bceSAndroid Build Coastguard Worker } getPrimitiveType(void) const117*35238bceSAndroid Build Coastguard Worker inline PrimitiveType getPrimitiveType(void) const 118*35238bceSAndroid Build Coastguard Worker { 119*35238bceSAndroid Build Coastguard Worker return m_primitiveType; 120*35238bceSAndroid Build Coastguard Worker } getIndexType(void) const121*35238bceSAndroid Build Coastguard Worker inline IndexType getIndexType(void) const 122*35238bceSAndroid Build Coastguard Worker { 123*35238bceSAndroid Build Coastguard Worker return m_indexType; 124*35238bceSAndroid Build Coastguard Worker } 125*35238bceSAndroid Build Coastguard Worker 126*35238bceSAndroid Build Coastguard Worker private: 127*35238bceSAndroid Build Coastguard Worker const PrimitiveType m_primitiveType; 128*35238bceSAndroid Build Coastguard Worker const size_t m_numElements; 129*35238bceSAndroid Build Coastguard Worker const void *const 130*35238bceSAndroid Build Coastguard Worker m_indices; // !< if indices is NULL, indices is interpreted as [first (== baseVertex) + 0, first + 1, first + 2, ...] 131*35238bceSAndroid Build Coastguard Worker const IndexType m_indexType; 132*35238bceSAndroid Build Coastguard Worker const int m_baseVertex; 133*35238bceSAndroid Build Coastguard Worker }; 134*35238bceSAndroid Build Coastguard Worker 135*35238bceSAndroid Build Coastguard Worker class DrawCommand 136*35238bceSAndroid Build Coastguard Worker { 137*35238bceSAndroid Build Coastguard Worker public: DrawCommand(const RenderState & state_,const RenderTarget & renderTarget_,const Program & program_,int numVertexAttribs_,const VertexAttrib * vertexAttribs_,const PrimitiveList & primitives_)138*35238bceSAndroid Build Coastguard Worker DrawCommand(const RenderState &state_, const RenderTarget &renderTarget_, const Program &program_, 139*35238bceSAndroid Build Coastguard Worker int numVertexAttribs_, const VertexAttrib *vertexAttribs_, const PrimitiveList &primitives_) 140*35238bceSAndroid Build Coastguard Worker : state(state_) 141*35238bceSAndroid Build Coastguard Worker , renderTarget(renderTarget_) 142*35238bceSAndroid Build Coastguard Worker , program(program_) 143*35238bceSAndroid Build Coastguard Worker , numVertexAttribs(numVertexAttribs_) 144*35238bceSAndroid Build Coastguard Worker , vertexAttribs(vertexAttribs_) 145*35238bceSAndroid Build Coastguard Worker , primitives(primitives_) 146*35238bceSAndroid Build Coastguard Worker { 147*35238bceSAndroid Build Coastguard Worker } 148*35238bceSAndroid Build Coastguard Worker 149*35238bceSAndroid Build Coastguard Worker const RenderState &state; 150*35238bceSAndroid Build Coastguard Worker const RenderTarget &renderTarget; 151*35238bceSAndroid Build Coastguard Worker const Program &program; 152*35238bceSAndroid Build Coastguard Worker 153*35238bceSAndroid Build Coastguard Worker const int numVertexAttribs; 154*35238bceSAndroid Build Coastguard Worker const VertexAttrib *const vertexAttribs; 155*35238bceSAndroid Build Coastguard Worker 156*35238bceSAndroid Build Coastguard Worker const PrimitiveList &primitives; 157*35238bceSAndroid Build Coastguard Worker } DE_WARN_UNUSED_TYPE; 158*35238bceSAndroid Build Coastguard Worker 159*35238bceSAndroid Build Coastguard Worker class Renderer 160*35238bceSAndroid Build Coastguard Worker { 161*35238bceSAndroid Build Coastguard Worker public: 162*35238bceSAndroid Build Coastguard Worker Renderer(void); 163*35238bceSAndroid Build Coastguard Worker ~Renderer(void); 164*35238bceSAndroid Build Coastguard Worker 165*35238bceSAndroid Build Coastguard Worker void draw(const DrawCommand &command) const; 166*35238bceSAndroid Build Coastguard Worker void drawInstanced(const DrawCommand &command, int numInstances) const; 167*35238bceSAndroid Build Coastguard Worker } DE_WARN_UNUSED_TYPE; 168*35238bceSAndroid Build Coastguard Worker 169*35238bceSAndroid Build Coastguard Worker } // namespace rr 170*35238bceSAndroid Build Coastguard Worker 171*35238bceSAndroid Build Coastguard Worker #endif // _RRRENDERER_HPP 172