Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.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 glBindVertexBuffer与glBindBuffer_Opengl - Fatal编程技术网

Opengl glBindVertexBuffer与glBindBuffer

Opengl glBindVertexBuffer与glBindBuffer,opengl,Opengl,我发现我可以使用glBindBuffer(GL_数组_缓冲区,vbo)绑定顶点缓冲区。这是可行的,我还可以使用glBindBuffer(GL\u element\u array\u BUFFER,ebo)绑定元素数组。使用这些工具时,一切都会按需要绘制 在阅读第10.3.1节中的OpenGL 4.4规范时,我发现提到了glBindVertexBuffer。看起来这允许绑定多个顶点缓冲区,然后一次渲染所有顶点缓冲区。这是正确的吗?另外,它与使用glBindBuffer有何不同?在绑定顶点缓冲区时,

我发现我可以使用
glBindBuffer(GL_数组_缓冲区,vbo)绑定顶点缓冲区。这是可行的,我还可以使用
glBindBuffer(GL\u element\u array\u BUFFER,ebo)绑定元素数组。使用这些工具时,一切都会按需要绘制


在阅读第10.3.1节中的OpenGL 4.4规范时,我发现提到了
glBindVertexBuffer
。看起来这允许绑定多个顶点缓冲区,然后一次渲染所有顶点缓冲区。这是正确的吗?另外,它与使用
glBindBuffer
有何不同?在绑定顶点缓冲区时,是否可以使用元素数组缓冲区?

不太可能<代码>glBindVertexBuffers
用于绑定多个顶点缓冲区。对于
glBindVertexBuffer
,它用于将缓冲区绑定到顶点缓冲区。您可能需要多次调用它才能绑定多个顶点缓冲区

您可以在此处查看他们的文档:

实际上,
glBindVertexBuffer(…)
的要点是完全不同的

年引入时的想法是分离始终存在于顶点缓冲区和指针之间的固定映射,并将其替换为更灵活的系统,该系统允许您设置顶点属性的格式,顶点缓冲区/属性要使用的绑定位置,然后简单地交换绑定到该位置的缓冲区

您不会简单地用这个新函数替换对
glBindBuffer(…)
的调用,您至少还需要调用另外两个函数来设置通用顶点属性,以便能够利用
glBindVertexBuffer(…)

  • glvertexattributeformat(…)

    • 这与
      glvertexattributepointer(…)
      实际上是一样的,只是它不设置指针,它只是确定如何解释将与此属性配对的缓冲区。

  • glVertexAttribBinding(…)

    • 这将通用属性位置与新的类型的绑定位置(顶点缓冲区绑定)相关联,以便您可以使用
      glBindVertexBuffer(…)
      将VBO绑定到该属性将使用的位置

  • 为了更好地理解这一点,我在扩展规范中包含了一些伪代码,这些伪代码展示了
    glvertexattributepointer(…)
    如何与这个新的API添加相关

    命令: 控制顶点属性状态、顶点缓冲区绑定以及顶点属性和顶点缓冲区绑定之间的映射

    它们相当于(假设未生成错误):
    if(没有缓冲区绑定到GL_数组_缓冲区和指针!=NULL){
    生成总账_无效_操作;
    }
    glVertexAttrib*格式(索引、大小、类型,{normalized,},0);
    glVertexAttribBinding(索引,索引);
    如果(步幅!=0){
    有效步幅=步幅;
    }否则{
    根据尺寸/类型计算有效步幅;
    }
    GL_顶点_属性数组_步长[索引]=步长;
    //GL_顶点_绑定_步幅将设置为有效步幅
    //通过glBindVertexBuffer。
    glBindVertexBuffer(索引,
    (GLchar*)指针-(GLchar*)NULL,有效跨步);
    

    一开始有点困难,但归根结底,这与在GL 3.3中引入采样器对象时,将采样器状态与纹理对象分离非常相似。您可以继续使用旧的API,但此替代解决方案为您提供了更多的灵活性

    关于元素数组缓冲区,没有。API的这一新部分与此无关,因为顶点数组对象实际上管理一个且唯一的元素数组缓冲区绑定。

    -1“它用于将缓冲区绑定到顶点缓冲区”-这一点非常不清楚,任何规范语言都不支持。BindVertexBuffer()用于将缓冲区对象绑定到所谓的绑定点(在[0,MAX_VERTEX_ATTRIB_BINDINGS-1]中),该绑定点可以通过调用VertexAttribinding()与VertexAttribFormat*()设置的特定属性绑定相关联。这将使顶点数组与缓冲区分离。
         void glVertexAttribPointer (GLuint index, GLint size, GLenum type,
                                     GLboolean normalized, GLsizei stride, 
                                     const GLvoid *pointer);
         void glVertexAttribIPointer (GLuint index, GLint size, GLenum type,
                                      GLsizei stride, const GLvoid *pointer);
         void glVertexAttribLPointer (GLuint index, GLint size, GLenum type,
                                      GLsizei stride, const GLvoid *pointer);
    
         if (no buffer is bound to GL_ARRAY_BUFFER and pointer != NULL) {
           generate GL_INVALID_OPERATION;
         }
         glVertexAttrib*Format (index, size, type, {normalized, }, 0);
         glVertexAttribBinding (index, index);
         if (stride != 0) {
           effectiveStride = stride;
         } else {
           compute effectiveStride based on size/type;
         }
         GL_VERTEX_ATTRIB_ARRAY_STRIDE[index] = stride;
         // GL_VERTEX_BINDING_STRIDE will be set to effectiveStride
         // by glBindVertexBuffer.
         glBindVertexBuffer (index, <buffer bound to GL_ARRAY_BUFFER>, 
                             (GLchar *)pointer - (GLchar *)NULL, effectiveStride);