Vega - Opera's vector graphics library
By Tim Johansson. Wednesday, 4. February 2009, 09:39:41
In my previous post here at Core concerns I wrote a bit about hardware acceleration of Opera's vector graphics library. In this post I will go into some more details about our vector graphics library.
The history of Vega
Vega was created shortly after we started working on SVG support. When we added SVG support in Opera we needed a vector graphics library. We looked into what was available to use and met our requirements (fast, low memory usage and works on platforms ranging from phones to TVs and desktop computers). We did not find and good match for our needs, so we decided to write our own.
Shortly after we created Vega we added <canvas> support, which also uses Vega.
The most recent addition to Vega is the ability to use a hardware accelerated back-end. The back-ends we are using at the moment are OpenGL and Direct3D.
HTML rendering
In the core version we are currently developing, Presto 2.3, we have made it possible to use Vega for all rendering in Opera. This means that we can replace the platform specific code for rendering with Vega. In the future it might be mandatory to use Vega for rendering, but in Presto 2.3 it is still possible to use the old rendering back-ends.
There are three reasons for doing this. The first reason is that the new CSS3 background and borders standard is much easier to implement using a vector graphics library. Presto 2.3 adds partial support for CSS3 backgrounds and borders, but only when using Vega for rendering.
The second reason is to support hardware acceleration of our vector graphics. In order to be able to render SVG and <canvas> in hardware we must also be able to directly draw the rendered vector graphics to the screen since reading back the rendered image from the graphics card is usually slower than rendering in software.
The final reason is that it enables us to easily add advanced graphical effects to our UI and to web pages.
Hardware requirements
The hardware back-end of Vega will unfortunately not work on all graphics cards. The good news is that we detect at runtime if your graphics card is supported or not and fallback to the software back-end of Vega if the graphics card is not supported. This means that everything will work regardless of your graphics cards capabilities.
The first requirement of you graphics card is that it has fast stencil buffers. If you are on a desktop computer that will not be a problem, but on some mobile phones that will be a problem. The reason for this requirement is that we use the stencil buffer for rendering some complex shapes instead of tessellating them and render triangles.
Since some web standards (for example opacity, SVG and <canvas>) require us to render to an off-screen buffer which is composited onto the screen we also require some kind of render to texture to be able to use Vega hardware back-end. This means a DirectX 9 compatible graphics card, or support for the framebuffer object (FBO) extension in OpenGL. It would be possible to do the same thing with pbuffers in OpenGL, but we need to do many render target switches and with pbuffers that is too slow.
The final requirement is pixel shaders 2.0, or fragment shaders 2.0 as it is called in OpenGL. We also require GLSL support on OpenGL. The shaders are required for filters. Filters is a part of SVG which performs an operation such as blur or color transforms on an image. Filters are also used in <canvas> and to support text shadows and box shadows in HTML.
For a PC user these requirements are met by any DirectX 9 compatible graphics card. So with the correct drivers you should be able to use the hardware back-end of Vega if you have a DirectX 9 compatible graphics card.
Update 2009-02-05:
I was not very clear about the multiple back-ends of Vega. If the graphics card is not capable of running the hardware back-end of Vega the software back-end will be used as a fallback and all features will still work. No features depends on hardware acceleration. All of them, including CSS3 backgrounds and borders, will work in the software back-end of Vega which does not depend on hardware accelerated graphics.


Tamil # 4. February 2009, 09:41
Sterkrig # 4. February 2009, 10:23
So Presto 2.2 has been feature-frozen? Only bugfixing etc?
malsumis # 4. February 2009, 11:11
Aux # 4. February 2009, 12:21
brunitoc # 4. February 2009, 12:36
Cant wait to see that !!!!
Turin # 4. February 2009, 13:13
serious # 4. February 2009, 13:17
Aux # 4. February 2009, 13:36
Jurgi # 4. February 2009, 14:11
Precise, maybe, but not clear for me…
Aux # 4. February 2009, 14:26
Jurgi # 4. February 2009, 16:02
MadAtWork # 4. February 2009, 16:30
serious # 4. February 2009, 16:38
Chas4 # 4. February 2009, 17:21
_Grey_ # 4. February 2009, 17:53
Well, too bad. Shader 1 card. Also what will you do on devices? Do all of them have better graphics cards than I have?
sms985 # 4. February 2009, 18:05
take a look here:
http://my.opera.com/core/blog/2008/06/05/engineering-seminar
I was hoping to see this in Opera 10 already, anyway we'll have to wait for Presto 2.3... Opera 10.5?
very exciting stuff!! bravo!
KuraFire # 4. February 2009, 18:30
elem.style.operaBorderTopLeftRadius
or this?
elem.style.oBorderTopLeftRadius
If the browser doesn't support it at times when using the software renderer, those properties should behave accordingly (whatever name they're using) and return "undefined" whether they're set in the CSS or not. Otherwise, it'll be impossible to do client-side detecting of whether those properties will be rendered by the browser if set (or toggled) in the code.
Chas4 # 4. February 2009, 18:52
timjoh # 5. February 2009, 08:51
@Turin: we will optimize both as much as possible, which is faster will vary between graphics cards and drivers.
@serious: OpenGL is usually not supported in the drivers shipped with windows. If you don't update your drivers it is common that D3D works but not GL. It is also difficult to get OpenGL running on some laptops with integrated graphics.
@_Grey_, KuraFire: nothing will depend on hardware acceleration, there is a software fallback which supports the same features.
malsumis # 5. February 2009, 12:16
thanks for an honest answer. Is that the case even for old computers with a slow ~600mhz cpu and, lets say, and Geforce 2/radeon 256 series GPU ?
Hades32 # 5. February 2009, 14:42
What about text rendering?
I absolutely HATE like text looks in Linux or OS X (and therefore in Safari under Windows, too).
But if you use DirectX or OpenGL I don't think you will be able to use ClearType...
How are you going to handle this issue?
Aux # 5. February 2009, 14:43
Sterkrig # 5. February 2009, 21:38
Originally posted by Hades32:
Does it look somehow differently?
malsumis # 5. February 2009, 22:25
serious # 6. February 2009, 07:35
aw ... did I ever say I hate windows? (and yes, I use it, but only to play some games, work gets done in ubuntu)
ah, well, I'm sure opera's dev guys know what works best. I'd just have liked a openGL solution for everywhere
Aux # 6. February 2009, 15:37
Hades32 # 7. February 2009, 11:06
Originally posted by Sterkrig:
Well, I can't say for Opera. But all text rendered around the system is rendered by the OS dependent font rendering software which uses different ways to soften text.
And YES it DOES look differently. Just download Safari for Windows to get a glimpse of what it would look like under OS X...
Sterkrig # 7. February 2009, 13:33
Originally posted by Hades32:
Well, there's minor differences, but I never bothered about them, moreover, I'm not sure I can determine OSes by font screenshots in "blind" test.
Fiddler3791 # 9. February 2009, 09:34
With these changes, text quality is easily superior compared to Windows *or* MacOS.
Caveat: KDE and all Qt4 based apps ignore the slight filtering directive and look awful. Qt3 and Qt4.5 (unreleased) don't suffer from this bug.
Caveat 2: Some distributions ship with older, lower quality subpixel renderers (e.g. Fedora, openSUSE and archlinux). You can find updated xft and freetype packages, with massively improved quality: they usually go by the -lcd or -ubuntu nomer.
Edit: It is possible to use subpixel rendering with OpenGL or DirectX, even without shaders. Don't worry, cleartype et al should still work with the hardware accelerated Vega.
Aux # 9. February 2009, 10:10
Hades32 # 15. April 2009, 13:27
Means that you will shift the WHOLE UI to Vega? That would be great!
Elephant454 # 6. September 2009, 21:37
f-blog # 16. October 2009, 09:52
DirectX 9 or Open GL 2.0 are very high standarts for users like me. I don't use my computer to play games. Then DX 8 and Open GL 1.4 supporting graphics card is fine for me. Hey until five months I was using onboard SIS651 chipset for my graphics.
I hope your application wouldn't be DX10 style (if all the DX10 features supported use it), instead would be DX9 style (check which functions work and use them, for functions that don't work use software render...).
xeon0541 # 3. November 2009, 09:02
andreidbz # 20. November 2009, 09:35
Old-Nick # 23. November 2009, 09:30
Originally posted by andreidbz:
How do they(Wave & Vega) connected to each other?