summaryrefslogtreecommitdiff
path: root/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2019-05-25 17:47:13 -0300
committerGravatar ReinUsesLisp2019-05-25 17:47:13 -0300
commit4b80dd23a4462b0f4e9f096e0dc0cc4606d8cfe8 (patch)
tree55e053696c28caab23c6da853f08e4f8593eb9e5 /src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
parentshader/shader_ir: Make Comment() take a std::string by value (diff)
downloadyuzu-4b80dd23a4462b0f4e9f096e0dc0cc4606d8cfe8.tar.gz
yuzu-4b80dd23a4462b0f4e9f096e0dc0cc4606d8cfe8.tar.xz
yuzu-4b80dd23a4462b0f4e9f096e0dc0cc4606d8cfe8.zip
yuzu_cmd: Split emu_window OpenGL implementation into its own file
Diffstat (limited to 'src/yuzu_cmd/emu_window/emu_window_sdl2.cpp')
-rw-r--r--src/yuzu_cmd/emu_window/emu_window_sdl2.cpp171
1 files changed, 15 insertions, 156 deletions
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
index 8f104062d..d32ad9fa0 100644
--- a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
+++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
@@ -2,53 +2,27 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <algorithm>
6#include <cstdlib>
7#include <string>
8#define SDL_MAIN_HANDLED
9#include <SDL.h> 5#include <SDL.h>
10#include <fmt/format.h>
11#include <glad/glad.h>
12#include "common/logging/log.h" 6#include "common/logging/log.h"
13#include "common/scm_rev.h"
14#include "common/string_util.h"
15#include "core/settings.h"
16#include "input_common/keyboard.h" 7#include "input_common/keyboard.h"
17#include "input_common/main.h" 8#include "input_common/main.h"
18#include "input_common/motion_emu.h" 9#include "input_common/motion_emu.h"
19#include "input_common/sdl/sdl.h" 10#include "input_common/sdl/sdl.h"
20#include "yuzu_cmd/emu_window/emu_window_sdl2.h" 11#include "yuzu_cmd/emu_window/emu_window_sdl2.h"
21 12
22class SDLGLContext : public Core::Frontend::GraphicsContext { 13EmuWindow_SDL2::EmuWindow_SDL2(bool fullscreen) {
23public: 14 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
24 explicit SDLGLContext() { 15 LOG_CRITICAL(Frontend, "Failed to initialize SDL2! Exiting...");
25 // create a hidden window to make the shared context against 16 exit(1);
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 } 17 }
18 InputCommon::Init();
19 SDL_SetMainReady();
20}
45 21
46 void SwapBuffers() override {} 22EmuWindow_SDL2::~EmuWindow_SDL2() {
47 23 InputCommon::Shutdown();
48private: 24 SDL_Quit();
49 SDL_Window* window; 25}
50 SDL_GLContext context;
51};
52 26
53void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) { 27void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) {
54 TouchMoved((unsigned)std::max(x, 0), (unsigned)std::max(y, 0)); 28 TouchMoved((unsigned)std::max(x, 0), (unsigned)std::max(y, 0));
@@ -139,112 +113,6 @@ void EmuWindow_SDL2::Fullscreen() {
139 SDL_MaximizeWindow(render_window); 113 SDL_MaximizeWindow(render_window);
140} 114}
141 115
142bool EmuWindow_SDL2::SupportsRequiredGLExtensions() {
143 std::vector<std::string> unsupported_ext;
144
145 if (!GLAD_GL_ARB_direct_state_access)
146 unsupported_ext.push_back("ARB_direct_state_access");
147 if (!GLAD_GL_ARB_vertex_type_10f_11f_11f_rev)
148 unsupported_ext.push_back("ARB_vertex_type_10f_11f_11f_rev");
149 if (!GLAD_GL_ARB_texture_mirror_clamp_to_edge)
150 unsupported_ext.push_back("ARB_texture_mirror_clamp_to_edge");
151 if (!GLAD_GL_ARB_multi_bind)
152 unsupported_ext.push_back("ARB_multi_bind");
153
154 // Extensions required to support some texture formats.
155 if (!GLAD_GL_EXT_texture_compression_s3tc)
156 unsupported_ext.push_back("EXT_texture_compression_s3tc");
157 if (!GLAD_GL_ARB_texture_compression_rgtc)
158 unsupported_ext.push_back("ARB_texture_compression_rgtc");
159 if (!GLAD_GL_ARB_depth_buffer_float)
160 unsupported_ext.push_back("ARB_depth_buffer_float");
161
162 for (const std::string& ext : unsupported_ext)
163 LOG_CRITICAL(Frontend, "Unsupported GL extension: {}", ext);
164
165 return unsupported_ext.empty();
166}
167
168EmuWindow_SDL2::EmuWindow_SDL2(bool fullscreen) {
169 // Initialize the window
170 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
171 LOG_CRITICAL(Frontend, "Failed to initialize SDL2! Exiting...");
172 exit(1);
173 }
174
175 InputCommon::Init();
176
177 SDL_SetMainReady();
178
179 const SDL_GLprofile profile = Settings::values.use_compatibility_profile
180 ? SDL_GL_CONTEXT_PROFILE_COMPATIBILITY
181 : SDL_GL_CONTEXT_PROFILE_CORE;
182
183 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
184 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
185 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile);
186 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
187 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
188 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
189 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
190 SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0);
191 SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
192
193 std::string window_title = fmt::format("yuzu {} | {}-{}", Common::g_build_fullname,
194 Common::g_scm_branch, Common::g_scm_desc);
195 render_window =
196 SDL_CreateWindow(window_title.c_str(),
197 SDL_WINDOWPOS_UNDEFINED, // x position
198 SDL_WINDOWPOS_UNDEFINED, // y position
199 Layout::ScreenUndocked::Width, Layout::ScreenUndocked::Height,
200 SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
201
202 if (render_window == nullptr) {
203 LOG_CRITICAL(Frontend, "Failed to create SDL2 window! {}", SDL_GetError());
204 exit(1);
205 }
206
207 if (fullscreen) {
208 Fullscreen();
209 }
210 gl_context = SDL_GL_CreateContext(render_window);
211
212 if (gl_context == nullptr) {
213 LOG_CRITICAL(Frontend, "Failed to create SDL2 GL context! {}", SDL_GetError());
214 exit(1);
215 }
216
217 if (!gladLoadGLLoader(static_cast<GLADloadproc>(SDL_GL_GetProcAddress))) {
218 LOG_CRITICAL(Frontend, "Failed to initialize GL functions! {}", SDL_GetError());
219 exit(1);
220 }
221
222 if (!SupportsRequiredGLExtensions()) {
223 LOG_CRITICAL(Frontend, "GPU does not support all required OpenGL extensions! Exiting...");
224 exit(1);
225 }
226
227 OnResize();
228 OnMinimalClientAreaChangeRequest(GetActiveConfig().min_client_area_size);
229 SDL_PumpEvents();
230 SDL_GL_SetSwapInterval(false);
231 LOG_INFO(Frontend, "yuzu Version: {} | {}-{}", Common::g_build_fullname, Common::g_scm_branch,
232 Common::g_scm_desc);
233 Settings::LogSettings();
234
235 DoneCurrent();
236}
237
238EmuWindow_SDL2::~EmuWindow_SDL2() {
239 InputCommon::Shutdown();
240 SDL_GL_DeleteContext(gl_context);
241 SDL_Quit();
242}
243
244void EmuWindow_SDL2::SwapBuffers() {
245 SDL_GL_SwapWindow(render_window);
246}
247
248void EmuWindow_SDL2::PollEvents() { 116void EmuWindow_SDL2::PollEvents() {
249 SDL_Event event; 117 SDL_Event event;
250 118
@@ -257,7 +125,11 @@ void EmuWindow_SDL2::PollEvents() {
257 case SDL_WINDOWEVENT_RESIZED: 125 case SDL_WINDOWEVENT_RESIZED:
258 case SDL_WINDOWEVENT_MAXIMIZED: 126 case SDL_WINDOWEVENT_MAXIMIZED:
259 case SDL_WINDOWEVENT_RESTORED: 127 case SDL_WINDOWEVENT_RESTORED:
128 OnResize();
129 break;
260 case SDL_WINDOWEVENT_MINIMIZED: 130 case SDL_WINDOWEVENT_MINIMIZED:
131 case SDL_WINDOWEVENT_EXPOSED:
132 is_shown = event.window.event == SDL_WINDOWEVENT_EXPOSED;
261 OnResize(); 133 OnResize();
262 break; 134 break;
263 case SDL_WINDOWEVENT_CLOSE: 135 case SDL_WINDOWEVENT_CLOSE:
@@ -300,20 +172,7 @@ void EmuWindow_SDL2::PollEvents() {
300 } 172 }
301} 173}
302 174
303void EmuWindow_SDL2::MakeCurrent() {
304 SDL_GL_MakeCurrent(render_window, gl_context);
305}
306
307void EmuWindow_SDL2::DoneCurrent() {
308 SDL_GL_MakeCurrent(render_window, nullptr);
309}
310
311void EmuWindow_SDL2::OnMinimalClientAreaChangeRequest( 175void EmuWindow_SDL2::OnMinimalClientAreaChangeRequest(
312 const std::pair<unsigned, unsigned>& minimal_size) { 176 const std::pair<unsigned, unsigned>& minimal_size) {
313
314 SDL_SetWindowMinimumSize(render_window, minimal_size.first, minimal_size.second); 177 SDL_SetWindowMinimumSize(render_window, minimal_size.first, minimal_size.second);
315} 178}
316
317std::unique_ptr<Core::Frontend::GraphicsContext> EmuWindow_SDL2::CreateSharedContext() const {
318 return std::make_unique<SDLGLContext>();
319}