GLSL and low level shaders

Started by
5 comments, last by V-man 17 years, 7 months ago
Hi, I'm working on integrating shaders into my engine, but there's a question: Can GLSL shaders (i.e. shader objects and program objects) be used concurrently with low level extensions? The purpose is to use GLSL as much as possible but provide support for low level shaders for fallback / performance reasons. My ShaderManager class will handle parameters, so it would be able to deal with named and indexed parameters. Thanks for your help.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
Advertisement
Quote:Original post by Lord_Evil
Can GLSL shaders (i.e. shader objects and program objects) be used concurrently with low level extensions?

Depends what you mean by 'low level extensions' and 'concurrently'.

If you want to write a GLSL path and a fallback fixed function path that'll work fine (assuming that only one path is actually rendering at any one time). Some extensions are ignored when you switch to using shaders, some aren't.
Well I mean using a GLSL program object in one render pass and using low level shaders (GL_ARB_vertex_program etc.) in another pass.

Does binding the low level shaders unbind the program object?

When shaders and/or glsl aren't available, fixed function fallback passes will be used. The ShaderManager will be online anyway but report that shaders aren't available for use.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
If you will use both, you need to disable one and also unbind before using the other.

Like glDisable(GL_VERTEX_PROGRAM_ARB)
glDisable(GL_FRAGMENT_PROGRAM_ARB)
glBindProgramARB(GL_VERTEX_PROGRAM_ARB, 0);
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, 0);

glUseProgram(MyShader);


and then

glUseProgram(0);

glEnable(GL_VERTEX_PROGRAM_ARB)
glEnable(GL_FRAGMENT_PROGRAM_ARB)
glBindProgramARB(GL_VERTEX_PROGRAM_ARB, MyVertex);
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, MyFrag);

and I suggest you test on all hw and drivers.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Quote:Original post by OrangyTang
Quote:Original post by Lord_Evil
Can GLSL shaders (i.e. shader objects and program objects) be used concurrently with low level extensions?

Depends what you mean by 'low level extensions' and 'concurrently'.

If you want to write a GLSL path and a fallback fixed function path that'll work fine (assuming that only one path is actually rendering at any one time). Some extensions are ignored when you switch to using shaders, some aren't.


That's because shaders override of some of the pipeline. Vertex shader takes some of it and fragment shader takes control of some other.
Things like blending will work as usual. Alpha testing works as usual, Stencil, depth, etc.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
So, in order to use high level shaders and low level programs together, would you suggest using CG?

Afaik, CG compiles highlevel and lowlevel shaders. Ok, in CG they're all high level, but in terms of profiles you have 'low level' profiles and 'high level' profiles. But you wouldn't have to worry about whether GLSL is supported or not (as long as you're using only basic instructions).

If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
Cg provides profiles. It used to be ARB_vp/fp, NV stuff
Now they added GLSL support, which I assume means you can convert Cg code to GLSL.
I don't know what happens if you want to use multiple profiles.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

This topic is closed to new replies.

Advertisement