码迷,mamicode.com
首页 > 其他好文 > 详细

DirectX9 Sample_Empty Project

时间:2015-07-29 13:58:48      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:

作为第一个程序,EmpytProject仅仅示范了如何绑定DXUTstate结构中的回调函数。(我并不理解这里回调函数的含义,回调函数绑定的子窗口、控件在哪?)

使用DXUT框架可以简化Win32和DirectX的api调用。

各个回调函数介绍如下,引用了DirectX11中的相关介绍,DirectX9的情况与之类似

  

Device Management and Initialization

DXUT provides various methods for creating and configuring the window and the Direct3D device. The methods that are used in this tutorial are listed below. They are sufficient for a moderately complex Direct3D application.

The procedure from the previous tutorial inside InitDevice() and CleanupDevice() has been properly managed by splitting it into the following functions.

  • IsD3D11DeviceAcceptable Callback
  • ModifyDeviceSettings Callback
  • OnD3D11CreateDevice Callback
  • OnD3D11DestroyDevice Callback

Because not all resources are created at the same time, we can minimize overhead by reducing the number of repeated calls. We achieve this goal by recreating only resources that are context dependent. For the sake of simplicity, previous tutorials recreated everything whenever the screen was resized.

IsD3D11DeviceAcceptable Callback

This function is invoked for each combination of valid device settings that is found on the system. It allows the application to accept or reject each combination. For example, the application can reject all REF devices, or it can reject full screen device setting combinations.

In this tutorial, all devices are acceptable, because we do not need any advanced functionality.

ModifyDeviceSettings Callback

This callback function allows the application to change any device settings immediately before DXUT creates the device. In this tutorial, nothing needs to be done in the callback, because we do not need any advanced functionality.

OnD3D11CreateDevice Callback

This function is called after the Direct3D11 device is created. After the device is created, an application can use this callback to allocate resources, set buffers, and handle other necessary tasks.

In this tutorial, most of the InitDevice() function from tutorial 7 is copied into this callback function. The code for device and swap chain creation is omitted, because these functions are handled by DXUT. OnD3D11CreateDevice creates the effect, the vertex/index buffers, the textures, and the transformation matrices. The code has been copied from tutorial 7 with minimal alterations.

OnD3D11DestroyDevice Callback

This callback function is called immediately before the ID3D11Device is released by DXUT. This callback is used to release resources that were used by the device.

In this tutorial, OnD3D11DestroyDevice releases the resources that were created by the OnD3D11CreateDevice function. These resources include the vertex/index buffers, the layout, the textures, and the effect. The code is copied from the CleanupDevice() function, but it has been changed to use the SAFE_RELEASE macro.

Rendering

For rendering, DXUT provides two callback functions to initiate rendering for your application. The first, OnFrameMove, is called before each frame is rendered. It advances time in the application. The second, OnD3D11FrameRender, provides rendering for DXUT.

These two functions split the work of the Render() function into logical steps. OnFrameMove updates all the matrices for animation. OnD3D11FrameRender contains the rendering calls.

OnFrameMove Callback

This function is called before a frame is rendered. It is used to process the world state. However, its update frequency depends on the speed of the system. On faster systems, it is called more often per second. This means that any state update code must be regulated by time. Otherwise, it performs differently on a slower system than on a faster system.

Every time the function is called in the tutorial, the world is updated once, and the mesh color is adjusted. This code is copied directly from the Render() function in tutorial 7. Note that the rendering calls are not included.

OnD3D11FrameRender Callback

This function is called whenever a frame is redrawn. Within this function, effects are applied, resources are associated, and the drawing for the scene is called.

In this tutorial, this function contains the calls to clear the back buffer and stencil buffer, set up the matrices, and draw the cubes.

Message Processing

Message processing is an intrinsic property of all window applications. DXUT exposes these messages for advanced applications.

MsgProc Callback

DXUT invokes this function when window messages are received. The function allows the application to handle messages as it sees fit.

In this tutorial, no additional messages are handled.

KeyboardProc Callback

This callback function is invoked by DXUT when a key is pressed. It can be used as a simple function to process keyboard commands.

The KeyboardProc callback is not used in this tutorial, because keyboard interaction is not necessary. However, there is a skeleton case for F1, which you can experiment with. Try to insert code to toggle the rotation of the cubes.

DirectX9 Sample_Empty Project

标签:

原文地址:http://www.cnblogs.com/Agravity/p/4685685.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!