Please tell VertexShader Error Solution

↘锁芯ラ 提交于 2019-12-11 10:18:42

问题


Students that use 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. 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. Out of resource error.

This brings up an error .

Is there any way I want to use the current arrangement made ​​more than 60

Thank you look at the question


回答1:


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);

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];

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];

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.

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.



来源:https://stackoverflow.com/questions/34891342/please-tell-vertexshader-error-solution

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!