3
\$\begingroup\$

I'm trying to use (un)packHalf2x16, without success so far. I'm drawing with:

glVertexAttribIPointer(0, 2, GL_UNSIGNED_INT, 0, 0);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glDrawArrays(GL_POINTS, 0, n_points);
glDisableVertexAttribArray(0);

and on the shader

#version 330 core
#extension GL_ARB_shading_language_packing : require
in uvec2 A0;
// (...)
vec4 t = vec4(unpackHalf2x16(A0.x), unpackHalf2x16(A0.y));

But nothing gets drawn. I'm pretty sure buffer's content is right, and if I use vec4 t = vec4(0); I can see it's working properly. How is this packing / unpacking thing supposed to work? I can't find any example.

\$\endgroup\$
  • 1
    \$\begingroup\$ How are you generating the buffer data? Are you sure the half-floats are being stored correctly? Also, have you checked that things draw correctly if you use regular 32-bit floats instead of half-floats? \$\endgroup\$ – Nathan Reed Oct 26 '13 at 20:21
  • \$\begingroup\$ I'm pretty sure. But even if it was just noise or 0s I should see something on the screen. It used to work with regular floats, I'm trying to save some bytes and (hypothetically) make it faster now. \$\endgroup\$ – user1032861 Oct 26 '13 at 20:39
1
\$\begingroup\$

I think you may have to bind your array buffer before calling glVertexAttribIPointer. But other than that the code looks correct. But why not just use half float vertex attributes and avoid the shader work?

glBindBuffer(GL_ARRAY_BUFFER, vbo);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4,  GL_HALF_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_POINTS, 0, n_points);
glDisableVertexAttribArray(0);

and

#version 330 core
in vec4 t;
// (...)
\$\endgroup\$
  • \$\begingroup\$ I forgot to copy the bind. It's there on the code. I don't use float attributes because my objective is to use transform feedback, that only outputs 32bits floats / ints. \$\endgroup\$ – user1032861 Oct 28 '13 at 11:47
  • \$\begingroup\$ Yeah I saw it. But it's after you call glVertexAttribPointer which AFAIK depends on the binding state. Also, you could still use float attributes. You could write the buffer as 2 32-bit ints and then read the buffer as 4 16-bit floats and only use the packing intrinsic on the write side. You can use different settings for glVertexAttribPointer on the same buffer data. \$\endgroup\$ – Lucas Oct 28 '13 at 21:33
  • \$\begingroup\$ Thanks, I need to try that. It makes sense, I didn't even try that way. Now I need to write this somewhere as I'll be AFK for the rest of the week :D \$\endgroup\$ – user1032861 Oct 29 '13 at 9:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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