OpenGL Superbible 7 03 Following the Pipeline
2017-05-04 23:11
381 查看
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.
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);
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
(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); 4000 }
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学习 Following the Pipeline
- 笔记:OpenGL SuperBible - First Program
- An intro to modern OpenGL. Chapter 1: The Graphics Pipelinehttp://duriansoftware.com/joe/An-intro-to
- win7 上配置openGL开发环境(配套openGL 超级宝典Super Bible 6th)
- Opengl SuperBible 7th摘抄
- 笔记:OpenGL SuperBible - First Triangle
- The OpenGL Light Bible
- 笔记:OpenGL SuperBible - Shaders
- A trip through the Graphics Pipeline 2011_03
- OpenGL(R) SuperBible: Comprehensive Tutorial and Reference (4th Edition)
- Following the pipeline
- OpenGL Superbible 7 01 Introduction
- OpenGL super bible(5th) 学习笔记 -- 像素缓冲区对象(PBO)
- The OpenGL pipeline
- 一个大牛的系列文章:An intro to modern OpenGL. Chapter 1: The Graphics Pipeline
- opengl super bible 方块动画的改进代码
- OpenGL SUPERBIBLE Fifth Edition 学习笔记1
- OpenGL Superbible 7 02 Our First OpenGL Program
- The Graphics Pipeline and OpenGL
- OpenGL Super Bible 6th