1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker * drawElements Quality Program OpenGL ES 3.0 Module
3*35238bceSAndroid Build Coastguard Worker * -------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker *
5*35238bceSAndroid Build Coastguard Worker * Copyright 2014 The Android Open Source Project
6*35238bceSAndroid Build Coastguard Worker *
7*35238bceSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
8*35238bceSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
9*35238bceSAndroid Build Coastguard Worker * You may obtain a copy of the License at
10*35238bceSAndroid Build Coastguard Worker *
11*35238bceSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
12*35238bceSAndroid Build Coastguard Worker *
13*35238bceSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
14*35238bceSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
15*35238bceSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16*35238bceSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
17*35238bceSAndroid Build Coastguard Worker * limitations under the License.
18*35238bceSAndroid Build Coastguard Worker *
19*35238bceSAndroid Build Coastguard Worker *//*!
20*35238bceSAndroid Build Coastguard Worker * \file
21*35238bceSAndroid Build Coastguard Worker * \brief Framebuffer Object Tests.
22*35238bceSAndroid Build Coastguard Worker *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker
24*35238bceSAndroid Build Coastguard Worker #include "es3fFboRenderTest.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "sglrContextUtil.hpp"
26*35238bceSAndroid Build Coastguard Worker #include "sglrGLContext.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "sglrReferenceContext.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "es3fFboTestUtil.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "tcuSurface.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "tcuImageCompare.hpp"
31*35238bceSAndroid Build Coastguard Worker #include "tcuTextureUtil.hpp"
32*35238bceSAndroid Build Coastguard Worker #include "tcuVectorUtil.hpp"
33*35238bceSAndroid Build Coastguard Worker #include "tcuRenderTarget.hpp"
34*35238bceSAndroid Build Coastguard Worker #include "gluPixelTransfer.hpp"
35*35238bceSAndroid Build Coastguard Worker #include "gluTextureUtil.hpp"
36*35238bceSAndroid Build Coastguard Worker #include "gluStrUtil.hpp"
37*35238bceSAndroid Build Coastguard Worker #include "deRandom.h"
38*35238bceSAndroid Build Coastguard Worker #include "deString.h"
39*35238bceSAndroid Build Coastguard Worker #include "glwDefs.hpp"
40*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
41*35238bceSAndroid Build Coastguard Worker
42*35238bceSAndroid Build Coastguard Worker #include <sstream>
43*35238bceSAndroid Build Coastguard Worker
44*35238bceSAndroid Build Coastguard Worker using std::string;
45*35238bceSAndroid Build Coastguard Worker using std::vector;
46*35238bceSAndroid Build Coastguard Worker using tcu::IVec2;
47*35238bceSAndroid Build Coastguard Worker using tcu::IVec3;
48*35238bceSAndroid Build Coastguard Worker using tcu::IVec4;
49*35238bceSAndroid Build Coastguard Worker using tcu::RGBA;
50*35238bceSAndroid Build Coastguard Worker using tcu::Surface;
51*35238bceSAndroid Build Coastguard Worker using tcu::TestLog;
52*35238bceSAndroid Build Coastguard Worker using tcu::Vec2;
53*35238bceSAndroid Build Coastguard Worker using tcu::Vec3;
54*35238bceSAndroid Build Coastguard Worker using tcu::Vec4;
55*35238bceSAndroid Build Coastguard Worker
56*35238bceSAndroid Build Coastguard Worker namespace deqp
57*35238bceSAndroid Build Coastguard Worker {
58*35238bceSAndroid Build Coastguard Worker namespace gles3
59*35238bceSAndroid Build Coastguard Worker {
60*35238bceSAndroid Build Coastguard Worker namespace Functional
61*35238bceSAndroid Build Coastguard Worker {
62*35238bceSAndroid Build Coastguard Worker
63*35238bceSAndroid Build Coastguard Worker using glw::GLenum;
64*35238bceSAndroid Build Coastguard Worker using namespace FboTestUtil;
65*35238bceSAndroid Build Coastguard Worker
66*35238bceSAndroid Build Coastguard Worker class FboConfig
67*35238bceSAndroid Build Coastguard Worker {
68*35238bceSAndroid Build Coastguard Worker public:
FboConfig(uint32_t buffers_,uint32_t colorType_,uint32_t colorFormat_,uint32_t depthStencilType_,uint32_t depthStencilFormat_,int width_=0,int height_=0,int samples_=0)69*35238bceSAndroid Build Coastguard Worker FboConfig(uint32_t buffers_, uint32_t colorType_, uint32_t colorFormat_, uint32_t depthStencilType_,
70*35238bceSAndroid Build Coastguard Worker uint32_t depthStencilFormat_, int width_ = 0, int height_ = 0, int samples_ = 0)
71*35238bceSAndroid Build Coastguard Worker : buffers(buffers_)
72*35238bceSAndroid Build Coastguard Worker , colorType(colorType_)
73*35238bceSAndroid Build Coastguard Worker , colorFormat(colorFormat_)
74*35238bceSAndroid Build Coastguard Worker , depthStencilType(depthStencilType_)
75*35238bceSAndroid Build Coastguard Worker , depthStencilFormat(depthStencilFormat_)
76*35238bceSAndroid Build Coastguard Worker , width(width_)
77*35238bceSAndroid Build Coastguard Worker , height(height_)
78*35238bceSAndroid Build Coastguard Worker , samples(samples_)
79*35238bceSAndroid Build Coastguard Worker {
80*35238bceSAndroid Build Coastguard Worker }
81*35238bceSAndroid Build Coastguard Worker
FboConfig(void)82*35238bceSAndroid Build Coastguard Worker FboConfig(void)
83*35238bceSAndroid Build Coastguard Worker : buffers(0)
84*35238bceSAndroid Build Coastguard Worker , colorType(GL_NONE)
85*35238bceSAndroid Build Coastguard Worker , colorFormat(GL_NONE)
86*35238bceSAndroid Build Coastguard Worker , depthStencilType(GL_NONE)
87*35238bceSAndroid Build Coastguard Worker , depthStencilFormat(GL_NONE)
88*35238bceSAndroid Build Coastguard Worker , width(0)
89*35238bceSAndroid Build Coastguard Worker , height(0)
90*35238bceSAndroid Build Coastguard Worker , samples(0)
91*35238bceSAndroid Build Coastguard Worker {
92*35238bceSAndroid Build Coastguard Worker }
93*35238bceSAndroid Build Coastguard Worker
94*35238bceSAndroid Build Coastguard Worker std::string getName(void) const;
95*35238bceSAndroid Build Coastguard Worker
96*35238bceSAndroid Build Coastguard Worker uint32_t buffers; //!< Buffer bit mask (GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|...)
97*35238bceSAndroid Build Coastguard Worker
98*35238bceSAndroid Build Coastguard Worker GLenum colorType; //!< GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP, GL_RENDERBUFFER
99*35238bceSAndroid Build Coastguard Worker GLenum colorFormat; //!< Internal format for color buffer texture or renderbuffer
100*35238bceSAndroid Build Coastguard Worker
101*35238bceSAndroid Build Coastguard Worker GLenum depthStencilType;
102*35238bceSAndroid Build Coastguard Worker GLenum depthStencilFormat;
103*35238bceSAndroid Build Coastguard Worker
104*35238bceSAndroid Build Coastguard Worker int width;
105*35238bceSAndroid Build Coastguard Worker int height;
106*35238bceSAndroid Build Coastguard Worker int samples;
107*35238bceSAndroid Build Coastguard Worker };
108*35238bceSAndroid Build Coastguard Worker
getTypeName(GLenum type)109*35238bceSAndroid Build Coastguard Worker static const char *getTypeName(GLenum type)
110*35238bceSAndroid Build Coastguard Worker {
111*35238bceSAndroid Build Coastguard Worker switch (type)
112*35238bceSAndroid Build Coastguard Worker {
113*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_2D:
114*35238bceSAndroid Build Coastguard Worker return "tex2d";
115*35238bceSAndroid Build Coastguard Worker case GL_RENDERBUFFER:
116*35238bceSAndroid Build Coastguard Worker return "rbo";
117*35238bceSAndroid Build Coastguard Worker default:
118*35238bceSAndroid Build Coastguard Worker TCU_FAIL("Unknown type");
119*35238bceSAndroid Build Coastguard Worker }
120*35238bceSAndroid Build Coastguard Worker }
121*35238bceSAndroid Build Coastguard Worker
getName(void) const122*35238bceSAndroid Build Coastguard Worker std::string FboConfig::getName(void) const
123*35238bceSAndroid Build Coastguard Worker {
124*35238bceSAndroid Build Coastguard Worker std::ostringstream name;
125*35238bceSAndroid Build Coastguard Worker
126*35238bceSAndroid Build Coastguard Worker DE_ASSERT(buffers & GL_COLOR_BUFFER_BIT);
127*35238bceSAndroid Build Coastguard Worker name << getTypeName(colorType) << "_" << getFormatName(colorFormat);
128*35238bceSAndroid Build Coastguard Worker
129*35238bceSAndroid Build Coastguard Worker if (buffers & GL_DEPTH_BUFFER_BIT)
130*35238bceSAndroid Build Coastguard Worker name << "_depth";
131*35238bceSAndroid Build Coastguard Worker if (buffers & GL_STENCIL_BUFFER_BIT)
132*35238bceSAndroid Build Coastguard Worker name << "_stencil";
133*35238bceSAndroid Build Coastguard Worker
134*35238bceSAndroid Build Coastguard Worker if (buffers & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT))
135*35238bceSAndroid Build Coastguard Worker name << "_" << getTypeName(depthStencilType) << "_" << getFormatName(depthStencilFormat);
136*35238bceSAndroid Build Coastguard Worker
137*35238bceSAndroid Build Coastguard Worker return name.str();
138*35238bceSAndroid Build Coastguard Worker }
139*35238bceSAndroid Build Coastguard Worker
140*35238bceSAndroid Build Coastguard Worker class Framebuffer
141*35238bceSAndroid Build Coastguard Worker {
142*35238bceSAndroid Build Coastguard Worker public:
143*35238bceSAndroid Build Coastguard Worker Framebuffer(sglr::Context &context, const FboConfig &config, int width, int height, uint32_t fbo = 0,
144*35238bceSAndroid Build Coastguard Worker uint32_t colorBuffer = 0, uint32_t depthStencilBuffer = 0);
145*35238bceSAndroid Build Coastguard Worker ~Framebuffer(void);
146*35238bceSAndroid Build Coastguard Worker
getConfig(void) const147*35238bceSAndroid Build Coastguard Worker const FboConfig &getConfig(void) const
148*35238bceSAndroid Build Coastguard Worker {
149*35238bceSAndroid Build Coastguard Worker return m_config;
150*35238bceSAndroid Build Coastguard Worker }
getFramebuffer(void) const151*35238bceSAndroid Build Coastguard Worker uint32_t getFramebuffer(void) const
152*35238bceSAndroid Build Coastguard Worker {
153*35238bceSAndroid Build Coastguard Worker return m_framebuffer;
154*35238bceSAndroid Build Coastguard Worker }
getColorBuffer(void) const155*35238bceSAndroid Build Coastguard Worker uint32_t getColorBuffer(void) const
156*35238bceSAndroid Build Coastguard Worker {
157*35238bceSAndroid Build Coastguard Worker return m_colorBuffer;
158*35238bceSAndroid Build Coastguard Worker }
getDepthStencilBuffer(void) const159*35238bceSAndroid Build Coastguard Worker uint32_t getDepthStencilBuffer(void) const
160*35238bceSAndroid Build Coastguard Worker {
161*35238bceSAndroid Build Coastguard Worker return m_depthStencilBuffer;
162*35238bceSAndroid Build Coastguard Worker }
163*35238bceSAndroid Build Coastguard Worker
164*35238bceSAndroid Build Coastguard Worker void checkCompleteness(void);
165*35238bceSAndroid Build Coastguard Worker
166*35238bceSAndroid Build Coastguard Worker private:
167*35238bceSAndroid Build Coastguard Worker uint32_t createTex2D(uint32_t name, GLenum format, int width, int height);
168*35238bceSAndroid Build Coastguard Worker uint32_t createRbo(uint32_t name, GLenum format, int width, int height);
169*35238bceSAndroid Build Coastguard Worker void destroyBuffer(uint32_t name, GLenum type);
170*35238bceSAndroid Build Coastguard Worker
171*35238bceSAndroid Build Coastguard Worker FboConfig m_config;
172*35238bceSAndroid Build Coastguard Worker sglr::Context &m_context;
173*35238bceSAndroid Build Coastguard Worker uint32_t m_framebuffer;
174*35238bceSAndroid Build Coastguard Worker uint32_t m_colorBuffer;
175*35238bceSAndroid Build Coastguard Worker uint32_t m_depthStencilBuffer;
176*35238bceSAndroid Build Coastguard Worker };
177*35238bceSAndroid Build Coastguard Worker
getEnablingExtensions(uint32_t format)178*35238bceSAndroid Build Coastguard Worker static std::vector<std::string> getEnablingExtensions(uint32_t format)
179*35238bceSAndroid Build Coastguard Worker {
180*35238bceSAndroid Build Coastguard Worker std::vector<std::string> out;
181*35238bceSAndroid Build Coastguard Worker
182*35238bceSAndroid Build Coastguard Worker switch (format)
183*35238bceSAndroid Build Coastguard Worker {
184*35238bceSAndroid Build Coastguard Worker case GL_RGB16F:
185*35238bceSAndroid Build Coastguard Worker out.push_back("GL_EXT_color_buffer_half_float");
186*35238bceSAndroid Build Coastguard Worker break;
187*35238bceSAndroid Build Coastguard Worker
188*35238bceSAndroid Build Coastguard Worker case GL_RGBA16F:
189*35238bceSAndroid Build Coastguard Worker case GL_RG16F:
190*35238bceSAndroid Build Coastguard Worker case GL_R16F:
191*35238bceSAndroid Build Coastguard Worker out.push_back("GL_EXT_color_buffer_half_float");
192*35238bceSAndroid Build Coastguard Worker // Fallthrough
193*35238bceSAndroid Build Coastguard Worker
194*35238bceSAndroid Build Coastguard Worker case GL_RGBA32F:
195*35238bceSAndroid Build Coastguard Worker case GL_RGB32F:
196*35238bceSAndroid Build Coastguard Worker case GL_R11F_G11F_B10F:
197*35238bceSAndroid Build Coastguard Worker case GL_RG32F:
198*35238bceSAndroid Build Coastguard Worker case GL_R32F:
199*35238bceSAndroid Build Coastguard Worker out.push_back("GL_EXT_color_buffer_float");
200*35238bceSAndroid Build Coastguard Worker break;
201*35238bceSAndroid Build Coastguard Worker
202*35238bceSAndroid Build Coastguard Worker default:
203*35238bceSAndroid Build Coastguard Worker break;
204*35238bceSAndroid Build Coastguard Worker }
205*35238bceSAndroid Build Coastguard Worker
206*35238bceSAndroid Build Coastguard Worker return out;
207*35238bceSAndroid Build Coastguard Worker }
208*35238bceSAndroid Build Coastguard Worker
isExtensionSupported(sglr::Context & context,const char * name)209*35238bceSAndroid Build Coastguard Worker static bool isExtensionSupported(sglr::Context &context, const char *name)
210*35238bceSAndroid Build Coastguard Worker {
211*35238bceSAndroid Build Coastguard Worker std::istringstream extensions(context.getString(GL_EXTENSIONS));
212*35238bceSAndroid Build Coastguard Worker std::string extension;
213*35238bceSAndroid Build Coastguard Worker
214*35238bceSAndroid Build Coastguard Worker while (std::getline(extensions, extension, ' '))
215*35238bceSAndroid Build Coastguard Worker {
216*35238bceSAndroid Build Coastguard Worker if (extension == name)
217*35238bceSAndroid Build Coastguard Worker return true;
218*35238bceSAndroid Build Coastguard Worker }
219*35238bceSAndroid Build Coastguard Worker
220*35238bceSAndroid Build Coastguard Worker return false;
221*35238bceSAndroid Build Coastguard Worker }
222*35238bceSAndroid Build Coastguard Worker
isAnyExtensionSupported(sglr::Context & context,const std::vector<std::string> & requiredExts)223*35238bceSAndroid Build Coastguard Worker static bool isAnyExtensionSupported(sglr::Context &context, const std::vector<std::string> &requiredExts)
224*35238bceSAndroid Build Coastguard Worker {
225*35238bceSAndroid Build Coastguard Worker if (requiredExts.empty())
226*35238bceSAndroid Build Coastguard Worker return true;
227*35238bceSAndroid Build Coastguard Worker
228*35238bceSAndroid Build Coastguard Worker for (std::vector<std::string>::const_iterator iter = requiredExts.begin(); iter != requiredExts.end(); iter++)
229*35238bceSAndroid Build Coastguard Worker {
230*35238bceSAndroid Build Coastguard Worker const std::string &extension = *iter;
231*35238bceSAndroid Build Coastguard Worker
232*35238bceSAndroid Build Coastguard Worker if (isExtensionSupported(context, extension.c_str()))
233*35238bceSAndroid Build Coastguard Worker return true;
234*35238bceSAndroid Build Coastguard Worker }
235*35238bceSAndroid Build Coastguard Worker
236*35238bceSAndroid Build Coastguard Worker return false;
237*35238bceSAndroid Build Coastguard Worker }
238*35238bceSAndroid Build Coastguard Worker
239*35238bceSAndroid Build Coastguard Worker template <typename T>
join(const std::vector<T> & list,const std::string & sep)240*35238bceSAndroid Build Coastguard Worker static std::string join(const std::vector<T> &list, const std::string &sep)
241*35238bceSAndroid Build Coastguard Worker {
242*35238bceSAndroid Build Coastguard Worker std::ostringstream out;
243*35238bceSAndroid Build Coastguard Worker
244*35238bceSAndroid Build Coastguard Worker for (typename std::vector<T>::const_iterator iter = list.begin(); iter != list.end(); iter++)
245*35238bceSAndroid Build Coastguard Worker {
246*35238bceSAndroid Build Coastguard Worker if (iter != list.begin())
247*35238bceSAndroid Build Coastguard Worker out << sep;
248*35238bceSAndroid Build Coastguard Worker out << *iter;
249*35238bceSAndroid Build Coastguard Worker }
250*35238bceSAndroid Build Coastguard Worker
251*35238bceSAndroid Build Coastguard Worker return out.str();
252*35238bceSAndroid Build Coastguard Worker }
253*35238bceSAndroid Build Coastguard Worker
checkColorFormatSupport(sglr::Context & context,uint32_t sizedFormat)254*35238bceSAndroid Build Coastguard Worker static void checkColorFormatSupport(sglr::Context &context, uint32_t sizedFormat)
255*35238bceSAndroid Build Coastguard Worker {
256*35238bceSAndroid Build Coastguard Worker const std::vector<std::string> requiredExts = getEnablingExtensions(sizedFormat);
257*35238bceSAndroid Build Coastguard Worker
258*35238bceSAndroid Build Coastguard Worker if (!isAnyExtensionSupported(context, requiredExts))
259*35238bceSAndroid Build Coastguard Worker {
260*35238bceSAndroid Build Coastguard Worker std::string errMsg =
261*35238bceSAndroid Build Coastguard Worker "Format not supported, requires " +
262*35238bceSAndroid Build Coastguard Worker ((requiredExts.size() == 1) ? requiredExts[0] : " one of the following: " + join(requiredExts, ", "));
263*35238bceSAndroid Build Coastguard Worker
264*35238bceSAndroid Build Coastguard Worker throw tcu::NotSupportedError(errMsg);
265*35238bceSAndroid Build Coastguard Worker }
266*35238bceSAndroid Build Coastguard Worker }
267*35238bceSAndroid Build Coastguard Worker
Framebuffer(sglr::Context & context,const FboConfig & config,int width,int height,uint32_t fbo,uint32_t colorBufferName,uint32_t depthStencilBufferName)268*35238bceSAndroid Build Coastguard Worker Framebuffer::Framebuffer(sglr::Context &context, const FboConfig &config, int width, int height, uint32_t fbo,
269*35238bceSAndroid Build Coastguard Worker uint32_t colorBufferName, uint32_t depthStencilBufferName)
270*35238bceSAndroid Build Coastguard Worker : m_config(config)
271*35238bceSAndroid Build Coastguard Worker , m_context(context)
272*35238bceSAndroid Build Coastguard Worker , m_framebuffer(fbo)
273*35238bceSAndroid Build Coastguard Worker , m_colorBuffer(0)
274*35238bceSAndroid Build Coastguard Worker , m_depthStencilBuffer(0)
275*35238bceSAndroid Build Coastguard Worker {
276*35238bceSAndroid Build Coastguard Worker // Verify that color format is supported
277*35238bceSAndroid Build Coastguard Worker checkColorFormatSupport(context, config.colorFormat);
278*35238bceSAndroid Build Coastguard Worker
279*35238bceSAndroid Build Coastguard Worker if (m_framebuffer == 0)
280*35238bceSAndroid Build Coastguard Worker context.genFramebuffers(1, &m_framebuffer);
281*35238bceSAndroid Build Coastguard Worker context.bindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
282*35238bceSAndroid Build Coastguard Worker
283*35238bceSAndroid Build Coastguard Worker if (m_config.buffers & (GL_COLOR_BUFFER_BIT))
284*35238bceSAndroid Build Coastguard Worker {
285*35238bceSAndroid Build Coastguard Worker switch (m_config.colorType)
286*35238bceSAndroid Build Coastguard Worker {
287*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_2D:
288*35238bceSAndroid Build Coastguard Worker m_colorBuffer = createTex2D(colorBufferName, m_config.colorFormat, width, height);
289*35238bceSAndroid Build Coastguard Worker context.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_colorBuffer, 0);
290*35238bceSAndroid Build Coastguard Worker break;
291*35238bceSAndroid Build Coastguard Worker
292*35238bceSAndroid Build Coastguard Worker case GL_RENDERBUFFER:
293*35238bceSAndroid Build Coastguard Worker m_colorBuffer = createRbo(colorBufferName, m_config.colorFormat, width, height);
294*35238bceSAndroid Build Coastguard Worker context.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_colorBuffer);
295*35238bceSAndroid Build Coastguard Worker break;
296*35238bceSAndroid Build Coastguard Worker
297*35238bceSAndroid Build Coastguard Worker default:
298*35238bceSAndroid Build Coastguard Worker TCU_FAIL("Unsupported type");
299*35238bceSAndroid Build Coastguard Worker }
300*35238bceSAndroid Build Coastguard Worker }
301*35238bceSAndroid Build Coastguard Worker
302*35238bceSAndroid Build Coastguard Worker if (m_config.buffers & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT))
303*35238bceSAndroid Build Coastguard Worker {
304*35238bceSAndroid Build Coastguard Worker switch (m_config.depthStencilType)
305*35238bceSAndroid Build Coastguard Worker {
306*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_2D:
307*35238bceSAndroid Build Coastguard Worker m_depthStencilBuffer = createTex2D(depthStencilBufferName, m_config.depthStencilFormat, width, height);
308*35238bceSAndroid Build Coastguard Worker break;
309*35238bceSAndroid Build Coastguard Worker case GL_RENDERBUFFER:
310*35238bceSAndroid Build Coastguard Worker m_depthStencilBuffer = createRbo(depthStencilBufferName, m_config.depthStencilFormat, width, height);
311*35238bceSAndroid Build Coastguard Worker break;
312*35238bceSAndroid Build Coastguard Worker default:
313*35238bceSAndroid Build Coastguard Worker TCU_FAIL("Unsupported type");
314*35238bceSAndroid Build Coastguard Worker }
315*35238bceSAndroid Build Coastguard Worker }
316*35238bceSAndroid Build Coastguard Worker
317*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < 2; ndx++)
318*35238bceSAndroid Build Coastguard Worker {
319*35238bceSAndroid Build Coastguard Worker uint32_t bit = ndx ? GL_STENCIL_BUFFER_BIT : GL_DEPTH_BUFFER_BIT;
320*35238bceSAndroid Build Coastguard Worker uint32_t point = ndx ? GL_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT;
321*35238bceSAndroid Build Coastguard Worker
322*35238bceSAndroid Build Coastguard Worker if ((m_config.buffers & bit) == 0)
323*35238bceSAndroid Build Coastguard Worker continue; /* Not used. */
324*35238bceSAndroid Build Coastguard Worker
325*35238bceSAndroid Build Coastguard Worker switch (m_config.depthStencilType)
326*35238bceSAndroid Build Coastguard Worker {
327*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_2D:
328*35238bceSAndroid Build Coastguard Worker context.framebufferTexture2D(GL_FRAMEBUFFER, point, GL_TEXTURE_2D, m_depthStencilBuffer, 0);
329*35238bceSAndroid Build Coastguard Worker break;
330*35238bceSAndroid Build Coastguard Worker case GL_RENDERBUFFER:
331*35238bceSAndroid Build Coastguard Worker context.framebufferRenderbuffer(GL_FRAMEBUFFER, point, GL_RENDERBUFFER, m_depthStencilBuffer);
332*35238bceSAndroid Build Coastguard Worker break;
333*35238bceSAndroid Build Coastguard Worker default:
334*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
335*35238bceSAndroid Build Coastguard Worker }
336*35238bceSAndroid Build Coastguard Worker }
337*35238bceSAndroid Build Coastguard Worker
338*35238bceSAndroid Build Coastguard Worker GLenum err = m_context.getError();
339*35238bceSAndroid Build Coastguard Worker if (err != GL_NO_ERROR)
340*35238bceSAndroid Build Coastguard Worker throw glu::Error(err, glu::getErrorStr(err).toString().c_str(), "", __FILE__, __LINE__);
341*35238bceSAndroid Build Coastguard Worker
342*35238bceSAndroid Build Coastguard Worker context.bindFramebuffer(GL_FRAMEBUFFER, 0);
343*35238bceSAndroid Build Coastguard Worker }
344*35238bceSAndroid Build Coastguard Worker
~Framebuffer(void)345*35238bceSAndroid Build Coastguard Worker Framebuffer::~Framebuffer(void)
346*35238bceSAndroid Build Coastguard Worker {
347*35238bceSAndroid Build Coastguard Worker m_context.deleteFramebuffers(1, &m_framebuffer);
348*35238bceSAndroid Build Coastguard Worker destroyBuffer(m_colorBuffer, m_config.colorType);
349*35238bceSAndroid Build Coastguard Worker destroyBuffer(m_depthStencilBuffer, m_config.depthStencilType);
350*35238bceSAndroid Build Coastguard Worker }
351*35238bceSAndroid Build Coastguard Worker
checkCompleteness(void)352*35238bceSAndroid Build Coastguard Worker void Framebuffer::checkCompleteness(void)
353*35238bceSAndroid Build Coastguard Worker {
354*35238bceSAndroid Build Coastguard Worker m_context.bindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
355*35238bceSAndroid Build Coastguard Worker GLenum status = m_context.checkFramebufferStatus(GL_FRAMEBUFFER);
356*35238bceSAndroid Build Coastguard Worker m_context.bindFramebuffer(GL_FRAMEBUFFER, 0);
357*35238bceSAndroid Build Coastguard Worker if (status != GL_FRAMEBUFFER_COMPLETE)
358*35238bceSAndroid Build Coastguard Worker throw FboIncompleteException(status, __FILE__, __LINE__);
359*35238bceSAndroid Build Coastguard Worker }
360*35238bceSAndroid Build Coastguard Worker
createTex2D(uint32_t name,GLenum format,int width,int height)361*35238bceSAndroid Build Coastguard Worker uint32_t Framebuffer::createTex2D(uint32_t name, GLenum format, int width, int height)
362*35238bceSAndroid Build Coastguard Worker {
363*35238bceSAndroid Build Coastguard Worker if (name == 0)
364*35238bceSAndroid Build Coastguard Worker m_context.genTextures(1, &name);
365*35238bceSAndroid Build Coastguard Worker
366*35238bceSAndroid Build Coastguard Worker m_context.bindTexture(GL_TEXTURE_2D, name);
367*35238bceSAndroid Build Coastguard Worker m_context.texImage2D(GL_TEXTURE_2D, 0, format, width, height);
368*35238bceSAndroid Build Coastguard Worker
369*35238bceSAndroid Build Coastguard Worker if (!deIsPowerOfTwo32(width) || !deIsPowerOfTwo32(height))
370*35238bceSAndroid Build Coastguard Worker {
371*35238bceSAndroid Build Coastguard Worker // Set wrap mode to clamp for NPOT FBOs
372*35238bceSAndroid Build Coastguard Worker m_context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
373*35238bceSAndroid Build Coastguard Worker m_context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
374*35238bceSAndroid Build Coastguard Worker }
375*35238bceSAndroid Build Coastguard Worker
376*35238bceSAndroid Build Coastguard Worker m_context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
377*35238bceSAndroid Build Coastguard Worker m_context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
378*35238bceSAndroid Build Coastguard Worker
379*35238bceSAndroid Build Coastguard Worker return name;
380*35238bceSAndroid Build Coastguard Worker }
381*35238bceSAndroid Build Coastguard Worker
createRbo(uint32_t name,GLenum format,int width,int height)382*35238bceSAndroid Build Coastguard Worker uint32_t Framebuffer::createRbo(uint32_t name, GLenum format, int width, int height)
383*35238bceSAndroid Build Coastguard Worker {
384*35238bceSAndroid Build Coastguard Worker if (name == 0)
385*35238bceSAndroid Build Coastguard Worker m_context.genRenderbuffers(1, &name);
386*35238bceSAndroid Build Coastguard Worker
387*35238bceSAndroid Build Coastguard Worker m_context.bindRenderbuffer(GL_RENDERBUFFER, name);
388*35238bceSAndroid Build Coastguard Worker m_context.renderbufferStorage(GL_RENDERBUFFER, format, width, height);
389*35238bceSAndroid Build Coastguard Worker
390*35238bceSAndroid Build Coastguard Worker return name;
391*35238bceSAndroid Build Coastguard Worker }
392*35238bceSAndroid Build Coastguard Worker
destroyBuffer(uint32_t name,GLenum type)393*35238bceSAndroid Build Coastguard Worker void Framebuffer::destroyBuffer(uint32_t name, GLenum type)
394*35238bceSAndroid Build Coastguard Worker {
395*35238bceSAndroid Build Coastguard Worker if (type == GL_TEXTURE_2D || type == GL_TEXTURE_CUBE_MAP)
396*35238bceSAndroid Build Coastguard Worker m_context.deleteTextures(1, &name);
397*35238bceSAndroid Build Coastguard Worker else if (type == GL_RENDERBUFFER)
398*35238bceSAndroid Build Coastguard Worker m_context.deleteRenderbuffers(1, &name);
399*35238bceSAndroid Build Coastguard Worker else
400*35238bceSAndroid Build Coastguard Worker DE_ASSERT(type == GL_NONE);
401*35238bceSAndroid Build Coastguard Worker }
402*35238bceSAndroid Build Coastguard Worker
createMetaballsTex2D(sglr::Context & context,uint32_t name,GLenum format,GLenum dataType,int width,int height)403*35238bceSAndroid Build Coastguard Worker static void createMetaballsTex2D(sglr::Context &context, uint32_t name, GLenum format, GLenum dataType, int width,
404*35238bceSAndroid Build Coastguard Worker int height)
405*35238bceSAndroid Build Coastguard Worker {
406*35238bceSAndroid Build Coastguard Worker tcu::TextureFormat texFormat = glu::mapGLTransferFormat(format, dataType);
407*35238bceSAndroid Build Coastguard Worker tcu::TextureLevel level(texFormat, width, height);
408*35238bceSAndroid Build Coastguard Worker
409*35238bceSAndroid Build Coastguard Worker tcu::fillWithMetaballs(level.getAccess(), 5, name ^ width ^ height);
410*35238bceSAndroid Build Coastguard Worker
411*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, name);
412*35238bceSAndroid Build Coastguard Worker context.texImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, dataType, level.getAccess().getDataPtr());
413*35238bceSAndroid Build Coastguard Worker context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
414*35238bceSAndroid Build Coastguard Worker }
415*35238bceSAndroid Build Coastguard Worker
createQuadsTex2D(sglr::Context & context,uint32_t name,GLenum format,GLenum dataType,int width,int height)416*35238bceSAndroid Build Coastguard Worker static void createQuadsTex2D(sglr::Context &context, uint32_t name, GLenum format, GLenum dataType, int width,
417*35238bceSAndroid Build Coastguard Worker int height)
418*35238bceSAndroid Build Coastguard Worker {
419*35238bceSAndroid Build Coastguard Worker tcu::TextureFormat texFormat = glu::mapGLTransferFormat(format, dataType);
420*35238bceSAndroid Build Coastguard Worker tcu::TextureLevel level(texFormat, width, height);
421*35238bceSAndroid Build Coastguard Worker
422*35238bceSAndroid Build Coastguard Worker tcu::fillWithRGBAQuads(level.getAccess());
423*35238bceSAndroid Build Coastguard Worker
424*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, name);
425*35238bceSAndroid Build Coastguard Worker context.texImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, dataType, level.getAccess().getDataPtr());
426*35238bceSAndroid Build Coastguard Worker context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
427*35238bceSAndroid Build Coastguard Worker }
428*35238bceSAndroid Build Coastguard Worker
429*35238bceSAndroid Build Coastguard Worker class FboRenderCase : public TestCase
430*35238bceSAndroid Build Coastguard Worker {
431*35238bceSAndroid Build Coastguard Worker public:
432*35238bceSAndroid Build Coastguard Worker FboRenderCase(Context &context, const char *name, const char *description, const FboConfig &config);
~FboRenderCase(void)433*35238bceSAndroid Build Coastguard Worker virtual ~FboRenderCase(void)
434*35238bceSAndroid Build Coastguard Worker {
435*35238bceSAndroid Build Coastguard Worker }
436*35238bceSAndroid Build Coastguard Worker
437*35238bceSAndroid Build Coastguard Worker virtual IterateResult iterate(void);
438*35238bceSAndroid Build Coastguard Worker virtual void render(sglr::Context &fboContext, Surface &dst) = DE_NULL;
439*35238bceSAndroid Build Coastguard Worker
440*35238bceSAndroid Build Coastguard Worker bool compare(const tcu::Surface &reference, const tcu::Surface &result);
441*35238bceSAndroid Build Coastguard Worker
442*35238bceSAndroid Build Coastguard Worker protected:
443*35238bceSAndroid Build Coastguard Worker const FboConfig m_config;
444*35238bceSAndroid Build Coastguard Worker };
445*35238bceSAndroid Build Coastguard Worker
FboRenderCase(Context & context,const char * name,const char * description,const FboConfig & config)446*35238bceSAndroid Build Coastguard Worker FboRenderCase::FboRenderCase(Context &context, const char *name, const char *description, const FboConfig &config)
447*35238bceSAndroid Build Coastguard Worker : TestCase(context, name, description)
448*35238bceSAndroid Build Coastguard Worker , m_config(config)
449*35238bceSAndroid Build Coastguard Worker {
450*35238bceSAndroid Build Coastguard Worker }
451*35238bceSAndroid Build Coastguard Worker
iterate(void)452*35238bceSAndroid Build Coastguard Worker TestCase::IterateResult FboRenderCase::iterate(void)
453*35238bceSAndroid Build Coastguard Worker {
454*35238bceSAndroid Build Coastguard Worker tcu::Vec4 clearColor = tcu::Vec4(0.125f, 0.25f, 0.5f, 1.0f);
455*35238bceSAndroid Build Coastguard Worker glu::RenderContext &renderCtx = m_context.getRenderContext();
456*35238bceSAndroid Build Coastguard Worker const tcu::RenderTarget &renderTarget = renderCtx.getRenderTarget();
457*35238bceSAndroid Build Coastguard Worker tcu::TestLog &log = m_testCtx.getLog();
458*35238bceSAndroid Build Coastguard Worker const char *failReason = DE_NULL;
459*35238bceSAndroid Build Coastguard Worker
460*35238bceSAndroid Build Coastguard Worker // Position & size for context
461*35238bceSAndroid Build Coastguard Worker deRandom rnd;
462*35238bceSAndroid Build Coastguard Worker deRandom_init(&rnd, deStringHash(getName()));
463*35238bceSAndroid Build Coastguard Worker
464*35238bceSAndroid Build Coastguard Worker int width = deMin32(renderTarget.getWidth(), 128);
465*35238bceSAndroid Build Coastguard Worker int height = deMin32(renderTarget.getHeight(), 128);
466*35238bceSAndroid Build Coastguard Worker int xMax = renderTarget.getWidth() - width + 1;
467*35238bceSAndroid Build Coastguard Worker int yMax = renderTarget.getHeight() - height + 1;
468*35238bceSAndroid Build Coastguard Worker int x = deRandom_getUint32(&rnd) % xMax;
469*35238bceSAndroid Build Coastguard Worker int y = deRandom_getUint32(&rnd) % yMax;
470*35238bceSAndroid Build Coastguard Worker
471*35238bceSAndroid Build Coastguard Worker tcu::Surface gles3Frame(width, height);
472*35238bceSAndroid Build Coastguard Worker tcu::Surface refFrame(width, height);
473*35238bceSAndroid Build Coastguard Worker GLenum gles3Error;
474*35238bceSAndroid Build Coastguard Worker GLenum refError;
475*35238bceSAndroid Build Coastguard Worker
476*35238bceSAndroid Build Coastguard Worker // Render using GLES3
477*35238bceSAndroid Build Coastguard Worker try
478*35238bceSAndroid Build Coastguard Worker {
479*35238bceSAndroid Build Coastguard Worker sglr::GLContext context(renderCtx, log, sglr::GLCONTEXT_LOG_CALLS, tcu::IVec4(x, y, width, height));
480*35238bceSAndroid Build Coastguard Worker
481*35238bceSAndroid Build Coastguard Worker context.clearColor(clearColor.x(), clearColor.y(), clearColor.z(), clearColor.w());
482*35238bceSAndroid Build Coastguard Worker context.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
483*35238bceSAndroid Build Coastguard Worker
484*35238bceSAndroid Build Coastguard Worker render(context, gles3Frame); // Call actual render func
485*35238bceSAndroid Build Coastguard Worker gles3Error = context.getError();
486*35238bceSAndroid Build Coastguard Worker }
487*35238bceSAndroid Build Coastguard Worker catch (const FboIncompleteException &e)
488*35238bceSAndroid Build Coastguard Worker {
489*35238bceSAndroid Build Coastguard Worker if (e.getReason() == GL_FRAMEBUFFER_UNSUPPORTED)
490*35238bceSAndroid Build Coastguard Worker {
491*35238bceSAndroid Build Coastguard Worker // Mark test case as unsupported
492*35238bceSAndroid Build Coastguard Worker log << e;
493*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not supported");
494*35238bceSAndroid Build Coastguard Worker return STOP;
495*35238bceSAndroid Build Coastguard Worker }
496*35238bceSAndroid Build Coastguard Worker else
497*35238bceSAndroid Build Coastguard Worker throw; // Propagate error
498*35238bceSAndroid Build Coastguard Worker }
499*35238bceSAndroid Build Coastguard Worker
500*35238bceSAndroid Build Coastguard Worker // Render reference image
501*35238bceSAndroid Build Coastguard Worker {
502*35238bceSAndroid Build Coastguard Worker sglr::ReferenceContextBuffers buffers(
503*35238bceSAndroid Build Coastguard Worker tcu::PixelFormat(8, 8, 8, renderTarget.getPixelFormat().alphaBits ? 8 : 0), renderTarget.getDepthBits(),
504*35238bceSAndroid Build Coastguard Worker renderTarget.getStencilBits(), width, height);
505*35238bceSAndroid Build Coastguard Worker sglr::ReferenceContext context(sglr::ReferenceContextLimits(renderCtx), buffers.getColorbuffer(),
506*35238bceSAndroid Build Coastguard Worker buffers.getDepthbuffer(), buffers.getStencilbuffer());
507*35238bceSAndroid Build Coastguard Worker
508*35238bceSAndroid Build Coastguard Worker context.clearColor(clearColor.x(), clearColor.y(), clearColor.z(), clearColor.w());
509*35238bceSAndroid Build Coastguard Worker context.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
510*35238bceSAndroid Build Coastguard Worker
511*35238bceSAndroid Build Coastguard Worker render(context, refFrame);
512*35238bceSAndroid Build Coastguard Worker refError = context.getError();
513*35238bceSAndroid Build Coastguard Worker }
514*35238bceSAndroid Build Coastguard Worker
515*35238bceSAndroid Build Coastguard Worker // Compare error codes
516*35238bceSAndroid Build Coastguard Worker bool errorCodesOk = (gles3Error == refError);
517*35238bceSAndroid Build Coastguard Worker
518*35238bceSAndroid Build Coastguard Worker if (!errorCodesOk)
519*35238bceSAndroid Build Coastguard Worker {
520*35238bceSAndroid Build Coastguard Worker log << tcu::TestLog::Message << "Error code mismatch: got " << glu::getErrorStr(gles3Error) << ", expected "
521*35238bceSAndroid Build Coastguard Worker << glu::getErrorStr(refError) << tcu::TestLog::EndMessage;
522*35238bceSAndroid Build Coastguard Worker failReason = "Got unexpected error";
523*35238bceSAndroid Build Coastguard Worker }
524*35238bceSAndroid Build Coastguard Worker
525*35238bceSAndroid Build Coastguard Worker // Compare images
526*35238bceSAndroid Build Coastguard Worker bool imagesOk = compare(refFrame, gles3Frame);
527*35238bceSAndroid Build Coastguard Worker
528*35238bceSAndroid Build Coastguard Worker if (!imagesOk && !failReason)
529*35238bceSAndroid Build Coastguard Worker failReason = "Image comparison failed";
530*35238bceSAndroid Build Coastguard Worker
531*35238bceSAndroid Build Coastguard Worker // Store test result
532*35238bceSAndroid Build Coastguard Worker bool isOk = errorCodesOk && imagesOk;
533*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL, isOk ? "Pass" : failReason);
534*35238bceSAndroid Build Coastguard Worker
535*35238bceSAndroid Build Coastguard Worker return STOP;
536*35238bceSAndroid Build Coastguard Worker }
537*35238bceSAndroid Build Coastguard Worker
compare(const tcu::Surface & reference,const tcu::Surface & result)538*35238bceSAndroid Build Coastguard Worker bool FboRenderCase::compare(const tcu::Surface &reference, const tcu::Surface &result)
539*35238bceSAndroid Build Coastguard Worker {
540*35238bceSAndroid Build Coastguard Worker const tcu::RGBA threshold(tcu::max(getFormatThreshold(m_config.colorFormat), tcu::RGBA(12, 12, 12, 12)));
541*35238bceSAndroid Build Coastguard Worker
542*35238bceSAndroid Build Coastguard Worker return tcu::bilinearCompare(m_testCtx.getLog(), "ComparisonResult", "Image comparison result",
543*35238bceSAndroid Build Coastguard Worker reference.getAccess(), result.getAccess(), threshold, tcu::COMPARE_LOG_RESULT);
544*35238bceSAndroid Build Coastguard Worker }
545*35238bceSAndroid Build Coastguard Worker
546*35238bceSAndroid Build Coastguard Worker namespace FboCases
547*35238bceSAndroid Build Coastguard Worker {
548*35238bceSAndroid Build Coastguard Worker
549*35238bceSAndroid Build Coastguard Worker class StencilClearsTest : public FboRenderCase
550*35238bceSAndroid Build Coastguard Worker {
551*35238bceSAndroid Build Coastguard Worker public:
552*35238bceSAndroid Build Coastguard Worker StencilClearsTest(Context &context, const FboConfig &config);
~StencilClearsTest(void)553*35238bceSAndroid Build Coastguard Worker virtual ~StencilClearsTest(void)
554*35238bceSAndroid Build Coastguard Worker {
555*35238bceSAndroid Build Coastguard Worker }
556*35238bceSAndroid Build Coastguard Worker
557*35238bceSAndroid Build Coastguard Worker void render(sglr::Context &context, Surface &dst);
558*35238bceSAndroid Build Coastguard Worker };
559*35238bceSAndroid Build Coastguard Worker
StencilClearsTest(Context & context,const FboConfig & config)560*35238bceSAndroid Build Coastguard Worker StencilClearsTest::StencilClearsTest(Context &context, const FboConfig &config)
561*35238bceSAndroid Build Coastguard Worker : FboRenderCase(context, config.getName().c_str(), "Stencil clears", config)
562*35238bceSAndroid Build Coastguard Worker {
563*35238bceSAndroid Build Coastguard Worker }
564*35238bceSAndroid Build Coastguard Worker
render(sglr::Context & context,Surface & dst)565*35238bceSAndroid Build Coastguard Worker void StencilClearsTest::render(sglr::Context &context, Surface &dst)
566*35238bceSAndroid Build Coastguard Worker {
567*35238bceSAndroid Build Coastguard Worker tcu::TextureFormat colorFormat = glu::mapGLInternalFormat(m_config.colorFormat);
568*35238bceSAndroid Build Coastguard Worker glu::DataType fboSamplerType = glu::getSampler2DType(colorFormat);
569*35238bceSAndroid Build Coastguard Worker glu::DataType fboOutputType = getFragmentOutputType(colorFormat);
570*35238bceSAndroid Build Coastguard Worker tcu::TextureFormatInfo fboRangeInfo = tcu::getTextureFormatInfo(colorFormat);
571*35238bceSAndroid Build Coastguard Worker Vec4 fboOutScale = fboRangeInfo.valueMax - fboRangeInfo.valueMin;
572*35238bceSAndroid Build Coastguard Worker Vec4 fboOutBias = fboRangeInfo.valueMin;
573*35238bceSAndroid Build Coastguard Worker
574*35238bceSAndroid Build Coastguard Worker Texture2DShader texToFboShader(DataTypes() << glu::TYPE_SAMPLER_2D, fboOutputType);
575*35238bceSAndroid Build Coastguard Worker Texture2DShader texFromFboShader(DataTypes() << fboSamplerType, glu::TYPE_FLOAT_VEC4);
576*35238bceSAndroid Build Coastguard Worker
577*35238bceSAndroid Build Coastguard Worker uint32_t texToFboShaderID = context.createProgram(&texToFboShader);
578*35238bceSAndroid Build Coastguard Worker uint32_t texFromFboShaderID = context.createProgram(&texFromFboShader);
579*35238bceSAndroid Build Coastguard Worker
580*35238bceSAndroid Build Coastguard Worker uint32_t metaballsTex = 1;
581*35238bceSAndroid Build Coastguard Worker uint32_t quadsTex = 2;
582*35238bceSAndroid Build Coastguard Worker int width = 128;
583*35238bceSAndroid Build Coastguard Worker int height = 128;
584*35238bceSAndroid Build Coastguard Worker
585*35238bceSAndroid Build Coastguard Worker texToFboShader.setOutScaleBias(fboOutScale, fboOutBias);
586*35238bceSAndroid Build Coastguard Worker texFromFboShader.setTexScaleBias(0, fboRangeInfo.lookupScale, fboRangeInfo.lookupBias);
587*35238bceSAndroid Build Coastguard Worker
588*35238bceSAndroid Build Coastguard Worker createQuadsTex2D(context, quadsTex, GL_RGBA, GL_UNSIGNED_BYTE, width, height);
589*35238bceSAndroid Build Coastguard Worker createMetaballsTex2D(context, metaballsTex, GL_RGBA, GL_UNSIGNED_BYTE, width, height);
590*35238bceSAndroid Build Coastguard Worker
591*35238bceSAndroid Build Coastguard Worker Framebuffer fbo(context, m_config, width, height);
592*35238bceSAndroid Build Coastguard Worker fbo.checkCompleteness();
593*35238bceSAndroid Build Coastguard Worker
594*35238bceSAndroid Build Coastguard Worker // Bind framebuffer and clear
595*35238bceSAndroid Build Coastguard Worker context.bindFramebuffer(GL_FRAMEBUFFER, fbo.getFramebuffer());
596*35238bceSAndroid Build Coastguard Worker context.viewport(0, 0, width, height);
597*35238bceSAndroid Build Coastguard Worker context.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
598*35238bceSAndroid Build Coastguard Worker context.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
599*35238bceSAndroid Build Coastguard Worker
600*35238bceSAndroid Build Coastguard Worker // Do stencil clears
601*35238bceSAndroid Build Coastguard Worker context.enable(GL_SCISSOR_TEST);
602*35238bceSAndroid Build Coastguard Worker context.scissor(10, 16, 32, 120);
603*35238bceSAndroid Build Coastguard Worker context.clearStencil(1);
604*35238bceSAndroid Build Coastguard Worker context.clear(GL_STENCIL_BUFFER_BIT);
605*35238bceSAndroid Build Coastguard Worker context.scissor(16, 32, 100, 64);
606*35238bceSAndroid Build Coastguard Worker context.clearStencil(2);
607*35238bceSAndroid Build Coastguard Worker context.clear(GL_STENCIL_BUFFER_BIT);
608*35238bceSAndroid Build Coastguard Worker context.disable(GL_SCISSOR_TEST);
609*35238bceSAndroid Build Coastguard Worker
610*35238bceSAndroid Build Coastguard Worker // Draw 2 textures with stecil tests
611*35238bceSAndroid Build Coastguard Worker context.enable(GL_STENCIL_TEST);
612*35238bceSAndroid Build Coastguard Worker
613*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, quadsTex);
614*35238bceSAndroid Build Coastguard Worker context.stencilFunc(GL_EQUAL, 1, 0xffu);
615*35238bceSAndroid Build Coastguard Worker
616*35238bceSAndroid Build Coastguard Worker texToFboShader.setUniforms(context, texToFboShaderID);
617*35238bceSAndroid Build Coastguard Worker sglr::drawQuad(context, texToFboShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(+1.0f, +1.0f, 0.0f));
618*35238bceSAndroid Build Coastguard Worker
619*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, metaballsTex);
620*35238bceSAndroid Build Coastguard Worker context.stencilFunc(GL_EQUAL, 2, 0xffu);
621*35238bceSAndroid Build Coastguard Worker
622*35238bceSAndroid Build Coastguard Worker texToFboShader.setUniforms(context, texToFboShaderID);
623*35238bceSAndroid Build Coastguard Worker sglr::drawQuad(context, texToFboShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(+1.0f, +1.0f, 0.0f));
624*35238bceSAndroid Build Coastguard Worker
625*35238bceSAndroid Build Coastguard Worker context.disable(GL_STENCIL_TEST);
626*35238bceSAndroid Build Coastguard Worker
627*35238bceSAndroid Build Coastguard Worker if (fbo.getConfig().colorType == GL_TEXTURE_2D)
628*35238bceSAndroid Build Coastguard Worker {
629*35238bceSAndroid Build Coastguard Worker context.bindFramebuffer(GL_FRAMEBUFFER, 0);
630*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, fbo.getColorBuffer());
631*35238bceSAndroid Build Coastguard Worker context.viewport(0, 0, context.getWidth(), context.getHeight());
632*35238bceSAndroid Build Coastguard Worker
633*35238bceSAndroid Build Coastguard Worker texFromFboShader.setUniforms(context, texFromFboShaderID);
634*35238bceSAndroid Build Coastguard Worker sglr::drawQuad(context, texFromFboShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
635*35238bceSAndroid Build Coastguard Worker
636*35238bceSAndroid Build Coastguard Worker context.readPixels(dst, 0, 0, context.getWidth(), context.getHeight());
637*35238bceSAndroid Build Coastguard Worker }
638*35238bceSAndroid Build Coastguard Worker else
639*35238bceSAndroid Build Coastguard Worker readPixels(context, dst, 0, 0, width, height, colorFormat, fboRangeInfo.lookupScale, fboRangeInfo.lookupBias);
640*35238bceSAndroid Build Coastguard Worker }
641*35238bceSAndroid Build Coastguard Worker
642*35238bceSAndroid Build Coastguard Worker class SharedColorbufferTest : public FboRenderCase
643*35238bceSAndroid Build Coastguard Worker {
644*35238bceSAndroid Build Coastguard Worker public:
645*35238bceSAndroid Build Coastguard Worker SharedColorbufferTest(Context &context, const FboConfig &config);
~SharedColorbufferTest(void)646*35238bceSAndroid Build Coastguard Worker virtual ~SharedColorbufferTest(void)
647*35238bceSAndroid Build Coastguard Worker {
648*35238bceSAndroid Build Coastguard Worker }
649*35238bceSAndroid Build Coastguard Worker
650*35238bceSAndroid Build Coastguard Worker void render(sglr::Context &context, Surface &dst);
651*35238bceSAndroid Build Coastguard Worker };
652*35238bceSAndroid Build Coastguard Worker
SharedColorbufferTest(Context & context,const FboConfig & config)653*35238bceSAndroid Build Coastguard Worker SharedColorbufferTest::SharedColorbufferTest(Context &context, const FboConfig &config)
654*35238bceSAndroid Build Coastguard Worker : FboRenderCase(context, config.getName().c_str(), "Shared colorbuffer", config)
655*35238bceSAndroid Build Coastguard Worker {
656*35238bceSAndroid Build Coastguard Worker }
657*35238bceSAndroid Build Coastguard Worker
render(sglr::Context & context,Surface & dst)658*35238bceSAndroid Build Coastguard Worker void SharedColorbufferTest::render(sglr::Context &context, Surface &dst)
659*35238bceSAndroid Build Coastguard Worker {
660*35238bceSAndroid Build Coastguard Worker Texture2DShader texShader(DataTypes() << glu::TYPE_SAMPLER_2D, glu::TYPE_FLOAT_VEC4);
661*35238bceSAndroid Build Coastguard Worker FlatColorShader flatShader(glu::TYPE_FLOAT_VEC4);
662*35238bceSAndroid Build Coastguard Worker uint32_t texShaderID = context.createProgram(&texShader);
663*35238bceSAndroid Build Coastguard Worker uint32_t flatShaderID = context.createProgram(&flatShader);
664*35238bceSAndroid Build Coastguard Worker
665*35238bceSAndroid Build Coastguard Worker int width = 128;
666*35238bceSAndroid Build Coastguard Worker int height = 128;
667*35238bceSAndroid Build Coastguard Worker uint32_t quadsTex = 1;
668*35238bceSAndroid Build Coastguard Worker uint32_t metaballsTex = 2;
669*35238bceSAndroid Build Coastguard Worker bool stencil = (m_config.buffers & GL_STENCIL_BUFFER_BIT) != 0;
670*35238bceSAndroid Build Coastguard Worker
671*35238bceSAndroid Build Coastguard Worker context.disable(GL_DITHER);
672*35238bceSAndroid Build Coastguard Worker
673*35238bceSAndroid Build Coastguard Worker // Textures
674*35238bceSAndroid Build Coastguard Worker createQuadsTex2D(context, quadsTex, GL_RGB, GL_UNSIGNED_BYTE, 64, 64);
675*35238bceSAndroid Build Coastguard Worker createMetaballsTex2D(context, metaballsTex, GL_RGBA, GL_UNSIGNED_BYTE, 64, 64);
676*35238bceSAndroid Build Coastguard Worker
677*35238bceSAndroid Build Coastguard Worker context.viewport(0, 0, width, height);
678*35238bceSAndroid Build Coastguard Worker
679*35238bceSAndroid Build Coastguard Worker // Fbo A
680*35238bceSAndroid Build Coastguard Worker Framebuffer fboA(context, m_config, width, height);
681*35238bceSAndroid Build Coastguard Worker fboA.checkCompleteness();
682*35238bceSAndroid Build Coastguard Worker
683*35238bceSAndroid Build Coastguard Worker // Fbo B - don't create colorbuffer
684*35238bceSAndroid Build Coastguard Worker FboConfig cfg = m_config;
685*35238bceSAndroid Build Coastguard Worker cfg.buffers &= ~GL_COLOR_BUFFER_BIT;
686*35238bceSAndroid Build Coastguard Worker cfg.colorType = GL_NONE;
687*35238bceSAndroid Build Coastguard Worker cfg.colorFormat = GL_NONE;
688*35238bceSAndroid Build Coastguard Worker Framebuffer fboB(context, cfg, width, height);
689*35238bceSAndroid Build Coastguard Worker
690*35238bceSAndroid Build Coastguard Worker // Attach color buffer from fbo A
691*35238bceSAndroid Build Coastguard Worker context.bindFramebuffer(GL_FRAMEBUFFER, fboB.getFramebuffer());
692*35238bceSAndroid Build Coastguard Worker switch (m_config.colorType)
693*35238bceSAndroid Build Coastguard Worker {
694*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_2D:
695*35238bceSAndroid Build Coastguard Worker context.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fboA.getColorBuffer(), 0);
696*35238bceSAndroid Build Coastguard Worker break;
697*35238bceSAndroid Build Coastguard Worker
698*35238bceSAndroid Build Coastguard Worker case GL_RENDERBUFFER:
699*35238bceSAndroid Build Coastguard Worker context.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, fboA.getColorBuffer());
700*35238bceSAndroid Build Coastguard Worker break;
701*35238bceSAndroid Build Coastguard Worker
702*35238bceSAndroid Build Coastguard Worker default:
703*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
704*35238bceSAndroid Build Coastguard Worker }
705*35238bceSAndroid Build Coastguard Worker
706*35238bceSAndroid Build Coastguard Worker // Clear depth and stencil in fbo B
707*35238bceSAndroid Build Coastguard Worker context.clear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
708*35238bceSAndroid Build Coastguard Worker
709*35238bceSAndroid Build Coastguard Worker // Render quads to fbo 1, with depth 0.0
710*35238bceSAndroid Build Coastguard Worker context.bindFramebuffer(GL_FRAMEBUFFER, fboA.getFramebuffer());
711*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, quadsTex);
712*35238bceSAndroid Build Coastguard Worker context.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
713*35238bceSAndroid Build Coastguard Worker context.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
714*35238bceSAndroid Build Coastguard Worker
715*35238bceSAndroid Build Coastguard Worker if (stencil)
716*35238bceSAndroid Build Coastguard Worker {
717*35238bceSAndroid Build Coastguard Worker // Stencil to 1 in fbo A
718*35238bceSAndroid Build Coastguard Worker context.clearStencil(1);
719*35238bceSAndroid Build Coastguard Worker context.clear(GL_STENCIL_BUFFER_BIT);
720*35238bceSAndroid Build Coastguard Worker }
721*35238bceSAndroid Build Coastguard Worker
722*35238bceSAndroid Build Coastguard Worker texShader.setUniforms(context, texShaderID);
723*35238bceSAndroid Build Coastguard Worker
724*35238bceSAndroid Build Coastguard Worker context.enable(GL_DEPTH_TEST);
725*35238bceSAndroid Build Coastguard Worker sglr::drawQuad(context, texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
726*35238bceSAndroid Build Coastguard Worker context.disable(GL_DEPTH_TEST);
727*35238bceSAndroid Build Coastguard Worker
728*35238bceSAndroid Build Coastguard Worker // Blend metaballs to fbo 2
729*35238bceSAndroid Build Coastguard Worker context.bindFramebuffer(GL_FRAMEBUFFER, fboB.getFramebuffer());
730*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, metaballsTex);
731*35238bceSAndroid Build Coastguard Worker context.enable(GL_BLEND);
732*35238bceSAndroid Build Coastguard Worker context.blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE);
733*35238bceSAndroid Build Coastguard Worker sglr::drawQuad(context, texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
734*35238bceSAndroid Build Coastguard Worker
735*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
736*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, quadsTex);
737*35238bceSAndroid Build Coastguard Worker context.enable(GL_DEPTH_TEST);
738*35238bceSAndroid Build Coastguard Worker sglr::drawQuad(context, texShaderID, Vec3(0.5f, 0.5f, 0.5f), Vec3(1.0f, 1.0f, 0.5f));
739*35238bceSAndroid Build Coastguard Worker context.disable(GL_DEPTH_TEST);
740*35238bceSAndroid Build Coastguard Worker
741*35238bceSAndroid Build Coastguard Worker if (stencil)
742*35238bceSAndroid Build Coastguard Worker {
743*35238bceSAndroid Build Coastguard Worker flatShader.setColor(context, flatShaderID, Vec4(0.0f, 1.0f, 0.0f, 1.0f));
744*35238bceSAndroid Build Coastguard Worker
745*35238bceSAndroid Build Coastguard Worker // Clear subset of stencil buffer to 1
746*35238bceSAndroid Build Coastguard Worker context.enable(GL_SCISSOR_TEST);
747*35238bceSAndroid Build Coastguard Worker context.scissor(10, 10, 12, 25);
748*35238bceSAndroid Build Coastguard Worker context.clearStencil(1);
749*35238bceSAndroid Build Coastguard Worker context.clear(GL_STENCIL_BUFFER_BIT);
750*35238bceSAndroid Build Coastguard Worker context.disable(GL_SCISSOR_TEST);
751*35238bceSAndroid Build Coastguard Worker
752*35238bceSAndroid Build Coastguard Worker // Render quad with stencil mask == 1
753*35238bceSAndroid Build Coastguard Worker context.enable(GL_STENCIL_TEST);
754*35238bceSAndroid Build Coastguard Worker context.stencilFunc(GL_EQUAL, 1, 0xffu);
755*35238bceSAndroid Build Coastguard Worker sglr::drawQuad(context, flatShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
756*35238bceSAndroid Build Coastguard Worker context.disable(GL_STENCIL_TEST);
757*35238bceSAndroid Build Coastguard Worker }
758*35238bceSAndroid Build Coastguard Worker
759*35238bceSAndroid Build Coastguard Worker // Get results
760*35238bceSAndroid Build Coastguard Worker if (fboA.getConfig().colorType == GL_TEXTURE_2D)
761*35238bceSAndroid Build Coastguard Worker {
762*35238bceSAndroid Build Coastguard Worker texShader.setUniforms(context, texShaderID);
763*35238bceSAndroid Build Coastguard Worker
764*35238bceSAndroid Build Coastguard Worker context.bindFramebuffer(GL_FRAMEBUFFER, 0);
765*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, fboA.getColorBuffer());
766*35238bceSAndroid Build Coastguard Worker context.viewport(0, 0, context.getWidth(), context.getHeight());
767*35238bceSAndroid Build Coastguard Worker sglr::drawQuad(context, texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
768*35238bceSAndroid Build Coastguard Worker context.readPixels(dst, 0, 0, context.getWidth(), context.getHeight());
769*35238bceSAndroid Build Coastguard Worker }
770*35238bceSAndroid Build Coastguard Worker else
771*35238bceSAndroid Build Coastguard Worker readPixels(context, dst, 0, 0, width, height, glu::mapGLInternalFormat(fboA.getConfig().colorFormat),
772*35238bceSAndroid Build Coastguard Worker Vec4(1.0f), Vec4(0.0f));
773*35238bceSAndroid Build Coastguard Worker }
774*35238bceSAndroid Build Coastguard Worker
775*35238bceSAndroid Build Coastguard Worker class SharedColorbufferClearsTest : public FboRenderCase
776*35238bceSAndroid Build Coastguard Worker {
777*35238bceSAndroid Build Coastguard Worker public:
778*35238bceSAndroid Build Coastguard Worker SharedColorbufferClearsTest(Context &context, const FboConfig &config);
~SharedColorbufferClearsTest(void)779*35238bceSAndroid Build Coastguard Worker virtual ~SharedColorbufferClearsTest(void)
780*35238bceSAndroid Build Coastguard Worker {
781*35238bceSAndroid Build Coastguard Worker }
782*35238bceSAndroid Build Coastguard Worker
783*35238bceSAndroid Build Coastguard Worker void render(sglr::Context &context, Surface &dst);
784*35238bceSAndroid Build Coastguard Worker };
785*35238bceSAndroid Build Coastguard Worker
SharedColorbufferClearsTest(Context & context,const FboConfig & config)786*35238bceSAndroid Build Coastguard Worker SharedColorbufferClearsTest::SharedColorbufferClearsTest(Context &context, const FboConfig &config)
787*35238bceSAndroid Build Coastguard Worker : FboRenderCase(context, config.getName().c_str(), "Shared colorbuffer clears", config)
788*35238bceSAndroid Build Coastguard Worker {
789*35238bceSAndroid Build Coastguard Worker }
790*35238bceSAndroid Build Coastguard Worker
render(sglr::Context & context,Surface & dst)791*35238bceSAndroid Build Coastguard Worker void SharedColorbufferClearsTest::render(sglr::Context &context, Surface &dst)
792*35238bceSAndroid Build Coastguard Worker {
793*35238bceSAndroid Build Coastguard Worker tcu::TextureFormat colorFormat = glu::mapGLInternalFormat(m_config.colorFormat);
794*35238bceSAndroid Build Coastguard Worker glu::DataType fboSamplerType = glu::getSampler2DType(colorFormat);
795*35238bceSAndroid Build Coastguard Worker int width = 128;
796*35238bceSAndroid Build Coastguard Worker int height = 128;
797*35238bceSAndroid Build Coastguard Worker uint32_t colorbuffer = 1;
798*35238bceSAndroid Build Coastguard Worker
799*35238bceSAndroid Build Coastguard Worker // Check for format support.
800*35238bceSAndroid Build Coastguard Worker checkColorFormatSupport(context, m_config.colorFormat);
801*35238bceSAndroid Build Coastguard Worker
802*35238bceSAndroid Build Coastguard Worker // Single colorbuffer
803*35238bceSAndroid Build Coastguard Worker if (m_config.colorType == GL_TEXTURE_2D)
804*35238bceSAndroid Build Coastguard Worker {
805*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, colorbuffer);
806*35238bceSAndroid Build Coastguard Worker context.texImage2D(GL_TEXTURE_2D, 0, m_config.colorFormat, width, height);
807*35238bceSAndroid Build Coastguard Worker context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
808*35238bceSAndroid Build Coastguard Worker context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
809*35238bceSAndroid Build Coastguard Worker }
810*35238bceSAndroid Build Coastguard Worker else
811*35238bceSAndroid Build Coastguard Worker {
812*35238bceSAndroid Build Coastguard Worker DE_ASSERT(m_config.colorType == GL_RENDERBUFFER);
813*35238bceSAndroid Build Coastguard Worker context.bindRenderbuffer(GL_RENDERBUFFER, colorbuffer);
814*35238bceSAndroid Build Coastguard Worker context.renderbufferStorage(GL_RENDERBUFFER, m_config.colorFormat, width, height);
815*35238bceSAndroid Build Coastguard Worker }
816*35238bceSAndroid Build Coastguard Worker
817*35238bceSAndroid Build Coastguard Worker // Multiple framebuffers sharing the colorbuffer
818*35238bceSAndroid Build Coastguard Worker for (int fbo = 1; fbo <= 3; fbo++)
819*35238bceSAndroid Build Coastguard Worker {
820*35238bceSAndroid Build Coastguard Worker context.bindFramebuffer(GL_FRAMEBUFFER, fbo);
821*35238bceSAndroid Build Coastguard Worker
822*35238bceSAndroid Build Coastguard Worker if (m_config.colorType == GL_TEXTURE_2D)
823*35238bceSAndroid Build Coastguard Worker context.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorbuffer, 0);
824*35238bceSAndroid Build Coastguard Worker else
825*35238bceSAndroid Build Coastguard Worker context.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorbuffer);
826*35238bceSAndroid Build Coastguard Worker }
827*35238bceSAndroid Build Coastguard Worker
828*35238bceSAndroid Build Coastguard Worker context.bindFramebuffer(GL_FRAMEBUFFER, 1);
829*35238bceSAndroid Build Coastguard Worker
830*35238bceSAndroid Build Coastguard Worker // Check completeness
831*35238bceSAndroid Build Coastguard Worker {
832*35238bceSAndroid Build Coastguard Worker GLenum status = context.checkFramebufferStatus(GL_FRAMEBUFFER);
833*35238bceSAndroid Build Coastguard Worker if (status != GL_FRAMEBUFFER_COMPLETE)
834*35238bceSAndroid Build Coastguard Worker throw FboIncompleteException(status, __FILE__, __LINE__);
835*35238bceSAndroid Build Coastguard Worker }
836*35238bceSAndroid Build Coastguard Worker
837*35238bceSAndroid Build Coastguard Worker // Render to them
838*35238bceSAndroid Build Coastguard Worker context.viewport(0, 0, width, height);
839*35238bceSAndroid Build Coastguard Worker context.clearColor(0.0f, 0.0f, 1.0f, 1.0f);
840*35238bceSAndroid Build Coastguard Worker context.clear(GL_COLOR_BUFFER_BIT);
841*35238bceSAndroid Build Coastguard Worker
842*35238bceSAndroid Build Coastguard Worker context.enable(GL_SCISSOR_TEST);
843*35238bceSAndroid Build Coastguard Worker
844*35238bceSAndroid Build Coastguard Worker context.bindFramebuffer(GL_FRAMEBUFFER, 2);
845*35238bceSAndroid Build Coastguard Worker context.clearColor(0.6f, 0.0f, 0.0f, 1.0f);
846*35238bceSAndroid Build Coastguard Worker context.scissor(10, 10, 64, 64);
847*35238bceSAndroid Build Coastguard Worker context.clear(GL_COLOR_BUFFER_BIT);
848*35238bceSAndroid Build Coastguard Worker context.clearColor(0.0f, 0.6f, 0.0f, 1.0f);
849*35238bceSAndroid Build Coastguard Worker context.scissor(60, 60, 40, 20);
850*35238bceSAndroid Build Coastguard Worker context.clear(GL_COLOR_BUFFER_BIT);
851*35238bceSAndroid Build Coastguard Worker
852*35238bceSAndroid Build Coastguard Worker context.bindFramebuffer(GL_FRAMEBUFFER, 3);
853*35238bceSAndroid Build Coastguard Worker context.clearColor(0.0f, 0.0f, 0.6f, 1.0f);
854*35238bceSAndroid Build Coastguard Worker context.scissor(20, 20, 100, 10);
855*35238bceSAndroid Build Coastguard Worker context.clear(GL_COLOR_BUFFER_BIT);
856*35238bceSAndroid Build Coastguard Worker
857*35238bceSAndroid Build Coastguard Worker context.bindFramebuffer(GL_FRAMEBUFFER, 1);
858*35238bceSAndroid Build Coastguard Worker context.clearColor(0.6f, 0.0f, 0.6f, 1.0f);
859*35238bceSAndroid Build Coastguard Worker context.scissor(20, 20, 5, 100);
860*35238bceSAndroid Build Coastguard Worker context.clear(GL_COLOR_BUFFER_BIT);
861*35238bceSAndroid Build Coastguard Worker
862*35238bceSAndroid Build Coastguard Worker context.disable(GL_SCISSOR_TEST);
863*35238bceSAndroid Build Coastguard Worker
864*35238bceSAndroid Build Coastguard Worker if (m_config.colorType == GL_TEXTURE_2D)
865*35238bceSAndroid Build Coastguard Worker {
866*35238bceSAndroid Build Coastguard Worker Texture2DShader shader(DataTypes() << fboSamplerType, glu::TYPE_FLOAT_VEC4);
867*35238bceSAndroid Build Coastguard Worker uint32_t shaderID = context.createProgram(&shader);
868*35238bceSAndroid Build Coastguard Worker
869*35238bceSAndroid Build Coastguard Worker shader.setUniforms(context, shaderID);
870*35238bceSAndroid Build Coastguard Worker
871*35238bceSAndroid Build Coastguard Worker context.bindFramebuffer(GL_FRAMEBUFFER, 0);
872*35238bceSAndroid Build Coastguard Worker context.viewport(0, 0, context.getWidth(), context.getHeight());
873*35238bceSAndroid Build Coastguard Worker sglr::drawQuad(context, shaderID, Vec3(-0.9f, -0.9f, 0.0f), Vec3(0.9f, 0.9f, 0.0f));
874*35238bceSAndroid Build Coastguard Worker context.readPixels(dst, 0, 0, context.getWidth(), context.getHeight());
875*35238bceSAndroid Build Coastguard Worker }
876*35238bceSAndroid Build Coastguard Worker else
877*35238bceSAndroid Build Coastguard Worker readPixels(context, dst, 0, 0, width, height, colorFormat, Vec4(1.0f), Vec4(0.0f));
878*35238bceSAndroid Build Coastguard Worker }
879*35238bceSAndroid Build Coastguard Worker
880*35238bceSAndroid Build Coastguard Worker class SharedDepthStencilTest : public FboRenderCase
881*35238bceSAndroid Build Coastguard Worker {
882*35238bceSAndroid Build Coastguard Worker public:
883*35238bceSAndroid Build Coastguard Worker SharedDepthStencilTest(Context &context, const FboConfig &config);
~SharedDepthStencilTest(void)884*35238bceSAndroid Build Coastguard Worker virtual ~SharedDepthStencilTest(void)
885*35238bceSAndroid Build Coastguard Worker {
886*35238bceSAndroid Build Coastguard Worker }
887*35238bceSAndroid Build Coastguard Worker
888*35238bceSAndroid Build Coastguard Worker static bool isConfigSupported(const FboConfig &config);
889*35238bceSAndroid Build Coastguard Worker void render(sglr::Context &context, Surface &dst);
890*35238bceSAndroid Build Coastguard Worker };
891*35238bceSAndroid Build Coastguard Worker
SharedDepthStencilTest(Context & context,const FboConfig & config)892*35238bceSAndroid Build Coastguard Worker SharedDepthStencilTest::SharedDepthStencilTest(Context &context, const FboConfig &config)
893*35238bceSAndroid Build Coastguard Worker : FboRenderCase(context, config.getName().c_str(), "Shared depth/stencilbuffer", config)
894*35238bceSAndroid Build Coastguard Worker {
895*35238bceSAndroid Build Coastguard Worker }
896*35238bceSAndroid Build Coastguard Worker
isConfigSupported(const FboConfig & config)897*35238bceSAndroid Build Coastguard Worker bool SharedDepthStencilTest::isConfigSupported(const FboConfig &config)
898*35238bceSAndroid Build Coastguard Worker {
899*35238bceSAndroid Build Coastguard Worker return (config.buffers & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0;
900*35238bceSAndroid Build Coastguard Worker }
901*35238bceSAndroid Build Coastguard Worker
render(sglr::Context & context,Surface & dst)902*35238bceSAndroid Build Coastguard Worker void SharedDepthStencilTest::render(sglr::Context &context, Surface &dst)
903*35238bceSAndroid Build Coastguard Worker {
904*35238bceSAndroid Build Coastguard Worker Texture2DShader texShader(DataTypes() << glu::TYPE_SAMPLER_2D, glu::TYPE_FLOAT_VEC4);
905*35238bceSAndroid Build Coastguard Worker FlatColorShader flatShader(glu::TYPE_FLOAT_VEC4);
906*35238bceSAndroid Build Coastguard Worker uint32_t texShaderID = context.createProgram(&texShader);
907*35238bceSAndroid Build Coastguard Worker uint32_t flatShaderID = context.createProgram(&flatShader);
908*35238bceSAndroid Build Coastguard Worker int width = 128;
909*35238bceSAndroid Build Coastguard Worker int height = 128;
910*35238bceSAndroid Build Coastguard Worker // bool depth = (m_config.buffers & GL_DEPTH_BUFFER_BIT) != 0;
911*35238bceSAndroid Build Coastguard Worker bool stencil = (m_config.buffers & GL_STENCIL_BUFFER_BIT) != 0;
912*35238bceSAndroid Build Coastguard Worker
913*35238bceSAndroid Build Coastguard Worker // Textures
914*35238bceSAndroid Build Coastguard Worker uint32_t metaballsTex = 5;
915*35238bceSAndroid Build Coastguard Worker uint32_t quadsTex = 6;
916*35238bceSAndroid Build Coastguard Worker createMetaballsTex2D(context, metaballsTex, GL_RGB, GL_UNSIGNED_BYTE, 64, 64);
917*35238bceSAndroid Build Coastguard Worker createQuadsTex2D(context, quadsTex, GL_RGB, GL_UNSIGNED_BYTE, 64, 64);
918*35238bceSAndroid Build Coastguard Worker
919*35238bceSAndroid Build Coastguard Worker context.viewport(0, 0, width, height);
920*35238bceSAndroid Build Coastguard Worker
921*35238bceSAndroid Build Coastguard Worker // Fbo A
922*35238bceSAndroid Build Coastguard Worker Framebuffer fboA(context, m_config, width, height);
923*35238bceSAndroid Build Coastguard Worker fboA.checkCompleteness();
924*35238bceSAndroid Build Coastguard Worker
925*35238bceSAndroid Build Coastguard Worker // Fbo B
926*35238bceSAndroid Build Coastguard Worker FboConfig cfg = m_config;
927*35238bceSAndroid Build Coastguard Worker cfg.buffers &= ~(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
928*35238bceSAndroid Build Coastguard Worker cfg.depthStencilType = GL_NONE;
929*35238bceSAndroid Build Coastguard Worker cfg.depthStencilFormat = GL_NONE;
930*35238bceSAndroid Build Coastguard Worker Framebuffer fboB(context, cfg, width, height);
931*35238bceSAndroid Build Coastguard Worker
932*35238bceSAndroid Build Coastguard Worker // Bind depth/stencil buffers from fbo A to fbo B
933*35238bceSAndroid Build Coastguard Worker context.bindFramebuffer(GL_FRAMEBUFFER, fboB.getFramebuffer());
934*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < 2; ndx++)
935*35238bceSAndroid Build Coastguard Worker {
936*35238bceSAndroid Build Coastguard Worker uint32_t bit = ndx ? GL_STENCIL_BUFFER_BIT : GL_DEPTH_BUFFER_BIT;
937*35238bceSAndroid Build Coastguard Worker uint32_t point = ndx ? GL_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT;
938*35238bceSAndroid Build Coastguard Worker
939*35238bceSAndroid Build Coastguard Worker if ((m_config.buffers & bit) == 0)
940*35238bceSAndroid Build Coastguard Worker continue;
941*35238bceSAndroid Build Coastguard Worker
942*35238bceSAndroid Build Coastguard Worker switch (m_config.depthStencilType)
943*35238bceSAndroid Build Coastguard Worker {
944*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_2D:
945*35238bceSAndroid Build Coastguard Worker context.framebufferTexture2D(GL_FRAMEBUFFER, point, GL_TEXTURE_2D, fboA.getDepthStencilBuffer(), 0);
946*35238bceSAndroid Build Coastguard Worker break;
947*35238bceSAndroid Build Coastguard Worker case GL_RENDERBUFFER:
948*35238bceSAndroid Build Coastguard Worker context.framebufferRenderbuffer(GL_FRAMEBUFFER, point, GL_RENDERBUFFER, fboA.getDepthStencilBuffer());
949*35238bceSAndroid Build Coastguard Worker break;
950*35238bceSAndroid Build Coastguard Worker default:
951*35238bceSAndroid Build Coastguard Worker TCU_FAIL("Not implemented");
952*35238bceSAndroid Build Coastguard Worker }
953*35238bceSAndroid Build Coastguard Worker }
954*35238bceSAndroid Build Coastguard Worker
955*35238bceSAndroid Build Coastguard Worker // Setup uniforms
956*35238bceSAndroid Build Coastguard Worker texShader.setUniforms(context, texShaderID);
957*35238bceSAndroid Build Coastguard Worker
958*35238bceSAndroid Build Coastguard Worker // Clear color to red and stencil to 1 in fbo B.
959*35238bceSAndroid Build Coastguard Worker context.clearColor(1.0f, 0.0f, 0.0f, 1.0f);
960*35238bceSAndroid Build Coastguard Worker context.clearStencil(1);
961*35238bceSAndroid Build Coastguard Worker context.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
962*35238bceSAndroid Build Coastguard Worker
963*35238bceSAndroid Build Coastguard Worker context.enable(GL_DEPTH_TEST);
964*35238bceSAndroid Build Coastguard Worker
965*35238bceSAndroid Build Coastguard Worker // Render quad to fbo A
966*35238bceSAndroid Build Coastguard Worker context.bindFramebuffer(GL_FRAMEBUFFER, fboA.getFramebuffer());
967*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, quadsTex);
968*35238bceSAndroid Build Coastguard Worker sglr::drawQuad(context, texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
969*35238bceSAndroid Build Coastguard Worker
970*35238bceSAndroid Build Coastguard Worker if (stencil)
971*35238bceSAndroid Build Coastguard Worker {
972*35238bceSAndroid Build Coastguard Worker // Clear subset of stencil buffer to 0 in fbo A
973*35238bceSAndroid Build Coastguard Worker context.enable(GL_SCISSOR_TEST);
974*35238bceSAndroid Build Coastguard Worker context.scissor(10, 10, 12, 25);
975*35238bceSAndroid Build Coastguard Worker context.clearStencil(0);
976*35238bceSAndroid Build Coastguard Worker context.clear(GL_STENCIL_BUFFER_BIT);
977*35238bceSAndroid Build Coastguard Worker context.disable(GL_SCISSOR_TEST);
978*35238bceSAndroid Build Coastguard Worker }
979*35238bceSAndroid Build Coastguard Worker
980*35238bceSAndroid Build Coastguard Worker // Render metaballs to fbo B
981*35238bceSAndroid Build Coastguard Worker context.bindFramebuffer(GL_FRAMEBUFFER, fboB.getFramebuffer());
982*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, metaballsTex);
983*35238bceSAndroid Build Coastguard Worker sglr::drawQuad(context, texShaderID, Vec3(-1.0f, -1.0f, -1.0f), Vec3(1.0f, 1.0f, 1.0f));
984*35238bceSAndroid Build Coastguard Worker
985*35238bceSAndroid Build Coastguard Worker context.disable(GL_DEPTH_TEST);
986*35238bceSAndroid Build Coastguard Worker
987*35238bceSAndroid Build Coastguard Worker if (stencil)
988*35238bceSAndroid Build Coastguard Worker {
989*35238bceSAndroid Build Coastguard Worker // Render quad with stencil mask == 0
990*35238bceSAndroid Build Coastguard Worker context.enable(GL_STENCIL_TEST);
991*35238bceSAndroid Build Coastguard Worker context.stencilFunc(GL_EQUAL, 0, 0xffu);
992*35238bceSAndroid Build Coastguard Worker context.useProgram(flatShaderID);
993*35238bceSAndroid Build Coastguard Worker flatShader.setColor(context, flatShaderID, Vec4(0.0f, 1.0f, 0.0f, 1.0f));
994*35238bceSAndroid Build Coastguard Worker sglr::drawQuad(context, flatShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(+1.0f, +1.0f, 0.0f));
995*35238bceSAndroid Build Coastguard Worker context.disable(GL_STENCIL_TEST);
996*35238bceSAndroid Build Coastguard Worker }
997*35238bceSAndroid Build Coastguard Worker
998*35238bceSAndroid Build Coastguard Worker if (m_config.colorType == GL_TEXTURE_2D)
999*35238bceSAndroid Build Coastguard Worker {
1000*35238bceSAndroid Build Coastguard Worker // Render both to screen
1001*35238bceSAndroid Build Coastguard Worker context.bindFramebuffer(GL_FRAMEBUFFER, 0);
1002*35238bceSAndroid Build Coastguard Worker context.viewport(0, 0, context.getWidth(), context.getHeight());
1003*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, fboA.getColorBuffer());
1004*35238bceSAndroid Build Coastguard Worker sglr::drawQuad(context, texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(0.0f, 1.0f, 0.0f));
1005*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, fboB.getColorBuffer());
1006*35238bceSAndroid Build Coastguard Worker sglr::drawQuad(context, texShaderID, Vec3(0.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
1007*35238bceSAndroid Build Coastguard Worker
1008*35238bceSAndroid Build Coastguard Worker context.readPixels(dst, 0, 0, context.getWidth(), context.getHeight());
1009*35238bceSAndroid Build Coastguard Worker }
1010*35238bceSAndroid Build Coastguard Worker else
1011*35238bceSAndroid Build Coastguard Worker {
1012*35238bceSAndroid Build Coastguard Worker // Read results from fbo B
1013*35238bceSAndroid Build Coastguard Worker readPixels(context, dst, 0, 0, width, height, glu::mapGLInternalFormat(m_config.colorFormat), Vec4(1.0f),
1014*35238bceSAndroid Build Coastguard Worker Vec4(0.0f));
1015*35238bceSAndroid Build Coastguard Worker }
1016*35238bceSAndroid Build Coastguard Worker }
1017*35238bceSAndroid Build Coastguard Worker
1018*35238bceSAndroid Build Coastguard Worker #if 0
1019*35238bceSAndroid Build Coastguard Worker class TexSubImageAfterRenderTest : public FboRenderCase
1020*35238bceSAndroid Build Coastguard Worker {
1021*35238bceSAndroid Build Coastguard Worker public:
1022*35238bceSAndroid Build Coastguard Worker TexSubImageAfterRenderTest (Context& context, const FboConfig& config);
1023*35238bceSAndroid Build Coastguard Worker virtual ~TexSubImageAfterRenderTest (void) {}
1024*35238bceSAndroid Build Coastguard Worker
1025*35238bceSAndroid Build Coastguard Worker void render (sglr::Context& context, Surface& dst);
1026*35238bceSAndroid Build Coastguard Worker };
1027*35238bceSAndroid Build Coastguard Worker
1028*35238bceSAndroid Build Coastguard Worker TexSubImageAfterRenderTest::TexSubImageAfterRenderTest (Context& context, const FboConfig& config)
1029*35238bceSAndroid Build Coastguard Worker : FboRenderCase(context, (string("after_render_") + config.getName()).c_str(), "TexSubImage after rendering to texture", config)
1030*35238bceSAndroid Build Coastguard Worker {
1031*35238bceSAndroid Build Coastguard Worker }
1032*35238bceSAndroid Build Coastguard Worker
1033*35238bceSAndroid Build Coastguard Worker void TexSubImageAfterRenderTest::render (sglr::Context& context, Surface& dst)
1034*35238bceSAndroid Build Coastguard Worker {
1035*35238bceSAndroid Build Coastguard Worker using sglr::TexturedQuadOp;
1036*35238bceSAndroid Build Coastguard Worker
1037*35238bceSAndroid Build Coastguard Worker bool isRGBA = true;
1038*35238bceSAndroid Build Coastguard Worker
1039*35238bceSAndroid Build Coastguard Worker Surface fourQuads(Surface::PIXELFORMAT_RGB, 64, 64);
1040*35238bceSAndroid Build Coastguard Worker tcu::SurfaceUtil::fillWithFourQuads(fourQuads);
1041*35238bceSAndroid Build Coastguard Worker
1042*35238bceSAndroid Build Coastguard Worker Surface metaballs(isRGBA ? Surface::PIXELFORMAT_RGBA : Surface::PIXELFORMAT_RGB, 64, 64);
1043*35238bceSAndroid Build Coastguard Worker tcu::SurfaceUtil::fillWithMetaballs(metaballs, 5, 3);
1044*35238bceSAndroid Build Coastguard Worker
1045*35238bceSAndroid Build Coastguard Worker uint32_t fourQuadsTex = 1;
1046*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, fourQuadsTex);
1047*35238bceSAndroid Build Coastguard Worker context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1048*35238bceSAndroid Build Coastguard Worker context.texImage2D(GL_TEXTURE_2D, 0, GL_RGB, fourQuads);
1049*35238bceSAndroid Build Coastguard Worker
1050*35238bceSAndroid Build Coastguard Worker context.bindFramebuffer(GL_FRAMEBUFFER, 1);
1051*35238bceSAndroid Build Coastguard Worker
1052*35238bceSAndroid Build Coastguard Worker uint32_t fboTex = 2;
1053*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, fboTex);
1054*35238bceSAndroid Build Coastguard Worker context.texImage2D(GL_TEXTURE_2D, 0, isRGBA ? GL_RGBA : GL_RGB, 128, 128);
1055*35238bceSAndroid Build Coastguard Worker context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1056*35238bceSAndroid Build Coastguard Worker context.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fboTex, 0);
1057*35238bceSAndroid Build Coastguard Worker
1058*35238bceSAndroid Build Coastguard Worker // Render to fbo
1059*35238bceSAndroid Build Coastguard Worker context.viewport(0, 0, 128, 128);
1060*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, fourQuadsTex);
1061*35238bceSAndroid Build Coastguard Worker context.draw(TexturedQuadOp(-1.0f, -1.0f, 1.0f, 1.0f, 0));
1062*35238bceSAndroid Build Coastguard Worker
1063*35238bceSAndroid Build Coastguard Worker // Update texture using TexSubImage2D
1064*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, fboTex);
1065*35238bceSAndroid Build Coastguard Worker context.texSubImage2D(GL_TEXTURE_2D, 0, 32, 32, metaballs);
1066*35238bceSAndroid Build Coastguard Worker
1067*35238bceSAndroid Build Coastguard Worker // Draw to screen
1068*35238bceSAndroid Build Coastguard Worker context.bindFramebuffer(GL_FRAMEBUFFER, 0);
1069*35238bceSAndroid Build Coastguard Worker context.viewport(0, 0, context.getWidth(), context.getHeight());
1070*35238bceSAndroid Build Coastguard Worker context.draw(TexturedQuadOp(-1.0f, -1.0f, 1.0f, 1.0f, 0));
1071*35238bceSAndroid Build Coastguard Worker context.readPixels(dst, 0, 0, context.getWidth(), context.getHeight());
1072*35238bceSAndroid Build Coastguard Worker }
1073*35238bceSAndroid Build Coastguard Worker
1074*35238bceSAndroid Build Coastguard Worker class TexSubImageBetweenRenderTest : public FboRenderCase
1075*35238bceSAndroid Build Coastguard Worker {
1076*35238bceSAndroid Build Coastguard Worker public:
1077*35238bceSAndroid Build Coastguard Worker TexSubImageBetweenRenderTest (Context& context, const FboConfig& config);
1078*35238bceSAndroid Build Coastguard Worker virtual ~TexSubImageBetweenRenderTest (void) {}
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
1083*35238bceSAndroid Build Coastguard Worker TexSubImageBetweenRenderTest::TexSubImageBetweenRenderTest (Context& context, const FboConfig& config)
1084*35238bceSAndroid Build Coastguard Worker : FboRenderCase(context, (string("between_render_") + config.getName()).c_str(), "TexSubImage between rendering calls", config)
1085*35238bceSAndroid Build Coastguard Worker {
1086*35238bceSAndroid Build Coastguard Worker }
1087*35238bceSAndroid Build Coastguard Worker
1088*35238bceSAndroid Build Coastguard Worker void TexSubImageBetweenRenderTest::render (sglr::Context& context, Surface& dst)
1089*35238bceSAndroid Build Coastguard Worker {
1090*35238bceSAndroid Build Coastguard Worker using sglr::TexturedQuadOp;
1091*35238bceSAndroid Build Coastguard Worker using sglr::BlendTextureOp;
1092*35238bceSAndroid Build Coastguard Worker
1093*35238bceSAndroid Build Coastguard Worker bool isRGBA = true;
1094*35238bceSAndroid Build Coastguard Worker
1095*35238bceSAndroid Build Coastguard Worker Surface fourQuads(Surface::PIXELFORMAT_RGB, 64, 64);
1096*35238bceSAndroid Build Coastguard Worker tcu::SurfaceUtil::fillWithFourQuads(fourQuads);
1097*35238bceSAndroid Build Coastguard Worker
1098*35238bceSAndroid Build Coastguard Worker Surface metaballs(isRGBA ? Surface::PIXELFORMAT_RGBA : Surface::PIXELFORMAT_RGB, 64, 64);
1099*35238bceSAndroid Build Coastguard Worker tcu::SurfaceUtil::fillWithMetaballs(metaballs, 5, 3);
1100*35238bceSAndroid Build Coastguard Worker
1101*35238bceSAndroid Build Coastguard Worker Surface metaballs2(Surface::PIXELFORMAT_RGBA, 64, 64);
1102*35238bceSAndroid Build Coastguard Worker tcu::SurfaceUtil::fillWithMetaballs(metaballs2, 5, 4);
1103*35238bceSAndroid Build Coastguard Worker
1104*35238bceSAndroid Build Coastguard Worker uint32_t metaballsTex = 3;
1105*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, metaballsTex);
1106*35238bceSAndroid Build Coastguard Worker context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1107*35238bceSAndroid Build Coastguard Worker context.texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, metaballs2);
1108*35238bceSAndroid Build Coastguard Worker
1109*35238bceSAndroid Build Coastguard Worker uint32_t fourQuadsTex = 1;
1110*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, fourQuadsTex);
1111*35238bceSAndroid Build Coastguard Worker context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1112*35238bceSAndroid Build Coastguard Worker context.texImage2D(GL_TEXTURE_2D, 0, GL_RGB, fourQuads);
1113*35238bceSAndroid Build Coastguard Worker
1114*35238bceSAndroid Build Coastguard Worker context.bindFramebuffer(GL_FRAMEBUFFER, 1);
1115*35238bceSAndroid Build Coastguard Worker
1116*35238bceSAndroid Build Coastguard Worker uint32_t fboTex = 2;
1117*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, fboTex);
1118*35238bceSAndroid Build Coastguard Worker context.texImage2D(GL_TEXTURE_2D, 0, isRGBA ? GL_RGBA : GL_RGB, 128, 128);
1119*35238bceSAndroid Build Coastguard Worker context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1120*35238bceSAndroid Build Coastguard Worker context.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fboTex, 0);
1121*35238bceSAndroid Build Coastguard Worker
1122*35238bceSAndroid Build Coastguard Worker // Render to fbo
1123*35238bceSAndroid Build Coastguard Worker context.viewport(0, 0, 128, 128);
1124*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, fourQuadsTex);
1125*35238bceSAndroid Build Coastguard Worker context.draw(TexturedQuadOp(-1.0f, -1.0f, 1.0f, 1.0f, 0));
1126*35238bceSAndroid Build Coastguard Worker
1127*35238bceSAndroid Build Coastguard Worker // Update texture using TexSubImage2D
1128*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, fboTex);
1129*35238bceSAndroid Build Coastguard Worker context.texSubImage2D(GL_TEXTURE_2D, 0, 32, 32, metaballs);
1130*35238bceSAndroid Build Coastguard Worker
1131*35238bceSAndroid Build Coastguard Worker // Render again to fbo
1132*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, metaballsTex);
1133*35238bceSAndroid Build Coastguard Worker context.draw(BlendTextureOp(0));
1134*35238bceSAndroid Build Coastguard Worker
1135*35238bceSAndroid Build Coastguard Worker // Draw to screen
1136*35238bceSAndroid Build Coastguard Worker context.bindFramebuffer(GL_FRAMEBUFFER, 0);
1137*35238bceSAndroid Build Coastguard Worker context.viewport(0, 0, context.getWidth(), context.getHeight());
1138*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, fboTex);
1139*35238bceSAndroid Build Coastguard Worker context.draw(TexturedQuadOp(-1.0f, -1.0f, 1.0f, 1.0f, 0));
1140*35238bceSAndroid Build Coastguard Worker
1141*35238bceSAndroid Build Coastguard Worker context.readPixels(dst, 0, 0, context.getWidth(), context.getHeight());
1142*35238bceSAndroid Build Coastguard Worker }
1143*35238bceSAndroid Build Coastguard Worker #endif
1144*35238bceSAndroid Build Coastguard Worker
1145*35238bceSAndroid Build Coastguard Worker class ResizeTest : public FboRenderCase
1146*35238bceSAndroid Build Coastguard Worker {
1147*35238bceSAndroid Build Coastguard Worker public:
1148*35238bceSAndroid Build Coastguard Worker ResizeTest(Context &context, const FboConfig &config);
~ResizeTest(void)1149*35238bceSAndroid Build Coastguard Worker virtual ~ResizeTest(void)
1150*35238bceSAndroid Build Coastguard Worker {
1151*35238bceSAndroid Build Coastguard Worker }
1152*35238bceSAndroid Build Coastguard Worker
1153*35238bceSAndroid Build Coastguard Worker void render(sglr::Context &context, Surface &dst);
1154*35238bceSAndroid Build Coastguard Worker };
1155*35238bceSAndroid Build Coastguard Worker
ResizeTest(Context & context,const FboConfig & config)1156*35238bceSAndroid Build Coastguard Worker ResizeTest::ResizeTest(Context &context, const FboConfig &config)
1157*35238bceSAndroid Build Coastguard Worker : FboRenderCase(context, config.getName().c_str(), "Resize framebuffer", config)
1158*35238bceSAndroid Build Coastguard Worker {
1159*35238bceSAndroid Build Coastguard Worker }
1160*35238bceSAndroid Build Coastguard Worker
render(sglr::Context & context,Surface & dst)1161*35238bceSAndroid Build Coastguard Worker void ResizeTest::render(sglr::Context &context, Surface &dst)
1162*35238bceSAndroid Build Coastguard Worker {
1163*35238bceSAndroid Build Coastguard Worker tcu::TextureFormat colorFormat = glu::mapGLInternalFormat(m_config.colorFormat);
1164*35238bceSAndroid Build Coastguard Worker glu::DataType fboSamplerType = glu::getSampler2DType(colorFormat);
1165*35238bceSAndroid Build Coastguard Worker glu::DataType fboOutputType = getFragmentOutputType(colorFormat);
1166*35238bceSAndroid Build Coastguard Worker tcu::TextureFormatInfo fboRangeInfo = tcu::getTextureFormatInfo(colorFormat);
1167*35238bceSAndroid Build Coastguard Worker Vec4 fboOutScale = fboRangeInfo.valueMax - fboRangeInfo.valueMin;
1168*35238bceSAndroid Build Coastguard Worker Vec4 fboOutBias = fboRangeInfo.valueMin;
1169*35238bceSAndroid Build Coastguard Worker
1170*35238bceSAndroid Build Coastguard Worker Texture2DShader texToFboShader(DataTypes() << glu::TYPE_SAMPLER_2D, fboOutputType);
1171*35238bceSAndroid Build Coastguard Worker Texture2DShader texFromFboShader(DataTypes() << fboSamplerType, glu::TYPE_FLOAT_VEC4);
1172*35238bceSAndroid Build Coastguard Worker FlatColorShader flatShader(fboOutputType);
1173*35238bceSAndroid Build Coastguard Worker uint32_t texToFboShaderID = context.createProgram(&texToFboShader);
1174*35238bceSAndroid Build Coastguard Worker uint32_t texFromFboShaderID = context.createProgram(&texFromFboShader);
1175*35238bceSAndroid Build Coastguard Worker uint32_t flatShaderID = context.createProgram(&flatShader);
1176*35238bceSAndroid Build Coastguard Worker
1177*35238bceSAndroid Build Coastguard Worker uint32_t quadsTex = 1;
1178*35238bceSAndroid Build Coastguard Worker uint32_t metaballsTex = 2;
1179*35238bceSAndroid Build Coastguard Worker bool depth = (m_config.buffers & GL_DEPTH_BUFFER_BIT) != 0;
1180*35238bceSAndroid Build Coastguard Worker bool stencil = (m_config.buffers & GL_STENCIL_BUFFER_BIT) != 0;
1181*35238bceSAndroid Build Coastguard Worker int initialWidth = 128;
1182*35238bceSAndroid Build Coastguard Worker int initialHeight = 128;
1183*35238bceSAndroid Build Coastguard Worker int newWidth = 64;
1184*35238bceSAndroid Build Coastguard Worker int newHeight = 32;
1185*35238bceSAndroid Build Coastguard Worker
1186*35238bceSAndroid Build Coastguard Worker texToFboShader.setOutScaleBias(fboOutScale, fboOutBias);
1187*35238bceSAndroid Build Coastguard Worker texFromFboShader.setTexScaleBias(0, fboRangeInfo.lookupScale, fboRangeInfo.lookupBias);
1188*35238bceSAndroid Build Coastguard Worker
1189*35238bceSAndroid Build Coastguard Worker createQuadsTex2D(context, quadsTex, GL_RGB, GL_UNSIGNED_BYTE, 64, 64);
1190*35238bceSAndroid Build Coastguard Worker createMetaballsTex2D(context, metaballsTex, GL_RGB, GL_UNSIGNED_BYTE, 32, 32);
1191*35238bceSAndroid Build Coastguard Worker
1192*35238bceSAndroid Build Coastguard Worker Framebuffer fbo(context, m_config, initialWidth, initialHeight);
1193*35238bceSAndroid Build Coastguard Worker fbo.checkCompleteness();
1194*35238bceSAndroid Build Coastguard Worker
1195*35238bceSAndroid Build Coastguard Worker // Setup shaders
1196*35238bceSAndroid Build Coastguard Worker texToFboShader.setUniforms(context, texToFboShaderID);
1197*35238bceSAndroid Build Coastguard Worker texFromFboShader.setUniforms(context, texFromFboShaderID);
1198*35238bceSAndroid Build Coastguard Worker flatShader.setColor(context, flatShaderID, Vec4(0.0f, 1.0f, 0.0f, 1.0f) * fboOutScale + fboOutBias);
1199*35238bceSAndroid Build Coastguard Worker
1200*35238bceSAndroid Build Coastguard Worker // Render quads
1201*35238bceSAndroid Build Coastguard Worker context.bindFramebuffer(GL_FRAMEBUFFER, fbo.getFramebuffer());
1202*35238bceSAndroid Build Coastguard Worker context.viewport(0, 0, initialWidth, initialHeight);
1203*35238bceSAndroid Build Coastguard Worker clearColorBuffer(context, colorFormat, tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
1204*35238bceSAndroid Build Coastguard Worker context.clear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1205*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, quadsTex);
1206*35238bceSAndroid Build Coastguard Worker sglr::drawQuad(context, texToFboShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
1207*35238bceSAndroid Build Coastguard Worker
1208*35238bceSAndroid Build Coastguard Worker if (fbo.getConfig().colorType == GL_TEXTURE_2D)
1209*35238bceSAndroid Build Coastguard Worker {
1210*35238bceSAndroid Build Coastguard Worker // Render fbo to screen
1211*35238bceSAndroid Build Coastguard Worker context.bindFramebuffer(GL_FRAMEBUFFER, 0);
1212*35238bceSAndroid Build Coastguard Worker context.viewport(0, 0, context.getWidth(), context.getHeight());
1213*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, fbo.getColorBuffer());
1214*35238bceSAndroid Build Coastguard Worker sglr::drawQuad(context, texFromFboShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
1215*35238bceSAndroid Build Coastguard Worker
1216*35238bceSAndroid Build Coastguard Worker // Restore binding
1217*35238bceSAndroid Build Coastguard Worker context.bindFramebuffer(GL_FRAMEBUFFER, fbo.getFramebuffer());
1218*35238bceSAndroid Build Coastguard Worker }
1219*35238bceSAndroid Build Coastguard Worker
1220*35238bceSAndroid Build Coastguard Worker // Resize buffers
1221*35238bceSAndroid Build Coastguard Worker switch (fbo.getConfig().colorType)
1222*35238bceSAndroid Build Coastguard Worker {
1223*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_2D:
1224*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, fbo.getColorBuffer());
1225*35238bceSAndroid Build Coastguard Worker context.texImage2D(GL_TEXTURE_2D, 0, fbo.getConfig().colorFormat, newWidth, newHeight);
1226*35238bceSAndroid Build Coastguard Worker break;
1227*35238bceSAndroid Build Coastguard Worker
1228*35238bceSAndroid Build Coastguard Worker case GL_RENDERBUFFER:
1229*35238bceSAndroid Build Coastguard Worker context.bindRenderbuffer(GL_RENDERBUFFER, fbo.getColorBuffer());
1230*35238bceSAndroid Build Coastguard Worker context.renderbufferStorage(GL_RENDERBUFFER, fbo.getConfig().colorFormat, newWidth, newHeight);
1231*35238bceSAndroid Build Coastguard Worker break;
1232*35238bceSAndroid Build Coastguard Worker
1233*35238bceSAndroid Build Coastguard Worker default:
1234*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
1235*35238bceSAndroid Build Coastguard Worker }
1236*35238bceSAndroid Build Coastguard Worker
1237*35238bceSAndroid Build Coastguard Worker if (depth || stencil)
1238*35238bceSAndroid Build Coastguard Worker {
1239*35238bceSAndroid Build Coastguard Worker switch (fbo.getConfig().depthStencilType)
1240*35238bceSAndroid Build Coastguard Worker {
1241*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_2D:
1242*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, fbo.getDepthStencilBuffer());
1243*35238bceSAndroid Build Coastguard Worker context.texImage2D(GL_TEXTURE_2D, 0, fbo.getConfig().depthStencilFormat, newWidth, newHeight);
1244*35238bceSAndroid Build Coastguard Worker break;
1245*35238bceSAndroid Build Coastguard Worker
1246*35238bceSAndroid Build Coastguard Worker case GL_RENDERBUFFER:
1247*35238bceSAndroid Build Coastguard Worker context.bindRenderbuffer(GL_RENDERBUFFER, fbo.getDepthStencilBuffer());
1248*35238bceSAndroid Build Coastguard Worker context.renderbufferStorage(GL_RENDERBUFFER, fbo.getConfig().depthStencilFormat, newWidth, newHeight);
1249*35238bceSAndroid Build Coastguard Worker break;
1250*35238bceSAndroid Build Coastguard Worker
1251*35238bceSAndroid Build Coastguard Worker default:
1252*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
1253*35238bceSAndroid Build Coastguard Worker }
1254*35238bceSAndroid Build Coastguard Worker }
1255*35238bceSAndroid Build Coastguard Worker
1256*35238bceSAndroid Build Coastguard Worker // Render to resized fbo
1257*35238bceSAndroid Build Coastguard Worker context.viewport(0, 0, newWidth, newHeight);
1258*35238bceSAndroid Build Coastguard Worker clearColorBuffer(context, colorFormat, tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f));
1259*35238bceSAndroid Build Coastguard Worker context.clear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1260*35238bceSAndroid Build Coastguard Worker
1261*35238bceSAndroid Build Coastguard Worker context.enable(GL_DEPTH_TEST);
1262*35238bceSAndroid Build Coastguard Worker
1263*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, metaballsTex);
1264*35238bceSAndroid Build Coastguard Worker sglr::drawQuad(context, texToFboShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(+1.0f, +1.0f, 0.0f));
1265*35238bceSAndroid Build Coastguard Worker
1266*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, quadsTex);
1267*35238bceSAndroid Build Coastguard Worker sglr::drawQuad(context, texToFboShaderID, Vec3(0.0f, 0.0f, -1.0f), Vec3(+1.0f, +1.0f, 1.0f));
1268*35238bceSAndroid Build Coastguard Worker
1269*35238bceSAndroid Build Coastguard Worker context.disable(GL_DEPTH_TEST);
1270*35238bceSAndroid Build Coastguard Worker
1271*35238bceSAndroid Build Coastguard Worker if (stencil)
1272*35238bceSAndroid Build Coastguard Worker {
1273*35238bceSAndroid Build Coastguard Worker context.enable(GL_SCISSOR_TEST);
1274*35238bceSAndroid Build Coastguard Worker context.clearStencil(1);
1275*35238bceSAndroid Build Coastguard Worker context.scissor(10, 10, 5, 15);
1276*35238bceSAndroid Build Coastguard Worker context.clear(GL_STENCIL_BUFFER_BIT);
1277*35238bceSAndroid Build Coastguard Worker context.disable(GL_SCISSOR_TEST);
1278*35238bceSAndroid Build Coastguard Worker
1279*35238bceSAndroid Build Coastguard Worker context.enable(GL_STENCIL_TEST);
1280*35238bceSAndroid Build Coastguard Worker context.stencilFunc(GL_EQUAL, 1, 0xffu);
1281*35238bceSAndroid Build Coastguard Worker sglr::drawQuad(context, flatShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(+1.0f, +1.0f, 0.0f));
1282*35238bceSAndroid Build Coastguard Worker context.disable(GL_STENCIL_TEST);
1283*35238bceSAndroid Build Coastguard Worker }
1284*35238bceSAndroid Build Coastguard Worker
1285*35238bceSAndroid Build Coastguard Worker if (m_config.colorType == GL_TEXTURE_2D)
1286*35238bceSAndroid Build Coastguard Worker {
1287*35238bceSAndroid Build Coastguard Worker context.bindFramebuffer(GL_FRAMEBUFFER, 0);
1288*35238bceSAndroid Build Coastguard Worker context.viewport(0, 0, context.getWidth(), context.getHeight());
1289*35238bceSAndroid Build Coastguard Worker context.bindTexture(GL_TEXTURE_2D, fbo.getColorBuffer());
1290*35238bceSAndroid Build Coastguard Worker sglr::drawQuad(context, texFromFboShaderID, Vec3(-0.5f, -0.5f, 0.0f), Vec3(0.5f, 0.5f, 0.0f));
1291*35238bceSAndroid Build Coastguard Worker context.readPixels(dst, 0, 0, context.getWidth(), context.getHeight());
1292*35238bceSAndroid Build Coastguard Worker }
1293*35238bceSAndroid Build Coastguard Worker else
1294*35238bceSAndroid Build Coastguard Worker readPixels(context, dst, 0, 0, newWidth, newHeight, colorFormat, fboRangeInfo.lookupScale,
1295*35238bceSAndroid Build Coastguard Worker fboRangeInfo.lookupBias);
1296*35238bceSAndroid Build Coastguard Worker }
1297*35238bceSAndroid Build Coastguard Worker
1298*35238bceSAndroid Build Coastguard Worker class RecreateBuffersTest : public FboRenderCase
1299*35238bceSAndroid Build Coastguard Worker {
1300*35238bceSAndroid Build Coastguard Worker public:
1301*35238bceSAndroid Build Coastguard Worker RecreateBuffersTest(Context &context, const FboConfig &config, uint32_t buffers, bool rebind);
~RecreateBuffersTest(void)1302*35238bceSAndroid Build Coastguard Worker virtual ~RecreateBuffersTest(void)
1303*35238bceSAndroid Build Coastguard Worker {
1304*35238bceSAndroid Build Coastguard Worker }
1305*35238bceSAndroid Build Coastguard Worker
1306*35238bceSAndroid Build Coastguard Worker void render(sglr::Context &context, Surface &dst);
1307*35238bceSAndroid Build Coastguard Worker
1308*35238bceSAndroid Build Coastguard Worker private:
1309*35238bceSAndroid Build Coastguard Worker uint32_t m_buffers;
1310*35238bceSAndroid Build Coastguard Worker bool m_rebind;
1311*35238bceSAndroid Build Coastguard Worker };
1312*35238bceSAndroid Build Coastguard Worker
RecreateBuffersTest(Context & context,const FboConfig & config,uint32_t buffers,bool rebind)1313*35238bceSAndroid Build Coastguard Worker RecreateBuffersTest::RecreateBuffersTest(Context &context, const FboConfig &config, uint32_t buffers, bool rebind)
1314*35238bceSAndroid Build Coastguard Worker : FboRenderCase(context, (string(config.getName()) + (rebind ? "" : "_no_rebind")).c_str(), "Recreate buffers",
1315*35238bceSAndroid Build Coastguard Worker config)
1316*35238bceSAndroid Build Coastguard Worker , m_buffers(buffers)
1317*35238bceSAndroid Build Coastguard Worker , m_rebind(rebind)
1318*35238bceSAndroid Build Coastguard Worker {
1319*35238bceSAndroid Build Coastguard Worker }
1320*35238bceSAndroid Build Coastguard Worker
render(sglr::Context & ctx,Surface & dst)1321*35238bceSAndroid Build Coastguard Worker void RecreateBuffersTest::render(sglr::Context &ctx, Surface &dst)
1322*35238bceSAndroid Build Coastguard Worker {
1323*35238bceSAndroid Build Coastguard Worker tcu::TextureFormat colorFormat = glu::mapGLInternalFormat(m_config.colorFormat);
1324*35238bceSAndroid Build Coastguard Worker glu::DataType fboSamplerType = glu::getSampler2DType(colorFormat);
1325*35238bceSAndroid Build Coastguard Worker glu::DataType fboOutputType = getFragmentOutputType(colorFormat);
1326*35238bceSAndroid Build Coastguard Worker tcu::TextureFormatInfo fboRangeInfo = tcu::getTextureFormatInfo(colorFormat);
1327*35238bceSAndroid Build Coastguard Worker Vec4 fboOutScale = fboRangeInfo.valueMax - fboRangeInfo.valueMin;
1328*35238bceSAndroid Build Coastguard Worker Vec4 fboOutBias = fboRangeInfo.valueMin;
1329*35238bceSAndroid Build Coastguard Worker
1330*35238bceSAndroid Build Coastguard Worker Texture2DShader texToFboShader(DataTypes() << glu::TYPE_SAMPLER_2D, fboOutputType);
1331*35238bceSAndroid Build Coastguard Worker Texture2DShader texFromFboShader(DataTypes() << fboSamplerType, glu::TYPE_FLOAT_VEC4);
1332*35238bceSAndroid Build Coastguard Worker FlatColorShader flatShader(fboOutputType);
1333*35238bceSAndroid Build Coastguard Worker uint32_t texToFboShaderID = ctx.createProgram(&texToFboShader);
1334*35238bceSAndroid Build Coastguard Worker uint32_t texFromFboShaderID = ctx.createProgram(&texFromFboShader);
1335*35238bceSAndroid Build Coastguard Worker uint32_t flatShaderID = ctx.createProgram(&flatShader);
1336*35238bceSAndroid Build Coastguard Worker
1337*35238bceSAndroid Build Coastguard Worker int width = 128;
1338*35238bceSAndroid Build Coastguard Worker int height = 128;
1339*35238bceSAndroid Build Coastguard Worker uint32_t metaballsTex = 1;
1340*35238bceSAndroid Build Coastguard Worker uint32_t quadsTex = 2;
1341*35238bceSAndroid Build Coastguard Worker bool stencil = (m_config.buffers & GL_STENCIL_BUFFER_BIT) != 0;
1342*35238bceSAndroid Build Coastguard Worker
1343*35238bceSAndroid Build Coastguard Worker createQuadsTex2D(ctx, quadsTex, GL_RGB, GL_UNSIGNED_BYTE, 64, 64);
1344*35238bceSAndroid Build Coastguard Worker createMetaballsTex2D(ctx, metaballsTex, GL_RGB, GL_UNSIGNED_BYTE, 64, 64);
1345*35238bceSAndroid Build Coastguard Worker
1346*35238bceSAndroid Build Coastguard Worker Framebuffer fbo(ctx, m_config, width, height);
1347*35238bceSAndroid Build Coastguard Worker fbo.checkCompleteness();
1348*35238bceSAndroid Build Coastguard Worker
1349*35238bceSAndroid Build Coastguard Worker // Setup shaders
1350*35238bceSAndroid Build Coastguard Worker texToFboShader.setOutScaleBias(fboOutScale, fboOutBias);
1351*35238bceSAndroid Build Coastguard Worker texFromFboShader.setTexScaleBias(0, fboRangeInfo.lookupScale, fboRangeInfo.lookupBias);
1352*35238bceSAndroid Build Coastguard Worker texToFboShader.setUniforms(ctx, texToFboShaderID);
1353*35238bceSAndroid Build Coastguard Worker texFromFboShader.setUniforms(ctx, texFromFboShaderID);
1354*35238bceSAndroid Build Coastguard Worker flatShader.setColor(ctx, flatShaderID, Vec4(0.0f, 0.0f, 1.0f, 1.0f) * fboOutScale + fboOutBias);
1355*35238bceSAndroid Build Coastguard Worker
1356*35238bceSAndroid Build Coastguard Worker // Draw scene
1357*35238bceSAndroid Build Coastguard Worker ctx.bindFramebuffer(GL_FRAMEBUFFER, fbo.getFramebuffer());
1358*35238bceSAndroid Build Coastguard Worker ctx.viewport(0, 0, width, height);
1359*35238bceSAndroid Build Coastguard Worker clearColorBuffer(ctx, colorFormat, tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f));
1360*35238bceSAndroid Build Coastguard Worker ctx.clear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1361*35238bceSAndroid Build Coastguard Worker
1362*35238bceSAndroid Build Coastguard Worker ctx.enable(GL_DEPTH_TEST);
1363*35238bceSAndroid Build Coastguard Worker
1364*35238bceSAndroid Build Coastguard Worker ctx.bindTexture(GL_TEXTURE_2D, quadsTex);
1365*35238bceSAndroid Build Coastguard Worker sglr::drawQuad(ctx, texToFboShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
1366*35238bceSAndroid Build Coastguard Worker
1367*35238bceSAndroid Build Coastguard Worker ctx.disable(GL_DEPTH_TEST);
1368*35238bceSAndroid Build Coastguard Worker
1369*35238bceSAndroid Build Coastguard Worker if (stencil)
1370*35238bceSAndroid Build Coastguard Worker {
1371*35238bceSAndroid Build Coastguard Worker ctx.enable(GL_SCISSOR_TEST);
1372*35238bceSAndroid Build Coastguard Worker ctx.scissor(width / 4, height / 4, width / 2, height / 2);
1373*35238bceSAndroid Build Coastguard Worker ctx.clearStencil(1);
1374*35238bceSAndroid Build Coastguard Worker ctx.clear(GL_STENCIL_BUFFER_BIT);
1375*35238bceSAndroid Build Coastguard Worker ctx.disable(GL_SCISSOR_TEST);
1376*35238bceSAndroid Build Coastguard Worker }
1377*35238bceSAndroid Build Coastguard Worker
1378*35238bceSAndroid Build Coastguard Worker // Recreate buffers
1379*35238bceSAndroid Build Coastguard Worker if (!m_rebind)
1380*35238bceSAndroid Build Coastguard Worker ctx.bindFramebuffer(GL_FRAMEBUFFER, 0);
1381*35238bceSAndroid Build Coastguard Worker
1382*35238bceSAndroid Build Coastguard Worker DE_ASSERT((m_buffers & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) == 0 ||
1383*35238bceSAndroid Build Coastguard Worker (m_buffers & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) ==
1384*35238bceSAndroid Build Coastguard Worker (m_config.buffers & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)));
1385*35238bceSAndroid Build Coastguard Worker
1386*35238bceSAndroid Build Coastguard Worker // Recreate.
1387*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < 2; ndx++)
1388*35238bceSAndroid Build Coastguard Worker {
1389*35238bceSAndroid Build Coastguard Worker uint32_t bit = ndx == 0 ? GL_COLOR_BUFFER_BIT : (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1390*35238bceSAndroid Build Coastguard Worker uint32_t type = ndx == 0 ? fbo.getConfig().colorType : fbo.getConfig().depthStencilType;
1391*35238bceSAndroid Build Coastguard Worker uint32_t format = ndx == 0 ? fbo.getConfig().colorFormat : fbo.getConfig().depthStencilFormat;
1392*35238bceSAndroid Build Coastguard Worker uint32_t buf = ndx == 0 ? fbo.getColorBuffer() : fbo.getDepthStencilBuffer();
1393*35238bceSAndroid Build Coastguard Worker
1394*35238bceSAndroid Build Coastguard Worker if ((m_buffers & bit) == 0)
1395*35238bceSAndroid Build Coastguard Worker continue;
1396*35238bceSAndroid Build Coastguard Worker
1397*35238bceSAndroid Build Coastguard Worker switch (type)
1398*35238bceSAndroid Build Coastguard Worker {
1399*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_2D:
1400*35238bceSAndroid Build Coastguard Worker ctx.deleteTextures(1, &buf);
1401*35238bceSAndroid Build Coastguard Worker ctx.bindTexture(GL_TEXTURE_2D, buf);
1402*35238bceSAndroid Build Coastguard Worker ctx.texImage2D(GL_TEXTURE_2D, 0, format, width, height);
1403*35238bceSAndroid Build Coastguard Worker ctx.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1404*35238bceSAndroid Build Coastguard Worker ctx.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1405*35238bceSAndroid Build Coastguard Worker break;
1406*35238bceSAndroid Build Coastguard Worker
1407*35238bceSAndroid Build Coastguard Worker case GL_RENDERBUFFER:
1408*35238bceSAndroid Build Coastguard Worker ctx.deleteRenderbuffers(1, &buf);
1409*35238bceSAndroid Build Coastguard Worker ctx.bindRenderbuffer(GL_RENDERBUFFER, buf);
1410*35238bceSAndroid Build Coastguard Worker ctx.renderbufferStorage(GL_RENDERBUFFER, format, width, height);
1411*35238bceSAndroid Build Coastguard Worker break;
1412*35238bceSAndroid Build Coastguard Worker
1413*35238bceSAndroid Build Coastguard Worker default:
1414*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
1415*35238bceSAndroid Build Coastguard Worker }
1416*35238bceSAndroid Build Coastguard Worker }
1417*35238bceSAndroid Build Coastguard Worker
1418*35238bceSAndroid Build Coastguard Worker // Rebind.
1419*35238bceSAndroid Build Coastguard Worker if (m_rebind)
1420*35238bceSAndroid Build Coastguard Worker {
1421*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < 3; ndx++)
1422*35238bceSAndroid Build Coastguard Worker {
1423*35238bceSAndroid Build Coastguard Worker uint32_t bit = ndx == 0 ? GL_COLOR_BUFFER_BIT :
1424*35238bceSAndroid Build Coastguard Worker ndx == 1 ? GL_DEPTH_BUFFER_BIT :
1425*35238bceSAndroid Build Coastguard Worker ndx == 2 ? GL_STENCIL_BUFFER_BIT :
1426*35238bceSAndroid Build Coastguard Worker 0;
1427*35238bceSAndroid Build Coastguard Worker uint32_t point = ndx == 0 ? GL_COLOR_ATTACHMENT0 :
1428*35238bceSAndroid Build Coastguard Worker ndx == 1 ? GL_DEPTH_ATTACHMENT :
1429*35238bceSAndroid Build Coastguard Worker ndx == 2 ? GL_STENCIL_ATTACHMENT :
1430*35238bceSAndroid Build Coastguard Worker 0;
1431*35238bceSAndroid Build Coastguard Worker uint32_t type = ndx == 0 ? fbo.getConfig().colorType : fbo.getConfig().depthStencilType;
1432*35238bceSAndroid Build Coastguard Worker uint32_t buf = ndx == 0 ? fbo.getColorBuffer() : fbo.getDepthStencilBuffer();
1433*35238bceSAndroid Build Coastguard Worker
1434*35238bceSAndroid Build Coastguard Worker if ((m_buffers & bit) == 0)
1435*35238bceSAndroid Build Coastguard Worker continue;
1436*35238bceSAndroid Build Coastguard Worker
1437*35238bceSAndroid Build Coastguard Worker switch (type)
1438*35238bceSAndroid Build Coastguard Worker {
1439*35238bceSAndroid Build Coastguard Worker case GL_TEXTURE_2D:
1440*35238bceSAndroid Build Coastguard Worker ctx.framebufferTexture2D(GL_FRAMEBUFFER, point, GL_TEXTURE_2D, buf, 0);
1441*35238bceSAndroid Build Coastguard Worker break;
1442*35238bceSAndroid Build Coastguard Worker
1443*35238bceSAndroid Build Coastguard Worker case GL_RENDERBUFFER:
1444*35238bceSAndroid Build Coastguard Worker ctx.framebufferRenderbuffer(GL_FRAMEBUFFER, point, GL_RENDERBUFFER, buf);
1445*35238bceSAndroid Build Coastguard Worker break;
1446*35238bceSAndroid Build Coastguard Worker
1447*35238bceSAndroid Build Coastguard Worker default:
1448*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
1449*35238bceSAndroid Build Coastguard Worker }
1450*35238bceSAndroid Build Coastguard Worker }
1451*35238bceSAndroid Build Coastguard Worker }
1452*35238bceSAndroid Build Coastguard Worker
1453*35238bceSAndroid Build Coastguard Worker if (!m_rebind)
1454*35238bceSAndroid Build Coastguard Worker ctx.bindFramebuffer(GL_FRAMEBUFFER, fbo.getFramebuffer());
1455*35238bceSAndroid Build Coastguard Worker
1456*35238bceSAndroid Build Coastguard Worker ctx.clearStencil(0);
1457*35238bceSAndroid Build Coastguard Worker ctx.clear(m_buffers &
1458*35238bceSAndroid Build Coastguard Worker (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)); // \note Clear only buffers that were re-created
1459*35238bceSAndroid Build Coastguard Worker if (m_buffers & GL_COLOR_BUFFER_BIT)
1460*35238bceSAndroid Build Coastguard Worker {
1461*35238bceSAndroid Build Coastguard Worker // Clearing of integer buffers is undefined so do clearing by rendering flat color.
1462*35238bceSAndroid Build Coastguard Worker sglr::drawQuad(ctx, flatShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
1463*35238bceSAndroid Build Coastguard Worker }
1464*35238bceSAndroid Build Coastguard Worker
1465*35238bceSAndroid Build Coastguard Worker ctx.enable(GL_DEPTH_TEST);
1466*35238bceSAndroid Build Coastguard Worker
1467*35238bceSAndroid Build Coastguard Worker if (stencil)
1468*35238bceSAndroid Build Coastguard Worker {
1469*35238bceSAndroid Build Coastguard Worker // \note Stencil test enabled only if we have stencil buffer
1470*35238bceSAndroid Build Coastguard Worker ctx.enable(GL_STENCIL_TEST);
1471*35238bceSAndroid Build Coastguard Worker ctx.stencilFunc(GL_EQUAL, 0, 0xffu);
1472*35238bceSAndroid Build Coastguard Worker }
1473*35238bceSAndroid Build Coastguard Worker ctx.bindTexture(GL_TEXTURE_2D, metaballsTex);
1474*35238bceSAndroid Build Coastguard Worker sglr::drawQuad(ctx, texToFboShaderID, Vec3(-1.0f, -1.0f, 1.0f), Vec3(1.0f, 1.0f, -1.0f));
1475*35238bceSAndroid Build Coastguard Worker if (stencil)
1476*35238bceSAndroid Build Coastguard Worker ctx.disable(GL_STENCIL_TEST);
1477*35238bceSAndroid Build Coastguard Worker
1478*35238bceSAndroid Build Coastguard Worker ctx.disable(GL_DEPTH_TEST);
1479*35238bceSAndroid Build Coastguard Worker
1480*35238bceSAndroid Build Coastguard Worker if (fbo.getConfig().colorType == GL_TEXTURE_2D)
1481*35238bceSAndroid Build Coastguard Worker {
1482*35238bceSAndroid Build Coastguard Worker // Unbind fbo
1483*35238bceSAndroid Build Coastguard Worker ctx.bindFramebuffer(GL_FRAMEBUFFER, 0);
1484*35238bceSAndroid Build Coastguard Worker
1485*35238bceSAndroid Build Coastguard Worker // Draw to screen
1486*35238bceSAndroid Build Coastguard Worker ctx.bindTexture(GL_TEXTURE_2D, fbo.getColorBuffer());
1487*35238bceSAndroid Build Coastguard Worker ctx.viewport(0, 0, ctx.getWidth(), ctx.getHeight());
1488*35238bceSAndroid Build Coastguard Worker sglr::drawQuad(ctx, texFromFboShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
1489*35238bceSAndroid Build Coastguard Worker
1490*35238bceSAndroid Build Coastguard Worker // Read from screen
1491*35238bceSAndroid Build Coastguard Worker ctx.readPixels(dst, 0, 0, ctx.getWidth(), ctx.getHeight());
1492*35238bceSAndroid Build Coastguard Worker }
1493*35238bceSAndroid Build Coastguard Worker else
1494*35238bceSAndroid Build Coastguard Worker {
1495*35238bceSAndroid Build Coastguard Worker // Read from fbo
1496*35238bceSAndroid Build Coastguard Worker readPixels(ctx, dst, 0, 0, width, height, colorFormat, fboRangeInfo.lookupScale, fboRangeInfo.lookupBias);
1497*35238bceSAndroid Build Coastguard Worker }
1498*35238bceSAndroid Build Coastguard Worker }
1499*35238bceSAndroid Build Coastguard Worker
1500*35238bceSAndroid Build Coastguard Worker } // namespace FboCases
1501*35238bceSAndroid Build Coastguard Worker
FboRenderTestGroup(Context & context)1502*35238bceSAndroid Build Coastguard Worker FboRenderTestGroup::FboRenderTestGroup(Context &context) : TestCaseGroup(context, "render", "Rendering Tests")
1503*35238bceSAndroid Build Coastguard Worker {
1504*35238bceSAndroid Build Coastguard Worker }
1505*35238bceSAndroid Build Coastguard Worker
~FboRenderTestGroup(void)1506*35238bceSAndroid Build Coastguard Worker FboRenderTestGroup::~FboRenderTestGroup(void)
1507*35238bceSAndroid Build Coastguard Worker {
1508*35238bceSAndroid Build Coastguard Worker }
1509*35238bceSAndroid Build Coastguard Worker
init(void)1510*35238bceSAndroid Build Coastguard Worker void FboRenderTestGroup::init(void)
1511*35238bceSAndroid Build Coastguard Worker {
1512*35238bceSAndroid Build Coastguard Worker static const uint32_t objectTypes[] = {GL_TEXTURE_2D, GL_RENDERBUFFER};
1513*35238bceSAndroid Build Coastguard Worker
1514*35238bceSAndroid Build Coastguard Worker enum FormatType
1515*35238bceSAndroid Build Coastguard Worker {
1516*35238bceSAndroid Build Coastguard Worker FORMATTYPE_FLOAT = 0,
1517*35238bceSAndroid Build Coastguard Worker FORMATTYPE_FIXED,
1518*35238bceSAndroid Build Coastguard Worker FORMATTYPE_INT,
1519*35238bceSAndroid Build Coastguard Worker FORMATTYPE_UINT,
1520*35238bceSAndroid Build Coastguard Worker
1521*35238bceSAndroid Build Coastguard Worker FORMATTYPE_LAST
1522*35238bceSAndroid Build Coastguard Worker };
1523*35238bceSAndroid Build Coastguard Worker
1524*35238bceSAndroid Build Coastguard Worker // Required by specification.
1525*35238bceSAndroid Build Coastguard Worker static const struct
1526*35238bceSAndroid Build Coastguard Worker {
1527*35238bceSAndroid Build Coastguard Worker uint32_t format;
1528*35238bceSAndroid Build Coastguard Worker FormatType type;
1529*35238bceSAndroid Build Coastguard Worker } colorFormats[] = {{GL_RGBA32F, FORMATTYPE_FLOAT},
1530*35238bceSAndroid Build Coastguard Worker {GL_RGBA32I, FORMATTYPE_INT},
1531*35238bceSAndroid Build Coastguard Worker {GL_RGBA32UI, FORMATTYPE_UINT},
1532*35238bceSAndroid Build Coastguard Worker {GL_RGBA16F, FORMATTYPE_FLOAT},
1533*35238bceSAndroid Build Coastguard Worker {GL_RGBA16I, FORMATTYPE_INT},
1534*35238bceSAndroid Build Coastguard Worker {GL_RGBA16UI, FORMATTYPE_UINT},
1535*35238bceSAndroid Build Coastguard Worker {GL_RGB16F, FORMATTYPE_FLOAT},
1536*35238bceSAndroid Build Coastguard Worker {GL_RGBA8, FORMATTYPE_FIXED},
1537*35238bceSAndroid Build Coastguard Worker {GL_RGBA8I, FORMATTYPE_INT},
1538*35238bceSAndroid Build Coastguard Worker {GL_RGBA8UI, FORMATTYPE_UINT},
1539*35238bceSAndroid Build Coastguard Worker {GL_SRGB8_ALPHA8, FORMATTYPE_FIXED},
1540*35238bceSAndroid Build Coastguard Worker {GL_RGB10_A2, FORMATTYPE_FIXED},
1541*35238bceSAndroid Build Coastguard Worker {GL_RGB10_A2UI, FORMATTYPE_UINT},
1542*35238bceSAndroid Build Coastguard Worker {GL_RGBA4, FORMATTYPE_FIXED},
1543*35238bceSAndroid Build Coastguard Worker {GL_RGB5_A1, FORMATTYPE_FIXED},
1544*35238bceSAndroid Build Coastguard Worker {GL_RGB8, FORMATTYPE_FIXED},
1545*35238bceSAndroid Build Coastguard Worker {GL_RGB565, FORMATTYPE_FIXED},
1546*35238bceSAndroid Build Coastguard Worker {GL_R11F_G11F_B10F, FORMATTYPE_FLOAT},
1547*35238bceSAndroid Build Coastguard Worker {GL_RG32F, FORMATTYPE_FLOAT},
1548*35238bceSAndroid Build Coastguard Worker {GL_RG32I, FORMATTYPE_INT},
1549*35238bceSAndroid Build Coastguard Worker {GL_RG32UI, FORMATTYPE_UINT},
1550*35238bceSAndroid Build Coastguard Worker {GL_RG16F, FORMATTYPE_FLOAT},
1551*35238bceSAndroid Build Coastguard Worker {GL_RG16I, FORMATTYPE_INT},
1552*35238bceSAndroid Build Coastguard Worker {GL_RG16UI, FORMATTYPE_UINT},
1553*35238bceSAndroid Build Coastguard Worker {GL_RG8, FORMATTYPE_FLOAT},
1554*35238bceSAndroid Build Coastguard Worker {GL_RG8I, FORMATTYPE_INT},
1555*35238bceSAndroid Build Coastguard Worker {GL_RG8UI, FORMATTYPE_UINT},
1556*35238bceSAndroid Build Coastguard Worker {GL_R32F, FORMATTYPE_FLOAT},
1557*35238bceSAndroid Build Coastguard Worker {GL_R32I, FORMATTYPE_INT},
1558*35238bceSAndroid Build Coastguard Worker {GL_R32UI, FORMATTYPE_UINT},
1559*35238bceSAndroid Build Coastguard Worker {GL_R16F, FORMATTYPE_FLOAT},
1560*35238bceSAndroid Build Coastguard Worker {GL_R16I, FORMATTYPE_INT},
1561*35238bceSAndroid Build Coastguard Worker {GL_R16UI, FORMATTYPE_UINT},
1562*35238bceSAndroid Build Coastguard Worker {GL_R8, FORMATTYPE_FLOAT},
1563*35238bceSAndroid Build Coastguard Worker {GL_R8I, FORMATTYPE_INT},
1564*35238bceSAndroid Build Coastguard Worker {GL_R8UI, FORMATTYPE_UINT}};
1565*35238bceSAndroid Build Coastguard Worker
1566*35238bceSAndroid Build Coastguard Worker static const struct
1567*35238bceSAndroid Build Coastguard Worker {
1568*35238bceSAndroid Build Coastguard Worker uint32_t format;
1569*35238bceSAndroid Build Coastguard Worker bool depth;
1570*35238bceSAndroid Build Coastguard Worker bool stencil;
1571*35238bceSAndroid Build Coastguard Worker } depthStencilFormats[] = {{GL_DEPTH_COMPONENT32F, true, false}, {GL_DEPTH_COMPONENT24, true, false},
1572*35238bceSAndroid Build Coastguard Worker {GL_DEPTH_COMPONENT16, true, false}, {GL_DEPTH32F_STENCIL8, true, true},
1573*35238bceSAndroid Build Coastguard Worker {GL_DEPTH24_STENCIL8, true, true}, {GL_STENCIL_INDEX8, false, true}};
1574*35238bceSAndroid Build Coastguard Worker
1575*35238bceSAndroid Build Coastguard Worker using namespace FboCases;
1576*35238bceSAndroid Build Coastguard Worker
1577*35238bceSAndroid Build Coastguard Worker // .stencil_clear
1578*35238bceSAndroid Build Coastguard Worker tcu::TestCaseGroup *stencilClearGroup = new tcu::TestCaseGroup(m_testCtx, "stencil_clear", "Stencil buffer clears");
1579*35238bceSAndroid Build Coastguard Worker addChild(stencilClearGroup);
1580*35238bceSAndroid Build Coastguard Worker for (int fmtNdx = 0; fmtNdx < DE_LENGTH_OF_ARRAY(depthStencilFormats); fmtNdx++)
1581*35238bceSAndroid Build Coastguard Worker {
1582*35238bceSAndroid Build Coastguard Worker uint32_t colorType = GL_TEXTURE_2D;
1583*35238bceSAndroid Build Coastguard Worker uint32_t stencilType = GL_RENDERBUFFER;
1584*35238bceSAndroid Build Coastguard Worker uint32_t colorFmt = GL_RGBA8;
1585*35238bceSAndroid Build Coastguard Worker
1586*35238bceSAndroid Build Coastguard Worker if (!depthStencilFormats[fmtNdx].stencil)
1587*35238bceSAndroid Build Coastguard Worker continue;
1588*35238bceSAndroid Build Coastguard Worker
1589*35238bceSAndroid Build Coastguard Worker FboConfig config(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, colorType, colorFmt, stencilType,
1590*35238bceSAndroid Build Coastguard Worker depthStencilFormats[fmtNdx].format);
1591*35238bceSAndroid Build Coastguard Worker stencilClearGroup->addChild(new StencilClearsTest(m_context, config));
1592*35238bceSAndroid Build Coastguard Worker }
1593*35238bceSAndroid Build Coastguard Worker
1594*35238bceSAndroid Build Coastguard Worker // .shared_colorbuffer_clear
1595*35238bceSAndroid Build Coastguard Worker tcu::TestCaseGroup *sharedColorbufferClearGroup =
1596*35238bceSAndroid Build Coastguard Worker new tcu::TestCaseGroup(m_testCtx, "shared_colorbuffer_clear", "Shader colorbuffer clears");
1597*35238bceSAndroid Build Coastguard Worker addChild(sharedColorbufferClearGroup);
1598*35238bceSAndroid Build Coastguard Worker for (int colorFmtNdx = 0; colorFmtNdx < DE_LENGTH_OF_ARRAY(colorFormats); colorFmtNdx++)
1599*35238bceSAndroid Build Coastguard Worker {
1600*35238bceSAndroid Build Coastguard Worker // Clearing of integer buffers is undefined.
1601*35238bceSAndroid Build Coastguard Worker if (colorFormats[colorFmtNdx].type == FORMATTYPE_INT || colorFormats[colorFmtNdx].type == FORMATTYPE_UINT)
1602*35238bceSAndroid Build Coastguard Worker continue;
1603*35238bceSAndroid Build Coastguard Worker
1604*35238bceSAndroid Build Coastguard Worker for (int typeNdx = 0; typeNdx < DE_LENGTH_OF_ARRAY(objectTypes); typeNdx++)
1605*35238bceSAndroid Build Coastguard Worker {
1606*35238bceSAndroid Build Coastguard Worker FboConfig config(GL_COLOR_BUFFER_BIT, objectTypes[typeNdx], colorFormats[colorFmtNdx].format, GL_NONE,
1607*35238bceSAndroid Build Coastguard Worker GL_NONE);
1608*35238bceSAndroid Build Coastguard Worker sharedColorbufferClearGroup->addChild(new SharedColorbufferClearsTest(m_context, config));
1609*35238bceSAndroid Build Coastguard Worker }
1610*35238bceSAndroid Build Coastguard Worker }
1611*35238bceSAndroid Build Coastguard Worker
1612*35238bceSAndroid Build Coastguard Worker // .shared_colorbuffer
1613*35238bceSAndroid Build Coastguard Worker tcu::TestCaseGroup *sharedColorbufferGroup =
1614*35238bceSAndroid Build Coastguard Worker new tcu::TestCaseGroup(m_testCtx, "shared_colorbuffer", "Shared colorbuffer tests");
1615*35238bceSAndroid Build Coastguard Worker addChild(sharedColorbufferGroup);
1616*35238bceSAndroid Build Coastguard Worker for (int colorFmtNdx = 0; colorFmtNdx < DE_LENGTH_OF_ARRAY(colorFormats); colorFmtNdx++)
1617*35238bceSAndroid Build Coastguard Worker {
1618*35238bceSAndroid Build Coastguard Worker uint32_t depthStencilType = GL_RENDERBUFFER;
1619*35238bceSAndroid Build Coastguard Worker uint32_t depthStencilFormat = GL_DEPTH24_STENCIL8;
1620*35238bceSAndroid Build Coastguard Worker
1621*35238bceSAndroid Build Coastguard Worker // Blending with integer buffers and fp32 targets is not supported.
1622*35238bceSAndroid Build Coastguard Worker if (colorFormats[colorFmtNdx].type == FORMATTYPE_INT || colorFormats[colorFmtNdx].type == FORMATTYPE_UINT ||
1623*35238bceSAndroid Build Coastguard Worker colorFormats[colorFmtNdx].format == GL_RGBA32F || colorFormats[colorFmtNdx].format == GL_RGB32F ||
1624*35238bceSAndroid Build Coastguard Worker colorFormats[colorFmtNdx].format == GL_RG32F || colorFormats[colorFmtNdx].format == GL_R32F)
1625*35238bceSAndroid Build Coastguard Worker continue;
1626*35238bceSAndroid Build Coastguard Worker
1627*35238bceSAndroid Build Coastguard Worker for (int typeNdx = 0; typeNdx < DE_LENGTH_OF_ARRAY(objectTypes); typeNdx++)
1628*35238bceSAndroid Build Coastguard Worker {
1629*35238bceSAndroid Build Coastguard Worker FboConfig colorOnlyConfig(GL_COLOR_BUFFER_BIT, objectTypes[typeNdx], colorFormats[colorFmtNdx].format,
1630*35238bceSAndroid Build Coastguard Worker GL_NONE, GL_NONE);
1631*35238bceSAndroid Build Coastguard Worker FboConfig colorDepthConfig(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, objectTypes[typeNdx],
1632*35238bceSAndroid Build Coastguard Worker colorFormats[colorFmtNdx].format, depthStencilType, depthStencilFormat);
1633*35238bceSAndroid Build Coastguard Worker FboConfig colorDepthStencilConfig(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
1634*35238bceSAndroid Build Coastguard Worker objectTypes[typeNdx], colorFormats[colorFmtNdx].format, depthStencilType,
1635*35238bceSAndroid Build Coastguard Worker depthStencilFormat);
1636*35238bceSAndroid Build Coastguard Worker
1637*35238bceSAndroid Build Coastguard Worker sharedColorbufferGroup->addChild(new SharedColorbufferTest(m_context, colorOnlyConfig));
1638*35238bceSAndroid Build Coastguard Worker sharedColorbufferGroup->addChild(new SharedColorbufferTest(m_context, colorDepthConfig));
1639*35238bceSAndroid Build Coastguard Worker sharedColorbufferGroup->addChild(new SharedColorbufferTest(m_context, colorDepthStencilConfig));
1640*35238bceSAndroid Build Coastguard Worker }
1641*35238bceSAndroid Build Coastguard Worker }
1642*35238bceSAndroid Build Coastguard Worker
1643*35238bceSAndroid Build Coastguard Worker // .shared_depth_stencil
1644*35238bceSAndroid Build Coastguard Worker tcu::TestCaseGroup *sharedDepthStencilGroup =
1645*35238bceSAndroid Build Coastguard Worker new tcu::TestCaseGroup(m_testCtx, "shared_depth_stencil", "Shared depth and stencil buffers");
1646*35238bceSAndroid Build Coastguard Worker addChild(sharedDepthStencilGroup);
1647*35238bceSAndroid Build Coastguard Worker for (int fmtNdx = 0; fmtNdx < DE_LENGTH_OF_ARRAY(depthStencilFormats); fmtNdx++)
1648*35238bceSAndroid Build Coastguard Worker {
1649*35238bceSAndroid Build Coastguard Worker uint32_t colorType = GL_TEXTURE_2D;
1650*35238bceSAndroid Build Coastguard Worker uint32_t colorFmt = GL_RGBA8;
1651*35238bceSAndroid Build Coastguard Worker bool depth = depthStencilFormats[fmtNdx].depth;
1652*35238bceSAndroid Build Coastguard Worker bool stencil = depthStencilFormats[fmtNdx].stencil;
1653*35238bceSAndroid Build Coastguard Worker
1654*35238bceSAndroid Build Coastguard Worker if (!depth)
1655*35238bceSAndroid Build Coastguard Worker continue; // Not verified.
1656*35238bceSAndroid Build Coastguard Worker
1657*35238bceSAndroid Build Coastguard Worker // Depth and stencil: both rbo and textures
1658*35238bceSAndroid Build Coastguard Worker for (int typeNdx = 0; typeNdx < DE_LENGTH_OF_ARRAY(objectTypes); typeNdx++)
1659*35238bceSAndroid Build Coastguard Worker {
1660*35238bceSAndroid Build Coastguard Worker FboConfig config(GL_COLOR_BUFFER_BIT | (depth ? GL_DEPTH_BUFFER_BIT : 0) |
1661*35238bceSAndroid Build Coastguard Worker (stencil ? GL_STENCIL_BUFFER_BIT : 0),
1662*35238bceSAndroid Build Coastguard Worker colorType, colorFmt, objectTypes[typeNdx], depthStencilFormats[fmtNdx].format);
1663*35238bceSAndroid Build Coastguard Worker sharedDepthStencilGroup->addChild(new SharedDepthStencilTest(m_context, config));
1664*35238bceSAndroid Build Coastguard Worker }
1665*35238bceSAndroid Build Coastguard Worker }
1666*35238bceSAndroid Build Coastguard Worker
1667*35238bceSAndroid Build Coastguard Worker // .resize
1668*35238bceSAndroid Build Coastguard Worker tcu::TestCaseGroup *resizeGroup = new tcu::TestCaseGroup(m_testCtx, "resize", "FBO resize tests");
1669*35238bceSAndroid Build Coastguard Worker addChild(resizeGroup);
1670*35238bceSAndroid Build Coastguard Worker for (int colorFmtNdx = 0; colorFmtNdx < DE_LENGTH_OF_ARRAY(colorFormats); colorFmtNdx++)
1671*35238bceSAndroid Build Coastguard Worker {
1672*35238bceSAndroid Build Coastguard Worker uint32_t colorFormat = colorFormats[colorFmtNdx].format;
1673*35238bceSAndroid Build Coastguard Worker
1674*35238bceSAndroid Build Coastguard Worker // Color-only.
1675*35238bceSAndroid Build Coastguard Worker for (int typeNdx = 0; typeNdx < DE_LENGTH_OF_ARRAY(objectTypes); typeNdx++)
1676*35238bceSAndroid Build Coastguard Worker {
1677*35238bceSAndroid Build Coastguard Worker FboConfig config(GL_COLOR_BUFFER_BIT, objectTypes[typeNdx], colorFormat, GL_NONE, GL_NONE);
1678*35238bceSAndroid Build Coastguard Worker resizeGroup->addChild(new ResizeTest(m_context, config));
1679*35238bceSAndroid Build Coastguard Worker }
1680*35238bceSAndroid Build Coastguard Worker
1681*35238bceSAndroid Build Coastguard Worker // For selected color formats tests depth & stencil variants.
1682*35238bceSAndroid Build Coastguard Worker if (colorFormat == GL_RGBA8 || colorFormat == GL_RGBA16F)
1683*35238bceSAndroid Build Coastguard Worker {
1684*35238bceSAndroid Build Coastguard Worker for (int depthStencilFmtNdx = 0; depthStencilFmtNdx < DE_LENGTH_OF_ARRAY(depthStencilFormats);
1685*35238bceSAndroid Build Coastguard Worker depthStencilFmtNdx++)
1686*35238bceSAndroid Build Coastguard Worker {
1687*35238bceSAndroid Build Coastguard Worker uint32_t colorType = GL_TEXTURE_2D;
1688*35238bceSAndroid Build Coastguard Worker bool depth = depthStencilFormats[depthStencilFmtNdx].depth;
1689*35238bceSAndroid Build Coastguard Worker bool stencil = depthStencilFormats[depthStencilFmtNdx].stencil;
1690*35238bceSAndroid Build Coastguard Worker
1691*35238bceSAndroid Build Coastguard Worker // Depth and stencil: both rbo and textures
1692*35238bceSAndroid Build Coastguard Worker for (int typeNdx = 0; typeNdx < DE_LENGTH_OF_ARRAY(objectTypes); typeNdx++)
1693*35238bceSAndroid Build Coastguard Worker {
1694*35238bceSAndroid Build Coastguard Worker if (!depth && objectTypes[typeNdx] != GL_RENDERBUFFER)
1695*35238bceSAndroid Build Coastguard Worker continue; // Not supported.
1696*35238bceSAndroid Build Coastguard Worker
1697*35238bceSAndroid Build Coastguard Worker FboConfig config(
1698*35238bceSAndroid Build Coastguard Worker GL_COLOR_BUFFER_BIT | (depth ? GL_DEPTH_BUFFER_BIT : 0) | (stencil ? GL_STENCIL_BUFFER_BIT : 0),
1699*35238bceSAndroid Build Coastguard Worker colorType, colorFormat, objectTypes[typeNdx], depthStencilFormats[depthStencilFmtNdx].format);
1700*35238bceSAndroid Build Coastguard Worker resizeGroup->addChild(new ResizeTest(m_context, config));
1701*35238bceSAndroid Build Coastguard Worker }
1702*35238bceSAndroid Build Coastguard Worker }
1703*35238bceSAndroid Build Coastguard Worker }
1704*35238bceSAndroid Build Coastguard Worker }
1705*35238bceSAndroid Build Coastguard Worker
1706*35238bceSAndroid Build Coastguard Worker // .recreate_color
1707*35238bceSAndroid Build Coastguard Worker tcu::TestCaseGroup *recreateColorGroup =
1708*35238bceSAndroid Build Coastguard Worker new tcu::TestCaseGroup(m_testCtx, "recreate_color", "Recreate colorbuffer tests");
1709*35238bceSAndroid Build Coastguard Worker addChild(recreateColorGroup);
1710*35238bceSAndroid Build Coastguard Worker for (int colorFmtNdx = 0; colorFmtNdx < DE_LENGTH_OF_ARRAY(colorFormats); colorFmtNdx++)
1711*35238bceSAndroid Build Coastguard Worker {
1712*35238bceSAndroid Build Coastguard Worker uint32_t colorFormat = colorFormats[colorFmtNdx].format;
1713*35238bceSAndroid Build Coastguard Worker uint32_t depthStencilFormat = GL_DEPTH24_STENCIL8;
1714*35238bceSAndroid Build Coastguard Worker uint32_t depthStencilType = GL_RENDERBUFFER;
1715*35238bceSAndroid Build Coastguard Worker
1716*35238bceSAndroid Build Coastguard Worker // Color-only.
1717*35238bceSAndroid Build Coastguard Worker for (int typeNdx = 0; typeNdx < DE_LENGTH_OF_ARRAY(objectTypes); typeNdx++)
1718*35238bceSAndroid Build Coastguard Worker {
1719*35238bceSAndroid Build Coastguard Worker FboConfig config(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, objectTypes[typeNdx],
1720*35238bceSAndroid Build Coastguard Worker colorFormat, depthStencilType, depthStencilFormat);
1721*35238bceSAndroid Build Coastguard Worker recreateColorGroup->addChild(
1722*35238bceSAndroid Build Coastguard Worker new RecreateBuffersTest(m_context, config, GL_COLOR_BUFFER_BIT, true /* rebind */));
1723*35238bceSAndroid Build Coastguard Worker }
1724*35238bceSAndroid Build Coastguard Worker }
1725*35238bceSAndroid Build Coastguard Worker
1726*35238bceSAndroid Build Coastguard Worker // .recreate_depth_stencil
1727*35238bceSAndroid Build Coastguard Worker tcu::TestCaseGroup *recreateDepthStencilGroup =
1728*35238bceSAndroid Build Coastguard Worker new tcu::TestCaseGroup(m_testCtx, "recreate_depth_stencil", "Recreate depth and stencil buffers");
1729*35238bceSAndroid Build Coastguard Worker addChild(recreateDepthStencilGroup);
1730*35238bceSAndroid Build Coastguard Worker for (int fmtNdx = 0; fmtNdx < DE_LENGTH_OF_ARRAY(depthStencilFormats); fmtNdx++)
1731*35238bceSAndroid Build Coastguard Worker {
1732*35238bceSAndroid Build Coastguard Worker uint32_t colorType = GL_TEXTURE_2D;
1733*35238bceSAndroid Build Coastguard Worker uint32_t colorFmt = GL_RGBA8;
1734*35238bceSAndroid Build Coastguard Worker bool depth = depthStencilFormats[fmtNdx].depth;
1735*35238bceSAndroid Build Coastguard Worker bool stencil = depthStencilFormats[fmtNdx].stencil;
1736*35238bceSAndroid Build Coastguard Worker
1737*35238bceSAndroid Build Coastguard Worker // Depth and stencil: both rbo and textures
1738*35238bceSAndroid Build Coastguard Worker for (int typeNdx = 0; typeNdx < DE_LENGTH_OF_ARRAY(objectTypes); typeNdx++)
1739*35238bceSAndroid Build Coastguard Worker {
1740*35238bceSAndroid Build Coastguard Worker if (!depth && objectTypes[typeNdx] != GL_RENDERBUFFER)
1741*35238bceSAndroid Build Coastguard Worker continue;
1742*35238bceSAndroid Build Coastguard Worker
1743*35238bceSAndroid Build Coastguard Worker FboConfig config(GL_COLOR_BUFFER_BIT | (depth ? GL_DEPTH_BUFFER_BIT : 0) |
1744*35238bceSAndroid Build Coastguard Worker (stencil ? GL_STENCIL_BUFFER_BIT : 0),
1745*35238bceSAndroid Build Coastguard Worker colorType, colorFmt, objectTypes[typeNdx], depthStencilFormats[fmtNdx].format);
1746*35238bceSAndroid Build Coastguard Worker recreateDepthStencilGroup->addChild(new RecreateBuffersTest(
1747*35238bceSAndroid Build Coastguard Worker m_context, config, (depth ? GL_DEPTH_BUFFER_BIT : 0) | (stencil ? GL_STENCIL_BUFFER_BIT : 0),
1748*35238bceSAndroid Build Coastguard Worker true /* rebind */));
1749*35238bceSAndroid Build Coastguard Worker }
1750*35238bceSAndroid Build Coastguard Worker }
1751*35238bceSAndroid Build Coastguard Worker }
1752*35238bceSAndroid Build Coastguard Worker
1753*35238bceSAndroid Build Coastguard Worker } // namespace Functional
1754*35238bceSAndroid Build Coastguard Worker } // namespace gles3
1755*35238bceSAndroid Build Coastguard Worker } // namespace deqp
1756