简体   繁体   English

请告诉VertexShader错误解决方案

[英]Please tell VertexShader Error Solution

Students that use OpenGL. 使用OpenGL的学生。 Do not speak English well. 不会说英语。 So please understand. 所以请理解。

There is currently a problem 目前存在一个问题

#version 400
layout (location = 0) in vec3 VertexPosition;
layout (location = 1) in vec3 VertexNormal;
layout (location = 2) in mat4 instance_ModelMatrix [3];

The VertexShader Code. VertexShader代码。 Code above , but it is run 上面的代码,但它运行

layout (location = 2) in mat4 instance_ModelMatrix [3];

-> - >

layout (location = 2) in mat4 instance_ModelMatrix [4];

With this changing run 随着这种变化的运行

Attribute instance_ModelMatrix is ​​a matrix or array, and there is no room to insert it at the bound generic attribute channel. 属性instance_ModelMatrix是一个矩阵或数组,没有空间将其插入绑定的通用属性通道。 Out of resource error. 出于资源错误。

This brings up an error . 这会带来错误。

Is there any way I want to use the current arrangement made ​​more than 60 有什么方法我想使用目前超过60的安排

Thank you look at the question 谢谢你看看这个问题

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...?). 最大属性数由GL_MAX_VERTEX_ATTRIBS确定,这对于每个实现都不同但必须至少为16(因此它应该工作......?)。 You can get the value using glGetIntegerv() : 您可以使用glGetIntegerv()获取值:

int maxVertexAttribs;
glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs);

Since each mat4 counts as four attributes, and each vec3 counts as one, the following code uses uses 14 attributes: 由于每个mat4计为四个属性,并且每个vec3计为一个,因此以下代码使用14个属性:

#version 400
layout (location = 0) in vec3 VertexPosition;
layout (location = 1) in vec3 VertexNormal;
layout (location = 2) in mat4 instance_ModelMatrix [3];

In this code, instance_ModelMatrix will actually use locations 2 through 13. When you change the array size: 在此代码中, instance_ModelMatrix实际上将使用位置2到13.当您更改数组大小时:

#version 400
layout (location = 0) in vec3 VertexPosition;
layout (location = 1) in vec3 VertexNormal;
layout (location = 2) in mat4 instance_ModelMatrix [4];

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. 这使用18个顶点属性,在插槽2到17中使用instance_ModelMatrix 。我的猜测是系统上的顶点属性的最大数量是16,所以这不适合。

Solution

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. 然后,您可以使用gl_InstanceID作为实例数据的索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM