View Full Version : are const variables optimized?

05-30-2006, 03:18 PM
I know this is probably highly driver dependent, but would this ever be optimized (by not actually copying gl_Vertex):

void main()
const vec4 vec4Pos = gl_Vertex;

}btw, the reason I do this is to use built-in attributes for non-standard reasons (as opposed to using user-defined attributes).

05-30-2006, 04:02 PM
That will be optimized for sure (on ATI anyway, don't know about other IHVs).

05-30-2006, 04:21 PM
sweet, thanks!

06-02-2006, 11:42 AM
canukle, that code is incorrect. You are declaring a variable const, and then assigning to it. It isn't const at all.

The GLSL compiler on Mac OS X (used for ATI, NV, Intel, and Software renderers), will fail to compile that shader. Any compiler that succeeds is broken.

Assuming the const is removed, a simple assignment like that will ineeded be optimized away.

06-02-2006, 11:53 AM
Yes, it fails to compile on ATI for that reason. Removing the const it works and I verified that it indeed optimizes that away as expected.