Exclude shared_presentable_image scale down from Android CTS am: 4e9d89ac4a am: 8192b...
[platform/upstream/VK-GL-CTS.git] / modules / gles3 / functional / es3fFboTestUtil.hpp
1 #ifndef _ES3FFBOTESTUTIL_HPP
2 #define _ES3FFBOTESTUTIL_HPP
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program OpenGL ES 3.0 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 gles3
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;
50         DataTypes& operator<< (glu::DataType type) { vec.push_back(type); return *this; }
51 };
52
53 // Shaders.
54
55 class FlatColorShader : public sglr::ShaderProgram
56 {
57 public:
58                                                 FlatColorShader         (glu::DataType outputType);
59                                                 ~FlatColorShader        (void) {}
60
61         void                            setColor                        (sglr::Context& context, deUint32 program, const tcu::Vec4& color);
62
63         void                            shadeVertices           (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const;
64         void                            shadeFragments          (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const;
65
66 private:
67         const glu::DataType     m_outputType;
68 };
69
70 class GradientShader : public sglr::ShaderProgram
71 {
72 public:
73                                                 GradientShader          (glu::DataType outputType);
74                                                 ~GradientShader         (void) {}
75
76         void                            setGradient                     (sglr::Context& context, deUint32 program, const tcu::Vec4& gradientMin, const tcu::Vec4& gradientMax);
77
78         void                            shadeVertices           (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const;
79         void                            shadeFragments          (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const;
80
81 private:
82         const glu::DataType     m_outputType;
83 };
84
85 class Texture2DShader : public sglr::ShaderProgram
86 {
87 public:
88                                         Texture2DShader                 (const DataTypes& samplerTypes, glu::DataType outputType, const tcu::Vec4& outScale = tcu::Vec4(1.0f), const tcu::Vec4& outBias = tcu::Vec4(0.0f));
89                                         ~Texture2DShader                (void) {}
90
91         void                    setUnit                                 (int samplerNdx, int unitNdx);
92         void                    setTexScaleBias                 (int samplerNdx, const tcu::Vec4& scale, const tcu::Vec4& bias);
93         void                    setOutScaleBias                 (const tcu::Vec4& scale, const tcu::Vec4& bias);
94
95         void                    setUniforms                             (sglr::Context& context, deUint32 program) const;
96
97         void                    shadeVertices                   (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const;
98         void                    shadeFragments                  (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const;
99
100 private:
101         struct Input
102         {
103                 int                     unitNdx;
104                 tcu::Vec4       scale;
105                 tcu::Vec4       bias;
106         };
107
108         std::vector<Input>      m_inputs;
109         tcu::Vec4                       m_outScale;
110         tcu::Vec4                       m_outBias;
111
112         const glu::DataType     m_outputType;
113 };
114
115 class TextureCubeShader : public sglr::ShaderProgram
116 {
117 public:
118                                                 TextureCubeShader               (glu::DataType samplerType, glu::DataType outputType);
119                                                 ~TextureCubeShader              (void) {}
120
121         void                            setFace                                 (tcu::CubeFace face);
122         void                            setTexScaleBias                 (const tcu::Vec4& scale, const tcu::Vec4& bias);
123
124         void                            setUniforms                             (sglr::Context& context, deUint32 program) const;
125
126         void                            shadeVertices                   (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const;
127         void                            shadeFragments                  (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const;
128
129 private:
130         tcu::Mat3                       m_coordMat;
131         tcu::Vec4                       m_texScale;
132         tcu::Vec4                       m_texBias;
133
134         const glu::DataType     m_outputType;
135 };
136
137 class Texture2DArrayShader : public sglr::ShaderProgram
138 {
139 public:
140                                                 Texture2DArrayShader    (glu::DataType samplerType, glu::DataType outputType);
141                                                 ~Texture2DArrayShader   (void) {}
142
143         void                            setLayer                                (int layer);
144         void                            setTexScaleBias                 (const tcu::Vec4& scale, const tcu::Vec4& bias);
145
146         void                            setUniforms                             (sglr::Context& context, deUint32 program) const;
147
148         void                            shadeVertices                   (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const;
149         void                            shadeFragments                  (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const;
150
151 private:
152         tcu::Vec4                       m_texScale;
153         tcu::Vec4                       m_texBias;
154         int                                     m_layer;
155
156         const glu::DataType     m_outputType;
157 };
158
159 class Texture3DShader : public sglr::ShaderProgram
160 {
161 public:
162                                                 Texture3DShader                 (glu::DataType samplerType, glu::DataType outputType);
163                                                 ~Texture3DShader                (void) {}
164
165         void                            setDepth                                (float r);
166         void                            setTexScaleBias                 (const tcu::Vec4& scale, const tcu::Vec4& bias);
167
168         void                            setUniforms                             (sglr::Context& context, deUint32 program) const;
169
170         void                            shadeVertices                   (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const;
171         void                            shadeFragments                  (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const;
172
173 private:
174         tcu::Vec4                       m_texScale;
175         tcu::Vec4                       m_texBias;
176         float                           m_depth;
177
178         const glu::DataType     m_outputType;
179 };
180
181 class DepthGradientShader : public sglr::ShaderProgram
182 {
183 public:
184                                                                 DepthGradientShader             (glu::DataType outputType);
185                                                                 ~DepthGradientShader    (void) {}
186
187         void                                            setUniforms                             (sglr::Context& context, deUint32 program, const float gradientMin, const float gradientMax, const tcu::Vec4& color);
188
189         void                                            shadeVertices                   (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const;
190         void                                            shadeFragments                  (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const;
191
192 private:
193         const glu::DataType                     m_outputType;
194         const sglr::UniformSlot&        u_minGradient;
195         const sglr::UniformSlot&        u_maxGradient;
196         const sglr::UniformSlot&        u_color;
197 };
198
199 // Framebuffer incomplete exception.
200 class FboIncompleteException : public tcu::TestError
201 {
202 public:
203                                                 FboIncompleteException          (deUint32 reason, const char* file, int line);
204         virtual                         ~FboIncompleteException         (void) throw() {}
205
206         deUint32                        getReason                                       (void) const { return m_reason; }
207
208 private:
209         deUint32                        m_reason;
210 };
211
212 // Utility functions.
213
214 glu::DataType                   getFragmentOutputType                           (const tcu::TextureFormat& format);
215 tcu::TextureFormat              getFramebufferReadFormat                        (const tcu::TextureFormat& format);
216
217 const char*                             getFormatName                                           (deUint32 format);
218
219 void                                    clearColorBuffer                                        (sglr::Context& ctx, const tcu::TextureFormat& format, const tcu::Vec4& value);
220 void                                    readPixels                                                      (sglr::Context& ctx, tcu::Surface& dst, int x, int y, int width, int height, const tcu::TextureFormat& format, const tcu::Vec4& scale, const tcu::Vec4& bias);
221
222 tcu::RGBA                               getFormatThreshold                                      (const tcu::TextureFormat& format);
223 tcu::RGBA                               getFormatThreshold                                      (const deUint32 glFormat);
224
225 tcu::RGBA                               getToSRGBConversionThreshold            (const tcu::TextureFormat& src, const tcu::TextureFormat& dst);
226
227 } // FboTestUtil
228 } // Functional
229 } // gles3
230 } // deqp
231
232 #endif // _ES3FFBOTESTUTIL_HPP