博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Vertex shader Attributes
阅读量:4659 次
发布时间:2019-06-09

本文共 2212 字,大约阅读时间需要 7 分钟。

       在VertexShader 中,和顶点相关的数据如Position、Normal、Color等等均称为Attribute,为了给VertexShader传入这些数据,必须首先知道相关Attribute在Shader中位置。在layout尚未出现之间有两种设定Attribute 位置的方法。 方法一OpenGL允许我们显示的设定Attribute的位置,方法二OpenGL帮我们设定好Attribute的位置,然后我们在程序中查询Attribute的位置。方法一要特别注意:设定Attribute的位置必须在Link Program 之前,如果在Link之后才设定Attribute的位置,需要重新Link program.

        对于下面的VertexShader:

1 #version 3302  3 in vec3 position;4 in vec3 normal;5 in vec2 texCoord;6 ...

 

        设定Attribute位置的函数glBindAttribLocation如下:

void glBindAttribLocation( GLuint program, GLuint index, const GLchar *name);Params:program: the program object handleindex: the index to bind the attribute toname: the name of the vertex attribute

 对于上面shader中的

 

 

     

 

 

Mismatched Attributes and Programs

You may be wondering what happens if there is a mis-match between the attributes provided by a VAO and the vertex shader inputs. For example, we could use the position-only vertex shader with a mesh that provides attributes 0 and 1, with 0 being the position and 1 being the color.

OpenGL is actually very lenient about this sort of thing. It also goes through some effort to fully define what information the vertex shader gets in the event of a mismatch.

A VAO can provide attributes that a vertex shader does not use without penalty. Well, there may be a performance penalty for reading unused information, but it will still render correctly.

If a vertex shader takes attributes that the VAO does not provide, then the value the vertex shader gets will be a vector of (0, 0, 0, 1). If the vertex shader input vector has fewer than 4 elements, then it fills them in in that order. A vec3 input that is not provided by the VAO will be (0, 0, 0).

Speaking of which, if a VAO provides more components of an attribute vector than the vertex shader expects (the VAO provides 4 elements, but the vertex shader input is a vec2), then the vertex shader input will be filled in as much as it can be. If the reverse is true, if the VAO does not provide enough components of the vector, then the unfilled values are always filled in from the (0, 0, 0, 1) vector.

 

reference:

[1] http://www.arcsynthesis.org/gltut/Positioning/Tut07%20Shared%20Uniforms.html

[2]

转载于:https://www.cnblogs.com/graph/archive/2012/12/07/2778931.html

你可能感兴趣的文章
笔记本安装SSD固态硬盘详细的优化设置
查看>>
批处理语法介绍
查看>>
FFmpeg 基础库(三)模块组成
查看>>
Linq 查询 与方法调用
查看>>
iOS开源项目(旧)
查看>>
winform的datagridview控件滚动更新数据
查看>>
java中Object类 源代码详解
查看>>
开源控Meteor的个人资料
查看>>
kafka在zookeeper中的存储结构
查看>>
linux上FTP服务器搭建
查看>>
.net 使用AgsXMPP与openfire连接,实现跨平台信息流通。
查看>>
DP动态规划【专辑@AbandonZHANG】
查看>>
Android TextureView简易教程
查看>>
fatal: the remote end hung up unexpectedly
查看>>
Delphi-操作剪贴板
查看>>
hdu 1029
查看>>
Docker 容器的网络连接 & 容器互联
查看>>
吾爱专题脱壳练习----压缩壳练习之三
查看>>
LeetCode -- Palindrome Linked List
查看>>
栈应用——逆波兰式表达式的值
查看>>