1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program EGL 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 Simple context construction test for EGL_KHR_create_context.
22 *//*--------------------------------------------------------------------*/
24 #include "teglCreateContextExtTests.hpp"
26 #include "tcuTestLog.hpp"
28 #include "egluNativeDisplay.hpp"
29 #include "egluNativeWindow.hpp"
30 #include "egluNativePixmap.hpp"
31 #include "egluConfigFilter.hpp"
32 #include "egluStrUtil.hpp"
33 #include "egluUtil.hpp"
34 #include "egluUnique.hpp"
36 #include "eglwLibrary.hpp"
37 #include "eglwEnums.hpp"
39 #include "gluDefs.hpp"
40 #include "gluRenderConfig.hpp"
42 #include "glwFunctions.hpp"
43 #include "glwEnums.hpp"
45 #include "deStringUtil.hpp"
46 #include "deUniquePtr.hpp"
47 #include "deSTLUtil.hpp"
63 // Make sure KHR / core values match to those in GL_ARB_robustness and GL_EXT_robustness
64 DE_STATIC_ASSERT(GL_RESET_NOTIFICATION_STRATEGY == 0x8256);
65 DE_STATIC_ASSERT(GL_LOSE_CONTEXT_ON_RESET == 0x8252);
66 DE_STATIC_ASSERT(GL_NO_RESET_NOTIFICATION == 0x8261);
68 #if !defined(GL_CONTEXT_ROBUST_ACCESS)
69 # define GL_CONTEXT_ROBUST_ACCESS 0x90F3
80 size_t getAttribListLength (const EGLint* attribList)
84 while (attribList[size] != EGL_NONE)
90 string eglContextFlagsToString (EGLint flags)
92 std::ostringstream stream;
100 if ((flags & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0)
107 stream << "EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR";
110 if ((flags & EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR) != 0)
117 stream << "EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR";
120 if ((flags & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) != 0)
125 stream << "EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR";
132 string eglProfileMaskToString (EGLint mask)
134 std::ostringstream stream;
142 if ((mask & EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR) != 0)
149 stream << "EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR";
152 if ((mask & EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR) != 0)
157 stream << "EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR";
164 const char* eglResetNotificationStrategyToString (EGLint strategy)
168 case EGL_NO_RESET_NOTIFICATION_KHR: return "EGL_NO_RESET_NOTIFICATION_KHR";
169 case EGL_LOSE_CONTEXT_ON_RESET_KHR: return "EGL_LOSE_CONTEXT_ON_RESET_KHR";
175 class CreateContextExtCase : public TestCase
178 CreateContextExtCase (EglTestContext& eglTestCtx, EGLenum api, const EGLint* attribList, const eglu::FilterList& filter, const char* name, const char* description);
179 ~CreateContextExtCase (void);
181 void executeForSurface (EGLConfig config, EGLSurface surface);
186 IterateResult iterate (void);
187 void checkRequiredExtensions (void);
188 void logAttribList (void);
189 bool validateCurrentContext (const glw::Functions& gl);
195 const eglu::FilterList m_filter;
196 vector<EGLint> m_attribList;
199 EGLDisplay m_display;
200 vector<EGLConfig> m_configs;
201 glu::ContextType m_glContextType;
204 glu::ContextType attribListToContextType (EGLenum api, const EGLint* attribList)
206 EGLint majorVersion = 1;
207 EGLint minorVersion = 0;
208 glu::ContextFlags flags = glu::ContextFlags(0);
209 glu::Profile profile = api == EGL_OPENGL_ES_API ? glu::PROFILE_ES : glu::PROFILE_CORE;
210 const EGLint* iter = attribList;
212 while ((*iter) != EGL_NONE)
216 case EGL_CONTEXT_MAJOR_VERSION_KHR:
218 majorVersion = (*iter);
222 case EGL_CONTEXT_MINOR_VERSION_KHR:
224 minorVersion = (*iter);
228 case EGL_CONTEXT_FLAGS_KHR:
231 if ((*iter & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) != 0)
232 flags = flags | glu::CONTEXT_ROBUST;
234 if ((*iter & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0)
235 flags = flags | glu::CONTEXT_DEBUG;
237 if ((*iter & EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR) != 0)
238 flags = flags | glu::CONTEXT_FORWARD_COMPATIBLE;
243 case EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR:
246 if (*iter == EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR)
247 profile = glu::PROFILE_COMPATIBILITY;
248 else if (*iter != EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR)
249 throw tcu::InternalError("Indeterminate OpenGL profile");
254 case EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR:
258 case EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT:
262 case EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT:
271 return glu::ContextType(majorVersion, minorVersion, profile, flags);
274 CreateContextExtCase::CreateContextExtCase (EglTestContext& eglTestCtx, EGLenum api, const EGLint* attribList, const eglu::FilterList& filter, const char* name, const char* description)
275 : TestCase (eglTestCtx, name, description)
279 , m_attribList (attribList, attribList + getAttribListLength(attribList))
281 , m_display (EGL_NO_DISPLAY)
282 , m_glContextType (attribListToContextType(api, attribList))
286 CreateContextExtCase::~CreateContextExtCase (void)
291 void CreateContextExtCase::init (void)
293 m_display = eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay());
294 m_configs = eglu::chooseConfigs(m_eglTestCtx.getLibrary(), m_display, m_filter);
297 void CreateContextExtCase::deinit (void)
299 m_attribList.clear();
302 if (m_display != EGL_NO_DISPLAY)
304 m_eglTestCtx.getLibrary().terminate(m_display);
305 m_display = EGL_NO_DISPLAY;
309 void CreateContextExtCase::logAttribList (void)
311 const EGLint* iter = &(m_attribList[0]);
312 std::ostringstream attribListString;
314 while ((*iter) != EGL_NONE)
318 case EGL_CONTEXT_MAJOR_VERSION_KHR:
320 attribListString << "EGL_CONTEXT_MAJOR_VERSION_KHR(EGL_CONTEXT_CLIENT_VERSION), " << (*iter) << ", ";
324 case EGL_CONTEXT_MINOR_VERSION_KHR:
326 attribListString << "EGL_CONTEXT_MINOR_VERSION_KHR, " << (*iter) << ", ";
330 case EGL_CONTEXT_FLAGS_KHR:
332 attribListString << "EGL_CONTEXT_FLAGS_KHR, " << eglContextFlagsToString(*iter) << ", ";
336 case EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR:
338 attribListString << "EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, " << eglProfileMaskToString(*iter) << ", ";
342 case EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR:
344 attribListString << "EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR, " << eglResetNotificationStrategyToString(*iter) << ", ";
348 case EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT:
350 attribListString << "EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, ";
352 if (*iter == EGL_FALSE || *iter == EGL_TRUE)
353 attribListString << (*iter ? "EGL_TRUE" : "EGL_FALSE");
355 attribListString << (*iter);
364 attribListString << "EGL_NONE";
365 m_testCtx.getLog() << TestLog::Message << "EGL attrib list: { " << attribListString.str() << " }" << TestLog::EndMessage;
368 void CreateContextExtCase::checkRequiredExtensions (void)
371 set<string> requiredExtensions;
372 vector<string> extensions = eglu::getClientExtensions(m_eglTestCtx.getLibrary(), m_display);
375 const EGLint* iter = &(m_attribList[0]);
377 while ((*iter) != EGL_NONE)
381 case EGL_CONTEXT_MAJOR_VERSION_KHR:
386 case EGL_CONTEXT_MINOR_VERSION_KHR:
388 requiredExtensions.insert("EGL_KHR_create_context");
392 case EGL_CONTEXT_FLAGS_KHR:
394 requiredExtensions.insert("EGL_KHR_create_context");
398 case EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR:
400 requiredExtensions.insert("EGL_KHR_create_context");
404 case EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR:
406 requiredExtensions.insert("EGL_KHR_create_context");
410 case EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT:
412 requiredExtensions.insert("EGL_EXT_create_context_robustness");
416 case EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT:
418 requiredExtensions.insert("EGL_EXT_create_context_robustness");
428 for (std::set<string>::const_iterator reqExt = requiredExtensions.begin(); reqExt != requiredExtensions.end(); ++reqExt)
430 if (!de::contains(extensions.begin(), extensions.end(), *reqExt))
432 m_testCtx.getLog() << TestLog::Message << "Required extension '" << (*reqExt) << "' not supported" << TestLog::EndMessage;
438 TCU_THROW(NotSupportedError, "Required extensions not supported");
441 bool checkVersionString (TestLog& log, const glw::Functions& gl, bool desktop, int major, int minor)
443 const char* const versionStr = (const char*)gl.getString(GL_VERSION);
444 const char* iter = versionStr;
446 int majorVersion = 0;
447 int minorVersion = 0;
449 // Check embedded version prefixes
452 const char* prefix = NULL;
453 const char* prefixIter = NULL;
456 prefix = "OpenGL ES-CM ";
458 prefix = "OpenGL ES ";
464 if ((*prefixIter) != (*iter))
466 log << TestLog::Message << "Invalid version string prefix. Expected '" << prefix << "'." << TestLog::EndMessage;
475 while ((*iter) && (*iter) != '.')
477 const int val = (*iter) - '0';
480 if (val < 0 || val > 9)
482 log << TestLog::Message << "Failed to parse major version number. Not a number." << TestLog::EndMessage;
487 if (majorVersion == 0 && val == 0)
489 log << TestLog::Message << "Failed to parse major version number. Begins with zero." << TestLog::EndMessage;
493 majorVersion = majorVersion * 10 + val;
501 log << TestLog::Message << "Failed to parse version. Expected '.' after major version number." << TestLog::EndMessage;
507 while ((*iter) && (*iter) != ' ' && (*iter) != '.')
509 const int val = (*iter) - '0';
512 if (val < 0 || val > 9)
514 log << TestLog::Message << "Failed to parse minor version number. Not a number." << TestLog::EndMessage;
519 if (minorVersion == 0 && val == 0)
521 // Leading zeros in minor version
522 if ((*(iter + 1)) != ' ' && (*(iter + 1)) != '.' && (*(iter + 1)) != '\0')
524 log << TestLog::Message << "Failed to parse minor version number. Leading zeros." << TestLog::EndMessage;
529 minorVersion = minorVersion * 10 + val;
535 if ((*iter) != ' ' && (*iter) != '.' && (*iter) != '\0')
540 if (majorVersion < major)
542 log << TestLog::Message << "Major version is less than required." << TestLog::EndMessage;
545 else if (majorVersion == major && minorVersion < minor)
547 log << TestLog::Message << "Minor version is less than required." << TestLog::EndMessage;
550 else if (majorVersion == major && minorVersion == minor)
553 if (major < 3 || (major == 3 && minor == 0))
555 if (majorVersion == 3 && minorVersion == 1)
557 if (glu::hasExtension(gl, glu::ApiType::core(3, 1), "GL_ARB_compatibility"))
561 log << TestLog::Message << "Required OpenGL 3.0 or earlier. Got OpenGL 3.1 without GL_ARB_compatibility." << TestLog::EndMessage;
565 else if (majorVersion > 3 || (majorVersion == 3 && minorVersion >= minor))
569 gl.getIntegerv(GL_CONTEXT_PROFILE_MASK, &profile);
570 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv()");
572 if (profile == GL_CONTEXT_COMPATIBILITY_PROFILE_BIT)
576 log << TestLog::Message << "Required OpenGL 3.0 or earlier. Got later version without compatibility profile." << TestLog::EndMessage;
585 else if (major == 3 && minor == 1)
587 if (majorVersion > 3 || (majorVersion == 3 && minorVersion >= minor))
591 gl.getIntegerv(GL_CONTEXT_PROFILE_MASK, &profile);
592 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv()");
594 if (profile == GL_CONTEXT_CORE_PROFILE_BIT)
598 log << TestLog::Message << "Required OpenGL 3.1. Got later version without core profile." << TestLog::EndMessage;
609 log << TestLog::Message << "Couldn't do any further compatibilyt checks." << TestLog::EndMessage;
615 if (majorVersion < major)
617 log << TestLog::Message << "Major version is less than required." << TestLog::EndMessage;
620 else if (majorVersion == major && minorVersion < minor)
622 log << TestLog::Message << "Minor version is less than required." << TestLog::EndMessage;
630 bool checkVersionQueries (TestLog& log, const glw::Functions& gl, int major, int minor)
632 deInt32 majorVersion = 0;
633 deInt32 minorVersion = 0;
635 gl.getIntegerv(GL_MAJOR_VERSION, &majorVersion);
636 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv()");
638 gl.getIntegerv(GL_MINOR_VERSION, &minorVersion);
639 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv()");
641 if (majorVersion < major || (majorVersion == major && minorVersion < minor))
643 if (majorVersion < major)
644 log << TestLog::Message << "glGetIntegerv(GL_MAJOR_VERSION) returned '" << majorVersion << "' expected at least '" << major << "'" << TestLog::EndMessage;
645 else if (majorVersion == major && minorVersion < minor)
646 log << TestLog::Message << "glGetIntegerv(GL_MINOR_VERSION) returned '" << minorVersion << "' expected '" << minor << "'" << TestLog::EndMessage;
656 bool CreateContextExtCase::validateCurrentContext (const glw::Functions& gl)
659 TestLog& log = m_testCtx.getLog();
660 const EGLint* iter = &(m_attribList[0]);
662 EGLint majorVersion = -1;
663 EGLint minorVersion = -1;
664 EGLint contextFlags = -1;
665 EGLint profileMask = -1;
666 EGLint notificationStrategy = -1;
667 EGLint robustAccessExt = -1;
668 EGLint notificationStrategyExt = -1;
670 while ((*iter) != EGL_NONE)
674 case EGL_CONTEXT_MAJOR_VERSION_KHR:
676 majorVersion = (*iter);
680 case EGL_CONTEXT_MINOR_VERSION_KHR:
682 minorVersion = (*iter);
686 case EGL_CONTEXT_FLAGS_KHR:
688 contextFlags = (*iter);
692 case EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR:
694 profileMask = (*iter);
698 case EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR:
700 notificationStrategy = (*iter);
704 case EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT:
706 robustAccessExt = *iter;
710 case EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT:
712 notificationStrategyExt = *iter;
721 const string version = (const char*)gl.getString(GL_VERSION);
723 log << TestLog::Message << "GL_VERSION: '" << version << "'" << TestLog::EndMessage;
725 if (majorVersion == -1)
728 if (minorVersion == -1)
731 if (m_api == EGL_OPENGL_ES_API)
733 if (!checkVersionString(log, gl, false, majorVersion, minorVersion))
736 if (majorVersion == 3)
738 if (!checkVersionQueries(log, gl, majorVersion, minorVersion))
742 else if (m_api == EGL_OPENGL_API)
744 if (!checkVersionString(log, gl, true, majorVersion, minorVersion))
747 if (majorVersion >= 3)
749 if (!checkVersionQueries(log, gl, majorVersion, minorVersion))
757 if (contextFlags != -1)
759 if (m_api == EGL_OPENGL_API && (majorVersion > 3 || (majorVersion == 3 && minorVersion >= 1)))
761 deInt32 contextFlagsGL;
763 DE_ASSERT(m_api == EGL_OPENGL_API);
765 if (contextFlags == -1)
768 gl.getIntegerv(GL_CONTEXT_FLAGS, &contextFlagsGL);
770 if (contextFlags != contextFlagsGL)
772 log << TestLog::Message << "Invalid GL_CONTEXT_FLAGS. Expected '" << eglContextFlagsToString(contextFlags) << "' got '" << eglContextFlagsToString(contextFlagsGL) << "'" << TestLog::EndMessage;
778 if (profileMask != -1 || (m_api == EGL_OPENGL_API && (majorVersion >= 3)))
780 if (profileMask == -1)
781 profileMask = EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR;
783 DE_ASSERT(m_api == EGL_OPENGL_API);
785 if (majorVersion < 3 || (majorVersion == 3 && minorVersion < 2))
787 // \note Ignore profile masks. This is not an error
791 deInt32 profileMaskGL = 0;
793 gl.getIntegerv(GL_CONTEXT_PROFILE_MASK, &profileMask);
794 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv()");
796 if (profileMask != profileMaskGL)
798 log << TestLog::Message << "Invalid GL_CONTEXT_PROFILE_MASK. Expected '" << eglProfileMaskToString(profileMask) << "' got '" << eglProfileMaskToString(profileMaskGL) << "'" << TestLog::EndMessage;
804 DE_ASSERT(notificationStrategy == -1 || notificationStrategyExt == -1);
806 if (notificationStrategy != -1 || notificationStrategyExt != -1)
808 const deInt32 expected = notificationStrategy != -1 ? notificationStrategy : notificationStrategyExt;
809 deInt32 strategy = 0;
811 gl.getIntegerv(GL_RESET_NOTIFICATION_STRATEGY, &strategy);
812 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv()");
814 if (expected == EGL_NO_RESET_NOTIFICATION && strategy != GL_NO_RESET_NOTIFICATION)
816 log << TestLog::Message << "glGetIntegerv(GL_RESET_NOTIFICATION_STRATEGY) returned '" << strategy << "', expected 'GL_NO_RESET_NOTIFICATION'" << TestLog::EndMessage;
819 else if (expected == EGL_LOSE_CONTEXT_ON_RESET && strategy != GL_LOSE_CONTEXT_ON_RESET)
821 log << TestLog::Message << "glGetIntegerv(GL_RESET_NOTIFICATION_STRATEGY) returned '" << strategy << "', expected 'GL_LOSE_CONTEXT_ON_RESET'" << TestLog::EndMessage;
826 if (robustAccessExt == EGL_TRUE)
828 if (m_api == EGL_OPENGL_API)
830 if (!glu::hasExtension(gl, glu::ApiType::core(majorVersion, minorVersion), "GL_ARB_robustness"))
832 log << TestLog::Message << "Created robustness context but it doesn't support GL_ARB_robustness." << TestLog::EndMessage;
836 else if (m_api == EGL_OPENGL_ES_API)
838 if (!glu::hasExtension(gl, glu::ApiType::es(majorVersion, minorVersion), "GL_EXT_robustness"))
840 log << TestLog::Message << "Created robustness context but it doesn't support GL_EXT_robustness." << TestLog::EndMessage;
845 if (m_api == EGL_OPENGL_API && (majorVersion > 3 || (majorVersion == 3 && minorVersion >= 1)))
847 deInt32 contextFlagsGL;
849 DE_ASSERT(m_api == EGL_OPENGL_API);
851 gl.getIntegerv(GL_CONTEXT_FLAGS, &contextFlagsGL);
853 if ((contextFlagsGL & GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT) != 0)
855 log << TestLog::Message << "Invalid GL_CONTEXT_FLAGS. GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT to be set, got '" << eglContextFlagsToString(contextFlagsGL) << "'" << TestLog::EndMessage;
859 else if (m_api == EGL_OPENGL_ES_API)
861 deUint8 robustAccessGL;
863 gl.getBooleanv(GL_CONTEXT_ROBUST_ACCESS, &robustAccessGL);
864 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetBooleanv()");
866 if (robustAccessGL != GL_TRUE)
868 log << TestLog::Message << "Invalid GL_CONTEXT_ROBUST_ACCESS returned by glGetBooleanv(). Got '" << robustAccessGL << "' expected GL_TRUE." << TestLog::EndMessage;
878 TestCase::IterateResult CreateContextExtCase::iterate (void)
880 if (m_iteration == 0)
883 checkRequiredExtensions();
886 if (m_iteration < (int)m_configs.size())
888 const Library& egl = m_eglTestCtx.getLibrary();
889 const EGLConfig config = m_configs[m_iteration];
890 const EGLint surfaceTypes = eglu::getConfigAttribInt(egl, m_display, config, EGL_SURFACE_TYPE);
891 const EGLint configId = eglu::getConfigAttribInt(egl, m_display, config, EGL_CONFIG_ID);
893 if ((surfaceTypes & EGL_PBUFFER_BIT) != 0)
895 tcu::ScopedLogSection section (m_testCtx.getLog(), ("EGLConfig ID: " + de::toString(configId) + " with PBuffer").c_str(), ("EGLConfig ID: " + de::toString(configId)).c_str());
896 const EGLint attribList[] =
902 eglu::UniqueSurface surface (egl, m_display, egl.createPbufferSurface(m_display, config, attribList));
903 EGLU_CHECK_MSG(egl, "eglCreatePbufferSurface");
905 executeForSurface(config, *surface);
907 else if ((surfaceTypes & EGL_WINDOW_BIT) != 0)
909 const eglu::NativeWindowFactory& factory = eglu::selectNativeWindowFactory(m_eglTestCtx.getNativeDisplayFactory(), m_testCtx.getCommandLine());
911 de::UniquePtr<eglu::NativeWindow> window (factory.createWindow(&m_eglTestCtx.getNativeDisplay(), m_display, config, DE_NULL, eglu::WindowParams(256, 256, eglu::parseWindowVisibility(m_testCtx.getCommandLine()))));
912 eglu::UniqueSurface surface (egl, m_display, eglu::createWindowSurface(m_eglTestCtx.getNativeDisplay(), *window, m_display, config, DE_NULL));
914 executeForSurface(config, *surface);
916 else if ((surfaceTypes & EGL_PIXMAP_BIT) != 0)
918 const eglu::NativePixmapFactory& factory = eglu::selectNativePixmapFactory(m_eglTestCtx.getNativeDisplayFactory(), m_testCtx.getCommandLine());
920 de::UniquePtr<eglu::NativePixmap> pixmap (factory.createPixmap(&m_eglTestCtx.getNativeDisplay(), m_display, config, DE_NULL, 256, 256));
921 eglu::UniqueSurface surface (egl, m_display, eglu::createPixmapSurface(m_eglTestCtx.getNativeDisplay(), *pixmap, m_display, config, DE_NULL));
923 executeForSurface(config, *surface);
925 else // No supported surface type
926 TCU_FAIL("Invalid or empty surface type bits");
933 if (m_configs.size() == 0)
935 m_testCtx.getLog() << TestLog::Message << "No supported configs found" << TestLog::EndMessage;
936 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "No supported configs found");
939 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
941 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
947 void CreateContextExtCase::executeForSurface (EGLConfig config, EGLSurface surface)
949 const Library& egl = m_eglTestCtx.getLibrary();
951 EGLU_CHECK_CALL(egl, bindAPI(m_api));
956 eglu::UniqueContext context (egl, m_display, egl.createContext(m_display, config, EGL_NO_CONTEXT, &m_attribList[0]));
957 EGLU_CHECK_MSG(egl, "eglCreateContext");
959 EGLU_CHECK_CALL(egl, makeCurrent(m_display, surface, surface, *context));
961 m_eglTestCtx.initGLFunctions(&gl, m_glContextType.getAPI());
963 if (!validateCurrentContext(gl))
966 catch (const eglu::Error& error)
968 if (error.getError() == EGL_BAD_MATCH)
969 m_testCtx.getLog() << TestLog::Message << "Context creation failed with error EGL_BAD_CONTEXT. Config doesn't support api version." << TestLog::EndMessage;
970 else if (error.getError() == EGL_BAD_CONFIG)
971 m_testCtx.getLog() << TestLog::Message << "Context creation failed with error EGL_BAD_MATCH. Context attribute compination not supported." << TestLog::EndMessage;
974 m_testCtx.getLog() << TestLog::Message << "Context creation failed with error " << eglu::getErrorStr(error.getError()) << ". Error is not result of unsupported api etc." << TestLog::EndMessage;
979 EGLU_CHECK_CALL(egl, makeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
982 class CreateContextExtGroup : public TestCaseGroup
985 CreateContextExtGroup (EglTestContext& eglTestCtx, EGLenum api, EGLint apiBit, const EGLint* attribList, const char* name, const char* description);
986 virtual ~CreateContextExtGroup (void);
992 const EGLint m_apiBit;
993 vector<EGLint> m_attribList;
996 CreateContextExtGroup::CreateContextExtGroup (EglTestContext& eglTestCtx, EGLenum api, EGLint apiBit, const EGLint* attribList, const char* name, const char* description)
997 : TestCaseGroup (eglTestCtx, name, description)
1000 , m_attribList (attribList, attribList + getAttribListLength(attribList))
1004 CreateContextExtGroup::~CreateContextExtGroup (void)
1009 template <int Red, int Green, int Blue, int Alpha>
1010 static bool colorBits (const eglu::CandidateConfig& c)
1012 return c.redSize() == Red &&
1013 c.greenSize() == Green &&
1014 c.blueSize() == Blue &&
1015 c.alphaSize() == Alpha;
1018 static bool hasDepth (const eglu::CandidateConfig& c) { return c.depthSize() > 0; }
1019 static bool noDepth (const eglu::CandidateConfig& c) { return c.depthSize() == 0; }
1020 static bool hasStencil (const eglu::CandidateConfig& c) { return c.stencilSize() > 0; }
1021 static bool noStencil (const eglu::CandidateConfig& c) { return c.stencilSize() == 0; }
1023 template <deUint32 Type>
1024 static bool renderable (const eglu::CandidateConfig& c)
1026 return (c.renderableType() & Type) == Type;
1029 static eglu::ConfigFilter getRenderableFilter (deUint32 bits)
1033 case EGL_OPENGL_ES2_BIT: return renderable<EGL_OPENGL_ES2_BIT>;
1034 case EGL_OPENGL_ES3_BIT: return renderable<EGL_OPENGL_ES3_BIT>;
1035 case EGL_OPENGL_BIT: return renderable<EGL_OPENGL_BIT>;
1038 return renderable<0>;
1042 void CreateContextExtGroup::init (void)
1047 const char* description;
1049 eglu::ConfigFilter colorFilter;
1050 eglu::ConfigFilter depthFilter;
1051 eglu::ConfigFilter stencilFilter;
1054 { "rgb565_no_depth_no_stencil", "RGB565 configs without depth or stencil", colorBits<5, 6, 5, 0>, noDepth, noStencil },
1055 { "rgb565_no_depth_stencil", "RGB565 configs with stencil and no depth", colorBits<5, 6, 5, 0>, noDepth, hasStencil },
1056 { "rgb565_depth_no_stencil", "RGB565 configs with depth and no stencil", colorBits<5, 6, 5, 0>, hasDepth, noStencil },
1057 { "rgb565_depth_stencil", "RGB565 configs with depth and stencil", colorBits<5, 6, 5, 0>, hasDepth, hasStencil },
1059 { "rgb888_no_depth_no_stencil", "RGB888 configs without depth or stencil", colorBits<8, 8, 8, 0>, noDepth, noStencil },
1060 { "rgb888_no_depth_stencil", "RGB888 configs with stencil and no depth", colorBits<8, 8, 8, 0>, noDepth, hasStencil },
1061 { "rgb888_depth_no_stencil", "RGB888 configs with depth and no stencil", colorBits<8, 8, 8, 0>, hasDepth, noStencil },
1062 { "rgb888_depth_stencil", "RGB888 configs with depth and stencil", colorBits<8, 8, 8, 0>, hasDepth, hasStencil },
1064 { "rgba4444_no_depth_no_stencil", "RGBA4444 configs without depth or stencil", colorBits<4, 4, 4, 4>, noDepth, noStencil },
1065 { "rgba4444_no_depth_stencil", "RGBA4444 configs with stencil and no depth", colorBits<4, 4, 4, 4>, noDepth, hasStencil },
1066 { "rgba4444_depth_no_stencil", "RGBA4444 configs with depth and no stencil", colorBits<4, 4, 4, 4>, hasDepth, noStencil },
1067 { "rgba4444_depth_stencil", "RGBA4444 configs with depth and stencil", colorBits<4, 4, 4, 4>, hasDepth, hasStencil },
1069 { "rgba5551_no_depth_no_stencil", "RGBA5551 configs without depth or stencil", colorBits<5, 5, 5, 1>, noDepth, noStencil },
1070 { "rgba5551_no_depth_stencil", "RGBA5551 configs with stencil and no depth", colorBits<5, 5, 5, 1>, noDepth, hasStencil },
1071 { "rgba5551_depth_no_stencil", "RGBA5551 configs with depth and no stencil", colorBits<5, 5, 5, 1>, hasDepth, noStencil },
1072 { "rgba5551_depth_stencil", "RGBA5551 configs with depth and stencil", colorBits<5, 5, 5, 1>, hasDepth, hasStencil },
1074 { "rgba8888_no_depth_no_stencil", "RGBA8888 configs without depth or stencil", colorBits<8, 8, 8, 8>, noDepth, noStencil },
1075 { "rgba8888_no_depth_stencil", "RGBA8888 configs with stencil and no depth", colorBits<8, 8, 8, 8>, noDepth, hasStencil },
1076 { "rgba8888_depth_no_stencil", "RGBA8888 configs with depth and no stencil", colorBits<8, 8, 8, 8>, hasDepth, noStencil },
1077 { "rgba8888_depth_stencil", "RGBA8888 configs with depth and stencil", colorBits<8, 8, 8, 8>, hasDepth, hasStencil }
1080 for (int groupNdx = 0; groupNdx < DE_LENGTH_OF_ARRAY(groups); groupNdx++)
1082 eglu::FilterList filter;
1084 filter << groups[groupNdx].colorFilter
1085 << groups[groupNdx].depthFilter
1086 << groups[groupNdx].stencilFilter
1087 << getRenderableFilter(m_apiBit);
1089 addChild(new CreateContextExtCase(m_eglTestCtx, m_api, &(m_attribList[0]), filter, groups[groupNdx].name, groups[groupNdx].description));
1091 // \todo [mika] Add other group
1096 CreateContextExtTests::CreateContextExtTests (EglTestContext& eglTestCtx)
1097 : TestCaseGroup(eglTestCtx, "create_context_ext", "EGL_KHR_create_context tests.")
1101 CreateContextExtTests::~CreateContextExtTests (void)
1105 void CreateContextExtTests::init (void)
1107 const size_t maxAttributeCount = 10;
1111 const char* description;
1114 EGLint attribList[maxAttributeCount];
1118 // \todo [mika] Not supported by glw
1120 { "gles_10", "Create OpenGL ES 1.0 context", EGL_OPENGL_ES_API, EGL_OPENGL_ES_BIT,
1121 { EGL_CONTEXT_MAJOR_VERSION_KHR, 1, EGL_CONTEXT_MINOR_VERSION_KHR, 0, EGL_NONE} },
1122 { "gles_11", "Create OpenGL ES 1.1 context", EGL_OPENGL_ES_API, EGL_OPENGL_ES_BIT,
1123 { EGL_CONTEXT_MAJOR_VERSION_KHR, 1, EGL_CONTEXT_MINOR_VERSION_KHR, 1, EGL_NONE } },
1126 { "gles_20", "Create OpenGL ES 2.0 context", EGL_OPENGL_ES_API, EGL_OPENGL_ES2_BIT,
1127 { EGL_CONTEXT_MAJOR_VERSION_KHR, 2, EGL_CONTEXT_MINOR_VERSION_KHR, 0, EGL_NONE } },
1129 { "gles_30", "Create OpenGL ES 3.0 context", EGL_OPENGL_ES_API, EGL_OPENGL_ES3_BIT_KHR,
1130 { EGL_CONTEXT_MAJOR_VERSION_KHR, 3, EGL_CONTEXT_MINOR_VERSION_KHR, 0, EGL_NONE} },
1132 // \todo [mika] Not supported by glw
1133 // \note [mika] Should we really test 1.x?
1134 { "gl_10", "Create OpenGL 1.0 context", EGL_OPENGL_API, EGL_OPENGL_BIT,
1135 { EGL_CONTEXT_MAJOR_VERSION_KHR, 1, EGL_CONTEXT_MINOR_VERSION_KHR, 0, EGL_NONE} },
1136 { "gl_11", "Create OpenGL 1.1 context", EGL_OPENGL_API, EGL_OPENGL_BIT,
1137 { EGL_CONTEXT_MAJOR_VERSION_KHR, 1, EGL_CONTEXT_MINOR_VERSION_KHR, 1, EGL_NONE } },
1140 { "gl_20", "Create OpenGL 2.0 context", EGL_OPENGL_API, EGL_OPENGL_BIT,
1141 { EGL_CONTEXT_MAJOR_VERSION_KHR, 2, EGL_CONTEXT_MINOR_VERSION_KHR, 0, EGL_NONE } },
1142 { "gl_21", "Create OpenGL 2.1 context", EGL_OPENGL_API, EGL_OPENGL_BIT,
1143 { EGL_CONTEXT_MAJOR_VERSION_KHR, 2, EGL_CONTEXT_MINOR_VERSION_KHR, 1, EGL_NONE } },
1146 { "gl_30", "Create OpenGL 3.0 context", EGL_OPENGL_API, EGL_OPENGL_BIT,
1147 { EGL_CONTEXT_MAJOR_VERSION_KHR, 3, EGL_CONTEXT_MINOR_VERSION_KHR, 0, EGL_NONE } },
1148 { "robust_gl_30", "Create robust OpenGL 3.0 context", EGL_OPENGL_API, EGL_OPENGL_BIT,
1149 { EGL_CONTEXT_MAJOR_VERSION_KHR, 3, EGL_CONTEXT_MINOR_VERSION_KHR, 0, EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR, EGL_NONE } },
1150 { "gl_31", "Create OpenGL 3.1 context", EGL_OPENGL_API, EGL_OPENGL_BIT,
1151 { EGL_CONTEXT_MAJOR_VERSION_KHR, 3, EGL_CONTEXT_MINOR_VERSION_KHR, 1, EGL_NONE } },
1152 { "robust_gl_31", "Create robust OpenGL 3.1 context", EGL_OPENGL_API, EGL_OPENGL_BIT,
1153 { EGL_CONTEXT_MAJOR_VERSION_KHR, 3, EGL_CONTEXT_MINOR_VERSION_KHR, 1, EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR, EGL_NONE } },
1154 { "gl_32", "Create OpenGL 3.2 context", EGL_OPENGL_API, EGL_OPENGL_BIT,
1155 { EGL_CONTEXT_MAJOR_VERSION_KHR, 3, EGL_CONTEXT_MINOR_VERSION_KHR, 2, EGL_NONE } },
1156 { "robust_gl_32", "Create robust OpenGL 3.2 context", EGL_OPENGL_API, EGL_OPENGL_BIT,
1157 { EGL_CONTEXT_MAJOR_VERSION_KHR, 3, EGL_CONTEXT_MINOR_VERSION_KHR, 2, EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR, EGL_NONE } },
1158 { "gl_33", "Create OpenGL 3.3 context", EGL_OPENGL_API, EGL_OPENGL_BIT,
1159 { EGL_CONTEXT_MAJOR_VERSION_KHR, 3, EGL_CONTEXT_MINOR_VERSION_KHR, 3, EGL_NONE } },
1160 { "robust_gl_33", "Create robust OpenGL 3.3 context", EGL_OPENGL_API, EGL_OPENGL_BIT,
1161 { EGL_CONTEXT_MAJOR_VERSION_KHR, 3, EGL_CONTEXT_MINOR_VERSION_KHR, 3, EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR, EGL_NONE } },
1164 { "gl_40", "Create OpenGL 4.0 context", EGL_OPENGL_API, EGL_OPENGL_BIT,
1165 { EGL_CONTEXT_MAJOR_VERSION_KHR, 4, EGL_CONTEXT_MINOR_VERSION_KHR, 0, EGL_NONE } },
1166 { "robust_gl_40", "Create robust OpenGL 4.0 context", EGL_OPENGL_API, EGL_OPENGL_BIT,
1167 { EGL_CONTEXT_MAJOR_VERSION_KHR, 4, EGL_CONTEXT_MINOR_VERSION_KHR, 0, EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR, EGL_NONE } },
1168 { "gl_41", "Create OpenGL 4.1 context", EGL_OPENGL_API, EGL_OPENGL_BIT,
1169 { EGL_CONTEXT_MAJOR_VERSION_KHR, 4, EGL_CONTEXT_MINOR_VERSION_KHR, 1, EGL_NONE } },
1170 { "robust_gl_41", "Create robust OpenGL 4.1 context", EGL_OPENGL_API, EGL_OPENGL_BIT,
1171 { EGL_CONTEXT_MAJOR_VERSION_KHR, 4, EGL_CONTEXT_MINOR_VERSION_KHR, 1, EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR, EGL_NONE } },
1172 { "gl_42", "Create OpenGL 4.2 context", EGL_OPENGL_API, EGL_OPENGL_BIT,
1173 { EGL_CONTEXT_MAJOR_VERSION_KHR, 4, EGL_CONTEXT_MINOR_VERSION_KHR, 2, EGL_NONE } },
1174 { "robust_gl_42", "Create robust OpenGL 4.2 context", EGL_OPENGL_API, EGL_OPENGL_BIT,
1175 { EGL_CONTEXT_MAJOR_VERSION_KHR, 4, EGL_CONTEXT_MINOR_VERSION_KHR, 2, EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR, EGL_NONE } },
1176 { "gl_43", "Create OpenGL 4.3 context", EGL_OPENGL_API, EGL_OPENGL_BIT,
1177 { EGL_CONTEXT_MAJOR_VERSION_KHR, 4, EGL_CONTEXT_MINOR_VERSION_KHR, 3, EGL_NONE } },
1178 { "robust_gl_43", "Create robust OpenGL 4.3 context", EGL_OPENGL_API, EGL_OPENGL_BIT,
1179 { EGL_CONTEXT_MAJOR_VERSION_KHR, 4, EGL_CONTEXT_MINOR_VERSION_KHR, 3, EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR, EGL_NONE } },
1181 // Robust contexts with EGL_EXT_create_context_robustness
1182 { "robust_gles_2_ext", "Create robust OpenGL ES 2.0 context with EGL_EXT_create_context_robustness.", EGL_OPENGL_ES_API, EGL_OPENGL_ES2_BIT,
1183 { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_TRUE, EGL_NONE } },
1184 { "robust_gles_3_ext", "Create robust OpenGL ES 3.0 context with EGL_EXT_create_context_robustness.", EGL_OPENGL_ES_API, EGL_OPENGL_ES3_BIT_KHR,
1185 { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_TRUE, EGL_NONE } },
1187 // glu/glw doesn't support any version of OpenGL and EGL doesn't allow use of EGL_CONTEXT_CLIENT_VERSION with OpenGL and doesn't define which OpenGL version should be returned.
1188 { "robust_gl_ext", "Create robust OpenGL context with EGL_EXT_create_context_robustness.", EGL_OPENGL_API, EGL_OPENGL_BIT,
1189 { EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_TRUE, EGL_NONE } }
1193 for (int groupNdx = 0; groupNdx < DE_LENGTH_OF_ARRAY(groupList); groupNdx++)
1194 addChild(new CreateContextExtGroup(m_eglTestCtx, groupList[groupNdx].api, groupList[groupNdx].apiBit, groupList[groupNdx].attribList, groupList[groupNdx].name, groupList[groupNdx].description));