summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Zach Hilman2019-03-25 20:30:57 -0400
committerGravatar Zach Hilman2019-06-10 00:03:11 -0400
commitae5a46256e35a89e7f303fa6510e3f2e8aca04e3 (patch)
tree3319a836b2b905110288ffd485857377aacff1c7 /src
parentyuzu_tester: Use config, icon, and main from yuzu-cmd (diff)
downloadyuzu-ae5a46256e35a89e7f303fa6510e3f2e8aca04e3.tar.gz
yuzu-ae5a46256e35a89e7f303fa6510e3f2e8aca04e3.tar.xz
yuzu-ae5a46256e35a89e7f303fa6510e3f2e8aca04e3.zip
yuzu_tester: Add SDL2-based EmuWindow that doesn't show the window
Diffstat (limited to 'src')
-rw-r--r--src/yuzu_tester/emu_window/emu_window_sdl2_hide.cpp123
-rw-r--r--src/yuzu_tester/emu_window/emu_window_sdl2_hide.h41
2 files changed, 164 insertions, 0 deletions
diff --git a/src/yuzu_tester/emu_window/emu_window_sdl2_hide.cpp b/src/yuzu_tester/emu_window/emu_window_sdl2_hide.cpp
new file mode 100644
index 000000000..3775a51e0
--- /dev/null
+++ b/src/yuzu_tester/emu_window/emu_window_sdl2_hide.cpp
@@ -0,0 +1,123 @@
1// Copyright 2019 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <algorithm>
6#include <cstdlib>
7#include <string>
8#define SDL_MAIN_HANDLED
9#include <SDL.h>
10#include <fmt/format.h>
11#include <glad/glad.h>
12#include "common/logging/log.h"
13#include "common/scm_rev.h"
14#include "core/settings.h"
15#include "input_common/main.h"
16#include "yuzu_tester/emu_window/emu_window_sdl2_hide.h"
17
18bool EmuWindow_SDL2_Hide::SupportsRequiredGLExtensions() {
19 std::vector<std::string> unsupported_ext;
20
21 if (!GLAD_GL_ARB_direct_state_access)
22 unsupported_ext.push_back("ARB_direct_state_access");
23 if (!GLAD_GL_ARB_vertex_type_10f_11f_11f_rev)
24 unsupported_ext.push_back("ARB_vertex_type_10f_11f_11f_rev");
25 if (!GLAD_GL_ARB_texture_mirror_clamp_to_edge)
26 unsupported_ext.push_back("ARB_texture_mirror_clamp_to_edge");
27 if (!GLAD_GL_ARB_multi_bind)
28 unsupported_ext.push_back("ARB_multi_bind");
29
30 // Extensions required to support some texture formats.
31 if (!GLAD_GL_EXT_texture_compression_s3tc)
32 unsupported_ext.push_back("EXT_texture_compression_s3tc");
33 if (!GLAD_GL_ARB_texture_compression_rgtc)
34 unsupported_ext.push_back("ARB_texture_compression_rgtc");
35 if (!GLAD_GL_ARB_depth_buffer_float)
36 unsupported_ext.push_back("ARB_depth_buffer_float");
37
38 for (const std::string& ext : unsupported_ext)
39 LOG_CRITICAL(Frontend, "Unsupported GL extension: {}", ext);
40
41 return unsupported_ext.empty();
42}
43
44EmuWindow_SDL2_Hide::EmuWindow_SDL2_Hide() {
45 // Initialize the window
46 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
47 LOG_CRITICAL(Frontend, "Failed to initialize SDL2! Exiting...");
48 exit(1);
49 }
50
51 InputCommon::Init();
52
53 SDL_SetMainReady();
54
55 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
56 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
57 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
58 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
59 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
60 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
61 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
62 SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0);
63
64 std::string window_title = fmt::format("yuzu-tester {} | {}-{}", Common::g_build_fullname,
65 Common::g_scm_branch, Common::g_scm_desc);
66 render_window =
67 SDL_CreateWindow(window_title.c_str(),
68 SDL_WINDOWPOS_UNDEFINED, // x position
69 SDL_WINDOWPOS_UNDEFINED, // y position
70 Layout::ScreenUndocked::Width, Layout::ScreenUndocked::Height,
71 SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
72 SDL_HideWindow(render_window);
73
74 if (render_window == nullptr) {
75 LOG_CRITICAL(Frontend, "Failed to create SDL2 window! {}", SDL_GetError());
76 exit(1);
77 }
78
79 gl_context = SDL_GL_CreateContext(render_window);
80
81 if (gl_context == nullptr) {
82 LOG_CRITICAL(Frontend, "Failed to create SDL2 GL context! {}", SDL_GetError());
83 exit(1);
84 }
85
86 if (!gladLoadGLLoader(static_cast<GLADloadproc>(SDL_GL_GetProcAddress))) {
87 LOG_CRITICAL(Frontend, "Failed to initialize GL functions! {}", SDL_GetError());
88 exit(1);
89 }
90
91 if (!SupportsRequiredGLExtensions()) {
92 LOG_CRITICAL(Frontend, "GPU does not support all required OpenGL extensions! Exiting...");
93 exit(1);
94 }
95
96 SDL_PumpEvents();
97 SDL_GL_SetSwapInterval(false);
98 LOG_INFO(Frontend, "yuzu-tester Version: {} | {}-{}", Common::g_build_fullname,
99 Common::g_scm_branch, Common::g_scm_desc);
100 Settings::LogSettings();
101
102 DoneCurrent();
103}
104
105EmuWindow_SDL2_Hide::~EmuWindow_SDL2_Hide() {
106 InputCommon::Shutdown();
107 SDL_GL_DeleteContext(gl_context);
108 SDL_Quit();
109}
110
111void EmuWindow_SDL2_Hide::SwapBuffers() {
112 SDL_GL_SwapWindow(render_window);
113}
114
115void EmuWindow_SDL2_Hide::PollEvents() {}
116
117void EmuWindow_SDL2_Hide::MakeCurrent() {
118 SDL_GL_MakeCurrent(render_window, gl_context);
119}
120
121void EmuWindow_SDL2_Hide::DoneCurrent() {
122 SDL_GL_MakeCurrent(render_window, nullptr);
123}
diff --git a/src/yuzu_tester/emu_window/emu_window_sdl2_hide.h b/src/yuzu_tester/emu_window/emu_window_sdl2_hide.h
new file mode 100644
index 000000000..1a8953c75
--- /dev/null
+++ b/src/yuzu_tester/emu_window/emu_window_sdl2_hide.h
@@ -0,0 +1,41 @@
1// Copyright 2019 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "core/frontend/emu_window.h"
8
9struct SDL_Window;
10
11class EmuWindow_SDL2_Hide : public Core::Frontend::EmuWindow {
12public:
13 explicit EmuWindow_SDL2_Hide();
14 ~EmuWindow_SDL2_Hide();
15
16 /// Swap buffers to display the next frame
17 void SwapBuffers() override;
18
19 /// Polls window events
20 void PollEvents() override;
21
22 /// Makes the graphics context current for the caller thread
23 void MakeCurrent() override;
24
25 /// Releases the GL context from the caller thread
26 void DoneCurrent() override;
27
28 /// Whether the window is still open, and a close request hasn't yet been sent
29 bool IsOpen() const;
30
31private:
32 /// Whether the GPU and driver supports the OpenGL extension required
33 bool SupportsRequiredGLExtensions();
34
35 /// Internal SDL2 render window
36 SDL_Window* render_window;
37
38 using SDL_GLContext = void*;
39 /// The OpenGL context associated with the window
40 SDL_GLContext gl_context;
41};