public XnaComponentRenderer(XnaComponent component = null) { _component = component; IsVisibleChanged += OnIsVisibleChanged; SizeChanged += OnSizeChanged; Loaded += OnLoaded; Unloaded += OnUnloaded; }
public GraphicsDeviceManager([NotNull] XnaComponent owner) { if (owner == null) { throw new ArgumentNullException("owner"); } _owner = owner; _owner.Services.AddService(typeof(IGraphicsDeviceService), this); _owner.Services.AddService(typeof(IGraphicsDeviceManager), this); _owner.TargetSizeChanged += OnOwnerSizeChanged; UpdateClientBounds(_owner.TargetSize); }
public static GraphicsDeviceManager CreateDeviceManager(XnaComponent owner) { var deviceManager = new GraphicsDeviceManager(owner) { PreferMultiSampling = owner.GraphicsOptions.PreferMultiSampling, PreferredBackBufferFormat = SurfaceFormat.Color, PreferredDepthStencilFormat = DepthFormat.Depth24 }; deviceManager.PreparingDeviceSettings += (sender, args) => { var deviceType = args.GraphicsDeviceInformation.DeviceType; args.GraphicsDeviceInformation.PresentationParameters.EnableAutoDepthStencil = owner.GraphicsOptions.EnableDepthStencil; if (!owner.GraphicsOptions.PreferAnisotropicFiltering || deviceType != DeviceType.Hardware) { return; } deviceManager.DeviceCreated += (s, e) => { var device = deviceManager.GraphicsDevice; var deviceCapabilities = device.GraphicsDeviceCapabilities; /* * If the graphics adapter supports anisotropic filtering, then enable it with * the the desired level of anisotropy, or the highest level supported (whichever * is lower). */ if (deviceCapabilities.TextureFilterCapabilities.SupportsMinifyAnisotropic && deviceCapabilities.TextureFilterCapabilities.SupportsMagnifyAnisotropic) { device.SamplerStates[0].MinFilter = TextureFilter.Anisotropic; device.SamplerStates[0].MagFilter = TextureFilter.Anisotropic; device.SamplerStates[0].MaxAnisotropy = Math.Min( deviceCapabilities.MaxAnisotropy, DesiredMaxAnisotropy); } }; }; return(deviceManager); }