Repository navigation
Expand file tree
/
Copy pathSDL3DisplaySetup.cpp
More file actions
78 lines (66 loc) · 2.5 KB
/
Copy pathSDL3DisplaySetup.cpp
File metadata and controls
78 lines (66 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "SDL3DisplaySetup.h"
#include <deki/LogSystem.h>
#if !defined(DEKI_EDITOR) && defined(DEKI_PACKAGE_SDL3)
#include "SDL3Display.h"
#include "SDL3GLDisplay.h"
#include <deki/Engine.h>
#endif
namespace DekiSdl3
{
#if !defined(DEKI_EDITOR) && defined(DEKI_PACKAGE_SDL3)
// The package owns the display and keeps it for the whole program; the engine
// only holds a pointer to it.
static std::unique_ptr<SDL3Display> s_SDL3Display;
#if defined(DEKI_CAPABILITY_OPENGL)
static std::unique_ptr<SDL3GLDisplay> s_SDL3GLDisplay;
#endif
#if !defined(DEKI_SCREEN_WIDTH) || !defined(DEKI_SCREEN_HEIGHT) || !defined(DEKI_SCREEN_COLOR_FORMAT)
#error \
"The simulator emulates the target platform's screen: its build must define DEKI_SCREEN_WIDTH, DEKI_SCREEN_HEIGHT and DEKI_SCREEN_COLOR_FORMAT (the platform's screenWidth, screenHeight and colorFormat)."
#endif
void SDL3DisplaySetup::Setup(SetupCallback onComplete)
{
#if defined(DEKI_CAPABILITY_OPENGL)
if (presentThroughOpenGL)
{
s_SDL3GLDisplay = std::make_unique<SDL3GLDisplay>();
s_SDL3GLDisplay->SetWindowScale(windowScale);
s_SDL3GLDisplay->SetDraw2DOnGpu(draw2DOnGpu);
if (s_SDL3GLDisplay->Initialize(DEKI_SCREEN_WIDTH, DEKI_SCREEN_HEIGHT))
{
Deki::Engine::GetInstance().SetDisplay(s_SDL3GLDisplay.get(), "SDL3 OpenGL");
onComplete(true);
return;
}
// It said why; SDL's GPU API still shows the game.
s_SDL3GLDisplay.reset();
}
#endif
DEKI_LOG_INFO("SDL3DisplaySetup: Creating SDL3 display (%dx%d screen, window x%d)", (int)DEKI_SCREEN_WIDTH,
(int)DEKI_SCREEN_HEIGHT, (int)windowScale);
s_SDL3Display = std::make_unique<SDL3Display>();
if (s_SDL3Display)
{
s_SDL3Display->SetWindowScale(windowScale);
s_SDL3Display->SetColorFormat(DEKI_SCREEN_COLOR_FORMAT);
}
if (s_SDL3Display && s_SDL3Display->Initialize(DEKI_SCREEN_WIDTH, DEKI_SCREEN_HEIGHT))
{
Deki::Engine::GetInstance().SetDisplay(s_SDL3Display.get(), "SDL3");
onComplete(true);
}
else
{
DEKI_LOG_ERROR("SDL3DisplaySetup: Failed to initialize SDL3 display");
s_SDL3Display.reset();
onComplete(false);
}
}
#else
void SDL3DisplaySetup::Setup(SetupCallback onComplete)
{
// The editor and device builds have no SDL3 window to open.
onComplete(true);
}
#endif
} // namespace DekiSdl3