Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/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-需要一个简单的概念说明_Opengl - Fatal编程技术网

OpenGL-需要一个简单的概念说明

OpenGL-需要一个简单的概念说明,opengl,Opengl,我是OpenGL新手。 我了解如何创建顶点和片段着色器,以及如何创建顶点数组并将它们放置在缓冲区中,但如何将两者链接? 意思-当我运行程序时,它如何知道当前活动缓冲区上的顶点数组应该“馈送”到顶点着色器 是否只需使用glVertexAttribPointer 谢谢 实际上没有“当前活动缓冲区”这样的东西。(当然有,但它仅在VAO规范与非直接状态访问API时相关。) 顶点数组对象(VAO)将指针(通过glvertexattributepointer设置)保存到内存缓冲区内的数据中。这些缓冲区的绑定

我是OpenGL新手。 我了解如何创建顶点和片段着色器,以及如何创建顶点数组并将它们放置在缓冲区中,但如何将两者链接? 意思-当我运行程序时,它如何知道当前活动缓冲区上的顶点数组应该“馈送”到顶点着色器

是否只需使用
glVertexAttribPointer


谢谢

实际上没有“当前活动缓冲区”这样的东西。(当然有,但它仅在VAO规范与非直接状态访问API时相关。)

顶点数组对象(VAO)将指针(通过
glvertexattributepointer
设置)保存到内存缓冲区内的数据中。这些缓冲区的绑定是VAO状态的一部分。绑定VAO时,随后的
glDraw*
命令将顶点从绑定到当前VAO的缓冲区转移到管道

为便于理解,以下是VAO的大致含义,使用相关的OpenGL 4.5直接状态访问函数名设置该状态:

struct VertexArrayObject
{
    // VertexArrayElementBuffer
    uint element_buffer;

    struct Binding {
        // VertexArrayVertexBuffers
        uint buffer;
        intptr offset;
        sizei stride;

        // VertexArrayBindingDivisor
        uint divisor;
    } bindings[];

    struct Attrib {
        // VertexArrayAttribBinding
        uint binding; // This is an index into bindings[]

        // EnableVertexArrayAttrib
        bool enabled;

        // VertexArrayAttrib*Format
        int size;
        enum type;
        boolean normalized;
        boolean integer;
        boolean long;
        uint relativeoffset;
    } attribs[];
};
调用
glvertexattributepointer
时,它在当前绑定的VAO上基本上执行以下操作:

vao.attribs[index].binding = index;
vao.attribs[index].size = size;
vao.attribs[index].type = type;
vao.attribs[index].normalized = normalized;
vao.attribs[index].relativeoffset = 0;
vao.bindings[index].buffer = current ARRAY_BUFFER;
vao.bindings[index].offset = pointer;
vao.bindings[index].stride = stride; // if stride == 0 computes based on size and type

好的,只是为了确保我理解-使用VAO(不推荐)的替代方法是每次您必须告诉GPU如何处理缓冲区中的数据时“重新声明”
glvertexAttributePointer
?错误是什么?必须在OpenGL 3之后使用VAO将原语传输到GPU。此外,在
glVertexAttributePointer
的第一个参数中,我写入了对着色器变量的引用,对吗?这就是程序知道如何将顶点发送到着色器的原因吗?是的,这是属性索引,您可以使用着色器中的
布局(location=n)
说明符指定它。好的,谢谢!最后一个问题,我发誓!哈哈,我很确定答案是“是”,但我想再核实一下。所以VAO的整个想法就是绑定一个,然后创建一个缓冲区并绑定一些数据,
glvertexattributepointer
,等等。。。然后绑定另一个VAO,用其他数据和不同的指针创建不同的缓冲区,然后我就可以在VAO之间切换,后续的draw调用将使用当前绑定的VAO?