From 62012e3c68ea1e39aaf50045c863f0b90c29065f Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 8 Nov 2016 22:44:59 +0100 Subject: [PATCH] OSMesa: Add fallback to OSMesaCreateContextExt --- src/osmesa_context.c | 72 ++++++++++++++++++++++++++++++-------------- src/osmesa_context.h | 3 ++ 2 files changed, 52 insertions(+), 23 deletions(-) diff --git a/src/osmesa_context.c b/src/osmesa_context.c index 65fb6e92..852d4e54 100644 --- a/src/osmesa_context.c +++ b/src/osmesa_context.c @@ -120,6 +120,7 @@ GLFWbool _glfwInitOSMesa(void) #elif defined(__CYGWIN__) "libOSMesa-8.so", #else + "libOSMesa.so.8", "libOSMesa.so.6", #endif NULL @@ -141,6 +142,8 @@ GLFWbool _glfwInitOSMesa(void) return GLFW_FALSE; } + _glfw.osmesa.CreateContextExt = (PFNOSMESACREATECONTEXTEXTPROC) + _glfw_dlsym(_glfw.osmesa.handle, "OSMesaCreateContextExt"); _glfw.osmesa.CreateContextAttribs = (PFNOSMESACREATECONTEXTATTRIBSPROC) _glfw_dlsym(_glfw.osmesa.handle, "OSMesaCreateContextAttribs"); _glfw.osmesa.DestroyContext = (PFNOSMESADESTROYCONTEXTPROC) @@ -154,7 +157,7 @@ GLFWbool _glfwInitOSMesa(void) _glfw.osmesa.GetProcAddress = (PFNOSMESAGETPROCADDRESSPROC) _glfw_dlsym(_glfw.osmesa.handle, "OSMesaGetProcAddress"); - if (!_glfw.osmesa.CreateContextAttribs || + if (!_glfw.osmesa.CreateContextExt || !_glfw.osmesa.DestroyContext || !_glfw.osmesa.MakeCurrent || !_glfw.osmesa.GetColorBuffer || @@ -192,37 +195,60 @@ GLFWbool _glfwCreateContextOSMesa(_GLFWwindow* window, const _GLFWfbconfig* fbconfig) { OSMesaContext share = NULL; - int index = 0, attribs[40]; + const int accumBits = fbconfig->accumRedBits + + fbconfig->accumGreenBits + + fbconfig->accumBlueBits + + fbconfig->accumAlphaBits; if (ctxconfig->share) share = ctxconfig->share->context.osmesa.handle; - setAttrib(OSMESA_FORMAT, OSMESA_RGBA); - setAttrib(OSMESA_DEPTH_BITS, fbconfig->depthBits); - setAttrib(OSMESA_STENCIL_BITS, fbconfig->stencilBits); - setAttrib(OSMESA_ACCUM_BITS, fbconfig->accumRedBits + - fbconfig->accumGreenBits + - fbconfig->accumBlueBits + - fbconfig->accumAlphaBits); + if (OSMesaCreateContextAttribs) + { + int index = 0, attribs[40]; - if (ctxconfig->profile == GLFW_OPENGL_CORE_PROFILE) - { - setAttrib(OSMESA_PROFILE, OSMESA_CORE_PROFILE); + setAttrib(OSMESA_FORMAT, OSMESA_RGBA); + setAttrib(OSMESA_DEPTH_BITS, fbconfig->depthBits); + setAttrib(OSMESA_STENCIL_BITS, fbconfig->stencilBits); + setAttrib(OSMESA_ACCUM_BITS, accumBits); + + if (ctxconfig->profile == GLFW_OPENGL_CORE_PROFILE) + { + setAttrib(OSMESA_PROFILE, OSMESA_CORE_PROFILE); + } + else if (ctxconfig->profile == GLFW_OPENGL_COMPAT_PROFILE) + { + setAttrib(OSMESA_PROFILE, OSMESA_COMPAT_PROFILE); + } + + if (ctxconfig->major != 1 || ctxconfig->minor != 0) + { + setAttrib(OSMESA_CONTEXT_MAJOR_VERSION, ctxconfig->major); + setAttrib(OSMESA_CONTEXT_MINOR_VERSION, ctxconfig->minor); + } + + setAttrib(0, 0); + + window->context.osmesa.handle = + OSMesaCreateContextAttribs(attribs, share); } - else if (ctxconfig->profile == GLFW_OPENGL_COMPAT_PROFILE) + else { - setAttrib(OSMESA_PROFILE, OSMESA_COMPAT_PROFILE); + if (ctxconfig->profile) + { + _glfwInputError(GLFW_VERSION_UNAVAILABLE, + "OSMesa: OpenGL profiles unavailable"); + return GLFW_FALSE; + } + + window->context.osmesa.handle = + OSMesaCreateContextExt(OSMESA_RGBA, + fbconfig->depthBits, + fbconfig->stencilBits, + accumBits, + share); } - if (ctxconfig->major != 1 || ctxconfig->minor != 0) - { - setAttrib(OSMESA_CONTEXT_MAJOR_VERSION, ctxconfig->major); - setAttrib(OSMESA_CONTEXT_MINOR_VERSION, ctxconfig->minor); - } - - setAttrib(0, 0); - - window->context.osmesa.handle = OSMesaCreateContextAttribs(attribs, share); if (window->context.osmesa.handle == NULL) { _glfwInputError(GLFW_VERSION_UNAVAILABLE, diff --git a/src/osmesa_context.h b/src/osmesa_context.h index 2dbac9dd..5b49b054 100644 --- a/src/osmesa_context.h +++ b/src/osmesa_context.h @@ -43,11 +43,13 @@ typedef void* OSMesaContext; typedef void (*OSMESAproc)(); typedef OSMesaContext (* PFNOSMESACREATECONTEXTATTRIBSPROC)(const int*,OSMesaContext); +typedef OSMesaContext (* PFNOSMESACREATECONTEXTEXTPROC)(GLenum,GLint,GLint,GLint,OSMesaContext); typedef void (* PFNOSMESADESTROYCONTEXTPROC)(OSMesaContext); typedef int (* PFNOSMESAMAKECURRENTPROC)(OSMesaContext,void*,int,int,int); typedef int (* PFNOSMESAGETCOLORBUFFERPROC)(OSMesaContext,int*,int*,int*,void**); typedef int (* PFNOSMESAGETDEPTHBUFFERPROC)(OSMesaContext,int*,int*,int*,void**); typedef GLFWglproc (* PFNOSMESAGETPROCADDRESSPROC)(const char*); +#define OSMesaCreateContextExt _glfw.osmesa.CreateContextExt #define OSMesaCreateContextAttribs _glfw.osmesa.CreateContextAttribs #define OSMesaDestroyContext _glfw.osmesa.DestroyContext #define OSMesaMakeCurrent _glfw.osmesa.MakeCurrent @@ -76,6 +78,7 @@ typedef struct _GLFWlibraryOSMesa { void* handle; + PFNOSMESACREATECONTEXTEXTPROC CreateContextExt; PFNOSMESACREATECONTEXTATTRIBSPROC CreateContextAttribs; PFNOSMESADESTROYCONTEXTPROC DestroyContext; PFNOSMESAMAKECURRENTPROC MakeCurrent;