如何将两个不同的顶点缓冲区绑定到两个槽

时间:2013-06-19 11:11:17

标签: c++ qt opengl

如何将两个顶点缓冲区绑定到不同的槽(slot0和slot1),

我想在OpenGL(QT)中使用这样的东西:

QGLBuffer VB0, VB1;

VB0.bind(0);
VB1.bind(1);

到目前为止,我有这个:

verticesBuffer = new QGLBuffer(QGLBuffer::VertexBuffer);
verticesBuffer->create();
verticesBuffer->bind();
verticesBuffer->setUsagePattern(QGLBuffer::DynamicDraw);
verticesBuffer->allocate(vertices.constData(), _ANGLE_CNT * _RANGE_CNT * 6 * sizeof(QVector3D));
verticesBuffer->release();

colorsBuffer = new QGLBuffer(QGLBuffer::VertexBuffer);
colorsBuffer->create();
colorsBuffer->bind();
colorsBuffer->setUsagePattern(QGLBuffer::DynamicDraw);
colorsBuffer->allocate(_ANGLE_CNT * _RANGE_CNT * 6 * sizeof(float));
colorsBuffer->release();

你能写一个样本来解释我应该把这些缓冲区绑定到插槽吗?

2 个答案:

答案 0 :(得分:0)

当人们不完全理解我的问题时,他们可以自由地给予反对票。我在另一个论坛上问了同样的问题,我得到了确切的答案。我的帐户被这种愚蠢的投票方式所阻止。所以,我在这里回答我自己的问题:

glGenVertexArrays(1, &VAO_ID);
glBindVertexArray(VAO_ID);

glBindBuffer(GL_ARRAY_BUFFER,buffer_0_id);
 glVertexAttribPointer(POSITION_0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);
...


glBindBuffer(GL_ARRAY_BUFFER,buffer_1_id);
 glVertexAttribPointer(POSITION_1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);
...

layout(location = POSITION_0) in  vec3  Position0;
layout(location = POSITION_1) in  vec3  Position1;

答案 1 :(得分:-2)

更新: 将此添加到初始化部分:

verticesSize = sizeof(vertices);
colorsSize   = sizeof(colors);

glGenBuffers(2, vbods);                       

glBindBuffer(GL_ARRAY_BUFFER, vbods[VERTEX]); 

glBufferData(GL_ARRAY_BUFFER,
             sizeof(vertices)+sizeof(colors),
             vertices, GL_STATIC_DRAW );

glBufferSubData(GL_ARRAY_BUFFER, sizeof(vertices), sizeof(colors), colors);

glEnableClientState(GL_VERTEX_ARRAY); 
glEnableClientState(GL_COLOR_ARRAY);  

这是渲染部分:

glBindBuffer(GL_ARRAY_BUFFER, vbods[VERTEX]);
glVertexPointer(2, QVector3D, 0, 0);   
glColorPointer(3, GL_FLOAT, 0, (GLvoid *) (ANGLE_COUNT * RANGE_COUNT * 6));