1

I need to access a one dimensional big(~2MB) buffer from a shader. However, I don't know which type of OpenGL buffer I should use. I'm going to store floats(16F) and unsigned integers (16UI). My data will be like an struct:

struct{
    float d; //16F
    int  a[7]; //or a1,a2,a3,a4,a5,a6,a7; //7x16UI
}

I read about buffer texture and other kind of buffers(Passing a list of values to fragment shader), but it only works for one type of data (float or int), not both. I could use two buffers, but I think this won't be cache friendly nor easy.

Community
  • 1
  • 1
dv1729
  • 987
  • 1
  • 8
  • 25
  • 3
    Have a look at [Shader Storage Buffer Objects (SSBO)](https://www.opengl.org/registry/specs/ARB/shader_storage_buffer_object.txt). They are core since 4.0 and should do exactly what you need. – BDL Oct 27 '14 at 23:31
  • That's exactly what I wanted, thanks! – dv1729 Oct 28 '14 at 00:21
  • 1
    You're going to have a bit of trouble here if you're really and truly trying to use a half-float format (16F). You are going to have to resort to things like `unpackHalf2x16` because `float` in GLSL is 32-bit (as is `int`). – Andon M. Coleman Oct 28 '14 at 03:38
  • Thanks, I didn't think about that... That reminds me that I need to pack them on the CPU side, I was looking for C(not C++) libraries, I only found [this](http://cellperformance.beyond3d.com/articles/2006/07/update-19-july-06-added.html) one, that will work, right? – dv1729 Oct 28 '14 at 09:52
  • @dv1729: Yes, that should work. I've actually never bothered to deal with this exclusively in C. Most people use GLM for this, but I can see why you wouldn't want to use a templated C++ library in a C project :P – Andon M. Coleman Oct 29 '14 at 13:43

0 Answers0