コード例 #1
0
        /// <summary>
        /// Creates device-based resources to store a constant buffer, cube
        /// geometry, and vertex and pixel shaders. In some cases this will also
        /// store a geometry shader.
        /// </summary>
        public void CreateDeviceDependentResources()
        {
            ReleaseDeviceDependentResources();

            // Create a default sampler state, which will use point sampling.
            pointSampler = ToDispose(new SamplerState(deviceResources.D3DDevice, new SamplerStateDescription()
            {
                AddressU           = TextureAddressMode.Clamp,
                AddressV           = TextureAddressMode.Clamp,
                AddressW           = TextureAddressMode.Clamp,
                BorderColor        = new RawColor4(0, 0, 0, 0),
                ComparisonFunction = Comparison.Never,
                Filter             = Filter.MinMagMipLinear,
                MaximumAnisotropy  = 16,
                MaximumLod         = float.MaxValue,
                MinimumLod         = 0,
                MipLodBias         = 0.0f
            }));

            // Create the texture that will be used as the offscreen render target.
            var textureDesc = new Texture2DDescription
            {
                Format            = SharpDX.DXGI.Format.B8G8R8A8_UNorm,
                Width             = textureWidth,
                Height            = textureHeight,
                MipLevels         = 1,
                ArraySize         = 1,
                BindFlags         = BindFlags.ShaderResource | BindFlags.RenderTarget,
                SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
                OptionFlags       = ResourceOptionFlags.None,
                Usage             = ResourceUsage.Default,
                CpuAccessFlags    = CpuAccessFlags.None
            };

            texture2D = new Texture2D(deviceResources.D3DDevice, textureDesc);

            // Create read and write views for the offscreen render target.
            shaderResourceView = new ShaderResourceView(deviceResources.D3DDevice, texture2D);
            renderTargetView   = new RenderTargetView(deviceResources.D3DDevice, texture2D);

            // In this example, we are using D2D and DirectWrite; so, we need to create a D2D render target as well.
            SharpDX.Direct2D1.RenderTargetProperties props = new SharpDX.Direct2D1.RenderTargetProperties(
                SharpDX.Direct2D1.RenderTargetType.Default,
                new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.Unknown, SharpDX.Direct2D1.AlphaMode.Premultiplied),
                96, 96,
                SharpDX.Direct2D1.RenderTargetUsage.None,
                SharpDX.Direct2D1.FeatureLevel.Level_DEFAULT);

            // The DXGI surface is used to create the render target.
            SharpDX.DXGI.Surface dxgiSurface = texture2D.QueryInterface <SharpDX.DXGI.Surface>();
            d2dRenderTarget = new SharpDX.Direct2D1.RenderTarget(deviceResources.D2DFactory, dxgiSurface, props);

            // Create a solid color brush that will be used to render the text.
            whiteBrush = new SharpDX.Direct2D1.SolidColorBrush(d2dRenderTarget, new RawColor4(1f, 1f, 1f, 1f));

            // This is where we format the text that will be written on the render target.
            textFormat = new SharpDX.DirectWrite.TextFormat(deviceResources.DWriteFactory, "Consolas", SharpDX.DirectWrite.FontWeight.Normal, SharpDX.DirectWrite.FontStyle.Normal, 64f);
            textFormat.TextAlignment      = SharpDX.DirectWrite.TextAlignment.Center;
            textFormat.ParagraphAlignment = SharpDX.DirectWrite.ParagraphAlignment.Center;
        }
コード例 #2
0
 /// <summary>
 /// <p>Creates a new Direct2D device context associated with a DXGI surface. </p>
 /// </summary>
 /// <param name = "dxgiSurface"><dd> <p>The DXGI surface the Direct2D device context is associated with.</p> </dd></param>
 /// <param name = "creationProperties"><dd> <p>The properties to apply to the Direct2D device context.</p> </dd></param>
 /// <param name = "d2dDeviceContext"><dd> <p>When this function returns, contains the address of a reference to a Direct2D device context.</p> </dd></param>
 /// <returns><p>The function returns an <strong><see cref = "SharpDX.Result"/></strong>. Possible values include, but are not limited to, those in the following table.</p><table> <tr><th><see cref = "SharpDX.Result"/></th><th>Description</th></tr> <tr><td><see cref = "SharpDX.Result.Ok"/></td><td>No error occurred.</td></tr> <tr><td>E_OUTOFMEMORY</td><td>Direct2D could not allocate sufficient memory to complete the call.</td></tr> <tr><td>E_INVALIDARG</td><td>An invalid value was passed to the method.</td></tr> </table><p>?</p></returns>
 /// <remarks>
 /// <p>This function will also create a new <strong><see cref = "SharpDX.Direct2D1.Factory1"/></strong> that can be retrieved through <strong>ID2D1Resource::GetFactory</strong>.</p><p>This function will also create a new <strong><see cref = "SharpDX.Direct2D1.Device"/></strong> that can be retrieved through <strong>ID2D1DeviceContext::GetDevice</strong>.</p><p>The DXGI device will be specified implicitly through <em>dxgiSurface</em>.</p><p>If <em>creationProperties</em> are not specified, the Direct2D device will inherit its threading mode from the DXGI device implied by <em>dxgiSurface</em> and debug tracing will not be enabled.</p>
 /// </remarks>
 /// <doc-id>hh404273</doc-id>
 /// <unmanaged>HRESULT D2D1CreateDeviceContext([In] IDXGISurface* dxgiSurface,[In, Optional] const D2D1_CREATION_PROPERTIES* creationProperties,[Out, Fast] ID2D1DeviceContext** d2dDeviceContext)</unmanaged>
 /// <unmanaged-short>D2D1CreateDeviceContext</unmanaged-short>
 public static unsafe void CreateDeviceContext(SharpDX.DXGI.Surface dxgiSurface, SharpDX.Direct2D1.CreationProperties?creationProperties, SharpDX.Direct2D1.DeviceContext d2dDeviceContext)
 {
     System.IntPtr dxgiSurface_ = System.IntPtr.Zero;
     SharpDX.Direct2D1.CreationProperties creationProperties_;
     System.IntPtr  d2dDeviceContext_ = System.IntPtr.Zero;
     SharpDX.Result __result__;
     dxgiSurface_ = SharpDX.CppObject.ToCallbackPtr <SharpDX.DXGI.Surface>(dxgiSurface);
     if (creationProperties != null)
         creationProperties_ = creationProperties.Value; }
コード例 #3
0
        public WebWindow(int width, int height, string url)
        {
            this.width  = width;
            this.height = height;

            views.Add(this);

            webView = WebCore.CreateWebView(width, height, session);

            webView.Source = new Uri("file:///" + System.IO.Directory.GetCurrentDirectory() + "/" + Resources.FindFile(url));
            //webView.Source = new Uri("http://www.google.com");
            //webView.Source = new Uri("http://www.chiptune.com/starfield/starfield.html");

            webView.IsTransparent = true;

            webView.PropertyChanged += webView_PropertyChanged;

            webView.Crashed += webView_Crashed;

            webView.DocumentReady += webView_DocumentReady;

            descHM = new Texture2DDescription()
            {
                ArraySize         = 1,
                BindFlags         = BindFlags.None,
                CpuAccessFlags    = CpuAccessFlags.Write,
                Format            = SharpDX.DXGI.Format.B8G8R8A8_UNorm,
                Width             = width,
                Height            = height,
                MipLevels         = 1,
                OptionFlags       = ResourceOptionFlags.None,
                SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
                Usage             = ResourceUsage.Staging,
            };

            mappableTexture = new Texture2D(Display.device, descHM);
            mappableSurface = mappableTexture.QueryInterface <SharpDX.DXGI.Surface>();

            descHM.Usage          = ResourceUsage.Default;
            descHM.CpuAccessFlags = CpuAccessFlags.None;
            descHM.BindFlags      = BindFlags.ShaderResource;

            InputManager.MouseDown += _onMouseDown;
            InputManager.MouseUp   += _onMouseUp;
            InputManager.MouseMove += _onMouseMove;
            InputManager.Wheel     += _onMouseWheel;

            Texture2D webTexture = new Texture2D(Display.device, descHM);

            webTex = new Texture(webTexture);


            position = new Vector2(0, 0);

            binds   = new Stack <Tuple <string, JavascriptMethodEventHandler> >();
            invokes = new Stack <Tuple <string, JSValue[]> >();
        }
コード例 #4
0
ファイル: DUIDeviceContext3.cs プロジェクト: scjjcs/DirectUI
 public override void Resize(Size size)
 {
     this.deviceContext3.Target = null;
     this.swapChainBuffer.Dispose();
     this.targetBitmap.Dispose();
     this.swapChain.ResizeBuffers(1, 0, 0, SharpDX.DXGI.Format.B8G8R8A8_UNorm, SharpDX.DXGI.SwapChainFlags.None);
     this.swapChainBuffer       = SharpDX.DXGI.Surface.FromSwapChain(this.swapChain, 0);
     this.targetBitmap          = new SharpDX.Direct2D1.Bitmap1(this.deviceContext3, this.swapChainBuffer);
     this.deviceContext3.Target = targetBitmap;
 }
コード例 #5
0
        public Direct2DGraphics(SharpDX.DXGI.SwapChain swapChain)
            : this()
        {
            surface = DisposeLater(SharpDX.DXGI.Surface.FromSwapChain(swapChain, 0));
            dc      = DisposeLater(new RenderTarget(
                                       d2dFactory,
                                       surface,
                                       new RenderTargetProperties(new PixelFormat(SharpDX.DXGI.Format.Unknown, AlphaMode.Premultiplied)))
                                   );

            Initialize();
        }
コード例 #6
0
        private void CompleteMediaInitialization()
        {
            //Get our video size
            mediaEngine.GetNativeVideoSize(out videoWidth, out videoHeight);
            Duration = TimeSpan.FromSeconds(mediaEngine.Duration);

            //Get DXGI surface to be used by our media engine
            videoOutputTexture = Texture.New2D(GraphicsDevice, videoWidth, videoHeight, 1, PixelFormat.B8G8R8A8_UNorm, TextureFlags.ShaderResource | TextureFlags.RenderTarget);
            videoOutputSurface = videoOutputTexture.NativeResource.QueryInterface <SharpDX.DXGI.Surface>();

            AllocateVideoTexture(videoWidth, videoHeight);

            mediaEngine.Muted = true;
        }
コード例 #7
0
 /// <summary>
 /// <p>Creates a new Direct2D device context associated with a DXGI surface. </p>
 /// </summary>
 /// <param name="dxgiSurface"><dd> <p>The DXGI surface the Direct2D device context is associated with.</p> </dd></param>
 /// <param name="creationProperties"><dd> <p>The properties to apply to the Direct2D device context.</p> </dd></param>
 /// <param name="d2dDeviceContext"><dd> <p>When this function returns, contains the address of a reference to a Direct2D device context.</p> </dd></param>
 /// <returns><p>The function returns an <strong><see cref="SharpDX.Result"/></strong>. Possible values include, but are not limited to, those in the following table.</p><table> <tr><th><see cref="SharpDX.Result"/></th><th>Description</th></tr> <tr><td><see cref="SharpDX.Result.Ok"/></td><td>No error occurred.</td></tr> <tr><td>E_OUTOFMEMORY</td><td>Direct2D could not allocate sufficient memory to complete the call.</td></tr> <tr><td>E_INVALIDARG</td><td>An invalid value was passed to the method.</td></tr> </table><p>?</p></returns>
 /// <remarks>
 /// <p>This function will also create a new <strong><see cref="SharpDX.Direct2D1.Factory1"/></strong> that can be retrieved through <strong><see cref="SharpDX.Direct2D1.Resource.GetFactory"/></strong>.</p><p>This function will also create a new <strong><see cref="SharpDX.Direct2D1.Device"/></strong> that can be retrieved through <strong><see cref="SharpDX.Direct2D1.DeviceContext.GetDevice"/></strong>.</p><p>The DXGI device will be specified implicitly through <em>dxgiSurface</em>.</p><p>The created device context will have exactly the same behavior as if <strong>ID2D1DeviceContext::SetTargetSurface</strong> were called with the corresponding surface.</p><p>If <em>creationProperties</em> are not specified, the Direct2D device will inherit its threading mode from the DXGI device implied by <em>dxgiSurface</em> and debug tracing will not be enabled.</p><p><strong>Windows Phone 8.1:</strong> This API is supported.</p>
 /// </remarks>
 /// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='D2D1CreateDeviceContext']/*"/>
 /// <msdn-id>hh404273</msdn-id>
 /// <unmanaged>HRESULT D2D1CreateDeviceContext([In] IDXGISurface* dxgiSurface,[In, Optional] const D2D1_CREATION_PROPERTIES* creationProperties,[Out, Fast] ID2D1DeviceContext** d2dDeviceContext)</unmanaged>
 /// <unmanaged-short>D2D1CreateDeviceContext</unmanaged-short>
 public static void CreateDeviceContext(SharpDX.DXGI.Surface dxgiSurface, SharpDX.Direct2D1.CreationProperties?creationProperties, SharpDX.Direct2D1.DeviceContext d2dDeviceContext)
 {
     unsafe {
         SharpDX.Direct2D1.CreationProperties creationProperties_;
         if (creationProperties.HasValue)
         {
             creationProperties_ = creationProperties.Value;
         }
         IntPtr         d2dDeviceContext_ = IntPtr.Zero;
         SharpDX.Result __result__;
         __result__ =
             D2D1CreateDeviceContext_((void *)((dxgiSurface == null)?IntPtr.Zero:dxgiSurface.NativePointer), (creationProperties.HasValue)?&creationProperties_:(void *)IntPtr.Zero, &d2dDeviceContext_);
         ((SharpDX.Direct2D1.DeviceContext)d2dDeviceContext).NativePointer = d2dDeviceContext_;
         __result__.CheckError();
     }
 }
コード例 #8
0
        public Direct2DGraphics(SharpDX.DXGI.SwapChain swapChain)
            : this()
        {
            surface = DisposeLater(SharpDX.DXGI.Surface.FromSwapChain(swapChain, 0));
            dc      = DisposeLater(new RenderTarget(
                                       d2dFactory,
                                       surface,
                                       new RenderTargetProperties(
                                           RenderTargetType.Default,
                                           new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied),
                                           d2dFactory.DesktopDpi.Width, d2dFactory.DesktopDpi.Height,
                                           RenderTargetUsage.None,
                                           FeatureLevel.Level_DEFAULT)));

            Initialize();
        }
コード例 #9
0
        /// <summary>
        ///     MediaFoundation のビデオサンプルを D2DBitmap に変換して返す。
        /// </summary>
        public unsafe Bitmap サンプルからビットマップを取得する(Sample Sample)
        {
            // 1. Sample → MediaBuffer
            using var mediaBuffer = Sample.ConvertToContiguousBuffer();

            // 2. MediaBuffer → DXGIBuffer
            using var dxgiBuffer = mediaBuffer.QueryInterface <DXGIBuffer>();

            // 3. DXGIBuffer → DXGISurface(IntPtr)
            dxgiBuffer.GetResource(typeof(SharpDX.DXGI.Surface).GUID, out IntPtr vDxgiSurface);

            // 4.  DXGISurface(IntPtr) → DXGISurface
            using var dxgiSurface = new SharpDX.DXGI.Surface(vDxgiSurface);

            // 5. DXGISurface → Bitmap
            return(new Bitmap(
                       Global.既定のD2D1DeviceContext,
                       dxgiSurface,
                       new BitmapProperties(new PixelFormat(dxgiSurface.Description.Format, AlphaMode.Ignore))));
        }
コード例 #10
0
        partial void ReleaseMediaImpl()
        {
            mediaEngine?.Shutdown();
            mediaEngine?.Dispose();
            mediaEngine = null;

            // Randomly crashes in sharpDX and the native code when disabling this
            // The stream is problably accessed after disposal due to communication latency
            // Unfortunately we don't receive any events after the call to Shutdown where we could dispose those

            //videoDataStream?.Dispose();
            //videoDataStream = null;
            //videoFileStream?.Dispose();
            //videoFileStream = null;

            videoOutputSurface?.Dispose();
            videoOutputSurface = null;
            videoOutputTexture?.Dispose();
            videoOutputTexture = null;
        }
コード例 #11
0
        public void Resize(int width, int height)
        {
            if (this.width == width && this.height == height)
            {
                return;
            }

            this.width  = width;
            this.height = height;

            mappableTexture.Dispose();
            webTex.Tex.Dispose();
            mappableSurface.Dispose();

            webView.Resize(width, height);
            //webView.Reload(false);


            //descHM
            descHM.Usage          = ResourceUsage.Staging;
            descHM.CpuAccessFlags = CpuAccessFlags.Write;
            descHM.BindFlags      = BindFlags.None;
            descHM.Width          = width;
            descHM.Height         = height;

            mappableTexture = new Texture2D(Display.device, descHM);
            mappableSurface = mappableTexture.QueryInterface <SharpDX.DXGI.Surface>();

            descHM.Usage          = ResourceUsage.Default;
            descHM.CpuAccessFlags = CpuAccessFlags.None;
            descHM.BindFlags      = BindFlags.ShaderResource;

            Texture2D webTexture = new Texture2D(Display.device, descHM);

            webTex.Tex    = webTexture;
            webTex.Width  = width;
            webTex.Height = height;
            webTex.RecreateSRV();
        }
コード例 #12
0
ファイル: DUIDeviceContext3.cs プロジェクト: scjjcs/DirectUI
 public DUIDeviceContext3(IntPtr handle)
 {
     this.d3d11Device    = new SharpDX.Direct3D11.Device(SharpDX.Direct3D.DriverType.Hardware, SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport);
     this.dxgiDevice     = d3d11Device.QueryInterface <SharpDX.Direct3D11.Device1>().QueryInterface <SharpDX.DXGI.Device>();
     this.d2dDevice3     = new SharpDX.Direct2D1.Device3(dxgiDevice);
     this.deviceContext3 = new SharpDX.Direct2D1.DeviceContext3(d2dDevice3, SharpDX.Direct2D1.DeviceContextOptions.None);
     // 创建 DXGI SwapChain。
     SharpDX.DXGI.SwapChainDescription swapChainDescription = new SharpDX.DXGI.SwapChainDescription()
     {
         BufferCount  = 1,
         Usage        = SharpDX.DXGI.Usage.RenderTargetOutput,
         OutputHandle = handle,
         IsWindowed   = true,
         // 这里宽度和高度都是 0,表示自动获取。
         ModeDescription   = new SharpDX.DXGI.ModeDescription(0, 0, new SharpDX.DXGI.Rational(60, 1), SharpDX.DXGI.Format.B8G8R8A8_UNorm),
         SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
         SwapEffect        = SharpDX.DXGI.SwapEffect.Discard
     };
     this.swapChain             = new SharpDX.DXGI.SwapChain(dxgiDevice.GetParent <SharpDX.DXGI.Adapter>().GetParent <SharpDX.DXGI.Factory>(), d3d11Device, swapChainDescription);
     this.swapChainBuffer       = SharpDX.DXGI.Surface.FromSwapChain(this.swapChain, 0);
     this.targetBitmap          = new SharpDX.Direct2D1.Bitmap1(this.deviceContext3, this.swapChainBuffer);
     this.deviceContext3.Target = targetBitmap;
 }
コード例 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Device"/> class.
 /// </summary>
 /// <param name="surface">The surface.</param>
 /// <param name="creationProperties">The creation properties.</param>
 /// <unmanaged>HRESULT D2D1CreateDeviceContext([In] IDXGISurface* dxgiSurface,[In, Optional] const D2D1_CREATION_PROPERTIES* creationProperties,[Out] ID2D1DeviceContext** d2dDeviceContext)</unmanaged>
 public DeviceContext(SharpDX.DXGI.Surface surface, CreationProperties creationProperties)
     : base(IntPtr.Zero)
 {
     D2D1.CreateDeviceContext(surface, creationProperties, this);
 }
コード例 #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DeviceContext"/> class.
 /// </summary>
 /// <param name="surface">The surface.</param>
 /// <unmanaged>HRESULT D2D1CreateDeviceContext([In] IDXGISurface* dxgiSurface,[In, Optional] const D2D1_CREATION_PROPERTIES* creationProperties,[Out] ID2D1DeviceContext** d2dDeviceContext)</unmanaged>
 public DeviceContext(SharpDX.DXGI.Surface surface)
     : base(IntPtr.Zero)
 {
     D2D1.CreateDeviceContext(surface, null, this);
 }