3

In my program I am doing a single render of one model. I have a generated array of unsigned chars where all bits in each byte can be used. There is an element in the array for each triangle in the model. To get the color for the triangle I use gl_PrimitiveID which gives you the location of the triangle in the buffer being rendered.

My problem is that my GPU is 4.2 meaning I can only use UBOs and not SSBOs. The max array size (byte array) is a little over 16,000 and I need 100,000, The smallest required UBO size is 16KB. Using a standard uniform float[N] has the same limit as the UBO in my case.

I have been looking at this: https://www.opengl.org/registry/specs/NV/shader_buffer_load.txt

But I would like to know if there are other option before I use something so device specific.

My current Frag-Shader if you would like to see:

#version 420 core
out vec3 color;
layout (std140) uniform ColorBlock{
    unsigned char colors[16000]; // this need to be 100,000
};
void main(){
    float r, g, b;
    r = colors[1.0f / gl_PrimitiveID];
    g = colors[1.0f / gl_PrimitiveID];
    b = colors[1.0f / gl_PrimitiveID];
    color = vec3(r, g, b);
}
1
  • unsigned char? The smallest data type GLSL supports is 32-bit. If you have an array of bytes like that in C, you're going to have to unpack it in GLSL. Commented Mar 7, 2015 at 23:24

1 Answer 1

9

You can use texture buffer objects (TBOs).

Note that although they are exposed via the texture interface, the data access is totally different from textures, the data is directly fetched from the underlying buffer object, with no sampler overhead.

Also note that the guaranteed minimum size for TBOs is only 65536 texels. However, on all desktop implementations, it is much larger. Also note that you can pack up to 4 floats into an texel, so that 100000 values will be possible that way, even if only the minimum size is available.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.