新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论高级C/C++编程、代码重构(Refactoring)、极限编程(XP)、泛型编程等话题
    [返回] 中文XML论坛 - 专业的XML技术讨论区计算机技术与应用『 C/C++编程思想 』 → Direct3D程序设计基础 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 14694 个阅读者浏览上一篇主题  刷新本主题   平板显示贴子 浏览下一篇主题
     * 贴子主题: Direct3D程序设计基础 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     卷积内核 帅哥哟,离线,有人找我吗?
      
      
      威望:8
      头衔:总统
      等级:博士二年级(版主)
      文章:3942
      积分:27590
      门派:XML.ORG.CN
      注册:2004/7/21

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给卷积内核发送一个短消息 把卷积内核加入好友 查看卷积内核的个人资料 搜索卷积内核在『 C/C++编程思想 』的所有贴子 访问卷积内核的主页 引用回复这个贴子 回复这个贴子 查看卷积内核的博客楼主
    发贴心情 Direct3D程序设计基础

    Direct3D对象

    Microsoft Direct3D的一种实现方式是通过组件对象模型(Component Object Model, COM)及其接口实现的,在用C++语言和COM接口方式开发的程序中可以直接访问这些接口和对象。Direct3D对象是Direct3D程序中需要创建的第一个对象,也是需要最后一个释放的对象,这里所说的对象是指COM对象。通过Direct3D对象,可以枚举和检索Direct3D设备,这样应用程序就可以在不需要创建设备对象的前提下选择Direct3D渲染设备。

    在用C++语言编写Direct3D程序时,需要先获取一个指向IDirect3D9接口的指针,从而可以通过该接口调用Direct3D对象的功能。

    创建Direct3D设备对象

    创建Direct3D设备对象时,需要先创建Direct3D对象,然后再调用Direct3D对象的接口函数IDirect3D9::CreateDevice创建Direct3D设备对象。通过同一个Direct3D对象创建的所有Direct3D设备对象共享相同的物理资源(显卡)。因为共享同一硬件,所以如果通过一个Direct3D对象创建多个Direct3D渲染设备对象会明显降低系统性能。

    在创建Direct3D设备对象之前,还需要先初始化D3DPRESENT_PARAMETERS结构,该结构用于创建Direct3D设备对象。D3DPRESENT_PARAMETERS结构定义了Direct3D设备对象的相关信息,而这些信息将会影响Direct3D设备的显示方法。该结构的定义如下:

    Describes the presentation parameters.

    typedef struct D3DPRESENT_PARAMETERS {    UINT BackBufferWidth, BackBufferHeight;    D3DFORMAT BackBufferFormat;    UINT BackBufferCount;    D3DMULTISAMPLE_TYPE MultiSampleType;    DWORD MultiSampleQuality;    D3DSWAPEFFECT SwapEffect;    HWND hDeviceWindow;    BOOL Windowed;    BOOL EnableAutoDepthStencil;    D3DFORMAT AutoDepthStencilFormat;    DWORD Flags;    UINT FullScreen_RefreshRateInHz;    UINT PresentationInterval;} D3DPRESENT_PARAMETERS, *LPD3DPRESENT_PARAMETERS;
    Members
    BackBufferWidth, BackBufferHeight
    Width and height of the new swap chain's back buffers, in pixels. If Windowed is FALSE (the presentation is full-screen), these values must equal the width and height of one of the enumerated display modes found through IDirect3D9::EnumAdapterModes. If Windowed is TRUE and either of these values is zero, the corresponding dimension of the client area of the hDeviceWindow (or the focus window, if hDeviceWindow is NULL) is taken.
    BackBufferFormat
    The back buffer format. For more information about formats, see D3DFORMAT. This value must be one of the render-target formats as validated by IDirect3D9::CheckDeviceType. You can use IDirect3DDevice9::GetDisplayMode to obtain the current format.
    In fact, D3DFMT_UNKNOWN can be specified for the BackBufferFormat while in windowed mode. This tells the runtime to use the current display-mode format and eliminates the need to call IDirect3DDevice9::GetDisplayMode.

    For windowed applications, the back buffer format no longer needs to match the display-mode format because color conversion can now be done by the hardware (if the hardware supports color conversion). The set of possible back buffer formats is constrained, but the runtime will allow any valid back buffer format to be presented to any desktop format. (There is the additional requirement that the device be operable in the desktop mode; devices typically do not operate in 8 bits per pixel modes.)

    Full-screen applications cannot do color conversion.

    BackBufferCount
    This value can be between 0 and D3DPRESENT_BACK_BUFFERS_MAX (or D3DPRESENT_BACK_BUFFERS_MAX_EX when using Direct3D 9Ex). Values of 0 are treated as 1. If the number of back buffers cannot be created, the runtime will fail the method call and fill this value with the number of back buffers that could be created. As a result, an application can call the method twice with the same D3DPRESENT_PARAMETERS structure and expect it to work the second time.
    The method fails if one back buffer cannot be created. The value of BackBufferCount influences what set of swap effects are allowed. Specifically, any D3DSWAPEFFECT_COPY swap effect requires that there be exactly one back buffer.

    MultiSampleType
    Member of the D3DMULTISAMPLE_TYPE enumerated type. The value must be D3DMULTISAMPLE_NONE unless SwapEffect has been set to D3DSWAPEFFECT_DISCARD. Multisampling is supported only if the swap effect is D3DSWAPEFFECT_DISCARD.
    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. Paired values of render targets or of depth stencil surfaces and D3DMULTISAMPLE_TYPE must match.
    SwapEffect
    Member of the D3DSWAPEFFECT enumerated type. The runtime will guarantee the implied semantics concerning buffer swap behavior; therefore, if Windowed is TRUE and SwapEffect is set to D3DSWAPEFFECT_FLIP, the runtime will create one extra back buffer and copy whichever becomes the front buffer at presentation time.
    D3DSWAPEFFECT_COPY requires that BackBufferCount be set to 1.

    D3DSWAPEFFECT_DISCARD will be enforced in the debug runtime by filling any buffer with noise after it is presented.

    hDeviceWindow
    The device window determines the location and size of the back buffer on screen. This is used by Direct3D when the back buffer contents are copied to the front buffer during IDirect3DDevice9::Present.
    For a full-screen application, this is a handle to the top window (which is the focus window).
    For applications that use multiple full-screen devices (such as a multimonitor system), exactly one device can use the focus window as the device window. All other devices must have unique device windows.

    For a windowed-mode application, this handle will be the default target window for IDirect3DDevice9::Present. If this handle is NULL, the focus window will be taken.
    Note that no attempt is made by the runtime to reflect user changes in window size. The back buffer is not implicitly reset when this window is reset. However, the IDirect3DDevice9::Present method does automatically track window position changes.

    Windowed
    TRUE if the application runs windowed; FALSE if the application runs full-screen.
    EnableAutoDepthStencil
    If this value is TRUE, Direct3D will manage depth buffers for the application. The device will create a depth-stencil buffer when it is created. The depth-stencil buffer will be automatically set as the render target of the device. When the device is reset, the depth-stencil buffer will be automatically destroyed and recreated in the new size.
    If EnableAutoDepthStencil is TRUE, then AutoDepthStencilFormat must be a valid depth-stencil format.

    AutoDepthStencilFormat
    Member of the D3DFORMAT enumerated type. The format of the automatic depth-stencil surface that the device will create. This member is ignored unless EnableAutoDepthStencil is TRUE.
    Flags
    One of the D3DPRESENTFLAG constants.
    FullScreen_RefreshRateInHz
    The rate at which the display adapter refreshes the screen. The value depends on the mode in which the application is running:
    For windowed mode, the refresh rate must be 0.
    For full-screen mode, the refresh rate is one of the refresh rates returned by IDirect3D9::EnumAdapterModes.
    PresentationInterval
    The maximum rate at which the swap chain's back buffers can be presented to the front buffer. For a detailed explanation of the modes and the intervals that are supported, see D3DPRESENT.


       收藏   分享  
    顶(0)
      




    ----------------------------------------------
    事业是国家的,荣誉是单位的,成绩是领导的,工资是老婆的,财产是孩子的,错误是自己的。

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2008/11/26 8:24:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 C/C++编程思想 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/5/6 11:47:24

    本主题贴数6,分页: [1]

     *树形目录 (最近20个回帖) 顶端 
    主题:  Direct3D程序设计基础(7219字) - 卷积内核,2008年11月26日
        回复:  渲染图形使用Direct3D绘制三维图形和使用GDI绘制二维图形的方法非常类似,Direct3..(5952字) - 卷积内核,2008年11月26日
        回复:  消息循环在Direct3D中,渲染图形通常是在消息循环中进行的: MSG msg; Z..(1070字) - 卷积内核,2008年11月26日
        回复:  初始化Direct3D创建了可供绘制图形的窗口后,在使用Direct3D渲染图形前,还需要进行..(6089字) - 卷积内核,2008年11月26日
        回复:  创建窗口Direct3D是基于Microsoft Windows的图形开发接口,它的使用必须建..(726字) - 卷积内核,2008年11月26日
        回复:  [B]Direct3D程序基本结构[/B]虽然Direct3D功能非常强大,但是Direct3..(3428字) - 卷积内核,2008年11月26日

    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    78.125ms