Plasma Engine  2.0
Loading...
Searching...
No Matches
Screen_GLFW.h
1#include <Foundation/FoundationInternal.h>
2PL_FOUNDATION_INTERNAL_HEADER
3
4#include <Foundation/System/Screen.h>
5#include <GLFW/glfw3.h>
6
7namespace
8{
9 plResult plGlfwError(const char* file, size_t line)
10 {
11 const char* desc;
12 int errorCode = glfwGetError(&desc);
13 if (errorCode != GLFW_NO_ERROR)
14 {
15 plLog::Error("GLFW error {} ({}): {} - {}", file, line, errorCode, desc);
16 return PL_FAILURE;
17 }
18 return PL_SUCCESS;
19 }
20} // namespace
21
22#define PL_GLFW_RETURN_FAILURE_ON_ERROR() \
23 do \
24 { \
25 if (plGlfwError(__FILE__, __LINE__).Failed()) \
26 return PL_FAILURE; \
27 } while (false)
28
30{
31 out_Screens.Clear();
32
33 int iMonitorCount = 0;
34 GLFWmonitor** pMonitors = glfwGetMonitors(&iMonitorCount);
35 PL_GLFW_RETURN_FAILURE_ON_ERROR();
36 if (iMonitorCount == 0)
37 {
38 return PL_FAILURE;
39 }
40
41 GLFWmonitor* pPrimaryMonitor = glfwGetPrimaryMonitor();
42 PL_GLFW_RETURN_FAILURE_ON_ERROR();
43 if (pPrimaryMonitor == nullptr)
44 {
45 return PL_FAILURE;
46 }
47
48 for (int i = 0; i < iMonitorCount; ++i)
49 {
50 plScreenInfo& screen = out_Screens.ExpandAndGetRef();
51 screen.m_sDisplayName = glfwGetMonitorName(pMonitors[i]);
52 PL_GLFW_RETURN_FAILURE_ON_ERROR();
53
54 const GLFWvidmode* mode = glfwGetVideoMode(pMonitors[i]);
55 PL_GLFW_RETURN_FAILURE_ON_ERROR();
56 if (mode == nullptr)
57 {
58 return PL_FAILURE;
59 }
60 screen.m_iResolutionX = mode->width;
61 screen.m_iResolutionY = mode->height;
62
63 glfwGetMonitorPos(pMonitors[i], &screen.m_iOffsetX, &screen.m_iOffsetY);
64 PL_GLFW_RETURN_FAILURE_ON_ERROR();
65
66 screen.m_bIsPrimary = pMonitors[i] == pPrimaryMonitor;
67 }
68
69 return PL_SUCCESS;
70}
T & ExpandAndGetRef()
Grows the array by one element and returns a reference to the newly created element.
Definition ArrayBase_inl.h:310
void Clear()
Clears the array.
Definition ArrayBase_inl.h:184
Definition DynamicArray.h:81
static void Error(plLogInterface *pInterface, const plFormatString &string)
An error that needs to be fixed as soon as possible.
Definition Log.cpp:375
static plResult EnumerateScreens(plDynamicArray< plScreenInfo > &out_screens)
Enumerates all available screens. When it returns PL_SUCCESS, at least one screen has been found.
Definition Screen_GLFW.h:29
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
Describes the properties of a screen.
Definition Screen.h:10
plString m_sDisplayName
Some OS provided name for the screen, typically the manufacturer and model name.
Definition Screen.h:11
bool m_bIsPrimary
Whether this is the primary/main screen.
Definition Screen.h:17
plInt32 m_iOffsetY
The virtual position of the screen. Ie. a window created at this location will appear on this screen.
Definition Screen.h:14
plInt32 m_iResolutionX
The virtual resolution. Ie. a window with this dimension will span the entire screen.
Definition Screen.h:15
plInt32 m_iOffsetX
The virtual position of the screen. Ie. a window created at this location will appear on this screen.
Definition Screen.h:13
plInt32 m_iResolutionY
The virtual resolution. Ie. a window with this dimension will span the entire screen.
Definition Screen.h:16