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);
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);
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
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)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)
94 , m_format (format)
95 , m_dataType (dataType)
96 , m_wrapS (wrapS)
97 , m_wrapT (wrapT)
98 , m_minFilter (minFilter)
99 , m_magFilter (magFilter)
100 , m_width (width)
101 , m_height (height)
102 , m_texture (DE_NULL)
103 , m_renderer (renderCtx, testCtx.getLog(), glu::GLSL_VERSION_100_ES, glu::PRECISION_MEDIUMP)
104 {
105 }
106
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)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)
111 , m_format (GL_NONE)
112 , m_dataType (GL_NONE)
113 , m_wrapS (wrapS)
114 , m_wrapT (wrapT)
115 , m_minFilter (minFilter)
116 , m_magFilter (magFilter)
117 , m_width (0)
118 , m_height (0)
119 , m_filenames (filenames)
120 , m_texture (DE_NULL)
121 , m_renderer (renderCtx, testCtx.getLog(), glu::GLSL_VERSION_100_ES, glu::PRECISION_MEDIUMP)
122 {
123 }
124
~TextureWrapCase(void)125 TextureWrapCase::~TextureWrapCase (void)
126 {
127 deinit();
128 }
129
init(void)130 void TextureWrapCase::init (void)
131 {
132 if (!m_filenames.empty())
133 {
134 DE_ASSERT(m_width == 0 && m_height == 0 && m_format == GL_NONE && m_dataType == GL_NONE);
135
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();
139 }
140 else
141 {
142 m_texture = new Texture2D(m_renderCtx, m_format, m_dataType, m_width, m_height);
143
144 // Fill level 0.
145 m_texture->getRefTexture().allocLevel(0);
146 if (m_wrapS == GL_REPEAT ||
147 m_wrapT == GL_REPEAT)
148 {
149 // If run in repeat mode, use conical style texture to avoid edge sample result have a huge difference when coordinate offset in allow range.
150 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));
151 }
152 else
153 {
154 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));
155 }
156
157 m_texture->upload();
158 }
159 }
160
deinit(void)161 void TextureWrapCase::deinit (void)
162 {
163 delete m_texture;
164 m_texture = DE_NULL;
165
166 m_renderer.clear();
167 }
168
iterate(void)169 TextureWrapCase::IterateResult TextureWrapCase::iterate (void)
170 {
171 const glw::Functions& gl = m_renderCtx.getFunctions();
172 TestLog& log = m_testCtx.getLog();
173 RandomViewport viewport (m_renderCtx.getRenderTarget(), VIEWPORT_WIDTH, VIEWPORT_HEIGHT, deStringHash(getName()));
174 tcu::Surface renderedFrame (viewport.width, viewport.height);
175 tcu::Surface referenceFrame (viewport.width, viewport.height);
176 bool isCompressedTex = !m_filenames.empty();
177 ReferenceParams refParams (TEXTURETYPE_2D);
178 int leftWidth = viewport.width / 2;
179 int rightWidth = viewport.width - leftWidth;
180 vector<float> texCoord;
181
182 tcu::RGBA threshold;
183 if (m_texture->getRefTexture().getFormat().type == tcu::TextureFormat::UNORM_SHORT_4444 ||
184 m_texture->getRefTexture().getFormat().type == tcu::TextureFormat::UNSIGNED_SHORT_4444)
185 {
186 threshold = tcu::PixelFormat(4, 4, 4, 4).getColorThreshold() + tcu::RGBA(1, 1, 1, 1);
187 }
188 else
189 {
190 threshold = m_renderCtx.getRenderTarget().getPixelFormat().getColorThreshold() +
191 (isCompressedTex ? tcu::RGBA(7, 7, 7, 7) : tcu::RGBA(3, 3, 3, 3));
192 }
193
194 // Bind to unit 0.
195 gl.activeTexture(GL_TEXTURE0);
196 gl.bindTexture(GL_TEXTURE_2D, m_texture->getGLTexture());
197
198 // Setup filtering and wrap modes.
199 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_wrapS);
200 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_wrapT);
201 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_minFilter);
202 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, m_magFilter);
203
204 GLU_EXPECT_NO_ERROR(gl.getError(), "Set texturing state");
205
206 // Parameters for reference images.
207 refParams.sampler = mapGLSampler(m_wrapS, m_wrapT, m_minFilter, m_magFilter);
208 refParams.lodMode = LODMODE_EXACT;
209
210 // Left: minification
211 {
212 gl.viewport(viewport.x, viewport.y, leftWidth, viewport.height);
213
214 computeQuadTexCoord2D(texCoord, tcu::Vec2(-1.5f, -3.0f), tcu::Vec2(1.5f, 2.5f));
215
216 m_renderer.renderQuad(0, &texCoord[0], refParams);
217 glu::readPixels(m_renderCtx, viewport.x, viewport.y, renderedFrame.getAccess());
218
219 sampleTexture(tcu::SurfaceAccess(referenceFrame, m_renderCtx.getRenderTarget().getPixelFormat(), 0, 0, leftWidth, viewport.height),
220 m_texture->getRefTexture(), &texCoord[0], refParams);
221 }
222
223 // Right: magnification
224 {
225 gl.viewport(viewport.x+leftWidth, viewport.y, rightWidth, viewport.height);
226
227 computeQuadTexCoord2D(texCoord, tcu::Vec2(-0.5f, 0.75f), tcu::Vec2(0.25f, 1.25f));
228
229 m_renderer.renderQuad(0, &texCoord[0], refParams);
230 glu::readPixels(m_renderCtx, viewport.x, viewport.y, renderedFrame.getAccess());
231
232 sampleTexture(tcu::SurfaceAccess(referenceFrame, m_renderCtx.getRenderTarget().getPixelFormat(), leftWidth, 0, rightWidth, viewport.height),
233 m_texture->getRefTexture(), &texCoord[0], refParams);
234 }
235
236 // Compare and log.
237 bool isOk = compareImages(log, referenceFrame, renderedFrame, threshold);
238
239 m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL,
240 isOk ? "Pass" : "Image comparison failed");
241
242 return STOP;
243 }
244
TextureWrapTests(Context & context)245 TextureWrapTests::TextureWrapTests (Context& context)
246 : TestCaseGroup(context, "wrap", "Wrap Mode Tests")
247 {
248 }
249
~TextureWrapTests(void)250 TextureWrapTests::~TextureWrapTests (void)
251 {
252 }
253
init(void)254 void TextureWrapTests::init (void)
255 {
256 static const struct
257 {
258 const char* name;
259 deUint32 mode;
260 } wrapModes[] =
261 {
262 { "clamp", GL_CLAMP_TO_EDGE },
263 { "repeat", GL_REPEAT },
264 { "mirror", GL_MIRRORED_REPEAT }
265 };
266
267 static const struct
268 {
269 const char* name;
270 deUint32 mode;
271 } filteringModes[] =
272 {
273 { "nearest", GL_NEAREST },
274 { "linear", GL_LINEAR }
275 };
276
277 static const struct
278 {
279 const char* name;
280 int width;
281 int height;
282 } sizes[] =
283 {
284 { "pot", 64, 128 },
285 { "npot", 63, 112 }
286 };
287
288 static const struct
289 {
290 const char* name;
291 deUint32 format;
292 deUint32 dataType;
293 } formats[] =
294 {
295 { "rgba8888", GL_RGBA, GL_UNSIGNED_BYTE },
296 { "rgb888", GL_RGB, GL_UNSIGNED_BYTE },
297 { "rgba4444", GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 },
298 { "l8", GL_LUMINANCE, GL_UNSIGNED_BYTE },
299 };
300
301 #define FOR_EACH(ITERATOR, ARRAY, BODY) \
302 for (int ITERATOR = 0; ITERATOR < DE_LENGTH_OF_ARRAY(ARRAY); ITERATOR++) \
303 BODY
304
305 FOR_EACH(wrapS, wrapModes,
306 FOR_EACH(wrapT, wrapModes,
307 FOR_EACH(filter, filteringModes,
308 FOR_EACH(size, sizes,
309 FOR_EACH(format, formats,
310 {
311 bool is_clamp_clamp = (wrapModes[wrapS].mode == GL_CLAMP_TO_EDGE && wrapModes[wrapT].mode == GL_CLAMP_TO_EDGE);
312 bool is_repeat_mirror = (wrapModes[wrapS].mode == GL_REPEAT && wrapModes[wrapT].mode == GL_MIRRORED_REPEAT);
313
314 if (!is_clamp_clamp && !is_repeat_mirror && format != 0)
315 continue; // Use other format varants with clamp_clamp & repeat_mirror pair only.
316
317 if (!is_clamp_clamp && (!deIsPowerOfTwo32(sizes[size].width) || !deIsPowerOfTwo32(sizes[size].height)))
318 continue; // Not supported as described in Spec section 3.8.2.
319
320 string name = string("") + wrapModes[wrapS].name + "_" + wrapModes[wrapT].name + "_" + filteringModes[filter].name + "_" + sizes[size].name + "_" + formats[format].name;
321 addChild(new TextureWrapCase(m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(), name.c_str(), "",
322 formats[format].format, formats[format].dataType,
323 wrapModes[wrapS].mode,
324 wrapModes[wrapT].mode,
325 filteringModes[filter].mode, filteringModes[filter].mode,
326 sizes[size].width, sizes[size].height));
327
328 })))))
329
330 // Power-of-two ETC1 texture
331 std::vector<std::string> potFilenames;
332 potFilenames.push_back("data/etc1/photo_helsinki_mip_0.pkm");
333
334 FOR_EACH(wrapS, wrapModes,
335 FOR_EACH(wrapT, wrapModes,
336 FOR_EACH(filter, filteringModes,
337 {
338 string name = string("") + wrapModes[wrapS].name + "_" + wrapModes[wrapT].name + "_" + filteringModes[filter].name + "_pot_etc1";
339 addChild(new TextureWrapCase(m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(), name.c_str(), "",
340 wrapModes[wrapS].mode,
341 wrapModes[wrapT].mode,
342 filteringModes[filter].mode, filteringModes[filter].mode,
343 potFilenames));
344
345 })))
346
347 std::vector<std::string> npotFilenames;
348 npotFilenames.push_back("data/etc1/photo_helsinki_113x89.pkm");
349
350 // NPOT ETC1 texture
351 for (int filter = 0; filter < DE_LENGTH_OF_ARRAY(filteringModes); filter++)
352 {
353 string name = string("clamp_clamp_") + filteringModes[filter].name + "_npot_etc1";
354 addChild(new TextureWrapCase(m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(), name.c_str(), "",
355 GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE,
356 filteringModes[filter].mode, filteringModes[filter].mode,
357 npotFilenames));
358 }
359 }
360
361 } // Functional
362 } // gles2
363 } // deqp
364