private static MyDisplayMode[] GetSupportedDisplayModes(Direct3D d3d, int adapterOrdinal) { var modeAvailable = new List <MyDisplayMode>(); var modeMap = new Dictionary <string, MyDisplayMode>(); SharpDX.Direct3D9.Format format = m_backbufferFormat; int modeCount = format == Format.Unknown ? 0 : d3d.GetAdapterModeCount(adapterOrdinal, format); for (int modeIndex = 0; modeIndex < modeCount; modeIndex++) { var mode = d3d.EnumAdapterModes(adapterOrdinal, (SharpDX.Direct3D9.Format)format, modeIndex); string key = format + ";" + mode.Width + ";" + mode.Height + ";" + mode.RefreshRate; MyDisplayMode oldMode; if (!modeMap.TryGetValue(key, out oldMode)) { var displayMode = new MyDisplayMode() { Width = mode.Width, Height = mode.Height, RefreshRate = mode.RefreshRate, AspectRatio = mode.AspectRatio }; modeMap.Add(key, displayMode); modeAvailable.Add(displayMode); } } modeAvailable.Sort(m_refreshRatePriorityComparer); return(modeAvailable.ToArray()); }
/// <summary> /// Sets the render target of this D3DImage object. /// </summary> /// <param name="renderTarget">The render target to set.</param> public void SetRenderTarget(D3D11.Texture2D renderTarget) { if (this.m_d3dRenderTarget != null) { this.m_d3dRenderTarget = null; base.Lock(); base.SetBackBuffer(D3DResourceType.IDirect3DSurface9, IntPtr.Zero); base.Unlock(); } if (renderTarget == null) { return; } if (!IsShareable(renderTarget)) { throw new ArgumentException("Texture must be created with ResourceOptionFlags.Shared"); } D3D9.Format format = HigherD3DImageSource.TranslateFormat(renderTarget); if (format == D3D9.Format.Unknown) { throw new ArgumentException("Texture format is not compatible with OpenSharedResource"); } IntPtr handle = GetSharedHandle(renderTarget); if (handle == IntPtr.Zero) { throw new ArgumentNullException("Handle"); } //Map the texture to the D3DImage base class bool tDisposed = renderTarget.IsDisposed; float tWidth = renderTarget.Description.Width; float tHeight = renderTarget.Description.Height; this.m_d3dRenderTarget = new D3D9.Texture( m_d3dDevice, renderTarget.Description.Width, renderTarget.Description.Height, 1, D3D9.Usage.RenderTarget, format, D3D9.Pool.Default, ref handle); using (D3D9.Surface surface = this.m_d3dRenderTarget.GetSurfaceLevel(0)) { base.Lock(); base.SetBackBuffer(D3DResourceType.IDirect3DSurface9, surface.NativePointer); base.Unlock(); } }
//--------------------------------------------------------------------------------------------------------- /// <summary> /// Установка в качестве источника поверхности ренденинга текстуры Direct3D11 /// </summary> /// <param name="render_target">Текстура Direct3D11</param> //--------------------------------------------------------------------------------------------------------- public void SetRenderTarget(Direct3D11.Texture2D render_target) { // Если есть наша поверхность ренденинга то обнуляем ее if (mRenderTarget != null) { mRenderTarget = null; base.Lock(); base.SetBackBuffer(D3DResourceType.IDirect3DSurface9, IntPtr.Zero); base.Unlock(); } if (render_target == null) { return; } if (!XDirect2DManager.IsShareable(render_target)) { throw new ArgumentException("Texture must be created with ResourceOptionFlags.Shared"); } Direct3D9.Format format = XDirect2DManager.TranslateFormat(render_target); if (format == Direct3D9.Format.Unknown) { throw new ArgumentException("Texture format is not compatible with OpenSharedResource"); } IntPtr handle = XDirect2DManager.GetSharedHandle(render_target); if (handle == IntPtr.Zero) { throw new ArgumentNullException("Handle"); } // Создаем в текстура для ренденинга mRenderTarget = new Direct3D9.Texture(XDirect2DManager.D3DDevice, render_target.Description.Width, render_target.Description.Height, 1, Direct3D9.Usage.RenderTarget, format, Direct3D9.Pool.Default, ref handle); // Получаем поверхность и обновляем представление using (Direct3D9.Surface surface = mRenderTarget.GetSurfaceLevel(0)) { base.Lock(); base.SetBackBuffer(D3DResourceType.IDirect3DSurface9, surface.NativePointer); base.Unlock(); } }
void aquireResources() { if (videoWidth == 0 || videoHeight == 0) { throw new VideoPlayerException("Cannot instantiate D3D surface with a width or height of 0 pixels"); } D3D.Format pixelFormat = makeFourCC('Y', 'V', '1', '2'); offscreen = D3D.Surface.CreateOffscreenPlain(device, videoWidth, videoHeight, pixelFormat, D3D.Pool.Default); screenShot = D3D.Surface.CreateOffscreenPlain(device, videoWidth, videoHeight, D3D.Format.A8R8G8B8, D3D.Pool.Default); backBuffer = device.GetBackBuffer(0, 0); FontDescription fontDescription = new FontDescription(); fontDescription.FaceName = "TimesNewRoman"; fontDescription.Height = 15; infoFont = new D3D.Font(device, fontDescription); fontDescription = new FontDescription(); fontDescription.FaceName = "Arial"; videoDestRect = getVideoDestRect(backBuffer); fontDescription.Height = videoDestRect.Height / 14; fontDescription.Quality = FontQuality.Antialiased; subtitleShadowOffset = fontDescription.Height / 18; subtitleBottomMargin = videoDestRect.Height / 12; subtitleFont = new D3D.Font(device, fontDescription); }
D3D.PresentParameters[] createPresentParams(bool windowed, System.Windows.Forms.Control owner) { D3D.PresentParameters[] presentParams = new D3D.PresentParameters[1]; //No Z (Depth) buffer or Stencil buffer presentParams[0].EnableAutoDepthStencil = false; //multiple backbuffers for a flipchain presentParams[0].BackBufferCount = 3; //Set our Window as the Device Window presentParams[0].DeviceWindowHandle = owner.Handle; //wait for VSync presentParams[0].PresentationInterval = D3D.PresentInterval.Immediate; //flip frames on vsync presentParams[0].SwapEffect = D3D.SwapEffect.Discard; //Set Windowed vs. Full-screen presentParams[0].Windowed = windowed; //We only need to set the Width/Height in full-screen mode if (!windowed) { presentParams[0].BackBufferHeight = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height; presentParams[0].BackBufferWidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width; D3D.Format format = D3D.Format.X8R8G8B8; //Choose a compatible 16-bit mode. presentParams[0].BackBufferFormat = format; } else { presentParams[0].BackBufferHeight = 0; presentParams[0].BackBufferWidth = 0; presentParams[0].BackBufferFormat = D3D.Format.Unknown; } return(presentParams); }
private void _enumerateByFormat(D3D9.Format format) { var pD3D = D3D9RenderSystem.Direct3D9; var adapter = this._mpDriver.AdapterNumber; for (var iMode = 0; iMode < pD3D.GetAdapterModeCount(adapter, format); iMode++) { var displayMode = pD3D.EnumAdapterModes(adapter, format, iMode); // Filter out low-resolutions if (displayMode.Width < 640 || displayMode.Height < 400) { continue; } // Check to see if it is already in the list (to filter out refresh rates) var found = false; for (var it = 0; it < Count; it++) { var oldDisp = this[it].DisplayMode; if (oldDisp.Width == displayMode.Width && oldDisp.Height == displayMode.Height && oldDisp.Format == displayMode.Format) { // Check refresh rate and favour higher if poss if (oldDisp.RefreshRate < displayMode.RefreshRate) { this[it].RefreshRate = displayMode.RefreshRate; } found = true; break; } } if (!found) { Add(new D3D9VideoMode(displayMode)); } } }
public static Media.PixelFormat ConvertEnum(D3D9.Format format) { switch (format) { case D3D9.Format.A8: return(Media.PixelFormat.A8); case D3D9.Format.L8: return(Media.PixelFormat.L8); case D3D9.Format.L16: return(Media.PixelFormat.L16); case D3D9.Format.A4L4: return(Media.PixelFormat.A4L4); case D3D9.Format.A8L8: // Assume little endian here return(Media.PixelFormat.A8L8); case D3D9.Format.R3G3B2: return(Media.PixelFormat.R3G3B2); case D3D9.Format.A1R5G5B5: return(Media.PixelFormat.A1R5G5B5); case D3D9.Format.A4R4G4B4: return(Media.PixelFormat.A4R4G4B4); case D3D9.Format.R5G6B5: return(Media.PixelFormat.R5G6B5); case D3D9.Format.R8G8B8: return(Media.PixelFormat.R8G8B8); case D3D9.Format.X8R8G8B8: return(Media.PixelFormat.X8R8G8B8); case D3D9.Format.A8R8G8B8: return(Media.PixelFormat.A8R8G8B8); case D3D9.Format.X8B8G8R8: return(Media.PixelFormat.X8B8G8R8); case D3D9.Format.A8B8G8R8: return(Media.PixelFormat.A8B8G8R8); case D3D9.Format.A2R10G10B10: return(Media.PixelFormat.A2R10G10B10); case D3D9.Format.A2B10G10R10: return(Media.PixelFormat.A2B10G10R10); case D3D9.Format.R16F: return(Media.PixelFormat.FLOAT16_R); case D3D9.Format.A16B16G16R16F: return(Media.PixelFormat.FLOAT16_RGBA); case D3D9.Format.R32F: return(Media.PixelFormat.FLOAT32_R); case D3D9.Format.A32B32G32R32F: return(Media.PixelFormat.FLOAT32_RGBA); case D3D9.Format.A16B16G16R16: return(Media.PixelFormat.SHORT_RGBA); case D3D9.Format.Dxt1: return(Media.PixelFormat.DXT1); case D3D9.Format.Dxt2: return(Media.PixelFormat.DXT2); case D3D9.Format.Dxt3: return(Media.PixelFormat.DXT3); case D3D9.Format.Dxt4: return(Media.PixelFormat.DXT4); case D3D9.Format.Dxt5: return(Media.PixelFormat.DXT5); default: return(Media.PixelFormat.Unknown); } }