Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Opengl es 向使用多个顶点阵列对象的渲染器引入深度缓冲区_Opengl Es_Opengl Es 2.0_Depth Buffer_Vertex Array - Fatal编程技术网

Opengl es 向使用多个顶点阵列对象的渲染器引入深度缓冲区

Opengl es 向使用多个顶点阵列对象的渲染器引入深度缓冲区,opengl-es,opengl-es-2.0,depth-buffer,vertex-array,Opengl Es,Opengl Es 2.0,Depth Buffer,Vertex Array,我有一个渲染基础设施,它使用多个顶点数组对象渲染复杂场景。每个顶点数组对象负责维护自己的绑定缓冲区、指针和属性集(正如它们设计的那样) 给定负责渲染的多个阵列对象,如何引入深度缓冲,使每个单独的阵列对象在渲染期间使用相同的深度缓冲?换句话说,我如何统一顶点数组对象(及其良好的封装属性)和深度缓冲的概念,这似乎是一个更全局的概念 我发现的所有示例都描述了在帧缓冲区上下文中使用深度缓冲区。苹果公司描述了这种技术。那么,是在帧缓冲区级别实现深度缓冲,然后让顶点数组对象写入该帧缓冲区的技术吗?有没有使用

我有一个渲染基础设施,它使用多个顶点数组对象渲染复杂场景。每个顶点数组对象负责维护自己的绑定缓冲区、指针和属性集(正如它们设计的那样)

给定负责渲染的多个阵列对象,如何引入深度缓冲,使每个单独的阵列对象在渲染期间使用相同的深度缓冲?换句话说,我如何统一顶点数组对象(及其良好的封装属性)和深度缓冲的概念,这似乎是一个更全局的概念

我发现的所有示例都描述了在帧缓冲区上下文中使用深度缓冲区。苹果公司描述了这种技术。那么,是在帧缓冲区级别实现深度缓冲,然后让顶点数组对象写入该帧缓冲区的技术吗?有没有使用VAOs和深度缓冲的例子

我有一个封装vertex数组对象的类,这是它的bind方法(负责设置各种缓冲区、指针和属性)

绑定后,draw方法按如下方式实现(并对每个单独的顶点缓冲区对象调用此draw方法):

所有这些工作都很顺利,但我很难看到深度缓冲适合这一点

我很难看到深度缓冲适合这一点

那是因为它不适合任何一个

顶点数组对象是封装顶点数组状态的方法。此状态与其他状态无关,如当前程序对象、当前绑定的纹理或帧缓冲区。最后一个是深度缓冲区的来源

如果要使用VAO将多个对象渲染到同一帧缓冲区,则只需不更改帧缓冲区即可。这就是如何将它们渲染到同一个图像(为了简单起见,我们称之为屏幕)。深度缓冲区是帧缓冲区的一部分,因此如果要渲染到相同的深度缓冲区,请不要更改不同对象之间的帧缓冲区


简而言之,对象的
Draw
函数既不知道也不关心当前使用的深度缓冲区。就像
Draw
函数不知道或不关心正在使用的程序、绑定的纹理以及当前视口是什么。

谢谢!这在很大程度上消除了我心目中的这种关系。
void scene_GLBuffer::BindTriangles()
{
    glBindVertexArrayOES(_mVertexArrayObject);
    glGenVertexArraysOES(1, &_mVertexArrayObject);

    // generate the buffer and configure the gl pointers for position and normal data
    glGenBuffers(1, &_mVertexPositionNormalTriangles);
    /* Bind and set up vertex position and normal data */
    glBindBuffer(GL_ARRAY_BUFFER, _mVertexPositionNormalTriangles);
    glBufferData(GL_ARRAY_BUFFER,
                 sizeof(crVertexPN)*_mPositionNormalTriangleData->size(),
                 _mPositionNormalTriangleData->data(),
                 GL_STATIC_DRAW);
    glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE,
                          sizeof(crVertexPN), (void*)offsetof(crVertexPN,Position));
    glEnableVertexAttribArray(GLKVertexAttribPosition);
    glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE,
                          sizeof(crVertexPN), (void*)offsetof(crVertexPN,Normal));
    glEnableVertexAttribArray(GLKVertexAttribNormal);

    // generate the buffer and configure the gl pointers for color and alpha data
    glGenBuffers(1, &_mVertexColorTriangles);
    glBindBuffer(GL_ARRAY_BUFFER, _mVertexColorTriangles);
    glBufferData(GL_ARRAY_BUFFER,
                 sizeof(crVertexC)*_mColorTriangleData->size(),
                 _mColorTriangleData->data(),
                 GL_DYNAMIC_DRAW);
    glVertexAttribPointer(GLKVertexAttribColor, 4, GL_FLOAT, GL_TRUE,
                          sizeof(crVertexC), (void*)offsetof(crVertexC,Color));
    glEnableVertexAttribArray(GLKVertexAttribColor);
    glBindBuffer(GL_ARRAY_BUFFER,0);

    // generate the buffer and configure the gl pointers for triangle index data
    glGenBuffers(1, &_mVertexIndexTriangles);
    /* Bind and set up triangle index data */
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _mVertexIndexTriangles);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(bits32)*_mIndexTriangleData->size(),_mIndexTriangleData->data(), GL_STATIC_DRAW);
    //        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);

    glBindVertexArrayOES(0);
}
void scene_GLBuffer::Draw()
{
    glBindVertexArrayOES(_mVertexArrayObject);

    glBindBuffer(GL_ARRAY_BUFFER, _mVertexPositionNormalTriangles);
    glDrawElements(GL_TRIANGLES, _mIndexTriangleData->size(), GL_UNSIGNED_INT, 0);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    glBindVertexArrayOES(0);
}