Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 10 of 10

Thread: Using same Vertex shader

  1. #1
    Intern Newbie
    Join Date
    Jun 2011
    Posts
    33

    Using same Vertex shader

    Well I was wondering if there was a way to use the same vertex shader across multiple programs. For example I need about 20 programs and each of them use the same vertex shader. So rather than storing the uniform location of the same thing for 20 different programs just store it for one? Is there a way to do this? Or better yet is there a way to use only 1 program yet still be able to use multiple fragment shaders?

  2. #2
    Junior Member Newbie
    Join Date
    Jan 2011
    Posts
    8

    Re: Using same Vertex shader

    If your hardware allows it, you can use the separable programs. Each programs owns one stage (so a program holds a vertex shader). Then you combine them in a program pipeline.

  3. #3
    Intern Newbie
    Join Date
    Jun 2011
    Posts
    33

    Re: Using same Vertex shader

    Well I'm targeting opengl 2.0 right now. Not sure what you mean by separable programs, could you elaborate on that please.

    How efficient are the glAttachShader and glDetachShader functions? That would be one possible solution to attach and detach shaders as needed but it would be called fairly often, is this a viable solution?

  4. #4
    Junior Member Newbie
    Join Date
    Jan 2011
    Posts
    8

    Re: Using same Vertex shader

    Forget them, it's an OpenGL 4.0 feature.

    http://www.opengl.org/registry/specs...er_objects.txt

  5. #5
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948

    Re: Using same Vertex shader

    Forget them, it's an OpenGL 4.0 feature.
    Technically, it is a 4.1 feature. But it is also an extension. If you're using an NVIDIA GPU of GeForce 6xxx or better, you can use the extension just fine. All other GL 2.1 drivers won't expose it, but that's only because they're no longer supported.

  6. #6
    Intern Newbie
    Join Date
    Jun 2011
    Posts
    33

    Re: Using same Vertex shader

    I'm using an ATI but I was hoping to have it be used on pretty much any gpu.

    So any other suggestions to how to use many shaders? There isn't really a whole lot of information on it, almost any information I find is usually directed to how to get certain effects.

    On a side note I was hoping someone could explain why this is happening. I have an attribute set in my vertex shader and I am using "glVertexAttribPointer" to set the attribute, which is an unsigned short. The only problem is that for some reason it converts it to a type "float" rather than an "int", like so:

    Code :
    uniform mat4 bones[18];
    attribute float node;
     
    void main(void){
        gl_Position = gl_ModelViewProjectionMatrix * bones[ int(node) ] * vec4(gl_Vertex.xyz, 1.0);
    }

  7. #7
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948

    Re: Using same Vertex shader

    So any other suggestions to how to use many shaders?
    If you can't use ARB_separate_shader_objects, then the only option left is the obvious. Each program is independent and must be treated as such. You must query and store each program's uniform locations independently. And so forth.

    This problem is exactly why ARB_separate_shader_objects exists; so you don't have to do this. But if you don't have access to it, you have to accept dealing with what's left.

    That's why whenever possible I only concern myself with hardware that's still being supported. Any hardware that doesn't implement ARB_separate_shader_objects is either Intel (where they barely implement OpenGL as is) or is no longer having drivers written for it.

    It should be noted that GL 3.x-capable hardware dates back to 2006, so 5+ years now. It can be found embedded in motherboards and even CPUs. It's rather common.

    I have an attribute set in my vertex shader and I am using "glVertexAttribPointer" to set the attribute, which is an unsigned short. The only problem is that for some reason it converts it to a type "float" rather than an "int", like so:
    Unless you are using GLSL 1.30 or above (or using the EXT_gpu_shader4 extension), you cannot have integer attribute types. And if you do, you have to use `glVertexAttribIPointer` to set them up.

  8. #8
    Intern Newbie
    Join Date
    Jun 2011
    Posts
    33

    Re: Using same Vertex shader

    Thanks for the help, my nvidia card (8600) does have GL_ARB_separate_shader_objects but my ati card (3650 mobility) doesn't.

    I am planning on using one program, rather than having thousands, with a switch statement in the main function for the vertex and fragment shader. Along with a uniform int to choose the appropriate functions. What I was wondering is if anyone knows if glsl creates a jump table for a switch statement, much like a C/C++ compiler would?

  9. #9
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948

    Re: Using same Vertex shader

    but my ati card (3650 mobility) doesn't.
    Have you tried updating your drivers? Driver updates for mobile GPUs are harder, but still doable.

    What I was wondering is if anyone knows if glsl creates a jump table for a switch statement, much like a C/C++ compiler would?
    If I recall correctly, switch statements are only available in 1.30 and above. As to exactly what it compiles to, it's compiler-specific.

  10. #10
    Junior Member Regular Contributor tksuoran's Avatar
    Join Date
    Mar 2008
    Location
    Cambridge, UK
    Posts
    223

    Re: Using same Vertex shader

    Using uniform buffer objects will greatly lessen the need to query uniform locations, especially if you use std140 layout. Uniform buffer objects can be shared to any/all programs, so it is easy to set uniform value once and it will affect all or selected programs.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •