0

I am implementing a 3d renderer in OpenGL. Here is how you would render some 3d models:

Renderer3D.begin(camera);

Renderer3D.setShader(shader_1);
Renderer3D.render(model_1, transform_1);

Renderer3D.setShader(shader_2);
Renderer3D.render(model_2, transform_2);

...
Renderer3D.end();

Each .render() call will issue a GPU draw-call. (by calling .glDraw()) Here, I am using 2 shaders: shader_1, and shader_2.

However, both shaders have a uniform variable:

mat4 u_camera_projection;

Now, since u_camera_projection is a uniform variable, I will have to bind it whenever I switch shaders. What I would love to have - and I don't know if this feature exists in OpenGL - are "global", "bindless" variables. Variables that you can bind once, from the CPU side, and then they are accessible as read data from ANY shader.

2
  • since u_camera_projection is a uniform variable, I will have to bind it whenever I switch shaders: Uniforms are never bound. They are stored per shader program and keep the last value that you set. As long as the value doesn't need to be changed, you don't have to set them again. Commented Apr 6 at 15:25
  • If you want to share uniforms between different shader programs, you must use a Uniform Buffer Object, see here: khronos.org/opengl/wiki/Uniform_Buffer_Object. At least read the Uses section to find out if it's what you're looking for. Commented Apr 8 at 8:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.