简体   繁体   English

Open GLES 3.0中的布局限定符

[英]Layout Qualifiers in Open GLES 3.0

I'm experimenting with using the Open GLES 3.0 API (with the accompanying core 330 GLSL shader language) in a Swift Playground. 我正在尝试在Swift Playground中使用Open GLES 3.0 API(及其随附的核心330 GLSL着色器语言)。 I have the following declaration at the top of my vertex shader: 我的顶点着色器顶部有以下声明:

layout(location = 0) in vec4 a_Position;

My understanding of the layout qualifier is that is specifies where a_Position is in the Vertex Buffer Object's attribute indices. 我对布局限定符的理解是,它指定a_Position在顶点缓冲区对象的属性索引中的位置。 (loose as my understanding of VAO's is..). (因为我对VAO的理解而变得宽松。)

But my triangle doesn't render unless I also include the following code: 但是除非我也包含以下代码,否则三角形不会渲染:

glEnableVertexAttribArray(0)
glVertexAttribPointer(
        0,
        3,
        GLenum(GL_FLOAT),
        GLboolean(GL_FALSE),
        GLsizei(MemoryLayout<Vertex>.size),
        BUFFER_OFFSET(0))

But my understanding of the layout qualifier would suggest to me that this is not necessary as the it is already specifying where a_Position lies in the vertex attribute array. 但是我对布局限定符的理解会提示我这不是必需的,因为它已经指定了a_Position在顶点属性数组中的位置。 (at index 0). (在索引0处)。

So either I'm missing some minor detail, or my understanding of how VAO data is accessed in shaders on the GPU is flawed. 因此,或者我缺少一些细微的细节,或者我对如何在GPU的着色器中访问VAO数据的理解存在缺陷。 It is probably both. 可能两者都有。 So why isn't the shader declaration with the layout qualifier sufficient to get my vertex positions into a_Position ? 那么,为什么带有布局限定符的着色器声明不足以将顶点位置放入a_Position

layout(location=0) means that you don't have to call glGetVertexAttribLocation to get the attribute index for glEnableVertexAttribArray and glVertexAttribPointer calls. layout(location=0)意味着您不必调用glGetVertexAttribLocation即可获取glEnableVertexAttribArrayglVertexAttribPointer调用的属性索引。 Those calls are still necessary. 这些电话仍然是必要的。

Shader declaration is not sufficient because you still need to provide the information that is in the parameters of glVertexAttribPointer , like normalisation, data type etc. 着色器声明是不够的,因为您仍然需要提供glVertexAttribPointer参数中的信息,例如规范化,数据类型等。

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

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