问题描述
使用OpenGL的学生.英文说得不好.所以请您理解.
Students that use OpenGL.Do not speak English well.So please understand.
当前有问题
#version 400
layout (location = 0) in vec3 VertexPosition;
layout (location = 1) in vec3 VertexNormal;
layout (location = 2) in mat4 instance_ModelMatrix [3];
VertexShader代码.上面的代码,但是可以运行
The VertexShader Code.Code above , but it is run
layout (location = 2) in mat4 instance_ModelMatrix [3];
->
layout (location = 2) in mat4 instance_ModelMatrix [4];
此更改运行
这会引发错误.
我有什么办法可以使用当前的60以上的安排
Is there any way I want to use the current arrangement made more than 60
谢谢你看问题
推荐答案
为什么不起作用
最大属性数由GL_MAX_VERTEX_ATTRIBS
确定,每个实现都不同,但必须至少为16(因此应该起作用...?).您可以使用glGetIntegerv()
:
Why it doesn't work
The maximum number of attributes is determined by GL_MAX_VERTEX_ATTRIBS
, this is different for every implementation but must be at least 16 (so it should work...?). You can get the value using glGetIntegerv()
:
int maxVertexAttribs;
glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs);
由于每个mat4
都被视为四个属性,每个vec3
都被视为一个属性,因此以下代码使用了14个属性:
Since each mat4
counts as four attributes, and each vec3
counts as one, the following code uses uses 14 attributes:
#version 400
layout (location = 0) in vec3 VertexPosition;
layout (location = 1) in vec3 VertexNormal;
layout (location = 2) in mat4 instance_ModelMatrix [3];
在此代码中,instance_ModelMatrix
实际上将使用位置2到13.更改数组大小时:
In this code, instance_ModelMatrix
will actually use locations 2 through 13. When you change the array size:
#version 400
layout (location = 0) in vec3 VertexPosition;
layout (location = 1) in vec3 VertexNormal;
layout (location = 2) in mat4 instance_ModelMatrix [4];
这使用18个顶点属性,插槽2到17中具有instance_ModelMatrix
.我的猜测是,系统上的顶点属性最大数量为16,因此不合适.
This uses 18 vertex attributes, with instance_ModelMatrix
in slots 2 through 17. My guess is that the maximum number of vertex attributes on your system is 16, so this doesn't fit.
如果要使用大量每个实例的数据,则必须使用统一,统一缓冲区对象或缓冲区纹理. 统一缓冲区对象可能最适合您的应用程序.然后,您可以使用gl_InstanceID
作为实例数据的索引.
If you want to use a lot of per-instance data, you will have to use uniforms, uniform buffer objects, or buffer textures. Uniform buffer objects are probably the right fit for your application. You can then use gl_InstanceID
as an index into your instance data.
这篇关于请告诉VertexShader错误解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!