GLSL 几何着色器和通用顶点属性
所以我已经尝试了一段时间,将顶点属性数组传递到几何着色器中。它是一个浮点数组(其中每个顶点的属性只是一个浮点值)
现在,当我将其放入几何着色器中时:
attribute float nodesizes;
着色器编译器抱怨:
OpenGL requires geometry inputs to be arrays
我如何准确地传递它?
另外,这是我放置顶点属性的代码:
glBindAttribLocation(programid, 1, "nodesizes");
glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, array);
glEnableVertexAttribArray(1);
我做错了什么吗?
So I've been trying for a while now, to pass a vertex attribute array into the geometry shader. It is an array of float (where the attribute per vertex is just a float value)
Now, when I put this in the geometry shader:
attribute float nodesizes;
The shader compiler complains:
OpenGL requires geometry inputs to be arrays
How do I exactly pass it along?
Also, here's my code for putting the vertex attrib:
glBindAttribLocation(programid, 1, "nodesizes");
glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, array);
glEnableVertexAttribArray(1);
Am I doing something wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
几何着色器不获取属性。顶点着色器获取
属性
并输出变化
(用旧语法来说)。然后可以在几何着色器中读取它们,但作为数组,因为一个几何着色器调用跟随多个顶点着色器调用。像这样的东西:顶点着色器:
几何着色器:
名称是任意的,但当然变量的名称必须在两个着色器中匹配。我希望您不要混淆顶点着色器和几何着色器这两个术语。
The geometry shader doesn't get attributes. The vertex shader gets
attribute
s and puts outvarying
s (speaking in the old syntax). These can then be read in the geometry shader, but as an array, as one geometry shader invocation follows multiple vertex shader invocations. Something like this:vertex shader:
geometry shader:
The names are arbitrary, but of course the names of the varyings have to match in both shaders. I hope you didn't just mess up the terms vertex shader and geometry shader.
您使用的是哪个 open gl 版本?
来自Open GL语言规范(4.10.6)
这意味着您需要指定几何图形所采用的图元类型(点、线、三角形、四边形)。
如果我理解正确的话,您希望几何着色器为每个顶点发出一个立方体。因此,您应该将几何输入类型设置为点。
因此,几何着色器代码应该这样开始:
其中 i = 0 表示点 =1 表示线等。
Which open gl version are you using?
From the Open GL language specification (4.10.6)
This means that you need to specify on witch kind of primitive (point, line, trianle, quad) the geometry assumes.
If I understand you correctly you want the geom shader to emit a cube for each vertex. So you should set the geometry input type to point.
As a reslult the geom shader code should start like this:
Where i = 0 for points =1 for lines and so on.