Jump to content
  • Advertisement
Sign in to follow this  
Tommato

Attributes as arrays

This topic is 628 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
Advertisement

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!