-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
GUI: Also try a separate-shared-context mode #756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6b1e464
fix include
VelorumS e769b60
guisys: separate context mode
VelorumS ff1b7ff
guisys: logger for separate context mode
VelorumS 76b9a97
guisys: context init sequences for unique and separate modes
VelorumS 2b90c96
guisys: common interface for context init modes
VelorumS 3ea6df9
guisys: try both init modes
VelorumS 2bc8a97
provide missing GL_DEBUG definitions to fix compile on Mac
Birch-san File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| // Copyright 2017-2017 the openage authors. See copying.md for legal info. | ||
|
|
||
| #include "gui_ctx_setup.h" | ||
|
|
||
| #include <cassert> | ||
|
|
||
| #include <QOpenGLDebugLogger> | ||
|
|
||
| #include "platforms/context_extraction.h" | ||
| #include "opengl_debug_logger.h" | ||
|
|
||
| namespace qtsdl { | ||
|
|
||
| CtxExtractionException::CtxExtractionException(const std::string &what_arg) | ||
| : | ||
| std::runtime_error{what_arg} { | ||
| } | ||
|
|
||
| QOpenGLContext* CtxExtractionMode::get_ctx() { | ||
| return &this->ctx; | ||
| } | ||
|
|
||
| GuiUniqueRenderingContext::GuiUniqueRenderingContext(SDL_Window *window) | ||
| : | ||
| CtxExtractionMode{} { | ||
|
|
||
| QVariant handle; | ||
| WId id; | ||
|
|
||
| std::tie(handle, id) = extract_native_context(window); | ||
|
|
||
| if (handle.isValid()) { | ||
| // pass the SDL opengl context so qt can use it | ||
| this->ctx.setNativeHandle(handle); | ||
| this->ctx.create(); | ||
| assert(this->ctx.isValid()); | ||
|
|
||
| // reuse the sdl window | ||
| QWindow *w = QWindow::fromWinId(id); | ||
| w->setSurfaceType(QSurface::OpenGLSurface); | ||
|
|
||
| if (this->ctx.makeCurrent(w)) { | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| throw CtxExtractionException("adding GUI to the main rendering context failed"); | ||
| } | ||
|
|
||
| void GuiUniqueRenderingContext::pre_render() { | ||
| } | ||
|
|
||
| void GuiUniqueRenderingContext::post_render() { | ||
| } | ||
|
|
||
| GuiSeparateRenderingContext::GuiSeparateRenderingContext(SDL_Window *window) | ||
| : | ||
| CtxExtractionMode{} { | ||
|
|
||
| QVariant handle; | ||
|
|
||
| std::tie(handle, this->make_current_back) = extract_native_context_and_switchback_func(window); | ||
|
|
||
| if (handle.isValid()) { | ||
| this->main_ctx.setNativeHandle(handle); | ||
| this->main_ctx.create(); | ||
| assert(this->main_ctx.isValid()); | ||
|
|
||
| auto context_debug_parameters = get_current_opengl_debug_parameters(this->main_ctx); | ||
|
|
||
| this->ctx.setFormat(this->main_ctx.format()); | ||
| this->ctx.setShareContext(&this->main_ctx); | ||
| this->ctx.create(); | ||
| assert(this->ctx.isValid()); | ||
| assert(!(this->main_ctx.format().options() ^ this->ctx.format().options()).testFlag(QSurfaceFormat::DebugContext)); | ||
|
|
||
| this->offscreen_surface.setFormat(this->ctx.format()); | ||
| this->offscreen_surface.create(); | ||
|
|
||
| this->pre_render(); | ||
| apply_opengl_debug_parameters(context_debug_parameters, this->ctx); | ||
| this->post_render(); | ||
| } else { | ||
| throw CtxExtractionException("creating separate context for GUI failed"); | ||
| } | ||
| } | ||
|
|
||
| GuiSeparateRenderingContext::~GuiSeparateRenderingContext() { | ||
| this->pre_render(); | ||
| this->ctx_logger.reset(); | ||
| this->post_render(); | ||
| } | ||
|
|
||
| void GuiSeparateRenderingContext::pre_render() { | ||
| if (!this->ctx.makeCurrent(&this->offscreen_surface)) { | ||
| assert(false); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| void GuiSeparateRenderingContext::post_render() { | ||
| this->make_current_back(); | ||
| } | ||
|
|
||
| } // namespace qtsdl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| // Copyright 2017-2017 the openage authors. See copying.md for legal info. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <stdexcept> | ||
| #include <memory> | ||
| #include <functional> | ||
|
|
||
| #include <QOpenGLContext> | ||
| #include <QOffscreenSurface> | ||
|
|
||
| struct SDL_Window; | ||
|
|
||
| QT_FORWARD_DECLARE_CLASS(QOpenGLDebugLogger) | ||
|
|
||
| namespace qtsdl { | ||
|
|
||
| class CtxExtractionException : public std::runtime_error { | ||
| public: | ||
| explicit CtxExtractionException(const std::string &what_arg); | ||
| }; | ||
|
|
||
| /** | ||
| * Abstract base for the method of getting a Qt-usable context. | ||
| */ | ||
| class CtxExtractionMode { | ||
| public: | ||
| virtual ~CtxExtractionMode() { | ||
| } | ||
|
|
||
| /** | ||
| * @return context that can be used by Qt | ||
| */ | ||
| QOpenGLContext* get_ctx(); | ||
|
|
||
| /** | ||
| * Function that must be called before rendering the GUI. | ||
| */ | ||
| virtual void pre_render() = 0; | ||
|
|
||
| /** | ||
| * Function that must be called after rendering the GUI. | ||
| */ | ||
| virtual void post_render() = 0; | ||
|
|
||
| protected: | ||
| QOpenGLContext ctx; | ||
| }; | ||
|
|
||
| /** | ||
| * Use the same context to render the GUI. | ||
| */ | ||
| class GuiUniqueRenderingContext : public CtxExtractionMode { | ||
| public: | ||
| explicit GuiUniqueRenderingContext(SDL_Window *window); | ||
|
|
||
| virtual void pre_render() override; | ||
| virtual void post_render() override; | ||
| }; | ||
|
|
||
| /** | ||
| * Create a separate context to render the GUI, make it shared with the main context. | ||
| */ | ||
| class GuiSeparateRenderingContext : public CtxExtractionMode { | ||
| public: | ||
| explicit GuiSeparateRenderingContext(SDL_Window *window); | ||
| virtual ~GuiSeparateRenderingContext(); | ||
|
|
||
| virtual void pre_render() override; | ||
| virtual void post_render() override; | ||
|
|
||
| private: | ||
| /** | ||
| * GL context of the game | ||
| */ | ||
| QOpenGLContext main_ctx; | ||
|
|
||
| /** | ||
| * GL debug logger of the GL context of the GUI | ||
| */ | ||
| std::unique_ptr<QOpenGLDebugLogger> ctx_logger; | ||
|
|
||
| /** | ||
| * Function to make the game context current | ||
| */ | ||
| std::function<void()> make_current_back; | ||
|
|
||
| /** | ||
| * Surface that is needed to make the GUI context current | ||
| */ | ||
| QOffscreenSurface offscreen_surface; | ||
| }; | ||
|
|
||
| } // namespace qtsdl | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be a good job for the
error::Errorso we had nice backtraces etc.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's too deep to include the
error. Replace the exception with an assert?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as you catch it yourself it should be ok like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, that's done. They won't escape.