1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 2.0 Module
3 * -------------------------------------------------
4 *
5 * Copyright 2014 The Android Open Source Project
6 *
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
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
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.
18 *
19 *//*!
20 * \file
21 * \brief Texture wrap mode tests.
22 *//*--------------------------------------------------------------------*/
23
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"
32
33 #include "glwEnums.hpp"
34 #include "glwFunctions.hpp"
35
36 namespace deqp
37 {
38 namespace gles2
39 {
40 namespace Functional
41 {
42
43 using tcu::TestLog;
44 using std::vector;
45 using std::string;
46 using tcu::Sampler;
47 using namespace glu;
48 using namespace gls::TextureTestUtil;
49 using namespace glu::TextureTestUtil;
50
51 enum
52 {
53 VIEWPORT_WIDTH = 256,
54 VIEWPORT_HEIGHT = 256
55 };
56
57 class TextureWrapCase : public tcu::TestCase
58 {
59 public:
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, bool enableRelaxedRef = false);
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, bool enableRelaxedRef = false);
62 ~TextureWrapCase (void);
63
64 void init (void);
65 void deinit (void);
66 IterateResult iterate (void);
67
68 private:
69 TextureWrapCase (const TextureWrapCase& other);
70 TextureWrapCase& operator= (const TextureWrapCase& other);
71
72 glu::RenderContext& m_renderCtx;
73 const glu::ContextInfo& m_renderCtxInfo;
74
75 deUint32 m_format;
76 deUint32 m_dataType;
77 deUint32 m_wrapS;
78 deUint32 m_wrapT;
79 deUint32 m_minFilter;
80 deUint32 m_magFilter;
81
82 int m_width;
83 int m_height;
84 std::vector<std::string> m_filenames;
85
86 glu::Texture2D* m_texture;
87 TextureRenderer m_renderer;
88
89 bool m_enableRelaxedRef;
90 };
91
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,bool enableRelaxedRef)92 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, bool enableRelaxedRef)
93 : TestCase (testCtx, name, description)
94 , m_renderCtx (renderCtx)
95 , m_renderCtxInfo (ctxInfo)
96 , m_format (format)
97 , m_dataType (dataType)
98 , m_wrapS (wrapS)
99 , m_wrapT (wrapT)
100 , m_minFilter (minFilter)
101 , m_magFilter (magFilter)
102 , m_width (width)
103 , m_height (height)
104 , m_texture (DE_NULL)
105 , m_renderer (renderCtx, testCtx.getLog(), glu::GLSL_VERSION_100_ES, glu::PRECISION_MEDIUMP)
106 , m_enableRelaxedRef(enableRelaxedRef)
107 {
108 }
109
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,bool enableRelaxedRef)110 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, bool enableRelaxedRef)
111 : TestCase (testCtx, name, description)
112 , m_renderCtx (renderCtx)
113 , m_renderCtxInfo (ctxInfo)
114 , m_format (GL_NONE)
115 , m_dataType (GL_NONE)
116 , m_wrapS (wrapS)
117 , m_wrapT (wrapT)
118 , m_minFilter (minFilter)
119 , m_magFilter (magFilter)
120 , m_width (0)
121 , m_height (0)
122 , m_filenames (filenames)
123 , m_texture (DE_NULL)
124 , m_renderer (renderCtx, testCtx.getLog(), glu::GLSL_VERSION_100_ES, glu::PRECISION_MEDIUMP)
125 , m_enableRelaxedRef(enableRelaxedRef)
126 {
127 }
128
~TextureWrapCase(void)129 TextureWrapCase::~TextureWrapCase (void)
130 {
131 deinit();
132 }
133
init(void)134 void TextureWrapCase::init (void)
135 {
136 if (!m_filenames.empty())
137 {
138 DE_ASSERT(m_width == 0 && m_height == 0 && m_format == GL_NONE && m_dataType == GL_NONE);
139
140 m_texture = glu::Texture2D::create(m_renderCtx, m_renderCtxInfo, m_testCtx.getArchive(), (int)m_filenames.size(), m_filenames);
141 m_width = m_texture->getRefTexture().getWidth();
142 m_height = m_texture->getRefTexture().getHeight();
143 }
144 else
145 {
146 m_texture = new Texture2D(m_renderCtx, m_format, m_dataType, m_width, m_height);
147
148 // Fill level 0.
149 m_texture->getRefTexture().allocLevel(0);
150 if (m_wrapS == GL_REPEAT ||
151 m_wrapT == GL_REPEAT)
152 {
153 // If run in repeat mode, use conical style texture to avoid edge sample result have a huge difference when coordinate offset in allow range.
154 tcu::fillWithComponentGradients3(m_texture->getRefTexture().getLevel(0), tcu::Vec4(-0.5f, -0.5f, -0.5f, 1.5f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f));
155 }
156 else
157 {
158 tcu::fillWithComponentGradients(m_texture->getRefTexture().getLevel(0), tcu::Vec4(-0.5f, -0.5f, -0.5f, 1.5f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f));
159 }
160
161 m_texture->upload();
162 }
163 }
164
deinit(void)165 void TextureWrapCase::deinit (void)
166 {
167 delete m_texture;
168 m_texture = DE_NULL;
169
170 m_renderer.clear();
171 }
172
iterate(void)173 TextureWrapCase::IterateResult TextureWrapCase::iterate (void)
174 {
175 const glw::Functions& gl = m_renderCtx.getFunctions();
176 TestLog& log = m_testCtx.getLog();
177 RandomViewport viewport (m_renderCtx.getRenderTarget(), VIEWPORT_WIDTH, VIEWPORT_HEIGHT, deStringHash(getName()));
178 tcu::Surface renderedFrame (viewport.width, viewport.height);
179 tcu::Surface referenceFrame (viewport.width, viewport.height);
180 bool isCompressedTex = !m_filenames.empty();
181 ReferenceParams refParams (TEXTURETYPE_2D);
182 int leftWidth = viewport.width / 2;
183 int rightWidth = viewport.width - leftWidth;
184 vector<float> texCoord;
185
186 tcu::RGBA threshold;
187 if (m_texture->getRefTexture().getFormat().type == tcu::TextureFormat::UNORM_SHORT_4444 ||
188 m_texture->getRefTexture().getFormat().type == tcu::TextureFormat::UNSIGNED_SHORT_4444)
189 {
190 threshold = tcu::PixelFormat(4, 4, 4, 4).getColorThreshold() + tcu::RGBA(1, 1, 1, 1);
191 }
192 else
193 {
194 threshold = m_renderCtx.getRenderTarget().getPixelFormat().getColorThreshold() +
195 (isCompressedTex ? tcu::RGBA(7, 7, 7, 7) : tcu::RGBA(3, 3, 3, 3));
196 }
197
198 // Bind to unit 0.
199 gl.activeTexture(GL_TEXTURE0);
200 gl.bindTexture(GL_TEXTURE_2D, m_texture->getGLTexture());
201
202 // Setup filtering and wrap modes.
203 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_wrapS);
204 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_wrapT);
205 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_minFilter);
206 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, m_magFilter);
207
208 GLU_EXPECT_NO_ERROR(gl.getError(), "Set texturing state");
209
210 // Parameters for reference images.
211 refParams.sampler = mapGLSampler(m_wrapS, m_wrapT, m_minFilter, m_magFilter);
212 refParams.lodMode = LODMODE_EXACT;
213
214 // Left: minification
215 {
216 gl.viewport(viewport.x, viewport.y, leftWidth, viewport.height);
217
218 computeQuadTexCoord2D(texCoord, tcu::Vec2(-1.5f, -3.0f), tcu::Vec2(1.5f, 2.5f));
219
220 m_renderer.renderQuad(0, &texCoord[0], refParams);
221 glu::readPixels(m_renderCtx, viewport.x, viewport.y, renderedFrame.getAccess());
222
223 sampleTexture(tcu::SurfaceAccess(referenceFrame, m_renderCtx.getRenderTarget().getPixelFormat(), 0, 0, leftWidth, viewport.height),
224 m_texture->getRefTexture(), &texCoord[0], refParams);
225 }
226
227 // Right: magnification
228 {
229 gl.viewport(viewport.x+leftWidth, viewport.y, rightWidth, viewport.height);
230
231 computeQuadTexCoord2D(texCoord, tcu::Vec2(-0.5f, 0.75f), tcu::Vec2(0.25f, 1.25f));
232
233 m_renderer.renderQuad(0, &texCoord[0], refParams);
234 glu::readPixels(m_renderCtx, viewport.x, viewport.y, renderedFrame.getAccess());
235
236 sampleTexture(tcu::SurfaceAccess(referenceFrame, m_renderCtx.getRenderTarget().getPixelFormat(), leftWidth, 0, rightWidth, viewport.height),
237 m_texture->getRefTexture(), &texCoord[0], refParams);
238 }
239
240 // Compare and log.
241 bool isOk = compareImages(log, referenceFrame, renderedFrame, threshold);
242
243 if ((isOk == false) &&
244 m_enableRelaxedRef &&
245 m_renderer.getTexCoordPrecision() != PRECISION_HIGHP)
246 {
247 refParams.float16TexCoord = true;
248 // Left: minification
249 {
250 computeQuadTexCoord2D(texCoord, tcu::Vec2(-1.5f, -3.0f), tcu::Vec2(1.5f, 2.5f));
251 sampleTexture(tcu::SurfaceAccess(referenceFrame, m_renderCtx.getRenderTarget().getPixelFormat(), 0, 0, leftWidth, viewport.height),
252 m_texture->getRefTexture(), &texCoord[0], refParams);
253 }
254
255 // Right: magnification
256 {
257 computeQuadTexCoord2D(texCoord, tcu::Vec2(-0.5f, 0.75f), tcu::Vec2(0.25f, 1.25f));
258 sampleTexture(tcu::SurfaceAccess(referenceFrame, m_renderCtx.getRenderTarget().getPixelFormat(), leftWidth, 0, rightWidth, viewport.height),
259 m_texture->getRefTexture(), &texCoord[0], refParams);
260 }
261
262 isOk |= compareImages(log, referenceFrame, renderedFrame, threshold);
263 }
264
265 m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL,
266 isOk ? "Pass" : "Image comparison failed");
267
268 return STOP;
269 }
270
TextureWrapTests(Context & context)271 TextureWrapTests::TextureWrapTests (Context& context)
272 : TestCaseGroup(context, "wrap", "Wrap Mode Tests")
273 {
274 }
275
~TextureWrapTests(void)276 TextureWrapTests::~TextureWrapTests (void)
277 {
278 }
279
init(void)280 void TextureWrapTests::init (void)
281 {
282 static const struct
283 {
284 const char* name;
285 deUint32 mode;
286 } wrapModes[] =
287 {
288 { "clamp", GL_CLAMP_TO_EDGE },
289 { "repeat", GL_REPEAT },
290 { "mirror", GL_MIRRORED_REPEAT }
291 };
292
293 static const struct
294 {
295 const char* name;
296 deUint32 mode;
297 } filteringModes[] =
298 {
299 { "nearest", GL_NEAREST },
300 { "linear", GL_LINEAR }
301 };
302
303 static const struct
304 {
305 const char* name;
306 int width;
307 int height;
308 } sizes[] =
309 {
310 { "pot", 64, 128 },
311 { "npot", 63, 112 }
312 };
313
314 static const struct
315 {
316 const char* name;
317 deUint32 format;
318 deUint32 dataType;
319 } formats[] =
320 {
321 { "rgba8888", GL_RGBA, GL_UNSIGNED_BYTE },
322 { "rgb888", GL_RGB, GL_UNSIGNED_BYTE },
323 { "rgba4444", GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 },
324 { "l8", GL_LUMINANCE, GL_UNSIGNED_BYTE },
325 };
326
327 #define FOR_EACH(ITERATOR, ARRAY, BODY) \
328 for (int ITERATOR = 0; ITERATOR < DE_LENGTH_OF_ARRAY(ARRAY); ITERATOR++) \
329 BODY
330
331 FOR_EACH(wrapS, wrapModes,
332 FOR_EACH(wrapT, wrapModes,
333 FOR_EACH(filter, filteringModes,
334 FOR_EACH(size, sizes,
335 FOR_EACH(format, formats,
336 {
337 bool is_clamp_clamp = (wrapModes[wrapS].mode == GL_CLAMP_TO_EDGE && wrapModes[wrapT].mode == GL_CLAMP_TO_EDGE);
338 bool is_repeat_mirror = (wrapModes[wrapS].mode == GL_REPEAT && wrapModes[wrapT].mode == GL_MIRRORED_REPEAT);
339 bool enableRelaxedPrecisionRef = wrapModes[wrapS].mode == GL_REPEAT ||
340 wrapModes[wrapT].mode == GL_REPEAT ||
341 wrapModes[wrapS].mode == GL_MIRRORED_REPEAT ||
342 wrapModes[wrapT].mode == GL_MIRRORED_REPEAT;
343
344 if (!is_clamp_clamp && !is_repeat_mirror && format != 0)
345 continue; // Use other format varants with clamp_clamp & repeat_mirror pair only.
346
347 if (!is_clamp_clamp && (!deIsPowerOfTwo32(sizes[size].width) || !deIsPowerOfTwo32(sizes[size].height)))
348 continue; // Not supported as described in Spec section 3.8.2.
349
350 string name = string("") + wrapModes[wrapS].name + "_" + wrapModes[wrapT].name + "_" + filteringModes[filter].name + "_" + sizes[size].name + "_" + formats[format].name;
351 addChild(new TextureWrapCase(m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(), name.c_str(), "",
352 formats[format].format, formats[format].dataType,
353 wrapModes[wrapS].mode,
354 wrapModes[wrapT].mode,
355 filteringModes[filter].mode, filteringModes[filter].mode,
356 sizes[size].width, sizes[size].height, enableRelaxedPrecisionRef));
357
358 })))))
359
360 // Power-of-two ETC1 texture
361 std::vector<std::string> potFilenames;
362 potFilenames.push_back("data/etc1/photo_helsinki_mip_0.pkm");
363
364 FOR_EACH(wrapS, wrapModes,
365 FOR_EACH(wrapT, wrapModes,
366 FOR_EACH(filter, filteringModes,
367 {
368 bool enableRelaxedPrecisionRef = wrapModes[wrapS].mode == GL_REPEAT ||
369 wrapModes[wrapT].mode == GL_REPEAT ||
370 wrapModes[wrapS].mode == GL_MIRRORED_REPEAT ||
371 wrapModes[wrapT].mode == GL_MIRRORED_REPEAT;
372
373 string name = string("") + wrapModes[wrapS].name + "_" + wrapModes[wrapT].name + "_" + filteringModes[filter].name + "_pot_etc1";
374 addChild(new TextureWrapCase(m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(), name.c_str(), "",
375 wrapModes[wrapS].mode,
376 wrapModes[wrapT].mode,
377 filteringModes[filter].mode, filteringModes[filter].mode,
378 potFilenames, enableRelaxedPrecisionRef));
379
380 })))
381
382 std::vector<std::string> npotFilenames;
383 npotFilenames.push_back("data/etc1/photo_helsinki_113x89.pkm");
384
385 // NPOT ETC1 texture
386 for (int filter = 0; filter < DE_LENGTH_OF_ARRAY(filteringModes); filter++)
387 {
388 string name = string("clamp_clamp_") + filteringModes[filter].name + "_npot_etc1";
389 addChild(new TextureWrapCase(m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(), name.c_str(), "",
390 GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE,
391 filteringModes[filter].mode, filteringModes[filter].mode,
392 npotFilenames));
393 }
394 }
395
396 } // Functional
397 } // gles2
398 } // deqp
399