diff options
| author | 2019-04-13 22:08:40 -0400 | |
|---|---|---|
| committer | 2019-04-13 22:08:40 -0400 | |
| commit | 065f83c6c321c9672cda9b89c09bef6c7f3c5472 (patch) | |
| tree | 3efd50ea836f1ab052581108f1fa218a22e73b62 /src/yuzu_cmd/emu_window/emu_window_sdl2.cpp | |
| parent | Merge pull request #2389 from FreddyFunk/rename-gamedir (diff) | |
| parent | bootmanager: Bypass input focus issues (diff) | |
| download | yuzu-065f83c6c321c9672cda9b89c09bef6c7f3c5472.tar.gz yuzu-065f83c6c321c9672cda9b89c09bef6c7f3c5472.tar.xz yuzu-065f83c6c321c9672cda9b89c09bef6c7f3c5472.zip | |
Merge pull request #2017 from jroweboy/glwidget
Frontend: Migrate to QOpenGLWindow and support shared contexts
Diffstat (limited to 'src/yuzu_cmd/emu_window/emu_window_sdl2.cpp')
| -rw-r--r-- | src/yuzu_cmd/emu_window/emu_window_sdl2.cpp | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp index de7a26e14..68a176032 100644 --- a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp | |||
| @@ -19,6 +19,37 @@ | |||
| 19 | #include "input_common/sdl/sdl.h" | 19 | #include "input_common/sdl/sdl.h" |
| 20 | #include "yuzu_cmd/emu_window/emu_window_sdl2.h" | 20 | #include "yuzu_cmd/emu_window/emu_window_sdl2.h" |
| 21 | 21 | ||
| 22 | class SDLGLContext : public Core::Frontend::GraphicsContext { | ||
| 23 | public: | ||
| 24 | explicit SDLGLContext() { | ||
| 25 | // create a hidden window to make the shared context against | ||
| 26 | window = SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED, // x position | ||
| 27 | SDL_WINDOWPOS_UNDEFINED, // y position | ||
| 28 | Layout::ScreenUndocked::Width, Layout::ScreenUndocked::Height, | ||
| 29 | SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN); | ||
| 30 | context = SDL_GL_CreateContext(window); | ||
| 31 | } | ||
| 32 | |||
| 33 | ~SDLGLContext() { | ||
| 34 | SDL_GL_DeleteContext(context); | ||
| 35 | SDL_DestroyWindow(window); | ||
| 36 | } | ||
| 37 | |||
| 38 | void MakeCurrent() override { | ||
| 39 | SDL_GL_MakeCurrent(window, context); | ||
| 40 | } | ||
| 41 | |||
| 42 | void DoneCurrent() override { | ||
| 43 | SDL_GL_MakeCurrent(window, nullptr); | ||
| 44 | } | ||
| 45 | |||
| 46 | void SwapBuffers() override {} | ||
| 47 | |||
| 48 | private: | ||
| 49 | SDL_Window* window; | ||
| 50 | SDL_GLContext context; | ||
| 51 | }; | ||
| 52 | |||
| 22 | void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) { | 53 | void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) { |
| 23 | TouchMoved((unsigned)std::max(x, 0), (unsigned)std::max(y, 0)); | 54 | TouchMoved((unsigned)std::max(x, 0), (unsigned)std::max(y, 0)); |
| 24 | InputCommon::GetMotionEmu()->Tilt(x, y); | 55 | InputCommon::GetMotionEmu()->Tilt(x, y); |
| @@ -153,6 +184,7 @@ EmuWindow_SDL2::EmuWindow_SDL2(bool fullscreen) { | |||
| 153 | SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); | 184 | SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); |
| 154 | SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); | 185 | SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); |
| 155 | SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0); | 186 | SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0); |
| 187 | SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1); | ||
| 156 | 188 | ||
| 157 | std::string window_title = fmt::format("yuzu {} | {}-{}", Common::g_build_fullname, | 189 | std::string window_title = fmt::format("yuzu {} | {}-{}", Common::g_build_fullname, |
| 158 | Common::g_scm_branch, Common::g_scm_desc); | 190 | Common::g_scm_branch, Common::g_scm_desc); |
| @@ -171,7 +203,6 @@ EmuWindow_SDL2::EmuWindow_SDL2(bool fullscreen) { | |||
| 171 | if (fullscreen) { | 203 | if (fullscreen) { |
| 172 | Fullscreen(); | 204 | Fullscreen(); |
| 173 | } | 205 | } |
| 174 | |||
| 175 | gl_context = SDL_GL_CreateContext(render_window); | 206 | gl_context = SDL_GL_CreateContext(render_window); |
| 176 | 207 | ||
| 177 | if (gl_context == nullptr) { | 208 | if (gl_context == nullptr) { |
| @@ -278,3 +309,7 @@ void EmuWindow_SDL2::OnMinimalClientAreaChangeRequest( | |||
| 278 | 309 | ||
| 279 | SDL_SetWindowMinimumSize(render_window, minimal_size.first, minimal_size.second); | 310 | SDL_SetWindowMinimumSize(render_window, minimal_size.first, minimal_size.second); |
| 280 | } | 311 | } |
| 312 | |||
| 313 | std::unique_ptr<Core::Frontend::GraphicsContext> EmuWindow_SDL2::CreateSharedContext() const { | ||
| 314 | return std::make_unique<SDLGLContext>(); | ||
| 315 | } | ||