青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

天行健 君子當自強而不息

初始化Direct3D(1)

1.1 Direct3D概述

Direct3D是一種低層圖形API,它能讓我們利用3D硬件加速來渲染3D世界。我們可以把Direct3D看作是應用程序和圖形設備之間的中介。例如通知圖形設備清空屏幕,應用程序將調用Direct3D的IDirect3DDevice9::Clear方法。圖1.1顯示了應用程序、Direct3D和圖形設備之間的關系。

圖1.1中Direct3D所表示的是Direct3D中已定義的,供程序員使用的Direct3D接口和函數的集合。這些接口和函數代表了當前版本的Direct3D所支持的全部特性。注意:僅僅因為Direct3D支持某種特性,并不意味著你所使用的圖形硬件(顯卡)也能支持它。

如圖1.1所示,在Direct3D和圖形設備之間有一層中介——叫做硬件抽象層(HAL,Hardware Abstraction Layer)。Direct3D不能直接作用于圖形設備,因為現在市面上的顯卡種類實在是太多了并且每種顯卡都有不同的性能和處理事件的方式。例如,兩種不同的顯卡實現清屏的方式也可能是不同的。因此,Direct3D要求設備制造商實現HAL。HAL是一組指示設備執行某種操作的特殊設備代碼的集合。用這種方法,Direct3D避免了必須去了解某個設備的特殊細節,使它能夠獨立于硬件設備。

設備制造商在HAL中實現他們的產品所支持的所有特性。HAL將不會實現那些Direct3D支持但硬件產品不支持的特性。調用一個HAL中沒有實現的Direct3D的函數將會出錯,除非它是頂點處理操作,因為這個功能可以由軟件模擬來實現。因此當使用某些僅由市面上少數顯卡所支持的高級特性時,必須檢測一下設備是否支持。

 

1.1.1 REF設備

你也許想把一些你的設備不支持的Direct3D函數寫入程序。為了達到這個目的,Direct3D提供了REF設備,它用軟件模擬了所有的Direct3D API。這允許你寫并測試那些你的顯卡不支持的Direct3D特性的代碼。懂得REF設備僅僅用于開發階段,這是很重要的。它只會和DirectX SDK一起被裝載,而不會發布給最終用戶。 另外,REF設備實在是太慢了,除了測試以外它沒有任何利用價值。

 

1.1.2 D3DDEVTYPE

在代碼中,我們用D3DDEVTYPE_HAL來定義HAL設備,它是D3DDEVTYPE枚舉類型的一個成員。同樣的,REF設備則由D3DDEVTYPE_REF來定義,它也屬于D3DDEVTYPE枚舉類型。記住這些類型很重要,因為在創建設備的時候我們需要指定我們將要使用的類型。

Defines device types.

typedef enum D3DDEVTYPE
{
D3DDEVTYPE_HAL = 1,
D3DDEVTYPE_NULLREF = 4,
D3DDEVTYPE_REF = 2,
D3DDEVTYPE_SW = 3,
D3DDEVTYPE_FORCE_DWORD = 0xffffffff,
} D3DDEVTYPE, *LPD3DDEVTYPE;

Constants

D3DDEVTYPE_HAL
Hardware rasterization. Shading is done with software, hardware, or mixed transform and lighting.
D3DDEVTYPE_NULLREF
Initialize Direct3D on a computer that has neither hardware nor reference rasterization available, and enable resources for 3D content creation. See Remarks.
D3DDEVTYPE_REF
Direct3D features are implemented in software; however, the reference rasterizer does make use of special CPU instructions whenever it can.
D3DDEVTYPE_SW
A pluggable software device that has been registered with IDirect3D9::RegisterSoftwareDevice.
D3DDEVTYPE_FORCE_DWORD
Forces this enumeration to compile to 32 bits in size. Without this value, some compilers would allow this enumeration to compile to a size other than 32 bits. This value is not used.

Remarks

All methods of the IDirect3D9 interface that take a D3DDEVTYPE device type will fail if D3DDEVTYPE_NULLREF is specified. To use these methods, substitute D3DDEVTYPE_REF in the method call.

A D3DDEVTYPE_REF device should be created in D3DPOOL_SCRATCH memory, unless vertex and index buffers are required. To support vertex and index buffers, create the device in D3DPOOL_SYSTEMMEM memory.

If D3dref9.dll is installed, Direct3D will use the reference rasterizer to create a D3DDEVTYPE_REF device type, even if D3DDEVTYPE_NULLREF is specified. If D3dref9.dll is not available and D3DDEVTYPE_NULLREF is specified, Direct3D will neither render nor present the scene.

1.2 COM

組件對象模型(COM, Component Object Model)是一種能使DirectX獨立于編程語言和具有向下兼容性的技術。我們通常把COM對象作為一個接口,你可以把它當作達到某種目的的C++類來使用它。當使用C++寫DirectX程序的時候,COM的大部分細節對我們來說是透明。但是有一件事,我們必須知道,那就是我們通過某個特殊的COM接口的函數或指針獲得了另一個COM接口指針,而不是通過C++的新關鍵字來創建它。當我們使用完某個接口后,調用它的Release方法比直接Delete它更好。COM對象具有它們自己的內存管理。

對COM來說還有很多細節可以了解,但是掌握這些細節對于我們有效的使用DirectX不是必須的。

注意:COM接口都具有前綴大寫字母“I”,例如表示一個表面的COM接口叫做IDirect3DSurface9。

 

1.3 一些準備工作

Direct3D的初始化過程要求我們對圖形學基礎知識和Direct3D類型有一定了解。這里將介紹這些知識和類型,以確保以后能把焦點集中在討論Direct3D的初始化上。

1.3.1 表面

表面是一個像素點陣,在Direct3D中主要用來存儲2D圖形數據。圖1.2指明了表面的一些成分。由圖可以看出表面數據就像一個矩陣,像素數據實際上存儲在線性數組里面。

 

表面的Width和Height是按像素計算的。Pitch以字節為單位。而且Pitch有可能比Width大且依賴于低層硬件,所以不能單純的認為Pitch = Width * sizeof (pixelFormat)。

在代碼中,我們可以使用IDirect3DSurface9接口來描述表面。這個接口提供若干方法來直接讀寫表面數據并且還有一個方法用來返回表面息。IDirect3DSurface9中最重要的方法是:

l         LockRect——使用這個方法,我們將獲得一個指向表面內存的指針,然后,通過一系列指針運算,我們可以對表面上任一個像素點進行讀、寫操作。

 

Locks a rectangle on a surface.

HRESULT LockRect(
D3DLOCKED_RECT * pLockedRect,
CONST RECT * pRect,
DWORD Flags
);

Parameters

pLockedRect
[out] Pointer to a D3DLOCKED_RECT structure that describes the locked region.
pRect
[in] Pointer to a rectangle to lock. Specified by a pointer to a RECT structure. Specifying NULL for this parameter expands the dirty region to cover the entire surface.
Flags
[in] Combination of zero or more locking flags that describe the type of lock to perform. For this method, the valid flags are:
  • D3DLOCK_DISCARD
  • D3DLOCK_DONOTWAIT
  • D3DLOCK_NO_DIRTY_UPDATE
  • D3DLOCK_NOSYSLOCK
  • D3DLOCK_READONLY
You may not specify a subrect when using D3DLOCK_DISCARD. For a description of the flags, see D3DLOCK.

Return Values

If the method succeeds, the return value is D3D_OK.

If the method fails, the return value can be D3DERR_INVALIDCALL or D3DERR_WASSTILLDRAWING.

Remarks

If the D3DLOCK_DONOTWAIT flag is specified and the driver cannot lock the surface immediately, IDirect3DSurface9::LockRect will return D3DERR_WASSTILLDRAWING so that an application can use the CPU cycles while waiting for the driver to lock the surface.

The only lockable format for a depth-stencil surface is D3DFMT_D16_LOCKABLE. See D3DFORMAT.

For performance reasons, dirty regions are recorded only for level zero of a texture. Dirty regions are automatically recorded when IDirect3DSurface9::LockRect is called without D3DLOCK_NO_DIRTY_UPDATE or D3DLOCK_READONLY. See IDirect3DDevice9::UpdateTexture for more information.

A multisample back buffer cannot be locked.

This method cannot retrieve data from a surface that is is contained by a texture resource created with D3DUSAGE_RENDERTARGET because such a texture must be assigned to D3DPOOL_DEFAULT memory and is therefore not lockable. In this case, use instead IDirect3DDevice9::GetRenderTargetData to copy texture data from device memory to system memory.

 

l         UnlockRect——當你調用了LockRect和完成了對表面內存的訪問后,你必須調用這個方法給表面解鎖。

 

Unlocks a rectangle on a surface.

HRESULT UnlockRect();

Parameters

None.

Return Values

If the method succeeds, the return value is D3D_OK. If the method fails, the return value can be D3DERR_INVALIDCALL.

 

l         GetDesc——這個方法將通過填充D3DSURFACE_DESC結構來返回表面的描述信息。

 

D3DSURFACE_DESC

Describes a surface.

typedef struct D3DSURFACE_DESC {
D3DFORMAT Format;
D3DRESOURCETYPE Type;
DWORD Usage;
D3DPOOL Pool;
D3DMULTISAMPLE_TYPE MultiSampleType;
DWORD MultiSampleQuality;
UINT Width;
UINT Height;
} D3DSURFACE_DESC, *LPD3DSURFACE_DESC;

Members

Format
Member of the D3DFORMAT enumerated type, describing the surface format.
Type
Member of the D3DRESOURCETYPE enumerated type, identifying this resource as a surface.
Usage
Either the D3DUSAGE_DEPTHSTENCIL or D3DUSAGE_RENDERTARGET values. For more information, see D3DUSAGE.
Pool
Member of the D3DPOOL enumerated type, specifying the class of memory allocated for this surface.
MultiSampleType
Member of the D3DMULTISAMPLE_TYPE enumerated type, specifying the levels of full-scene multisampling supported by the surface.
MultiSampleQuality
Quality level. The valid range is between zero and one less than the level returned by pQualityLevels used by IDirect3D9::CheckDeviceMultiSampleType. Passing a larger value returns the error, D3DERR_INVALIDCALL. The MultisampleQuality values of paired render targets, depth stencil surfaces and the MultiSample type must all match.
Width
Width of the surface, in pixels.
Height
Height of the surface, in pixels.

Retrieves a description of the surface.

HRESULT GetDesc(
D3DSURFACE_DESC * pDesc
);

Parameters

pDesc
[out] Pointer to a D3DSURFACE_DESC structure, describing the surface.

Return Values

If the method succeeds, the return value is D3D_OK.

D3DERR_INVALIDCALL is returned if the argument is invalid.

 

最初鎖定表面和改寫每一像素看來稍微有點迷茫。下面的代碼表示鎖定表面并將每一像素染成紅色:

// Assume _surface is a pointer to an IDirect3DSurface9 interface.
// Assumes a 32-bit pixel format for each pixel.

// Get the surface description.
D3DSURFACE_DESC surfaceDesc;
_surface
->GetDesc(&surfaceDesc);

// Get a pointer to the surface pixel data.
D3DLOCKED RECT lockedRect;

_surface
->LockRect(
      
&lockedRect,// pointer to receive locked data
      0,          // lock entire surface
      0);         // no lock flags specified

// Iterate through each pixel in the surface and set it to red.
DWORD* imageData = (DWORD*)lockedRect.pBits;

for(int i = 0; i < surfaceDesc.Height; i++)
{
      
for(int j = 0; j < surfaceDesc.Width; j++)
      {
            
// index into texture, note we use the pitch and divide by
            
// four since the pitch is given in bytes and there are 4 bytes per DWORD.
            int index = i * lockedRect.Pitch / 4 + j;

            imageData[index] 
= 0xffff0000// red
      }
}

_surface
->UnlockRect();

程序中D3DLOCKED_RECT結構的定義如下:

typedef struct _D3DLOCKED RECT {
    INT Pitch;   // the surface pitch
    void *pBits; // pointer to the start of the surface memory
} D3DLOCKED_RECT;

在這里有一些關于表面鎖定代碼的一些說明。32-bit像素格式這個設定很重要,我們把bits轉換成DWORDs。這讓我們能把每一個DWORD視為表示一個像素。

posted on 2008-03-12 18:52 lovedday 閱讀(2004) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


公告

導航

統計

常用鏈接

隨筆分類(178)

3D游戲編程相關鏈接

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            欧美日韩成人一区| 亚洲愉拍自拍另类高清精品| 一区二区不卡在线视频 午夜欧美不卡在| 亚洲欧美一区二区精品久久久| 一本色道久久88综合亚洲精品ⅰ| 在线观看91精品国产麻豆| 欧美电影在线| 最新国产成人在线观看| 亚洲国产精品一区二区三区| 91久久综合亚洲鲁鲁五月天| 日韩视频永久免费观看| 亚洲私人影院在线观看| 性欧美超级视频| 麻豆精品视频在线观看| 亚洲精品国久久99热| 亚洲精品美女久久7777777| 亚洲图片在区色| 久久久在线视频| 欧美日本亚洲视频| 国产午夜精品一区二区三区视频 | 久久国产精品久久久| 久久免费国产精品1| 美日韩精品视频免费看| 日韩亚洲成人av在线| 亚洲精品美女免费| 亚洲欧洲一区二区天堂久久| 亚洲一区二区精品在线观看| 久久精品国产999大香线蕉| 欧美丝袜一区二区三区| 国产美女精品视频| 91久久精品国产| 欧美一区二区视频在线| 欧美69视频| 性娇小13――14欧美| 欧美精品久久久久久久免费观看| 国产字幕视频一区二区| 亚洲精品一区二区在线观看| 麻豆精品在线视频| 亚洲精品裸体| 久久久亚洲国产美女国产盗摄| 欧美日韩国产电影| 欲香欲色天天天综合和网| 先锋a资源在线看亚洲| 国内成+人亚洲| 亚洲综合色视频| 亚洲国产一区二区精品专区| 欧美一区二区视频在线观看2020 | 一区二区成人精品| 亚洲欧美日韩在线观看a三区 | 免费日韩av电影| 国产一区二区三区在线观看精品 | 欧美激情亚洲| 最近中文字幕日韩精品| 老司机免费视频一区二区| 午夜久久久久| 国产乱码精品1区2区3区| 亚洲特色特黄| 日韩午夜在线观看视频| 亚洲激情一区| 免费日韩av片| 亚洲精品乱码久久久久久蜜桃麻豆 | 99国产精品私拍| 免费视频一区| 亚洲国产精品日韩| 蜜臀av性久久久久蜜臀aⅴ四虎| 欧美一级二级三级蜜桃| 国产精品视频第一区| 亚洲午夜精品久久久久久app| 免费黄网站欧美| 欧美亚洲自偷自偷| 国产午夜精品福利| 久久av免费一区| 一本色道久久综合狠狠躁篇怎么玩| 欧美高清自拍一区| 欧美日韩午夜剧场| 亚洲欧美久久久| 午夜影院日韩| 在线观看亚洲| 亚洲欧洲另类| 欧美国产日韩一区| 欧美一区二区三区男人的天堂| 老司机精品视频网站| 一区二区三区不卡视频在线观看| 一本久道久久久| 国产日韩欧美自拍| 欧美激情偷拍| 国产精品美女久久久免费| 久久久久久久网| 欧美日本免费| 久久久久久尹人网香蕉| 欧美成人一区二区三区片免费| 99视频日韩| 夜夜嗨av一区二区三区中文字幕 | 欧美日韩你懂的| 国产欧美一区二区三区另类精品| 午夜一区不卡| 欧美大片91| 久久精品国产亚洲5555| 欧美大尺度在线| 久久久99爱| 欧美日韩一级视频| 久久亚洲一区二区| 国产精品播放| 久久婷婷av| 亚洲黄色视屏| 亚洲欧美在线高清| 99亚洲精品| 久久精品主播| 亚洲永久视频| 欧美精品一区二区三区蜜桃| 久久夜色精品国产| 国产精品一二一区| 亚洲看片网站| 亚洲激情偷拍| 久久久av水蜜桃| 欧美一区二区三区在线看| 欧美电影在线| 欧美国产成人精品| 狠狠色狠狠色综合| 亚洲一区二区在线播放| 欧美阿v一级看视频| 久久精品视频在线观看| 国产精品二区在线观看| 日韩视频免费看| 亚洲人成艺术| 女生裸体视频一区二区三区| 每日更新成人在线视频| 国产在线国偷精品产拍免费yy| 国产精品久久中文| 夜夜嗨av一区二区三区| 国产精品美女久久久久久久 | 亚洲主播在线| 欧美日韩一区视频| 日韩视频在线观看免费| 99香蕉国产精品偷在线观看| 欧美电影电视剧在线观看| 亚洲国产精品久久久久秋霞蜜臀| 国产一级一区二区| 久久精品视频va| 久久久久久免费| 国产欧美日韩精品在线| 亚洲欧美国产另类| 欧美三级视频在线| 久热精品视频在线观看一区| 日韩视频免费观看| 久久免费少妇高潮久久精品99| 久久成人18免费网站| 国产欧美精品xxxx另类| 午夜精品视频在线| 久久欧美中文字幕| 亚洲高清视频在线| 亚洲欧美一区二区在线观看| 女女同性精品视频| 亚洲精品国产系列| 欧美日韩亚洲综合一区| 亚洲一区亚洲| 老司机成人在线视频| 99精品国产99久久久久久福利| 欧美日韩免费高清| 国产精品五月天| 亚洲激情中文1区| 欧美日韩视频在线第一区| 亚洲图片欧洲图片日韩av| 久久中文精品| 一区二区国产日产| 国产三级精品在线不卡| 欧美sm重口味系列视频在线观看| 日韩亚洲视频| 久久免费视频一区| 一区二区三区久久网| 一区二区三区av| 久热精品在线| 亚洲综合色自拍一区| 亚洲国产高清一区二区三区| 欧美午夜免费电影| 麻豆精品网站| 亚洲已满18点击进入久久| 欧美va天堂在线| 在线精品视频一区二区| 亚洲天堂网在线观看| 亚洲视频综合在线| 一本大道久久精品懂色aⅴ| 久久av在线看| 亚洲欧美日韩国产中文在线| 免费成人av在线| 亚洲激情电影在线| 亚洲福利视频二区| 久久综合网络一区二区| 久久久99精品免费观看不卡| 国产精品麻豆成人av电影艾秋 | 亚洲一区二区三区精品动漫| 久久综合亚洲社区| 久久综合影视| 久久影音先锋| 欧美亚洲专区| 欧美日一区二区三区在线观看国产免 | 国产一区二区精品在线观看| 欧美成人一区在线| 久久精品欧美日韩| 亚洲视频成人|