ProXicT
ProXicT

Reputation: 1933

OpenGL GLSL shader versions

Recently I have had some problems with GLSL shader versions on different computers. I know every GPU can have different support for shaders, but I don't know how to make one shader which will work on all GPU's. If I write some shaders on my PC (GPU - AMD HD7770) I don't even have to specify the version, but on some older PC's or on PS's with nVidia GPU it's more strict on the version, so I've to specify the version that the GPU supports.

Now here comes the real problem. If I specify e.g version 330 on my PC, it works as it should, but on other PC's which should support version 330 it does not seem to work. So I have to rewrite it and make it work. And if I switch back to my PC which has newer GPU, it doesn't work either.

Does anyone know, how do I have to write the shader so it can run on all GPU's?

Upvotes: 3

Views: 4354

Answers (1)

Dietrich Epp
Dietrich Epp

Reputation: 213268

Writing portable OpenGL code isn't as straightforward as you might like.

  1. nVidia drivers are permissive. You can get away with a lot of things on nVidia drivers that you can't get away with on other systems.

  2. It's easy to accidentally use extra features. For example, I wrote a program targeting the 3.2 core profile, but used GL_INT_2_10_10_10_REV as a vertex format. The GL_INT_2_10_10_10_REV symbol is defined in 3.2, but it's not allowed as a vertex format until 3.3, and you won't get any error messages for using it by accident.

  3. Lots of people run old drivers. According to the Steam survey, in 2013, 38% of customers with OpenGL 3.x drivers didn't have 3.3 support, even though hardware which supports 3.0 should support 3.3.

  4. You will always have to test. This is the unfortunate reality.

My recommendations are:

  • Always target the core profile.

  • Always specify shader language version.

  • Check the driver version and abort if it is too old.

  • If you can, use OpenGL headers/bindings that only expose symbols in the version you are targeting.

  • Get a copy of the spec for the target version, and use that as a reference instead of the OpenGL man pages.

  • Write your code so that it can also run on OpenGL ES, if that's feasible.

  • Test on different systems. One PC is probably not going to cut it. If you can dig up a second PC with a graphics card from a different vendor (don't forget Intel's integrated graphics), that would be better. You can probably get an OpenGL 3.x desktop for a couple hundred dollars, or if you want to save the money, ask to use a friend's computer for some quick testing. You could also buy a second video card (think under $40 for a low-end card with OpenGL 4.x support), just be careful when swapping them out.

The main reason that commercial games run on a variety of systems is that they have a QA budget. If you can afford a QA team, do it! If you don't have a QA team, then you're going to have to do both QA and development -- two jobs is more work, but that's the price you pay for quashing bugs.

Upvotes: 5

Related Questions