Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- internal Graphics()
- {
- d3d = new Direct3D();
- CreateDevice();
- Camera = new Camera();
- }
- private void CreateDevice()
- {
- int msaa = PickBestMSAALevel(Game.Current.Config.GetInt("renderer.msaa"));
- bool fullScreen = Game.Current.Config.GetBool("renderer.fullScreen");
- PresentParameters pp = new PresentParameters();
- pp.AutoDepthStencilFormat = Format.D24S8;
- pp.BackBufferCount = 1;
- pp.BackBufferWidth = fullScreen ? Game.Current.Config.GetInt("engine.width") : Game.Current.Width;
- pp.BackBufferHeight = fullScreen ? Game.Current.Config.GetInt("engine.height") : Game.Current.Height;
- pp.BackBufferFormat = !fullScreen ? Format.Unknown : Format.X8R8G8B8;
- pp.DeviceWindowHandle = Game.Current.Form.Handle;
- pp.EnableAutoDepthStencil = true;
- pp.SwapEffect = SwapEffect.Discard;
- pp.Windowed = !fullScreen;
- pp.MultiSampleType = (MultisampleType)msaa;
- pp.FullScreenRefreshRateInHz = 0;
- pp.MultiSampleQuality = 0;
- pp.PresentFlags = PresentFlags.None;
- pp.PresentationInterval = PresentInterval.Default;
- pp.SwapEffect = SwapEffect.Discard;
- device = new Device(d3d, 0, DeviceType.Hardware, Game.Current.Form.Handle, CreateFlags.HardwareVertexProcessing | CreateFlags.PureDevice, pp);
- Game.Current.Log.Print("Initialized graphics");
- Game.Current.Log.Print("Total video memory: " + device.AvailableTextureMemory / 1024 / 1024);
- }
- private int PickBestMSAALevel(int level)
- {
- int ret = level;
- for (int i = level; i > 1; i--)
- {
- if (d3d.CheckDeviceMultisampleType(0, DeviceType.Hardware, Format.Unknown,
- !Game.Current.Config.GetBool("renderer.fullScreen"), (MultisampleType)i))
- {
- ret = i;
- continue;
- }
- }
- if(ret != level)
- Game.Current.Log.Print("Picked MSAA x" + ret + " , as your GPU doesn't support desired level");
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement