From 18d3d911952525410b86f5bf1df3e47c58af6855 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 12 Oct 2024 23:43:06 +0900 Subject: [PATCH] internal/glfw: reduce TLS usages at refreshContextAttribs --- internal/glfw/context_unix.c | 18 ++++++++---------- internal/glfw/context_windows.go | 17 +++-------------- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/internal/glfw/context_unix.c b/internal/glfw/context_unix.c index ee6dc2574..f56275404 100644 --- a/internal/glfw/context_unix.c +++ b/internal/glfw/context_unix.c @@ -326,7 +326,6 @@ GLFWbool _glfwRefreshContextAttribs(_GLFWwindow* window, const _GLFWctxconfig* ctxconfig) { int i; - _GLFWwindow* previous; const char* version; const char* prefixes[] = { @@ -339,10 +338,9 @@ GLFWbool _glfwRefreshContextAttribs(_GLFWwindow* window, window->context.source = ctxconfig->source; window->context.client = GLFW_OPENGL_API; - previous = _glfwPlatformGetTls(&_glfw.contextSlot); + // In Ebitengine, only one window is created. + // Always assume that the current context is not set. glfwMakeContextCurrent((GLFWwindow*) window); - if (_glfwPlatformGetTls(&_glfw.contextSlot) != window) - return GLFW_FALSE; window->context.GetIntegerv = (PFNGLGETINTEGERVPROC) window->context.getProcAddress("glGetIntegerv"); @@ -351,7 +349,7 @@ GLFWbool _glfwRefreshContextAttribs(_GLFWwindow* window, if (!window->context.GetIntegerv || !window->context.GetString) { _glfwInputError(GLFW_PLATFORM_ERROR, "Entry point retrieval is broken"); - glfwMakeContextCurrent((GLFWwindow*) previous); + glfwMakeContextCurrent(NULL); return GLFW_FALSE; } @@ -369,7 +367,7 @@ GLFWbool _glfwRefreshContextAttribs(_GLFWwindow* window, "OpenGL ES version string retrieval is broken"); } - glfwMakeContextCurrent((GLFWwindow*) previous); + glfwMakeContextCurrent(NULL); return GLFW_FALSE; } @@ -401,7 +399,7 @@ GLFWbool _glfwRefreshContextAttribs(_GLFWwindow* window, "No version found in OpenGL ES version string"); } - glfwMakeContextCurrent((GLFWwindow*) previous); + glfwMakeContextCurrent(NULL); return GLFW_FALSE; } @@ -431,7 +429,7 @@ GLFWbool _glfwRefreshContextAttribs(_GLFWwindow* window, window->context.major, window->context.minor); } - glfwMakeContextCurrent((GLFWwindow*) previous); + glfwMakeContextCurrent(NULL); return GLFW_FALSE; } @@ -447,7 +445,7 @@ GLFWbool _glfwRefreshContextAttribs(_GLFWwindow* window, { _glfwInputError(GLFW_PLATFORM_ERROR, "Entry point retrieval is broken"); - glfwMakeContextCurrent((GLFWwindow*) previous); + glfwMakeContextCurrent(NULL); return GLFW_FALSE; } } @@ -556,7 +554,7 @@ GLFWbool _glfwRefreshContextAttribs(_GLFWwindow* window, window->context.swapBuffers(window); } - glfwMakeContextCurrent((GLFWwindow*) previous); + glfwMakeContextCurrent(NULL); return GLFW_TRUE; } diff --git a/internal/glfw/context_windows.go b/internal/glfw/context_windows.go index 836c9cbd1..3ee361daf 100644 --- a/internal/glfw/context_windows.go +++ b/internal/glfw/context_windows.go @@ -252,13 +252,10 @@ func (w *Window) refreshContextAttribs(ctxconfig *ctxconfig) (ferr error) { w.context.source = ctxconfig.source w.context.client = OpenGLAPI - p1, err := _glfw.contextSlot.get() - if err != nil { - return err - } - previous := (*Window)(unsafe.Pointer(p1)) + // In Ebitengine, only one window is created. + // Always assume that the current context is not set. defer func() { - err := previous.MakeContextCurrent() + err := (*Window)(nil).MakeContextCurrent() if ferr == nil { ferr = err } @@ -267,14 +264,6 @@ func (w *Window) refreshContextAttribs(ctxconfig *ctxconfig) (ferr error) { return err } - p2, err := _glfw.contextSlot.get() - if err != nil { - return err - } - if (*Window)(unsafe.Pointer(p2)) != w { - return nil - } - getIntegerv := w.context.getProcAddress("glGetIntegerv") getString := w.context.getProcAddress("glGetString") if getIntegerv == 0 || getString == 0 {