天天看點

龍書D3D11章節習題答案(第四章)

下面答案僅供參考,有錯歡迎留言。

Chapter 4:Direct3D Initialzation

1. Modify the previous exercise solution by disabling the ALT-ENTER functionality to switch between full screen and windowed mode;  use the IDXGIFactory::MakeWindowAssociation method

and specify the DXGI_MWA_NO_WINDOW_CHANGES flag so that DXGI does not monitor the message queue. Note that the IDXGIFactory::MakeWindowAssociation method needs to be called after IDXGIFactory::CreateSwapChain is called.

意思是禁用架構代碼提供的ALT-ENTER鍵功能,即全屏和窗體模式間的切換。

按要求加入代碼(注意加入在建立交換鍊之後):

龍書D3D11章節習題答案(第四章)

DXGI應該是利用Hook窗體消息處理過程,監聽ALT+ENTER按鍵,來實作自己主動的在窗體模式和全屏模式切換。而用DXGI_MWA_NO_WINDOW_CHANGES能夠指定取消監聽程式消息隊列。來"取消"此功能。

為了滿足好奇心能夠用VS工具菜單下的Spy++來檢測ALT-ENTER所發送的窗體消息:

龍書D3D11章節習題答案(第四章)

過濾掉全部已知的消息= =。剩下的未知消息應該會包括發送給DXGI的消息吧(我自己的推測...)

這個窗體正常執行時會一直SendMessage和return一個辨別為0x00AE的消息。

而在按下ALT+ENTER切換全屏時。則有額外的0x0093、0x0094消息...

是以93、94消息即為DXGI所監聽的消息。

龍書D3D11章節習題答案(第四章)

然後呢,我們調用DXGIFactory::MakeWindowAssociation以後再用spy++看看...

這次怎麼按ALT-ENTER都不會出現93、94消息了,而僅僅是一直在發送、傳回AE消息(= =, 真不知道是幹嘛的。

)...

2. Some systems have more than one adapter (video card), and the application may wish to let the user choose which one to use, instead of always using the default adapter. Use the IDXGIFactory::EnumAdapters method to determine

how many adapters are on your system.

意思是說有些系統有多塊顯示卡。讓你用DXGI接口給的EnumAdapters來看看究竟是哪幾塊= =

考慮到大多數電腦最多也就是雙顯示卡。

。是以存儲顯示卡相關資訊的數組僅僅定義了[3][256]。。處理的時候使用的是Unicode字元集,是以字元數組用的是WCHAR。而用于格式化生成輸出字元串的sprintf換成了swprintf。加個_s幫忙在越界時提示資訊;在調試窗體程式時輸出資訊到VS的輸出窗體最為友善(和MessageBox相比不會影響程式正常執行),是以用OutputDebugStringW來完畢此操作。

龍書D3D11章節習題答案(第四章)

顯存輸出的機關是B,即byte,我的獨立顯示卡是2G顯存的,這裡正好是2*10^9 B,符合~

唯一有點疑惑的是MS Basic Render Driver這個adapter,顯然這不是一塊真實存在的顯示卡。。或許是做軟體模拟的?。。

至于ADAPTER_DESC裡面的LUID(Local Unique IDentifier)我非常外行,輸出的時候組合highpart在前,lowpart在後。不知道對不正确。。

3. For each adapter the system possesses, IDXGIFactory::EnumAdapters outputs a pointer to a filled out IDXGIAdapter interface. This interface can be used to query information about the adapter. Use the IDXGIAdapter::CheckInterfaceSupport

method to see if the adapters on your system support Direct3D 11.

龍書D3D11章節習題答案(第四章)

經個人測試,我的明明支援dx11的顯示卡(這一點能夠window+R鍵執行dxdiag看看),檢測ID3D11Device時總是會return DXGI_ERROR_UNSUPPORTED,官方的最新說明表示這種方法如今僅僅能Check 10.x了,是以如今請不要用這種方法檢測是否支援11.x。如今呢,你要檢查顯示卡是否支援某個特定的接口必須試試看去建立它。。

也就是說。一項一項的檢測= =。。想調用融合相關接口那就要去試試ID3D11Device::CreateBlendState是不是傳回成功,假設失敗就證明不支援。。

這真是個壞消息...

4. An adapter has outputs associated with it (e.g., a monitor). You can use the IDXGIAdapter::EnumOutputs method to enumerate the outputs for a particular adapter. Use this method to determine the number of outputs for the default

adapter.

5. Each output has a list of supported display modes (DXGI_MODE_DESC) for a given pixel format. For each output(IDXGIOutput), show the width, height, and refresh rate of each display mode the output supports for theDXGI_FORMAT_R8G8B8A8_UNORM

format using the IDXGIOutput::GetDisplayModeList method.

意思是顯示卡(adater)之是以能正确輸出到顯示器上(monitor)。是由于顯示卡有支援這塊螢幕相應的寬、高、格式等屬性,即顯示卡關聯(associated with)顯示器。

試着用IDXGIAdapter::EnumOutputs去輸出顯示卡所支援的屬性表(Outputs)以及其支援屬性的數量(the num of outputs)。

龍書D3D11章節習題答案(第四章)

在本機測試總共輸出了107條支援資訊。從320*200一直到1920*1080格式。

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

今天又一次看了下寫的東西:

上圖輸出的重新整理率非常不正常,原來RefreshRate并不能直接輸出,由于其是一個DXGI_RATIONAL結構體,

是以輸出的時候須要分子/分母(Numerator/Denominator)。

龍書D3D11章節習題答案(第四章)

由于我還有塊HDMI接口的顯示屏外接筆記本是以。。正好測試下會不會輸出兩份資訊~

開啟雙屏...

龍書D3D11章節習題答案(第四章)
龍書D3D11章節習題答案(第四章)

雙顯示卡的電腦對同一塊顯示器不會有兩份outputs的原因應該是:雙顯示卡在執行某個程式時并不會兩塊顯示卡同一時候火力全開。。而是須要節能時開內建顯示卡作為主顯示卡。須要高性能時開獨立顯示卡作為主顯示卡。

雙顯示卡技術不是太了解= =。至少我還沒想通為什麼我的雙顯示卡單開獨顯fps非常低。而開了集顯和獨顯以後fps是僅僅開集顯的兩倍以上。。或許是我打開方式有問題。。

6. Experiment with modifying the viewport settings to draw the scene into a subrectangle of the back buffer. For example, try:....

按要求改動下d3dAPP::OnResize()裡面md3dImmediateContext->RSSetViewports(1, &mScreenViewport)所調用的mScreenViewport屬性就能夠了,注意至少要畫個物體才幹觀察到變化。。

建議能夠使用第六章的BoxDemo啊什麼的來試試