xref: /aosp_15_r20/external/deqp/modules/gles31/functional/es31fFboSRGBWriteControlTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program OpenGL ES 3.1 Module
3*35238bceSAndroid Build Coastguard Worker  * -------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker  *
5*35238bceSAndroid Build Coastguard Worker  * Copyright 2017 The Android Open Source Project
6*35238bceSAndroid Build Coastguard Worker  *
7*35238bceSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
8*35238bceSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
9*35238bceSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
10*35238bceSAndroid Build Coastguard Worker  *
11*35238bceSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
12*35238bceSAndroid Build Coastguard Worker  *
13*35238bceSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
14*35238bceSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
15*35238bceSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16*35238bceSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
17*35238bceSAndroid Build Coastguard Worker  * limitations under the License.
18*35238bceSAndroid Build Coastguard Worker  *
19*35238bceSAndroid Build Coastguard Worker  *//*!
20*35238bceSAndroid Build Coastguard Worker  * \file
21*35238bceSAndroid Build Coastguard Worker  * \brief FBO sRGB tests.
22*35238bceSAndroid Build Coastguard Worker *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker 
24*35238bceSAndroid Build Coastguard Worker #include "es31fFboSRGBWriteControlTests.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "es31fFboTestUtil.hpp"
26*35238bceSAndroid Build Coastguard Worker #include "gluTextureUtil.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "gluContextInfo.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "sglrContextUtil.hpp"
31*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
32*35238bceSAndroid Build Coastguard Worker #include "deUniquePtr.hpp"
33*35238bceSAndroid Build Coastguard Worker #include "deSharedPtr.hpp"
34*35238bceSAndroid Build Coastguard Worker #include "gluObjectWrapper.hpp"
35*35238bceSAndroid Build Coastguard Worker #include "gluPixelTransfer.hpp"
36*35238bceSAndroid Build Coastguard Worker #include "glsTextureTestUtil.hpp"
37*35238bceSAndroid Build Coastguard Worker #include "tcuVectorUtil.hpp"
38*35238bceSAndroid Build Coastguard Worker #include "gluStrUtil.hpp"
39*35238bceSAndroid Build Coastguard Worker 
40*35238bceSAndroid Build Coastguard Worker namespace deqp
41*35238bceSAndroid Build Coastguard Worker {
42*35238bceSAndroid Build Coastguard Worker namespace gles31
43*35238bceSAndroid Build Coastguard Worker {
44*35238bceSAndroid Build Coastguard Worker namespace Functional
45*35238bceSAndroid Build Coastguard Worker {
46*35238bceSAndroid Build Coastguard Worker namespace
47*35238bceSAndroid Build Coastguard Worker {
48*35238bceSAndroid Build Coastguard Worker 
getTestColorLinear(void)49*35238bceSAndroid Build Coastguard Worker tcu::Vec4 getTestColorLinear(void)
50*35238bceSAndroid Build Coastguard Worker {
51*35238bceSAndroid Build Coastguard Worker     return tcu::Vec4(0.2f, 0.3f, 0.4f, 1.0f);
52*35238bceSAndroid Build Coastguard Worker }
53*35238bceSAndroid Build Coastguard Worker 
getTestColorSRGB(void)54*35238bceSAndroid Build Coastguard Worker tcu::Vec4 getTestColorSRGB(void)
55*35238bceSAndroid Build Coastguard Worker {
56*35238bceSAndroid Build Coastguard Worker     return linearToSRGB(tcu::Vec4(0.2f, 0.3f, 0.4f, 1.0f));
57*35238bceSAndroid Build Coastguard Worker }
58*35238bceSAndroid Build Coastguard Worker 
getTestColorBlank(void)59*35238bceSAndroid Build Coastguard Worker tcu::Vec4 getTestColorBlank(void)
60*35238bceSAndroid Build Coastguard Worker {
61*35238bceSAndroid Build Coastguard Worker     return tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f);
62*35238bceSAndroid Build Coastguard Worker }
63*35238bceSAndroid Build Coastguard Worker 
getEpsilonError(void)64*35238bceSAndroid Build Coastguard Worker tcu::Vec4 getEpsilonError(void)
65*35238bceSAndroid Build Coastguard Worker {
66*35238bceSAndroid Build Coastguard Worker     return tcu::Vec4(0.005f);
67*35238bceSAndroid Build Coastguard Worker }
68*35238bceSAndroid Build Coastguard Worker 
69*35238bceSAndroid Build Coastguard Worker enum QueryType
70*35238bceSAndroid Build Coastguard Worker {
71*35238bceSAndroid Build Coastguard Worker     QUERYTYPE_ISENABLED = 0,
72*35238bceSAndroid Build Coastguard Worker     QUERYTYPE_BOOLEAN,
73*35238bceSAndroid Build Coastguard Worker     QUERYTYPE_FLOAT,
74*35238bceSAndroid Build Coastguard Worker     QUERYTYPE_INT,
75*35238bceSAndroid Build Coastguard Worker     QUERYTYPE_INT64,
76*35238bceSAndroid Build Coastguard Worker     QUERYTYPE_LAST
77*35238bceSAndroid Build Coastguard Worker };
78*35238bceSAndroid Build Coastguard Worker 
79*35238bceSAndroid Build Coastguard Worker enum DataType
80*35238bceSAndroid Build Coastguard Worker {
81*35238bceSAndroid Build Coastguard Worker     DATATYPE_BOOLEAN = 0,
82*35238bceSAndroid Build Coastguard Worker     DATATYPE_FLOAT,
83*35238bceSAndroid Build Coastguard Worker     DATATYPE_INT,
84*35238bceSAndroid Build Coastguard Worker     DATATYPE_INT64,
85*35238bceSAndroid Build Coastguard Worker };
86*35238bceSAndroid Build Coastguard Worker 
87*35238bceSAndroid Build Coastguard Worker enum FramebufferSRGB
88*35238bceSAndroid Build Coastguard Worker {
89*35238bceSAndroid Build Coastguard Worker     FRAMEBUFFERSRGB_ENABLED = 0,
90*35238bceSAndroid Build Coastguard Worker     FRAMEBUFFERSRGB_DISABLED
91*35238bceSAndroid Build Coastguard Worker };
92*35238bceSAndroid Build Coastguard Worker 
93*35238bceSAndroid Build Coastguard Worker enum FramebufferBlend
94*35238bceSAndroid Build Coastguard Worker {
95*35238bceSAndroid Build Coastguard Worker     FRAMEBUFFERBLEND_ENABLED = 0,
96*35238bceSAndroid Build Coastguard Worker     FRAMEBUFFERBLEND_DISABLED
97*35238bceSAndroid Build Coastguard Worker };
98*35238bceSAndroid Build Coastguard Worker 
99*35238bceSAndroid Build Coastguard Worker enum TextureSourcesType
100*35238bceSAndroid Build Coastguard Worker {
101*35238bceSAndroid Build Coastguard Worker     TEXTURESOURCESTYPE_RGBA = 0,
102*35238bceSAndroid Build Coastguard Worker     TEXTURESOURCESTYPE_SRGBA,
103*35238bceSAndroid Build Coastguard Worker     TEXTURESOURCESTYPE_BOTH,
104*35238bceSAndroid Build Coastguard Worker     TEXTURESOURCESTYPE_NONE
105*35238bceSAndroid Build Coastguard Worker };
106*35238bceSAndroid Build Coastguard Worker 
107*35238bceSAndroid Build Coastguard Worker enum FboType
108*35238bceSAndroid Build Coastguard Worker {
109*35238bceSAndroid Build Coastguard Worker     FBOTYPE_SOURCE = 0,
110*35238bceSAndroid Build Coastguard Worker     FBOTYPE_DESTINATION
111*35238bceSAndroid Build Coastguard Worker };
112*35238bceSAndroid Build Coastguard Worker 
113*35238bceSAndroid Build Coastguard Worker enum RendererTask
114*35238bceSAndroid Build Coastguard Worker {
115*35238bceSAndroid Build Coastguard Worker     RENDERERTASK_DRAW = 0,
116*35238bceSAndroid Build Coastguard Worker     RENDERERTASK_COPY
117*35238bceSAndroid Build Coastguard Worker };
118*35238bceSAndroid Build Coastguard Worker 
119*35238bceSAndroid Build Coastguard Worker enum SamplingType
120*35238bceSAndroid Build Coastguard Worker {
121*35238bceSAndroid Build Coastguard Worker     SAMPLINGTYPE_TEXTURE = 0,
122*35238bceSAndroid Build Coastguard Worker     SAMPLINGTYPE_TEXTURE_LOD,
123*35238bceSAndroid Build Coastguard Worker     SAMPLINGTYPE_TEXTURE_GRAD,
124*35238bceSAndroid Build Coastguard Worker     SAMPLINGTYPE_TEXTURE_OFFSET,
125*35238bceSAndroid Build Coastguard Worker     SAMPLINGTYPE_TEXTURE_PROJ,
126*35238bceSAndroid Build Coastguard Worker };
127*35238bceSAndroid Build Coastguard Worker 
128*35238bceSAndroid Build Coastguard Worker namespace TestTextureSizes
129*35238bceSAndroid Build Coastguard Worker {
130*35238bceSAndroid Build Coastguard Worker const int WIDTH  = 128;
131*35238bceSAndroid Build Coastguard Worker const int HEIGHT = 128;
132*35238bceSAndroid Build Coastguard Worker } // namespace TestTextureSizes
133*35238bceSAndroid Build Coastguard Worker 
134*35238bceSAndroid Build Coastguard Worker namespace SampligTypeCount
135*35238bceSAndroid Build Coastguard Worker {
136*35238bceSAndroid Build Coastguard Worker const int MAX = 5;
137*35238bceSAndroid Build Coastguard Worker } // namespace SampligTypeCount
138*35238bceSAndroid Build Coastguard Worker 
buildSamplingPassType(const int samplerTotal)139*35238bceSAndroid Build Coastguard Worker std::string buildSamplingPassType(const int samplerTotal)
140*35238bceSAndroid Build Coastguard Worker {
141*35238bceSAndroid Build Coastguard Worker     std::ostringstream shaderFragment;
142*35238bceSAndroid Build Coastguard Worker 
143*35238bceSAndroid Build Coastguard Worker     const SamplingType samplingTypeList[] = {SAMPLINGTYPE_TEXTURE, SAMPLINGTYPE_TEXTURE_LOD, SAMPLINGTYPE_TEXTURE_GRAD,
144*35238bceSAndroid Build Coastguard Worker                                              SAMPLINGTYPE_TEXTURE_OFFSET, SAMPLINGTYPE_TEXTURE_PROJ};
145*35238bceSAndroid Build Coastguard Worker 
146*35238bceSAndroid Build Coastguard Worker     for (int samplerTypeIdx = 0; samplerTypeIdx < DE_LENGTH_OF_ARRAY(samplingTypeList); samplerTypeIdx++)
147*35238bceSAndroid Build Coastguard Worker     {
148*35238bceSAndroid Build Coastguard Worker         shaderFragment << "    if (uFunctionType == " << samplerTypeIdx << ") \n"
149*35238bceSAndroid Build Coastguard Worker                        << "    { \n";
150*35238bceSAndroid Build Coastguard Worker 
151*35238bceSAndroid Build Coastguard Worker         for (int samplerIdx = 0; samplerIdx < samplerTotal; samplerIdx++)
152*35238bceSAndroid Build Coastguard Worker         {
153*35238bceSAndroid Build Coastguard Worker             switch (static_cast<SamplingType>(samplerTypeIdx))
154*35238bceSAndroid Build Coastguard Worker             {
155*35238bceSAndroid Build Coastguard Worker             case SAMPLINGTYPE_TEXTURE:
156*35238bceSAndroid Build Coastguard Worker             {
157*35238bceSAndroid Build Coastguard Worker                 shaderFragment << "        texelColor" << samplerIdx << " = texture(uTexture" << samplerIdx
158*35238bceSAndroid Build Coastguard Worker                                << ", vs_aTexCoord); \n";
159*35238bceSAndroid Build Coastguard Worker                 break;
160*35238bceSAndroid Build Coastguard Worker             }
161*35238bceSAndroid Build Coastguard Worker             case SAMPLINGTYPE_TEXTURE_LOD:
162*35238bceSAndroid Build Coastguard Worker             {
163*35238bceSAndroid Build Coastguard Worker                 shaderFragment << "        texelColor" << samplerIdx << " = textureLod(uTexture" << samplerIdx
164*35238bceSAndroid Build Coastguard Worker                                << ", vs_aTexCoord, 0.0f); \n";
165*35238bceSAndroid Build Coastguard Worker                 break;
166*35238bceSAndroid Build Coastguard Worker             }
167*35238bceSAndroid Build Coastguard Worker             case SAMPLINGTYPE_TEXTURE_GRAD:
168*35238bceSAndroid Build Coastguard Worker             {
169*35238bceSAndroid Build Coastguard Worker                 shaderFragment << "        texelColor" << samplerIdx << " = textureGrad(uTexture" << samplerIdx
170*35238bceSAndroid Build Coastguard Worker                                << ", vs_aTexCoord, vec2(0.0f, 0.0f), vec2(0.0f, 0.0f)); \n";
171*35238bceSAndroid Build Coastguard Worker                 break;
172*35238bceSAndroid Build Coastguard Worker             }
173*35238bceSAndroid Build Coastguard Worker             case SAMPLINGTYPE_TEXTURE_OFFSET:
174*35238bceSAndroid Build Coastguard Worker             {
175*35238bceSAndroid Build Coastguard Worker                 shaderFragment << "        texelColor" << samplerIdx << " = textureOffset(uTexture" << samplerIdx
176*35238bceSAndroid Build Coastguard Worker                                << ", vs_aTexCoord, ivec2(0.0f, 0.0f)); \n";
177*35238bceSAndroid Build Coastguard Worker                 break;
178*35238bceSAndroid Build Coastguard Worker             }
179*35238bceSAndroid Build Coastguard Worker             case SAMPLINGTYPE_TEXTURE_PROJ:
180*35238bceSAndroid Build Coastguard Worker             {
181*35238bceSAndroid Build Coastguard Worker                 shaderFragment << "        texelColor" << samplerIdx << " = textureProj(uTexture" << samplerIdx
182*35238bceSAndroid Build Coastguard Worker                                << ", vec3(vs_aTexCoord, 1.0f)); \n";
183*35238bceSAndroid Build Coastguard Worker                 break;
184*35238bceSAndroid Build Coastguard Worker             }
185*35238bceSAndroid Build Coastguard Worker             default:
186*35238bceSAndroid Build Coastguard Worker                 DE_FATAL("Error: sampling type unrecognised");
187*35238bceSAndroid Build Coastguard Worker             }
188*35238bceSAndroid Build Coastguard Worker         }
189*35238bceSAndroid Build Coastguard Worker 
190*35238bceSAndroid Build Coastguard Worker         shaderFragment << "    } \n";
191*35238bceSAndroid Build Coastguard Worker     }
192*35238bceSAndroid Build Coastguard Worker 
193*35238bceSAndroid Build Coastguard Worker     return shaderFragment.str();
194*35238bceSAndroid Build Coastguard Worker }
195*35238bceSAndroid Build Coastguard Worker 
logColor(Context & context,const std::string & colorLogMessage,const tcu::Vec4 resultColor)196*35238bceSAndroid Build Coastguard Worker void logColor(Context &context, const std::string &colorLogMessage, const tcu::Vec4 resultColor)
197*35238bceSAndroid Build Coastguard Worker {
198*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log = context.getTestContext().getLog();
199*35238bceSAndroid Build Coastguard Worker     std::ostringstream message;
200*35238bceSAndroid Build Coastguard Worker 
201*35238bceSAndroid Build Coastguard Worker     message << colorLogMessage << " = (" << resultColor.x() << ", " << resultColor.y() << ", " << resultColor.z()
202*35238bceSAndroid Build Coastguard Worker             << ", " << resultColor.w() << ")";
203*35238bceSAndroid Build Coastguard Worker     log << tcu::TestLog::Message << message.str() << tcu::TestLog::EndMessage;
204*35238bceSAndroid Build Coastguard Worker }
205*35238bceSAndroid Build Coastguard Worker 
206*35238bceSAndroid Build Coastguard Worker struct TestFunction
207*35238bceSAndroid Build Coastguard Worker {
TestFunctiondeqp::gles31::Functional::__anon0174e0ff0111::TestFunction208*35238bceSAndroid Build Coastguard Worker     explicit TestFunction(const bool hasFunctionValue) : hasFunction(hasFunctionValue)
209*35238bceSAndroid Build Coastguard Worker     {
210*35238bceSAndroid Build Coastguard Worker     }
TestFunctiondeqp::gles31::Functional::__anon0174e0ff0111::TestFunction211*35238bceSAndroid Build Coastguard Worker     TestFunction(const char *const functionNameValue, const char *const functionDefinition)
212*35238bceSAndroid Build Coastguard Worker         : hasFunction(true)
213*35238bceSAndroid Build Coastguard Worker         , functionName(functionNameValue)
214*35238bceSAndroid Build Coastguard Worker         , functionDefintion(functionDefinition)
215*35238bceSAndroid Build Coastguard Worker     {
216*35238bceSAndroid Build Coastguard Worker     }
~TestFunctiondeqp::gles31::Functional::__anon0174e0ff0111::TestFunction217*35238bceSAndroid Build Coastguard Worker     ~TestFunction(void)
218*35238bceSAndroid Build Coastguard Worker     {
219*35238bceSAndroid Build Coastguard Worker     }
220*35238bceSAndroid Build Coastguard Worker 
221*35238bceSAndroid Build Coastguard Worker     bool hasFunction;
222*35238bceSAndroid Build Coastguard Worker     const char *functionName;
223*35238bceSAndroid Build Coastguard Worker     const char *functionDefintion;
224*35238bceSAndroid Build Coastguard Worker };
225*35238bceSAndroid Build Coastguard Worker 
getFunctionBlendLinearToSRGBCheck(void)226*35238bceSAndroid Build Coastguard Worker TestFunction getFunctionBlendLinearToSRGBCheck(void)
227*35238bceSAndroid Build Coastguard Worker {
228*35238bceSAndroid Build Coastguard Worker     const char *const functionName = "blendPlusLinearToSRGB";
229*35238bceSAndroid Build Coastguard Worker 
230*35238bceSAndroid Build Coastguard Worker     const char *const functionDefinition =
231*35238bceSAndroid Build Coastguard Worker         "mediump vec4 blendPlusLinearToSRGB(in mediump vec4 colorSrc, in mediump vec4 colorDst) \n"
232*35238bceSAndroid Build Coastguard Worker         "{ \n"
233*35238bceSAndroid Build Coastguard Worker         "    const int MAX_VECTOR_SIZE = 4; \n"
234*35238bceSAndroid Build Coastguard Worker         "    mediump vec4 colorConverted; \n"
235*35238bceSAndroid Build Coastguard Worker         "    mediump vec4 colorBlended; \n"
236*35238bceSAndroid Build Coastguard Worker         "    for (int idx = 0; idx < MAX_VECTOR_SIZE; idx++) \n"
237*35238bceSAndroid Build Coastguard Worker         "    { \n"
238*35238bceSAndroid Build Coastguard Worker         "        if (uBlendFunctionType == 0) \n"
239*35238bceSAndroid Build Coastguard Worker         "        { \n"
240*35238bceSAndroid Build Coastguard Worker         "            colorBlended[idx] = (colorSrc[idx] * uFactorSrc) + colorDst[idx] * uFactorDst; \n"
241*35238bceSAndroid Build Coastguard Worker         "        } \n"
242*35238bceSAndroid Build Coastguard Worker         "        if (uBlendFunctionType == 1) \n"
243*35238bceSAndroid Build Coastguard Worker         "        { \n"
244*35238bceSAndroid Build Coastguard Worker         "            colorBlended[idx] = (colorSrc[idx] * uFactorSrc) - (colorDst[idx] * uFactorDst); \n"
245*35238bceSAndroid Build Coastguard Worker         "        } \n"
246*35238bceSAndroid Build Coastguard Worker         "if (uBlendFunctionType == 2) \n"
247*35238bceSAndroid Build Coastguard Worker         "        { \n"
248*35238bceSAndroid Build Coastguard Worker         "            colorBlended[idx] = (colorDst[idx] * uFactorDst) - (colorSrc[idx] * uFactorSrc); \n"
249*35238bceSAndroid Build Coastguard Worker         "        } \n"
250*35238bceSAndroid Build Coastguard Worker         "        if (colorBlended[idx] < 0.0031308f) \n"
251*35238bceSAndroid Build Coastguard Worker         "        { \n"
252*35238bceSAndroid Build Coastguard Worker         "            colorConverted[idx] = 12.92f * colorBlended[idx]; \n"
253*35238bceSAndroid Build Coastguard Worker         "        } \n"
254*35238bceSAndroid Build Coastguard Worker         "        else \n"
255*35238bceSAndroid Build Coastguard Worker         "        { \n"
256*35238bceSAndroid Build Coastguard Worker         "            colorConverted[idx] = 1.055f * pow(colorBlended[idx], 0.41666f) - 0.055f; \n"
257*35238bceSAndroid Build Coastguard Worker         "        } \n"
258*35238bceSAndroid Build Coastguard Worker         "    } \n"
259*35238bceSAndroid Build Coastguard Worker         "    return colorConverted; \n"
260*35238bceSAndroid Build Coastguard Worker         "} \n";
261*35238bceSAndroid Build Coastguard Worker 
262*35238bceSAndroid Build Coastguard Worker     TestFunction testFunction(functionName, functionDefinition);
263*35238bceSAndroid Build Coastguard Worker 
264*35238bceSAndroid Build Coastguard Worker     return testFunction;
265*35238bceSAndroid Build Coastguard Worker }
266*35238bceSAndroid Build Coastguard Worker 
267*35238bceSAndroid Build Coastguard Worker struct FBOConfig
268*35238bceSAndroid Build Coastguard Worker {
FBOConfigdeqp::gles31::Functional::__anon0174e0ff0111::FBOConfig269*35238bceSAndroid Build Coastguard Worker     FBOConfig(const uint32_t textureInternalFormatValue, const tcu::Vec4 textureColorValue,
270*35238bceSAndroid Build Coastguard Worker               const uint32_t fboTargetTypeValue, const uint32_t fboColorAttachmentValue, const FboType fboTypeValue)
271*35238bceSAndroid Build Coastguard Worker         : textureInternalFormat(textureInternalFormatValue)
272*35238bceSAndroid Build Coastguard Worker         , textureColor(textureColorValue)
273*35238bceSAndroid Build Coastguard Worker         , fboTargetType(fboTargetTypeValue)
274*35238bceSAndroid Build Coastguard Worker         , fboColorAttachment(fboColorAttachmentValue)
275*35238bceSAndroid Build Coastguard Worker         , fboType(fboTypeValue)
276*35238bceSAndroid Build Coastguard Worker     {
277*35238bceSAndroid Build Coastguard Worker     }
~FBOConfigdeqp::gles31::Functional::__anon0174e0ff0111::FBOConfig278*35238bceSAndroid Build Coastguard Worker     ~FBOConfig(void)
279*35238bceSAndroid Build Coastguard Worker     {
280*35238bceSAndroid Build Coastguard Worker     }
281*35238bceSAndroid Build Coastguard Worker 
282*35238bceSAndroid Build Coastguard Worker     uint32_t textureInternalFormat;
283*35238bceSAndroid Build Coastguard Worker     tcu::Vec4 textureColor;
284*35238bceSAndroid Build Coastguard Worker     uint32_t fboTargetType;
285*35238bceSAndroid Build Coastguard Worker     uint32_t fboColorAttachment;
286*35238bceSAndroid Build Coastguard Worker     FboType fboType;
287*35238bceSAndroid Build Coastguard Worker };
288*35238bceSAndroid Build Coastguard Worker 
289*35238bceSAndroid Build Coastguard Worker struct BlendConfig
290*35238bceSAndroid Build Coastguard Worker {
291*35238bceSAndroid Build Coastguard Worker     uint32_t equation;
292*35238bceSAndroid Build Coastguard Worker     uint32_t funcSrc;
293*35238bceSAndroid Build Coastguard Worker     uint32_t funcDst;
294*35238bceSAndroid Build Coastguard Worker };
295*35238bceSAndroid Build Coastguard Worker 
getBlendingConfigList(void)296*35238bceSAndroid Build Coastguard Worker std::vector<BlendConfig> getBlendingConfigList(void)
297*35238bceSAndroid Build Coastguard Worker {
298*35238bceSAndroid Build Coastguard Worker     BlendConfig blendConfigs[12];
299*35238bceSAndroid Build Coastguard Worker 
300*35238bceSAndroid Build Coastguard Worker     // add function permutations
301*35238bceSAndroid Build Coastguard Worker     blendConfigs[0].equation = GL_FUNC_ADD;
302*35238bceSAndroid Build Coastguard Worker     blendConfigs[1].equation = GL_FUNC_ADD;
303*35238bceSAndroid Build Coastguard Worker     blendConfigs[2].equation = GL_FUNC_ADD;
304*35238bceSAndroid Build Coastguard Worker     blendConfigs[3].equation = GL_FUNC_ADD;
305*35238bceSAndroid Build Coastguard Worker 
306*35238bceSAndroid Build Coastguard Worker     blendConfigs[0].funcSrc = GL_ONE;
307*35238bceSAndroid Build Coastguard Worker     blendConfigs[0].funcDst = GL_ONE;
308*35238bceSAndroid Build Coastguard Worker     blendConfigs[1].funcSrc = GL_ONE;
309*35238bceSAndroid Build Coastguard Worker     blendConfigs[1].funcDst = GL_ZERO;
310*35238bceSAndroid Build Coastguard Worker     blendConfigs[2].funcSrc = GL_ZERO;
311*35238bceSAndroid Build Coastguard Worker     blendConfigs[2].funcDst = GL_ONE;
312*35238bceSAndroid Build Coastguard Worker     blendConfigs[3].funcSrc = GL_ZERO;
313*35238bceSAndroid Build Coastguard Worker     blendConfigs[3].funcDst = GL_ZERO;
314*35238bceSAndroid Build Coastguard Worker 
315*35238bceSAndroid Build Coastguard Worker     // subtract function permutations
316*35238bceSAndroid Build Coastguard Worker     blendConfigs[4].equation = GL_FUNC_SUBTRACT;
317*35238bceSAndroid Build Coastguard Worker     blendConfigs[5].equation = GL_FUNC_SUBTRACT;
318*35238bceSAndroid Build Coastguard Worker     blendConfigs[6].equation = GL_FUNC_SUBTRACT;
319*35238bceSAndroid Build Coastguard Worker     blendConfigs[7].equation = GL_FUNC_SUBTRACT;
320*35238bceSAndroid Build Coastguard Worker 
321*35238bceSAndroid Build Coastguard Worker     blendConfigs[4].funcSrc = GL_ONE;
322*35238bceSAndroid Build Coastguard Worker     blendConfigs[4].funcDst = GL_ONE;
323*35238bceSAndroid Build Coastguard Worker     blendConfigs[5].funcSrc = GL_ONE;
324*35238bceSAndroid Build Coastguard Worker     blendConfigs[5].funcDst = GL_ZERO;
325*35238bceSAndroid Build Coastguard Worker     blendConfigs[6].funcSrc = GL_ZERO;
326*35238bceSAndroid Build Coastguard Worker     blendConfigs[6].funcDst = GL_ONE;
327*35238bceSAndroid Build Coastguard Worker     blendConfigs[7].funcSrc = GL_ZERO;
328*35238bceSAndroid Build Coastguard Worker     blendConfigs[7].funcDst = GL_ZERO;
329*35238bceSAndroid Build Coastguard Worker 
330*35238bceSAndroid Build Coastguard Worker     // reverse subtract function permutations
331*35238bceSAndroid Build Coastguard Worker     blendConfigs[8].equation  = GL_FUNC_REVERSE_SUBTRACT;
332*35238bceSAndroid Build Coastguard Worker     blendConfigs[9].equation  = GL_FUNC_REVERSE_SUBTRACT;
333*35238bceSAndroid Build Coastguard Worker     blendConfigs[10].equation = GL_FUNC_REVERSE_SUBTRACT;
334*35238bceSAndroid Build Coastguard Worker     blendConfigs[11].equation = GL_FUNC_REVERSE_SUBTRACT;
335*35238bceSAndroid Build Coastguard Worker 
336*35238bceSAndroid Build Coastguard Worker     blendConfigs[8].funcSrc  = GL_ONE;
337*35238bceSAndroid Build Coastguard Worker     blendConfigs[8].funcDst  = GL_ONE;
338*35238bceSAndroid Build Coastguard Worker     blendConfigs[9].funcSrc  = GL_ONE;
339*35238bceSAndroid Build Coastguard Worker     blendConfigs[9].funcDst  = GL_ZERO;
340*35238bceSAndroid Build Coastguard Worker     blendConfigs[10].funcSrc = GL_ZERO;
341*35238bceSAndroid Build Coastguard Worker     blendConfigs[10].funcDst = GL_ONE;
342*35238bceSAndroid Build Coastguard Worker     blendConfigs[11].funcSrc = GL_ZERO;
343*35238bceSAndroid Build Coastguard Worker     blendConfigs[11].funcDst = GL_ZERO;
344*35238bceSAndroid Build Coastguard Worker 
345*35238bceSAndroid Build Coastguard Worker     std::vector<BlendConfig> configList(blendConfigs, blendConfigs + DE_LENGTH_OF_ARRAY(blendConfigs));
346*35238bceSAndroid Build Coastguard Worker 
347*35238bceSAndroid Build Coastguard Worker     return configList;
348*35238bceSAndroid Build Coastguard Worker }
349*35238bceSAndroid Build Coastguard Worker 
350*35238bceSAndroid Build Coastguard Worker struct TestRenderPassConfig
351*35238bceSAndroid Build Coastguard Worker {
TestRenderPassConfigdeqp::gles31::Functional::__anon0174e0ff0111::TestRenderPassConfig352*35238bceSAndroid Build Coastguard Worker     TestRenderPassConfig(void) : testFunction(false)
353*35238bceSAndroid Build Coastguard Worker     {
354*35238bceSAndroid Build Coastguard Worker     }
355*35238bceSAndroid Build Coastguard Worker 
TestRenderPassConfigdeqp::gles31::Functional::__anon0174e0ff0111::TestRenderPassConfig356*35238bceSAndroid Build Coastguard Worker     TestRenderPassConfig(const TextureSourcesType textureSourcesTypeValue, FBOConfig fboConfigListValue,
357*35238bceSAndroid Build Coastguard Worker                          const FramebufferSRGB framebufferSRGBValue, const FramebufferBlend framebufferBendValue,
358*35238bceSAndroid Build Coastguard Worker                          const RendererTask rendererTaskValue)
359*35238bceSAndroid Build Coastguard Worker         : textureSourcesType(textureSourcesTypeValue)
360*35238bceSAndroid Build Coastguard Worker         , framebufferSRGB(framebufferSRGBValue)
361*35238bceSAndroid Build Coastguard Worker         , frameBufferBlend(framebufferBendValue)
362*35238bceSAndroid Build Coastguard Worker         , testFunction(false)
363*35238bceSAndroid Build Coastguard Worker         , rendererTask(rendererTaskValue)
364*35238bceSAndroid Build Coastguard Worker     {
365*35238bceSAndroid Build Coastguard Worker         fboConfigList.push_back(fboConfigListValue);
366*35238bceSAndroid Build Coastguard Worker     }
367*35238bceSAndroid Build Coastguard Worker 
TestRenderPassConfigdeqp::gles31::Functional::__anon0174e0ff0111::TestRenderPassConfig368*35238bceSAndroid Build Coastguard Worker     TestRenderPassConfig(const TextureSourcesType textureSourcesTypeValue, FBOConfig fboConfigListValue,
369*35238bceSAndroid Build Coastguard Worker                          const FramebufferSRGB framebufferSRGBValue, const FramebufferBlend framebufferBendValue,
370*35238bceSAndroid Build Coastguard Worker                          TestFunction testFunctionValue, const RendererTask rendererTaskValue)
371*35238bceSAndroid Build Coastguard Worker         : textureSourcesType(textureSourcesTypeValue)
372*35238bceSAndroid Build Coastguard Worker         , framebufferSRGB(framebufferSRGBValue)
373*35238bceSAndroid Build Coastguard Worker         , frameBufferBlend(framebufferBendValue)
374*35238bceSAndroid Build Coastguard Worker         , testFunction(testFunctionValue)
375*35238bceSAndroid Build Coastguard Worker         , rendererTask(rendererTaskValue)
376*35238bceSAndroid Build Coastguard Worker     {
377*35238bceSAndroid Build Coastguard Worker         fboConfigList.push_back(fboConfigListValue);
378*35238bceSAndroid Build Coastguard Worker     }
379*35238bceSAndroid Build Coastguard Worker 
TestRenderPassConfigdeqp::gles31::Functional::__anon0174e0ff0111::TestRenderPassConfig380*35238bceSAndroid Build Coastguard Worker     TestRenderPassConfig(const TextureSourcesType textureSourcesTypeValue, std::vector<FBOConfig> fboConfigListValue,
381*35238bceSAndroid Build Coastguard Worker                          const FramebufferSRGB framebufferSRGBValue, const FramebufferBlend framebufferBendValue,
382*35238bceSAndroid Build Coastguard Worker                          TestFunction testFunctionValue, const RendererTask rendererTaskValue)
383*35238bceSAndroid Build Coastguard Worker         : textureSourcesType(textureSourcesTypeValue)
384*35238bceSAndroid Build Coastguard Worker         , fboConfigList(fboConfigListValue)
385*35238bceSAndroid Build Coastguard Worker         , framebufferSRGB(framebufferSRGBValue)
386*35238bceSAndroid Build Coastguard Worker         , frameBufferBlend(framebufferBendValue)
387*35238bceSAndroid Build Coastguard Worker         , testFunction(testFunctionValue)
388*35238bceSAndroid Build Coastguard Worker         , rendererTask(rendererTaskValue)
389*35238bceSAndroid Build Coastguard Worker     {
390*35238bceSAndroid Build Coastguard Worker     }
391*35238bceSAndroid Build Coastguard Worker 
~TestRenderPassConfigdeqp::gles31::Functional::__anon0174e0ff0111::TestRenderPassConfig392*35238bceSAndroid Build Coastguard Worker     ~TestRenderPassConfig(void)
393*35238bceSAndroid Build Coastguard Worker     {
394*35238bceSAndroid Build Coastguard Worker     }
395*35238bceSAndroid Build Coastguard Worker 
396*35238bceSAndroid Build Coastguard Worker     TextureSourcesType textureSourcesType;
397*35238bceSAndroid Build Coastguard Worker     std::vector<FBOConfig> fboConfigList;
398*35238bceSAndroid Build Coastguard Worker     FramebufferSRGB framebufferSRGB;
399*35238bceSAndroid Build Coastguard Worker     FramebufferBlend frameBufferBlend;
400*35238bceSAndroid Build Coastguard Worker     TestFunction testFunction;
401*35238bceSAndroid Build Coastguard Worker     RendererTask rendererTask;
402*35238bceSAndroid Build Coastguard Worker };
403*35238bceSAndroid Build Coastguard Worker 
404*35238bceSAndroid Build Coastguard Worker class TestVertexData
405*35238bceSAndroid Build Coastguard Worker {
406*35238bceSAndroid Build Coastguard Worker public:
407*35238bceSAndroid Build Coastguard Worker     TestVertexData(Context &context);
408*35238bceSAndroid Build Coastguard Worker     ~TestVertexData(void);
409*35238bceSAndroid Build Coastguard Worker 
410*35238bceSAndroid Build Coastguard Worker     void init(void);
411*35238bceSAndroid Build Coastguard Worker 
412*35238bceSAndroid Build Coastguard Worker     void bind(void) const;
413*35238bceSAndroid Build Coastguard Worker     void unbind(void) const;
414*35238bceSAndroid Build Coastguard Worker 
415*35238bceSAndroid Build Coastguard Worker private:
416*35238bceSAndroid Build Coastguard Worker     const glw::Functions *m_gl;
417*35238bceSAndroid Build Coastguard Worker     std::vector<float> m_data;
418*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_vboHandle;
419*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_vaoHandle;
420*35238bceSAndroid Build Coastguard Worker };
421*35238bceSAndroid Build Coastguard Worker 
TestVertexData(Context & context)422*35238bceSAndroid Build Coastguard Worker TestVertexData::TestVertexData(Context &context) : m_gl(&context.getRenderContext().getFunctions())
423*35238bceSAndroid Build Coastguard Worker {
424*35238bceSAndroid Build Coastguard Worker     const glw::GLfloat vertexData[] = {
425*35238bceSAndroid Build Coastguard Worker         // position                // texcoord
426*35238bceSAndroid Build Coastguard Worker         -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, // bottom left corner
427*35238bceSAndroid Build Coastguard Worker         1.0f,  -1.0f, 0.0f, 1.0f, 0.0f, // bottom right corner
428*35238bceSAndroid Build Coastguard Worker         1.0f,  1.0f,  0.0f, 1.0f, 1.0f, // Top right corner
429*35238bceSAndroid Build Coastguard Worker 
430*35238bceSAndroid Build Coastguard Worker         -1.0f, 1.0f,  0.0f, 0.0f, 1.0f, // top left corner
431*35238bceSAndroid Build Coastguard Worker         1.0f,  1.0f,  0.0f, 1.0f, 1.0f, // Top right corner
432*35238bceSAndroid Build Coastguard Worker         -1.0f, -1.0f, 0.0f, 0.0f, 0.0f  // bottom left corner
433*35238bceSAndroid Build Coastguard Worker     };
434*35238bceSAndroid Build Coastguard Worker 
435*35238bceSAndroid Build Coastguard Worker     m_data.resize(DE_LENGTH_OF_ARRAY(vertexData));
436*35238bceSAndroid Build Coastguard Worker     for (int idx = 0; idx < (int)m_data.size(); idx++)
437*35238bceSAndroid Build Coastguard Worker         m_data[idx] = vertexData[idx];
438*35238bceSAndroid Build Coastguard Worker 
439*35238bceSAndroid Build Coastguard Worker     m_gl->genVertexArrays(1, &m_vaoHandle);
440*35238bceSAndroid Build Coastguard Worker     m_gl->bindVertexArray(m_vaoHandle);
441*35238bceSAndroid Build Coastguard Worker 
442*35238bceSAndroid Build Coastguard Worker     m_gl->genBuffers(1, &m_vboHandle);
443*35238bceSAndroid Build Coastguard Worker     m_gl->bindBuffer(GL_ARRAY_BUFFER, m_vboHandle);
444*35238bceSAndroid Build Coastguard Worker 
445*35238bceSAndroid Build Coastguard Worker     m_gl->bufferData(GL_ARRAY_BUFFER, (glw::GLsizei)(m_data.size() * sizeof(glw::GLfloat)), &m_data[0], GL_STATIC_DRAW);
446*35238bceSAndroid Build Coastguard Worker 
447*35238bceSAndroid Build Coastguard Worker     m_gl->enableVertexAttribArray(0);
448*35238bceSAndroid Build Coastguard Worker     m_gl->vertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * (glw::GLsizei)sizeof(float), (glw::GLvoid *)0);
449*35238bceSAndroid Build Coastguard Worker     m_gl->enableVertexAttribArray(1);
450*35238bceSAndroid Build Coastguard Worker     m_gl->vertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * (glw::GLsizei)sizeof(float),
451*35238bceSAndroid Build Coastguard Worker                               (glw::GLvoid *)(3 * sizeof(float)));
452*35238bceSAndroid Build Coastguard Worker 
453*35238bceSAndroid Build Coastguard Worker     m_gl->bindVertexArray(0);
454*35238bceSAndroid Build Coastguard Worker     m_gl->bindBuffer(GL_ARRAY_BUFFER, 0);
455*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(m_gl->getError(), "gl error during vertex data setup");
456*35238bceSAndroid Build Coastguard Worker }
457*35238bceSAndroid Build Coastguard Worker 
~TestVertexData(void)458*35238bceSAndroid Build Coastguard Worker TestVertexData::~TestVertexData(void)
459*35238bceSAndroid Build Coastguard Worker {
460*35238bceSAndroid Build Coastguard Worker     m_gl->deleteBuffers(1, &m_vboHandle);
461*35238bceSAndroid Build Coastguard Worker     m_gl->deleteVertexArrays(1, &m_vaoHandle);
462*35238bceSAndroid Build Coastguard Worker }
463*35238bceSAndroid Build Coastguard Worker 
bind(void) const464*35238bceSAndroid Build Coastguard Worker void TestVertexData::bind(void) const
465*35238bceSAndroid Build Coastguard Worker {
466*35238bceSAndroid Build Coastguard Worker     m_gl->bindVertexArray(m_vaoHandle);
467*35238bceSAndroid Build Coastguard Worker }
468*35238bceSAndroid Build Coastguard Worker 
unbind(void) const469*35238bceSAndroid Build Coastguard Worker void TestVertexData::unbind(void) const
470*35238bceSAndroid Build Coastguard Worker {
471*35238bceSAndroid Build Coastguard Worker     m_gl->bindVertexArray(0);
472*35238bceSAndroid Build Coastguard Worker }
473*35238bceSAndroid Build Coastguard Worker 
474*35238bceSAndroid Build Coastguard Worker class TestTexture2D
475*35238bceSAndroid Build Coastguard Worker {
476*35238bceSAndroid Build Coastguard Worker public:
477*35238bceSAndroid Build Coastguard Worker     TestTexture2D(Context &context, const uint32_t internalFormatValue, const uint32_t transferFormatValue,
478*35238bceSAndroid Build Coastguard Worker                   const uint32_t transferTypeValue, const tcu::Vec4 imageColorValue);
479*35238bceSAndroid Build Coastguard Worker     ~TestTexture2D(void);
480*35238bceSAndroid Build Coastguard Worker 
481*35238bceSAndroid Build Coastguard Worker     int getTextureUnit(void) const;
482*35238bceSAndroid Build Coastguard Worker     uint32_t getHandle(void) const;
483*35238bceSAndroid Build Coastguard Worker 
484*35238bceSAndroid Build Coastguard Worker     void bind(const int textureUnit);
485*35238bceSAndroid Build Coastguard Worker     void unbind(void) const;
486*35238bceSAndroid Build Coastguard Worker 
487*35238bceSAndroid Build Coastguard Worker private:
488*35238bceSAndroid Build Coastguard Worker     const glw::Functions *m_gl;
489*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_handle;
490*35238bceSAndroid Build Coastguard Worker     const uint32_t m_internalFormat;
491*35238bceSAndroid Build Coastguard Worker     tcu::TextureFormat m_transferFormat;
492*35238bceSAndroid Build Coastguard Worker     int m_width;
493*35238bceSAndroid Build Coastguard Worker     int m_height;
494*35238bceSAndroid Build Coastguard Worker     tcu::TextureLevel m_imageData;
495*35238bceSAndroid Build Coastguard Worker     int m_textureUnit;
496*35238bceSAndroid Build Coastguard Worker };
497*35238bceSAndroid Build Coastguard Worker 
TestTexture2D(Context & context,const uint32_t internalFormat,const uint32_t transferFormat,const uint32_t transferType,const tcu::Vec4 imageColor)498*35238bceSAndroid Build Coastguard Worker TestTexture2D::TestTexture2D(Context &context, const uint32_t internalFormat, const uint32_t transferFormat,
499*35238bceSAndroid Build Coastguard Worker                              const uint32_t transferType, const tcu::Vec4 imageColor)
500*35238bceSAndroid Build Coastguard Worker     : m_gl(&context.getRenderContext().getFunctions())
501*35238bceSAndroid Build Coastguard Worker     , m_internalFormat(internalFormat)
502*35238bceSAndroid Build Coastguard Worker     , m_transferFormat(tcu::TextureFormat(glu::mapGLTransferFormat(transferFormat, transferType)))
503*35238bceSAndroid Build Coastguard Worker     , m_width(TestTextureSizes::WIDTH)
504*35238bceSAndroid Build Coastguard Worker     , m_height(TestTextureSizes::HEIGHT)
505*35238bceSAndroid Build Coastguard Worker     , m_imageData(tcu::TextureLevel(glu::mapGLInternalFormat(internalFormat), m_width, m_height, 1))
506*35238bceSAndroid Build Coastguard Worker {
507*35238bceSAndroid Build Coastguard Worker     // fill image data with a solid test color
508*35238bceSAndroid Build Coastguard Worker     tcu::clear(m_imageData.getAccess(), tcu::Vec4(0.0f));
509*35238bceSAndroid Build Coastguard Worker     for (int py = 0; py < m_imageData.getHeight(); py++)
510*35238bceSAndroid Build Coastguard Worker     {
511*35238bceSAndroid Build Coastguard Worker         for (int px = 0; px < m_imageData.getWidth(); px++)
512*35238bceSAndroid Build Coastguard Worker             m_imageData.getAccess().setPixel(imageColor, px, py);
513*35238bceSAndroid Build Coastguard Worker     }
514*35238bceSAndroid Build Coastguard Worker 
515*35238bceSAndroid Build Coastguard Worker     m_gl->genTextures(1, &m_handle);
516*35238bceSAndroid Build Coastguard Worker 
517*35238bceSAndroid Build Coastguard Worker     m_gl->bindTexture(GL_TEXTURE_2D, m_handle);
518*35238bceSAndroid Build Coastguard Worker     m_gl->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
519*35238bceSAndroid Build Coastguard Worker     m_gl->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
520*35238bceSAndroid Build Coastguard Worker     m_gl->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
521*35238bceSAndroid Build Coastguard Worker     m_gl->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
522*35238bceSAndroid Build Coastguard Worker 
523*35238bceSAndroid Build Coastguard Worker     m_gl->texImage2D(GL_TEXTURE_2D, 0, m_internalFormat, m_width, m_height, 0, transferFormat, transferType,
524*35238bceSAndroid Build Coastguard Worker                      m_imageData.getAccess().getDataPtr());
525*35238bceSAndroid Build Coastguard Worker 
526*35238bceSAndroid Build Coastguard Worker     m_gl->bindTexture(GL_TEXTURE_2D, 0);
527*35238bceSAndroid Build Coastguard Worker }
528*35238bceSAndroid Build Coastguard Worker 
~TestTexture2D(void)529*35238bceSAndroid Build Coastguard Worker TestTexture2D::~TestTexture2D(void)
530*35238bceSAndroid Build Coastguard Worker {
531*35238bceSAndroid Build Coastguard Worker     m_gl->deleteTextures(1, &m_handle);
532*35238bceSAndroid Build Coastguard Worker }
533*35238bceSAndroid Build Coastguard Worker 
getTextureUnit(void) const534*35238bceSAndroid Build Coastguard Worker int TestTexture2D::getTextureUnit(void) const
535*35238bceSAndroid Build Coastguard Worker {
536*35238bceSAndroid Build Coastguard Worker     return m_textureUnit;
537*35238bceSAndroid Build Coastguard Worker }
538*35238bceSAndroid Build Coastguard Worker 
getHandle(void) const539*35238bceSAndroid Build Coastguard Worker uint32_t TestTexture2D::getHandle(void) const
540*35238bceSAndroid Build Coastguard Worker {
541*35238bceSAndroid Build Coastguard Worker     return m_handle;
542*35238bceSAndroid Build Coastguard Worker }
543*35238bceSAndroid Build Coastguard Worker 
bind(const int textureUnit)544*35238bceSAndroid Build Coastguard Worker void TestTexture2D::bind(const int textureUnit)
545*35238bceSAndroid Build Coastguard Worker {
546*35238bceSAndroid Build Coastguard Worker     m_textureUnit = textureUnit;
547*35238bceSAndroid Build Coastguard Worker     m_gl->activeTexture(GL_TEXTURE0 + m_textureUnit);
548*35238bceSAndroid Build Coastguard Worker     m_gl->bindTexture(GL_TEXTURE_2D, m_handle);
549*35238bceSAndroid Build Coastguard Worker }
550*35238bceSAndroid Build Coastguard Worker 
unbind(void) const551*35238bceSAndroid Build Coastguard Worker void TestTexture2D::unbind(void) const
552*35238bceSAndroid Build Coastguard Worker {
553*35238bceSAndroid Build Coastguard Worker     m_gl->bindTexture(GL_TEXTURE_2D, 0);
554*35238bceSAndroid Build Coastguard Worker }
555*35238bceSAndroid Build Coastguard Worker 
556*35238bceSAndroid Build Coastguard Worker class TestFramebuffer
557*35238bceSAndroid Build Coastguard Worker {
558*35238bceSAndroid Build Coastguard Worker public:
559*35238bceSAndroid Build Coastguard Worker     TestFramebuffer(void);
560*35238bceSAndroid Build Coastguard Worker     TestFramebuffer(Context &context, const uint32_t targetType, const uint32_t colorAttachment,
561*35238bceSAndroid Build Coastguard Worker                     glw::GLuint textureAttachmentHandle, const bool isSRGB, const FboType fboType, const int idx);
562*35238bceSAndroid Build Coastguard Worker     ~TestFramebuffer(void);
563*35238bceSAndroid Build Coastguard Worker 
564*35238bceSAndroid Build Coastguard Worker     void setTargetType(const uint32_t targetType);
565*35238bceSAndroid Build Coastguard Worker 
566*35238bceSAndroid Build Coastguard Worker     FboType getType(void) const;
567*35238bceSAndroid Build Coastguard Worker     uint32_t getColorAttachment(void) const;
568*35238bceSAndroid Build Coastguard Worker     int getIdx(void) const;
569*35238bceSAndroid Build Coastguard Worker 
570*35238bceSAndroid Build Coastguard Worker     void bind(void);
571*35238bceSAndroid Build Coastguard Worker     void unbind(void);
572*35238bceSAndroid Build Coastguard Worker 
573*35238bceSAndroid Build Coastguard Worker     typedef de::UniquePtr<glu::Framebuffer> fboUniquePtr;
574*35238bceSAndroid Build Coastguard Worker 
575*35238bceSAndroid Build Coastguard Worker private:
576*35238bceSAndroid Build Coastguard Worker     const glw::Functions *m_gl;
577*35238bceSAndroid Build Coastguard Worker     fboUniquePtr m_referenceSource;
578*35238bceSAndroid Build Coastguard Worker     uint32_t m_targetType;
579*35238bceSAndroid Build Coastguard Worker     bool m_bound;
580*35238bceSAndroid Build Coastguard Worker     bool m_isSRGB;
581*35238bceSAndroid Build Coastguard Worker     FboType m_type;
582*35238bceSAndroid Build Coastguard Worker     const int m_idx;
583*35238bceSAndroid Build Coastguard Worker     uint32_t m_colorAttachment;
584*35238bceSAndroid Build Coastguard Worker };
585*35238bceSAndroid Build Coastguard Worker 
TestFramebuffer(Context & context,const uint32_t targetType,const uint32_t colorAttachment,glw::GLuint textureAttachmentHandle,const bool isSRGB,const FboType fboType,const int idx)586*35238bceSAndroid Build Coastguard Worker TestFramebuffer::TestFramebuffer(Context &context, const uint32_t targetType, const uint32_t colorAttachment,
587*35238bceSAndroid Build Coastguard Worker                                  glw::GLuint textureAttachmentHandle, const bool isSRGB, const FboType fboType,
588*35238bceSAndroid Build Coastguard Worker                                  const int idx)
589*35238bceSAndroid Build Coastguard Worker     : m_gl(&context.getRenderContext().getFunctions())
590*35238bceSAndroid Build Coastguard Worker     , m_referenceSource(new glu::Framebuffer(context.getRenderContext()))
591*35238bceSAndroid Build Coastguard Worker     , m_targetType(targetType)
592*35238bceSAndroid Build Coastguard Worker     , m_bound(false)
593*35238bceSAndroid Build Coastguard Worker     , m_isSRGB(isSRGB)
594*35238bceSAndroid Build Coastguard Worker     , m_type(fboType)
595*35238bceSAndroid Build Coastguard Worker     , m_idx(idx)
596*35238bceSAndroid Build Coastguard Worker     , m_colorAttachment(colorAttachment)
597*35238bceSAndroid Build Coastguard Worker {
598*35238bceSAndroid Build Coastguard Worker     m_gl->bindFramebuffer(m_targetType, **m_referenceSource);
599*35238bceSAndroid Build Coastguard Worker 
600*35238bceSAndroid Build Coastguard Worker     m_gl->framebufferTexture2D(m_targetType, m_colorAttachment, GL_TEXTURE_2D, textureAttachmentHandle, 0);
601*35238bceSAndroid Build Coastguard Worker 
602*35238bceSAndroid Build Coastguard Worker     TCU_CHECK(m_gl->checkFramebufferStatus(m_targetType) == GL_FRAMEBUFFER_COMPLETE);
603*35238bceSAndroid Build Coastguard Worker 
604*35238bceSAndroid Build Coastguard Worker     if (targetType == GL_DRAW_BUFFER)
605*35238bceSAndroid Build Coastguard Worker     {
606*35238bceSAndroid Build Coastguard Worker         glw::GLuint textureAttachments[] = {m_colorAttachment};
607*35238bceSAndroid Build Coastguard Worker         m_gl->drawBuffers(DE_LENGTH_OF_ARRAY(textureAttachments), textureAttachments);
608*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(m_gl->getError(), "glDrawBuffer()");
609*35238bceSAndroid Build Coastguard Worker     }
610*35238bceSAndroid Build Coastguard Worker 
611*35238bceSAndroid Build Coastguard Worker     if (targetType == GL_READ_BUFFER)
612*35238bceSAndroid Build Coastguard Worker     {
613*35238bceSAndroid Build Coastguard Worker         m_gl->readBuffer(m_colorAttachment);
614*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(m_gl->getError(), "glReadBuffer()");
615*35238bceSAndroid Build Coastguard Worker     }
616*35238bceSAndroid Build Coastguard Worker 
617*35238bceSAndroid Build Coastguard Worker     m_gl->bindFramebuffer(m_targetType, 0);
618*35238bceSAndroid Build Coastguard Worker }
619*35238bceSAndroid Build Coastguard Worker 
~TestFramebuffer(void)620*35238bceSAndroid Build Coastguard Worker TestFramebuffer::~TestFramebuffer(void)
621*35238bceSAndroid Build Coastguard Worker {
622*35238bceSAndroid Build Coastguard Worker }
623*35238bceSAndroid Build Coastguard Worker 
setTargetType(const uint32_t targetType)624*35238bceSAndroid Build Coastguard Worker void TestFramebuffer::setTargetType(const uint32_t targetType)
625*35238bceSAndroid Build Coastguard Worker {
626*35238bceSAndroid Build Coastguard Worker     m_targetType = targetType;
627*35238bceSAndroid Build Coastguard Worker }
628*35238bceSAndroid Build Coastguard Worker 
getType(void) const629*35238bceSAndroid Build Coastguard Worker FboType TestFramebuffer::getType(void) const
630*35238bceSAndroid Build Coastguard Worker {
631*35238bceSAndroid Build Coastguard Worker     return m_type;
632*35238bceSAndroid Build Coastguard Worker }
633*35238bceSAndroid Build Coastguard Worker 
getColorAttachment(void) const634*35238bceSAndroid Build Coastguard Worker uint32_t TestFramebuffer::getColorAttachment(void) const
635*35238bceSAndroid Build Coastguard Worker {
636*35238bceSAndroid Build Coastguard Worker     return m_colorAttachment;
637*35238bceSAndroid Build Coastguard Worker }
638*35238bceSAndroid Build Coastguard Worker 
getIdx(void) const639*35238bceSAndroid Build Coastguard Worker int TestFramebuffer::getIdx(void) const
640*35238bceSAndroid Build Coastguard Worker {
641*35238bceSAndroid Build Coastguard Worker     return m_idx;
642*35238bceSAndroid Build Coastguard Worker }
643*35238bceSAndroid Build Coastguard Worker 
bind(void)644*35238bceSAndroid Build Coastguard Worker void TestFramebuffer::bind(void)
645*35238bceSAndroid Build Coastguard Worker {
646*35238bceSAndroid Build Coastguard Worker     if (!m_bound)
647*35238bceSAndroid Build Coastguard Worker     {
648*35238bceSAndroid Build Coastguard Worker         m_gl->bindFramebuffer(m_targetType, **m_referenceSource);
649*35238bceSAndroid Build Coastguard Worker         m_bound = true;
650*35238bceSAndroid Build Coastguard Worker     }
651*35238bceSAndroid Build Coastguard Worker }
652*35238bceSAndroid Build Coastguard Worker 
unbind(void)653*35238bceSAndroid Build Coastguard Worker void TestFramebuffer::unbind(void)
654*35238bceSAndroid Build Coastguard Worker {
655*35238bceSAndroid Build Coastguard Worker     if (m_bound)
656*35238bceSAndroid Build Coastguard Worker     {
657*35238bceSAndroid Build Coastguard Worker         m_gl->bindFramebuffer(m_targetType, 0);
658*35238bceSAndroid Build Coastguard Worker         m_bound = false;
659*35238bceSAndroid Build Coastguard Worker     }
660*35238bceSAndroid Build Coastguard Worker }
661*35238bceSAndroid Build Coastguard Worker 
662*35238bceSAndroid Build Coastguard Worker class TestShaderProgram
663*35238bceSAndroid Build Coastguard Worker {
664*35238bceSAndroid Build Coastguard Worker public:
665*35238bceSAndroid Build Coastguard Worker     TestShaderProgram(Context &context, const int samplerTotal, TestFunction testFunction);
666*35238bceSAndroid Build Coastguard Worker     ~TestShaderProgram(void);
667*35238bceSAndroid Build Coastguard Worker 
668*35238bceSAndroid Build Coastguard Worker     glw::GLuint getHandle(void) const;
669*35238bceSAndroid Build Coastguard Worker 
670*35238bceSAndroid Build Coastguard Worker     void use(void) const;
671*35238bceSAndroid Build Coastguard Worker     void unuse(void) const;
672*35238bceSAndroid Build Coastguard Worker 
673*35238bceSAndroid Build Coastguard Worker     glu::ShaderProgramInfo getLogInfo(void);
674*35238bceSAndroid Build Coastguard Worker 
675*35238bceSAndroid Build Coastguard Worker private:
676*35238bceSAndroid Build Coastguard Worker     const glw::Functions *m_gl;
677*35238bceSAndroid Build Coastguard Worker     de::MovePtr<glu::ShaderProgram> m_referenceSource;
678*35238bceSAndroid Build Coastguard Worker     const int m_samplerTotal;
679*35238bceSAndroid Build Coastguard Worker     const int m_shaderStagesTotal;
680*35238bceSAndroid Build Coastguard Worker };
681*35238bceSAndroid Build Coastguard Worker 
TestShaderProgram(Context & context,const int samplerTotal,TestFunction testFunction)682*35238bceSAndroid Build Coastguard Worker TestShaderProgram::TestShaderProgram(Context &context, const int samplerTotal, TestFunction testFunction)
683*35238bceSAndroid Build Coastguard Worker     : m_gl(&context.getRenderContext().getFunctions())
684*35238bceSAndroid Build Coastguard Worker     , m_samplerTotal(samplerTotal)
685*35238bceSAndroid Build Coastguard Worker     , m_shaderStagesTotal(2)
686*35238bceSAndroid Build Coastguard Worker {
687*35238bceSAndroid Build Coastguard Worker     std::ostringstream shaderFragment;
688*35238bceSAndroid Build Coastguard Worker 
689*35238bceSAndroid Build Coastguard Worker     const char *const shaderVertex = "#version 310 es \n"
690*35238bceSAndroid Build Coastguard Worker                                      "layout (location = 0) in mediump vec3 aPosition; \n"
691*35238bceSAndroid Build Coastguard Worker                                      "layout (location = 1) in mediump vec2 aTexCoord; \n"
692*35238bceSAndroid Build Coastguard Worker                                      "out mediump vec2 vs_aTexCoord; \n"
693*35238bceSAndroid Build Coastguard Worker                                      "void main () \n"
694*35238bceSAndroid Build Coastguard Worker                                      "{ \n"
695*35238bceSAndroid Build Coastguard Worker                                      "    gl_Position = vec4(aPosition, 1.0f); \n"
696*35238bceSAndroid Build Coastguard Worker                                      "    vs_aTexCoord = aTexCoord; \n"
697*35238bceSAndroid Build Coastguard Worker                                      "} \n";
698*35238bceSAndroid Build Coastguard Worker 
699*35238bceSAndroid Build Coastguard Worker     shaderFragment << "#version 310 es \n"
700*35238bceSAndroid Build Coastguard Worker                    << "in mediump vec2 vs_aTexCoord; \n"
701*35238bceSAndroid Build Coastguard Worker                    << "layout (location = 0) out mediump vec4 fs_aColor0; \n";
702*35238bceSAndroid Build Coastguard Worker 
703*35238bceSAndroid Build Coastguard Worker     for (int samplerIdx = 0; samplerIdx < m_samplerTotal; samplerIdx++)
704*35238bceSAndroid Build Coastguard Worker         shaderFragment << "uniform sampler2D uTexture" << samplerIdx << "; \n";
705*35238bceSAndroid Build Coastguard Worker 
706*35238bceSAndroid Build Coastguard Worker     shaderFragment << "uniform int uFunctionType; \n";
707*35238bceSAndroid Build Coastguard Worker 
708*35238bceSAndroid Build Coastguard Worker     if (testFunction.hasFunction)
709*35238bceSAndroid Build Coastguard Worker         shaderFragment << "uniform int uBlendFunctionType; \n"
710*35238bceSAndroid Build Coastguard Worker                        << "uniform mediump float uFactorSrc; \n"
711*35238bceSAndroid Build Coastguard Worker                        << "uniform mediump float uFactorDst; \n"
712*35238bceSAndroid Build Coastguard Worker                        << testFunction.functionDefintion;
713*35238bceSAndroid Build Coastguard Worker 
714*35238bceSAndroid Build Coastguard Worker     shaderFragment << "void main () \n"
715*35238bceSAndroid Build Coastguard Worker                    << "{ \n";
716*35238bceSAndroid Build Coastguard Worker 
717*35238bceSAndroid Build Coastguard Worker     for (int samplerIdx = 0; samplerIdx < m_samplerTotal; samplerIdx++)
718*35238bceSAndroid Build Coastguard Worker         shaderFragment << "    mediump vec4 texelColor" << samplerIdx << " = vec4(0.0f, 0.0f, 0.0f, 1.0f); \n";
719*35238bceSAndroid Build Coastguard Worker 
720*35238bceSAndroid Build Coastguard Worker     shaderFragment << buildSamplingPassType(m_samplerTotal);
721*35238bceSAndroid Build Coastguard Worker 
722*35238bceSAndroid Build Coastguard Worker     if (testFunction.hasFunction)
723*35238bceSAndroid Build Coastguard Worker         shaderFragment << "    fs_aColor0 = " << testFunction.functionName << "(texelColor0, texelColor1); \n";
724*35238bceSAndroid Build Coastguard Worker     else
725*35238bceSAndroid Build Coastguard Worker         shaderFragment << "    fs_aColor0 = texelColor0; \n";
726*35238bceSAndroid Build Coastguard Worker 
727*35238bceSAndroid Build Coastguard Worker     shaderFragment << "} \n";
728*35238bceSAndroid Build Coastguard Worker 
729*35238bceSAndroid Build Coastguard Worker     m_referenceSource = de::MovePtr<glu::ShaderProgram>(new glu::ShaderProgram(
730*35238bceSAndroid Build Coastguard Worker         context.getRenderContext(), glu::makeVtxFragSources(shaderVertex, shaderFragment.str())));
731*35238bceSAndroid Build Coastguard Worker     if (!m_referenceSource->isOk())
732*35238bceSAndroid Build Coastguard Worker     {
733*35238bceSAndroid Build Coastguard Worker         tcu::TestLog &log = context.getTestContext().getLog();
734*35238bceSAndroid Build Coastguard Worker         log << this->getLogInfo();
735*35238bceSAndroid Build Coastguard Worker         TCU_FAIL("Failed to compile shaders and link program");
736*35238bceSAndroid Build Coastguard Worker     }
737*35238bceSAndroid Build Coastguard Worker }
738*35238bceSAndroid Build Coastguard Worker 
~TestShaderProgram(void)739*35238bceSAndroid Build Coastguard Worker TestShaderProgram::~TestShaderProgram(void)
740*35238bceSAndroid Build Coastguard Worker {
741*35238bceSAndroid Build Coastguard Worker     m_referenceSource = de::MovePtr<glu::ShaderProgram>(DE_NULL);
742*35238bceSAndroid Build Coastguard Worker     m_referenceSource.clear();
743*35238bceSAndroid Build Coastguard Worker }
744*35238bceSAndroid Build Coastguard Worker 
getHandle(void) const745*35238bceSAndroid Build Coastguard Worker uint32_t TestShaderProgram::getHandle(void) const
746*35238bceSAndroid Build Coastguard Worker {
747*35238bceSAndroid Build Coastguard Worker     return m_referenceSource->getProgram();
748*35238bceSAndroid Build Coastguard Worker }
749*35238bceSAndroid Build Coastguard Worker 
use(void) const750*35238bceSAndroid Build Coastguard Worker void TestShaderProgram::use(void) const
751*35238bceSAndroid Build Coastguard Worker {
752*35238bceSAndroid Build Coastguard Worker     m_gl->useProgram(this->getHandle());
753*35238bceSAndroid Build Coastguard Worker }
754*35238bceSAndroid Build Coastguard Worker 
unuse(void) const755*35238bceSAndroid Build Coastguard Worker void TestShaderProgram::unuse(void) const
756*35238bceSAndroid Build Coastguard Worker {
757*35238bceSAndroid Build Coastguard Worker     m_gl->useProgram(0);
758*35238bceSAndroid Build Coastguard Worker }
759*35238bceSAndroid Build Coastguard Worker 
getLogInfo(void)760*35238bceSAndroid Build Coastguard Worker glu::ShaderProgramInfo TestShaderProgram::getLogInfo(void)
761*35238bceSAndroid Build Coastguard Worker {
762*35238bceSAndroid Build Coastguard Worker     glu::ShaderProgramInfo buildInfo;
763*35238bceSAndroid Build Coastguard Worker 
764*35238bceSAndroid Build Coastguard Worker     // log shader program info. Only vertex and fragment shaders included
765*35238bceSAndroid Build Coastguard Worker     buildInfo.program = m_referenceSource->getProgramInfo();
766*35238bceSAndroid Build Coastguard Worker     for (int shaderIdx = 0; shaderIdx < m_shaderStagesTotal; shaderIdx++)
767*35238bceSAndroid Build Coastguard Worker     {
768*35238bceSAndroid Build Coastguard Worker         glu::ShaderInfo shaderInfo = m_referenceSource->getShaderInfo(
769*35238bceSAndroid Build Coastguard Worker             static_cast<glu::ShaderType>(static_cast<int>(glu::SHADERTYPE_VERTEX) + static_cast<int>(shaderIdx)), 0);
770*35238bceSAndroid Build Coastguard Worker         buildInfo.shaders.push_back(shaderInfo);
771*35238bceSAndroid Build Coastguard Worker     }
772*35238bceSAndroid Build Coastguard Worker     return buildInfo;
773*35238bceSAndroid Build Coastguard Worker }
774*35238bceSAndroid Build Coastguard Worker 
775*35238bceSAndroid Build Coastguard Worker class Renderer
776*35238bceSAndroid Build Coastguard Worker {
777*35238bceSAndroid Build Coastguard Worker public:
778*35238bceSAndroid Build Coastguard Worker     Renderer(Context &context);
779*35238bceSAndroid Build Coastguard Worker     ~Renderer(void);
780*35238bceSAndroid Build Coastguard Worker 
781*35238bceSAndroid Build Coastguard Worker     void init(const TestRenderPassConfig &renderPassConfig, const int renderpass);
782*35238bceSAndroid Build Coastguard Worker     void deinit(void);
783*35238bceSAndroid Build Coastguard Worker 
784*35238bceSAndroid Build Coastguard Worker     void setSamplingType(const SamplingType samplerIdx);
785*35238bceSAndroid Build Coastguard Worker     void setBlendIteration(const int blendIteration);
786*35238bceSAndroid Build Coastguard Worker     void setFramebufferBlend(const bool blend);
787*35238bceSAndroid Build Coastguard Worker     void setFramebufferSRGB(const bool sRGB);
788*35238bceSAndroid Build Coastguard Worker 
789*35238bceSAndroid Build Coastguard Worker     std::vector<tcu::Vec4> getResultsPreDraw(void) const;
790*35238bceSAndroid Build Coastguard Worker     std::vector<tcu::Vec4> getResultsPostDraw(void) const;
791*35238bceSAndroid Build Coastguard Worker     int getBlendConfigCount(void) const;
792*35238bceSAndroid Build Coastguard Worker     glu::ShaderProgramInfo getShaderProgramInfo(void);
793*35238bceSAndroid Build Coastguard Worker 
794*35238bceSAndroid Build Coastguard Worker     void copyFrameBufferTexture(const int srcPx, const int srcPy, const int dstPx, const int dstPy);
795*35238bceSAndroid Build Coastguard Worker     void draw(void);
796*35238bceSAndroid Build Coastguard Worker     void storeShaderProgramInfo(void);
797*35238bceSAndroid Build Coastguard Worker     void logShaderProgramInfo(void);
798*35238bceSAndroid Build Coastguard Worker 
799*35238bceSAndroid Build Coastguard Worker     typedef de::SharedPtr<TestTexture2D> TextureSp;
800*35238bceSAndroid Build Coastguard Worker     typedef de::SharedPtr<TestFramebuffer> FboSp;
801*35238bceSAndroid Build Coastguard Worker 
802*35238bceSAndroid Build Coastguard Worker private:
803*35238bceSAndroid Build Coastguard Worker     void createFBOwithColorAttachment(const std::vector<FBOConfig> fboConfigList);
804*35238bceSAndroid Build Coastguard Worker     void setShaderProgramSamplingType(const int samplerIdx);
805*35238bceSAndroid Build Coastguard Worker     void setShaderBlendFunctionType(void);
806*35238bceSAndroid Build Coastguard Worker     void setShaderBlendSrcDstValues(void);
807*35238bceSAndroid Build Coastguard Worker     void bindActiveTexturesSamplers(void);
808*35238bceSAndroid Build Coastguard Worker     void bindAllRequiredSourceTextures(const TextureSourcesType texturesRequired);
809*35238bceSAndroid Build Coastguard Worker     void unbindAllSourceTextures(void);
810*35238bceSAndroid Build Coastguard Worker     void bindFramebuffer(const int framebufferIdx);
811*35238bceSAndroid Build Coastguard Worker     void unbindFramebuffer(const int framebufferIdx);
812*35238bceSAndroid Build Coastguard Worker     void enableFramebufferSRGB(void);
813*35238bceSAndroid Build Coastguard Worker     void enableFramebufferBlend(void);
814*35238bceSAndroid Build Coastguard Worker     bool isFramebufferAttachmentSRGB(const uint32_t targetType, const uint32_t attachment) const;
815*35238bceSAndroid Build Coastguard Worker     void readTexels(const int px, const int py, const uint32_t attachment, tcu::Vec4 &texelData);
816*35238bceSAndroid Build Coastguard Worker     void logState(const uint32_t targetType, const uint32_t attachment, const SamplingType samplingType) const;
817*35238bceSAndroid Build Coastguard Worker 
818*35238bceSAndroid Build Coastguard Worker     // renderer specific constants initialized during constructor
819*35238bceSAndroid Build Coastguard Worker     Context &m_context;
820*35238bceSAndroid Build Coastguard Worker     const TestVertexData m_vertexData;
821*35238bceSAndroid Build Coastguard Worker     const int m_textureSourceTotal;
822*35238bceSAndroid Build Coastguard Worker 
823*35238bceSAndroid Build Coastguard Worker     // additional resources monitored by the renderer
824*35238bceSAndroid Build Coastguard Worker     std::vector<BlendConfig> m_blendConfigList;
825*35238bceSAndroid Build Coastguard Worker     std::vector<TextureSp> m_textureSourceList;
826*35238bceSAndroid Build Coastguard Worker     TestRenderPassConfig m_renderPassConfig;
827*35238bceSAndroid Build Coastguard Worker     std::vector<TextureSp> m_fboTextureList;
828*35238bceSAndroid Build Coastguard Worker     TestShaderProgram *m_shaderProgram;
829*35238bceSAndroid Build Coastguard Worker     std::vector<FboSp> m_framebufferList;
830*35238bceSAndroid Build Coastguard Worker     std::vector<tcu::Vec4> m_resultsListPreDraw;
831*35238bceSAndroid Build Coastguard Worker     std::vector<tcu::Vec4> m_resultsListPostDraw;
832*35238bceSAndroid Build Coastguard Worker 
833*35238bceSAndroid Build Coastguard Worker     // mutable state variables (internal access only)
834*35238bceSAndroid Build Coastguard Worker     bool m_hasShaderProgramInfo;
835*35238bceSAndroid Build Coastguard Worker     int m_renderPass;
836*35238bceSAndroid Build Coastguard Worker     int m_samplersRequired;
837*35238bceSAndroid Build Coastguard Worker     bool m_hasFunction;
838*35238bceSAndroid Build Coastguard Worker     bool m_blittingEnabled;
839*35238bceSAndroid Build Coastguard Worker     glu::ShaderProgramInfo m_shaderProgramInfo;
840*35238bceSAndroid Build Coastguard Worker 
841*35238bceSAndroid Build Coastguard Worker     // mutable state variables (external access via setters)
842*35238bceSAndroid Build Coastguard Worker     SamplingType m_samplingType;
843*35238bceSAndroid Build Coastguard Worker     int m_blendIteration;
844*35238bceSAndroid Build Coastguard Worker     bool m_framebufferBlendEnabled;
845*35238bceSAndroid Build Coastguard Worker     bool m_framebufferSRGBEnabled;
846*35238bceSAndroid Build Coastguard Worker };
847*35238bceSAndroid Build Coastguard Worker 
Renderer(Context & context)848*35238bceSAndroid Build Coastguard Worker Renderer::Renderer(Context &context)
849*35238bceSAndroid Build Coastguard Worker     : m_context(context)
850*35238bceSAndroid Build Coastguard Worker     , m_vertexData(context)
851*35238bceSAndroid Build Coastguard Worker     , m_textureSourceTotal(2)
852*35238bceSAndroid Build Coastguard Worker     , m_blendConfigList(getBlendingConfigList())
853*35238bceSAndroid Build Coastguard Worker     , m_hasShaderProgramInfo(false)
854*35238bceSAndroid Build Coastguard Worker {
855*35238bceSAndroid Build Coastguard Worker     TextureSp textureLinear(new TestTexture2D(m_context, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, getTestColorLinear()));
856*35238bceSAndroid Build Coastguard Worker     m_textureSourceList.push_back(textureLinear);
857*35238bceSAndroid Build Coastguard Worker 
858*35238bceSAndroid Build Coastguard Worker     TextureSp textureSRGB(
859*35238bceSAndroid Build Coastguard Worker         new TestTexture2D(m_context, GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, getTestColorLinear()));
860*35238bceSAndroid Build Coastguard Worker     m_textureSourceList.push_back(textureSRGB);
861*35238bceSAndroid Build Coastguard Worker }
862*35238bceSAndroid Build Coastguard Worker 
~Renderer(void)863*35238bceSAndroid Build Coastguard Worker Renderer::~Renderer(void)
864*35238bceSAndroid Build Coastguard Worker {
865*35238bceSAndroid Build Coastguard Worker     m_textureSourceList.clear();
866*35238bceSAndroid Build Coastguard Worker     this->deinit();
867*35238bceSAndroid Build Coastguard Worker }
868*35238bceSAndroid Build Coastguard Worker 
init(const TestRenderPassConfig & renderPassConfig,const int renderpass)869*35238bceSAndroid Build Coastguard Worker void Renderer::init(const TestRenderPassConfig &renderPassConfig, const int renderpass)
870*35238bceSAndroid Build Coastguard Worker {
871*35238bceSAndroid Build Coastguard Worker     m_renderPassConfig = renderPassConfig;
872*35238bceSAndroid Build Coastguard Worker     m_renderPass       = renderpass;
873*35238bceSAndroid Build Coastguard Worker 
874*35238bceSAndroid Build Coastguard Worker     this->createFBOwithColorAttachment(m_renderPassConfig.fboConfigList);
875*35238bceSAndroid Build Coastguard Worker 
876*35238bceSAndroid Build Coastguard Worker     if (m_renderPassConfig.textureSourcesType != TEXTURESOURCESTYPE_NONE)
877*35238bceSAndroid Build Coastguard Worker     {
878*35238bceSAndroid Build Coastguard Worker         if (m_renderPassConfig.textureSourcesType == TEXTURESOURCESTYPE_RGBA ||
879*35238bceSAndroid Build Coastguard Worker             m_renderPassConfig.textureSourcesType == TEXTURESOURCESTYPE_SRGBA)
880*35238bceSAndroid Build Coastguard Worker             m_samplersRequired = 1;
881*35238bceSAndroid Build Coastguard Worker         else if (m_renderPassConfig.textureSourcesType == TEXTURESOURCESTYPE_BOTH)
882*35238bceSAndroid Build Coastguard Worker             m_samplersRequired = 2;
883*35238bceSAndroid Build Coastguard Worker         else
884*35238bceSAndroid Build Coastguard Worker             DE_FATAL("Error: Texture source required not recognised");
885*35238bceSAndroid Build Coastguard Worker 
886*35238bceSAndroid Build Coastguard Worker         m_shaderProgram = new TestShaderProgram(m_context, m_samplersRequired, m_renderPassConfig.testFunction);
887*35238bceSAndroid Build Coastguard Worker         m_hasFunction   = m_renderPassConfig.testFunction.hasFunction;
888*35238bceSAndroid Build Coastguard Worker     }
889*35238bceSAndroid Build Coastguard Worker     else
890*35238bceSAndroid Build Coastguard Worker         m_shaderProgram = DE_NULL;
891*35238bceSAndroid Build Coastguard Worker }
892*35238bceSAndroid Build Coastguard Worker 
deinit(void)893*35238bceSAndroid Build Coastguard Worker void Renderer::deinit(void)
894*35238bceSAndroid Build Coastguard Worker {
895*35238bceSAndroid Build Coastguard Worker     if (m_shaderProgram != DE_NULL)
896*35238bceSAndroid Build Coastguard Worker     {
897*35238bceSAndroid Build Coastguard Worker         delete m_shaderProgram;
898*35238bceSAndroid Build Coastguard Worker         m_shaderProgram = DE_NULL;
899*35238bceSAndroid Build Coastguard Worker     }
900*35238bceSAndroid Build Coastguard Worker 
901*35238bceSAndroid Build Coastguard Worker     m_fboTextureList.clear();
902*35238bceSAndroid Build Coastguard Worker     m_framebufferList.clear();
903*35238bceSAndroid Build Coastguard Worker }
904*35238bceSAndroid Build Coastguard Worker 
setSamplingType(const SamplingType samplingType)905*35238bceSAndroid Build Coastguard Worker void Renderer::setSamplingType(const SamplingType samplingType)
906*35238bceSAndroid Build Coastguard Worker {
907*35238bceSAndroid Build Coastguard Worker     m_samplingType = samplingType;
908*35238bceSAndroid Build Coastguard Worker }
909*35238bceSAndroid Build Coastguard Worker 
setBlendIteration(const int blendIteration)910*35238bceSAndroid Build Coastguard Worker void Renderer::setBlendIteration(const int blendIteration)
911*35238bceSAndroid Build Coastguard Worker {
912*35238bceSAndroid Build Coastguard Worker     m_blendIteration = blendIteration;
913*35238bceSAndroid Build Coastguard Worker }
914*35238bceSAndroid Build Coastguard Worker 
setFramebufferBlend(const bool blend)915*35238bceSAndroid Build Coastguard Worker void Renderer::setFramebufferBlend(const bool blend)
916*35238bceSAndroid Build Coastguard Worker {
917*35238bceSAndroid Build Coastguard Worker     m_framebufferBlendEnabled = blend;
918*35238bceSAndroid Build Coastguard Worker }
919*35238bceSAndroid Build Coastguard Worker 
setFramebufferSRGB(const bool sRGB)920*35238bceSAndroid Build Coastguard Worker void Renderer::setFramebufferSRGB(const bool sRGB)
921*35238bceSAndroid Build Coastguard Worker {
922*35238bceSAndroid Build Coastguard Worker     m_framebufferSRGBEnabled = sRGB;
923*35238bceSAndroid Build Coastguard Worker }
924*35238bceSAndroid Build Coastguard Worker 
getResultsPreDraw(void) const925*35238bceSAndroid Build Coastguard Worker std::vector<tcu::Vec4> Renderer::getResultsPreDraw(void) const
926*35238bceSAndroid Build Coastguard Worker {
927*35238bceSAndroid Build Coastguard Worker     return m_resultsListPreDraw;
928*35238bceSAndroid Build Coastguard Worker }
929*35238bceSAndroid Build Coastguard Worker 
getResultsPostDraw(void) const930*35238bceSAndroid Build Coastguard Worker std::vector<tcu::Vec4> Renderer::getResultsPostDraw(void) const
931*35238bceSAndroid Build Coastguard Worker {
932*35238bceSAndroid Build Coastguard Worker     return m_resultsListPostDraw;
933*35238bceSAndroid Build Coastguard Worker }
934*35238bceSAndroid Build Coastguard Worker 
getBlendConfigCount(void) const935*35238bceSAndroid Build Coastguard Worker int Renderer::getBlendConfigCount(void) const
936*35238bceSAndroid Build Coastguard Worker {
937*35238bceSAndroid Build Coastguard Worker     return (int)m_blendConfigList.size();
938*35238bceSAndroid Build Coastguard Worker }
939*35238bceSAndroid Build Coastguard Worker 
copyFrameBufferTexture(const int srcPx,const int srcPy,const int dstPx,const int dstPy)940*35238bceSAndroid Build Coastguard Worker void Renderer::copyFrameBufferTexture(const int srcPx, const int srcPy, const int dstPx, const int dstPy)
941*35238bceSAndroid Build Coastguard Worker {
942*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl     = m_context.getRenderContext().getFunctions();
943*35238bceSAndroid Build Coastguard Worker     int fboSrcIdx                = -1;
944*35238bceSAndroid Build Coastguard Worker     int fboDstIdx                = -1;
945*35238bceSAndroid Build Coastguard Worker     uint32_t fboSrcColAttachment = GL_NONE;
946*35238bceSAndroid Build Coastguard Worker     uint32_t fboDstColAttachment = GL_NONE;
947*35238bceSAndroid Build Coastguard Worker 
948*35238bceSAndroid Build Coastguard Worker     for (int idx = 0; idx < (int)m_framebufferList.size(); idx++)
949*35238bceSAndroid Build Coastguard Worker         this->bindFramebuffer(idx);
950*35238bceSAndroid Build Coastguard Worker 
951*35238bceSAndroid Build Coastguard Worker     // cache fbo attachments and idx locations
952*35238bceSAndroid Build Coastguard Worker     for (int idx = 0; idx < (int)m_framebufferList.size(); idx++)
953*35238bceSAndroid Build Coastguard Worker     {
954*35238bceSAndroid Build Coastguard Worker         if (m_framebufferList[idx]->getType() == FBOTYPE_SOURCE)
955*35238bceSAndroid Build Coastguard Worker         {
956*35238bceSAndroid Build Coastguard Worker             fboSrcIdx           = m_framebufferList[idx]->getIdx();
957*35238bceSAndroid Build Coastguard Worker             fboSrcColAttachment = m_framebufferList[fboSrcIdx]->getColorAttachment();
958*35238bceSAndroid Build Coastguard Worker         }
959*35238bceSAndroid Build Coastguard Worker         if (m_framebufferList[idx]->getType() == FBOTYPE_DESTINATION)
960*35238bceSAndroid Build Coastguard Worker         {
961*35238bceSAndroid Build Coastguard Worker             fboDstIdx           = m_framebufferList[idx]->getIdx();
962*35238bceSAndroid Build Coastguard Worker             fboDstColAttachment = m_framebufferList[fboDstIdx]->getColorAttachment();
963*35238bceSAndroid Build Coastguard Worker         }
964*35238bceSAndroid Build Coastguard Worker     }
965*35238bceSAndroid Build Coastguard Worker 
966*35238bceSAndroid Build Coastguard Worker     for (int idx = 0; idx < (int)m_framebufferList.size(); idx++)
967*35238bceSAndroid Build Coastguard Worker         m_framebufferList[idx]->unbind();
968*35238bceSAndroid Build Coastguard Worker 
969*35238bceSAndroid Build Coastguard Worker     // store texel data from both src and dst before performing the copy
970*35238bceSAndroid Build Coastguard Worker     m_resultsListPreDraw.resize(2);
971*35238bceSAndroid Build Coastguard Worker     m_framebufferList[fboSrcIdx]->bind();
972*35238bceSAndroid Build Coastguard Worker     this->readTexels(0, 0, fboSrcColAttachment, m_resultsListPreDraw[0]);
973*35238bceSAndroid Build Coastguard Worker     m_framebufferList[fboSrcIdx]->unbind();
974*35238bceSAndroid Build Coastguard Worker     m_framebufferList[fboDstIdx]->setTargetType(GL_READ_FRAMEBUFFER);
975*35238bceSAndroid Build Coastguard Worker     m_framebufferList[fboDstIdx]->bind();
976*35238bceSAndroid Build Coastguard Worker     this->readTexels(0, 0, fboDstColAttachment, m_resultsListPreDraw[1]);
977*35238bceSAndroid Build Coastguard Worker     m_framebufferList[fboDstIdx]->unbind();
978*35238bceSAndroid Build Coastguard Worker     m_framebufferList[fboDstIdx]->setTargetType(GL_DRAW_FRAMEBUFFER);
979*35238bceSAndroid Build Coastguard Worker 
980*35238bceSAndroid Build Coastguard Worker     m_framebufferList[fboSrcIdx]->bind();
981*35238bceSAndroid Build Coastguard Worker     m_framebufferList[fboDstIdx]->bind();
982*35238bceSAndroid Build Coastguard Worker 
983*35238bceSAndroid Build Coastguard Worker     this->enableFramebufferSRGB();
984*35238bceSAndroid Build Coastguard Worker     this->enableFramebufferBlend();
985*35238bceSAndroid Build Coastguard Worker 
986*35238bceSAndroid Build Coastguard Worker     gl.blitFramebuffer(srcPx, srcPy, TestTextureSizes::WIDTH, TestTextureSizes::HEIGHT, dstPx, dstPy,
987*35238bceSAndroid Build Coastguard Worker                        TestTextureSizes::WIDTH, TestTextureSizes::HEIGHT, GL_COLOR_BUFFER_BIT, GL_NEAREST);
988*35238bceSAndroid Build Coastguard Worker 
989*35238bceSAndroid Build Coastguard Worker     m_resultsListPostDraw.resize(2);
990*35238bceSAndroid Build Coastguard Worker     this->readTexels(0, 0, fboSrcColAttachment, m_resultsListPostDraw[0]);
991*35238bceSAndroid Build Coastguard Worker     m_framebufferList[fboSrcIdx]->unbind();
992*35238bceSAndroid Build Coastguard Worker     m_framebufferList[fboDstIdx]->unbind();
993*35238bceSAndroid Build Coastguard Worker 
994*35238bceSAndroid Build Coastguard Worker     m_framebufferList[fboDstIdx]->setTargetType(GL_READ_FRAMEBUFFER);
995*35238bceSAndroid Build Coastguard Worker     m_framebufferList[fboDstIdx]->bind();
996*35238bceSAndroid Build Coastguard Worker     this->readTexels(0, 0, fboDstColAttachment, m_resultsListPostDraw[1]);
997*35238bceSAndroid Build Coastguard Worker     m_framebufferList[fboDstIdx]->unbind();
998*35238bceSAndroid Build Coastguard Worker }
999*35238bceSAndroid Build Coastguard Worker 
draw(void)1000*35238bceSAndroid Build Coastguard Worker void Renderer::draw(void)
1001*35238bceSAndroid Build Coastguard Worker {
1002*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1003*35238bceSAndroid Build Coastguard Worker 
1004*35238bceSAndroid Build Coastguard Worker     if (m_renderPassConfig.textureSourcesType == TEXTURESOURCESTYPE_NONE)
1005*35238bceSAndroid Build Coastguard Worker         DE_FATAL("Error: Attempted to draw with no texture sources");
1006*35238bceSAndroid Build Coastguard Worker 
1007*35238bceSAndroid Build Coastguard Worker     // resize results storage with each render pass
1008*35238bceSAndroid Build Coastguard Worker     m_resultsListPreDraw.resize(m_renderPass + 1);
1009*35238bceSAndroid Build Coastguard Worker     m_resultsListPostDraw.resize(m_renderPass + 1);
1010*35238bceSAndroid Build Coastguard Worker 
1011*35238bceSAndroid Build Coastguard Worker     m_shaderProgram->use();
1012*35238bceSAndroid Build Coastguard Worker     m_vertexData.bind();
1013*35238bceSAndroid Build Coastguard Worker 
1014*35238bceSAndroid Build Coastguard Worker     for (int idx = 0; idx < (int)m_framebufferList.size(); idx++)
1015*35238bceSAndroid Build Coastguard Worker         this->bindFramebuffer(idx);
1016*35238bceSAndroid Build Coastguard Worker 
1017*35238bceSAndroid Build Coastguard Worker     this->bindAllRequiredSourceTextures(m_renderPassConfig.textureSourcesType);
1018*35238bceSAndroid Build Coastguard Worker     this->bindActiveTexturesSamplers();
1019*35238bceSAndroid Build Coastguard Worker 
1020*35238bceSAndroid Build Coastguard Worker     this->enableFramebufferSRGB();
1021*35238bceSAndroid Build Coastguard Worker     this->enableFramebufferBlend();
1022*35238bceSAndroid Build Coastguard Worker 
1023*35238bceSAndroid Build Coastguard Worker     this->readTexels(0, 0, GL_COLOR_ATTACHMENT0, m_resultsListPreDraw[m_renderPass]);
1024*35238bceSAndroid Build Coastguard Worker     this->setShaderProgramSamplingType(m_samplingType);
1025*35238bceSAndroid Build Coastguard Worker     if (m_hasFunction)
1026*35238bceSAndroid Build Coastguard Worker     {
1027*35238bceSAndroid Build Coastguard Worker         this->setShaderBlendFunctionType();
1028*35238bceSAndroid Build Coastguard Worker         this->setShaderBlendSrcDstValues();
1029*35238bceSAndroid Build Coastguard Worker     }
1030*35238bceSAndroid Build Coastguard Worker 
1031*35238bceSAndroid Build Coastguard Worker     gl.drawArrays(GL_TRIANGLES, 0, 6);
1032*35238bceSAndroid Build Coastguard Worker 
1033*35238bceSAndroid Build Coastguard Worker     this->readTexels(0, 0, GL_COLOR_ATTACHMENT0, m_resultsListPostDraw[m_renderPass]);
1034*35238bceSAndroid Build Coastguard Worker     this->logState(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_samplingType);
1035*35238bceSAndroid Build Coastguard Worker 
1036*35238bceSAndroid Build Coastguard Worker     this->unbindAllSourceTextures();
1037*35238bceSAndroid Build Coastguard Worker     for (int idx = 0; idx < (int)m_framebufferList.size(); idx++)
1038*35238bceSAndroid Build Coastguard Worker         this->unbindFramebuffer(idx);
1039*35238bceSAndroid Build Coastguard Worker     m_vertexData.unbind();
1040*35238bceSAndroid Build Coastguard Worker     m_shaderProgram->unuse();
1041*35238bceSAndroid Build Coastguard Worker }
1042*35238bceSAndroid Build Coastguard Worker 
storeShaderProgramInfo(void)1043*35238bceSAndroid Build Coastguard Worker void Renderer::storeShaderProgramInfo(void)
1044*35238bceSAndroid Build Coastguard Worker {
1045*35238bceSAndroid Build Coastguard Worker     m_shaderProgramInfo    = m_shaderProgram->getLogInfo();
1046*35238bceSAndroid Build Coastguard Worker     m_hasShaderProgramInfo = true;
1047*35238bceSAndroid Build Coastguard Worker }
1048*35238bceSAndroid Build Coastguard Worker 
logShaderProgramInfo(void)1049*35238bceSAndroid Build Coastguard Worker void Renderer::logShaderProgramInfo(void)
1050*35238bceSAndroid Build Coastguard Worker {
1051*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log = m_context.getTestContext().getLog();
1052*35238bceSAndroid Build Coastguard Worker 
1053*35238bceSAndroid Build Coastguard Worker     if (m_hasShaderProgramInfo)
1054*35238bceSAndroid Build Coastguard Worker         log << m_shaderProgramInfo;
1055*35238bceSAndroid Build Coastguard Worker }
1056*35238bceSAndroid Build Coastguard Worker 
createFBOwithColorAttachment(const std::vector<FBOConfig> fboConfigList)1057*35238bceSAndroid Build Coastguard Worker void Renderer::createFBOwithColorAttachment(const std::vector<FBOConfig> fboConfigList)
1058*35238bceSAndroid Build Coastguard Worker {
1059*35238bceSAndroid Build Coastguard Worker     const int size = (int)fboConfigList.size();
1060*35238bceSAndroid Build Coastguard Worker     for (int idx = 0; idx < size; idx++)
1061*35238bceSAndroid Build Coastguard Worker     {
1062*35238bceSAndroid Build Coastguard Worker         TextureSp texture(new TestTexture2D(m_context, fboConfigList[idx].textureInternalFormat, GL_RGBA,
1063*35238bceSAndroid Build Coastguard Worker                                             GL_UNSIGNED_BYTE, fboConfigList[idx].textureColor));
1064*35238bceSAndroid Build Coastguard Worker         m_fboTextureList.push_back(texture);
1065*35238bceSAndroid Build Coastguard Worker 
1066*35238bceSAndroid Build Coastguard Worker         bool isSRGB;
1067*35238bceSAndroid Build Coastguard Worker         if (fboConfigList[idx].textureInternalFormat == GL_SRGB8_ALPHA8)
1068*35238bceSAndroid Build Coastguard Worker             isSRGB = true;
1069*35238bceSAndroid Build Coastguard Worker         else
1070*35238bceSAndroid Build Coastguard Worker             isSRGB = false;
1071*35238bceSAndroid Build Coastguard Worker 
1072*35238bceSAndroid Build Coastguard Worker         FboSp framebuffer(new TestFramebuffer(m_context, fboConfigList[idx].fboTargetType,
1073*35238bceSAndroid Build Coastguard Worker                                               fboConfigList[idx].fboColorAttachment, texture->getHandle(), isSRGB,
1074*35238bceSAndroid Build Coastguard Worker                                               fboConfigList[idx].fboType, idx));
1075*35238bceSAndroid Build Coastguard Worker         m_framebufferList.push_back(framebuffer);
1076*35238bceSAndroid Build Coastguard Worker     }
1077*35238bceSAndroid Build Coastguard Worker }
1078*35238bceSAndroid Build Coastguard Worker 
setShaderProgramSamplingType(const int samplerIdx)1079*35238bceSAndroid Build Coastguard Worker void Renderer::setShaderProgramSamplingType(const int samplerIdx)
1080*35238bceSAndroid Build Coastguard Worker {
1081*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1082*35238bceSAndroid Build Coastguard Worker 
1083*35238bceSAndroid Build Coastguard Worker     glw::GLuint location = gl.getUniformLocation(m_shaderProgram->getHandle(), "uFunctionType");
1084*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(location != (glw::GLuint)-1);
1085*35238bceSAndroid Build Coastguard Worker     gl.uniform1i(location, samplerIdx);
1086*35238bceSAndroid Build Coastguard Worker }
1087*35238bceSAndroid Build Coastguard Worker 
setShaderBlendFunctionType(void)1088*35238bceSAndroid Build Coastguard Worker void Renderer::setShaderBlendFunctionType(void)
1089*35238bceSAndroid Build Coastguard Worker {
1090*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1091*35238bceSAndroid Build Coastguard Worker 
1092*35238bceSAndroid Build Coastguard Worker     int function = -1;
1093*35238bceSAndroid Build Coastguard Worker     if (m_blendConfigList[m_blendIteration].equation == GL_FUNC_ADD)
1094*35238bceSAndroid Build Coastguard Worker         function = 0;
1095*35238bceSAndroid Build Coastguard Worker     else if (m_blendConfigList[m_blendIteration].equation == GL_FUNC_SUBTRACT)
1096*35238bceSAndroid Build Coastguard Worker         function = 1;
1097*35238bceSAndroid Build Coastguard Worker     else if (m_blendConfigList[m_blendIteration].equation == GL_FUNC_REVERSE_SUBTRACT)
1098*35238bceSAndroid Build Coastguard Worker         function = 2;
1099*35238bceSAndroid Build Coastguard Worker     else
1100*35238bceSAndroid Build Coastguard Worker         DE_FATAL("Error: Blend function not recognised");
1101*35238bceSAndroid Build Coastguard Worker 
1102*35238bceSAndroid Build Coastguard Worker     glw::GLuint location = gl.getUniformLocation(m_shaderProgram->getHandle(), "uBlendFunctionType");
1103*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(location != (glw::GLuint)-1);
1104*35238bceSAndroid Build Coastguard Worker     gl.uniform1i(location, function);
1105*35238bceSAndroid Build Coastguard Worker }
1106*35238bceSAndroid Build Coastguard Worker 
setShaderBlendSrcDstValues(void)1107*35238bceSAndroid Build Coastguard Worker void Renderer::setShaderBlendSrcDstValues(void)
1108*35238bceSAndroid Build Coastguard Worker {
1109*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1110*35238bceSAndroid Build Coastguard Worker 
1111*35238bceSAndroid Build Coastguard Worker     float funcSrc;
1112*35238bceSAndroid Build Coastguard Worker     if (m_blendConfigList[m_blendIteration].funcSrc == GL_ONE)
1113*35238bceSAndroid Build Coastguard Worker         funcSrc = 1.0f;
1114*35238bceSAndroid Build Coastguard Worker     else
1115*35238bceSAndroid Build Coastguard Worker         funcSrc = 0.0f;
1116*35238bceSAndroid Build Coastguard Worker 
1117*35238bceSAndroid Build Coastguard Worker     float funcDst;
1118*35238bceSAndroid Build Coastguard Worker     if (m_blendConfigList[m_blendIteration].funcDst == GL_ONE)
1119*35238bceSAndroid Build Coastguard Worker         funcDst = 1.0f;
1120*35238bceSAndroid Build Coastguard Worker     else
1121*35238bceSAndroid Build Coastguard Worker         funcDst = 0.0f;
1122*35238bceSAndroid Build Coastguard Worker 
1123*35238bceSAndroid Build Coastguard Worker     glw::GLuint locationSrc = gl.getUniformLocation(m_shaderProgram->getHandle(), "uFactorSrc");
1124*35238bceSAndroid Build Coastguard Worker     gl.uniform1f(locationSrc, funcSrc);
1125*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1f()");
1126*35238bceSAndroid Build Coastguard Worker 
1127*35238bceSAndroid Build Coastguard Worker     glw::GLuint locationDst = gl.getUniformLocation(m_shaderProgram->getHandle(), "uFactorDst");
1128*35238bceSAndroid Build Coastguard Worker     gl.uniform1f(locationDst, funcDst);
1129*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1f()");
1130*35238bceSAndroid Build Coastguard Worker }
1131*35238bceSAndroid Build Coastguard Worker 
bindActiveTexturesSamplers(void)1132*35238bceSAndroid Build Coastguard Worker void Renderer::bindActiveTexturesSamplers(void)
1133*35238bceSAndroid Build Coastguard Worker {
1134*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1135*35238bceSAndroid Build Coastguard Worker 
1136*35238bceSAndroid Build Coastguard Worker     for (int idx = 0; idx < m_samplersRequired; idx++)
1137*35238bceSAndroid Build Coastguard Worker     {
1138*35238bceSAndroid Build Coastguard Worker         std::ostringstream stream;
1139*35238bceSAndroid Build Coastguard Worker         stream << "uTexture" << idx;
1140*35238bceSAndroid Build Coastguard Worker         std::string uniformName(stream.str());
1141*35238bceSAndroid Build Coastguard Worker         glw::GLint location = gl.getUniformLocation(m_shaderProgram->getHandle(), uniformName.c_str());
1142*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(location != -1);
1143*35238bceSAndroid Build Coastguard Worker         gl.uniform1i(location, m_textureSourceList[idx]->getTextureUnit());
1144*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetUniformLocation()");
1145*35238bceSAndroid Build Coastguard Worker     }
1146*35238bceSAndroid Build Coastguard Worker }
1147*35238bceSAndroid Build Coastguard Worker 
bindAllRequiredSourceTextures(const TextureSourcesType texturesRequired)1148*35238bceSAndroid Build Coastguard Worker void Renderer::bindAllRequiredSourceTextures(const TextureSourcesType texturesRequired)
1149*35238bceSAndroid Build Coastguard Worker {
1150*35238bceSAndroid Build Coastguard Worker     if (texturesRequired == TEXTURESOURCESTYPE_RGBA)
1151*35238bceSAndroid Build Coastguard Worker         m_textureSourceList[0]->bind(0);
1152*35238bceSAndroid Build Coastguard Worker     else if (texturesRequired == TEXTURESOURCESTYPE_SRGBA)
1153*35238bceSAndroid Build Coastguard Worker         m_textureSourceList[1]->bind(0);
1154*35238bceSAndroid Build Coastguard Worker     else if (texturesRequired == TEXTURESOURCESTYPE_BOTH)
1155*35238bceSAndroid Build Coastguard Worker     {
1156*35238bceSAndroid Build Coastguard Worker         m_textureSourceList[0]->bind(0);
1157*35238bceSAndroid Build Coastguard Worker         m_textureSourceList[1]->bind(1);
1158*35238bceSAndroid Build Coastguard Worker     }
1159*35238bceSAndroid Build Coastguard Worker     else
1160*35238bceSAndroid Build Coastguard Worker         DE_FATAL("Error: Invalid sources requested in bind all");
1161*35238bceSAndroid Build Coastguard Worker }
1162*35238bceSAndroid Build Coastguard Worker 
unbindAllSourceTextures(void)1163*35238bceSAndroid Build Coastguard Worker void Renderer::unbindAllSourceTextures(void)
1164*35238bceSAndroid Build Coastguard Worker {
1165*35238bceSAndroid Build Coastguard Worker     for (int idx = 0; idx < (int)m_textureSourceList.size(); idx++)
1166*35238bceSAndroid Build Coastguard Worker         m_textureSourceList[idx]->unbind();
1167*35238bceSAndroid Build Coastguard Worker }
1168*35238bceSAndroid Build Coastguard Worker 
bindFramebuffer(const int framebufferIdx)1169*35238bceSAndroid Build Coastguard Worker void Renderer::bindFramebuffer(const int framebufferIdx)
1170*35238bceSAndroid Build Coastguard Worker {
1171*35238bceSAndroid Build Coastguard Worker     m_framebufferList[framebufferIdx]->bind();
1172*35238bceSAndroid Build Coastguard Worker }
1173*35238bceSAndroid Build Coastguard Worker 
unbindFramebuffer(const int framebufferIdx)1174*35238bceSAndroid Build Coastguard Worker void Renderer::unbindFramebuffer(const int framebufferIdx)
1175*35238bceSAndroid Build Coastguard Worker {
1176*35238bceSAndroid Build Coastguard Worker     m_framebufferList[framebufferIdx]->unbind();
1177*35238bceSAndroid Build Coastguard Worker }
1178*35238bceSAndroid Build Coastguard Worker 
enableFramebufferSRGB(void)1179*35238bceSAndroid Build Coastguard Worker void Renderer::enableFramebufferSRGB(void)
1180*35238bceSAndroid Build Coastguard Worker {
1181*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1182*35238bceSAndroid Build Coastguard Worker 
1183*35238bceSAndroid Build Coastguard Worker     if (m_framebufferSRGBEnabled)
1184*35238bceSAndroid Build Coastguard Worker         gl.enable(GL_FRAMEBUFFER_SRGB);
1185*35238bceSAndroid Build Coastguard Worker     else
1186*35238bceSAndroid Build Coastguard Worker         gl.disable(GL_FRAMEBUFFER_SRGB);
1187*35238bceSAndroid Build Coastguard Worker }
1188*35238bceSAndroid Build Coastguard Worker 
enableFramebufferBlend(void)1189*35238bceSAndroid Build Coastguard Worker void Renderer::enableFramebufferBlend(void)
1190*35238bceSAndroid Build Coastguard Worker {
1191*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1192*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log        = m_context.getTestContext().getLog();
1193*35238bceSAndroid Build Coastguard Worker     std::ostringstream message;
1194*35238bceSAndroid Build Coastguard Worker 
1195*35238bceSAndroid Build Coastguard Worker     message << "Blend settings = ";
1196*35238bceSAndroid Build Coastguard Worker 
1197*35238bceSAndroid Build Coastguard Worker     if (m_framebufferBlendEnabled)
1198*35238bceSAndroid Build Coastguard Worker     {
1199*35238bceSAndroid Build Coastguard Worker         gl.enable(GL_BLEND);
1200*35238bceSAndroid Build Coastguard Worker         gl.blendEquation(m_blendConfigList[m_blendIteration].equation);
1201*35238bceSAndroid Build Coastguard Worker         gl.blendFunc(m_blendConfigList[m_blendIteration].funcSrc, m_blendConfigList[m_blendIteration].funcDst);
1202*35238bceSAndroid Build Coastguard Worker 
1203*35238bceSAndroid Build Coastguard Worker         std::string equation, src, dst;
1204*35238bceSAndroid Build Coastguard Worker         if (m_blendConfigList[m_blendIteration].equation == GL_FUNC_ADD)
1205*35238bceSAndroid Build Coastguard Worker             equation = "GL_FUNC_ADD";
1206*35238bceSAndroid Build Coastguard Worker         if (m_blendConfigList[m_blendIteration].equation == GL_FUNC_SUBTRACT)
1207*35238bceSAndroid Build Coastguard Worker             equation = "GL_FUNC_SUBTRACT";
1208*35238bceSAndroid Build Coastguard Worker         if (m_blendConfigList[m_blendIteration].equation == GL_FUNC_REVERSE_SUBTRACT)
1209*35238bceSAndroid Build Coastguard Worker             equation = "GL_FUNC_REVERSE_SUBTRACT";
1210*35238bceSAndroid Build Coastguard Worker         if (m_blendConfigList[m_blendIteration].funcSrc == GL_ONE)
1211*35238bceSAndroid Build Coastguard Worker             src = "GL_ONE";
1212*35238bceSAndroid Build Coastguard Worker         else
1213*35238bceSAndroid Build Coastguard Worker             src = "GL_ZERO";
1214*35238bceSAndroid Build Coastguard Worker         if (m_blendConfigList[m_blendIteration].funcDst == GL_ONE)
1215*35238bceSAndroid Build Coastguard Worker             dst = "GL_ONE";
1216*35238bceSAndroid Build Coastguard Worker         else
1217*35238bceSAndroid Build Coastguard Worker             dst = "GL_ZERO";
1218*35238bceSAndroid Build Coastguard Worker 
1219*35238bceSAndroid Build Coastguard Worker         message << "Enabled: equation = " << equation << ", func src = " << src << ", func dst = " << dst;
1220*35238bceSAndroid Build Coastguard Worker     }
1221*35238bceSAndroid Build Coastguard Worker     else
1222*35238bceSAndroid Build Coastguard Worker     {
1223*35238bceSAndroid Build Coastguard Worker         gl.disable(GL_BLEND);
1224*35238bceSAndroid Build Coastguard Worker         message << "Disabled";
1225*35238bceSAndroid Build Coastguard Worker     }
1226*35238bceSAndroid Build Coastguard Worker 
1227*35238bceSAndroid Build Coastguard Worker     log << tcu::TestLog::Message << message.str() << tcu::TestLog::EndMessage;
1228*35238bceSAndroid Build Coastguard Worker }
1229*35238bceSAndroid Build Coastguard Worker 
isFramebufferAttachmentSRGB(const uint32_t targetType,const uint32_t attachment) const1230*35238bceSAndroid Build Coastguard Worker bool Renderer::isFramebufferAttachmentSRGB(const uint32_t targetType, const uint32_t attachment) const
1231*35238bceSAndroid Build Coastguard Worker {
1232*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1233*35238bceSAndroid Build Coastguard Worker     glw::GLint encodingType;
1234*35238bceSAndroid Build Coastguard Worker 
1235*35238bceSAndroid Build Coastguard Worker     gl.getFramebufferAttachmentParameteriv(targetType, attachment, GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING,
1236*35238bceSAndroid Build Coastguard Worker                                            &encodingType);
1237*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(gl.getError(), "glGetNamedFramebufferAttachmentParameteriv()");
1238*35238bceSAndroid Build Coastguard Worker 
1239*35238bceSAndroid Build Coastguard Worker     switch (static_cast<glw::GLenum>(encodingType))
1240*35238bceSAndroid Build Coastguard Worker     {
1241*35238bceSAndroid Build Coastguard Worker     case GL_SRGB:
1242*35238bceSAndroid Build Coastguard Worker     {
1243*35238bceSAndroid Build Coastguard Worker         return true;
1244*35238bceSAndroid Build Coastguard Worker     }
1245*35238bceSAndroid Build Coastguard Worker     case GL_LINEAR:
1246*35238bceSAndroid Build Coastguard Worker     {
1247*35238bceSAndroid Build Coastguard Worker         return false;
1248*35238bceSAndroid Build Coastguard Worker     }
1249*35238bceSAndroid Build Coastguard Worker     default:
1250*35238bceSAndroid Build Coastguard Worker     {
1251*35238bceSAndroid Build Coastguard Worker         DE_FATAL("Error: Color attachment format not recognised");
1252*35238bceSAndroid Build Coastguard Worker         return false;
1253*35238bceSAndroid Build Coastguard Worker     }
1254*35238bceSAndroid Build Coastguard Worker     }
1255*35238bceSAndroid Build Coastguard Worker }
1256*35238bceSAndroid Build Coastguard Worker 
readTexels(const int px,const int py,const uint32_t mode,tcu::Vec4 & texelData)1257*35238bceSAndroid Build Coastguard Worker void Renderer::readTexels(const int px, const int py, const uint32_t mode, tcu::Vec4 &texelData)
1258*35238bceSAndroid Build Coastguard Worker {
1259*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1260*35238bceSAndroid Build Coastguard Worker     tcu::TextureLevel textureRead;
1261*35238bceSAndroid Build Coastguard Worker 
1262*35238bceSAndroid Build Coastguard Worker     // ensure result sampling coordinates are within range of the result color attachment
1263*35238bceSAndroid Build Coastguard Worker     DE_ASSERT((px >= 0) && (px < m_context.getRenderTarget().getWidth()));
1264*35238bceSAndroid Build Coastguard Worker     DE_ASSERT((py >= 0) && (py < m_context.getRenderTarget().getHeight()));
1265*35238bceSAndroid Build Coastguard Worker 
1266*35238bceSAndroid Build Coastguard Worker     gl.readBuffer(mode);
1267*35238bceSAndroid Build Coastguard Worker     textureRead.setStorage(glu::mapGLTransferFormat(GL_RGBA, GL_UNSIGNED_BYTE), TestTextureSizes::WIDTH,
1268*35238bceSAndroid Build Coastguard Worker                            TestTextureSizes::HEIGHT);
1269*35238bceSAndroid Build Coastguard Worker     glu::readPixels(m_context.getRenderContext(), px, py, textureRead.getAccess());
1270*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels()");
1271*35238bceSAndroid Build Coastguard Worker     texelData = textureRead.getAccess().getPixel(px, py);
1272*35238bceSAndroid Build Coastguard Worker }
1273*35238bceSAndroid Build Coastguard Worker 
logState(const uint32_t targetType,const uint32_t attachment,const SamplingType samplingType) const1274*35238bceSAndroid Build Coastguard Worker void Renderer::logState(const uint32_t targetType, const uint32_t attachment, const SamplingType samplingType) const
1275*35238bceSAndroid Build Coastguard Worker {
1276*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log = m_context.getTestContext().getLog();
1277*35238bceSAndroid Build Coastguard Worker     std::ostringstream message;
1278*35238bceSAndroid Build Coastguard Worker 
1279*35238bceSAndroid Build Coastguard Worker     bool fboAttachmentSRGB = this->isFramebufferAttachmentSRGB(targetType, attachment);
1280*35238bceSAndroid Build Coastguard Worker     message.str("");
1281*35238bceSAndroid Build Coastguard Worker     message << "getFramebufferAttachmentParameteriv() check = ";
1282*35238bceSAndroid Build Coastguard Worker     if (fboAttachmentSRGB)
1283*35238bceSAndroid Build Coastguard Worker         message << "GL_SRGB";
1284*35238bceSAndroid Build Coastguard Worker     else
1285*35238bceSAndroid Build Coastguard Worker         message << "GL_LINEAR";
1286*35238bceSAndroid Build Coastguard Worker     log << tcu::TestLog::Message << message.str() << tcu::TestLog::EndMessage;
1287*35238bceSAndroid Build Coastguard Worker 
1288*35238bceSAndroid Build Coastguard Worker     message.str("");
1289*35238bceSAndroid Build Coastguard Worker     message << "Framebuffer color attachment value BEFORE draw call";
1290*35238bceSAndroid Build Coastguard Worker     logColor(m_context, message.str(), m_resultsListPreDraw[m_renderPass]);
1291*35238bceSAndroid Build Coastguard Worker 
1292*35238bceSAndroid Build Coastguard Worker     message.str("");
1293*35238bceSAndroid Build Coastguard Worker     message << "Framebuffer color attachment value AFTER draw call";
1294*35238bceSAndroid Build Coastguard Worker     logColor(m_context, message.str(), m_resultsListPostDraw[m_renderPass]);
1295*35238bceSAndroid Build Coastguard Worker 
1296*35238bceSAndroid Build Coastguard Worker     message.str("");
1297*35238bceSAndroid Build Coastguard Worker     message << "Sampling type = ";
1298*35238bceSAndroid Build Coastguard Worker     std::string type;
1299*35238bceSAndroid Build Coastguard Worker     if (samplingType == 0)
1300*35238bceSAndroid Build Coastguard Worker         type = "texture()";
1301*35238bceSAndroid Build Coastguard Worker     else if (samplingType == 1)
1302*35238bceSAndroid Build Coastguard Worker         type = "textureLOD()";
1303*35238bceSAndroid Build Coastguard Worker     else if (samplingType == 2)
1304*35238bceSAndroid Build Coastguard Worker         type = "textureGrad()";
1305*35238bceSAndroid Build Coastguard Worker     else if (samplingType == 3)
1306*35238bceSAndroid Build Coastguard Worker         type = "textureOffset()";
1307*35238bceSAndroid Build Coastguard Worker     else if (samplingType == 4)
1308*35238bceSAndroid Build Coastguard Worker         type = "textureProj()";
1309*35238bceSAndroid Build Coastguard Worker     else
1310*35238bceSAndroid Build Coastguard Worker         DE_FATAL("Error: Sampling type unregonised");
1311*35238bceSAndroid Build Coastguard Worker     message << type;
1312*35238bceSAndroid Build Coastguard Worker     log << tcu::TestLog::Message << message.str() << tcu::TestLog::EndMessage;
1313*35238bceSAndroid Build Coastguard Worker 
1314*35238bceSAndroid Build Coastguard Worker     message.str("");
1315*35238bceSAndroid Build Coastguard Worker     if (m_framebufferSRGBEnabled)
1316*35238bceSAndroid Build Coastguard Worker         message << "Framebuffer SRGB = enabled";
1317*35238bceSAndroid Build Coastguard Worker     else
1318*35238bceSAndroid Build Coastguard Worker         message << "Framebuffer SRGB = disabled";
1319*35238bceSAndroid Build Coastguard Worker     log << tcu::TestLog::Message << message.str() << tcu::TestLog::EndMessage;
1320*35238bceSAndroid Build Coastguard Worker }
1321*35238bceSAndroid Build Coastguard Worker 
1322*35238bceSAndroid Build Coastguard Worker class FboSRGBTestCase : public TestCase
1323*35238bceSAndroid Build Coastguard Worker {
1324*35238bceSAndroid Build Coastguard Worker public:
1325*35238bceSAndroid Build Coastguard Worker     FboSRGBTestCase(Context &context, const char *const name, const char *const desc);
1326*35238bceSAndroid Build Coastguard Worker     ~FboSRGBTestCase(void);
1327*35238bceSAndroid Build Coastguard Worker 
1328*35238bceSAndroid Build Coastguard Worker     void init(void);
1329*35238bceSAndroid Build Coastguard Worker     void deinit(void);
1330*35238bceSAndroid Build Coastguard Worker     IterateResult iterate(void);
1331*35238bceSAndroid Build Coastguard Worker 
1332*35238bceSAndroid Build Coastguard Worker     void setTestConfig(std::vector<TestRenderPassConfig> renderPassConfigList);
1333*35238bceSAndroid Build Coastguard Worker 
1334*35238bceSAndroid Build Coastguard Worker     virtual void setupTest(void)    = 0;
1335*35238bceSAndroid Build Coastguard Worker     virtual bool verifyResult(void) = 0;
1336*35238bceSAndroid Build Coastguard Worker 
1337*35238bceSAndroid Build Coastguard Worker protected:
1338*35238bceSAndroid Build Coastguard Worker     bool m_hasTestConfig;
1339*35238bceSAndroid Build Coastguard Worker     std::vector<TestRenderPassConfig> m_renderPassConfigList;
1340*35238bceSAndroid Build Coastguard Worker     bool m_testcaseRequiresBlend;
1341*35238bceSAndroid Build Coastguard Worker     std::vector<tcu::Vec4> m_resultsPreDraw;
1342*35238bceSAndroid Build Coastguard Worker     std::vector<tcu::Vec4> m_resultsPostDraw;
1343*35238bceSAndroid Build Coastguard Worker 
1344*35238bceSAndroid Build Coastguard Worker private:
1345*35238bceSAndroid Build Coastguard Worker     FboSRGBTestCase(const FboSRGBTestCase &);
1346*35238bceSAndroid Build Coastguard Worker     FboSRGBTestCase &operator=(const FboSRGBTestCase &);
1347*35238bceSAndroid Build Coastguard Worker };
1348*35238bceSAndroid Build Coastguard Worker 
FboSRGBTestCase(Context & context,const char * const name,const char * const desc)1349*35238bceSAndroid Build Coastguard Worker FboSRGBTestCase::FboSRGBTestCase(Context &context, const char *const name, const char *const desc)
1350*35238bceSAndroid Build Coastguard Worker     : TestCase(context, name, desc)
1351*35238bceSAndroid Build Coastguard Worker     , m_hasTestConfig(false)
1352*35238bceSAndroid Build Coastguard Worker     , m_testcaseRequiresBlend(false)
1353*35238bceSAndroid Build Coastguard Worker {
1354*35238bceSAndroid Build Coastguard Worker }
1355*35238bceSAndroid Build Coastguard Worker 
~FboSRGBTestCase(void)1356*35238bceSAndroid Build Coastguard Worker FboSRGBTestCase::~FboSRGBTestCase(void)
1357*35238bceSAndroid Build Coastguard Worker {
1358*35238bceSAndroid Build Coastguard Worker     FboSRGBTestCase::deinit();
1359*35238bceSAndroid Build Coastguard Worker }
1360*35238bceSAndroid Build Coastguard Worker 
init(void)1361*35238bceSAndroid Build Coastguard Worker void FboSRGBTestCase::init(void)
1362*35238bceSAndroid Build Coastguard Worker {
1363*35238bceSAndroid Build Coastguard Worker     if (glu::isContextTypeES(m_context.getRenderContext().getType()))
1364*35238bceSAndroid Build Coastguard Worker     {
1365*35238bceSAndroid Build Coastguard Worker         // extensions requirements for test
1366*35238bceSAndroid Build Coastguard Worker         if (!glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::es(3, 2)))
1367*35238bceSAndroid Build Coastguard Worker             TCU_THROW(NotSupportedError, "Test requires a context version equal or higher than 3.2");
1368*35238bceSAndroid Build Coastguard Worker 
1369*35238bceSAndroid Build Coastguard Worker         if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_sRGB_write_control"))
1370*35238bceSAndroid Build Coastguard Worker             TCU_THROW(NotSupportedError, "Test requires extension GL_EXT_sRGB_write_control");
1371*35238bceSAndroid Build Coastguard Worker 
1372*35238bceSAndroid Build Coastguard Worker         if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_texture_sRGB_decode"))
1373*35238bceSAndroid Build Coastguard Worker             TCU_THROW(NotSupportedError, "Test requires GL_EXT_texture_sRGB_decode extension");
1374*35238bceSAndroid Build Coastguard Worker     }
1375*35238bceSAndroid Build Coastguard Worker }
1376*35238bceSAndroid Build Coastguard Worker 
deinit(void)1377*35238bceSAndroid Build Coastguard Worker void FboSRGBTestCase::deinit(void)
1378*35238bceSAndroid Build Coastguard Worker {
1379*35238bceSAndroid Build Coastguard Worker }
1380*35238bceSAndroid Build Coastguard Worker 
iterate(void)1381*35238bceSAndroid Build Coastguard Worker FboSRGBTestCase::IterateResult FboSRGBTestCase::iterate(void)
1382*35238bceSAndroid Build Coastguard Worker {
1383*35238bceSAndroid Build Coastguard Worker     this->setupTest();
1384*35238bceSAndroid Build Coastguard Worker 
1385*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(m_hasTestConfig && "Error: Renderer was not supplied a test config");
1386*35238bceSAndroid Build Coastguard Worker 
1387*35238bceSAndroid Build Coastguard Worker     Renderer renderer(m_context);
1388*35238bceSAndroid Build Coastguard Worker 
1389*35238bceSAndroid Build Coastguard Worker     // loop through each sampling type
1390*35238bceSAndroid Build Coastguard Worker     for (int samplingIdx = 0; samplingIdx < SampligTypeCount::MAX; samplingIdx++)
1391*35238bceSAndroid Build Coastguard Worker     {
1392*35238bceSAndroid Build Coastguard Worker         renderer.setSamplingType(static_cast<SamplingType>(samplingIdx));
1393*35238bceSAndroid Build Coastguard Worker 
1394*35238bceSAndroid Build Coastguard Worker         // loop through each blend configuration
1395*35238bceSAndroid Build Coastguard Worker         const int blendCount = renderer.getBlendConfigCount();
1396*35238bceSAndroid Build Coastguard Worker         for (int blendIdx = 0; blendIdx < blendCount; blendIdx++)
1397*35238bceSAndroid Build Coastguard Worker         {
1398*35238bceSAndroid Build Coastguard Worker             // loop through each render pass
1399*35238bceSAndroid Build Coastguard Worker             const int renderPassCount = (int)m_renderPassConfigList.size();
1400*35238bceSAndroid Build Coastguard Worker             for (int renderPassIdx = 0; renderPassIdx < renderPassCount; renderPassIdx++)
1401*35238bceSAndroid Build Coastguard Worker             {
1402*35238bceSAndroid Build Coastguard Worker                 TestRenderPassConfig renderPassConfig = m_renderPassConfigList[renderPassIdx];
1403*35238bceSAndroid Build Coastguard Worker 
1404*35238bceSAndroid Build Coastguard Worker                 renderer.init(renderPassConfig, renderPassIdx);
1405*35238bceSAndroid Build Coastguard Worker 
1406*35238bceSAndroid Build Coastguard Worker                 if (blendIdx == 0 && renderPassConfig.rendererTask == RENDERERTASK_DRAW)
1407*35238bceSAndroid Build Coastguard Worker                     renderer.storeShaderProgramInfo();
1408*35238bceSAndroid Build Coastguard Worker 
1409*35238bceSAndroid Build Coastguard Worker                 if (renderPassConfig.frameBufferBlend == FRAMEBUFFERBLEND_ENABLED)
1410*35238bceSAndroid Build Coastguard Worker                 {
1411*35238bceSAndroid Build Coastguard Worker                     renderer.setBlendIteration(blendIdx);
1412*35238bceSAndroid Build Coastguard Worker                     renderer.setFramebufferBlend(true);
1413*35238bceSAndroid Build Coastguard Worker                 }
1414*35238bceSAndroid Build Coastguard Worker                 else
1415*35238bceSAndroid Build Coastguard Worker                     renderer.setFramebufferBlend(false);
1416*35238bceSAndroid Build Coastguard Worker 
1417*35238bceSAndroid Build Coastguard Worker                 if (renderPassConfig.framebufferSRGB == FRAMEBUFFERSRGB_ENABLED)
1418*35238bceSAndroid Build Coastguard Worker                     renderer.setFramebufferSRGB(true);
1419*35238bceSAndroid Build Coastguard Worker                 else
1420*35238bceSAndroid Build Coastguard Worker                     renderer.setFramebufferSRGB(false);
1421*35238bceSAndroid Build Coastguard Worker 
1422*35238bceSAndroid Build Coastguard Worker                 if (renderPassConfig.rendererTask == RENDERERTASK_DRAW)
1423*35238bceSAndroid Build Coastguard Worker                     renderer.draw();
1424*35238bceSAndroid Build Coastguard Worker                 else if (renderPassConfig.rendererTask == RENDERERTASK_COPY)
1425*35238bceSAndroid Build Coastguard Worker                     renderer.copyFrameBufferTexture(0, 0, 0, 0);
1426*35238bceSAndroid Build Coastguard Worker                 else
1427*35238bceSAndroid Build Coastguard Worker                     DE_FATAL("Error: render task not recognised");
1428*35238bceSAndroid Build Coastguard Worker 
1429*35238bceSAndroid Build Coastguard Worker                 renderer.deinit();
1430*35238bceSAndroid Build Coastguard Worker 
1431*35238bceSAndroid Build Coastguard Worker             } // render passes
1432*35238bceSAndroid Build Coastguard Worker 
1433*35238bceSAndroid Build Coastguard Worker             m_resultsPreDraw  = renderer.getResultsPreDraw();
1434*35238bceSAndroid Build Coastguard Worker             m_resultsPostDraw = renderer.getResultsPostDraw();
1435*35238bceSAndroid Build Coastguard Worker 
1436*35238bceSAndroid Build Coastguard Worker             bool testPassed = this->verifyResult();
1437*35238bceSAndroid Build Coastguard Worker             if (testPassed)
1438*35238bceSAndroid Build Coastguard Worker                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1439*35238bceSAndroid Build Coastguard Worker             else
1440*35238bceSAndroid Build Coastguard Worker             {
1441*35238bceSAndroid Build Coastguard Worker                 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Result verification failed");
1442*35238bceSAndroid Build Coastguard Worker                 renderer.logShaderProgramInfo();
1443*35238bceSAndroid Build Coastguard Worker                 return STOP;
1444*35238bceSAndroid Build Coastguard Worker             }
1445*35238bceSAndroid Build Coastguard Worker 
1446*35238bceSAndroid Build Coastguard Worker             if (!m_testcaseRequiresBlend)
1447*35238bceSAndroid Build Coastguard Worker                 break;
1448*35238bceSAndroid Build Coastguard Worker         } // blend configs
1449*35238bceSAndroid Build Coastguard Worker 
1450*35238bceSAndroid Build Coastguard Worker         renderer.logShaderProgramInfo();
1451*35238bceSAndroid Build Coastguard Worker     } // sampling types
1452*35238bceSAndroid Build Coastguard Worker 
1453*35238bceSAndroid Build Coastguard Worker     return STOP;
1454*35238bceSAndroid Build Coastguard Worker }
1455*35238bceSAndroid Build Coastguard Worker 
setTestConfig(std::vector<TestRenderPassConfig> renderPassConfigList)1456*35238bceSAndroid Build Coastguard Worker void FboSRGBTestCase::setTestConfig(std::vector<TestRenderPassConfig> renderPassConfigList)
1457*35238bceSAndroid Build Coastguard Worker {
1458*35238bceSAndroid Build Coastguard Worker     m_renderPassConfigList = renderPassConfigList;
1459*35238bceSAndroid Build Coastguard Worker     m_hasTestConfig        = true;
1460*35238bceSAndroid Build Coastguard Worker 
1461*35238bceSAndroid Build Coastguard Worker     for (int idx = 0; idx < (int)renderPassConfigList.size(); idx++)
1462*35238bceSAndroid Build Coastguard Worker     {
1463*35238bceSAndroid Build Coastguard Worker         if (renderPassConfigList[idx].frameBufferBlend == FRAMEBUFFERBLEND_ENABLED)
1464*35238bceSAndroid Build Coastguard Worker         {
1465*35238bceSAndroid Build Coastguard Worker             m_testcaseRequiresBlend = true;
1466*35238bceSAndroid Build Coastguard Worker             return;
1467*35238bceSAndroid Build Coastguard Worker         }
1468*35238bceSAndroid Build Coastguard Worker     }
1469*35238bceSAndroid Build Coastguard Worker     m_testcaseRequiresBlend = false;
1470*35238bceSAndroid Build Coastguard Worker }
1471*35238bceSAndroid Build Coastguard Worker 
1472*35238bceSAndroid Build Coastguard Worker class FboSRGBQueryCase : public TestCase
1473*35238bceSAndroid Build Coastguard Worker {
1474*35238bceSAndroid Build Coastguard Worker public:
1475*35238bceSAndroid Build Coastguard Worker     FboSRGBQueryCase(Context &context, const char *const name, const char *const description);
1476*35238bceSAndroid Build Coastguard Worker     ~FboSRGBQueryCase(void);
1477*35238bceSAndroid Build Coastguard Worker 
1478*35238bceSAndroid Build Coastguard Worker     void init(void);
1479*35238bceSAndroid Build Coastguard Worker     void deinit(void);
1480*35238bceSAndroid Build Coastguard Worker     IterateResult iterate(void);
1481*35238bceSAndroid Build Coastguard Worker };
1482*35238bceSAndroid Build Coastguard Worker 
FboSRGBQueryCase(Context & context,const char * const name,const char * const description)1483*35238bceSAndroid Build Coastguard Worker FboSRGBQueryCase::FboSRGBQueryCase(Context &context, const char *const name, const char *const description)
1484*35238bceSAndroid Build Coastguard Worker     : TestCase(context, name, description)
1485*35238bceSAndroid Build Coastguard Worker {
1486*35238bceSAndroid Build Coastguard Worker }
1487*35238bceSAndroid Build Coastguard Worker 
~FboSRGBQueryCase(void)1488*35238bceSAndroid Build Coastguard Worker FboSRGBQueryCase::~FboSRGBQueryCase(void)
1489*35238bceSAndroid Build Coastguard Worker {
1490*35238bceSAndroid Build Coastguard Worker     FboSRGBQueryCase::deinit();
1491*35238bceSAndroid Build Coastguard Worker }
1492*35238bceSAndroid Build Coastguard Worker 
init(void)1493*35238bceSAndroid Build Coastguard Worker void FboSRGBQueryCase::init(void)
1494*35238bceSAndroid Build Coastguard Worker {
1495*35238bceSAndroid Build Coastguard Worker     // extension requirements for test
1496*35238bceSAndroid Build Coastguard Worker     if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_sRGB_write_control"))
1497*35238bceSAndroid Build Coastguard Worker         TCU_THROW(NotSupportedError, "Test requires extension GL_EXT_sRGB_write_control");
1498*35238bceSAndroid Build Coastguard Worker }
1499*35238bceSAndroid Build Coastguard Worker 
deinit(void)1500*35238bceSAndroid Build Coastguard Worker void FboSRGBQueryCase::deinit(void)
1501*35238bceSAndroid Build Coastguard Worker {
1502*35238bceSAndroid Build Coastguard Worker }
1503*35238bceSAndroid Build Coastguard Worker 
iterate(void)1504*35238bceSAndroid Build Coastguard Worker FboSRGBQueryCase::IterateResult FboSRGBQueryCase::iterate(void)
1505*35238bceSAndroid Build Coastguard Worker {
1506*35238bceSAndroid Build Coastguard Worker     // TEST INFO:
1507*35238bceSAndroid Build Coastguard Worker     // API tests which check when querying FRAMEBUFFER_SRGB_EXT capability returns the correct information when using glEnabled() or glDisabled()
1508*35238bceSAndroid Build Coastguard Worker 
1509*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl  = m_context.getRenderContext().getFunctions();
1510*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log         = m_context.getTestContext().getLog();
1511*35238bceSAndroid Build Coastguard Worker     const char *const msgPart = ", after disabling = ";
1512*35238bceSAndroid Build Coastguard Worker 
1513*35238bceSAndroid Build Coastguard Worker     for (int idx = 0; idx < static_cast<int>(QUERYTYPE_LAST); idx++)
1514*35238bceSAndroid Build Coastguard Worker     {
1515*35238bceSAndroid Build Coastguard Worker         std::ostringstream message;
1516*35238bceSAndroid Build Coastguard Worker         bool pass = false;
1517*35238bceSAndroid Build Coastguard Worker 
1518*35238bceSAndroid Build Coastguard Worker         message << std::string("Results: After Enabling = ");
1519*35238bceSAndroid Build Coastguard Worker 
1520*35238bceSAndroid Build Coastguard Worker         gl.enable(GL_FRAMEBUFFER_SRGB);
1521*35238bceSAndroid Build Coastguard Worker 
1522*35238bceSAndroid Build Coastguard Worker         switch (static_cast<QueryType>(idx))
1523*35238bceSAndroid Build Coastguard Worker         {
1524*35238bceSAndroid Build Coastguard Worker         case QUERYTYPE_ISENABLED:
1525*35238bceSAndroid Build Coastguard Worker         {
1526*35238bceSAndroid Build Coastguard Worker             glw::GLboolean enabled[2];
1527*35238bceSAndroid Build Coastguard Worker             enabled[0] = gl.isEnabled(GL_FRAMEBUFFER_SRGB);
1528*35238bceSAndroid Build Coastguard Worker             gl.disable(GL_FRAMEBUFFER_SRGB);
1529*35238bceSAndroid Build Coastguard Worker             enabled[1] = gl.isEnabled(GL_FRAMEBUFFER_SRGB);
1530*35238bceSAndroid Build Coastguard Worker 
1531*35238bceSAndroid Build Coastguard Worker             message << static_cast<float>(enabled[0]) << msgPart << static_cast<float>(enabled[1]);
1532*35238bceSAndroid Build Coastguard Worker             pass = (enabled[0] && !(enabled[1])) ? true : false;
1533*35238bceSAndroid Build Coastguard Worker             break;
1534*35238bceSAndroid Build Coastguard Worker         }
1535*35238bceSAndroid Build Coastguard Worker         case QUERYTYPE_BOOLEAN:
1536*35238bceSAndroid Build Coastguard Worker         {
1537*35238bceSAndroid Build Coastguard Worker             glw::GLboolean enabled[2];
1538*35238bceSAndroid Build Coastguard Worker             gl.getBooleanv(GL_FRAMEBUFFER_SRGB, &enabled[0]);
1539*35238bceSAndroid Build Coastguard Worker             gl.disable(GL_FRAMEBUFFER_SRGB);
1540*35238bceSAndroid Build Coastguard Worker             gl.getBooleanv(GL_FRAMEBUFFER_SRGB, &enabled[1]);
1541*35238bceSAndroid Build Coastguard Worker 
1542*35238bceSAndroid Build Coastguard Worker             message << static_cast<float>(enabled[0]) << msgPart << static_cast<float>(enabled[1]);
1543*35238bceSAndroid Build Coastguard Worker             pass = (enabled[0] && !(enabled[1])) ? true : false;
1544*35238bceSAndroid Build Coastguard Worker             break;
1545*35238bceSAndroid Build Coastguard Worker         }
1546*35238bceSAndroid Build Coastguard Worker         case QUERYTYPE_FLOAT:
1547*35238bceSAndroid Build Coastguard Worker         {
1548*35238bceSAndroid Build Coastguard Worker             glw::GLfloat enabled[2];
1549*35238bceSAndroid Build Coastguard Worker             gl.getFloatv(GL_FRAMEBUFFER_SRGB, &enabled[0]);
1550*35238bceSAndroid Build Coastguard Worker             gl.disable(GL_FRAMEBUFFER_SRGB);
1551*35238bceSAndroid Build Coastguard Worker             gl.getFloatv(GL_FRAMEBUFFER_SRGB, &enabled[1]);
1552*35238bceSAndroid Build Coastguard Worker 
1553*35238bceSAndroid Build Coastguard Worker             message << static_cast<float>(enabled[0]) << msgPart << static_cast<float>(enabled[1]);
1554*35238bceSAndroid Build Coastguard Worker             pass = ((int)enabled[0] && !((int)enabled[1])) ? true : false;
1555*35238bceSAndroid Build Coastguard Worker             break;
1556*35238bceSAndroid Build Coastguard Worker         }
1557*35238bceSAndroid Build Coastguard Worker         case QUERYTYPE_INT:
1558*35238bceSAndroid Build Coastguard Worker         {
1559*35238bceSAndroid Build Coastguard Worker             glw::GLint enabled[2];
1560*35238bceSAndroid Build Coastguard Worker             gl.getIntegerv(GL_FRAMEBUFFER_SRGB, &enabled[0]);
1561*35238bceSAndroid Build Coastguard Worker             gl.disable(GL_FRAMEBUFFER_SRGB);
1562*35238bceSAndroid Build Coastguard Worker             gl.getIntegerv(GL_FRAMEBUFFER_SRGB, &enabled[1]);
1563*35238bceSAndroid Build Coastguard Worker 
1564*35238bceSAndroid Build Coastguard Worker             message << static_cast<float>(enabled[0]) << msgPart << static_cast<float>(enabled[1]);
1565*35238bceSAndroid Build Coastguard Worker             pass = (enabled[0] && !(enabled[1])) ? true : false;
1566*35238bceSAndroid Build Coastguard Worker             break;
1567*35238bceSAndroid Build Coastguard Worker         }
1568*35238bceSAndroid Build Coastguard Worker         case QUERYTYPE_INT64:
1569*35238bceSAndroid Build Coastguard Worker         {
1570*35238bceSAndroid Build Coastguard Worker             glw::GLint64 enabled[2];
1571*35238bceSAndroid Build Coastguard Worker             gl.getInteger64v(GL_FRAMEBUFFER_SRGB, &enabled[0]);
1572*35238bceSAndroid Build Coastguard Worker             gl.disable(GL_FRAMEBUFFER_SRGB);
1573*35238bceSAndroid Build Coastguard Worker             gl.getInteger64v(GL_FRAMEBUFFER_SRGB, &enabled[1]);
1574*35238bceSAndroid Build Coastguard Worker 
1575*35238bceSAndroid Build Coastguard Worker             message << static_cast<float>(enabled[0]) << msgPart << static_cast<float>(enabled[1]);
1576*35238bceSAndroid Build Coastguard Worker             pass = (enabled[0] && !(enabled[1])) ? true : false;
1577*35238bceSAndroid Build Coastguard Worker             break;
1578*35238bceSAndroid Build Coastguard Worker         }
1579*35238bceSAndroid Build Coastguard Worker         default:
1580*35238bceSAndroid Build Coastguard Worker             DE_FATAL("Error: Datatype not recognised");
1581*35238bceSAndroid Build Coastguard Worker         }
1582*35238bceSAndroid Build Coastguard Worker 
1583*35238bceSAndroid Build Coastguard Worker         log << tcu::TestLog::Message << message.str() << tcu::TestLog::EndMessage;
1584*35238bceSAndroid Build Coastguard Worker 
1585*35238bceSAndroid Build Coastguard Worker         if (pass)
1586*35238bceSAndroid Build Coastguard Worker             m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1587*35238bceSAndroid Build Coastguard Worker         else
1588*35238bceSAndroid Build Coastguard Worker         {
1589*35238bceSAndroid Build Coastguard Worker             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Result verification failed");
1590*35238bceSAndroid Build Coastguard Worker             return STOP;
1591*35238bceSAndroid Build Coastguard Worker         }
1592*35238bceSAndroid Build Coastguard Worker     }
1593*35238bceSAndroid Build Coastguard Worker     return STOP;
1594*35238bceSAndroid Build Coastguard Worker }
1595*35238bceSAndroid Build Coastguard Worker 
1596*35238bceSAndroid Build Coastguard Worker class FboSRGBColAttachCase : public FboSRGBTestCase
1597*35238bceSAndroid Build Coastguard Worker {
1598*35238bceSAndroid Build Coastguard Worker public:
FboSRGBColAttachCase(Context & context,const char * const name,const char * const description)1599*35238bceSAndroid Build Coastguard Worker     FboSRGBColAttachCase(Context &context, const char *const name, const char *const description)
1600*35238bceSAndroid Build Coastguard Worker         : FboSRGBTestCase(context, name, description)
1601*35238bceSAndroid Build Coastguard Worker     {
1602*35238bceSAndroid Build Coastguard Worker     }
~FboSRGBColAttachCase(void)1603*35238bceSAndroid Build Coastguard Worker     ~FboSRGBColAttachCase(void)
1604*35238bceSAndroid Build Coastguard Worker     {
1605*35238bceSAndroid Build Coastguard Worker     }
1606*35238bceSAndroid Build Coastguard Worker 
1607*35238bceSAndroid Build Coastguard Worker     void setupTest(void);
1608*35238bceSAndroid Build Coastguard Worker     bool verifyResult(void);
1609*35238bceSAndroid Build Coastguard Worker };
1610*35238bceSAndroid Build Coastguard Worker 
setupTest(void)1611*35238bceSAndroid Build Coastguard Worker void FboSRGBColAttachCase::setupTest(void)
1612*35238bceSAndroid Build Coastguard Worker {
1613*35238bceSAndroid Build Coastguard Worker     // TEST INFO:
1614*35238bceSAndroid Build Coastguard Worker     // Check if FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING  set to SRGB and FRAMEBUFFER_SRGB_EXT enabled, destination colors are converted from SRGB to linear
1615*35238bceSAndroid Build Coastguard Worker     // before and after blending, finally the result is converted back to SRGB for storage
1616*35238bceSAndroid Build Coastguard Worker 
1617*35238bceSAndroid Build Coastguard Worker     // NOTE:
1618*35238bceSAndroid Build Coastguard Worker     // if fbo pre-draw color set to linaer, color values get linearlized "twice"
1619*35238bceSAndroid Build Coastguard Worker     // (0.2f, 0.3f, 0.4f, 1.0f) when sampled i.e. converted in shader = (0.0331048f, 0.073239f, 0.132868f)
1620*35238bceSAndroid Build Coastguard Worker     // resulting in the follolwing blending equation (0.2f, 0.3f, 0.4f 1.0f) + (0.0331048, 0.073239, 0.132868) = (0.521569f, 0.647059f, 0.756863f, 1.0f)
1621*35238bceSAndroid Build Coastguard Worker 
1622*35238bceSAndroid Build Coastguard Worker     FBOConfig fboConfig0 =
1623*35238bceSAndroid Build Coastguard Worker         FBOConfig(GL_SRGB8_ALPHA8, getTestColorLinear(), GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, FBOTYPE_SOURCE);
1624*35238bceSAndroid Build Coastguard Worker     FBOConfig fboConfig1 =
1625*35238bceSAndroid Build Coastguard Worker         FBOConfig(GL_RGBA8, getTestColorLinear(), GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, FBOTYPE_SOURCE);
1626*35238bceSAndroid Build Coastguard Worker 
1627*35238bceSAndroid Build Coastguard Worker     const TestRenderPassConfig renderPassConfigs[] = {
1628*35238bceSAndroid Build Coastguard Worker         TestRenderPassConfig(TEXTURESOURCESTYPE_RGBA, fboConfig0, FRAMEBUFFERSRGB_ENABLED, FRAMEBUFFERBLEND_ENABLED,
1629*35238bceSAndroid Build Coastguard Worker                              RENDERERTASK_DRAW),
1630*35238bceSAndroid Build Coastguard Worker         TestRenderPassConfig(TEXTURESOURCESTYPE_BOTH, fboConfig1, FRAMEBUFFERSRGB_DISABLED, FRAMEBUFFERBLEND_DISABLED,
1631*35238bceSAndroid Build Coastguard Worker                              getFunctionBlendLinearToSRGBCheck(), RENDERERTASK_DRAW)};
1632*35238bceSAndroid Build Coastguard Worker     std::vector<TestRenderPassConfig> renderPassConfigList(renderPassConfigs,
1633*35238bceSAndroid Build Coastguard Worker                                                            renderPassConfigs + DE_LENGTH_OF_ARRAY(renderPassConfigs));
1634*35238bceSAndroid Build Coastguard Worker 
1635*35238bceSAndroid Build Coastguard Worker     this->setTestConfig(renderPassConfigList);
1636*35238bceSAndroid Build Coastguard Worker }
1637*35238bceSAndroid Build Coastguard Worker 
verifyResult(void)1638*35238bceSAndroid Build Coastguard Worker bool FboSRGBColAttachCase::verifyResult(void)
1639*35238bceSAndroid Build Coastguard Worker {
1640*35238bceSAndroid Build Coastguard Worker     if (tcu::boolAll(tcu::lessThan(tcu::abs(m_resultsPostDraw[0] - m_resultsPostDraw[1]), getEpsilonError())) ||
1641*35238bceSAndroid Build Coastguard Worker         tcu::boolAll(tcu::equal(m_resultsPostDraw[0], m_resultsPostDraw[1])))
1642*35238bceSAndroid Build Coastguard Worker         return true;
1643*35238bceSAndroid Build Coastguard Worker     else
1644*35238bceSAndroid Build Coastguard Worker         return false;
1645*35238bceSAndroid Build Coastguard Worker }
1646*35238bceSAndroid Build Coastguard Worker 
1647*35238bceSAndroid Build Coastguard Worker class FboSRGBToggleBlendCase : public FboSRGBTestCase
1648*35238bceSAndroid Build Coastguard Worker {
1649*35238bceSAndroid Build Coastguard Worker public:
FboSRGBToggleBlendCase(Context & context,const char * const name,const char * const description)1650*35238bceSAndroid Build Coastguard Worker     FboSRGBToggleBlendCase(Context &context, const char *const name, const char *const description)
1651*35238bceSAndroid Build Coastguard Worker         : FboSRGBTestCase(context, name, description)
1652*35238bceSAndroid Build Coastguard Worker     {
1653*35238bceSAndroid Build Coastguard Worker     }
~FboSRGBToggleBlendCase(void)1654*35238bceSAndroid Build Coastguard Worker     ~FboSRGBToggleBlendCase(void)
1655*35238bceSAndroid Build Coastguard Worker     {
1656*35238bceSAndroid Build Coastguard Worker     }
1657*35238bceSAndroid Build Coastguard Worker 
1658*35238bceSAndroid Build Coastguard Worker     void setupTest(void);
1659*35238bceSAndroid Build Coastguard Worker     bool verifyResult(void);
1660*35238bceSAndroid Build Coastguard Worker };
1661*35238bceSAndroid Build Coastguard Worker 
setupTest(void)1662*35238bceSAndroid Build Coastguard Worker void FboSRGBToggleBlendCase::setupTest(void)
1663*35238bceSAndroid Build Coastguard Worker {
1664*35238bceSAndroid Build Coastguard Worker     //    TEST INFO:
1665*35238bceSAndroid Build Coastguard Worker     //    Test to check if changing FRAMEBUFFER_SRGB_EXT from enabled to disabled. Enabled should produce SRGB color whilst disabled
1666*35238bceSAndroid Build Coastguard Worker     //    should produce linear color. Test conducted with blending disabled.
1667*35238bceSAndroid Build Coastguard Worker 
1668*35238bceSAndroid Build Coastguard Worker     FBOConfig fboConfig0 =
1669*35238bceSAndroid Build Coastguard Worker         FBOConfig(GL_SRGB8_ALPHA8, getTestColorLinear(), GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, FBOTYPE_DESTINATION);
1670*35238bceSAndroid Build Coastguard Worker 
1671*35238bceSAndroid Build Coastguard Worker     const TestRenderPassConfig renderPassConfigs[] = {
1672*35238bceSAndroid Build Coastguard Worker         TestRenderPassConfig(TEXTURESOURCESTYPE_RGBA, fboConfig0, FRAMEBUFFERSRGB_ENABLED, FRAMEBUFFERBLEND_DISABLED,
1673*35238bceSAndroid Build Coastguard Worker                              TestFunction(false), RENDERERTASK_DRAW),
1674*35238bceSAndroid Build Coastguard Worker         TestRenderPassConfig(TEXTURESOURCESTYPE_RGBA, fboConfig0, FRAMEBUFFERSRGB_DISABLED, FRAMEBUFFERBLEND_DISABLED,
1675*35238bceSAndroid Build Coastguard Worker                              TestFunction(false), RENDERERTASK_DRAW)};
1676*35238bceSAndroid Build Coastguard Worker     std::vector<TestRenderPassConfig> renderPassConfigList(renderPassConfigs,
1677*35238bceSAndroid Build Coastguard Worker                                                            renderPassConfigs + DE_LENGTH_OF_ARRAY(renderPassConfigs));
1678*35238bceSAndroid Build Coastguard Worker 
1679*35238bceSAndroid Build Coastguard Worker     this->setTestConfig(renderPassConfigList);
1680*35238bceSAndroid Build Coastguard Worker }
1681*35238bceSAndroid Build Coastguard Worker 
verifyResult(void)1682*35238bceSAndroid Build Coastguard Worker bool FboSRGBToggleBlendCase::verifyResult(void)
1683*35238bceSAndroid Build Coastguard Worker {
1684*35238bceSAndroid Build Coastguard Worker     if (tcu::boolAny(tcu::greaterThan(tcu::abs(m_resultsPostDraw[0] - m_resultsPostDraw[1]), getEpsilonError())))
1685*35238bceSAndroid Build Coastguard Worker         return true;
1686*35238bceSAndroid Build Coastguard Worker     else
1687*35238bceSAndroid Build Coastguard Worker         return false;
1688*35238bceSAndroid Build Coastguard Worker }
1689*35238bceSAndroid Build Coastguard Worker 
1690*35238bceSAndroid Build Coastguard Worker class FboSRGBRenderTargetIgnoreCase : public FboSRGBTestCase
1691*35238bceSAndroid Build Coastguard Worker {
1692*35238bceSAndroid Build Coastguard Worker public:
FboSRGBRenderTargetIgnoreCase(Context & context,const char * const name,const char * const description)1693*35238bceSAndroid Build Coastguard Worker     FboSRGBRenderTargetIgnoreCase(Context &context, const char *const name, const char *const description)
1694*35238bceSAndroid Build Coastguard Worker         : FboSRGBTestCase(context, name, description)
1695*35238bceSAndroid Build Coastguard Worker     {
1696*35238bceSAndroid Build Coastguard Worker     }
~FboSRGBRenderTargetIgnoreCase(void)1697*35238bceSAndroid Build Coastguard Worker     ~FboSRGBRenderTargetIgnoreCase(void)
1698*35238bceSAndroid Build Coastguard Worker     {
1699*35238bceSAndroid Build Coastguard Worker     }
1700*35238bceSAndroid Build Coastguard Worker 
1701*35238bceSAndroid Build Coastguard Worker     void setupTest(void);
1702*35238bceSAndroid Build Coastguard Worker     bool verifyResult(void);
1703*35238bceSAndroid Build Coastguard Worker };
1704*35238bceSAndroid Build Coastguard Worker 
setupTest(void)1705*35238bceSAndroid Build Coastguard Worker void FboSRGBRenderTargetIgnoreCase::setupTest(void)
1706*35238bceSAndroid Build Coastguard Worker {
1707*35238bceSAndroid Build Coastguard Worker     // TEST INFO:
1708*35238bceSAndroid Build Coastguard Worker     // Check if render targets that are non-RGB ignore the state of GL_FRAMEBUFFER_SRGB_EXT. Rendering to an fbo with non-sRGB color
1709*35238bceSAndroid Build Coastguard Worker     // attachment should ignore color space conversion, producing linear color.
1710*35238bceSAndroid Build Coastguard Worker 
1711*35238bceSAndroid Build Coastguard Worker     FBOConfig fboConfig0 =
1712*35238bceSAndroid Build Coastguard Worker         FBOConfig(GL_RGBA8, getTestColorBlank(), GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, FBOTYPE_DESTINATION);
1713*35238bceSAndroid Build Coastguard Worker 
1714*35238bceSAndroid Build Coastguard Worker     const TestRenderPassConfig renderPassConfigs[] = {
1715*35238bceSAndroid Build Coastguard Worker         TestRenderPassConfig(TEXTURESOURCESTYPE_RGBA, fboConfig0, FRAMEBUFFERSRGB_ENABLED, FRAMEBUFFERBLEND_DISABLED,
1716*35238bceSAndroid Build Coastguard Worker                              TestFunction(false), RENDERERTASK_DRAW)
1717*35238bceSAndroid Build Coastguard Worker 
1718*35238bceSAndroid Build Coastguard Worker     };
1719*35238bceSAndroid Build Coastguard Worker     std::vector<TestRenderPassConfig> renderPassConfigList(renderPassConfigs,
1720*35238bceSAndroid Build Coastguard Worker                                                            renderPassConfigs + DE_LENGTH_OF_ARRAY(renderPassConfigs));
1721*35238bceSAndroid Build Coastguard Worker 
1722*35238bceSAndroid Build Coastguard Worker     this->setTestConfig(renderPassConfigList);
1723*35238bceSAndroid Build Coastguard Worker }
1724*35238bceSAndroid Build Coastguard Worker 
verifyResult(void)1725*35238bceSAndroid Build Coastguard Worker bool FboSRGBRenderTargetIgnoreCase::verifyResult(void)
1726*35238bceSAndroid Build Coastguard Worker {
1727*35238bceSAndroid Build Coastguard Worker     if (tcu::boolAll(tcu::lessThan(tcu::abs(m_resultsPostDraw[0] - getTestColorLinear()), getEpsilonError())) ||
1728*35238bceSAndroid Build Coastguard Worker         tcu::boolAll(tcu::equal(m_resultsPostDraw[0], getTestColorLinear())))
1729*35238bceSAndroid Build Coastguard Worker         return true;
1730*35238bceSAndroid Build Coastguard Worker     else
1731*35238bceSAndroid Build Coastguard Worker         return false;
1732*35238bceSAndroid Build Coastguard Worker }
1733*35238bceSAndroid Build Coastguard Worker 
1734*35238bceSAndroid Build Coastguard Worker class FboSRGBCopyToLinearCase : public FboSRGBTestCase
1735*35238bceSAndroid Build Coastguard Worker {
1736*35238bceSAndroid Build Coastguard Worker public:
FboSRGBCopyToLinearCase(Context & context,const char * const name,const char * const description)1737*35238bceSAndroid Build Coastguard Worker     FboSRGBCopyToLinearCase(Context &context, const char *const name, const char *const description)
1738*35238bceSAndroid Build Coastguard Worker         : FboSRGBTestCase(context, name, description)
1739*35238bceSAndroid Build Coastguard Worker     {
1740*35238bceSAndroid Build Coastguard Worker     }
~FboSRGBCopyToLinearCase(void)1741*35238bceSAndroid Build Coastguard Worker     ~FboSRGBCopyToLinearCase(void)
1742*35238bceSAndroid Build Coastguard Worker     {
1743*35238bceSAndroid Build Coastguard Worker     }
1744*35238bceSAndroid Build Coastguard Worker 
1745*35238bceSAndroid Build Coastguard Worker     void setupTest(void);
1746*35238bceSAndroid Build Coastguard Worker     bool verifyResult(void);
1747*35238bceSAndroid Build Coastguard Worker };
1748*35238bceSAndroid Build Coastguard Worker 
setupTest(void)1749*35238bceSAndroid Build Coastguard Worker void FboSRGBCopyToLinearCase::setupTest(void)
1750*35238bceSAndroid Build Coastguard Worker {
1751*35238bceSAndroid Build Coastguard Worker     // TEST INFO:
1752*35238bceSAndroid Build Coastguard Worker     // Check if copying from an fbo with an sRGB color attachment to an fbo with a linear color attachment with FRAMEBUFFER_EXT enabled results in
1753*35238bceSAndroid Build Coastguard Worker     // an sRGB to linear conversion
1754*35238bceSAndroid Build Coastguard Worker 
1755*35238bceSAndroid Build Coastguard Worker     FBOConfig fboConfigs[] = {
1756*35238bceSAndroid Build Coastguard Worker         FBOConfig(GL_SRGB8_ALPHA8, getTestColorSRGB(), GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, FBOTYPE_SOURCE),
1757*35238bceSAndroid Build Coastguard Worker         FBOConfig(GL_RGBA8, getTestColorBlank(), GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, FBOTYPE_DESTINATION)};
1758*35238bceSAndroid Build Coastguard Worker     std::vector<FBOConfig> fboConfigList(fboConfigs, fboConfigs + DE_LENGTH_OF_ARRAY(fboConfigs));
1759*35238bceSAndroid Build Coastguard Worker 
1760*35238bceSAndroid Build Coastguard Worker     const TestRenderPassConfig renderPassConfigs[] = {
1761*35238bceSAndroid Build Coastguard Worker         TestRenderPassConfig(TEXTURESOURCESTYPE_NONE, fboConfigList, FRAMEBUFFERSRGB_ENABLED, FRAMEBUFFERBLEND_DISABLED,
1762*35238bceSAndroid Build Coastguard Worker                              TestFunction(false), RENDERERTASK_COPY)};
1763*35238bceSAndroid Build Coastguard Worker     std::vector<TestRenderPassConfig> renderPassConfigList(renderPassConfigs,
1764*35238bceSAndroid Build Coastguard Worker                                                            renderPassConfigs + DE_LENGTH_OF_ARRAY(renderPassConfigs));
1765*35238bceSAndroid Build Coastguard Worker 
1766*35238bceSAndroid Build Coastguard Worker     this->setTestConfig(renderPassConfigList);
1767*35238bceSAndroid Build Coastguard Worker }
1768*35238bceSAndroid Build Coastguard Worker 
verifyResult(void)1769*35238bceSAndroid Build Coastguard Worker bool FboSRGBCopyToLinearCase::verifyResult(void)
1770*35238bceSAndroid Build Coastguard Worker {
1771*35238bceSAndroid Build Coastguard Worker     logColor(m_context, "pre-copy source fbo color values", m_resultsPreDraw[0]);
1772*35238bceSAndroid Build Coastguard Worker     logColor(m_context, "pre-copy destination fbo color values", m_resultsPreDraw[1]);
1773*35238bceSAndroid Build Coastguard Worker     logColor(m_context, "post-copy source fbo color values", m_resultsPostDraw[0]);
1774*35238bceSAndroid Build Coastguard Worker     logColor(m_context, "post-copy destination fbo color values", m_resultsPostDraw[1]);
1775*35238bceSAndroid Build Coastguard Worker 
1776*35238bceSAndroid Build Coastguard Worker     if (tcu::boolAll(tcu::lessThan(tcu::abs(m_resultsPostDraw[1] - getTestColorLinear()), getEpsilonError())) ||
1777*35238bceSAndroid Build Coastguard Worker         tcu::boolAll(tcu::equal(m_resultsPostDraw[1], getTestColorLinear())))
1778*35238bceSAndroid Build Coastguard Worker         return true;
1779*35238bceSAndroid Build Coastguard Worker     else
1780*35238bceSAndroid Build Coastguard Worker         return false;
1781*35238bceSAndroid Build Coastguard Worker }
1782*35238bceSAndroid Build Coastguard Worker 
1783*35238bceSAndroid Build Coastguard Worker class FboSRGBUnsupportedEnumCase : public TestCase
1784*35238bceSAndroid Build Coastguard Worker {
1785*35238bceSAndroid Build Coastguard Worker public:
1786*35238bceSAndroid Build Coastguard Worker     FboSRGBUnsupportedEnumCase(Context &context, const char *const name, const char *const description);
1787*35238bceSAndroid Build Coastguard Worker     ~FboSRGBUnsupportedEnumCase(void);
1788*35238bceSAndroid Build Coastguard Worker 
1789*35238bceSAndroid Build Coastguard Worker     void init(void);
1790*35238bceSAndroid Build Coastguard Worker     void deinit(void);
1791*35238bceSAndroid Build Coastguard Worker     bool isInvalidEnum(std::string functionName);
1792*35238bceSAndroid Build Coastguard Worker     IterateResult iterate(void);
1793*35238bceSAndroid Build Coastguard Worker };
1794*35238bceSAndroid Build Coastguard Worker 
FboSRGBUnsupportedEnumCase(Context & context,const char * const name,const char * const description)1795*35238bceSAndroid Build Coastguard Worker FboSRGBUnsupportedEnumCase::FboSRGBUnsupportedEnumCase(Context &context, const char *const name,
1796*35238bceSAndroid Build Coastguard Worker                                                        const char *const description)
1797*35238bceSAndroid Build Coastguard Worker     : TestCase(context, name, description)
1798*35238bceSAndroid Build Coastguard Worker {
1799*35238bceSAndroid Build Coastguard Worker }
1800*35238bceSAndroid Build Coastguard Worker 
~FboSRGBUnsupportedEnumCase(void)1801*35238bceSAndroid Build Coastguard Worker FboSRGBUnsupportedEnumCase::~FboSRGBUnsupportedEnumCase(void)
1802*35238bceSAndroid Build Coastguard Worker {
1803*35238bceSAndroid Build Coastguard Worker     FboSRGBUnsupportedEnumCase::deinit();
1804*35238bceSAndroid Build Coastguard Worker }
1805*35238bceSAndroid Build Coastguard Worker 
init(void)1806*35238bceSAndroid Build Coastguard Worker void FboSRGBUnsupportedEnumCase::init(void)
1807*35238bceSAndroid Build Coastguard Worker {
1808*35238bceSAndroid Build Coastguard Worker     if (!glu::isContextTypeES(m_context.getRenderContext().getType()))
1809*35238bceSAndroid Build Coastguard Worker         TCU_THROW(NotSupportedError, "The test is not supported in a non-GLES context");
1810*35238bceSAndroid Build Coastguard Worker 
1811*35238bceSAndroid Build Coastguard Worker     // extension requirements for test
1812*35238bceSAndroid Build Coastguard Worker     if (m_context.getContextInfo().isExtensionSupported("GL_EXT_sRGB_write_control"))
1813*35238bceSAndroid Build Coastguard Worker         TCU_THROW(NotSupportedError, "Test requires extension GL_EXT_sRGB_write_control to be unsupported");
1814*35238bceSAndroid Build Coastguard Worker }
1815*35238bceSAndroid Build Coastguard Worker 
deinit(void)1816*35238bceSAndroid Build Coastguard Worker void FboSRGBUnsupportedEnumCase::deinit(void)
1817*35238bceSAndroid Build Coastguard Worker {
1818*35238bceSAndroid Build Coastguard Worker }
1819*35238bceSAndroid Build Coastguard Worker 
isInvalidEnum(std::string functionName)1820*35238bceSAndroid Build Coastguard Worker bool FboSRGBUnsupportedEnumCase::isInvalidEnum(std::string functionName)
1821*35238bceSAndroid Build Coastguard Worker {
1822*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1823*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log        = m_context.getTestContext().getLog();
1824*35238bceSAndroid Build Coastguard Worker     bool isOk                = true;
1825*35238bceSAndroid Build Coastguard Worker     glw::GLenum error        = GL_NO_ERROR;
1826*35238bceSAndroid Build Coastguard Worker 
1827*35238bceSAndroid Build Coastguard Worker     log << tcu::TestLog::Message << "Checking call to " << functionName << tcu::TestLog::EndMessage;
1828*35238bceSAndroid Build Coastguard Worker 
1829*35238bceSAndroid Build Coastguard Worker     error = gl.getError();
1830*35238bceSAndroid Build Coastguard Worker 
1831*35238bceSAndroid Build Coastguard Worker     if (error != GL_INVALID_ENUM)
1832*35238bceSAndroid Build Coastguard Worker     {
1833*35238bceSAndroid Build Coastguard Worker         log << tcu::TestLog::Message << " returned wrong value [" << glu::getErrorStr(error) << ", expected "
1834*35238bceSAndroid Build Coastguard Worker             << glu::getErrorStr(GL_INVALID_ENUM) << "]" << tcu::TestLog::EndMessage;
1835*35238bceSAndroid Build Coastguard Worker         isOk = false;
1836*35238bceSAndroid Build Coastguard Worker     }
1837*35238bceSAndroid Build Coastguard Worker 
1838*35238bceSAndroid Build Coastguard Worker     return isOk;
1839*35238bceSAndroid Build Coastguard Worker }
1840*35238bceSAndroid Build Coastguard Worker 
iterate(void)1841*35238bceSAndroid Build Coastguard Worker FboSRGBUnsupportedEnumCase::IterateResult FboSRGBUnsupportedEnumCase::iterate(void)
1842*35238bceSAndroid Build Coastguard Worker {
1843*35238bceSAndroid Build Coastguard Worker     // TEST INFO:
1844*35238bceSAndroid Build Coastguard Worker     // API tests that check calls using enum GL_FRAMEBUFFER_SRGB return GL_INVALID_ENUM  when GL_EXT_sRGB_write_control is not supported
1845*35238bceSAndroid Build Coastguard Worker 
1846*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1847*35238bceSAndroid Build Coastguard Worker     bool allPass             = true;
1848*35238bceSAndroid Build Coastguard Worker     glw::GLboolean bEnabled  = GL_FALSE;
1849*35238bceSAndroid Build Coastguard Worker     glw::GLfloat fEnabled    = 0;
1850*35238bceSAndroid Build Coastguard Worker     glw::GLint iEnabled      = 0;
1851*35238bceSAndroid Build Coastguard Worker     glw::GLint64 lEnabled    = 0;
1852*35238bceSAndroid Build Coastguard Worker 
1853*35238bceSAndroid Build Coastguard Worker     m_context.getTestContext().getLog() << tcu::TestLog::Message
1854*35238bceSAndroid Build Coastguard Worker                                         << "Check calls using enum GL_FRAMEBUFFER_SRGB return GL_INVALID_ENUM  when "
1855*35238bceSAndroid Build Coastguard Worker                                            "GL_EXT_sRGB_write_control is not supported\n\n"
1856*35238bceSAndroid Build Coastguard Worker                                         << tcu::TestLog::EndMessage;
1857*35238bceSAndroid Build Coastguard Worker 
1858*35238bceSAndroid Build Coastguard Worker     gl.enable(GL_FRAMEBUFFER_SRGB);
1859*35238bceSAndroid Build Coastguard Worker     allPass &= isInvalidEnum("glEnable()");
1860*35238bceSAndroid Build Coastguard Worker 
1861*35238bceSAndroid Build Coastguard Worker     gl.disable(GL_FRAMEBUFFER_SRGB);
1862*35238bceSAndroid Build Coastguard Worker     allPass &= isInvalidEnum("glDisable()");
1863*35238bceSAndroid Build Coastguard Worker 
1864*35238bceSAndroid Build Coastguard Worker     gl.isEnabled(GL_FRAMEBUFFER_SRGB);
1865*35238bceSAndroid Build Coastguard Worker     allPass &= isInvalidEnum("glIsEnabled()");
1866*35238bceSAndroid Build Coastguard Worker 
1867*35238bceSAndroid Build Coastguard Worker     gl.getBooleanv(GL_FRAMEBUFFER_SRGB, &bEnabled);
1868*35238bceSAndroid Build Coastguard Worker     allPass &= isInvalidEnum("glGetBooleanv()");
1869*35238bceSAndroid Build Coastguard Worker 
1870*35238bceSAndroid Build Coastguard Worker     gl.getFloatv(GL_FRAMEBUFFER_SRGB, &fEnabled);
1871*35238bceSAndroid Build Coastguard Worker     allPass &= isInvalidEnum("glGetFloatv()");
1872*35238bceSAndroid Build Coastguard Worker 
1873*35238bceSAndroid Build Coastguard Worker     gl.getIntegerv(GL_FRAMEBUFFER_SRGB, &iEnabled);
1874*35238bceSAndroid Build Coastguard Worker     allPass &= isInvalidEnum("glGetIntegerv()");
1875*35238bceSAndroid Build Coastguard Worker 
1876*35238bceSAndroid Build Coastguard Worker     gl.getInteger64v(GL_FRAMEBUFFER_SRGB, &lEnabled);
1877*35238bceSAndroid Build Coastguard Worker     allPass &= isInvalidEnum("glGetInteger64v()");
1878*35238bceSAndroid Build Coastguard Worker 
1879*35238bceSAndroid Build Coastguard Worker     if (allPass)
1880*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1881*35238bceSAndroid Build Coastguard Worker     else
1882*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
1883*35238bceSAndroid Build Coastguard Worker 
1884*35238bceSAndroid Build Coastguard Worker     return STOP;
1885*35238bceSAndroid Build Coastguard Worker }
1886*35238bceSAndroid Build Coastguard Worker 
1887*35238bceSAndroid Build Coastguard Worker } // namespace
1888*35238bceSAndroid Build Coastguard Worker 
FboSRGBWriteControlTests(Context & context)1889*35238bceSAndroid Build Coastguard Worker FboSRGBWriteControlTests::FboSRGBWriteControlTests(Context &context)
1890*35238bceSAndroid Build Coastguard Worker     : TestCaseGroup(context, "srgb_write_control", "Colorbuffer tests")
1891*35238bceSAndroid Build Coastguard Worker {
1892*35238bceSAndroid Build Coastguard Worker }
1893*35238bceSAndroid Build Coastguard Worker 
~FboSRGBWriteControlTests(void)1894*35238bceSAndroid Build Coastguard Worker FboSRGBWriteControlTests::~FboSRGBWriteControlTests(void)
1895*35238bceSAndroid Build Coastguard Worker {
1896*35238bceSAndroid Build Coastguard Worker }
1897*35238bceSAndroid Build Coastguard Worker 
init(void)1898*35238bceSAndroid Build Coastguard Worker void FboSRGBWriteControlTests::init(void)
1899*35238bceSAndroid Build Coastguard Worker {
1900*35238bceSAndroid Build Coastguard Worker     this->addChild(new FboSRGBQueryCase(m_context, "framebuffer_srgb_enabled", "srgb enable framebuffer"));
1901*35238bceSAndroid Build Coastguard Worker     this->addChild(new FboSRGBColAttachCase(m_context, "framebuffer_srgb_enabled_col_attach",
1902*35238bceSAndroid Build Coastguard Worker                                             "srgb enable color attachment and framebuffer"));
1903*35238bceSAndroid Build Coastguard Worker     this->addChild(new FboSRGBToggleBlendCase(m_context, "framebuffer_srgb_enabled_blend",
1904*35238bceSAndroid Build Coastguard Worker                                               "toggle framebuffer srgb settings with blend disabled"));
1905*35238bceSAndroid Build Coastguard Worker     this->addChild(new FboSRGBRenderTargetIgnoreCase(m_context, "framebuffer_srgb_enabled_render_target_ignore",
1906*35238bceSAndroid Build Coastguard Worker                                                      "enable framebuffer srgb, non-srgb render target should ignore"));
1907*35238bceSAndroid Build Coastguard Worker     this->addChild(new FboSRGBCopyToLinearCase(m_context, "framebuffer_srgb_enabled_copy_to_linear",
1908*35238bceSAndroid Build Coastguard Worker                                                "no conversion when blittering between framebuffer srgb and linear"));
1909*35238bceSAndroid Build Coastguard Worker 
1910*35238bceSAndroid Build Coastguard Worker     // negative
1911*35238bceSAndroid Build Coastguard Worker     this->addChild(
1912*35238bceSAndroid Build Coastguard Worker         new FboSRGBUnsupportedEnumCase(m_context, "framebuffer_srgb_unsupported_enum",
1913*35238bceSAndroid Build Coastguard Worker                                        "check error codes for query functions when extension is not supported"));
1914*35238bceSAndroid Build Coastguard Worker }
1915*35238bceSAndroid Build Coastguard Worker 
1916*35238bceSAndroid Build Coastguard Worker } // namespace Functional
1917*35238bceSAndroid Build Coastguard Worker } // namespace gles31
1918*35238bceSAndroid Build Coastguard Worker } // namespace deqp
1919