1 #ifndef _GLSFRAGMENTOPUTIL_HPP 2 #define _GLSFRAGMENTOPUTIL_HPP 3 /*------------------------------------------------------------------------- 4 * drawElements Quality Program OpenGL (ES) Module 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 Fragment operation test utilities. 24 *//*--------------------------------------------------------------------*/ 25 26 #include "tcuDefs.hpp" 27 #include "gluShaderUtil.hpp" 28 #include "tcuVector.hpp" 29 #include "tcuTexture.hpp" 30 #include "rrFragmentOperations.hpp" 31 32 namespace glu 33 { 34 class ShaderProgram; 35 class RenderContext; 36 } // namespace glu 37 38 namespace deqp 39 { 40 namespace gls 41 { 42 namespace FragmentOpUtil 43 { 44 45 struct Quad 46 { 47 tcu::Vec2 posA; 48 tcu::Vec2 posB; 49 50 // Normalized device coordinates (range [-1, 1]). 51 // In order (A.x, A.y), (A.x, B.y), (B.x, A.y), (B.x, B.y) 52 tcu::Vec4 color[4]; 53 tcu::Vec4 color1[4]; 54 float depth[4]; 55 Quaddeqp::gls::FragmentOpUtil::Quad56 Quad(void) : posA(-1.0f, -1.0f), posB(1.0f, 1.0f) 57 { 58 for (int i = 0; i < DE_LENGTH_OF_ARRAY(depth); i++) 59 depth[i] = 0.0f; 60 } 61 }; 62 63 class QuadRenderer 64 { 65 public: 66 QuadRenderer(const glu::RenderContext &context, glu::GLSLVersion glslVersion); 67 ~QuadRenderer(void); 68 69 void render(const Quad &quad) const; 70 71 private: 72 QuadRenderer(const QuadRenderer &other); // Not allowed! 73 QuadRenderer &operator=(const QuadRenderer &other); // Not allowed! 74 75 const glu::RenderContext &m_context; 76 glu::ShaderProgram *m_program; 77 int m_positionLoc; 78 int m_colorLoc; 79 int m_color1Loc; 80 const bool m_blendFuncExt; 81 }; 82 83 struct IntegerQuad 84 { 85 tcu::IVec2 posA; 86 tcu::IVec2 posB; 87 88 // Viewport coordinates (depth in range [0, 1]). 89 // In order (A.x, A.y), (A.x, B.y), (B.x, A.y), (B.x, B.y) 90 tcu::Vec4 color[4]; 91 tcu::Vec4 color1[4]; 92 float depth[4]; 93 IntegerQuaddeqp::gls::FragmentOpUtil::IntegerQuad94 IntegerQuad(int windowWidth, int windowHeight) : posA(0, 0), posB(windowWidth - 1, windowHeight - 1) 95 { 96 for (int i = 0; i < DE_LENGTH_OF_ARRAY(depth); i++) 97 depth[i] = 0.0f; 98 } 99 IntegerQuaddeqp::gls::FragmentOpUtil::IntegerQuad100 IntegerQuad(void) : posA(0, 0), posB(1, 1) 101 { 102 for (int i = 0; i < DE_LENGTH_OF_ARRAY(depth); i++) 103 depth[i] = 0.0f; 104 } 105 }; 106 107 class ReferenceQuadRenderer 108 { 109 public: 110 ReferenceQuadRenderer(void); 111 112 void render(const tcu::PixelBufferAccess &colorBuffer, const tcu::PixelBufferAccess &depthBuffer, 113 const tcu::PixelBufferAccess &stencilBuffer, const IntegerQuad &quad, 114 const rr::FragmentOperationState &state); 115 116 private: 117 enum 118 { 119 MAX_FRAGMENT_BUFFER_SIZE = 1024 120 }; 121 122 void flushFragmentBuffer(const rr::MultisamplePixelBufferAccess &colorBuffer, 123 const rr::MultisamplePixelBufferAccess &depthBuffer, 124 const rr::MultisamplePixelBufferAccess &stencilBuffer, rr::FaceType faceType, 125 const rr::FragmentOperationState &state); 126 127 rr::Fragment m_fragmentBuffer[MAX_FRAGMENT_BUFFER_SIZE]; 128 float m_fragmentDepths[MAX_FRAGMENT_BUFFER_SIZE]; 129 int m_fragmentBufferSize; 130 131 rr::FragmentProcessor m_fragmentProcessor; 132 }; 133 134 // These functions take a normally-indexed 2d pixel buffer and return a pixel buffer access 135 // that indexes the same memory area, but using the multisample indexing convention. 136 tcu::PixelBufferAccess getMultisampleAccess(const tcu::PixelBufferAccess &original); 137 tcu::ConstPixelBufferAccess getMultisampleAccess(const tcu::ConstPixelBufferAccess &original); 138 139 } // namespace FragmentOpUtil 140 } // namespace gls 141 } // namespace deqp 142 143 #endif // _GLSFRAGMENTOPUTIL_HPP 144