简体   繁体   English

OpenGL glVertexAttribPointer正常

[英]OpenGL glVertexAttribPointer normal

Let's say I am rendering a 3d GL_TRIANGLE. 假设我正在渲染一个3d GL_TRIANGLE。 The object requires 3 vertices for it to be defined: A,B,C. 该对象需要3个顶点才能定义:A,B,C。 I place such data into a buffer and bind it to the shader through glVertexAttribPointer. 我将这些数据放入缓冲区并通过glVertexAttribPointer将其绑定到着色器。

Now I want to pass in the normal to the shader. 现在我想将正常传递给着色器。 For every triangle there should be 1 normal vector but if I try to pass it in through a glVertexAttribPointer, I would need to define the same normal 3 times for points A,B,C. 对于每个三角形,应该有1个法向量,但如果我尝试通过glVertexAttribPointer传递它,我需要为点A,B,C定义相同的法线3次。 Is it possible to pass in 1 vertex every 3 other vertices in a glVertexAttribPointer to avoid this? 是否可以在glVertexAttribPointer中每隔3个顶点传入1个顶点以避免这种情况?

Or is it a good idea to pass it in for all vertices? 或者将它传递给所有顶点是个好主意?

Now I want to pass in the normal to the shader. 现在我想将正常传递给着色器。 For every triangle there should be 1 normal vector 对于每个三角形,应该有1个法向量

No, there are 3 normals. 不,有3个法线。 One for each vertex. 每个顶点一个。

Is it possible to pass in 1 vertex every 3 other vertices in a glVertexAttribPointer to avoid this? 是否可以在glVertexAttribPointer中每隔3个顶点传入1个顶点以避免这种情况?

No, because vertex attributes belong together and can not be separated. 不,因为顶点属性属于一起而无法分开。

Or is it a good idea to pass it in for all vertices? 或者将它传递给所有顶点是个好主意?

Definitely. 当然。 Makes life much easier for everybody. 让每个人的生活更轻松。

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

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