{"id":24421,"date":"2014-09-21T15:24:35","date_gmt":"2014-09-21T20:24:35","guid":{"rendered":"http:\/\/www.shamusyoung.com\/twentysidedtale\/?p=24421"},"modified":"2014-09-24T19:20:12","modified_gmt":"2014-09-25T00:20:12","slug":"glnext","status":"publish","type":"post","link":"https:\/\/www.shamusyoung.com\/twentysidedtale\/?p=24421","title":{"rendered":"glNext"},"content":{"rendered":"<p>Big things are going on in the world of graphics API. A graphics API is what a programmer uses to talk to the graphics hardware. This is a complicated job. You write some videogame code, which talks to the graphics API, which talks to the graphics driver, which makes the graphics card give up the shiny pixels for the player. <\/p>\n<p>For a lot of years, there were really only two players in town: OpenGL and DirectX. OpenGL is so old that the original code was written in hieroglyphs on stone tablets, and all of the documentation was localized for Mesopotamia. The first version was released in 1992, back when developers were still living on Pangaea. It was built in a development world very unlike the one we have today. Before C++ rose to become the language of choice for AAA game development. Before shaders existed, and indeed before consumer-level graphics cards evolved. <\/p>\n<p>This means that the OpenGL API looks pretty weird to modern coders. There&#8217;s an alternative, but&#8230;<\/p>\n<p><!--more-->The only other alternative is DirectX, which is controlled by Microsoft. That means it&#8217;s only available in places where Microsoft chooses. So if you make a game using DirectX and want to port your game over to (say) Linux but Microsoft has decided to they don&#8217;t care to make a Linux version available, then you can&#8217;t. You don&#8217;t have access to a platform unless Microsoft goes there first, which gives them a scary amount of power over various platforms. This is a big part of how Microsoft works: Slowly get a stranglehold over something and then use that control to strong-arm rivals and reward obedience. Every game made with DirectX makes them just a little stronger. If you&#8217;re a developer taking the long view, then you&#8217;d probably rather not add to this.<\/p>\n<div class=\"dmnotes\">Example: Microsoft is working On DirectX 12. It will have shiny new features that developers will want to use. But they probably won&#8217;t make it available on Windows 7. So suddenly to play the latest game you&#8217;ll need to buy a new version of Windows you don&#8217;t want or need, even if your machine has plenty of power to run the game in question. They did the same thing to XP. <\/p>\n<p>So by making a game with DirectX 12, you&#8217;ll effectively turn your game into a sales pitch for Microsoft Windows&trade;.<\/p><\/div>\n<p>On the other hand, Microsoft can write good software. I mean, when they want to. When they don&#8217;t care you get <a href=\"?p=8059\">Games For Windows Live<\/a>, a program that would qualify as Malware if it wasn&#8217;t so buggy. But when they care they make awesome stuff like Visual Studio. And DirectX is indeed one of the things they care about. I&#8217;m not riding the cutting edge with the hotshot AAA developers, but the buzz seems to be that DirectX is significantly better and faster.<\/p>\n<p><table width='600'  cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/unearth_normal7.jpg' class='insetimage' width='600' alt='Image unrelated.' title='Image unrelated.'\/><\/td><\/tr><\/table><\/p>\n<p>So for years developers have had to make a choice: Do I go with the open platform that sucks or the closed platform that puts me at the mercy of Microsoft? This choice is no fun. So what do we do?<\/p>\n<p>AMD tried to &#8220;help&#8221; by coming out with a third graphics API, called Mantle. Note that AMD is one of two major players in the graphics card industry, with the other being NVIDIA. They claimed it would be an open standard, meaning it could work (or could be made to work) on NVIDIA hardware, but these two idiots have been cock-blocking each other at every turn, and there&#8217;s no way one would accept a standard devised by the other. I&#8217;d be willing to bet that AMD would design Mantle to favor their hardware at the expense of NVIDIA hardware (so games using Mantle would run faster on AMD cards than NVIDIA cards) and I&#8217;m sure NVIDIA would design their stuff to preemptively sabotage any such move. This entire enterprise sounds like a non-starter to me. And even if it worked, you&#8217;d just be at the mercy of AMD instead of Microsoft, which is just a different devil.<\/p>\n<p>At the same time, Apple rolls out yet another API, which is (because things aren&#8217;t confusing enough yet) Metal. (Not Mantle.) The names Mettle, Molten, and Mental are still available if anyone else wants to enter the fray and make things more confusing<span class='snote' title='1'>Mercifully, Mattel is taken.<\/span>. But it&#8217;s Apple, which means it has all the drawbacks of Microsoft. EDIT: <em>Also, as Nick points out below, Metal is only for iOS, so it&#8217;s only useful if you&#8217;re targeting Apple devices.<\/em><\/p>\n<p>So what else can we do? Lots of graphics engines act as &#8220;wrappers&#8221; for the big two: They use DirectX where that makes sense, and OpenGL where DX isn&#8217;t available. You just talk to the graphics engine and don&#8217;t worry your pretty little head about what&#8217;s happening under the hood.  That&#8217;s nice, but graphics engines are expensive, and they end up being yet <em>another<\/em> layer between you and the hardware. This might mean that your game runs slower than if you used OpenGL or DirectX natively. It also means you might end up cut off from certain features. Maybe there&#8217;s some exotic (or new) thing that graphics cards can do, but is not supported by your graphic engine. Either the developers didn&#8217;t know about it, didn&#8217;t think it was important<span class='snote' title='2'>&#8221;Why would anyone do that?&#8221; is one of the most natural yet infuriating questions an engineer can ask.<\/span>, or it didn&#8217;t exist yet when the engine was written. Because you&#8217;re so far from the hardware you won&#8217;t be able to use that feature. <\/p>\n<p>So&#8230; expensive, slow, and limiting. This isn&#8217;t an attractive option either.<\/p>\n<p><table width='600'  cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/unearth_backface1.jpg' class='insetimage' width='600' alt='Image unrelated.' title='Image unrelated.'\/><\/td><\/tr><\/table><\/p>\n<p>Of course, you could just write all your code twice.  Write a DirectX version of your game and an OpenGL version. Have fun doing three times the work for code that will be a support nightmare. Loser.<\/p>\n<p>Valve has been funding an open-source alternative to OpenGl called <a href=\"http:\/\/lunarg.com\/glassymesa\/\">Mesa<\/a>. This could fix (or perhaps has already fixed) some of the speed problems of OpenGL, but it can&#8217;t really help with the slightly idiosyncratic and very dated OpenGL API.  It would get faster, but not easier to use.<\/p>\n<p>It should be clear by now that the real solution that would make everyone<span class='snote' title='3'>Except Microsoft, who is the main beneficiary of this mess.<\/span> happy would be for OpenGL to stop sucking. The Kronos Group<span class='snote' title='4'>The not-for-profit member-funded industry consortium that <a href=\"http:\/\/en.wikipedia.org\/wiki\/Khronos_Group\">maintains OpenGL<\/a>.<\/span> has been trying to do this for years. I&#8217;m not in the loop enough to understand all their moves because I&#8217;m so far back the tech curve, but the buzz I generally hear is that their changes are too few, too rare, and too incremental. They seem to be an incredibly cautious and conservative<span class='snote' title='5'>I value these attributes in engineers. Generally I think the daring, devil-may-care types are best using technology, and the people who invent the technology should be slightly obsessive and paranoid. The astronaut should be bouncing around in space and giving thumbs-up to the world while the eggheads at home wring their hands and worry about every thing that could ever go wrong. Seems to be the best way to Get Stuff Done.<\/span> bunch, and they&#8217;re not eager to make Big Scary Changes.<\/p>\n<p>But things have gotten bad enough &#8211; or at least worrisome enough &#8211; that they seem to be doing exactly that. <a href=\"http:\/\/www.tomdalling.com\/blog\/modern-opengl\/opengl-in-2014\/\">They&#8217;re working on glNext<\/a>, which is a complete re-write of OpenGL. Now, I recognize the <a href=\"http:\/\/www.joelonsoftware.com\/articles\/fog0000000069.html\">re-writes are generally foolish and self-indulgent<\/a>, the work of engineers who are obsessing over code &#8220;cleanness&#8221; and not on the usefulness of the product.  But if re-writes are ever warranted, then I think this would be such a case. <\/p>\n<p>On the other hand, if this is a complete re-write without regard for backwards compatibility, then from the perspective of a game developer it&#8217;s basically just another API entering the field. If &#8211; like me &#8211; you&#8217;ve been faithfully working on OpenGL stuff for years, you&#8217;re not going to get a magic speed boost for nothing. You&#8217;re going to need to re-write your code to do things the new way. <\/p>\n<p><table   class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/oculus5.jpg' class='insetimage'   alt='On the Oculus, it&#8217;s not just framerate that matters, but also latency. It&#8217;s possible to have a demo running at 75fps, but each frame is slightly delayed by a fraction of a second due to some clog in the operating system. In this case, you&#8217;ll turn your head and the thing you&#8217;re looking at will seem to move with you, then snap back to where it should be. It looks like everything vibates slightly when you turn your head, with vibrations getting more extreme the faster you turn. This is called &#8220;juddering&#8221;. It&#8217;s not pleasant.' title='On the Oculus, it&#8217;s not just framerate that matters, but also latency. It&#8217;s possible to have a demo running at 75fps, but each frame is slightly delayed by a fraction of a second due to some clog in the operating system. In this case, you&#8217;ll turn your head and the thing you&#8217;re looking at will seem to move with you, then snap back to where it should be. It looks like everything vibates slightly when you turn your head, with vibrations getting more extreme the faster you turn. This is called &#8220;juddering&#8221;. It&#8217;s not pleasant.'\/><\/td><\/tr><tr><td class='insetcaption'>On the Oculus, it&#8217;s not just framerate that matters, but also latency. It&#8217;s possible to have a demo running at 75fps, but each frame is slightly delayed by a fraction of a second due to some clog in the operating system. In this case, you&#8217;ll turn your head and the thing you&#8217;re looking at will seem to move with you, then snap back to where it should be. It looks like everything vibates slightly when you turn your head, with vibrations getting more extreme the faster you turn. This is called &#8220;juddering&#8221;. It&#8217;s not pleasant.<\/td><\/tr><\/table><\/p>\n<p>For me, the more immediate problem is that the Oculus SDK doesn&#8217;t really properly support OpenGL right now. For a product going for a broad, multi-platform rlease, this strikes me as being really odd. The OpenGL version of the SDK is incomplete, and there&#8217;s almost nothing in the way of example code if you&#8217;re looking to figure out which parts work and which parts don&#8217;t. Specifically, you can&#8217;t render directly to the device. You have to set it up as an extra monitor, then create a maximized window on that second monitor. That ends up being really laggy for a lot of annoying reasons. Your rendering images get squeezed through some extra layers of Windows processing to be turned into images on your &#8220;desktop&#8221;, and that latency makes the Rift really uncomfortable to use. <\/p>\n<p>Since I got the Rift because I wanted to experiment with simulation quality and how to minimize VR sickness, this basically puts me out of business. Trying to measure smoothness and user experience in this mode is like trying to play Jenga on a rollercoaster. The noise in the system is larger than the thing I&#8217;m trying to measure. I can either drop what I&#8217;m doing and go learn DirectX (a massive and frustrating investment of time) or I can shelve my Rift until the SDK is finally updated.  And there&#8217;s no ETA on when they will add OpenGL support, so I could end up waiting a long time. <\/p>\n<p>There are no easy answers. Only very ugly tradeoffs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Big things are going on in the world of graphics API. A graphics API is what a programmer uses to talk to the graphics hardware. This is a complicated job. You write some videogame code, which talks to the graphics API, which talks to the graphics driver, which makes the graphics card give up the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[66],"tags":[],"class_list":["post-24421","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/24421","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=24421"}],"version-history":[{"count":0,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/24421\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=24421"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=24421"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=24421"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}