当前位置:网站首页>初识OpenGL (4)链接着色器
初识OpenGL (4)链接着色器
2022-07-26 15:51:00 【thefist11】
1. 着色器程序
着色器程序对象(Shader Program Object)是多个着色器合并之后并最终链接完成的版本。如果要使用刚才编译的着色器我们必须把它们链接(Link)为一个着色器程序对象,然后在渲染对象的时候激活这个着色器程序。已激活着色器程序的着色器将在我们发送渲染调用的时候被使用。
当链接着色器至一个程序的时候,它会把每个着色器的输出链接到下个着色器的输入。当输出和输入不匹配的时候,你会得到一个连接错误。
step1. 创建着色器程序对象
glCreateProgram函数创建一个程序,并返回新创建程序对象的ID引用。
unsigned int shaderProgram;
shaderProgram = glCreateProgram();
step2. 把之前编译的着色器附加到程序对象上,然后用glLinkProgram链接它们
glAttachShader(shaderProgram, vertexShader);
glAttachShader(shaderProgram, fragmentShader);
glLinkProgram(shaderProgram);
step3. 检测链接着色器程序是否失败,并获取相应的日志。
与之前不同,我们不会调用glGetShaderiv和glGetShaderInfoLog
glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
if(!success) {
glGetProgramInfoLog(shaderProgram, 512, NULL, infoLog);
...
}
step4. 激活这个程序对象
调用glUseProgram函数,用刚创建的程序对象作为它的参数。
glUseProgram(shaderProgram);
在glUseProgram函数调用之后,每个着色器调用和渲染调用都会使用这个程序对象(也就是之前写的着色器)了。
step5. 删除着色器对象
glDeleteShader(vertexShader);
glDeleteShader(fragmentShader);
现在,我们已经把输入顶点数据发送给了GPU,并指示了GPU如何在顶点和片段着色器中处理它。就快要完成了,但还没结束,OpenGL还不知道它该如何解释内存中的顶点数据,以及它该如何将顶点数据链接到顶点着色器的属性上。下一步需要告诉OpenGL怎么做。
边栏推荐
- How to convert planning map into vector data with longitude and latitude geojson
- 泰山OFFICE技术讲座:WORD的缩放比例与显示略有差异
- Clojure 运行原理之编译器剖析
- API version control [eolink translation]
- [expdp export data] expdp exports a table with 23 rows of records and no lob field. It takes 48 minutes. Please help us have a look
- 剑指offer专项突击版第11天
- Specific practice cases of "card note taking method" in Siyuan
- LeetCode_ Prefix and_ Hash table_ Medium_ 525. Continuous array
- Google Earth engine - merra-2 m2t1nxaer: aerosol daily data set from 1980 to 2022
- TKE集群节点max-pod是如何配置的
猜你喜欢

Development and implementation of campus epidemic prevention and control management system based on SSM

提问征集丨快来向NLLB作者提问啦!(智源Live第24期)
![[expdp export data] expdp exports a table with 23 rows of records and no lob field. It takes 48 minutes. Please help us have a look](/img/ee/7bec8211dddc90e52c2bc0f56c8dd4.png)
[expdp export data] expdp exports a table with 23 rows of records and no lob field. It takes 48 minutes. Please help us have a look

2022 what is your sense of security? Volvo asked in the middle of the year

如何通过ETL调度工具 TASKCTL 使用作业插件类型调用 kettle作业?

反射、枚举以及lambda表达式

换把人体工学椅,缓解久坐写代码的老腰吧~

Question collection come and ask nllb authors! (Zhiyuan live issue 24)

Parker pump pv140r1k1t1pmmc

Bucher gear pump qx81-400r301
随机推荐
TKE集群节点max-pod是如何配置的
VS2019Debug模式太卡进不去断点
Google Earth engine - merra-2 m2t1nxlv: 1980 present global pressure, temperature, wind and other data sets
八叉树建立地图并实现路径规划导航
SAP ABAP Netweaver 容器化的一些前沿性研究工作分享
We were tossed all night by a Kong performance bug
Vs2019debug mode too laggy can't enter the breakpoint
parker泵PV140R1K1T1PMMC
基于SSM实现个性化健康饮食推荐系统
一文搞懂│XSS攻击、SQL注入、CSRF攻击、DDOS攻击、DNS劫持
Parker solenoid valve d1vw020dnypz5
理解卷积神经网络中的权值共享
中金财富证券安全吗 开户要多久
Jmeter快速上手之接口测试
白话详解决策树模型之使用信息熵构建决策树
Question collection come and ask nllb authors! (Zhiyuan live issue 24)
The solution to the display disorder of several events files in the tensorboard
线程和进程
十周岁生日快乐,Clojure
Encryption model