Commit 082f2b60 authored by Doug Binks's avatar Doug Binks Committed by Degrande Samuel
Browse files

User context Wayland and EGL implementations

parent b3cadd67
......@@ -454,16 +454,15 @@ void _glfwTerminateEGL(void)
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 _GLFWfbconfig* fbconfig)
EGLContext* context)
{
EGLint attribs[40];
EGLConfig config;
EGLContext share = NULL;
int index = 0;
EGLContext share = NULL;
if (!_glfw.egl.display)
{
......@@ -474,13 +473,6 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window,
if (ctxconfig->share)
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 (!eglBindAPI(EGL_OPENGL_ES_API))
......@@ -577,7 +569,7 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window,
setAttrib(EGL_NONE, EGL_NONE);
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)
{
......@@ -587,10 +579,32 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window,
return GLFW_FALSE;
}
// Set up attributes for surface creation
{
return GLFW_TRUE;
}
// 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 (_glfw.egl.KHR_gl_colorspace)
......@@ -598,6 +612,19 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window,
}
setAttrib(EGL_NONE, EGL_NONE);
native = _glfwPlatformGetEGLNativeWindow(window);
// HACK: ANGLE does not implement eglCreatePlatformWindowSurfaceEXT
// despite reporting EGL_EXT_platform_base
if (_glfw.egl.platform && _glfw.egl.platform != EGL_PLATFORM_ANGLE_ANGLE)
{
window->context.egl.surface =
eglCreatePlatformWindowSurfaceEXT(_glfw.egl.display, window->context.egl.config, native, attribs);
}
else
{
window->context.egl.surface =
eglCreateWindowSurface(_glfw.egl.display, window->context.egl.config, native, attribs);
}
window->context.egl.surface =
......@@ -613,7 +640,6 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window,
return GLFW_FALSE;
}
window->context.egl.config = config;
// Load the appropriate client library
if (!_glfw.egl.KHR_get_all_proc_addresses)
......@@ -748,10 +774,68 @@ GLFWbool _glfwChooseVisualEGL(const _GLFWwndconfig* wndconfig,
}
#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)
{
// TODO
_GLFWusercontext* context;
_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;
}
......
......@@ -123,6 +123,13 @@ typedef struct _GLFWcontextWGL
} _GLFWcontextWGL;
// WGL-specific user context data
//
typedef struct _GLFWusercontextWGL
{
HGLRC handle;
} _GLFWusercontextWGL;
// WGL-specific global data
//
typedef struct _GLFWlibraryWGL
......@@ -156,13 +163,6 @@ typedef struct _GLFWlibraryWGL
} _GLFWlibraryWGL;
// WGL-specific user context data
//
typedef struct _GLFWusercontextWGL
{
HGLRC handle;
} _GLFWusercontextWGL;
GLFWbool _glfwInitWGL(void);
void _glfwTerminateWGL(void);
GLFWbool _glfwCreateContextWGL(_GLFWwindow* window,
......
......@@ -77,6 +77,7 @@ typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR
#define _GLFW_PLATFORM_CONTEXT_STATE struct { int dummyContext; }
#define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE struct { int dummyLibraryContext; }
#define _GLFW_PLATFORM_USER_CONTEXT_STATE struct { int dummyUserContext; }
struct wl_cursor_image {
uint32_t width;
......
......@@ -1874,6 +1874,19 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
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 //////
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment