Update window.cpp

Fixed a problem that'd cause setting vsync to behave strangely and overlays to crash.
This commit is contained in:
2024-01-24 06:22:34 -05:00
parent 7320f07d0e
commit 668d7869fe

View File

@@ -6,22 +6,20 @@ Window window;
XEvent xev;
Display* display = XOpenDisplay(nullptr);
int defaultScreen = DefaultScreen(display);
//Visual* visual = DefaultVisual(display,defaultScreen);
XVisualInfo* visual;
//int depth = DefaultDepth(display, defaultScreen);
XSetWindowAttributes xSetWindowAttributes;
XWindowAttributes windowAttributes;
Atom wmDeleteWindow;
XSizeHints hints;
GLXContext glContext;
PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT = nullptr;
PFNGLXSWAPINTERVALEXTPROC _glXSwapIntervalEXT = nullptr; //It causes issues if it's named just "glXSwapIntervalEXT".
void RWindow::init(RenderingAPI api, const char* title, int width, int height, bool sync) {
if (api == RenderingAPI::OPENGL) {
xSetWindowAttributes.border_pixel = BlackPixel(display, defaultScreen);
xSetWindowAttributes.background_pixel = BlackPixel(display, defaultScreen);
xSetWindowAttributes.override_redirect = True;
xSetWindowAttributes.event_mask = ExposureMask;
xSetWindowAttributes.border_pixel = BlackPixel(display, defaultScreen);
xSetWindowAttributes.background_pixel = BlackPixel(display, defaultScreen);
xSetWindowAttributes.override_redirect = True;
xSetWindowAttributes.event_mask = ExposureMask;
GLint glAttributes[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None};
visual = glXChooseVisual(display, defaultScreen, glAttributes);
glContext = glXCreateContext(display, visual, nullptr, GL_TRUE);
@@ -42,6 +40,7 @@ void RWindow::init(RenderingAPI api, const char* title, int width, int height, b
wmDeleteWindow = XInternAtom(display, "WM_DELETE_WINDOW", False);
XSetWMProtocols(display, window, &wmDeleteWindow, 1);
glXMakeCurrent(display, window, glContext);
setVsyncEnabled(vsync);
} else {exit(0);}
}
@@ -199,15 +198,11 @@ MouseButtonDownEvent RWindow::getEvent(MOUSEBUTTONCODE buttoncode) {
void RWindow::glSwapBuffers() {
glXSwapBuffers(display,window);
//This seems to be the best option for now
//Because sending it *only once* doesn't work.
setVsyncEnabled(vsync);
}
void RWindow::setVsyncEnabled(bool b) {
vsync = b;
glXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddressARB((const GLubyte*)"glXSwapIntervalEXT");
glXSwapIntervalEXT(display, window, vsync);
_glXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddressARB((const GLubyte*)"glXSwapIntervalEXT");
_glXSwapIntervalEXT(display, window, vsync);
}