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

            天行健 君子當(dāng)自強(qiáng)而不息

            DXUT框架剖析(2)

            DXUT框架用來幫助程序員花更少的時(shí)間來解決下列問題:創(chuàng)建窗口、創(chuàng)建Direct3D設(shè)備、進(jìn)行消息循環(huán)和處理設(shè)備事件。在DXUT框架基礎(chǔ)上編寫代碼,可以快速高效地進(jìn)行Direct3D程序設(shè)計(jì),大多數(shù)Direct3D SDK示例程序使用了DXUT框架。

            下面的代碼是AppFrame示例程序的WinMain函數(shù):

            INT WINAPI wWinMain( HINSTANCE, HINSTANCE, LPWSTR, int )
            {
            // Enable run-time memory check for debug builds.
            #if defined(DEBUG) | defined(_DEBUG)
            _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
            #endif
                // Set the callback functions
            DXUTSetCallbackD3D9DeviceAcceptable(IsD3D9DeviceAcceptable);
            DXUTSetCallbackD3D9DeviceCreated(OnD3D9CreateDevice);
            DXUTSetCallbackD3D9DeviceReset(OnD3D9ResetDevice);
            DXUTSetCallbackD3D9FrameRender(OnD3D9FrameRender);
            DXUTSetCallbackD3D9DeviceLost(OnD3D9LostDevice);
            DXUTSetCallbackD3D9DeviceDestroyed(OnD3D9DestroyDevice);
            DXUTSetCallbackDeviceChanging(ModifyDeviceSettings);
            DXUTSetCallbackMsgProc(MsgProc);
            DXUTSetCallbackFrameMove(OnFrameMove);
                // TODO: Perform any application-level initialization here
                // Initialize DXUT and create the desired Win32 window and Direct3D device for the application
                DXUTInit( true, true ); // Parse the command line and show msgboxes
            DXUTSetHotkeyHandling( true, true, true ); // handle the default hotkeys
            DXUTSetCursorSettings( true, true ); // Show the cursor and clip it when in full screen
            DXUTCreateWindow( L"AppFrame Sample" );
            DXUTCreateDevice( true, 640, 480 );
                // Start the render loop
            DXUTMainLoop();
                // TODO: Perform any application-level cleanup here
                return DXUTGetExitCode();
            }

            在上面的代碼中,DXUT框架做了大部分的工作。它創(chuàng)建了一個(gè)窗口和一個(gè)Direct3D設(shè)備,處理消息循環(huán)、并當(dāng)事件發(fā)生時(shí)(例如重新設(shè)置設(shè)備或渲染一幀)調(diào)用應(yīng)用程序提供的回調(diào)函數(shù)。 DXUT框架是模塊化的,所以應(yīng)用程序可以使用DXUT框架的所有函數(shù)或其中的一部分。

            下面這組代碼時(shí)一組注冊(cè)函數(shù)的調(diào)用:

                // Set the callback functions
                DXUTSetCallbackD3D9DeviceAcceptable(IsD3D9DeviceAcceptable);
                DXUTSetCallbackD3D9DeviceCreated(OnD3D9CreateDevice);
                DXUTSetCallbackD3D9DeviceReset(OnD3D9ResetDevice);
                DXUTSetCallbackD3D9FrameRender(OnD3D9FrameRender);
                DXUTSetCallbackD3D9DeviceLost(OnD3D9LostDevice);
                DXUTSetCallbackD3D9DeviceDestroyed(OnD3D9DestroyDevice);
                DXUTSetCallbackDeviceChanging(ModifyDeviceSettings);
                DXUTSetCallbackMsgProc(MsgProc);
                DXUTSetCallbackFrameMove(OnFrameMove);

            以函數(shù)DXUTSetCallbackD3D9DeviceCreated為例,它的聲明如下:

            Sets the Direct3D 9 device created callback function.

            VOID DXUTSetCallbackD3D9DeviceCreated(
            LPDXUTCALLBACKD3D9DEVICECREATED pCallback,
            void* pUserContext
            );

            Parameters

            pCallback
            [in] Pointer to a LPDXUTCALLBACKD3D9DEVICECREATED callback function. If the callback function is supplied, it will be called after the Direct3D 9 device has been created. Device creation will happen during application initialization and if the device is changed. If NULL, DXUT will not notify the application about device creation.
            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

            This function only needs to be called if the application supports rendering with Direct3D 9 device.

            The LPDXUTCALLBACKD3D9DEVICECREATED callback function is the appropriate location for the application to create Direct3D 9 device resources that will live through a device reset such as D3DPOOL_MANAGED or D3DPOOL_SYSTEMMEM memory and that aren't tied to the back buffer size. Resources created in the LPDXUTCALLBACKD3D9DEVICECREATED callback function should be released in the LPDXUTCALLBACKD3D9DEVICEDESTROYED callback function.

            LPDXUTCALLBACKD3D9DEVICECREATED

            Application-defined resource creation callback function, called by DXUT after the Direct3D 9 device is created. Passes a pointer to the newly created Direct3D 9 device.

            HRESULT LPDXUTCALLBACKD3D9DEVICECREATED(
            IDirect3DDevice9 * pd3dDevice,
            CONST D3DSURFACE_DESC * pBackBufferSurfaceDesc,
            void* pUserContext
            );

            Parameters

            pd3dDevice
            [out] Pointer to the newly created Direct3D 9 device.
            pBackBufferSurfaceDesc
            [out] Pointer to the back buffer surface description
            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

            In general, if no error occurs, program the function to return S_OK. Program the function to return an HRESULT failure code if the function fails. If DXUT receives a failure HRESULT code, it shuts down the application.

            Remarks

            The LPDXUTCALLBACKD3D9DEVICECREATED callback function is the appropriate location for the application to create Direct3D 9 device resources that will live through a device reset such as D3DPOOL_MANAGED or D3DPOOL_SYSTEMMEM memory and that aren't tied to the back buffer size. Resources created in the LPDXUTCALLBACKD3D9DEVICECREATED callback function should be released in the LPDXUTCALLBACKD3D9DEVICEDESTROYED callback function.

            該注冊(cè)函數(shù)的作用在于通知應(yīng)用程序,在應(yīng)用程序的初始化期間或當(dāng)設(shè)備改變時(shí),如果需要?jiǎng)?chuàng)建D3DPOOL_MANAGED類型的資源,就會(huì)自動(dòng)調(diào)用函數(shù)OnD3D9CreateDevice()進(jìn)行創(chuàng)建。而程序員需要做的就是編寫OnD3D9CreateDevice()函數(shù),告訴應(yīng)用程序創(chuàng)建哪些資源以及如何創(chuàng)建。其他注冊(cè)函數(shù)的作用同樣是通知應(yīng)用程序,使應(yīng)用程序在特定時(shí)機(jī)調(diào)用注冊(cè)函數(shù)指定的具體回調(diào)函數(shù)。程序員的核心工作就是實(shí)現(xiàn)這些具體的回調(diào)函數(shù),事實(shí)上,這種構(gòu)架正是DXUT框架的核心,也可以把它看成是區(qū)別于Direct3D API程序的地方。

            DXUT框架提供了下列服務(wù),幫助程序員創(chuàng)建一個(gè)應(yīng)用程序:

            (1)簡化窗口和設(shè)備的創(chuàng)建。

            (2)聲明設(shè)備事件(創(chuàng)建、重置、丟失、銷毀)和窗口事件(消息、鍵盤、鼠標(biāo))。

            (3)在窗口模式和全屏模式間切換,在硬件抽象層設(shè)備和參考設(shè)備間切換。

            (4)高分辨率計(jì)時(shí)器。

            (5)為自動(dòng)測(cè)試提供命令行支持。

            (6)通過對(duì)話框或API選擇設(shè)備。

            (7)紋理GUI控件組,包括IME-enable文本框。

            (8)附加雜類,例如簡單的攝像機(jī)類。

            為使用方便,DXUT框架支持Direct3D設(shè)備和窗口一一對(duì)應(yīng)(一個(gè)設(shè)備只能對(duì)應(yīng)一個(gè)窗口)。對(duì)于需要同時(shí)使用多個(gè)設(shè)備或顯示多個(gè)Direct3D窗口的高級(jí)應(yīng)用程序,該框架不支持。不過,大多數(shù)應(yīng)用程序只使用一個(gè)窗口和一個(gè)Direct3D設(shè)備,所以大部分應(yīng)用程序都能使用該框架。


            posted on 2008-05-15 12:12 lovedday 閱讀(2313) 評(píng)論(0)  編輯 收藏 引用


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            公告

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關(guān)鏈接

            搜索

            最新評(píng)論

            伊人久久大香线蕉AV色婷婷色| 久久777国产线看观看精品| 精品久久久久久国产免费了| 久久夜色精品国产www| 久久九九兔免费精品6| 99久久综合狠狠综合久久| 久久精品一区二区三区AV| 婷婷伊人久久大香线蕉AV| 亚洲а∨天堂久久精品| 2021少妇久久久久久久久久| 思思久久精品在热线热| 国产精品免费看久久久香蕉| 亚洲精品国产综合久久一线| 久久精品国产第一区二区| 久久99国产精品一区二区| 久久精品国产黑森林| 91视频国产91久久久| 久久亚洲sm情趣捆绑调教 | 久久99久久99小草精品免视看| 久久精品不卡| 国产精品久久网| 久久精品国产亚洲av水果派| 久久人妻AV中文字幕| 久久九九久精品国产| 久久精品国产亚洲av麻豆小说| 2021国内精品久久久久久影院| 99久久成人国产精品免费| 香蕉久久夜色精品升级完成| 久久综合久久综合亚洲| 无码国内精品久久人妻麻豆按摩| 亚洲国产另类久久久精品小说 | 久久精品国产亚洲一区二区| 亚洲中文字幕无码一久久区| 久久久久精品国产亚洲AV无码| 欧美久久一级内射wwwwww.| 久久久久亚洲爆乳少妇无| 99久久99久久精品国产| 亚洲国产成人久久一区WWW| 欧美久久一级内射wwwwww.| 亚洲精品WWW久久久久久 | 69久久精品无码一区二区|