User context Wayland and EGL implementations

This commit is contained in:
Doug Binks 2020-07-13 18:48:10 +01:00
parent 5e94092263
commit 51f11929f3
4 changed files with 114 additions and 29 deletions

View File

@ -500,17 +500,15 @@ void _glfwTerminateEGL(void)
attribs[index++] = v; \ attribs[index++] = v; \
} }
// Create the OpenGL or OpenGL ES context // Create the OpenGL or OpenGL ES context for the window eglConfig
// //
GLFWbool _glfwCreateContextEGL(_GLFWwindow* window, GLFWbool _glfwCreateContextForConfigEGL(_GLFWwindow* window,
const _GLFWctxconfig* ctxconfig, const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig) EGLContext* context)
{ {
EGLint attribs[40]; EGLint attribs[40];
EGLConfig config;
EGLContext share = NULL;
EGLNativeWindowType native;
int index = 0; int index = 0;
EGLContext share = NULL;
if (!_glfw.egl.display) if (!_glfw.egl.display)
{ {
@ -521,13 +519,6 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window,
if (ctxconfig->share) if (ctxconfig->share)
share = ctxconfig->share->context.egl.handle; share = ctxconfig->share->context.egl.handle;
if (!chooseEGLConfig(ctxconfig, fbconfig, &config))
{
_glfwInputError(GLFW_FORMAT_UNAVAILABLE,
"EGL: Failed to find a suitable EGLConfig");
return GLFW_FALSE;
}
if (ctxconfig->client == GLFW_OPENGL_ES_API) if (ctxconfig->client == GLFW_OPENGL_ES_API)
{ {
if (!eglBindAPI(EGL_OPENGL_ES_API)) if (!eglBindAPI(EGL_OPENGL_ES_API))
@ -624,7 +615,7 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window,
setAttrib(EGL_NONE, EGL_NONE); setAttrib(EGL_NONE, EGL_NONE);
window->context.egl.handle = eglCreateContext(_glfw.egl.display, window->context.egl.handle = eglCreateContext(_glfw.egl.display,
config, share, attribs); window->context.egl.config, share, attribs);
if (window->context.egl.handle == EGL_NO_CONTEXT) if (window->context.egl.handle == EGL_NO_CONTEXT)
{ {
@ -634,9 +625,32 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window,
return GLFW_FALSE; return GLFW_FALSE;
} }
// Set up attributes for surface creation return GLFW_TRUE;
index = 0; }
// Create the OpenGL or OpenGL ES context
//
GLFWbool _glfwCreateContextEGL(_GLFWwindow* window,
const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig)
{
EGLNativeWindowType native;
EGLint attribs[40];
int index = 0;
if (!chooseEGLConfig(ctxconfig, fbconfig, &window->context.egl.config))
{
_glfwInputError(GLFW_FORMAT_UNAVAILABLE,
"EGL: Failed to find a suitable EGLConfig");
return GLFW_FALSE;
}
if (!_glfwCreateContextForConfigEGL(window,ctxconfig,&window->context.egl.handle))
{
return GLFW_FALSE;
}
// Set up attributes for surface creation
if (fbconfig->sRGB) if (fbconfig->sRGB)
{ {
if (_glfw.egl.KHR_gl_colorspace) if (_glfw.egl.KHR_gl_colorspace)
@ -651,12 +665,12 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window,
if (_glfw.egl.platform && _glfw.egl.platform != EGL_PLATFORM_ANGLE_ANGLE) if (_glfw.egl.platform && _glfw.egl.platform != EGL_PLATFORM_ANGLE_ANGLE)
{ {
window->context.egl.surface = window->context.egl.surface =
eglCreatePlatformWindowSurfaceEXT(_glfw.egl.display, config, native, attribs); eglCreatePlatformWindowSurfaceEXT(_glfw.egl.display, window->context.egl.config, native, attribs);
} }
else else
{ {
window->context.egl.surface = window->context.egl.surface =
eglCreateWindowSurface(_glfw.egl.display, config, native, attribs); eglCreateWindowSurface(_glfw.egl.display, window->context.egl.config, native, attribs);
} }
if (window->context.egl.surface == EGL_NO_SURFACE) if (window->context.egl.surface == EGL_NO_SURFACE)
@ -667,7 +681,6 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window,
return GLFW_FALSE; return GLFW_FALSE;
} }
window->context.egl.config = config;
// Load the appropriate client library // Load the appropriate client library
if (!_glfw.egl.KHR_get_all_proc_addresses) if (!_glfw.egl.KHR_get_all_proc_addresses)
@ -802,10 +815,68 @@ GLFWbool _glfwChooseVisualEGL(const _GLFWwndconfig* wndconfig,
} }
#endif // _GLFW_X11 #endif // _GLFW_X11
static void _glfwMakeUserContextCurrentEGL(_GLFWusercontext* context)
{
if(context)
{
if (!eglMakeCurrent(_glfw.egl.display,
context->window->context.egl.surface,
context->window->context.egl.surface,
context->egl.handle))
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"EGL: Failed to make context current: %s",
getEGLErrorString(eglGetError()));
return;
}
}
else
{
if (!eglMakeCurrent(_glfw.egl.display,
EGL_NO_SURFACE,
EGL_NO_SURFACE,
EGL_NO_CONTEXT))
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"EGL: Failed to clear current context: %s",
getEGLErrorString(eglGetError()));
return;
}
}
}
static void _glfwDestroyUserContextEGL(_GLFWusercontext* context)
{
if (context->egl.handle)
{
eglDestroyContext(_glfw.egl.display, context->egl.handle);
}
free(context);
}
_GLFWusercontext* _glfwCreateUserContextEGL(_GLFWwindow* window) _GLFWusercontext* _glfwCreateUserContextEGL(_GLFWwindow* window)
{ {
// TODO _GLFWusercontext* context;
return NULL; _GLFWctxconfig ctxconfig;
context = calloc(1, sizeof(_GLFWusercontext));
context->window = window;
ctxconfig = _glfw.hints.context;
ctxconfig.share = window;
if(!_glfwCreateContextForConfigEGL(window,&ctxconfig,&context->egl.handle))
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"EGL: Failed to create user OpenGL context");
free(context);
return NULL;
}
context->makeCurrent = _glfwMakeUserContextCurrentEGL;
context->destroy = _glfwDestroyUserContextEGL;
return context;
} }

View File

@ -119,6 +119,13 @@ typedef struct _GLFWcontextWGL
} _GLFWcontextWGL; } _GLFWcontextWGL;
// WGL-specific user context data
//
typedef struct _GLFWusercontextWGL
{
HGLRC handle;
} _GLFWusercontextWGL;
// WGL-specific global data // WGL-specific global data
// //
typedef struct _GLFWlibraryWGL typedef struct _GLFWlibraryWGL
@ -152,13 +159,6 @@ typedef struct _GLFWlibraryWGL
} _GLFWlibraryWGL; } _GLFWlibraryWGL;
// WGL-specific user context data
//
typedef struct _GLFWusercontextWGL
{
HGLRC handle;
} _GLFWusercontextWGL;
GLFWbool _glfwInitWGL(void); GLFWbool _glfwInitWGL(void);
void _glfwTerminateWGL(void); void _glfwTerminateWGL(void);
GLFWbool _glfwCreateContextWGL(_GLFWwindow* window, GLFWbool _glfwCreateContextWGL(_GLFWwindow* window,

View File

@ -72,6 +72,7 @@ typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR
#define _GLFW_PLATFORM_CONTEXT_STATE struct { int dummyContext; } #define _GLFW_PLATFORM_CONTEXT_STATE struct { int dummyContext; }
#define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE struct { int dummyLibraryContext; } #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE struct { int dummyLibraryContext; }
#define _GLFW_PLATFORM_USER_CONTEXT_STATE struct { int dummyUserContext; }
struct wl_cursor_image { struct wl_cursor_image {
uint32_t width; uint32_t width;

View File

@ -1765,6 +1765,19 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
return err; return err;
} }
_GLFWusercontext* _glfwPlatformCreateUserContext(_GLFWwindow* window)
{
if (window->context.egl.handle)
{
return _glfwCreateUserContextEGL(window);
}
else if (window->context.osmesa.handle)
{
return _glfwCreateUserContextOSMesa(window);
}
return GLFW_FALSE;
}
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
////// GLFW native API ////// ////// GLFW native API //////