xref: /aosp_15_r20/external/deqp/modules/gles3/functional/es3fFboInvalidateTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program OpenGL ES 3.0 Module
3*35238bceSAndroid Build Coastguard Worker  * -------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker  *
5*35238bceSAndroid Build Coastguard Worker  * Copyright 2014 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 invalidate tests.
22*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker 
24*35238bceSAndroid Build Coastguard Worker #include "es3fFboInvalidateTests.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "es3fFboTestCase.hpp"
26*35238bceSAndroid Build Coastguard Worker #include "es3fFboTestUtil.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "gluTextureUtil.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "tcuImageCompare.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "tcuTextureUtil.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "sglrContextUtil.hpp"
31*35238bceSAndroid Build Coastguard Worker 
32*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
33*35238bceSAndroid Build Coastguard Worker 
34*35238bceSAndroid Build Coastguard Worker #include <algorithm>
35*35238bceSAndroid Build Coastguard Worker 
36*35238bceSAndroid Build Coastguard Worker namespace deqp
37*35238bceSAndroid Build Coastguard Worker {
38*35238bceSAndroid Build Coastguard Worker namespace gles3
39*35238bceSAndroid Build Coastguard Worker {
40*35238bceSAndroid Build Coastguard Worker namespace Functional
41*35238bceSAndroid Build Coastguard Worker {
42*35238bceSAndroid Build Coastguard Worker 
43*35238bceSAndroid Build Coastguard Worker using std::string;
44*35238bceSAndroid Build Coastguard Worker using std::vector;
45*35238bceSAndroid Build Coastguard Worker using tcu::IVec2;
46*35238bceSAndroid Build Coastguard Worker using tcu::IVec3;
47*35238bceSAndroid Build Coastguard Worker using tcu::IVec4;
48*35238bceSAndroid Build Coastguard Worker using tcu::UVec4;
49*35238bceSAndroid Build Coastguard Worker using tcu::Vec2;
50*35238bceSAndroid Build Coastguard Worker using tcu::Vec3;
51*35238bceSAndroid Build Coastguard Worker using tcu::Vec4;
52*35238bceSAndroid Build Coastguard Worker using namespace FboTestUtil;
53*35238bceSAndroid Build Coastguard Worker 
getDefaultFBDiscardAttachments(uint32_t discardBufferBits)54*35238bceSAndroid Build Coastguard Worker static std::vector<uint32_t> getDefaultFBDiscardAttachments(uint32_t discardBufferBits)
55*35238bceSAndroid Build Coastguard Worker {
56*35238bceSAndroid Build Coastguard Worker     vector<uint32_t> attachments;
57*35238bceSAndroid Build Coastguard Worker 
58*35238bceSAndroid Build Coastguard Worker     if (discardBufferBits & GL_COLOR_BUFFER_BIT)
59*35238bceSAndroid Build Coastguard Worker         attachments.push_back(GL_COLOR);
60*35238bceSAndroid Build Coastguard Worker 
61*35238bceSAndroid Build Coastguard Worker     if (discardBufferBits & GL_DEPTH_BUFFER_BIT)
62*35238bceSAndroid Build Coastguard Worker         attachments.push_back(GL_DEPTH);
63*35238bceSAndroid Build Coastguard Worker 
64*35238bceSAndroid Build Coastguard Worker     if (discardBufferBits & GL_STENCIL_BUFFER_BIT)
65*35238bceSAndroid Build Coastguard Worker         attachments.push_back(GL_STENCIL);
66*35238bceSAndroid Build Coastguard Worker 
67*35238bceSAndroid Build Coastguard Worker     return attachments;
68*35238bceSAndroid Build Coastguard Worker }
69*35238bceSAndroid Build Coastguard Worker 
getFBODiscardAttachments(uint32_t discardBufferBits)70*35238bceSAndroid Build Coastguard Worker static std::vector<uint32_t> getFBODiscardAttachments(uint32_t discardBufferBits)
71*35238bceSAndroid Build Coastguard Worker {
72*35238bceSAndroid Build Coastguard Worker     vector<uint32_t> attachments;
73*35238bceSAndroid Build Coastguard Worker 
74*35238bceSAndroid Build Coastguard Worker     if (discardBufferBits & GL_COLOR_BUFFER_BIT)
75*35238bceSAndroid Build Coastguard Worker         attachments.push_back(GL_COLOR_ATTACHMENT0);
76*35238bceSAndroid Build Coastguard Worker 
77*35238bceSAndroid Build Coastguard Worker     // \note DEPTH_STENCIL_ATTACHMENT is allowed when discarding FBO, but not with default FB
78*35238bceSAndroid Build Coastguard Worker     if ((discardBufferBits & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) ==
79*35238bceSAndroid Build Coastguard Worker         (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT))
80*35238bceSAndroid Build Coastguard Worker         attachments.push_back(GL_DEPTH_STENCIL_ATTACHMENT);
81*35238bceSAndroid Build Coastguard Worker     else if (discardBufferBits & GL_DEPTH_BUFFER_BIT)
82*35238bceSAndroid Build Coastguard Worker         attachments.push_back(GL_DEPTH_ATTACHMENT);
83*35238bceSAndroid Build Coastguard Worker     else if (discardBufferBits & GL_STENCIL_BUFFER_BIT)
84*35238bceSAndroid Build Coastguard Worker         attachments.push_back(GL_STENCIL_ATTACHMENT);
85*35238bceSAndroid Build Coastguard Worker 
86*35238bceSAndroid Build Coastguard Worker     return attachments;
87*35238bceSAndroid Build Coastguard Worker }
88*35238bceSAndroid Build Coastguard Worker 
hasAttachment(const std::vector<uint32_t> & attachmentList,uint32_t attachment)89*35238bceSAndroid Build Coastguard Worker static inline bool hasAttachment(const std::vector<uint32_t> &attachmentList, uint32_t attachment)
90*35238bceSAndroid Build Coastguard Worker {
91*35238bceSAndroid Build Coastguard Worker     return std::find(attachmentList.begin(), attachmentList.end(), attachment) != attachmentList.end();
92*35238bceSAndroid Build Coastguard Worker }
93*35238bceSAndroid Build Coastguard Worker 
getCompatibleColorFormat(const tcu::RenderTarget & renderTargetInfo)94*35238bceSAndroid Build Coastguard Worker static uint32_t getCompatibleColorFormat(const tcu::RenderTarget &renderTargetInfo)
95*35238bceSAndroid Build Coastguard Worker {
96*35238bceSAndroid Build Coastguard Worker     const tcu::PixelFormat &pxFmt = renderTargetInfo.getPixelFormat();
97*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(de::inBounds(pxFmt.redBits, 0, 0xff) && de::inBounds(pxFmt.greenBits, 0, 0xff) &&
98*35238bceSAndroid Build Coastguard Worker               de::inBounds(pxFmt.blueBits, 0, 0xff) && de::inBounds(pxFmt.alphaBits, 0, 0xff));
99*35238bceSAndroid Build Coastguard Worker 
100*35238bceSAndroid Build Coastguard Worker #define PACK_FMT(R, G, B, A) (((R) << 24) | ((G) << 16) | ((B) << 8) | (A))
101*35238bceSAndroid Build Coastguard Worker 
102*35238bceSAndroid Build Coastguard Worker     // \note [pyry] This may not hold true on some implementations - best effort guess only.
103*35238bceSAndroid Build Coastguard Worker     switch (PACK_FMT(pxFmt.redBits, pxFmt.greenBits, pxFmt.blueBits, pxFmt.alphaBits))
104*35238bceSAndroid Build Coastguard Worker     {
105*35238bceSAndroid Build Coastguard Worker     case PACK_FMT(8, 8, 8, 8):
106*35238bceSAndroid Build Coastguard Worker         return GL_RGBA8;
107*35238bceSAndroid Build Coastguard Worker     case PACK_FMT(8, 8, 8, 0):
108*35238bceSAndroid Build Coastguard Worker         return GL_RGB8;
109*35238bceSAndroid Build Coastguard Worker     case PACK_FMT(4, 4, 4, 4):
110*35238bceSAndroid Build Coastguard Worker         return GL_RGBA4;
111*35238bceSAndroid Build Coastguard Worker     case PACK_FMT(5, 5, 5, 1):
112*35238bceSAndroid Build Coastguard Worker         return GL_RGB5_A1;
113*35238bceSAndroid Build Coastguard Worker     case PACK_FMT(5, 6, 5, 0):
114*35238bceSAndroid Build Coastguard Worker         return GL_RGB565;
115*35238bceSAndroid Build Coastguard Worker     default:
116*35238bceSAndroid Build Coastguard Worker         return GL_NONE;
117*35238bceSAndroid Build Coastguard Worker     }
118*35238bceSAndroid Build Coastguard Worker 
119*35238bceSAndroid Build Coastguard Worker #undef PACK_FMT
120*35238bceSAndroid Build Coastguard Worker }
121*35238bceSAndroid Build Coastguard Worker 
getCompatibleDepthStencilFormat(const tcu::RenderTarget & renderTargetInfo)122*35238bceSAndroid Build Coastguard Worker static uint32_t getCompatibleDepthStencilFormat(const tcu::RenderTarget &renderTargetInfo)
123*35238bceSAndroid Build Coastguard Worker {
124*35238bceSAndroid Build Coastguard Worker     const int depthBits   = renderTargetInfo.getDepthBits();
125*35238bceSAndroid Build Coastguard Worker     const int stencilBits = renderTargetInfo.getStencilBits();
126*35238bceSAndroid Build Coastguard Worker     const bool hasDepth   = depthBits > 0;
127*35238bceSAndroid Build Coastguard Worker     const bool hasStencil = stencilBits > 0;
128*35238bceSAndroid Build Coastguard Worker 
129*35238bceSAndroid Build Coastguard Worker     if (!hasDepth || !hasStencil || (stencilBits != 8))
130*35238bceSAndroid Build Coastguard Worker         return GL_NONE;
131*35238bceSAndroid Build Coastguard Worker 
132*35238bceSAndroid Build Coastguard Worker     if (depthBits == 32)
133*35238bceSAndroid Build Coastguard Worker         return GL_DEPTH32F_STENCIL8;
134*35238bceSAndroid Build Coastguard Worker     else if (depthBits == 24)
135*35238bceSAndroid Build Coastguard Worker         return GL_DEPTH24_STENCIL8;
136*35238bceSAndroid Build Coastguard Worker     else
137*35238bceSAndroid Build Coastguard Worker         return GL_NONE;
138*35238bceSAndroid Build Coastguard Worker }
139*35238bceSAndroid Build Coastguard Worker 
140*35238bceSAndroid Build Coastguard Worker class InvalidateDefaultFramebufferRenderCase : public FboTestCase
141*35238bceSAndroid Build Coastguard Worker {
142*35238bceSAndroid Build Coastguard Worker public:
InvalidateDefaultFramebufferRenderCase(Context & context,const char * name,const char * description,uint32_t buffers,uint32_t fboTarget=GL_FRAMEBUFFER)143*35238bceSAndroid Build Coastguard Worker     InvalidateDefaultFramebufferRenderCase(Context &context, const char *name, const char *description,
144*35238bceSAndroid Build Coastguard Worker                                            uint32_t buffers, uint32_t fboTarget = GL_FRAMEBUFFER)
145*35238bceSAndroid Build Coastguard Worker         : FboTestCase(context, name, description)
146*35238bceSAndroid Build Coastguard Worker         , m_buffers(buffers)
147*35238bceSAndroid Build Coastguard Worker         , m_fboTarget(fboTarget)
148*35238bceSAndroid Build Coastguard Worker     {
149*35238bceSAndroid Build Coastguard Worker     }
150*35238bceSAndroid Build Coastguard Worker 
render(tcu::Surface & dst)151*35238bceSAndroid Build Coastguard Worker     void render(tcu::Surface &dst)
152*35238bceSAndroid Build Coastguard Worker     {
153*35238bceSAndroid Build Coastguard Worker         FlatColorShader flatShader(glu::TYPE_FLOAT_VEC4);
154*35238bceSAndroid Build Coastguard Worker         vector<uint32_t> attachments = getDefaultFBDiscardAttachments(m_buffers);
155*35238bceSAndroid Build Coastguard Worker         uint32_t flatShaderID        = getCurrentContext()->createProgram(&flatShader);
156*35238bceSAndroid Build Coastguard Worker 
157*35238bceSAndroid Build Coastguard Worker         glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
158*35238bceSAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
159*35238bceSAndroid Build Coastguard Worker 
160*35238bceSAndroid Build Coastguard Worker         glEnable(GL_DEPTH_TEST);
161*35238bceSAndroid Build Coastguard Worker         glEnable(GL_STENCIL_TEST);
162*35238bceSAndroid Build Coastguard Worker         glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
163*35238bceSAndroid Build Coastguard Worker         glStencilFunc(GL_ALWAYS, 1, 0xff);
164*35238bceSAndroid Build Coastguard Worker 
165*35238bceSAndroid Build Coastguard Worker         flatShader.setColor(*getCurrentContext(), flatShaderID, Vec4(1.0f, 0.0f, 0.0f, 1.0f));
166*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(*getCurrentContext(), flatShaderID, Vec3(-1.0f, -1.0f, -1.0f), Vec3(1.0f, 1.0f, 1.0f));
167*35238bceSAndroid Build Coastguard Worker 
168*35238bceSAndroid Build Coastguard Worker         glInvalidateFramebuffer(m_fboTarget, (int)attachments.size(), attachments.empty() ? DE_NULL : &attachments[0]);
169*35238bceSAndroid Build Coastguard Worker 
170*35238bceSAndroid Build Coastguard Worker         if ((m_buffers & GL_COLOR_BUFFER_BIT) != 0)
171*35238bceSAndroid Build Coastguard Worker         {
172*35238bceSAndroid Build Coastguard Worker             // Color was not preserved - fill with green.
173*35238bceSAndroid Build Coastguard Worker             glDisable(GL_DEPTH_TEST);
174*35238bceSAndroid Build Coastguard Worker             glDisable(GL_STENCIL_TEST);
175*35238bceSAndroid Build Coastguard Worker 
176*35238bceSAndroid Build Coastguard Worker             flatShader.setColor(*getCurrentContext(), flatShaderID, Vec4(0.0f, 1.0f, 0.0f, 1.0f));
177*35238bceSAndroid Build Coastguard Worker             sglr::drawQuad(*getCurrentContext(), flatShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
178*35238bceSAndroid Build Coastguard Worker 
179*35238bceSAndroid Build Coastguard Worker             glEnable(GL_DEPTH_TEST);
180*35238bceSAndroid Build Coastguard Worker             glEnable(GL_STENCIL_TEST);
181*35238bceSAndroid Build Coastguard Worker         }
182*35238bceSAndroid Build Coastguard Worker 
183*35238bceSAndroid Build Coastguard Worker         if ((m_buffers & GL_DEPTH_BUFFER_BIT) != 0)
184*35238bceSAndroid Build Coastguard Worker         {
185*35238bceSAndroid Build Coastguard Worker             // Depth was not preserved.
186*35238bceSAndroid Build Coastguard Worker             glDepthFunc(GL_ALWAYS);
187*35238bceSAndroid Build Coastguard Worker         }
188*35238bceSAndroid Build Coastguard Worker 
189*35238bceSAndroid Build Coastguard Worker         if ((m_buffers & GL_STENCIL_BUFFER_BIT) == 0)
190*35238bceSAndroid Build Coastguard Worker         {
191*35238bceSAndroid Build Coastguard Worker             // Stencil was preserved.
192*35238bceSAndroid Build Coastguard Worker             glStencilFunc(GL_EQUAL, 1, 0xff);
193*35238bceSAndroid Build Coastguard Worker         }
194*35238bceSAndroid Build Coastguard Worker 
195*35238bceSAndroid Build Coastguard Worker         glEnable(GL_BLEND);
196*35238bceSAndroid Build Coastguard Worker         glBlendFunc(GL_ONE, GL_ONE);
197*35238bceSAndroid Build Coastguard Worker         glBlendEquation(GL_FUNC_ADD);
198*35238bceSAndroid Build Coastguard Worker 
199*35238bceSAndroid Build Coastguard Worker         flatShader.setColor(*getCurrentContext(), flatShaderID, Vec4(0.0f, 0.0f, 1.0f, 1.0f));
200*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(*getCurrentContext(), flatShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
201*35238bceSAndroid Build Coastguard Worker 
202*35238bceSAndroid Build Coastguard Worker         readPixels(dst, 0, 0, getWidth(), getHeight());
203*35238bceSAndroid Build Coastguard Worker     }
204*35238bceSAndroid Build Coastguard Worker 
205*35238bceSAndroid Build Coastguard Worker private:
206*35238bceSAndroid Build Coastguard Worker     uint32_t m_buffers;
207*35238bceSAndroid Build Coastguard Worker     uint32_t m_fboTarget;
208*35238bceSAndroid Build Coastguard Worker };
209*35238bceSAndroid Build Coastguard Worker 
210*35238bceSAndroid Build Coastguard Worker class InvalidateDefaultFramebufferBindCase : public FboTestCase
211*35238bceSAndroid Build Coastguard Worker {
212*35238bceSAndroid Build Coastguard Worker public:
InvalidateDefaultFramebufferBindCase(Context & context,const char * name,const char * description,uint32_t buffers)213*35238bceSAndroid Build Coastguard Worker     InvalidateDefaultFramebufferBindCase(Context &context, const char *name, const char *description, uint32_t buffers)
214*35238bceSAndroid Build Coastguard Worker         : FboTestCase(context, name, description)
215*35238bceSAndroid Build Coastguard Worker         , m_buffers(buffers)
216*35238bceSAndroid Build Coastguard Worker     {
217*35238bceSAndroid Build Coastguard Worker     }
218*35238bceSAndroid Build Coastguard Worker 
render(tcu::Surface & dst)219*35238bceSAndroid Build Coastguard Worker     void render(tcu::Surface &dst)
220*35238bceSAndroid Build Coastguard Worker     {
221*35238bceSAndroid Build Coastguard Worker         uint32_t fbo = 0;
222*35238bceSAndroid Build Coastguard Worker         uint32_t tex = 0;
223*35238bceSAndroid Build Coastguard Worker         FlatColorShader flatShader(glu::TYPE_FLOAT_VEC4);
224*35238bceSAndroid Build Coastguard Worker         Texture2DShader texShader(DataTypes() << glu::TYPE_SAMPLER_2D, glu::TYPE_FLOAT_VEC4);
225*35238bceSAndroid Build Coastguard Worker         GradientShader gradShader(glu::TYPE_FLOAT_VEC4);
226*35238bceSAndroid Build Coastguard Worker         vector<uint32_t> attachments = getDefaultFBDiscardAttachments(m_buffers);
227*35238bceSAndroid Build Coastguard Worker         uint32_t flatShaderID        = getCurrentContext()->createProgram(&flatShader);
228*35238bceSAndroid Build Coastguard Worker         uint32_t texShaderID         = getCurrentContext()->createProgram(&texShader);
229*35238bceSAndroid Build Coastguard Worker         uint32_t gradShaderID        = getCurrentContext()->createProgram(&gradShader);
230*35238bceSAndroid Build Coastguard Worker 
231*35238bceSAndroid Build Coastguard Worker         glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
232*35238bceSAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
233*35238bceSAndroid Build Coastguard Worker 
234*35238bceSAndroid Build Coastguard Worker         // Create fbo.
235*35238bceSAndroid Build Coastguard Worker         glGenFramebuffers(1, &fbo);
236*35238bceSAndroid Build Coastguard Worker         glGenTextures(1, &tex);
237*35238bceSAndroid Build Coastguard Worker         glBindTexture(GL_TEXTURE_2D, tex);
238*35238bceSAndroid Build Coastguard Worker         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWidth(), getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
239*35238bceSAndroid Build Coastguard Worker         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
240*35238bceSAndroid Build Coastguard Worker         glBindFramebuffer(GL_FRAMEBUFFER, fbo);
241*35238bceSAndroid Build Coastguard Worker         glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
242*35238bceSAndroid Build Coastguard Worker         glBindTexture(GL_TEXTURE_2D, 0);
243*35238bceSAndroid Build Coastguard Worker         checkFramebufferStatus(GL_FRAMEBUFFER);
244*35238bceSAndroid Build Coastguard Worker 
245*35238bceSAndroid Build Coastguard Worker         glBindFramebuffer(GL_FRAMEBUFFER, 0);
246*35238bceSAndroid Build Coastguard Worker 
247*35238bceSAndroid Build Coastguard Worker         glEnable(GL_DEPTH_TEST);
248*35238bceSAndroid Build Coastguard Worker         glEnable(GL_STENCIL_TEST);
249*35238bceSAndroid Build Coastguard Worker         glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
250*35238bceSAndroid Build Coastguard Worker         glStencilFunc(GL_ALWAYS, 1, 0xff);
251*35238bceSAndroid Build Coastguard Worker 
252*35238bceSAndroid Build Coastguard Worker         flatShader.setColor(*getCurrentContext(), flatShaderID, Vec4(1.0f, 0.0f, 0.0f, 1.0f));
253*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(*getCurrentContext(), flatShaderID, Vec3(-1.0f, -1.0f, -1.0f), Vec3(1.0f, 1.0f, 1.0f));
254*35238bceSAndroid Build Coastguard Worker 
255*35238bceSAndroid Build Coastguard Worker         glInvalidateFramebuffer(GL_FRAMEBUFFER, (int)attachments.size(),
256*35238bceSAndroid Build Coastguard Worker                                 attachments.empty() ? DE_NULL : &attachments[0]);
257*35238bceSAndroid Build Coastguard Worker 
258*35238bceSAndroid Build Coastguard Worker         // Switch to fbo and render gradient into it.
259*35238bceSAndroid Build Coastguard Worker         glDisable(GL_DEPTH_TEST);
260*35238bceSAndroid Build Coastguard Worker         glDisable(GL_STENCIL_TEST);
261*35238bceSAndroid Build Coastguard Worker         glBindFramebuffer(GL_FRAMEBUFFER, fbo);
262*35238bceSAndroid Build Coastguard Worker 
263*35238bceSAndroid Build Coastguard Worker         gradShader.setGradient(*getCurrentContext(), gradShaderID, Vec4(0.0f), Vec4(1.0f));
264*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(*getCurrentContext(), gradShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
265*35238bceSAndroid Build Coastguard Worker 
266*35238bceSAndroid Build Coastguard Worker         // Restore default fbo.
267*35238bceSAndroid Build Coastguard Worker         glBindFramebuffer(GL_FRAMEBUFFER, 0);
268*35238bceSAndroid Build Coastguard Worker 
269*35238bceSAndroid Build Coastguard Worker         if ((m_buffers & GL_COLOR_BUFFER_BIT) != 0)
270*35238bceSAndroid Build Coastguard Worker         {
271*35238bceSAndroid Build Coastguard Worker             // Color was not preserved - fill with green.
272*35238bceSAndroid Build Coastguard Worker             flatShader.setColor(*getCurrentContext(), flatShaderID, Vec4(0.0f, 1.0f, 0.0f, 1.0f));
273*35238bceSAndroid Build Coastguard Worker             sglr::drawQuad(*getCurrentContext(), flatShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
274*35238bceSAndroid Build Coastguard Worker         }
275*35238bceSAndroid Build Coastguard Worker 
276*35238bceSAndroid Build Coastguard Worker         if ((m_buffers & GL_DEPTH_BUFFER_BIT) != 0)
277*35238bceSAndroid Build Coastguard Worker         {
278*35238bceSAndroid Build Coastguard Worker             // Depth was not preserved.
279*35238bceSAndroid Build Coastguard Worker             glDepthFunc(GL_ALWAYS);
280*35238bceSAndroid Build Coastguard Worker         }
281*35238bceSAndroid Build Coastguard Worker 
282*35238bceSAndroid Build Coastguard Worker         if ((m_buffers & GL_STENCIL_BUFFER_BIT) == 0)
283*35238bceSAndroid Build Coastguard Worker         {
284*35238bceSAndroid Build Coastguard Worker             // Stencil was preserved.
285*35238bceSAndroid Build Coastguard Worker             glStencilFunc(GL_EQUAL, 1, 0xff);
286*35238bceSAndroid Build Coastguard Worker         }
287*35238bceSAndroid Build Coastguard Worker 
288*35238bceSAndroid Build Coastguard Worker         glEnable(GL_DEPTH_TEST);
289*35238bceSAndroid Build Coastguard Worker         glEnable(GL_STENCIL_TEST);
290*35238bceSAndroid Build Coastguard Worker         glEnable(GL_BLEND);
291*35238bceSAndroid Build Coastguard Worker         glBlendFunc(GL_ONE, GL_ONE);
292*35238bceSAndroid Build Coastguard Worker         glBlendEquation(GL_FUNC_ADD);
293*35238bceSAndroid Build Coastguard Worker         glBindTexture(GL_TEXTURE_2D, tex);
294*35238bceSAndroid Build Coastguard Worker 
295*35238bceSAndroid Build Coastguard Worker         texShader.setUniforms(*getCurrentContext(), texShaderID);
296*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(*getCurrentContext(), texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
297*35238bceSAndroid Build Coastguard Worker 
298*35238bceSAndroid Build Coastguard Worker         readPixels(dst, 0, 0, getWidth(), getHeight());
299*35238bceSAndroid Build Coastguard Worker     }
300*35238bceSAndroid Build Coastguard Worker 
301*35238bceSAndroid Build Coastguard Worker private:
302*35238bceSAndroid Build Coastguard Worker     uint32_t m_buffers;
303*35238bceSAndroid Build Coastguard Worker };
304*35238bceSAndroid Build Coastguard Worker 
305*35238bceSAndroid Build Coastguard Worker class InvalidateDefaultSubFramebufferRenderCase : public FboTestCase
306*35238bceSAndroid Build Coastguard Worker {
307*35238bceSAndroid Build Coastguard Worker public:
InvalidateDefaultSubFramebufferRenderCase(Context & context,const char * name,const char * description,uint32_t buffers)308*35238bceSAndroid Build Coastguard Worker     InvalidateDefaultSubFramebufferRenderCase(Context &context, const char *name, const char *description,
309*35238bceSAndroid Build Coastguard Worker                                               uint32_t buffers)
310*35238bceSAndroid Build Coastguard Worker         : FboTestCase(context, name, description)
311*35238bceSAndroid Build Coastguard Worker         , m_buffers(buffers)
312*35238bceSAndroid Build Coastguard Worker     {
313*35238bceSAndroid Build Coastguard Worker     }
314*35238bceSAndroid Build Coastguard Worker 
render(tcu::Surface & dst)315*35238bceSAndroid Build Coastguard Worker     void render(tcu::Surface &dst)
316*35238bceSAndroid Build Coastguard Worker     {
317*35238bceSAndroid Build Coastguard Worker         int invalidateX = getWidth() / 4;
318*35238bceSAndroid Build Coastguard Worker         int invalidateY = getHeight() / 4;
319*35238bceSAndroid Build Coastguard Worker         int invalidateW = getWidth() / 2;
320*35238bceSAndroid Build Coastguard Worker         int invalidateH = getHeight() / 2;
321*35238bceSAndroid Build Coastguard Worker         FlatColorShader flatShader(glu::TYPE_FLOAT_VEC4);
322*35238bceSAndroid Build Coastguard Worker         vector<uint32_t> attachments = getDefaultFBDiscardAttachments(m_buffers);
323*35238bceSAndroid Build Coastguard Worker         uint32_t flatShaderID        = getCurrentContext()->createProgram(&flatShader);
324*35238bceSAndroid Build Coastguard Worker 
325*35238bceSAndroid Build Coastguard Worker         glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
326*35238bceSAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
327*35238bceSAndroid Build Coastguard Worker 
328*35238bceSAndroid Build Coastguard Worker         glEnable(GL_DEPTH_TEST);
329*35238bceSAndroid Build Coastguard Worker         glEnable(GL_STENCIL_TEST);
330*35238bceSAndroid Build Coastguard Worker         glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
331*35238bceSAndroid Build Coastguard Worker         glStencilFunc(GL_ALWAYS, 1, 0xff);
332*35238bceSAndroid Build Coastguard Worker 
333*35238bceSAndroid Build Coastguard Worker         flatShader.setColor(*getCurrentContext(), flatShaderID, Vec4(1.0f, 0.0f, 0.0f, 1.0f));
334*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(*getCurrentContext(), flatShaderID, Vec3(-1.0f, -1.0f, -1.0f), Vec3(1.0f, 1.0f, 1.0f));
335*35238bceSAndroid Build Coastguard Worker 
336*35238bceSAndroid Build Coastguard Worker         glInvalidateSubFramebuffer(GL_FRAMEBUFFER, (int)attachments.size(), &attachments[0], invalidateX, invalidateY,
337*35238bceSAndroid Build Coastguard Worker                                    invalidateW, invalidateH);
338*35238bceSAndroid Build Coastguard Worker 
339*35238bceSAndroid Build Coastguard Worker         // Clear invalidated buffers.
340*35238bceSAndroid Build Coastguard Worker         glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
341*35238bceSAndroid Build Coastguard Worker         glClearStencil(1);
342*35238bceSAndroid Build Coastguard Worker         glScissor(invalidateX, invalidateY, invalidateW, invalidateH);
343*35238bceSAndroid Build Coastguard Worker         glEnable(GL_SCISSOR_TEST);
344*35238bceSAndroid Build Coastguard Worker         glClear(m_buffers);
345*35238bceSAndroid Build Coastguard Worker         glDisable(GL_SCISSOR_TEST);
346*35238bceSAndroid Build Coastguard Worker 
347*35238bceSAndroid Build Coastguard Worker         glEnable(GL_BLEND);
348*35238bceSAndroid Build Coastguard Worker         glBlendFunc(GL_ONE, GL_ONE);
349*35238bceSAndroid Build Coastguard Worker         glBlendEquation(GL_FUNC_ADD);
350*35238bceSAndroid Build Coastguard Worker 
351*35238bceSAndroid Build Coastguard Worker         flatShader.setColor(*getCurrentContext(), flatShaderID, Vec4(0.0f, 0.0f, 1.0f, 1.0f));
352*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(*getCurrentContext(), flatShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
353*35238bceSAndroid Build Coastguard Worker 
354*35238bceSAndroid Build Coastguard Worker         readPixels(dst, 0, 0, getWidth(), getHeight());
355*35238bceSAndroid Build Coastguard Worker     }
356*35238bceSAndroid Build Coastguard Worker 
357*35238bceSAndroid Build Coastguard Worker private:
358*35238bceSAndroid Build Coastguard Worker     uint32_t m_buffers;
359*35238bceSAndroid Build Coastguard Worker };
360*35238bceSAndroid Build Coastguard Worker 
361*35238bceSAndroid Build Coastguard Worker class InvalidateDefaultSubFramebufferBindCase : public FboTestCase
362*35238bceSAndroid Build Coastguard Worker {
363*35238bceSAndroid Build Coastguard Worker public:
InvalidateDefaultSubFramebufferBindCase(Context & context,const char * name,const char * description,uint32_t buffers)364*35238bceSAndroid Build Coastguard Worker     InvalidateDefaultSubFramebufferBindCase(Context &context, const char *name, const char *description,
365*35238bceSAndroid Build Coastguard Worker                                             uint32_t buffers)
366*35238bceSAndroid Build Coastguard Worker         : FboTestCase(context, name, description)
367*35238bceSAndroid Build Coastguard Worker         , m_buffers(buffers)
368*35238bceSAndroid Build Coastguard Worker     {
369*35238bceSAndroid Build Coastguard Worker     }
370*35238bceSAndroid Build Coastguard Worker 
render(tcu::Surface & dst)371*35238bceSAndroid Build Coastguard Worker     void render(tcu::Surface &dst)
372*35238bceSAndroid Build Coastguard Worker     {
373*35238bceSAndroid Build Coastguard Worker         uint32_t fbo = 0;
374*35238bceSAndroid Build Coastguard Worker         uint32_t tex = 0;
375*35238bceSAndroid Build Coastguard Worker         FlatColorShader flatShader(glu::TYPE_FLOAT_VEC4);
376*35238bceSAndroid Build Coastguard Worker         Texture2DShader texShader(DataTypes() << glu::TYPE_SAMPLER_2D, glu::TYPE_FLOAT_VEC4);
377*35238bceSAndroid Build Coastguard Worker         GradientShader gradShader(glu::TYPE_FLOAT_VEC4);
378*35238bceSAndroid Build Coastguard Worker         vector<uint32_t> attachments = getDefaultFBDiscardAttachments(m_buffers);
379*35238bceSAndroid Build Coastguard Worker         uint32_t flatShaderID        = getCurrentContext()->createProgram(&flatShader);
380*35238bceSAndroid Build Coastguard Worker         uint32_t texShaderID         = getCurrentContext()->createProgram(&texShader);
381*35238bceSAndroid Build Coastguard Worker         uint32_t gradShaderID        = getCurrentContext()->createProgram(&gradShader);
382*35238bceSAndroid Build Coastguard Worker 
383*35238bceSAndroid Build Coastguard Worker         int invalidateX = getWidth() / 4;
384*35238bceSAndroid Build Coastguard Worker         int invalidateY = getHeight() / 4;
385*35238bceSAndroid Build Coastguard Worker         int invalidateW = getWidth() / 2;
386*35238bceSAndroid Build Coastguard Worker         int invalidateH = getHeight() / 2;
387*35238bceSAndroid Build Coastguard Worker 
388*35238bceSAndroid Build Coastguard Worker         flatShader.setColor(*getCurrentContext(), flatShaderID, Vec4(1.0f, 0.0f, 0.0f, 1.0f));
389*35238bceSAndroid Build Coastguard Worker         texShader.setUniforms(*getCurrentContext(), texShaderID);
390*35238bceSAndroid Build Coastguard Worker         gradShader.setGradient(*getCurrentContext(), gradShaderID, Vec4(0.0f), Vec4(1.0f));
391*35238bceSAndroid Build Coastguard Worker 
392*35238bceSAndroid Build Coastguard Worker         glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
393*35238bceSAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
394*35238bceSAndroid Build Coastguard Worker 
395*35238bceSAndroid Build Coastguard Worker         // Create fbo.
396*35238bceSAndroid Build Coastguard Worker         glGenFramebuffers(1, &fbo);
397*35238bceSAndroid Build Coastguard Worker         glGenTextures(1, &tex);
398*35238bceSAndroid Build Coastguard Worker         glBindTexture(GL_TEXTURE_2D, tex);
399*35238bceSAndroid Build Coastguard Worker         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWidth(), getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
400*35238bceSAndroid Build Coastguard Worker         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
401*35238bceSAndroid Build Coastguard Worker         glBindFramebuffer(GL_FRAMEBUFFER, fbo);
402*35238bceSAndroid Build Coastguard Worker         glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
403*35238bceSAndroid Build Coastguard Worker         glBindTexture(GL_TEXTURE_2D, 0);
404*35238bceSAndroid Build Coastguard Worker         checkFramebufferStatus(GL_FRAMEBUFFER);
405*35238bceSAndroid Build Coastguard Worker 
406*35238bceSAndroid Build Coastguard Worker         glBindFramebuffer(GL_FRAMEBUFFER, 0);
407*35238bceSAndroid Build Coastguard Worker 
408*35238bceSAndroid Build Coastguard Worker         glEnable(GL_DEPTH_TEST);
409*35238bceSAndroid Build Coastguard Worker         glEnable(GL_STENCIL_TEST);
410*35238bceSAndroid Build Coastguard Worker         glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
411*35238bceSAndroid Build Coastguard Worker         glStencilFunc(GL_ALWAYS, 1, 0xff);
412*35238bceSAndroid Build Coastguard Worker 
413*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(*getCurrentContext(), flatShaderID, Vec3(-1.0f, -1.0f, -1.0f), Vec3(1.0f, 1.0f, 1.0f));
414*35238bceSAndroid Build Coastguard Worker 
415*35238bceSAndroid Build Coastguard Worker         glInvalidateSubFramebuffer(GL_FRAMEBUFFER, (int)attachments.size(), &attachments[0], invalidateX, invalidateY,
416*35238bceSAndroid Build Coastguard Worker                                    invalidateW, invalidateH);
417*35238bceSAndroid Build Coastguard Worker 
418*35238bceSAndroid Build Coastguard Worker         // Switch to fbo and render gradient into it.
419*35238bceSAndroid Build Coastguard Worker         glDisable(GL_DEPTH_TEST);
420*35238bceSAndroid Build Coastguard Worker         glDisable(GL_STENCIL_TEST);
421*35238bceSAndroid Build Coastguard Worker         glBindFramebuffer(GL_FRAMEBUFFER, fbo);
422*35238bceSAndroid Build Coastguard Worker 
423*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(*getCurrentContext(), gradShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
424*35238bceSAndroid Build Coastguard Worker 
425*35238bceSAndroid Build Coastguard Worker         // Restore default fbo.
426*35238bceSAndroid Build Coastguard Worker         glBindFramebuffer(GL_FRAMEBUFFER, 0);
427*35238bceSAndroid Build Coastguard Worker 
428*35238bceSAndroid Build Coastguard Worker         // Clear invalidated buffers.
429*35238bceSAndroid Build Coastguard Worker         glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
430*35238bceSAndroid Build Coastguard Worker         glClearStencil(1);
431*35238bceSAndroid Build Coastguard Worker         glScissor(invalidateX, invalidateY, invalidateW, invalidateH);
432*35238bceSAndroid Build Coastguard Worker         glEnable(GL_SCISSOR_TEST);
433*35238bceSAndroid Build Coastguard Worker         glClear(m_buffers);
434*35238bceSAndroid Build Coastguard Worker         glDisable(GL_SCISSOR_TEST);
435*35238bceSAndroid Build Coastguard Worker 
436*35238bceSAndroid Build Coastguard Worker         glEnable(GL_DEPTH_TEST);
437*35238bceSAndroid Build Coastguard Worker         glEnable(GL_STENCIL_TEST);
438*35238bceSAndroid Build Coastguard Worker         glEnable(GL_BLEND);
439*35238bceSAndroid Build Coastguard Worker         glBlendFunc(GL_ONE, GL_ONE);
440*35238bceSAndroid Build Coastguard Worker         glBlendEquation(GL_FUNC_ADD);
441*35238bceSAndroid Build Coastguard Worker         glBindTexture(GL_TEXTURE_2D, tex);
442*35238bceSAndroid Build Coastguard Worker 
443*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(*getCurrentContext(), texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
444*35238bceSAndroid Build Coastguard Worker 
445*35238bceSAndroid Build Coastguard Worker         readPixels(dst, 0, 0, getWidth(), getHeight());
446*35238bceSAndroid Build Coastguard Worker     }
447*35238bceSAndroid Build Coastguard Worker 
448*35238bceSAndroid Build Coastguard Worker private:
449*35238bceSAndroid Build Coastguard Worker     uint32_t m_buffers;
450*35238bceSAndroid Build Coastguard Worker };
451*35238bceSAndroid Build Coastguard Worker 
452*35238bceSAndroid Build Coastguard Worker class InvalidateFboRenderCase : public FboTestCase
453*35238bceSAndroid Build Coastguard Worker {
454*35238bceSAndroid Build Coastguard Worker public:
InvalidateFboRenderCase(Context & context,const char * name,const char * description,uint32_t colorFmt,uint32_t depthStencilFmt,uint32_t invalidateBuffers)455*35238bceSAndroid Build Coastguard Worker     InvalidateFboRenderCase(Context &context, const char *name, const char *description, uint32_t colorFmt,
456*35238bceSAndroid Build Coastguard Worker                             uint32_t depthStencilFmt, uint32_t invalidateBuffers)
457*35238bceSAndroid Build Coastguard Worker         : FboTestCase(context, name, description)
458*35238bceSAndroid Build Coastguard Worker         , m_colorFmt(colorFmt)
459*35238bceSAndroid Build Coastguard Worker         , m_depthStencilFmt(depthStencilFmt)
460*35238bceSAndroid Build Coastguard Worker         , m_invalidateBuffers(invalidateBuffers)
461*35238bceSAndroid Build Coastguard Worker     {
462*35238bceSAndroid Build Coastguard Worker     }
463*35238bceSAndroid Build Coastguard Worker 
464*35238bceSAndroid Build Coastguard Worker protected:
preCheck(void)465*35238bceSAndroid Build Coastguard Worker     void preCheck(void)
466*35238bceSAndroid Build Coastguard Worker     {
467*35238bceSAndroid Build Coastguard Worker         if (m_colorFmt != GL_NONE)
468*35238bceSAndroid Build Coastguard Worker             checkFormatSupport(m_colorFmt);
469*35238bceSAndroid Build Coastguard Worker         if (m_depthStencilFmt != GL_NONE)
470*35238bceSAndroid Build Coastguard Worker             checkFormatSupport(m_depthStencilFmt);
471*35238bceSAndroid Build Coastguard Worker     }
472*35238bceSAndroid Build Coastguard Worker 
render(tcu::Surface & dst)473*35238bceSAndroid Build Coastguard Worker     void render(tcu::Surface &dst)
474*35238bceSAndroid Build Coastguard Worker     {
475*35238bceSAndroid Build Coastguard Worker         tcu::TextureFormat colorFmt = glu::mapGLInternalFormat(m_colorFmt);
476*35238bceSAndroid Build Coastguard Worker         tcu::TextureFormat depthStencilFmt =
477*35238bceSAndroid Build Coastguard Worker             m_depthStencilFmt != GL_NONE ? glu::mapGLInternalFormat(m_depthStencilFmt) : tcu::TextureFormat();
478*35238bceSAndroid Build Coastguard Worker         tcu::TextureFormatInfo colorFmtInfo = tcu::getTextureFormatInfo(colorFmt);
479*35238bceSAndroid Build Coastguard Worker         bool depth = depthStencilFmt.order == tcu::TextureFormat::D || depthStencilFmt.order == tcu::TextureFormat::DS;
480*35238bceSAndroid Build Coastguard Worker         bool stencil =
481*35238bceSAndroid Build Coastguard Worker             depthStencilFmt.order == tcu::TextureFormat::S || depthStencilFmt.order == tcu::TextureFormat::DS;
482*35238bceSAndroid Build Coastguard Worker         const tcu::Vec4 &cBias   = colorFmtInfo.valueMin;
483*35238bceSAndroid Build Coastguard Worker         tcu::Vec4 cScale         = colorFmtInfo.valueMax - colorFmtInfo.valueMin;
484*35238bceSAndroid Build Coastguard Worker         uint32_t fbo             = 0;
485*35238bceSAndroid Build Coastguard Worker         uint32_t colorRbo        = 0;
486*35238bceSAndroid Build Coastguard Worker         uint32_t depthStencilRbo = 0;
487*35238bceSAndroid Build Coastguard Worker         FlatColorShader flatShader(glu::TYPE_FLOAT_VEC4);
488*35238bceSAndroid Build Coastguard Worker         vector<uint32_t> attachments = getFBODiscardAttachments(m_invalidateBuffers);
489*35238bceSAndroid Build Coastguard Worker         uint32_t flatShaderID        = getCurrentContext()->createProgram(&flatShader);
490*35238bceSAndroid Build Coastguard Worker 
491*35238bceSAndroid Build Coastguard Worker         // Create fbo.
492*35238bceSAndroid Build Coastguard Worker         glGenRenderbuffers(1, &colorRbo);
493*35238bceSAndroid Build Coastguard Worker         glBindRenderbuffer(GL_RENDERBUFFER, colorRbo);
494*35238bceSAndroid Build Coastguard Worker         glRenderbufferStorage(GL_RENDERBUFFER, m_colorFmt, getWidth(), getHeight());
495*35238bceSAndroid Build Coastguard Worker 
496*35238bceSAndroid Build Coastguard Worker         if (m_depthStencilFmt != GL_NONE)
497*35238bceSAndroid Build Coastguard Worker         {
498*35238bceSAndroid Build Coastguard Worker             glGenRenderbuffers(1, &depthStencilRbo);
499*35238bceSAndroid Build Coastguard Worker             glBindRenderbuffer(GL_RENDERBUFFER, depthStencilRbo);
500*35238bceSAndroid Build Coastguard Worker             glRenderbufferStorage(GL_RENDERBUFFER, m_depthStencilFmt, getWidth(), getHeight());
501*35238bceSAndroid Build Coastguard Worker         }
502*35238bceSAndroid Build Coastguard Worker 
503*35238bceSAndroid Build Coastguard Worker         glGenFramebuffers(1, &fbo);
504*35238bceSAndroid Build Coastguard Worker         glBindFramebuffer(GL_FRAMEBUFFER, fbo);
505*35238bceSAndroid Build Coastguard Worker         glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRbo);
506*35238bceSAndroid Build Coastguard Worker 
507*35238bceSAndroid Build Coastguard Worker         if (depth)
508*35238bceSAndroid Build Coastguard Worker             glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthStencilRbo);
509*35238bceSAndroid Build Coastguard Worker 
510*35238bceSAndroid Build Coastguard Worker         if (stencil)
511*35238bceSAndroid Build Coastguard Worker             glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthStencilRbo);
512*35238bceSAndroid Build Coastguard Worker 
513*35238bceSAndroid Build Coastguard Worker         checkFramebufferStatus(GL_FRAMEBUFFER);
514*35238bceSAndroid Build Coastguard Worker 
515*35238bceSAndroid Build Coastguard Worker         glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
516*35238bceSAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
517*35238bceSAndroid Build Coastguard Worker 
518*35238bceSAndroid Build Coastguard Worker         glEnable(GL_DEPTH_TEST);
519*35238bceSAndroid Build Coastguard Worker         glEnable(GL_STENCIL_TEST);
520*35238bceSAndroid Build Coastguard Worker         glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
521*35238bceSAndroid Build Coastguard Worker         glStencilFunc(GL_ALWAYS, 1, 0xff);
522*35238bceSAndroid Build Coastguard Worker 
523*35238bceSAndroid Build Coastguard Worker         flatShader.setColor(*getCurrentContext(), flatShaderID, Vec4(1.0f, 0.0f, 0.0f, 1.0f) * cScale + cBias);
524*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(*getCurrentContext(), flatShaderID, Vec3(-1.0f, -1.0f, -1.0f), Vec3(1.0f, 1.0f, 1.0f));
525*35238bceSAndroid Build Coastguard Worker 
526*35238bceSAndroid Build Coastguard Worker         glInvalidateFramebuffer(GL_FRAMEBUFFER, (int)attachments.size(),
527*35238bceSAndroid Build Coastguard Worker                                 attachments.empty() ? DE_NULL : &attachments[0]);
528*35238bceSAndroid Build Coastguard Worker 
529*35238bceSAndroid Build Coastguard Worker         if ((m_invalidateBuffers & GL_COLOR_BUFFER_BIT) != 0)
530*35238bceSAndroid Build Coastguard Worker         {
531*35238bceSAndroid Build Coastguard Worker             // Color was not preserved - fill with green.
532*35238bceSAndroid Build Coastguard Worker             glDisable(GL_DEPTH_TEST);
533*35238bceSAndroid Build Coastguard Worker             glDisable(GL_STENCIL_TEST);
534*35238bceSAndroid Build Coastguard Worker 
535*35238bceSAndroid Build Coastguard Worker             flatShader.setColor(*getCurrentContext(), flatShaderID, Vec4(0.0f, 1.0f, 0.0f, 1.0f) * cScale + cBias);
536*35238bceSAndroid Build Coastguard Worker             sglr::drawQuad(*getCurrentContext(), flatShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
537*35238bceSAndroid Build Coastguard Worker 
538*35238bceSAndroid Build Coastguard Worker             glEnable(GL_DEPTH_TEST);
539*35238bceSAndroid Build Coastguard Worker             glEnable(GL_STENCIL_TEST);
540*35238bceSAndroid Build Coastguard Worker         }
541*35238bceSAndroid Build Coastguard Worker 
542*35238bceSAndroid Build Coastguard Worker         if ((m_invalidateBuffers & GL_DEPTH_BUFFER_BIT) != 0)
543*35238bceSAndroid Build Coastguard Worker         {
544*35238bceSAndroid Build Coastguard Worker             // Depth was not preserved.
545*35238bceSAndroid Build Coastguard Worker             glDepthFunc(GL_ALWAYS);
546*35238bceSAndroid Build Coastguard Worker         }
547*35238bceSAndroid Build Coastguard Worker 
548*35238bceSAndroid Build Coastguard Worker         if ((m_invalidateBuffers & GL_STENCIL_BUFFER_BIT) == 0)
549*35238bceSAndroid Build Coastguard Worker         {
550*35238bceSAndroid Build Coastguard Worker             // Stencil was preserved.
551*35238bceSAndroid Build Coastguard Worker             glStencilFunc(GL_EQUAL, 1, 0xff);
552*35238bceSAndroid Build Coastguard Worker         }
553*35238bceSAndroid Build Coastguard Worker 
554*35238bceSAndroid Build Coastguard Worker         glEnable(GL_BLEND);
555*35238bceSAndroid Build Coastguard Worker         glBlendFunc(GL_ONE, GL_ONE);
556*35238bceSAndroid Build Coastguard Worker         glBlendEquation(GL_FUNC_ADD);
557*35238bceSAndroid Build Coastguard Worker 
558*35238bceSAndroid Build Coastguard Worker         flatShader.setColor(*getCurrentContext(), flatShaderID, Vec4(0.0f, 0.0f, 1.0f, 1.0f) * cScale + cBias);
559*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(*getCurrentContext(), flatShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
560*35238bceSAndroid Build Coastguard Worker 
561*35238bceSAndroid Build Coastguard Worker         readPixels(dst, 0, 0, getWidth(), getHeight(), colorFmt, colorFmtInfo.lookupScale, colorFmtInfo.lookupBias);
562*35238bceSAndroid Build Coastguard Worker     }
563*35238bceSAndroid Build Coastguard Worker 
564*35238bceSAndroid Build Coastguard Worker private:
565*35238bceSAndroid Build Coastguard Worker     uint32_t m_colorFmt;
566*35238bceSAndroid Build Coastguard Worker     uint32_t m_depthStencilFmt;
567*35238bceSAndroid Build Coastguard Worker     uint32_t m_invalidateBuffers;
568*35238bceSAndroid Build Coastguard Worker };
569*35238bceSAndroid Build Coastguard Worker 
570*35238bceSAndroid Build Coastguard Worker class InvalidateFboUnbindReadCase : public FboTestCase
571*35238bceSAndroid Build Coastguard Worker {
572*35238bceSAndroid Build Coastguard Worker public:
InvalidateFboUnbindReadCase(Context & context,const char * name,const char * description,uint32_t colorFmt,uint32_t depthStencilFmt,uint32_t invalidateBuffers)573*35238bceSAndroid Build Coastguard Worker     InvalidateFboUnbindReadCase(Context &context, const char *name, const char *description, uint32_t colorFmt,
574*35238bceSAndroid Build Coastguard Worker                                 uint32_t depthStencilFmt, uint32_t invalidateBuffers)
575*35238bceSAndroid Build Coastguard Worker         : FboTestCase(context, name, description)
576*35238bceSAndroid Build Coastguard Worker         , m_colorFmt(colorFmt)
577*35238bceSAndroid Build Coastguard Worker         , m_depthStencilFmt(depthStencilFmt)
578*35238bceSAndroid Build Coastguard Worker         , m_invalidateBuffers(invalidateBuffers)
579*35238bceSAndroid Build Coastguard Worker     {
580*35238bceSAndroid Build Coastguard Worker         DE_ASSERT((m_invalidateBuffers & (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) !=
581*35238bceSAndroid Build Coastguard Worker                   (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
582*35238bceSAndroid Build Coastguard Worker     }
583*35238bceSAndroid Build Coastguard Worker 
584*35238bceSAndroid Build Coastguard Worker protected:
preCheck(void)585*35238bceSAndroid Build Coastguard Worker     void preCheck(void)
586*35238bceSAndroid Build Coastguard Worker     {
587*35238bceSAndroid Build Coastguard Worker         if (m_colorFmt != GL_NONE)
588*35238bceSAndroid Build Coastguard Worker             checkFormatSupport(m_colorFmt);
589*35238bceSAndroid Build Coastguard Worker         if (m_depthStencilFmt != GL_NONE)
590*35238bceSAndroid Build Coastguard Worker             checkFormatSupport(m_depthStencilFmt);
591*35238bceSAndroid Build Coastguard Worker     }
592*35238bceSAndroid Build Coastguard Worker 
render(tcu::Surface & dst)593*35238bceSAndroid Build Coastguard Worker     void render(tcu::Surface &dst)
594*35238bceSAndroid Build Coastguard Worker     {
595*35238bceSAndroid Build Coastguard Worker         tcu::TextureFormat colorFmt = glu::mapGLInternalFormat(m_colorFmt);
596*35238bceSAndroid Build Coastguard Worker         tcu::TextureFormat depthStencilFmt =
597*35238bceSAndroid Build Coastguard Worker             m_depthStencilFmt != GL_NONE ? glu::mapGLInternalFormat(m_depthStencilFmt) : tcu::TextureFormat();
598*35238bceSAndroid Build Coastguard Worker         tcu::TextureFormatInfo colorFmtInfo = tcu::getTextureFormatInfo(colorFmt);
599*35238bceSAndroid Build Coastguard Worker         bool depth = depthStencilFmt.order == tcu::TextureFormat::D || depthStencilFmt.order == tcu::TextureFormat::DS;
600*35238bceSAndroid Build Coastguard Worker         bool stencil =
601*35238bceSAndroid Build Coastguard Worker             depthStencilFmt.order == tcu::TextureFormat::S || depthStencilFmt.order == tcu::TextureFormat::DS;
602*35238bceSAndroid Build Coastguard Worker         uint32_t fbo             = 0;
603*35238bceSAndroid Build Coastguard Worker         uint32_t colorTex        = 0;
604*35238bceSAndroid Build Coastguard Worker         uint32_t depthStencilTex = 0;
605*35238bceSAndroid Build Coastguard Worker         GradientShader gradShader(getFragmentOutputType(colorFmt));
606*35238bceSAndroid Build Coastguard Worker         vector<uint32_t> attachments = getFBODiscardAttachments(m_invalidateBuffers);
607*35238bceSAndroid Build Coastguard Worker         uint32_t gradShaderID        = getCurrentContext()->createProgram(&gradShader);
608*35238bceSAndroid Build Coastguard Worker 
609*35238bceSAndroid Build Coastguard Worker         // Create fbo.
610*35238bceSAndroid Build Coastguard Worker         {
611*35238bceSAndroid Build Coastguard Worker             glu::TransferFormat transferFmt = glu::getTransferFormat(colorFmt);
612*35238bceSAndroid Build Coastguard Worker 
613*35238bceSAndroid Build Coastguard Worker             glGenTextures(1, &colorTex);
614*35238bceSAndroid Build Coastguard Worker             glBindTexture(GL_TEXTURE_2D, colorTex);
615*35238bceSAndroid Build Coastguard Worker             glTexImage2D(GL_TEXTURE_2D, 0, m_colorFmt, getWidth(), getHeight(), 0, transferFmt.format,
616*35238bceSAndroid Build Coastguard Worker                          transferFmt.dataType, DE_NULL);
617*35238bceSAndroid Build Coastguard Worker             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
618*35238bceSAndroid Build Coastguard Worker         }
619*35238bceSAndroid Build Coastguard Worker 
620*35238bceSAndroid Build Coastguard Worker         if (m_depthStencilFmt != GL_NONE)
621*35238bceSAndroid Build Coastguard Worker         {
622*35238bceSAndroid Build Coastguard Worker             glu::TransferFormat transferFmt = glu::getTransferFormat(depthStencilFmt);
623*35238bceSAndroid Build Coastguard Worker 
624*35238bceSAndroid Build Coastguard Worker             glGenTextures(1, &depthStencilTex);
625*35238bceSAndroid Build Coastguard Worker             glBindTexture(GL_TEXTURE_2D, depthStencilTex);
626*35238bceSAndroid Build Coastguard Worker             glTexImage2D(GL_TEXTURE_2D, 0, m_depthStencilFmt, getWidth(), getHeight(), 0, transferFmt.format,
627*35238bceSAndroid Build Coastguard Worker                          transferFmt.dataType, DE_NULL);
628*35238bceSAndroid Build Coastguard Worker             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
629*35238bceSAndroid Build Coastguard Worker             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
630*35238bceSAndroid Build Coastguard Worker         }
631*35238bceSAndroid Build Coastguard Worker 
632*35238bceSAndroid Build Coastguard Worker         glGenFramebuffers(1, &fbo);
633*35238bceSAndroid Build Coastguard Worker         glBindFramebuffer(GL_FRAMEBUFFER, fbo);
634*35238bceSAndroid Build Coastguard Worker         glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorTex, 0);
635*35238bceSAndroid Build Coastguard Worker 
636*35238bceSAndroid Build Coastguard Worker         if (depth)
637*35238bceSAndroid Build Coastguard Worker             glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthStencilTex, 0);
638*35238bceSAndroid Build Coastguard Worker 
639*35238bceSAndroid Build Coastguard Worker         if (stencil)
640*35238bceSAndroid Build Coastguard Worker             glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, depthStencilTex, 0);
641*35238bceSAndroid Build Coastguard Worker 
642*35238bceSAndroid Build Coastguard Worker         checkFramebufferStatus(GL_FRAMEBUFFER);
643*35238bceSAndroid Build Coastguard Worker 
644*35238bceSAndroid Build Coastguard Worker         glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
645*35238bceSAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
646*35238bceSAndroid Build Coastguard Worker 
647*35238bceSAndroid Build Coastguard Worker         glEnable(GL_DEPTH_TEST);
648*35238bceSAndroid Build Coastguard Worker         glEnable(GL_STENCIL_TEST);
649*35238bceSAndroid Build Coastguard Worker         glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
650*35238bceSAndroid Build Coastguard Worker         glStencilFunc(GL_ALWAYS, 1, 0xff);
651*35238bceSAndroid Build Coastguard Worker 
652*35238bceSAndroid Build Coastguard Worker         gradShader.setGradient(*getCurrentContext(), gradShaderID, colorFmtInfo.valueMin, colorFmtInfo.valueMax);
653*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(*getCurrentContext(), gradShaderID, Vec3(-1.0f, -1.0f, -1.0f), Vec3(1.0f, 1.0f, 1.0f));
654*35238bceSAndroid Build Coastguard Worker 
655*35238bceSAndroid Build Coastguard Worker         glInvalidateFramebuffer(GL_FRAMEBUFFER, (int)attachments.size(), &attachments[0]);
656*35238bceSAndroid Build Coastguard Worker 
657*35238bceSAndroid Build Coastguard Worker         glBindFramebuffer(GL_FRAMEBUFFER, 0);
658*35238bceSAndroid Build Coastguard Worker         glDisable(GL_DEPTH_TEST);
659*35238bceSAndroid Build Coastguard Worker         glDisable(GL_STENCIL_TEST);
660*35238bceSAndroid Build Coastguard Worker 
661*35238bceSAndroid Build Coastguard Worker         if ((m_invalidateBuffers & GL_DEPTH_BUFFER_BIT) != 0)
662*35238bceSAndroid Build Coastguard Worker         {
663*35238bceSAndroid Build Coastguard Worker             // Render color.
664*35238bceSAndroid Build Coastguard Worker             Texture2DShader texShader(DataTypes() << glu::getSampler2DType(colorFmt), glu::TYPE_FLOAT_VEC4);
665*35238bceSAndroid Build Coastguard Worker             uint32_t texShaderID = getCurrentContext()->createProgram(&texShader);
666*35238bceSAndroid Build Coastguard Worker 
667*35238bceSAndroid Build Coastguard Worker             texShader.setTexScaleBias(0, colorFmtInfo.lookupScale, colorFmtInfo.lookupBias);
668*35238bceSAndroid Build Coastguard Worker             texShader.setUniforms(*getCurrentContext(), texShaderID);
669*35238bceSAndroid Build Coastguard Worker 
670*35238bceSAndroid Build Coastguard Worker             glBindTexture(GL_TEXTURE_2D, colorTex);
671*35238bceSAndroid Build Coastguard Worker             sglr::drawQuad(*getCurrentContext(), texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
672*35238bceSAndroid Build Coastguard Worker         }
673*35238bceSAndroid Build Coastguard Worker         else
674*35238bceSAndroid Build Coastguard Worker         {
675*35238bceSAndroid Build Coastguard Worker             // Render depth.
676*35238bceSAndroid Build Coastguard Worker             Texture2DShader texShader(DataTypes() << glu::getSampler2DType(depthStencilFmt), glu::TYPE_FLOAT_VEC4);
677*35238bceSAndroid Build Coastguard Worker             uint32_t texShaderID = getCurrentContext()->createProgram(&texShader);
678*35238bceSAndroid Build Coastguard Worker 
679*35238bceSAndroid Build Coastguard Worker             texShader.setUniforms(*getCurrentContext(), texShaderID);
680*35238bceSAndroid Build Coastguard Worker 
681*35238bceSAndroid Build Coastguard Worker             glBindTexture(GL_TEXTURE_2D, depthStencilTex);
682*35238bceSAndroid Build Coastguard Worker             sglr::drawQuad(*getCurrentContext(), texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
683*35238bceSAndroid Build Coastguard Worker         }
684*35238bceSAndroid Build Coastguard Worker 
685*35238bceSAndroid Build Coastguard Worker         readPixels(dst, 0, 0, getWidth(), getHeight());
686*35238bceSAndroid Build Coastguard Worker     }
687*35238bceSAndroid Build Coastguard Worker 
688*35238bceSAndroid Build Coastguard Worker private:
689*35238bceSAndroid Build Coastguard Worker     uint32_t m_colorFmt;
690*35238bceSAndroid Build Coastguard Worker     uint32_t m_depthStencilFmt;
691*35238bceSAndroid Build Coastguard Worker     uint32_t m_invalidateBuffers;
692*35238bceSAndroid Build Coastguard Worker };
693*35238bceSAndroid Build Coastguard Worker 
694*35238bceSAndroid Build Coastguard Worker class InvalidateFboUnbindBlitCase : public FboTestCase
695*35238bceSAndroid Build Coastguard Worker {
696*35238bceSAndroid Build Coastguard Worker public:
InvalidateFboUnbindBlitCase(Context & context,const char * name,const char * description,int numSamples,uint32_t invalidateBuffers)697*35238bceSAndroid Build Coastguard Worker     InvalidateFboUnbindBlitCase(Context &context, const char *name, const char *description, int numSamples,
698*35238bceSAndroid Build Coastguard Worker                                 uint32_t invalidateBuffers)
699*35238bceSAndroid Build Coastguard Worker         : FboTestCase(context, name, description,
700*35238bceSAndroid Build Coastguard Worker                       numSamples >
701*35238bceSAndroid Build Coastguard Worker                           0) // \note Use fullscreen viewport when multisampling - we can't allow GLES3Context do its
702*35238bceSAndroid Build Coastguard Worker         //         behing-the-scenes viewport position randomization, because with glBlitFramebuffer,
703*35238bceSAndroid Build Coastguard Worker         //         source and destination rectangles must match when multisampling.
704*35238bceSAndroid Build Coastguard Worker         , m_colorFmt(0)
705*35238bceSAndroid Build Coastguard Worker         , m_depthStencilFmt(0)
706*35238bceSAndroid Build Coastguard Worker         , m_numSamples(numSamples)
707*35238bceSAndroid Build Coastguard Worker         , m_invalidateBuffers(invalidateBuffers)
708*35238bceSAndroid Build Coastguard Worker     {
709*35238bceSAndroid Build Coastguard Worker         // Figure out formats that are compatible with default framebuffer.
710*35238bceSAndroid Build Coastguard Worker         m_colorFmt        = getCompatibleColorFormat(m_context.getRenderTarget());
711*35238bceSAndroid Build Coastguard Worker         m_depthStencilFmt = getCompatibleDepthStencilFormat(m_context.getRenderTarget());
712*35238bceSAndroid Build Coastguard Worker     }
713*35238bceSAndroid Build Coastguard Worker 
714*35238bceSAndroid Build Coastguard Worker protected:
preCheck(void)715*35238bceSAndroid Build Coastguard Worker     void preCheck(void)
716*35238bceSAndroid Build Coastguard Worker     {
717*35238bceSAndroid Build Coastguard Worker         if (m_context.getRenderTarget().getNumSamples() > 0)
718*35238bceSAndroid Build Coastguard Worker             throw tcu::NotSupportedError("Not supported in MSAA config");
719*35238bceSAndroid Build Coastguard Worker 
720*35238bceSAndroid Build Coastguard Worker         if (m_colorFmt == GL_NONE)
721*35238bceSAndroid Build Coastguard Worker             throw tcu::NotSupportedError("Unsupported color format");
722*35238bceSAndroid Build Coastguard Worker 
723*35238bceSAndroid Build Coastguard Worker         if (m_depthStencilFmt == GL_NONE)
724*35238bceSAndroid Build Coastguard Worker             throw tcu::NotSupportedError("Unsupported depth/stencil format");
725*35238bceSAndroid Build Coastguard Worker 
726*35238bceSAndroid Build Coastguard Worker         checkFormatSupport(m_colorFmt);
727*35238bceSAndroid Build Coastguard Worker         checkFormatSupport(m_depthStencilFmt);
728*35238bceSAndroid Build Coastguard Worker     }
729*35238bceSAndroid Build Coastguard Worker 
render(tcu::Surface & dst)730*35238bceSAndroid Build Coastguard Worker     void render(tcu::Surface &dst)
731*35238bceSAndroid Build Coastguard Worker     {
732*35238bceSAndroid Build Coastguard Worker         // \note When using fullscreen viewport (when m_numSamples > 0), still only use a 128x128 pixel quad at most.
733*35238bceSAndroid Build Coastguard Worker         IVec2 quadSizePixels(m_numSamples == 0 ? getWidth() : de::min(128, getWidth()),
734*35238bceSAndroid Build Coastguard Worker                              m_numSamples == 0 ? getHeight() : de::min(128, getHeight()));
735*35238bceSAndroid Build Coastguard Worker         Vec2 quadNDCLeftBottomXY(-1.0f, -1.0f);
736*35238bceSAndroid Build Coastguard Worker         Vec2 quadNDCSize(2.0f * (float)quadSizePixels.x() / (float)getWidth(),
737*35238bceSAndroid Build Coastguard Worker                          2.0f * (float)quadSizePixels.y() / (float)getHeight());
738*35238bceSAndroid Build Coastguard Worker         Vec2 quadNDCRightTopXY = quadNDCLeftBottomXY + quadNDCSize;
739*35238bceSAndroid Build Coastguard Worker         tcu::TextureFormat depthStencilFmt =
740*35238bceSAndroid Build Coastguard Worker             m_depthStencilFmt != GL_NONE ? glu::mapGLInternalFormat(m_depthStencilFmt) : tcu::TextureFormat();
741*35238bceSAndroid Build Coastguard Worker         bool depth = depthStencilFmt.order == tcu::TextureFormat::D || depthStencilFmt.order == tcu::TextureFormat::DS;
742*35238bceSAndroid Build Coastguard Worker         bool stencil =
743*35238bceSAndroid Build Coastguard Worker             depthStencilFmt.order == tcu::TextureFormat::S || depthStencilFmt.order == tcu::TextureFormat::DS;
744*35238bceSAndroid Build Coastguard Worker         uint32_t fbo             = 0;
745*35238bceSAndroid Build Coastguard Worker         uint32_t colorRbo        = 0;
746*35238bceSAndroid Build Coastguard Worker         uint32_t depthStencilRbo = 0;
747*35238bceSAndroid Build Coastguard Worker         FlatColorShader flatShader(glu::TYPE_FLOAT_VEC4);
748*35238bceSAndroid Build Coastguard Worker         vector<uint32_t> attachments = getFBODiscardAttachments(m_invalidateBuffers);
749*35238bceSAndroid Build Coastguard Worker         uint32_t flatShaderID        = getCurrentContext()->createProgram(&flatShader);
750*35238bceSAndroid Build Coastguard Worker 
751*35238bceSAndroid Build Coastguard Worker         glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
752*35238bceSAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
753*35238bceSAndroid Build Coastguard Worker 
754*35238bceSAndroid Build Coastguard Worker         // Create fbo.
755*35238bceSAndroid Build Coastguard Worker         glGenRenderbuffers(1, &colorRbo);
756*35238bceSAndroid Build Coastguard Worker         glBindRenderbuffer(GL_RENDERBUFFER, colorRbo);
757*35238bceSAndroid Build Coastguard Worker         glRenderbufferStorageMultisample(GL_RENDERBUFFER, m_numSamples, m_colorFmt, quadSizePixels.x(),
758*35238bceSAndroid Build Coastguard Worker                                          quadSizePixels.y());
759*35238bceSAndroid Build Coastguard Worker 
760*35238bceSAndroid Build Coastguard Worker         if (m_depthStencilFmt != GL_NONE)
761*35238bceSAndroid Build Coastguard Worker         {
762*35238bceSAndroid Build Coastguard Worker             glGenRenderbuffers(1, &depthStencilRbo);
763*35238bceSAndroid Build Coastguard Worker             glBindRenderbuffer(GL_RENDERBUFFER, depthStencilRbo);
764*35238bceSAndroid Build Coastguard Worker             glRenderbufferStorageMultisample(GL_RENDERBUFFER, m_numSamples, m_depthStencilFmt, quadSizePixels.x(),
765*35238bceSAndroid Build Coastguard Worker                                              quadSizePixels.y());
766*35238bceSAndroid Build Coastguard Worker         }
767*35238bceSAndroid Build Coastguard Worker 
768*35238bceSAndroid Build Coastguard Worker         glGenFramebuffers(1, &fbo);
769*35238bceSAndroid Build Coastguard Worker         glBindFramebuffer(GL_FRAMEBUFFER, fbo);
770*35238bceSAndroid Build Coastguard Worker         glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRbo);
771*35238bceSAndroid Build Coastguard Worker 
772*35238bceSAndroid Build Coastguard Worker         if (depth)
773*35238bceSAndroid Build Coastguard Worker             glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthStencilRbo);
774*35238bceSAndroid Build Coastguard Worker 
775*35238bceSAndroid Build Coastguard Worker         if (stencil)
776*35238bceSAndroid Build Coastguard Worker             glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthStencilRbo);
777*35238bceSAndroid Build Coastguard Worker 
778*35238bceSAndroid Build Coastguard Worker         checkFramebufferStatus(GL_FRAMEBUFFER);
779*35238bceSAndroid Build Coastguard Worker 
780*35238bceSAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
781*35238bceSAndroid Build Coastguard Worker 
782*35238bceSAndroid Build Coastguard Worker         glEnable(GL_DEPTH_TEST);
783*35238bceSAndroid Build Coastguard Worker         glEnable(GL_STENCIL_TEST);
784*35238bceSAndroid Build Coastguard Worker         glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
785*35238bceSAndroid Build Coastguard Worker         glStencilFunc(GL_ALWAYS, 1, 0xff);
786*35238bceSAndroid Build Coastguard Worker 
787*35238bceSAndroid Build Coastguard Worker         flatShader.setColor(*getCurrentContext(), flatShaderID, Vec4(1.0f, 0.0f, 0.0f, 1.0f));
788*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(*getCurrentContext(), flatShaderID,
789*35238bceSAndroid Build Coastguard Worker                        Vec3(quadNDCLeftBottomXY.x(), quadNDCLeftBottomXY.y(), -1.0f),
790*35238bceSAndroid Build Coastguard Worker                        Vec3(quadNDCRightTopXY.x(), quadNDCRightTopXY.y(), 1.0f));
791*35238bceSAndroid Build Coastguard Worker 
792*35238bceSAndroid Build Coastguard Worker         glInvalidateFramebuffer(GL_FRAMEBUFFER, (int)attachments.size(), &attachments[0]);
793*35238bceSAndroid Build Coastguard Worker 
794*35238bceSAndroid Build Coastguard Worker         // Set default framebuffer as draw framebuffer and blit preserved buffers.
795*35238bceSAndroid Build Coastguard Worker         glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
796*35238bceSAndroid Build Coastguard Worker         glBlitFramebuffer(0, 0, quadSizePixels.x(), quadSizePixels.y(), 0, 0, quadSizePixels.x(), quadSizePixels.y(),
797*35238bceSAndroid Build Coastguard Worker                           (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT) & ~m_invalidateBuffers,
798*35238bceSAndroid Build Coastguard Worker                           GL_NEAREST);
799*35238bceSAndroid Build Coastguard Worker         glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
800*35238bceSAndroid Build Coastguard Worker 
801*35238bceSAndroid Build Coastguard Worker         if ((m_invalidateBuffers & GL_COLOR_BUFFER_BIT) != 0)
802*35238bceSAndroid Build Coastguard Worker         {
803*35238bceSAndroid Build Coastguard Worker             // Color was not preserved - fill with green.
804*35238bceSAndroid Build Coastguard Worker             glDisable(GL_DEPTH_TEST);
805*35238bceSAndroid Build Coastguard Worker             glDisable(GL_STENCIL_TEST);
806*35238bceSAndroid Build Coastguard Worker 
807*35238bceSAndroid Build Coastguard Worker             flatShader.setColor(*getCurrentContext(), flatShaderID, Vec4(0.0f, 1.0f, 0.0f, 1.0f));
808*35238bceSAndroid Build Coastguard Worker             sglr::drawQuad(*getCurrentContext(), flatShaderID,
809*35238bceSAndroid Build Coastguard Worker                            Vec3(quadNDCLeftBottomXY.x(), quadNDCLeftBottomXY.y(), 0.0f),
810*35238bceSAndroid Build Coastguard Worker                            Vec3(quadNDCRightTopXY.x(), quadNDCRightTopXY.y(), 0.0f));
811*35238bceSAndroid Build Coastguard Worker 
812*35238bceSAndroid Build Coastguard Worker             glEnable(GL_DEPTH_TEST);
813*35238bceSAndroid Build Coastguard Worker             glEnable(GL_STENCIL_TEST);
814*35238bceSAndroid Build Coastguard Worker         }
815*35238bceSAndroid Build Coastguard Worker 
816*35238bceSAndroid Build Coastguard Worker         if ((m_invalidateBuffers & GL_DEPTH_BUFFER_BIT) != 0)
817*35238bceSAndroid Build Coastguard Worker         {
818*35238bceSAndroid Build Coastguard Worker             // Depth was not preserved.
819*35238bceSAndroid Build Coastguard Worker             glDepthFunc(GL_ALWAYS);
820*35238bceSAndroid Build Coastguard Worker         }
821*35238bceSAndroid Build Coastguard Worker 
822*35238bceSAndroid Build Coastguard Worker         if ((m_invalidateBuffers & GL_STENCIL_BUFFER_BIT) == 0)
823*35238bceSAndroid Build Coastguard Worker         {
824*35238bceSAndroid Build Coastguard Worker             // Stencil was preserved.
825*35238bceSAndroid Build Coastguard Worker             glStencilFunc(GL_EQUAL, 1, 0xff);
826*35238bceSAndroid Build Coastguard Worker         }
827*35238bceSAndroid Build Coastguard Worker 
828*35238bceSAndroid Build Coastguard Worker         glEnable(GL_BLEND);
829*35238bceSAndroid Build Coastguard Worker         glBlendFunc(GL_ONE, GL_ONE);
830*35238bceSAndroid Build Coastguard Worker         glBlendEquation(GL_FUNC_ADD);
831*35238bceSAndroid Build Coastguard Worker 
832*35238bceSAndroid Build Coastguard Worker         flatShader.setColor(*getCurrentContext(), flatShaderID, Vec4(0.0f, 0.0f, 1.0f, 1.0f));
833*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(*getCurrentContext(), flatShaderID, Vec3(quadNDCLeftBottomXY.x(), quadNDCLeftBottomXY.y(), 0.0f),
834*35238bceSAndroid Build Coastguard Worker                        Vec3(quadNDCRightTopXY.x(), quadNDCRightTopXY.y(), 0.0f));
835*35238bceSAndroid Build Coastguard Worker 
836*35238bceSAndroid Build Coastguard Worker         readPixels(dst, 0, 0, quadSizePixels.x(), quadSizePixels.y());
837*35238bceSAndroid Build Coastguard Worker     }
838*35238bceSAndroid Build Coastguard Worker 
839*35238bceSAndroid Build Coastguard Worker private:
840*35238bceSAndroid Build Coastguard Worker     uint32_t m_colorFmt;
841*35238bceSAndroid Build Coastguard Worker     uint32_t m_depthStencilFmt;
842*35238bceSAndroid Build Coastguard Worker     int m_numSamples;
843*35238bceSAndroid Build Coastguard Worker     uint32_t m_invalidateBuffers;
844*35238bceSAndroid Build Coastguard Worker };
845*35238bceSAndroid Build Coastguard Worker 
846*35238bceSAndroid Build Coastguard Worker class InvalidateSubFboRenderCase : public FboTestCase
847*35238bceSAndroid Build Coastguard Worker {
848*35238bceSAndroid Build Coastguard Worker public:
InvalidateSubFboRenderCase(Context & context,const char * name,const char * description,uint32_t colorFmt,uint32_t depthStencilFmt,uint32_t invalidateBuffers)849*35238bceSAndroid Build Coastguard Worker     InvalidateSubFboRenderCase(Context &context, const char *name, const char *description, uint32_t colorFmt,
850*35238bceSAndroid Build Coastguard Worker                                uint32_t depthStencilFmt, uint32_t invalidateBuffers)
851*35238bceSAndroid Build Coastguard Worker         : FboTestCase(context, name, description)
852*35238bceSAndroid Build Coastguard Worker         , m_colorFmt(colorFmt)
853*35238bceSAndroid Build Coastguard Worker         , m_depthStencilFmt(depthStencilFmt)
854*35238bceSAndroid Build Coastguard Worker         , m_invalidateBuffers(invalidateBuffers)
855*35238bceSAndroid Build Coastguard Worker     {
856*35238bceSAndroid Build Coastguard Worker     }
857*35238bceSAndroid Build Coastguard Worker 
858*35238bceSAndroid Build Coastguard Worker protected:
preCheck(void)859*35238bceSAndroid Build Coastguard Worker     void preCheck(void)
860*35238bceSAndroid Build Coastguard Worker     {
861*35238bceSAndroid Build Coastguard Worker         if (m_colorFmt != GL_NONE)
862*35238bceSAndroid Build Coastguard Worker             checkFormatSupport(m_colorFmt);
863*35238bceSAndroid Build Coastguard Worker         if (m_depthStencilFmt != GL_NONE)
864*35238bceSAndroid Build Coastguard Worker             checkFormatSupport(m_depthStencilFmt);
865*35238bceSAndroid Build Coastguard Worker     }
866*35238bceSAndroid Build Coastguard Worker 
render(tcu::Surface & dst)867*35238bceSAndroid Build Coastguard Worker     void render(tcu::Surface &dst)
868*35238bceSAndroid Build Coastguard Worker     {
869*35238bceSAndroid Build Coastguard Worker         tcu::TextureFormat colorFmt = glu::mapGLInternalFormat(m_colorFmt);
870*35238bceSAndroid Build Coastguard Worker         tcu::TextureFormat depthStencilFmt =
871*35238bceSAndroid Build Coastguard Worker             m_depthStencilFmt != GL_NONE ? glu::mapGLInternalFormat(m_depthStencilFmt) : tcu::TextureFormat();
872*35238bceSAndroid Build Coastguard Worker         tcu::TextureFormatInfo colorFmtInfo = tcu::getTextureFormatInfo(colorFmt);
873*35238bceSAndroid Build Coastguard Worker         bool depth = depthStencilFmt.order == tcu::TextureFormat::D || depthStencilFmt.order == tcu::TextureFormat::DS;
874*35238bceSAndroid Build Coastguard Worker         bool stencil =
875*35238bceSAndroid Build Coastguard Worker             depthStencilFmt.order == tcu::TextureFormat::S || depthStencilFmt.order == tcu::TextureFormat::DS;
876*35238bceSAndroid Build Coastguard Worker         const tcu::Vec4 &cBias   = colorFmtInfo.valueMin;
877*35238bceSAndroid Build Coastguard Worker         tcu::Vec4 cScale         = colorFmtInfo.valueMax - colorFmtInfo.valueMin;
878*35238bceSAndroid Build Coastguard Worker         uint32_t fbo             = 0;
879*35238bceSAndroid Build Coastguard Worker         uint32_t colorRbo        = 0;
880*35238bceSAndroid Build Coastguard Worker         uint32_t depthStencilRbo = 0;
881*35238bceSAndroid Build Coastguard Worker         int invalidateX          = getWidth() / 4;
882*35238bceSAndroid Build Coastguard Worker         int invalidateY          = getHeight() / 4;
883*35238bceSAndroid Build Coastguard Worker         int invalidateW          = getWidth() / 2;
884*35238bceSAndroid Build Coastguard Worker         int invalidateH          = getHeight() / 2;
885*35238bceSAndroid Build Coastguard Worker         FlatColorShader flatShader(glu::TYPE_FLOAT_VEC4);
886*35238bceSAndroid Build Coastguard Worker         vector<uint32_t> attachments = getFBODiscardAttachments(m_invalidateBuffers);
887*35238bceSAndroid Build Coastguard Worker         uint32_t flatShaderID        = getCurrentContext()->createProgram(&flatShader);
888*35238bceSAndroid Build Coastguard Worker 
889*35238bceSAndroid Build Coastguard Worker         // Create fbo.
890*35238bceSAndroid Build Coastguard Worker         glGenRenderbuffers(1, &colorRbo);
891*35238bceSAndroid Build Coastguard Worker         glBindRenderbuffer(GL_RENDERBUFFER, colorRbo);
892*35238bceSAndroid Build Coastguard Worker         glRenderbufferStorage(GL_RENDERBUFFER, m_colorFmt, getWidth(), getHeight());
893*35238bceSAndroid Build Coastguard Worker 
894*35238bceSAndroid Build Coastguard Worker         if (m_depthStencilFmt != GL_NONE)
895*35238bceSAndroid Build Coastguard Worker         {
896*35238bceSAndroid Build Coastguard Worker             glGenRenderbuffers(1, &depthStencilRbo);
897*35238bceSAndroid Build Coastguard Worker             glBindRenderbuffer(GL_RENDERBUFFER, depthStencilRbo);
898*35238bceSAndroid Build Coastguard Worker             glRenderbufferStorage(GL_RENDERBUFFER, m_depthStencilFmt, getWidth(), getHeight());
899*35238bceSAndroid Build Coastguard Worker         }
900*35238bceSAndroid Build Coastguard Worker 
901*35238bceSAndroid Build Coastguard Worker         glGenFramebuffers(1, &fbo);
902*35238bceSAndroid Build Coastguard Worker         glBindFramebuffer(GL_FRAMEBUFFER, fbo);
903*35238bceSAndroid Build Coastguard Worker         glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRbo);
904*35238bceSAndroid Build Coastguard Worker 
905*35238bceSAndroid Build Coastguard Worker         if (depth)
906*35238bceSAndroid Build Coastguard Worker             glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthStencilRbo);
907*35238bceSAndroid Build Coastguard Worker 
908*35238bceSAndroid Build Coastguard Worker         if (stencil)
909*35238bceSAndroid Build Coastguard Worker             glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthStencilRbo);
910*35238bceSAndroid Build Coastguard Worker 
911*35238bceSAndroid Build Coastguard Worker         checkFramebufferStatus(GL_FRAMEBUFFER);
912*35238bceSAndroid Build Coastguard Worker 
913*35238bceSAndroid Build Coastguard Worker         glClearBufferfv(GL_COLOR, 0, (Vec4(0.0f, 0.0f, 0.0f, 1.0f) * cScale + cBias).getPtr());
914*35238bceSAndroid Build Coastguard Worker         glClearBufferfi(GL_DEPTH_STENCIL, 0, 1.0f, 0);
915*35238bceSAndroid Build Coastguard Worker 
916*35238bceSAndroid Build Coastguard Worker         glEnable(GL_DEPTH_TEST);
917*35238bceSAndroid Build Coastguard Worker         glEnable(GL_STENCIL_TEST);
918*35238bceSAndroid Build Coastguard Worker         glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
919*35238bceSAndroid Build Coastguard Worker         glStencilFunc(GL_ALWAYS, 1, 0xff);
920*35238bceSAndroid Build Coastguard Worker 
921*35238bceSAndroid Build Coastguard Worker         flatShader.setColor(*getCurrentContext(), flatShaderID, Vec4(1.0f, 0.0f, 0.0f, 1.0f) * cScale + cBias);
922*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(*getCurrentContext(), flatShaderID, Vec3(-1.0f, -1.0f, -1.0f), Vec3(1.0f, 1.0f, 1.0f));
923*35238bceSAndroid Build Coastguard Worker 
924*35238bceSAndroid Build Coastguard Worker         glInvalidateSubFramebuffer(GL_FRAMEBUFFER, (int)attachments.size(),
925*35238bceSAndroid Build Coastguard Worker                                    attachments.empty() ? DE_NULL : &attachments[0], invalidateX, invalidateY,
926*35238bceSAndroid Build Coastguard Worker                                    invalidateW, invalidateH);
927*35238bceSAndroid Build Coastguard Worker 
928*35238bceSAndroid Build Coastguard Worker         // Clear invalidated buffers.
929*35238bceSAndroid Build Coastguard Worker         glScissor(invalidateX, invalidateY, invalidateW, invalidateH);
930*35238bceSAndroid Build Coastguard Worker         glEnable(GL_SCISSOR_TEST);
931*35238bceSAndroid Build Coastguard Worker 
932*35238bceSAndroid Build Coastguard Worker         if (m_invalidateBuffers & GL_COLOR_BUFFER_BIT)
933*35238bceSAndroid Build Coastguard Worker             glClearBufferfv(GL_COLOR, 0, (Vec4(0.0f, 1.0f, 0.0f, 1.0f) * cScale + cBias).getPtr());
934*35238bceSAndroid Build Coastguard Worker 
935*35238bceSAndroid Build Coastguard Worker         glClear(m_invalidateBuffers & ~GL_COLOR_BUFFER_BIT);
936*35238bceSAndroid Build Coastguard Worker         glDisable(GL_SCISSOR_TEST);
937*35238bceSAndroid Build Coastguard Worker 
938*35238bceSAndroid Build Coastguard Worker         glEnable(GL_BLEND);
939*35238bceSAndroid Build Coastguard Worker         glBlendFunc(GL_ONE, GL_ONE);
940*35238bceSAndroid Build Coastguard Worker         glBlendEquation(GL_FUNC_ADD);
941*35238bceSAndroid Build Coastguard Worker 
942*35238bceSAndroid Build Coastguard Worker         flatShader.setColor(*getCurrentContext(), flatShaderID, Vec4(0.0f, 0.0f, 1.0f, 1.0f) * cScale + cBias);
943*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(*getCurrentContext(), flatShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
944*35238bceSAndroid Build Coastguard Worker 
945*35238bceSAndroid Build Coastguard Worker         readPixels(dst, 0, 0, getWidth(), getHeight(), colorFmt, colorFmtInfo.lookupScale, colorFmtInfo.lookupBias);
946*35238bceSAndroid Build Coastguard Worker     }
947*35238bceSAndroid Build Coastguard Worker 
948*35238bceSAndroid Build Coastguard Worker private:
949*35238bceSAndroid Build Coastguard Worker     uint32_t m_colorFmt;
950*35238bceSAndroid Build Coastguard Worker     uint32_t m_depthStencilFmt;
951*35238bceSAndroid Build Coastguard Worker     uint32_t m_invalidateBuffers;
952*35238bceSAndroid Build Coastguard Worker };
953*35238bceSAndroid Build Coastguard Worker 
954*35238bceSAndroid Build Coastguard Worker class InvalidateSubFboUnbindReadCase : public FboTestCase
955*35238bceSAndroid Build Coastguard Worker {
956*35238bceSAndroid Build Coastguard Worker public:
InvalidateSubFboUnbindReadCase(Context & context,const char * name,const char * description,uint32_t colorFmt,uint32_t depthStencilFmt,uint32_t invalidateBuffers)957*35238bceSAndroid Build Coastguard Worker     InvalidateSubFboUnbindReadCase(Context &context, const char *name, const char *description, uint32_t colorFmt,
958*35238bceSAndroid Build Coastguard Worker                                    uint32_t depthStencilFmt, uint32_t invalidateBuffers)
959*35238bceSAndroid Build Coastguard Worker         : FboTestCase(context, name, description)
960*35238bceSAndroid Build Coastguard Worker         , m_colorFmt(colorFmt)
961*35238bceSAndroid Build Coastguard Worker         , m_depthStencilFmt(depthStencilFmt)
962*35238bceSAndroid Build Coastguard Worker         , m_invalidateBuffers(invalidateBuffers)
963*35238bceSAndroid Build Coastguard Worker     {
964*35238bceSAndroid Build Coastguard Worker         DE_ASSERT((m_invalidateBuffers & (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) !=
965*35238bceSAndroid Build Coastguard Worker                   (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
966*35238bceSAndroid Build Coastguard Worker     }
967*35238bceSAndroid Build Coastguard Worker 
968*35238bceSAndroid Build Coastguard Worker protected:
preCheck(void)969*35238bceSAndroid Build Coastguard Worker     void preCheck(void)
970*35238bceSAndroid Build Coastguard Worker     {
971*35238bceSAndroid Build Coastguard Worker         if (m_colorFmt != GL_NONE)
972*35238bceSAndroid Build Coastguard Worker             checkFormatSupport(m_colorFmt);
973*35238bceSAndroid Build Coastguard Worker         if (m_depthStencilFmt != GL_NONE)
974*35238bceSAndroid Build Coastguard Worker             checkFormatSupport(m_depthStencilFmt);
975*35238bceSAndroid Build Coastguard Worker     }
976*35238bceSAndroid Build Coastguard Worker 
render(tcu::Surface & dst)977*35238bceSAndroid Build Coastguard Worker     void render(tcu::Surface &dst)
978*35238bceSAndroid Build Coastguard Worker     {
979*35238bceSAndroid Build Coastguard Worker         tcu::TextureFormat colorFmt = glu::mapGLInternalFormat(m_colorFmt);
980*35238bceSAndroid Build Coastguard Worker         tcu::TextureFormat depthStencilFmt =
981*35238bceSAndroid Build Coastguard Worker             m_depthStencilFmt != GL_NONE ? glu::mapGLInternalFormat(m_depthStencilFmt) : tcu::TextureFormat();
982*35238bceSAndroid Build Coastguard Worker         tcu::TextureFormatInfo colorFmtInfo = tcu::getTextureFormatInfo(colorFmt);
983*35238bceSAndroid Build Coastguard Worker         bool depth = depthStencilFmt.order == tcu::TextureFormat::D || depthStencilFmt.order == tcu::TextureFormat::DS;
984*35238bceSAndroid Build Coastguard Worker         bool stencil =
985*35238bceSAndroid Build Coastguard Worker             depthStencilFmt.order == tcu::TextureFormat::S || depthStencilFmt.order == tcu::TextureFormat::DS;
986*35238bceSAndroid Build Coastguard Worker         uint32_t fbo             = 0;
987*35238bceSAndroid Build Coastguard Worker         uint32_t colorTex        = 0;
988*35238bceSAndroid Build Coastguard Worker         uint32_t depthStencilTex = 0;
989*35238bceSAndroid Build Coastguard Worker         int invalidateX          = 0;
990*35238bceSAndroid Build Coastguard Worker         int invalidateY          = 0;
991*35238bceSAndroid Build Coastguard Worker         int invalidateW          = getWidth() / 2;
992*35238bceSAndroid Build Coastguard Worker         int invalidateH          = getHeight();
993*35238bceSAndroid Build Coastguard Worker         int readX                = invalidateW;
994*35238bceSAndroid Build Coastguard Worker         int readY                = 0;
995*35238bceSAndroid Build Coastguard Worker         int readW                = getWidth() / 2;
996*35238bceSAndroid Build Coastguard Worker         int readH                = getHeight();
997*35238bceSAndroid Build Coastguard Worker         GradientShader gradShader(getFragmentOutputType(colorFmt));
998*35238bceSAndroid Build Coastguard Worker         vector<uint32_t> attachments = getFBODiscardAttachments(m_invalidateBuffers);
999*35238bceSAndroid Build Coastguard Worker         uint32_t gradShaderID        = getCurrentContext()->createProgram(&gradShader);
1000*35238bceSAndroid Build Coastguard Worker 
1001*35238bceSAndroid Build Coastguard Worker         // Create fbo.
1002*35238bceSAndroid Build Coastguard Worker         {
1003*35238bceSAndroid Build Coastguard Worker             glu::TransferFormat transferFmt = glu::getTransferFormat(colorFmt);
1004*35238bceSAndroid Build Coastguard Worker 
1005*35238bceSAndroid Build Coastguard Worker             glGenTextures(1, &colorTex);
1006*35238bceSAndroid Build Coastguard Worker             glBindTexture(GL_TEXTURE_2D, colorTex);
1007*35238bceSAndroid Build Coastguard Worker             glTexImage2D(GL_TEXTURE_2D, 0, m_colorFmt, getWidth(), getHeight(), 0, transferFmt.format,
1008*35238bceSAndroid Build Coastguard Worker                          transferFmt.dataType, DE_NULL);
1009*35238bceSAndroid Build Coastguard Worker             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1010*35238bceSAndroid Build Coastguard Worker             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1011*35238bceSAndroid Build Coastguard Worker         }
1012*35238bceSAndroid Build Coastguard Worker 
1013*35238bceSAndroid Build Coastguard Worker         if (m_depthStencilFmt != GL_NONE)
1014*35238bceSAndroid Build Coastguard Worker         {
1015*35238bceSAndroid Build Coastguard Worker             glu::TransferFormat transferFmt = glu::getTransferFormat(depthStencilFmt);
1016*35238bceSAndroid Build Coastguard Worker 
1017*35238bceSAndroid Build Coastguard Worker             glGenTextures(1, &depthStencilTex);
1018*35238bceSAndroid Build Coastguard Worker             glBindTexture(GL_TEXTURE_2D, depthStencilTex);
1019*35238bceSAndroid Build Coastguard Worker             glTexImage2D(GL_TEXTURE_2D, 0, m_depthStencilFmt, getWidth(), getHeight(), 0, transferFmt.format,
1020*35238bceSAndroid Build Coastguard Worker                          transferFmt.dataType, DE_NULL);
1021*35238bceSAndroid Build Coastguard Worker             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1022*35238bceSAndroid Build Coastguard Worker             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1023*35238bceSAndroid Build Coastguard Worker         }
1024*35238bceSAndroid Build Coastguard Worker 
1025*35238bceSAndroid Build Coastguard Worker         glGenFramebuffers(1, &fbo);
1026*35238bceSAndroid Build Coastguard Worker         glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1027*35238bceSAndroid Build Coastguard Worker         glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorTex, 0);
1028*35238bceSAndroid Build Coastguard Worker 
1029*35238bceSAndroid Build Coastguard Worker         if (depth)
1030*35238bceSAndroid Build Coastguard Worker             glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthStencilTex, 0);
1031*35238bceSAndroid Build Coastguard Worker 
1032*35238bceSAndroid Build Coastguard Worker         if (stencil)
1033*35238bceSAndroid Build Coastguard Worker             glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, depthStencilTex, 0);
1034*35238bceSAndroid Build Coastguard Worker 
1035*35238bceSAndroid Build Coastguard Worker         checkFramebufferStatus(GL_FRAMEBUFFER);
1036*35238bceSAndroid Build Coastguard Worker 
1037*35238bceSAndroid Build Coastguard Worker         clearColorBuffer(colorFmt, tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
1038*35238bceSAndroid Build Coastguard Worker         glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1039*35238bceSAndroid Build Coastguard Worker 
1040*35238bceSAndroid Build Coastguard Worker         glEnable(GL_DEPTH_TEST);
1041*35238bceSAndroid Build Coastguard Worker         glEnable(GL_STENCIL_TEST);
1042*35238bceSAndroid Build Coastguard Worker         glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
1043*35238bceSAndroid Build Coastguard Worker         glStencilFunc(GL_ALWAYS, 1, 0xff);
1044*35238bceSAndroid Build Coastguard Worker 
1045*35238bceSAndroid Build Coastguard Worker         gradShader.setGradient(*getCurrentContext(), gradShaderID, colorFmtInfo.valueMin, colorFmtInfo.valueMax);
1046*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(*getCurrentContext(), gradShaderID, Vec3(-1.0f, -1.0f, -1.0f), Vec3(1.0f, 1.0f, 1.0f));
1047*35238bceSAndroid Build Coastguard Worker 
1048*35238bceSAndroid Build Coastguard Worker         glInvalidateSubFramebuffer(GL_FRAMEBUFFER, (int)attachments.size(), &attachments[0], invalidateX, invalidateY,
1049*35238bceSAndroid Build Coastguard Worker                                    invalidateW, invalidateH);
1050*35238bceSAndroid Build Coastguard Worker 
1051*35238bceSAndroid Build Coastguard Worker         glBindFramebuffer(GL_FRAMEBUFFER, 0);
1052*35238bceSAndroid Build Coastguard Worker         glDisable(GL_DEPTH_TEST);
1053*35238bceSAndroid Build Coastguard Worker         glDisable(GL_STENCIL_TEST);
1054*35238bceSAndroid Build Coastguard Worker 
1055*35238bceSAndroid Build Coastguard Worker         glClearColor(0.25f, 0.5f, 0.75f, 1.0f);
1056*35238bceSAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1057*35238bceSAndroid Build Coastguard Worker 
1058*35238bceSAndroid Build Coastguard Worker         // Limit read area using scissor.
1059*35238bceSAndroid Build Coastguard Worker         glScissor(readX, readY, readW, readH);
1060*35238bceSAndroid Build Coastguard Worker         glEnable(GL_SCISSOR_TEST);
1061*35238bceSAndroid Build Coastguard Worker 
1062*35238bceSAndroid Build Coastguard Worker         if ((m_invalidateBuffers & GL_COLOR_BUFFER_BIT) != 0)
1063*35238bceSAndroid Build Coastguard Worker         {
1064*35238bceSAndroid Build Coastguard Worker             // Render color.
1065*35238bceSAndroid Build Coastguard Worker             Texture2DShader texShader(DataTypes() << glu::getSampler2DType(colorFmt), glu::TYPE_FLOAT_VEC4);
1066*35238bceSAndroid Build Coastguard Worker             uint32_t texShaderID = getCurrentContext()->createProgram(&texShader);
1067*35238bceSAndroid Build Coastguard Worker 
1068*35238bceSAndroid Build Coastguard Worker             texShader.setTexScaleBias(0, colorFmtInfo.lookupScale, colorFmtInfo.lookupBias);
1069*35238bceSAndroid Build Coastguard Worker             texShader.setUniforms(*getCurrentContext(), texShaderID);
1070*35238bceSAndroid Build Coastguard Worker 
1071*35238bceSAndroid Build Coastguard Worker             glBindTexture(GL_TEXTURE_2D, colorTex);
1072*35238bceSAndroid Build Coastguard Worker             sglr::drawQuad(*getCurrentContext(), texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
1073*35238bceSAndroid Build Coastguard Worker         }
1074*35238bceSAndroid Build Coastguard Worker         else
1075*35238bceSAndroid Build Coastguard Worker         {
1076*35238bceSAndroid Build Coastguard Worker             // Render depth.
1077*35238bceSAndroid Build Coastguard Worker             Texture2DShader texShader(DataTypes() << glu::getSampler2DType(depthStencilFmt), glu::TYPE_FLOAT_VEC4);
1078*35238bceSAndroid Build Coastguard Worker             uint32_t texShaderID = getCurrentContext()->createProgram(&texShader);
1079*35238bceSAndroid Build Coastguard Worker 
1080*35238bceSAndroid Build Coastguard Worker             texShader.setUniforms(*getCurrentContext(), texShaderID);
1081*35238bceSAndroid Build Coastguard Worker 
1082*35238bceSAndroid Build Coastguard Worker             glBindTexture(GL_TEXTURE_2D, depthStencilTex);
1083*35238bceSAndroid Build Coastguard Worker             sglr::drawQuad(*getCurrentContext(), texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
1084*35238bceSAndroid Build Coastguard Worker         }
1085*35238bceSAndroid Build Coastguard Worker 
1086*35238bceSAndroid Build Coastguard Worker         readPixels(dst, 0, 0, getWidth(), getHeight());
1087*35238bceSAndroid Build Coastguard Worker     }
1088*35238bceSAndroid Build Coastguard Worker 
compare(const tcu::Surface & reference,const tcu::Surface & result)1089*35238bceSAndroid Build Coastguard Worker     bool compare(const tcu::Surface &reference, const tcu::Surface &result)
1090*35238bceSAndroid Build Coastguard Worker     {
1091*35238bceSAndroid Build Coastguard Worker         const tcu::RGBA threshold(tcu::max(getFormatThreshold(m_colorFmt), tcu::RGBA(12, 12, 12, 12)));
1092*35238bceSAndroid Build Coastguard Worker 
1093*35238bceSAndroid Build Coastguard Worker         return tcu::bilinearCompare(m_testCtx.getLog(), "Result", "Image comparison result", reference.getAccess(),
1094*35238bceSAndroid Build Coastguard Worker                                     result.getAccess(), threshold, tcu::COMPARE_LOG_RESULT);
1095*35238bceSAndroid Build Coastguard Worker     }
1096*35238bceSAndroid Build Coastguard Worker 
1097*35238bceSAndroid Build Coastguard Worker private:
1098*35238bceSAndroid Build Coastguard Worker     uint32_t m_colorFmt;
1099*35238bceSAndroid Build Coastguard Worker     uint32_t m_depthStencilFmt;
1100*35238bceSAndroid Build Coastguard Worker     uint32_t m_invalidateBuffers;
1101*35238bceSAndroid Build Coastguard Worker };
1102*35238bceSAndroid Build Coastguard Worker 
1103*35238bceSAndroid Build Coastguard Worker class InvalidateSubFboUnbindBlitCase : public FboTestCase
1104*35238bceSAndroid Build Coastguard Worker {
1105*35238bceSAndroid Build Coastguard Worker public:
InvalidateSubFboUnbindBlitCase(Context & context,const char * name,const char * description,int numSamples,uint32_t invalidateBuffers)1106*35238bceSAndroid Build Coastguard Worker     InvalidateSubFboUnbindBlitCase(Context &context, const char *name, const char *description, int numSamples,
1107*35238bceSAndroid Build Coastguard Worker                                    uint32_t invalidateBuffers)
1108*35238bceSAndroid Build Coastguard Worker         : FboTestCase(context, name, description,
1109*35238bceSAndroid Build Coastguard Worker                       numSamples >
1110*35238bceSAndroid Build Coastguard Worker                           0) // \note Use fullscreen viewport when multisampling - we can't allow GLES3Context do its
1111*35238bceSAndroid Build Coastguard Worker         //         behing-the-scenes viewport position randomization, because with glBlitFramebuffer,
1112*35238bceSAndroid Build Coastguard Worker         //         source and destination rectangles must match when multisampling.
1113*35238bceSAndroid Build Coastguard Worker         , m_colorFmt(0)
1114*35238bceSAndroid Build Coastguard Worker         , m_depthStencilFmt(0)
1115*35238bceSAndroid Build Coastguard Worker         , m_numSamples(numSamples)
1116*35238bceSAndroid Build Coastguard Worker         , m_invalidateBuffers(invalidateBuffers)
1117*35238bceSAndroid Build Coastguard Worker     {
1118*35238bceSAndroid Build Coastguard Worker         // Figure out formats that are compatible with default framebuffer.
1119*35238bceSAndroid Build Coastguard Worker         m_colorFmt        = getCompatibleColorFormat(m_context.getRenderTarget());
1120*35238bceSAndroid Build Coastguard Worker         m_depthStencilFmt = getCompatibleDepthStencilFormat(m_context.getRenderTarget());
1121*35238bceSAndroid Build Coastguard Worker     }
1122*35238bceSAndroid Build Coastguard Worker 
1123*35238bceSAndroid Build Coastguard Worker protected:
preCheck(void)1124*35238bceSAndroid Build Coastguard Worker     void preCheck(void)
1125*35238bceSAndroid Build Coastguard Worker     {
1126*35238bceSAndroid Build Coastguard Worker         if (m_context.getRenderTarget().getNumSamples() > 0)
1127*35238bceSAndroid Build Coastguard Worker             throw tcu::NotSupportedError("Not supported in MSAA config");
1128*35238bceSAndroid Build Coastguard Worker 
1129*35238bceSAndroid Build Coastguard Worker         if (m_colorFmt == GL_NONE)
1130*35238bceSAndroid Build Coastguard Worker             throw tcu::NotSupportedError("Unsupported color format");
1131*35238bceSAndroid Build Coastguard Worker 
1132*35238bceSAndroid Build Coastguard Worker         if (m_depthStencilFmt == GL_NONE)
1133*35238bceSAndroid Build Coastguard Worker             throw tcu::NotSupportedError("Unsupported depth/stencil format");
1134*35238bceSAndroid Build Coastguard Worker 
1135*35238bceSAndroid Build Coastguard Worker         checkFormatSupport(m_colorFmt);
1136*35238bceSAndroid Build Coastguard Worker         checkFormatSupport(m_depthStencilFmt);
1137*35238bceSAndroid Build Coastguard Worker     }
1138*35238bceSAndroid Build Coastguard Worker 
render(tcu::Surface & dst)1139*35238bceSAndroid Build Coastguard Worker     void render(tcu::Surface &dst)
1140*35238bceSAndroid Build Coastguard Worker     {
1141*35238bceSAndroid Build Coastguard Worker         // \note When using fullscreen viewport (when m_numSamples > 0), still only use a 128x128 pixel quad at most.
1142*35238bceSAndroid Build Coastguard Worker         IVec2 quadSizePixels(m_numSamples == 0 ? getWidth() : de::min(128, getWidth()),
1143*35238bceSAndroid Build Coastguard Worker                              m_numSamples == 0 ? getHeight() : de::min(128, getHeight()));
1144*35238bceSAndroid Build Coastguard Worker         Vec2 quadNDCLeftBottomXY(-1.0f, -1.0f);
1145*35238bceSAndroid Build Coastguard Worker         Vec2 quadNDCSize(2.0f * (float)quadSizePixels.x() / (float)getWidth(),
1146*35238bceSAndroid Build Coastguard Worker                          2.0f * (float)quadSizePixels.y() / (float)getHeight());
1147*35238bceSAndroid Build Coastguard Worker         Vec2 quadNDCRightTopXY = quadNDCLeftBottomXY + quadNDCSize;
1148*35238bceSAndroid Build Coastguard Worker         tcu::TextureFormat depthStencilFmt =
1149*35238bceSAndroid Build Coastguard Worker             m_depthStencilFmt != GL_NONE ? glu::mapGLInternalFormat(m_depthStencilFmt) : tcu::TextureFormat();
1150*35238bceSAndroid Build Coastguard Worker         bool depth = depthStencilFmt.order == tcu::TextureFormat::D || depthStencilFmt.order == tcu::TextureFormat::DS;
1151*35238bceSAndroid Build Coastguard Worker         bool stencil =
1152*35238bceSAndroid Build Coastguard Worker             depthStencilFmt.order == tcu::TextureFormat::S || depthStencilFmt.order == tcu::TextureFormat::DS;
1153*35238bceSAndroid Build Coastguard Worker         uint32_t fbo             = 0;
1154*35238bceSAndroid Build Coastguard Worker         uint32_t colorRbo        = 0;
1155*35238bceSAndroid Build Coastguard Worker         uint32_t depthStencilRbo = 0;
1156*35238bceSAndroid Build Coastguard Worker         int invalidateX          = 0;
1157*35238bceSAndroid Build Coastguard Worker         int invalidateY          = 0;
1158*35238bceSAndroid Build Coastguard Worker         int invalidateW          = quadSizePixels.x() / 2;
1159*35238bceSAndroid Build Coastguard Worker         int invalidateH          = quadSizePixels.y();
1160*35238bceSAndroid Build Coastguard Worker         int blitX0               = invalidateW;
1161*35238bceSAndroid Build Coastguard Worker         int blitY0               = 0;
1162*35238bceSAndroid Build Coastguard Worker         int blitX1               = blitX0 + quadSizePixels.x() / 2;
1163*35238bceSAndroid Build Coastguard Worker         int blitY1               = blitY0 + quadSizePixels.y();
1164*35238bceSAndroid Build Coastguard Worker         FlatColorShader flatShader(glu::TYPE_FLOAT_VEC4);
1165*35238bceSAndroid Build Coastguard Worker         vector<uint32_t> attachments = getFBODiscardAttachments(m_invalidateBuffers);
1166*35238bceSAndroid Build Coastguard Worker         uint32_t flatShaderID        = getCurrentContext()->createProgram(&flatShader);
1167*35238bceSAndroid Build Coastguard Worker 
1168*35238bceSAndroid Build Coastguard Worker         glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
1169*35238bceSAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1170*35238bceSAndroid Build Coastguard Worker 
1171*35238bceSAndroid Build Coastguard Worker         // Create fbo.
1172*35238bceSAndroid Build Coastguard Worker         glGenRenderbuffers(1, &colorRbo);
1173*35238bceSAndroid Build Coastguard Worker         glBindRenderbuffer(GL_RENDERBUFFER, colorRbo);
1174*35238bceSAndroid Build Coastguard Worker         glRenderbufferStorageMultisample(GL_RENDERBUFFER, m_numSamples, m_colorFmt, quadSizePixels.x(),
1175*35238bceSAndroid Build Coastguard Worker                                          quadSizePixels.y());
1176*35238bceSAndroid Build Coastguard Worker 
1177*35238bceSAndroid Build Coastguard Worker         if (m_depthStencilFmt != GL_NONE)
1178*35238bceSAndroid Build Coastguard Worker         {
1179*35238bceSAndroid Build Coastguard Worker             glGenRenderbuffers(1, &depthStencilRbo);
1180*35238bceSAndroid Build Coastguard Worker             glBindRenderbuffer(GL_RENDERBUFFER, depthStencilRbo);
1181*35238bceSAndroid Build Coastguard Worker             glRenderbufferStorageMultisample(GL_RENDERBUFFER, m_numSamples, m_depthStencilFmt, quadSizePixels.x(),
1182*35238bceSAndroid Build Coastguard Worker                                              quadSizePixels.y());
1183*35238bceSAndroid Build Coastguard Worker         }
1184*35238bceSAndroid Build Coastguard Worker 
1185*35238bceSAndroid Build Coastguard Worker         glGenFramebuffers(1, &fbo);
1186*35238bceSAndroid Build Coastguard Worker         glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1187*35238bceSAndroid Build Coastguard Worker         glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRbo);
1188*35238bceSAndroid Build Coastguard Worker 
1189*35238bceSAndroid Build Coastguard Worker         if (depth)
1190*35238bceSAndroid Build Coastguard Worker             glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthStencilRbo);
1191*35238bceSAndroid Build Coastguard Worker 
1192*35238bceSAndroid Build Coastguard Worker         if (stencil)
1193*35238bceSAndroid Build Coastguard Worker             glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthStencilRbo);
1194*35238bceSAndroid Build Coastguard Worker 
1195*35238bceSAndroid Build Coastguard Worker         checkFramebufferStatus(GL_FRAMEBUFFER);
1196*35238bceSAndroid Build Coastguard Worker 
1197*35238bceSAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1198*35238bceSAndroid Build Coastguard Worker 
1199*35238bceSAndroid Build Coastguard Worker         glEnable(GL_DEPTH_TEST);
1200*35238bceSAndroid Build Coastguard Worker         glEnable(GL_STENCIL_TEST);
1201*35238bceSAndroid Build Coastguard Worker         glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
1202*35238bceSAndroid Build Coastguard Worker         glStencilFunc(GL_ALWAYS, 1, 0xff);
1203*35238bceSAndroid Build Coastguard Worker 
1204*35238bceSAndroid Build Coastguard Worker         flatShader.setColor(*getCurrentContext(), flatShaderID, Vec4(1.0f, 0.0f, 0.0f, 1.0f));
1205*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(*getCurrentContext(), flatShaderID,
1206*35238bceSAndroid Build Coastguard Worker                        Vec3(quadNDCLeftBottomXY.x(), quadNDCLeftBottomXY.y(), -1.0f),
1207*35238bceSAndroid Build Coastguard Worker                        Vec3(quadNDCRightTopXY.x(), quadNDCRightTopXY.y(), 1.0f));
1208*35238bceSAndroid Build Coastguard Worker 
1209*35238bceSAndroid Build Coastguard Worker         glInvalidateSubFramebuffer(GL_FRAMEBUFFER, (int)attachments.size(), &attachments[0], invalidateX, invalidateY,
1210*35238bceSAndroid Build Coastguard Worker                                    invalidateW, invalidateH);
1211*35238bceSAndroid Build Coastguard Worker 
1212*35238bceSAndroid Build Coastguard Worker         // Set default framebuffer as draw framebuffer and blit preserved buffers.
1213*35238bceSAndroid Build Coastguard Worker         glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
1214*35238bceSAndroid Build Coastguard Worker         glBlitFramebuffer(blitX0, blitY0, blitX1, blitY1, blitX0, blitY0, blitX1, blitY1,
1215*35238bceSAndroid Build Coastguard Worker                           (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT) & ~m_invalidateBuffers,
1216*35238bceSAndroid Build Coastguard Worker                           GL_NEAREST);
1217*35238bceSAndroid Build Coastguard Worker         glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
1218*35238bceSAndroid Build Coastguard Worker 
1219*35238bceSAndroid Build Coastguard Worker         if ((m_invalidateBuffers & GL_COLOR_BUFFER_BIT) != 0)
1220*35238bceSAndroid Build Coastguard Worker         {
1221*35238bceSAndroid Build Coastguard Worker             // Color was not preserved - fill with green.
1222*35238bceSAndroid Build Coastguard Worker             glDisable(GL_DEPTH_TEST);
1223*35238bceSAndroid Build Coastguard Worker             glDisable(GL_STENCIL_TEST);
1224*35238bceSAndroid Build Coastguard Worker 
1225*35238bceSAndroid Build Coastguard Worker             flatShader.setColor(*getCurrentContext(), flatShaderID, Vec4(0.0f, 1.0f, 0.0f, 1.0f));
1226*35238bceSAndroid Build Coastguard Worker             sglr::drawQuad(*getCurrentContext(), flatShaderID,
1227*35238bceSAndroid Build Coastguard Worker                            Vec3(quadNDCLeftBottomXY.x(), quadNDCLeftBottomXY.y(), 0.0f),
1228*35238bceSAndroid Build Coastguard Worker                            Vec3(quadNDCRightTopXY.x(), quadNDCRightTopXY.y(), 0.0f));
1229*35238bceSAndroid Build Coastguard Worker 
1230*35238bceSAndroid Build Coastguard Worker             glEnable(GL_DEPTH_TEST);
1231*35238bceSAndroid Build Coastguard Worker             glEnable(GL_STENCIL_TEST);
1232*35238bceSAndroid Build Coastguard Worker         }
1233*35238bceSAndroid Build Coastguard Worker 
1234*35238bceSAndroid Build Coastguard Worker         if ((m_invalidateBuffers & GL_DEPTH_BUFFER_BIT) != 0)
1235*35238bceSAndroid Build Coastguard Worker         {
1236*35238bceSAndroid Build Coastguard Worker             // Depth was not preserved.
1237*35238bceSAndroid Build Coastguard Worker             glDepthFunc(GL_ALWAYS);
1238*35238bceSAndroid Build Coastguard Worker         }
1239*35238bceSAndroid Build Coastguard Worker 
1240*35238bceSAndroid Build Coastguard Worker         if ((m_invalidateBuffers & GL_STENCIL_BUFFER_BIT) == 0)
1241*35238bceSAndroid Build Coastguard Worker         {
1242*35238bceSAndroid Build Coastguard Worker             // Stencil was preserved.
1243*35238bceSAndroid Build Coastguard Worker             glStencilFunc(GL_EQUAL, 1, 0xff);
1244*35238bceSAndroid Build Coastguard Worker         }
1245*35238bceSAndroid Build Coastguard Worker 
1246*35238bceSAndroid Build Coastguard Worker         glEnable(GL_BLEND);
1247*35238bceSAndroid Build Coastguard Worker         glBlendFunc(GL_ONE, GL_ONE);
1248*35238bceSAndroid Build Coastguard Worker         glBlendEquation(GL_FUNC_ADD);
1249*35238bceSAndroid Build Coastguard Worker 
1250*35238bceSAndroid Build Coastguard Worker         flatShader.setColor(*getCurrentContext(), flatShaderID, Vec4(0.0f, 0.0f, 1.0f, 1.0f));
1251*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(*getCurrentContext(), flatShaderID, Vec3(quadNDCLeftBottomXY.x(), quadNDCLeftBottomXY.y(), 0.0f),
1252*35238bceSAndroid Build Coastguard Worker                        Vec3(quadNDCRightTopXY.x(), quadNDCRightTopXY.y(), 0.0f));
1253*35238bceSAndroid Build Coastguard Worker 
1254*35238bceSAndroid Build Coastguard Worker         readPixels(dst, 0, 0, quadSizePixels.x(), quadSizePixels.y());
1255*35238bceSAndroid Build Coastguard Worker     }
1256*35238bceSAndroid Build Coastguard Worker 
1257*35238bceSAndroid Build Coastguard Worker private:
1258*35238bceSAndroid Build Coastguard Worker     uint32_t m_colorFmt;
1259*35238bceSAndroid Build Coastguard Worker     uint32_t m_depthStencilFmt;
1260*35238bceSAndroid Build Coastguard Worker     int m_numSamples;
1261*35238bceSAndroid Build Coastguard Worker     uint32_t m_invalidateBuffers;
1262*35238bceSAndroid Build Coastguard Worker };
1263*35238bceSAndroid Build Coastguard Worker 
1264*35238bceSAndroid Build Coastguard Worker class InvalidateFboTargetCase : public FboTestCase
1265*35238bceSAndroid Build Coastguard Worker {
1266*35238bceSAndroid Build Coastguard Worker public:
InvalidateFboTargetCase(Context & context,const char * name,const char * description,uint32_t boundTarget,uint32_t invalidateTarget,const uint32_t * invalidateAttachments,int numAttachments)1267*35238bceSAndroid Build Coastguard Worker     InvalidateFboTargetCase(Context &context, const char *name, const char *description, uint32_t boundTarget,
1268*35238bceSAndroid Build Coastguard Worker                             uint32_t invalidateTarget, const uint32_t *invalidateAttachments, int numAttachments)
1269*35238bceSAndroid Build Coastguard Worker         : FboTestCase(context, name, description)
1270*35238bceSAndroid Build Coastguard Worker         , m_boundTarget(boundTarget)
1271*35238bceSAndroid Build Coastguard Worker         , m_invalidateTarget(invalidateTarget)
1272*35238bceSAndroid Build Coastguard Worker         , m_invalidateAttachments(invalidateAttachments, invalidateAttachments + numAttachments)
1273*35238bceSAndroid Build Coastguard Worker     {
1274*35238bceSAndroid Build Coastguard Worker     }
1275*35238bceSAndroid Build Coastguard Worker 
1276*35238bceSAndroid Build Coastguard Worker protected:
render(tcu::Surface & dst)1277*35238bceSAndroid Build Coastguard Worker     void render(tcu::Surface &dst)
1278*35238bceSAndroid Build Coastguard Worker     {
1279*35238bceSAndroid Build Coastguard Worker         const uint32_t colorFormat                = GL_RGBA8;
1280*35238bceSAndroid Build Coastguard Worker         const uint32_t depthStencilFormat         = GL_DEPTH24_STENCIL8;
1281*35238bceSAndroid Build Coastguard Worker         const tcu::TextureFormat colorFmt         = glu::mapGLInternalFormat(colorFormat);
1282*35238bceSAndroid Build Coastguard Worker         const tcu::TextureFormatInfo colorFmtInfo = tcu::getTextureFormatInfo(colorFmt);
1283*35238bceSAndroid Build Coastguard Worker         const tcu::Vec4 &cBias                    = colorFmtInfo.valueMin;
1284*35238bceSAndroid Build Coastguard Worker         const tcu::Vec4 cScale                    = colorFmtInfo.valueMax - colorFmtInfo.valueMin;
1285*35238bceSAndroid Build Coastguard Worker         const bool isDiscarded                    = (m_boundTarget == GL_FRAMEBUFFER) ||
1286*35238bceSAndroid Build Coastguard Worker                                  (m_invalidateTarget == GL_FRAMEBUFFER && m_boundTarget == GL_DRAW_FRAMEBUFFER) ||
1287*35238bceSAndroid Build Coastguard Worker                                  (m_invalidateTarget == m_boundTarget);
1288*35238bceSAndroid Build Coastguard Worker         const bool isColorDiscarded = isDiscarded && hasAttachment(m_invalidateAttachments, GL_COLOR_ATTACHMENT0);
1289*35238bceSAndroid Build Coastguard Worker         const bool isDepthDiscarded =
1290*35238bceSAndroid Build Coastguard Worker             isDiscarded && (hasAttachment(m_invalidateAttachments, GL_DEPTH_ATTACHMENT) ||
1291*35238bceSAndroid Build Coastguard Worker                             hasAttachment(m_invalidateAttachments, GL_DEPTH_STENCIL_ATTACHMENT));
1292*35238bceSAndroid Build Coastguard Worker         const bool isStencilDiscarded =
1293*35238bceSAndroid Build Coastguard Worker             isDiscarded && (hasAttachment(m_invalidateAttachments, GL_STENCIL_ATTACHMENT) ||
1294*35238bceSAndroid Build Coastguard Worker                             hasAttachment(m_invalidateAttachments, GL_DEPTH_STENCIL_ATTACHMENT));
1295*35238bceSAndroid Build Coastguard Worker 
1296*35238bceSAndroid Build Coastguard Worker         uint32_t fbo             = 0;
1297*35238bceSAndroid Build Coastguard Worker         uint32_t colorRbo        = 0;
1298*35238bceSAndroid Build Coastguard Worker         uint32_t depthStencilRbo = 0;
1299*35238bceSAndroid Build Coastguard Worker         FlatColorShader flatShader(glu::TYPE_FLOAT_VEC4);
1300*35238bceSAndroid Build Coastguard Worker         uint32_t flatShaderID = getCurrentContext()->createProgram(&flatShader);
1301*35238bceSAndroid Build Coastguard Worker 
1302*35238bceSAndroid Build Coastguard Worker         // Create fbo.
1303*35238bceSAndroid Build Coastguard Worker         glGenRenderbuffers(1, &colorRbo);
1304*35238bceSAndroid Build Coastguard Worker         glBindRenderbuffer(GL_RENDERBUFFER, colorRbo);
1305*35238bceSAndroid Build Coastguard Worker         glRenderbufferStorage(GL_RENDERBUFFER, colorFormat, getWidth(), getHeight());
1306*35238bceSAndroid Build Coastguard Worker 
1307*35238bceSAndroid Build Coastguard Worker         glGenRenderbuffers(1, &depthStencilRbo);
1308*35238bceSAndroid Build Coastguard Worker         glBindRenderbuffer(GL_RENDERBUFFER, depthStencilRbo);
1309*35238bceSAndroid Build Coastguard Worker         glRenderbufferStorage(GL_RENDERBUFFER, depthStencilFormat, getWidth(), getHeight());
1310*35238bceSAndroid Build Coastguard Worker 
1311*35238bceSAndroid Build Coastguard Worker         glGenFramebuffers(1, &fbo);
1312*35238bceSAndroid Build Coastguard Worker         glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1313*35238bceSAndroid Build Coastguard Worker         glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRbo);
1314*35238bceSAndroid Build Coastguard Worker         glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthStencilRbo);
1315*35238bceSAndroid Build Coastguard Worker         glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthStencilRbo);
1316*35238bceSAndroid Build Coastguard Worker 
1317*35238bceSAndroid Build Coastguard Worker         checkFramebufferStatus(GL_FRAMEBUFFER);
1318*35238bceSAndroid Build Coastguard Worker 
1319*35238bceSAndroid Build Coastguard Worker         glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
1320*35238bceSAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1321*35238bceSAndroid Build Coastguard Worker 
1322*35238bceSAndroid Build Coastguard Worker         glEnable(GL_DEPTH_TEST);
1323*35238bceSAndroid Build Coastguard Worker         glEnable(GL_STENCIL_TEST);
1324*35238bceSAndroid Build Coastguard Worker         glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
1325*35238bceSAndroid Build Coastguard Worker         glStencilFunc(GL_ALWAYS, 1, 0xff);
1326*35238bceSAndroid Build Coastguard Worker 
1327*35238bceSAndroid Build Coastguard Worker         flatShader.setColor(*getCurrentContext(), flatShaderID, Vec4(1.0f, 0.0f, 0.0f, 1.0f) * cScale + cBias);
1328*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(*getCurrentContext(), flatShaderID, Vec3(-1.0f, -1.0f, -1.0f), Vec3(1.0f, 1.0f, 1.0f));
1329*35238bceSAndroid Build Coastguard Worker 
1330*35238bceSAndroid Build Coastguard Worker         // Bound FBO to test target and default to other
1331*35238bceSAndroid Build Coastguard Worker         if (m_boundTarget != GL_FRAMEBUFFER)
1332*35238bceSAndroid Build Coastguard Worker         {
1333*35238bceSAndroid Build Coastguard Worker             // Unused fbo is used as complemeting target (read when discarding draw for example).
1334*35238bceSAndroid Build Coastguard Worker             // \note Framework takes care of deleting objects at the end of test case.
1335*35238bceSAndroid Build Coastguard Worker             const uint32_t unusedTarget =
1336*35238bceSAndroid Build Coastguard Worker                 m_boundTarget == GL_DRAW_FRAMEBUFFER ? GL_READ_FRAMEBUFFER : GL_DRAW_FRAMEBUFFER;
1337*35238bceSAndroid Build Coastguard Worker             uint32_t unusedFbo      = 0;
1338*35238bceSAndroid Build Coastguard Worker             uint32_t unusedColorRbo = 0;
1339*35238bceSAndroid Build Coastguard Worker 
1340*35238bceSAndroid Build Coastguard Worker             glGenRenderbuffers(1, &unusedColorRbo);
1341*35238bceSAndroid Build Coastguard Worker             glBindRenderbuffer(GL_RENDERBUFFER, unusedColorRbo);
1342*35238bceSAndroid Build Coastguard Worker             glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 64, 64);
1343*35238bceSAndroid Build Coastguard Worker             glGenFramebuffers(1, &unusedFbo);
1344*35238bceSAndroid Build Coastguard Worker             glBindFramebuffer(unusedTarget, unusedFbo);
1345*35238bceSAndroid Build Coastguard Worker             glFramebufferRenderbuffer(unusedTarget, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, unusedColorRbo);
1346*35238bceSAndroid Build Coastguard Worker 
1347*35238bceSAndroid Build Coastguard Worker             glBindFramebuffer(m_boundTarget, fbo);
1348*35238bceSAndroid Build Coastguard Worker         }
1349*35238bceSAndroid Build Coastguard Worker 
1350*35238bceSAndroid Build Coastguard Worker         glInvalidateFramebuffer(m_invalidateTarget, (int)m_invalidateAttachments.size(),
1351*35238bceSAndroid Build Coastguard Worker                                 m_invalidateAttachments.empty() ? DE_NULL : &m_invalidateAttachments[0]);
1352*35238bceSAndroid Build Coastguard Worker 
1353*35238bceSAndroid Build Coastguard Worker         if (m_boundTarget != GL_FRAMEBUFFER)
1354*35238bceSAndroid Build Coastguard Worker             glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1355*35238bceSAndroid Build Coastguard Worker 
1356*35238bceSAndroid Build Coastguard Worker         if (isColorDiscarded)
1357*35238bceSAndroid Build Coastguard Worker         {
1358*35238bceSAndroid Build Coastguard Worker             // Color was not preserved - fill with green.
1359*35238bceSAndroid Build Coastguard Worker             glDisable(GL_DEPTH_TEST);
1360*35238bceSAndroid Build Coastguard Worker             glDisable(GL_STENCIL_TEST);
1361*35238bceSAndroid Build Coastguard Worker 
1362*35238bceSAndroid Build Coastguard Worker             flatShader.setColor(*getCurrentContext(), flatShaderID, Vec4(0.0f, 1.0f, 0.0f, 1.0f) * cScale + cBias);
1363*35238bceSAndroid Build Coastguard Worker             sglr::drawQuad(*getCurrentContext(), flatShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
1364*35238bceSAndroid Build Coastguard Worker 
1365*35238bceSAndroid Build Coastguard Worker             glEnable(GL_DEPTH_TEST);
1366*35238bceSAndroid Build Coastguard Worker             glEnable(GL_STENCIL_TEST);
1367*35238bceSAndroid Build Coastguard Worker         }
1368*35238bceSAndroid Build Coastguard Worker 
1369*35238bceSAndroid Build Coastguard Worker         if (isDepthDiscarded)
1370*35238bceSAndroid Build Coastguard Worker         {
1371*35238bceSAndroid Build Coastguard Worker             // Depth was not preserved.
1372*35238bceSAndroid Build Coastguard Worker             glDepthFunc(GL_ALWAYS);
1373*35238bceSAndroid Build Coastguard Worker         }
1374*35238bceSAndroid Build Coastguard Worker 
1375*35238bceSAndroid Build Coastguard Worker         if (!isStencilDiscarded)
1376*35238bceSAndroid Build Coastguard Worker         {
1377*35238bceSAndroid Build Coastguard Worker             // Stencil was preserved.
1378*35238bceSAndroid Build Coastguard Worker             glStencilFunc(GL_EQUAL, 1, 0xff);
1379*35238bceSAndroid Build Coastguard Worker         }
1380*35238bceSAndroid Build Coastguard Worker 
1381*35238bceSAndroid Build Coastguard Worker         glEnable(GL_BLEND);
1382*35238bceSAndroid Build Coastguard Worker         glBlendFunc(GL_ONE, GL_ONE);
1383*35238bceSAndroid Build Coastguard Worker         glBlendEquation(GL_FUNC_ADD);
1384*35238bceSAndroid Build Coastguard Worker 
1385*35238bceSAndroid Build Coastguard Worker         flatShader.setColor(*getCurrentContext(), flatShaderID, Vec4(0.0f, 0.0f, 1.0f, 1.0f) * cScale + cBias);
1386*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(*getCurrentContext(), flatShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
1387*35238bceSAndroid Build Coastguard Worker 
1388*35238bceSAndroid Build Coastguard Worker         readPixels(dst, 0, 0, getWidth(), getHeight(), colorFmt, colorFmtInfo.lookupScale, colorFmtInfo.lookupBias);
1389*35238bceSAndroid Build Coastguard Worker     }
1390*35238bceSAndroid Build Coastguard Worker 
1391*35238bceSAndroid Build Coastguard Worker private:
1392*35238bceSAndroid Build Coastguard Worker     uint32_t m_boundTarget;
1393*35238bceSAndroid Build Coastguard Worker     uint32_t m_invalidateTarget;
1394*35238bceSAndroid Build Coastguard Worker     std::vector<uint32_t> m_invalidateAttachments;
1395*35238bceSAndroid Build Coastguard Worker };
1396*35238bceSAndroid Build Coastguard Worker 
FboInvalidateTests(Context & context)1397*35238bceSAndroid Build Coastguard Worker FboInvalidateTests::FboInvalidateTests(Context &context)
1398*35238bceSAndroid Build Coastguard Worker     : TestCaseGroup(context, "invalidate", "Framebuffer invalidate tests")
1399*35238bceSAndroid Build Coastguard Worker {
1400*35238bceSAndroid Build Coastguard Worker }
1401*35238bceSAndroid Build Coastguard Worker 
~FboInvalidateTests(void)1402*35238bceSAndroid Build Coastguard Worker FboInvalidateTests::~FboInvalidateTests(void)
1403*35238bceSAndroid Build Coastguard Worker {
1404*35238bceSAndroid Build Coastguard Worker }
1405*35238bceSAndroid Build Coastguard Worker 
init(void)1406*35238bceSAndroid Build Coastguard Worker void FboInvalidateTests::init(void)
1407*35238bceSAndroid Build Coastguard Worker {
1408*35238bceSAndroid Build Coastguard Worker     // invalidate.default.
1409*35238bceSAndroid Build Coastguard Worker     {
1410*35238bceSAndroid Build Coastguard Worker         tcu::TestCaseGroup *defaultFbGroup =
1411*35238bceSAndroid Build Coastguard Worker             new tcu::TestCaseGroup(m_testCtx, "default", "Default framebuffer invalidate tests");
1412*35238bceSAndroid Build Coastguard Worker         addChild(defaultFbGroup);
1413*35238bceSAndroid Build Coastguard Worker 
1414*35238bceSAndroid Build Coastguard Worker         defaultFbGroup->addChild(new InvalidateDefaultFramebufferRenderCase(m_context, "render_none",
1415*35238bceSAndroid Build Coastguard Worker                                                                             "Invalidating no framebuffers (ref)", 0));
1416*35238bceSAndroid Build Coastguard Worker         defaultFbGroup->addChild(new InvalidateDefaultFramebufferRenderCase(
1417*35238bceSAndroid Build Coastguard Worker             m_context, "render_color", "Rendering after invalidating colorbuffer", GL_COLOR_BUFFER_BIT));
1418*35238bceSAndroid Build Coastguard Worker         defaultFbGroup->addChild(new InvalidateDefaultFramebufferRenderCase(
1419*35238bceSAndroid Build Coastguard Worker             m_context, "render_depth", "Rendering after invalidating depthbuffer", GL_DEPTH_BUFFER_BIT));
1420*35238bceSAndroid Build Coastguard Worker         defaultFbGroup->addChild(new InvalidateDefaultFramebufferRenderCase(
1421*35238bceSAndroid Build Coastguard Worker             m_context, "render_stencil", "Rendering after invalidating stencilbuffer", GL_STENCIL_BUFFER_BIT));
1422*35238bceSAndroid Build Coastguard Worker         defaultFbGroup->addChild(new InvalidateDefaultFramebufferRenderCase(
1423*35238bceSAndroid Build Coastguard Worker             m_context, "render_depth_stencil", "Rendering after invalidating depth- and stencilbuffers",
1424*35238bceSAndroid Build Coastguard Worker             GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
1425*35238bceSAndroid Build Coastguard Worker         defaultFbGroup->addChild(new InvalidateDefaultFramebufferRenderCase(
1426*35238bceSAndroid Build Coastguard Worker             m_context, "render_all", "Rendering after invalidating all buffers",
1427*35238bceSAndroid Build Coastguard Worker             GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
1428*35238bceSAndroid Build Coastguard Worker 
1429*35238bceSAndroid Build Coastguard Worker         defaultFbGroup->addChild(new InvalidateDefaultFramebufferBindCase(
1430*35238bceSAndroid Build Coastguard Worker             m_context, "bind_color", "Binding fbo after invalidating colorbuffer", GL_COLOR_BUFFER_BIT));
1431*35238bceSAndroid Build Coastguard Worker         defaultFbGroup->addChild(new InvalidateDefaultFramebufferBindCase(
1432*35238bceSAndroid Build Coastguard Worker             m_context, "bind_depth", "Binding fbo after invalidating depthbuffer", GL_DEPTH_BUFFER_BIT));
1433*35238bceSAndroid Build Coastguard Worker         defaultFbGroup->addChild(new InvalidateDefaultFramebufferBindCase(
1434*35238bceSAndroid Build Coastguard Worker             m_context, "bind_stencil", "Binding fbo after invalidating stencilbuffer", GL_STENCIL_BUFFER_BIT));
1435*35238bceSAndroid Build Coastguard Worker         defaultFbGroup->addChild(new InvalidateDefaultFramebufferBindCase(
1436*35238bceSAndroid Build Coastguard Worker             m_context, "bind_depth_stencil", "Binding fbo after invalidating depth- and stencilbuffers",
1437*35238bceSAndroid Build Coastguard Worker             GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
1438*35238bceSAndroid Build Coastguard Worker         defaultFbGroup->addChild(new InvalidateDefaultFramebufferBindCase(
1439*35238bceSAndroid Build Coastguard Worker             m_context, "bind_all", "Binding fbo after invalidating all buffers",
1440*35238bceSAndroid Build Coastguard Worker             GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
1441*35238bceSAndroid Build Coastguard Worker 
1442*35238bceSAndroid Build Coastguard Worker         defaultFbGroup->addChild(new InvalidateDefaultSubFramebufferRenderCase(
1443*35238bceSAndroid Build Coastguard Worker             m_context, "sub_render_color", "Rendering after invalidating colorbuffer", GL_COLOR_BUFFER_BIT));
1444*35238bceSAndroid Build Coastguard Worker         defaultFbGroup->addChild(new InvalidateDefaultSubFramebufferRenderCase(
1445*35238bceSAndroid Build Coastguard Worker             m_context, "sub_render_depth", "Rendering after invalidating depthbuffer", GL_DEPTH_BUFFER_BIT));
1446*35238bceSAndroid Build Coastguard Worker         defaultFbGroup->addChild(new InvalidateDefaultSubFramebufferRenderCase(
1447*35238bceSAndroid Build Coastguard Worker             m_context, "sub_render_stencil", "Rendering after invalidating stencilbuffer", GL_STENCIL_BUFFER_BIT));
1448*35238bceSAndroid Build Coastguard Worker         defaultFbGroup->addChild(new InvalidateDefaultSubFramebufferRenderCase(
1449*35238bceSAndroid Build Coastguard Worker             m_context, "sub_render_depth_stencil", "Rendering after invalidating depth- and stencilbuffers",
1450*35238bceSAndroid Build Coastguard Worker             GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
1451*35238bceSAndroid Build Coastguard Worker         defaultFbGroup->addChild(new InvalidateDefaultSubFramebufferRenderCase(
1452*35238bceSAndroid Build Coastguard Worker             m_context, "sub_render_all", "Rendering after invalidating all buffers",
1453*35238bceSAndroid Build Coastguard Worker             GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
1454*35238bceSAndroid Build Coastguard Worker 
1455*35238bceSAndroid Build Coastguard Worker         defaultFbGroup->addChild(new InvalidateDefaultSubFramebufferBindCase(
1456*35238bceSAndroid Build Coastguard Worker             m_context, "sub_bind_color", "Binding fbo after invalidating colorbuffer", GL_COLOR_BUFFER_BIT));
1457*35238bceSAndroid Build Coastguard Worker         defaultFbGroup->addChild(new InvalidateDefaultSubFramebufferBindCase(
1458*35238bceSAndroid Build Coastguard Worker             m_context, "sub_bind_depth", "Binding fbo after invalidating depthbuffer", GL_DEPTH_BUFFER_BIT));
1459*35238bceSAndroid Build Coastguard Worker         defaultFbGroup->addChild(new InvalidateDefaultSubFramebufferBindCase(
1460*35238bceSAndroid Build Coastguard Worker             m_context, "sub_bind_stencil", "Binding fbo after invalidating stencilbuffer", GL_STENCIL_BUFFER_BIT));
1461*35238bceSAndroid Build Coastguard Worker         defaultFbGroup->addChild(new InvalidateDefaultSubFramebufferBindCase(
1462*35238bceSAndroid Build Coastguard Worker             m_context, "sub_bind_depth_stencil", "Binding fbo after invalidating depth- and stencilbuffers",
1463*35238bceSAndroid Build Coastguard Worker             GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
1464*35238bceSAndroid Build Coastguard Worker         defaultFbGroup->addChild(new InvalidateDefaultSubFramebufferBindCase(
1465*35238bceSAndroid Build Coastguard Worker             m_context, "sub_bind_all", "Binding fbo after invalidating all buffers",
1466*35238bceSAndroid Build Coastguard Worker             GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
1467*35238bceSAndroid Build Coastguard Worker 
1468*35238bceSAndroid Build Coastguard Worker         defaultFbGroup->addChild(new InvalidateDefaultFramebufferRenderCase(
1469*35238bceSAndroid Build Coastguard Worker             m_context, "draw_framebuffer_color", "Invalidating GL_COLOR in GL_DRAW_FRAMEBUFFER", GL_COLOR_BUFFER_BIT,
1470*35238bceSAndroid Build Coastguard Worker             GL_DRAW_FRAMEBUFFER));
1471*35238bceSAndroid Build Coastguard Worker         defaultFbGroup->addChild(new InvalidateDefaultFramebufferRenderCase(
1472*35238bceSAndroid Build Coastguard Worker             m_context, "draw_framebuffer_all", "Invalidating all in GL_DRAW_FRAMEBUFFER",
1473*35238bceSAndroid Build Coastguard Worker             GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_DRAW_FRAMEBUFFER));
1474*35238bceSAndroid Build Coastguard Worker         defaultFbGroup->addChild(new InvalidateDefaultFramebufferRenderCase(
1475*35238bceSAndroid Build Coastguard Worker             m_context, "read_framebuffer_color", "Invalidating GL_COLOR in GL_READ_FRAMEBUFFER", GL_COLOR_BUFFER_BIT,
1476*35238bceSAndroid Build Coastguard Worker             GL_READ_FRAMEBUFFER));
1477*35238bceSAndroid Build Coastguard Worker         defaultFbGroup->addChild(new InvalidateDefaultFramebufferRenderCase(
1478*35238bceSAndroid Build Coastguard Worker             m_context, "read_framebuffer_all", "Invalidating all in GL_READ_FRAMEBUFFER",
1479*35238bceSAndroid Build Coastguard Worker             GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_READ_FRAMEBUFFER));
1480*35238bceSAndroid Build Coastguard Worker     }
1481*35238bceSAndroid Build Coastguard Worker 
1482*35238bceSAndroid Build Coastguard Worker     // invalidate.whole.
1483*35238bceSAndroid Build Coastguard Worker     {
1484*35238bceSAndroid Build Coastguard Worker         tcu::TestCaseGroup *wholeFboGroup =
1485*35238bceSAndroid Build Coastguard Worker             new tcu::TestCaseGroup(m_testCtx, "whole", "Invalidating whole framebuffer object");
1486*35238bceSAndroid Build Coastguard Worker         addChild(wholeFboGroup);
1487*35238bceSAndroid Build Coastguard Worker 
1488*35238bceSAndroid Build Coastguard Worker         wholeFboGroup->addChild(
1489*35238bceSAndroid Build Coastguard Worker             new InvalidateFboRenderCase(m_context, "render_none", "", GL_RGBA8, GL_DEPTH24_STENCIL8, 0));
1490*35238bceSAndroid Build Coastguard Worker         wholeFboGroup->addChild(new InvalidateFboRenderCase(m_context, "render_color", "", GL_RGBA8,
1491*35238bceSAndroid Build Coastguard Worker                                                             GL_DEPTH24_STENCIL8, GL_COLOR_BUFFER_BIT));
1492*35238bceSAndroid Build Coastguard Worker         wholeFboGroup->addChild(new InvalidateFboRenderCase(m_context, "render_depth", "", GL_RGBA8,
1493*35238bceSAndroid Build Coastguard Worker                                                             GL_DEPTH24_STENCIL8, GL_DEPTH_BUFFER_BIT));
1494*35238bceSAndroid Build Coastguard Worker         wholeFboGroup->addChild(new InvalidateFboRenderCase(m_context, "render_stencil", "", GL_RGBA8,
1495*35238bceSAndroid Build Coastguard Worker                                                             GL_DEPTH24_STENCIL8, GL_STENCIL_BUFFER_BIT));
1496*35238bceSAndroid Build Coastguard Worker         wholeFboGroup->addChild(new InvalidateFboRenderCase(m_context, "render_depth_stencil", "", GL_RGBA8,
1497*35238bceSAndroid Build Coastguard Worker                                                             GL_DEPTH24_STENCIL8,
1498*35238bceSAndroid Build Coastguard Worker                                                             GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
1499*35238bceSAndroid Build Coastguard Worker         wholeFboGroup->addChild(
1500*35238bceSAndroid Build Coastguard Worker             new InvalidateFboRenderCase(m_context, "render_all", "", GL_RGBA8, GL_DEPTH24_STENCIL8,
1501*35238bceSAndroid Build Coastguard Worker                                         GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
1502*35238bceSAndroid Build Coastguard Worker 
1503*35238bceSAndroid Build Coastguard Worker         wholeFboGroup->addChild(new InvalidateFboUnbindReadCase(m_context, "unbind_read_color", "", GL_RGBA8,
1504*35238bceSAndroid Build Coastguard Worker                                                                 GL_DEPTH24_STENCIL8, GL_COLOR_BUFFER_BIT));
1505*35238bceSAndroid Build Coastguard Worker         wholeFboGroup->addChild(new InvalidateFboUnbindReadCase(m_context, "unbind_read_depth", "", GL_RGBA8,
1506*35238bceSAndroid Build Coastguard Worker                                                                 GL_DEPTH24_STENCIL8, GL_DEPTH_BUFFER_BIT));
1507*35238bceSAndroid Build Coastguard Worker         wholeFboGroup->addChild(new InvalidateFboUnbindReadCase(m_context, "unbind_read_stencil", "", GL_RGBA8,
1508*35238bceSAndroid Build Coastguard Worker                                                                 GL_DEPTH24_STENCIL8, GL_STENCIL_BUFFER_BIT));
1509*35238bceSAndroid Build Coastguard Worker         wholeFboGroup->addChild(new InvalidateFboUnbindReadCase(m_context, "unbind_read_depth_stencil", "", GL_RGBA8,
1510*35238bceSAndroid Build Coastguard Worker                                                                 GL_DEPTH24_STENCIL8,
1511*35238bceSAndroid Build Coastguard Worker                                                                 GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
1512*35238bceSAndroid Build Coastguard Worker         wholeFboGroup->addChild(new InvalidateFboUnbindReadCase(m_context, "unbind_read_color_stencil", "", GL_RGBA8,
1513*35238bceSAndroid Build Coastguard Worker                                                                 GL_DEPTH24_STENCIL8,
1514*35238bceSAndroid Build Coastguard Worker                                                                 GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
1515*35238bceSAndroid Build Coastguard Worker 
1516*35238bceSAndroid Build Coastguard Worker         wholeFboGroup->addChild(
1517*35238bceSAndroid Build Coastguard Worker             new InvalidateFboUnbindBlitCase(m_context, "unbind_blit_color", "", 0, GL_COLOR_BUFFER_BIT));
1518*35238bceSAndroid Build Coastguard Worker         wholeFboGroup->addChild(
1519*35238bceSAndroid Build Coastguard Worker             new InvalidateFboUnbindBlitCase(m_context, "unbind_blit_depth", "", 0, GL_DEPTH_BUFFER_BIT));
1520*35238bceSAndroid Build Coastguard Worker         wholeFboGroup->addChild(
1521*35238bceSAndroid Build Coastguard Worker             new InvalidateFboUnbindBlitCase(m_context, "unbind_blit_stencil", "", 0, GL_STENCIL_BUFFER_BIT));
1522*35238bceSAndroid Build Coastguard Worker         wholeFboGroup->addChild(new InvalidateFboUnbindBlitCase(m_context, "unbind_blit_depth_stencil", "", 0,
1523*35238bceSAndroid Build Coastguard Worker                                                                 GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
1524*35238bceSAndroid Build Coastguard Worker 
1525*35238bceSAndroid Build Coastguard Worker         wholeFboGroup->addChild(
1526*35238bceSAndroid Build Coastguard Worker             new InvalidateFboUnbindBlitCase(m_context, "unbind_blit_msaa_color", "", 4, GL_COLOR_BUFFER_BIT));
1527*35238bceSAndroid Build Coastguard Worker         wholeFboGroup->addChild(
1528*35238bceSAndroid Build Coastguard Worker             new InvalidateFboUnbindBlitCase(m_context, "unbind_blit_msaa_depth", "", 4, GL_DEPTH_BUFFER_BIT));
1529*35238bceSAndroid Build Coastguard Worker         wholeFboGroup->addChild(
1530*35238bceSAndroid Build Coastguard Worker             new InvalidateFboUnbindBlitCase(m_context, "unbind_blit_msaa_stencil", "", 4, GL_STENCIL_BUFFER_BIT));
1531*35238bceSAndroid Build Coastguard Worker         wholeFboGroup->addChild(new InvalidateFboUnbindBlitCase(m_context, "unbind_blit_msaa_depth_stencil", "", 4,
1532*35238bceSAndroid Build Coastguard Worker                                                                 GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
1533*35238bceSAndroid Build Coastguard Worker     }
1534*35238bceSAndroid Build Coastguard Worker 
1535*35238bceSAndroid Build Coastguard Worker     // invalidate.sub.
1536*35238bceSAndroid Build Coastguard Worker     {
1537*35238bceSAndroid Build Coastguard Worker         tcu::TestCaseGroup *subFboGroup =
1538*35238bceSAndroid Build Coastguard Worker             new tcu::TestCaseGroup(m_testCtx, "sub", "Invalidating subsection of framebuffer object");
1539*35238bceSAndroid Build Coastguard Worker         addChild(subFboGroup);
1540*35238bceSAndroid Build Coastguard Worker 
1541*35238bceSAndroid Build Coastguard Worker         subFboGroup->addChild(
1542*35238bceSAndroid Build Coastguard Worker             new InvalidateSubFboRenderCase(m_context, "render_none", "", GL_RGBA8, GL_DEPTH24_STENCIL8, 0));
1543*35238bceSAndroid Build Coastguard Worker         subFboGroup->addChild(new InvalidateSubFboRenderCase(m_context, "render_color", "", GL_RGBA8,
1544*35238bceSAndroid Build Coastguard Worker                                                              GL_DEPTH24_STENCIL8, GL_COLOR_BUFFER_BIT));
1545*35238bceSAndroid Build Coastguard Worker         subFboGroup->addChild(new InvalidateSubFboRenderCase(m_context, "render_depth", "", GL_RGBA8,
1546*35238bceSAndroid Build Coastguard Worker                                                              GL_DEPTH24_STENCIL8, GL_DEPTH_BUFFER_BIT));
1547*35238bceSAndroid Build Coastguard Worker         subFboGroup->addChild(new InvalidateSubFboRenderCase(m_context, "render_stencil", "", GL_RGBA8,
1548*35238bceSAndroid Build Coastguard Worker                                                              GL_DEPTH24_STENCIL8, GL_STENCIL_BUFFER_BIT));
1549*35238bceSAndroid Build Coastguard Worker         subFboGroup->addChild(new InvalidateSubFboRenderCase(m_context, "render_depth_stencil", "", GL_RGBA8,
1550*35238bceSAndroid Build Coastguard Worker                                                              GL_DEPTH24_STENCIL8,
1551*35238bceSAndroid Build Coastguard Worker                                                              GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
1552*35238bceSAndroid Build Coastguard Worker         subFboGroup->addChild(
1553*35238bceSAndroid Build Coastguard Worker             new InvalidateSubFboRenderCase(m_context, "render_all", "", GL_RGBA8, GL_DEPTH24_STENCIL8,
1554*35238bceSAndroid Build Coastguard Worker                                            GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
1555*35238bceSAndroid Build Coastguard Worker 
1556*35238bceSAndroid Build Coastguard Worker         subFboGroup->addChild(new InvalidateSubFboUnbindReadCase(m_context, "unbind_read_color", "", GL_RGBA8,
1557*35238bceSAndroid Build Coastguard Worker                                                                  GL_DEPTH24_STENCIL8, GL_COLOR_BUFFER_BIT));
1558*35238bceSAndroid Build Coastguard Worker         subFboGroup->addChild(new InvalidateSubFboUnbindReadCase(m_context, "unbind_read_depth", "", GL_RGBA8,
1559*35238bceSAndroid Build Coastguard Worker                                                                  GL_DEPTH24_STENCIL8, GL_DEPTH_BUFFER_BIT));
1560*35238bceSAndroid Build Coastguard Worker         subFboGroup->addChild(new InvalidateSubFboUnbindReadCase(m_context, "unbind_read_stencil", "", GL_RGBA8,
1561*35238bceSAndroid Build Coastguard Worker                                                                  GL_DEPTH24_STENCIL8, GL_STENCIL_BUFFER_BIT));
1562*35238bceSAndroid Build Coastguard Worker         subFboGroup->addChild(new InvalidateSubFboUnbindReadCase(m_context, "unbind_read_depth_stencil", "", GL_RGBA8,
1563*35238bceSAndroid Build Coastguard Worker                                                                  GL_DEPTH24_STENCIL8,
1564*35238bceSAndroid Build Coastguard Worker                                                                  GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
1565*35238bceSAndroid Build Coastguard Worker         subFboGroup->addChild(new InvalidateSubFboUnbindReadCase(m_context, "unbind_read_color_stencil", "", GL_RGBA8,
1566*35238bceSAndroid Build Coastguard Worker                                                                  GL_DEPTH24_STENCIL8,
1567*35238bceSAndroid Build Coastguard Worker                                                                  GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
1568*35238bceSAndroid Build Coastguard Worker 
1569*35238bceSAndroid Build Coastguard Worker         subFboGroup->addChild(
1570*35238bceSAndroid Build Coastguard Worker             new InvalidateSubFboUnbindBlitCase(m_context, "unbind_blit_color", "", 0, GL_COLOR_BUFFER_BIT));
1571*35238bceSAndroid Build Coastguard Worker         subFboGroup->addChild(
1572*35238bceSAndroid Build Coastguard Worker             new InvalidateSubFboUnbindBlitCase(m_context, "unbind_blit_depth", "", 0, GL_DEPTH_BUFFER_BIT));
1573*35238bceSAndroid Build Coastguard Worker         subFboGroup->addChild(
1574*35238bceSAndroid Build Coastguard Worker             new InvalidateSubFboUnbindBlitCase(m_context, "unbind_blit_stencil", "", 0, GL_STENCIL_BUFFER_BIT));
1575*35238bceSAndroid Build Coastguard Worker         subFboGroup->addChild(new InvalidateSubFboUnbindBlitCase(m_context, "unbind_blit_depth_stencil", "", 0,
1576*35238bceSAndroid Build Coastguard Worker                                                                  GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
1577*35238bceSAndroid Build Coastguard Worker 
1578*35238bceSAndroid Build Coastguard Worker         subFboGroup->addChild(
1579*35238bceSAndroid Build Coastguard Worker             new InvalidateSubFboUnbindBlitCase(m_context, "unbind_blit_msaa_color", "", 4, GL_COLOR_BUFFER_BIT));
1580*35238bceSAndroid Build Coastguard Worker         subFboGroup->addChild(
1581*35238bceSAndroid Build Coastguard Worker             new InvalidateSubFboUnbindBlitCase(m_context, "unbind_blit_msaa_depth", "", 4, GL_DEPTH_BUFFER_BIT));
1582*35238bceSAndroid Build Coastguard Worker         subFboGroup->addChild(
1583*35238bceSAndroid Build Coastguard Worker             new InvalidateSubFboUnbindBlitCase(m_context, "unbind_blit_msaa_stencil", "", 4, GL_STENCIL_BUFFER_BIT));
1584*35238bceSAndroid Build Coastguard Worker         subFboGroup->addChild(new InvalidateSubFboUnbindBlitCase(m_context, "unbind_blit_msaa_depth_stencil", "", 4,
1585*35238bceSAndroid Build Coastguard Worker                                                                  GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
1586*35238bceSAndroid Build Coastguard Worker     }
1587*35238bceSAndroid Build Coastguard Worker 
1588*35238bceSAndroid Build Coastguard Worker     // invalidate.format.
1589*35238bceSAndroid Build Coastguard Worker     {
1590*35238bceSAndroid Build Coastguard Worker         tcu::TestCaseGroup *formatGroup =
1591*35238bceSAndroid Build Coastguard Worker             new tcu::TestCaseGroup(m_testCtx, "format", "Invalidating framebuffers with selected formats");
1592*35238bceSAndroid Build Coastguard Worker         addChild(formatGroup);
1593*35238bceSAndroid Build Coastguard Worker 
1594*35238bceSAndroid Build Coastguard Worker         // Color buffer formats.
1595*35238bceSAndroid Build Coastguard Worker         static const uint32_t colorFormats[] = {
1596*35238bceSAndroid Build Coastguard Worker             // RGBA formats
1597*35238bceSAndroid Build Coastguard Worker             GL_RGBA32I, GL_RGBA32UI, GL_RGBA16I, GL_RGBA16UI, GL_RGBA8, GL_RGBA8I, GL_RGBA8UI, GL_SRGB8_ALPHA8,
1598*35238bceSAndroid Build Coastguard Worker             GL_RGB10_A2, GL_RGB10_A2UI, GL_RGBA4, GL_RGB5_A1,
1599*35238bceSAndroid Build Coastguard Worker 
1600*35238bceSAndroid Build Coastguard Worker             // RGB formats
1601*35238bceSAndroid Build Coastguard Worker             GL_RGB8, GL_RGB565,
1602*35238bceSAndroid Build Coastguard Worker 
1603*35238bceSAndroid Build Coastguard Worker             // RG formats
1604*35238bceSAndroid Build Coastguard Worker             GL_RG32I, GL_RG32UI, GL_RG16I, GL_RG16UI, GL_RG8, GL_RG8I, GL_RG8UI,
1605*35238bceSAndroid Build Coastguard Worker 
1606*35238bceSAndroid Build Coastguard Worker             // R formats
1607*35238bceSAndroid Build Coastguard Worker             GL_R32I, GL_R32UI, GL_R16I, GL_R16UI, GL_R8, GL_R8I, GL_R8UI,
1608*35238bceSAndroid Build Coastguard Worker 
1609*35238bceSAndroid Build Coastguard Worker             // GL_EXT_color_buffer_float
1610*35238bceSAndroid Build Coastguard Worker             GL_RGBA32F, GL_RGBA16F, GL_R11F_G11F_B10F, GL_RG32F, GL_RG16F, GL_R32F, GL_R16F};
1611*35238bceSAndroid Build Coastguard Worker 
1612*35238bceSAndroid Build Coastguard Worker         // Depth/stencilbuffer formats.
1613*35238bceSAndroid Build Coastguard Worker         static const uint32_t depthStencilFormats[] = {GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT24,
1614*35238bceSAndroid Build Coastguard Worker                                                        GL_DEPTH_COMPONENT16,  GL_DEPTH32F_STENCIL8,
1615*35238bceSAndroid Build Coastguard Worker                                                        GL_DEPTH24_STENCIL8,   GL_STENCIL_INDEX8};
1616*35238bceSAndroid Build Coastguard Worker 
1617*35238bceSAndroid Build Coastguard Worker         // Colorbuffer tests use invalidate, unbind, read test.
1618*35238bceSAndroid Build Coastguard Worker         for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(colorFormats); ndx++)
1619*35238bceSAndroid Build Coastguard Worker             formatGroup->addChild(new InvalidateSubFboUnbindReadCase(m_context, getFormatName(colorFormats[ndx]), "",
1620*35238bceSAndroid Build Coastguard Worker                                                                      colorFormats[ndx], GL_NONE, GL_COLOR_BUFFER_BIT));
1621*35238bceSAndroid Build Coastguard Worker 
1622*35238bceSAndroid Build Coastguard Worker         // Depth/stencilbuffer tests use invalidate, render test.
1623*35238bceSAndroid Build Coastguard Worker         for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(depthStencilFormats); ndx++)
1624*35238bceSAndroid Build Coastguard Worker             formatGroup->addChild(new InvalidateSubFboRenderCase(m_context, getFormatName(depthStencilFormats[ndx]), "",
1625*35238bceSAndroid Build Coastguard Worker                                                                  GL_RGBA8, depthStencilFormats[ndx],
1626*35238bceSAndroid Build Coastguard Worker                                                                  GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
1627*35238bceSAndroid Build Coastguard Worker     }
1628*35238bceSAndroid Build Coastguard Worker 
1629*35238bceSAndroid Build Coastguard Worker     // invalidate.target
1630*35238bceSAndroid Build Coastguard Worker     {
1631*35238bceSAndroid Build Coastguard Worker         tcu::TestCaseGroup *targetGroup = new tcu::TestCaseGroup(m_testCtx, "target", "Invalidate target");
1632*35238bceSAndroid Build Coastguard Worker         addChild(targetGroup);
1633*35238bceSAndroid Build Coastguard Worker 
1634*35238bceSAndroid Build Coastguard Worker         static const struct
1635*35238bceSAndroid Build Coastguard Worker         {
1636*35238bceSAndroid Build Coastguard Worker             const char *name;
1637*35238bceSAndroid Build Coastguard Worker             uint32_t invalidateTarget;
1638*35238bceSAndroid Build Coastguard Worker             uint32_t boundTarget;
1639*35238bceSAndroid Build Coastguard Worker         } s_targetCases[] = {
1640*35238bceSAndroid Build Coastguard Worker             {"framebuffer_framebuffer", GL_FRAMEBUFFER, GL_FRAMEBUFFER},
1641*35238bceSAndroid Build Coastguard Worker             {"framebuffer_read_framebuffer", GL_FRAMEBUFFER, GL_READ_FRAMEBUFFER},
1642*35238bceSAndroid Build Coastguard Worker             {"framebuffer_draw_framebuffer", GL_FRAMEBUFFER, GL_DRAW_FRAMEBUFFER},
1643*35238bceSAndroid Build Coastguard Worker             {"read_framebuffer_framebuffer", GL_READ_FRAMEBUFFER, GL_FRAMEBUFFER},
1644*35238bceSAndroid Build Coastguard Worker             {"read_framebuffer_read_framebuffer", GL_READ_FRAMEBUFFER, GL_READ_FRAMEBUFFER},
1645*35238bceSAndroid Build Coastguard Worker             {"read_framebuffer_draw_framebuffer", GL_READ_FRAMEBUFFER, GL_DRAW_FRAMEBUFFER},
1646*35238bceSAndroid Build Coastguard Worker             {"draw_framebuffer_framebuffer", GL_DRAW_FRAMEBUFFER, GL_FRAMEBUFFER},
1647*35238bceSAndroid Build Coastguard Worker             {"draw_framebuffer_read_framebuffer", GL_DRAW_FRAMEBUFFER, GL_READ_FRAMEBUFFER},
1648*35238bceSAndroid Build Coastguard Worker             {"draw_framebuffer_draw_framebuffer", GL_DRAW_FRAMEBUFFER, GL_DRAW_FRAMEBUFFER},
1649*35238bceSAndroid Build Coastguard Worker         };
1650*35238bceSAndroid Build Coastguard Worker 
1651*35238bceSAndroid Build Coastguard Worker         static const uint32_t colorAttachment[]        = {GL_COLOR_ATTACHMENT0};
1652*35238bceSAndroid Build Coastguard Worker         static const uint32_t depthStencilAttachment[] = {GL_DEPTH_STENCIL_ATTACHMENT};
1653*35238bceSAndroid Build Coastguard Worker         static const uint32_t allAttachments[] = {GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT};
1654*35238bceSAndroid Build Coastguard Worker 
1655*35238bceSAndroid Build Coastguard Worker         for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(s_targetCases); caseNdx++)
1656*35238bceSAndroid Build Coastguard Worker         {
1657*35238bceSAndroid Build Coastguard Worker             const std::string baseName = s_targetCases[caseNdx].name;
1658*35238bceSAndroid Build Coastguard Worker             const uint32_t invalidateT = s_targetCases[caseNdx].invalidateTarget;
1659*35238bceSAndroid Build Coastguard Worker             const uint32_t boundT      = s_targetCases[caseNdx].boundTarget;
1660*35238bceSAndroid Build Coastguard Worker 
1661*35238bceSAndroid Build Coastguard Worker             targetGroup->addChild(new InvalidateFboTargetCase(m_context, (baseName + "_color").c_str(), "", boundT,
1662*35238bceSAndroid Build Coastguard Worker                                                               invalidateT, &colorAttachment[0],
1663*35238bceSAndroid Build Coastguard Worker                                                               DE_LENGTH_OF_ARRAY(colorAttachment)));
1664*35238bceSAndroid Build Coastguard Worker             targetGroup->addChild(new InvalidateFboTargetCase(m_context, (baseName + "_depth_stencil").c_str(), "",
1665*35238bceSAndroid Build Coastguard Worker                                                               boundT, invalidateT, &depthStencilAttachment[0],
1666*35238bceSAndroid Build Coastguard Worker                                                               DE_LENGTH_OF_ARRAY(depthStencilAttachment)));
1667*35238bceSAndroid Build Coastguard Worker             targetGroup->addChild(new InvalidateFboTargetCase(m_context, (baseName + "_all").c_str(), "", boundT,
1668*35238bceSAndroid Build Coastguard Worker                                                               invalidateT, &allAttachments[0],
1669*35238bceSAndroid Build Coastguard Worker                                                               DE_LENGTH_OF_ARRAY(allAttachments)));
1670*35238bceSAndroid Build Coastguard Worker         }
1671*35238bceSAndroid Build Coastguard Worker     }
1672*35238bceSAndroid Build Coastguard Worker }
1673*35238bceSAndroid Build Coastguard Worker 
1674*35238bceSAndroid Build Coastguard Worker } // namespace Functional
1675*35238bceSAndroid Build Coastguard Worker } // namespace gles3
1676*35238bceSAndroid Build Coastguard Worker } // namespace deqp
1677