mirror of https://github.com/mosra/magnum.git
Browse Source
The whole class was a bad idea, why create something that's 99% similar to another application and has just one platform-specific workaround? Of course it resulted in this code being completely untested and not even built anywhere, because it served a tiny insignificant use case. To avoid losing all the code, I did my best in attempting to merge this into the WindowlessEglApplication. But since, again, EGL isn't really used on any Windows platform, I can't even say it builds properly. Maybe not even the original code built.pull/580/head
19 changed files with 103 additions and 921 deletions
@ -1,55 +0,0 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||
2020, 2021, 2022 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include <Corrade/Utility/Arguments.h> |
||||
|
||||
#include "Magnum/Platform/WindowlessWindowsEglApplication.h" |
||||
|
||||
namespace Magnum { namespace Platform { namespace Test { namespace { |
||||
|
||||
struct WindowlessWindowsEglApplicationTest: Platform::WindowlessApplication { |
||||
explicit WindowlessWindowsEglApplicationTest(const Arguments& arguments); |
||||
int exec() override { return 0; } |
||||
}; |
||||
|
||||
WindowlessWindowsEglApplicationTest::WindowlessWindowsEglApplicationTest(const Arguments& arguments): Platform::WindowlessApplication{arguments, NoCreate} { |
||||
Utility::Arguments args; |
||||
args.addSkippedPrefix("magnum", "engine-specific options") |
||||
.addBooleanOption("quiet").setHelp("quiet", "like --magnum-log quiet, but specified via a Context::Configuration instead") |
||||
.addBooleanOption("gpu-validation").setHelp("gpu-validation", "like --magnum-gpu-validation, but specified via a Context::Configuration instead") |
||||
.parse(arguments.argc, arguments.argv); |
||||
|
||||
Configuration conf; |
||||
if(args.isSet("quiet")) |
||||
conf.addFlags(Configuration::Flag::QuietLog); |
||||
/* No verbose logs in this app */ |
||||
if(args.isSet("gpu-validation")) |
||||
conf.addFlags(Configuration::Flag::GpuValidation); |
||||
createContext(conf); |
||||
} |
||||
|
||||
}}}} |
||||
|
||||
MAGNUM_WINDOWLESSAPPLICATION_MAIN(Magnum::Platform::Test::WindowlessWindowsEglApplicationTest) |
||||
@ -1,238 +0,0 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||
2020, 2021, 2022 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "WindowlessWindowsEglApplication.h" |
||||
|
||||
#include <Corrade/Utility/Assert.h> |
||||
#include <Corrade/Utility/Debug.h> |
||||
|
||||
#include "Magnum/GL/Version.h" |
||||
|
||||
#include "Implementation/Egl.h" |
||||
|
||||
#ifndef EGL_KHR_create_context_no_error |
||||
#define EGL_CONTEXT_OPENGL_NO_ERROR_KHR 0x31B3 |
||||
#endif |
||||
|
||||
namespace Magnum { namespace Platform { |
||||
|
||||
WindowlessWindowsEglContext::WindowlessWindowsEglContext(const Configuration& configuration, GLContext* const magnumContext) { |
||||
/** @todo device selection and skipping of eglInitialize()/Terminate() the
|
||||
same way as with WindowlessEglContext */ |
||||
|
||||
/* Register the window class (if not yet done) */ |
||||
WNDCLASSW wc; |
||||
if(!GetClassInfoW(GetModuleHandleW(nullptr), L"Magnum Windowless Application", &wc)) { |
||||
wc = WNDCLASSW{ |
||||
0, |
||||
DefWindowProcW, |
||||
0, |
||||
0, |
||||
GetModuleHandleW(nullptr), |
||||
nullptr, |
||||
nullptr, |
||||
HBRUSH(COLOR_BACKGROUND), |
||||
nullptr, |
||||
L"Magnum Windowless Application" |
||||
}; |
||||
|
||||
if(!RegisterClassW(&wc)) { |
||||
Error() << "Platform::WindowlessWglContext: cannot create window class:" << GetLastError(); |
||||
return; |
||||
} |
||||
} |
||||
|
||||
/* Create the window */ |
||||
_window = CreateWindowW(wc.lpszClassName, L"Magnum Windowless Application", |
||||
WS_OVERLAPPEDWINDOW, 0, 0, 32, 32, 0, 0, wc.hInstance, 0); |
||||
|
||||
/* Initialize */ |
||||
_display = eglGetDisplay(GetDC(_window)); |
||||
if(!eglInitialize(_display, nullptr, nullptr)) { |
||||
Error() << "Platform::WindowlessWindowsEglApplication::tryCreateContext(): cannot initialize EGL:" << Implementation::eglErrorString(eglGetError()); |
||||
return; |
||||
} |
||||
|
||||
const EGLenum api = |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
EGL_OPENGL_API |
||||
#else |
||||
EGL_OPENGL_ES_API |
||||
#endif |
||||
; |
||||
if(!eglBindAPI(api)) { |
||||
Error() << "Platform::WindowlessWindowsEglApplication::tryCreateContext(): cannot bind EGL API:" << Implementation::eglErrorString(eglGetError()); |
||||
return; |
||||
} |
||||
|
||||
/* Choose EGL config */ |
||||
static const EGLint attribs[] = { |
||||
EGL_RED_SIZE, 1, |
||||
EGL_GREEN_SIZE, 1, |
||||
EGL_BLUE_SIZE, 1, |
||||
EGL_DEPTH_SIZE, 1, |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, |
||||
#elif defined(MAGNUM_TARGET_GLES3) |
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT, |
||||
#elif defined(MAGNUM_TARGET_GLES2) |
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
||||
#else |
||||
#error unsupported OpenGL edition |
||||
#endif |
||||
EGL_NONE |
||||
}; |
||||
EGLint configCount; |
||||
EGLConfig config; |
||||
if(!eglChooseConfig(_display, attribs, &config, 1, &configCount)) { |
||||
Error() << "Platform::WindowlessWindowsEglApplication::tryCreateContext(): cannot get EGL visual config:" << Implementation::eglErrorString(eglGetError()); |
||||
return; |
||||
} |
||||
|
||||
if(!configCount) { |
||||
Error() << "Platform::WindowlessWindowsEglApplication::tryCreateContext(): no matching EGL visual config available"; |
||||
return; |
||||
} |
||||
|
||||
/* Request debug context if GpuValidation is enabled either via the
|
||||
configuration or via command-line */ |
||||
Configuration::Flags flags = configuration.flags(); |
||||
if((flags & Configuration::Flag::GpuValidation) || (magnumContext && magnumContext->configurationFlags() & GL::Context::Configuration::Flag::GpuValidation)) |
||||
flags |= Configuration::Flag::Debug; |
||||
else if((flags & Configuration::Flag::GpuValidationNoError) || (magnumContext && magnumContext->configurationFlags() & GL::Context::Configuration::Flag::GpuValidationNoError)) |
||||
flags |= Configuration::Flag::NoError; |
||||
|
||||
/** @todo needs a growable DynamicArray with disabled alloc or somesuch */ |
||||
EGLint attributes[7] = { |
||||
#ifdef MAGNUM_TARGET_GLES |
||||
EGL_CONTEXT_CLIENT_VERSION, |
||||
#ifdef MAGNUM_TARGET_GLES3 |
||||
3, |
||||
#elif defined(MAGNUM_TARGET_GLES2) |
||||
2, |
||||
#else |
||||
#error unsupported OpenGL ES version |
||||
#endif |
||||
#endif |
||||
/* Mask out the upper 32bits used for other flags */ |
||||
EGL_CONTEXT_FLAGS_KHR, EGLint(UnsignedLong(flags) & 0xffffffffu), |
||||
|
||||
/* The rest is added optionally */ |
||||
EGL_NONE, EGL_NONE, /* EGL_CONTEXT_OPENGL_NO_ERROR_KHR */ |
||||
EGL_NONE |
||||
}; |
||||
|
||||
std::size_t nextAttribute = 4; |
||||
CORRADE_INTERNAL_ASSERT(attributes[nextAttribute] == EGL_NONE); |
||||
|
||||
if(flags & Configuration::Flag::NoError) { |
||||
attributes[nextAttribute++] = EGL_CONTEXT_OPENGL_NO_ERROR_KHR; |
||||
attributes[nextAttribute++] = true; |
||||
} |
||||
|
||||
CORRADE_INTERNAL_ASSERT(nextAttribute < Containers::arraySize(attributes)); |
||||
|
||||
if(!(_context = eglCreateContext(_display, config, configuration.sharedContext(), attributes))) { |
||||
Error() << "Platform::WindowlessWindowsEglContext: cannot create EGL context:" << Implementation::eglErrorString(eglGetError()); |
||||
return; |
||||
} |
||||
|
||||
if(!(_surface = eglCreateWindowSurface(_display, config, _window, nullptr))) |
||||
Error() << "Platform::WindowlessWindowsEglContext: cannot create window surface:" << Implementation::eglErrorString(eglGetError()); |
||||
} |
||||
|
||||
WindowlessWindowsEglContext::WindowlessWindowsEglContext(WindowlessWindowsEglContext&& other) noexcept: _window{other._window}, _display{other._display}, _surface{other._surface}, _context{other._context} { |
||||
other._window = {}; |
||||
other._display = {}; |
||||
other._surface = {}; |
||||
other._context = {}; |
||||
} |
||||
|
||||
WindowlessWindowsEglContext::~WindowlessWindowsEglContext() { |
||||
if(_context) eglDestroyContext(_display, _context); |
||||
if(_surface) eglDestroySurface(_display, _surface); |
||||
if(_display) eglTerminate(_display); |
||||
if(_window) DestroyWindow(_window); |
||||
} |
||||
|
||||
WindowlessWindowsEglContext& WindowlessWindowsEglContext::operator=(WindowlessWindowsEglContext&& other) noexcept { |
||||
using std::swap; |
||||
swap(other._window, _window); |
||||
swap(other._display, _display); |
||||
swap(other._surface, _surface); |
||||
swap(other._context, _context); |
||||
return *this; |
||||
} |
||||
|
||||
bool WindowlessWindowsEglContext::makeCurrent() { |
||||
if(eglMakeCurrent(_display, _surface, _surface, _context)) |
||||
return true; |
||||
|
||||
Error() << "Platform::WindowlessWindowsEglContext::makeCurrent(): cannot make context current:" << GetLastError(); |
||||
return false; |
||||
} |
||||
|
||||
bool WindowlessWindowsEglContext::release() { |
||||
if(eglMakeCurrent(_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) |
||||
return true; |
||||
|
||||
Error() << "Platform::WindowlessWindowsEglApplication::release(): cannot release current context:" << GetLastError(); |
||||
return false; |
||||
} |
||||
|
||||
WindowlessWindowsEglContext::Configuration::Configuration() { |
||||
GL::Context::Configuration::addFlags(GL::Context::Configuration::Flag::Windowless); |
||||
} |
||||
|
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
WindowlessWindowsEglApplication::WindowlessWindowsEglApplication(const Arguments& arguments): WindowlessWindowsEglApplication{arguments, Configuration{}} {} |
||||
#endif |
||||
|
||||
WindowlessWindowsEglApplication::WindowlessWindowsEglApplication(const Arguments& arguments, const Configuration& configuration): WindowlessWindowsEglApplication{arguments, NoCreate} { |
||||
createContext(configuration); |
||||
} |
||||
|
||||
WindowlessWindowsEglApplication::WindowlessWindowsEglApplication(const Arguments& arguments, NoCreateT): _glContext{NoCreate}, _context{NoCreate, arguments.argc, arguments.argv} {} |
||||
|
||||
void WindowlessWindowsEglApplication::createContext() { createContext({}); } |
||||
|
||||
void WindowlessWindowsEglApplication::createContext(const Configuration& configuration) { |
||||
if(!tryCreateContext(configuration)) std::exit(1); |
||||
} |
||||
|
||||
bool WindowlessWindowsEglApplication::tryCreateContext(const Configuration& configuration) { |
||||
CORRADE_ASSERT(_context.version() == Version::None, "Platform::WindowlessWindowsEglApplication::tryCreateContext(): context already created", false); |
||||
|
||||
WindowlessWindowsEglContext glContext{configuration, &_context}; |
||||
if(!glContext.isCreated() || !glContext.makeCurrent() || !_context.tryCreate(configuration)) |
||||
return false; |
||||
|
||||
_glContext = std::move(glContext); |
||||
return true; |
||||
} |
||||
|
||||
WindowlessWindowsEglApplication::~WindowlessWindowsEglApplication() = default; |
||||
|
||||
}} |
||||
@ -1,538 +0,0 @@
|
||||
#ifndef Magnum_Platform_WindowlessWindowsEglApplication_h |
||||
#define Magnum_Platform_WindowlessWindowsEglApplication_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||
2020, 2021, 2022 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
/** @file
|
||||
* @brief Class @ref Magnum::Platform::WindowlessWindowsEglApplication, @ref Magnum::Platform::WindowlessWindowsEglContext, macro @ref MAGNUM_WINDOWLESSWINDOWSEGLAPPLICATION_MAIN() |
||||
*/ |
||||
|
||||
#include "Magnum/configure.h" |
||||
|
||||
#ifdef MAGNUM_TARGET_GL |
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
#define WIN32_LEAN_AND_MEAN 1 |
||||
#define VC_EXTRALEAN |
||||
#endif |
||||
#include <windows.h> |
||||
#include <EGL/egl.h> |
||||
#include <EGL/eglext.h> |
||||
#include <Corrade/Containers/EnumSet.h> |
||||
|
||||
#include "Magnum/Magnum.h" |
||||
#include "Magnum/Tags.h" |
||||
#include "Magnum/Platform/GLContext.h" |
||||
|
||||
namespace Magnum { namespace Platform { |
||||
|
||||
/**
|
||||
@brief Windowless Windows/EGL context |
||||
|
||||
@m_keywords{WindowlessGLContext EGL} |
||||
|
||||
GL context using pure WINAPI and EGL, used in @ref WindowlessWindowsEglApplication. |
||||
|
||||
Meant to be used when there is a need to manage (multiple) GL contexts |
||||
manually. See @ref platform-windowless-contexts for more information. If no |
||||
other application header is included, this class is also aliased to |
||||
@cpp Platform::WindowlessGLContext @ce. |
||||
|
||||
@note This class is available only if Magnum is compiled with |
||||
@ref MAGNUM_TARGET_GL enabled (done by default). See @ref building-features |
||||
for more information. |
||||
*/ |
||||
class WindowlessWindowsEglContext { |
||||
public: |
||||
class Configuration; |
||||
|
||||
/**
|
||||
* @brief Constructor |
||||
* @param configuration Context configuration |
||||
* @param context Optional Magnum context instance constructed |
||||
* using @ref NoCreate to manage driver workarounds |
||||
* |
||||
* Once the context is created, make it current using |
||||
* @ref makeCurrent() and create @ref Platform::GLContext instance to |
||||
* be able to use Magnum. |
||||
* @see @ref isCreated() |
||||
*/ |
||||
explicit WindowlessWindowsEglContext(const Configuration& configuration, GLContext* context = nullptr); |
||||
|
||||
/**
|
||||
* @brief Construct without creating the context |
||||
* |
||||
* Move a instance with created context over to make it usable. |
||||
*/ |
||||
explicit WindowlessWindowsEglContext(NoCreateT) {} |
||||
|
||||
/** @brief Copying is not allowed */ |
||||
WindowlessWindowsEglContext(const WindowlessWindowsEglContext&) = delete; |
||||
|
||||
/** @brief Move constructor */ |
||||
WindowlessWindowsEglContext(WindowlessWindowsEglContext&& other) noexcept; |
||||
|
||||
/** @brief Copying is not allowed */ |
||||
WindowlessWindowsEglContext& operator=(const WindowlessWindowsEglContext&) = delete; |
||||
|
||||
/** @brief Move assignment */ |
||||
WindowlessWindowsEglContext& operator=(WindowlessWindowsEglContext&& other) noexcept; |
||||
|
||||
/**
|
||||
* @brief Destructor |
||||
* |
||||
* Destroys the context, if any. |
||||
*/ |
||||
~WindowlessWindowsEglContext(); |
||||
|
||||
/** @brief Whether the context is created */ |
||||
bool isCreated() const { return _context; } |
||||
|
||||
/**
|
||||
* @brief Make the context current |
||||
* |
||||
* Prints error message and returns @cpp false @ce on failure, |
||||
* otherwise returns @cpp true @ce. If the context is current on |
||||
* another thread, you have to @ref release() it there first --- an |
||||
* OpenGL context can't be current in multiple threads at the same |
||||
* time. |
||||
*/ |
||||
bool makeCurrent(); |
||||
|
||||
/**
|
||||
* @brief Release current context |
||||
* @m_since_latest |
||||
* |
||||
* Releases a context previously made current using @ref makeCurrent(). |
||||
* Prints error message and returns @cpp false @ce on failure, |
||||
* otherwise returns @cpp true @ce. |
||||
*/ |
||||
bool release(); |
||||
|
||||
/**
|
||||
* @brief Underlying OpenGL context |
||||
* @m_since{2020,06} |
||||
* |
||||
* Use in case you need to call EGL functionality directly or in order |
||||
* to create a shared context. Returns @cpp nullptr @ce in case the |
||||
* context was not created yet. |
||||
* @see @ref Configuration::setSharedContext() |
||||
*/ |
||||
EGLContext glContext() { return _context; } |
||||
|
||||
private: |
||||
HWND _window{}; |
||||
EGLDisplay _display{}; |
||||
EGLSurface _surface{}; |
||||
EGLContext _context{}; |
||||
}; |
||||
|
||||
/**
|
||||
@brief Configuration |
||||
|
||||
@see @ref WindowlessWindowsEglContext(), |
||||
@ref WindowlessWindowsEglApplication::WindowlessWindowsEglApplication(), |
||||
@ref WindowlessWindowsEglApplication::createContext(), |
||||
@ref WindowlessWindowsEglApplication::tryCreateContext() |
||||
*/ |
||||
class WindowlessWindowsEglContext::Configuration: public GL::Context::Configuration { |
||||
public: |
||||
/**
|
||||
* @brief Context flag |
||||
* |
||||
* Includes also everything from @ref GL::Context::Configuration::Flag |
||||
* except for @relativeref{GL::Context::Configuration,Flag::Windowless}, |
||||
* which is enabled implicitly by default. |
||||
* @see @ref Flags, @ref setFlags(), @ref GL::Context::Flag |
||||
*/ |
||||
enum class Flag: UnsignedLong { |
||||
/**
|
||||
* Debug context. Enabled automatically if supported by the driver |
||||
* and the @ref Flag::GpuValidation flag is set or if the |
||||
* `--magnum-gpu-validation` @ref GL-Context-usage-command-line "command-line option" |
||||
* is set to `on`. |
||||
*/ |
||||
Debug = EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR, |
||||
|
||||
/**
|
||||
* Context without error reporting. Might result in better |
||||
* performance, but situations that would have generated errors |
||||
* instead cause undefined behavior. Enabled automatically if |
||||
* supported by the driver and the @ref Flag::GpuValidationNoError |
||||
* flag is set or if the `--magnum-gpu-validation` @ref GL-Context-usage-command-line "command-line option" |
||||
* is set to `no-error`. |
||||
* @m_since_latest |
||||
*/ |
||||
/* Treated as a separate attribute and not a flag in EGL, thus
|
||||
handling manually. */ |
||||
NoError = 1ull << 32, |
||||
|
||||
/**
|
||||
* @copydoc GL::Context::Configuration::Flag::QuietLog |
||||
* @m_since_latest |
||||
*/ |
||||
QuietLog = UnsignedLong(GL::Context::Configuration::Flag::QuietLog), |
||||
|
||||
/**
|
||||
* @copydoc GL::Context::Configuration::Flag::VerboseLog |
||||
* @m_since_latest |
||||
*/ |
||||
VerboseLog = UnsignedLong(GL::Context::Configuration::Flag::VerboseLog), |
||||
|
||||
/**
|
||||
* @copydoc GL::Context::Configuration::Flag::GpuValidation |
||||
* @m_since_latest |
||||
*/ |
||||
GpuValidation = UnsignedLong(GL::Context::Configuration::Flag::GpuValidation), |
||||
|
||||
/**
|
||||
* @copydoc GL::Context::Configuration::Flag::GpuValidationNoError |
||||
* @m_since_latest |
||||
*/ |
||||
GpuValidationNoError = UnsignedLong(GL::Context::Configuration::Flag::GpuValidationNoError) |
||||
}; |
||||
|
||||
/**
|
||||
* @brief Context flags |
||||
* |
||||
* @see @ref setFlags(), @ref Context::Flags |
||||
*/ |
||||
typedef Containers::EnumSet<Flag> Flags; |
||||
|
||||
/*implicit*/ Configuration(); |
||||
|
||||
/** @brief Context flags */ |
||||
Flags flags() const { |
||||
return Flag(UnsignedLong(GL::Context::Configuration::flags())); |
||||
} |
||||
|
||||
/**
|
||||
* @brief Set context flags |
||||
* @return Reference to self (for method chaining) |
||||
* |
||||
* Default is no flag. To avoid clearing default flags by accident, |
||||
* prefer to use @ref addFlags() and @ref clearFlags() instead. |
||||
* @see @ref GL::Context::flags() |
||||
*/ |
||||
Configuration& setFlags(Flags flags) { |
||||
GL::Context::Configuration::setFlags(GL::Context::Configuration::Flag(UnsignedLong(flags))); |
||||
return *this; |
||||
} |
||||
|
||||
/**
|
||||
* @brief Add context flags |
||||
* @return Reference to self (for method chaining) |
||||
* |
||||
* Unlike @ref setFlags(), ORs the flags with existing instead of |
||||
* replacing them. Useful for preserving the defaults. |
||||
* @see @ref clearFlags() |
||||
*/ |
||||
Configuration& addFlags(Flags flags) { |
||||
GL::Context::Configuration::addFlags(GL::Context::Configuration::Flag(UnsignedLong(flags))); |
||||
return *this; |
||||
} |
||||
|
||||
/**
|
||||
* @brief Clear context flags |
||||
* @return Reference to self (for method chaining) |
||||
* |
||||
* Unlike @ref setFlags(), ANDs the inverse of @p flags with existing |
||||
* instead of replacing them. Useful for removing default flags. |
||||
* @see @ref addFlags() |
||||
*/ |
||||
Configuration& clearFlags(Flags flags) { |
||||
GL::Context::Configuration::clearFlags(GL::Context::Configuration::Flag(UnsignedLong(flags))); |
||||
return *this; |
||||
} |
||||
|
||||
/**
|
||||
* @brief Create a shared context |
||||
* @return Reference to self (for method chaining) |
||||
* @m_since{2020,06} |
||||
* |
||||
* When set, the created context will share a subset of OpenGL objects |
||||
* with @p context, instead of being independent. Many caveats and |
||||
* limitations apply to shared OpenGL contexts, please consult the |
||||
* OpenGL specification for details. Default is `EGL_NO_CONTEXT`, i.e. |
||||
* no sharing. |
||||
* @see @ref WindowlessWindowsEglContext::glContext(), |
||||
* @ref WindowlessWindowsEglApplication::glContext() |
||||
*/ |
||||
Configuration& setSharedContext(EGLContext context) { |
||||
_sharedContext = context; |
||||
return *this; |
||||
} |
||||
|
||||
/**
|
||||
* @brief Shared context |
||||
* @m_since{2020,06} |
||||
*/ |
||||
EGLContext sharedContext() const { return _sharedContext; } |
||||
|
||||
/* Overloads to remove WTF-factor from method chaining order */ |
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
MAGNUM_GL_CONTEXT_CONFIGURATION_SUBCLASS_IMPLEMENTATION(Configuration) |
||||
#endif |
||||
|
||||
private: |
||||
EGLContext _sharedContext = EGL_NO_CONTEXT; |
||||
}; |
||||
|
||||
CORRADE_ENUMSET_OPERATORS(WindowlessWindowsEglContext::Configuration::Flags) |
||||
|
||||
/**
|
||||
@brief Windowless Windows/EGL application |
||||
|
||||
@m_keywords{WindowlessApplication EGL} |
||||
|
||||
Application for offscreen rendering using @ref WindowlessWindowsEglContext. |
||||
This application library is available on OpenGL ES (also ANGLE) on Windows. |
||||
|
||||
@section Platform-WindowlessWindowsEglApplication-bootstrap Bootstrap application |
||||
|
||||
Fully contained windowless application using @ref WindowlessWindowsEglApplication |
||||
along with CMake setup is available in `windowless` branch of |
||||
[Magnum Bootstrap](https://github.com/mosra/magnum-bootstrap) repository,
|
||||
download it as [tar.gz](https://github.com/mosra/magnum-bootstrap/archive/windowless.tar.gz)
|
||||
or [zip](https://github.com/mosra/magnum-bootstrap/archive/windowless.zip)
|
||||
file. After extracting the downloaded archive you can build and run the |
||||
application with these four commands: |
||||
|
||||
@code{.sh} |
||||
mkdir build && cd build |
||||
cmake .. |
||||
cmake --build . |
||||
./src/MyApplication # or ./src/Debug/MyApplication |
||||
@endcode |
||||
|
||||
See @ref cmake for more information. |
||||
|
||||
@section Platform-WindowlessWindowsEglApplication-usage General usage |
||||
|
||||
This application library is built if `MAGNUM_WITH_WINDOWLESSWINDOWSEGLAPPLICATION` |
||||
is enabled when building Magnum. To use this library from CMake, put |
||||
[FindEGL.cmake](https://github.com/mosra/magnum/blob/master/modules/FindEGL.cmake)
|
||||
into your `modules/` directory, request the `WindowlessWindowsEglApplication` |
||||
component of the `Magnum` package and link to the |
||||
`Magnum::WindowlessWindowsEglApplication` target: |
||||
|
||||
@code{.cmake} |
||||
find_package(Magnum REQUIRED) |
||||
if(CORRADE_TARGET_WINDOWS) |
||||
find_package(Magnum REQUIRED WindowlessWindowsEglApplication) |
||||
endif() |
||||
|
||||
# ... |
||||
if(CORRADE_TARGET_WINDOWS) |
||||
target_link_libraries(your-app PRIVATE Magnum::WindowlessWindowsEglApplication) |
||||
endif() |
||||
@endcode |
||||
|
||||
Additionally, if you're using Magnum as a CMake subproject, do the following |
||||
* *before* calling @cmake find_package() @ce to ensure it's enabled, as the |
||||
library is not built by default: |
||||
|
||||
@code{.cmake} |
||||
set(MAGNUM_WITH_WINDOWLESSWINDOWSEGLAPPLICATION ON CACHE BOOL "" FORCE) |
||||
add_subdirectory(magnum EXCLUDE_FROM_ALL) |
||||
@endcode |
||||
|
||||
If no other application is requested, you can also use the generic |
||||
`Magnum::WindowlessApplication` alias to simplify porting. Again, see |
||||
@ref building and @ref cmake for more information. |
||||
|
||||
Place your code into @ref exec(). The subclass can be then used in main |
||||
function using @ref MAGNUM_WINDOWLESSWINDOWSEGLAPPLICATION_MAIN() macro. See |
||||
@ref platform for more information. |
||||
|
||||
@code{.cpp} |
||||
class MyApplication: public Platform::WindowlessWindowsEglApplication { |
||||
// implement required methods...
|
||||
}; |
||||
MAGNUM_WINDOWLESSWINDOWSEGLAPPLICATION_MAIN(MyApplication) |
||||
@endcode |
||||
|
||||
If no other application header is included, this class is also aliased to |
||||
@cpp Platform::WindowlessApplication @ce and the macro is aliased to |
||||
@cpp MAGNUM_WINDOWLESSAPPLICATION_MAIN() @ce to simplify porting. |
||||
|
||||
@note This class is available only if Magnum is compiled with |
||||
@ref MAGNUM_TARGET_GL enabled (done by default). See @ref building-features |
||||
for more information. |
||||
*/ |
||||
class WindowlessWindowsEglApplication { |
||||
public: |
||||
/** @brief Application arguments */ |
||||
struct Arguments { |
||||
/** @brief Constructor */ |
||||
/*implicit*/ constexpr Arguments(int& argc, char** argv) noexcept: argc{argc}, argv{argv} {} |
||||
|
||||
int& argc; /**< @brief Argument count */ |
||||
char** argv; /**< @brief Argument values */ |
||||
}; |
||||
|
||||
/**
|
||||
* @brief Configuration |
||||
* |
||||
* @see @ref WindowlessWindowsEglApplication(), @ref createContext(), |
||||
* @ref tryCreateContext() |
||||
*/ |
||||
typedef WindowlessWindowsEglContext::Configuration Configuration; |
||||
|
||||
/**
|
||||
* @brief Default constructor |
||||
* @param arguments Application arguments |
||||
* @param configuration Configuration |
||||
* |
||||
* Creates application with default or user-specified configuration. |
||||
* See @ref Configuration for more information. The program exits if |
||||
* the context cannot be created, see @ref tryCreateContext() for an |
||||
* alternative. |
||||
*/ |
||||
#ifdef DOXYGEN_GENERATING_OUTPUT |
||||
explicit WindowlessWindowsEglApplication(const Arguments& arguments, const Configuration& configuration = Configuration()); |
||||
#else |
||||
/* To avoid "invalid use of incomplete type" */ |
||||
explicit WindowlessWindowsEglApplication(const Arguments& arguments, const Configuration& configuration); |
||||
explicit WindowlessWindowsEglApplication(const Arguments& arguments); |
||||
#endif |
||||
|
||||
/**
|
||||
* @brief Constructor |
||||
* @param arguments Application arguments |
||||
* |
||||
* Unlike above, the context is not created and must be created later |
||||
* with @ref createContext() or @ref tryCreateContext(). |
||||
*/ |
||||
explicit WindowlessWindowsEglApplication(const Arguments& arguments, NoCreateT); |
||||
|
||||
/** @brief Copying is not allowed */ |
||||
WindowlessWindowsEglApplication(const WindowlessWindowsEglApplication&) = delete; |
||||
|
||||
/** @brief Moving is not allowed */ |
||||
WindowlessWindowsEglApplication(WindowlessWindowsEglApplication&&) = delete; |
||||
|
||||
/** @brief Copying is not allowed */ |
||||
WindowlessWindowsEglApplication& operator=(const WindowlessWindowsEglApplication&) = delete; |
||||
|
||||
/** @brief Moving is not allowed */ |
||||
WindowlessWindowsEglApplication& operator=(WindowlessWindowsEglApplication&&) = delete; |
||||
|
||||
/**
|
||||
* @brief Execute application |
||||
* @return Value for returning from @cpp main() @ce |
||||
* |
||||
* See @ref MAGNUM_WINDOWLESSWINDOWSEGLAPPLICATION_MAIN() for usage |
||||
* information. |
||||
*/ |
||||
virtual int exec() = 0; |
||||
|
||||
/**
|
||||
* @brief Underlying OpenGL context |
||||
* @m_since{2020,06} |
||||
* |
||||
* Use in case you need to call EGL functionality directly or in order |
||||
* to create a shared context. Returns @cpp nullptr @ce in case the |
||||
* context was not created yet. |
||||
* @see @ref Configuration::setSharedContext() |
||||
*/ |
||||
EGLContext glContext() { return _glContext.glContext(); } |
||||
|
||||
protected: |
||||
/* Nobody will need to have (and delete) WindowlessWindowsEglApplication*,
|
||||
thus this is faster than public pure virtual destructor */ |
||||
~WindowlessWindowsEglApplication(); |
||||
|
||||
/**
|
||||
* @brief Create context with given configuration |
||||
* |
||||
* Must be called if and only if the context wasn't created by the |
||||
* constructor itself. Error message is printed and the program exits |
||||
* if the context cannot be created, see @ref tryCreateContext() for an |
||||
* alternative. |
||||
*/ |
||||
#ifdef DOXYGEN_GENERATING_OUTPUT |
||||
void createContext(const Configuration& configuration = Configuration()); |
||||
#else |
||||
/* To avoid "invalid use of incomplete type" */ |
||||
void createContext(const Configuration& configuration); |
||||
void createContext(); |
||||
#endif |
||||
|
||||
/**
|
||||
* @brief Try to create context with given configuration |
||||
* |
||||
* Unlike @ref createContext() returns @cpp false @ce if the context |
||||
* cannot be created, @cpp true @ce otherwise. |
||||
*/ |
||||
bool tryCreateContext(const Configuration& configuration); |
||||
|
||||
private: |
||||
WindowlessWindowsEglContext _glContext; |
||||
Platform::GLContext _context; |
||||
}; |
||||
|
||||
/** @hideinitializer
|
||||
@brief Entry point for windowless Windows/EGL application |
||||
@param className Class name |
||||
|
||||
@m_keywords{MAGNUM_WINDOWLESSAPPLICATION_MAIN()} |
||||
|
||||
See @ref Magnum::Platform::WindowlessWindowsEglApplication "Platform::WindowlessWindowsEglApplication" |
||||
for usage information.This macro abstracts out platform-specific entry point |
||||
code and is equivalent to the following, see @ref portability-applications for |
||||
more information. |
||||
|
||||
@code{.cpp} |
||||
int main(int argc, char** argv) { |
||||
className app({argc, argv}); |
||||
return app.exec(); |
||||
} |
||||
@endcode |
||||
|
||||
When no other windowless application header is included this macro is also |
||||
aliased to @cpp MAGNUM_WINDOWLESSAPPLICATION_MAIN() @ce. |
||||
*/ |
||||
#define MAGNUM_WINDOWLESSWINDOWSEGLAPPLICATION_MAIN(className) \ |
||||
int main(int argc, char** argv) { \
|
||||
className app({argc, argv}); \
|
||||
return app.exec(); \
|
||||
} |
||||
|
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
#ifndef MAGNUM_WINDOWLESSAPPLICATION_MAIN |
||||
typedef WindowlessWindowsEglApplication WindowlessApplication; |
||||
typedef WindowlessWindowsEglContext WindowlessGLContext; |
||||
#define MAGNUM_WINDOWLESSAPPLICATION_MAIN(className) MAGNUM_WINDOWLESSWINDOWSEGLAPPLICATION_MAIN(className) |
||||
#else |
||||
#undef MAGNUM_WINDOWLESSAPPLICATION_MAIN |
||||
#endif |
||||
#endif |
||||
|
||||
}} |
||||
#else |
||||
#error this header is available only in the OpenGL build |
||||
#endif |
||||
|
||||
#endif |
||||
Loading…
Reference in new issue