5

Background

As far as I know, WPF does hardware-accelerated drawing if possible, with a fallback to software rendering if the user does not have DirectX 9+. That is a very interesting idea, and I even like the idea of XAML.

The reason I don't like it, and why I didn't even bother learning it, is that while Windows Forms is a Microsoft technology, and inferior to WPF, it is cross-platform through Mono, something that's not true for WPF, and probably will never be.
There's debate around whether a .NET WinForms wrapper for Linux/OS X will hit a patent brick wall in the future, but that's outside of the scope of this question.

Question

Is there any library for .NET and Mono that will let me use basic hardware acceleration (think alpha compositing, fast pixel manipulation, etc) with a software fallback for systems without the required GPUs/drivers?

In short: fast graphics on non-ancient desktops and modern laptops, but usable graphics on low-end netbooks and similar devices. This is not for game development.

Further Notes

There are several tricks to make GDI+ faster. Set/GetPixel are much improved by raw pointer access.
The pixel format used can improve rendering greatly, 32bppPArgb (32-bit with 8-bit Alpha and RGB values Pre-multiplied by the alpha).
There are other tricks that can get faster speeds, but managed GDI+ is still slow for some purposes.

Frameworks I'm Aware Of

  • Unity3D - AFAIK does not support Mono. Does. Shareware with free version.
  • TAO Framework - Looks a bit complicated, and does not seem to support sofware rendering.
  • OpenTK - Active, well-developed, and better than TAO, but no software fallback either.
  • SDL.NET - Same problem as above.
  • MonoXNA - Same as above.
  • Irrlicht - "It is completely cross-platform, using D3D, OpenGL and its own software renderer".
  • Silverlight/Moonlight - Suggested by dthorpe. Alpha quality, no support whatsoever.
  • Mono.Cairo - Suggested by Mark H.
  • AGG - High quality, very efficient software rendering, implemented in C++ with an unofficial C# port.
  • Axiom3D - Ogre port. Supports Mono, open-source and seems alive. Promising.

My current choice is to try Irrlicht, but only because I see no alternative. Is there?
Besides, even though it seems to support software rendering, I don't know how's the state of it in it's .NET/Mono wrapper, and the support link of it is a forum post.

none at the moment.

Besides there is a further problem: I have no idea how to "abstract" around a graphics library. If further on I realize I've made the wrong choice, I won't know what to do.

Please excuse the length of this question.


Edit: Since this question had two really constructive answers, I'll wait some days and tick the most upvoted one as the accepted answer.

In another news, it seems OpenGL is implemented in software, both by OS vendors as by third parties, and these implementations will be used by OpenGL frameworks in the lack of third party drivers.

Andrew Morton
  • 24,203
  • 9
  • 60
  • 84
Camilo Martin
  • 37,236
  • 20
  • 111
  • 154

3 Answers3

5

How about cairo? It has multiple back-ends, including OpenGL, GDI, X, and Quartz, and should work on nearly any device. Mono.Cairo implements a .NET wrapper for it, but I'm unsure whether this allows switching back-end through code, or whether it requires rebuilding for each system.

Cairo is used as the back-end for Moonlight, Gtk+, and Mono's System.Drawing implementation.

Mark H
  • 13,797
  • 4
  • 31
  • 45
  • Seems interesting, due to the number of back-ends provided. Do you know if Mono.Cairo works well for a Windows Forms application with the drawing happening in User Controls? – Camilo Martin Dec 15 '11 at 01:31
  • I don't think Mono.Cairo directly supports drawing in Winforms apps, only indirectly via System.Drawing on non-windows platforms. Most of the Mono.Cairo applications I'm familiar with are Gtk# based, and cross platform. (The native gtk library itself targets GDI+ on windows though, and can get close to the windows look and feel). – Mark H Dec 15 '11 at 17:55
  • Looks like something to be considered, but I don't know anything about Gtk#, so it would be an undertaking. If I understood properly what you suggest is P/Invoking the native cairo libs, is that correct? – Camilo Martin Dec 16 '11 at 06:17
  • I happily got Mono.Cairo going in a Gtk# app on linux / windows ( with zero source changes ) – IanNorton Dec 16 '11 at 07:03
  • @IanNorton so Mono.Cairo is a technology I can use without changes in both Windows and Linux? Did you had to do something special (at build time, etc.) or did it work out-of-the-box? Is it hardware-accelerated? – Camilo Martin Dec 17 '11 at 06:49
  • @CamiloMartin Absolutely nothing, my app was originally written on linux using monodevelop with the gtk designer. Just loaded it up and built it using monodevelop on windows and it worked fine – IanNorton Dec 18 '11 at 23:09
  • @IanNorton Thanks for the answer, I am considering Cairo because it looks like the most straightforward framework, but I'd really appreciate to know how's the state of hardware acceleration on it (the page says a "glitz" backend is on the way), and another question: is it also straightforward to draw and manipulate (rotate, scale, etc) vector graphics from a (SVG) file/resource on it? Being able to use vector graphics would be a big plus. – Camilo Martin Dec 19 '11 at 06:48
  • I think cairo can draw svg directly. I'm not that sure how fast accelerated cairo is though – IanNorton Dec 19 '11 at 22:07
  • Actually, I also note that you have assumed SDL doesn't do software rendering. It does. – IanNorton Dec 19 '11 at 22:08
4

One framework set not mentioned in your lineup is Silverlight. It's hardware accelerated on Windows, and Moonlight is now hardware accelerated on Linux. Not sure about software fallback, but I imagine they have to have fallback since they were both designed for very broad consumer use.

dthorpe
  • 35,318
  • 5
  • 75
  • 119
  • But Silverlight is for web applications, right? I'm almost sure it has a software renderer fallback, but I'm on the desktop ground here. – Camilo Martin Dec 15 '11 at 00:18
  • 1
    As of Silverlight 4.0, you can create desktop apps that run "out of the browser". They still run in a sandbox internally, but they have the look & feel of desktop apps. – dthorpe Dec 15 '11 at 00:20
  • Do you know of any (much preferably open source) application running Silverlight on the desktop that works under Moonlight? I'd like to look at an example. – Camilo Martin Dec 15 '11 at 01:35
  • That looks very interesting and promising, and if I have to learn a new API, I *maybe* could get into that one (although Silverlight looks massive for someone that barely knows Winforms). My only regret is that the post is from 3 1/2 years ago, and it has 5 comments, and even the svn server where the samples are seems dead. Besides, after looking around a bit I see people saying things like [this](http://stackoverflow.com/a/3172714/124119), and it makes me think twice before getting into the boat. Don't misunderstand me, it looks good, but I wouldn't like to be alone in the moonlight. – Camilo Martin Dec 16 '11 at 06:28
  • Well, Silverlight and Moonlight do have the eyeball advantage. There are a lot of Silverlight apps out there, and most of the time you don't even realize you're using one. Netflix, for example, uses Silverlight for its online movie player. I've never heard of most of the frameworks you listed in your post. Are you more comfortable choosing a technically competent but relatively obscure framework over a technically competent widely used framework? Also consider that Moonlight is open source and will likely continue to be developed / supported long after Microsoft sunsets Silverlight. – dthorpe Dec 16 '11 at 17:50
  • My biggest fear is that after learning some several weeks/months worth of Silverlight, I find out it's just as slow as GDI+. Actually, the worst part is that in GDI+ I know my workarounds (such as using stack blur instead of gaussian blur), but if a framework is doing the actual rendering, I wouldn't know what to do. I don't know if it's an awesome fast rendering engine or a quirky and slow one, and I'm scared to find out the hard way. However, as you well say, it has the advantage that many people use it, albeit for the browser. – Camilo Martin Dec 17 '11 at 06:34
  • FWIW, GDI+ was a huge step backwards, IMO, compared to the hardware acceleration that the original GDI was designed for. GDI+ seemed to focus first on fancy effects and completely ignored enabling hardware vendors to implement those effects in hardware. – dthorpe Dec 17 '11 at 06:37
  • Another concern of mine is Microsoft dropping Silverlight completely in light of its unexpectedly sudden advances towards HTML5 (which could be in direct conflict with Silverlight), and the open source community going with them since HTML5 is loved by almost everyone (and IMHO slightly overrated). At least with OpenGL I know things are a bit more stable and widely adopted. – Camilo Martin Dec 17 '11 at 06:39
  • Agreed that GDI+ was mis-designed, and if it was hardware accelerated or if it was possible for someone to plug in a GDI+ hardware driver it would all be much better in the desktop world. – Camilo Martin Dec 17 '11 at 06:40
  • You can get up to speed in Silverlight UI construction sufficiently to test graphics performance in a matter of days. And Silverlight's UI framework is a subset/cousin of WPF on the desktop, and they are both related by XAML to the new Windows Mobile "Metro" UI framework. The skills and patterns you learn in experimenting or full on working with Silverlight can be applied to WPF and Metro app development. Besides, learning a different way to do things makes you a better programmer. Period. – dthorpe Dec 17 '11 at 06:41
  • I agree with your last statement. I'm indeed considering getting into Silverlight, mostly thanks to your advice. I think I'll try it on a trivial utility, then on a toy project, and see how it works on practice. – Camilo Martin Dec 17 '11 at 06:52
  • Okay not trying to be inconvenient, but I can't find any good get-started guide or explanation of how to make Silverlight applications explicitely to be ran stand-alone (e.g., not installed from the browser, but really stand-alone as an assembly). Could you please give me a pointer to get started? – Camilo Martin Dec 29 '11 at 22:12
1

How about OpenTK but then using http://www.mesa3d.org/? It's been a long time since I looked at mesa3d but it provides a software-rendering capability to OpenGL.

JimFing
  • 151
  • 5
  • 11
  • So let's see if I understand, Mesa3D is something that could be easily installed and provide a system-wide OpenGL fallback? So it would just be a matter of writing code using OpenTK and making sure Mesa3D has been installed by the user if there isn't an OpenGL-capable hardware (is it a drop-in replacement)? – Camilo Martin Jul 01 '12 at 14:27