xref: /aosp_15_r20/external/deqp/modules/gles2/functional/es2fFboRenderTest.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program OpenGL ES 2.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 Framebuffer Object Tests.
22*35238bceSAndroid Build Coastguard Worker  *
23*35238bceSAndroid Build Coastguard Worker  * Notes:
24*35238bceSAndroid Build Coastguard Worker  *   + Like in API tests, tcu::sgl2s::Context class is used.
25*35238bceSAndroid Build Coastguard Worker  *   + ReferenceContext is used to generate reference images.
26*35238bceSAndroid Build Coastguard Worker  *   + API calls can be logged \todo [pyry] Implement.
27*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
28*35238bceSAndroid Build Coastguard Worker 
29*35238bceSAndroid Build Coastguard Worker #include "es2fFboRenderTest.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "sglrContextUtil.hpp"
31*35238bceSAndroid Build Coastguard Worker #include "sglrGLContext.hpp"
32*35238bceSAndroid Build Coastguard Worker #include "sglrReferenceContext.hpp"
33*35238bceSAndroid Build Coastguard Worker #include "tcuSurface.hpp"
34*35238bceSAndroid Build Coastguard Worker #include "tcuTextureUtil.hpp"
35*35238bceSAndroid Build Coastguard Worker #include "tcuImageCompare.hpp"
36*35238bceSAndroid Build Coastguard Worker #include "tcuRenderTarget.hpp"
37*35238bceSAndroid Build Coastguard Worker #include "gluPixelTransfer.hpp"
38*35238bceSAndroid Build Coastguard Worker #include "gluTextureUtil.hpp"
39*35238bceSAndroid Build Coastguard Worker #include "gluStrUtil.hpp"
40*35238bceSAndroid Build Coastguard Worker #include "deRandom.hpp"
41*35238bceSAndroid Build Coastguard Worker #include "deString.h"
42*35238bceSAndroid Build Coastguard Worker 
43*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
44*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
45*35238bceSAndroid Build Coastguard Worker 
46*35238bceSAndroid Build Coastguard Worker using std::string;
47*35238bceSAndroid Build Coastguard Worker using std::vector;
48*35238bceSAndroid Build Coastguard Worker using tcu::RGBA;
49*35238bceSAndroid Build Coastguard Worker using tcu::Surface;
50*35238bceSAndroid Build Coastguard Worker using tcu::Vec2;
51*35238bceSAndroid Build Coastguard Worker using tcu::Vec3;
52*35238bceSAndroid Build Coastguard Worker using tcu::Vec4;
53*35238bceSAndroid Build Coastguard Worker using namespace glw; // GL types
54*35238bceSAndroid Build Coastguard Worker 
55*35238bceSAndroid Build Coastguard Worker namespace deqp
56*35238bceSAndroid Build Coastguard Worker {
57*35238bceSAndroid Build Coastguard Worker namespace gles2
58*35238bceSAndroid Build Coastguard Worker {
59*35238bceSAndroid Build Coastguard Worker namespace Functional
60*35238bceSAndroid Build Coastguard Worker {
61*35238bceSAndroid Build Coastguard Worker 
62*35238bceSAndroid Build Coastguard Worker // Shaders.
63*35238bceSAndroid Build Coastguard Worker 
64*35238bceSAndroid Build Coastguard Worker class FlatColorShader : public sglr::ShaderProgram
65*35238bceSAndroid Build Coastguard Worker {
66*35238bceSAndroid Build Coastguard Worker public:
FlatColorShader(void)67*35238bceSAndroid Build Coastguard Worker     FlatColorShader(void)
68*35238bceSAndroid Build Coastguard Worker         : sglr::ShaderProgram(sglr::pdec::ShaderProgramDeclaration()
69*35238bceSAndroid Build Coastguard Worker                               << sglr::pdec::VertexAttribute("a_position", rr::GENERICVECTYPE_FLOAT)
70*35238bceSAndroid Build Coastguard Worker                               << sglr::pdec::FragmentOutput(rr::GENERICVECTYPE_FLOAT)
71*35238bceSAndroid Build Coastguard Worker                               << sglr::pdec::Uniform("u_color", glu::TYPE_FLOAT_VEC4)
72*35238bceSAndroid Build Coastguard Worker                               << sglr::pdec::VertexSource("attribute highp vec4 a_position;\n"
73*35238bceSAndroid Build Coastguard Worker                                                           "void main (void)\n"
74*35238bceSAndroid Build Coastguard Worker                                                           "{\n"
75*35238bceSAndroid Build Coastguard Worker                                                           "    gl_Position = a_position;\n"
76*35238bceSAndroid Build Coastguard Worker                                                           "}\n")
77*35238bceSAndroid Build Coastguard Worker                               << sglr::pdec::FragmentSource("uniform mediump vec4 u_color;\n"
78*35238bceSAndroid Build Coastguard Worker                                                             "void main (void)\n"
79*35238bceSAndroid Build Coastguard Worker                                                             "{\n"
80*35238bceSAndroid Build Coastguard Worker                                                             "    gl_FragColor = u_color;\n"
81*35238bceSAndroid Build Coastguard Worker                                                             "}\n"))
82*35238bceSAndroid Build Coastguard Worker     {
83*35238bceSAndroid Build Coastguard Worker     }
84*35238bceSAndroid Build Coastguard Worker 
setColor(sglr::Context & gl,uint32_t program,const tcu::Vec4 & color)85*35238bceSAndroid Build Coastguard Worker     void setColor(sglr::Context &gl, uint32_t program, const tcu::Vec4 &color)
86*35238bceSAndroid Build Coastguard Worker     {
87*35238bceSAndroid Build Coastguard Worker         gl.useProgram(program);
88*35238bceSAndroid Build Coastguard Worker         gl.uniform4fv(gl.getUniformLocation(program, "u_color"), 1, color.getPtr());
89*35238bceSAndroid Build Coastguard Worker     }
90*35238bceSAndroid Build Coastguard Worker 
shadeVertices(const rr::VertexAttrib * inputs,rr::VertexPacket * const * packets,const int numPackets) const91*35238bceSAndroid Build Coastguard Worker     void shadeVertices(const rr::VertexAttrib *inputs, rr::VertexPacket *const *packets, const int numPackets) const
92*35238bceSAndroid Build Coastguard Worker     {
93*35238bceSAndroid Build Coastguard Worker         for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
94*35238bceSAndroid Build Coastguard Worker             packets[packetNdx]->position =
95*35238bceSAndroid Build Coastguard Worker                 rr::readVertexAttribFloat(inputs[0], packets[packetNdx]->instanceNdx, packets[packetNdx]->vertexNdx);
96*35238bceSAndroid Build Coastguard Worker     }
97*35238bceSAndroid Build Coastguard Worker 
shadeFragments(rr::FragmentPacket * packets,const int numPackets,const rr::FragmentShadingContext & context) const98*35238bceSAndroid Build Coastguard Worker     void shadeFragments(rr::FragmentPacket *packets, const int numPackets,
99*35238bceSAndroid Build Coastguard Worker                         const rr::FragmentShadingContext &context) const
100*35238bceSAndroid Build Coastguard Worker     {
101*35238bceSAndroid Build Coastguard Worker         const tcu::Vec4 color(m_uniforms[0].value.f4);
102*35238bceSAndroid Build Coastguard Worker 
103*35238bceSAndroid Build Coastguard Worker         DE_UNREF(packets);
104*35238bceSAndroid Build Coastguard Worker 
105*35238bceSAndroid Build Coastguard Worker         for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
106*35238bceSAndroid Build Coastguard Worker             for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
107*35238bceSAndroid Build Coastguard Worker                 rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, color);
108*35238bceSAndroid Build Coastguard Worker     }
109*35238bceSAndroid Build Coastguard Worker };
110*35238bceSAndroid Build Coastguard Worker 
111*35238bceSAndroid Build Coastguard Worker class SingleTex2DShader : public sglr::ShaderProgram
112*35238bceSAndroid Build Coastguard Worker {
113*35238bceSAndroid Build Coastguard Worker public:
SingleTex2DShader(void)114*35238bceSAndroid Build Coastguard Worker     SingleTex2DShader(void)
115*35238bceSAndroid Build Coastguard Worker         : sglr::ShaderProgram(sglr::pdec::ShaderProgramDeclaration()
116*35238bceSAndroid Build Coastguard Worker                               << sglr::pdec::VertexAttribute("a_position", rr::GENERICVECTYPE_FLOAT)
117*35238bceSAndroid Build Coastguard Worker                               << sglr::pdec::VertexAttribute("a_coord", rr::GENERICVECTYPE_FLOAT)
118*35238bceSAndroid Build Coastguard Worker                               << sglr::pdec::VertexToFragmentVarying(rr::GENERICVECTYPE_FLOAT)
119*35238bceSAndroid Build Coastguard Worker                               << sglr::pdec::FragmentOutput(rr::GENERICVECTYPE_FLOAT)
120*35238bceSAndroid Build Coastguard Worker                               << sglr::pdec::Uniform("u_sampler0", glu::TYPE_SAMPLER_2D)
121*35238bceSAndroid Build Coastguard Worker                               << sglr::pdec::VertexSource("attribute highp vec4 a_position;\n"
122*35238bceSAndroid Build Coastguard Worker                                                           "attribute mediump vec2 a_coord;\n"
123*35238bceSAndroid Build Coastguard Worker                                                           "varying mediump vec2 v_coord;\n"
124*35238bceSAndroid Build Coastguard Worker                                                           "void main (void)\n"
125*35238bceSAndroid Build Coastguard Worker                                                           "{\n"
126*35238bceSAndroid Build Coastguard Worker                                                           "    gl_Position = a_position;\n"
127*35238bceSAndroid Build Coastguard Worker                                                           "    v_coord = a_coord;\n"
128*35238bceSAndroid Build Coastguard Worker                                                           "}\n")
129*35238bceSAndroid Build Coastguard Worker                               << sglr::pdec::FragmentSource("uniform sampler2D u_sampler0;\n"
130*35238bceSAndroid Build Coastguard Worker                                                             "varying mediump vec2 v_coord;\n"
131*35238bceSAndroid Build Coastguard Worker                                                             "void main (void)\n"
132*35238bceSAndroid Build Coastguard Worker                                                             "{\n"
133*35238bceSAndroid Build Coastguard Worker                                                             "    gl_FragColor = texture2D(u_sampler0, v_coord);\n"
134*35238bceSAndroid Build Coastguard Worker                                                             "}\n"))
135*35238bceSAndroid Build Coastguard Worker     {
136*35238bceSAndroid Build Coastguard Worker     }
137*35238bceSAndroid Build Coastguard Worker 
setUnit(sglr::Context & gl,uint32_t program,int unitNdx)138*35238bceSAndroid Build Coastguard Worker     void setUnit(sglr::Context &gl, uint32_t program, int unitNdx)
139*35238bceSAndroid Build Coastguard Worker     {
140*35238bceSAndroid Build Coastguard Worker         gl.useProgram(program);
141*35238bceSAndroid Build Coastguard Worker         gl.uniform1i(gl.getUniformLocation(program, "u_sampler0"), unitNdx);
142*35238bceSAndroid Build Coastguard Worker     }
143*35238bceSAndroid Build Coastguard Worker 
shadeVertices(const rr::VertexAttrib * inputs,rr::VertexPacket * const * packets,const int numPackets) const144*35238bceSAndroid Build Coastguard Worker     void shadeVertices(const rr::VertexAttrib *inputs, rr::VertexPacket *const *packets, const int numPackets) const
145*35238bceSAndroid Build Coastguard Worker     {
146*35238bceSAndroid Build Coastguard Worker         for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
147*35238bceSAndroid Build Coastguard Worker         {
148*35238bceSAndroid Build Coastguard Worker             rr::VertexPacket &packet = *packets[packetNdx];
149*35238bceSAndroid Build Coastguard Worker 
150*35238bceSAndroid Build Coastguard Worker             packet.position   = rr::readVertexAttribFloat(inputs[0], packet.instanceNdx, packet.vertexNdx);
151*35238bceSAndroid Build Coastguard Worker             packet.outputs[0] = rr::readVertexAttribFloat(inputs[1], packet.instanceNdx, packet.vertexNdx);
152*35238bceSAndroid Build Coastguard Worker         }
153*35238bceSAndroid Build Coastguard Worker     }
154*35238bceSAndroid Build Coastguard Worker 
shadeFragments(rr::FragmentPacket * packets,const int numPackets,const rr::FragmentShadingContext & context) const155*35238bceSAndroid Build Coastguard Worker     void shadeFragments(rr::FragmentPacket *packets, const int numPackets,
156*35238bceSAndroid Build Coastguard Worker                         const rr::FragmentShadingContext &context) const
157*35238bceSAndroid Build Coastguard Worker     {
158*35238bceSAndroid Build Coastguard Worker         for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
159*35238bceSAndroid Build Coastguard Worker             for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
160*35238bceSAndroid Build Coastguard Worker             {
161*35238bceSAndroid Build Coastguard Worker                 const tcu::Vec4 v_coord = rr::readVarying<float>(packets[packetNdx], context, 0, fragNdx);
162*35238bceSAndroid Build Coastguard Worker                 const float lod         = 0.0f;
163*35238bceSAndroid Build Coastguard Worker 
164*35238bceSAndroid Build Coastguard Worker                 rr::writeFragmentOutput(context, packetNdx, fragNdx, 0,
165*35238bceSAndroid Build Coastguard Worker                                         this->m_uniforms[0].sampler.tex2D->sample(v_coord.x(), v_coord.y(), lod));
166*35238bceSAndroid Build Coastguard Worker             }
167*35238bceSAndroid Build Coastguard Worker     }
168*35238bceSAndroid Build Coastguard Worker };
169*35238bceSAndroid Build Coastguard Worker 
170*35238bceSAndroid Build Coastguard Worker class MixTexturesShader : public sglr::ShaderProgram
171*35238bceSAndroid Build Coastguard Worker {
172*35238bceSAndroid Build Coastguard Worker public:
MixTexturesShader(void)173*35238bceSAndroid Build Coastguard Worker     MixTexturesShader(void)
174*35238bceSAndroid Build Coastguard Worker         : sglr::ShaderProgram(
175*35238bceSAndroid Build Coastguard Worker               sglr::pdec::ShaderProgramDeclaration()
176*35238bceSAndroid Build Coastguard Worker               << sglr::pdec::VertexAttribute("a_position", rr::GENERICVECTYPE_FLOAT)
177*35238bceSAndroid Build Coastguard Worker               << sglr::pdec::VertexAttribute("a_coord", rr::GENERICVECTYPE_FLOAT)
178*35238bceSAndroid Build Coastguard Worker               << sglr::pdec::VertexToFragmentVarying(rr::GENERICVECTYPE_FLOAT)
179*35238bceSAndroid Build Coastguard Worker               << sglr::pdec::FragmentOutput(rr::GENERICVECTYPE_FLOAT)
180*35238bceSAndroid Build Coastguard Worker               << sglr::pdec::Uniform("u_sampler0", glu::TYPE_SAMPLER_2D)
181*35238bceSAndroid Build Coastguard Worker               << sglr::pdec::Uniform("u_sampler1", glu::TYPE_SAMPLER_2D)
182*35238bceSAndroid Build Coastguard Worker               << sglr::pdec::VertexSource("attribute highp vec4 a_position;\n"
183*35238bceSAndroid Build Coastguard Worker                                           "attribute mediump vec2 a_coord;\n"
184*35238bceSAndroid Build Coastguard Worker                                           "varying mediump vec2 v_coord;\n"
185*35238bceSAndroid Build Coastguard Worker                                           "void main (void)\n"
186*35238bceSAndroid Build Coastguard Worker                                           "{\n"
187*35238bceSAndroid Build Coastguard Worker                                           "    gl_Position = a_position;\n"
188*35238bceSAndroid Build Coastguard Worker                                           "    v_coord = a_coord;\n"
189*35238bceSAndroid Build Coastguard Worker                                           "}\n")
190*35238bceSAndroid Build Coastguard Worker               << sglr::pdec::FragmentSource(
191*35238bceSAndroid Build Coastguard Worker                      "uniform sampler2D u_sampler0;\n"
192*35238bceSAndroid Build Coastguard Worker                      "uniform sampler2D u_sampler1;\n"
193*35238bceSAndroid Build Coastguard Worker                      "varying mediump vec2 v_coord;\n"
194*35238bceSAndroid Build Coastguard Worker                      "void main (void)\n"
195*35238bceSAndroid Build Coastguard Worker                      "{\n"
196*35238bceSAndroid Build Coastguard Worker                      "    gl_FragColor = texture2D(u_sampler0, v_coord)*0.5 + texture2D(u_sampler1, v_coord)*0.5;\n"
197*35238bceSAndroid Build Coastguard Worker                      "}\n"))
198*35238bceSAndroid Build Coastguard Worker     {
199*35238bceSAndroid Build Coastguard Worker     }
200*35238bceSAndroid Build Coastguard Worker 
setUnits(sglr::Context & gl,uint32_t program,int unit0,int unit1)201*35238bceSAndroid Build Coastguard Worker     void setUnits(sglr::Context &gl, uint32_t program, int unit0, int unit1)
202*35238bceSAndroid Build Coastguard Worker     {
203*35238bceSAndroid Build Coastguard Worker         gl.useProgram(program);
204*35238bceSAndroid Build Coastguard Worker         gl.uniform1i(gl.getUniformLocation(program, "u_sampler0"), unit0);
205*35238bceSAndroid Build Coastguard Worker         gl.uniform1i(gl.getUniformLocation(program, "u_sampler1"), unit1);
206*35238bceSAndroid Build Coastguard Worker     }
207*35238bceSAndroid Build Coastguard Worker 
shadeVertices(const rr::VertexAttrib * inputs,rr::VertexPacket * const * packets,const int numPackets) const208*35238bceSAndroid Build Coastguard Worker     void shadeVertices(const rr::VertexAttrib *inputs, rr::VertexPacket *const *packets, const int numPackets) const
209*35238bceSAndroid Build Coastguard Worker     {
210*35238bceSAndroid Build Coastguard Worker         for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
211*35238bceSAndroid Build Coastguard Worker         {
212*35238bceSAndroid Build Coastguard Worker             rr::VertexPacket &packet = *packets[packetNdx];
213*35238bceSAndroid Build Coastguard Worker 
214*35238bceSAndroid Build Coastguard Worker             packet.position   = rr::readVertexAttribFloat(inputs[0], packet.instanceNdx, packet.vertexNdx);
215*35238bceSAndroid Build Coastguard Worker             packet.outputs[0] = rr::readVertexAttribFloat(inputs[1], packet.instanceNdx, packet.vertexNdx);
216*35238bceSAndroid Build Coastguard Worker         }
217*35238bceSAndroid Build Coastguard Worker     }
218*35238bceSAndroid Build Coastguard Worker 
shadeFragments(rr::FragmentPacket * packets,const int numPackets,const rr::FragmentShadingContext & context) const219*35238bceSAndroid Build Coastguard Worker     void shadeFragments(rr::FragmentPacket *packets, const int numPackets,
220*35238bceSAndroid Build Coastguard Worker                         const rr::FragmentShadingContext &context) const
221*35238bceSAndroid Build Coastguard Worker     {
222*35238bceSAndroid Build Coastguard Worker         for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
223*35238bceSAndroid Build Coastguard Worker             for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
224*35238bceSAndroid Build Coastguard Worker             {
225*35238bceSAndroid Build Coastguard Worker                 const tcu::Vec4 v_coord = rr::readVarying<float>(packets[packetNdx], context, 0, fragNdx);
226*35238bceSAndroid Build Coastguard Worker                 const float lod         = 0.0f;
227*35238bceSAndroid Build Coastguard Worker 
228*35238bceSAndroid Build Coastguard Worker                 rr::writeFragmentOutput(
229*35238bceSAndroid Build Coastguard Worker                     context, packetNdx, fragNdx, 0,
230*35238bceSAndroid Build Coastguard Worker                     this->m_uniforms[0].sampler.tex2D->sample(v_coord.x(), v_coord.y(), lod) * 0.5f +
231*35238bceSAndroid Build Coastguard Worker                         this->m_uniforms[1].sampler.tex2D->sample(v_coord.x(), v_coord.y(), lod) * 0.5f);
232*35238bceSAndroid Build Coastguard Worker             }
233*35238bceSAndroid Build Coastguard Worker     }
234*35238bceSAndroid Build Coastguard Worker };
235*35238bceSAndroid Build Coastguard Worker 
236*35238bceSAndroid Build Coastguard Worker // Framebuffer config.
237*35238bceSAndroid Build Coastguard Worker 
238*35238bceSAndroid Build Coastguard Worker class FboConfig
239*35238bceSAndroid Build Coastguard Worker {
240*35238bceSAndroid Build Coastguard Worker public:
FboConfig(void)241*35238bceSAndroid Build Coastguard Worker     FboConfig(void)
242*35238bceSAndroid Build Coastguard Worker         : colorbufferType(GL_NONE)
243*35238bceSAndroid Build Coastguard Worker         , colorbufferFormat(GL_NONE)
244*35238bceSAndroid Build Coastguard Worker         , depthbufferType(GL_NONE)
245*35238bceSAndroid Build Coastguard Worker         , depthbufferFormat(GL_NONE)
246*35238bceSAndroid Build Coastguard Worker         , stencilbufferType(GL_NONE)
247*35238bceSAndroid Build Coastguard Worker         , stencilbufferFormat(GL_NONE)
248*35238bceSAndroid Build Coastguard Worker     {
249*35238bceSAndroid Build Coastguard Worker     }
250*35238bceSAndroid Build Coastguard Worker 
251*35238bceSAndroid Build Coastguard Worker     std::string getName(void) const;
252*35238bceSAndroid Build Coastguard Worker 
253*35238bceSAndroid Build Coastguard Worker     GLenum colorbufferType;   //!< GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP, GL_RENDERBUFFER
254*35238bceSAndroid Build Coastguard Worker     GLenum colorbufferFormat; //!< Internal format for color buffer texture or renderbuffer
255*35238bceSAndroid Build Coastguard Worker 
256*35238bceSAndroid Build Coastguard Worker     GLenum depthbufferType; //!< GL_RENDERBUFFER
257*35238bceSAndroid Build Coastguard Worker     GLenum depthbufferFormat;
258*35238bceSAndroid Build Coastguard Worker 
259*35238bceSAndroid Build Coastguard Worker     GLenum stencilbufferType; //!< GL_RENDERBUFFER
260*35238bceSAndroid Build Coastguard Worker     GLenum stencilbufferFormat;
261*35238bceSAndroid Build Coastguard Worker 
262*35238bceSAndroid Build Coastguard Worker private:
263*35238bceSAndroid Build Coastguard Worker     static const char *getFormatName(GLenum format);
264*35238bceSAndroid Build Coastguard Worker };
265*35238bceSAndroid Build Coastguard Worker 
getFormatName(GLenum format)266*35238bceSAndroid Build Coastguard Worker const char *FboConfig::getFormatName(GLenum format)
267*35238bceSAndroid Build Coastguard Worker {
268*35238bceSAndroid Build Coastguard Worker     switch (format)
269*35238bceSAndroid Build Coastguard Worker     {
270*35238bceSAndroid Build Coastguard Worker     case GL_RGB:
271*35238bceSAndroid Build Coastguard Worker         return "rgb";
272*35238bceSAndroid Build Coastguard Worker     case GL_RGBA:
273*35238bceSAndroid Build Coastguard Worker         return "rgba";
274*35238bceSAndroid Build Coastguard Worker     case GL_ALPHA:
275*35238bceSAndroid Build Coastguard Worker         return "alpha";
276*35238bceSAndroid Build Coastguard Worker     case GL_LUMINANCE:
277*35238bceSAndroid Build Coastguard Worker         return "luminance";
278*35238bceSAndroid Build Coastguard Worker     case GL_LUMINANCE_ALPHA:
279*35238bceSAndroid Build Coastguard Worker         return "luminance_alpha";
280*35238bceSAndroid Build Coastguard Worker     case GL_RGB565:
281*35238bceSAndroid Build Coastguard Worker         return "rgb565";
282*35238bceSAndroid Build Coastguard Worker     case GL_RGB5_A1:
283*35238bceSAndroid Build Coastguard Worker         return "rgb5_a1";
284*35238bceSAndroid Build Coastguard Worker     case GL_RGBA4:
285*35238bceSAndroid Build Coastguard Worker         return "rgba4";
286*35238bceSAndroid Build Coastguard Worker     case GL_RGBA16F:
287*35238bceSAndroid Build Coastguard Worker         return "rgba16f";
288*35238bceSAndroid Build Coastguard Worker     case GL_RGB16F:
289*35238bceSAndroid Build Coastguard Worker         return "rgb16f";
290*35238bceSAndroid Build Coastguard Worker     case GL_DEPTH_COMPONENT16:
291*35238bceSAndroid Build Coastguard Worker         return "depth_component16";
292*35238bceSAndroid Build Coastguard Worker     case GL_STENCIL_INDEX8:
293*35238bceSAndroid Build Coastguard Worker         return "stencil_index8";
294*35238bceSAndroid Build Coastguard Worker     default:
295*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(false);
296*35238bceSAndroid Build Coastguard Worker         return DE_NULL;
297*35238bceSAndroid Build Coastguard Worker     }
298*35238bceSAndroid Build Coastguard Worker }
299*35238bceSAndroid Build Coastguard Worker 
getName(void) const300*35238bceSAndroid Build Coastguard Worker std::string FboConfig::getName(void) const
301*35238bceSAndroid Build Coastguard Worker {
302*35238bceSAndroid Build Coastguard Worker     std::string name = "";
303*35238bceSAndroid Build Coastguard Worker 
304*35238bceSAndroid Build Coastguard Worker     if (colorbufferType != GL_NONE)
305*35238bceSAndroid Build Coastguard Worker     {
306*35238bceSAndroid Build Coastguard Worker         switch (colorbufferType)
307*35238bceSAndroid Build Coastguard Worker         {
308*35238bceSAndroid Build Coastguard Worker         case GL_TEXTURE_2D:
309*35238bceSAndroid Build Coastguard Worker             name += "tex2d_";
310*35238bceSAndroid Build Coastguard Worker             break;
311*35238bceSAndroid Build Coastguard Worker         case GL_TEXTURE_CUBE_MAP:
312*35238bceSAndroid Build Coastguard Worker             name += "texcube_";
313*35238bceSAndroid Build Coastguard Worker             break;
314*35238bceSAndroid Build Coastguard Worker         case GL_RENDERBUFFER:
315*35238bceSAndroid Build Coastguard Worker             name += "rbo_";
316*35238bceSAndroid Build Coastguard Worker             break;
317*35238bceSAndroid Build Coastguard Worker         default:
318*35238bceSAndroid Build Coastguard Worker             DE_ASSERT(false);
319*35238bceSAndroid Build Coastguard Worker             break;
320*35238bceSAndroid Build Coastguard Worker         }
321*35238bceSAndroid Build Coastguard Worker         name += getFormatName(colorbufferFormat);
322*35238bceSAndroid Build Coastguard Worker     }
323*35238bceSAndroid Build Coastguard Worker 
324*35238bceSAndroid Build Coastguard Worker     if (depthbufferType != GL_NONE)
325*35238bceSAndroid Build Coastguard Worker     {
326*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(depthbufferType == GL_RENDERBUFFER);
327*35238bceSAndroid Build Coastguard Worker         if (name.length() > 0)
328*35238bceSAndroid Build Coastguard Worker             name += "_";
329*35238bceSAndroid Build Coastguard Worker         name += getFormatName(depthbufferFormat);
330*35238bceSAndroid Build Coastguard Worker     }
331*35238bceSAndroid Build Coastguard Worker 
332*35238bceSAndroid Build Coastguard Worker     if (stencilbufferType != GL_NONE)
333*35238bceSAndroid Build Coastguard Worker     {
334*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(stencilbufferType == GL_RENDERBUFFER);
335*35238bceSAndroid Build Coastguard Worker         if (name.length() > 0)
336*35238bceSAndroid Build Coastguard Worker             name += "_";
337*35238bceSAndroid Build Coastguard Worker         name += getFormatName(stencilbufferFormat);
338*35238bceSAndroid Build Coastguard Worker     }
339*35238bceSAndroid Build Coastguard Worker 
340*35238bceSAndroid Build Coastguard Worker     return name;
341*35238bceSAndroid Build Coastguard Worker }
342*35238bceSAndroid Build Coastguard Worker 
343*35238bceSAndroid Build Coastguard Worker class FboIncompleteException : public tcu::TestError
344*35238bceSAndroid Build Coastguard Worker {
345*35238bceSAndroid Build Coastguard Worker public:
346*35238bceSAndroid Build Coastguard Worker     FboIncompleteException(const FboConfig &config, GLenum reason, const char *file, int line);
~FboIncompleteException(void)347*35238bceSAndroid Build Coastguard Worker     virtual ~FboIncompleteException(void) throw()
348*35238bceSAndroid Build Coastguard Worker     {
349*35238bceSAndroid Build Coastguard Worker     }
350*35238bceSAndroid Build Coastguard Worker 
getConfig(void) const351*35238bceSAndroid Build Coastguard Worker     const FboConfig &getConfig(void) const
352*35238bceSAndroid Build Coastguard Worker     {
353*35238bceSAndroid Build Coastguard Worker         return m_config;
354*35238bceSAndroid Build Coastguard Worker     }
getReason(void) const355*35238bceSAndroid Build Coastguard Worker     GLenum getReason(void) const
356*35238bceSAndroid Build Coastguard Worker     {
357*35238bceSAndroid Build Coastguard Worker         return m_reason;
358*35238bceSAndroid Build Coastguard Worker     }
359*35238bceSAndroid Build Coastguard Worker 
360*35238bceSAndroid Build Coastguard Worker private:
361*35238bceSAndroid Build Coastguard Worker     FboConfig m_config;
362*35238bceSAndroid Build Coastguard Worker     GLenum m_reason;
363*35238bceSAndroid Build Coastguard Worker };
364*35238bceSAndroid Build Coastguard Worker 
getFboIncompleteReasonName(GLenum reason)365*35238bceSAndroid Build Coastguard Worker static const char *getFboIncompleteReasonName(GLenum reason)
366*35238bceSAndroid Build Coastguard Worker {
367*35238bceSAndroid Build Coastguard Worker     switch (reason)
368*35238bceSAndroid Build Coastguard Worker     {
369*35238bceSAndroid Build Coastguard Worker     case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
370*35238bceSAndroid Build Coastguard Worker         return "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT";
371*35238bceSAndroid Build Coastguard Worker     case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
372*35238bceSAndroid Build Coastguard Worker         return "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";
373*35238bceSAndroid Build Coastguard Worker     case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
374*35238bceSAndroid Build Coastguard Worker         return "GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS";
375*35238bceSAndroid Build Coastguard Worker     case GL_FRAMEBUFFER_UNSUPPORTED:
376*35238bceSAndroid Build Coastguard Worker         return "GL_FRAMEBUFFER_UNSUPPORTED";
377*35238bceSAndroid Build Coastguard Worker     case GL_FRAMEBUFFER_COMPLETE:
378*35238bceSAndroid Build Coastguard Worker         return "GL_FRAMEBUFFER_COMPLETE";
379*35238bceSAndroid Build Coastguard Worker     default:
380*35238bceSAndroid Build Coastguard Worker         return "UNKNOWN";
381*35238bceSAndroid Build Coastguard Worker     }
382*35238bceSAndroid Build Coastguard Worker }
383*35238bceSAndroid Build Coastguard Worker 
FboIncompleteException(const FboConfig & config,GLenum reason,const char * file,int line)384*35238bceSAndroid Build Coastguard Worker FboIncompleteException::FboIncompleteException(const FboConfig &config, GLenum reason, const char *file, int line)
385*35238bceSAndroid Build Coastguard Worker     : TestError("Framebuffer is not complete", getFboIncompleteReasonName(reason), file, line)
386*35238bceSAndroid Build Coastguard Worker     , m_config(config)
387*35238bceSAndroid Build Coastguard Worker     , m_reason(reason)
388*35238bceSAndroid Build Coastguard Worker {
389*35238bceSAndroid Build Coastguard Worker }
390*35238bceSAndroid Build Coastguard Worker 
391*35238bceSAndroid Build Coastguard Worker class Framebuffer
392*35238bceSAndroid Build Coastguard Worker {
393*35238bceSAndroid Build Coastguard Worker public:
394*35238bceSAndroid Build Coastguard Worker     Framebuffer(sglr::Context &context, const FboConfig &config, int width, int height, uint32_t fbo = 0,
395*35238bceSAndroid Build Coastguard Worker                 uint32_t colorbuffer = 0, uint32_t depthbuffer = 0, uint32_t stencilbuffer = 0);
396*35238bceSAndroid Build Coastguard Worker     ~Framebuffer(void);
397*35238bceSAndroid Build Coastguard Worker 
getConfig(void) const398*35238bceSAndroid Build Coastguard Worker     const FboConfig &getConfig(void) const
399*35238bceSAndroid Build Coastguard Worker     {
400*35238bceSAndroid Build Coastguard Worker         return m_config;
401*35238bceSAndroid Build Coastguard Worker     }
getFramebuffer(void) const402*35238bceSAndroid Build Coastguard Worker     uint32_t getFramebuffer(void) const
403*35238bceSAndroid Build Coastguard Worker     {
404*35238bceSAndroid Build Coastguard Worker         return m_framebuffer;
405*35238bceSAndroid Build Coastguard Worker     }
getColorbuffer(void) const406*35238bceSAndroid Build Coastguard Worker     uint32_t getColorbuffer(void) const
407*35238bceSAndroid Build Coastguard Worker     {
408*35238bceSAndroid Build Coastguard Worker         return m_colorbuffer;
409*35238bceSAndroid Build Coastguard Worker     }
getDepthbuffer(void) const410*35238bceSAndroid Build Coastguard Worker     uint32_t getDepthbuffer(void) const
411*35238bceSAndroid Build Coastguard Worker     {
412*35238bceSAndroid Build Coastguard Worker         return m_depthbuffer;
413*35238bceSAndroid Build Coastguard Worker     }
getStencilbuffer(void) const414*35238bceSAndroid Build Coastguard Worker     uint32_t getStencilbuffer(void) const
415*35238bceSAndroid Build Coastguard Worker     {
416*35238bceSAndroid Build Coastguard Worker         return m_stencilbuffer;
417*35238bceSAndroid Build Coastguard Worker     }
418*35238bceSAndroid Build Coastguard Worker 
419*35238bceSAndroid Build Coastguard Worker     void checkCompleteness(void);
420*35238bceSAndroid Build Coastguard Worker 
421*35238bceSAndroid Build Coastguard Worker private:
422*35238bceSAndroid Build Coastguard Worker     void createRbo(uint32_t &name, GLenum format, int width, int height);
423*35238bceSAndroid Build Coastguard Worker     void destroyBuffer(uint32_t name, GLenum type);
424*35238bceSAndroid Build Coastguard Worker 
425*35238bceSAndroid Build Coastguard Worker     FboConfig m_config;
426*35238bceSAndroid Build Coastguard Worker     sglr::Context &m_context;
427*35238bceSAndroid Build Coastguard Worker     uint32_t m_framebuffer;
428*35238bceSAndroid Build Coastguard Worker     uint32_t m_colorbuffer;
429*35238bceSAndroid Build Coastguard Worker     uint32_t m_depthbuffer;
430*35238bceSAndroid Build Coastguard Worker     uint32_t m_stencilbuffer;
431*35238bceSAndroid Build Coastguard Worker };
432*35238bceSAndroid Build Coastguard Worker 
isExtensionSupported(sglr::Context & context,const char * name)433*35238bceSAndroid Build Coastguard Worker static bool isExtensionSupported(sglr::Context &context, const char *name)
434*35238bceSAndroid Build Coastguard Worker {
435*35238bceSAndroid Build Coastguard Worker     std::istringstream extensions(context.getString(GL_EXTENSIONS));
436*35238bceSAndroid Build Coastguard Worker     std::string extension;
437*35238bceSAndroid Build Coastguard Worker 
438*35238bceSAndroid Build Coastguard Worker     while (std::getline(extensions, extension, ' '))
439*35238bceSAndroid Build Coastguard Worker     {
440*35238bceSAndroid Build Coastguard Worker         if (extension == name)
441*35238bceSAndroid Build Coastguard Worker             return true;
442*35238bceSAndroid Build Coastguard Worker     }
443*35238bceSAndroid Build Coastguard Worker 
444*35238bceSAndroid Build Coastguard Worker     return false;
445*35238bceSAndroid Build Coastguard Worker }
446*35238bceSAndroid Build Coastguard Worker 
checkColorFormatSupport(sglr::Context & context,uint32_t sizedFormat)447*35238bceSAndroid Build Coastguard Worker static void checkColorFormatSupport(sglr::Context &context, uint32_t sizedFormat)
448*35238bceSAndroid Build Coastguard Worker {
449*35238bceSAndroid Build Coastguard Worker     switch (sizedFormat)
450*35238bceSAndroid Build Coastguard Worker     {
451*35238bceSAndroid Build Coastguard Worker     case GL_RGBA16F:
452*35238bceSAndroid Build Coastguard Worker     case GL_RGB16F:
453*35238bceSAndroid Build Coastguard Worker     case GL_RG16F:
454*35238bceSAndroid Build Coastguard Worker     case GL_R16F:
455*35238bceSAndroid Build Coastguard Worker         if (!isExtensionSupported(context, "GL_EXT_color_buffer_half_float"))
456*35238bceSAndroid Build Coastguard Worker             throw tcu::NotSupportedError("GL_EXT_color_buffer_half_float is not supported");
457*35238bceSAndroid Build Coastguard Worker 
458*35238bceSAndroid Build Coastguard Worker     default:
459*35238bceSAndroid Build Coastguard Worker         break;
460*35238bceSAndroid Build Coastguard Worker     }
461*35238bceSAndroid Build Coastguard Worker }
462*35238bceSAndroid Build Coastguard Worker 
Framebuffer(sglr::Context & context,const FboConfig & config,int width,int height,uint32_t fbo,uint32_t colorbuffer,uint32_t depthbuffer,uint32_t stencilbuffer)463*35238bceSAndroid Build Coastguard Worker Framebuffer::Framebuffer(sglr::Context &context, const FboConfig &config, int width, int height, uint32_t fbo,
464*35238bceSAndroid Build Coastguard Worker                          uint32_t colorbuffer, uint32_t depthbuffer, uint32_t stencilbuffer)
465*35238bceSAndroid Build Coastguard Worker     : m_config(config)
466*35238bceSAndroid Build Coastguard Worker     , m_context(context)
467*35238bceSAndroid Build Coastguard Worker     , m_framebuffer(fbo)
468*35238bceSAndroid Build Coastguard Worker     , m_colorbuffer(colorbuffer)
469*35238bceSAndroid Build Coastguard Worker     , m_depthbuffer(depthbuffer)
470*35238bceSAndroid Build Coastguard Worker     , m_stencilbuffer(stencilbuffer)
471*35238bceSAndroid Build Coastguard Worker {
472*35238bceSAndroid Build Coastguard Worker     // Verify that color format is supported
473*35238bceSAndroid Build Coastguard Worker     checkColorFormatSupport(context, config.colorbufferFormat);
474*35238bceSAndroid Build Coastguard Worker 
475*35238bceSAndroid Build Coastguard Worker     if (m_framebuffer == 0)
476*35238bceSAndroid Build Coastguard Worker         context.genFramebuffers(1, &m_framebuffer);
477*35238bceSAndroid Build Coastguard Worker     context.bindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
478*35238bceSAndroid Build Coastguard Worker 
479*35238bceSAndroid Build Coastguard Worker     switch (m_config.colorbufferType)
480*35238bceSAndroid Build Coastguard Worker     {
481*35238bceSAndroid Build Coastguard Worker     case GL_TEXTURE_2D:
482*35238bceSAndroid Build Coastguard Worker         if (m_colorbuffer == 0)
483*35238bceSAndroid Build Coastguard Worker             context.genTextures(1, &m_colorbuffer);
484*35238bceSAndroid Build Coastguard Worker         context.bindTexture(GL_TEXTURE_2D, m_colorbuffer);
485*35238bceSAndroid Build Coastguard Worker         context.texImage2D(GL_TEXTURE_2D, 0, m_config.colorbufferFormat, width, height);
486*35238bceSAndroid Build Coastguard Worker         context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
487*35238bceSAndroid Build Coastguard Worker 
488*35238bceSAndroid Build Coastguard Worker         if (!deIsPowerOfTwo32(width) || !deIsPowerOfTwo32(height))
489*35238bceSAndroid Build Coastguard Worker         {
490*35238bceSAndroid Build Coastguard Worker             // Set wrap mode to clamp for NPOT FBOs
491*35238bceSAndroid Build Coastguard Worker             context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
492*35238bceSAndroid Build Coastguard Worker             context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
493*35238bceSAndroid Build Coastguard Worker         }
494*35238bceSAndroid Build Coastguard Worker 
495*35238bceSAndroid Build Coastguard Worker         context.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_colorbuffer, 0);
496*35238bceSAndroid Build Coastguard Worker         break;
497*35238bceSAndroid Build Coastguard Worker 
498*35238bceSAndroid Build Coastguard Worker     case GL_TEXTURE_CUBE_MAP:
499*35238bceSAndroid Build Coastguard Worker         DE_FATAL("TODO");
500*35238bceSAndroid Build Coastguard Worker         break;
501*35238bceSAndroid Build Coastguard Worker 
502*35238bceSAndroid Build Coastguard Worker     case GL_RENDERBUFFER:
503*35238bceSAndroid Build Coastguard Worker         createRbo(m_colorbuffer, m_config.colorbufferFormat, width, height);
504*35238bceSAndroid Build Coastguard Worker         context.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_colorbuffer);
505*35238bceSAndroid Build Coastguard Worker         break;
506*35238bceSAndroid Build Coastguard Worker 
507*35238bceSAndroid Build Coastguard Worker     default:
508*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(m_config.colorbufferType == GL_NONE);
509*35238bceSAndroid Build Coastguard Worker         break;
510*35238bceSAndroid Build Coastguard Worker     }
511*35238bceSAndroid Build Coastguard Worker 
512*35238bceSAndroid Build Coastguard Worker     if (m_config.depthbufferType == GL_RENDERBUFFER)
513*35238bceSAndroid Build Coastguard Worker     {
514*35238bceSAndroid Build Coastguard Worker         createRbo(m_depthbuffer, m_config.depthbufferFormat, width, height);
515*35238bceSAndroid Build Coastguard Worker         context.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthbuffer);
516*35238bceSAndroid Build Coastguard Worker     }
517*35238bceSAndroid Build Coastguard Worker     else
518*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(m_config.depthbufferType == GL_NONE);
519*35238bceSAndroid Build Coastguard Worker 
520*35238bceSAndroid Build Coastguard Worker     if (m_config.stencilbufferType == GL_RENDERBUFFER)
521*35238bceSAndroid Build Coastguard Worker     {
522*35238bceSAndroid Build Coastguard Worker         createRbo(m_stencilbuffer, m_config.stencilbufferFormat, width, height);
523*35238bceSAndroid Build Coastguard Worker         context.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_stencilbuffer);
524*35238bceSAndroid Build Coastguard Worker     }
525*35238bceSAndroid Build Coastguard Worker     else
526*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(m_config.stencilbufferType == GL_NONE);
527*35238bceSAndroid Build Coastguard Worker 
528*35238bceSAndroid Build Coastguard Worker     context.bindFramebuffer(GL_FRAMEBUFFER, 0);
529*35238bceSAndroid Build Coastguard Worker }
530*35238bceSAndroid Build Coastguard Worker 
~Framebuffer(void)531*35238bceSAndroid Build Coastguard Worker Framebuffer::~Framebuffer(void)
532*35238bceSAndroid Build Coastguard Worker {
533*35238bceSAndroid Build Coastguard Worker     m_context.deleteFramebuffers(1, &m_framebuffer);
534*35238bceSAndroid Build Coastguard Worker     destroyBuffer(m_colorbuffer, m_config.colorbufferType);
535*35238bceSAndroid Build Coastguard Worker     destroyBuffer(m_depthbuffer, m_config.depthbufferType);
536*35238bceSAndroid Build Coastguard Worker     destroyBuffer(m_stencilbuffer, m_config.stencilbufferType);
537*35238bceSAndroid Build Coastguard Worker }
538*35238bceSAndroid Build Coastguard Worker 
checkCompleteness(void)539*35238bceSAndroid Build Coastguard Worker void Framebuffer::checkCompleteness(void)
540*35238bceSAndroid Build Coastguard Worker {
541*35238bceSAndroid Build Coastguard Worker     m_context.bindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
542*35238bceSAndroid Build Coastguard Worker     GLenum status = m_context.checkFramebufferStatus(GL_FRAMEBUFFER);
543*35238bceSAndroid Build Coastguard Worker     m_context.bindFramebuffer(GL_FRAMEBUFFER, 0);
544*35238bceSAndroid Build Coastguard Worker     if (status != GL_FRAMEBUFFER_COMPLETE)
545*35238bceSAndroid Build Coastguard Worker         throw FboIncompleteException(m_config, status, __FILE__, __LINE__);
546*35238bceSAndroid Build Coastguard Worker }
547*35238bceSAndroid Build Coastguard Worker 
createRbo(uint32_t & name,GLenum format,int width,int height)548*35238bceSAndroid Build Coastguard Worker void Framebuffer::createRbo(uint32_t &name, GLenum format, int width, int height)
549*35238bceSAndroid Build Coastguard Worker {
550*35238bceSAndroid Build Coastguard Worker     if (name == 0)
551*35238bceSAndroid Build Coastguard Worker         m_context.genRenderbuffers(1, &name);
552*35238bceSAndroid Build Coastguard Worker     m_context.bindRenderbuffer(GL_RENDERBUFFER, name);
553*35238bceSAndroid Build Coastguard Worker     m_context.renderbufferStorage(GL_RENDERBUFFER, format, width, height);
554*35238bceSAndroid Build Coastguard Worker }
555*35238bceSAndroid Build Coastguard Worker 
destroyBuffer(uint32_t name,GLenum type)556*35238bceSAndroid Build Coastguard Worker void Framebuffer::destroyBuffer(uint32_t name, GLenum type)
557*35238bceSAndroid Build Coastguard Worker {
558*35238bceSAndroid Build Coastguard Worker     if (type == GL_TEXTURE_2D || type == GL_TEXTURE_CUBE_MAP)
559*35238bceSAndroid Build Coastguard Worker         m_context.deleteTextures(1, &name);
560*35238bceSAndroid Build Coastguard Worker     else if (type == GL_RENDERBUFFER)
561*35238bceSAndroid Build Coastguard Worker         m_context.deleteRenderbuffers(1, &name);
562*35238bceSAndroid Build Coastguard Worker     else
563*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(type == GL_NONE);
564*35238bceSAndroid Build Coastguard Worker }
565*35238bceSAndroid Build Coastguard Worker 
createMetaballsTex2D(sglr::Context & context,uint32_t name,GLenum format,GLenum dataType,int width,int height)566*35238bceSAndroid Build Coastguard Worker static void createMetaballsTex2D(sglr::Context &context, uint32_t name, GLenum format, GLenum dataType, int width,
567*35238bceSAndroid Build Coastguard Worker                                  int height)
568*35238bceSAndroid Build Coastguard Worker {
569*35238bceSAndroid Build Coastguard Worker     tcu::TextureFormat texFormat = glu::mapGLTransferFormat(format, dataType);
570*35238bceSAndroid Build Coastguard Worker     tcu::TextureLevel level(texFormat, width, height);
571*35238bceSAndroid Build Coastguard Worker 
572*35238bceSAndroid Build Coastguard Worker     tcu::fillWithMetaballs(level.getAccess(), 5, name ^ width ^ height);
573*35238bceSAndroid Build Coastguard Worker 
574*35238bceSAndroid Build Coastguard Worker     context.bindTexture(GL_TEXTURE_2D, name);
575*35238bceSAndroid Build Coastguard Worker     context.texImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, dataType, level.getAccess().getDataPtr());
576*35238bceSAndroid Build Coastguard Worker     context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
577*35238bceSAndroid Build Coastguard Worker }
578*35238bceSAndroid Build Coastguard Worker 
createQuadsTex2D(sglr::Context & context,uint32_t name,GLenum format,GLenum dataType,int width,int height)579*35238bceSAndroid Build Coastguard Worker static void createQuadsTex2D(sglr::Context &context, uint32_t name, GLenum format, GLenum dataType, int width,
580*35238bceSAndroid Build Coastguard Worker                              int height)
581*35238bceSAndroid Build Coastguard Worker {
582*35238bceSAndroid Build Coastguard Worker     tcu::TextureFormat texFormat = glu::mapGLTransferFormat(format, dataType);
583*35238bceSAndroid Build Coastguard Worker     tcu::TextureLevel level(texFormat, width, height);
584*35238bceSAndroid Build Coastguard Worker 
585*35238bceSAndroid Build Coastguard Worker     tcu::fillWithRGBAQuads(level.getAccess());
586*35238bceSAndroid Build Coastguard Worker 
587*35238bceSAndroid Build Coastguard Worker     context.bindTexture(GL_TEXTURE_2D, name);
588*35238bceSAndroid Build Coastguard Worker     context.texImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, dataType, level.getAccess().getDataPtr());
589*35238bceSAndroid Build Coastguard Worker     context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
590*35238bceSAndroid Build Coastguard Worker }
591*35238bceSAndroid Build Coastguard Worker 
592*35238bceSAndroid Build Coastguard Worker class FboRenderCase : public TestCase
593*35238bceSAndroid Build Coastguard Worker {
594*35238bceSAndroid Build Coastguard Worker public:
595*35238bceSAndroid Build Coastguard Worker     FboRenderCase(Context &context, const char *name, const char *description, const FboConfig &config);
~FboRenderCase(void)596*35238bceSAndroid Build Coastguard Worker     virtual ~FboRenderCase(void)
597*35238bceSAndroid Build Coastguard Worker     {
598*35238bceSAndroid Build Coastguard Worker     }
599*35238bceSAndroid Build Coastguard Worker 
600*35238bceSAndroid Build Coastguard Worker     virtual IterateResult iterate(void);
601*35238bceSAndroid Build Coastguard Worker     virtual void render(sglr::Context &fboContext, Surface &dst) = DE_NULL;
602*35238bceSAndroid Build Coastguard Worker 
getConfig(void) const603*35238bceSAndroid Build Coastguard Worker     const FboConfig &getConfig(void) const
604*35238bceSAndroid Build Coastguard Worker     {
605*35238bceSAndroid Build Coastguard Worker         return m_config;
606*35238bceSAndroid Build Coastguard Worker     }
607*35238bceSAndroid Build Coastguard Worker 
isConfigSupported(const FboConfig & config)608*35238bceSAndroid Build Coastguard Worker     static bool isConfigSupported(const FboConfig &config)
609*35238bceSAndroid Build Coastguard Worker     {
610*35238bceSAndroid Build Coastguard Worker         DE_UNREF(config);
611*35238bceSAndroid Build Coastguard Worker         return true;
612*35238bceSAndroid Build Coastguard Worker     }
613*35238bceSAndroid Build Coastguard Worker 
614*35238bceSAndroid Build Coastguard Worker private:
615*35238bceSAndroid Build Coastguard Worker     FboConfig m_config;
616*35238bceSAndroid Build Coastguard Worker };
617*35238bceSAndroid Build Coastguard Worker 
FboRenderCase(Context & context,const char * name,const char * description,const FboConfig & config)618*35238bceSAndroid Build Coastguard Worker FboRenderCase::FboRenderCase(Context &context, const char *name, const char *description, const FboConfig &config)
619*35238bceSAndroid Build Coastguard Worker     : TestCase(context, name, description)
620*35238bceSAndroid Build Coastguard Worker     , m_config(config)
621*35238bceSAndroid Build Coastguard Worker {
622*35238bceSAndroid Build Coastguard Worker }
623*35238bceSAndroid Build Coastguard Worker 
iterate(void)624*35238bceSAndroid Build Coastguard Worker TestCase::IterateResult FboRenderCase::iterate(void)
625*35238bceSAndroid Build Coastguard Worker {
626*35238bceSAndroid Build Coastguard Worker     Vec4 clearColor(0.125f, 0.25f, 0.5f, 1.0f);
627*35238bceSAndroid Build Coastguard Worker     glu::RenderContext &renderCtx         = m_context.getRenderContext();
628*35238bceSAndroid Build Coastguard Worker     const tcu::RenderTarget &renderTarget = m_context.getRenderTarget();
629*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log                     = m_testCtx.getLog();
630*35238bceSAndroid Build Coastguard Worker     const char *failReason                = DE_NULL;
631*35238bceSAndroid Build Coastguard Worker 
632*35238bceSAndroid Build Coastguard Worker     // Position & size for context
633*35238bceSAndroid Build Coastguard Worker     deRandom rnd;
634*35238bceSAndroid Build Coastguard Worker     deRandom_init(&rnd, deStringHash(getName()));
635*35238bceSAndroid Build Coastguard Worker 
636*35238bceSAndroid Build Coastguard Worker     int width  = deMin32(renderTarget.getWidth(), 128);
637*35238bceSAndroid Build Coastguard Worker     int height = deMin32(renderTarget.getHeight(), 128);
638*35238bceSAndroid Build Coastguard Worker     int xMax   = renderTarget.getWidth() - width + 1;
639*35238bceSAndroid Build Coastguard Worker     int yMax   = renderTarget.getHeight() - height + 1;
640*35238bceSAndroid Build Coastguard Worker     int x      = deRandom_getUint32(&rnd) % xMax;
641*35238bceSAndroid Build Coastguard Worker     int y      = deRandom_getUint32(&rnd) % yMax;
642*35238bceSAndroid Build Coastguard Worker 
643*35238bceSAndroid Build Coastguard Worker     tcu::Surface gles2Frame(width, height);
644*35238bceSAndroid Build Coastguard Worker     tcu::Surface refFrame(width, height);
645*35238bceSAndroid Build Coastguard Worker     GLenum gles2Error;
646*35238bceSAndroid Build Coastguard Worker     GLenum refError;
647*35238bceSAndroid Build Coastguard Worker 
648*35238bceSAndroid Build Coastguard Worker     // Render using GLES2
649*35238bceSAndroid Build Coastguard Worker     try
650*35238bceSAndroid Build Coastguard Worker     {
651*35238bceSAndroid Build Coastguard Worker         sglr::GLContext context(renderCtx, log, sglr::GLCONTEXT_LOG_CALLS, tcu::IVec4(x, y, width, height));
652*35238bceSAndroid Build Coastguard Worker 
653*35238bceSAndroid Build Coastguard Worker         context.clearColor(clearColor.x(), clearColor.y(), clearColor.z(), clearColor.w());
654*35238bceSAndroid Build Coastguard Worker         context.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
655*35238bceSAndroid Build Coastguard Worker 
656*35238bceSAndroid Build Coastguard Worker         render(context, gles2Frame); // Call actual render func
657*35238bceSAndroid Build Coastguard Worker         gles2Error = context.getError();
658*35238bceSAndroid Build Coastguard Worker     }
659*35238bceSAndroid Build Coastguard Worker     catch (const FboIncompleteException &e)
660*35238bceSAndroid Build Coastguard Worker     {
661*35238bceSAndroid Build Coastguard Worker         if (e.getReason() == GL_FRAMEBUFFER_UNSUPPORTED)
662*35238bceSAndroid Build Coastguard Worker         {
663*35238bceSAndroid Build Coastguard Worker             // Mark test case as unsupported
664*35238bceSAndroid Build Coastguard Worker             log << e;
665*35238bceSAndroid Build Coastguard Worker             m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not supported");
666*35238bceSAndroid Build Coastguard Worker             return STOP;
667*35238bceSAndroid Build Coastguard Worker         }
668*35238bceSAndroid Build Coastguard Worker         else
669*35238bceSAndroid Build Coastguard Worker             throw; // Propagate error
670*35238bceSAndroid Build Coastguard Worker     }
671*35238bceSAndroid Build Coastguard Worker 
672*35238bceSAndroid Build Coastguard Worker     // Render reference image
673*35238bceSAndroid Build Coastguard Worker     {
674*35238bceSAndroid Build Coastguard Worker         sglr::ReferenceContextBuffers buffers(
675*35238bceSAndroid Build Coastguard Worker             tcu::PixelFormat(8, 8, 8, renderTarget.getPixelFormat().alphaBits ? 8 : 0), renderTarget.getDepthBits(),
676*35238bceSAndroid Build Coastguard Worker             renderTarget.getStencilBits(), width, height);
677*35238bceSAndroid Build Coastguard Worker         sglr::ReferenceContext context(sglr::ReferenceContextLimits(renderCtx), buffers.getColorbuffer(),
678*35238bceSAndroid Build Coastguard Worker                                        buffers.getDepthbuffer(), buffers.getStencilbuffer());
679*35238bceSAndroid Build Coastguard Worker 
680*35238bceSAndroid Build Coastguard Worker         context.clearColor(clearColor.x(), clearColor.y(), clearColor.z(), clearColor.w());
681*35238bceSAndroid Build Coastguard Worker         context.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
682*35238bceSAndroid Build Coastguard Worker 
683*35238bceSAndroid Build Coastguard Worker         render(context, refFrame);
684*35238bceSAndroid Build Coastguard Worker         refError = context.getError();
685*35238bceSAndroid Build Coastguard Worker     }
686*35238bceSAndroid Build Coastguard Worker 
687*35238bceSAndroid Build Coastguard Worker     // Compare error codes
688*35238bceSAndroid Build Coastguard Worker     bool errorCodesOk = (gles2Error == refError);
689*35238bceSAndroid Build Coastguard Worker 
690*35238bceSAndroid Build Coastguard Worker     if (!errorCodesOk)
691*35238bceSAndroid Build Coastguard Worker     {
692*35238bceSAndroid Build Coastguard Worker         log << tcu::TestLog::Message << "Error code mismatch: got " << glu::getErrorStr(gles2Error) << ", expected "
693*35238bceSAndroid Build Coastguard Worker             << glu::getErrorStr(refError) << tcu::TestLog::EndMessage;
694*35238bceSAndroid Build Coastguard Worker         failReason = "Got unexpected error";
695*35238bceSAndroid Build Coastguard Worker     }
696*35238bceSAndroid Build Coastguard Worker 
697*35238bceSAndroid Build Coastguard Worker     // Compare images
698*35238bceSAndroid Build Coastguard Worker     const float threshold = 0.05f;
699*35238bceSAndroid Build Coastguard Worker     bool imagesOk         = tcu::fuzzyCompare(log, "ComparisonResult", "Image comparison result", refFrame, gles2Frame,
700*35238bceSAndroid Build Coastguard Worker                                               threshold, tcu::COMPARE_LOG_RESULT);
701*35238bceSAndroid Build Coastguard Worker 
702*35238bceSAndroid Build Coastguard Worker     if (!imagesOk && !failReason)
703*35238bceSAndroid Build Coastguard Worker         failReason = "Image comparison failed";
704*35238bceSAndroid Build Coastguard Worker 
705*35238bceSAndroid Build Coastguard Worker     // Store test result
706*35238bceSAndroid Build Coastguard Worker     bool isOk = errorCodesOk && imagesOk;
707*35238bceSAndroid Build Coastguard Worker     m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL, isOk ? "Pass" : failReason);
708*35238bceSAndroid Build Coastguard Worker 
709*35238bceSAndroid Build Coastguard Worker     return STOP;
710*35238bceSAndroid Build Coastguard Worker }
711*35238bceSAndroid Build Coastguard Worker 
712*35238bceSAndroid Build Coastguard Worker namespace FboCases
713*35238bceSAndroid Build Coastguard Worker {
714*35238bceSAndroid Build Coastguard Worker 
715*35238bceSAndroid Build Coastguard Worker class ColorClearsTest : public FboRenderCase
716*35238bceSAndroid Build Coastguard Worker {
717*35238bceSAndroid Build Coastguard Worker public:
718*35238bceSAndroid Build Coastguard Worker     ColorClearsTest(Context &context, const FboConfig &config);
~ColorClearsTest(void)719*35238bceSAndroid Build Coastguard Worker     ~ColorClearsTest(void)
720*35238bceSAndroid Build Coastguard Worker     {
721*35238bceSAndroid Build Coastguard Worker     }
722*35238bceSAndroid Build Coastguard Worker 
723*35238bceSAndroid Build Coastguard Worker     void render(sglr::Context &context, Surface &dst);
724*35238bceSAndroid Build Coastguard Worker };
725*35238bceSAndroid Build Coastguard Worker 
ColorClearsTest(Context & context,const FboConfig & config)726*35238bceSAndroid Build Coastguard Worker ColorClearsTest::ColorClearsTest(Context &context, const FboConfig &config)
727*35238bceSAndroid Build Coastguard Worker     : FboRenderCase(context, config.getName().c_str(), "Color buffer clears", config)
728*35238bceSAndroid Build Coastguard Worker {
729*35238bceSAndroid Build Coastguard Worker }
730*35238bceSAndroid Build Coastguard Worker 
render(sglr::Context & context,Surface & dst)731*35238bceSAndroid Build Coastguard Worker void ColorClearsTest::render(sglr::Context &context, Surface &dst)
732*35238bceSAndroid Build Coastguard Worker {
733*35238bceSAndroid Build Coastguard Worker     int width  = 128;
734*35238bceSAndroid Build Coastguard Worker     int height = 128;
735*35238bceSAndroid Build Coastguard Worker     deRandom rnd;
736*35238bceSAndroid Build Coastguard Worker 
737*35238bceSAndroid Build Coastguard Worker     deRandom_init(&rnd, 0);
738*35238bceSAndroid Build Coastguard Worker 
739*35238bceSAndroid Build Coastguard Worker     // Create framebuffer
740*35238bceSAndroid Build Coastguard Worker     Framebuffer fbo(context, getConfig(), width, height);
741*35238bceSAndroid Build Coastguard Worker     fbo.checkCompleteness();
742*35238bceSAndroid Build Coastguard Worker 
743*35238bceSAndroid Build Coastguard Worker     // Clear fbo
744*35238bceSAndroid Build Coastguard Worker     context.bindFramebuffer(GL_FRAMEBUFFER, fbo.getFramebuffer());
745*35238bceSAndroid Build Coastguard Worker     context.viewport(0, 0, width, height);
746*35238bceSAndroid Build Coastguard Worker     context.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
747*35238bceSAndroid Build Coastguard Worker     context.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
748*35238bceSAndroid Build Coastguard Worker 
749*35238bceSAndroid Build Coastguard Worker     // Enable scissor test.
750*35238bceSAndroid Build Coastguard Worker     context.enable(GL_SCISSOR_TEST);
751*35238bceSAndroid Build Coastguard Worker 
752*35238bceSAndroid Build Coastguard Worker     // Do 10 random color clears
753*35238bceSAndroid Build Coastguard Worker     for (int i = 0; i < 15; i++)
754*35238bceSAndroid Build Coastguard Worker     {
755*35238bceSAndroid Build Coastguard Worker         int cX      = (int)(deRandom_getUint32(&rnd) & 0x7fffffff) % width;
756*35238bceSAndroid Build Coastguard Worker         int cY      = (int)(deRandom_getUint32(&rnd) & 0x7fffffff) % height;
757*35238bceSAndroid Build Coastguard Worker         int cWidth  = (int)(deRandom_getUint32(&rnd) & 0x7fffffff) % (width - cX);
758*35238bceSAndroid Build Coastguard Worker         int cHeight = (int)(deRandom_getUint32(&rnd) & 0x7fffffff) % (height - cY);
759*35238bceSAndroid Build Coastguard Worker         Vec4 color  = RGBA(deRandom_getUint32(&rnd)).toVec();
760*35238bceSAndroid Build Coastguard Worker 
761*35238bceSAndroid Build Coastguard Worker         context.scissor(cX, cY, cWidth, cHeight);
762*35238bceSAndroid Build Coastguard Worker         context.clearColor(color.x(), color.y(), color.z(), color.w());
763*35238bceSAndroid Build Coastguard Worker         context.clear(GL_COLOR_BUFFER_BIT);
764*35238bceSAndroid Build Coastguard Worker     }
765*35238bceSAndroid Build Coastguard Worker 
766*35238bceSAndroid Build Coastguard Worker     // Disable scissor.
767*35238bceSAndroid Build Coastguard Worker     context.disable(GL_SCISSOR_TEST);
768*35238bceSAndroid Build Coastguard Worker 
769*35238bceSAndroid Build Coastguard Worker     if (fbo.getConfig().colorbufferType == GL_TEXTURE_2D)
770*35238bceSAndroid Build Coastguard Worker     {
771*35238bceSAndroid Build Coastguard Worker         // Unbind fbo
772*35238bceSAndroid Build Coastguard Worker         context.bindFramebuffer(GL_FRAMEBUFFER, 0);
773*35238bceSAndroid Build Coastguard Worker 
774*35238bceSAndroid Build Coastguard Worker         // Draw to screen
775*35238bceSAndroid Build Coastguard Worker         SingleTex2DShader shader;
776*35238bceSAndroid Build Coastguard Worker         uint32_t shaderID = context.createProgram(&shader);
777*35238bceSAndroid Build Coastguard Worker 
778*35238bceSAndroid Build Coastguard Worker         shader.setUnit(context, shaderID, 0);
779*35238bceSAndroid Build Coastguard Worker 
780*35238bceSAndroid Build Coastguard Worker         context.bindTexture(GL_TEXTURE_2D, fbo.getColorbuffer());
781*35238bceSAndroid Build Coastguard Worker         context.viewport(0, 0, context.getWidth(), context.getHeight());
782*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(context, shaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
783*35238bceSAndroid Build Coastguard Worker 
784*35238bceSAndroid Build Coastguard Worker         // Read from screen
785*35238bceSAndroid Build Coastguard Worker         context.readPixels(dst, 0, 0, context.getWidth(), context.getHeight());
786*35238bceSAndroid Build Coastguard Worker     }
787*35238bceSAndroid Build Coastguard Worker     else
788*35238bceSAndroid Build Coastguard Worker     {
789*35238bceSAndroid Build Coastguard Worker         // clear alpha channel for GL_RGB5_A1 format because test
790*35238bceSAndroid Build Coastguard Worker         // thresholds for the alpha channel do not account for dithering
791*35238bceSAndroid Build Coastguard Worker         if (getConfig().colorbufferFormat == GL_RGB5_A1)
792*35238bceSAndroid Build Coastguard Worker         {
793*35238bceSAndroid Build Coastguard Worker             context.colorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);
794*35238bceSAndroid Build Coastguard Worker             context.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
795*35238bceSAndroid Build Coastguard Worker             context.clear(GL_COLOR_BUFFER_BIT);
796*35238bceSAndroid Build Coastguard Worker             context.colorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
797*35238bceSAndroid Build Coastguard Worker         }
798*35238bceSAndroid Build Coastguard Worker 
799*35238bceSAndroid Build Coastguard Worker         // Read from fbo
800*35238bceSAndroid Build Coastguard Worker         context.readPixels(dst, 0, 0, width, height);
801*35238bceSAndroid Build Coastguard Worker     }
802*35238bceSAndroid Build Coastguard Worker }
803*35238bceSAndroid Build Coastguard Worker 
804*35238bceSAndroid Build Coastguard Worker class IntersectingQuadsTest : public FboRenderCase
805*35238bceSAndroid Build Coastguard Worker {
806*35238bceSAndroid Build Coastguard Worker public:
807*35238bceSAndroid Build Coastguard Worker     IntersectingQuadsTest(Context &context, const FboConfig &config, bool npot = false);
~IntersectingQuadsTest(void)808*35238bceSAndroid Build Coastguard Worker     virtual ~IntersectingQuadsTest(void)
809*35238bceSAndroid Build Coastguard Worker     {
810*35238bceSAndroid Build Coastguard Worker     }
811*35238bceSAndroid Build Coastguard Worker 
812*35238bceSAndroid Build Coastguard Worker     virtual void render(sglr::Context &context, Surface &dst);
813*35238bceSAndroid Build Coastguard Worker 
814*35238bceSAndroid Build Coastguard Worker     static bool isConfigSupported(const FboConfig &config);
815*35238bceSAndroid Build Coastguard Worker 
816*35238bceSAndroid Build Coastguard Worker private:
817*35238bceSAndroid Build Coastguard Worker     int m_fboWidth;
818*35238bceSAndroid Build Coastguard Worker     int m_fboHeight;
819*35238bceSAndroid Build Coastguard Worker };
820*35238bceSAndroid Build Coastguard Worker 
821*35238bceSAndroid Build Coastguard Worker class IntersectingQuadsNpotTest : public IntersectingQuadsTest
822*35238bceSAndroid Build Coastguard Worker {
823*35238bceSAndroid Build Coastguard Worker public:
IntersectingQuadsNpotTest(Context & context,const FboConfig & config)824*35238bceSAndroid Build Coastguard Worker     IntersectingQuadsNpotTest(Context &context, const FboConfig &config) : IntersectingQuadsTest(context, config, true)
825*35238bceSAndroid Build Coastguard Worker     {
826*35238bceSAndroid Build Coastguard Worker     }
827*35238bceSAndroid Build Coastguard Worker };
828*35238bceSAndroid Build Coastguard Worker 
IntersectingQuadsTest(Context & context,const FboConfig & config,bool npot)829*35238bceSAndroid Build Coastguard Worker IntersectingQuadsTest::IntersectingQuadsTest(Context &context, const FboConfig &config, bool npot)
830*35238bceSAndroid Build Coastguard Worker     : FboRenderCase(context, (string(npot ? "npot_" : "") + config.getName()).c_str(), "Intersecting textured quads",
831*35238bceSAndroid Build Coastguard Worker                     config)
832*35238bceSAndroid Build Coastguard Worker     , m_fboWidth(npot ? 127 : 128)
833*35238bceSAndroid Build Coastguard Worker     , m_fboHeight(npot ? 95 : 128)
834*35238bceSAndroid Build Coastguard Worker {
835*35238bceSAndroid Build Coastguard Worker }
836*35238bceSAndroid Build Coastguard Worker 
isConfigSupported(const FboConfig & config)837*35238bceSAndroid Build Coastguard Worker bool IntersectingQuadsTest::isConfigSupported(const FboConfig &config)
838*35238bceSAndroid Build Coastguard Worker {
839*35238bceSAndroid Build Coastguard Worker     // \note Disabled for stencil configurations since doesn't exercise stencil buffer
840*35238bceSAndroid Build Coastguard Worker     return config.depthbufferType != GL_NONE && config.stencilbufferType == GL_NONE;
841*35238bceSAndroid Build Coastguard Worker }
842*35238bceSAndroid Build Coastguard Worker 
render(sglr::Context & ctx,Surface & dst)843*35238bceSAndroid Build Coastguard Worker void IntersectingQuadsTest::render(sglr::Context &ctx, Surface &dst)
844*35238bceSAndroid Build Coastguard Worker {
845*35238bceSAndroid Build Coastguard Worker     SingleTex2DShader texShader;
846*35238bceSAndroid Build Coastguard Worker     uint32_t texShaderID = ctx.createProgram(&texShader);
847*35238bceSAndroid Build Coastguard Worker 
848*35238bceSAndroid Build Coastguard Worker     uint32_t metaballsTex = 1;
849*35238bceSAndroid Build Coastguard Worker     uint32_t quadsTex     = 2;
850*35238bceSAndroid Build Coastguard Worker 
851*35238bceSAndroid Build Coastguard Worker     createMetaballsTex2D(ctx, metaballsTex, GL_RGB, GL_UNSIGNED_BYTE, 64, 64);
852*35238bceSAndroid Build Coastguard Worker     createQuadsTex2D(ctx, quadsTex, GL_RGB, GL_UNSIGNED_BYTE, 64, 64);
853*35238bceSAndroid Build Coastguard Worker 
854*35238bceSAndroid Build Coastguard Worker     int width  = m_fboWidth;
855*35238bceSAndroid Build Coastguard Worker     int height = m_fboHeight;
856*35238bceSAndroid Build Coastguard Worker     Framebuffer fbo(ctx, getConfig(), width, height);
857*35238bceSAndroid Build Coastguard Worker     fbo.checkCompleteness();
858*35238bceSAndroid Build Coastguard Worker 
859*35238bceSAndroid Build Coastguard Worker     // Setup shaders
860*35238bceSAndroid Build Coastguard Worker     texShader.setUnit(ctx, texShaderID, 0);
861*35238bceSAndroid Build Coastguard Worker 
862*35238bceSAndroid Build Coastguard Worker     // Draw scene
863*35238bceSAndroid Build Coastguard Worker     ctx.bindFramebuffer(GL_FRAMEBUFFER, fbo.getFramebuffer());
864*35238bceSAndroid Build Coastguard Worker     ctx.viewport(0, 0, width, height);
865*35238bceSAndroid Build Coastguard Worker     ctx.clearColor(1.0f, 0.0f, 0.0f, 1.0f);
866*35238bceSAndroid Build Coastguard Worker     ctx.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
867*35238bceSAndroid Build Coastguard Worker 
868*35238bceSAndroid Build Coastguard Worker     ctx.enable(GL_DEPTH_TEST);
869*35238bceSAndroid Build Coastguard Worker 
870*35238bceSAndroid Build Coastguard Worker     ctx.bindTexture(GL_TEXTURE_2D, metaballsTex);
871*35238bceSAndroid Build Coastguard Worker     sglr::drawQuad(ctx, texShaderID, Vec3(-1.0f, -1.0f, -1.0f), Vec3(1.0f, 1.0f, 1.0f));
872*35238bceSAndroid Build Coastguard Worker 
873*35238bceSAndroid Build Coastguard Worker     ctx.bindTexture(GL_TEXTURE_2D, quadsTex);
874*35238bceSAndroid Build Coastguard Worker     sglr::drawQuad(ctx, texShaderID, Vec3(-1.0f, -1.0f, 1.0f), Vec3(1.0f, 1.0f, -1.0f));
875*35238bceSAndroid Build Coastguard Worker 
876*35238bceSAndroid Build Coastguard Worker     ctx.disable(GL_DEPTH_TEST);
877*35238bceSAndroid Build Coastguard Worker 
878*35238bceSAndroid Build Coastguard Worker     if (fbo.getConfig().colorbufferType == GL_TEXTURE_2D)
879*35238bceSAndroid Build Coastguard Worker     {
880*35238bceSAndroid Build Coastguard Worker         // Unbind fbo
881*35238bceSAndroid Build Coastguard Worker         ctx.bindFramebuffer(GL_FRAMEBUFFER, 0);
882*35238bceSAndroid Build Coastguard Worker 
883*35238bceSAndroid Build Coastguard Worker         // Draw to screen
884*35238bceSAndroid Build Coastguard Worker         ctx.bindTexture(GL_TEXTURE_2D, fbo.getColorbuffer());
885*35238bceSAndroid Build Coastguard Worker         ctx.viewport(0, 0, ctx.getWidth(), ctx.getHeight());
886*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(ctx, texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
887*35238bceSAndroid Build Coastguard Worker 
888*35238bceSAndroid Build Coastguard Worker         // Read from screen
889*35238bceSAndroid Build Coastguard Worker         ctx.readPixels(dst, 0, 0, ctx.getWidth(), ctx.getHeight());
890*35238bceSAndroid Build Coastguard Worker     }
891*35238bceSAndroid Build Coastguard Worker     else
892*35238bceSAndroid Build Coastguard Worker     {
893*35238bceSAndroid Build Coastguard Worker         // Read from fbo
894*35238bceSAndroid Build Coastguard Worker         ctx.readPixels(dst, 0, 0, width, height);
895*35238bceSAndroid Build Coastguard Worker     }
896*35238bceSAndroid Build Coastguard Worker }
897*35238bceSAndroid Build Coastguard Worker 
898*35238bceSAndroid Build Coastguard Worker class MixTest : public FboRenderCase
899*35238bceSAndroid Build Coastguard Worker {
900*35238bceSAndroid Build Coastguard Worker public:
901*35238bceSAndroid Build Coastguard Worker     MixTest(Context &context, const FboConfig &config, bool npot = false);
~MixTest(void)902*35238bceSAndroid Build Coastguard Worker     virtual ~MixTest(void)
903*35238bceSAndroid Build Coastguard Worker     {
904*35238bceSAndroid Build Coastguard Worker     }
905*35238bceSAndroid Build Coastguard Worker 
906*35238bceSAndroid Build Coastguard Worker     void render(sglr::Context &context, Surface &dst);
907*35238bceSAndroid Build Coastguard Worker 
908*35238bceSAndroid Build Coastguard Worker     static bool isConfigSupported(const FboConfig &config);
909*35238bceSAndroid Build Coastguard Worker 
910*35238bceSAndroid Build Coastguard Worker private:
911*35238bceSAndroid Build Coastguard Worker     int m_fboAWidth;
912*35238bceSAndroid Build Coastguard Worker     int m_fboAHeight;
913*35238bceSAndroid Build Coastguard Worker     int m_fboBWidth;
914*35238bceSAndroid Build Coastguard Worker     int m_fboBHeight;
915*35238bceSAndroid Build Coastguard Worker };
916*35238bceSAndroid Build Coastguard Worker 
917*35238bceSAndroid Build Coastguard Worker class MixNpotTest : public MixTest
918*35238bceSAndroid Build Coastguard Worker {
919*35238bceSAndroid Build Coastguard Worker public:
MixNpotTest(Context & context,const FboConfig & config)920*35238bceSAndroid Build Coastguard Worker     MixNpotTest(Context &context, const FboConfig &config) : MixTest(context, config, true)
921*35238bceSAndroid Build Coastguard Worker     {
922*35238bceSAndroid Build Coastguard Worker     }
923*35238bceSAndroid Build Coastguard Worker };
924*35238bceSAndroid Build Coastguard Worker 
MixTest(Context & context,const FboConfig & config,bool npot)925*35238bceSAndroid Build Coastguard Worker MixTest::MixTest(Context &context, const FboConfig &config, bool npot)
926*35238bceSAndroid Build Coastguard Worker     : FboRenderCase(context, (string(npot ? "mix_npot_" : "mix_") + config.getName()).c_str(),
927*35238bceSAndroid Build Coastguard Worker                     "Use two fbos as sources in draw operation", config)
928*35238bceSAndroid Build Coastguard Worker     , m_fboAWidth(npot ? 127 : 128)
929*35238bceSAndroid Build Coastguard Worker     , m_fboAHeight(npot ? 95 : 128)
930*35238bceSAndroid Build Coastguard Worker     , m_fboBWidth(npot ? 55 : 64)
931*35238bceSAndroid Build Coastguard Worker     , m_fboBHeight(npot ? 63 : 64)
932*35238bceSAndroid Build Coastguard Worker {
933*35238bceSAndroid Build Coastguard Worker }
934*35238bceSAndroid Build Coastguard Worker 
isConfigSupported(const FboConfig & config)935*35238bceSAndroid Build Coastguard Worker bool MixTest::isConfigSupported(const FboConfig &config)
936*35238bceSAndroid Build Coastguard Worker {
937*35238bceSAndroid Build Coastguard Worker     // \note Disabled for stencil configurations since doesn't exercise stencil buffer
938*35238bceSAndroid Build Coastguard Worker     return config.colorbufferType == GL_TEXTURE_2D && config.stencilbufferType == GL_NONE;
939*35238bceSAndroid Build Coastguard Worker }
940*35238bceSAndroid Build Coastguard Worker 
render(sglr::Context & context,Surface & dst)941*35238bceSAndroid Build Coastguard Worker void MixTest::render(sglr::Context &context, Surface &dst)
942*35238bceSAndroid Build Coastguard Worker {
943*35238bceSAndroid Build Coastguard Worker     SingleTex2DShader singleTexShader;
944*35238bceSAndroid Build Coastguard Worker     MixTexturesShader mixShader;
945*35238bceSAndroid Build Coastguard Worker 
946*35238bceSAndroid Build Coastguard Worker     uint32_t singleTexShaderID = context.createProgram(&singleTexShader);
947*35238bceSAndroid Build Coastguard Worker     uint32_t mixShaderID       = context.createProgram(&mixShader);
948*35238bceSAndroid Build Coastguard Worker 
949*35238bceSAndroid Build Coastguard Worker     // Texture with metaballs
950*35238bceSAndroid Build Coastguard Worker     uint32_t metaballsTex = 1;
951*35238bceSAndroid Build Coastguard Worker     context.pixelStorei(GL_UNPACK_ALIGNMENT, 1);
952*35238bceSAndroid Build Coastguard Worker     createMetaballsTex2D(context, metaballsTex, GL_RGB, GL_UNSIGNED_BYTE, 64, 64);
953*35238bceSAndroid Build Coastguard Worker 
954*35238bceSAndroid Build Coastguard Worker     // Setup shaders
955*35238bceSAndroid Build Coastguard Worker     singleTexShader.setUnit(context, singleTexShaderID, 0);
956*35238bceSAndroid Build Coastguard Worker     mixShader.setUnits(context, mixShaderID, 0, 1);
957*35238bceSAndroid Build Coastguard Worker 
958*35238bceSAndroid Build Coastguard Worker     // Fbo, quad with metaballs texture
959*35238bceSAndroid Build Coastguard Worker     Framebuffer fboA(context, getConfig(), m_fboAWidth, m_fboAHeight);
960*35238bceSAndroid Build Coastguard Worker     fboA.checkCompleteness();
961*35238bceSAndroid Build Coastguard Worker     context.bindFramebuffer(GL_FRAMEBUFFER, fboA.getFramebuffer());
962*35238bceSAndroid Build Coastguard Worker     context.viewport(0, 0, m_fboAWidth, m_fboAHeight);
963*35238bceSAndroid Build Coastguard Worker     context.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
964*35238bceSAndroid Build Coastguard Worker     context.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
965*35238bceSAndroid Build Coastguard Worker     context.bindTexture(GL_TEXTURE_2D, metaballsTex);
966*35238bceSAndroid Build Coastguard Worker     sglr::drawQuad(context, singleTexShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
967*35238bceSAndroid Build Coastguard Worker 
968*35238bceSAndroid Build Coastguard Worker     // Fbo, color clears
969*35238bceSAndroid Build Coastguard Worker     Framebuffer fboB(context, getConfig(), m_fboBWidth, m_fboBHeight);
970*35238bceSAndroid Build Coastguard Worker     fboB.checkCompleteness();
971*35238bceSAndroid Build Coastguard Worker     context.bindFramebuffer(GL_FRAMEBUFFER, fboB.getFramebuffer());
972*35238bceSAndroid Build Coastguard Worker     context.viewport(0, 0, m_fboBWidth, m_fboBHeight);
973*35238bceSAndroid Build Coastguard Worker     context.enable(GL_SCISSOR_TEST);
974*35238bceSAndroid Build Coastguard Worker     context.scissor(0, 0, 32, 64);
975*35238bceSAndroid Build Coastguard Worker     context.clearColor(1.0f, 0.0f, 0.0f, 1.0f);
976*35238bceSAndroid Build Coastguard Worker     context.clear(GL_COLOR_BUFFER_BIT);
977*35238bceSAndroid Build Coastguard Worker     context.scissor(32, 0, 32, 64);
978*35238bceSAndroid Build Coastguard Worker     context.clearColor(0.0f, 1.0f, 0.0f, 1.0f);
979*35238bceSAndroid Build Coastguard Worker     context.clear(GL_COLOR_BUFFER_BIT);
980*35238bceSAndroid Build Coastguard Worker     context.disable(GL_SCISSOR_TEST);
981*35238bceSAndroid Build Coastguard Worker 
982*35238bceSAndroid Build Coastguard Worker     // Final mix op
983*35238bceSAndroid Build Coastguard Worker     context.activeTexture(GL_TEXTURE0);
984*35238bceSAndroid Build Coastguard Worker     context.bindTexture(GL_TEXTURE_2D, fboA.getColorbuffer());
985*35238bceSAndroid Build Coastguard Worker     context.activeTexture(GL_TEXTURE1);
986*35238bceSAndroid Build Coastguard Worker     context.bindTexture(GL_TEXTURE_2D, fboB.getColorbuffer());
987*35238bceSAndroid Build Coastguard Worker     context.bindFramebuffer(GL_FRAMEBUFFER, 0);
988*35238bceSAndroid Build Coastguard Worker     context.viewport(0, 0, context.getWidth(), context.getHeight());
989*35238bceSAndroid Build Coastguard Worker     sglr::drawQuad(context, mixShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
990*35238bceSAndroid Build Coastguard Worker 
991*35238bceSAndroid Build Coastguard Worker     context.readPixels(dst, 0, 0, context.getWidth(), context.getHeight());
992*35238bceSAndroid Build Coastguard Worker }
993*35238bceSAndroid Build Coastguard Worker 
994*35238bceSAndroid Build Coastguard Worker class BlendTest : public FboRenderCase
995*35238bceSAndroid Build Coastguard Worker {
996*35238bceSAndroid Build Coastguard Worker public:
997*35238bceSAndroid Build Coastguard Worker     BlendTest(Context &context, const FboConfig &config, bool npot = false);
~BlendTest(void)998*35238bceSAndroid Build Coastguard Worker     virtual ~BlendTest(void)
999*35238bceSAndroid Build Coastguard Worker     {
1000*35238bceSAndroid Build Coastguard Worker     }
1001*35238bceSAndroid Build Coastguard Worker 
1002*35238bceSAndroid Build Coastguard Worker     void render(sglr::Context &context, Surface &dst);
1003*35238bceSAndroid Build Coastguard Worker 
1004*35238bceSAndroid Build Coastguard Worker     static bool isConfigSupported(const FboConfig &config);
1005*35238bceSAndroid Build Coastguard Worker 
1006*35238bceSAndroid Build Coastguard Worker private:
1007*35238bceSAndroid Build Coastguard Worker     int m_fboWidth;
1008*35238bceSAndroid Build Coastguard Worker     int m_fboHeight;
1009*35238bceSAndroid Build Coastguard Worker };
1010*35238bceSAndroid Build Coastguard Worker 
1011*35238bceSAndroid Build Coastguard Worker class BlendNpotTest : public BlendTest
1012*35238bceSAndroid Build Coastguard Worker {
1013*35238bceSAndroid Build Coastguard Worker public:
BlendNpotTest(Context & context,const FboConfig & config)1014*35238bceSAndroid Build Coastguard Worker     BlendNpotTest(Context &context, const FboConfig &config) : BlendTest(context, config, true)
1015*35238bceSAndroid Build Coastguard Worker     {
1016*35238bceSAndroid Build Coastguard Worker     }
1017*35238bceSAndroid Build Coastguard Worker };
1018*35238bceSAndroid Build Coastguard Worker 
BlendTest(Context & context,const FboConfig & config,bool npot)1019*35238bceSAndroid Build Coastguard Worker BlendTest::BlendTest(Context &context, const FboConfig &config, bool npot)
1020*35238bceSAndroid Build Coastguard Worker     : FboRenderCase(context, (string(npot ? "blend_npot_" : "blend_") + config.getName()).c_str(), "Blend to fbo",
1021*35238bceSAndroid Build Coastguard Worker                     config)
1022*35238bceSAndroid Build Coastguard Worker     , m_fboWidth(npot ? 111 : 128)
1023*35238bceSAndroid Build Coastguard Worker     , m_fboHeight(npot ? 122 : 128)
1024*35238bceSAndroid Build Coastguard Worker {
1025*35238bceSAndroid Build Coastguard Worker }
1026*35238bceSAndroid Build Coastguard Worker 
isConfigSupported(const FboConfig & config)1027*35238bceSAndroid Build Coastguard Worker bool BlendTest::isConfigSupported(const FboConfig &config)
1028*35238bceSAndroid Build Coastguard Worker {
1029*35238bceSAndroid Build Coastguard Worker     // \note Disabled for stencil configurations since doesn't exercise stencil buffer
1030*35238bceSAndroid Build Coastguard Worker     return config.stencilbufferType == GL_NONE;
1031*35238bceSAndroid Build Coastguard Worker }
1032*35238bceSAndroid Build Coastguard Worker 
render(sglr::Context & context,Surface & dst)1033*35238bceSAndroid Build Coastguard Worker void BlendTest::render(sglr::Context &context, Surface &dst)
1034*35238bceSAndroid Build Coastguard Worker {
1035*35238bceSAndroid Build Coastguard Worker     SingleTex2DShader shader;
1036*35238bceSAndroid Build Coastguard Worker     uint32_t shaderID     = context.createProgram(&shader);
1037*35238bceSAndroid Build Coastguard Worker     int width             = m_fboWidth;
1038*35238bceSAndroid Build Coastguard Worker     int height            = m_fboHeight;
1039*35238bceSAndroid Build Coastguard Worker     uint32_t metaballsTex = 1;
1040*35238bceSAndroid Build Coastguard Worker 
1041*35238bceSAndroid Build Coastguard Worker     createMetaballsTex2D(context, metaballsTex, GL_RGBA, GL_UNSIGNED_BYTE, 64, 64);
1042*35238bceSAndroid Build Coastguard Worker 
1043*35238bceSAndroid Build Coastguard Worker     Framebuffer fbo(context, getConfig(), width, height);
1044*35238bceSAndroid Build Coastguard Worker     fbo.checkCompleteness();
1045*35238bceSAndroid Build Coastguard Worker 
1046*35238bceSAndroid Build Coastguard Worker     shader.setUnit(context, shaderID, 0);
1047*35238bceSAndroid Build Coastguard Worker 
1048*35238bceSAndroid Build Coastguard Worker     context.bindFramebuffer(GL_FRAMEBUFFER, fbo.getFramebuffer());
1049*35238bceSAndroid Build Coastguard Worker     context.viewport(0, 0, width, height);
1050*35238bceSAndroid Build Coastguard Worker     context.bindTexture(GL_TEXTURE_2D, metaballsTex);
1051*35238bceSAndroid Build Coastguard Worker     context.clearColor(0.6f, 0.0f, 0.6f, 1.0f);
1052*35238bceSAndroid Build Coastguard Worker     context.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1053*35238bceSAndroid Build Coastguard Worker 
1054*35238bceSAndroid Build Coastguard Worker     context.enable(GL_BLEND);
1055*35238bceSAndroid Build Coastguard Worker     context.blendEquation(GL_FUNC_ADD);
1056*35238bceSAndroid Build Coastguard Worker     context.blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE);
1057*35238bceSAndroid Build Coastguard Worker     sglr::drawQuad(context, shaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
1058*35238bceSAndroid Build Coastguard Worker     context.disable(GL_BLEND);
1059*35238bceSAndroid Build Coastguard Worker 
1060*35238bceSAndroid Build Coastguard Worker     if (fbo.getConfig().colorbufferType == GL_TEXTURE_2D)
1061*35238bceSAndroid Build Coastguard Worker     {
1062*35238bceSAndroid Build Coastguard Worker         context.bindFramebuffer(GL_FRAMEBUFFER, 0);
1063*35238bceSAndroid Build Coastguard Worker         context.bindTexture(GL_TEXTURE_2D, fbo.getColorbuffer());
1064*35238bceSAndroid Build Coastguard Worker         context.viewport(0, 0, context.getWidth(), context.getHeight());
1065*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(context, shaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
1066*35238bceSAndroid Build Coastguard Worker         context.readPixels(dst, 0, 0, context.getWidth(), context.getHeight());
1067*35238bceSAndroid Build Coastguard Worker     }
1068*35238bceSAndroid Build Coastguard Worker     else
1069*35238bceSAndroid Build Coastguard Worker         context.readPixels(dst, 0, 0, width, height);
1070*35238bceSAndroid Build Coastguard Worker }
1071*35238bceSAndroid Build Coastguard Worker 
1072*35238bceSAndroid Build Coastguard Worker class StencilClearsTest : public FboRenderCase
1073*35238bceSAndroid Build Coastguard Worker {
1074*35238bceSAndroid Build Coastguard Worker public:
1075*35238bceSAndroid Build Coastguard Worker     StencilClearsTest(Context &context, const FboConfig &config);
~StencilClearsTest(void)1076*35238bceSAndroid Build Coastguard Worker     virtual ~StencilClearsTest(void)
1077*35238bceSAndroid Build Coastguard Worker     {
1078*35238bceSAndroid Build Coastguard Worker     }
1079*35238bceSAndroid Build Coastguard Worker 
1080*35238bceSAndroid Build Coastguard Worker     void render(sglr::Context &context, Surface &dst);
1081*35238bceSAndroid Build Coastguard Worker 
1082*35238bceSAndroid Build Coastguard Worker     static bool isConfigSupported(const FboConfig &config);
1083*35238bceSAndroid Build Coastguard Worker };
1084*35238bceSAndroid Build Coastguard Worker 
StencilClearsTest(Context & context,const FboConfig & config)1085*35238bceSAndroid Build Coastguard Worker StencilClearsTest::StencilClearsTest(Context &context, const FboConfig &config)
1086*35238bceSAndroid Build Coastguard Worker     : FboRenderCase(context, config.getName().c_str(), "Stencil clears", config)
1087*35238bceSAndroid Build Coastguard Worker {
1088*35238bceSAndroid Build Coastguard Worker }
1089*35238bceSAndroid Build Coastguard Worker 
render(sglr::Context & context,Surface & dst)1090*35238bceSAndroid Build Coastguard Worker void StencilClearsTest::render(sglr::Context &context, Surface &dst)
1091*35238bceSAndroid Build Coastguard Worker {
1092*35238bceSAndroid Build Coastguard Worker     SingleTex2DShader shader;
1093*35238bceSAndroid Build Coastguard Worker     uint32_t shaderID     = context.createProgram(&shader);
1094*35238bceSAndroid Build Coastguard Worker     int width             = 128;
1095*35238bceSAndroid Build Coastguard Worker     int height            = 128;
1096*35238bceSAndroid Build Coastguard Worker     uint32_t quadsTex     = 1;
1097*35238bceSAndroid Build Coastguard Worker     uint32_t metaballsTex = 2;
1098*35238bceSAndroid Build Coastguard Worker 
1099*35238bceSAndroid Build Coastguard Worker     createQuadsTex2D(context, quadsTex, GL_RGBA, GL_UNSIGNED_BYTE, width, height);
1100*35238bceSAndroid Build Coastguard Worker     createMetaballsTex2D(context, metaballsTex, GL_RGBA, GL_UNSIGNED_BYTE, width, height);
1101*35238bceSAndroid Build Coastguard Worker 
1102*35238bceSAndroid Build Coastguard Worker     Framebuffer fbo(context, getConfig(), width, height);
1103*35238bceSAndroid Build Coastguard Worker     fbo.checkCompleteness();
1104*35238bceSAndroid Build Coastguard Worker 
1105*35238bceSAndroid Build Coastguard Worker     // Bind framebuffer and clear
1106*35238bceSAndroid Build Coastguard Worker     context.bindFramebuffer(GL_FRAMEBUFFER, fbo.getFramebuffer());
1107*35238bceSAndroid Build Coastguard Worker     context.viewport(0, 0, width, height);
1108*35238bceSAndroid Build Coastguard Worker     context.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
1109*35238bceSAndroid Build Coastguard Worker     context.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1110*35238bceSAndroid Build Coastguard Worker 
1111*35238bceSAndroid Build Coastguard Worker     // Do stencil clears
1112*35238bceSAndroid Build Coastguard Worker     context.enable(GL_SCISSOR_TEST);
1113*35238bceSAndroid Build Coastguard Worker     context.scissor(10, 16, 32, 120);
1114*35238bceSAndroid Build Coastguard Worker     context.clearStencil(1);
1115*35238bceSAndroid Build Coastguard Worker     context.clear(GL_STENCIL_BUFFER_BIT);
1116*35238bceSAndroid Build Coastguard Worker     context.scissor(16, 32, 100, 64);
1117*35238bceSAndroid Build Coastguard Worker     context.clearStencil(2);
1118*35238bceSAndroid Build Coastguard Worker     context.clear(GL_STENCIL_BUFFER_BIT);
1119*35238bceSAndroid Build Coastguard Worker     context.disable(GL_SCISSOR_TEST);
1120*35238bceSAndroid Build Coastguard Worker 
1121*35238bceSAndroid Build Coastguard Worker     // Draw 2 textures with stecil tests
1122*35238bceSAndroid Build Coastguard Worker     context.activeTexture(GL_TEXTURE0);
1123*35238bceSAndroid Build Coastguard Worker     context.bindTexture(GL_TEXTURE_2D, quadsTex);
1124*35238bceSAndroid Build Coastguard Worker     context.activeTexture(GL_TEXTURE1);
1125*35238bceSAndroid Build Coastguard Worker     context.bindTexture(GL_TEXTURE_2D, metaballsTex);
1126*35238bceSAndroid Build Coastguard Worker 
1127*35238bceSAndroid Build Coastguard Worker     context.enable(GL_STENCIL_TEST);
1128*35238bceSAndroid Build Coastguard Worker     context.stencilFunc(GL_EQUAL, 1, 0xffffffffu);
1129*35238bceSAndroid Build Coastguard Worker     shader.setUnit(context, shaderID, 0);
1130*35238bceSAndroid Build Coastguard Worker     sglr::drawQuad(context, shaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
1131*35238bceSAndroid Build Coastguard Worker 
1132*35238bceSAndroid Build Coastguard Worker     context.stencilFunc(GL_EQUAL, 2, 0xffffffffu);
1133*35238bceSAndroid Build Coastguard Worker     shader.setUnit(context, shaderID, 1);
1134*35238bceSAndroid Build Coastguard Worker     sglr::drawQuad(context, shaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
1135*35238bceSAndroid Build Coastguard Worker 
1136*35238bceSAndroid Build Coastguard Worker     context.disable(GL_STENCIL_TEST);
1137*35238bceSAndroid Build Coastguard Worker 
1138*35238bceSAndroid Build Coastguard Worker     if (fbo.getConfig().colorbufferType == GL_TEXTURE_2D)
1139*35238bceSAndroid Build Coastguard Worker     {
1140*35238bceSAndroid Build Coastguard Worker         context.bindFramebuffer(GL_FRAMEBUFFER, 0);
1141*35238bceSAndroid Build Coastguard Worker         context.activeTexture(GL_TEXTURE0);
1142*35238bceSAndroid Build Coastguard Worker         context.bindTexture(GL_TEXTURE_2D, fbo.getColorbuffer());
1143*35238bceSAndroid Build Coastguard Worker         context.viewport(0, 0, context.getWidth(), context.getHeight());
1144*35238bceSAndroid Build Coastguard Worker         shader.setUnit(context, shaderID, 0);
1145*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(context, shaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
1146*35238bceSAndroid Build Coastguard Worker         context.readPixels(dst, 0, 0, context.getWidth(), context.getHeight());
1147*35238bceSAndroid Build Coastguard Worker     }
1148*35238bceSAndroid Build Coastguard Worker     else
1149*35238bceSAndroid Build Coastguard Worker     {
1150*35238bceSAndroid Build Coastguard Worker         // clear alpha channel for GL_RGB5_A1 format because test
1151*35238bceSAndroid Build Coastguard Worker         // thresholds for the alpha channel do not account for dithering
1152*35238bceSAndroid Build Coastguard Worker         if (getConfig().colorbufferFormat == GL_RGB5_A1)
1153*35238bceSAndroid Build Coastguard Worker         {
1154*35238bceSAndroid Build Coastguard Worker             context.colorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);
1155*35238bceSAndroid Build Coastguard Worker             context.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
1156*35238bceSAndroid Build Coastguard Worker             context.clear(GL_COLOR_BUFFER_BIT);
1157*35238bceSAndroid Build Coastguard Worker             context.colorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
1158*35238bceSAndroid Build Coastguard Worker         }
1159*35238bceSAndroid Build Coastguard Worker 
1160*35238bceSAndroid Build Coastguard Worker         context.readPixels(dst, 0, 0, width, height);
1161*35238bceSAndroid Build Coastguard Worker     }
1162*35238bceSAndroid Build Coastguard Worker }
1163*35238bceSAndroid Build Coastguard Worker 
isConfigSupported(const FboConfig & config)1164*35238bceSAndroid Build Coastguard Worker bool StencilClearsTest::isConfigSupported(const FboConfig &config)
1165*35238bceSAndroid Build Coastguard Worker {
1166*35238bceSAndroid Build Coastguard Worker     return config.stencilbufferType != GL_NONE;
1167*35238bceSAndroid Build Coastguard Worker }
1168*35238bceSAndroid Build Coastguard Worker 
1169*35238bceSAndroid Build Coastguard Worker class StencilTest : public FboRenderCase
1170*35238bceSAndroid Build Coastguard Worker {
1171*35238bceSAndroid Build Coastguard Worker public:
1172*35238bceSAndroid Build Coastguard Worker     StencilTest(Context &context, const FboConfig &config, bool npot = false);
~StencilTest(void)1173*35238bceSAndroid Build Coastguard Worker     virtual ~StencilTest(void)
1174*35238bceSAndroid Build Coastguard Worker     {
1175*35238bceSAndroid Build Coastguard Worker     }
1176*35238bceSAndroid Build Coastguard Worker 
1177*35238bceSAndroid Build Coastguard Worker     void render(sglr::Context &context, Surface &dst);
1178*35238bceSAndroid Build Coastguard Worker 
1179*35238bceSAndroid Build Coastguard Worker     static bool isConfigSupported(const FboConfig &config);
1180*35238bceSAndroid Build Coastguard Worker 
1181*35238bceSAndroid Build Coastguard Worker private:
1182*35238bceSAndroid Build Coastguard Worker     int m_fboWidth;
1183*35238bceSAndroid Build Coastguard Worker     int m_fboHeight;
1184*35238bceSAndroid Build Coastguard Worker };
1185*35238bceSAndroid Build Coastguard Worker 
1186*35238bceSAndroid Build Coastguard Worker class StencilNpotTest : public StencilTest
1187*35238bceSAndroid Build Coastguard Worker {
1188*35238bceSAndroid Build Coastguard Worker public:
StencilNpotTest(Context & context,const FboConfig & config)1189*35238bceSAndroid Build Coastguard Worker     StencilNpotTest(Context &context, const FboConfig &config) : StencilTest(context, config, true)
1190*35238bceSAndroid Build Coastguard Worker     {
1191*35238bceSAndroid Build Coastguard Worker     }
1192*35238bceSAndroid Build Coastguard Worker };
1193*35238bceSAndroid Build Coastguard Worker 
StencilTest(Context & context,const FboConfig & config,bool npot)1194*35238bceSAndroid Build Coastguard Worker StencilTest::StencilTest(Context &context, const FboConfig &config, bool npot)
1195*35238bceSAndroid Build Coastguard Worker     : FboRenderCase(context, (string(npot ? "npot_" : "") + config.getName()).c_str(), "Stencil ops", config)
1196*35238bceSAndroid Build Coastguard Worker     , m_fboWidth(npot ? 99 : 128)
1197*35238bceSAndroid Build Coastguard Worker     , m_fboHeight(npot ? 110 : 128)
1198*35238bceSAndroid Build Coastguard Worker {
1199*35238bceSAndroid Build Coastguard Worker }
1200*35238bceSAndroid Build Coastguard Worker 
isConfigSupported(const FboConfig & config)1201*35238bceSAndroid Build Coastguard Worker bool StencilTest::isConfigSupported(const FboConfig &config)
1202*35238bceSAndroid Build Coastguard Worker {
1203*35238bceSAndroid Build Coastguard Worker     return config.stencilbufferType != GL_NONE;
1204*35238bceSAndroid Build Coastguard Worker }
1205*35238bceSAndroid Build Coastguard Worker 
render(sglr::Context & ctx,Surface & dst)1206*35238bceSAndroid Build Coastguard Worker void StencilTest::render(sglr::Context &ctx, Surface &dst)
1207*35238bceSAndroid Build Coastguard Worker {
1208*35238bceSAndroid Build Coastguard Worker     FlatColorShader colorShader;
1209*35238bceSAndroid Build Coastguard Worker     SingleTex2DShader texShader;
1210*35238bceSAndroid Build Coastguard Worker     uint32_t colorShaderID = ctx.createProgram(&colorShader);
1211*35238bceSAndroid Build Coastguard Worker     uint32_t texShaderID   = ctx.createProgram(&texShader);
1212*35238bceSAndroid Build Coastguard Worker     int width              = m_fboWidth;
1213*35238bceSAndroid Build Coastguard Worker     int height             = m_fboHeight;
1214*35238bceSAndroid Build Coastguard Worker     int texWidth           = 64;
1215*35238bceSAndroid Build Coastguard Worker     int texHeight          = 64;
1216*35238bceSAndroid Build Coastguard Worker     uint32_t quadsTex      = 1;
1217*35238bceSAndroid Build Coastguard Worker     uint32_t metaballsTex  = 2;
1218*35238bceSAndroid Build Coastguard Worker     bool depth             = getConfig().depthbufferType != GL_NONE;
1219*35238bceSAndroid Build Coastguard Worker 
1220*35238bceSAndroid Build Coastguard Worker     createQuadsTex2D(ctx, quadsTex, GL_RGB, GL_UNSIGNED_BYTE, texWidth, texHeight);
1221*35238bceSAndroid Build Coastguard Worker     createMetaballsTex2D(ctx, metaballsTex, GL_RGB, GL_UNSIGNED_BYTE, texWidth, texHeight);
1222*35238bceSAndroid Build Coastguard Worker 
1223*35238bceSAndroid Build Coastguard Worker     Framebuffer fbo(ctx, getConfig(), width, height);
1224*35238bceSAndroid Build Coastguard Worker     fbo.checkCompleteness();
1225*35238bceSAndroid Build Coastguard Worker 
1226*35238bceSAndroid Build Coastguard Worker     // Bind framebuffer and clear
1227*35238bceSAndroid Build Coastguard Worker     ctx.bindFramebuffer(GL_FRAMEBUFFER, fbo.getFramebuffer());
1228*35238bceSAndroid Build Coastguard Worker     ctx.viewport(0, 0, width, height);
1229*35238bceSAndroid Build Coastguard Worker     ctx.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
1230*35238bceSAndroid Build Coastguard Worker     ctx.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1231*35238bceSAndroid Build Coastguard Worker 
1232*35238bceSAndroid Build Coastguard Worker     // Render intersecting quads - increment stencil on depth pass
1233*35238bceSAndroid Build Coastguard Worker     ctx.enable(GL_DEPTH_TEST);
1234*35238bceSAndroid Build Coastguard Worker     ctx.enable(GL_STENCIL_TEST);
1235*35238bceSAndroid Build Coastguard Worker     ctx.stencilFunc(GL_ALWAYS, 0, 0xffu);
1236*35238bceSAndroid Build Coastguard Worker     ctx.stencilOp(GL_KEEP, GL_KEEP, GL_INCR);
1237*35238bceSAndroid Build Coastguard Worker 
1238*35238bceSAndroid Build Coastguard Worker     colorShader.setColor(ctx, colorShaderID, Vec4(0.0f, 0.0f, 1.0f, 1.0f));
1239*35238bceSAndroid Build Coastguard Worker     sglr::drawQuad(ctx, colorShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(+1.0f, +1.0f, 0.0f));
1240*35238bceSAndroid Build Coastguard Worker 
1241*35238bceSAndroid Build Coastguard Worker     ctx.bindTexture(GL_TEXTURE_2D, quadsTex);
1242*35238bceSAndroid Build Coastguard Worker     texShader.setUnit(ctx, texShaderID, 0);
1243*35238bceSAndroid Build Coastguard Worker     sglr::drawQuad(ctx, texShaderID, Vec3(-1.0f, -1.0f, -1.0f), Vec3(+1.0f, +1.0f, +1.0f));
1244*35238bceSAndroid Build Coastguard Worker 
1245*35238bceSAndroid Build Coastguard Worker     // Draw quad with stencil test (stencil == 1 or 2 depending on depth) - decrement on stencil failure
1246*35238bceSAndroid Build Coastguard Worker     ctx.disable(GL_DEPTH_TEST);
1247*35238bceSAndroid Build Coastguard Worker     ctx.stencilFunc(GL_EQUAL, depth ? 2 : 1, 0xffu);
1248*35238bceSAndroid Build Coastguard Worker     ctx.stencilOp(GL_DECR, GL_KEEP, GL_KEEP);
1249*35238bceSAndroid Build Coastguard Worker     colorShader.setColor(ctx, colorShaderID, Vec4(0.0f, 1.0f, 0.0f, 1.0f));
1250*35238bceSAndroid Build Coastguard Worker     sglr::drawQuad(ctx, colorShaderID, Vec3(-0.5f, -0.5f, 0.0f), Vec3(+0.5f, +0.5f, 0.0f));
1251*35238bceSAndroid Build Coastguard Worker 
1252*35238bceSAndroid Build Coastguard Worker     // Draw metaballs with stencil test where stencil > 1 or 2 depending on depth buffer
1253*35238bceSAndroid Build Coastguard Worker     ctx.bindTexture(GL_TEXTURE_2D, metaballsTex);
1254*35238bceSAndroid Build Coastguard Worker     ctx.stencilFunc(GL_GREATER, depth ? 1 : 2, 0xffu);
1255*35238bceSAndroid Build Coastguard Worker     ctx.stencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
1256*35238bceSAndroid Build Coastguard Worker     sglr::drawQuad(ctx, texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(+1.0f, +1.0f, 0.0f));
1257*35238bceSAndroid Build Coastguard Worker 
1258*35238bceSAndroid Build Coastguard Worker     ctx.disable(GL_STENCIL_TEST);
1259*35238bceSAndroid Build Coastguard Worker 
1260*35238bceSAndroid Build Coastguard Worker     if (fbo.getConfig().colorbufferType == GL_TEXTURE_2D)
1261*35238bceSAndroid Build Coastguard Worker     {
1262*35238bceSAndroid Build Coastguard Worker         ctx.bindFramebuffer(GL_FRAMEBUFFER, 0);
1263*35238bceSAndroid Build Coastguard Worker         ctx.activeTexture(GL_TEXTURE0);
1264*35238bceSAndroid Build Coastguard Worker         ctx.bindTexture(GL_TEXTURE_2D, fbo.getColorbuffer());
1265*35238bceSAndroid Build Coastguard Worker         ctx.viewport(0, 0, ctx.getWidth(), ctx.getHeight());
1266*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(ctx, texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
1267*35238bceSAndroid Build Coastguard Worker         ctx.readPixels(dst, 0, 0, ctx.getWidth(), ctx.getHeight());
1268*35238bceSAndroid Build Coastguard Worker     }
1269*35238bceSAndroid Build Coastguard Worker     else
1270*35238bceSAndroid Build Coastguard Worker         ctx.readPixels(dst, 0, 0, width, height);
1271*35238bceSAndroid Build Coastguard Worker }
1272*35238bceSAndroid Build Coastguard Worker 
1273*35238bceSAndroid Build Coastguard Worker class SharedColorbufferTest : public FboRenderCase
1274*35238bceSAndroid Build Coastguard Worker {
1275*35238bceSAndroid Build Coastguard Worker public:
1276*35238bceSAndroid Build Coastguard Worker     SharedColorbufferTest(Context &context, const FboConfig &config);
~SharedColorbufferTest(void)1277*35238bceSAndroid Build Coastguard Worker     virtual ~SharedColorbufferTest(void)
1278*35238bceSAndroid Build Coastguard Worker     {
1279*35238bceSAndroid Build Coastguard Worker     }
1280*35238bceSAndroid Build Coastguard Worker 
1281*35238bceSAndroid Build Coastguard Worker     void render(sglr::Context &context, Surface &dst);
1282*35238bceSAndroid Build Coastguard Worker };
1283*35238bceSAndroid Build Coastguard Worker 
SharedColorbufferTest(Context & context,const FboConfig & config)1284*35238bceSAndroid Build Coastguard Worker SharedColorbufferTest::SharedColorbufferTest(Context &context, const FboConfig &config)
1285*35238bceSAndroid Build Coastguard Worker     : FboRenderCase(context, config.getName().c_str(), "Shared colorbuffer", config)
1286*35238bceSAndroid Build Coastguard Worker {
1287*35238bceSAndroid Build Coastguard Worker }
1288*35238bceSAndroid Build Coastguard Worker 
render(sglr::Context & context,Surface & dst)1289*35238bceSAndroid Build Coastguard Worker void SharedColorbufferTest::render(sglr::Context &context, Surface &dst)
1290*35238bceSAndroid Build Coastguard Worker {
1291*35238bceSAndroid Build Coastguard Worker     SingleTex2DShader shader;
1292*35238bceSAndroid Build Coastguard Worker     uint32_t shaderID = context.createProgram(&shader);
1293*35238bceSAndroid Build Coastguard Worker     int width         = 128;
1294*35238bceSAndroid Build Coastguard Worker     int height        = 128;
1295*35238bceSAndroid Build Coastguard Worker     // bool depth = getConfig().depthbufferFormat != GL_NONE;
1296*35238bceSAndroid Build Coastguard Worker     bool stencil = getConfig().stencilbufferFormat != GL_NONE;
1297*35238bceSAndroid Build Coastguard Worker 
1298*35238bceSAndroid Build Coastguard Worker     // Textures
1299*35238bceSAndroid Build Coastguard Worker     uint32_t quadsTex     = 1;
1300*35238bceSAndroid Build Coastguard Worker     uint32_t metaballsTex = 2;
1301*35238bceSAndroid Build Coastguard Worker     createQuadsTex2D(context, quadsTex, GL_RGB, GL_UNSIGNED_BYTE, 64, 64);
1302*35238bceSAndroid Build Coastguard Worker     createMetaballsTex2D(context, metaballsTex, GL_RGBA, GL_UNSIGNED_BYTE, 64, 64);
1303*35238bceSAndroid Build Coastguard Worker 
1304*35238bceSAndroid Build Coastguard Worker     context.viewport(0, 0, width, height);
1305*35238bceSAndroid Build Coastguard Worker 
1306*35238bceSAndroid Build Coastguard Worker     shader.setUnit(context, shaderID, 0);
1307*35238bceSAndroid Build Coastguard Worker 
1308*35238bceSAndroid Build Coastguard Worker     // Fbo A
1309*35238bceSAndroid Build Coastguard Worker     Framebuffer fboA(context, getConfig(), width, height);
1310*35238bceSAndroid Build Coastguard Worker     fboA.checkCompleteness();
1311*35238bceSAndroid Build Coastguard Worker 
1312*35238bceSAndroid Build Coastguard Worker     // Fbo B - don't create colorbuffer
1313*35238bceSAndroid Build Coastguard Worker     FboConfig cfg         = getConfig();
1314*35238bceSAndroid Build Coastguard Worker     cfg.colorbufferType   = GL_NONE;
1315*35238bceSAndroid Build Coastguard Worker     cfg.colorbufferFormat = GL_NONE;
1316*35238bceSAndroid Build Coastguard Worker     Framebuffer fboB(context, cfg, width, height);
1317*35238bceSAndroid Build Coastguard Worker 
1318*35238bceSAndroid Build Coastguard Worker     // Attach color buffer from fbo A
1319*35238bceSAndroid Build Coastguard Worker     context.bindFramebuffer(GL_FRAMEBUFFER, fboB.getFramebuffer());
1320*35238bceSAndroid Build Coastguard Worker     switch (getConfig().colorbufferType)
1321*35238bceSAndroid Build Coastguard Worker     {
1322*35238bceSAndroid Build Coastguard Worker     case GL_TEXTURE_2D:
1323*35238bceSAndroid Build Coastguard Worker         context.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fboA.getColorbuffer(), 0);
1324*35238bceSAndroid Build Coastguard Worker         break;
1325*35238bceSAndroid Build Coastguard Worker 
1326*35238bceSAndroid Build Coastguard Worker     case GL_RENDERBUFFER:
1327*35238bceSAndroid Build Coastguard Worker         context.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, fboA.getColorbuffer());
1328*35238bceSAndroid Build Coastguard Worker         break;
1329*35238bceSAndroid Build Coastguard Worker 
1330*35238bceSAndroid Build Coastguard Worker     default:
1331*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(false);
1332*35238bceSAndroid Build Coastguard Worker     }
1333*35238bceSAndroid Build Coastguard Worker 
1334*35238bceSAndroid Build Coastguard Worker     // Clear depth and stencil in fbo B
1335*35238bceSAndroid Build Coastguard Worker     context.clear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1336*35238bceSAndroid Build Coastguard Worker 
1337*35238bceSAndroid Build Coastguard Worker     // Render quads to fbo 1, with depth 0.0
1338*35238bceSAndroid Build Coastguard Worker     context.bindFramebuffer(GL_FRAMEBUFFER, fboA.getFramebuffer());
1339*35238bceSAndroid Build Coastguard Worker     context.bindTexture(GL_TEXTURE_2D, quadsTex);
1340*35238bceSAndroid Build Coastguard Worker     context.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
1341*35238bceSAndroid Build Coastguard Worker     context.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1342*35238bceSAndroid Build Coastguard Worker 
1343*35238bceSAndroid Build Coastguard Worker     if (stencil)
1344*35238bceSAndroid Build Coastguard Worker     {
1345*35238bceSAndroid Build Coastguard Worker         // Stencil to 1 in fbo A
1346*35238bceSAndroid Build Coastguard Worker         context.clearStencil(1);
1347*35238bceSAndroid Build Coastguard Worker         context.clear(GL_STENCIL_BUFFER_BIT);
1348*35238bceSAndroid Build Coastguard Worker     }
1349*35238bceSAndroid Build Coastguard Worker 
1350*35238bceSAndroid Build Coastguard Worker     context.enable(GL_DEPTH_TEST);
1351*35238bceSAndroid Build Coastguard Worker     sglr::drawQuad(context, shaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
1352*35238bceSAndroid Build Coastguard Worker     context.disable(GL_DEPTH_TEST);
1353*35238bceSAndroid Build Coastguard Worker 
1354*35238bceSAndroid Build Coastguard Worker     // Blend metaballs to fbo 2
1355*35238bceSAndroid Build Coastguard Worker     context.bindFramebuffer(GL_FRAMEBUFFER, fboB.getFramebuffer());
1356*35238bceSAndroid Build Coastguard Worker     context.bindTexture(GL_TEXTURE_2D, metaballsTex);
1357*35238bceSAndroid Build Coastguard Worker     context.enable(GL_BLEND);
1358*35238bceSAndroid Build Coastguard Worker     context.blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE);
1359*35238bceSAndroid Build Coastguard Worker     sglr::drawQuad(context, shaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
1360*35238bceSAndroid Build Coastguard Worker 
1361*35238bceSAndroid Build Coastguard Worker     // Render small quad that is only visible if depth buffer is not shared with fbo A - or there is no depth bits
1362*35238bceSAndroid Build Coastguard Worker     context.bindTexture(GL_TEXTURE_2D, quadsTex);
1363*35238bceSAndroid Build Coastguard Worker     context.enable(GL_DEPTH_TEST);
1364*35238bceSAndroid Build Coastguard Worker     sglr::drawQuad(context, shaderID, Vec3(0.5f, 0.5f, 0.5f), Vec3(1.0f, 1.0f, 0.5f));
1365*35238bceSAndroid Build Coastguard Worker     context.disable(GL_DEPTH_TEST);
1366*35238bceSAndroid Build Coastguard Worker 
1367*35238bceSAndroid Build Coastguard Worker     if (stencil)
1368*35238bceSAndroid Build Coastguard Worker     {
1369*35238bceSAndroid Build Coastguard Worker         FlatColorShader flatShader;
1370*35238bceSAndroid Build Coastguard Worker         uint32_t flatShaderID = context.createProgram(&flatShader);
1371*35238bceSAndroid Build Coastguard Worker 
1372*35238bceSAndroid Build Coastguard Worker         flatShader.setColor(context, flatShaderID, Vec4(0.0f, 1.0f, 0.0f, 1.0f));
1373*35238bceSAndroid Build Coastguard Worker 
1374*35238bceSAndroid Build Coastguard Worker         // Clear subset of stencil buffer to 1
1375*35238bceSAndroid Build Coastguard Worker         context.enable(GL_SCISSOR_TEST);
1376*35238bceSAndroid Build Coastguard Worker         context.scissor(10, 10, 12, 25);
1377*35238bceSAndroid Build Coastguard Worker         context.clearStencil(1);
1378*35238bceSAndroid Build Coastguard Worker         context.clear(GL_STENCIL_BUFFER_BIT);
1379*35238bceSAndroid Build Coastguard Worker         context.disable(GL_SCISSOR_TEST);
1380*35238bceSAndroid Build Coastguard Worker 
1381*35238bceSAndroid Build Coastguard Worker         // Render quad with stencil mask == 1
1382*35238bceSAndroid Build Coastguard Worker         context.enable(GL_STENCIL_TEST);
1383*35238bceSAndroid Build Coastguard Worker         context.stencilFunc(GL_EQUAL, 1, 0xffu);
1384*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(context, flatShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
1385*35238bceSAndroid Build Coastguard Worker         context.disable(GL_STENCIL_TEST);
1386*35238bceSAndroid Build Coastguard Worker     }
1387*35238bceSAndroid Build Coastguard Worker 
1388*35238bceSAndroid Build Coastguard Worker     // Get results
1389*35238bceSAndroid Build Coastguard Worker     if (fboA.getConfig().colorbufferType == GL_TEXTURE_2D)
1390*35238bceSAndroid Build Coastguard Worker     {
1391*35238bceSAndroid Build Coastguard Worker         context.bindFramebuffer(GL_FRAMEBUFFER, 0);
1392*35238bceSAndroid Build Coastguard Worker         context.bindTexture(GL_TEXTURE_2D, fboA.getColorbuffer());
1393*35238bceSAndroid Build Coastguard Worker         context.viewport(0, 0, context.getWidth(), context.getHeight());
1394*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(context, shaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
1395*35238bceSAndroid Build Coastguard Worker         context.readPixels(dst, 0, 0, context.getWidth(), context.getHeight());
1396*35238bceSAndroid Build Coastguard Worker     }
1397*35238bceSAndroid Build Coastguard Worker     else
1398*35238bceSAndroid Build Coastguard Worker         context.readPixels(dst, 0, 0, width, height);
1399*35238bceSAndroid Build Coastguard Worker }
1400*35238bceSAndroid Build Coastguard Worker 
1401*35238bceSAndroid Build Coastguard Worker class SharedColorbufferClearsTest : public FboRenderCase
1402*35238bceSAndroid Build Coastguard Worker {
1403*35238bceSAndroid Build Coastguard Worker public:
1404*35238bceSAndroid Build Coastguard Worker     SharedColorbufferClearsTest(Context &context, const FboConfig &config);
~SharedColorbufferClearsTest(void)1405*35238bceSAndroid Build Coastguard Worker     virtual ~SharedColorbufferClearsTest(void)
1406*35238bceSAndroid Build Coastguard Worker     {
1407*35238bceSAndroid Build Coastguard Worker     }
1408*35238bceSAndroid Build Coastguard Worker 
1409*35238bceSAndroid Build Coastguard Worker     static bool isConfigSupported(const FboConfig &config);
1410*35238bceSAndroid Build Coastguard Worker     void render(sglr::Context &context, Surface &dst);
1411*35238bceSAndroid Build Coastguard Worker };
1412*35238bceSAndroid Build Coastguard Worker 
SharedColorbufferClearsTest(Context & context,const FboConfig & config)1413*35238bceSAndroid Build Coastguard Worker SharedColorbufferClearsTest::SharedColorbufferClearsTest(Context &context, const FboConfig &config)
1414*35238bceSAndroid Build Coastguard Worker     : FboRenderCase(context, config.getName().c_str(), "Shared colorbuffer clears", config)
1415*35238bceSAndroid Build Coastguard Worker {
1416*35238bceSAndroid Build Coastguard Worker }
1417*35238bceSAndroid Build Coastguard Worker 
isConfigSupported(const FboConfig & config)1418*35238bceSAndroid Build Coastguard Worker bool SharedColorbufferClearsTest::isConfigSupported(const FboConfig &config)
1419*35238bceSAndroid Build Coastguard Worker {
1420*35238bceSAndroid Build Coastguard Worker     return config.colorbufferType != GL_NONE && config.depthbufferType == GL_NONE &&
1421*35238bceSAndroid Build Coastguard Worker            config.stencilbufferType == GL_NONE;
1422*35238bceSAndroid Build Coastguard Worker }
1423*35238bceSAndroid Build Coastguard Worker 
render(sglr::Context & context,Surface & dst)1424*35238bceSAndroid Build Coastguard Worker void SharedColorbufferClearsTest::render(sglr::Context &context, Surface &dst)
1425*35238bceSAndroid Build Coastguard Worker {
1426*35238bceSAndroid Build Coastguard Worker     int width            = 128;
1427*35238bceSAndroid Build Coastguard Worker     int height           = 128;
1428*35238bceSAndroid Build Coastguard Worker     uint32_t colorbuffer = 1;
1429*35238bceSAndroid Build Coastguard Worker 
1430*35238bceSAndroid Build Coastguard Worker     checkColorFormatSupport(context, getConfig().colorbufferFormat);
1431*35238bceSAndroid Build Coastguard Worker 
1432*35238bceSAndroid Build Coastguard Worker     // Single colorbuffer
1433*35238bceSAndroid Build Coastguard Worker     if (getConfig().colorbufferType == GL_TEXTURE_2D)
1434*35238bceSAndroid Build Coastguard Worker     {
1435*35238bceSAndroid Build Coastguard Worker         context.bindTexture(GL_TEXTURE_2D, colorbuffer);
1436*35238bceSAndroid Build Coastguard Worker         context.texImage2D(GL_TEXTURE_2D, 0, getConfig().colorbufferFormat, width, height);
1437*35238bceSAndroid Build Coastguard Worker         context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1438*35238bceSAndroid Build Coastguard Worker     }
1439*35238bceSAndroid Build Coastguard Worker     else
1440*35238bceSAndroid Build Coastguard Worker     {
1441*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(getConfig().colorbufferType == GL_RENDERBUFFER);
1442*35238bceSAndroid Build Coastguard Worker         context.bindRenderbuffer(GL_RENDERBUFFER, colorbuffer);
1443*35238bceSAndroid Build Coastguard Worker         context.renderbufferStorage(GL_RENDERBUFFER, getConfig().colorbufferFormat, width, height);
1444*35238bceSAndroid Build Coastguard Worker     }
1445*35238bceSAndroid Build Coastguard Worker 
1446*35238bceSAndroid Build Coastguard Worker     // Multiple framebuffers sharing the colorbuffer
1447*35238bceSAndroid Build Coastguard Worker     for (int fbo = 1; fbo <= 3; fbo++)
1448*35238bceSAndroid Build Coastguard Worker     {
1449*35238bceSAndroid Build Coastguard Worker         context.bindFramebuffer(GL_FRAMEBUFFER, fbo);
1450*35238bceSAndroid Build Coastguard Worker 
1451*35238bceSAndroid Build Coastguard Worker         if (getConfig().colorbufferType == GL_TEXTURE_2D)
1452*35238bceSAndroid Build Coastguard Worker             context.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorbuffer, 0);
1453*35238bceSAndroid Build Coastguard Worker         else
1454*35238bceSAndroid Build Coastguard Worker             context.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorbuffer);
1455*35238bceSAndroid Build Coastguard Worker     }
1456*35238bceSAndroid Build Coastguard Worker 
1457*35238bceSAndroid Build Coastguard Worker     context.bindFramebuffer(GL_FRAMEBUFFER, 1);
1458*35238bceSAndroid Build Coastguard Worker 
1459*35238bceSAndroid Build Coastguard Worker     // Check completeness
1460*35238bceSAndroid Build Coastguard Worker     {
1461*35238bceSAndroid Build Coastguard Worker         GLenum status = context.checkFramebufferStatus(GL_FRAMEBUFFER);
1462*35238bceSAndroid Build Coastguard Worker         if (status != GL_FRAMEBUFFER_COMPLETE)
1463*35238bceSAndroid Build Coastguard Worker             throw FboIncompleteException(getConfig(), status, __FILE__, __LINE__);
1464*35238bceSAndroid Build Coastguard Worker     }
1465*35238bceSAndroid Build Coastguard Worker 
1466*35238bceSAndroid Build Coastguard Worker     // Render to them
1467*35238bceSAndroid Build Coastguard Worker     context.viewport(0, 0, width, height);
1468*35238bceSAndroid Build Coastguard Worker     context.clearColor(0.0f, 0.0f, 1.0f, 1.0f);
1469*35238bceSAndroid Build Coastguard Worker     context.clear(GL_COLOR_BUFFER_BIT);
1470*35238bceSAndroid Build Coastguard Worker 
1471*35238bceSAndroid Build Coastguard Worker     context.enable(GL_SCISSOR_TEST);
1472*35238bceSAndroid Build Coastguard Worker 
1473*35238bceSAndroid Build Coastguard Worker     context.bindFramebuffer(GL_FRAMEBUFFER, 2);
1474*35238bceSAndroid Build Coastguard Worker     context.clearColor(0.6f, 0.0f, 0.0f, 1.0f);
1475*35238bceSAndroid Build Coastguard Worker     context.scissor(10, 10, 64, 64);
1476*35238bceSAndroid Build Coastguard Worker     context.clear(GL_COLOR_BUFFER_BIT);
1477*35238bceSAndroid Build Coastguard Worker     context.clearColor(0.0f, 0.6f, 0.0f, 1.0f);
1478*35238bceSAndroid Build Coastguard Worker     context.scissor(60, 60, 40, 20);
1479*35238bceSAndroid Build Coastguard Worker     context.clear(GL_COLOR_BUFFER_BIT);
1480*35238bceSAndroid Build Coastguard Worker 
1481*35238bceSAndroid Build Coastguard Worker     context.bindFramebuffer(GL_FRAMEBUFFER, 3);
1482*35238bceSAndroid Build Coastguard Worker     context.clearColor(0.0f, 0.0f, 0.6f, 1.0f);
1483*35238bceSAndroid Build Coastguard Worker     context.scissor(20, 20, 100, 10);
1484*35238bceSAndroid Build Coastguard Worker     context.clear(GL_COLOR_BUFFER_BIT);
1485*35238bceSAndroid Build Coastguard Worker 
1486*35238bceSAndroid Build Coastguard Worker     context.bindFramebuffer(GL_FRAMEBUFFER, 1);
1487*35238bceSAndroid Build Coastguard Worker     context.clearColor(0.6f, 0.0f, 0.6f, 1.0f);
1488*35238bceSAndroid Build Coastguard Worker     context.scissor(20, 20, 5, 100);
1489*35238bceSAndroid Build Coastguard Worker     context.clear(GL_COLOR_BUFFER_BIT);
1490*35238bceSAndroid Build Coastguard Worker 
1491*35238bceSAndroid Build Coastguard Worker     context.disable(GL_SCISSOR_TEST);
1492*35238bceSAndroid Build Coastguard Worker 
1493*35238bceSAndroid Build Coastguard Worker     if (getConfig().colorbufferType == GL_TEXTURE_2D)
1494*35238bceSAndroid Build Coastguard Worker     {
1495*35238bceSAndroid Build Coastguard Worker         SingleTex2DShader shader;
1496*35238bceSAndroid Build Coastguard Worker         uint32_t shaderID = context.createProgram(&shader);
1497*35238bceSAndroid Build Coastguard Worker 
1498*35238bceSAndroid Build Coastguard Worker         shader.setUnit(context, shaderID, 0);
1499*35238bceSAndroid Build Coastguard Worker 
1500*35238bceSAndroid Build Coastguard Worker         context.bindFramebuffer(GL_FRAMEBUFFER, 0);
1501*35238bceSAndroid Build Coastguard Worker         context.viewport(0, 0, context.getWidth(), context.getHeight());
1502*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(context, shaderID, Vec3(-0.9f, -0.9f, 0.0f), Vec3(0.9f, 0.9f, 0.0f));
1503*35238bceSAndroid Build Coastguard Worker         context.readPixels(dst, 0, 0, context.getWidth(), context.getHeight());
1504*35238bceSAndroid Build Coastguard Worker     }
1505*35238bceSAndroid Build Coastguard Worker     else
1506*35238bceSAndroid Build Coastguard Worker         context.readPixels(dst, 0, 0, width, height);
1507*35238bceSAndroid Build Coastguard Worker }
1508*35238bceSAndroid Build Coastguard Worker 
1509*35238bceSAndroid Build Coastguard Worker class SharedDepthbufferTest : public FboRenderCase
1510*35238bceSAndroid Build Coastguard Worker {
1511*35238bceSAndroid Build Coastguard Worker public:
1512*35238bceSAndroid Build Coastguard Worker     SharedDepthbufferTest(Context &context, const FboConfig &config);
~SharedDepthbufferTest(void)1513*35238bceSAndroid Build Coastguard Worker     virtual ~SharedDepthbufferTest(void)
1514*35238bceSAndroid Build Coastguard Worker     {
1515*35238bceSAndroid Build Coastguard Worker     }
1516*35238bceSAndroid Build Coastguard Worker 
1517*35238bceSAndroid Build Coastguard Worker     static bool isConfigSupported(const FboConfig &config);
1518*35238bceSAndroid Build Coastguard Worker     void render(sglr::Context &context, Surface &dst);
1519*35238bceSAndroid Build Coastguard Worker };
1520*35238bceSAndroid Build Coastguard Worker 
SharedDepthbufferTest(Context & context,const FboConfig & config)1521*35238bceSAndroid Build Coastguard Worker SharedDepthbufferTest::SharedDepthbufferTest(Context &context, const FboConfig &config)
1522*35238bceSAndroid Build Coastguard Worker     : FboRenderCase(context, config.getName().c_str(), "Shared depthbuffer", config)
1523*35238bceSAndroid Build Coastguard Worker {
1524*35238bceSAndroid Build Coastguard Worker }
1525*35238bceSAndroid Build Coastguard Worker 
isConfigSupported(const FboConfig & config)1526*35238bceSAndroid Build Coastguard Worker bool SharedDepthbufferTest::isConfigSupported(const FboConfig &config)
1527*35238bceSAndroid Build Coastguard Worker {
1528*35238bceSAndroid Build Coastguard Worker     return config.depthbufferType == GL_RENDERBUFFER;
1529*35238bceSAndroid Build Coastguard Worker }
1530*35238bceSAndroid Build Coastguard Worker 
render(sglr::Context & context,Surface & dst)1531*35238bceSAndroid Build Coastguard Worker void SharedDepthbufferTest::render(sglr::Context &context, Surface &dst)
1532*35238bceSAndroid Build Coastguard Worker {
1533*35238bceSAndroid Build Coastguard Worker     SingleTex2DShader texShader;
1534*35238bceSAndroid Build Coastguard Worker     FlatColorShader colorShader;
1535*35238bceSAndroid Build Coastguard Worker     uint32_t texShaderID   = context.createProgram(&texShader);
1536*35238bceSAndroid Build Coastguard Worker     uint32_t colorShaderID = context.createProgram(&colorShader);
1537*35238bceSAndroid Build Coastguard Worker     int width              = 128;
1538*35238bceSAndroid Build Coastguard Worker     int height             = 128;
1539*35238bceSAndroid Build Coastguard Worker     bool stencil           = getConfig().stencilbufferType != GL_NONE;
1540*35238bceSAndroid Build Coastguard Worker 
1541*35238bceSAndroid Build Coastguard Worker     // Setup shaders
1542*35238bceSAndroid Build Coastguard Worker     texShader.setUnit(context, texShaderID, 0);
1543*35238bceSAndroid Build Coastguard Worker     colorShader.setColor(context, colorShaderID, Vec4(0.0f, 1.0f, 0.0f, 1.0f));
1544*35238bceSAndroid Build Coastguard Worker 
1545*35238bceSAndroid Build Coastguard Worker     // Textures
1546*35238bceSAndroid Build Coastguard Worker     uint32_t metaballsTex = 5;
1547*35238bceSAndroid Build Coastguard Worker     uint32_t quadsTex     = 6;
1548*35238bceSAndroid Build Coastguard Worker     createMetaballsTex2D(context, metaballsTex, GL_RGB, GL_UNSIGNED_BYTE, 64, 64);
1549*35238bceSAndroid Build Coastguard Worker     createQuadsTex2D(context, quadsTex, GL_RGB, GL_UNSIGNED_BYTE, 64, 64);
1550*35238bceSAndroid Build Coastguard Worker 
1551*35238bceSAndroid Build Coastguard Worker     context.viewport(0, 0, width, height);
1552*35238bceSAndroid Build Coastguard Worker 
1553*35238bceSAndroid Build Coastguard Worker     // Fbo A
1554*35238bceSAndroid Build Coastguard Worker     Framebuffer fboA(context, getConfig(), width, height);
1555*35238bceSAndroid Build Coastguard Worker     fboA.checkCompleteness();
1556*35238bceSAndroid Build Coastguard Worker 
1557*35238bceSAndroid Build Coastguard Worker     // Fbo B
1558*35238bceSAndroid Build Coastguard Worker     FboConfig cfg         = getConfig();
1559*35238bceSAndroid Build Coastguard Worker     cfg.depthbufferType   = GL_NONE;
1560*35238bceSAndroid Build Coastguard Worker     cfg.depthbufferFormat = GL_NONE;
1561*35238bceSAndroid Build Coastguard Worker     Framebuffer fboB(context, cfg, width, height);
1562*35238bceSAndroid Build Coastguard Worker 
1563*35238bceSAndroid Build Coastguard Worker     // Bind depth buffer from fbo A to fbo B
1564*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(fboA.getConfig().depthbufferType == GL_RENDERBUFFER);
1565*35238bceSAndroid Build Coastguard Worker     context.bindFramebuffer(GL_FRAMEBUFFER, fboB.getFramebuffer());
1566*35238bceSAndroid Build Coastguard Worker     context.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fboA.getDepthbuffer());
1567*35238bceSAndroid Build Coastguard Worker 
1568*35238bceSAndroid Build Coastguard Worker     // Clear fbo B color to red and stencil to 1
1569*35238bceSAndroid Build Coastguard Worker     context.clearColor(1.0f, 0.0f, 0.0f, 1.0f);
1570*35238bceSAndroid Build Coastguard Worker     context.clearStencil(1);
1571*35238bceSAndroid Build Coastguard Worker     context.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1572*35238bceSAndroid Build Coastguard Worker 
1573*35238bceSAndroid Build Coastguard Worker     // Enable depth test.
1574*35238bceSAndroid Build Coastguard Worker     context.enable(GL_DEPTH_TEST);
1575*35238bceSAndroid Build Coastguard Worker 
1576*35238bceSAndroid Build Coastguard Worker     // Render quad to fbo A
1577*35238bceSAndroid Build Coastguard Worker     context.bindFramebuffer(GL_FRAMEBUFFER, fboA.getFramebuffer());
1578*35238bceSAndroid Build Coastguard Worker     context.bindTexture(GL_TEXTURE_2D, quadsTex);
1579*35238bceSAndroid Build Coastguard Worker     context.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
1580*35238bceSAndroid Build Coastguard Worker     context.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1581*35238bceSAndroid Build Coastguard Worker     sglr::drawQuad(context, texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
1582*35238bceSAndroid Build Coastguard Worker 
1583*35238bceSAndroid Build Coastguard Worker     // Render metaballs to fbo B
1584*35238bceSAndroid Build Coastguard Worker     context.bindFramebuffer(GL_FRAMEBUFFER, fboB.getFramebuffer());
1585*35238bceSAndroid Build Coastguard Worker     context.bindTexture(GL_TEXTURE_2D, metaballsTex);
1586*35238bceSAndroid Build Coastguard Worker     sglr::drawQuad(context, texShaderID, Vec3(-1.0f, -1.0f, -1.0f), Vec3(1.0f, 1.0f, 1.0f));
1587*35238bceSAndroid Build Coastguard Worker 
1588*35238bceSAndroid Build Coastguard Worker     context.disable(GL_DEPTH_TEST);
1589*35238bceSAndroid Build Coastguard Worker 
1590*35238bceSAndroid Build Coastguard Worker     if (stencil)
1591*35238bceSAndroid Build Coastguard Worker     {
1592*35238bceSAndroid Build Coastguard Worker         // Clear subset of stencil buffer to 0
1593*35238bceSAndroid Build Coastguard Worker         context.enable(GL_SCISSOR_TEST);
1594*35238bceSAndroid Build Coastguard Worker         context.scissor(10, 10, 12, 25);
1595*35238bceSAndroid Build Coastguard Worker         context.clearStencil(0);
1596*35238bceSAndroid Build Coastguard Worker         context.clear(GL_STENCIL_BUFFER_BIT);
1597*35238bceSAndroid Build Coastguard Worker         context.disable(GL_SCISSOR_TEST);
1598*35238bceSAndroid Build Coastguard Worker 
1599*35238bceSAndroid Build Coastguard Worker         // Render quad with stencil mask == 0
1600*35238bceSAndroid Build Coastguard Worker         context.enable(GL_STENCIL_TEST);
1601*35238bceSAndroid Build Coastguard Worker         context.stencilFunc(GL_EQUAL, 0, 0xffu);
1602*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(context, colorShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
1603*35238bceSAndroid Build Coastguard Worker         context.disable(GL_STENCIL_TEST);
1604*35238bceSAndroid Build Coastguard Worker     }
1605*35238bceSAndroid Build Coastguard Worker 
1606*35238bceSAndroid Build Coastguard Worker     if (getConfig().colorbufferType == GL_TEXTURE_2D)
1607*35238bceSAndroid Build Coastguard Worker     {
1608*35238bceSAndroid Build Coastguard Worker         // Render both to screen
1609*35238bceSAndroid Build Coastguard Worker         context.bindFramebuffer(GL_FRAMEBUFFER, 0);
1610*35238bceSAndroid Build Coastguard Worker         context.viewport(0, 0, context.getWidth(), context.getHeight());
1611*35238bceSAndroid Build Coastguard Worker         context.bindTexture(GL_TEXTURE_2D, fboA.getColorbuffer());
1612*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(context, texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(0.0f, 1.0f, 0.0f));
1613*35238bceSAndroid Build Coastguard Worker         context.bindTexture(GL_TEXTURE_2D, fboB.getColorbuffer());
1614*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(context, texShaderID, Vec3(0.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
1615*35238bceSAndroid Build Coastguard Worker 
1616*35238bceSAndroid Build Coastguard Worker         context.readPixels(dst, 0, 0, context.getWidth(), context.getHeight());
1617*35238bceSAndroid Build Coastguard Worker     }
1618*35238bceSAndroid Build Coastguard Worker     else
1619*35238bceSAndroid Build Coastguard Worker     {
1620*35238bceSAndroid Build Coastguard Worker         // Read results from fbo B
1621*35238bceSAndroid Build Coastguard Worker         context.readPixels(dst, 0, 0, width, height);
1622*35238bceSAndroid Build Coastguard Worker     }
1623*35238bceSAndroid Build Coastguard Worker }
1624*35238bceSAndroid Build Coastguard Worker 
1625*35238bceSAndroid Build Coastguard Worker class TexSubImageAfterRenderTest : public FboRenderCase
1626*35238bceSAndroid Build Coastguard Worker {
1627*35238bceSAndroid Build Coastguard Worker public:
1628*35238bceSAndroid Build Coastguard Worker     TexSubImageAfterRenderTest(Context &context, const FboConfig &config);
~TexSubImageAfterRenderTest(void)1629*35238bceSAndroid Build Coastguard Worker     virtual ~TexSubImageAfterRenderTest(void)
1630*35238bceSAndroid Build Coastguard Worker     {
1631*35238bceSAndroid Build Coastguard Worker     }
1632*35238bceSAndroid Build Coastguard Worker 
1633*35238bceSAndroid Build Coastguard Worker     static bool isConfigSupported(const FboConfig &config);
1634*35238bceSAndroid Build Coastguard Worker     void render(sglr::Context &context, Surface &dst);
1635*35238bceSAndroid Build Coastguard Worker };
1636*35238bceSAndroid Build Coastguard Worker 
TexSubImageAfterRenderTest(Context & context,const FboConfig & config)1637*35238bceSAndroid Build Coastguard Worker TexSubImageAfterRenderTest::TexSubImageAfterRenderTest(Context &context, const FboConfig &config)
1638*35238bceSAndroid Build Coastguard Worker     : FboRenderCase(context, (string("after_render_") + config.getName()).c_str(),
1639*35238bceSAndroid Build Coastguard Worker                     "TexSubImage after rendering to texture", config)
1640*35238bceSAndroid Build Coastguard Worker {
1641*35238bceSAndroid Build Coastguard Worker }
1642*35238bceSAndroid Build Coastguard Worker 
isConfigSupported(const FboConfig & config)1643*35238bceSAndroid Build Coastguard Worker bool TexSubImageAfterRenderTest::isConfigSupported(const FboConfig &config)
1644*35238bceSAndroid Build Coastguard Worker {
1645*35238bceSAndroid Build Coastguard Worker     return config.colorbufferType == GL_TEXTURE_2D &&
1646*35238bceSAndroid Build Coastguard Worker            (config.colorbufferFormat == GL_RGB || config.colorbufferFormat == GL_RGBA) &&
1647*35238bceSAndroid Build Coastguard Worker            config.depthbufferType == GL_NONE && config.stencilbufferType == GL_NONE;
1648*35238bceSAndroid Build Coastguard Worker }
1649*35238bceSAndroid Build Coastguard Worker 
render(sglr::Context & context,Surface & dst)1650*35238bceSAndroid Build Coastguard Worker void TexSubImageAfterRenderTest::render(sglr::Context &context, Surface &dst)
1651*35238bceSAndroid Build Coastguard Worker {
1652*35238bceSAndroid Build Coastguard Worker     SingleTex2DShader shader;
1653*35238bceSAndroid Build Coastguard Worker     uint32_t shaderID = context.createProgram(&shader);
1654*35238bceSAndroid Build Coastguard Worker     bool isRGBA       = getConfig().colorbufferFormat == GL_RGBA;
1655*35238bceSAndroid Build Coastguard Worker 
1656*35238bceSAndroid Build Coastguard Worker     tcu::TextureLevel fourQuads(tcu::TextureFormat(tcu::TextureFormat::RGB, tcu::TextureFormat::UNORM_INT8), 64, 64);
1657*35238bceSAndroid Build Coastguard Worker     tcu::fillWithRGBAQuads(fourQuads.getAccess());
1658*35238bceSAndroid Build Coastguard Worker 
1659*35238bceSAndroid Build Coastguard Worker     tcu::TextureLevel metaballs(
1660*35238bceSAndroid Build Coastguard Worker         tcu::TextureFormat(isRGBA ? tcu::TextureFormat::RGBA : tcu::TextureFormat::RGB, tcu::TextureFormat::UNORM_INT8),
1661*35238bceSAndroid Build Coastguard Worker         64, 64);
1662*35238bceSAndroid Build Coastguard Worker     tcu::fillWithMetaballs(metaballs.getAccess(), 5, 3);
1663*35238bceSAndroid Build Coastguard Worker 
1664*35238bceSAndroid Build Coastguard Worker     shader.setUnit(context, shaderID, 0);
1665*35238bceSAndroid Build Coastguard Worker 
1666*35238bceSAndroid Build Coastguard Worker     uint32_t fourQuadsTex = 1;
1667*35238bceSAndroid Build Coastguard Worker     context.bindTexture(GL_TEXTURE_2D, fourQuadsTex);
1668*35238bceSAndroid Build Coastguard Worker     context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1669*35238bceSAndroid Build Coastguard Worker     context.texImage2D(GL_TEXTURE_2D, 0, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE,
1670*35238bceSAndroid Build Coastguard Worker                        fourQuads.getAccess().getDataPtr());
1671*35238bceSAndroid Build Coastguard Worker 
1672*35238bceSAndroid Build Coastguard Worker     context.bindFramebuffer(GL_FRAMEBUFFER, 1);
1673*35238bceSAndroid Build Coastguard Worker 
1674*35238bceSAndroid Build Coastguard Worker     uint32_t fboTex = 2;
1675*35238bceSAndroid Build Coastguard Worker     context.bindTexture(GL_TEXTURE_2D, fboTex);
1676*35238bceSAndroid Build Coastguard Worker     context.texImage2D(GL_TEXTURE_2D, 0, isRGBA ? GL_RGBA : GL_RGB, 128, 128);
1677*35238bceSAndroid Build Coastguard Worker     context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1678*35238bceSAndroid Build Coastguard Worker     context.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fboTex, 0);
1679*35238bceSAndroid Build Coastguard Worker 
1680*35238bceSAndroid Build Coastguard Worker     // Render to fbo
1681*35238bceSAndroid Build Coastguard Worker     context.viewport(0, 0, 128, 128);
1682*35238bceSAndroid Build Coastguard Worker     context.bindTexture(GL_TEXTURE_2D, fourQuadsTex);
1683*35238bceSAndroid Build Coastguard Worker     sglr::drawQuad(context, shaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
1684*35238bceSAndroid Build Coastguard Worker 
1685*35238bceSAndroid Build Coastguard Worker     // Update texture using TexSubImage2D
1686*35238bceSAndroid Build Coastguard Worker     context.bindTexture(GL_TEXTURE_2D, fboTex);
1687*35238bceSAndroid Build Coastguard Worker     context.texSubImage2D(GL_TEXTURE_2D, 0, 32, 32, 64, 64, isRGBA ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE,
1688*35238bceSAndroid Build Coastguard Worker                           metaballs.getAccess().getDataPtr());
1689*35238bceSAndroid Build Coastguard Worker 
1690*35238bceSAndroid Build Coastguard Worker     // Draw to screen
1691*35238bceSAndroid Build Coastguard Worker     context.bindFramebuffer(GL_FRAMEBUFFER, 0);
1692*35238bceSAndroid Build Coastguard Worker     context.viewport(0, 0, context.getWidth(), context.getHeight());
1693*35238bceSAndroid Build Coastguard Worker     sglr::drawQuad(context, shaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
1694*35238bceSAndroid Build Coastguard Worker     context.readPixels(dst, 0, 0, context.getWidth(), context.getHeight());
1695*35238bceSAndroid Build Coastguard Worker }
1696*35238bceSAndroid Build Coastguard Worker 
1697*35238bceSAndroid Build Coastguard Worker class TexSubImageBetweenRenderTest : public FboRenderCase
1698*35238bceSAndroid Build Coastguard Worker {
1699*35238bceSAndroid Build Coastguard Worker public:
1700*35238bceSAndroid Build Coastguard Worker     TexSubImageBetweenRenderTest(Context &context, const FboConfig &config);
~TexSubImageBetweenRenderTest(void)1701*35238bceSAndroid Build Coastguard Worker     virtual ~TexSubImageBetweenRenderTest(void)
1702*35238bceSAndroid Build Coastguard Worker     {
1703*35238bceSAndroid Build Coastguard Worker     }
1704*35238bceSAndroid Build Coastguard Worker 
1705*35238bceSAndroid Build Coastguard Worker     static bool isConfigSupported(const FboConfig &config);
1706*35238bceSAndroid Build Coastguard Worker     void render(sglr::Context &context, Surface &dst);
1707*35238bceSAndroid Build Coastguard Worker };
1708*35238bceSAndroid Build Coastguard Worker 
TexSubImageBetweenRenderTest(Context & context,const FboConfig & config)1709*35238bceSAndroid Build Coastguard Worker TexSubImageBetweenRenderTest::TexSubImageBetweenRenderTest(Context &context, const FboConfig &config)
1710*35238bceSAndroid Build Coastguard Worker     : FboRenderCase(context, (string("between_render_") + config.getName()).c_str(),
1711*35238bceSAndroid Build Coastguard Worker                     "TexSubImage between rendering calls", config)
1712*35238bceSAndroid Build Coastguard Worker {
1713*35238bceSAndroid Build Coastguard Worker }
1714*35238bceSAndroid Build Coastguard Worker 
isConfigSupported(const FboConfig & config)1715*35238bceSAndroid Build Coastguard Worker bool TexSubImageBetweenRenderTest::isConfigSupported(const FboConfig &config)
1716*35238bceSAndroid Build Coastguard Worker {
1717*35238bceSAndroid Build Coastguard Worker     return config.colorbufferType == GL_TEXTURE_2D &&
1718*35238bceSAndroid Build Coastguard Worker            (config.colorbufferFormat == GL_RGB || config.colorbufferFormat == GL_RGBA) &&
1719*35238bceSAndroid Build Coastguard Worker            config.depthbufferType == GL_NONE && config.stencilbufferType == GL_NONE;
1720*35238bceSAndroid Build Coastguard Worker }
1721*35238bceSAndroid Build Coastguard Worker 
render(sglr::Context & context,Surface & dst)1722*35238bceSAndroid Build Coastguard Worker void TexSubImageBetweenRenderTest::render(sglr::Context &context, Surface &dst)
1723*35238bceSAndroid Build Coastguard Worker {
1724*35238bceSAndroid Build Coastguard Worker     SingleTex2DShader shader;
1725*35238bceSAndroid Build Coastguard Worker     uint32_t shaderID = context.createProgram(&shader);
1726*35238bceSAndroid Build Coastguard Worker     bool isRGBA       = getConfig().colorbufferFormat == GL_RGBA;
1727*35238bceSAndroid Build Coastguard Worker 
1728*35238bceSAndroid Build Coastguard Worker     tcu::TextureLevel fourQuads(tcu::TextureFormat(tcu::TextureFormat::RGB, tcu::TextureFormat::UNORM_INT8), 64, 64);
1729*35238bceSAndroid Build Coastguard Worker     tcu::fillWithRGBAQuads(fourQuads.getAccess());
1730*35238bceSAndroid Build Coastguard Worker 
1731*35238bceSAndroid Build Coastguard Worker     tcu::TextureLevel metaballs(
1732*35238bceSAndroid Build Coastguard Worker         tcu::TextureFormat(isRGBA ? tcu::TextureFormat::RGBA : tcu::TextureFormat::RGB, tcu::TextureFormat::UNORM_INT8),
1733*35238bceSAndroid Build Coastguard Worker         64, 64);
1734*35238bceSAndroid Build Coastguard Worker     tcu::fillWithMetaballs(metaballs.getAccess(), 5, 3);
1735*35238bceSAndroid Build Coastguard Worker 
1736*35238bceSAndroid Build Coastguard Worker     tcu::TextureLevel metaballs2(tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), 64, 64);
1737*35238bceSAndroid Build Coastguard Worker     tcu::fillWithMetaballs(metaballs2.getAccess(), 5, 4);
1738*35238bceSAndroid Build Coastguard Worker 
1739*35238bceSAndroid Build Coastguard Worker     uint32_t metaballsTex = 3;
1740*35238bceSAndroid Build Coastguard Worker     context.bindTexture(GL_TEXTURE_2D, metaballsTex);
1741*35238bceSAndroid Build Coastguard Worker     context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1742*35238bceSAndroid Build Coastguard Worker     context.texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1743*35238bceSAndroid Build Coastguard Worker                        metaballs2.getAccess().getDataPtr());
1744*35238bceSAndroid Build Coastguard Worker 
1745*35238bceSAndroid Build Coastguard Worker     uint32_t fourQuadsTex = 1;
1746*35238bceSAndroid Build Coastguard Worker     context.bindTexture(GL_TEXTURE_2D, fourQuadsTex);
1747*35238bceSAndroid Build Coastguard Worker     context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1748*35238bceSAndroid Build Coastguard Worker     context.texImage2D(GL_TEXTURE_2D, 0, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE,
1749*35238bceSAndroid Build Coastguard Worker                        fourQuads.getAccess().getDataPtr());
1750*35238bceSAndroid Build Coastguard Worker 
1751*35238bceSAndroid Build Coastguard Worker     context.bindFramebuffer(GL_FRAMEBUFFER, 1);
1752*35238bceSAndroid Build Coastguard Worker 
1753*35238bceSAndroid Build Coastguard Worker     uint32_t fboTex = 2;
1754*35238bceSAndroid Build Coastguard Worker     context.bindTexture(GL_TEXTURE_2D, fboTex);
1755*35238bceSAndroid Build Coastguard Worker     context.texImage2D(GL_TEXTURE_2D, 0, isRGBA ? GL_RGBA : GL_RGB, 128, 128);
1756*35238bceSAndroid Build Coastguard Worker     context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1757*35238bceSAndroid Build Coastguard Worker     context.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fboTex, 0);
1758*35238bceSAndroid Build Coastguard Worker 
1759*35238bceSAndroid Build Coastguard Worker     shader.setUnit(context, shaderID, 0);
1760*35238bceSAndroid Build Coastguard Worker 
1761*35238bceSAndroid Build Coastguard Worker     // Render to fbo
1762*35238bceSAndroid Build Coastguard Worker     context.viewport(0, 0, 128, 128);
1763*35238bceSAndroid Build Coastguard Worker     context.bindTexture(GL_TEXTURE_2D, fourQuadsTex);
1764*35238bceSAndroid Build Coastguard Worker     sglr::drawQuad(context, shaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
1765*35238bceSAndroid Build Coastguard Worker 
1766*35238bceSAndroid Build Coastguard Worker     // Update texture using TexSubImage2D
1767*35238bceSAndroid Build Coastguard Worker     context.bindTexture(GL_TEXTURE_2D, fboTex);
1768*35238bceSAndroid Build Coastguard Worker     context.texSubImage2D(GL_TEXTURE_2D, 0, 32, 32, 64, 64, isRGBA ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE,
1769*35238bceSAndroid Build Coastguard Worker                           metaballs.getAccess().getDataPtr());
1770*35238bceSAndroid Build Coastguard Worker 
1771*35238bceSAndroid Build Coastguard Worker     // Render again to fbo
1772*35238bceSAndroid Build Coastguard Worker     context.bindTexture(GL_TEXTURE_2D, metaballsTex);
1773*35238bceSAndroid Build Coastguard Worker     context.enable(GL_BLEND);
1774*35238bceSAndroid Build Coastguard Worker     context.blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE);
1775*35238bceSAndroid Build Coastguard Worker     sglr::drawQuad(context, shaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
1776*35238bceSAndroid Build Coastguard Worker     context.disable(GL_BLEND);
1777*35238bceSAndroid Build Coastguard Worker 
1778*35238bceSAndroid Build Coastguard Worker     // Draw to screen
1779*35238bceSAndroid Build Coastguard Worker     context.bindFramebuffer(GL_FRAMEBUFFER, 0);
1780*35238bceSAndroid Build Coastguard Worker     context.viewport(0, 0, context.getWidth(), context.getHeight());
1781*35238bceSAndroid Build Coastguard Worker     context.bindTexture(GL_TEXTURE_2D, fboTex);
1782*35238bceSAndroid Build Coastguard Worker     sglr::drawQuad(context, shaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
1783*35238bceSAndroid Build Coastguard Worker 
1784*35238bceSAndroid Build Coastguard Worker     context.readPixels(dst, 0, 0, context.getWidth(), context.getHeight());
1785*35238bceSAndroid Build Coastguard Worker }
1786*35238bceSAndroid Build Coastguard Worker 
1787*35238bceSAndroid Build Coastguard Worker class ResizeTest : public FboRenderCase
1788*35238bceSAndroid Build Coastguard Worker {
1789*35238bceSAndroid Build Coastguard Worker public:
1790*35238bceSAndroid Build Coastguard Worker     ResizeTest(Context &context, const FboConfig &config);
~ResizeTest(void)1791*35238bceSAndroid Build Coastguard Worker     virtual ~ResizeTest(void)
1792*35238bceSAndroid Build Coastguard Worker     {
1793*35238bceSAndroid Build Coastguard Worker     }
1794*35238bceSAndroid Build Coastguard Worker 
1795*35238bceSAndroid Build Coastguard Worker     void render(sglr::Context &context, Surface &dst);
1796*35238bceSAndroid Build Coastguard Worker };
1797*35238bceSAndroid Build Coastguard Worker 
ResizeTest(Context & context,const FboConfig & config)1798*35238bceSAndroid Build Coastguard Worker ResizeTest::ResizeTest(Context &context, const FboConfig &config)
1799*35238bceSAndroid Build Coastguard Worker     : FboRenderCase(context, config.getName().c_str(), "Resize framebuffer", config)
1800*35238bceSAndroid Build Coastguard Worker {
1801*35238bceSAndroid Build Coastguard Worker }
1802*35238bceSAndroid Build Coastguard Worker 
render(sglr::Context & context,Surface & dst)1803*35238bceSAndroid Build Coastguard Worker void ResizeTest::render(sglr::Context &context, Surface &dst)
1804*35238bceSAndroid Build Coastguard Worker {
1805*35238bceSAndroid Build Coastguard Worker     SingleTex2DShader texShader;
1806*35238bceSAndroid Build Coastguard Worker     FlatColorShader colorShader;
1807*35238bceSAndroid Build Coastguard Worker     uint32_t texShaderID   = context.createProgram(&texShader);
1808*35238bceSAndroid Build Coastguard Worker     uint32_t colorShaderID = context.createProgram(&colorShader);
1809*35238bceSAndroid Build Coastguard Worker     uint32_t quadsTex      = 1;
1810*35238bceSAndroid Build Coastguard Worker     uint32_t metaballsTex  = 2;
1811*35238bceSAndroid Build Coastguard Worker     bool depth             = getConfig().depthbufferType != GL_NONE;
1812*35238bceSAndroid Build Coastguard Worker     bool stencil           = getConfig().stencilbufferType != GL_NONE;
1813*35238bceSAndroid Build Coastguard Worker 
1814*35238bceSAndroid Build Coastguard Worker     createQuadsTex2D(context, quadsTex, GL_RGB, GL_UNSIGNED_BYTE, 64, 64);
1815*35238bceSAndroid Build Coastguard Worker     createMetaballsTex2D(context, metaballsTex, GL_RGB, GL_UNSIGNED_BYTE, 32, 32);
1816*35238bceSAndroid Build Coastguard Worker 
1817*35238bceSAndroid Build Coastguard Worker     Framebuffer fbo(context, getConfig(), 128, 128);
1818*35238bceSAndroid Build Coastguard Worker     fbo.checkCompleteness();
1819*35238bceSAndroid Build Coastguard Worker 
1820*35238bceSAndroid Build Coastguard Worker     // Setup shaders
1821*35238bceSAndroid Build Coastguard Worker     texShader.setUnit(context, texShaderID, 0);
1822*35238bceSAndroid Build Coastguard Worker     colorShader.setColor(context, colorShaderID, Vec4(0.0f, 1.0f, 0.0f, 1.0f));
1823*35238bceSAndroid Build Coastguard Worker 
1824*35238bceSAndroid Build Coastguard Worker     // Render quads
1825*35238bceSAndroid Build Coastguard Worker     context.bindFramebuffer(GL_FRAMEBUFFER, fbo.getFramebuffer());
1826*35238bceSAndroid Build Coastguard Worker     context.viewport(0, 0, 128, 128);
1827*35238bceSAndroid Build Coastguard Worker     context.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
1828*35238bceSAndroid Build Coastguard Worker     context.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1829*35238bceSAndroid Build Coastguard Worker     context.bindTexture(GL_TEXTURE_2D, quadsTex);
1830*35238bceSAndroid Build Coastguard Worker     sglr::drawQuad(context, texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
1831*35238bceSAndroid Build Coastguard Worker 
1832*35238bceSAndroid Build Coastguard Worker     if (fbo.getConfig().colorbufferType == GL_TEXTURE_2D)
1833*35238bceSAndroid Build Coastguard Worker     {
1834*35238bceSAndroid Build Coastguard Worker         // Render fbo to screen
1835*35238bceSAndroid Build Coastguard Worker         context.bindFramebuffer(GL_FRAMEBUFFER, 0);
1836*35238bceSAndroid Build Coastguard Worker         context.viewport(0, 0, context.getWidth(), context.getHeight());
1837*35238bceSAndroid Build Coastguard Worker         context.bindTexture(GL_TEXTURE_2D, fbo.getColorbuffer());
1838*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(context, texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
1839*35238bceSAndroid Build Coastguard Worker 
1840*35238bceSAndroid Build Coastguard Worker         // Restore binding
1841*35238bceSAndroid Build Coastguard Worker         context.bindFramebuffer(GL_FRAMEBUFFER, fbo.getFramebuffer());
1842*35238bceSAndroid Build Coastguard Worker     }
1843*35238bceSAndroid Build Coastguard Worker 
1844*35238bceSAndroid Build Coastguard Worker     int newWidth  = 64;
1845*35238bceSAndroid Build Coastguard Worker     int newHeight = 32;
1846*35238bceSAndroid Build Coastguard Worker 
1847*35238bceSAndroid Build Coastguard Worker     // Resize buffers
1848*35238bceSAndroid Build Coastguard Worker     switch (fbo.getConfig().colorbufferType)
1849*35238bceSAndroid Build Coastguard Worker     {
1850*35238bceSAndroid Build Coastguard Worker     case GL_TEXTURE_2D:
1851*35238bceSAndroid Build Coastguard Worker         context.bindTexture(GL_TEXTURE_2D, fbo.getColorbuffer());
1852*35238bceSAndroid Build Coastguard Worker         context.texImage2D(GL_TEXTURE_2D, 0, fbo.getConfig().colorbufferFormat, newWidth, newHeight);
1853*35238bceSAndroid Build Coastguard Worker         break;
1854*35238bceSAndroid Build Coastguard Worker 
1855*35238bceSAndroid Build Coastguard Worker     case GL_RENDERBUFFER:
1856*35238bceSAndroid Build Coastguard Worker         context.bindRenderbuffer(GL_RENDERBUFFER, fbo.getColorbuffer());
1857*35238bceSAndroid Build Coastguard Worker         context.renderbufferStorage(GL_RENDERBUFFER, fbo.getConfig().colorbufferFormat, newWidth, newHeight);
1858*35238bceSAndroid Build Coastguard Worker         break;
1859*35238bceSAndroid Build Coastguard Worker 
1860*35238bceSAndroid Build Coastguard Worker     default:
1861*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(false);
1862*35238bceSAndroid Build Coastguard Worker     }
1863*35238bceSAndroid Build Coastguard Worker 
1864*35238bceSAndroid Build Coastguard Worker     if (depth)
1865*35238bceSAndroid Build Coastguard Worker     {
1866*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(fbo.getConfig().depthbufferType == GL_RENDERBUFFER);
1867*35238bceSAndroid Build Coastguard Worker         context.bindRenderbuffer(GL_RENDERBUFFER, fbo.getDepthbuffer());
1868*35238bceSAndroid Build Coastguard Worker         context.renderbufferStorage(GL_RENDERBUFFER, fbo.getConfig().depthbufferFormat, newWidth, newHeight);
1869*35238bceSAndroid Build Coastguard Worker     }
1870*35238bceSAndroid Build Coastguard Worker 
1871*35238bceSAndroid Build Coastguard Worker     if (stencil)
1872*35238bceSAndroid Build Coastguard Worker     {
1873*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(fbo.getConfig().stencilbufferType == GL_RENDERBUFFER);
1874*35238bceSAndroid Build Coastguard Worker         context.bindRenderbuffer(GL_RENDERBUFFER, fbo.getStencilbuffer());
1875*35238bceSAndroid Build Coastguard Worker         context.renderbufferStorage(GL_RENDERBUFFER, fbo.getConfig().stencilbufferFormat, newWidth, newHeight);
1876*35238bceSAndroid Build Coastguard Worker     }
1877*35238bceSAndroid Build Coastguard Worker 
1878*35238bceSAndroid Build Coastguard Worker     // Render to resized fbo
1879*35238bceSAndroid Build Coastguard Worker     context.viewport(0, 0, newWidth, newHeight);
1880*35238bceSAndroid Build Coastguard Worker     context.clearColor(1.0f, 0.0f, 0.0f, 1.0f);
1881*35238bceSAndroid Build Coastguard Worker     context.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1882*35238bceSAndroid Build Coastguard Worker 
1883*35238bceSAndroid Build Coastguard Worker     context.enable(GL_DEPTH_TEST);
1884*35238bceSAndroid Build Coastguard Worker 
1885*35238bceSAndroid Build Coastguard Worker     context.bindTexture(GL_TEXTURE_2D, metaballsTex);
1886*35238bceSAndroid Build Coastguard Worker     sglr::drawQuad(context, texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(+1.0f, +1.0f, 0.0f));
1887*35238bceSAndroid Build Coastguard Worker 
1888*35238bceSAndroid Build Coastguard Worker     context.bindTexture(GL_TEXTURE_2D, quadsTex);
1889*35238bceSAndroid Build Coastguard Worker     sglr::drawQuad(context, texShaderID, Vec3(0.0f, 0.0f, -1.0f), Vec3(+1.0f, +1.0f, 1.0f));
1890*35238bceSAndroid Build Coastguard Worker 
1891*35238bceSAndroid Build Coastguard Worker     context.disable(GL_DEPTH_TEST);
1892*35238bceSAndroid Build Coastguard Worker 
1893*35238bceSAndroid Build Coastguard Worker     if (stencil)
1894*35238bceSAndroid Build Coastguard Worker     {
1895*35238bceSAndroid Build Coastguard Worker         context.enable(GL_SCISSOR_TEST);
1896*35238bceSAndroid Build Coastguard Worker         context.scissor(10, 10, 5, 15);
1897*35238bceSAndroid Build Coastguard Worker         context.clearStencil(1);
1898*35238bceSAndroid Build Coastguard Worker         context.clear(GL_STENCIL_BUFFER_BIT);
1899*35238bceSAndroid Build Coastguard Worker         context.disable(GL_SCISSOR_TEST);
1900*35238bceSAndroid Build Coastguard Worker 
1901*35238bceSAndroid Build Coastguard Worker         context.enable(GL_STENCIL_TEST);
1902*35238bceSAndroid Build Coastguard Worker         context.stencilFunc(GL_EQUAL, 1, 0xffu);
1903*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(context, colorShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(+1.0f, +1.0f, 0.0f));
1904*35238bceSAndroid Build Coastguard Worker         context.disable(GL_STENCIL_TEST);
1905*35238bceSAndroid Build Coastguard Worker     }
1906*35238bceSAndroid Build Coastguard Worker 
1907*35238bceSAndroid Build Coastguard Worker     if (getConfig().colorbufferType == GL_TEXTURE_2D)
1908*35238bceSAndroid Build Coastguard Worker     {
1909*35238bceSAndroid Build Coastguard Worker         context.bindFramebuffer(GL_FRAMEBUFFER, 0);
1910*35238bceSAndroid Build Coastguard Worker         context.viewport(0, 0, context.getWidth(), context.getHeight());
1911*35238bceSAndroid Build Coastguard Worker         context.bindTexture(GL_TEXTURE_2D, fbo.getColorbuffer());
1912*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(context, texShaderID, Vec3(-0.5f, -0.5f, 0.0f), Vec3(0.5f, 0.5f, 0.0f));
1913*35238bceSAndroid Build Coastguard Worker         context.readPixels(dst, 0, 0, context.getWidth(), context.getHeight());
1914*35238bceSAndroid Build Coastguard Worker     }
1915*35238bceSAndroid Build Coastguard Worker     else
1916*35238bceSAndroid Build Coastguard Worker         context.readPixels(dst, 0, 0, newWidth, newHeight);
1917*35238bceSAndroid Build Coastguard Worker }
1918*35238bceSAndroid Build Coastguard Worker 
1919*35238bceSAndroid Build Coastguard Worker template <GLenum Buffers>
1920*35238bceSAndroid Build Coastguard Worker class RecreateBuffersTest : public FboRenderCase
1921*35238bceSAndroid Build Coastguard Worker {
1922*35238bceSAndroid Build Coastguard Worker public:
1923*35238bceSAndroid Build Coastguard Worker     RecreateBuffersTest(Context &context, const FboConfig &config, bool rebind);
~RecreateBuffersTest(void)1924*35238bceSAndroid Build Coastguard Worker     virtual ~RecreateBuffersTest(void)
1925*35238bceSAndroid Build Coastguard Worker     {
1926*35238bceSAndroid Build Coastguard Worker     }
1927*35238bceSAndroid Build Coastguard Worker 
1928*35238bceSAndroid Build Coastguard Worker     static bool isConfigSupported(const FboConfig &config);
1929*35238bceSAndroid Build Coastguard Worker     void render(sglr::Context &context, Surface &dst);
1930*35238bceSAndroid Build Coastguard Worker 
1931*35238bceSAndroid Build Coastguard Worker private:
1932*35238bceSAndroid Build Coastguard Worker     bool m_rebind;
1933*35238bceSAndroid Build Coastguard Worker };
1934*35238bceSAndroid Build Coastguard Worker 
1935*35238bceSAndroid Build Coastguard Worker template <GLenum Buffers>
1936*35238bceSAndroid Build Coastguard Worker class RecreateBuffersNoRebindTest : public RecreateBuffersTest<Buffers>
1937*35238bceSAndroid Build Coastguard Worker {
1938*35238bceSAndroid Build Coastguard Worker public:
RecreateBuffersNoRebindTest(Context & context,const FboConfig & config)1939*35238bceSAndroid Build Coastguard Worker     RecreateBuffersNoRebindTest(Context &context, const FboConfig &config)
1940*35238bceSAndroid Build Coastguard Worker         : RecreateBuffersTest<Buffers>(context, config, false)
1941*35238bceSAndroid Build Coastguard Worker     {
1942*35238bceSAndroid Build Coastguard Worker     }
1943*35238bceSAndroid Build Coastguard Worker };
1944*35238bceSAndroid Build Coastguard Worker 
1945*35238bceSAndroid Build Coastguard Worker template <GLenum Buffers>
1946*35238bceSAndroid Build Coastguard Worker class RecreateBuffersRebindTest : public RecreateBuffersTest<Buffers>
1947*35238bceSAndroid Build Coastguard Worker {
1948*35238bceSAndroid Build Coastguard Worker public:
RecreateBuffersRebindTest(Context & context,const FboConfig & config)1949*35238bceSAndroid Build Coastguard Worker     RecreateBuffersRebindTest(Context &context, const FboConfig &config)
1950*35238bceSAndroid Build Coastguard Worker         : RecreateBuffersTest<Buffers>(context, config, true)
1951*35238bceSAndroid Build Coastguard Worker     {
1952*35238bceSAndroid Build Coastguard Worker     }
1953*35238bceSAndroid Build Coastguard Worker };
1954*35238bceSAndroid Build Coastguard Worker 
1955*35238bceSAndroid Build Coastguard Worker template <GLenum Buffers>
RecreateBuffersTest(Context & context,const FboConfig & config,bool rebind)1956*35238bceSAndroid Build Coastguard Worker RecreateBuffersTest<Buffers>::RecreateBuffersTest(Context &context, const FboConfig &config, bool rebind)
1957*35238bceSAndroid Build Coastguard Worker     : FboRenderCase(context, (string(rebind ? "rebind_" : "no_rebind_") + config.getName()).c_str(), "Recreate buffers",
1958*35238bceSAndroid Build Coastguard Worker                     config)
1959*35238bceSAndroid Build Coastguard Worker     , m_rebind(rebind)
1960*35238bceSAndroid Build Coastguard Worker {
1961*35238bceSAndroid Build Coastguard Worker }
1962*35238bceSAndroid Build Coastguard Worker 
1963*35238bceSAndroid Build Coastguard Worker template <GLenum Buffers>
isConfigSupported(const FboConfig & config)1964*35238bceSAndroid Build Coastguard Worker bool RecreateBuffersTest<Buffers>::isConfigSupported(const FboConfig &config)
1965*35238bceSAndroid Build Coastguard Worker {
1966*35238bceSAndroid Build Coastguard Worker     if ((Buffers & GL_COLOR_BUFFER_BIT) && config.colorbufferType == GL_NONE)
1967*35238bceSAndroid Build Coastguard Worker         return false;
1968*35238bceSAndroid Build Coastguard Worker     if ((Buffers & GL_DEPTH_BUFFER_BIT) && config.depthbufferType == GL_NONE)
1969*35238bceSAndroid Build Coastguard Worker         return false;
1970*35238bceSAndroid Build Coastguard Worker     if ((Buffers & GL_STENCIL_BUFFER_BIT) && config.stencilbufferType == GL_NONE)
1971*35238bceSAndroid Build Coastguard Worker         return false;
1972*35238bceSAndroid Build Coastguard Worker     return true;
1973*35238bceSAndroid Build Coastguard Worker }
1974*35238bceSAndroid Build Coastguard Worker 
1975*35238bceSAndroid Build Coastguard Worker template <GLenum Buffers>
render(sglr::Context & ctx,Surface & dst)1976*35238bceSAndroid Build Coastguard Worker void RecreateBuffersTest<Buffers>::render(sglr::Context &ctx, Surface &dst)
1977*35238bceSAndroid Build Coastguard Worker {
1978*35238bceSAndroid Build Coastguard Worker     SingleTex2DShader texShader;
1979*35238bceSAndroid Build Coastguard Worker     uint32_t texShaderID  = ctx.createProgram(&texShader);
1980*35238bceSAndroid Build Coastguard Worker     int width             = 128;
1981*35238bceSAndroid Build Coastguard Worker     int height            = 128;
1982*35238bceSAndroid Build Coastguard Worker     uint32_t metaballsTex = 1;
1983*35238bceSAndroid Build Coastguard Worker     uint32_t quadsTex     = 2;
1984*35238bceSAndroid Build Coastguard Worker     bool stencil          = getConfig().stencilbufferType != GL_NONE;
1985*35238bceSAndroid Build Coastguard Worker 
1986*35238bceSAndroid Build Coastguard Worker     createQuadsTex2D(ctx, quadsTex, GL_RGB, GL_UNSIGNED_BYTE, 64, 64);
1987*35238bceSAndroid Build Coastguard Worker     createMetaballsTex2D(ctx, metaballsTex, GL_RGB, GL_UNSIGNED_BYTE, 64, 64);
1988*35238bceSAndroid Build Coastguard Worker 
1989*35238bceSAndroid Build Coastguard Worker     Framebuffer fbo(ctx, getConfig(), width, height);
1990*35238bceSAndroid Build Coastguard Worker     fbo.checkCompleteness();
1991*35238bceSAndroid Build Coastguard Worker 
1992*35238bceSAndroid Build Coastguard Worker     // Setup shader
1993*35238bceSAndroid Build Coastguard Worker     texShader.setUnit(ctx, texShaderID, 0);
1994*35238bceSAndroid Build Coastguard Worker 
1995*35238bceSAndroid Build Coastguard Worker     // Draw scene
1996*35238bceSAndroid Build Coastguard Worker     ctx.bindFramebuffer(GL_FRAMEBUFFER, fbo.getFramebuffer());
1997*35238bceSAndroid Build Coastguard Worker     ctx.viewport(0, 0, width, height);
1998*35238bceSAndroid Build Coastguard Worker     ctx.clearColor(1.0f, 0.0f, 0.0f, 1.0f);
1999*35238bceSAndroid Build Coastguard Worker     ctx.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
2000*35238bceSAndroid Build Coastguard Worker 
2001*35238bceSAndroid Build Coastguard Worker     ctx.enable(GL_DEPTH_TEST);
2002*35238bceSAndroid Build Coastguard Worker 
2003*35238bceSAndroid Build Coastguard Worker     ctx.bindTexture(GL_TEXTURE_2D, quadsTex);
2004*35238bceSAndroid Build Coastguard Worker     sglr::drawQuad(ctx, texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
2005*35238bceSAndroid Build Coastguard Worker 
2006*35238bceSAndroid Build Coastguard Worker     if (stencil)
2007*35238bceSAndroid Build Coastguard Worker     {
2008*35238bceSAndroid Build Coastguard Worker         ctx.enable(GL_SCISSOR_TEST);
2009*35238bceSAndroid Build Coastguard Worker         ctx.scissor(width / 4, height / 4, width / 2, height / 2);
2010*35238bceSAndroid Build Coastguard Worker         ctx.clearStencil(1);
2011*35238bceSAndroid Build Coastguard Worker         ctx.clear(GL_STENCIL_BUFFER_BIT);
2012*35238bceSAndroid Build Coastguard Worker         ctx.disable(GL_SCISSOR_TEST);
2013*35238bceSAndroid Build Coastguard Worker     }
2014*35238bceSAndroid Build Coastguard Worker 
2015*35238bceSAndroid Build Coastguard Worker     // Recreate buffers
2016*35238bceSAndroid Build Coastguard Worker     if (!m_rebind)
2017*35238bceSAndroid Build Coastguard Worker         ctx.bindFramebuffer(GL_FRAMEBUFFER, 0);
2018*35238bceSAndroid Build Coastguard Worker 
2019*35238bceSAndroid Build Coastguard Worker     if (Buffers & GL_COLOR_BUFFER_BIT)
2020*35238bceSAndroid Build Coastguard Worker     {
2021*35238bceSAndroid Build Coastguard Worker         uint32_t colorbuf = fbo.getColorbuffer();
2022*35238bceSAndroid Build Coastguard Worker         switch (fbo.getConfig().colorbufferType)
2023*35238bceSAndroid Build Coastguard Worker         {
2024*35238bceSAndroid Build Coastguard Worker         case GL_TEXTURE_2D:
2025*35238bceSAndroid Build Coastguard Worker             ctx.deleteTextures(1, &colorbuf);
2026*35238bceSAndroid Build Coastguard Worker             ctx.bindTexture(GL_TEXTURE_2D, colorbuf);
2027*35238bceSAndroid Build Coastguard Worker             ctx.texImage2D(GL_TEXTURE_2D, 0, fbo.getConfig().colorbufferFormat, width, height);
2028*35238bceSAndroid Build Coastguard Worker             ctx.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
2029*35238bceSAndroid Build Coastguard Worker 
2030*35238bceSAndroid Build Coastguard Worker             if (m_rebind)
2031*35238bceSAndroid Build Coastguard Worker                 ctx.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorbuf, 0);
2032*35238bceSAndroid Build Coastguard Worker             break;
2033*35238bceSAndroid Build Coastguard Worker 
2034*35238bceSAndroid Build Coastguard Worker         case GL_RENDERBUFFER:
2035*35238bceSAndroid Build Coastguard Worker             ctx.deleteRenderbuffers(1, &colorbuf);
2036*35238bceSAndroid Build Coastguard Worker             ctx.bindRenderbuffer(GL_RENDERBUFFER, colorbuf);
2037*35238bceSAndroid Build Coastguard Worker             ctx.renderbufferStorage(GL_RENDERBUFFER, fbo.getConfig().colorbufferFormat, width, height);
2038*35238bceSAndroid Build Coastguard Worker 
2039*35238bceSAndroid Build Coastguard Worker             if (m_rebind)
2040*35238bceSAndroid Build Coastguard Worker                 ctx.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorbuf);
2041*35238bceSAndroid Build Coastguard Worker             break;
2042*35238bceSAndroid Build Coastguard Worker 
2043*35238bceSAndroid Build Coastguard Worker         default:
2044*35238bceSAndroid Build Coastguard Worker             DE_ASSERT(false);
2045*35238bceSAndroid Build Coastguard Worker         }
2046*35238bceSAndroid Build Coastguard Worker     }
2047*35238bceSAndroid Build Coastguard Worker 
2048*35238bceSAndroid Build Coastguard Worker     if (Buffers & GL_DEPTH_BUFFER_BIT)
2049*35238bceSAndroid Build Coastguard Worker     {
2050*35238bceSAndroid Build Coastguard Worker         uint32_t depthbuf = fbo.getDepthbuffer();
2051*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(fbo.getConfig().depthbufferType == GL_RENDERBUFFER);
2052*35238bceSAndroid Build Coastguard Worker 
2053*35238bceSAndroid Build Coastguard Worker         ctx.deleteRenderbuffers(1, &depthbuf);
2054*35238bceSAndroid Build Coastguard Worker         ctx.bindRenderbuffer(GL_RENDERBUFFER, depthbuf);
2055*35238bceSAndroid Build Coastguard Worker         ctx.renderbufferStorage(GL_RENDERBUFFER, fbo.getConfig().depthbufferFormat, width, height);
2056*35238bceSAndroid Build Coastguard Worker 
2057*35238bceSAndroid Build Coastguard Worker         if (m_rebind)
2058*35238bceSAndroid Build Coastguard Worker             ctx.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthbuf);
2059*35238bceSAndroid Build Coastguard Worker     }
2060*35238bceSAndroid Build Coastguard Worker 
2061*35238bceSAndroid Build Coastguard Worker     if (Buffers & GL_STENCIL_BUFFER_BIT)
2062*35238bceSAndroid Build Coastguard Worker     {
2063*35238bceSAndroid Build Coastguard Worker         uint32_t stencilbuf = fbo.getStencilbuffer();
2064*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(fbo.getConfig().stencilbufferType == GL_RENDERBUFFER);
2065*35238bceSAndroid Build Coastguard Worker 
2066*35238bceSAndroid Build Coastguard Worker         ctx.deleteRenderbuffers(1, &stencilbuf);
2067*35238bceSAndroid Build Coastguard Worker         ctx.bindRenderbuffer(GL_RENDERBUFFER, stencilbuf);
2068*35238bceSAndroid Build Coastguard Worker         ctx.renderbufferStorage(GL_RENDERBUFFER, fbo.getConfig().stencilbufferFormat, width, height);
2069*35238bceSAndroid Build Coastguard Worker 
2070*35238bceSAndroid Build Coastguard Worker         if (m_rebind)
2071*35238bceSAndroid Build Coastguard Worker             ctx.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, stencilbuf);
2072*35238bceSAndroid Build Coastguard Worker     }
2073*35238bceSAndroid Build Coastguard Worker 
2074*35238bceSAndroid Build Coastguard Worker     if (!m_rebind)
2075*35238bceSAndroid Build Coastguard Worker         ctx.bindFramebuffer(GL_FRAMEBUFFER, fbo.getFramebuffer());
2076*35238bceSAndroid Build Coastguard Worker 
2077*35238bceSAndroid Build Coastguard Worker     ctx.clearColor(0.0f, 0.0f, 1.0f, 0.0f);
2078*35238bceSAndroid Build Coastguard Worker     ctx.clearStencil(0);
2079*35238bceSAndroid Build Coastguard Worker     ctx.clear(Buffers); // \note Clear only buffers that were re-created
2080*35238bceSAndroid Build Coastguard Worker 
2081*35238bceSAndroid Build Coastguard Worker     if (stencil)
2082*35238bceSAndroid Build Coastguard Worker     {
2083*35238bceSAndroid Build Coastguard Worker         // \note Stencil test enabled only if we have stencil buffer
2084*35238bceSAndroid Build Coastguard Worker         ctx.enable(GL_STENCIL_TEST);
2085*35238bceSAndroid Build Coastguard Worker         ctx.stencilFunc(GL_EQUAL, 0, 0xffu);
2086*35238bceSAndroid Build Coastguard Worker     }
2087*35238bceSAndroid Build Coastguard Worker     ctx.bindTexture(GL_TEXTURE_2D, metaballsTex);
2088*35238bceSAndroid Build Coastguard Worker     sglr::drawQuad(ctx, texShaderID, Vec3(-1.0f, -1.0f, 1.0f), Vec3(1.0f, 1.0f, -1.0f));
2089*35238bceSAndroid Build Coastguard Worker     if (stencil)
2090*35238bceSAndroid Build Coastguard Worker         ctx.disable(GL_STENCIL_TEST);
2091*35238bceSAndroid Build Coastguard Worker 
2092*35238bceSAndroid Build Coastguard Worker     ctx.disable(GL_DEPTH_TEST);
2093*35238bceSAndroid Build Coastguard Worker 
2094*35238bceSAndroid Build Coastguard Worker     // Read from fbo
2095*35238bceSAndroid Build Coastguard Worker     ctx.readPixels(dst, 0, 0, width, height);
2096*35238bceSAndroid Build Coastguard Worker }
2097*35238bceSAndroid Build Coastguard Worker 
2098*35238bceSAndroid Build Coastguard Worker class RepeatedClearCase : public FboRenderCase
2099*35238bceSAndroid Build Coastguard Worker {
2100*35238bceSAndroid Build Coastguard Worker private:
makeConfig(uint32_t format)2101*35238bceSAndroid Build Coastguard Worker     static FboConfig makeConfig(uint32_t format)
2102*35238bceSAndroid Build Coastguard Worker     {
2103*35238bceSAndroid Build Coastguard Worker         FboConfig cfg;
2104*35238bceSAndroid Build Coastguard Worker         cfg.colorbufferType   = GL_TEXTURE_2D;
2105*35238bceSAndroid Build Coastguard Worker         cfg.colorbufferFormat = format;
2106*35238bceSAndroid Build Coastguard Worker         cfg.depthbufferType   = GL_NONE;
2107*35238bceSAndroid Build Coastguard Worker         cfg.stencilbufferType = GL_NONE;
2108*35238bceSAndroid Build Coastguard Worker         return cfg;
2109*35238bceSAndroid Build Coastguard Worker     }
2110*35238bceSAndroid Build Coastguard Worker 
2111*35238bceSAndroid Build Coastguard Worker public:
RepeatedClearCase(Context & context,uint32_t format)2112*35238bceSAndroid Build Coastguard Worker     RepeatedClearCase(Context &context, uint32_t format)
2113*35238bceSAndroid Build Coastguard Worker         : FboRenderCase(context, makeConfig(format).getName().c_str(), "Repeated clears", makeConfig(format))
2114*35238bceSAndroid Build Coastguard Worker     {
2115*35238bceSAndroid Build Coastguard Worker     }
2116*35238bceSAndroid Build Coastguard Worker 
2117*35238bceSAndroid Build Coastguard Worker protected:
render(sglr::Context & ctx,Surface & dst)2118*35238bceSAndroid Build Coastguard Worker     void render(sglr::Context &ctx, Surface &dst)
2119*35238bceSAndroid Build Coastguard Worker     {
2120*35238bceSAndroid Build Coastguard Worker         const int numRowsCols = 4;
2121*35238bceSAndroid Build Coastguard Worker         const int cellSize    = 16;
2122*35238bceSAndroid Build Coastguard Worker         const int fboSizes[]  = {cellSize, cellSize * numRowsCols};
2123*35238bceSAndroid Build Coastguard Worker 
2124*35238bceSAndroid Build Coastguard Worker         SingleTex2DShader fboBlitShader;
2125*35238bceSAndroid Build Coastguard Worker         const uint32_t fboBlitShaderID = ctx.createProgram(&fboBlitShader);
2126*35238bceSAndroid Build Coastguard Worker 
2127*35238bceSAndroid Build Coastguard Worker         de::Random rnd(18169662);
2128*35238bceSAndroid Build Coastguard Worker         uint32_t fbos[]     = {0, 0};
2129*35238bceSAndroid Build Coastguard Worker         uint32_t textures[] = {0, 0};
2130*35238bceSAndroid Build Coastguard Worker 
2131*35238bceSAndroid Build Coastguard Worker         ctx.genFramebuffers(2, &fbos[0]);
2132*35238bceSAndroid Build Coastguard Worker         ctx.genTextures(2, &textures[0]);
2133*35238bceSAndroid Build Coastguard Worker 
2134*35238bceSAndroid Build Coastguard Worker         for (int fboNdx = 0; fboNdx < DE_LENGTH_OF_ARRAY(fbos); fboNdx++)
2135*35238bceSAndroid Build Coastguard Worker         {
2136*35238bceSAndroid Build Coastguard Worker             ctx.bindTexture(GL_TEXTURE_2D, textures[fboNdx]);
2137*35238bceSAndroid Build Coastguard Worker             ctx.texImage2D(GL_TEXTURE_2D, 0, getConfig().colorbufferFormat, fboSizes[fboNdx], fboSizes[fboNdx], 0,
2138*35238bceSAndroid Build Coastguard Worker                            getConfig().colorbufferFormat, GL_UNSIGNED_BYTE, DE_NULL);
2139*35238bceSAndroid Build Coastguard Worker             ctx.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2140*35238bceSAndroid Build Coastguard Worker             ctx.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2141*35238bceSAndroid Build Coastguard Worker             ctx.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2142*35238bceSAndroid Build Coastguard Worker             ctx.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2143*35238bceSAndroid Build Coastguard Worker 
2144*35238bceSAndroid Build Coastguard Worker             ctx.bindFramebuffer(GL_FRAMEBUFFER, fbos[fboNdx]);
2145*35238bceSAndroid Build Coastguard Worker             ctx.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[fboNdx], 0);
2146*35238bceSAndroid Build Coastguard Worker 
2147*35238bceSAndroid Build Coastguard Worker             {
2148*35238bceSAndroid Build Coastguard Worker                 const GLenum status = ctx.checkFramebufferStatus(GL_FRAMEBUFFER);
2149*35238bceSAndroid Build Coastguard Worker                 if (status != GL_FRAMEBUFFER_COMPLETE)
2150*35238bceSAndroid Build Coastguard Worker                     throw FboIncompleteException(getConfig(), status, __FILE__, __LINE__);
2151*35238bceSAndroid Build Coastguard Worker             }
2152*35238bceSAndroid Build Coastguard Worker         }
2153*35238bceSAndroid Build Coastguard Worker 
2154*35238bceSAndroid Build Coastguard Worker         // larger fbo bound -- clear to transparent black
2155*35238bceSAndroid Build Coastguard Worker         ctx.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
2156*35238bceSAndroid Build Coastguard Worker         ctx.clear(GL_COLOR_BUFFER_BIT);
2157*35238bceSAndroid Build Coastguard Worker 
2158*35238bceSAndroid Build Coastguard Worker         fboBlitShader.setUnit(ctx, fboBlitShaderID, 0);
2159*35238bceSAndroid Build Coastguard Worker         ctx.bindTexture(GL_TEXTURE_2D, textures[0]);
2160*35238bceSAndroid Build Coastguard Worker 
2161*35238bceSAndroid Build Coastguard Worker         for (int cellY = 0; cellY < numRowsCols; cellY++)
2162*35238bceSAndroid Build Coastguard Worker             for (int cellX = 0; cellX < numRowsCols; cellX++)
2163*35238bceSAndroid Build Coastguard Worker             {
2164*35238bceSAndroid Build Coastguard Worker                 const float r = rnd.getFloat();
2165*35238bceSAndroid Build Coastguard Worker                 const float g = rnd.getFloat();
2166*35238bceSAndroid Build Coastguard Worker                 const float b = rnd.getFloat();
2167*35238bceSAndroid Build Coastguard Worker                 const float a = rnd.getFloat();
2168*35238bceSAndroid Build Coastguard Worker 
2169*35238bceSAndroid Build Coastguard Worker                 ctx.bindFramebuffer(GL_FRAMEBUFFER, fbos[0]);
2170*35238bceSAndroid Build Coastguard Worker                 ctx.clearColor(r, g, b, a);
2171*35238bceSAndroid Build Coastguard Worker                 ctx.clear(GL_COLOR_BUFFER_BIT);
2172*35238bceSAndroid Build Coastguard Worker 
2173*35238bceSAndroid Build Coastguard Worker                 ctx.bindFramebuffer(GL_FRAMEBUFFER, fbos[1]);
2174*35238bceSAndroid Build Coastguard Worker                 ctx.viewport(cellX * cellSize, cellY * cellSize, cellSize, cellSize);
2175*35238bceSAndroid Build Coastguard Worker                 sglr::drawQuad(ctx, fboBlitShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
2176*35238bceSAndroid Build Coastguard Worker             }
2177*35238bceSAndroid Build Coastguard Worker 
2178*35238bceSAndroid Build Coastguard Worker         ctx.readPixels(dst, 0, 0, fboSizes[1], fboSizes[1]);
2179*35238bceSAndroid Build Coastguard Worker     }
2180*35238bceSAndroid Build Coastguard Worker };
2181*35238bceSAndroid Build Coastguard Worker 
2182*35238bceSAndroid Build Coastguard Worker } // namespace FboCases
2183*35238bceSAndroid Build Coastguard Worker 
FboRenderTestGroup(Context & context)2184*35238bceSAndroid Build Coastguard Worker FboRenderTestGroup::FboRenderTestGroup(Context &context) : TestCaseGroup(context, "render", "Rendering Tests")
2185*35238bceSAndroid Build Coastguard Worker {
2186*35238bceSAndroid Build Coastguard Worker }
2187*35238bceSAndroid Build Coastguard Worker 
~FboRenderTestGroup(void)2188*35238bceSAndroid Build Coastguard Worker FboRenderTestGroup::~FboRenderTestGroup(void)
2189*35238bceSAndroid Build Coastguard Worker {
2190*35238bceSAndroid Build Coastguard Worker }
2191*35238bceSAndroid Build Coastguard Worker 
2192*35238bceSAndroid Build Coastguard Worker namespace
2193*35238bceSAndroid Build Coastguard Worker {
2194*35238bceSAndroid Build Coastguard Worker 
2195*35238bceSAndroid Build Coastguard Worker struct TypeFormatPair
2196*35238bceSAndroid Build Coastguard Worker {
2197*35238bceSAndroid Build Coastguard Worker     GLenum type;
2198*35238bceSAndroid Build Coastguard Worker     GLenum format;
2199*35238bceSAndroid Build Coastguard Worker };
2200*35238bceSAndroid Build Coastguard Worker 
2201*35238bceSAndroid Build Coastguard Worker template <typename CaseType>
addChildVariants(deqp::gles2::TestCaseGroup * group)2202*35238bceSAndroid Build Coastguard Worker void addChildVariants(deqp::gles2::TestCaseGroup *group)
2203*35238bceSAndroid Build Coastguard Worker {
2204*35238bceSAndroid Build Coastguard Worker     TypeFormatPair colorbufferConfigs[] = {
2205*35238bceSAndroid Build Coastguard Worker         //        { GL_TEXTURE_2D, GL_ALPHA },
2206*35238bceSAndroid Build Coastguard Worker         //        { GL_TEXTURE_2D, GL_LUMINANCE },
2207*35238bceSAndroid Build Coastguard Worker         //        { GL_TEXTURE_2D, GL_LUMINANCE_ALPHA },
2208*35238bceSAndroid Build Coastguard Worker         {GL_TEXTURE_2D, GL_RGB},       {GL_TEXTURE_2D, GL_RGBA},    {GL_RENDERBUFFER, GL_RGB565},
2209*35238bceSAndroid Build Coastguard Worker         {GL_RENDERBUFFER, GL_RGB5_A1}, {GL_RENDERBUFFER, GL_RGBA4},
2210*35238bceSAndroid Build Coastguard Worker         //        { GL_RENDERBUFFER, GL_RGBA16F },
2211*35238bceSAndroid Build Coastguard Worker         //        { GL_RENDERBUFFER, GL_RGB16F }
2212*35238bceSAndroid Build Coastguard Worker     };
2213*35238bceSAndroid Build Coastguard Worker     TypeFormatPair depthbufferConfigs[]   = {{GL_NONE, GL_NONE}, {GL_RENDERBUFFER, GL_DEPTH_COMPONENT16}};
2214*35238bceSAndroid Build Coastguard Worker     TypeFormatPair stencilbufferConfigs[] = {{GL_NONE, GL_NONE}, {GL_RENDERBUFFER, GL_STENCIL_INDEX8}};
2215*35238bceSAndroid Build Coastguard Worker 
2216*35238bceSAndroid Build Coastguard Worker     for (int colorbufferNdx = 0; colorbufferNdx < DE_LENGTH_OF_ARRAY(colorbufferConfigs); colorbufferNdx++)
2217*35238bceSAndroid Build Coastguard Worker         for (int depthbufferNdx = 0; depthbufferNdx < DE_LENGTH_OF_ARRAY(depthbufferConfigs); depthbufferNdx++)
2218*35238bceSAndroid Build Coastguard Worker             for (int stencilbufferNdx = 0; stencilbufferNdx < DE_LENGTH_OF_ARRAY(stencilbufferConfigs);
2219*35238bceSAndroid Build Coastguard Worker                  stencilbufferNdx++)
2220*35238bceSAndroid Build Coastguard Worker             {
2221*35238bceSAndroid Build Coastguard Worker                 FboConfig config;
2222*35238bceSAndroid Build Coastguard Worker                 config.colorbufferType     = colorbufferConfigs[colorbufferNdx].type;
2223*35238bceSAndroid Build Coastguard Worker                 config.colorbufferFormat   = colorbufferConfigs[colorbufferNdx].format;
2224*35238bceSAndroid Build Coastguard Worker                 config.depthbufferType     = depthbufferConfigs[depthbufferNdx].type;
2225*35238bceSAndroid Build Coastguard Worker                 config.depthbufferFormat   = depthbufferConfigs[depthbufferNdx].format;
2226*35238bceSAndroid Build Coastguard Worker                 config.stencilbufferType   = stencilbufferConfigs[stencilbufferNdx].type;
2227*35238bceSAndroid Build Coastguard Worker                 config.stencilbufferFormat = stencilbufferConfigs[stencilbufferNdx].format;
2228*35238bceSAndroid Build Coastguard Worker 
2229*35238bceSAndroid Build Coastguard Worker                 if (CaseType::isConfigSupported(config))
2230*35238bceSAndroid Build Coastguard Worker                     group->addChild(new CaseType(group->getContext(), config));
2231*35238bceSAndroid Build Coastguard Worker             }
2232*35238bceSAndroid Build Coastguard Worker }
2233*35238bceSAndroid Build Coastguard Worker 
2234*35238bceSAndroid Build Coastguard Worker template <typename CaseType>
createChildGroup(deqp::gles2::TestCaseGroup * parent,const char * name,const char * description)2235*35238bceSAndroid Build Coastguard Worker void createChildGroup(deqp::gles2::TestCaseGroup *parent, const char *name, const char *description)
2236*35238bceSAndroid Build Coastguard Worker {
2237*35238bceSAndroid Build Coastguard Worker     deqp::gles2::TestCaseGroup *tmpGroup = new deqp::gles2::TestCaseGroup(parent->getContext(), name, description);
2238*35238bceSAndroid Build Coastguard Worker     parent->addChild(tmpGroup);
2239*35238bceSAndroid Build Coastguard Worker     addChildVariants<CaseType>(tmpGroup);
2240*35238bceSAndroid Build Coastguard Worker }
2241*35238bceSAndroid Build Coastguard Worker 
2242*35238bceSAndroid Build Coastguard Worker template <GLbitfield Buffers>
createRecreateBuffersGroup(deqp::gles2::TestCaseGroup * parent,const char * name,const char * description)2243*35238bceSAndroid Build Coastguard Worker void createRecreateBuffersGroup(deqp::gles2::TestCaseGroup *parent, const char *name, const char *description)
2244*35238bceSAndroid Build Coastguard Worker {
2245*35238bceSAndroid Build Coastguard Worker     deqp::gles2::TestCaseGroup *tmpGroup = new deqp::gles2::TestCaseGroup(parent->getContext(), name, description);
2246*35238bceSAndroid Build Coastguard Worker     parent->addChild(tmpGroup);
2247*35238bceSAndroid Build Coastguard Worker     addChildVariants<FboCases::RecreateBuffersRebindTest<Buffers>>(tmpGroup);
2248*35238bceSAndroid Build Coastguard Worker     addChildVariants<FboCases::RecreateBuffersNoRebindTest<Buffers>>(tmpGroup);
2249*35238bceSAndroid Build Coastguard Worker }
2250*35238bceSAndroid Build Coastguard Worker 
2251*35238bceSAndroid Build Coastguard Worker } // namespace
2252*35238bceSAndroid Build Coastguard Worker 
init(void)2253*35238bceSAndroid Build Coastguard Worker void FboRenderTestGroup::init(void)
2254*35238bceSAndroid Build Coastguard Worker {
2255*35238bceSAndroid Build Coastguard Worker     createChildGroup<FboCases::ColorClearsTest>(this, "color_clear", "Color buffer clears");
2256*35238bceSAndroid Build Coastguard Worker     createChildGroup<FboCases::StencilClearsTest>(this, "stencil_clear", "Stencil buffer clears");
2257*35238bceSAndroid Build Coastguard Worker 
2258*35238bceSAndroid Build Coastguard Worker     deqp::gles2::TestCaseGroup *colorGroup = new deqp::gles2::TestCaseGroup(m_context, "color", "Color buffer tests");
2259*35238bceSAndroid Build Coastguard Worker     addChild(colorGroup);
2260*35238bceSAndroid Build Coastguard Worker     addChildVariants<FboCases::MixTest>(colorGroup);
2261*35238bceSAndroid Build Coastguard Worker     addChildVariants<FboCases::MixNpotTest>(colorGroup);
2262*35238bceSAndroid Build Coastguard Worker     addChildVariants<FboCases::BlendTest>(colorGroup);
2263*35238bceSAndroid Build Coastguard Worker     addChildVariants<FboCases::BlendNpotTest>(colorGroup);
2264*35238bceSAndroid Build Coastguard Worker 
2265*35238bceSAndroid Build Coastguard Worker     deqp::gles2::TestCaseGroup *depthGroup = new deqp::gles2::TestCaseGroup(m_context, "depth", "Depth bufer tests");
2266*35238bceSAndroid Build Coastguard Worker     addChild(depthGroup);
2267*35238bceSAndroid Build Coastguard Worker     addChildVariants<FboCases::IntersectingQuadsTest>(depthGroup);
2268*35238bceSAndroid Build Coastguard Worker     addChildVariants<FboCases::IntersectingQuadsNpotTest>(depthGroup);
2269*35238bceSAndroid Build Coastguard Worker 
2270*35238bceSAndroid Build Coastguard Worker     deqp::gles2::TestCaseGroup *stencilGroup =
2271*35238bceSAndroid Build Coastguard Worker         new deqp::gles2::TestCaseGroup(m_context, "stencil", "Stencil buffer tests");
2272*35238bceSAndroid Build Coastguard Worker     addChild(stencilGroup);
2273*35238bceSAndroid Build Coastguard Worker     addChildVariants<FboCases::StencilTest>(stencilGroup);
2274*35238bceSAndroid Build Coastguard Worker     addChildVariants<FboCases::StencilNpotTest>(stencilGroup);
2275*35238bceSAndroid Build Coastguard Worker 
2276*35238bceSAndroid Build Coastguard Worker     createChildGroup<FboCases::SharedColorbufferClearsTest>(this, "shared_colorbuffer_clear",
2277*35238bceSAndroid Build Coastguard Worker                                                             "Shared colorbuffer clears");
2278*35238bceSAndroid Build Coastguard Worker     createChildGroup<FboCases::SharedColorbufferTest>(this, "shared_colorbuffer", "Shared colorbuffer tests");
2279*35238bceSAndroid Build Coastguard Worker     createChildGroup<FboCases::SharedDepthbufferTest>(this, "shared_depthbuffer", "Shared depthbuffer tests");
2280*35238bceSAndroid Build Coastguard Worker     createChildGroup<FboCases::ResizeTest>(this, "resize", "FBO resize tests");
2281*35238bceSAndroid Build Coastguard Worker 
2282*35238bceSAndroid Build Coastguard Worker     createRecreateBuffersGroup<GL_COLOR_BUFFER_BIT>(this, "recreate_colorbuffer", "Recreate colorbuffer tests");
2283*35238bceSAndroid Build Coastguard Worker     createRecreateBuffersGroup<GL_DEPTH_BUFFER_BIT>(this, "recreate_depthbuffer", "Recreate depthbuffer tests");
2284*35238bceSAndroid Build Coastguard Worker     createRecreateBuffersGroup<GL_STENCIL_BUFFER_BIT>(this, "recreate_stencilbuffer", "Recreate stencilbuffer tests");
2285*35238bceSAndroid Build Coastguard Worker 
2286*35238bceSAndroid Build Coastguard Worker     deqp::gles2::TestCaseGroup *texSubImageGroup =
2287*35238bceSAndroid Build Coastguard Worker         new deqp::gles2::TestCaseGroup(m_context, "texsubimage", "TexSubImage interop with FBO colorbuffer texture");
2288*35238bceSAndroid Build Coastguard Worker     addChild(texSubImageGroup);
2289*35238bceSAndroid Build Coastguard Worker     addChildVariants<FboCases::TexSubImageAfterRenderTest>(texSubImageGroup);
2290*35238bceSAndroid Build Coastguard Worker     addChildVariants<FboCases::TexSubImageBetweenRenderTest>(texSubImageGroup);
2291*35238bceSAndroid Build Coastguard Worker 
2292*35238bceSAndroid Build Coastguard Worker     {
2293*35238bceSAndroid Build Coastguard Worker         tcu::TestCaseGroup *const repeatedClearGroup =
2294*35238bceSAndroid Build Coastguard Worker             new tcu::TestCaseGroup(m_testCtx, "repeated_clear", "Repeated FBO clears");
2295*35238bceSAndroid Build Coastguard Worker         addChild(repeatedClearGroup);
2296*35238bceSAndroid Build Coastguard Worker 
2297*35238bceSAndroid Build Coastguard Worker         repeatedClearGroup->addChild(new FboCases::RepeatedClearCase(m_context, GL_RGB));
2298*35238bceSAndroid Build Coastguard Worker         repeatedClearGroup->addChild(new FboCases::RepeatedClearCase(m_context, GL_RGBA));
2299*35238bceSAndroid Build Coastguard Worker     }
2300*35238bceSAndroid Build Coastguard Worker }
2301*35238bceSAndroid Build Coastguard Worker 
2302*35238bceSAndroid Build Coastguard Worker } // namespace Functional
2303*35238bceSAndroid Build Coastguard Worker } // namespace gles2
2304*35238bceSAndroid Build Coastguard Worker } // namespace deqp
2305