xref: /aosp_15_r20/external/deqp/modules/gles2/accuracy/es2aTextureMipmapTests.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 Mipmapping accuracy tests.
22*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker 
24*35238bceSAndroid Build Coastguard Worker #include "es2aTextureMipmapTests.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "glsTextureTestUtil.hpp"
26*35238bceSAndroid Build Coastguard Worker #include "gluTexture.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "gluStrUtil.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "gluTextureUtil.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "gluPixelTransfer.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
31*35238bceSAndroid Build Coastguard Worker #include "tcuTextureUtil.hpp"
32*35238bceSAndroid Build Coastguard Worker #include "tcuTexVerifierUtil.hpp"
33*35238bceSAndroid Build Coastguard Worker #include "tcuVector.hpp"
34*35238bceSAndroid Build Coastguard Worker #include "tcuMatrix.hpp"
35*35238bceSAndroid Build Coastguard Worker #include "tcuMatrixUtil.hpp"
36*35238bceSAndroid Build Coastguard Worker #include "deStringUtil.hpp"
37*35238bceSAndroid Build Coastguard Worker #include "deRandom.hpp"
38*35238bceSAndroid Build Coastguard Worker 
39*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
40*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
41*35238bceSAndroid Build Coastguard Worker 
42*35238bceSAndroid Build Coastguard Worker namespace deqp
43*35238bceSAndroid Build Coastguard Worker {
44*35238bceSAndroid Build Coastguard Worker namespace gles2
45*35238bceSAndroid Build Coastguard Worker {
46*35238bceSAndroid Build Coastguard Worker namespace Accuracy
47*35238bceSAndroid Build Coastguard Worker {
48*35238bceSAndroid Build Coastguard Worker 
49*35238bceSAndroid Build Coastguard Worker using std::string;
50*35238bceSAndroid Build Coastguard Worker using std::vector;
51*35238bceSAndroid Build Coastguard Worker using tcu::IVec2;
52*35238bceSAndroid Build Coastguard Worker using tcu::IVec4;
53*35238bceSAndroid Build Coastguard Worker using tcu::Mat2;
54*35238bceSAndroid Build Coastguard Worker using tcu::Sampler;
55*35238bceSAndroid Build Coastguard Worker using tcu::TestLog;
56*35238bceSAndroid Build Coastguard Worker using tcu::Vec2;
57*35238bceSAndroid Build Coastguard Worker using tcu::Vec4;
58*35238bceSAndroid Build Coastguard Worker using namespace glu;
59*35238bceSAndroid Build Coastguard Worker using namespace gls::TextureTestUtil;
60*35238bceSAndroid Build Coastguard Worker using namespace glu::TextureTestUtil;
61*35238bceSAndroid Build Coastguard Worker 
62*35238bceSAndroid Build Coastguard Worker enum CoordType
63*35238bceSAndroid Build Coastguard Worker {
64*35238bceSAndroid Build Coastguard Worker     COORDTYPE_BASIC,      //!< texCoord = translateScale(position).
65*35238bceSAndroid Build Coastguard Worker     COORDTYPE_BASIC_BIAS, //!< Like basic, but with bias values.
66*35238bceSAndroid Build Coastguard Worker     COORDTYPE_AFFINE,     //!< texCoord = translateScaleRotateShear(position).
67*35238bceSAndroid Build Coastguard Worker     COORDTYPE_PROJECTED,  //!< Projected coordinates, w != 1
68*35238bceSAndroid Build Coastguard Worker 
69*35238bceSAndroid Build Coastguard Worker     COORDTYPE_LAST
70*35238bceSAndroid Build Coastguard Worker };
71*35238bceSAndroid Build Coastguard Worker 
72*35238bceSAndroid Build Coastguard Worker // Texture2DMipmapCase
73*35238bceSAndroid Build Coastguard Worker 
74*35238bceSAndroid Build Coastguard Worker class Texture2DMipmapCase : public tcu::TestCase
75*35238bceSAndroid Build Coastguard Worker {
76*35238bceSAndroid Build Coastguard Worker public:
77*35238bceSAndroid Build Coastguard Worker     Texture2DMipmapCase(tcu::TestContext &testCtx, glu::RenderContext &renderCtx, const glu::ContextInfo &renderCtxInfo,
78*35238bceSAndroid Build Coastguard Worker                         const char *name, const char *desc, CoordType coordType, uint32_t minFilter, uint32_t wrapS,
79*35238bceSAndroid Build Coastguard Worker                         uint32_t wrapT, uint32_t format, uint32_t dataType, int width, int height);
80*35238bceSAndroid Build Coastguard Worker     ~Texture2DMipmapCase(void);
81*35238bceSAndroid Build Coastguard Worker 
82*35238bceSAndroid Build Coastguard Worker     void init(void);
83*35238bceSAndroid Build Coastguard Worker     void deinit(void);
84*35238bceSAndroid Build Coastguard Worker     IterateResult iterate(void);
85*35238bceSAndroid Build Coastguard Worker 
86*35238bceSAndroid Build Coastguard Worker private:
87*35238bceSAndroid Build Coastguard Worker     Texture2DMipmapCase(const Texture2DMipmapCase &other);
88*35238bceSAndroid Build Coastguard Worker     Texture2DMipmapCase &operator=(const Texture2DMipmapCase &other);
89*35238bceSAndroid Build Coastguard Worker 
90*35238bceSAndroid Build Coastguard Worker     glu::RenderContext &m_renderCtx;
91*35238bceSAndroid Build Coastguard Worker     const glu::ContextInfo &m_renderCtxInfo;
92*35238bceSAndroid Build Coastguard Worker 
93*35238bceSAndroid Build Coastguard Worker     CoordType m_coordType;
94*35238bceSAndroid Build Coastguard Worker     uint32_t m_minFilter;
95*35238bceSAndroid Build Coastguard Worker     uint32_t m_wrapS;
96*35238bceSAndroid Build Coastguard Worker     uint32_t m_wrapT;
97*35238bceSAndroid Build Coastguard Worker     uint32_t m_format;
98*35238bceSAndroid Build Coastguard Worker     uint32_t m_dataType;
99*35238bceSAndroid Build Coastguard Worker     int m_width;
100*35238bceSAndroid Build Coastguard Worker     int m_height;
101*35238bceSAndroid Build Coastguard Worker 
102*35238bceSAndroid Build Coastguard Worker     glu::Texture2D *m_texture;
103*35238bceSAndroid Build Coastguard Worker     TextureRenderer m_renderer;
104*35238bceSAndroid Build Coastguard Worker };
105*35238bceSAndroid Build Coastguard Worker 
Texture2DMipmapCase(tcu::TestContext & testCtx,glu::RenderContext & renderCtx,const glu::ContextInfo & renderCtxInfo,const char * name,const char * desc,CoordType coordType,uint32_t minFilter,uint32_t wrapS,uint32_t wrapT,uint32_t format,uint32_t dataType,int width,int height)106*35238bceSAndroid Build Coastguard Worker Texture2DMipmapCase::Texture2DMipmapCase(tcu::TestContext &testCtx, glu::RenderContext &renderCtx,
107*35238bceSAndroid Build Coastguard Worker                                          const glu::ContextInfo &renderCtxInfo, const char *name, const char *desc,
108*35238bceSAndroid Build Coastguard Worker                                          CoordType coordType, uint32_t minFilter, uint32_t wrapS, uint32_t wrapT,
109*35238bceSAndroid Build Coastguard Worker                                          uint32_t format, uint32_t dataType, int width, int height)
110*35238bceSAndroid Build Coastguard Worker     : TestCase(testCtx, tcu::NODETYPE_ACCURACY, name, desc)
111*35238bceSAndroid Build Coastguard Worker     , m_renderCtx(renderCtx)
112*35238bceSAndroid Build Coastguard Worker     , m_renderCtxInfo(renderCtxInfo)
113*35238bceSAndroid Build Coastguard Worker     , m_coordType(coordType)
114*35238bceSAndroid Build Coastguard Worker     , m_minFilter(minFilter)
115*35238bceSAndroid Build Coastguard Worker     , m_wrapS(wrapS)
116*35238bceSAndroid Build Coastguard Worker     , m_wrapT(wrapT)
117*35238bceSAndroid Build Coastguard Worker     , m_format(format)
118*35238bceSAndroid Build Coastguard Worker     , m_dataType(dataType)
119*35238bceSAndroid Build Coastguard Worker     , m_width(width)
120*35238bceSAndroid Build Coastguard Worker     , m_height(height)
121*35238bceSAndroid Build Coastguard Worker     , m_texture(DE_NULL)
122*35238bceSAndroid Build Coastguard Worker     , m_renderer(renderCtx, testCtx.getLog(), glu::GLSL_VERSION_100_ES,
123*35238bceSAndroid Build Coastguard Worker                  renderCtxInfo.isFragmentHighPrecisionSupported() ? glu::PRECISION_HIGHP // Use highp if available.
124*35238bceSAndroid Build Coastguard Worker                                                                     :
125*35238bceSAndroid Build Coastguard Worker                                                                     glu::PRECISION_MEDIUMP)
126*35238bceSAndroid Build Coastguard Worker {
127*35238bceSAndroid Build Coastguard Worker }
128*35238bceSAndroid Build Coastguard Worker 
~Texture2DMipmapCase(void)129*35238bceSAndroid Build Coastguard Worker Texture2DMipmapCase::~Texture2DMipmapCase(void)
130*35238bceSAndroid Build Coastguard Worker {
131*35238bceSAndroid Build Coastguard Worker     deinit();
132*35238bceSAndroid Build Coastguard Worker }
133*35238bceSAndroid Build Coastguard Worker 
init(void)134*35238bceSAndroid Build Coastguard Worker void Texture2DMipmapCase::init(void)
135*35238bceSAndroid Build Coastguard Worker {
136*35238bceSAndroid Build Coastguard Worker     if (!m_renderCtxInfo.isFragmentHighPrecisionSupported())
137*35238bceSAndroid Build Coastguard Worker         m_testCtx.getLog() << TestLog::Message << "Warning: High precision not supported in fragment shaders."
138*35238bceSAndroid Build Coastguard Worker                            << TestLog::EndMessage;
139*35238bceSAndroid Build Coastguard Worker 
140*35238bceSAndroid Build Coastguard Worker     m_texture = new Texture2D(m_renderCtx, m_format, m_dataType, m_width, m_height);
141*35238bceSAndroid Build Coastguard Worker 
142*35238bceSAndroid Build Coastguard Worker     int numLevels = deLog2Floor32(de::max(m_width, m_height)) + 1;
143*35238bceSAndroid Build Coastguard Worker 
144*35238bceSAndroid Build Coastguard Worker     // Fill texture with colored grid.
145*35238bceSAndroid Build Coastguard Worker     for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
146*35238bceSAndroid Build Coastguard Worker     {
147*35238bceSAndroid Build Coastguard Worker         uint32_t step  = 0xff / (numLevels - 1);
148*35238bceSAndroid Build Coastguard Worker         uint32_t inc   = deClamp32(step * levelNdx, 0x00, 0xff);
149*35238bceSAndroid Build Coastguard Worker         uint32_t dec   = 0xff - inc;
150*35238bceSAndroid Build Coastguard Worker         uint32_t rgb   = (inc << 16) | (dec << 8) | 0xff;
151*35238bceSAndroid Build Coastguard Worker         uint32_t color = 0xff000000 | rgb;
152*35238bceSAndroid Build Coastguard Worker 
153*35238bceSAndroid Build Coastguard Worker         m_texture->getRefTexture().allocLevel(levelNdx);
154*35238bceSAndroid Build Coastguard Worker         tcu::clear(m_texture->getRefTexture().getLevel(levelNdx), tcu::RGBA(color).toVec());
155*35238bceSAndroid Build Coastguard Worker     }
156*35238bceSAndroid Build Coastguard Worker }
157*35238bceSAndroid Build Coastguard Worker 
deinit(void)158*35238bceSAndroid Build Coastguard Worker void Texture2DMipmapCase::deinit(void)
159*35238bceSAndroid Build Coastguard Worker {
160*35238bceSAndroid Build Coastguard Worker     delete m_texture;
161*35238bceSAndroid Build Coastguard Worker     m_texture = DE_NULL;
162*35238bceSAndroid Build Coastguard Worker 
163*35238bceSAndroid Build Coastguard Worker     m_renderer.clear();
164*35238bceSAndroid Build Coastguard Worker }
165*35238bceSAndroid Build Coastguard Worker 
getBasicTexCoord2D(std::vector<float> & dst,int cellNdx)166*35238bceSAndroid Build Coastguard Worker static void getBasicTexCoord2D(std::vector<float> &dst, int cellNdx)
167*35238bceSAndroid Build Coastguard Worker {
168*35238bceSAndroid Build Coastguard Worker     static const struct
169*35238bceSAndroid Build Coastguard Worker     {
170*35238bceSAndroid Build Coastguard Worker         Vec2 bottomLeft;
171*35238bceSAndroid Build Coastguard Worker         Vec2 topRight;
172*35238bceSAndroid Build Coastguard Worker     } s_basicCoords[] = {
173*35238bceSAndroid Build Coastguard Worker         {Vec2(-0.1f, 0.1f), Vec2(0.8f, 1.0f)},     {Vec2(-0.3f, -0.6f), Vec2(0.7f, 0.4f)},
174*35238bceSAndroid Build Coastguard Worker         {Vec2(-0.3f, 0.6f), Vec2(0.7f, -0.9f)},    {Vec2(-0.8f, 0.6f), Vec2(0.7f, -0.9f)},
175*35238bceSAndroid Build Coastguard Worker 
176*35238bceSAndroid Build Coastguard Worker         {Vec2(-0.5f, -0.5f), Vec2(1.5f, 1.5f)},    {Vec2(1.0f, -1.0f), Vec2(-1.3f, 1.0f)},
177*35238bceSAndroid Build Coastguard Worker         {Vec2(1.2f, -1.0f), Vec2(-1.3f, 1.6f)},    {Vec2(2.2f, -1.1f), Vec2(-1.3f, 0.8f)},
178*35238bceSAndroid Build Coastguard Worker 
179*35238bceSAndroid Build Coastguard Worker         {Vec2(-1.5f, 1.6f), Vec2(1.7f, -1.4f)},    {Vec2(2.0f, 1.6f), Vec2(2.3f, -1.4f)},
180*35238bceSAndroid Build Coastguard Worker         {Vec2(1.3f, -2.6f), Vec2(-2.7f, 2.9f)},    {Vec2(-0.8f, -6.6f), Vec2(6.0f, -0.9f)},
181*35238bceSAndroid Build Coastguard Worker 
182*35238bceSAndroid Build Coastguard Worker         {Vec2(-8.0f, 9.0f), Vec2(8.3f, -7.0f)},    {Vec2(-16.0f, 10.0f), Vec2(18.3f, 24.0f)},
183*35238bceSAndroid Build Coastguard Worker         {Vec2(30.2f, 55.0f), Vec2(-24.3f, -1.6f)}, {Vec2(-33.2f, 64.1f), Vec2(32.1f, -64.1f)},
184*35238bceSAndroid Build Coastguard Worker     };
185*35238bceSAndroid Build Coastguard Worker 
186*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(de::inBounds(cellNdx, 0, DE_LENGTH_OF_ARRAY(s_basicCoords)));
187*35238bceSAndroid Build Coastguard Worker 
188*35238bceSAndroid Build Coastguard Worker     const Vec2 &bottomLeft = s_basicCoords[cellNdx].bottomLeft;
189*35238bceSAndroid Build Coastguard Worker     const Vec2 &topRight   = s_basicCoords[cellNdx].topRight;
190*35238bceSAndroid Build Coastguard Worker 
191*35238bceSAndroid Build Coastguard Worker     computeQuadTexCoord2D(dst, bottomLeft, topRight);
192*35238bceSAndroid Build Coastguard Worker }
193*35238bceSAndroid Build Coastguard Worker 
getAffineTexCoord2D(std::vector<float> & dst,int cellNdx)194*35238bceSAndroid Build Coastguard Worker static void getAffineTexCoord2D(std::vector<float> &dst, int cellNdx)
195*35238bceSAndroid Build Coastguard Worker {
196*35238bceSAndroid Build Coastguard Worker     // Use basic coords as base.
197*35238bceSAndroid Build Coastguard Worker     getBasicTexCoord2D(dst, cellNdx);
198*35238bceSAndroid Build Coastguard Worker 
199*35238bceSAndroid Build Coastguard Worker     // Rotate based on cell index.
200*35238bceSAndroid Build Coastguard Worker     float angle         = 2.0f * DE_PI * ((float)cellNdx / 16.0f);
201*35238bceSAndroid Build Coastguard Worker     tcu::Mat2 rotMatrix = tcu::rotationMatrix(angle);
202*35238bceSAndroid Build Coastguard Worker 
203*35238bceSAndroid Build Coastguard Worker     // Second and third row are sheared.
204*35238bceSAndroid Build Coastguard Worker     float shearX          = de::inRange(cellNdx, 4, 11) ? (float)(15 - cellNdx) / 16.0f : 0.0f;
205*35238bceSAndroid Build Coastguard Worker     tcu::Mat2 shearMatrix = tcu::shearMatrix(tcu::Vec2(shearX, 0.0f));
206*35238bceSAndroid Build Coastguard Worker 
207*35238bceSAndroid Build Coastguard Worker     tcu::Mat2 transform = rotMatrix * shearMatrix;
208*35238bceSAndroid Build Coastguard Worker     Vec2 p0             = transform * Vec2(dst[0], dst[1]);
209*35238bceSAndroid Build Coastguard Worker     Vec2 p1             = transform * Vec2(dst[2], dst[3]);
210*35238bceSAndroid Build Coastguard Worker     Vec2 p2             = transform * Vec2(dst[4], dst[5]);
211*35238bceSAndroid Build Coastguard Worker     Vec2 p3             = transform * Vec2(dst[6], dst[7]);
212*35238bceSAndroid Build Coastguard Worker 
213*35238bceSAndroid Build Coastguard Worker     dst[0] = p0.x();
214*35238bceSAndroid Build Coastguard Worker     dst[1] = p0.y();
215*35238bceSAndroid Build Coastguard Worker     dst[2] = p1.x();
216*35238bceSAndroid Build Coastguard Worker     dst[3] = p1.y();
217*35238bceSAndroid Build Coastguard Worker     dst[4] = p2.x();
218*35238bceSAndroid Build Coastguard Worker     dst[5] = p2.y();
219*35238bceSAndroid Build Coastguard Worker     dst[6] = p3.x();
220*35238bceSAndroid Build Coastguard Worker     dst[7] = p3.y();
221*35238bceSAndroid Build Coastguard Worker }
222*35238bceSAndroid Build Coastguard Worker 
iterate(void)223*35238bceSAndroid Build Coastguard Worker Texture2DMipmapCase::IterateResult Texture2DMipmapCase::iterate(void)
224*35238bceSAndroid Build Coastguard Worker {
225*35238bceSAndroid Build Coastguard Worker     // Constants.
226*35238bceSAndroid Build Coastguard Worker     const uint32_t magFilter = GL_NEAREST;
227*35238bceSAndroid Build Coastguard Worker 
228*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_renderCtx.getFunctions();
229*35238bceSAndroid Build Coastguard Worker     TestLog &log             = m_testCtx.getLog();
230*35238bceSAndroid Build Coastguard Worker 
231*35238bceSAndroid Build Coastguard Worker     const tcu::Texture2D &refTexture = m_texture->getRefTexture();
232*35238bceSAndroid Build Coastguard Worker     const tcu::TextureFormat &texFmt = refTexture.getFormat();
233*35238bceSAndroid Build Coastguard Worker     tcu::TextureFormatInfo fmtInfo   = tcu::getTextureFormatInfo(texFmt);
234*35238bceSAndroid Build Coastguard Worker 
235*35238bceSAndroid Build Coastguard Worker     int texWidth          = refTexture.getWidth();
236*35238bceSAndroid Build Coastguard Worker     int texHeight         = refTexture.getHeight();
237*35238bceSAndroid Build Coastguard Worker     int defViewportWidth  = texWidth * 4;
238*35238bceSAndroid Build Coastguard Worker     int defViewportHeight = texHeight * 4;
239*35238bceSAndroid Build Coastguard Worker 
240*35238bceSAndroid Build Coastguard Worker     RandomViewport viewport(m_renderCtx.getRenderTarget(), defViewportWidth, defViewportHeight,
241*35238bceSAndroid Build Coastguard Worker                             deStringHash(getName()));
242*35238bceSAndroid Build Coastguard Worker     ReferenceParams sampleParams(TEXTURETYPE_2D);
243*35238bceSAndroid Build Coastguard Worker     vector<float> texCoord;
244*35238bceSAndroid Build Coastguard Worker     bool isProjected = m_coordType == COORDTYPE_PROJECTED;
245*35238bceSAndroid Build Coastguard Worker     bool useLodBias  = m_coordType == COORDTYPE_BASIC_BIAS;
246*35238bceSAndroid Build Coastguard Worker 
247*35238bceSAndroid Build Coastguard Worker     tcu::Surface renderedFrame(viewport.width, viewport.height);
248*35238bceSAndroid Build Coastguard Worker 
249*35238bceSAndroid Build Coastguard Worker     // Accuracy cases test against ideal lod computation.
250*35238bceSAndroid Build Coastguard Worker     tcu::Surface idealFrame(viewport.width, viewport.height);
251*35238bceSAndroid Build Coastguard Worker 
252*35238bceSAndroid Build Coastguard Worker     // Viewport is divided into 4x4 grid.
253*35238bceSAndroid Build Coastguard Worker     int gridWidth  = 4;
254*35238bceSAndroid Build Coastguard Worker     int gridHeight = 4;
255*35238bceSAndroid Build Coastguard Worker     int cellWidth  = viewport.width / gridWidth;
256*35238bceSAndroid Build Coastguard Worker     int cellHeight = viewport.height / gridHeight;
257*35238bceSAndroid Build Coastguard Worker 
258*35238bceSAndroid Build Coastguard Worker     // Accuracy measurements are off unless we get the expected viewport size.
259*35238bceSAndroid Build Coastguard Worker     if (viewport.width < defViewportWidth || viewport.height < defViewportHeight)
260*35238bceSAndroid Build Coastguard Worker         throw tcu::NotSupportedError("Too small viewport", "", __FILE__, __LINE__);
261*35238bceSAndroid Build Coastguard Worker 
262*35238bceSAndroid Build Coastguard Worker     // Sampling parameters.
263*35238bceSAndroid Build Coastguard Worker     sampleParams.sampler     = glu::mapGLSampler(m_wrapS, m_wrapT, m_minFilter, magFilter);
264*35238bceSAndroid Build Coastguard Worker     sampleParams.samplerType = glu::TextureTestUtil::getSamplerType(m_texture->getRefTexture().getFormat());
265*35238bceSAndroid Build Coastguard Worker     sampleParams.colorBias   = fmtInfo.lookupBias;
266*35238bceSAndroid Build Coastguard Worker     sampleParams.colorScale  = fmtInfo.lookupScale;
267*35238bceSAndroid Build Coastguard Worker     sampleParams.flags = (isProjected ? ReferenceParams::PROJECTED : 0) | (useLodBias ? ReferenceParams::USE_BIAS : 0);
268*35238bceSAndroid Build Coastguard Worker 
269*35238bceSAndroid Build Coastguard Worker     // Upload texture data.
270*35238bceSAndroid Build Coastguard Worker     m_texture->upload();
271*35238bceSAndroid Build Coastguard Worker 
272*35238bceSAndroid Build Coastguard Worker     // Use unit 0.
273*35238bceSAndroid Build Coastguard Worker     gl.activeTexture(GL_TEXTURE0);
274*35238bceSAndroid Build Coastguard Worker 
275*35238bceSAndroid Build Coastguard Worker     // Bind gradient texture and setup sampler parameters.
276*35238bceSAndroid Build Coastguard Worker     gl.bindTexture(GL_TEXTURE_2D, m_texture->getGLTexture());
277*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_wrapS);
278*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_wrapT);
279*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_minFilter);
280*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter);
281*35238bceSAndroid Build Coastguard Worker 
282*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(gl.getError(), "After texture setup");
283*35238bceSAndroid Build Coastguard Worker 
284*35238bceSAndroid Build Coastguard Worker     // Bias values.
285*35238bceSAndroid Build Coastguard Worker     static const float s_bias[] = {1.0f, -2.0f, 0.8f, -0.5f, 1.5f, 0.9f, 2.0f, 4.0f};
286*35238bceSAndroid Build Coastguard Worker 
287*35238bceSAndroid Build Coastguard Worker     // Projection values.
288*35238bceSAndroid Build Coastguard Worker     static const Vec4 s_projections[] = {Vec4(1.2f, 1.0f, 0.7f, 1.0f), Vec4(1.3f, 0.8f, 0.6f, 2.0f),
289*35238bceSAndroid Build Coastguard Worker                                          Vec4(0.8f, 1.0f, 1.7f, 0.6f), Vec4(1.2f, 1.0f, 1.7f, 1.5f)};
290*35238bceSAndroid Build Coastguard Worker 
291*35238bceSAndroid Build Coastguard Worker     // Render cells.
292*35238bceSAndroid Build Coastguard Worker     for (int gridY = 0; gridY < gridHeight; gridY++)
293*35238bceSAndroid Build Coastguard Worker     {
294*35238bceSAndroid Build Coastguard Worker         for (int gridX = 0; gridX < gridWidth; gridX++)
295*35238bceSAndroid Build Coastguard Worker         {
296*35238bceSAndroid Build Coastguard Worker             int curX    = cellWidth * gridX;
297*35238bceSAndroid Build Coastguard Worker             int curY    = cellHeight * gridY;
298*35238bceSAndroid Build Coastguard Worker             int curW    = gridX + 1 == gridWidth ? (viewport.width - curX) : cellWidth;
299*35238bceSAndroid Build Coastguard Worker             int curH    = gridY + 1 == gridHeight ? (viewport.height - curY) : cellHeight;
300*35238bceSAndroid Build Coastguard Worker             int cellNdx = gridY * gridWidth + gridX;
301*35238bceSAndroid Build Coastguard Worker 
302*35238bceSAndroid Build Coastguard Worker             // Compute texcoord.
303*35238bceSAndroid Build Coastguard Worker             switch (m_coordType)
304*35238bceSAndroid Build Coastguard Worker             {
305*35238bceSAndroid Build Coastguard Worker             case COORDTYPE_BASIC_BIAS: // Fall-through.
306*35238bceSAndroid Build Coastguard Worker             case COORDTYPE_PROJECTED:
307*35238bceSAndroid Build Coastguard Worker             case COORDTYPE_BASIC:
308*35238bceSAndroid Build Coastguard Worker                 getBasicTexCoord2D(texCoord, cellNdx);
309*35238bceSAndroid Build Coastguard Worker                 break;
310*35238bceSAndroid Build Coastguard Worker             case COORDTYPE_AFFINE:
311*35238bceSAndroid Build Coastguard Worker                 getAffineTexCoord2D(texCoord, cellNdx);
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             if (isProjected)
318*35238bceSAndroid Build Coastguard Worker                 sampleParams.w = s_projections[cellNdx % DE_LENGTH_OF_ARRAY(s_projections)];
319*35238bceSAndroid Build Coastguard Worker 
320*35238bceSAndroid Build Coastguard Worker             if (useLodBias)
321*35238bceSAndroid Build Coastguard Worker                 sampleParams.bias = s_bias[cellNdx % DE_LENGTH_OF_ARRAY(s_bias)];
322*35238bceSAndroid Build Coastguard Worker 
323*35238bceSAndroid Build Coastguard Worker             // Render with GL.
324*35238bceSAndroid Build Coastguard Worker             gl.viewport(viewport.x + curX, viewport.y + curY, curW, curH);
325*35238bceSAndroid Build Coastguard Worker             m_renderer.renderQuad(0, &texCoord[0], sampleParams);
326*35238bceSAndroid Build Coastguard Worker 
327*35238bceSAndroid Build Coastguard Worker             // Render reference(s).
328*35238bceSAndroid Build Coastguard Worker             {
329*35238bceSAndroid Build Coastguard Worker                 tcu::SurfaceAccess idealDst(idealFrame, m_renderCtx.getRenderTarget().getPixelFormat(), curX, curY,
330*35238bceSAndroid Build Coastguard Worker                                             curW, curH);
331*35238bceSAndroid Build Coastguard Worker                 sampleParams.lodMode = LODMODE_EXACT;
332*35238bceSAndroid Build Coastguard Worker                 sampleTexture(idealDst, m_texture->getRefTexture(), &texCoord[0], sampleParams);
333*35238bceSAndroid Build Coastguard Worker             }
334*35238bceSAndroid Build Coastguard Worker         }
335*35238bceSAndroid Build Coastguard Worker     }
336*35238bceSAndroid Build Coastguard Worker 
337*35238bceSAndroid Build Coastguard Worker     // Read result.
338*35238bceSAndroid Build Coastguard Worker     glu::readPixels(m_renderCtx, viewport.x, viewport.y, renderedFrame.getAccess());
339*35238bceSAndroid Build Coastguard Worker 
340*35238bceSAndroid Build Coastguard Worker     // Compare and log.
341*35238bceSAndroid Build Coastguard Worker     {
342*35238bceSAndroid Build Coastguard Worker         const int bestScoreDiff  = (texWidth / 16) * (texHeight / 16);
343*35238bceSAndroid Build Coastguard Worker         const int worstScoreDiff = texWidth * texHeight;
344*35238bceSAndroid Build Coastguard Worker 
345*35238bceSAndroid Build Coastguard Worker         int score = measureAccuracy(log, idealFrame, renderedFrame, bestScoreDiff, worstScoreDiff);
346*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, de::toString(score).c_str());
347*35238bceSAndroid Build Coastguard Worker     }
348*35238bceSAndroid Build Coastguard Worker 
349*35238bceSAndroid Build Coastguard Worker     return STOP;
350*35238bceSAndroid Build Coastguard Worker }
351*35238bceSAndroid Build Coastguard Worker 
352*35238bceSAndroid Build Coastguard Worker // TextureCubeMipmapCase
353*35238bceSAndroid Build Coastguard Worker 
354*35238bceSAndroid Build Coastguard Worker class TextureCubeMipmapCase : public tcu::TestCase
355*35238bceSAndroid Build Coastguard Worker {
356*35238bceSAndroid Build Coastguard Worker public:
357*35238bceSAndroid Build Coastguard Worker     TextureCubeMipmapCase(tcu::TestContext &testCtx, glu::RenderContext &renderCtx,
358*35238bceSAndroid Build Coastguard Worker                           const glu::ContextInfo &renderCtxInfo, const char *name, const char *desc,
359*35238bceSAndroid Build Coastguard Worker                           CoordType coordType, uint32_t minFilter, uint32_t wrapS, uint32_t wrapT, uint32_t format,
360*35238bceSAndroid Build Coastguard Worker                           uint32_t dataType, int size);
361*35238bceSAndroid Build Coastguard Worker     ~TextureCubeMipmapCase(void);
362*35238bceSAndroid Build Coastguard Worker 
363*35238bceSAndroid Build Coastguard Worker     void init(void);
364*35238bceSAndroid Build Coastguard Worker     void deinit(void);
365*35238bceSAndroid Build Coastguard Worker     IterateResult iterate(void);
366*35238bceSAndroid Build Coastguard Worker 
367*35238bceSAndroid Build Coastguard Worker private:
368*35238bceSAndroid Build Coastguard Worker     TextureCubeMipmapCase(const TextureCubeMipmapCase &other);
369*35238bceSAndroid Build Coastguard Worker     TextureCubeMipmapCase &operator=(const TextureCubeMipmapCase &other);
370*35238bceSAndroid Build Coastguard Worker 
371*35238bceSAndroid Build Coastguard Worker     glu::RenderContext &m_renderCtx;
372*35238bceSAndroid Build Coastguard Worker     const glu::ContextInfo &m_renderCtxInfo;
373*35238bceSAndroid Build Coastguard Worker 
374*35238bceSAndroid Build Coastguard Worker     CoordType m_coordType;
375*35238bceSAndroid Build Coastguard Worker     uint32_t m_minFilter;
376*35238bceSAndroid Build Coastguard Worker     uint32_t m_wrapS;
377*35238bceSAndroid Build Coastguard Worker     uint32_t m_wrapT;
378*35238bceSAndroid Build Coastguard Worker     uint32_t m_format;
379*35238bceSAndroid Build Coastguard Worker     uint32_t m_dataType;
380*35238bceSAndroid Build Coastguard Worker     int m_size;
381*35238bceSAndroid Build Coastguard Worker 
382*35238bceSAndroid Build Coastguard Worker     glu::TextureCube *m_texture;
383*35238bceSAndroid Build Coastguard Worker     TextureRenderer m_renderer;
384*35238bceSAndroid Build Coastguard Worker };
385*35238bceSAndroid Build Coastguard Worker 
TextureCubeMipmapCase(tcu::TestContext & testCtx,glu::RenderContext & renderCtx,const glu::ContextInfo & renderCtxInfo,const char * name,const char * desc,CoordType coordType,uint32_t minFilter,uint32_t wrapS,uint32_t wrapT,uint32_t format,uint32_t dataType,int size)386*35238bceSAndroid Build Coastguard Worker TextureCubeMipmapCase::TextureCubeMipmapCase(tcu::TestContext &testCtx, glu::RenderContext &renderCtx,
387*35238bceSAndroid Build Coastguard Worker                                              const glu::ContextInfo &renderCtxInfo, const char *name, const char *desc,
388*35238bceSAndroid Build Coastguard Worker                                              CoordType coordType, uint32_t minFilter, uint32_t wrapS, uint32_t wrapT,
389*35238bceSAndroid Build Coastguard Worker                                              uint32_t format, uint32_t dataType, int size)
390*35238bceSAndroid Build Coastguard Worker     : TestCase(testCtx, tcu::NODETYPE_ACCURACY, name, desc)
391*35238bceSAndroid Build Coastguard Worker     , m_renderCtx(renderCtx)
392*35238bceSAndroid Build Coastguard Worker     , m_renderCtxInfo(renderCtxInfo)
393*35238bceSAndroid Build Coastguard Worker     , m_coordType(coordType)
394*35238bceSAndroid Build Coastguard Worker     , m_minFilter(minFilter)
395*35238bceSAndroid Build Coastguard Worker     , m_wrapS(wrapS)
396*35238bceSAndroid Build Coastguard Worker     , m_wrapT(wrapT)
397*35238bceSAndroid Build Coastguard Worker     , m_format(format)
398*35238bceSAndroid Build Coastguard Worker     , m_dataType(dataType)
399*35238bceSAndroid Build Coastguard Worker     , m_size(size)
400*35238bceSAndroid Build Coastguard Worker     , m_texture(DE_NULL)
401*35238bceSAndroid Build Coastguard Worker     , m_renderer(renderCtx, testCtx.getLog(), glu::GLSL_VERSION_100_ES,
402*35238bceSAndroid Build Coastguard Worker                  renderCtxInfo.isFragmentHighPrecisionSupported() ? glu::PRECISION_HIGHP // Use highp if available.
403*35238bceSAndroid Build Coastguard Worker                                                                     :
404*35238bceSAndroid Build Coastguard Worker                                                                     glu::PRECISION_MEDIUMP)
405*35238bceSAndroid Build Coastguard Worker {
406*35238bceSAndroid Build Coastguard Worker }
407*35238bceSAndroid Build Coastguard Worker 
~TextureCubeMipmapCase(void)408*35238bceSAndroid Build Coastguard Worker TextureCubeMipmapCase::~TextureCubeMipmapCase(void)
409*35238bceSAndroid Build Coastguard Worker {
410*35238bceSAndroid Build Coastguard Worker     deinit();
411*35238bceSAndroid Build Coastguard Worker }
412*35238bceSAndroid Build Coastguard Worker 
init(void)413*35238bceSAndroid Build Coastguard Worker void TextureCubeMipmapCase::init(void)
414*35238bceSAndroid Build Coastguard Worker {
415*35238bceSAndroid Build Coastguard Worker     if (!m_renderCtxInfo.isFragmentHighPrecisionSupported())
416*35238bceSAndroid Build Coastguard Worker         m_testCtx.getLog() << TestLog::Message << "Warning: High precision not supported in fragment shaders."
417*35238bceSAndroid Build Coastguard Worker                            << TestLog::EndMessage;
418*35238bceSAndroid Build Coastguard Worker 
419*35238bceSAndroid Build Coastguard Worker     m_texture = new TextureCube(m_renderCtx, m_format, m_dataType, m_size);
420*35238bceSAndroid Build Coastguard Worker 
421*35238bceSAndroid Build Coastguard Worker     int numLevels = deLog2Floor32(m_size) + 1;
422*35238bceSAndroid Build Coastguard Worker 
423*35238bceSAndroid Build Coastguard Worker     // Fill texture with colored grid.
424*35238bceSAndroid Build Coastguard Worker     for (int faceNdx = 0; faceNdx < tcu::CUBEFACE_LAST; faceNdx++)
425*35238bceSAndroid Build Coastguard Worker     {
426*35238bceSAndroid Build Coastguard Worker         for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
427*35238bceSAndroid Build Coastguard Worker         {
428*35238bceSAndroid Build Coastguard Worker             uint32_t step = 0xff / (numLevels - 1);
429*35238bceSAndroid Build Coastguard Worker             uint32_t inc  = deClamp32(step * levelNdx, 0x00, 0xff);
430*35238bceSAndroid Build Coastguard Worker             uint32_t dec  = 0xff - inc;
431*35238bceSAndroid Build Coastguard Worker             uint32_t rgb  = 0;
432*35238bceSAndroid Build Coastguard Worker 
433*35238bceSAndroid Build Coastguard Worker             switch (faceNdx)
434*35238bceSAndroid Build Coastguard Worker             {
435*35238bceSAndroid Build Coastguard Worker             case 0:
436*35238bceSAndroid Build Coastguard Worker                 rgb = (inc << 16) | (dec << 8) | 255;
437*35238bceSAndroid Build Coastguard Worker                 break;
438*35238bceSAndroid Build Coastguard Worker             case 1:
439*35238bceSAndroid Build Coastguard Worker                 rgb = (255 << 16) | (inc << 8) | dec;
440*35238bceSAndroid Build Coastguard Worker                 break;
441*35238bceSAndroid Build Coastguard Worker             case 2:
442*35238bceSAndroid Build Coastguard Worker                 rgb = (dec << 16) | (255 << 8) | inc;
443*35238bceSAndroid Build Coastguard Worker                 break;
444*35238bceSAndroid Build Coastguard Worker             case 3:
445*35238bceSAndroid Build Coastguard Worker                 rgb = (dec << 16) | (inc << 8) | 255;
446*35238bceSAndroid Build Coastguard Worker                 break;
447*35238bceSAndroid Build Coastguard Worker             case 4:
448*35238bceSAndroid Build Coastguard Worker                 rgb = (255 << 16) | (dec << 8) | inc;
449*35238bceSAndroid Build Coastguard Worker                 break;
450*35238bceSAndroid Build Coastguard Worker             case 5:
451*35238bceSAndroid Build Coastguard Worker                 rgb = (inc << 16) | (255 << 8) | dec;
452*35238bceSAndroid Build Coastguard Worker                 break;
453*35238bceSAndroid Build Coastguard Worker             }
454*35238bceSAndroid Build Coastguard Worker 
455*35238bceSAndroid Build Coastguard Worker             uint32_t color = 0xff000000 | rgb;
456*35238bceSAndroid Build Coastguard Worker 
457*35238bceSAndroid Build Coastguard Worker             m_texture->getRefTexture().allocLevel((tcu::CubeFace)faceNdx, levelNdx);
458*35238bceSAndroid Build Coastguard Worker             tcu::clear(m_texture->getRefTexture().getLevelFace(levelNdx, (tcu::CubeFace)faceNdx),
459*35238bceSAndroid Build Coastguard Worker                        tcu::RGBA(color).toVec());
460*35238bceSAndroid Build Coastguard Worker         }
461*35238bceSAndroid Build Coastguard Worker     }
462*35238bceSAndroid Build Coastguard Worker }
463*35238bceSAndroid Build Coastguard Worker 
deinit(void)464*35238bceSAndroid Build Coastguard Worker void TextureCubeMipmapCase::deinit(void)
465*35238bceSAndroid Build Coastguard Worker {
466*35238bceSAndroid Build Coastguard Worker     delete m_texture;
467*35238bceSAndroid Build Coastguard Worker     m_texture = DE_NULL;
468*35238bceSAndroid Build Coastguard Worker 
469*35238bceSAndroid Build Coastguard Worker     m_renderer.clear();
470*35238bceSAndroid Build Coastguard Worker }
471*35238bceSAndroid Build Coastguard Worker 
randomPartition(vector<IVec4> & dst,de::Random & rnd,int x,int y,int width,int height)472*35238bceSAndroid Build Coastguard Worker static void randomPartition(vector<IVec4> &dst, de::Random &rnd, int x, int y, int width, int height)
473*35238bceSAndroid Build Coastguard Worker {
474*35238bceSAndroid Build Coastguard Worker     const int minWidth  = 8;
475*35238bceSAndroid Build Coastguard Worker     const int minHeight = 8;
476*35238bceSAndroid Build Coastguard Worker 
477*35238bceSAndroid Build Coastguard Worker     bool partition  = rnd.getFloat() > 0.4f;
478*35238bceSAndroid Build Coastguard Worker     bool partitionX = partition && width > minWidth && rnd.getBool();
479*35238bceSAndroid Build Coastguard Worker     bool partitionY = partition && height > minHeight && !partitionX;
480*35238bceSAndroid Build Coastguard Worker 
481*35238bceSAndroid Build Coastguard Worker     if (partitionX)
482*35238bceSAndroid Build Coastguard Worker     {
483*35238bceSAndroid Build Coastguard Worker         int split = width / 2 + rnd.getInt(-width / 4, +width / 4);
484*35238bceSAndroid Build Coastguard Worker         randomPartition(dst, rnd, x, y, split, height);
485*35238bceSAndroid Build Coastguard Worker         randomPartition(dst, rnd, x + split, y, width - split, height);
486*35238bceSAndroid Build Coastguard Worker     }
487*35238bceSAndroid Build Coastguard Worker     else if (partitionY)
488*35238bceSAndroid Build Coastguard Worker     {
489*35238bceSAndroid Build Coastguard Worker         int split = height / 2 + rnd.getInt(-height / 4, +height / 4);
490*35238bceSAndroid Build Coastguard Worker         randomPartition(dst, rnd, x, y, width, split);
491*35238bceSAndroid Build Coastguard Worker         randomPartition(dst, rnd, x, y + split, width, height - split);
492*35238bceSAndroid Build Coastguard Worker     }
493*35238bceSAndroid Build Coastguard Worker     else
494*35238bceSAndroid Build Coastguard Worker         dst.push_back(IVec4(x, y, width, height));
495*35238bceSAndroid Build Coastguard Worker }
496*35238bceSAndroid Build Coastguard Worker 
computeGridLayout(vector<IVec4> & dst,int width,int height)497*35238bceSAndroid Build Coastguard Worker static void computeGridLayout(vector<IVec4> &dst, int width, int height)
498*35238bceSAndroid Build Coastguard Worker {
499*35238bceSAndroid Build Coastguard Worker     de::Random rnd(7);
500*35238bceSAndroid Build Coastguard Worker     randomPartition(dst, rnd, 0, 0, width, height);
501*35238bceSAndroid Build Coastguard Worker }
502*35238bceSAndroid Build Coastguard Worker 
iterate(void)503*35238bceSAndroid Build Coastguard Worker TextureCubeMipmapCase::IterateResult TextureCubeMipmapCase::iterate(void)
504*35238bceSAndroid Build Coastguard Worker {
505*35238bceSAndroid Build Coastguard Worker     // Constants.
506*35238bceSAndroid Build Coastguard Worker     const uint32_t magFilter = GL_NEAREST;
507*35238bceSAndroid Build Coastguard Worker 
508*35238bceSAndroid Build Coastguard Worker     int texWidth  = m_texture->getRefTexture().getSize();
509*35238bceSAndroid Build Coastguard Worker     int texHeight = m_texture->getRefTexture().getSize();
510*35238bceSAndroid Build Coastguard Worker 
511*35238bceSAndroid Build Coastguard Worker     int defViewportWidth  = texWidth * 2;
512*35238bceSAndroid Build Coastguard Worker     int defViewportHeight = texHeight * 2;
513*35238bceSAndroid Build Coastguard Worker 
514*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_renderCtx.getFunctions();
515*35238bceSAndroid Build Coastguard Worker     TestLog &log             = m_testCtx.getLog();
516*35238bceSAndroid Build Coastguard Worker     RandomViewport viewport(m_renderCtx.getRenderTarget(), defViewportWidth, defViewportHeight,
517*35238bceSAndroid Build Coastguard Worker                             deStringHash(getName()));
518*35238bceSAndroid Build Coastguard Worker     tcu::Sampler sampler = mapGLSampler(m_wrapS, m_wrapT, m_minFilter, magFilter);
519*35238bceSAndroid Build Coastguard Worker 
520*35238bceSAndroid Build Coastguard Worker     vector<float> texCoord;
521*35238bceSAndroid Build Coastguard Worker 
522*35238bceSAndroid Build Coastguard Worker     bool isProjected = m_coordType == COORDTYPE_PROJECTED;
523*35238bceSAndroid Build Coastguard Worker     bool useLodBias  = m_coordType == COORDTYPE_BASIC_BIAS;
524*35238bceSAndroid Build Coastguard Worker 
525*35238bceSAndroid Build Coastguard Worker     tcu::Surface renderedFrame(viewport.width, viewport.height);
526*35238bceSAndroid Build Coastguard Worker 
527*35238bceSAndroid Build Coastguard Worker     // Accuracy cases test against ideal lod computation.
528*35238bceSAndroid Build Coastguard Worker     tcu::Surface idealFrame(viewport.width, viewport.height);
529*35238bceSAndroid Build Coastguard Worker 
530*35238bceSAndroid Build Coastguard Worker     // Accuracy measurements are off unless we get the expected viewport size.
531*35238bceSAndroid Build Coastguard Worker     if (viewport.width < defViewportWidth || viewport.height < defViewportHeight)
532*35238bceSAndroid Build Coastguard Worker         throw tcu::NotSupportedError("Too small viewport", "", __FILE__, __LINE__);
533*35238bceSAndroid Build Coastguard Worker 
534*35238bceSAndroid Build Coastguard Worker     // Upload texture data.
535*35238bceSAndroid Build Coastguard Worker     m_texture->upload();
536*35238bceSAndroid Build Coastguard Worker 
537*35238bceSAndroid Build Coastguard Worker     // Use unit 0.
538*35238bceSAndroid Build Coastguard Worker     gl.activeTexture(GL_TEXTURE0);
539*35238bceSAndroid Build Coastguard Worker 
540*35238bceSAndroid Build Coastguard Worker     // Bind gradient texture and setup sampler parameters.
541*35238bceSAndroid Build Coastguard Worker     gl.bindTexture(GL_TEXTURE_CUBE_MAP, m_texture->getGLTexture());
542*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, m_wrapS);
543*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, m_wrapT);
544*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, m_minFilter);
545*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, magFilter);
546*35238bceSAndroid Build Coastguard Worker 
547*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(gl.getError(), "After texture setup");
548*35238bceSAndroid Build Coastguard Worker 
549*35238bceSAndroid Build Coastguard Worker     // Compute grid.
550*35238bceSAndroid Build Coastguard Worker     vector<IVec4> gridLayout;
551*35238bceSAndroid Build Coastguard Worker     computeGridLayout(gridLayout, viewport.width, viewport.height);
552*35238bceSAndroid Build Coastguard Worker 
553*35238bceSAndroid Build Coastguard Worker     // Bias values.
554*35238bceSAndroid Build Coastguard Worker     static const float s_bias[] = {1.0f, -2.0f, 0.8f, -0.5f, 1.5f, 0.9f, 2.0f, 4.0f};
555*35238bceSAndroid Build Coastguard Worker 
556*35238bceSAndroid Build Coastguard Worker     // Projection values \note Less agressive than in 2D case due to smaller quads.
557*35238bceSAndroid Build Coastguard Worker     static const Vec4 s_projections[] = {Vec4(1.2f, 1.0f, 0.7f, 1.0f), Vec4(1.3f, 0.8f, 0.6f, 1.1f),
558*35238bceSAndroid Build Coastguard Worker                                          Vec4(0.8f, 1.0f, 1.2f, 0.8f), Vec4(1.2f, 1.0f, 1.3f, 0.9f)};
559*35238bceSAndroid Build Coastguard Worker 
560*35238bceSAndroid Build Coastguard Worker     for (int cellNdx = 0; cellNdx < (int)gridLayout.size(); cellNdx++)
561*35238bceSAndroid Build Coastguard Worker     {
562*35238bceSAndroid Build Coastguard Worker         int curX               = gridLayout[cellNdx].x();
563*35238bceSAndroid Build Coastguard Worker         int curY               = gridLayout[cellNdx].y();
564*35238bceSAndroid Build Coastguard Worker         int curW               = gridLayout[cellNdx].z();
565*35238bceSAndroid Build Coastguard Worker         int curH               = gridLayout[cellNdx].w();
566*35238bceSAndroid Build Coastguard Worker         tcu::CubeFace cubeFace = (tcu::CubeFace)(cellNdx % tcu::CUBEFACE_LAST);
567*35238bceSAndroid Build Coastguard Worker         ReferenceParams params(TEXTURETYPE_CUBE);
568*35238bceSAndroid Build Coastguard Worker 
569*35238bceSAndroid Build Coastguard Worker         params.sampler = sampler;
570*35238bceSAndroid Build Coastguard Worker 
571*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(m_coordType != COORDTYPE_AFFINE); // Not supported.
572*35238bceSAndroid Build Coastguard Worker         computeQuadTexCoordCube(texCoord, cubeFace);
573*35238bceSAndroid Build Coastguard Worker 
574*35238bceSAndroid Build Coastguard Worker         if (isProjected)
575*35238bceSAndroid Build Coastguard Worker         {
576*35238bceSAndroid Build Coastguard Worker             params.flags |= ReferenceParams::PROJECTED;
577*35238bceSAndroid Build Coastguard Worker             params.w = s_projections[cellNdx % DE_LENGTH_OF_ARRAY(s_projections)];
578*35238bceSAndroid Build Coastguard Worker         }
579*35238bceSAndroid Build Coastguard Worker 
580*35238bceSAndroid Build Coastguard Worker         if (useLodBias)
581*35238bceSAndroid Build Coastguard Worker         {
582*35238bceSAndroid Build Coastguard Worker             params.flags |= ReferenceParams::USE_BIAS;
583*35238bceSAndroid Build Coastguard Worker             params.bias = s_bias[cellNdx % DE_LENGTH_OF_ARRAY(s_bias)];
584*35238bceSAndroid Build Coastguard Worker         }
585*35238bceSAndroid Build Coastguard Worker 
586*35238bceSAndroid Build Coastguard Worker         // Render with GL.
587*35238bceSAndroid Build Coastguard Worker         gl.viewport(viewport.x + curX, viewport.y + curY, curW, curH);
588*35238bceSAndroid Build Coastguard Worker         m_renderer.renderQuad(0, &texCoord[0], params);
589*35238bceSAndroid Build Coastguard Worker 
590*35238bceSAndroid Build Coastguard Worker         // Render reference(s).
591*35238bceSAndroid Build Coastguard Worker         {
592*35238bceSAndroid Build Coastguard Worker             tcu::SurfaceAccess idealDst(idealFrame, m_renderCtx.getRenderTarget().getPixelFormat(), curX, curY, curW,
593*35238bceSAndroid Build Coastguard Worker                                         curH);
594*35238bceSAndroid Build Coastguard Worker             params.lodMode = LODMODE_EXACT;
595*35238bceSAndroid Build Coastguard Worker             sampleTexture(idealDst, m_texture->getRefTexture(), &texCoord[0], params);
596*35238bceSAndroid Build Coastguard Worker         }
597*35238bceSAndroid Build Coastguard Worker     }
598*35238bceSAndroid Build Coastguard Worker 
599*35238bceSAndroid Build Coastguard Worker     // Read result.
600*35238bceSAndroid Build Coastguard Worker     glu::readPixels(m_renderCtx, viewport.x, viewport.y, renderedFrame.getAccess());
601*35238bceSAndroid Build Coastguard Worker 
602*35238bceSAndroid Build Coastguard Worker     // Compare and log.
603*35238bceSAndroid Build Coastguard Worker     {
604*35238bceSAndroid Build Coastguard Worker         const int bestScoreDiff  = (texWidth / 16) * (texHeight / 16);
605*35238bceSAndroid Build Coastguard Worker         const int worstScoreDiff = texWidth * texHeight;
606*35238bceSAndroid Build Coastguard Worker 
607*35238bceSAndroid Build Coastguard Worker         int score = measureAccuracy(log, idealFrame, renderedFrame, bestScoreDiff, worstScoreDiff);
608*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, de::toString(score).c_str());
609*35238bceSAndroid Build Coastguard Worker     }
610*35238bceSAndroid Build Coastguard Worker 
611*35238bceSAndroid Build Coastguard Worker     return STOP;
612*35238bceSAndroid Build Coastguard Worker }
613*35238bceSAndroid Build Coastguard Worker 
TextureMipmapTests(Context & context)614*35238bceSAndroid Build Coastguard Worker TextureMipmapTests::TextureMipmapTests(Context &context) : TestCaseGroup(context, "mipmap", "Mipmapping accuracy tests")
615*35238bceSAndroid Build Coastguard Worker {
616*35238bceSAndroid Build Coastguard Worker }
617*35238bceSAndroid Build Coastguard Worker 
~TextureMipmapTests(void)618*35238bceSAndroid Build Coastguard Worker TextureMipmapTests::~TextureMipmapTests(void)
619*35238bceSAndroid Build Coastguard Worker {
620*35238bceSAndroid Build Coastguard Worker }
621*35238bceSAndroid Build Coastguard Worker 
init(void)622*35238bceSAndroid Build Coastguard Worker void TextureMipmapTests::init(void)
623*35238bceSAndroid Build Coastguard Worker {
624*35238bceSAndroid Build Coastguard Worker     tcu::TestCaseGroup *group2D   = new tcu::TestCaseGroup(m_testCtx, "2d", "2D Texture Mipmapping");
625*35238bceSAndroid Build Coastguard Worker     tcu::TestCaseGroup *groupCube = new tcu::TestCaseGroup(m_testCtx, "cube", "Cube Map Filtering");
626*35238bceSAndroid Build Coastguard Worker     addChild(group2D);
627*35238bceSAndroid Build Coastguard Worker     addChild(groupCube);
628*35238bceSAndroid Build Coastguard Worker 
629*35238bceSAndroid Build Coastguard Worker     static const struct
630*35238bceSAndroid Build Coastguard Worker     {
631*35238bceSAndroid Build Coastguard Worker         const char *name;
632*35238bceSAndroid Build Coastguard Worker         uint32_t mode;
633*35238bceSAndroid Build Coastguard Worker     } wrapModes[] = {{"clamp", GL_CLAMP_TO_EDGE}, {"repeat", GL_REPEAT}, {"mirror", GL_MIRRORED_REPEAT}};
634*35238bceSAndroid Build Coastguard Worker 
635*35238bceSAndroid Build Coastguard Worker     static const struct
636*35238bceSAndroid Build Coastguard Worker     {
637*35238bceSAndroid Build Coastguard Worker         const char *name;
638*35238bceSAndroid Build Coastguard Worker         uint32_t mode;
639*35238bceSAndroid Build Coastguard Worker     } minFilterModes[] = {{"nearest_nearest", GL_NEAREST_MIPMAP_NEAREST},
640*35238bceSAndroid Build Coastguard Worker                           {"linear_nearest", GL_LINEAR_MIPMAP_NEAREST},
641*35238bceSAndroid Build Coastguard Worker                           {"nearest_linear", GL_NEAREST_MIPMAP_LINEAR},
642*35238bceSAndroid Build Coastguard Worker                           {"linear_linear", GL_LINEAR_MIPMAP_LINEAR}};
643*35238bceSAndroid Build Coastguard Worker 
644*35238bceSAndroid Build Coastguard Worker     static const struct
645*35238bceSAndroid Build Coastguard Worker     {
646*35238bceSAndroid Build Coastguard Worker         CoordType type;
647*35238bceSAndroid Build Coastguard Worker         const char *name;
648*35238bceSAndroid Build Coastguard Worker         const char *desc;
649*35238bceSAndroid Build Coastguard Worker     } coordTypes[] = {{COORDTYPE_BASIC, "basic", "Mipmapping with translated and scaled coordinates"},
650*35238bceSAndroid Build Coastguard Worker                       {COORDTYPE_AFFINE, "affine", "Mipmapping with affine coordinate transform"},
651*35238bceSAndroid Build Coastguard Worker                       {COORDTYPE_PROJECTED, "projected", "Mipmapping with perspective projection"}};
652*35238bceSAndroid Build Coastguard Worker 
653*35238bceSAndroid Build Coastguard Worker     const int tex2DWidth  = 64;
654*35238bceSAndroid Build Coastguard Worker     const int tex2DHeight = 64;
655*35238bceSAndroid Build Coastguard Worker 
656*35238bceSAndroid Build Coastguard Worker     // 2D cases.
657*35238bceSAndroid Build Coastguard Worker     for (int coordType = 0; coordType < DE_LENGTH_OF_ARRAY(coordTypes); coordType++)
658*35238bceSAndroid Build Coastguard Worker     {
659*35238bceSAndroid Build Coastguard Worker         tcu::TestCaseGroup *coordTypeGroup =
660*35238bceSAndroid Build Coastguard Worker             new tcu::TestCaseGroup(m_testCtx, coordTypes[coordType].name, coordTypes[coordType].desc);
661*35238bceSAndroid Build Coastguard Worker         group2D->addChild(coordTypeGroup);
662*35238bceSAndroid Build Coastguard Worker 
663*35238bceSAndroid Build Coastguard Worker         for (int minFilter = 0; minFilter < DE_LENGTH_OF_ARRAY(minFilterModes); minFilter++)
664*35238bceSAndroid Build Coastguard Worker         {
665*35238bceSAndroid Build Coastguard Worker             for (int wrapMode = 0; wrapMode < DE_LENGTH_OF_ARRAY(wrapModes); wrapMode++)
666*35238bceSAndroid Build Coastguard Worker             {
667*35238bceSAndroid Build Coastguard Worker                 std::ostringstream name;
668*35238bceSAndroid Build Coastguard Worker                 name << minFilterModes[minFilter].name << "_" << wrapModes[wrapMode].name;
669*35238bceSAndroid Build Coastguard Worker 
670*35238bceSAndroid Build Coastguard Worker                 coordTypeGroup->addChild(new Texture2DMipmapCase(
671*35238bceSAndroid Build Coastguard Worker                     m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(), name.str().c_str(), "",
672*35238bceSAndroid Build Coastguard Worker                     coordTypes[coordType].type, minFilterModes[minFilter].mode, wrapModes[wrapMode].mode,
673*35238bceSAndroid Build Coastguard Worker                     wrapModes[wrapMode].mode, GL_RGBA, GL_UNSIGNED_BYTE, tex2DWidth, tex2DHeight));
674*35238bceSAndroid Build Coastguard Worker             }
675*35238bceSAndroid Build Coastguard Worker         }
676*35238bceSAndroid Build Coastguard Worker     }
677*35238bceSAndroid Build Coastguard Worker 
678*35238bceSAndroid Build Coastguard Worker     const int cubeMapSize = 64;
679*35238bceSAndroid Build Coastguard Worker 
680*35238bceSAndroid Build Coastguard Worker     static const struct
681*35238bceSAndroid Build Coastguard Worker     {
682*35238bceSAndroid Build Coastguard Worker         CoordType type;
683*35238bceSAndroid Build Coastguard Worker         const char *name;
684*35238bceSAndroid Build Coastguard Worker         const char *desc;
685*35238bceSAndroid Build Coastguard Worker     } cubeCoordTypes[] = {{COORDTYPE_BASIC, "basic", "Mipmapping with translated and scaled coordinates"},
686*35238bceSAndroid Build Coastguard Worker                           {COORDTYPE_PROJECTED, "projected", "Mipmapping with perspective projection"}};
687*35238bceSAndroid Build Coastguard Worker 
688*35238bceSAndroid Build Coastguard Worker     // Cubemap cases.
689*35238bceSAndroid Build Coastguard Worker     for (int coordType = 0; coordType < DE_LENGTH_OF_ARRAY(cubeCoordTypes); coordType++)
690*35238bceSAndroid Build Coastguard Worker     {
691*35238bceSAndroid Build Coastguard Worker         tcu::TestCaseGroup *coordTypeGroup =
692*35238bceSAndroid Build Coastguard Worker             new tcu::TestCaseGroup(m_testCtx, cubeCoordTypes[coordType].name, cubeCoordTypes[coordType].desc);
693*35238bceSAndroid Build Coastguard Worker         groupCube->addChild(coordTypeGroup);
694*35238bceSAndroid Build Coastguard Worker 
695*35238bceSAndroid Build Coastguard Worker         for (int minFilter = 0; minFilter < DE_LENGTH_OF_ARRAY(minFilterModes); minFilter++)
696*35238bceSAndroid Build Coastguard Worker         {
697*35238bceSAndroid Build Coastguard Worker             coordTypeGroup->addChild(new TextureCubeMipmapCase(
698*35238bceSAndroid Build Coastguard Worker                 m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(), minFilterModes[minFilter].name, "",
699*35238bceSAndroid Build Coastguard Worker                 cubeCoordTypes[coordType].type, minFilterModes[minFilter].mode, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE,
700*35238bceSAndroid Build Coastguard Worker                 GL_RGBA, GL_UNSIGNED_BYTE, cubeMapSize));
701*35238bceSAndroid Build Coastguard Worker         }
702*35238bceSAndroid Build Coastguard Worker     }
703*35238bceSAndroid Build Coastguard Worker }
704*35238bceSAndroid Build Coastguard Worker 
705*35238bceSAndroid Build Coastguard Worker } // namespace Accuracy
706*35238bceSAndroid Build Coastguard Worker } // namespace gles2
707*35238bceSAndroid Build Coastguard Worker } // namespace deqp
708