xref: /aosp_15_r20/external/deqp/modules/gles2/functional/es2fTextureFormatTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program OpenGL ES 2.0 Module
3*35238bceSAndroid Build Coastguard Worker  * -------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker  *
5*35238bceSAndroid Build Coastguard Worker  * Copyright 2014 The Android Open Source Project
6*35238bceSAndroid Build Coastguard Worker  *
7*35238bceSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
8*35238bceSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
9*35238bceSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
10*35238bceSAndroid Build Coastguard Worker  *
11*35238bceSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
12*35238bceSAndroid Build Coastguard Worker  *
13*35238bceSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
14*35238bceSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
15*35238bceSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16*35238bceSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
17*35238bceSAndroid Build Coastguard Worker  * limitations under the License.
18*35238bceSAndroid Build Coastguard Worker  *
19*35238bceSAndroid Build Coastguard Worker  *//*!
20*35238bceSAndroid Build Coastguard Worker  * \file
21*35238bceSAndroid Build Coastguard Worker  * \brief Texture format tests.
22*35238bceSAndroid Build Coastguard Worker  *
23*35238bceSAndroid Build Coastguard Worker  * Constants:
24*35238bceSAndroid Build Coastguard Worker  *  + nearest-neighbor filtering
25*35238bceSAndroid Build Coastguard Worker  *  + no mipmaps
26*35238bceSAndroid Build Coastguard Worker  *  + full texture coordinate range (but not outside) tested
27*35238bceSAndroid Build Coastguard Worker  *  + accessed from fragment shader
28*35238bceSAndroid Build Coastguard Worker  *  + texture unit 0
29*35238bceSAndroid Build Coastguard Worker  *  + named texture object
30*35238bceSAndroid Build Coastguard Worker  *
31*35238bceSAndroid Build Coastguard Worker  * Variables:
32*35238bceSAndroid Build Coastguard Worker  *  + texture format
33*35238bceSAndroid Build Coastguard Worker  *  + texture type: 2D or cubemap
34*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
35*35238bceSAndroid Build Coastguard Worker 
36*35238bceSAndroid Build Coastguard Worker #include "es2fTextureFormatTests.hpp"
37*35238bceSAndroid Build Coastguard Worker #include "glsTextureTestUtil.hpp"
38*35238bceSAndroid Build Coastguard Worker #include "gluTexture.hpp"
39*35238bceSAndroid Build Coastguard Worker #include "gluStrUtil.hpp"
40*35238bceSAndroid Build Coastguard Worker #include "gluTextureUtil.hpp"
41*35238bceSAndroid Build Coastguard Worker #include "gluPixelTransfer.hpp"
42*35238bceSAndroid Build Coastguard Worker #include "tcuSurfaceAccess.hpp"
43*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
44*35238bceSAndroid Build Coastguard Worker #include "tcuTextureUtil.hpp"
45*35238bceSAndroid Build Coastguard Worker 
46*35238bceSAndroid Build Coastguard Worker #include "deStringUtil.hpp"
47*35238bceSAndroid Build Coastguard Worker 
48*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
49*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
50*35238bceSAndroid Build Coastguard Worker 
51*35238bceSAndroid Build Coastguard Worker namespace deqp
52*35238bceSAndroid Build Coastguard Worker {
53*35238bceSAndroid Build Coastguard Worker namespace gles2
54*35238bceSAndroid Build Coastguard Worker {
55*35238bceSAndroid Build Coastguard Worker namespace Functional
56*35238bceSAndroid Build Coastguard Worker {
57*35238bceSAndroid Build Coastguard Worker 
58*35238bceSAndroid Build Coastguard Worker using std::string;
59*35238bceSAndroid Build Coastguard Worker using std::vector;
60*35238bceSAndroid Build Coastguard Worker using tcu::Sampler;
61*35238bceSAndroid Build Coastguard Worker using tcu::TestLog;
62*35238bceSAndroid Build Coastguard Worker using namespace glu;
63*35238bceSAndroid Build Coastguard Worker using namespace gls::TextureTestUtil;
64*35238bceSAndroid Build Coastguard Worker using namespace glu::TextureTestUtil;
65*35238bceSAndroid Build Coastguard Worker 
66*35238bceSAndroid Build Coastguard Worker // Texture2DFormatCase
67*35238bceSAndroid Build Coastguard Worker 
68*35238bceSAndroid Build Coastguard Worker class Texture2DFormatCase : public tcu::TestCase
69*35238bceSAndroid Build Coastguard Worker {
70*35238bceSAndroid Build Coastguard Worker public:
71*35238bceSAndroid Build Coastguard Worker     Texture2DFormatCase(tcu::TestContext &testCtx, glu::RenderContext &renderCtx, const char *name,
72*35238bceSAndroid Build Coastguard Worker                         const char *description, uint32_t format, uint32_t dataType, int width, int height);
73*35238bceSAndroid Build Coastguard Worker     ~Texture2DFormatCase(void);
74*35238bceSAndroid Build Coastguard Worker 
75*35238bceSAndroid Build Coastguard Worker     void init(void);
76*35238bceSAndroid Build Coastguard Worker     void deinit(void);
77*35238bceSAndroid Build Coastguard Worker     IterateResult iterate(void);
78*35238bceSAndroid Build Coastguard Worker 
79*35238bceSAndroid Build Coastguard Worker private:
80*35238bceSAndroid Build Coastguard Worker     Texture2DFormatCase(const Texture2DFormatCase &other);
81*35238bceSAndroid Build Coastguard Worker     Texture2DFormatCase &operator=(const Texture2DFormatCase &other);
82*35238bceSAndroid Build Coastguard Worker 
83*35238bceSAndroid Build Coastguard Worker     glu::RenderContext &m_renderCtx;
84*35238bceSAndroid Build Coastguard Worker 
85*35238bceSAndroid Build Coastguard Worker     const uint32_t m_format;
86*35238bceSAndroid Build Coastguard Worker     const uint32_t m_dataType;
87*35238bceSAndroid Build Coastguard Worker     const int m_width;
88*35238bceSAndroid Build Coastguard Worker     const int m_height;
89*35238bceSAndroid Build Coastguard Worker 
90*35238bceSAndroid Build Coastguard Worker     glu::Texture2D *m_texture;
91*35238bceSAndroid Build Coastguard Worker     TextureRenderer m_renderer;
92*35238bceSAndroid Build Coastguard Worker };
93*35238bceSAndroid Build Coastguard Worker 
Texture2DFormatCase(tcu::TestContext & testCtx,glu::RenderContext & renderCtx,const char * name,const char * description,uint32_t format,uint32_t dataType,int width,int height)94*35238bceSAndroid Build Coastguard Worker Texture2DFormatCase::Texture2DFormatCase(tcu::TestContext &testCtx, glu::RenderContext &renderCtx, const char *name,
95*35238bceSAndroid Build Coastguard Worker                                          const char *description, uint32_t format, uint32_t dataType, int width,
96*35238bceSAndroid Build Coastguard Worker                                          int height)
97*35238bceSAndroid Build Coastguard Worker     : TestCase(testCtx, name, description)
98*35238bceSAndroid Build Coastguard Worker     , m_renderCtx(renderCtx)
99*35238bceSAndroid Build Coastguard Worker     , m_format(format)
100*35238bceSAndroid Build Coastguard Worker     , m_dataType(dataType)
101*35238bceSAndroid Build Coastguard Worker     , m_width(width)
102*35238bceSAndroid Build Coastguard Worker     , m_height(height)
103*35238bceSAndroid Build Coastguard Worker     , m_texture(DE_NULL)
104*35238bceSAndroid Build Coastguard Worker     , m_renderer(renderCtx, testCtx.getLog(), glu::GLSL_VERSION_100_ES, glu::PRECISION_MEDIUMP)
105*35238bceSAndroid Build Coastguard Worker {
106*35238bceSAndroid Build Coastguard Worker }
107*35238bceSAndroid Build Coastguard Worker 
~Texture2DFormatCase(void)108*35238bceSAndroid Build Coastguard Worker Texture2DFormatCase::~Texture2DFormatCase(void)
109*35238bceSAndroid Build Coastguard Worker {
110*35238bceSAndroid Build Coastguard Worker     deinit();
111*35238bceSAndroid Build Coastguard Worker }
112*35238bceSAndroid Build Coastguard Worker 
init(void)113*35238bceSAndroid Build Coastguard Worker void Texture2DFormatCase::init(void)
114*35238bceSAndroid Build Coastguard Worker {
115*35238bceSAndroid Build Coastguard Worker     TestLog &log                = m_testCtx.getLog();
116*35238bceSAndroid Build Coastguard Worker     tcu::TextureFormat fmt      = glu::mapGLTransferFormat(m_format, m_dataType);
117*35238bceSAndroid Build Coastguard Worker     tcu::TextureFormatInfo spec = tcu::getTextureFormatInfo(fmt);
118*35238bceSAndroid Build Coastguard Worker     std::ostringstream fmtName;
119*35238bceSAndroid Build Coastguard Worker 
120*35238bceSAndroid Build Coastguard Worker     fmtName << getTextureFormatStr(m_format) << ", " << getTypeStr(m_dataType);
121*35238bceSAndroid Build Coastguard Worker 
122*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << "2D texture, " << fmtName.str() << ", " << m_width << "x" << m_height
123*35238bceSAndroid Build Coastguard Worker         << ",\n  fill with " << formatGradient(&spec.valueMin, &spec.valueMax) << " gradient" << TestLog::EndMessage;
124*35238bceSAndroid Build Coastguard Worker 
125*35238bceSAndroid Build Coastguard Worker     m_texture = new Texture2D(m_renderCtx, m_format, m_dataType, m_width, m_height);
126*35238bceSAndroid Build Coastguard Worker 
127*35238bceSAndroid Build Coastguard Worker     // Fill level 0.
128*35238bceSAndroid Build Coastguard Worker     m_texture->getRefTexture().allocLevel(0);
129*35238bceSAndroid Build Coastguard Worker     tcu::fillWithComponentGradients(m_texture->getRefTexture().getLevel(0), spec.valueMin, spec.valueMax);
130*35238bceSAndroid Build Coastguard Worker }
131*35238bceSAndroid Build Coastguard Worker 
deinit(void)132*35238bceSAndroid Build Coastguard Worker void Texture2DFormatCase::deinit(void)
133*35238bceSAndroid Build Coastguard Worker {
134*35238bceSAndroid Build Coastguard Worker     delete m_texture;
135*35238bceSAndroid Build Coastguard Worker     m_texture = DE_NULL;
136*35238bceSAndroid Build Coastguard Worker 
137*35238bceSAndroid Build Coastguard Worker     m_renderer.clear();
138*35238bceSAndroid Build Coastguard Worker }
139*35238bceSAndroid Build Coastguard Worker 
iterate(void)140*35238bceSAndroid Build Coastguard Worker Texture2DFormatCase::IterateResult Texture2DFormatCase::iterate(void)
141*35238bceSAndroid Build Coastguard Worker {
142*35238bceSAndroid Build Coastguard Worker     TestLog &log             = m_testCtx.getLog();
143*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_renderCtx.getFunctions();
144*35238bceSAndroid Build Coastguard Worker     RandomViewport viewport(m_renderCtx.getRenderTarget(), m_width, m_height, deStringHash(getName()));
145*35238bceSAndroid Build Coastguard Worker     tcu::Surface renderedFrame(viewport.width, viewport.height);
146*35238bceSAndroid Build Coastguard Worker     tcu::Surface referenceFrame(viewport.width, viewport.height);
147*35238bceSAndroid Build Coastguard Worker     tcu::RGBA threshold = m_renderCtx.getRenderTarget().getPixelFormat().getColorThreshold() + tcu::RGBA(1, 1, 1, 1);
148*35238bceSAndroid Build Coastguard Worker     vector<float> texCoord;
149*35238bceSAndroid Build Coastguard Worker     ReferenceParams renderParams(TEXTURETYPE_2D);
150*35238bceSAndroid Build Coastguard Worker     tcu::TextureFormatInfo spec = tcu::getTextureFormatInfo(m_texture->getRefTexture().getFormat());
151*35238bceSAndroid Build Coastguard Worker     const uint32_t wrapS        = GL_CLAMP_TO_EDGE;
152*35238bceSAndroid Build Coastguard Worker     const uint32_t wrapT        = GL_CLAMP_TO_EDGE;
153*35238bceSAndroid Build Coastguard Worker     const uint32_t minFilter    = GL_NEAREST;
154*35238bceSAndroid Build Coastguard Worker     const uint32_t magFilter    = GL_NEAREST;
155*35238bceSAndroid Build Coastguard Worker 
156*35238bceSAndroid Build Coastguard Worker     renderParams.flags |= RenderParams::LOG_ALL;
157*35238bceSAndroid Build Coastguard Worker     renderParams.samplerType = getSamplerType(m_texture->getRefTexture().getFormat());
158*35238bceSAndroid Build Coastguard Worker     renderParams.sampler     = Sampler(Sampler::CLAMP_TO_EDGE, Sampler::CLAMP_TO_EDGE, Sampler::CLAMP_TO_EDGE,
159*35238bceSAndroid Build Coastguard Worker                                        Sampler::NEAREST, Sampler::NEAREST);
160*35238bceSAndroid Build Coastguard Worker     renderParams.colorScale  = spec.lookupScale;
161*35238bceSAndroid Build Coastguard Worker     renderParams.colorBias   = spec.lookupBias;
162*35238bceSAndroid Build Coastguard Worker 
163*35238bceSAndroid Build Coastguard Worker     computeQuadTexCoord2D(texCoord, tcu::Vec2(0.0f, 0.0f), tcu::Vec2(1.0f, 1.0f));
164*35238bceSAndroid Build Coastguard Worker 
165*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << "Texture parameters:"
166*35238bceSAndroid Build Coastguard Worker         << "\n  WRAP_S = " << getTextureParameterValueStr(GL_TEXTURE_WRAP_S, wrapS)
167*35238bceSAndroid Build Coastguard Worker         << "\n  WRAP_T = " << getTextureParameterValueStr(GL_TEXTURE_WRAP_T, wrapT)
168*35238bceSAndroid Build Coastguard Worker         << "\n  MIN_FILTER = " << getTextureParameterValueStr(GL_TEXTURE_MIN_FILTER, minFilter)
169*35238bceSAndroid Build Coastguard Worker         << "\n  MAG_FILTER = " << getTextureParameterValueStr(GL_TEXTURE_MAG_FILTER, magFilter) << TestLog::EndMessage;
170*35238bceSAndroid Build Coastguard Worker 
171*35238bceSAndroid Build Coastguard Worker     // Setup base viewport.
172*35238bceSAndroid Build Coastguard Worker     gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
173*35238bceSAndroid Build Coastguard Worker 
174*35238bceSAndroid Build Coastguard Worker     // Upload texture data to GL.
175*35238bceSAndroid Build Coastguard Worker     m_texture->upload();
176*35238bceSAndroid Build Coastguard Worker 
177*35238bceSAndroid Build Coastguard Worker     // Bind to unit 0.
178*35238bceSAndroid Build Coastguard Worker     gl.activeTexture(GL_TEXTURE0);
179*35238bceSAndroid Build Coastguard Worker     gl.bindTexture(GL_TEXTURE_2D, m_texture->getGLTexture());
180*35238bceSAndroid Build Coastguard Worker 
181*35238bceSAndroid Build Coastguard Worker     // Setup nearest neighbor filtering and clamp-to-edge.
182*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapS);
183*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapT);
184*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter);
185*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter);
186*35238bceSAndroid Build Coastguard Worker 
187*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(gl.getError(), "Set texturing state");
188*35238bceSAndroid Build Coastguard Worker 
189*35238bceSAndroid Build Coastguard Worker     // Draw.
190*35238bceSAndroid Build Coastguard Worker     m_renderer.renderQuad(0, &texCoord[0], renderParams);
191*35238bceSAndroid Build Coastguard Worker     glu::readPixels(m_renderCtx, viewport.x, viewport.y, renderedFrame.getAccess());
192*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels()");
193*35238bceSAndroid Build Coastguard Worker 
194*35238bceSAndroid Build Coastguard Worker     // Compute reference.
195*35238bceSAndroid Build Coastguard Worker     sampleTexture(tcu::SurfaceAccess(referenceFrame, m_renderCtx.getRenderTarget().getPixelFormat()),
196*35238bceSAndroid Build Coastguard Worker                   m_texture->getRefTexture(), &texCoord[0], renderParams);
197*35238bceSAndroid Build Coastguard Worker 
198*35238bceSAndroid Build Coastguard Worker     // Compare and log.
199*35238bceSAndroid Build Coastguard Worker     bool isOk = compareImages(log, referenceFrame, renderedFrame, threshold);
200*35238bceSAndroid Build Coastguard Worker 
201*35238bceSAndroid Build Coastguard Worker     m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL,
202*35238bceSAndroid Build Coastguard Worker                             isOk ? "Pass" : "Image comparison failed");
203*35238bceSAndroid Build Coastguard Worker 
204*35238bceSAndroid Build Coastguard Worker     return STOP;
205*35238bceSAndroid Build Coastguard Worker }
206*35238bceSAndroid Build Coastguard Worker 
207*35238bceSAndroid Build Coastguard Worker // TextureCubeFormatCase
208*35238bceSAndroid Build Coastguard Worker 
209*35238bceSAndroid Build Coastguard Worker class TextureCubeFormatCase : public tcu::TestCase
210*35238bceSAndroid Build Coastguard Worker {
211*35238bceSAndroid Build Coastguard Worker public:
212*35238bceSAndroid Build Coastguard Worker     TextureCubeFormatCase(tcu::TestContext &testCtx, glu::RenderContext &renderCtx, const char *name,
213*35238bceSAndroid Build Coastguard Worker                           const char *description, uint32_t format, uint32_t dataType, int width, int height);
214*35238bceSAndroid Build Coastguard Worker     ~TextureCubeFormatCase(void);
215*35238bceSAndroid Build Coastguard Worker 
216*35238bceSAndroid Build Coastguard Worker     void init(void);
217*35238bceSAndroid Build Coastguard Worker     void deinit(void);
218*35238bceSAndroid Build Coastguard Worker     IterateResult iterate(void);
219*35238bceSAndroid Build Coastguard Worker 
220*35238bceSAndroid Build Coastguard Worker private:
221*35238bceSAndroid Build Coastguard Worker     TextureCubeFormatCase(const TextureCubeFormatCase &other);
222*35238bceSAndroid Build Coastguard Worker     TextureCubeFormatCase &operator=(const TextureCubeFormatCase &other);
223*35238bceSAndroid Build Coastguard Worker 
224*35238bceSAndroid Build Coastguard Worker     bool testFace(tcu::CubeFace face);
225*35238bceSAndroid Build Coastguard Worker 
226*35238bceSAndroid Build Coastguard Worker     glu::RenderContext &m_renderCtx;
227*35238bceSAndroid Build Coastguard Worker 
228*35238bceSAndroid Build Coastguard Worker     const uint32_t m_format;
229*35238bceSAndroid Build Coastguard Worker     const uint32_t m_dataType;
230*35238bceSAndroid Build Coastguard Worker     const int m_width;
231*35238bceSAndroid Build Coastguard Worker     const int m_height;
232*35238bceSAndroid Build Coastguard Worker 
233*35238bceSAndroid Build Coastguard Worker     glu::TextureCube *m_texture;
234*35238bceSAndroid Build Coastguard Worker     TextureRenderer m_renderer;
235*35238bceSAndroid Build Coastguard Worker 
236*35238bceSAndroid Build Coastguard Worker     int m_curFace;
237*35238bceSAndroid Build Coastguard Worker     bool m_isOk;
238*35238bceSAndroid Build Coastguard Worker };
239*35238bceSAndroid Build Coastguard Worker 
TextureCubeFormatCase(tcu::TestContext & testCtx,glu::RenderContext & renderCtx,const char * name,const char * description,uint32_t format,uint32_t dataType,int width,int height)240*35238bceSAndroid Build Coastguard Worker TextureCubeFormatCase::TextureCubeFormatCase(tcu::TestContext &testCtx, glu::RenderContext &renderCtx, const char *name,
241*35238bceSAndroid Build Coastguard Worker                                              const char *description, uint32_t format, uint32_t dataType, int width,
242*35238bceSAndroid Build Coastguard Worker                                              int height)
243*35238bceSAndroid Build Coastguard Worker     : TestCase(testCtx, name, description)
244*35238bceSAndroid Build Coastguard Worker     , m_renderCtx(renderCtx)
245*35238bceSAndroid Build Coastguard Worker     , m_format(format)
246*35238bceSAndroid Build Coastguard Worker     , m_dataType(dataType)
247*35238bceSAndroid Build Coastguard Worker     , m_width(width)
248*35238bceSAndroid Build Coastguard Worker     , m_height(height)
249*35238bceSAndroid Build Coastguard Worker     , m_texture(DE_NULL)
250*35238bceSAndroid Build Coastguard Worker     , m_renderer(renderCtx, testCtx.getLog(), glu::GLSL_VERSION_100_ES, glu::PRECISION_MEDIUMP)
251*35238bceSAndroid Build Coastguard Worker     , m_curFace(0)
252*35238bceSAndroid Build Coastguard Worker     , m_isOk(false)
253*35238bceSAndroid Build Coastguard Worker {
254*35238bceSAndroid Build Coastguard Worker }
255*35238bceSAndroid Build Coastguard Worker 
~TextureCubeFormatCase(void)256*35238bceSAndroid Build Coastguard Worker TextureCubeFormatCase::~TextureCubeFormatCase(void)
257*35238bceSAndroid Build Coastguard Worker {
258*35238bceSAndroid Build Coastguard Worker     deinit();
259*35238bceSAndroid Build Coastguard Worker }
260*35238bceSAndroid Build Coastguard Worker 
init(void)261*35238bceSAndroid Build Coastguard Worker void TextureCubeFormatCase::init(void)
262*35238bceSAndroid Build Coastguard Worker {
263*35238bceSAndroid Build Coastguard Worker     TestLog &log                = m_testCtx.getLog();
264*35238bceSAndroid Build Coastguard Worker     tcu::TextureFormat fmt      = glu::mapGLTransferFormat(m_format, m_dataType);
265*35238bceSAndroid Build Coastguard Worker     tcu::TextureFormatInfo spec = tcu::getTextureFormatInfo(fmt);
266*35238bceSAndroid Build Coastguard Worker     std::ostringstream fmtName;
267*35238bceSAndroid Build Coastguard Worker 
268*35238bceSAndroid Build Coastguard Worker     if (m_dataType)
269*35238bceSAndroid Build Coastguard Worker         fmtName << getTextureFormatStr(m_format) << ", " << getTypeStr(m_dataType);
270*35238bceSAndroid Build Coastguard Worker     else
271*35238bceSAndroid Build Coastguard Worker         fmtName << getTextureFormatStr(m_format);
272*35238bceSAndroid Build Coastguard Worker 
273*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << "Cube map texture, " << fmtName.str() << ", " << m_width << "x" << m_height
274*35238bceSAndroid Build Coastguard Worker         << ",\n  fill with " << formatGradient(&spec.valueMin, &spec.valueMax) << " gradient" << TestLog::EndMessage;
275*35238bceSAndroid Build Coastguard Worker 
276*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(m_width == m_height);
277*35238bceSAndroid Build Coastguard Worker     m_texture = m_dataType != GL_NONE ?
278*35238bceSAndroid Build Coastguard Worker                     new TextureCube(m_renderCtx, m_format, m_dataType, m_width) // Implicit internal format.
279*35238bceSAndroid Build Coastguard Worker                     :
280*35238bceSAndroid Build Coastguard Worker                     new TextureCube(m_renderCtx, m_format, m_width); // Explicit internal format.
281*35238bceSAndroid Build Coastguard Worker 
282*35238bceSAndroid Build Coastguard Worker     // Fill level 0.
283*35238bceSAndroid Build Coastguard Worker     for (int face = 0; face < tcu::CUBEFACE_LAST; face++)
284*35238bceSAndroid Build Coastguard Worker     {
285*35238bceSAndroid Build Coastguard Worker         tcu::Vec4 gMin, gMax;
286*35238bceSAndroid Build Coastguard Worker 
287*35238bceSAndroid Build Coastguard Worker         switch (face)
288*35238bceSAndroid Build Coastguard Worker         {
289*35238bceSAndroid Build Coastguard Worker         case 0:
290*35238bceSAndroid Build Coastguard Worker             gMin = spec.valueMin.swizzle(0, 1, 2, 3);
291*35238bceSAndroid Build Coastguard Worker             gMax = spec.valueMax.swizzle(0, 1, 2, 3);
292*35238bceSAndroid Build Coastguard Worker             break;
293*35238bceSAndroid Build Coastguard Worker         case 1:
294*35238bceSAndroid Build Coastguard Worker             gMin = spec.valueMin.swizzle(2, 1, 0, 3);
295*35238bceSAndroid Build Coastguard Worker             gMax = spec.valueMax.swizzle(2, 1, 0, 3);
296*35238bceSAndroid Build Coastguard Worker             break;
297*35238bceSAndroid Build Coastguard Worker         case 2:
298*35238bceSAndroid Build Coastguard Worker             gMin = spec.valueMin.swizzle(1, 2, 0, 3);
299*35238bceSAndroid Build Coastguard Worker             gMax = spec.valueMax.swizzle(1, 2, 0, 3);
300*35238bceSAndroid Build Coastguard Worker             break;
301*35238bceSAndroid Build Coastguard Worker         case 3:
302*35238bceSAndroid Build Coastguard Worker             gMin = spec.valueMax.swizzle(0, 1, 2, 3);
303*35238bceSAndroid Build Coastguard Worker             gMax = spec.valueMin.swizzle(0, 1, 2, 3);
304*35238bceSAndroid Build Coastguard Worker             break;
305*35238bceSAndroid Build Coastguard Worker         case 4:
306*35238bceSAndroid Build Coastguard Worker             gMin = spec.valueMax.swizzle(2, 1, 0, 3);
307*35238bceSAndroid Build Coastguard Worker             gMax = spec.valueMin.swizzle(2, 1, 0, 3);
308*35238bceSAndroid Build Coastguard Worker             break;
309*35238bceSAndroid Build Coastguard Worker         case 5:
310*35238bceSAndroid Build Coastguard Worker             gMin = spec.valueMax.swizzle(1, 2, 0, 3);
311*35238bceSAndroid Build Coastguard Worker             gMax = spec.valueMin.swizzle(1, 2, 0, 3);
312*35238bceSAndroid Build Coastguard Worker             break;
313*35238bceSAndroid Build Coastguard Worker         default:
314*35238bceSAndroid Build Coastguard Worker             DE_ASSERT(false);
315*35238bceSAndroid Build Coastguard Worker         }
316*35238bceSAndroid Build Coastguard Worker 
317*35238bceSAndroid Build Coastguard Worker         m_texture->getRefTexture().allocLevel((tcu::CubeFace)face, 0);
318*35238bceSAndroid Build Coastguard Worker         tcu::fillWithComponentGradients(m_texture->getRefTexture().getLevelFace(0, (tcu::CubeFace)face), gMin, gMax);
319*35238bceSAndroid Build Coastguard Worker     }
320*35238bceSAndroid Build Coastguard Worker 
321*35238bceSAndroid Build Coastguard Worker     // Upload texture data to GL.
322*35238bceSAndroid Build Coastguard Worker     m_texture->upload();
323*35238bceSAndroid Build Coastguard Worker 
324*35238bceSAndroid Build Coastguard Worker     // Initialize iteration state.
325*35238bceSAndroid Build Coastguard Worker     m_curFace = 0;
326*35238bceSAndroid Build Coastguard Worker     m_isOk    = true;
327*35238bceSAndroid Build Coastguard Worker }
328*35238bceSAndroid Build Coastguard Worker 
deinit(void)329*35238bceSAndroid Build Coastguard Worker void TextureCubeFormatCase::deinit(void)
330*35238bceSAndroid Build Coastguard Worker {
331*35238bceSAndroid Build Coastguard Worker     delete m_texture;
332*35238bceSAndroid Build Coastguard Worker     m_texture = DE_NULL;
333*35238bceSAndroid Build Coastguard Worker 
334*35238bceSAndroid Build Coastguard Worker     m_renderer.clear();
335*35238bceSAndroid Build Coastguard Worker }
336*35238bceSAndroid Build Coastguard Worker 
testFace(tcu::CubeFace face)337*35238bceSAndroid Build Coastguard Worker bool TextureCubeFormatCase::testFace(tcu::CubeFace face)
338*35238bceSAndroid Build Coastguard Worker {
339*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_renderCtx.getFunctions();
340*35238bceSAndroid Build Coastguard Worker     TestLog &log             = m_testCtx.getLog();
341*35238bceSAndroid Build Coastguard Worker     RandomViewport viewport(m_renderCtx.getRenderTarget(), m_width, m_height, deStringHash(getName()) + (uint32_t)face);
342*35238bceSAndroid Build Coastguard Worker     tcu::Surface renderedFrame(viewport.width, viewport.height);
343*35238bceSAndroid Build Coastguard Worker     tcu::Surface referenceFrame(viewport.width, viewport.height);
344*35238bceSAndroid Build Coastguard Worker     tcu::RGBA threshold = m_renderCtx.getRenderTarget().getPixelFormat().getColorThreshold() + tcu::RGBA(1, 1, 1, 1);
345*35238bceSAndroid Build Coastguard Worker     vector<float> texCoord;
346*35238bceSAndroid Build Coastguard Worker     ReferenceParams renderParams(TEXTURETYPE_CUBE);
347*35238bceSAndroid Build Coastguard Worker     tcu::TextureFormatInfo spec = tcu::getTextureFormatInfo(m_texture->getRefTexture().getFormat());
348*35238bceSAndroid Build Coastguard Worker 
349*35238bceSAndroid Build Coastguard Worker     renderParams.samplerType = getSamplerType(m_texture->getRefTexture().getFormat());
350*35238bceSAndroid Build Coastguard Worker     renderParams.sampler     = Sampler(Sampler::CLAMP_TO_EDGE, Sampler::CLAMP_TO_EDGE, Sampler::CLAMP_TO_EDGE,
351*35238bceSAndroid Build Coastguard Worker                                        Sampler::NEAREST, Sampler::NEAREST);
352*35238bceSAndroid Build Coastguard Worker     renderParams.sampler.seamlessCubeMap = false;
353*35238bceSAndroid Build Coastguard Worker     renderParams.colorScale              = spec.lookupScale;
354*35238bceSAndroid Build Coastguard Worker     renderParams.colorBias               = spec.lookupBias;
355*35238bceSAndroid Build Coastguard Worker 
356*35238bceSAndroid Build Coastguard Worker     // Log render info on first face.
357*35238bceSAndroid Build Coastguard Worker     if (face == tcu::CUBEFACE_NEGATIVE_X)
358*35238bceSAndroid Build Coastguard Worker         renderParams.flags |= RenderParams::LOG_ALL;
359*35238bceSAndroid Build Coastguard Worker 
360*35238bceSAndroid Build Coastguard Worker     computeQuadTexCoordCube(texCoord, face);
361*35238bceSAndroid Build Coastguard Worker 
362*35238bceSAndroid Build Coastguard Worker     // \todo [2011-10-28 pyry] Image set name / section?
363*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << face << TestLog::EndMessage;
364*35238bceSAndroid Build Coastguard Worker 
365*35238bceSAndroid Build Coastguard Worker     // Setup base viewport.
366*35238bceSAndroid Build Coastguard Worker     gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
367*35238bceSAndroid Build Coastguard Worker 
368*35238bceSAndroid Build Coastguard Worker     // Bind to unit 0.
369*35238bceSAndroid Build Coastguard Worker     gl.activeTexture(GL_TEXTURE0);
370*35238bceSAndroid Build Coastguard Worker     gl.bindTexture(GL_TEXTURE_CUBE_MAP, m_texture->getGLTexture());
371*35238bceSAndroid Build Coastguard Worker 
372*35238bceSAndroid Build Coastguard Worker     // Setup nearest neighbor filtering and clamp-to-edge.
373*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
374*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
375*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
376*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
377*35238bceSAndroid Build Coastguard Worker 
378*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(gl.getError(), "Set texturing state");
379*35238bceSAndroid Build Coastguard Worker 
380*35238bceSAndroid Build Coastguard Worker     m_renderer.renderQuad(0, &texCoord[0], renderParams);
381*35238bceSAndroid Build Coastguard Worker     glu::readPixels(m_renderCtx, viewport.x, viewport.y, renderedFrame.getAccess());
382*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels()");
383*35238bceSAndroid Build Coastguard Worker 
384*35238bceSAndroid Build Coastguard Worker     // Compute reference.
385*35238bceSAndroid Build Coastguard Worker     sampleTexture(tcu::SurfaceAccess(referenceFrame, m_renderCtx.getRenderTarget().getPixelFormat()),
386*35238bceSAndroid Build Coastguard Worker                   m_texture->getRefTexture(), &texCoord[0], renderParams);
387*35238bceSAndroid Build Coastguard Worker 
388*35238bceSAndroid Build Coastguard Worker     // Compare and log.
389*35238bceSAndroid Build Coastguard Worker     return compareImages(log, referenceFrame, renderedFrame, threshold);
390*35238bceSAndroid Build Coastguard Worker }
391*35238bceSAndroid Build Coastguard Worker 
iterate(void)392*35238bceSAndroid Build Coastguard Worker TextureCubeFormatCase::IterateResult TextureCubeFormatCase::iterate(void)
393*35238bceSAndroid Build Coastguard Worker {
394*35238bceSAndroid Build Coastguard Worker     // Execute test for all faces.
395*35238bceSAndroid Build Coastguard Worker     if (!testFace((tcu::CubeFace)m_curFace))
396*35238bceSAndroid Build Coastguard Worker         m_isOk = false;
397*35238bceSAndroid Build Coastguard Worker 
398*35238bceSAndroid Build Coastguard Worker     m_curFace += 1;
399*35238bceSAndroid Build Coastguard Worker 
400*35238bceSAndroid Build Coastguard Worker     if (m_curFace == tcu::CUBEFACE_LAST)
401*35238bceSAndroid Build Coastguard Worker     {
402*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(m_isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL,
403*35238bceSAndroid Build Coastguard Worker                                 m_isOk ? "Pass" : "Image comparison failed");
404*35238bceSAndroid Build Coastguard Worker         return STOP;
405*35238bceSAndroid Build Coastguard Worker     }
406*35238bceSAndroid Build Coastguard Worker     else
407*35238bceSAndroid Build Coastguard Worker         return CONTINUE;
408*35238bceSAndroid Build Coastguard Worker }
409*35238bceSAndroid Build Coastguard Worker 
TextureFormatTests(Context & context)410*35238bceSAndroid Build Coastguard Worker TextureFormatTests::TextureFormatTests(Context &context) : TestCaseGroup(context, "format", "Texture Format Tests")
411*35238bceSAndroid Build Coastguard Worker {
412*35238bceSAndroid Build Coastguard Worker }
413*35238bceSAndroid Build Coastguard Worker 
~TextureFormatTests(void)414*35238bceSAndroid Build Coastguard Worker TextureFormatTests::~TextureFormatTests(void)
415*35238bceSAndroid Build Coastguard Worker {
416*35238bceSAndroid Build Coastguard Worker }
417*35238bceSAndroid Build Coastguard Worker 
418*35238bceSAndroid Build Coastguard Worker // Compressed2DFormatCase
419*35238bceSAndroid Build Coastguard Worker 
420*35238bceSAndroid Build Coastguard Worker class Compressed2DFormatCase : public tcu::TestCase
421*35238bceSAndroid Build Coastguard Worker {
422*35238bceSAndroid Build Coastguard Worker public:
423*35238bceSAndroid Build Coastguard Worker     Compressed2DFormatCase(tcu::TestContext &testCtx, glu::RenderContext &renderCtx,
424*35238bceSAndroid Build Coastguard Worker                            const glu::ContextInfo &renderCtxInfo, const char *name, const char *description,
425*35238bceSAndroid Build Coastguard Worker                            const std::vector<std::string> &filenames);
426*35238bceSAndroid Build Coastguard Worker     ~Compressed2DFormatCase(void);
427*35238bceSAndroid Build Coastguard Worker 
428*35238bceSAndroid Build Coastguard Worker     void init(void);
429*35238bceSAndroid Build Coastguard Worker     void deinit(void);
430*35238bceSAndroid Build Coastguard Worker     IterateResult iterate(void);
431*35238bceSAndroid Build Coastguard Worker 
432*35238bceSAndroid Build Coastguard Worker private:
433*35238bceSAndroid Build Coastguard Worker     Compressed2DFormatCase(const Compressed2DFormatCase &other);
434*35238bceSAndroid Build Coastguard Worker     Compressed2DFormatCase &operator=(const Compressed2DFormatCase &other);
435*35238bceSAndroid Build Coastguard Worker 
436*35238bceSAndroid Build Coastguard Worker     glu::RenderContext &m_renderCtx;
437*35238bceSAndroid Build Coastguard Worker     const glu::ContextInfo &m_renderCtxInfo;
438*35238bceSAndroid Build Coastguard Worker 
439*35238bceSAndroid Build Coastguard Worker     std::vector<std::string> m_filenames;
440*35238bceSAndroid Build Coastguard Worker 
441*35238bceSAndroid Build Coastguard Worker     glu::Texture2D *m_texture;
442*35238bceSAndroid Build Coastguard Worker     TextureRenderer m_renderer;
443*35238bceSAndroid Build Coastguard Worker };
444*35238bceSAndroid Build Coastguard Worker 
Compressed2DFormatCase(tcu::TestContext & testCtx,glu::RenderContext & renderCtx,const glu::ContextInfo & renderCtxInfo,const char * name,const char * description,const std::vector<std::string> & filenames)445*35238bceSAndroid Build Coastguard Worker Compressed2DFormatCase::Compressed2DFormatCase(tcu::TestContext &testCtx, glu::RenderContext &renderCtx,
446*35238bceSAndroid Build Coastguard Worker                                                const glu::ContextInfo &renderCtxInfo, const char *name,
447*35238bceSAndroid Build Coastguard Worker                                                const char *description, const std::vector<std::string> &filenames)
448*35238bceSAndroid Build Coastguard Worker     : TestCase(testCtx, name, description)
449*35238bceSAndroid Build Coastguard Worker     , m_renderCtx(renderCtx)
450*35238bceSAndroid Build Coastguard Worker     , m_renderCtxInfo(renderCtxInfo)
451*35238bceSAndroid Build Coastguard Worker     , m_filenames(filenames)
452*35238bceSAndroid Build Coastguard Worker     , m_texture(DE_NULL)
453*35238bceSAndroid Build Coastguard Worker     , m_renderer(renderCtx, testCtx.getLog(), glu::GLSL_VERSION_100_ES, glu::PRECISION_MEDIUMP)
454*35238bceSAndroid Build Coastguard Worker {
455*35238bceSAndroid Build Coastguard Worker }
456*35238bceSAndroid Build Coastguard Worker 
~Compressed2DFormatCase(void)457*35238bceSAndroid Build Coastguard Worker Compressed2DFormatCase::~Compressed2DFormatCase(void)
458*35238bceSAndroid Build Coastguard Worker {
459*35238bceSAndroid Build Coastguard Worker     deinit();
460*35238bceSAndroid Build Coastguard Worker }
461*35238bceSAndroid Build Coastguard Worker 
init(void)462*35238bceSAndroid Build Coastguard Worker void Compressed2DFormatCase::init(void)
463*35238bceSAndroid Build Coastguard Worker {
464*35238bceSAndroid Build Coastguard Worker     // Create texture.
465*35238bceSAndroid Build Coastguard Worker     m_texture =
466*35238bceSAndroid Build Coastguard Worker         Texture2D::create(m_renderCtx, m_renderCtxInfo, m_testCtx.getArchive(), (int)m_filenames.size(), m_filenames);
467*35238bceSAndroid Build Coastguard Worker }
468*35238bceSAndroid Build Coastguard Worker 
deinit(void)469*35238bceSAndroid Build Coastguard Worker void Compressed2DFormatCase::deinit(void)
470*35238bceSAndroid Build Coastguard Worker {
471*35238bceSAndroid Build Coastguard Worker     delete m_texture;
472*35238bceSAndroid Build Coastguard Worker     m_texture = DE_NULL;
473*35238bceSAndroid Build Coastguard Worker 
474*35238bceSAndroid Build Coastguard Worker     m_renderer.clear();
475*35238bceSAndroid Build Coastguard Worker }
476*35238bceSAndroid Build Coastguard Worker 
iterate(void)477*35238bceSAndroid Build Coastguard Worker Compressed2DFormatCase::IterateResult Compressed2DFormatCase::iterate(void)
478*35238bceSAndroid Build Coastguard Worker {
479*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_renderCtx.getFunctions();
480*35238bceSAndroid Build Coastguard Worker     TestLog &log             = m_testCtx.getLog();
481*35238bceSAndroid Build Coastguard Worker     RandomViewport viewport(m_renderCtx.getRenderTarget(), m_texture->getRefTexture().getWidth(),
482*35238bceSAndroid Build Coastguard Worker                             m_texture->getRefTexture().getHeight(), deStringHash(getName()));
483*35238bceSAndroid Build Coastguard Worker     tcu::Surface renderedFrame(viewport.width, viewport.height);
484*35238bceSAndroid Build Coastguard Worker     tcu::Surface referenceFrame(viewport.width, viewport.height);
485*35238bceSAndroid Build Coastguard Worker     tcu::RGBA threshold = m_renderCtx.getRenderTarget().getPixelFormat().getColorThreshold() + tcu::RGBA(1, 1, 1, 1);
486*35238bceSAndroid Build Coastguard Worker     vector<float> texCoord;
487*35238bceSAndroid Build Coastguard Worker 
488*35238bceSAndroid Build Coastguard Worker     computeQuadTexCoord2D(texCoord, tcu::Vec2(0.0f, 0.0f), tcu::Vec2(1.0f, 1.0f));
489*35238bceSAndroid Build Coastguard Worker 
490*35238bceSAndroid Build Coastguard Worker     // Setup base viewport.
491*35238bceSAndroid Build Coastguard Worker     gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
492*35238bceSAndroid Build Coastguard Worker 
493*35238bceSAndroid Build Coastguard Worker     // Bind to unit 0.
494*35238bceSAndroid Build Coastguard Worker     gl.activeTexture(GL_TEXTURE0);
495*35238bceSAndroid Build Coastguard Worker     gl.bindTexture(GL_TEXTURE_2D, m_texture->getGLTexture());
496*35238bceSAndroid Build Coastguard Worker 
497*35238bceSAndroid Build Coastguard Worker     // Setup nearest neighbor filtering and clamp-to-edge.
498*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
499*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
500*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
501*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
502*35238bceSAndroid Build Coastguard Worker 
503*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(gl.getError(), "Set texturing state");
504*35238bceSAndroid Build Coastguard Worker 
505*35238bceSAndroid Build Coastguard Worker     // Draw.
506*35238bceSAndroid Build Coastguard Worker     m_renderer.renderQuad(0, &texCoord[0], TEXTURETYPE_2D);
507*35238bceSAndroid Build Coastguard Worker     glu::readPixels(m_renderCtx, viewport.x, viewport.y, renderedFrame.getAccess());
508*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels()");
509*35238bceSAndroid Build Coastguard Worker 
510*35238bceSAndroid Build Coastguard Worker     // Compute reference.
511*35238bceSAndroid Build Coastguard Worker     ReferenceParams refParams(TEXTURETYPE_2D);
512*35238bceSAndroid Build Coastguard Worker     refParams.sampler = Sampler(Sampler::CLAMP_TO_EDGE, Sampler::CLAMP_TO_EDGE, Sampler::CLAMP_TO_EDGE,
513*35238bceSAndroid Build Coastguard Worker                                 Sampler::NEAREST, Sampler::NEAREST);
514*35238bceSAndroid Build Coastguard Worker     sampleTexture(tcu::SurfaceAccess(referenceFrame, m_renderCtx.getRenderTarget().getPixelFormat()),
515*35238bceSAndroid Build Coastguard Worker                   m_texture->getRefTexture(), &texCoord[0], refParams);
516*35238bceSAndroid Build Coastguard Worker 
517*35238bceSAndroid Build Coastguard Worker     // Compare and log.
518*35238bceSAndroid Build Coastguard Worker     bool isOk = compareImages(log, referenceFrame, renderedFrame, threshold);
519*35238bceSAndroid Build Coastguard Worker 
520*35238bceSAndroid Build Coastguard Worker     m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL,
521*35238bceSAndroid Build Coastguard Worker                             isOk ? "Pass" : "Image comparison failed");
522*35238bceSAndroid Build Coastguard Worker 
523*35238bceSAndroid Build Coastguard Worker     return STOP;
524*35238bceSAndroid Build Coastguard Worker }
525*35238bceSAndroid Build Coastguard Worker 
526*35238bceSAndroid Build Coastguard Worker // CompressedCubeFormatCase
527*35238bceSAndroid Build Coastguard Worker 
528*35238bceSAndroid Build Coastguard Worker class CompressedCubeFormatCase : public tcu::TestCase
529*35238bceSAndroid Build Coastguard Worker {
530*35238bceSAndroid Build Coastguard Worker public:
531*35238bceSAndroid Build Coastguard Worker     CompressedCubeFormatCase(tcu::TestContext &testCtx, glu::RenderContext &renderCtx,
532*35238bceSAndroid Build Coastguard Worker                              const glu::ContextInfo &renderCtxInfo, const char *name, const char *description,
533*35238bceSAndroid Build Coastguard Worker                              const std::vector<std::string> &filenames);
534*35238bceSAndroid Build Coastguard Worker     ~CompressedCubeFormatCase(void);
535*35238bceSAndroid Build Coastguard Worker 
536*35238bceSAndroid Build Coastguard Worker     void init(void);
537*35238bceSAndroid Build Coastguard Worker     void deinit(void);
538*35238bceSAndroid Build Coastguard Worker     IterateResult iterate(void);
539*35238bceSAndroid Build Coastguard Worker 
540*35238bceSAndroid Build Coastguard Worker private:
541*35238bceSAndroid Build Coastguard Worker     CompressedCubeFormatCase(const CompressedCubeFormatCase &other);
542*35238bceSAndroid Build Coastguard Worker     CompressedCubeFormatCase &operator=(const CompressedCubeFormatCase &other);
543*35238bceSAndroid Build Coastguard Worker 
544*35238bceSAndroid Build Coastguard Worker     bool testFace(tcu::CubeFace face);
545*35238bceSAndroid Build Coastguard Worker 
546*35238bceSAndroid Build Coastguard Worker     glu::RenderContext &m_renderCtx;
547*35238bceSAndroid Build Coastguard Worker     const glu::ContextInfo &m_renderCtxInfo;
548*35238bceSAndroid Build Coastguard Worker 
549*35238bceSAndroid Build Coastguard Worker     std::vector<std::string> m_filenames;
550*35238bceSAndroid Build Coastguard Worker 
551*35238bceSAndroid Build Coastguard Worker     glu::TextureCube *m_texture;
552*35238bceSAndroid Build Coastguard Worker     TextureRenderer m_renderer;
553*35238bceSAndroid Build Coastguard Worker 
554*35238bceSAndroid Build Coastguard Worker     int m_curFace;
555*35238bceSAndroid Build Coastguard Worker     bool m_isOk;
556*35238bceSAndroid Build Coastguard Worker };
557*35238bceSAndroid Build Coastguard Worker 
CompressedCubeFormatCase(tcu::TestContext & testCtx,glu::RenderContext & renderCtx,const glu::ContextInfo & renderCtxInfo,const char * name,const char * description,const std::vector<std::string> & filenames)558*35238bceSAndroid Build Coastguard Worker CompressedCubeFormatCase::CompressedCubeFormatCase(tcu::TestContext &testCtx, glu::RenderContext &renderCtx,
559*35238bceSAndroid Build Coastguard Worker                                                    const glu::ContextInfo &renderCtxInfo, const char *name,
560*35238bceSAndroid Build Coastguard Worker                                                    const char *description, const std::vector<std::string> &filenames)
561*35238bceSAndroid Build Coastguard Worker     : TestCase(testCtx, name, description)
562*35238bceSAndroid Build Coastguard Worker     , m_renderCtx(renderCtx)
563*35238bceSAndroid Build Coastguard Worker     , m_renderCtxInfo(renderCtxInfo)
564*35238bceSAndroid Build Coastguard Worker     , m_filenames(filenames)
565*35238bceSAndroid Build Coastguard Worker     , m_texture(DE_NULL)
566*35238bceSAndroid Build Coastguard Worker     , m_renderer(renderCtx, testCtx.getLog(), glu::GLSL_VERSION_100_ES, glu::PRECISION_MEDIUMP)
567*35238bceSAndroid Build Coastguard Worker     , m_curFace(0)
568*35238bceSAndroid Build Coastguard Worker     , m_isOk(false)
569*35238bceSAndroid Build Coastguard Worker {
570*35238bceSAndroid Build Coastguard Worker }
571*35238bceSAndroid Build Coastguard Worker 
~CompressedCubeFormatCase(void)572*35238bceSAndroid Build Coastguard Worker CompressedCubeFormatCase::~CompressedCubeFormatCase(void)
573*35238bceSAndroid Build Coastguard Worker {
574*35238bceSAndroid Build Coastguard Worker     deinit();
575*35238bceSAndroid Build Coastguard Worker }
576*35238bceSAndroid Build Coastguard Worker 
init(void)577*35238bceSAndroid Build Coastguard Worker void CompressedCubeFormatCase::init(void)
578*35238bceSAndroid Build Coastguard Worker {
579*35238bceSAndroid Build Coastguard Worker     // Create texture.
580*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(m_filenames.size() % 6 == 0);
581*35238bceSAndroid Build Coastguard Worker     m_texture = TextureCube::create(m_renderCtx, m_renderCtxInfo, m_testCtx.getArchive(), (int)m_filenames.size() / 6,
582*35238bceSAndroid Build Coastguard Worker                                     m_filenames);
583*35238bceSAndroid Build Coastguard Worker 
584*35238bceSAndroid Build Coastguard Worker     m_curFace = 0;
585*35238bceSAndroid Build Coastguard Worker     m_isOk    = true;
586*35238bceSAndroid Build Coastguard Worker }
587*35238bceSAndroid Build Coastguard Worker 
deinit(void)588*35238bceSAndroid Build Coastguard Worker void CompressedCubeFormatCase::deinit(void)
589*35238bceSAndroid Build Coastguard Worker {
590*35238bceSAndroid Build Coastguard Worker     delete m_texture;
591*35238bceSAndroid Build Coastguard Worker     m_texture = DE_NULL;
592*35238bceSAndroid Build Coastguard Worker 
593*35238bceSAndroid Build Coastguard Worker     m_renderer.clear();
594*35238bceSAndroid Build Coastguard Worker }
595*35238bceSAndroid Build Coastguard Worker 
testFace(tcu::CubeFace face)596*35238bceSAndroid Build Coastguard Worker bool CompressedCubeFormatCase::testFace(tcu::CubeFace face)
597*35238bceSAndroid Build Coastguard Worker {
598*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_renderCtx.getFunctions();
599*35238bceSAndroid Build Coastguard Worker     TestLog &log             = m_testCtx.getLog();
600*35238bceSAndroid Build Coastguard Worker     RandomViewport viewport(m_renderCtx.getRenderTarget(), m_texture->getRefTexture().getSize(),
601*35238bceSAndroid Build Coastguard Worker                             m_texture->getRefTexture().getSize(), deStringHash(getName()) + (uint32_t)face);
602*35238bceSAndroid Build Coastguard Worker     tcu::Surface renderedFrame(viewport.width, viewport.height);
603*35238bceSAndroid Build Coastguard Worker     tcu::Surface referenceFrame(viewport.width, viewport.height);
604*35238bceSAndroid Build Coastguard Worker     Sampler sampler(Sampler::CLAMP_TO_EDGE, Sampler::CLAMP_TO_EDGE, Sampler::CLAMP_TO_EDGE, Sampler::NEAREST,
605*35238bceSAndroid Build Coastguard Worker                     Sampler::NEAREST);
606*35238bceSAndroid Build Coastguard Worker     tcu::RGBA threshold = m_renderCtx.getRenderTarget().getPixelFormat().getColorThreshold() + tcu::RGBA(1, 1, 1, 1);
607*35238bceSAndroid Build Coastguard Worker     vector<float> texCoord;
608*35238bceSAndroid Build Coastguard Worker 
609*35238bceSAndroid Build Coastguard Worker     computeQuadTexCoordCube(texCoord, face);
610*35238bceSAndroid Build Coastguard Worker 
611*35238bceSAndroid Build Coastguard Worker     // \todo [2011-10-28 pyry] Image set name / section?
612*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << face << TestLog::EndMessage;
613*35238bceSAndroid Build Coastguard Worker 
614*35238bceSAndroid Build Coastguard Worker     // Setup base viewport.
615*35238bceSAndroid Build Coastguard Worker     gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
616*35238bceSAndroid Build Coastguard Worker 
617*35238bceSAndroid Build Coastguard Worker     // Bind to unit 0.
618*35238bceSAndroid Build Coastguard Worker     gl.activeTexture(GL_TEXTURE0);
619*35238bceSAndroid Build Coastguard Worker     gl.bindTexture(GL_TEXTURE_CUBE_MAP, m_texture->getGLTexture());
620*35238bceSAndroid Build Coastguard Worker 
621*35238bceSAndroid Build Coastguard Worker     // Setup nearest neighbor filtering and clamp-to-edge.
622*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
623*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
624*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
625*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
626*35238bceSAndroid Build Coastguard Worker 
627*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(gl.getError(), "Set texturing state");
628*35238bceSAndroid Build Coastguard Worker 
629*35238bceSAndroid Build Coastguard Worker     m_renderer.renderQuad(0, &texCoord[0], TEXTURETYPE_CUBE);
630*35238bceSAndroid Build Coastguard Worker     glu::readPixels(m_renderCtx, viewport.x, viewport.y, renderedFrame.getAccess());
631*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels()");
632*35238bceSAndroid Build Coastguard Worker 
633*35238bceSAndroid Build Coastguard Worker     // Compute reference.
634*35238bceSAndroid Build Coastguard Worker     sampleTexture(tcu::SurfaceAccess(referenceFrame, m_renderCtx.getRenderTarget().getPixelFormat()),
635*35238bceSAndroid Build Coastguard Worker                   m_texture->getRefTexture(), &texCoord[0], ReferenceParams(TEXTURETYPE_CUBE, sampler));
636*35238bceSAndroid Build Coastguard Worker 
637*35238bceSAndroid Build Coastguard Worker     // Compare and log.
638*35238bceSAndroid Build Coastguard Worker     return compareImages(log, referenceFrame, renderedFrame, threshold);
639*35238bceSAndroid Build Coastguard Worker }
640*35238bceSAndroid Build Coastguard Worker 
iterate(void)641*35238bceSAndroid Build Coastguard Worker CompressedCubeFormatCase::IterateResult CompressedCubeFormatCase::iterate(void)
642*35238bceSAndroid Build Coastguard Worker {
643*35238bceSAndroid Build Coastguard Worker     // Execute test for all faces.
644*35238bceSAndroid Build Coastguard Worker     if (!testFace((tcu::CubeFace)m_curFace))
645*35238bceSAndroid Build Coastguard Worker         m_isOk = false;
646*35238bceSAndroid Build Coastguard Worker 
647*35238bceSAndroid Build Coastguard Worker     m_curFace += 1;
648*35238bceSAndroid Build Coastguard Worker 
649*35238bceSAndroid Build Coastguard Worker     if (m_curFace == tcu::CUBEFACE_LAST)
650*35238bceSAndroid Build Coastguard Worker     {
651*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(m_isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL,
652*35238bceSAndroid Build Coastguard Worker                                 m_isOk ? "Pass" : "Image comparison failed");
653*35238bceSAndroid Build Coastguard Worker         return STOP;
654*35238bceSAndroid Build Coastguard Worker     }
655*35238bceSAndroid Build Coastguard Worker     else
656*35238bceSAndroid Build Coastguard Worker         return CONTINUE;
657*35238bceSAndroid Build Coastguard Worker }
658*35238bceSAndroid Build Coastguard Worker 
toStringVector(const char * const * str,int numStr)659*35238bceSAndroid Build Coastguard Worker vector<string> toStringVector(const char *const *str, int numStr)
660*35238bceSAndroid Build Coastguard Worker {
661*35238bceSAndroid Build Coastguard Worker     vector<string> v;
662*35238bceSAndroid Build Coastguard Worker     v.resize(numStr);
663*35238bceSAndroid Build Coastguard Worker     for (int i = 0; i < numStr; i++)
664*35238bceSAndroid Build Coastguard Worker         v[i] = str[i];
665*35238bceSAndroid Build Coastguard Worker     return v;
666*35238bceSAndroid Build Coastguard Worker }
667*35238bceSAndroid Build Coastguard Worker 
init(void)668*35238bceSAndroid Build Coastguard Worker void TextureFormatTests::init(void)
669*35238bceSAndroid Build Coastguard Worker {
670*35238bceSAndroid Build Coastguard Worker     struct
671*35238bceSAndroid Build Coastguard Worker     {
672*35238bceSAndroid Build Coastguard Worker         const char *name;
673*35238bceSAndroid Build Coastguard Worker         uint32_t format;
674*35238bceSAndroid Build Coastguard Worker         uint32_t dataType;
675*35238bceSAndroid Build Coastguard Worker     } texFormats[] = {{"a8", GL_ALPHA, GL_UNSIGNED_BYTE},
676*35238bceSAndroid Build Coastguard Worker                       {"l8", GL_LUMINANCE, GL_UNSIGNED_BYTE},
677*35238bceSAndroid Build Coastguard Worker                       {"la88", GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE},
678*35238bceSAndroid Build Coastguard Worker                       {"rgb565", GL_RGB, GL_UNSIGNED_SHORT_5_6_5},
679*35238bceSAndroid Build Coastguard Worker                       {"rgb888", GL_RGB, GL_UNSIGNED_BYTE},
680*35238bceSAndroid Build Coastguard Worker                       {"rgba4444", GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4},
681*35238bceSAndroid Build Coastguard Worker                       {"rgba5551", GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1},
682*35238bceSAndroid Build Coastguard Worker                       {"rgba8888", GL_RGBA, GL_UNSIGNED_BYTE}};
683*35238bceSAndroid Build Coastguard Worker 
684*35238bceSAndroid Build Coastguard Worker     for (int formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(texFormats); formatNdx++)
685*35238bceSAndroid Build Coastguard Worker     {
686*35238bceSAndroid Build Coastguard Worker         uint32_t format        = texFormats[formatNdx].format;
687*35238bceSAndroid Build Coastguard Worker         uint32_t dataType      = texFormats[formatNdx].dataType;
688*35238bceSAndroid Build Coastguard Worker         string nameBase        = texFormats[formatNdx].name;
689*35238bceSAndroid Build Coastguard Worker         string descriptionBase = string(glu::getTextureFormatName(format)) + ", " + glu::getTypeName(dataType);
690*35238bceSAndroid Build Coastguard Worker 
691*35238bceSAndroid Build Coastguard Worker         addChild(new Texture2DFormatCase(m_testCtx, m_context.getRenderContext(), (nameBase + "_2d_pot").c_str(),
692*35238bceSAndroid Build Coastguard Worker                                          (descriptionBase + ", GL_TEXTURE_2D").c_str(), format, dataType, 128, 128));
693*35238bceSAndroid Build Coastguard Worker         addChild(new Texture2DFormatCase(m_testCtx, m_context.getRenderContext(), (nameBase + "_2d_npot").c_str(),
694*35238bceSAndroid Build Coastguard Worker                                          (descriptionBase + ", GL_TEXTURE_2D").c_str(), format, dataType, 63, 112));
695*35238bceSAndroid Build Coastguard Worker         addChild(new TextureCubeFormatCase(m_testCtx, m_context.getRenderContext(), (nameBase + "_cube_pot").c_str(),
696*35238bceSAndroid Build Coastguard Worker                                            (descriptionBase + ", GL_TEXTURE_CUBE_MAP").c_str(), format, dataType, 64,
697*35238bceSAndroid Build Coastguard Worker                                            64));
698*35238bceSAndroid Build Coastguard Worker         addChild(new TextureCubeFormatCase(m_testCtx, m_context.getRenderContext(), (nameBase + "_cube_npot").c_str(),
699*35238bceSAndroid Build Coastguard Worker                                            (descriptionBase + ", GL_TEXTURE_CUBE_MAP").c_str(), format, dataType, 57,
700*35238bceSAndroid Build Coastguard Worker                                            57));
701*35238bceSAndroid Build Coastguard Worker     }
702*35238bceSAndroid Build Coastguard Worker 
703*35238bceSAndroid Build Coastguard Worker     // ETC-1 compressed formats.
704*35238bceSAndroid Build Coastguard Worker     {
705*35238bceSAndroid Build Coastguard Worker         static const char *filenames[] = {"data/etc1/photo_helsinki_mip_0.pkm", "data/etc1/photo_helsinki_mip_1.pkm",
706*35238bceSAndroid Build Coastguard Worker                                           "data/etc1/photo_helsinki_mip_2.pkm", "data/etc1/photo_helsinki_mip_3.pkm",
707*35238bceSAndroid Build Coastguard Worker                                           "data/etc1/photo_helsinki_mip_4.pkm", "data/etc1/photo_helsinki_mip_5.pkm",
708*35238bceSAndroid Build Coastguard Worker                                           "data/etc1/photo_helsinki_mip_6.pkm", "data/etc1/photo_helsinki_mip_7.pkm"};
709*35238bceSAndroid Build Coastguard Worker         addChild(new Compressed2DFormatCase(m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(),
710*35238bceSAndroid Build Coastguard Worker                                             "etc1_2d_pot", "GL_ETC1_RGB8_OES, GL_TEXTURE_2D",
711*35238bceSAndroid Build Coastguard Worker                                             toStringVector(filenames, DE_LENGTH_OF_ARRAY(filenames))));
712*35238bceSAndroid Build Coastguard Worker     }
713*35238bceSAndroid Build Coastguard Worker 
714*35238bceSAndroid Build Coastguard Worker     {
715*35238bceSAndroid Build Coastguard Worker         vector<string> filenames;
716*35238bceSAndroid Build Coastguard Worker         filenames.push_back("data/etc1/photo_helsinki_113x89.pkm");
717*35238bceSAndroid Build Coastguard Worker         addChild(new Compressed2DFormatCase(m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(),
718*35238bceSAndroid Build Coastguard Worker                                             "etc1_2d_npot", "GL_ETC1_RGB8_OES, GL_TEXTURE_2D", filenames));
719*35238bceSAndroid Build Coastguard Worker     }
720*35238bceSAndroid Build Coastguard Worker 
721*35238bceSAndroid Build Coastguard Worker     {
722*35238bceSAndroid Build Coastguard Worker         static const char *faceExt[] = {"neg_x", "pos_x", "neg_y", "pos_y", "neg_z", "pos_z"};
723*35238bceSAndroid Build Coastguard Worker 
724*35238bceSAndroid Build Coastguard Worker         const int potNumLevels = 7;
725*35238bceSAndroid Build Coastguard Worker         vector<string> potFilenames;
726*35238bceSAndroid Build Coastguard Worker         for (int level = 0; level < potNumLevels; level++)
727*35238bceSAndroid Build Coastguard Worker             for (int face = 0; face < tcu::CUBEFACE_LAST; face++)
728*35238bceSAndroid Build Coastguard Worker                 potFilenames.push_back(string("data/etc1/skybox_") + faceExt[face] + "_mip_" + de::toString(level) +
729*35238bceSAndroid Build Coastguard Worker                                        ".pkm");
730*35238bceSAndroid Build Coastguard Worker 
731*35238bceSAndroid Build Coastguard Worker         addChild(new CompressedCubeFormatCase(m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(),
732*35238bceSAndroid Build Coastguard Worker                                               "etc1_cube_pot", "GL_ETC1_RGB8_OES, GL_TEXTURE_CUBE_MAP", potFilenames));
733*35238bceSAndroid Build Coastguard Worker 
734*35238bceSAndroid Build Coastguard Worker         vector<string> npotFilenames;
735*35238bceSAndroid Build Coastguard Worker         for (int face = 0; face < tcu::CUBEFACE_LAST; face++)
736*35238bceSAndroid Build Coastguard Worker             npotFilenames.push_back(string("data/etc1/skybox_61x61_") + faceExt[face] + ".pkm");
737*35238bceSAndroid Build Coastguard Worker 
738*35238bceSAndroid Build Coastguard Worker         addChild(new CompressedCubeFormatCase(m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(),
739*35238bceSAndroid Build Coastguard Worker                                               "etc1_cube_npot", "GL_ETC_RGB8_OES, GL_TEXTURE_CUBE_MAP", npotFilenames));
740*35238bceSAndroid Build Coastguard Worker     }
741*35238bceSAndroid Build Coastguard Worker }
742*35238bceSAndroid Build Coastguard Worker 
743*35238bceSAndroid Build Coastguard Worker } // namespace Functional
744*35238bceSAndroid Build Coastguard Worker } // namespace gles2
745*35238bceSAndroid Build Coastguard Worker } // namespace deqp
746