1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 2.0 Module
3 * -------------------------------------------------
5 * Copyright 2014 The Android Open Source Project
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief Texture filtering tests.
22 *//*--------------------------------------------------------------------*/
24 #include "es2fTextureFilteringTests.hpp"
25 #include "glsTextureTestUtil.hpp"
26 #include "gluTexture.hpp"
27 #include "gluStrUtil.hpp"
28 #include "gluTextureUtil.hpp"
29 #include "gluPixelTransfer.hpp"
30 #include "tcuTestLog.hpp"
31 #include "tcuTextureUtil.hpp"
32 #include "tcuTexLookupVerifier.hpp"
33 #include "tcuVectorUtil.hpp"
34 #include "deStringUtil.hpp"
35 #include "glwFunctions.hpp"
36 #include "glwEnums.hpp"
50 using namespace gls::TextureTestUtil;
51 using namespace glu::TextureTestUtil;
57 MIN_VIEWPORT_WIDTH = 64,
58 MIN_VIEWPORT_HEIGHT = 64
61 class Texture2DFilteringCase : public tcu::TestCase
64 Texture2DFilteringCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo, const char* name, const char* desc, deUint32 minFilter, deUint32 magFilter, deUint32 wrapS, deUint32 wrapT, deUint32 format, deUint32 dataType, int width, int height);
65 Texture2DFilteringCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo, const char* name, const char* desc, deUint32 minFilter, deUint32 magFilter, deUint32 wrapS, deUint32 wrapT, const std::vector<std::string>& filenames);
66 ~Texture2DFilteringCase (void);
70 IterateResult iterate (void);
73 Texture2DFilteringCase (const Texture2DFilteringCase& other);
74 Texture2DFilteringCase& operator= (const Texture2DFilteringCase& other);
76 glu::RenderContext& m_renderCtx;
77 const glu::ContextInfo& m_renderCtxInfo;
79 const deUint32 m_minFilter;
80 const deUint32 m_magFilter;
81 const deUint32 m_wrapS;
82 const deUint32 m_wrapT;
84 const deUint32 m_format;
85 const deUint32 m_dataType;
89 const std::vector<std::string> m_filenames;
93 const glu::Texture2D* texture;
102 FilterCase (const glu::Texture2D* tex_, const tcu::Vec2& minCoord_, const tcu::Vec2& maxCoord_)
104 , minCoord (minCoord_)
105 , maxCoord (maxCoord_)
110 std::vector<glu::Texture2D*> m_textures;
111 std::vector<FilterCase> m_cases;
113 TextureRenderer m_renderer;
118 Texture2DFilteringCase::Texture2DFilteringCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo, const char* name, const char* desc, deUint32 minFilter, deUint32 magFilter, deUint32 wrapS, deUint32 wrapT, deUint32 format, deUint32 dataType, int width, int height)
119 : TestCase (testCtx, name, desc)
120 , m_renderCtx (renderCtx)
121 , m_renderCtxInfo (ctxInfo)
122 , m_minFilter (minFilter)
123 , m_magFilter (magFilter)
127 , m_dataType (dataType)
130 , m_renderer (renderCtx, testCtx.getLog(), glu::GLSL_VERSION_100_ES, glu::PRECISION_MEDIUMP)
135 Texture2DFilteringCase::Texture2DFilteringCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo, const char* name, const char* desc, deUint32 minFilter, deUint32 magFilter, deUint32 wrapS, deUint32 wrapT, const std::vector<std::string>& filenames)
136 : TestCase (testCtx, name, desc)
137 , m_renderCtx (renderCtx)
138 , m_renderCtxInfo (ctxInfo)
139 , m_minFilter (minFilter)
140 , m_magFilter (magFilter)
144 , m_dataType (GL_NONE)
147 , m_filenames (filenames)
148 , m_renderer (renderCtx, testCtx.getLog(), glu::GLSL_VERSION_100_ES, glu::PRECISION_MEDIUMP)
153 Texture2DFilteringCase::~Texture2DFilteringCase (void)
158 void Texture2DFilteringCase::init (void)
162 if (!m_filenames.empty())
164 m_textures.reserve(1);
165 m_textures.push_back(glu::Texture2D::create(m_renderCtx, m_renderCtxInfo, m_testCtx.getArchive(), (int)m_filenames.size(), m_filenames));
169 // Create 2 textures.
170 m_textures.reserve(2);
171 for (int ndx = 0; ndx < 2; ndx++)
172 m_textures.push_back(new glu::Texture2D(m_renderCtx, m_format, m_dataType, m_width, m_height));
174 bool mipmaps = deIsPowerOfTwo32(m_width) && deIsPowerOfTwo32(m_height);
175 int numLevels = mipmaps ? deLog2Floor32(de::max(m_width, m_height))+1 : 1;
176 tcu::TextureFormatInfo fmtInfo = tcu::getTextureFormatInfo(m_textures[0]->getRefTexture().getFormat());
177 tcu::Vec4 cBias = fmtInfo.valueMin;
178 tcu::Vec4 cScale = fmtInfo.valueMax-fmtInfo.valueMin;
180 // Fill first gradient texture.
181 for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
183 tcu::Vec4 gMin = tcu::Vec4(-0.5f, -0.5f, -0.5f, 2.0f)*cScale + cBias;
184 tcu::Vec4 gMax = tcu::Vec4( 1.0f, 1.0f, 1.0f, 0.0f)*cScale + cBias;
186 m_textures[0]->getRefTexture().allocLevel(levelNdx);
187 tcu::fillWithComponentGradients(m_textures[0]->getRefTexture().getLevel(levelNdx), gMin, gMax);
190 // Fill second with grid texture.
191 for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
193 deUint32 step = 0x00ffffff / numLevels;
194 deUint32 rgb = step*levelNdx;
195 deUint32 colorA = 0xff000000 | rgb;
196 deUint32 colorB = 0xff000000 | ~rgb;
198 m_textures[1]->getRefTexture().allocLevel(levelNdx);
199 tcu::fillWithGrid(m_textures[1]->getRefTexture().getLevel(levelNdx), 4, tcu::RGBA(colorA).toVec()*cScale + cBias, tcu::RGBA(colorB).toVec()*cScale + cBias);
203 for (std::vector<glu::Texture2D*>::iterator i = m_textures.begin(); i != m_textures.end(); i++)
218 { 0, 1.6f, 2.9f, -1.0f, -2.7f },
219 { 0, -2.0f, -1.35f, -0.2f, 0.7f },
220 { 1, 0.14f, 0.275f, -1.5f, -1.1f },
221 { 1, -0.92f, -2.64f, 0.4f, -0.1f },
224 const float viewportW = (float)de::min<int>(VIEWPORT_WIDTH, m_renderCtx.getRenderTarget().getWidth());
225 const float viewportH = (float)de::min<int>(VIEWPORT_HEIGHT, m_renderCtx.getRenderTarget().getHeight());
227 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); caseNdx++)
229 const int texNdx = de::clamp(cases[caseNdx].texNdx, 0, (int)m_textures.size()-1);
230 const float lodX = cases[caseNdx].lodX;
231 const float lodY = cases[caseNdx].lodY;
232 const float oX = cases[caseNdx].oX;
233 const float oY = cases[caseNdx].oY;
234 const float sX = deFloatExp2(lodX)*viewportW / float(m_textures[texNdx]->getRefTexture().getWidth());
235 const float sY = deFloatExp2(lodY)*viewportH / float(m_textures[texNdx]->getRefTexture().getHeight());
237 m_cases.push_back(FilterCase(m_textures[texNdx], tcu::Vec2(oX, oY), tcu::Vec2(oX+sX, oY+sY)));
242 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
246 // Clean up to save memory.
247 Texture2DFilteringCase::deinit();
252 void Texture2DFilteringCase::deinit (void)
254 for (std::vector<glu::Texture2D*>::iterator i = m_textures.begin(); i != m_textures.end(); i++)
262 Texture2DFilteringCase::IterateResult Texture2DFilteringCase::iterate (void)
264 const glw::Functions& gl = m_renderCtx.getFunctions();
265 const RandomViewport viewport (m_renderCtx.getRenderTarget(), VIEWPORT_WIDTH, VIEWPORT_HEIGHT, deStringHash(getName()) ^ deInt32Hash(m_caseNdx));
266 const tcu::TextureFormat texFmt = m_textures[0]->getRefTexture().getFormat();
267 const tcu::TextureFormatInfo fmtInfo = tcu::getTextureFormatInfo(texFmt);
268 const FilterCase& curCase = m_cases[m_caseNdx];
269 const tcu::ScopedLogSection section (m_testCtx.getLog(), string("Test") + de::toString(m_caseNdx), string("Test ") + de::toString(m_caseNdx));
270 ReferenceParams refParams (TEXTURETYPE_2D);
271 tcu::Surface rendered (viewport.width, viewport.height);
272 vector<float> texCoord;
274 if (viewport.width < MIN_VIEWPORT_WIDTH || viewport.height < MIN_VIEWPORT_HEIGHT)
275 throw tcu::NotSupportedError("Too small viewport", "", __FILE__, __LINE__);
277 // Setup params for reference.
278 refParams.sampler = mapGLSampler(m_wrapS, m_wrapT, m_minFilter, m_magFilter);
279 refParams.samplerType = getSamplerType(texFmt);
280 refParams.lodMode = LODMODE_EXACT;
281 refParams.colorBias = fmtInfo.lookupBias;
282 refParams.colorScale = fmtInfo.lookupScale;
284 // Compute texture coordinates.
285 m_testCtx.getLog() << TestLog::Message << "Texture coordinates: " << curCase.minCoord << " -> " << curCase.maxCoord << TestLog::EndMessage;
286 computeQuadTexCoord2D(texCoord, curCase.minCoord, curCase.maxCoord);
288 gl.bindTexture (GL_TEXTURE_2D, curCase.texture->getGLTexture());
289 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_minFilter);
290 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, m_magFilter);
291 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_wrapS);
292 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_wrapT);
294 gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
295 m_renderer.renderQuad(0, &texCoord[0], refParams);
296 glu::readPixels(m_renderCtx, viewport.x, viewport.y, rendered.getAccess());
299 const bool isNearestOnly = m_minFilter == GL_NEAREST && m_magFilter == GL_NEAREST;
300 const tcu::PixelFormat pixelFormat = m_renderCtx.getRenderTarget().getPixelFormat();
301 const tcu::IVec4 colorBits = max(getBitsVec(pixelFormat) - (isNearestOnly ? 1 : 2), tcu::IVec4(0)); // 1 inaccurate bit if nearest only, 2 otherwise
302 tcu::LodPrecision lodPrecision;
303 tcu::LookupPrecision lookupPrecision;
305 lodPrecision.derivateBits = 7;
306 lodPrecision.lodBits = 4;
307 lookupPrecision.colorThreshold = tcu::computeFixedPointThreshold(colorBits) / refParams.colorScale;
308 lookupPrecision.coordBits = tcu::IVec3(9,9,0); // mediump interpolation
309 lookupPrecision.uvwBits = tcu::IVec3(5,5,0);
310 lookupPrecision.colorMask = getCompareMask(pixelFormat);
312 const bool isOk = verifyTextureResult(m_testCtx, rendered.getAccess(), curCase.texture->getRefTexture(),
313 &texCoord[0], refParams, lookupPrecision, lodPrecision, pixelFormat);
316 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Image verification failed");
320 return m_caseNdx < (int)m_cases.size() ? CONTINUE : STOP;
324 class TextureCubeFilteringCase : public tcu::TestCase
327 TextureCubeFilteringCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo, const char* name, const char* desc, deUint32 minFilter, deUint32 magFilter, deUint32 wrapS, deUint32 wrapT, deUint32 format, deUint32 dataType, int width, int height);
328 TextureCubeFilteringCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo, const char* name, const char* desc, deUint32 minFilter, deUint32 magFilter, deUint32 wrapS, deUint32 wrapT, const std::vector<std::string>& filenames);
329 ~TextureCubeFilteringCase (void);
333 IterateResult iterate (void);
336 TextureCubeFilteringCase (const TextureCubeFilteringCase& other);
337 TextureCubeFilteringCase& operator= (const TextureCubeFilteringCase& other);
339 glu::RenderContext& m_renderCtx;
340 const glu::ContextInfo& m_renderCtxInfo;
342 const deUint32 m_minFilter;
343 const deUint32 m_magFilter;
344 const deUint32 m_wrapS;
345 const deUint32 m_wrapT;
347 const deUint32 m_format;
348 const deUint32 m_dataType;
352 const std::vector<std::string> m_filenames;
356 const glu::TextureCube* texture;
357 tcu::Vec2 bottomLeft;
365 FilterCase (const glu::TextureCube* tex_, const tcu::Vec2& bottomLeft_, const tcu::Vec2& topRight_)
367 , bottomLeft(bottomLeft_)
368 , topRight (topRight_)
373 std::vector<glu::TextureCube*> m_textures;
374 std::vector<FilterCase> m_cases;
376 TextureRenderer m_renderer;
381 TextureCubeFilteringCase::TextureCubeFilteringCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo, const char* name, const char* desc, deUint32 minFilter, deUint32 magFilter, deUint32 wrapS, deUint32 wrapT, deUint32 format, deUint32 dataType, int width, int height)
382 : TestCase (testCtx, name, desc)
383 , m_renderCtx (renderCtx)
384 , m_renderCtxInfo (ctxInfo)
385 , m_minFilter (minFilter)
386 , m_magFilter (magFilter)
390 , m_dataType (dataType)
393 , m_renderer (renderCtx, testCtx.getLog(), glu::GLSL_VERSION_100_ES, glu::PRECISION_MEDIUMP)
398 TextureCubeFilteringCase::TextureCubeFilteringCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo, const char* name, const char* desc, deUint32 minFilter, deUint32 magFilter, deUint32 wrapS, deUint32 wrapT, const std::vector<std::string>& filenames)
399 : TestCase (testCtx, name, desc)
400 , m_renderCtx (renderCtx)
401 , m_renderCtxInfo (ctxInfo)
402 , m_minFilter (minFilter)
403 , m_magFilter (magFilter)
407 , m_dataType (GL_NONE)
410 , m_filenames (filenames)
411 , m_renderer (renderCtx, testCtx.getLog(), glu::GLSL_VERSION_100_ES, glu::PRECISION_MEDIUMP)
416 TextureCubeFilteringCase::~TextureCubeFilteringCase (void)
421 void TextureCubeFilteringCase::init (void)
425 if (!m_filenames.empty())
427 m_textures.reserve(1);
428 m_textures.push_back(glu::TextureCube::create(m_renderCtx, m_renderCtxInfo, m_testCtx.getArchive(), (int)m_filenames.size() / 6, m_filenames));
432 DE_ASSERT(m_width == m_height);
433 m_textures.reserve(2);
434 for (int ndx = 0; ndx < 2; ndx++)
435 m_textures.push_back(new glu::TextureCube(m_renderCtx, m_format, m_dataType, m_width));
437 const bool mipmaps = deIsPowerOfTwo32(m_width) && deIsPowerOfTwo32(m_height);
438 const int numLevels = mipmaps ? deLog2Floor32(de::max(m_width, m_height))+1 : 1;
439 tcu::TextureFormatInfo fmtInfo = tcu::getTextureFormatInfo(m_textures[0]->getRefTexture().getFormat());
440 tcu::Vec4 cBias = fmtInfo.valueMin;
441 tcu::Vec4 cScale = fmtInfo.valueMax-fmtInfo.valueMin;
443 // Fill first with gradient texture.
444 static const tcu::Vec4 gradients[tcu::CUBEFACE_LAST][2] =
446 { tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // negative x
447 { tcu::Vec4(0.5f, 0.0f, 0.0f, 1.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // positive x
448 { tcu::Vec4(0.0f, 0.5f, 0.0f, 1.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // negative y
449 { tcu::Vec4(0.0f, 0.0f, 0.5f, 1.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // positive y
450 { tcu::Vec4(0.0f, 0.0f, 0.0f, 0.5f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f) }, // negative z
451 { tcu::Vec4(0.5f, 0.5f, 0.5f, 1.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) } // positive z
453 for (int face = 0; face < tcu::CUBEFACE_LAST; face++)
455 for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
457 m_textures[0]->getRefTexture().allocLevel((tcu::CubeFace)face, levelNdx);
458 tcu::fillWithComponentGradients(m_textures[0]->getRefTexture().getLevelFace(levelNdx, (tcu::CubeFace)face), gradients[face][0]*cScale + cBias, gradients[face][1]*cScale + cBias);
462 // Fill second with grid texture.
463 for (int face = 0; face < tcu::CUBEFACE_LAST; face++)
465 for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
467 deUint32 step = 0x00ffffff / (numLevels*tcu::CUBEFACE_LAST);
468 deUint32 rgb = step*levelNdx*face;
469 deUint32 colorA = 0xff000000 | rgb;
470 deUint32 colorB = 0xff000000 | ~rgb;
472 m_textures[1]->getRefTexture().allocLevel((tcu::CubeFace)face, levelNdx);
473 tcu::fillWithGrid(m_textures[1]->getRefTexture().getLevelFace(levelNdx, (tcu::CubeFace)face), 4, tcu::RGBA(colorA).toVec()*cScale + cBias, tcu::RGBA(colorB).toVec()*cScale + cBias);
478 for (std::vector<glu::TextureCube*>::iterator i = m_textures.begin(); i != m_textures.end(); i++)
484 const glu::TextureCube* tex0 = m_textures[0];
485 const glu::TextureCube* tex1 = m_textures.size() > 1 ? m_textures[1] : tex0;
487 // \note Coordinates are chosen so that they only sample face interior. ES3 has changed edge sampling behavior
488 // and hw is not expected to implement both modes.
489 m_cases.push_back(FilterCase(tex0, tcu::Vec2(-0.8f, -0.8f), tcu::Vec2(0.8f, 0.8f))); // minification
490 m_cases.push_back(FilterCase(tex0, tcu::Vec2(0.5f, 0.65f), tcu::Vec2(0.8f, 0.8f))); // magnification
491 m_cases.push_back(FilterCase(tex1, tcu::Vec2(-0.8f, -0.8f), tcu::Vec2(0.8f, 0.8f))); // minification
492 m_cases.push_back(FilterCase(tex1, tcu::Vec2(0.2f, 0.2f), tcu::Vec2(0.6f, 0.5f))); // magnification
496 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
500 // Clean up to save memory.
501 TextureCubeFilteringCase::deinit();
506 void TextureCubeFilteringCase::deinit (void)
508 for (std::vector<glu::TextureCube*>::iterator i = m_textures.begin(); i != m_textures.end(); i++)
516 static const char* getFaceDesc (const tcu::CubeFace face)
520 case tcu::CUBEFACE_NEGATIVE_X: return "-X";
521 case tcu::CUBEFACE_POSITIVE_X: return "+X";
522 case tcu::CUBEFACE_NEGATIVE_Y: return "-Y";
523 case tcu::CUBEFACE_POSITIVE_Y: return "+Y";
524 case tcu::CUBEFACE_NEGATIVE_Z: return "-Z";
525 case tcu::CUBEFACE_POSITIVE_Z: return "+Z";
532 TextureCubeFilteringCase::IterateResult TextureCubeFilteringCase::iterate (void)
534 const glw::Functions& gl = m_renderCtx.getFunctions();
535 const int viewportSize = 28;
536 const RandomViewport viewport (m_renderCtx.getRenderTarget(), viewportSize, viewportSize, deStringHash(getName()) ^ deInt32Hash(m_caseNdx));
537 const tcu::ScopedLogSection iterSection (m_testCtx.getLog(), string("Test") + de::toString(m_caseNdx), string("Test ") + de::toString(m_caseNdx));
538 const FilterCase& curCase = m_cases[m_caseNdx];
539 const tcu::TextureFormat& texFmt = curCase.texture->getRefTexture().getFormat();
540 const tcu::TextureFormatInfo fmtInfo = tcu::getTextureFormatInfo(texFmt);
541 ReferenceParams sampleParams (TEXTURETYPE_CUBE);
543 if (viewport.width < viewportSize || viewport.height < viewportSize)
544 throw tcu::NotSupportedError("Too small render target", DE_NULL, __FILE__, __LINE__);
547 gl.bindTexture (GL_TEXTURE_CUBE_MAP, curCase.texture->getGLTexture());
548 gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, m_minFilter);
549 gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, m_magFilter);
550 gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, m_wrapS);
551 gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, m_wrapT);
554 gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
556 // Params for reference computation.
557 sampleParams.sampler = glu::mapGLSampler(m_wrapS, m_wrapT, m_minFilter, m_magFilter);
558 sampleParams.sampler.seamlessCubeMap = true;
559 sampleParams.samplerType = getSamplerType(texFmt);
560 sampleParams.colorBias = fmtInfo.lookupBias;
561 sampleParams.colorScale = fmtInfo.lookupScale;
562 sampleParams.lodMode = LODMODE_EXACT;
564 m_testCtx.getLog() << TestLog::Message << "Coordinates: " << curCase.bottomLeft << " -> " << curCase.topRight << TestLog::EndMessage;
566 for (int faceNdx = 0; faceNdx < tcu::CUBEFACE_LAST; faceNdx++)
568 const tcu::CubeFace face = tcu::CubeFace(faceNdx);
569 tcu::Surface result (viewport.width, viewport.height);
570 vector<float> texCoord;
572 computeQuadTexCoordCube(texCoord, face, curCase.bottomLeft, curCase.topRight);
574 m_testCtx.getLog() << TestLog::Message << "Face " << getFaceDesc(face) << TestLog::EndMessage;
576 // \todo Log texture coordinates.
578 m_renderer.renderQuad(0, &texCoord[0], sampleParams);
579 GLU_EXPECT_NO_ERROR(gl.getError(), "Draw");
581 glu::readPixels(m_renderCtx, viewport.x, viewport.y, result.getAccess());
582 GLU_EXPECT_NO_ERROR(gl.getError(), "Read pixels");
585 const bool isNearestOnly = m_minFilter == GL_NEAREST && m_magFilter == GL_NEAREST;
586 const tcu::PixelFormat pixelFormat = m_renderCtx.getRenderTarget().getPixelFormat();
587 const tcu::IVec4 colorBits = max(getBitsVec(pixelFormat) - (isNearestOnly ? 1 : 2), tcu::IVec4(0)); // 1 inaccurate bit if nearest only, 2 otherwise
588 tcu::LodPrecision lodPrecision;
589 tcu::LookupPrecision lookupPrecision;
591 lodPrecision.derivateBits = 5;
592 lodPrecision.lodBits = 3;
593 lookupPrecision.colorThreshold = tcu::computeFixedPointThreshold(colorBits) / sampleParams.colorScale;
594 lookupPrecision.coordBits = tcu::IVec3(9,9,9); // mediump interpolation
595 lookupPrecision.uvwBits = tcu::IVec3(3,3,0);
596 lookupPrecision.colorMask = getCompareMask(pixelFormat);
598 const bool isOk = verifyTextureResult(m_testCtx, result.getAccess(), curCase.texture->getRefTexture(),
599 &texCoord[0], sampleParams, lookupPrecision, lodPrecision, pixelFormat);
602 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Image verification failed");
607 return m_caseNdx < (int)m_cases.size() ? CONTINUE : STOP;
610 TextureFilteringTests::TextureFilteringTests (Context& context)
611 : TestCaseGroup(context, "filtering", "Texture Filtering Tests")
615 TextureFilteringTests::~TextureFilteringTests (void)
619 void TextureFilteringTests::init (void)
621 tcu::TestCaseGroup* group2D = new tcu::TestCaseGroup(m_testCtx, "2d", "2D Texture Filtering");
622 tcu::TestCaseGroup* groupCube = new tcu::TestCaseGroup(m_testCtx, "cube", "Cube Map Filtering");
632 { "clamp", GL_CLAMP_TO_EDGE },
633 { "repeat", GL_REPEAT },
634 { "mirror", GL_MIRRORED_REPEAT }
643 { "nearest", GL_NEAREST },
644 { "linear", GL_LINEAR },
645 { "nearest_mipmap_nearest", GL_NEAREST_MIPMAP_NEAREST },
646 { "linear_mipmap_nearest", GL_LINEAR_MIPMAP_NEAREST },
647 { "nearest_mipmap_linear", GL_NEAREST_MIPMAP_LINEAR },
648 { "linear_mipmap_linear", GL_LINEAR_MIPMAP_LINEAR }
657 { "nearest", GL_NEAREST },
658 { "linear", GL_LINEAR }
690 { "rgba8888", GL_RGBA, GL_UNSIGNED_BYTE },
691 { "rgb888", GL_RGB, GL_UNSIGNED_BYTE },
692 { "rgba4444", GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 },
693 { "l8", GL_LUMINANCE, GL_UNSIGNED_BYTE }
696 #define FOR_EACH(ITERATOR, ARRAY, BODY) \
697 for (int (ITERATOR) = 0; (ITERATOR) < DE_LENGTH_OF_ARRAY(ARRAY); (ITERATOR)++) \
701 FOR_EACH(minFilter, minFilterModes,
702 FOR_EACH(magFilter, magFilterModes,
703 FOR_EACH(wrapMode, wrapModes,
704 FOR_EACH(format, formats,
705 FOR_EACH(size, sizes2D,
707 bool isMipmap = minFilterModes[minFilter].mode != GL_NEAREST && minFilterModes[minFilter].mode != GL_LINEAR;
708 bool isClamp = wrapModes[wrapMode].mode == GL_CLAMP_TO_EDGE;
709 bool isRepeat = wrapModes[wrapMode].mode == GL_REPEAT;
710 bool isMagNearest = magFilterModes[magFilter].mode == GL_NEAREST;
711 bool isPotSize = deIsPowerOfTwo32(sizes2D[size].width) && deIsPowerOfTwo32(sizes2D[size].height);
713 if ((isMipmap || !isClamp) && !isPotSize)
714 continue; // Not supported.
716 if ((format != 0) && !(!isMipmap || (isRepeat && isMagNearest)))
719 string name = string("") + minFilterModes[minFilter].name + "_" + magFilterModes[magFilter].name + "_" + wrapModes[wrapMode].name + "_" + formats[format].name;
722 name += string("_") + sizes2D[size].name;
724 group2D->addChild(new Texture2DFilteringCase(m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(),
726 minFilterModes[minFilter].mode,
727 magFilterModes[magFilter].mode,
728 wrapModes[wrapMode].mode,
729 wrapModes[wrapMode].mode,
730 formats[format].format, formats[format].dataType,
731 sizes2D[size].width, sizes2D[size].height));
734 // 2D ETC1 texture cases.
736 std::vector<std::string> filenames;
737 for (int i = 0; i <= 7; i++)
738 filenames.push_back(string("data/etc1/photo_helsinki_mip_") + de::toString(i) + ".pkm");
740 FOR_EACH(minFilter, minFilterModes,
741 FOR_EACH(magFilter, magFilterModes,
742 FOR_EACH(wrapMode, wrapModes,
744 string name = string("") + minFilterModes[minFilter].name + "_" + magFilterModes[magFilter].name + "_" + wrapModes[wrapMode].name + "_etc1";
746 group2D->addChild(new Texture2DFilteringCase(m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(),
748 minFilterModes[minFilter].mode,
749 magFilterModes[magFilter].mode,
750 wrapModes[wrapMode].mode,
751 wrapModes[wrapMode].mode,
757 FOR_EACH(minFilter, minFilterModes,
758 FOR_EACH(magFilter, magFilterModes,
759 FOR_EACH(wrapMode, wrapModes,
760 FOR_EACH(format, formats,
761 FOR_EACH(size, sizesCube,
763 bool isMipmap = minFilterModes[minFilter].mode != GL_NEAREST && minFilterModes[minFilter].mode != GL_LINEAR;
764 bool isClamp = wrapModes[wrapMode].mode == GL_CLAMP_TO_EDGE;
765 bool isRepeat = wrapModes[wrapMode].mode == GL_REPEAT;
766 bool isMagNearest = magFilterModes[magFilter].mode == GL_NEAREST;
767 bool isPotSize = deIsPowerOfTwo32(sizesCube[size].width) && deIsPowerOfTwo32(sizesCube[size].height);
769 if ((isMipmap || !isClamp) && !isPotSize)
770 continue; // Not supported.
772 if (format != 0 && !(!isMipmap || (isRepeat && isMagNearest)))
775 string name = string("") + minFilterModes[minFilter].name + "_" + magFilterModes[magFilter].name + "_" + wrapModes[wrapMode].name + "_" + formats[format].name;
778 name += string("_") + sizesCube[size].name;
780 groupCube->addChild(new TextureCubeFilteringCase(m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(),
782 minFilterModes[minFilter].mode,
783 magFilterModes[magFilter].mode,
784 wrapModes[wrapMode].mode,
785 wrapModes[wrapMode].mode,
786 formats[format].format, formats[format].dataType,
787 sizesCube[size].width, sizesCube[size].height));
790 // Cubemap ETC1 cases
792 static const char* faceExt[] = { "neg_x", "pos_x", "neg_y", "pos_y", "neg_z", "pos_z" };
794 const int numLevels = 7;
795 vector<string> filenames;
796 for (int level = 0; level < numLevels; level++)
797 for (int face = 0; face < tcu::CUBEFACE_LAST; face++)
798 filenames.push_back(string("data/etc1/skybox_") + faceExt[face] + "_mip_" + de::toString(level) + ".pkm");
800 FOR_EACH(minFilter, minFilterModes,
801 FOR_EACH(magFilter, magFilterModes,
803 string name = string("") + minFilterModes[minFilter].name + "_" + magFilterModes[magFilter].name + "_clamp_etc1";
805 groupCube->addChild(new TextureCubeFilteringCase(m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(),
807 minFilterModes[minFilter].mode,
808 magFilterModes[magFilter].mode,