Pass shared context and parent window as window hints.

This CL doesn't include other platform since I'm not familiar with them.
Nevertheless, it would be cool to be able to pass shared context and
parent window as optional window hints.
CreateWindow no more need extra parameter to be passed (I assume 99% of
time, no one even use this). hints.context.share already exists. Its
just set in glfwChildWindowHind (the name can be changed, I really
didn't come with anything better).
This commit is contained in:
Kamil Nowakowski 2017-10-14 14:14:01 +02:00
parent 56ecd62f58
commit 22e2180a17
4 changed files with 62 additions and 6 deletions

View File

@ -942,6 +942,17 @@ extern "C" {
*/ */
#define GLFW_CONTEXT_CREATION_API 0x0002200B #define GLFW_CONTEXT_CREATION_API 0x0002200B
/*! @brief Window that will share context with new one
*
* Window shared context [window hint]
*/
#define GLFW_SHARE_CONTEXT 0x00000001
/*! @brief Window that is parent in hierarchy to new one
*
* Parent window [window hint]
*/
#define GLFW_PARENT_WINDOW 0x00000002
#define GLFW_COCOA_RETINA_FRAMEBUFFER 0x00023001 #define GLFW_COCOA_RETINA_FRAMEBUFFER 0x00023001
#define GLFW_COCOA_FRAME_AUTOSAVE 0x00023002 #define GLFW_COCOA_FRAME_AUTOSAVE 0x00023002
#define GLFW_COCOA_GRAPHICS_SWITCHING 0x00023003 #define GLFW_COCOA_GRAPHICS_SWITCHING 0x00023003
@ -2187,6 +2198,30 @@ GLFWAPI void glfwDefaultWindowHints(void);
*/ */
GLFWAPI void glfwWindowHint(int hint, int value); GLFWAPI void glfwWindowHint(int hint, int value);
/*! @brief Sets the specified window hint to the desired value.
*
* This function sets hints for the next call to @ref glfwCreateWindow. The
* hints, once set, retain their values until changed by a call to @ref
* glfwWindowHint or @ref glfwDefaultWindowHints, or until the library is
* terminated.
*
* @param[in] hint The [window hint](@ref window_hints) to set.
* @param[in] value The new value of the window hint.
*
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_INVALID_ENUM.
*
* @thread_safety This function must only be called from the main thread.
*
* @sa @ref window_hints
* @sa @ref glfwDefaultWindowHints
*
* @since Added in version 3.3.
*
* @ingroup window
*/
GLFWAPI void glfwChildWindowHint( int hint, const GLFWwindow* value );
/*! @brief Creates a window and its associated context. /*! @brief Creates a window and its associated context.
* *
* This function creates a window and its associated OpenGL or OpenGL ES * This function creates a window and its associated OpenGL or OpenGL ES
@ -2337,7 +2372,9 @@ GLFWAPI void glfwWindowHint(int hint, int value);
* *
* @ingroup window * @ingroup window
*/ */
GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, const char* title, GLFWmonitor* monitor, GLFWwindow* share);
GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, const char* title, GLFWmonitor* monitor );
/*! @brief Destroys the specified window and its context. /*! @brief Destroys the specified window and its context.
* *

View File

@ -304,6 +304,7 @@ struct _GLFWwndconfig
GLFWbool floating; GLFWbool floating;
GLFWbool maximized; GLFWbool maximized;
GLFWbool centerCursor; GLFWbool centerCursor;
const _GLFWwindow* parent;
struct { struct {
GLFWbool retina; GLFWbool retina;
GLFWbool frame; GLFWbool frame;
@ -328,7 +329,7 @@ struct _GLFWctxconfig
int profile; int profile;
int robustness; int robustness;
int release; int release;
_GLFWwindow* share; const _GLFWwindow* share;
struct { struct {
GLFWbool offline; GLFWbool offline;
} nsgl; } nsgl;

View File

@ -1080,7 +1080,7 @@ static int createNativeWindow(_GLFWwindow* window,
style, style,
xpos, ypos, xpos, ypos,
fullWidth, fullHeight, fullWidth, fullHeight,
NULL, // No parent window wndconfig->parent ? wndconfig->parent->win32.handle : NULL,
NULL, // No window menu NULL, // No window menu
GetModuleHandleW(NULL), GetModuleHandleW(NULL),
NULL); NULL);

View File

@ -120,8 +120,7 @@ void _glfwInputWindowMonitorChange(_GLFWwindow* window, _GLFWmonitor* monitor)
GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
const char* title, const char* title,
GLFWmonitor* monitor, GLFWmonitor* monitor )
GLFWwindow* share)
{ {
_GLFWfbconfig fbconfig; _GLFWfbconfig fbconfig;
_GLFWctxconfig ctxconfig; _GLFWctxconfig ctxconfig;
@ -151,7 +150,6 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
wndconfig.width = width; wndconfig.width = width;
wndconfig.height = height; wndconfig.height = height;
wndconfig.title = title; wndconfig.title = title;
ctxconfig.share = (_GLFWwindow*) share;
if (ctxconfig.share) if (ctxconfig.share)
{ {
@ -243,6 +241,7 @@ void glfwDefaultWindowHints(void)
_glfw.hints.context.source = GLFW_NATIVE_CONTEXT_API; _glfw.hints.context.source = GLFW_NATIVE_CONTEXT_API;
_glfw.hints.context.major = 1; _glfw.hints.context.major = 1;
_glfw.hints.context.minor = 0; _glfw.hints.context.minor = 0;
_glfw.hints.context.share = NULL;
// The default is a focused, visible, resizable window with decorations // The default is a focused, visible, resizable window with decorations
memset(&_glfw.hints.window, 0, sizeof(_glfw.hints.window)); memset(&_glfw.hints.window, 0, sizeof(_glfw.hints.window));
@ -251,6 +250,7 @@ void glfwDefaultWindowHints(void)
_glfw.hints.window.decorated = GLFW_TRUE; _glfw.hints.window.decorated = GLFW_TRUE;
_glfw.hints.window.focused = GLFW_TRUE; _glfw.hints.window.focused = GLFW_TRUE;
_glfw.hints.window.autoIconify = GLFW_TRUE; _glfw.hints.window.autoIconify = GLFW_TRUE;
_glfw.hints.window.parent = NULL;
// The default is 24 bits of color, 24 bits of depth and 8 bits of stencil, // The default is 24 bits of color, 24 bits of depth and 8 bits of stencil,
// double buffered // double buffered
@ -270,6 +270,24 @@ void glfwDefaultWindowHints(void)
_glfw.hints.window.ns.retina = GLFW_TRUE; _glfw.hints.window.ns.retina = GLFW_TRUE;
} }
GLFWAPI void glfwChildWindowHint( int hint, const GLFWwindow* value )
{
_GLFW_REQUIRE_INIT();
switch( hint )
{
case GLFW_SHARE_CONTEXT:
_glfw.hints.context.share = (const _GLFWwindow*)value;
return;
case GLFW_PARENT_WINDOW:
_glfw.hints.window.parent = (const _GLFWwindow*)value;
return;
}
_glfwInputError( GLFW_INVALID_ENUM, "Invalid window hint 0x%08X", hint );
}
GLFWAPI void glfwWindowHint(int hint, int value) GLFWAPI void glfwWindowHint(int hint, int value)
{ {
_GLFW_REQUIRE_INIT(); _GLFW_REQUIRE_INIT();