mirror of
https://github.com/glfw/glfw.git
synced 2026-09-22 16:52:57 +00:00
Add GLFW_NO_API for creating context-less windows
This commit is contained in:
+47
-42
@@ -665,10 +665,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||
|
||||
// Creates the GLFW window and rendering context
|
||||
//
|
||||
static GLFWbool createWindow(_GLFWwindow* window,
|
||||
const _GLFWwndconfig* wndconfig,
|
||||
const _GLFWctxconfig* ctxconfig,
|
||||
const _GLFWfbconfig* fbconfig)
|
||||
static int createWindow(_GLFWwindow* window, const _GLFWwndconfig* wndconfig)
|
||||
{
|
||||
int xpos, ypos, fullWidth, fullHeight;
|
||||
WCHAR* wideTitle;
|
||||
@@ -742,9 +739,6 @@ static GLFWbool createWindow(_GLFWwindow* window,
|
||||
|
||||
DragAcceptFiles(window->win32.handle, TRUE);
|
||||
|
||||
if (!_glfwCreateContext(window, ctxconfig, fbconfig))
|
||||
return GLFW_FALSE;
|
||||
|
||||
window->win32.minwidth = GLFW_DONT_CARE;
|
||||
window->win32.minheight = GLFW_DONT_CARE;
|
||||
window->win32.maxwidth = GLFW_DONT_CARE;
|
||||
@@ -759,8 +753,6 @@ static GLFWbool createWindow(_GLFWwindow* window,
|
||||
//
|
||||
static void destroyWindow(_GLFWwindow* window)
|
||||
{
|
||||
_glfwDestroyContext(window);
|
||||
|
||||
if (window->win32.handle)
|
||||
{
|
||||
DestroyWindow(window->win32.handle);
|
||||
@@ -830,43 +822,53 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
|
||||
{
|
||||
int status;
|
||||
|
||||
if (!createWindow(window, wndconfig, ctxconfig, fbconfig))
|
||||
if (!createWindow(window, wndconfig))
|
||||
return GLFW_FALSE;
|
||||
|
||||
status = _glfwAnalyzeContext(window, ctxconfig, fbconfig);
|
||||
|
||||
if (status == _GLFW_RECREATION_IMPOSSIBLE)
|
||||
return GLFW_FALSE;
|
||||
|
||||
if (status == _GLFW_RECREATION_REQUIRED)
|
||||
if (ctxconfig->api != GLFW_NO_API)
|
||||
{
|
||||
// Some window hints require us to re-create the context using WGL
|
||||
// extensions retrieved through the current context, as we cannot check
|
||||
// for WGL extensions or retrieve WGL entry points before we have a
|
||||
// current context (actually until we have implicitly loaded the ICD)
|
||||
|
||||
// Yes, this is strange, and yes, this is the proper way on Win32
|
||||
|
||||
// As Windows only allows you to set the pixel format once for a
|
||||
// window, we need to destroy the current window and create a new one
|
||||
// to be able to use the new pixel format
|
||||
|
||||
// Technically, it may be possible to keep the old window around if
|
||||
// we're just creating an OpenGL 3.0+ context with the same pixel
|
||||
// format, but it's not worth the added code complexity
|
||||
|
||||
// First we clear the current context (the one we just created)
|
||||
// This is usually done by glfwDestroyWindow, but as we're not doing
|
||||
// full GLFW window destruction, it's duplicated here
|
||||
_glfwPlatformMakeContextCurrent(NULL);
|
||||
|
||||
// Next destroy the Win32 window and WGL context (without resetting or
|
||||
// destroying the GLFW window object)
|
||||
destroyWindow(window);
|
||||
|
||||
// ...and then create them again, this time with better APIs
|
||||
if (!createWindow(window, wndconfig, ctxconfig, fbconfig))
|
||||
if (!_glfwCreateContext(window, ctxconfig, fbconfig))
|
||||
return GLFW_FALSE;
|
||||
|
||||
status = _glfwAnalyzeContext(window, ctxconfig, fbconfig);
|
||||
|
||||
if (status == _GLFW_RECREATION_IMPOSSIBLE)
|
||||
return GLFW_FALSE;
|
||||
|
||||
if (status == _GLFW_RECREATION_REQUIRED)
|
||||
{
|
||||
// Some window hints require us to re-create the context using WGL
|
||||
// extensions retrieved through the current context, as we cannot
|
||||
// check for WGL extensions or retrieve WGL entry points before we
|
||||
// have a current context (actually until we have implicitly loaded
|
||||
// the vendor ICD)
|
||||
|
||||
// Yes, this is strange, and yes, this is the proper way on Win32
|
||||
|
||||
// As Windows only allows you to set the pixel format once for
|
||||
// a window, we need to destroy the current window and create a new
|
||||
// one to be able to use the new pixel format
|
||||
|
||||
// Technically, it may be possible to keep the old window around if
|
||||
// we're just creating an OpenGL 3.0+ context with the same pixel
|
||||
// format, but it's not worth the added code complexity
|
||||
|
||||
// First we clear the current context (the one we just created)
|
||||
// This is usually done by glfwDestroyWindow, but as we're not doing
|
||||
// full GLFW window destruction, it's duplicated here
|
||||
_glfwPlatformMakeContextCurrent(NULL);
|
||||
|
||||
// Next destroy the Win32 window and WGL context (without resetting
|
||||
// or destroying the GLFW window object)
|
||||
_glfwDestroyContext(window);
|
||||
destroyWindow(window);
|
||||
|
||||
// ...and then create them again, this time with better APIs
|
||||
if (!createWindow(window, wndconfig))
|
||||
return GLFW_FALSE;
|
||||
if (!_glfwCreateContext(window, ctxconfig, fbconfig))
|
||||
return GLFW_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (window->monitor)
|
||||
@@ -884,6 +886,9 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window)
|
||||
if (window->monitor)
|
||||
leaveFullscreenMode(window);
|
||||
|
||||
if (window->context.api != GLFW_NO_API)
|
||||
_glfwDestroyContext(window);
|
||||
|
||||
destroyWindow(window);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user