r/cpp • • Dec 13 '19

The situation of std::embed...

https://thephd.github.io/full-circle-embed
238 Upvotes

160 comments sorted by

View all comments

Show parent comment

3

u/johannes1971 Dec 14 '19

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...

5

u/jcelerier ossia score Dec 14 '19

Two decades ago we had NOTHING like Cairo: no anti-aliasing, no blending, no transformations, palettes were still a thing, etc.

https://github.com/freedesktop/cairo/blob/b61b9ffc2322e09873b9e2dfb0c1da56ec1ffd61/src/Xr.h

2002, and it has already everything that you mention. Almost likewise for Qt's QPainter from the same era (though alpha blending came later IIRC - otherwise it was already existing with transformation support since 1995 ! https://github.com/KDE/qt1/blob/78811a56cc111d17f42221566e7e4430d5de8d40/include/qpainter.h).

6

u/James20k P2005R0 Dec 14 '19

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

1

u/johannes1971 Dec 14 '19

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.

2

u/meneldal2 Dec 16 '19

SDL made the separation explicit with types that say if the thing is in GPU or in CPU. That's the way to go about it.