zoukankan      html  css  js  c++  java
  • [WorldWind学习]3.Device对象

      首先介绍一下Device类,Device位于using Microsoft.DirectX.Direct3D;命名空间下。

      Device类用于完成DirectX 里所有绘图操作,我们可以把这个类假想为图形卡,场景里所有其他图形对象都依赖于Device,计算机里可以有多个Device对象。所以在全局变量中定义一个绘图设备,如下代码:
      private Device m_Device3d;//定义绘图设备  

     1 private void InitializeGraphics()
     2         {
     3             // Set up our presentation parameters
     4             m_presentParams = new PresentParameters();
     5 
     6             m_presentParams.Windowed = true;//指定以Windows窗体形式显示
     7             m_presentParams.SwapEffect = SwapEffect.Discard;//当前屏幕绘制后
    它将自动从内存中删除
    8 m_presentParams.AutoDepthStencilFormat = DepthFormat.D16;//深度检测 9 m_presentParams.EnableAutoDepthStencil = true; 10 11 if(!World.Settings.VSync) 12 // Disable wait for vertical retrace (higher frame rate at the expense of tearing) 13 m_presentParams.PresentationInterval = PresentInterval.Immediate; 14 15 int adapterOrdinal = 0; 16 try 17 { 18 // Store the default adapter 19 adapterOrdinal = Manager.Adapters.Default.Adapter; 20 } 21 catch 22 { 23 // User probably needs to upgrade DirectX or install a 3D capable graphics adapter 24 throw new NotAvailableException(); 25 } 26 27 DeviceType dType = DeviceType.Hardware; 28 29 foreach(AdapterInformation ai in Manager.Adapters) 30 { 31 if(ai.Information.Description.IndexOf("NVPerfHUD") >= 0) 32 { 33 adapterOrdinal = ai.Adapter; 34 dType = DeviceType.Reference; 35 } 36 } 37 CreateFlags flags = CreateFlags.SoftwareVertexProcessing; 38 39 // Check to see if we can use a pure hardware m_Device3d 40 Caps caps = Manager.GetDeviceCaps(adapterOrdinal, DeviceType.Hardware); 41 42 // Do we support hardware vertex processing? 43 if(caps.DeviceCaps.SupportsHardwareTransformAndLight) 44 // // Replace the software vertex processing 45 flags = CreateFlags.HardwareVertexProcessing; 46 47 // Use multi-threading for now - TODO: See if the code can be changed such that this isn't necessary (Texture Loading for example) 48 flags |= CreateFlags.MultiThreaded | CreateFlags.FpuPreserve; 49 50 try 51 { 52 // Create our m_Device3d 实例化device对象 53 m_Device3d = new Device(adapterOrdinal, dType, this, flags, m_presentParams); 54 } 55 catch( Microsoft.DirectX.DirectXException ) 56 { 57 throw new NotSupportedException("Unable to create the Direct3D m_Device3d."); 58 } 59 60 // Hook the m_Device3d reset event 61 m_Device3d.DeviceReset += new EventHandler(OnDeviceReset); 62 m_Device3d.DeviceResizing += new CancelEventHandler(m_Device3d_DeviceResizing); 63 OnDeviceReset(m_Device3d, null); 64 }
    文章未经说明均属原创,学习笔记可能有大段的引用,一般会注明参考文献。 欢迎大家留言交流,转载请注明出处。
  • 相关阅读:
    多年收集的一些稀有软件1
    Object-C中使用NSKeyedArchiver归档(将各种类型的对象存储到文件中)
    转-- iOS 30多个iOS常用动画,带详细注释
    转-ios设备唯一标识获取策略
    微信授权
    Windows服务Demo
    查询某个时间段在另一个时间段里面的时间
    微服务官方文档链接
    c# html 转word
    Unreal4 入门(配置)
  • 原文地址:https://www.cnblogs.com/yhlx125/p/2988491.html
Copyright © 2011-2022 走看看