我歸納一下就是:準(zhǔn)備頂點(diǎn)和圖元數(shù)據(jù)----》傳到D3D渲染管線----》處理頂點(diǎn)數(shù)據(jù)(固定、shader)----》幾何處理(裁剪、背面剔除、光柵化)----》像素處理(紋理采樣)----》著色
牢記這個:
Direct3D Graphics Pipeline
The graphics pipeline provides the horsepower to efficiently process and render Direct3D scenes to a display, taking advantage of available hardware. This figure conceptually illustrates the building blocks of the pipeline:
\Documentation\DirectX9\directx_sdk.chm::/BlockDiag_Graphics.gif)
Pipeline Component |
Description |
Related Topics |
Vertex Data |
Untransformed model vertices are stored in vertex memory buffers. |
Vertex Buffers (Direct3D 9), IDirect3DVertexBuffer9 |
Primitive Data |
Geometric primitives, including points, lines, triangles, and polygons, are referenced in the vertex data with index buffers. |
Index Buffers (Direct3D 9), IDirect3DIndexBuffer9, Primitives, Higher-Order Primitives (Direct3D 9) |
Tessellation |
The tesselator unit converts higher-order primitives, displacement maps, and mesh patches to vertex locations and stores those locations in vertex buffers. |
Tessellation (Direct3D 9) |
Vertex Processing |
Direct3D transformations are applied to vertices stored in the vertex buffer. |
Vertex Pipeline (Direct3D 9) |
Geometry Processing |
Clipping, back face culling, attribute evaluation, and rasterization are applied to the transformed vertices. |
Pixel Pipeline (Direct3D 9) |
Textured Surface |
Texture coordinates for Direct3D surfaces are supplied to Direct3D through the IDirect3DTexture9 interface. |
Direct3D Textures (Direct3D 9), IDirect3DTexture9 |
Texture Sampler |
Texture level-of-detail filtering is applied to input texture values. |
Direct3D Textures (Direct3D 9) |
Pixel Processing |
Pixel shader operations use geometry data to modify input vertex and texture data, yielding output pixel color values. |
Pixel Pipeline (Direct3D 9) |
Pixel Rendering |
Final rendering processes modify pixel color values with alpha, depth, or stencil testing, or by applying alpha blending or fog. All resulting pixel values are presented to the output display. |
Pixel Pipeline (Direct3D 9) |
Direct3D System Integration
This figure shows the relationships between a Window application, Direct3D,GDI, and the hardware:
\Documentation\DirectX9\directx_sdk.chm::/d3dsysint.gif)
Direct3D exposes a device-independent interface to an application. Direct3D applications can exist alongsideGDI applications, and both have access to the computer's graphics hardware through the device driver for the graphics card. UnlikeGDI, Direct3D can take advantage of hardware features by creating a hal device.
A hal device provides hardware acceleration to graphics pipeline functions, based upon the feature set supported by the graphics card. Direct3D methods are provided to retrieve device display capabilities at run time. (See IDirect3D9::GetDeviceCaps and IDirect3DDevice9::GetDeviceCaps.) If a capability is not provided by the hardware, the hal does not report it as a hardware capability.
For more information about hal and reference devices supported by Direct3D, see Device Types (Direct3D 9).
*.首先Device的使用者要準(zhǔn)備好頂點(diǎn)數(shù)據(jù),也就是一個頂點(diǎn)的數(shù)組,稱為A
*.然后這個數(shù)組A被傳入device的渲染管線
*.device內(nèi)部依次對每個頂點(diǎn)進(jìn)行處理,有兩種模式,固定管線和shader模式,所謂固定管線就是device內(nèi)部實(shí)現(xiàn)的一個固定的程 序,用戶只能通過設(shè)定各種參數(shù)(一些RenderState)來控制它,當(dāng)然這不夠靈活,所以有了shader模式,也就是說,用戶需要寫一個程序片段 (所謂vertex shader),傳給device,然后device使用這個片段對每個頂點(diǎn)進(jìn)行處理.這個程序片段是在顯卡上執(zhí)行的.
*.傳入的頂點(diǎn)數(shù)組A的每一個元素被轉(zhuǎn)換后,存儲到另一個數(shù)組B中.數(shù)組B中的每個元素必須至少包含一個透視空間的位置,用來做裁剪.
*.數(shù)組B被傳入到device的下一個計算階段,在這個階段里,數(shù)組B中的(被轉(zhuǎn)換過的)頂點(diǎn)被組織成一個個三角形,然后對這些三角形進(jìn)行裁 剪(利用頂點(diǎn)數(shù)據(jù)里包含的那一個透視空間的位置),背面剔除(注意背面剔除和頂點(diǎn)的法線是沒關(guān)系的),最后剩下的三角形被保存到一個數(shù)組C中.(注意在這 個階段里頂點(diǎn)數(shù)組變成了三角形數(shù)組)
*.數(shù)組C被傳入到下一個計算階段,光柵化,對于數(shù)組C中每一個三角形,首先把它們從透視空間映射到屏幕空間,然后找出它們在屏幕上覆蓋的像素 (一個三角形覆蓋的像素的數(shù)量有可能是很多的),對于每一個像素,根據(jù)它在三角形中的位置,通過三角形的頂點(diǎn)進(jìn)行線性插值,計算出一個像素數(shù)據(jù)(注意像素 數(shù)據(jù)是通過三角形的頂點(diǎn)數(shù)據(jù)插值而來,所以它們的數(shù)據(jù)類型是一致的),所有三角形算出來的像素數(shù)據(jù)最后被存儲到一個數(shù)組D中.(在這個階段里,三角形的數(shù) 組變成了像素數(shù)據(jù)數(shù)組)
*.數(shù)組D被傳入到下一個計算階段,在這個階段里,device會對這些像素做一些初步的過濾,主要是進(jìn)行stencil test(根據(jù)stencil
buffer上的值)和z-test(根據(jù)這個像素的Z值和z-buffer上的值進(jìn)行比較),根據(jù)測試結(jié)果會對stencil buffer進(jìn)行一些修改(使用一組render state來控制這個過程),通過這些test的像素被存儲到數(shù)組E.
*.數(shù)組E被傳入到下一個計算階段,在這個階段里,device對每個像素數(shù)據(jù)進(jìn)行處理,這個階段也有兩種模式,固定管線和shader模式, 與頂點(diǎn)處理階段類似,用戶也可以寫一個程序片段,來對每一個像素數(shù)據(jù)進(jìn)行處理,稱為pixel shader.像素數(shù)據(jù)可能包含各種類型的數(shù)據(jù),但經(jīng)過這一階段的處理后,輸出是很簡單的,一般就是一個顏色值和一個alpha值(透明度),也可以輸出 一個Z值,不過好像不常用.在pixel shader里還可以使用專門的指令來放棄某一個像素的后續(xù)處理.所有的像素數(shù)據(jù)被處理后,結(jié)果存在一個數(shù)組F中.
*.數(shù)組F進(jìn)入下一個階段,在這一個階段里,進(jìn)行alpha test(根據(jù)像素的alpha 值),alpha test是最后一個test了,通過了alpha test的像素可以保證繪制到屏幕上去,通過test的像素會把它們的z值更新到z-buffer中去(具體由一組render state控制),通過test的像素被存入數(shù)組G
*.數(shù)組G進(jìn)入下一個階段,在這個階段里,主要是把數(shù)組G里的像素和屏幕上已有的像素進(jìn)行混合,具體混合的方式有多種多樣,由一系列render state進(jìn)行控制.混合以后的像素就被"畫"到屏幕上了