LWJGL 2 - GLSL version

Started by Hanksha, April 11, 2015, 03:29:16

Previous topic - Next topic

Hanksha

Hi!
I have a question concerning glsl (it's not really specific to lwjgl, but since I develop with it I'll ask it here).
We are developing a 2D platform/adventure game and we are soon to enter testing period. One of my main objective when I started coding was that the game could run on a wide range of spec and os (that's why I use java and lwjgl!).
I am testing the builds of the game with a NVIDIA GT540M (OGL and GLSL 4.40) the game run smooth a 300fps. Now, to test for lower spec I use my Intel HD Graphics 3000, the latest driver proposed by intel has OGL 3.1.0 and GLSL 1.40, with the right shader version the game run nicely at 140fps stable.

I had a friend to test a build with an AMD (I think 1 or 2 years old) and the shaders were not working because I was using too old version (and also maybe not too careful on some part of the code). I did some research and found that some AMD gpu doesn't support older version of glsl while NVIDIA was more flexible. So I upgraded and modified my shaders.
My problem is that for instance if I use shader #version 440 core in my code it will not run on many integrated gpu (I assume) while it actually could.

I use VAO and VBO for rendering, I use the shaders for light map, some refraction and distortion of the water as well as few ambient light, nothing too fancy really (that requires latest glsl version at least).
So knowing all of that, what version of glsl should I use so it will run on a wide range of spec?


quew8

I would have thought that using the GLSL version that accompanies the GL version you are targeting would be the best approach. So sounds like you are targeting OpenGL 3.1. If you request an OpenGL 3.1 context with a core profile then you can use GLSL 1.40 and the driver cannot not let you use it. In LWJGL 3:

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);


before you initialize the window. In LWJGL2, I can't remember the exact syntax but it's messing around with the ContextAttribs instance you pass to Display.create().

As far as I can tell, this is the exact use of OpenGL profiles.

Hanksha

I think it's something like that:
ContextAttribs contextAtrributes = new ContextAttribs(3, 1)
                .withForwardCompatible(true)
                .withProfileCore(true);


I think I will require a minimum GL version of 3.1 with GLSL 1.4, and then I will modify the shader depending on the version so it will fit it, since the code doesn't change.

ps: Ah actually profiles are only supported on OpenGL version 3.2 or higher.