惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tenable Blog
H
Heimdal Security Blog
K
Kaspersky official blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
S
Schneier on Security
G
GRAHAM CLULEY
U
Unit 42
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
C
CERT Recently Published Vulnerability Notes
Google DeepMind News
Google DeepMind News
罗磊的独立博客
Stack Overflow Blog
Stack Overflow Blog
阮一峰的网络日志
阮一峰的网络日志
Simon Willison's Weblog
Simon Willison's Weblog
C
Cisco Blogs
Cyberwarzone
Cyberwarzone
T
The Exploit Database - CXSecurity.com
Project Zero
Project Zero
Security Archives - TechRepublic
Security Archives - TechRepublic
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园 - 司徒正美
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
V
Visual Studio Blog
博客园 - Franky
Engineering at Meta
Engineering at Meta
WordPress大学
WordPress大学
Jina AI
Jina AI
P
Proofpoint News Feed
P
Proofpoint News Feed
有赞技术团队
有赞技术团队
L
LINUX DO - 最新话题
宝玉的分享
宝玉的分享
N
News and Events Feed by Topic
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
博客园 - 聂微东
T
The Blog of Author Tim Ferriss
Spread Privacy
Spread Privacy
Application and Cybersecurity Blog
Application and Cybersecurity Blog
IT之家
IT之家
S
Security Affairs
博客园 - 叶小钗
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
小众软件
小众软件
N
News | PayPal Newsroom
Cloudbric
Cloudbric
AWS News Blog
AWS News Blog
W
WeLiveSecurity
The Last Watchdog
The Last Watchdog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
NISL@THU
NISL@THU

博客园 - 游戏行者

ubuntu 24 之后,登录时出现server refused our key,不认原来的ssh key的解决方法 zoho企业邮件管理页,如何登录 thunderBird如何选择配置文件 鼠标对码 PVE更换主板后,如何修改绑定网卡 关于ubuntu和debian的配置,以及vultr的防火墙设置 - 游戏行者 entity framework core使用sqlServer localDB指定文件路径 windows 10如何更改字体大小和开启防蓝光 ubuntu挂载ntfs分区(读写模式) vmware ubuntu虚拟机设置共享文件夹之后,虚拟机重启找不到的问题 Esxi(vSphere) 安装经验 瑞芯微系列主板刷机方法 f#如何设定main函数 探索texture对象的生命周期 opengl管理texture参数的函数总结 opengl 如何从指定位置画三角形,理解opengl的指针 vk.xml生成之坑 写代码的技巧 vulkan的QueueFamilyProperties
Opengl vertex shader中, layout location最多允许几个,或者说,顶点可以有多少个属性
游戏行者 · 2020-08-17 · via 博客园 - 游戏行者

先看一段vertex shader

#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aColor;
layout (location = 2) in vec2 aTexCoord;

out vec3 ourColor;
out vec2 TexCoord;

void main()
{
gl_Position = vec4(aPos, 1.0);
ourColor = aColor;
TexCoord = vec2(aTexCoord.x, aTexCoord.y);
}

当我们在调用shader之前,会声明vertex的attribPointer,实际上就是告诉显卡,这个vertex的内存布局

location=xxx,这个东东叫vertex attribute index

GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 8 * sizeof(float), 0);
GL.EnableVertexAttribArray(0);
GL.VertexAttribPointer(1, 3, VertexAttribPointerType.Float, false, 8 * sizeof(float), 3 * sizeof(float));
GL.EnableVertexAttribArray(1);
GL.VertexAttribPointer(2, 2, VertexAttribPointerType.Float, false, 8 * sizeof(float), 6 * sizeof(float));
GL.EnableVertexAttribArray(2);

三次调用GL.VertexAttribPointer的第一个参数,0,1,2,就是location

那么,能不能不按照递增顺序写呢?比如,第一个改成5,怎么样?

答案是,可以。

如果shader里这样写:(省略后半部分shader)

#version 330 core
layout (location = 5) in vec3 aPos;
layout (location = 1) in vec3 aColor;
layout (location = 2) in vec2 aTexCoord;

那么描述aPos的代码,就应该这样改:

GL.VertexAttribPointer(5, 3, VertexAttribPointerType.Float, false, 8 * sizeof(float), 0);
GL.EnableVertexAttribArray(5);

把vertex attribute index,都修改为5.

那么,最大的vertex attribute index是多少呢?可以通过一个函数来查询:

int maxVertexAttrib = GL.GetInteger(GetPName.MaxVertexAttribs);

我的显卡是gt 1030,这个值是16。

看官方文档,描述如下:

GL_MAX_VERTEX_ATTRIBS

data returns one value, the maximum number of 4-component generic vertex attributes accessible to a vertex shader. The value must be at least 16. See glVertexAttrib.

官方文档规定的最小值就是16。显卡也就只实现了16个。实际上也够用了,平时也就是位置法线纹理切线负切线。

也就是说,一般情况下,顶点可以有最多16个属性。