GLhalf [ 8 ] -> glVertexAttribPointer?

I know this isn’t explicitly supported, but do we have the tools to pass a GUhalf[8] in a single 4-component vertex attribute despite the API?

glVertexAttribPointer size <= 4, so the nieve approach doesn’t work.

But what about packing 2 halfs in a single float (or uint)?
Question is, once you get them in the shader, can you shift/mask off 16-bits of a float/uint into a half nowadays?

(ARB_shader_bit_encoding only provides for 32-bit float<->int AFAICT)

Do you want to use half float like any other type?

In this case I would say no without a hand written conversion from this raw half data (passed as int without normalization) to float with the bits operations and functions. With GLSL 4.0 and the pretty extract*** functions it should be easy. It should be possible with GLSL 3.3 with & | << to actually write these extract functions.

Maybe an explicit support of half in GLSL would be nice. We have double, so why not?

Yeah, the goal being just to save vertex attributes.

I could grab the right bits using bitfieldExtract, but then how to cast that to a half?

GLSL used to be pretty limited in casting capability. Is this supported now? Would you literally just do:

half( bitfieldExtract( packed_attrib, 0, 16 ) )

I suspect not, as it’ll interpret the half operand as a genuine integer, not an encoded half. In C++ you might have done something like:

*(half *)( &half_in_unsigned_short )

…but this is GLSL.

I use the half type that comes with OpenEXR, works perfectly. Yo don’t need to embed all the OpenEXR library, just two files.


What I meant is a by “hand cast”.

Extracting the bits (sign, mentissa, exponent) from the raw data, manipulating the value with shiftings (and maybe scaling?) and assembling the 3 bits fields in a int to finally use the extension you mention to get a float. It might not that sample actually as for example the half to float cast in OpenEXR is quite big relatively to a shader program at least.

Beside saving attribute slot for maybe some heavy attribute based instancing, I not sure it could really be useful. Maybe… I love to hear the use cases!

Ah, I see what you’re seeing. Could work. Was just hoping there was a simpler way.


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