private bool CheckDeviceType(Direct3D d3d, out DeviceType dType, out MultisampleType mType, out int mQuality) { dType = DeviceType.Hardware; mType = MultisampleType.EightSamples; mQuality = 0; //if (!d3d.CheckDeviceType(0, dType, Format.X8R8G8B8, Format.D16, true)) //{ // dType = DeviceType.Reference; // if (!d3d.CheckDeviceType(0, dType, Format.X8R8G8B8, Format.D16, true)) // return false; //} if (!d3d.CheckDeviceMultisampleType(0, dType, Format.X8R8G8B8, true, mType, out mQuality) || !d3d.CheckDeviceMultisampleType(0, dType, Format.D16, true, mType, out mQuality) || mQuality < 1) { mType = MultisampleType.FourSamples; if (!d3d.CheckDeviceMultisampleType(0, dType, Format.X8R8G8B8, true, mType, out mQuality) || !d3d.CheckDeviceMultisampleType(0, dType, Format.D16, true, mType, out mQuality) || mQuality < 1) { mType = MultisampleType.TwoSamples; if (!d3d.CheckDeviceMultisampleType(0, dType, Format.X8R8G8B8, true, mType, out mQuality) || !d3d.CheckDeviceMultisampleType(0, dType, Format.D16, true, mType, out mQuality) || mQuality < 1) { mType = MultisampleType.None; } } } return(true); }
public void Allocate(int width, int height, Format format, MultisampleType multisampleType, int multisampleQuality, bool lockable) { bool free; lock (_syncObj) free = width != _size.Width || height != _size.Height || format != _format; if (free) { Free(); } lock (_syncObj) { if (_surface != null) { return; } _size.Width = width; _size.Height = height; _format = format; _surface = Surface.CreateRenderTarget(GraphicsDevice.Device, width, height, format, multisampleType, multisampleQuality, lockable); } AllocationChanged(AllocationSize); KeepAlive(); }
public D3D9DepthBuffer( PoolId poolId, D3DRenderSystem renderSystem, Device creator, Surface depthBufferSurf, Format fmt, int width, int height, MultisampleType fsaa, int multiSampleQuality, bool isManual) : base(poolId, 0, width, height, (int)fsaa, "", isManual) { depthBuffer = depthBufferSurf; this.creator = creator; this.multiSampleQuality = multiSampleQuality; d3dFormat = fmt; this.renderSystem = renderSystem; switch (fmt) { case Format.D16Lockable: case Format.D15S1: case Format.D16: bitDepth = 16; break; case Format.D32: case Format.D24S8: case Format.D24X8: case Format.D24X4S4: case Format.D32Lockable: case Format.D24SingleS8: bitDepth = 32; break; } }
public void TestMultiamplingTypes(MultisampleType multisampleType) { var deviceWorkerSettings = new DeviceWorker.DeviceSettings { AutoDetermineMultisampleType = false, MultisampleType = multisampleType }; DirectXScene scene = null; OffscreenDirectXDrawer offscreenDrawer = null; try { var deviceWorker = new DeviceWorker(deviceWorkerSettings); using(var renderTarget = deviceWorker.Device.GetRenderTarget(0)) Assert.AreEqual(multisampleType, renderTarget.Description.MultisampleType); scene = new DirectXScene(deviceWorker, _rootBody, null); offscreenDrawer = new OffscreenDirectXDrawer(scene, Width, Height, ImageFormat); _rootBody.Add(RedBox); var camera = new TopViewCamera(new Frame3D(0, 0, 200), Width / Height); byte[] bitmapBytes; offscreenDrawer.TryGetImage(camera, out bitmapBytes); var bitmap = new Bitmap(new MemoryStream(bitmapBytes)); CheckImageSize(Width, Height, bitmap); CheckBitmapCenter(bitmap, Color.Red); } finally { if(offscreenDrawer != null) offscreenDrawer.Dispose(); if(scene != null) scene.DeviceWorker.TryDispose(); } }
/// <summary> /// Build presentation parameters from the given settings. /// </summary> /// <param name="configuration">Graphics configuration to use.</param> public PresentParameters BuildPresentParamsFromSettings(D3DConfiguration configuration) { int backBufferWidth; int backBufferHeight; if (configuration.DeviceCombo.IsWindowed) { backBufferWidth = _renderTarget.ClientRectangle.Width; backBufferHeight = _renderTarget.ClientRectangle.Height; } else { backBufferWidth = configuration.DisplayMode.Width; backBufferHeight = configuration.DisplayMode.Height; } ServiceRegistration.Get <ILogger>().Debug("BuildPresentParamsFromSettings: Windowed = {0}, {1} x {2}", configuration.DeviceCombo.IsWindowed, backBufferWidth, backBufferHeight); PresentParameters result = new PresentParameters(); AppSettings settings = ServiceRegistration.Get <ISettingsManager>().Load <AppSettings>(); DeviceCombo dc = configuration.DeviceCombo; MultisampleType mst = settings.MultisampleType; mst = dc.MultisampleTypes.ContainsKey(mst) ? mst : MultisampleType.None; result.Multisample = mst; result.MultisampleQuality = 0; result.EnableAutoDepthStencil = false; result.AutoDepthStencilFormat = dc.DepthStencilFormats.FirstOrDefault(dsf => !dc.DepthStencilMultiSampleConflicts.Contains(new DepthStencilMultiSampleConflict { DepthStencilFormat = dsf, MultisampleType = mst })); // Note that PresentFlags.Video makes NVidia graphics drivers switch off multisampling antialiasing result.PresentFlags = PresentFlags.None; result.DeviceWindowHandle = _renderTarget.Handle; result.Windowed = configuration.DeviceCombo.IsWindowed; result.BackBufferFormat = configuration.DeviceCombo.BackBufferFormat; #if PROFILE_PERFORMANCE result.BackBufferCount = 20; // Such high backbuffer count is only useful for benchmarking so that rendering is not limited by backbuffer count result.PresentationInterval = PresentInterval.One; #else result.BackBufferCount = 4; // 2 to 4 are recommended for FlipEx swap mode result.PresentationInterval = PresentInterval.One; #endif result.FullScreenRefreshRateInHertz = result.Windowed ? 0 : configuration.DisplayMode.RefreshRate; // From http://msdn.microsoft.com/en-us/library/windows/desktop/bb173422%28v=vs.85%29.aspx : // To use multisampling, the SwapEffect member of D3DPRESENT_PARAMETER must be set to D3DSWAPEFFECT_DISCARD. // SwapEffect must be set to SwapEffect.FlipEx to support the Present property to be Present.ForceImmediate // (see http://msdn.microsoft.com/en-us/library/windows/desktop/bb174343%28v=vs.85%29.aspx ) result.SwapEffect = mst == MultisampleType.None ? SwapEffect.FlipEx : SwapEffect.Discard; result.BackBufferWidth = backBufferWidth; result.BackBufferHeight = backBufferHeight; return(result); }
public override void Load() { _multisampleTypes = new List <MultisampleType>(GraphicsDevice.Setup.MultisampleTypes); MultisampleType selectedMsType = SettingsManager.Load <AppSettings>().MultisampleType; Selected = _multisampleTypes.IndexOf(selectedMsType); // Fill items _items = _multisampleTypes.Select(mst => LocalizationHelper.CreateStaticString(mst.ToString())).ToList(); }
public RenderWindow(int width, int height, Device device) { Width = width; Height = height; _device = device; _surfaceSettingsChanged = true; _multisampleType = new Direct3DEx().CheckDeviceMultisampleType(0, DeviceType.Hardware, Format.X8R8G8B8, true, MultisampleType.FourSamples) ? MultisampleType.FourSamples : MultisampleType.None; }
public Surface GetRenderSurfaceUnsafe(IDirectXDrawer drawer, Size size) { CheckSize(size); lock (DeviceLock) { _requestedSizes[drawer] = size; Format format = _deviceSettings.PresentParameters.BackBufferFormat; MultisampleType multisampleType = _deviceSettings.PresentParameters.Multisample; int multisampleQuality = _deviceSettings.PresentParameters.MultisampleQuality; return(Surface.CreateRenderTarget(Device, size.Width, size.Height, format, multisampleType, multisampleQuality, false)); } }
/// <summary> /// Initializes a new instance of the <see cref="PresentParameters"/> struct. /// </summary> /// <param name="backBufferWidth">Width of the back buffer.</param> /// <param name="backBufferHeight">Height of the back buffer.</param> /// <param name="backBufferFormat">The back buffer format.</param> /// <param name="backBufferCount">The back buffer count.</param> /// <param name="multiSampleType">Type of the multi sample.</param> /// <param name="multiSampleQuality">The multi sample quality.</param> /// <param name="swapEffect">The swap effect.</param> /// <param name="deviceWindowHandle">The device window handle.</param> /// <param name="windowed">if set to <c>true</c> [windowed].</param> /// <param name="enableAutoDepthStencil">if set to <c>true</c> [enable auto depth stencil].</param> /// <param name="autoDepthStencilFormat">The auto depth stencil format.</param> /// <param name="presentFlags">The present flags.</param> /// <param name="fullScreenRefreshRateInHz">The full screen refresh rate in hz.</param> /// <param name="presentationInterval">The presentation interval.</param> public PresentParameters(int backBufferWidth, int backBufferHeight, Format backBufferFormat, int backBufferCount, MultisampleType multiSampleType, int multiSampleQuality, SwapEffect swapEffect, IntPtr deviceWindowHandle, bool windowed, bool enableAutoDepthStencil, Format autoDepthStencilFormat, PresentFlags presentFlags, int fullScreenRefreshRateInHz, PresentInterval presentationInterval) { BackBufferWidth = backBufferWidth; BackBufferHeight = backBufferHeight; BackBufferFormat = backBufferFormat; BackBufferCount = backBufferCount; MultiSampleType = multiSampleType; MultiSampleQuality = multiSampleQuality; SwapEffect = swapEffect; DeviceWindowHandle = deviceWindowHandle; Windowed = windowed; EnableAutoDepthStencil = enableAutoDepthStencil; AutoDepthStencilFormat = autoDepthStencilFormat; PresentFlags = presentFlags; FullScreenRefreshRateInHz = fullScreenRefreshRateInHz; PresentationInterval = presentationInterval; }
/// <summary> /// Initializes a new instance of the <see cref="PresentParameters"/> struct. /// </summary> /// <param name="backBufferWidth">Width of the back buffer.</param> /// <param name="backBufferHeight">Height of the back buffer.</param> /// <param name="backBufferFormat">The back buffer format.</param> /// <param name="backBufferCount">The back buffer count.</param> /// <param name="multiSampleType">Type of the multi sample.</param> /// <param name="multiSampleQuality">The multi sample quality.</param> /// <param name="swapEffect">The swap effect.</param> /// <param name="deviceWindowHandle">The device window handle.</param> /// <param name="windowed">if set to <c>true</c> [windowed].</param> /// <param name="enableAutoDepthStencil">if set to <c>true</c> [enable auto depth stencil].</param> /// <param name="autoDepthStencilFormat">The auto depth stencil format.</param> /// <param name="presentFlags">The present flags.</param> /// <param name="fullScreenRefreshRateInHz">The full screen refresh rate in Hz.</param> /// <param name="presentationInterval">The presentation interval.</param> public PresentParameters(int backBufferWidth, int backBufferHeight, Format backBufferFormat, int backBufferCount, MultisampleType multiSampleType, int multiSampleQuality, SwapEffect swapEffect, IntPtr deviceWindowHandle, bool windowed, bool enableAutoDepthStencil, Format autoDepthStencilFormat, PresentFlags presentFlags, int fullScreenRefreshRateInHz, PresentInterval presentationInterval) { BackBufferWidth = backBufferWidth; BackBufferHeight = backBufferHeight; BackBufferFormat = backBufferFormat; BackBufferCount = backBufferCount; MultiSampleType = multiSampleType; MultiSampleQuality = multiSampleQuality; SwapEffect = swapEffect; DeviceWindowHandle = deviceWindowHandle; Windowed = windowed; EnableAutoDepthStencil = enableAutoDepthStencil; AutoDepthStencilFormat = autoDepthStencilFormat; PresentFlags = presentFlags; FullScreenRefreshRateInHz = fullScreenRefreshRateInHz; PresentationInterval = presentationInterval; }
public void Allocate(int width, int height, Format format, MultisampleType multisampleType, int multisampleQuality, bool lockable) { bool free; lock (_syncObj) free = width != _size.Width || height != _size.Height || format != _format; if (free) Free(); lock (_syncObj) { if (_surface != null) return; _size.Width = width; _size.Height = height; _format = format; _surface = Surface.CreateRenderTarget(GraphicsDevice.Device, width, height, format, multisampleType, multisampleQuality, lockable); } AllocationChanged(AllocationSize); KeepAlive(); }
public void TestMultiamplingTypes(MultisampleType multisampleType) { var deviceWorkerSettings = new DeviceWorker.DeviceSettings { AutoDetermineMultisampleType = false, MultisampleType = multisampleType }; DirectXScene scene = null; OffscreenDirectXDrawer offscreenDrawer = null; try { var deviceWorker = new DeviceWorker(deviceWorkerSettings); using (var renderTarget = deviceWorker.Device.GetRenderTarget(0)) Assert.AreEqual(multisampleType, renderTarget.Description.MultisampleType); scene = new DirectXScene(deviceWorker, _rootBody, null); offscreenDrawer = new OffscreenDirectXDrawer(scene, Width, Height, ImageFormat); _rootBody.Add(RedBox); var camera = new TopViewCamera(new Frame3D(0, 0, 200), Width / Height); byte[] bitmapBytes; offscreenDrawer.TryGetImage(camera, out bitmapBytes); var bitmap = new Bitmap(new MemoryStream(bitmapBytes)); CheckImageSize(Width, Height, bitmap); CheckBitmapCenter(bitmap, Color.Red); } finally { if (offscreenDrawer != null) { offscreenDrawer.Dispose(); } if (scene != null) { scene.DeviceWorker.TryDispose(); } } }
private Result CreateRenderTarget(IntPtr devicePointer, int width, int height, Format format, MultisampleType multiSampleType, int multiSampleQuality, bool lockable, out IntPtr surface, IntPtr sharedHandle) { try { this.Log.LogMethodSignatureTypesAndValues(devicePointer, width, height, format, multiSampleType, multiSampleQuality, lockable, "out", sharedHandle); this.GetOrCreateDevice(devicePointer); this.Surfaces.Add(sharedHandle == IntPtr.Zero ? Surface.CreateRenderTarget(this.Device, width, height, format, multiSampleType, multiSampleQuality, lockable) : Surface.CreateRenderTarget(this.Device, width, height, format, multiSampleType, multiSampleQuality, lockable, ref sharedHandle)); surface = this.Surfaces.Last().NativePointer; return Result.Ok; } catch (SharpDXException ex) { Log.Warn(ex); surface = IntPtr.Zero; return ex.ResultCode; } catch (Exception ex) { this.Log.Fatal(ex); surface = IntPtr.Zero; return Result.UnexpectedFailure; } }
/// <summary> /// Allocates a new render-texture with the specified parameters. /// </summary> public void AllocateCustom(int width, int height, Format format, MultisampleType multisampleType, int multisampleQuality, bool lockable) { _assetCore.Allocate(width, height, format, multisampleType, multisampleQuality, lockable); }
private void loadFromRegistry(RegistryKey key) { var strMs = (string)key.GetValue("Multisampling"); MultisampleType ms; if (Enum.TryParse<MultisampleType>(strMs, out ms) == false) throw new InvalidOperationException("Registry has stored an invalid Multisampling!"); Multisampling = ms; uint msq = 0; if (uint.TryParse((string)key.GetValue("MultisampleQuality"), out msq) == false) throw new InvalidOperationException("Registry has stored an invalid multisample quality!"); MultisampleQuality = msq; TextureFilterMode fm; if (Enum.TryParse<TextureFilterMode>((string)key.GetValue("TextureFilter"), out fm) == false) throw new InvalidOperationException("Registry has stored an invalid filter mode!"); Filtering = fm; if (uint.TryParse((string)key.GetValue("Anisotropy"), out msq) == false) throw new InvalidOperationException("Registry has stored an invalid anisotropy value!"); Anisotropy = msq; if (uint.TryParse((string)key.GetValue("AdapterOrdinal"), out msq) == false) throw new InvalidOperationException("Registry has stored an invalid adapter ordinal!"); Adapter = Game.GameManager.GraphicsThread.GraphicsManager.Direct3D.GetAdapterIdentifier((int)msq); Format fmt; if (Enum.TryParse<Format>((string)key.GetValue("DepthStencil"), out fmt) == false) throw new InvalidOperationException("Registry has stored an invalid depth stencil format!"); DepthStencilFormat = fmt; }
/// <summary> /// Determines if a multisampling technique is available on this device. /// </summary> /// <param name="adapter">The adapter.</param> /// <param name="deviceType">Type of the device.</param> /// <param name="surfaceFormat">The surface format.</param> /// <param name="windowed">if set to <c>true</c> [windowed].</param> /// <param name="multisampleType">Type of the multisample.</param> /// <returns> /// f the device can perform the specified multisampling method, this method returns <c>true</c> /// </returns> /// <unmanaged>HRESULT IDirect3D9::CheckDeviceMultiSampleType([In] unsigned int Adapter,[In] D3DDEVTYPE DeviceType,[In] D3DFORMAT SurfaceFormat,[In] BOOL Windowed,[In] D3DMULTISAMPLE_TYPE MultiSampleType,[Out] unsigned int* pQualityLevels)</unmanaged> public bool CheckDeviceMultisampleType(int adapter, DeviceType deviceType, Format surfaceFormat, bool windowed, MultisampleType multisampleType) { int qualityLevels; return CheckDeviceMultiSampleType_(adapter, deviceType, surfaceFormat, windowed, multisampleType, out qualityLevels) == 0; }
public unsafe IDirect3DSurface9 CreateRenderTargetEx(int width, int height, Format format, MultisampleType multiSample, int multisampleQuality, bool lockable, ref IntPtr sharedHandle, Usage usage) { fixed(void *pSharedHandle = &sharedHandle) { return(CreateRenderTargetEx_(width, height, format, multiSample, multisampleQuality, lockable, new IntPtr(pSharedHandle), usage)); } }
static public void Hook06000005(ref Direct3D d3d, ref Device device, ref PresentParameters param, Control control, bool windowed, Size size, int quality) { fullscreen |= !windowed; d3d = new Direct3D(); int adapter = d3d.Adapters.DefaultAdapter.Adapter; Capabilities deviceCaps = d3d.GetDeviceCaps(adapter, DeviceType.Hardware); DeviceType deviceType = deviceCaps.DeviceType; CreateFlags createFlags = (deviceCaps.VertexShaderVersion >= new Version(2, 0)) ? CreateFlags.HardwareVertexProcessing : CreateFlags.SoftwareVertexProcessing; param = new PresentParameters(); param.SwapEffect = SwapEffect.Discard; DisplayMode currentDisplayMode = d3d.Adapters[adapter].CurrentDisplayMode; param.Windowed = (windowed || !d3d.CheckDeviceType(adapter, DeviceType.Hardware, currentDisplayMode.Format, currentDisplayMode.Format, false)); if (param.Windowed) { param.DeviceWindowHandle = control.Handle; if (!fullscreen) { param.BackBufferWidth = 0; param.BackBufferHeight = 0; } else { param.BackBufferWidth = size.Width; param.BackBufferHeight = size.Height; control.ClientSize = new Size(currentDisplayMode.Width, currentDisplayMode.Height); control.Location = new Point(0, 0); } } else { param.BackBufferFormat = currentDisplayMode.Format; param.BackBufferCount = 1; if (size.Width == 0 || size.Height == 0) { size = new Size(currentDisplayMode.Width, currentDisplayMode.Height); } param.BackBufferWidth = size.Width; param.BackBufferHeight = size.Height; param.PresentFlags = PresentFlags.LockableBackBuffer; control.ClientSize = new Size(currentDisplayMode.Width, currentDisplayMode.Height); control.Location = new Point(0, 0); } if (d3d.CheckDeviceFormat(adapter, DeviceType.Hardware, currentDisplayMode.Format, Usage.DepthStencil, ResourceType.Surface, Format.D24S8)) { param.EnableAutoDepthStencil = true; param.AutoDepthStencilFormat = Format.D24S8; } MultisampleType multisampleType = quality <= 1 ? MultisampleType.None : MultisampleType.NonMaskable; while (multisampleType > MultisampleType.None) { int val; int val2; if (d3d.CheckDeviceMultisampleType(adapter, deviceType, param.BackBufferFormat, param.Windowed, multisampleType, out val) && d3d.CheckDeviceMultisampleType(adapter, deviceType, Format.D24S8, param.Windowed, multisampleType, out val2)) { param.Multisample = multisampleType; if (multisampleType == MultisampleType.NonMaskable) { param.MultisampleQuality = Math.Min(Math.Min(val, val2) - 1, (int)Math.Log(quality, 2) - 1); break; } break; } else { multisampleType--; } } param.PresentationInterval = PresentInterval.One; device = new Device(d3d, adapter, deviceType, control.Handle, createFlags, new PresentParameters[] { param }); }
public IDirect3DSurface9 CreateRenderTarget(int width, int height, Format format, MultisampleType multiSample, int multisampleQuality, bool lockable) { return(CreateRenderTarget(width, height, format, multiSample, multisampleQuality, lockable, IntPtr.Zero)); }
/// <summary> /// Determines if a multisampling technique is available on this device. /// </summary> /// <param name="adapter">The adapter.</param> /// <param name="deviceType">Type of the device.</param> /// <param name="surfaceFormat">The surface format.</param> /// <param name="windowed">if set to <c>true</c> [windowed].</param> /// <param name="multisampleType">Type of the multisample.</param> /// <returns> /// f the device can perform the specified multisampling method, this method returns <c>true</c> /// </returns> /// <unmanaged>HRESULT IDirect3D9::CheckDeviceMultiSampleType([In] unsigned int Adapter,[In] D3DDEVTYPE DeviceType,[In] D3DFORMAT SurfaceFormat,[In] BOOL Windowed,[In] D3DMULTISAMPLE_TYPE MultiSampleType,[Out] unsigned int* pQualityLevels)</unmanaged> public bool CheckDeviceMultisampleType(int adapter, DeviceType deviceType, Format surfaceFormat, bool windowed, MultisampleType multisampleType) { int qualityLevels; return(CheckDeviceMultiSampleType_(adapter, deviceType, surfaceFormat, windowed, multisampleType, out qualityLevels) == 0); }
public static Sampling Sampling(MultisampleType multisampleType, int multisampleQuality) { return new Sampling { Count = multisampleType == MultisampleType.None ? (ushort)1 : (ushort)multisampleType, Quality = (ushort)multisampleQuality }; }
/// <summary> /// Determines if a multisampling technique is available on this device. /// </summary> /// <param name="adapter">The adapter.</param> /// <param name="deviceType">Type of the device.</param> /// <param name="surfaceFormat">The surface format.</param> /// <param name="windowed">if set to <c>true</c> [windowed].</param> /// <param name="multisampleType">Type of the multisample.</param> /// <param name="qualityLevels">The quality levels.</param> /// <param name="result">The result.</param> /// <returns>f the device can perform the specified multisampling method, this method returns <c>true</c></returns> /// <unmanaged>HRESULT IDirect3D9::CheckDeviceMultiSampleType([In] unsigned int Adapter,[In] D3DDEVTYPE DeviceType,[In] D3DFORMAT SurfaceFormat,[In] BOOL Windowed,[In] D3DMULTISAMPLE_TYPE MultiSampleType,[Out] unsigned int* pQualityLevels)</unmanaged> public bool CheckDeviceMultisampleType(int adapter, DeviceType deviceType, Format surfaceFormat, bool windowed, MultisampleType multisampleType, out int qualityLevels, out Result result) { result = CheckDeviceMultiSampleType_(adapter, deviceType, surfaceFormat, windowed, multisampleType, out qualityLevels); return result == 0; }
private Result CreateRenderTarget(IntPtr devicePointer, int width, int height, Format format, MultisampleType multiSampleType, int multiSampleQuality, bool lockable, out IntPtr surface, IntPtr sharedHandle) { try { this.Log.LogMethodSignatureTypesAndValues(devicePointer, width, height, format, multiSampleType, multiSampleQuality, lockable, "out", sharedHandle); this.GetOrCreateDevice(devicePointer); this.Surfaces.Add(sharedHandle == IntPtr.Zero ? Surface.CreateRenderTarget(this.Device, width, height, format, multiSampleType, multiSampleQuality, lockable) : Surface.CreateRenderTarget(this.Device, width, height, format, multiSampleType, multiSampleQuality, lockable, ref sharedHandle)); surface = this.Surfaces.Last().NativePointer; return(Result.Ok); } catch (SharpDXException ex) { Log.Warn(ex); surface = IntPtr.Zero; return(ex.ResultCode); } catch (Exception ex) { this.Log.Fatal(ex); surface = IntPtr.Zero; return(Result.UnexpectedFailure); } }
public unsafe IDirect3DSurface9 CreateDepthStencilSurfaceEx(int width, int height, Format format, MultisampleType multiSample, int multisampleQuality, bool discard, ref IntPtr sharedHandle, Usage usage) { fixed(void *pSharedHandle = &sharedHandle) { return(CreateDepthStencilSurfaceEx_(width, height, format, multiSample, multisampleQuality, discard, new IntPtr(pSharedHandle), usage)); } }
public IDirect3DSurface9 CreateDepthStencilSurfaceEx(int width, int height, Format format, MultisampleType multiSample, int multisampleQuality, bool discard, Usage usage) { return(CreateDepthStencilSurfaceEx_(width, height, format, multiSample, multisampleQuality, discard, IntPtr.Zero, usage)); }
/// <summary>To be documented.</summary> public readonly int CheckDeviceMultiSampleType(uint Adapter, Devtype DeviceType, Format SurfaceFormat, int Windowed, MultisampleType MultiSampleType, ref uint pQualityLevels) { var @this = (IDirect3D9 *)Unsafe.AsPointer(ref Unsafe.AsRef(in this)); int ret = default; fixed(uint *pQualityLevelsPtr = &pQualityLevels) { ret = ((delegate * unmanaged[Cdecl] < IDirect3D9 *, uint, Devtype, Format, int, MultisampleType, uint *, int >)LpVtbl[11])(@this, Adapter, DeviceType, SurfaceFormat, Windowed, MultiSampleType, pQualityLevelsPtr); } return(ret); }
/// <summary> /// Determines if a multisampling technique is available on this device. /// </summary> /// <param name="adapter">The adapter.</param> /// <param name="deviceType">Type of the device.</param> /// <param name="surfaceFormat">The surface format.</param> /// <param name="windowed">if set to <c>true</c> [windowed].</param> /// <param name="multisampleType">Type of the multisample.</param> /// <param name="qualityLevels">The quality levels.</param> /// <param name="result">The result.</param> /// <returns>f the device can perform the specified multisampling method, this method returns <c>true</c></returns> /// <unmanaged>HRESULT IDirect3D9::CheckDeviceMultiSampleType([In] unsigned int Adapter,[In] D3DDEVTYPE DeviceType,[In] D3DFORMAT SurfaceFormat,[In] BOOL Windowed,[In] D3DMULTISAMPLE_TYPE MultiSampleType,[Out] unsigned int* pQualityLevels)</unmanaged> public bool CheckDeviceMultisampleType(int adapter, DeviceType deviceType, Format surfaceFormat, bool windowed, MultisampleType multisampleType, out int qualityLevels, out Result result) { result = CheckDeviceMultiSampleType_(adapter, deviceType, surfaceFormat, windowed, multisampleType, out qualityLevels); return(result == 0); }
public IDirect3DSurface9 CreateDepthStencilSurface(int width, int height, Format format, MultisampleType multiSample, int multisampleQuality, bool discard) { return(CreateDepthStencilSurface(width, height, format, multiSample, multisampleQuality, discard)); }
public static float RankSettingsCombo(SettingsCombo9 combo, Direct3D9Settings optimal, DisplayMode desktopMode) { float ranking = 0.0f; if (combo.AdapterOrdinal == optimal.AdapterOrdinal) { ranking += 1000.0f; } if (combo.DeviceType == optimal.DeviceType) { ranking += 100.0f; } if (combo.DeviceType == DeviceType.Hardware) { ranking += 0.1f; } if (combo.Windowed == optimal.PresentParameters.Windowed) { ranking += 10.0f; } if (combo.AdapterFormat == optimal.AdapterFormat) { ranking += 1.0f; } else { int bitDepthDelta = Math.Abs(ConversionMethods.GetColorBits(combo.AdapterFormat) - ConversionMethods.GetColorBits(optimal.AdapterFormat)); float scale = Math.Max(0.9f - bitDepthDelta * 0.2f, 0.0f); ranking += scale; } if (!combo.Windowed) { bool match; if (ConversionMethods.GetColorBits(desktopMode.Format) >= 8) { match = (combo.AdapterFormat == desktopMode.Format); } else { match = (combo.AdapterFormat == Format.X8R8G8B8); } if (match) { ranking += 0.1f; } } if ((optimal.CreationFlags & CreateFlags.HardwareVertexProcessing) != 0 && (optimal.CreationFlags & CreateFlags.MixedVertexProcessing) != 0) { if ((combo.DeviceInfo.Capabilities.DeviceCaps & DeviceCaps.HWTransformAndLight) != 0) { ranking += 1.0f; } } if ((combo.DeviceInfo.Capabilities.DeviceCaps & DeviceCaps.HWTransformAndLight) != 0) { ranking += 0.1f; } foreach (DisplayMode displayMode in combo.AdapterInfo.DisplayModes) { if (displayMode.Format == combo.AdapterFormat && displayMode.Width == optimal.PresentParameters.BackBufferWidth && displayMode.Height == optimal.PresentParameters.BackBufferHeight) { ranking += 1.0f; break; } } if (combo.BackBufferFormat == optimal.PresentParameters.BackBufferFormat) { ranking += 1.0f; } else { int bitDepthDelta = Math.Abs(ConversionMethods.GetColorBits(combo.BackBufferFormat) - ConversionMethods.GetColorBits(optimal.PresentParameters.BackBufferFormat)); float scale = Math.Max(0.9f - bitDepthDelta * 0.2f, 0.0f); ranking += scale; } if (combo.BackBufferFormat == combo.AdapterFormat) { ranking += 0.1f; } for (int i = 0; i < combo.MultisampleTypes.Count; i++) { MultisampleType type = combo.MultisampleTypes[i]; int quality = combo.MultisampleQualities[i]; if (type == optimal.PresentParameters.MultiSampleType && quality == optimal.PresentParameters.MultiSampleQuality) { ranking += 1.0f; break; } } if (combo.DepthStencilFormats.Contains(optimal.PresentParameters.AutoDepthStencilFormat)) { ranking += 1.0f; } foreach (DisplayMode displayMode in combo.AdapterInfo.DisplayModes) { if (displayMode.Format == combo.AdapterFormat && displayMode.RefreshRate == optimal.PresentParameters.FullScreenRefreshRateInHz) { ranking += 1.0f; break; } } if (combo.PresentIntervals.Contains(optimal.PresentParameters.PresentationInterval)) { ranking += 1.0f; } return(ranking); }
internal void DetermineFSAASettings(Device d3D9Device, int fsaa, string fsaaHint, Format d3DPixelFormat, bool fullScreen, out MultisampleType outMultisampleType, out int outMultisampleQuality) { outMultisampleType = MultisampleType.None; outMultisampleQuality = 0; var ok = false; var qualityHint = fsaaHint.Contains("Quality"); var origFSAA = fsaa; var driverList = Direct3DDrivers; var deviceDriver = _activeD3DDriver; var device = _deviceManager.GetDeviceFromD3D9Device(d3D9Device); foreach (var currDriver in driverList) { if ( currDriver.AdapterNumber != device.AdapterNumber ) continue; deviceDriver = currDriver; break; } var tryCsaa = false; // NVIDIA, prefer CSAA if available for 8+ // it would be tempting to use getCapabilities()->getVendor() == GPU_NVIDIA but // if this is the first window, caps will not be initialised yet if (deviceDriver.AdapterIdentifier.VendorId == 0x10DE && fsaa >= 8) { tryCsaa = true; } while (!ok) { // Deal with special cases if (tryCsaa) { // see http://developer.nvidia.com/object/coverage-sampled-aa.html switch(fsaa) { case 8: if (qualityHint) { outMultisampleType = MultisampleType.EightSamples; outMultisampleQuality = 0; } else { outMultisampleType = MultisampleType.FourSamples; outMultisampleQuality = 2; } break; case 16: if (qualityHint) { outMultisampleType = MultisampleType.EightSamples; outMultisampleQuality = 2; } else { outMultisampleType = MultisampleType.FourSamples; outMultisampleQuality = 4; } break; } } else // !CSAA { outMultisampleType = (MultisampleType)fsaa; outMultisampleQuality = 0; } int outQuality; var hr = _pD3D.CheckDeviceMultisampleType( deviceDriver.AdapterNumber, DeviceType.Hardware, d3DPixelFormat, fullScreen, outMultisampleType, out outQuality ); if (hr && (!tryCsaa || outQuality > outMultisampleQuality)) { ok = true; } else { // downgrade if (tryCsaa && fsaa == 8) { // for CSAA, we'll try downgrading with quality mode at all samples. // then try without quality, then drop CSAA if (qualityHint) { // drop quality first qualityHint = false; } else { // drop CSAA entirely tryCsaa = false; } // return to original requested samples fsaa = origFSAA; } else { // drop samples --fsaa; if (fsaa == 1) { // ran out of options, no FSAA fsaa = 0; ok = true; } } } } // while !ok }
public static Direct3D9Settings BuildValidSettings(SettingsCombo9 combo, Direct3D9Settings input) { Direct3D9Settings settings = new Direct3D9Settings(); var pp = settings.PresentParameters; settings.AdapterOrdinal = combo.AdapterOrdinal; settings.DeviceType = combo.DeviceType; settings.AdapterFormat = combo.AdapterFormat; pp.Windowed = combo.Windowed; pp.BackBufferFormat = combo.BackBufferFormat; pp.SwapEffect = input.PresentParameters.SwapEffect; pp.PresentFlags = input.PresentParameters.PresentFlags | PresentFlags.DiscardDepthStencil; settings.CreationFlags = input.CreationFlags; if ((combo.DeviceInfo.Capabilities.DeviceCaps & DeviceCaps.HWTransformAndLight) == 0 && ((settings.CreationFlags & CreateFlags.HardwareVertexProcessing) != 0 || (settings.CreationFlags & CreateFlags.MixedVertexProcessing) != 0)) { settings.CreationFlags &= ~CreateFlags.HardwareVertexProcessing; settings.CreationFlags &= ~CreateFlags.MixedVertexProcessing; settings.CreationFlags |= CreateFlags.SoftwareVertexProcessing; } if ((settings.CreationFlags & CreateFlags.HardwareVertexProcessing) == 0 && (settings.CreationFlags & CreateFlags.MixedVertexProcessing) == 0 && (settings.CreationFlags & CreateFlags.SoftwareVertexProcessing) == 0) { if ((combo.DeviceInfo.Capabilities.DeviceCaps & DeviceCaps.HWTransformAndLight) != 0) { settings.CreationFlags |= CreateFlags.HardwareVertexProcessing; } else { settings.CreationFlags |= CreateFlags.SoftwareVertexProcessing; } } DisplayMode bestDisplayMode = FindValidResolution(combo, input); pp.BackBufferWidth = bestDisplayMode.Width; pp.BackBufferHeight = bestDisplayMode.Height; pp.BackBufferCount = input.PresentParameters.BackBufferCount; if (pp.BackBufferCount > 3) { pp.BackBufferCount = 3; } if (pp.BackBufferCount < 1) { pp.BackBufferCount = 1; } if (input.PresentParameters.SwapEffect != SwapEffect.Discard) { pp.MultiSampleType = MultisampleType.None; pp.MultiSampleQuality = 0; } else { MultisampleType bestType = MultisampleType.None; int bestQuality = 0; for (int i = 0; i < combo.MultisampleTypes.Count; i++) { MultisampleType type = combo.MultisampleTypes[i]; int quality = combo.MultisampleQualities[i]; if (Math.Abs(type - input.PresentParameters.MultiSampleType) < Math.Abs(bestType - input.PresentParameters.MultiSampleType)) { bestType = type; bestQuality = Math.Min(quality - 1, input.PresentParameters.MultiSampleQuality); } } pp.MultiSampleType = bestType; pp.MultiSampleQuality = bestQuality; } List <int> rankings = new List <int>(); int inputDepthBitDepth = ConversionMethods.GetDepthBits(input.PresentParameters.AutoDepthStencilFormat); int inputStencilBitDepth = ConversionMethods.GetStencilBits(input.PresentParameters.AutoDepthStencilFormat); foreach (Format format in combo.DepthStencilFormats) { int currentBitDepth = ConversionMethods.GetDepthBits(format); int currentStencilDepth = ConversionMethods.GetStencilBits(format); int ranking = Math.Abs(currentBitDepth - inputDepthBitDepth); ranking += Math.Abs(currentStencilDepth - inputStencilBitDepth); rankings.Add(ranking); } int bestRanking = int.MaxValue; foreach (int ranking in rankings) { if (ranking < bestRanking) { bestRanking = ranking; } } int bestIndex = rankings.IndexOf(bestRanking); if (bestIndex >= 0) { pp.AutoDepthStencilFormat = combo.DepthStencilFormats[bestIndex]; pp.EnableAutoDepthStencil = true; } else { pp.AutoDepthStencilFormat = Format.Unknown; pp.EnableAutoDepthStencil = false; } if (combo.Windowed) { pp.FullScreenRefreshRateInHz = 0; } else { int match = input.PresentParameters.FullScreenRefreshRateInHz; bestDisplayMode.RefreshRate = 0; if (match != 0) { bestRanking = 100000; foreach (DisplayMode displayMode in combo.AdapterInfo.DisplayModes) { if (displayMode.Format != combo.AdapterFormat || displayMode.Width != bestDisplayMode.Width || displayMode.Height != bestDisplayMode.Height) { continue; } int ranking = Math.Abs(displayMode.RefreshRate - match); if (ranking < bestRanking) { bestDisplayMode.RefreshRate = displayMode.RefreshRate; bestRanking = ranking; if (bestRanking == 0) { break; } } } } pp.FullScreenRefreshRateInHz = bestDisplayMode.RefreshRate; } if (combo.PresentIntervals.Contains(input.PresentParameters.PresentationInterval)) { pp.PresentationInterval = input.PresentParameters.PresentationInterval; } else { pp.PresentationInterval = PresentInterval.Default; } settings.PresentParameters = pp; return(settings); }
private bool CheckMultiSampleQuality(MultisampleType type, out int outQuality, Format format, int adaptNum, DeviceType deviceType, bool fullScreen) { var hr = _pD3D.CheckDeviceMultisampleType( adaptNum, deviceType, format, fullScreen, type, out outQuality ); return hr; }
public static int CreateRenderTarget(IntPtr deviceHandle, int width, int height, Format format, MultisampleType multisample, int multisampleQuality, bool lockable, out IntPtr surfaceHandle, ref IntPtr sharedHandle) { IntPtr vTable = Marshal.ReadIntPtr(deviceHandle, 0); IntPtr functionPointer = Marshal.ReadIntPtr(vTable, CreateRenderTarget_Offset * IntPtr.Size); NativeCreateRenderTarget method = Marshal.GetDelegateForFunctionPointer <NativeCreateRenderTarget>(functionPointer); return(method(deviceHandle, width, height, format, multisample, multisampleQuality, lockable, out surfaceHandle, ref sharedHandle)); }