OpenGL Superbible 7 03 Following the Pipeline
来源:互联网 发布:淘宝3c认证编号怎么弄 编辑:程序博客网 时间:2024/06/05 13:25
01 学习目标
(1) What each of the stages in the OpenGL pipeline does.
(2) How to connect your shaders to the fixed-function pipeline stages.
(3) How to create a program that uses very stage of graphics pipeline.
In this chapter, we will walk all the way along the OpenGL pipeline from start to finish, providing insight into each of the stages, which include fixed-function blocks and programmable shader blocks.
This chapter introduces every part of the pipeline, hooks them up to one another, and provides an example shader for each stage.
02 Passing Data to the Vertex Shader
The vertex shader is the first programmable stage in the OpenGL pipeline and has the distinction(区别) of being the only mandatory(强制的) stage in the graphics pipeline.
However, before the vertex shader runs, a fixed-function stage known as vertex fetching, or sometimes vertex pulling, is run.
In GLSL, the mechanism fir getting data in and out of shaders is to declare global variables with the in and out storage qualifiers.
At the start of the OpenGL pipeline, we use the in keyword to bring inputs into the vertex shader.
03 实现三角形的椭圆形运动
Vertex attributes are how vertex data is introduced into the OpenGL pipeline. To declare a vertex attribute, you declare a variable in the vertex shader using the in storage qualifier.
static const char * vs_source[] = { "#version 450 core \n" " \n" "// 'offset' is an input vertex attribute \n" "layout (location = 0) in vec4 offset; \n" "void main(void) \n" "{ \n" " const vec4 vertices[] = vec4[](vec4( 0.25, -0.25, 0.5, 1.0), \n" " vec4(-0.25, -0.25, 0.5, 1.0), \n" " vec4( 0.25, 0.25, 0.5, 1.0)); \n" " \n" " gl_Position = vertices[gl_VertexID] + offset; \n" "} \n" };
We can tell this stage what to fill the variable with by using one of the many variants of the vertex attribute functions, glVertexAttrib*(). The prototype for glVertexAttrib4fv(), which we use in this example, is
void glVertexAttrib4fv(GLuint index, const GLfloat *v);
virtual void render(double currentTime) { static const GLfloat green[] = { 0.0f, 0.25f, 0.0f, 1.0f }; glClearBufferfv(GL_COLOR, 0, green); glUseProgram(program); GLfloat attrib[] = {(float) sin(currentTime) * 0.5f, (float) cos(currentTime) * 0.6f, 0.0f, 0.0f }; // Update the value of input attribute 0 glVertexAttrib4fv(0, attrib); glDrawArrays(GL_TRIANGLES, 0, 3); }
04 数据的内部传输
Anything you write to an output variable in one shader is sent to a similar named variable declared with the in keyword in the subsequent stage.
interface blocks
in out 使用
05 碎片化 Tessellation
Tessellation is the process of breaking a high-order primitive (which is known as a patch in OpenGL) into many smaller, simpler primitives such triangles for rendering. OpenGL includes a fixed-function, configurable tessellation engine that is able to break up quadrilaterals, triangles, and lines into a potentially large number of smaller points, lines, or triangles that can be directly consumed by the normal rasterization hardware further down the pipeline. Logically, the tessellation phase sits directly after the vertex shading stage in the OpenGL pipeline and is made up of three part: the tessellation control shader, the fixed-function tessellation engine, and the tessellation evaluation shader.
06
- OpenGL Superbible 7 03 Following the Pipeline
- Following the pipeline
- OpenGL Superbible 7 01 Introduction
- Opengl SuperBible 7th摘抄
- OpenGL SuperBible
- The OpenGL Pipeline
- The OpenGL pipeline
- The OpenGL Pipeline
- openGL SuperBible 7th 初编译
- OpenGL SuperBible 7th源码编译记录
- The Graphics Pipeline and OpenGL
- OpenGL Superbible 7 02 Our First OpenGL Program
- 笔记:OpenGL SuperBible - overview
- 笔记:OpenGL SuperBible - Intro
- 笔记:OpenGL SuperBible - Shaders
- 笔记:OpenGL SuperBible - Tessellation
- OpenGL SuperBible阅读笔记
- 笔记:OpenGL SuperBible - First Program
- Quartz.Net的使用
- 软件测试之测试类型
- RSA算法----加密解密
- AndroidManifest 合并出错 tools:replace="android:allowBackup"
- apache 配置入口目录
- OpenGL Superbible 7 03 Following the Pipeline
- 第二册第十单元补充
- 重新回归到博客中来
- 递归及生成器的示例
- HttpDNS 服务详解
- hdu 2045 不容易系列之(3)—— LELE的RPG难题
- C语言结构体字节对齐
- 淘宝:TLog的设计
- 叶片