Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Uniforms VS State Access for modelViewProjection

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2008
    Posts
    4

    Uniforms VS State Access for modelViewProjection

    Hello all!
    I want to know which of the following ways is the best for passing my world/view/projection matrices into a GLSL shader.
    1) passing the matrices as uniforms to the shader
    2) setting the matrices with glMatrixMode() "outside" glsl. and then in the glsl programm access the OpenGL state to get the matrices.

    Thanks for your time!

  2. #2
    Intern Contributor IneQuation.pl's Avatar
    Join Date
    Aug 2008
    Location
    Gliwice, Poland
    Posts
    69

    Re: Uniforms VS State Access for modelViewProjection

    Depends on which GL version you're targeting. State access is basically deprecated in GL 3.0, but for earlier versions I think it's the best way, since there's a limited number of uniforms you can use.

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Sep 2004
    Location
    Prombaatu
    Posts
    1,401

    Re: Uniforms VS State Access for modelViewProjection

    Only the builtins you actually use count against limit, so you could mix and match too if it fits the bill...

  4. #4
    Super Moderator Frequent Contributor Groovounet's Avatar
    Join Date
    Jul 2004
    Posts
    936

    Re: Uniforms VS State Access for modelViewProjection

    - If a generic uniform used or if what you could the outside GLSL is used, the number of uniform variables is the same!

    - glMatrixMode and all matrix functions are deprecated in OpenGL 3. Actually for me using this just make the whole program more complicated to work.

    If you want to do a very programmable oriented software based on OpenGL, I would say use the glUniform functions.

  5. #5
    Advanced Member Frequent Contributor _NK47's Avatar
    Join Date
    Mar 2008
    Posts
    574

    Re: Uniforms VS State Access for modelViewProjection

    guess it's easier with glMatrixMode calls. don't you need to pass or build f.e. a normal matrix inside the shader if passing via uniforms which is done automatically if using method 2? i guess this was implemented that way with something in mind.

  6. #6
    Super Moderator Frequent Contributor Groovounet's Avatar
    Join Date
    Jul 2004
    Posts
    936

    Re: Uniforms VS State Access for modelViewProjection

    I agree, with the fixe pipeline in mind

  7. #7
    Advanced Member Frequent Contributor _NK47's Avatar
    Join Date
    Mar 2008
    Posts
    574

    Re: Uniforms VS State Access for modelViewProjection

    yes. if you decide not to use GLSL for what ever reasons then everything would still work in FFP. kinda cool.

  8. #8
    Junior Member Newbie
    Join Date
    Oct 2008
    Posts
    4

    Re: Uniforms VS State Access for modelViewProjection

    Thank you all guys! I will try to use FFP as less ass possible.! thanks again!

  9. #9
    Intern Newbie
    Join Date
    Nov 2008
    Location
    Toronto, ON
    Posts
    48

    Re: Uniforms VS State Access for modelViewProjection

    The way I go is:

    On application side:
    Code :
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
    	glOrtho( -renderWidth/2,renderWidth/2, -renderHeight/2, renderHeight/2, 000, 50000.0 );
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();

    Then I access the matrix in glsl via the built-in variables:


    Code :
    gl_ModelViewMatrix
    gl_ProjectionMatrix

  10. #10
    Advanced Member Frequent Contributor _NK47's Avatar
    Join Date
    Mar 2008
    Posts
    574

    Re: Uniforms VS State Access for modelViewProjection

    Quote Originally Posted by Spongebob
    Thank you all guys! I will try to use FFP as less ass possible.! thanks again!
    why would you wanna drop it? gl_LightSource/gl_Material and the like are same reserved uniforms set via the gl calls. i use them like crazy maybe because of nostalgic OpenGL feeling, but yeah deprecated?

Posting Permissions

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