mirror of
https://github.com/glfw/glfw.git
synced 2024-12-02 06:47:10 +00:00
Re-try with Software Renderer on Mac OS if NSOpenGLPFAAccelerated fails.
I found that I needed to do a special DELETE_TERMINATING_NULL, because SET_ATTRIB(x, 0) are present elsewhere, and DELETE_ATTRIB(0) is not the reverse of ADD_ATTRIB(0). The DELETE_ATTRIB macro is not robust enough - there should be an UNSET_ATTRIB(a,v). fixes #2570 fixes #2080
This commit is contained in:
parent
b35641f4a3
commit
ba3ec0ff31
@ -200,6 +200,29 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window,
|
|||||||
assert((size_t) index < sizeof(attribs) / sizeof(attribs[0])); \
|
assert((size_t) index < sizeof(attribs) / sizeof(attribs[0])); \
|
||||||
attribs[index++] = a; \
|
attribs[index++] = a; \
|
||||||
}
|
}
|
||||||
|
// DELETE_ATTRIB checks a !=0, as SET_ATTRIB(x,0) are used, and needs
|
||||||
|
// a special UNSET_ATTRIB(x,0), instead of "DELETE_ATTRIB(x); DELETE_ATTRIB(0)"
|
||||||
|
#define DELETE_ATTRIB(a) \
|
||||||
|
{ \
|
||||||
|
assert(a != 0); \
|
||||||
|
assert(index > 0); \
|
||||||
|
int i = 0; \
|
||||||
|
while (attribs[i] != a && i < index) i++; \
|
||||||
|
if (i < index) { \
|
||||||
|
index--; \
|
||||||
|
while(i < index) { \
|
||||||
|
attribs[i] = attribs[i+1]; \
|
||||||
|
i++; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
#define DELETE_TERMINATING_NULL \
|
||||||
|
{ \
|
||||||
|
assert(index > 0); \
|
||||||
|
if (attribs[index-1] == 0) { \
|
||||||
|
index--; \
|
||||||
|
} \
|
||||||
|
}
|
||||||
#define SET_ATTRIB(a, v) { ADD_ATTRIB(a); ADD_ATTRIB(v); }
|
#define SET_ATTRIB(a, v) { ADD_ATTRIB(a); ADD_ATTRIB(v); }
|
||||||
|
|
||||||
NSOpenGLPixelFormatAttribute attribs[40];
|
NSOpenGLPixelFormatAttribute attribs[40];
|
||||||
@ -302,11 +325,18 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window,
|
|||||||
// NOTE: All NSOpenGLPixelFormats on the relevant cards support sRGB
|
// NOTE: All NSOpenGLPixelFormats on the relevant cards support sRGB
|
||||||
// framebuffer, so there's no need (and no way) to request it
|
// framebuffer, so there's no need (and no way) to request it
|
||||||
|
|
||||||
ADD_ATTRIB(0);
|
ADD_ATTRIB(0); // See also DELETE_TERMINATING_NULL!
|
||||||
|
|
||||||
#undef ADD_ATTRIB
|
|
||||||
#undef SET_ATTRIB
|
|
||||||
|
|
||||||
|
window->context.nsgl.pixelFormat =
|
||||||
|
[[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
|
||||||
|
if (window->context.nsgl.pixelFormat == nil)
|
||||||
|
{
|
||||||
|
// Re-try with Software Renderer
|
||||||
|
DELETE_ATTRIB(NSOpenGLPFAAccelerated);
|
||||||
|
DELETE_TERMINATING_NULL; // Unterminate.
|
||||||
|
ADD_ATTRIB(NSOpenGLPFARendererID);
|
||||||
|
ADD_ATTRIB(kCGLRendererGenericFloatID);
|
||||||
|
ADD_ATTRIB(0); // Re-terminate.
|
||||||
window->context.nsgl.pixelFormat =
|
window->context.nsgl.pixelFormat =
|
||||||
[[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
|
[[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
|
||||||
if (window->context.nsgl.pixelFormat == nil)
|
if (window->context.nsgl.pixelFormat == nil)
|
||||||
@ -315,6 +345,12 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window,
|
|||||||
"NSGL: Failed to find a suitable pixel format");
|
"NSGL: Failed to find a suitable pixel format");
|
||||||
return GLFW_FALSE;
|
return GLFW_FALSE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef ADD_ATTRIB
|
||||||
|
#undef DELETE_ATTRIB
|
||||||
|
#undef DELETE_TERMINATING_NULL
|
||||||
|
#undef SET_ATTRIB
|
||||||
|
|
||||||
NSOpenGLContext* share = nil;
|
NSOpenGLContext* share = nil;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user