Leith Bade

02-04-2011, 07:31 PM

I have just read ARB_serperate_shader_objects and when combined with GLSL layout qualifiers it is very easy to mix/match different parts of the pipeline.

E.g. in my program I have a single fragment program for filling a solid 2D shape. For triangles I use a simple MVP vertex shader with this fragment shader.

For thick/thin lines I use a different vertex shader that only does MV * vert which I combine with a geometry shader that does the P * vert part.

So I have a shared fragment shader, and seperate geomertry pipeline:

Triangles -> Vertex -> Fragment

Lines -> Vertex -> Geometry -> Triangles -> Fragment

Thus I will have 3 program objects:

1 - Triangle Vertex only

2 - Line Vertex & Geometry

3 - Fragment only

Using the layout qualifiers I know that vertex data always goes into slot 0, and fragments always output into slot 0.

But I also have some uniforms that are shared between programs 1 & 2.

The modelViewMatrix exists in vertex 1 and vertex 2 shader. The projectionMatrix exisits in vertex 1, and geometry 2.

In my drawStart function I would like to simply set these uniforms with the same functions regardless of the current program.

So is there a way to use layout qualifier with uniforms shared between the 3 shaders (vertex 1,2 and geometry 2).

e.g.

set_uniform(index 0, modelViewMatrix);

set_uniform(index 1, projectionMatrix);

E.g. in my program I have a single fragment program for filling a solid 2D shape. For triangles I use a simple MVP vertex shader with this fragment shader.

For thick/thin lines I use a different vertex shader that only does MV * vert which I combine with a geometry shader that does the P * vert part.

So I have a shared fragment shader, and seperate geomertry pipeline:

Triangles -> Vertex -> Fragment

Lines -> Vertex -> Geometry -> Triangles -> Fragment

Thus I will have 3 program objects:

1 - Triangle Vertex only

2 - Line Vertex & Geometry

3 - Fragment only

Using the layout qualifiers I know that vertex data always goes into slot 0, and fragments always output into slot 0.

But I also have some uniforms that are shared between programs 1 & 2.

The modelViewMatrix exists in vertex 1 and vertex 2 shader. The projectionMatrix exisits in vertex 1, and geometry 2.

In my drawStart function I would like to simply set these uniforms with the same functions regardless of the current program.

So is there a way to use layout qualifier with uniforms shared between the 3 shaders (vertex 1,2 and geometry 2).

e.g.

set_uniform(index 0, modelViewMatrix);

set_uniform(index 1, projectionMatrix);