OpenGL Rendering Pipeline

OpenGL渲染管线

原文地址:http://www.songho.ca/opengl/gl_pipeline.html

        (一下内容在OpenGL红宝书中第一张1.5小节中有,但是还是感觉红宝书介绍的有点抽象,处于温习的目的,所以决定将国外网站的内容翻译与扩展,如有错误,敬请指正。)

         OpenGL Pipeline has a series of processing stages in order. Two graphical information, vertex-based data and pixel-based data, are processed through the pipeline, combined together then written into the frame buffer. Notice that OpenGL can send the processed data back to your application. (See the grey colour lines)

        OpenGL渲染管线按照特定的顺序对图形信息进行处理,这些图形信息可以分为两个部分:顶点信息(坐标、法向量等)和像素信息(图像、纹理等),图形信息最终被写入帧缓存中,存储在帧缓存中的数据(图像),可以被应用程序获得(用于保存结果,或作为应用程序的输入等,见下图中灰色虚线)。

OpenGL Rendering Pipeline_第1张图片

Display List(显示列表)

Display list is a group of OpenGL commands that have been stored (compiled) for later execution. All data, geometry (vertex) and pixel data, can be stored in a display list. It may improve performance since commands and data are cached in a display list. When OpenGL program runs on the network, you can reduce data transmission over the network by using display list. Since display lists are part of server state and reside on the server machine, the client machine needs to send commands and data only once to server's display list. (See more details in Display List.)

显示列表中存储的是一组OpenGL命令,用于几何图元(顶点坐标、法向量等)与像素信息都可以保持到显示列表中,

显示列表中存储的是一组稍后执行的OpenGL命令,所有的数据,包括几何图元(顶点坐标、法向量等)和像素信息都可以保持到显示列表中,因为命令和数据都存储在显示列表中(类似计算机的缓存)所以一定程度上可以提高程序的性能。(网络中的应用暂没翻译)

Vertex Operation(顶点操作)

Each vertex and normal coordinates are transformed by GL_MODELVIEW matrix (from object coordinates to eye coordinates). Also, if lighting is enabled, the lighting calculation per vertex is performed using the transformed vertex and normal data. This lighting calculation updates new color of the vertex.

每个顶点和法向量坐标均经过模型视图变换(从物体坐标变换到视图坐标系下);如果启用了光照,将根据变换后的顶点坐标和法向量信息,计算每个顶点的光照信息,计算得到的光照信息将用来更新顶点的颜色(通常是光照计算后的颜色 = 环境光 + 反射光 * 顶点颜色 + 聚焦光)。

Primitive Assembly(图元装配)

After vertex operation, the primitives (point, line, and polygon) are transformed once again by projection matrix then clipped by viewing volume clipping planes; from eye coordinates to clip coordinates. After that, perspective division by w occurs and viewport transform is applied in order to map 3D scene to window space coordinates. Last thing to do in Primitive Assembly is culling test if culling is enabled.

Pixel Transfer Operation(像素操作)

After the pixels from client's memory are unpacked(read), the data are performed scaling, bias, mapping and clamping. These operations are called Pixel Transfer Operation. The transferred data are either stored in texture memory or rasterized directly to fragments.

Texture Memory(纹理内存)

Texture images are loaded into texture memory to be applied onto geometric objects.

纹理图像被装载到纹理内存中,一边进行纹理映射。(纹理内存比较特殊,我曾经将700多兆的数据,加载到只有512兆显存的显卡上进行计算,没有任何问题,所以关于纹理内存的内部机制,目前还不了解。)

Raterization(光栅化)

Rasterization is the conversion of both geometric and pixel data into fragment. Fragments are a rectangular array containing color, depth, line width, point size and antialiasing calculations (GL_POINT_SMOOTH, GL_LINE_SMOOTH, GL_POLYGON_SMOOTH). If shading mode is GL_FILL, then the interior pixels (area) of polygon will be filled at this stage. Each fragment corresponds to a pixel in the frame buffer.

OpenGL Rendering Pipeline_第2张图片

光栅化就是把几何(顶点坐标等)和像素数据转换为片段(fragment)的过程,每个片段对应于帧缓冲区中的一个像素,该像素对应屏幕上一点的颜色和不透明度信息。片段是一个矩形数组,包含了颜色、深度、线宽、点的大小等信息(反锯齿计算等)。如果渲染模式被设置为GL_FILL,多边形内部的像素信息在这个阶段会被填充。

如上图中的三角形,输入三角形的三个顶点坐标以及其颜色,顶点操作会对三角形的顶点坐标以及法向量进行变换,颜色信息不需要经过变换,但光照计算会影响顶点的颜色信息,经过光栅化后,三角形被离散为一个个点,不在是三个坐标表示,而是由一系列的点组成,每个点存储了相应的颜色、深度和不透明度等信息。

 


Fragment Operation(片段操作)

It is the last process to convert fragments to pixels onto frame buffer. The first process in this stage is texel generation; A texture element is generated from texture memory and it is applied to the each fragment. Then fog calculations are applied. After that, there are several fragment tests follow in order; Scissor Test ⇒ Alpha Test ⇒ Stencil Test ⇒ Depth Test.
Finally, blending, dithering, logical operation and masking by bitmask are performed and actual pixel data are stored in frame buffer.

Feedback(反馈)

OpenGL can return most of current states and information throughglGet*() andglIsEnabled() commands. Further more, you can read a rectangular area of pixel data from frame buffer usingglReadPixels(), and get fully transformed vertex data usingglRenderMode(GL_FEEDBACK).glCopyPixels() does not return pixel data to the specified system memory, but copy them back to the another frame buffer, for example, from front buffer to back buffer.

 

 

你可能感兴趣的:(OpenGL Rendering Pipeline)