Can I use EGL in OSX?
Asked Answered
D

3

8

I am trying to use Cairo library in a C++ application utilizing its GL acceleration in Mac. (I made same tests with its Quartz backend but the performance was disappointing.) It says it supports EGL and GLX. Use of GLX requires (externally installed) XQuartz and opens an XWindow so I lean towards EGL:

Apple's programming guide pages tell to use NSOpenGL*, which this page and others say it uses CGL.

This (2012) page says Mac has EAGL and it is only similar to EGL (I suppose it refers to IOS, not MAC as its EAGL reference links to IOS help pages).

Angle says it supports EGL but it is for Direct3D in windows, as I understand(?)

GLFW v3 is also said to support (in future releases?) but via GLX, it is said (?).

Mali says it has a simulator for Mac but I don't know if it is accelerated or is only for its hardware (it also says it only supports a subset of EGL on different platforms).

Most of the links refer to mobile when EGL is used. I am using Mac OS 10.8 and XCode 4.6. What is the current situation / How can I (if I can) use EGL in Mac (now)?

Dishonest answered 23/5, 2014 at 19:0 Comment(6)
Quartz is the native window system on OS X, you will not get better performance by going through a compatibility layer that is ultimately layered on top of Quartz.Virgiliovirgin
Right; I even got worse results than its software (image) backend!Dishonest
Well, it really depends what you mean when you say Quartz; there is the old Quartz 2D library which is not GPU accellerated, but Apple also calls about a half dozen other components of Core Graphics by the name Quartz ___. There is Quartz Composer, Quartz 2D Extreme (GPU accelerated Quartz 2D), an X Server called XQuartz, ... saying a piece of software has a Quartz backend really does not explain a whole lot. But ultimately, to display anything on screen in OS X you go through something with the word Quartz in its name.Virgiliovirgin
@Coleman , It (the Quartz backend) is constructed with a CGContextRef (and size) parameter. I don't know if it can be (GPU) accelerated (by configuring), but the EGL question still remains?Dishonest
Ah, well as far as I know Apple only supports EAGL on OS X. It is an Objective C framework, so Cairo would not be able to use it without some modification. Likewise, NSOpenGL is also Obj-C and CGL (which is C) only allows drawing in full-screen mode. Of those options, XQuartz sounds the easiest even though it is pretty far from native. To be honest though, I do not think Cairo even needs to create/manage the render context itself to use GL - the docs suggest you can use your own framework for that.Virgiliovirgin
@coleman, I am not sure OSX has EAGL, it is available for IOS(?). All or most of those Obj-c classes use/result in some c references (eg: CGContextRef) and CGL is not usable as it is fullscreen-only. I will (have to) try incorporating a library (opting for GLFW) if I cannot find an (positive) answer but it seems to require (way) more than a bit of work...Dishonest
B
1

Here it is https://github.com/SRA-SiliconValley/cairogles/

clone cairo, checkout branch nsgl. This cairo is our fork of cairo 1.12.14 that has the following enhancement vs the upstream cairo

  1. support OpenGL ES 3.0, and support OpenGL ES 2.0 angle MSAA extension
  2. new convex tessellator for fill circle for msaa compositor
  3. new cairo API - cairo_rounded_rectangle() - it is optimized for MSAA compositor
  4. support gaussian blur for four backends: GL/GLES, quartz, xcb and image
  5. support drop shadow and inset for four backends: GL/GLES, quartz, xcv and image with shaow cache
  6. support faster stroke when stroke width = 1 - we call hairline stroke
  7. add integration for NSOpenGL
  8. various bug fixes and optimization.

On Mac OSX, you have two choices: GLX or NSOpenGL - they are mutually exclusive. You can get mesa glx from macport. 1. To compile for NSOpenGL - ./configure --prefix=your_install_location --enable-gl=yes --enable-nsgl=yes --enable-glx=no --enable-egl=no

  1. To compile for GLX - ./configure --prefix=your_install_location --enable-gl=yes --enable-glx=yes --enable-nsgl=no --enable-egl=no.

If you are interested in egl (no available on mac, but mesa 9.1+ on linux and various embedded platform form has egl) do ./configure --prefix=your_install_location --enable-gl=no --enable-egl=yes --enable-glesv2=yes --enable-glesv3= no ===== this compiles for gles2 drivers.

./confgure --prefix=your_install_location --enable-gl=no --enable-egl=yes --enable-glesv2=no --enable-glesv3=yes ==== this compiles for glesv3 driver (mesa 9.1+ has glesv3)

you can have CFLAGS="-g" for debug or CFLAGS="-O2" for optimization.

cairo gl/gles has 3 GL compositors (rendering paths for GL/GLES backend). The default one is span compositor which is software simulation of AA and is slow. If your driver supports MSAA, use msaa compositor. To use MSAA compositor, you can export CAIRO_GL_COMPOSITOR=msaa in terminal, or you can setenv() in your program.

I have sample code to show cairo for quartz, xcv, image, glx, gel or nsgl. If you are interested, I can send you.

Any bug reports/patches are welcome. I have not have time to get wgl (MS windows) to work yet. Additional, it would be nice to have a d3d backend for cairo, I just don't have time to do that - on the todo list.

Enjoy

Bethina answered 29/5, 2014 at 22:15 Comment(0)
B
0

yes. cairo has been ported to use nsopengl. I will show you howto. amd sample code if you are interested. performance is much faster than quaetz gl.

Bethina answered 29/5, 2014 at 3:49 Comment(0)
R
0

You definitely can use angle:

#define GL_GLEXT_PROTOTYPES
#include <GLES2/gl2.h>
#include <EGL/egl.h>
Recommendation answered 3/11, 2016 at 13:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.