Remove need for context switching
Call wl_egl_window_resize just buffer swapping buffers at which point the context is already correct. Also might workaround bugs in the NVIDIA driver: https://github.com/NVIDIA/egl-wayland/issues/52
This commit is contained in:
parent
b7e22a357f
commit
72272ab4fe
4 changed files with 15 additions and 9 deletions
3
glfw/context.c
vendored
3
glfw/context.c
vendored
|
|
@ -476,6 +476,9 @@ GLFWAPI void glfwSwapBuffers(GLFWwindow* handle)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _GLFW_WAYLAND
|
||||||
|
_glfwWaylandBeforeBufferSwap(window);
|
||||||
|
#endif
|
||||||
window->context.swapBuffers(window);
|
window->context.swapBuffers(window);
|
||||||
#ifdef _GLFW_WAYLAND
|
#ifdef _GLFW_WAYLAND
|
||||||
_glfwWaylandAfterBufferSwap(window);
|
_glfwWaylandAfterBufferSwap(window);
|
||||||
|
|
|
||||||
4
glfw/wl_platform.h
vendored
4
glfw/wl_platform.h
vendored
|
|
@ -185,6 +185,9 @@ typedef struct _GLFWwindowWayland
|
||||||
struct zwlr_layer_surface_v1* zwlr_layer_surface_v1;
|
struct zwlr_layer_surface_v1* zwlr_layer_surface_v1;
|
||||||
} layer_shell;
|
} layer_shell;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
int width, height;
|
||||||
|
} framebuffer_size_at_last_resize;
|
||||||
/* information about axis events on current frame */
|
/* information about axis events on current frame */
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
|
|
@ -420,6 +423,7 @@ typedef struct _GLFWcursorWayland
|
||||||
|
|
||||||
|
|
||||||
void _glfwAddOutputWayland(uint32_t name, uint32_t version);
|
void _glfwAddOutputWayland(uint32_t name, uint32_t version);
|
||||||
|
void _glfwWaylandBeforeBufferSwap(_GLFWwindow *window);
|
||||||
void _glfwWaylandAfterBufferSwap(_GLFWwindow *window);
|
void _glfwWaylandAfterBufferSwap(_GLFWwindow *window);
|
||||||
void _glfwSetupWaylandDataDevice(void);
|
void _glfwSetupWaylandDataDevice(void);
|
||||||
void _glfwSetupWaylandPrimarySelectionDevice(void);
|
void _glfwSetupWaylandPrimarySelectionDevice(void);
|
||||||
|
|
|
||||||
13
glfw/wl_window.c
vendored
13
glfw/wl_window.c
vendored
|
|
@ -356,24 +356,25 @@ _glfwWaylandWindowScale(_GLFWwindow *window) {
|
||||||
return ans;
|
return ans;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct with_context { _GLFWwindow *current, *new; } with_context;
|
|
||||||
static inline void with_context_release(with_context *c) { if (c->current != c->new) glfwMakeContextCurrent((GLFWwindow*)c->current); }
|
|
||||||
#define RAII_window_context(window) with_context __wc __attribute__((cleanup(with_context_release))) = { .current=(_GLFWwindow*)glfwGetCurrentContext(), .new=window }; if (__wc.current != __wc.new) glfwMakeContextCurrent((GLFWwindow*)__wc.new);
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
resizeFramebuffer(_GLFWwindow* window) {
|
resizeFramebuffer(_GLFWwindow* window) {
|
||||||
RAII_window_context(window); // ensure wl_egl_window_resize called with correct context
|
|
||||||
double scale = _glfwWaylandWindowScale(window);
|
double scale = _glfwWaylandWindowScale(window);
|
||||||
int scaled_width = (int)round(window->wl.width * scale);
|
int scaled_width = (int)round(window->wl.width * scale);
|
||||||
int scaled_height = (int)round(window->wl.height * scale);
|
int scaled_height = (int)round(window->wl.height * scale);
|
||||||
debug("Resizing framebuffer of window: %llu to: %dx%d window size: %dx%d at scale: %.3f\n",
|
debug("Resizing framebuffer of window: %llu to: %dx%d window size: %dx%d at scale: %.3f\n",
|
||||||
window->id, scaled_width, scaled_height, window->wl.width, window->wl.height, scale);
|
window->id, scaled_width, scaled_height, window->wl.width, window->wl.height, scale);
|
||||||
wl_egl_window_resize(window->wl.native, scaled_width, scaled_height, 0, 0);
|
|
||||||
update_regions(window);
|
update_regions(window);
|
||||||
window->wl.waiting_for_swap_to_commit = true;
|
window->wl.waiting_for_swap_to_commit = true;
|
||||||
|
window->wl.framebuffer_size_at_last_resize.width = scaled_width;
|
||||||
|
window->wl.framebuffer_size_at_last_resize.height = scaled_height;
|
||||||
_glfwInputFramebufferSize(window, scaled_width, scaled_height);
|
_glfwInputFramebufferSize(window, scaled_width, scaled_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_glfwWaylandBeforeBufferSwap(_GLFWwindow* window) {
|
||||||
|
wl_egl_window_resize(window->wl.native, window->wl.framebuffer_size_at_last_resize.width, window->wl.framebuffer_size_at_last_resize.height, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_glfwWaylandAfterBufferSwap(_GLFWwindow* window) {
|
_glfwWaylandAfterBufferSwap(_GLFWwindow* window) {
|
||||||
if (window->wl.temp_buffer_used_during_window_creation) {
|
if (window->wl.temp_buffer_used_during_window_creation) {
|
||||||
|
|
|
||||||
|
|
@ -1191,9 +1191,7 @@ create_os_window(PyObject UNUSED *self, PyObject *args, PyObject *kw) {
|
||||||
if (temp_window) { glfwDestroyWindow(temp_window); temp_window = NULL; }
|
if (temp_window) { glfwDestroyWindow(temp_window); temp_window = NULL; }
|
||||||
if (glfw_window == NULL) { PyErr_SetString(PyExc_ValueError, "Failed to create GLFWwindow"); return NULL; }
|
if (glfw_window == NULL) { PyErr_SetString(PyExc_ValueError, "Failed to create GLFWwindow"); return NULL; }
|
||||||
glfwMakeContextCurrent(glfw_window);
|
glfwMakeContextCurrent(glfw_window);
|
||||||
if (is_first_window) {
|
if (is_first_window) gl_init();
|
||||||
gl_init();
|
|
||||||
}
|
|
||||||
// Will make the GPU automatically apply SRGB gamma curve on the resulting framebuffer
|
// Will make the GPU automatically apply SRGB gamma curve on the resulting framebuffer
|
||||||
glEnable(GL_FRAMEBUFFER_SRGB);
|
glEnable(GL_FRAMEBUFFER_SRGB);
|
||||||
bool is_semi_transparent = glfwGetWindowAttrib(glfw_window, GLFW_TRANSPARENT_FRAMEBUFFER);
|
bool is_semi_transparent = glfwGetWindowAttrib(glfw_window, GLFW_TRANSPARENT_FRAMEBUFFER);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue