OSMesa: Add fallback to OSMesaCreateContextExt

This commit is contained in:
Camilla Berglund 2016-11-08 22:44:59 +01:00
parent b8c71e7f2d
commit 62012e3c68
2 changed files with 52 additions and 23 deletions

View File

@ -120,6 +120,7 @@ GLFWbool _glfwInitOSMesa(void)
#elif defined(__CYGWIN__) #elif defined(__CYGWIN__)
"libOSMesa-8.so", "libOSMesa-8.so",
#else #else
"libOSMesa.so.8",
"libOSMesa.so.6", "libOSMesa.so.6",
#endif #endif
NULL NULL
@ -141,6 +142,8 @@ GLFWbool _glfwInitOSMesa(void)
return GLFW_FALSE; return GLFW_FALSE;
} }
_glfw.osmesa.CreateContextExt = (PFNOSMESACREATECONTEXTEXTPROC)
_glfw_dlsym(_glfw.osmesa.handle, "OSMesaCreateContextExt");
_glfw.osmesa.CreateContextAttribs = (PFNOSMESACREATECONTEXTATTRIBSPROC) _glfw.osmesa.CreateContextAttribs = (PFNOSMESACREATECONTEXTATTRIBSPROC)
_glfw_dlsym(_glfw.osmesa.handle, "OSMesaCreateContextAttribs"); _glfw_dlsym(_glfw.osmesa.handle, "OSMesaCreateContextAttribs");
_glfw.osmesa.DestroyContext = (PFNOSMESADESTROYCONTEXTPROC) _glfw.osmesa.DestroyContext = (PFNOSMESADESTROYCONTEXTPROC)
@ -154,7 +157,7 @@ GLFWbool _glfwInitOSMesa(void)
_glfw.osmesa.GetProcAddress = (PFNOSMESAGETPROCADDRESSPROC) _glfw.osmesa.GetProcAddress = (PFNOSMESAGETPROCADDRESSPROC)
_glfw_dlsym(_glfw.osmesa.handle, "OSMesaGetProcAddress"); _glfw_dlsym(_glfw.osmesa.handle, "OSMesaGetProcAddress");
if (!_glfw.osmesa.CreateContextAttribs || if (!_glfw.osmesa.CreateContextExt ||
!_glfw.osmesa.DestroyContext || !_glfw.osmesa.DestroyContext ||
!_glfw.osmesa.MakeCurrent || !_glfw.osmesa.MakeCurrent ||
!_glfw.osmesa.GetColorBuffer || !_glfw.osmesa.GetColorBuffer ||
@ -192,18 +195,22 @@ GLFWbool _glfwCreateContextOSMesa(_GLFWwindow* window,
const _GLFWfbconfig* fbconfig) const _GLFWfbconfig* fbconfig)
{ {
OSMesaContext share = NULL; OSMesaContext share = NULL;
int index = 0, attribs[40]; const int accumBits = fbconfig->accumRedBits +
fbconfig->accumGreenBits +
fbconfig->accumBlueBits +
fbconfig->accumAlphaBits;
if (ctxconfig->share) if (ctxconfig->share)
share = ctxconfig->share->context.osmesa.handle; share = ctxconfig->share->context.osmesa.handle;
if (OSMesaCreateContextAttribs)
{
int index = 0, attribs[40];
setAttrib(OSMESA_FORMAT, OSMESA_RGBA); setAttrib(OSMESA_FORMAT, OSMESA_RGBA);
setAttrib(OSMESA_DEPTH_BITS, fbconfig->depthBits); setAttrib(OSMESA_DEPTH_BITS, fbconfig->depthBits);
setAttrib(OSMESA_STENCIL_BITS, fbconfig->stencilBits); setAttrib(OSMESA_STENCIL_BITS, fbconfig->stencilBits);
setAttrib(OSMESA_ACCUM_BITS, fbconfig->accumRedBits + setAttrib(OSMESA_ACCUM_BITS, accumBits);
fbconfig->accumGreenBits +
fbconfig->accumBlueBits +
fbconfig->accumAlphaBits);
if (ctxconfig->profile == GLFW_OPENGL_CORE_PROFILE) if (ctxconfig->profile == GLFW_OPENGL_CORE_PROFILE)
{ {
@ -222,7 +229,26 @@ GLFWbool _glfwCreateContextOSMesa(_GLFWwindow* window,
setAttrib(0, 0); setAttrib(0, 0);
window->context.osmesa.handle = OSMesaCreateContextAttribs(attribs, share); window->context.osmesa.handle =
OSMesaCreateContextAttribs(attribs, share);
}
else
{
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 (window->context.osmesa.handle == NULL) if (window->context.osmesa.handle == NULL)
{ {
_glfwInputError(GLFW_VERSION_UNAVAILABLE, _glfwInputError(GLFW_VERSION_UNAVAILABLE,

View File

@ -43,11 +43,13 @@ typedef void* OSMesaContext;
typedef void (*OSMESAproc)(); typedef void (*OSMESAproc)();
typedef OSMesaContext (* PFNOSMESACREATECONTEXTATTRIBSPROC)(const int*,OSMesaContext); typedef OSMesaContext (* PFNOSMESACREATECONTEXTATTRIBSPROC)(const int*,OSMesaContext);
typedef OSMesaContext (* PFNOSMESACREATECONTEXTEXTPROC)(GLenum,GLint,GLint,GLint,OSMesaContext);
typedef void (* PFNOSMESADESTROYCONTEXTPROC)(OSMesaContext); typedef void (* PFNOSMESADESTROYCONTEXTPROC)(OSMesaContext);
typedef int (* PFNOSMESAMAKECURRENTPROC)(OSMesaContext,void*,int,int,int); typedef int (* PFNOSMESAMAKECURRENTPROC)(OSMesaContext,void*,int,int,int);
typedef int (* PFNOSMESAGETCOLORBUFFERPROC)(OSMesaContext,int*,int*,int*,void**); typedef int (* PFNOSMESAGETCOLORBUFFERPROC)(OSMesaContext,int*,int*,int*,void**);
typedef int (* PFNOSMESAGETDEPTHBUFFERPROC)(OSMesaContext,int*,int*,int*,void**); typedef int (* PFNOSMESAGETDEPTHBUFFERPROC)(OSMesaContext,int*,int*,int*,void**);
typedef GLFWglproc (* PFNOSMESAGETPROCADDRESSPROC)(const char*); typedef GLFWglproc (* PFNOSMESAGETPROCADDRESSPROC)(const char*);
#define OSMesaCreateContextExt _glfw.osmesa.CreateContextExt
#define OSMesaCreateContextAttribs _glfw.osmesa.CreateContextAttribs #define OSMesaCreateContextAttribs _glfw.osmesa.CreateContextAttribs
#define OSMesaDestroyContext _glfw.osmesa.DestroyContext #define OSMesaDestroyContext _glfw.osmesa.DestroyContext
#define OSMesaMakeCurrent _glfw.osmesa.MakeCurrent #define OSMesaMakeCurrent _glfw.osmesa.MakeCurrent
@ -76,6 +78,7 @@ typedef struct _GLFWlibraryOSMesa
{ {
void* handle; void* handle;
PFNOSMESACREATECONTEXTEXTPROC CreateContextExt;
PFNOSMESACREATECONTEXTATTRIBSPROC CreateContextAttribs; PFNOSMESACREATECONTEXTATTRIBSPROC CreateContextAttribs;
PFNOSMESADESTROYCONTEXTPROC DestroyContext; PFNOSMESADESTROYCONTEXTPROC DestroyContext;
PFNOSMESAMAKECURRENTPROC MakeCurrent; PFNOSMESAMAKECURRENTPROC MakeCurrent;