Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

In a GLSL fragment shader I am trying to cast a float into an int. The compiler has other ideas. It complains thusly:

ERROR: 0:60: '=' :  cannot convert from 'mediump float' to 'highp int'

I am trying to do this:

mediump float indexf = floor(2.0 * mixer);
highp int index = indexf;

I (vainly) tried to raise the precision of the int above the float to appease the GL Gods but no joy.

Could someone please school me here?

Thanks,
Doug

share|improve this question
1  
For future reference, you will get better answers if you ask general programming questions like this one at Stack Overflow. stackoverflow.com - depending on community feedback this question might be migrated there anyway. –  Ricket Feb 17 '11 at 18:48

1 Answer 1

up vote 7 down vote accepted

Try this:

highp int index = int(indexf);

I found it here.

share|improve this answer
    
Thanks for the tip –  dugla Feb 17 '11 at 19:10
    
Also note that casting a float to an int automatically floors it (at least in any implementation I've ever seen) so your call to floor should be unnecessary. –  Ricket Feb 17 '11 at 20:03
3  
In most languages the rounding mode is truncate / round-to-zero, which is equivalent to floor for positive numbers but not negative numbers. I don't remember if this applies to GLSL, but I'd be surprised if it doesn't. –  user744 Feb 17 '11 at 20:19
    
@Joe That's an interesting fact that I never thought about, and I just confirmed it with a Java test case. –  Ricket Feb 18 '11 at 3:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.