Advertisement
Guest User

Untitled

a guest
Oct 6th, 2023
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.26 KB | None | 0 0
  1.  internal Graphics()
  2.         {
  3.             d3d = new Direct3D();
  4.  
  5.             CreateDevice();
  6.             Camera = new Camera();
  7.         }
  8.  
  9.         private void CreateDevice()
  10.         {
  11.             int msaa = PickBestMSAALevel(Game.Current.Config.GetInt("renderer.msaa"));
  12.  
  13.             bool fullScreen = Game.Current.Config.GetBool("renderer.fullScreen");
  14.  
  15.             PresentParameters pp = new PresentParameters();
  16.             pp.AutoDepthStencilFormat = Format.D24S8;
  17.             pp.BackBufferCount = 1;
  18.             pp.BackBufferWidth = fullScreen ? Game.Current.Config.GetInt("engine.width") : Game.Current.Width;
  19.             pp.BackBufferHeight = fullScreen ? Game.Current.Config.GetInt("engine.height") : Game.Current.Height;
  20.             pp.BackBufferFormat = !fullScreen ? Format.Unknown : Format.X8R8G8B8;
  21.             pp.DeviceWindowHandle = Game.Current.Form.Handle;
  22.             pp.EnableAutoDepthStencil = true;
  23.             pp.SwapEffect = SwapEffect.Discard;
  24.             pp.Windowed = !fullScreen;
  25.             pp.MultiSampleType = (MultisampleType)msaa;
  26.             pp.FullScreenRefreshRateInHz = 0;
  27.             pp.MultiSampleQuality = 0;
  28.             pp.PresentFlags = PresentFlags.None;
  29.             pp.PresentationInterval = PresentInterval.Default;
  30.             pp.SwapEffect = SwapEffect.Discard;
  31.             device = new Device(d3d, 0, DeviceType.Hardware, Game.Current.Form.Handle, CreateFlags.HardwareVertexProcessing | CreateFlags.PureDevice, pp);
  32.  
  33.             Game.Current.Log.Print("Initialized graphics");
  34.             Game.Current.Log.Print("Total video memory: " + device.AvailableTextureMemory / 1024 / 1024);
  35.         }
  36.  
  37.         private int PickBestMSAALevel(int level)
  38.         {
  39.             int ret = level;
  40.  
  41.             for (int i = level; i > 1; i--)
  42.             {
  43.                 if (d3d.CheckDeviceMultisampleType(0, DeviceType.Hardware, Format.Unknown,
  44.                     !Game.Current.Config.GetBool("renderer.fullScreen"), (MultisampleType)i))
  45.                 {
  46.                     ret = i;
  47.  
  48.                     continue;
  49.                 }
  50.             }
  51.  
  52.             if(ret != level)
  53.                 Game.Current.Log.Print("Picked MSAA x" + ret + " , as your GPU doesn't support desired level");
  54.  
  55.             return ret;
  56.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement