Sign in to follow this  

Attributes as arrays

This topic is 416 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi All

 

Most probably it's a naive question but I can't find any answer. Can I use attribute as array (pseudocode)?

 

// vertex shader

attribute vec4 pos;

varying test;

...

void main( void )

{

 ...

  test = pos[5]; 

...

}

 

Is it valid? If yes what is returned? A value from attribute start or from current vertex?

 

Thank you

 

Share this post


Link to post
Share on other sites

No, but there are several ways to access data. It depends on what version of OpenGL you want to use as a minimum requirement, what size the data is, and if you want only read access or read/write access.

 

Very simple but also very limited in size is a uniform array. This only supports reading in the shader.

uniform vec4 pos[8];

Then there is the buffer texture. Core since OpenGL 3.0. Where you bind your buffer as 1-dimensonal "texture". And then access it via texelFetch?.

 

The next step would be a uniform buffer object (ubo). Core since OpenGL 3.1. This also is limited to read. And the guaranteed supported size is only 16KiB. In practice its 16 KiB on Intel, 64 KiB on Nvidia and very very large on AMD hardware.

 

Even newer and with support for write operations are Shader Storage Buffer Object (ssbo). Core since OpenGL 4.3. Guaranteed supported size is 16 MiB.

Edited by Osbios

Share this post


Link to post
Share on other sites

This topic is 416 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this