/// <summary>
        /// Constructor is private, because this is a singleton class:
        /// client controls should use the public AddRef method instead.
        /// </summary>
        SharpDXGraphicsDeviceService10()
        {
            // We need a a D3D9 device.
            sharpDXGraphicsDeviceService9 = SharpDXGraphicsDeviceService9.RefToNew(0, 0);

            factoryDXGI = new Factory();
            factory2D   = new SharpDX.Direct2D1.Factory();
            // Try to create a hardware device first and fall back to a
            // software (WARP doesn't let us share resources)
            var device1 = TryCreateDevice1(SharpDX.Direct3D10.DriverType.Hardware);

            if (device1 == null)
            {
                device1 = TryCreateDevice1(SharpDX.Direct3D10.DriverType.Software);
                if (device1 == null)
                {
                    throw new Exception("Unable to create a DirectX 10 device.");
                }
            }
            // Ratserizer not needed for Direct2D (retain for if mixing D2D and D3D).
            //RasterizerStateDescription rastDesc = new RasterizerStateDescription();
            //rastDesc.CullMode = CullMode.Back;
            //rastDesc.FillMode = FillMode.Solid;
            //rastDesc.IsMultisampleEnabled = false;
            //rastDesc.IsAntialiasedLineEnabled = false;
            //device1.Rasterizer.State = new RasterizerState(device1, rastDesc);
            this.device = device1;
        }
Esempio n. 2
0
 // Create Device(s) and start rendering.
 protected virtual unsafe void CreateDevice(SurfaceType surfaceType)
 {
     this.surfaceType = surfaceType;
     if (surfaceType == SurfaceType.Direct2D)
     {
         // Use shared devices resources.
         graphicsDeviceService10 = SharpDXGraphicsDeviceService10.AddRef();
         graphicsDeviceService10.DeviceResized += new EventHandler(graphicsDeviceService10_DeviceResized);
         graphicsDeviceService10.ResizeDevice(bufferWidth, bufferHeight);
         bufferWidth  = graphicsDeviceService10.Width;
         bufferHeight = graphicsDeviceService10.Height;
     }
     else if (surfaceType == SurfaceType.DirectX9)
     {
         // Use shared devices resources.
         graphicsDeviceService9              = SharpDXGraphicsDeviceService9.AddRef(bufferWidth, bufferHeight);
         graphicsDeviceService9.DeviceReset += new EventHandler(graphicsDeviceService9_DeviceReset);
         afterResizeReset = true;
     }
     Initialize();
     if (d3dImage.IsFrontBufferAvailable)
     {
         SetBackBuffer();
     }
     //CompositionTarget.Rendering += OnRendering;
 }
        /// <summary>
        /// Gets a reference to the singleton instance.
        /// </summary>
        public static SharpDXGraphicsDeviceService9 AddRef(int width, int height)
        {
            // Increment the "how many controls sharing the device" reference count.
            if (Interlocked.Increment(ref referenceCount) == 1)
            {
                // If this is the first control to start using the
                // device, we must create the singleton instance.
                singletonInstance = new SharpDXGraphicsDeviceService9(width, height);
            }

            return(singletonInstance);
        }
Esempio n. 4
0
 /// <summary>
 /// Disposes the control.
 /// </summary>
 protected void Dispose(bool disposing)
 {
     if (graphicsDeviceService9 != null)
     {
         graphicsDeviceService9.Release(disposing);
         graphicsDeviceService9 = null;
     }
     if (graphicsDeviceService10 != null)
     {
         graphicsDeviceService10.Release(disposing);
         graphicsDeviceService10 = null;
     }
 }
        /// <summary>
        /// Gets a reference to the singleton instance.
        /// </summary>
        public static SharpDXGraphicsDeviceService9 AddRef(int width, int height)
        {
            // Increment the "how many controls sharing the device" reference count.
            if (Interlocked.Increment(ref referenceCount) == 1)
            {
                // If this is the first control to start using the
                // device, we must create the singleton instance.
                singletonInstance = new SharpDXGraphicsDeviceService9(width, height);
            }

            return singletonInstance;
        }
 /// <summary>
 /// Constructor is private, because this is a singleton class:
 /// client controls should use the public AddRef method instead.
 /// </summary>
 SharpDXGraphicsDeviceService10()
 {
     // We need a a D3D9 device.
     sharpDXGraphicsDeviceService9 = SharpDXGraphicsDeviceService9.RefToNew(0, 0);
     
     factoryDXGI = new Factory();
     factory2D = new SharpDX.Direct2D1.Factory();
     // Try to create a hardware device first and fall back to a
     // software (WARP doesn't let us share resources)
     var device1 = TryCreateDevice1(SharpDX.Direct3D10.DriverType.Hardware);
     if (device1 == null)
     {
         device1 = TryCreateDevice1(SharpDX.Direct3D10.DriverType.Software);
         if (device1 == null)
         {
             throw new Exception("Unable to create a DirectX 10 device.");
         }
     }
     // Ratserizer not needed for Direct2D (retain for if mixing D2D and D3D).
     //RasterizerStateDescription rastDesc = new RasterizerStateDescription();
     //rastDesc.CullMode = CullMode.Back;
     //rastDesc.FillMode = FillMode.Solid;
     //rastDesc.IsMultisampleEnabled = false;
     //rastDesc.IsAntialiasedLineEnabled = false;
     //device1.Rasterizer.State = new RasterizerState(device1, rastDesc);
     this.device = device1;
 }
Esempio n. 7
0
 /// <summary>
 /// Disposes the control.
 /// </summary>
 protected void Dispose(bool disposing)
 {
     if (graphicsDeviceService9 != null)
     {
         graphicsDeviceService9.Release(disposing);
         graphicsDeviceService9 = null;
     }
     if (graphicsDeviceService10 != null)
     {
         graphicsDeviceService10.Release(disposing);
         graphicsDeviceService10 = null;
     }
 }
Esempio n. 8
0
 // Create Device(s) and start rendering.
 protected virtual unsafe void CreateDevice(SurfaceType surfaceType)
 {
     this.surfaceType = surfaceType;
     if (surfaceType == SurfaceType.Direct2D)
     {
         // Use shared devices resources.
         graphicsDeviceService10 = SharpDXGraphicsDeviceService10.AddRef();
         graphicsDeviceService10.DeviceResized += new EventHandler(graphicsDeviceService10_DeviceResized);
         graphicsDeviceService10.ResizeDevice(bufferWidth, bufferHeight);
         bufferWidth = graphicsDeviceService10.Width;
         bufferHeight = graphicsDeviceService10.Height;
     }
     else if (surfaceType == SurfaceType.DirectX9)
     {
         // Use shared devices resources.
         graphicsDeviceService9 = SharpDXGraphicsDeviceService9.AddRef(bufferWidth, bufferHeight);
         graphicsDeviceService9.DeviceReset += new EventHandler(graphicsDeviceService9_DeviceReset);
         afterResizeReset = true;
     }
     Initialize();
     if (d3dImage.IsFrontBufferAvailable)
     {
         SetBackBuffer();
     }
     //CompositionTarget.Rendering += OnRendering;
 }