Unity uses DirectX? So how do they get it to Mac?

Ok this post is just out of interest, I won’t really need it for a project or anything. I am fairly certain that Unity uses DirectX for all the graphical stuff we use day in and day out. I know that C# is portable to Mac using Mono, but how does Unity get things done with DirectX?

For iOS, they even have to port it to OpenGL/OpenCL - is MonoTouch capable of doing this?

I’m pretty interested in portability for all of my projects and I want to understand how things work in Unity to be able to use this knowledge for better optimizations and maybe some low-level programming. I am using C/C++ at my University (with things like OpenMP or Cuda) and it’s good to know as much as possible about portability of code as both Linux and Mac OS are very popular at German Universities.

Taken directly from the wiki:

so not sure what the web player does

The webplayer complies to the same, DX on Windows, OpenGL on Mac

MonoTouch does not offer any rendering so MonoTouch isn’t affected by any rendering.
Unity does neither use nor support mono touch

Ok so they actually are able to compile their engine for both OpenGL and DirectX. That’s not as awesome as I expected it to be because it means that DirectX 10 and 11 features are far away from getting implemendet - they would have to integrate all new DX10 and DX11 features into OpenGL. But ok it seems like this is the only possible way to go. Thanks for your answers!

I don’t think you understand how Graphics API work etc.

There is no compile DX into OpenGL or compile OpenGL into DX. They are distinct worlds and require own engines under the hood which they have.
This is the base to go anywhere cause focusing on OpenGL is no reasonable way of doing any engine on Windows unless you target the high end sector only.

But you are right on the consequence: Due to Apple sucking like hell on the OpenGL front, DX11 might be quite some bit away cause Unity normally favors cross platform availability over “windows dominance” even if it has as inacceptable consequences as the lack of AA in deferred rendering (which DX10+ wouldn’t have). Just to make sure of this too: Even if Unity used OpenGL on windows it wouldn’t change anything, the restrictions and implications are the same ones.
But Apple has been working on OpenGL 3 for quite some time now and the hope is that 10.6.6 might finally bring it (it was present in the prerelease 10.6.3 versions already but is not ready for primetime yet as it seems) which is all thats basically needed

But this does not prevent you from using Unity in a crossplatform environment at all

I do understand how graphics APIs work. I learned both DirectX (managed and unmanaged) and XNA before I started with Unity and I never said they would compile DirectX into OpenGL or vice versa - their engine is obviously made of wrapper functions for all the polygon, texture and buffer management. Those wrapper functions are available for both OpenGL and DirectX. So when you say to Unity to draw a texture, the function internally is able to either call a OpenGL or a DirectX equivalent.

That said, everything Unity is able to do has to be done in both OpenGL and DirectX. So everything that’s missing in OpenGL won’t be available in Unity until they find a workaround to create it on their own or a new version of OpenGL is available.

I really thought Unity found a way to get DirectX working on a Mac (projects like MacDX tried that before). But ok, we have to accept this as a fact. I personally won’t need DX11 features anytime soon.

There is not much missing in OpenGL that DirectX has and that would be important.
The problem is that Apple is 2 generations behind the current OpenGL version, thats where the problem actually comes from, so its ARB wise limited to SM3 tech level.

Also, technically nothing forces Unity to offer all on OSX that it offers on Windows and if the state of Apples OpenGL and driver implementations remain and don’t progress away from their laughable and inacceptable level I’m expecting to see at least a temporal delta here with Unity going to DX11 + DX9 fallback on Windows to benefit from driver optimizations and new driver capabilities and DX capabilities just not available without doing it. The most important one is the threaded graphics API access which on OGL is present on both platforms but on DX requires usage of DX11, even if you fallback to DX9 profiles.

MacDX or the Cedega technology are worlds worse than what Unity and other engines do with dedicated engines for the platforms cause call redirectors and alike perform worse to significantly worse (EVE Online which uses Cedegas tech, shows this pretty well)

Also independent of how they do it, the major, unchangeable problem does not change: It ends on the OpenGL Version that Apple offers and thats unhappily OpenGL 2.1 only in combination with the bad ATI driver quality which makes it completely unreasonable to even consider using non ARB extensions for a standard feature thats intend to work on ATIs too.