Reputation: 297
I have seen many graphics applications which primarily support OpenGL. I have also noticed that many of these applications have a -d3d
flag which will force them to use the DirectX API instead.
How exactly can a single graphics application use two different APIs but render the exact same result? Surely they would need to add code for both APIs, which is time consuming and a bit of a waste?
Upvotes: 2
Views: 2697
Reputation: 41127
The topic of OpenGL vs. DirectX is touchy with many folks, so let me start by saying my intent is to not inflame either side of the "API wars".
If you are talking about general graphics software like CAD, they tend to have a large set of cross-platform targets to support. In these cases, they use OpenGL for systems like MAC and *NIX as well as Windows.
While the developers can use OpenGL on Windows, the 'default' support for OpenGL on Windows is pretty minimal--OpenGL v1.x software only. If you want to use a more full-featured version of OpenGL, you need to have the user install an OpenGL ICD. The quality of these OpenGL ICDs is heavily dependent on each hardware vendor keeping up with the standard, and in the past the OpenGL ICDs for Windows have been tuned for very specific calling patterns for specific applications (read "Doom"). If your application didn't match those patterns, you would sometimes have strange performance problems or hit other bugs.
There has also been a tendency in the video hardware industry for the OpenGL support on Windows on 'consumer-grade' hardware being fairly minimal effort for a few games, while the 'workstation-grade' hardware gets lots of developer resources focused on writing a high-quality OpenGL ICD. In this case, software aimed at workstation (again, read CAD) tends to offer both APIs to cater to the needs of users on both cheaper and more expensive systems. Conversely for games, it's unrealistic to require a $2000+ video card to play to it's often much easier and more robust to use DirectX--unless you happen to the one "must-have" OpenGL only game on the market that the 'consumer-grade' drivers actually work well with.
Using DirectX, particularly DirectX 11 on Windows 7+, works well 'out of the box' for most systems across a wide array of devices from different vendors. Some software developers have found it be far more consistent across different devices and use it as the default when they offer both OpenGL and DirectX. This is why many PC games are DirectX only on Windows. However, if they are already doing an abstraction to support OpenGL for MAC, they may well leave it as an option for users on Windows as well.
For games, abstraction is typical in the rendering engines. To get good performance for a AAA title and hit all the different platforms that matter to them, they typically have to implement multiple versions of their renderer anyhow (Direct3D 11 for Windows Vista+, Direct3D 9 for Windows XP esp. for emerging markets, a variant of Direct3D 9 for Xbox 360, a variant of Direct3D 11 for Xbox One, OpenGL for MAC, specific renderers for PlayStation 3 and/or 4, and for mobile games OpenGL ES). This is usually achieved through an abstraction layer, and then dedicated coders for each platform to marshal the game through to ship taking advantage of what hardware-specific features matter to them. It is not an inexpensive solution, but many large publishers try to arbitrage project risk by offering versions of their content across many different platforms and consider it worth the additional cost.
For indie and small developers, trying to support both OpenGL and DirectX can be a pretty big challenge. It's usually better for them to focus on making a great game for a single platform using a single, well-supported API on that platform. Then if they are successful, they can port it to more platforms by doing the work needed to implement multiple rendering APIs -and- create custom content processing to tailor it to each platform. That said, indie games often don't focus on differentiating on graphics, so the feature & performance trade-offs for using an abstraction layer is less of a problem. It is, however, expensive to test your game across many different devices and do it twice to cover both OpenGL and DirectX.
Upvotes: 7