1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 3.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 Base class for FBO tests.
22 *//*--------------------------------------------------------------------*/
24 #include "es3fFboTestCase.hpp"
25 #include "es3fFboTestUtil.hpp"
26 #include "tcuTestLog.hpp"
27 #include "tcuImageCompare.hpp"
28 #include "tcuRenderTarget.hpp"
29 #include "sglrGLContext.hpp"
30 #include "sglrReferenceContext.hpp"
31 #include "gluStrUtil.hpp"
32 #include "gluContextInfo.hpp"
33 #include "deRandom.hpp"
34 #include "glwEnums.hpp"
35 #include "glwFunctions.hpp"
49 FboTestCase::FboTestCase (Context& context, const char* name, const char* description, bool useScreenSizedViewport)
50 : TestCase (context, name, description)
51 , m_viewportWidth (useScreenSizedViewport ? context.getRenderTarget().getWidth() : 128)
52 , m_viewportHeight (useScreenSizedViewport ? context.getRenderTarget().getHeight() : 128)
56 FboTestCase::~FboTestCase (void)
60 FboTestCase::IterateResult FboTestCase::iterate (void)
62 glu::RenderContext& renderCtx = TestCase::m_context.getRenderContext();
63 const tcu::RenderTarget& renderTarget = renderCtx.getRenderTarget();
64 TestLog& log = m_testCtx.getLog();
67 de::Random rnd (deStringHash(getName()));
68 int width = deMin32(renderTarget.getWidth(), m_viewportWidth);
69 int height = deMin32(renderTarget.getHeight(), m_viewportHeight);
70 int x = rnd.getInt(0, renderTarget.getWidth() - width);
71 int y = rnd.getInt(0, renderTarget.getHeight() - height);
73 // Surface format and storage is choosen by render().
74 tcu::Surface reference;
77 // Call preCheck() that can throw exception if some requirement is not met.
80 // Render using GLES3.
83 sglr::GLContext context(renderCtx, log, sglr::GLCONTEXT_LOG_CALLS, tcu::IVec4(x, y, width, height));
88 deUint32 err = glGetError();
89 if (err != GL_NO_ERROR)
90 throw glu::Error(err, glu::getErrorStr(err).toString().c_str(), DE_NULL, __FILE__, __LINE__);
94 catch (const FboTestUtil::FboIncompleteException& e)
96 if (e.getReason() == GL_FRAMEBUFFER_UNSUPPORTED)
99 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not supported");
108 sglr::ReferenceContextBuffers buffers (tcu::PixelFormat(8,8,8,renderTarget.getPixelFormat().alphaBits?8:0), renderTarget.getDepthBits(), renderTarget.getStencilBits(), width, height);
109 sglr::ReferenceContext context (sglr::ReferenceContextLimits(renderCtx), buffers.getColorbuffer(), buffers.getDepthbuffer(), buffers.getStencilbuffer());
111 setContext(&context);
116 bool isOk = compare(reference, result);
117 m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL,
118 isOk ? "Pass" : "Image comparison failed");
122 bool FboTestCase::compare (const tcu::Surface& reference, const tcu::Surface& result)
124 return tcu::fuzzyCompare(m_testCtx.getLog(), "Result", "Image comparison result", reference, result, 0.05f, tcu::COMPARE_LOG_RESULT);
127 void FboTestCase::readPixels (tcu::Surface& dst, int x, int y, int width, int height, const tcu::TextureFormat& format, const tcu::Vec4& scale, const tcu::Vec4& bias)
129 FboTestUtil::readPixels(*getCurrentContext(), dst, x, y, width, height, format, scale, bias);
132 void FboTestCase::readPixels (tcu::Surface& dst, int x, int y, int width, int height)
134 getCurrentContext()->readPixels(dst, x, y, width, height);
137 void FboTestCase::checkFramebufferStatus (deUint32 target)
139 deUint32 status = glCheckFramebufferStatus(target);
140 if (status != GL_FRAMEBUFFER_COMPLETE)
141 throw FboTestUtil::FboIncompleteException(status, __FILE__, __LINE__);
144 void FboTestCase::checkError (void)
146 deUint32 err = glGetError();
147 if (err != GL_NO_ERROR)
148 throw glu::Error((int)err, (string("Got ") + glu::getErrorStr(err).toString()).c_str(), DE_NULL, __FILE__, __LINE__);
151 static bool isRequiredFormat (deUint32 format, glu::RenderContext& renderContext)
155 // Color-renderable formats
163 case GL_SRGB8_ALPHA8:
187 case GL_DEPTH_COMPONENT32F:
188 case GL_DEPTH_COMPONENT24:
189 case GL_DEPTH_COMPONENT16:
192 // Depth+stencil formats
193 case GL_DEPTH32F_STENCIL8:
194 case GL_DEPTH24_STENCIL8:
198 case GL_STENCIL_INDEX8:
204 case GL_R11F_G11F_B10F:
207 return glu::contextSupports(renderContext.getType(), glu::ApiType::es(3, 2));;
214 static std::vector<std::string> getEnablingExtensions (deUint32 format, glu::RenderContext& renderContext)
216 const bool isES32 = glu::contextSupports(renderContext.getType(), glu::ApiType::es(3, 2));
217 std::vector<std::string> out;
219 DE_ASSERT(!isRequiredFormat(format, renderContext));
224 out.push_back("GL_EXT_color_buffer_half_float");
230 out.push_back("GL_EXT_color_buffer_half_float");
234 case GL_R11F_G11F_B10F:
238 out.push_back("GL_EXT_color_buffer_float");
247 static bool isAnyExtensionSupported (Context& context, const std::vector<std::string>& requiredExts)
249 for (std::vector<std::string>::const_iterator iter = requiredExts.begin(); iter != requiredExts.end(); iter++)
251 const std::string& extension = *iter;
253 if (context.getContextInfo().isExtensionSupported(extension.c_str()))
260 void FboTestCase::checkFormatSupport (deUint32 sizedFormat)
262 const bool isCoreFormat = isRequiredFormat(sizedFormat, m_context.getRenderContext());
263 const std::vector<std::string> requiredExts = (!isCoreFormat) ? getEnablingExtensions(sizedFormat, m_context.getRenderContext()) : std::vector<std::string>();
265 // Check that we don't try to use invalid formats.
266 DE_ASSERT(isCoreFormat || !requiredExts.empty());
268 if (!requiredExts.empty() && !isAnyExtensionSupported(m_context, requiredExts))
269 throw tcu::NotSupportedError("Format not supported");
272 static int getMinimumSampleCount (deUint32 format)
284 case GL_SRGB8_ALPHA8:
305 case GL_DEPTH_COMPONENT32F:
306 case GL_DEPTH_COMPONENT24:
307 case GL_DEPTH_COMPONENT16:
308 case GL_DEPTH32F_STENCIL8:
309 case GL_DEPTH24_STENCIL8:
310 case GL_STENCIL_INDEX8:
313 // GL_EXT_color_buffer_float
314 case GL_R11F_G11F_B10F:
325 // GL_EXT_color_buffer_half_float
330 DE_FATAL("Unknown format");
335 static std::vector<int> querySampleCounts (const glw::Functions& gl, deUint32 format)
337 int numSampleCounts = 0;
338 std::vector<int> sampleCounts;
340 gl.getInternalformativ(GL_RENDERBUFFER, format, GL_NUM_SAMPLE_COUNTS, 1, &numSampleCounts);
342 if (numSampleCounts > 0)
344 sampleCounts.resize(numSampleCounts);
345 gl.getInternalformativ(GL_RENDERBUFFER, format, GL_SAMPLES, (glw::GLsizei)sampleCounts.size(), &sampleCounts[0]);
348 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to query sample counts for format");
353 void FboTestCase::checkSampleCount (deUint32 sizedFormat, int numSamples)
355 const int minSampleCount = getMinimumSampleCount(sizedFormat);
357 if (numSamples > minSampleCount)
359 // Exceeds spec-mandated minimum - need to check.
360 const std::vector<int> supportedSampleCounts = querySampleCounts(m_context.getRenderContext().getFunctions(), sizedFormat);
362 if (std::find(supportedSampleCounts.begin(), supportedSampleCounts.end(), numSamples) == supportedSampleCounts.end())
363 throw tcu::NotSupportedError("Sample count not supported");
367 void FboTestCase::clearColorBuffer (const tcu::TextureFormat& format, const tcu::Vec4& value)
369 FboTestUtil::clearColorBuffer(*getCurrentContext(), format, value);