GLSL Geometry shader and general vertex attributes

So, I’ve been trying for some time to pass an array of vertex attributes to a geometric shader. This is a float array (where the attribute to the top is just a floating point value)

Now, when I put this in a geometric shader:

attribute float nodesizes; 

The shader compiler complains:

 OpenGL requires geometry inputs to be arrays 

How to accurately convey it?

Also, here is my code for pegging the vertex:

 glBindAttribLocation(programid, 1, "nodesizes"); glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, array); glEnableVertexAttribArray(1); 

Am I doing something wrong?

+6
source share
2 answers

The geometric shader does not receive attributes. The vertex shader receives an attribute and produces varying (speaking in the old syntax). Then they can be read in the geometric shader, but as an array, since one call to the geometry shader follows several calls to the vertex shader. Something like that:

vertex shader:

 attribute float nodesize; varying float vNodesize; void main() { ... vNodesize = nodesize; ... } 

geometric shader:

 varying float vNodesize[]; void main() { ...vNodesize[i]... } 

The names are arbitrary, but, of course, the names of the changes must match in both shaders. I hope you didn’t just spoil the terms of shaders and geometric shaders.

+8
source

What version of open gl are you using?

From the Open GL specification (4.10.6)

One call to the geometry executable file executed on the geometry processor will work on the declared input primitive with a fixed number of vertices. This single call can emit a variable number of vertices that are assembled into the primitives of the declared output primitive type and passed in the subsequent stages of the pipeline.

This means that you need to indicate the type of primitive (point, line, triangle, square) that the geometry implies.

If I understand you correctly, you want the geomechanical shader to emit a cube for each vertex. Therefore, you must set the type of geometry input to the point.

As a result code, the geom shader should start as follows:

 varying float vNodesize[]; void main() { ...vNodesize[i]... } 

Where i = 0 for dots = 1 for strings, etc.

-1
source

Source: https://habr.com/ru/post/891722/


All Articles