Are const variables optimized?

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

That will be optimized for sure (on ATI anyway, don’t know about other IHVs).

sweet, thanks!

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.

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.

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