INT2FLOAT

Some opengl functions (like glColor) require an integer to float conversion for some parameter.

Unsigned integers (GLuint, GLushort, GLubyte) are mapped to [0.0, 1.0] and signed integers (GLint, GLshort, GLbyte) to [-1.0,1.0].

Most of the time the values are encoded in IEEE 754 FP32 in the FIFO. But sometimes the values are compressed to 16 or 8 bits.

16 bits conversions

We have A and B, 2 integers converted to float in [-1.0, 1.0].

If A1 and B1 are signed short and A1=A*USHRT_MAX/2 ; B1=B*USHRT_MAX/2, we have in the FIFO

B1 << 16 | A1

example :

glNormal3i(0 ,INT_MAX,INT_MIN);

2b5   0x00000000   0x00082c40   {size: 0x2   channel: 0x1   cmd: NV15_NORMAL_SHORT_BYTE}
2b6   0x00000000   0x7fff0000  (FP16: 0.000000 | 0.999985)  
2b7   0x00000000   0x00008000  (FP16: -1.000015 | 0.000000)

8 bits conversions

We have A, B, C, D 4 unsigned integers converted to float in [0, 1.0].

If A1, B1, C1, D1 are unsigned char and A1=A/UCHAR_MAX; B1=B/UCHAR_MAX, C1=C/UCHAR_MAX, D1=D/UCHAR_MAX we have in the FIFO

D1 << 24 | C1 << 16 | B1 << 8 | A1

example :

glColor4ub(0,UCHAR_MAX, 0, UCHAR_MAX);

2b7   0x00000000   0x00042c6c   {size: 0x1   channel: 0x1   cmd: NV15_COLOR}
2b8   0x00000000   0xff00ff00  (FP8: 0.000000 | 1.000000 | 0.000000 | 1.000000)  

Note

The conversion can have some errors. For example in 16 bits, MAX_INT = 0x7fff but SCHAR_MAX = 0x7f7f.