# define kCGLOGLPVersion_Legacy 0x1000
#endif
+static const CGLPixelFormatAttribute prefered_pixel_format_legacy_attrs[] =
+{
+ kCGLPFAAccelerated,
+ kCGLPFAMinimumPolicy,
+ kCGLPFAColorSize, 32,
+ kCGLPFAAlphaSize, 8,
+ kCGLPFADepthSize, 24,
+ kCGLPFAStencilSize, 8,
+ kCGLPFAMultisample,
+ kCGLPFASampleBuffers, 1,
+ kCGLPFASamples, 4,
+ kCGLPFAPBuffer,
+ 0
+};
+
+static const CGLPixelFormatAttribute prefered_pixel_format_3_2_core_attrs[] =
+{
+ kCGLPFAAccelerated,
+ kCGLPFAMinimumPolicy,
+ kCGLPFAColorSize, 32,
+ kCGLPFAAlphaSize, 8,
+ kCGLPFADepthSize, 24,
+ kCGLPFAStencilSize, 8,
+ kCGLPFAMultisample,
+ kCGLPFASampleBuffers, 1,
+ kCGLPFASamples, 4,
+ kCGLPFAOpenGLProfile, kCGLOGLPVersion_3_2_Core,
+ 0
+};
+
static const CGLPixelFormatAttribute pixel_format_legacy_attrs[] =
{
kCGLPFAAccelerated,
"glVertexAttribDivisor"
};
+static CGLError yagl_egl_cgl_choose_pixel_format(const CGLPixelFormatAttribute prefered_attrs[],
+ const CGLPixelFormatAttribute fallback_attrs[],
+ CGLPixelFormatObj *pix,
+ int *n)
+{
+ CGLError error;
+
+ YAGL_LOG_FUNC_ENTER(yagl_egl_cgl_choose_pixel_format, NULL);
+
+ error = CGLChoosePixelFormat(prefered_attrs, pix, n);
+
+ if (error || !pix) {
+ YAGL_LOG_WARN("CGLChoosePixelFormat: no suitable prefered format found (%s)",
+ CGLErrorString(error));
+ return CGLChoosePixelFormat(fallback_attrs, pix, n);
+ }
+
+ return error;
+}
+
static bool yagl_egl_cgl_get_gl_version(struct yagl_egl_cgl *egl_cgl,
yagl_gl_version *version)
{
EGLNativeDisplayType dpy,
int *num_configs)
{
+ struct yagl_egl_cgl *egl_cgl = (struct yagl_egl_cgl*)driver;
struct yagl_egl_native_config *cfg = NULL;
+ CGLError error;
YAGL_LOG_FUNC_ENTER(yagl_egl_cgl_config_enum, "%p", dpy);
cfg->min_swap_interval = 0;
cfg->native_visual_id = 0;
cfg->native_visual_type = EGL_NONE;
- cfg->samples_per_pixel = 0;
+
+ if (egl_cgl->base.gl_version >= yagl_gl_3_2) {
+ error = CGLDescribePixelFormat(egl_cgl->pixel_format_3_2_core,
+ 0,
+ kCGLPFASamples,
+ &cfg->samples_per_pixel);
+ } else {
+ error = CGLDescribePixelFormat(egl_cgl->pixel_format_legacy,
+ 0,
+ kCGLPFASamples,
+ &cfg->samples_per_pixel);
+ }
+
+ if (error) {
+ YAGL_LOG_WARN("CGLDescribePixelFormat(kCGLPFASamples) failed: %s",
+ CGLErrorString(error));
+ cfg->samples_per_pixel = 0;
+ }
+
cfg->stencil_size = 8;
cfg->transparent_type = EGL_NONE;
cfg->trans_red_val = 0;
goto fail;
}
- error = CGLChoosePixelFormat(pixel_format_legacy_attrs,
- &egl_cgl->pixel_format_legacy,
- &n);
+ error = yagl_egl_cgl_choose_pixel_format(prefered_pixel_format_legacy_attrs,
+ pixel_format_legacy_attrs,
+ &egl_cgl->pixel_format_legacy,
+ &n);
if (error) {
YAGL_LOG_ERROR("CGLChoosePixelFormat failed for legacy attrs: %s", CGLErrorString(error));
}
if (egl_cgl->base.gl_version >= yagl_gl_3_2) {
- error = CGLChoosePixelFormat(pixel_format_3_2_core_attrs,
- &egl_cgl->pixel_format_3_2_core,
- &n);
+ error = yagl_egl_cgl_choose_pixel_format(prefered_pixel_format_3_2_core_attrs,
+ pixel_format_3_2_core_attrs,
+ &egl_cgl->pixel_format_3_2_core,
+ &n);
if (error) {
YAGL_LOG_ERROR("CGLChoosePixelFormat failed for 3_2_core attrs: %s", CGLErrorString(error));