Friday, December 6, 2013

Why OpenGL Probably isn't the Graphics API of the Future and I Hope it Dies

Anybody who has followed my Twitter for any length of time is probably aware there is no love lost between myself and OpenGL. Up until this point I haven't really done a good job of explaining why, courtesy of Twitter's 140 character limit, however the land of graphics API's has recently gotten really interesting with AMD's announcement of Mantle and Valve throwing its weight behind Linux/OpenGL with SteamOS so I've decided to wade into the fray.

First some background information: the I-Novae Engine has both OpenGL and D3D11 rendering backends for maximum cross platform portability. Both rendering backends are actively maintained by myself and Flavien. If you don't know what the I-Novae Engine is or why you should care then please watch this video. In my day job I work as a contractor programming OpenGL drivers for an RTOS being used by a large multinational corporation for its safety-critical embedded systems. I bring this up because I think most people in either the D3D camp or the OpenGL camp have little experience with the opposing API so I just wanted to say I've worked quite extensively with both and I hope this gives me the opportunity to be as unbiased as possible. Lastly if you're a programmer you can skip the next 2 sections and go straight to "the only reason why you should use OpenGL".

A condensed history of 3D graphics API's

Back in the glory days of Doom there was no such thing as OpenGL or DirectX. A graphics programmer had to code the entire 3D pipeline himself. The awesome part of this was that you had complete control over every aspect of the rendering pipeline. The downside was that everybody had to reinvent a whole lot of wheels and a general purpose CPU just isn't that great at (quickly) meeting the unique needs of 3D rendering - thus the consumer GPU was born. When GPU's were originally created they came with severe limitations on what a graphics programmer could do. These limitations are commonly referred to as the "fixed function" rendering pipeline because its features were fixed in silicon - a programmer couldn't add any additional functionality. To access these fixed function graphics capabilities there originally were 3 major API's:
  1. 3dfx Glide
  2. OpenGL
  3. DirectX
DirectX and OpenGL are general abstractions that make it easy for a developer to access the capabilities of a GPU from any manufacturer. Glide was proprietary to GPU's produced by 3dfx as it was the heavyweight champion of its day until NVIDIA suddenly gobbled it up, killed Glide in favor of OpenGL, released the Geforce 256, and took over the world of graphics.

Back in those days OpenGL was awesome. In fact I first started teaching myself graphics programming in high school using OpenGL and NeHe's tutorials (still a great resource for beginners). DirectX, while still supported by all of the various GPU manufacturers, was widely considered laughable. This all changed with the revolution that was, and still is, the programmable pipeline.

Viva la revoluciĆ³n!

The root problem with OpenGL, its Achilles heel if you will, is the fact that it's designed by a committee called the Khronos Group. Open standards hippies think this is great and while there are certainly some really good reasons not to have everything controlled by a single, evil corporation there are also some serious problems. For example HTML5 is all the rage these days and all of the web hippies are out basking in the glorious death of Flash and Silverlight. The problem with this line of thinking is that it took an entire decade for HTML5 to come out. While I have no love for Flash if you've ever used Silverlight you know that it's super easy to use, has great tools, and it's fast. If you've ever had to code a website by hand then you know it's a complete and total nightmare for absolutely no good reason. You have to deal with all these different implementations of the HTML standard in all these different browsers and for some completely insane reason Javascript became the lingua franca for client-side scripting. The story of OpenGL and DirectX at this point follow a similar arc - except Microsoft won - with good reason.

A programmable pipeline in the context of a GPU means a programmer can write little programs, called shaders, that get executed directly on a GPU to ultimately control the color that is output for each individual pixel. When programmable GPU's were first released OpenGL 2.0 and DirectX 8 came out to let developers access these new features. DirectX 8 was a complete rewrite of the DirectX API however OpenGL 2.0, in order to maintain backwards compatibility, kept all the old cruft and stapled on some new programmable pipeline stuff - similar to how each version of HTML just staples more crap onto the previous version. Needless to say when it came to working with shaders the shiny new DirectX 8 was awesome and the not so shiny and not so new OpenGL 2.0 was... not. At that point the only reason to choose OpenGL over DirectX was the fact that OpenGL was supported on non-Microsoft platforms. Since at that time consoles all used proprietary rendering API's and Windows was by far the most dominant gaming platform this really didn't matter so everybody switched over to DirectX.

The only reason you should use OpenGL... for now... I hope...

Realistically I think if you ask any hardcore graphics programmer if he prefers DirectX or OpenGL he's probably going to tell you he wishes he didn't have to use either one. Ironically, with the maturation of the programmable pipeline due to compute shaders, 3d graphics is coming full circle and you can now write very complicated "shaders" that run entirely on a GPU - they don't even have to have anything to do with graphics. The ultimate goal for graphics programmers is to be able to write C/C++ code, or possibly even some other language someday, that seamlessly executes on both CPU's and GPU's and lets you pass pointers without any hassle. There will only be fixed function hardware for rasterization and maybe a few other things and that'll be it. Both DirectX and OpenGL currently get in the way of this process by forcing you to dance a complicated jig as you move data to/from the CPU and GPU. Addressing this problem is the whole reason AMD recently announced Mantle but I'll get to that in a minute.

The only reason you should use OpenGL today is the exact same reason you would use OpenGL over DirectX 10 years ago: you want to target non-Microsoft platforms. With the emergence of mobile, another thing I'll get to in a minute, this is not an insignificant reason to favor OpenGL however it comes with some rather severe costs which are the primary reasons why I hate working with OpenGL:

  1. Now that we're onto OpenGL 4.4 the API has had a whole extra 2.4 versions haphazardly stapled onto it since 2.0. You now have to deal with things like two completely different sets of functions to do the exact same thing, like enumerate uniform buffer objects, because one set of functions supports a single extra feature that the other doesn't for absolutely no good reason.
  2. You have swiss army knife functions. An example of this is resolving an MSAA render target. All you want to do is resolve the MSAA render target but you have to use a function that can do 100 different things and you're left trying to figure out what which combination of flags you need.
  3. Driver support on Windows, still a dominant gaming platform, isn't that great since everybody has been using DirectX
  4. DirectX has an awesome debug layer, OpenGL's debug context pales in comparison
  5. DirectX has awesome tools (awesome is a relative word here), OpenGL does not. Granted, OpenGL has recently made some improvements in this area but saying OpenGL now has good tools is like saying that you would rather get kicked in the balls than be shot. Both options really suck though one just happens to be slightly better than the other
  6. OpenGL documentation sucks. If there is one thing that Microsoft tends to do better than everybody else it's developer tools and API documentation
Lastly the OpenGL specification has, historically, been updated very slowly relative to DirectX though recently the Khronos group has improved on this front. OpenGL acquired support for compute shaders a year after DirectX and both AMD and Apple still haven't released fully compatible drivers. There is, however, one caveat. Recently Microsoft has made the unfortunate choice of restricting new versions of DirectX to new versions of Windows. This sucks because Windows 8 adoption is much slower than Windows 7 and the newer versions of DirectX 11 have some really nice features. There are also some rumors floating around that Microsoft might kill off DirectX and that is obviously a huge concern when deciding which API to go with.

Mantle & CUDA

Ultimately Mantle, which is an open specification like OpenGL, and CUDA are the reason I think OpenGL is doomed, or at least the reason OpenGL should be doomed unless the Khronos Group does something radical, and they're also the reason the API wars are so interesting right now. For those of you who don't know, at a high level a graphics driver primarily does 3 things: it manages memory and it creates then executes command buffers. The primary purpose of Mantle is to provide developers with a lightweight hardware abstraction layer so they have more control over those 3 things than DirectX and OpenGL currently allow. Basically it gets developers closer to how the hardware actually works while reducing OS and driver overhead. CUDA isn't actually a graphics API per se, it's a proprietary compute shader language/runtime that provides seamless integration with C/C++, however I don't think it would take much for NVIDIA to turn it into a direct competitor with Mantle which is why I mention it here.

The jury is still out on Mantle and I think a lot depends on how Intel and NVIDIA react. If AMD can convince one of them or one of the mobile manufacturers to include it on their platform that'd be a huge vote of confidence for Mantle being useful on something other than AMD hardware. The reason Mantle and CUDA are such a threat to OpenGL is because, as has already been mentioned, the Khronos Group is not very good at responding quickly to changes in the marketplace. Microsoft has established with DirectX 8 and DirectX 10 that it is not afraid to completely rewrite DirectX to better accommodate changes in the architecture of next-gen hardware. There is nothing to prevent Microsoft from creating a Mantle style API with DirectX 12 and porting it to older versions of Windows whereas the Khronos Group demonstrated the exact opposite when they failed to rewrite OpenGL in any meaningful way with version 3.0. If Mantle gains traction, and Microsoft rewrites DirectX with version 12 to meet that threat, what incentive remains to use OpenGL? An even more radical thought is what if Microsoft does in fact discontinue development of DirectX, as AMD has suggested it might, in favor of Mantle? That would certainly explain why AMD made such a bold statement. Either way if Mantle begins gaining serious traction it seems likely OpenGL will no longer be worth supporting.

OpenGL ES and WebGL

There isn't much to say about OpenGL ES that hasn't already been said about the regular desktop version of OpenGL. Basically I think the Khronos Group really screwed up with OpenGL 2.0+ and WebGL. Firstly I think they screwed up with WebGL because they gave it the same feature set as OpenGL ES 2.0 instead of the full desktop OpenGL. Secondly I think they screwed up OpenGL ES 2.0 because they had an opportunity to start with a clean slate and create something really forward looking for mobile, like say Mantle, and instead they just took desktop OpenGL 2.0 and made it slightly more sane. Sure, there are some good reasons for that since plenty of people already have experience working with desktop OpenGL, but if Mantle or perhaps an NVIDIA competitor gets any traction in mobile then I can't think of any good reason as a developer to continue to use OpenGL ES.

In Closing

I've decided to leave out discussing SteamOS because I think that could be a blog of its own and this one is already way too long. Ultimately, regardless of what happens to OpenGL, I think 2014 is going to be an exciting year for computer graphics and high end gaming in general. New consoles, new API's, and ever more powerful PC hardware. The best part, if you're a consumer, is you don't have to worry about any of this API jazz. Us developer types shall wage holy war upon each other and once we get comfortable with these new API's and hardware capabilities consumers are going to have some great games to play!

Sunday, April 7, 2013

The Road to Crowd Funding

Needless to say I think we can all agree I'm a terrible blogger haha. It takes a lot of time to produce a quality blog article and I've been spending that time on coding instead of, well, blogging. That being said we've promised to become more active as we approach our crowd funding release date, which I confess we haven't announced yet, and to that end I would like to provide some information about what we're doing that's taking so long.

We've blogged a lot about our technology in the past. Things like HDR and atmospheric scattering and that's because our planetary tech is shiny and we <3 it and it's a big part of what makes us unique. It's the vehicle through which we will build the kind of games we want to build, bringing unique gameplay to you, the consumer. However there's something we really haven't talked about much yet that's just as important - our web/server/backend infrastructure.

The Vision

Believe it or not we are actually guided by a cohesive vision of the games we want to build, the type of company we want to create, and how we're going to interact with our consumers. A core pillar of this vision is a community first approach to everything we do. In the beginning this took the form of allowing the community to help build Infinity by contributing assets to the game. Unfortunately we realized some time later that there were two major problems with our contributions system. The first, and most important, is the complicated issue of intellectual property (IP) rights. We had no way of verifying who had made what and whether it was violating anyone's IP rights or anything like that. Everybody loses if we get sued into oblivion - except the lawyers of course. The second issue is that there really wasn't a good way for a contributor to submit their assets for a formal review for inclusion into the game. Later on in this article I'll address our solutions to these problems but first I want to talk about our plans for the cloud.

Joining the Cloud Kool Aid Party

If you look at what has made Apple so successful in consumer electronics it's the ability to create a seamless, easily accessible experience with their hardware and software. We would like to do that with our games by creating a cohesive, seamlessly integrated I-Novae ecosystem. Everyone who participates in this ecosystem will have an I-Novae ID that can be used across all I-Novae powered games and services. This is important in the near-term because we will need to keep track of everybody's donations during our crowd funding campaign so we can give them their awards upon successful completion of the campaign. We are considering making some of our reward tiers access to beta, alpha, and pre-alpha builds of the game. In order to properly support reward tiers like this we need to have the ability to provide/restrict access to builds of the game to the right people as well as collect their feedback, bug reports, etc. All of this will run through our I-Novae cloud platform and a users I-Novae ID.

Another benefit of the I-Novae ID will be our ability to provide a single sign-on experience. Many of you, if not most, are already using something like Google/GMail/g+, Twitter, Windows Live, or Facebook and instead of having to create yet-another-username/password you will be able to log into both our games and our services using credentials from one of those providers. Optionally you can still use a username/password if you prefer it.

In the long run we would like to support taking screen shots and video from directly within I-Novae Engine powered games and uploading them to your I-Novae profile in the cloud. We want to make it easy for you to share your favorite gaming moments with your friends through your preferred social media platforms. Lastly our I-Novae cloud will also support the usual cloud stuff like maintaining friends lists, digital distribution of I-Novae Engine powered games, and virtual market places.

Virtual Market, wait, WHAT!?

Infinity: Battlescape itself will not be released with assets from the community however, assuming we raise enough money (stretch goals!), the game will have a virtual marketplace where people can create and sell/share their own assets. These assets will be restricted to things that do not affect gameplay. For example you will not be able to create new weapons or ships but you will be able to create new skins - unless of course you create a mod. Mods will also be available through our virtual marketplace and will allow changing most of the game. Contributors will be able to submit their assets and mods to the marketplace for a nominal fee. This fee will serve two purposes. The first is to help cover our administrative overhead for verifying that the contribution does not violate anyone else's IP (solution to problem #1 above) and the second is to make sure the asset meets our minimum quality requirements and if they don't we will provide appropriate feedback (solution to problem #2 above). Lastly we don't want our virtual marketplace to fill up with tons of junk, a huge problem faced by all virtual marketplaces with a prime example being the Android app store, and having a nominal fee for submission is a huge step toward preventing that. Once a submission has been accepted the contributor will be able to set the price of the asset/mod themselves. Our community has a tremendous amount of energy and creativity, we have some really cool tech, and we would like to be able to harness that in a way that benefits everyone. We believe a virtual marketplace would go a long way toward achieving that goal.

In Closing

Laying the groundwork for this cloud infrastructure is also coinciding with rebuilding our website. Our current forums will likely be archived and replaced with a more modern solution that we can integrate with our I-Novae ID system. Since we don't really want to reinvent the wheel with forums software if anyone knows of something that's easy to integrate with a custom authentication/roles system, ideally built in ASP.NET, then please let us know. Redoing the website will be a lot of work but we believe it's necessary and in the long run it'll be worth it =).