diff --git a/samples/sample_util/SampleApplication.cpp b/samples/sample_util/SampleApplication.cpp index 2c5e33c5e..c4cf06202 100644 --- a/samples/sample_util/SampleApplication.cpp +++ b/samples/sample_util/SampleApplication.cpp @@ -6,6 +6,7 @@ #include "SampleApplication.h" +#include "common/debug.h" #include "util/EGLWindow.h" #include "util/gles_loader_autogen.h" #include "util/random_utils.h" @@ -15,9 +16,14 @@ #include #include +#if defined(ANGLE_PLATFORM_WINDOWS) +# include "util/windows/WGLWindow.h" +#endif // defined(ANGLE_PLATFORM_WINDOWS) + namespace { const char *kUseAngleArg = "--use-angle="; +const char *kUseGlArg = "--use-gl=native"; using DisplayTypeInfo = std::pair; @@ -71,29 +77,56 @@ SampleApplication::SampleApplication(std::string name, mWidth(width), mHeight(height), mRunning(false), + mGLWindow(nullptr), mEGLWindow(nullptr), - mOSWindow(nullptr) + mOSWindow(nullptr), + mDriverType(angle::GLESDriverType::AngleEGL) { mPlatformParams.renderer = EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE; + bool useNativeGL = false; - if (argc > 1 && strncmp(argv[1], kUseAngleArg, strlen(kUseAngleArg)) == 0) + for (int argIndex = 1; argIndex < argc; argIndex++) { - const char *arg = argv[1] + strlen(kUseAngleArg); - mPlatformParams.renderer = GetDisplayTypeFromArg(arg); - mPlatformParams.deviceType = GetDeviceTypeFromArg(arg); + if (strncmp(argv[argIndex], kUseAngleArg, strlen(kUseAngleArg)) == 0) + { + const char *arg = argv[argIndex] + strlen(kUseAngleArg); + mPlatformParams.renderer = GetDisplayTypeFromArg(arg); + mPlatformParams.deviceType = GetDeviceTypeFromArg(arg); + } + + if (strncmp(argv[argIndex], kUseGlArg, strlen(kUseGlArg)) == 0) + { + useNativeGL = true; + } } - // Load EGL library so we can initialize the display. - mEntryPointsLib.reset( - angle::OpenSharedLibrary(ANGLE_EGL_LIBRARY_NAME, angle::SearchType::ApplicationDir)); + mOSWindow = OSWindow::New(); - mEGLWindow = EGLWindow::New(glesMajorVersion, glesMinorVersion); - mOSWindow = OSWindow::New(); + // Load EGL library so we can initialize the display. + if (useNativeGL) + { +#if defined(ANGLE_PLATFORM_WINDOWS) + mGLWindow = WGLWindow::New(glesMajorVersion, glesMinorVersion); + mEntryPointsLib.reset(angle::OpenSharedLibrary("opengl32", angle::SearchType::SystemDir)); + mDriverType = angle::GLESDriverType::SystemWGL; +#else + mGLWindow = EGLWindow::New(glesMajorVersion, glesMinorVersion); + mEntryPointsLib.reset( + angle::OpenSharedLibraryWithExtension(angle::GetNativeEGLLibraryNameWithExtension())); + mDriverType = angle::GLESDriverType::SystemEGL; +#endif // defined(ANGLE_PLATFORM_WINDOWS) + } + else + { + mGLWindow = mEGLWindow = EGLWindow::New(glesMajorVersion, glesMinorVersion); + mEntryPointsLib.reset( + angle::OpenSharedLibrary(ANGLE_EGL_LIBRARY_NAME, angle::SearchType::ApplicationDir)); + } } SampleApplication::~SampleApplication() { - EGLWindow::Delete(&mEGLWindow); + GLWindowBase::Delete(&mGLWindow); OSWindow::Delete(&mOSWindow); } @@ -110,7 +143,7 @@ void SampleApplication::draw() {} void SampleApplication::swap() { - mEGLWindow->swap(); + mGLWindow->swap(); } OSWindow *SampleApplication::getWindow() const @@ -120,21 +153,25 @@ OSWindow *SampleApplication::getWindow() const EGLConfig SampleApplication::getConfig() const { + ASSERT(mEGLWindow); return mEGLWindow->getConfig(); } EGLDisplay SampleApplication::getDisplay() const { + ASSERT(mEGLWindow); return mEGLWindow->getDisplay(); } EGLSurface SampleApplication::getSurface() const { + ASSERT(mEGLWindow); return mEGLWindow->getSurface(); } EGLContext SampleApplication::getContext() const { + ASSERT(mEGLWindow); return mEGLWindow->getContext(); } @@ -155,20 +192,18 @@ int SampleApplication::run() configParams.depthBits = 24; configParams.stencilBits = 8; - if (!mEGLWindow->initializeGL(mOSWindow, mEntryPointsLib.get(), angle::GLESDriverType::AngleEGL, - mPlatformParams, configParams)) + if (!mGLWindow->initializeGL(mOSWindow, mEntryPointsLib.get(), mDriverType, mPlatformParams, + configParams)) { return -1; } // Disable vsync - if (!mEGLWindow->setSwapInterval(0)) + if (!mGLWindow->setSwapInterval(0)) { return -1; } - angle::LoadGLES(eglGetProcAddress); - mRunning = true; int result = 0; @@ -223,7 +258,7 @@ int SampleApplication::run() } destroy(); - mEGLWindow->destroyGL(); + mGLWindow->destroyGL(); mOSWindow->destroy(); return result; diff --git a/samples/sample_util/SampleApplication.h b/samples/sample_util/SampleApplication.h index 9206f154f..be1e9d617 100644 --- a/samples/sample_util/SampleApplication.h +++ b/samples/sample_util/SampleApplication.h @@ -19,6 +19,7 @@ #include "util/egl_loader_autogen.h" class EGLWindow; +class GLWindowBase; namespace angle { @@ -66,8 +67,10 @@ class SampleApplication bool mRunning; Timer mTimer; + GLWindowBase *mGLWindow; EGLWindow *mEGLWindow; OSWindow *mOSWindow; + angle::GLESDriverType mDriverType; EGLPlatformParameters mPlatformParams; diff --git a/src/tests/test_utils/angle_test_configs.cpp b/src/tests/test_utils/angle_test_configs.cpp index ffe7b593f..91694ea9b 100644 --- a/src/tests/test_utils/angle_test_configs.cpp +++ b/src/tests/test_utils/angle_test_configs.cpp @@ -784,18 +784,4 @@ PlatformParameters ES3_EGL() { return PlatformParameters(3, 0, GLESDriverType::SystemEGL); } - -const char *GetNativeEGLLibraryNameWithExtension() -{ -#if defined(ANGLE_PLATFORM_ANDROID) - return "libEGL.so"; -#elif defined(ANGLE_PLATFORM_LINUX) - return "libEGL.so.1"; -#elif defined(ANGLE_PLATFORM_WINDOWS) - return "libEGL.dll"; -#else - return "unknown_libegl"; -#endif -} - } // namespace angle diff --git a/util/posix/test_utils_posix.cpp b/util/posix/test_utils_posix.cpp index b1ec61ce9..2c2afafd1 100644 --- a/util/posix/test_utils_posix.cpp +++ b/util/posix/test_utils_posix.cpp @@ -433,4 +433,15 @@ int NumberOfProcessors() return static_cast(res); } + +const char *GetNativeEGLLibraryNameWithExtension() +{ +#if defined(ANGLE_PLATFORM_ANDROID) + return "libEGL.so"; +#elif defined(ANGLE_PLATFORM_LINUX) + return "libEGL.so.1"; +#else + return "unknown_libegl"; +#endif +} } // namespace angle diff --git a/util/test_utils.h b/util/test_utils.h index 43e996f21..6b821916d 100644 --- a/util/test_utils.h +++ b/util/test_utils.h @@ -120,6 +120,7 @@ Process *LaunchProcess(const std::vector &args, int NumberOfProcessors(); +const char *GetNativeEGLLibraryNameWithExtension(); } // namespace angle #endif // UTIL_TEST_UTILS_H_ diff --git a/util/windows/test_utils_win.cpp b/util/windows/test_utils_win.cpp index bdaf7e8ea..d7f5ef45d 100644 --- a/util/windows/test_utils_win.cpp +++ b/util/windows/test_utils_win.cpp @@ -444,4 +444,9 @@ bool DeleteFile(const char *path) return !!::DeleteFileA(path) ? true : ReturnSuccessOnNotFound(); } + +const char *GetNativeEGLLibraryNameWithExtension() +{ + return "libEGL.dll"; +} } // namespace angle