Uniforms VS State Access for modelViewProjection

Hello all! :slight_smile:
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! :slight_smile:

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.

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

  • 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.

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.

I agree, with the fixe pipeline in mind :wink:

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

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

The way I go is:

On application side:

	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:


gl_ModelViewMatrix
gl_ProjectionMatrix

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?

I really think that all these gl_LightSource, gl_Material, and matrices stuff just make this code more complex. Moreover nowdays with bindable uniforms, it becomes very inlikely to use those fixed pipeline stuff.

My believe is: Make it easy, make it programable!

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.