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 Prerequisite tests.
22 *//*--------------------------------------------------------------------*/
24 #include "es2fPrerequisiteTests.hpp"
26 #include "tcuRGBA.hpp"
27 #include "tcuSurface.hpp"
28 #include "tcuTextureUtil.hpp"
29 #include "tcuTestLog.hpp"
30 #include "tcuRenderTarget.hpp"
31 #include "gluPixelTransfer.hpp"
32 #include "gluStateReset.hpp"
47 class StateResetCase : public TestCase
50 StateResetCase (Context& context);
51 virtual ~StateResetCase (void);
52 virtual TestCase::IterateResult iterate (void);
55 StateResetCase::StateResetCase (Context& context)
56 : TestCase(context, "state_reset", "State Reset Test")
60 StateResetCase::~StateResetCase (void)
64 TestCase::IterateResult StateResetCase::iterate (void)
68 glu::resetState(m_context.getRenderContext(), m_context.getContextInfo());
69 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
71 catch (const tcu::TestError& e)
73 m_testCtx.getLog() << e;
74 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
77 return TestCase::STOP;
80 class ClearColorCase : public TestCase
83 ClearColorCase (Context& context);
84 virtual ~ClearColorCase (void);
85 virtual TestCase::IterateResult iterate (void);
93 ClearColorCase::ClearColorCase (Context& context)
94 : TestCase (context, "clear_color", "glClearColor test")
100 ClearColorCase::~ClearColorCase (void)
104 TestCase::IterateResult ClearColorCase::iterate (void)
132 deRandom_init(&rnd, deInt32Hash(m_curIter));
133 r = (int)(deRandom_getUint32(&rnd) & 0xFF);
134 g = (int)(deRandom_getUint32(&rnd) & 0xFF);
135 b = (int)(deRandom_getUint32(&rnd) & 0xFF);
136 a = (int)(deRandom_getUint32(&rnd) & 0xFF);
141 glClearColor(float(r)/255.0f, float(g)/255.0f, float(b)/255.0f, float(a)/255.0f);
142 glClear(GL_COLOR_BUFFER_BIT);
144 GLU_CHECK_MSG("CLES2 ClearColor failed.");
146 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
148 return (++m_curIter < m_numIters) ? CONTINUE : STOP;
151 class ReadPixelsCase : public TestCase
154 ReadPixelsCase (Context& context);
155 virtual ~ReadPixelsCase (void);
156 virtual TestCase::IterateResult iterate (void);
163 ReadPixelsCase::ReadPixelsCase (Context& context)
164 : TestCase(context, "read_pixels", "Read pixels test")
170 ReadPixelsCase::~ReadPixelsCase (void)
174 TestCase::IterateResult ReadPixelsCase::iterate (void)
176 const tcu::RenderTarget& renderTarget = m_context.getRenderTarget();
177 tcu::PixelFormat pixelFormat = renderTarget.getPixelFormat();
178 int targetWidth = renderTarget.getWidth();
179 int targetHeight = renderTarget.getHeight();
186 deRandom_init(&rnd, deInt32Hash(m_curIter));
194 imageWidth = targetWidth;
195 imageHeight = targetHeight;
201 imageWidth = targetWidth / 2;
202 imageHeight = targetHeight / 2;
205 // Lower right corner
207 y = targetHeight / 2;
208 imageWidth = targetWidth - x;
209 imageHeight = targetHeight - y;
212 x = deRandom_getUint32(&rnd) % (targetWidth - 1);
213 y = deRandom_getUint32(&rnd) % (targetHeight - 1);
214 imageWidth = 1 + (deRandom_getUint32(&rnd) % (targetWidth - x - 1));
215 imageHeight = 1 + (deRandom_getUint32(&rnd) % (targetHeight - y - 1));
219 Surface resImage(imageWidth, imageHeight);
220 Surface refImage(imageWidth, imageHeight);
221 Surface diffImage(imageWidth, imageHeight);
223 int r = (int)(deRandom_getUint32(&rnd) & 0xFF);
224 int g = (int)(deRandom_getUint32(&rnd) & 0xFF);
225 int b = (int)(deRandom_getUint32(&rnd) & 0xFF);
227 tcu::clear(refImage.getAccess(), tcu::IVec4(r, g, b, 255));
228 glClearColor(float(r)/255.0f, float(g)/255.0f, float(b)/255.0f, 1.0f);
229 glClear(GL_COLOR_BUFFER_BIT);
231 glu::readPixels(m_context.getRenderContext(), x, y, resImage.getAccess());
232 GLU_CHECK_MSG("glReadPixels() failed.");
234 RGBA colorThreshold = pixelFormat.getColorThreshold();
235 RGBA matchColor(0, 255, 0, 255);
236 RGBA diffColor(255, 0, 0, 255);
237 bool isImageOk = true;
239 for (int j = 0; j < imageHeight; j++)
241 for (int i = 0; i < imageWidth; i++)
243 RGBA resRGBA = resImage.getPixel(i, j);
244 RGBA refRGBA = refImage.getPixel(i, j);
245 bool isPixelOk = compareThreshold(refRGBA, resRGBA, colorThreshold);
246 diffImage.setPixel(i, j, isPixelOk ? matchColor : diffColor);
248 isImageOk = isImageOk && isPixelOk;
253 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
256 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
258 TestLog& log = m_testCtx.getLog();
259 log << TestLog::ImageSet("Result", "Resulting framebuffer")
260 << TestLog::Image("Result", "Resulting framebuffer", resImage)
261 << TestLog::Image("Reference", "Reference image", refImage)
262 << TestLog::Image("DiffMask", "Failing pixels", diffImage)
263 << TestLog::EndImageSet;
266 return (++m_curIter < m_numIters) ? CONTINUE : STOP;
269 PrerequisiteTests::PrerequisiteTests (Context& context)
270 : TestCaseGroup(context, "prerequisite", "Prerequisite Test Cases")
274 PrerequisiteTests::~PrerequisiteTests (void)
278 void PrerequisiteTests::init (void)
280 addChild(new StateResetCase(m_context));
281 addChild(new ClearColorCase(m_context));
282 addChild(new ReadPixelsCase(m_context));