Search code examples
game-enginemultiplatform

How is it possible to make complex games cross platform?


I've been OS X user for about 11 months now, before that I used both Linux and Windows and I know how painful it is to do something with GUI that works well on all platforms (no Java).

What I don't undestand is that how people can make games like Call of Duty, Duke Nukem Forever or Batman Arkham Asylum work both on Windows and OS X.

Aren't libraries like DirectX specific to Windows and completely unavailable on Mac? I'd guess that applications like Photoshop will have their own GUI written from zero in C++, so that won't cause as much trouble as doing this with a 3d graphic engine (am I wrong here?).

I know that it's possible to get some things working via Wine on Linux, but that's not really an official way.

How is it possible to achieve this kind of multi-platformness for high performance applications?


Solution

  • Even though 3D graphics APIs can vary quite a bit between platforms (OpenGL on Mac / Linux vs. Direct3D 11 on Windows vs. Xbox 360 flavour DirectX9 vs. LibGCM on PS3, etc.) the underlying 3D hardware is actually quite similar. Generally games will have a low level compatibility API layer which abstracts most of the differences between 3D APIs across the target platforms and then higher level rendering will be built on top of this lower level abstraction. This way porting to a new platform only involves porting the relatively small 'driver' to support the low level compatibility layer and not porting all of the higher level rendering code.

    The reality of developing a cross platform game that achieves high performance on all the target platforms tends to involve a bit more complexity than this idealized picture. For example, platform differences may leak through and affect high level rendering decisions because the most efficient way to achieve a particular effect may be quite different on different platforms. Handling shaders in an efficient cross platform way when different platforms may use different shading languages (GLSL, HLSL, Cg) can also be quite complex.

    Games developed with consoles in mind already tend to have a complex asset pipeline which takes the source assets authored by artists (textures, models, animations, material definitions, etc.) and pre-processes them into native formats that are optimal for loading and rendering on the console. Many platform differences can be handled in the pipeline where code only has to run on the PC and concerns about performance and memory limitations are less significant.

    This approach allows content creators to develop most of their content without worrying about platform specific details and saves the game runtime from having to deal with format conversions, endianness differences, etc. The graphics driver layer on the target platform can be fairly lean and only has to deal with native texture formats, vertex data, shaders, etc. with most of the complexity of converting between formats handled in pipeline code on the development system (usually a high end PC).

    Developing a cross platform game is a pretty complex challenge but by careful design of abstraction layers and asset pipelines it is possible to make the majority of the game runtime code platform agnostic and isolate the platform specific parts of the code to certain well defined modules.

    Many games now are developed using 3rd party engines like Unreal or Unity which have already done much of the hard work of dealing with platform differences and allow the games' creators to focus less on the details of handling platform differences and more on developing their specific game.