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 wrap mode tests.
22 *//*--------------------------------------------------------------------*/
24 #include "es2fTextureWrapTests.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"
33 #include "glwEnums.hpp"
34 #include "glwFunctions.hpp"
48 using namespace gls::TextureTestUtil;
49 using namespace glu::TextureTestUtil;
57 class TextureWrapCase : public tcu::TestCase
60 TextureWrapCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo, const char* name, const char* description, deUint32 format, deUint32 dataType, deUint32 wrapS, deUint32 wrapT, deUint32 minFilter, deUint32 magFilter, int width, int height);
61 TextureWrapCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo, const char* name, const char* description, deUint32 wrapS, deUint32 wrapT, deUint32 minFilter, deUint32 magFilter, const std::vector<std::string>& filenames);
62 ~TextureWrapCase (void);
66 IterateResult iterate (void);
69 TextureWrapCase (const TextureWrapCase& other);
70 TextureWrapCase& operator= (const TextureWrapCase& other);
72 glu::RenderContext& m_renderCtx;
73 const glu::ContextInfo& m_renderCtxInfo;
84 std::vector<std::string> m_filenames;
86 glu::Texture2D* m_texture;
87 TextureRenderer m_renderer;
90 TextureWrapCase::TextureWrapCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo, const char* name, const char* description, deUint32 format, deUint32 dataType, deUint32 wrapS, deUint32 wrapT, deUint32 minFilter, deUint32 magFilter, int width, int height)
91 : TestCase (testCtx, name, description)
92 , m_renderCtx (renderCtx)
93 , m_renderCtxInfo (ctxInfo)
95 , m_dataType (dataType)
98 , m_minFilter (minFilter)
99 , m_magFilter (magFilter)
102 , m_texture (DE_NULL)
103 , m_renderer (renderCtx, testCtx.getLog(), glu::GLSL_VERSION_100_ES, glu::PRECISION_MEDIUMP)
107 TextureWrapCase::TextureWrapCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo, const char* name, const char* description, deUint32 wrapS, deUint32 wrapT, deUint32 minFilter, deUint32 magFilter, const std::vector<std::string>& filenames)
108 : TestCase (testCtx, name, description)
109 , m_renderCtx (renderCtx)
110 , m_renderCtxInfo (ctxInfo)
112 , m_dataType (GL_NONE)
115 , m_minFilter (minFilter)
116 , m_magFilter (magFilter)
119 , m_filenames (filenames)
120 , m_texture (DE_NULL)
121 , m_renderer (renderCtx, testCtx.getLog(), glu::GLSL_VERSION_100_ES, glu::PRECISION_MEDIUMP)
125 TextureWrapCase::~TextureWrapCase (void)
130 void TextureWrapCase::init (void)
132 if (!m_filenames.empty())
134 DE_ASSERT(m_width == 0 && m_height == 0 && m_format == GL_NONE && m_dataType == GL_NONE);
136 m_texture = glu::Texture2D::create(m_renderCtx, m_renderCtxInfo, m_testCtx.getArchive(), (int)m_filenames.size(), m_filenames);
137 m_width = m_texture->getRefTexture().getWidth();
138 m_height = m_texture->getRefTexture().getHeight();
142 m_texture = new Texture2D(m_renderCtx, m_format, m_dataType, m_width, m_height);
145 m_texture->getRefTexture().allocLevel(0);
146 tcu::fillWithComponentGradients(m_texture->getRefTexture().getLevel(0), tcu::Vec4(-0.5f, -0.5f, -0.5f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f));
152 void TextureWrapCase::deinit (void)
160 TextureWrapCase::IterateResult TextureWrapCase::iterate (void)
162 const glw::Functions& gl = m_renderCtx.getFunctions();
163 TestLog& log = m_testCtx.getLog();
164 RandomViewport viewport (m_renderCtx.getRenderTarget(), VIEWPORT_WIDTH, VIEWPORT_HEIGHT, deStringHash(getName()));
165 tcu::Surface renderedFrame (viewport.width, viewport.height);
166 tcu::Surface referenceFrame (viewport.width, viewport.height);
167 bool isCompressedTex = !m_filenames.empty();
168 ReferenceParams refParams (TEXTURETYPE_2D);
169 int leftWidth = viewport.width / 2;
170 int rightWidth = viewport.width - leftWidth;
171 vector<float> texCoord;
172 tcu::RGBA threshold = m_renderCtx.getRenderTarget().getPixelFormat().getColorThreshold()
173 + (isCompressedTex ? tcu::RGBA(7,7,7,7) : tcu::RGBA(3,3,3,3));
176 gl.activeTexture(GL_TEXTURE0);
177 gl.bindTexture(GL_TEXTURE_2D, m_texture->getGLTexture());
179 // Setup filtering and wrap modes.
180 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_wrapS);
181 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_wrapT);
182 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_minFilter);
183 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, m_magFilter);
185 GLU_EXPECT_NO_ERROR(gl.getError(), "Set texturing state");
187 // Parameters for reference images.
188 refParams.sampler = mapGLSampler(m_wrapS, m_wrapT, m_minFilter, m_magFilter);
189 refParams.lodMode = LODMODE_EXACT;
191 // Left: minification
193 gl.viewport(viewport.x, viewport.y, leftWidth, viewport.height);
195 computeQuadTexCoord2D(texCoord, tcu::Vec2(-1.5f, -3.0f), tcu::Vec2(1.5f, 2.5f));
197 m_renderer.renderQuad(0, &texCoord[0], refParams);
198 glu::readPixels(m_renderCtx, viewport.x, viewport.y, renderedFrame.getAccess());
200 sampleTexture(tcu::SurfaceAccess(referenceFrame, m_renderCtx.getRenderTarget().getPixelFormat(), 0, 0, leftWidth, viewport.height),
201 m_texture->getRefTexture(), &texCoord[0], refParams);
204 // Right: magnification
206 gl.viewport(viewport.x+leftWidth, viewport.y, rightWidth, viewport.height);
208 computeQuadTexCoord2D(texCoord, tcu::Vec2(-0.5f, 0.75f), tcu::Vec2(0.25f, 1.25f));
210 m_renderer.renderQuad(0, &texCoord[0], refParams);
211 glu::readPixels(m_renderCtx, viewport.x, viewport.y, renderedFrame.getAccess());
213 sampleTexture(tcu::SurfaceAccess(referenceFrame, m_renderCtx.getRenderTarget().getPixelFormat(), leftWidth, 0, rightWidth, viewport.height),
214 m_texture->getRefTexture(), &texCoord[0], refParams);
218 bool isOk = compareImages(log, referenceFrame, renderedFrame, threshold);
220 m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL,
221 isOk ? "Pass" : "Image comparison failed");
226 TextureWrapTests::TextureWrapTests (Context& context)
227 : TestCaseGroup(context, "wrap", "Wrap Mode Tests")
231 TextureWrapTests::~TextureWrapTests (void)
235 void TextureWrapTests::init (void)
243 { "clamp", GL_CLAMP_TO_EDGE },
244 { "repeat", GL_REPEAT },
245 { "mirror", GL_MIRRORED_REPEAT }
254 { "nearest", GL_NEAREST },
255 { "linear", GL_LINEAR }
276 { "rgba8888", GL_RGBA, GL_UNSIGNED_BYTE },
277 { "rgb888", GL_RGB, GL_UNSIGNED_BYTE },
278 { "rgba4444", GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 },
279 { "l8", GL_LUMINANCE, GL_UNSIGNED_BYTE },
282 #define FOR_EACH(ITERATOR, ARRAY, BODY) \
283 for (int (ITERATOR) = 0; (ITERATOR) < DE_LENGTH_OF_ARRAY(ARRAY); (ITERATOR)++) \
286 FOR_EACH(wrapS, wrapModes,
287 FOR_EACH(wrapT, wrapModes,
288 FOR_EACH(filter, filteringModes,
289 FOR_EACH(size, sizes,
290 FOR_EACH(format, formats,
292 bool is_clamp_clamp = (wrapModes[wrapS].mode == GL_CLAMP_TO_EDGE && wrapModes[wrapT].mode == GL_CLAMP_TO_EDGE);
293 bool is_repeat_mirror = (wrapModes[wrapS].mode == GL_REPEAT && wrapModes[wrapT].mode == GL_MIRRORED_REPEAT);
295 if (!is_clamp_clamp && !is_repeat_mirror && format != 0)
296 continue; // Use other format varants with clamp_clamp & repeat_mirror pair only.
298 if (!is_clamp_clamp && (!deIsPowerOfTwo32(sizes[size].width) || !deIsPowerOfTwo32(sizes[size].height)))
299 continue; // Not supported as described in Spec section 3.8.2.
301 string name = string("") + wrapModes[wrapS].name + "_" + wrapModes[wrapT].name + "_" + filteringModes[filter].name + "_" + sizes[size].name + "_" + formats[format].name;
302 addChild(new TextureWrapCase(m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(), name.c_str(), "",
303 formats[format].format, formats[format].dataType,
304 wrapModes[wrapS].mode,
305 wrapModes[wrapT].mode,
306 filteringModes[filter].mode, filteringModes[filter].mode,
307 sizes[size].width, sizes[size].height));
311 // Power-of-two ETC1 texture
312 std::vector<std::string> potFilenames;
313 potFilenames.push_back("data/etc1/photo_helsinki_mip_0.pkm");
315 FOR_EACH(wrapS, wrapModes,
316 FOR_EACH(wrapT, wrapModes,
317 FOR_EACH(filter, filteringModes,
319 string name = string("") + wrapModes[wrapS].name + "_" + wrapModes[wrapT].name + "_" + filteringModes[filter].name + "_pot_etc1";
320 addChild(new TextureWrapCase(m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(), name.c_str(), "",
321 wrapModes[wrapS].mode,
322 wrapModes[wrapT].mode,
323 filteringModes[filter].mode, filteringModes[filter].mode,
328 std::vector<std::string> npotFilenames;
329 npotFilenames.push_back("data/etc1/photo_helsinki_113x89.pkm");
332 for (int filter = 0; filter < DE_LENGTH_OF_ARRAY(filteringModes); filter++)
334 string name = string("clamp_clamp_") + filteringModes[filter].name + "_npot_etc1";
335 addChild(new TextureWrapCase(m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(), name.c_str(), "",
336 GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE,
337 filteringModes[filter].mode, filteringModes[filter].mode,