Commit 5bbc53df authored by Doug Binks's avatar Doug Binks Committed by Degrande Samuel
Browse files

User context null platform and OSMESA implementation.

parent 082f2b60
...@@ -726,7 +726,6 @@ _GLFWusercontext* _glfwCreateUserContextGLX(_GLFWwindow* window) ...@@ -726,7 +726,6 @@ _GLFWusercontext* _glfwCreateUserContextGLX(_GLFWwindow* window)
context->makeCurrent = _glfwMakeUserContextCurrentGLX; context->makeCurrent = _glfwMakeUserContextCurrentGLX;
context->destroy = _glfwDestroyUserContextGLX; context->destroy = _glfwDestroyUserContextGLX;
return context; return context;
} }
......
...@@ -34,8 +34,7 @@ ...@@ -34,8 +34,7 @@
#define _GLFW_PLATFORM_CURSOR_STATE struct { int dummyCursor; } #define _GLFW_PLATFORM_CURSOR_STATE struct { int dummyCursor; }
#define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE struct { int dummyLibraryWindow; } #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE struct { int dummyLibraryWindow; }
#define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE struct { int dummyLibraryContext; } #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE struct { int dummyLibraryContext; }
#define _GLFW_EGL_CONTEXT_STATE struct { int dummyEGLContext; } #define _GLFW_PLATFORM_USER_CONTEXT_STATE struct { int dummyUserContext; }
#define _GLFW_EGL_LIBRARY_CONTEXT_STATE struct { int dummyEGLLibraryContext; }
#include "osmesa_context.h" #include "osmesa_context.h"
#include "posix_time.h" #include "posix_time.h"
......
...@@ -330,3 +330,12 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance, ...@@ -330,3 +330,12 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
return VK_ERROR_INITIALIZATION_FAILED; return VK_ERROR_INITIALIZATION_FAILED;
} }
_GLFWusercontext* _glfwPlatformCreateUserContext(_GLFWwindow* window)
{
if (window->context.osmesa.handle)
{
return _glfwCreateUserContextOSMesa(window);
}
return GLFW_FALSE;
}
...@@ -195,9 +195,9 @@ void _glfwTerminateOSMesa(void) ...@@ -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, ...@@ -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, ...@@ -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, ...@@ -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, ...@@ -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;
return NULL; _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;
}
context->makeCurrent = _glfwMakeUserContextCurrentOSMesa;
context->destroy = _glfwDestroyUserContextOSMesa;
return context;
} }
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
......
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