• <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>

            天行健 君子當自強而不息

            DXUT框架剖析(5)

            修改可用的設備

            應用程序可以通過DXUTSetCallbackDeviceChanging()設置回調函數(shù)來修改Direct3D設備的創(chuàng)建設置:

            Sets a callback function that allow the application to change the device settings before the device is created.

            VOID DXUTSetCallbackDeviceChanging(
            LPDXUTCALLBACKMODIFYDEVICESETTINGS pCallbackModifyDeviceSettings,
            void* pUserContext
            );

            Parameters

            pCallbackModifyDeviceSettings
            [in] Pointer to a LPDXUTCALLBACKMODIFYDEVICESETTINGS callback function. If the callback function is supplied, it will be called before the Direct3D device is created. If NULL, DXUT will not notify the application about device changes.
            pUserContext
            [in] Pointer to a user-defined value which is passed to the callback function. Typically used by an application to pass a pointer to a data structure that provides context information for the callback function. The default value is NULL

            Return Values

            No return value.

            Remarks

            Before a device is created by DXUT, the LPDXUTCALLBACKMODIFYDEVICESETTINGS callback will be called to allow the application to examine or change the device settings before the device is created. This allows an application to modify the device creation settings as it sees fit.

            This callback also allows applications to reject changing the device altogether. Returning false from inside this callback will notify DXUT to keep using the current device instead of changing to the new device.

            LPDXUTCALLBACKMODIFYDEVICESETTINGS

            Application-defined callback function, called by DXUT to allow changes in device settings before the device is created.

            bool LPDXUTCALLBACKMODIFYDEVICESETTINGS(
            DXUTDeviceSettings * pDeviceSettings,
            void* pUserContext
            );

            Parameters

            pDeviceSettings
            [in] Pointer to a DXUTDeviceSettings structure that contains the settings for the new device.
            pUserContext
            [in] Pointer to a user-defined value which is passed to the callback function. Typically used by an application to pass a pointer to a data structure that provides context information for the callback function. The default value is NULL

            Return Values

            Program the application to return true to continue creating the device. If not, the application should return false to continue using the current device if one exists.

            Remarks

            Before a device is created by DXUT, the LPDXUTCALLBACKMODIFYDEVICESETTINGS callback will be called to allow the application to examine or change the device settings before the device is created. This allows an application to modify the device creation settings as it sees fit.

            This callback also allows applications to reject changing the device altogether. Returning false from inside this callback will notify DXUT to keep using the current device instead of changing to the new device.

            Anything in pDeviceSettings can be changed by the application. DXUT will not prevent the failure of device creation caused by changes to device settings.

            DXUTDeviceSettings

            A union of settings describing how to create the Direct3D 9 or Direct3D 10 device.

            typedef struct DXUTDeviceSettings {
            DXUTDeviceVersion ver;
            union {
            DXUTD3D9DeviceSettings d3d9;
            DXUTD3D10DeviceSettings d3d10;
            };
            } DXUTDeviceSettings, *LPDXUTDeviceSettings;

            Members

            ver
            Indicates whether the settings structure is for a Direct3D 9 or Direct3D 10 device.
            d3d9
            Device settings for Direct3D 9 device. Only valid if ver is DXUT_D3D9_DEVICE.
            d3d10
            Device settings for Direct3D 10 device. Only valid if ver is DXUT_D3D10_DEVICE.

            Remarks

            The DXUTDeviceSettings can only describe a single device because the DXUTD3D9DeviceSettings and DXUTD3D10DeviceSettings member variables are unioned together. The DXUTDeviceVersion indicates which of these structures is valid.

            DXUTD3D9DeviceSettings

            Describes the settings used to create a Direct3D 9 device.

            typedef struct DXUTD3D9DeviceSettings {
            UINT AdapterOrdinal;
            D3DDEVTYPE DeviceType;
            D3DFORMAT AdapterFormat;
            DWORD BehaviorFlags;
            D3DPRESENT_PARAMETERS pp;
            } DXUTD3D9DeviceSettings, *LPDXUTD3D9DeviceSettings;

            Members

            AdapterOrdinal
            Ordinal number that denotes the display adapter.
            DeviceType
            Enumerated type of the device.
            AdapterFormat
            Adapter surface format.
            BehaviorFlags
            Behavior flags. This member can be a combination of one or more of the D3DCREATE values.
            pp
            Presentation parameters structure.

            DXUT fills this structure with valid values, and then passes the structure to the callback function where the application can modify it. Be sure to validate any changes your application makes in this callback function. Here is an example that changes the depth-stencil format.

            bool CALLBACK ModifyDeviceSettings( 
            DXUTDeviceSettings* pDeviceSettings,
            void* pUserContext )
            {
            if( pDeviceSettings->ver == DXUT_D3D9_DEVICE )
            {
            IDirect3D9* pD3D = DXUTGetD3DObject();

            if( SUCCEEDED( pD3D->CheckDeviceFormat(
            pDeviceSettings->d3d9.AdapterOrdinal, pDeviceSettings->d3d9.DeviceType,
            pDeviceSettings->d3d9.AdapterFormat, D3DUSAGE_DEPTHSTENCIL,
            D3DRTYPE_SURFACE, D3DFMT_D24S8 ) ) )
            {
            if( SUCCEEDED( pD3D->CheckDepthStencilMatch(
            pDeviceSettings->d3d9.AdapterOrdinal, pDeviceSettings->d3d9.DeviceType,
            pDeviceSettings->d3d9.AdapterFormat, pDeviceSettings->d3d9.pp.BackBufferFormat,
            D3DFMT_D24S8 ) ) )
            {
            pDeviceSettings->d3d9.pp.AutoDepthStencilFormat = D3DFMT_D24S8;
            }
            }
            }

            return true;
            }

            如果應用程序需要的深度模板格式是D3DFMT_D24S8,那么程序需要確定設備支持它。

            回調函數(shù)ModifyDeviceSettings()返回一個布爾值,如果應用程序返回TRUE,DXUT框架繼續(xù)像在正常情況下那樣進行設備創(chuàng)建。如果返回FALSE,框架不能改變設備,如果已有一個設備,則繼續(xù)使用當前設備。如果框架提出的請求是改變到一個應用程序不能使用的設備,應用程序可以拒絕該請求。例如,在一個多顯示器配置中,默認情況下在顯示器之間拖動窗口將使框架改變設備。但如果應用程序不能使用其他設備,它就必須拒絕這種改變并繼續(xù)使用當前設備。

             

            降級到軟件頂點處理

            Be careful if your hardware supports pixel processing (transforms and lighting) but does not support vertex processing. One common mistake is to reject devices based on the vertex shader version in the (LPDXUTCALLBACKISD3D9DEVICEACCEPTABLE or LPDXUTCALLBACKISD3D10DEVICEACCEPTABLE) callback functions. The correct solution is to implement the checking in the ModifyDeviceSettings callback function as shown here.

            bool CALLBACK ModifyDeviceSettings( DXUTDeviceSettings* pDeviceSettings, 
            void* pUserContext )
            {
            if( pDeviceSettings->ver == DXUT_D3D9_DEVICE )
            {
            D3DCAPS9 caps;
            DXUTGetD3D9DeviceCaps( pDeviceSettings, &caps );

            // If device doesn't support HW T&L or doesn't support 1.1 vertex
            // shaders in HW, then switch to SWVP.
            if( (pCaps->DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == 0 ||
            pCaps->VertexShaderVersion < D3DVS_VERSION(1,1) )
            {
            pDeviceSettings->d3d9.BehaviorFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
            }

            else
            {
            pDeviceSettings->d3d9.BehaviorFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
            }
            }

            return true;
            }

            posted on 2008-05-15 15:44 lovedday 閱讀(1336) 評論(0)  編輯 收藏 引用

            公告

            導航

            統(tǒng)計

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關鏈接

            搜索

            最新評論

            亚洲狠狠久久综合一区77777| 伊人久久无码中文字幕| 久久精品国产只有精品2020| 色噜噜狠狠先锋影音久久| 久久精品国产乱子伦| 久久久久久毛片免费播放| 狠狠狠色丁香婷婷综合久久五月| 伊人色综合久久| 7777久久久国产精品消防器材| 国产亚洲美女精品久久久久狼| 久久香蕉国产线看观看猫咪?v| 亚洲国产精品无码久久SM| segui久久国产精品| 亚洲色大成网站www久久九| 久久99久久99小草精品免视看| 久久丝袜精品中文字幕| 国产精品视频久久久| 偷偷做久久久久网站| 久久精品国产精品亚洲毛片| 久久高潮一级毛片免费| 久久夜色精品国产噜噜麻豆| 久久精品无码av| 亚洲国产精久久久久久久| 久久精品国产亚洲AV麻豆网站| 日日狠狠久久偷偷色综合免费 | 久久A级毛片免费观看| 一本久久免费视频| 久久亚洲欧洲国产综合| 久久国产三级无码一区二区| 精品久久久久久中文字幕| 久久久久亚洲AV无码永不| 亚洲∧v久久久无码精品| 久久久SS麻豆欧美国产日韩| 理论片午午伦夜理片久久| 久久精品国产精品亜洲毛片| 天天爽天天爽天天片a久久网| 精品久久久久久成人AV| 久久精品国产99久久无毒不卡| 久久精品人人做人人爽电影蜜月 | 91久久精品国产免费直播| 精品久久久久中文字幕日本|