Array in attribute - possible?

Hi!
I have a small problem: I need send to vertex program per one vertex (attribute qualifier) an array of floats for example 100-elements array… but I can not compile my shader using:
attribute float var[100]
I now that I’m able to write data to texture, bind sampler and send per one vertex an indices in the texture. But this solution is unsatisfactory, because each call of function “texture2D” or “texelFetch” i slow. If I call this function 100 times - hopelessly.

Do you know any solution for this problem?

Not sure if attribute arrays are supported, but if they are, 100 is likely exceeding the GL_MAX_VERTEX_ATTRIBS limit.

Arrays of vertex shader inputs (vertex attributes) are supported, but each element of the array counts against your GL_MAX_VERTEX_ATTRIBS limit. Which for pretty much all hardware, is 16.

I now that I’m able to write data to texture, bind sampler and send per one vertex an indices in the texture. But this solution is unsatisfactory, because each call of function “texture2D” or “texelFetch” i slow. If I call this function 100 times - hopelessly.

I’m rather confused as to what your overall goal for the program is. Could you explain this?

I can only say that for each vertex I need a lot of data, not necessarily 100 bytes, but may be 120 or 60. I do not know which solution is best for this.
In my hardware: GL_MAX_VERTEX_ATTRIBS: 16
Is there 13 build-in vertex attributes: gl_Vertex, gl_Normal, gl_Color, gl_SecondaryColor, gl_FogCoord, gl_MultiTexCoord0-gl_MultiTexCoord7… Does this mean that I can only upload my own three variables?

I can only say that for each vertex I need a lot of data, not necessarily 100 bytes, but may be 120 or 60. I do not know which solution is best for this.

There isn’t really a “good” solution for this. The best thing you could do is try to change what you’re doing so that it works within the attribute limits.

If you can’t, then you will need to resort to buffer textures to store your data. You will need to pass an index as an attribute, and then you will need to use that index to fetch whatever data you need from the buffer texture.

Is there 13 build-in vertex attributes: gl_Vertex, gl_Normal, gl_Color, gl_SecondaryColor, gl_FogCoord, gl_MultiTexCoord0-gl_MultiTexCoord7… Does this mean that I can only upload my own three variables?

They only count attributes that you actually use. So if you don’t use the built-in ones in GLSL, they don’t get counted.

First you are talking about 100 floats and now you need 120 or 60 bytes. That’s a huge difference, actually.

120 bytes = 30 ints < 8 ivec4

So you actually need only 8 attributes, which can be passed as an array.

Using only gl_Vertex, gl_Normal and gl_MultiTexCoord0 I have 13 free attributes, so I can pass 13*4=52 floats (13 4th dim.vectors).

But in many cases, my algorithm will need to calculate ‘a value’ integrating more floats (for example, 180) - then I have to share data in the texture.

I tested the integration by using attributes (27 floats) - very fast, and tested integration with sampler2D and texelFetch - very slow :frowning:

But in many cases, my algorithm will need to calculate ‘a value’ integrating more floats (for example, 180) - then I have to share data in the texture.

What is your algorithm that it has such requirements?

I apologise, but it does not matter at this time. I think none of You helped me, but thank you very much for taking part in the discussion :wink:

sorry for bringing up solved post, but how did you do your texelFetch? do you use a 1D sampler?

im currently having a problem trying to do a texelFetch combined with my isampler1D. it always return 0. is there any extension i should include? im using Shading Language version 1.30.

thanks in advance

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.