1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 3.1 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 "es31fFboTestCase.hpp"
25 #include "es31fFboTestUtil.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 log << TestLog::Message << "Rendering with GL driver" << TestLog::EndMessage;
82 // Render using GLES3.1
85 sglr::GLContext context(renderCtx, log, 0, tcu::IVec4(x, y, width, height));
90 deUint32 err = glGetError();
91 if (err != GL_NO_ERROR)
92 throw glu::Error(err, glu::getErrorStr(err).toString().c_str(), DE_NULL, __FILE__, __LINE__);
96 catch (const FboTestUtil::FboIncompleteException& e)
98 if (e.getReason() == GL_FRAMEBUFFER_UNSUPPORTED)
101 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not supported");
108 log << TestLog::Message << "Rendering reference image" << TestLog::EndMessage;
112 sglr::ReferenceContextBuffers buffers (tcu::PixelFormat(8,8,8,renderTarget.getPixelFormat().alphaBits?8:0), renderTarget.getDepthBits(), renderTarget.getStencilBits(), width, height);
113 sglr::ReferenceContext context (sglr::ReferenceContextLimits(renderCtx), buffers.getColorbuffer(), buffers.getDepthbuffer(), buffers.getStencilbuffer());
115 setContext(&context);
120 bool isOk = compare(reference, result);
121 m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL,
122 isOk ? "Pass" : "Image comparison failed");
126 bool FboTestCase::compare (const tcu::Surface& reference, const tcu::Surface& result)
128 return tcu::fuzzyCompare(m_testCtx.getLog(), "Result", "Image comparison result", reference, result, 0.05f, tcu::COMPARE_LOG_RESULT);
131 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)
133 FboTestUtil::readPixels(*getCurrentContext(), dst, x, y, width, height, format, scale, bias);
136 void FboTestCase::readPixels (tcu::Surface& dst, int x, int y, int width, int height)
138 getCurrentContext()->readPixels(dst, x, y, width, height);
141 void FboTestCase::checkFramebufferStatus (deUint32 target)
143 deUint32 status = glCheckFramebufferStatus(target);
144 if (status != GL_FRAMEBUFFER_COMPLETE)
145 throw FboTestUtil::FboIncompleteException(status, __FILE__, __LINE__);
148 void FboTestCase::checkError (void)
150 deUint32 err = glGetError();
151 if (err != GL_NO_ERROR)
152 throw glu::Error((int)err, (string("Got ") + glu::getErrorStr(err).toString()).c_str(), DE_NULL, __FILE__, __LINE__);
155 static bool isRequiredFormat (deUint32 format, glu::RenderContext& renderContext)
157 const bool supportsES32 = glu::contextSupports(renderContext.getType(), glu::ApiType::es(3, 2));
160 // Color-renderable formats
168 case GL_SRGB8_ALPHA8:
192 case GL_DEPTH_COMPONENT32F:
193 case GL_DEPTH_COMPONENT24:
194 case GL_DEPTH_COMPONENT16:
197 // Depth+stencil formats
198 case GL_DEPTH32F_STENCIL8:
199 case GL_DEPTH24_STENCIL8:
203 case GL_STENCIL_INDEX8:
208 case GL_R11F_G11F_B10F:
221 static std::vector<std::string> getEnablingExtensions (deUint32 format, glu::RenderContext& renderContext)
223 const bool supportsES32 = glu::contextSupports(renderContext.getType(), glu::ApiType::es(3, 2));
224 std::vector<std::string> out;
226 DE_ASSERT(!isRequiredFormat(format, renderContext));
231 out.push_back("GL_EXT_color_buffer_half_float");
235 out.push_back("GL_EXT_color_buffer_float");
242 out.push_back("GL_EXT_color_buffer_half_float");
246 case GL_R11F_G11F_B10F:
250 out.push_back("GL_EXT_color_buffer_float");
260 static bool isAnyExtensionSupported (Context& context, const std::vector<std::string>& requiredExts)
262 for (std::vector<std::string>::const_iterator iter = requiredExts.begin(); iter != requiredExts.end(); iter++)
264 const std::string& extension = *iter;
266 if (context.getContextInfo().isExtensionSupported(extension.c_str()))
273 void FboTestCase::checkFormatSupport (deUint32 sizedFormat)
275 const bool isCoreFormat = isRequiredFormat(sizedFormat, m_context.getRenderContext());
276 const std::vector<std::string> requiredExts = (!isCoreFormat) ? getEnablingExtensions(sizedFormat, m_context.getRenderContext()) : std::vector<std::string>();
278 // Check that we don't try to use invalid formats.
279 DE_ASSERT(isCoreFormat || !requiredExts.empty());
281 if (!requiredExts.empty() && !isAnyExtensionSupported(m_context, requiredExts))
282 throw tcu::NotSupportedError("Format not supported");
285 static int getMinimumSampleCount (deUint32 format)
297 case GL_SRGB8_ALPHA8:
318 case GL_DEPTH_COMPONENT32F:
319 case GL_DEPTH_COMPONENT24:
320 case GL_DEPTH_COMPONENT16:
321 case GL_DEPTH32F_STENCIL8:
322 case GL_DEPTH24_STENCIL8:
323 case GL_STENCIL_INDEX8:
326 // GL_EXT_color_buffer_float
327 case GL_R11F_G11F_B10F:
338 // GL_EXT_color_buffer_half_float
343 DE_FATAL("Unknown format");
348 static std::vector<int> querySampleCounts (const glw::Functions& gl, deUint32 format)
350 int numSampleCounts = 0;
351 std::vector<int> sampleCounts;
353 gl.getInternalformativ(GL_RENDERBUFFER, format, GL_NUM_SAMPLE_COUNTS, 1, &numSampleCounts);
355 if (numSampleCounts > 0)
357 sampleCounts.resize(numSampleCounts);
358 gl.getInternalformativ(GL_RENDERBUFFER, format, GL_SAMPLES, (glw::GLsizei)sampleCounts.size(), &sampleCounts[0]);
361 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to query sample counts for format");
366 void FboTestCase::checkSampleCount (deUint32 sizedFormat, int numSamples)
368 const int minSampleCount = getMinimumSampleCount(sizedFormat);
370 if (numSamples > minSampleCount)
372 // Exceeds spec-mandated minimum - need to check.
373 const std::vector<int> supportedSampleCounts = querySampleCounts(m_context.getRenderContext().getFunctions(), sizedFormat);
375 if (std::find(supportedSampleCounts.begin(), supportedSampleCounts.end(), numSamples) == supportedSampleCounts.end())
376 throw tcu::NotSupportedError("Sample count not supported");
380 void FboTestCase::clearColorBuffer (const tcu::TextureFormat& format, const tcu::Vec4& value)
382 FboTestUtil::clearColorBuffer(*getCurrentContext(), format, value);