简体   繁体   中英

Please tell VertexShader Error Solution

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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