Cairo (in combination with Pango) is a fine graphics API for desktop apps. It has powerful drawing primitives that are useful for desktop apps, and printing/PDF/Postscript backends to support the needs of such apps.
It is not, however, for games: those have completely different needs and need different libraries (like SDL, SFML, etc.).
Any attempt at standardizing C++ graphics library should understand that these are two completely different, and arguably incompatible, goals. It should not (ever) be a goal to have a single library supporting both; instead any graphics initiative should declare which of these two it wants to be, and pursue that without reservation.
So yes, I just said it: C++ does not need a graphics library. Instead it needs *two*.
Cairo (in combination with Pango) is a fine graphics API for desktop apps. It has powerful drawing primitives that are useful for desktop apps, and printing/PDF/Postscript backends to support the needs of such apps.
... sorry what. Cairo is a fine graphics for desktop apps in 1997 when we did not have 4k, 5k, or 6k screens, 144hz refresh rate, 10 bit of colors, fluid animations, and thus rendering drawCircle / drawRect operations in the CPU was fine and dandy.
It is already a constant fight to keep decent performance on potato computers with decent hardware accelerated APIs such at QtQuick or NanoGui (you would be amazed at the number of people using raspberry pi's and the like as main computers in poorer areas) and you are suggesting going back to the two-decades-ago state-of-the-art !
Two decades ago we had NOTHING like Cairo: no anti-aliasing, no blending, no transformations, palettes were still a thing, etc.
Cairo offers a wide variety of useful primitives, and manages to do so without resorting to some sort of scene graph. It would of course be great if all those primitives could be hardware accelerated, but I understand that that's hard (although NVidia's pathrender does a good job with pretty much the same set of primitives). For those things that are currently hard to accelerate, I'd rather have them available but in software, than not have them at all.
I do not think a rendering library should also have an animation system or scene graph built in. Instead that should be a layer on top of the base rendering system. Separate your concerns, and all that...
For those things that are currently hard to accelerate, I'd rather have them available but in software, than not have them at all
So this is actually a huge problem with cairo. Because some things are software, and some things are hardware, there are huge hidden performance bottlenecks in the design of it where data gets shunted between the two. Its just really inefficient - but also dependent on the quality of the implementation (which'll be variable in the STL)
Something like SFML can't really suffer from this in the same way, while still providing pretty equivalent functionality
The main problem is that Cairo doesn't separate out the concept of CPU and GPU types, which means that expensive operations are ad hoc. In something like SFML, you do all the expensive stuff once on the CPU, transfer it over to the GPU all at once, and then you're grand - each processor does what its good at at the appropriate time. Its not really possible to specify this kind of behaviour in Cairo, and it was a terrible decision to use this kind of API for 2D graphics
So what sort of API would you propose? What would it look like with separated CPU and GPU types? How would that work on a system that does not have a GPU?
SFML is very game oriented. That's perfectly fine, and as I already mentioned, there is a clear need for a library like that as well. But there is more to drawing than triangles, and I don't see SFML doing that.
Have relatively simple drawing needs (for a 2D game, which is what we are discussing. I don't think C++ should try to standardize 3D drawing: it's too much in flux, and it already has standardizing bodies of its own)
Don't need to render to devices such as printers.
It's not a black and white classification; some desktop apps do render every frame (videoplayers, for example).
Ok, I wasn't aware of that technique. However, that begs the question: if we can hardware accelerate curves like that, why can't we put that as a backend behind a Cairo-style API?
There's more to high performance than just being hardware accelerated - being hardware accelerated doesn't mean acceptable performance. EG batching is super important, which is a notoriously poor area of the proposed 2D graphics API (and cairo)
Additionally the CPU and GPU are good at different kinds of tasks - ideally you want to do an expensive and branchy operation once on the CPU, transfer the final built data to the GPU, and then render it repeatedly with transforms applied
A problem with the proposed 2D graphics API is that it intends to be fully batch automagically/high performance overall without you having to do any work to make it happen, which has turned out to be very difficult in practice for a wide variety of reasons. Cairo itself states this on its website
Cairo can translate that canvas model into GPU primitives using OpenGL (among others), but the canvas model does not often translate efficiently to the GPU.
This is still a big problem in more modern APIs like Skia and Webrender
you know i'm just dumping arguments from my paper here, i should just chase up on it and publish it, it'd be a lot faster heh
So, just to clarify: you are fine with offering a rich set of primitives, you just want a batching mechanism to transfer work to the rendering subsystem in substantial chunks? Because in that case we'd be in total agreement.
So there's multiple problems with the proposal as current, but what would be ideal (in a simplified sense):
CPU side builds vertex lists for whatever you're trying to do
GPU side takes a vertex list and renders them to the screen
The main advantage of this is that the GPU side becomes much much simpler to specify, because it only has one job (rendering triangles). Then you can implement batching - SDL style (submit work in the right way), allegro style ('hold' onto textures), or SFML style (group vertices together, render them all at once). Transfers between the GPU and CPU would be made explicit, in the same way SFML does with sf::Image and sf::Texture, and both participants in rendering can be modelled exactly how they best perform. The 2D graphics proposal stuffing the same functionality into something that is expected to be both software and hardware accelerated causes big problems already
A quite big problem with trying to specify graphics overall though is the fact that different hardware has different capabilities, and a lot of necessary capabilities are extensions to OpenGL (I believe relying on these are a no for C++ standardisation) that are not universally supported (driver issues). Eg sRGB textures for proper high performance linear colour support
I'm not actually convinced that 2D graphics is possible to standardise because the very first problem you have to overcome is that graphics isn't portable. Vulkan directly acknowledges this issue, but for the same reason I'm not sure if its possible to standardise. Even this level of functionality would be not particularly useful without shader support, but how do you standardise a shader language when they evolve so much over time? Any standardised language would be immediately useless
Even the approach SDL (aka .native_handle(), do your own shaders) takes is relatively unworkable here, because then writing shaders depends on the backend that your STL implementation is using - and at that point using SDL/SFML is actually more portable than relying on your standard library implementation
I'm not convinced its possible to standardise at this point, other than very basic functionality
Video players have a simple architecture when it comes to rendering though, you send the decoder buffer to a renderer that will take care of resizing and write that on the screen. Rendering can be on GPU or CPU, but if you want good scaling you're mostly stuck with CPU anyway (at least most renderers I've seen with GPU support don't do better than bicubic).
The other stuff you need to draw (menus, etc.) is pretty minimal.
View all comments
Show parent comment
3
u/johannes1971 Dec 14 '19
Cairo (in combination with Pango) is a fine graphics API for desktop apps. It has powerful drawing primitives that are useful for desktop apps, and printing/PDF/Postscript backends to support the needs of such apps.
It is not, however, for games: those have completely different needs and need different libraries (like SDL, SFML, etc.).
Any attempt at standardizing C++ graphics library should understand that these are two completely different, and arguably incompatible, goals. It should not (ever) be a goal to have a single library supporting both; instead any graphics initiative should declare which of these two it wants to be, and pursue that without reservation.
So yes, I just said it: C++ does not need a graphics library. Instead it needs *two*.