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