User context null platform and OSMESA implementation.

This commit is contained in:
Doug Binks 2020-07-14 11:41:42 +01:00
parent 51f11929f3
commit 931ba89aad
4 changed files with 78 additions and 10 deletions

View File

@ -726,7 +726,6 @@ _GLFWusercontext* _glfwCreateUserContextGLX(_GLFWwindow* window)
context->makeCurrent = _glfwMakeUserContextCurrentGLX; context->makeCurrent = _glfwMakeUserContextCurrentGLX;
context->destroy = _glfwDestroyUserContextGLX; context->destroy = _glfwDestroyUserContextGLX;
return context; return context;
} }

View File

@ -34,6 +34,7 @@
#define _GLFW_PLATFORM_CONTEXT_STATE struct { int dummyContext; } #define _GLFW_PLATFORM_CONTEXT_STATE struct { int dummyContext; }
#define _GLFW_PLATFORM_CURSOR_STATE struct { int dummyCursor; } #define _GLFW_PLATFORM_CURSOR_STATE struct { int dummyCursor; }
#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; }
#include "posix_time.h" #include "posix_time.h"
#include "posix_thread.h" #include "posix_thread.h"

View File

@ -649,3 +649,12 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
return VK_ERROR_EXTENSION_NOT_PRESENT; return VK_ERROR_EXTENSION_NOT_PRESENT;
} }
_GLFWusercontext* _glfwPlatformCreateUserContext(_GLFWwindow* window)
{
if (window->context.osmesa.handle)
{
return _glfwCreateUserContextOSMesa(window);
}
return GLFW_FALSE;
}

View File

@ -195,9 +195,9 @@ void _glfwTerminateOSMesa(void)
attribs[index++] = v; \ attribs[index++] = v; \
} }
GLFWbool _glfwCreateContextOSMesa(_GLFWwindow* window, GLFWbool _glfwCreateContextForConfigOSMesa(const _GLFWctxconfig* ctxconfig,
const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig,
const _GLFWfbconfig* fbconfig) OSMesaContext* context )
{ {
OSMesaContext share = NULL; OSMesaContext share = NULL;
const int accumBits = fbconfig->accumRedBits + const int accumBits = fbconfig->accumRedBits +
@ -248,7 +248,7 @@ GLFWbool _glfwCreateContextOSMesa(_GLFWwindow* window,
setAttrib(0, 0); setAttrib(0, 0);
window->context.osmesa.handle = *context =
OSMesaCreateContextAttribs(attribs, share); OSMesaCreateContextAttribs(attribs, share);
} }
else else
@ -260,7 +260,7 @@ GLFWbool _glfwCreateContextOSMesa(_GLFWwindow* window,
return GLFW_FALSE; return GLFW_FALSE;
} }
window->context.osmesa.handle = *context =
OSMesaCreateContextExt(OSMESA_RGBA, OSMesaCreateContextExt(OSMESA_RGBA,
fbconfig->depthBits, fbconfig->depthBits,
fbconfig->stencilBits, fbconfig->stencilBits,
@ -268,13 +268,27 @@ GLFWbool _glfwCreateContextOSMesa(_GLFWwindow* window,
share); share);
} }
if (window->context.osmesa.handle == NULL) if (*context == NULL)
{ {
_glfwInputError(GLFW_VERSION_UNAVAILABLE, _glfwInputError(GLFW_VERSION_UNAVAILABLE,
"OSMesa: Failed to create context"); "OSMesa: Failed to create context");
return GLFW_FALSE; return GLFW_FALSE;
} }
return GLFW_TRUE;
}
#undef setAttrib
GLFWbool _glfwCreateContextOSMesa(_GLFWwindow* window,
const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig)
{
if(!_glfwCreateContextForConfigOSMesa(ctxconfig,fbconfig,&window->context.osmesa.handle))
{
return GLFW_FALSE;
}
window->context.makeCurrent = makeContextCurrentOSMesa; window->context.makeCurrent = makeContextCurrentOSMesa;
window->context.swapBuffers = swapBuffersOSMesa; window->context.swapBuffers = swapBuffersOSMesa;
window->context.swapInterval = swapIntervalOSMesa; window->context.swapInterval = swapIntervalOSMesa;
@ -285,12 +299,57 @@ GLFWbool _glfwCreateContextOSMesa(_GLFWwindow* window,
return GLFW_TRUE; return GLFW_TRUE;
} }
#undef setAttrib static void _glfwMakeUserContextCurrentOSMesa(_GLFWusercontext* context)
{
if(context)
{
if (!OSMesaMakeCurrent(context->osmesa.handle,
context->window->context.osmesa.buffer,
GL_UNSIGNED_BYTE,
context->window->context.osmesa.width, context->window->context.osmesa.height))
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"OSMesa: Failed to make context current");
return;
}
}
}
static void _glfwDestroyUserContextOSMesa(_GLFWusercontext* context)
{
if (context->osmesa.handle)
{
OSMesaDestroyContext(context->osmesa.handle);
}
free(context);
}
_GLFWusercontext* _glfwCreateUserContextOSMesa(_GLFWwindow* window) _GLFWusercontext* _glfwCreateUserContextOSMesa(_GLFWwindow* window)
{ {
// TODO _GLFWusercontext* context;
_GLFWctxconfig ctxconfig;
_GLFWfbconfig fbconfig;
context = calloc(1, sizeof(_GLFWusercontext));
context->window = window;
ctxconfig = _glfw.hints.context;
ctxconfig.share = window;
fbconfig = _glfw.hints.framebuffer;
if(!_glfwCreateContextForConfigOSMesa(&ctxconfig,&fbconfig,&context->osmesa.handle))
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"OSMesa: Failed to create user OpenGL context");
free(context);
return NULL; return NULL;
}
context->makeCurrent = _glfwMakeUserContextCurrentOSMesa;
context->destroy = _glfwDestroyUserContextOSMesa;
return context;
} }
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////