-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphicsLinux.cpp
More file actions
165 lines (131 loc) · 4.25 KB
/
Copy pathGraphicsLinux.cpp
File metadata and controls
165 lines (131 loc) · 4.25 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include "precomp.h"
#include "GraphicsLinux.h"
void GraphicsLinux::Init(int width, int height)
{
// InitDisplay()
x_display = XOpenDisplay(NULL);
assert(x_display != NULL
&& "Failed to open an XDisplay");
root = DefaultRootWindow(x_display);
// esInitContext()
memset(&mState, 0, sizeof(Target_State));
// InitOGL
XSetWindowAttributes swa;
XSetWindowAttributes xattr;
Atom wm_state;
XWMHints hints;
XEvent xev;
mState.width = width;
mState.height = height;
EGLint numConfigs;
EGLint majorVersion;
EGLint minorVersion;
root = DefaultRootWindow(x_display);
swa.event_mask = ExposureMask | PointerMotionMask | KeyPressMask | KeyReleaseMask;
swa.background_pixmap = None;
swa.background_pixel = 0;
swa.border_pixel = 0;
swa.override_redirect = true;
win = XCreateWindow(
x_display,
root,
0, // puts it at the top left of the screen
0,
mState.width, //set size
mState.height,
0,
CopyFromParent,
InputOutput,
CopyFromParent,
CWEventMask,
&swa);
assert(win != 0);
mState.nativewindow = (EGLNativeWindowType)win;
XSelectInput(x_display, win, KeyPressMask | KeyReleaseMask);
xattr.override_redirect = TRUE;
XChangeWindowAttributes(x_display, win, CWOverrideRedirect, &xattr);
hints.input = TRUE;
hints.flags = InputHint;
XSetWMHints(x_display, win, &hints);
char* title = (char*)"x11 Demo";
// make the window visible on the screen
XMapWindow(x_display, win);
XStoreName(x_display, win, title);
// get identifiers for the provided atom name strings
wm_state = XInternAtom(x_display, "_NET_WM_STATE", FALSE);
memset(&xev, 0, sizeof(xev));
xev.type = ClientMessage;
xev.xclient.window = win;
xev.xclient.message_type = wm_state;
xev.xclient.format = 32;
xev.xclient.data.l[0] = 1;
xev.xclient.data.l[1] = FALSE;
XSendEvent(
x_display,
DefaultRootWindow(x_display),
FALSE,
SubstructureNotifyMask,
&xev);
// end of xdisplay
// Get EGLDisplay
egldisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); //eglGetDisplay(EGL_DEFAULT_DISPLAY);
assert(egldisplay != EGL_NO_DISPLAY);
bool succes;
// Initialize EGL
succes = eglInitialize(egldisplay, &majorVersion, &minorVersion);
assert(succes);
// Get configs
succes = eglGetConfigs(egldisplay, NULL, 0, &numConfigs);
assert(succes);
// Choose config
succes = eglChooseConfig(egldisplay, attribute_list, &config, 1, &numConfigs);
assert(succes);
// Create a GL context
context = eglCreateContext(egldisplay, config, NULL, GiveMeGLES3);
assert(context != EGL_NO_CONTEXT);
// Create a surface
surface = eglCreateWindowSurface(egldisplay, config, mState.nativewindow, NULL); // this fails with a segmentation error?
assert(surface != EGL_NO_SURFACE);
succes = eglMakeCurrent(egldisplay, surface, surface, context);
assert(succes);
mState.display = egldisplay;
mState.surface = surface;
mState.context = context;
eglSwapInterval(egldisplay, 01); // 1 to lock speed to 60fps (assuming we are able to maintain it), 0 for immediate swap (may cause tearing) which will indicate actual frame rate
// on xu4 this seems to have no effect
XSetInputFocus(x_display, win, RevertToNone, CurrentTime);
// For if you want to print some extra info
if (false
&& succes)
{
int t; // a dum,ing variable to extra some useful data
printf("This SBC supports version %i.%i of EGL\n", majorVersion, minorVersion);
printf("This GPU supplied by :%s\n", glGetString(GL_VENDOR));
printf("This GPU supports :%s\n", glGetString(GL_VERSION));
printf("This GPU Renders with :%s\n", glGetString(GL_RENDERER));
printf("This GPU supports :%s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &t);
printf("This GPU MaxTexSize is :%i\n", t);
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &t);
printf("This GPU supports %i Texture units\n", t); // pi4 16
printf("This GPU supports these extensions :%s\n", glGetString(GL_EXTENSIONS));
}
glViewport(0, 0, mState.width, mState.height);
}
void GraphicsLinux::NewFrame()
{
ImGui_ImplOpenGL3_NewFrame();
ImGui::NewFrame();
}
void GraphicsLinux::Render()
{
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
glFlush();
eglSwapBuffers(mState.display, mState.surface);
}
void GraphicsLinux::Exit()
{
ImGui_ImplOpenGL3_Shutdown();
ImGui::DestroyContext();
}