1 #ifndef _ES31FFBOTESTUTIL_HPP 2 #define _ES31FFBOTESTUTIL_HPP 3 /*------------------------------------------------------------------------- 4 * drawElements Quality Program OpenGL ES 3.1 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 FBO test utilities. 24 *//*--------------------------------------------------------------------*/ 25 26 #include "tcuDefs.hpp" 27 #include "sglrContext.hpp" 28 #include "gluShaderUtil.hpp" 29 #include "tcuTexture.hpp" 30 #include "tcuMatrix.hpp" 31 #include "tcuRenderTarget.hpp" 32 33 #include <vector> 34 35 namespace deqp 36 { 37 namespace gles31 38 { 39 namespace Functional 40 { 41 namespace FboTestUtil 42 { 43 44 // \todo [2012-04-29 pyry] Clean up and name as SglrUtil 45 46 // Helper class for constructing DataType vectors. 47 struct DataTypes 48 { 49 std::vector<glu::DataType> vec; operator <<deqp::gles31::Functional::FboTestUtil::DataTypes50 DataTypes &operator<<(glu::DataType type) 51 { 52 vec.push_back(type); 53 return *this; 54 } 55 }; 56 57 // Shaders. 58 59 class Texture2DShader : public sglr::ShaderProgram 60 { 61 public: 62 Texture2DShader(const DataTypes &samplerTypes, glu::DataType outputType, 63 const tcu::Vec4 &outScale = tcu::Vec4(1.0f), const tcu::Vec4 &outBias = tcu::Vec4(0.0f)); ~Texture2DShader(void)64 ~Texture2DShader(void) 65 { 66 } 67 68 void setUnit(int samplerNdx, int unitNdx); 69 void setTexScaleBias(int samplerNdx, const tcu::Vec4 &scale, const tcu::Vec4 &bias); 70 void setOutScaleBias(const tcu::Vec4 &scale, const tcu::Vec4 &bias); 71 72 void setUniforms(sglr::Context &context, uint32_t program) const; 73 74 void shadeVertices(const rr::VertexAttrib *inputs, rr::VertexPacket *const *packets, const int numPackets) const; 75 void shadeFragments(rr::FragmentPacket *packets, const int numPackets, 76 const rr::FragmentShadingContext &context) const; 77 78 private: 79 struct Input 80 { 81 int unitNdx; 82 tcu::Vec4 scale; 83 tcu::Vec4 bias; 84 }; 85 86 std::vector<Input> m_inputs; 87 tcu::Vec4 m_outScale; 88 tcu::Vec4 m_outBias; 89 90 const glu::DataType m_outputType; 91 }; 92 93 class TextureCubeArrayShader : public sglr::ShaderProgram 94 { 95 public: 96 TextureCubeArrayShader(glu::DataType samplerType, glu::DataType outputType, glu::GLSLVersion glslVersion); ~TextureCubeArrayShader(void)97 ~TextureCubeArrayShader(void) 98 { 99 } 100 101 void setLayer(int layer); 102 void setFace(tcu::CubeFace face); 103 void setTexScaleBias(const tcu::Vec4 &scale, const tcu::Vec4 &bias); 104 105 void setUniforms(sglr::Context &context, uint32_t program) const; 106 107 void shadeVertices(const rr::VertexAttrib *inputs, rr::VertexPacket *const *packets, const int numPackets) const; 108 void shadeFragments(rr::FragmentPacket *packets, const int numPackets, 109 const rr::FragmentShadingContext &context) const; 110 111 private: 112 tcu::Vec4 m_texScale; 113 tcu::Vec4 m_texBias; 114 int m_layer; 115 tcu::Mat3 m_coordMat; 116 117 const glu::DataType m_outputType; 118 }; 119 120 // Framebuffer incomplete exception. 121 class FboIncompleteException : public tcu::TestError 122 { 123 public: 124 FboIncompleteException(uint32_t reason, const char *file, int line); ~FboIncompleteException(void)125 virtual ~FboIncompleteException(void) throw() 126 { 127 } 128 getReason(void) const129 uint32_t getReason(void) const 130 { 131 return m_reason; 132 } 133 134 private: 135 uint32_t m_reason; 136 }; 137 138 // Utility functions 139 140 glu::DataType getFragmentOutputType(const tcu::TextureFormat &format); 141 tcu::TextureFormat getFramebufferReadFormat(const tcu::TextureFormat &format); 142 143 const char *getFormatName(uint32_t format); 144 145 void clearColorBuffer(sglr::Context &ctx, const tcu::TextureFormat &format, const tcu::Vec4 &value); 146 void readPixels(sglr::Context &ctx, tcu::Surface &dst, int x, int y, int width, int height, 147 const tcu::TextureFormat &format, const tcu::Vec4 &scale, const tcu::Vec4 &bias); 148 149 tcu::RGBA getFormatThreshold(const tcu::TextureFormat &format); 150 tcu::RGBA getFormatThreshold(const uint32_t glFormat); 151 152 } // namespace FboTestUtil 153 } // namespace Functional 154 } // namespace gles31 155 } // namespace deqp 156 157 #endif // _ES31FFBOTESTUTIL_HPP 158