Exemplo n.º 1
0
        private void InitD3D()
        {
            _dxDevice = new Device(DriverType.Hardware, DeviceCreationFlags.Debug | DeviceCreationFlags.BgraSupport, FeatureLevel.Level_10_0);

            EnsureOutputBuffers();

            FontDescription fontDesc = new FontDescription
            {
                Height         = 24,
                Width          = 0,
                Weight         = 0,
                MipLevels      = 1,
                IsItalic       = false,
                CharacterSet   = FontCharacterSet.Default,
                Precision      = FontPrecision.Default,
                Quality        = FontQuality.Default,
                PitchAndFamily = FontPitchAndFamily.Default | FontPitchAndFamily.DontCare,
                FaceName       = "Times New Roman"
            };

            _dxFont = new Font(_dxDevice, fontDesc);

            _textureManager = new DxTextureManager(_dxDevice);

//            _dxEffect = new DxEffect(_dxDevice);
            _dxCube = new DxCube(_dxDevice);
            CrateKinectPointsRenderer(KinectPointsRendererType.Billboard);

            ShaderResourceView texArray = _textureManager.CreateTexArray("flares", @"Assets\flare0.dds");

            _fire = new DxParticleSystemRenderer(_dxDevice, texArray, 500);

            _dxDevice.Flush();
        }
Exemplo n.º 2
0
    public Direct3DRenderer()
    {
      _device = new Device(DriverType.Hardware, DeviceCreationFlags.BgraSupport, FeatureLevel.Level_10_0);
      _rasterizerStateDescription = new RasterizerStateDescription()
      {
        CullMode = SlimDX.Direct3D10.CullMode.None,
        FillMode = FillMode.Solid,
        IsFrontCounterclockwise = true
      };
      var rasterizerState = RasterizerState.FromDescription(_device, _rasterizerStateDescription);
      _device.Rasterizer.State = rasterizerState;

      _depthStencilStateDescription = new DepthStencilStateDescription()
      {
        IsDepthEnabled = true,
        DepthComparison = Comparison.Less,
        DepthWriteMask = DepthWriteMask.All
      };
      var depthStencilState = DepthStencilState.FromDescription(_device, _depthStencilStateDescription);
      _device.OutputMerger.DepthStencilState = depthStencilState;

      _semanticsTable.Add("inPosition", "POSITION");
      _semanticsTable.Add("inNormal", "NORMAL");
      _semanticsTable.Add("inTextureCoords", "TEXCOORD");
    }
        public Direct3DRenderer()
        {
            _device = new Device(DriverType.Hardware, DeviceCreationFlags.BgraSupport, FeatureLevel.Level_10_0);
            _rasterizerStateDescription = new RasterizerStateDescription()
            {
                CullMode = SlimDX.Direct3D10.CullMode.None,
                FillMode = FillMode.Solid,
                IsFrontCounterclockwise = true
            };
            var rasterizerState = RasterizerState.FromDescription(_device, _rasterizerStateDescription);

            _device.Rasterizer.State = rasterizerState;

            _depthStencilStateDescription = new DepthStencilStateDescription()
            {
                IsDepthEnabled  = true,
                DepthComparison = Comparison.Less,
                DepthWriteMask  = DepthWriteMask.All
            };
            var depthStencilState = DepthStencilState.FromDescription(_device, _depthStencilStateDescription);

            _device.OutputMerger.DepthStencilState = depthStencilState;

            _semanticsTable.Add("inPosition", "POSITION");
            _semanticsTable.Add("inNormal", "NORMAL");
            _semanticsTable.Add("inTextureCoords", "TEXCOORD");
            _semanticsTable.Add("instanceMatrix", "INSTANCE_TRANSFORM");
        }
Exemplo n.º 4
0
        void InitD3D()
        {
            D3DDevice = new Device(DriverType.Hardware, DeviceCreationFlags.Debug | DeviceCreationFlags.BgraSupport, FeatureLevel.Level_10_0);

            Texture2DDescription colordesc = new Texture2DDescription();
            colordesc.BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource;
            colordesc.Format = Format.B8G8R8A8_UNorm;
            colordesc.Width = WindowWidth;
            colordesc.Height = WindowHeight;
            colordesc.MipLevels = 1;
            colordesc.SampleDescription = new SampleDescription(1, 0);
            colordesc.Usage = ResourceUsage.Default;
            colordesc.OptionFlags = ResourceOptionFlags.Shared;
            colordesc.CpuAccessFlags = CpuAccessFlags.None;
            colordesc.ArraySize = 1;

            Texture2DDescription depthdesc = new Texture2DDescription();
            depthdesc.BindFlags = BindFlags.DepthStencil;
            depthdesc.Format = Format.D32_Float_S8X24_UInt;
            depthdesc.Width = WindowWidth;
            depthdesc.Height = WindowHeight;
            depthdesc.MipLevels = 1;
            depthdesc.SampleDescription = new SampleDescription(1, 0);
            depthdesc.Usage = ResourceUsage.Default;
            depthdesc.OptionFlags = ResourceOptionFlags.None;
            depthdesc.CpuAccessFlags = CpuAccessFlags.None;
            depthdesc.ArraySize = 1;

            SharedTexture = new Texture2D(D3DDevice, colordesc);
            DepthTexture = new Texture2D(D3DDevice, depthdesc);
            SampleRenderView = new RenderTargetView(D3DDevice, SharedTexture);
            SampleDepthView = new DepthStencilView(D3DDevice, DepthTexture);
            SampleEffect = Effect.FromFile(D3DDevice, "MiniTri.fx", "fx_4_0");
            EffectTechnique technique = SampleEffect.GetTechniqueByIndex(0); ;
            EffectPass pass = technique.GetPassByIndex(0);
            SampleLayout = new InputLayout(D3DDevice, pass.Description.Signature, new[] {
                new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0) 
            });

            SampleStream = new DataStream(3 * 32, true, true);
            SampleStream.WriteRange(new[] {
                new Vector4(0.0f, 0.5f, 0.5f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new Vector4(0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(-0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f)
            });
            SampleStream.Position = 0;

            SampleVertices = new Buffer(D3DDevice, SampleStream, new BufferDescription()
            {
                BindFlags = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags = ResourceOptionFlags.None,
                SizeInBytes = 3 * 32,
                Usage = ResourceUsage.Default
            });

            D3DDevice.Flush();
        }
Exemplo n.º 5
0
        public D2DInteropHandler(RenderManager manager)
        {
            Manager = manager;
            #if DEBUG
            D3DDevice10 = new D3D101.Device1(manager.DXGIAdapter, D3D10.DriverType.Hardware, D3D10.DeviceCreationFlags.BgraSupport | D3D10.DeviceCreationFlags.Debug, D3D101.FeatureLevel.Level_10_0);
            #else
            D3DDevice10 = new D3D101.Device1(D3D10.DriverType.Hardware, D3D10.DeviceCreationFlags.BgraSupport, D3D101.FeatureLevel.Level_10_0);
            #endif
            D2DFactory = new D2D.Factory(D2D.FactoryType.SingleThreaded);

            DWFactory = new DW.Factory(DW.FactoryType.Shared);
        }
Exemplo n.º 6
0
        public override void Hook()
        {
            this.DebugMessage("Hook: Begin");

            // Determine method addresses in Direct3D10.Device, and DXGI.SwapChain
            if (_d3d10_1VTblAddresses == null)
            {
                _d3d10_1VTblAddresses       = new List <IntPtr>();
                _dxgiSwapChainVTblAddresses = new List <IntPtr>();
                this.DebugMessage("Hook: Before device creation");
                using (Factory1 factory = new Factory1())
                {
                    using (var device = new SlimDX.Direct3D10_1.Device1(factory.GetAdapter(0), DriverType.Hardware, SlimDX.Direct3D10.DeviceCreationFlags.None, FeatureLevel.Level_10_1))
                    {
                        this.DebugMessage("Hook: Device created");
                        _d3d10_1VTblAddresses.AddRange(GetVTblAddresses(device.ComPointer, D3D10_1_DEVICE_METHOD_COUNT));

                        using (var renderForm = new SlimDX.Windows.RenderForm())
                        {
                            using (var sc = new SwapChain(factory, device, DXGI.CreateSwapChainDescription(renderForm.Handle)))
                            {
                                _dxgiSwapChainVTblAddresses.AddRange(GetVTblAddresses(sc.ComPointer, DXGI.DXGI_SWAPCHAIN_METHOD_COUNT));
                            }
                        }
                    }
                }
            }

            // We will capture the backbuffer here
            DXGISwapChain_PresentHook = LocalHook.Create(
                _dxgiSwapChainVTblAddresses[(int)DXGI.DXGISwapChainVTbl.Present],
                new DXGISwapChain_PresentDelegate(PresentHook),
                this);

            // We will capture target/window resizes here
            DXGISwapChain_ResizeTargetHook = LocalHook.Create(
                _dxgiSwapChainVTblAddresses[(int)DXGI.DXGISwapChainVTbl.ResizeTarget],
                new DXGISwapChain_ResizeTargetDelegate(ResizeTargetHook),
                this);

            /*
             * Don't forget that all hooks will start deactivated...
             * The following ensures that all threads are intercepted:
             * Note: you must do this for each hook.
             */
            DXGISwapChain_PresentHook.ThreadACL.SetExclusiveACL(new Int32[1]);

            DXGISwapChain_ResizeTargetHook.ThreadACL.SetExclusiveACL(new Int32[1]);
        }
Exemplo n.º 7
0
        private void DestroyD3D()
        {
            _textureManager.Dispose();
            _dxCube.Dispose();
            //_dxEffect.Dispose();
            _kinectPoints.Dispose();


            if (_dxFont != null)
            {
                _dxFont.Dispose();
                _dxFont = null;
            }

            if (DepthTexture != null)
            {
                DepthTexture.Dispose();
                DepthTexture = null;
            }

            if (SharedTexture != null)
            {
                SharedTexture.Dispose();
                SharedTexture = null;
            }

            if (_dxRenderView != null)
            {
                _dxRenderView.Dispose();
                _dxRenderView = null;
            }

            if (_dxDepthStencilView != null)
            {
                _dxDepthStencilView.Dispose();
                _dxDepthStencilView = null;
            }

            if (_dxDevice != null)
            {
                _dxDevice.Dispose();
                _dxDevice = null;
            }
        }
Exemplo n.º 8
0
        void DestroyD3D()
        {
            if (SampleVertices != null)
            {
                SampleVertices.Dispose();
                SampleVertices = null;
            }

            if (SampleLayout != null)
            {
                SampleLayout.Dispose();
                SampleLayout = null;
            }

            if (SampleEffect != null)
            {
                SampleEffect.Dispose();
                SampleEffect = null;
            }

            if (SampleRenderView != null)
            {
                SampleRenderView.Dispose();
                SampleRenderView = null;
            }

            if (SampleDepthView != null)
            {
                SampleDepthView.Dispose();
                SampleDepthView = null;
            }

            if (SampleStream != null)
            {
                SampleStream.Dispose();
                SampleStream = null;
            }

            if (SampleLayout != null)
            {
                SampleLayout.Dispose();
                SampleLayout = null;
            }

            if (SharedTexture != null)
            {
                SharedTexture.Dispose();
                SharedTexture = null;
            }

            if (DepthTexture != null)
            {
                DepthTexture.Dispose();
                DepthTexture = null;
            }

            if (D3DDevice != null)
            {
                D3DDevice.Dispose();
                D3DDevice = null;
            }
        }
Exemplo n.º 9
0
        public override void Hook()
        {
            this.DebugMessage("Hook: Begin");

            // Determine method addresses in Direct3D10.Device, and DXGI.SwapChain
            if (_d3d10_1VTblAddresses == null)
            {
                _d3d10_1VTblAddresses = new List<IntPtr>();
                _dxgiSwapChainVTblAddresses = new List<IntPtr>();
                this.DebugMessage("Hook: Before device creation");
                using (Factory1 factory = new Factory1())
                {
                    using (var device = new SlimDX.Direct3D10_1.Device1(factory.GetAdapter(0), DriverType.Hardware, SlimDX.Direct3D10.DeviceCreationFlags.None, FeatureLevel.Level_10_1))
                    {
                        this.DebugMessage("Hook: Device created");
                        _d3d10_1VTblAddresses.AddRange(GetVTblAddresses(device.ComPointer, D3D10_1_DEVICE_METHOD_COUNT));

                        using (var renderForm = new SlimDX.Windows.RenderForm())
                        {
                            using (var sc = new SwapChain(factory, device, DXGI.CreateSwapChainDescription(renderForm.Handle)))
                            {
                                _dxgiSwapChainVTblAddresses.AddRange(GetVTblAddresses(sc.ComPointer, DXGI.DXGI_SWAPCHAIN_METHOD_COUNT));
                            }
                        }
                    }
                }
            }
            
            // We will capture the backbuffer here
            DXGISwapChain_PresentHook = LocalHook.Create(
                _dxgiSwapChainVTblAddresses[(int)DXGI.DXGISwapChainVTbl.Present],
                new DXGISwapChain_PresentDelegate(PresentHook),
                this);

            // We will capture target/window resizes here
            DXGISwapChain_ResizeTargetHook = LocalHook.Create(
                _dxgiSwapChainVTblAddresses[(int)DXGI.DXGISwapChainVTbl.ResizeTarget],
                new DXGISwapChain_ResizeTargetDelegate(ResizeTargetHook),
                this);

            /*
             * Don't forget that all hooks will start deactivated...
             * The following ensures that all threads are intercepted:
             * Note: you must do this for each hook.
             */
            DXGISwapChain_PresentHook.ThreadACL.SetExclusiveACL(new Int32[1]);

            DXGISwapChain_ResizeTargetHook.ThreadACL.SetExclusiveACL(new Int32[1]);
        }
Exemplo n.º 10
0
        private void InitD3D()
        {
            _dxDevice = new Device(DriverType.Hardware, DeviceCreationFlags.Debug | DeviceCreationFlags.BgraSupport, FeatureLevel.Level_10_0);

            EnsureOutputBuffers();

            FontDescription fontDesc = new FontDescription
                                           {
                                               Height = 24,
                                               Width = 0,
                                               Weight = 0,
                                               MipLevels = 1,
                                               IsItalic = false,
                                               CharacterSet = FontCharacterSet.Default,
                                               Precision = FontPrecision.Default,
                                               Quality = FontQuality.Default,
                                               PitchAndFamily = FontPitchAndFamily.Default | FontPitchAndFamily.DontCare,
                                               FaceName = "Times New Roman"
                                           };

            _dxFont = new Font(_dxDevice, fontDesc);

            _textureManager = new DxTextureManager(_dxDevice);

            //            _dxEffect = new DxEffect(_dxDevice);
            _dxCube = new DxCube(_dxDevice);
            CrateKinectPointsRenderer(KinectPointsRendererType.Billboard);

            ShaderResourceView texArray = _textureManager.CreateTexArray("flares", @"Assets\flare0.dds");
            _fire = new DxParticleSystemRenderer(_dxDevice, texArray, 500);

            _dxDevice.Flush();
        }
Exemplo n.º 11
0
        private void DestroyD3D()
        {
            _textureManager.Dispose();
            _dxCube.Dispose();
            //_dxEffect.Dispose();
            _kinectPoints.Dispose();

            if (_dxFont != null)
            {
                _dxFont.Dispose();
                _dxFont = null;
            }

            if (DepthTexture != null)
            {
                DepthTexture.Dispose();
                DepthTexture = null;
            }

            if (SharedTexture != null)
            {
                SharedTexture.Dispose();
                SharedTexture = null;
            }

            if (_dxRenderView != null)
            {
                _dxRenderView.Dispose();
                _dxRenderView = null;
            }

            if (_dxDepthStencilView != null)
            {
                _dxDepthStencilView.Dispose();
                _dxDepthStencilView = null;
            }

            if (_dxDevice != null)
            {
                _dxDevice.Dispose();
                _dxDevice = null;
            }
        }
Exemplo n.º 12
0
        void InitD3D()
        {
            D3DDevice = new Device(DriverType.Hardware, DeviceCreationFlags.Debug | DeviceCreationFlags.BgraSupport, FeatureLevel.Level_10_0);

            Texture2DDescription colordesc = new Texture2DDescription();

            colordesc.BindFlags         = BindFlags.RenderTarget | BindFlags.ShaderResource;
            colordesc.Format            = Format.B8G8R8A8_UNorm;
            colordesc.Width             = WindowWidth;
            colordesc.Height            = WindowHeight;
            colordesc.MipLevels         = 1;
            colordesc.SampleDescription = new SampleDescription(1, 0);
            colordesc.Usage             = ResourceUsage.Default;
            colordesc.OptionFlags       = ResourceOptionFlags.Shared;
            colordesc.CpuAccessFlags    = CpuAccessFlags.None;
            colordesc.ArraySize         = 1;

            Texture2DDescription depthdesc = new Texture2DDescription();

            depthdesc.BindFlags         = BindFlags.DepthStencil;
            depthdesc.Format            = Format.D32_Float_S8X24_UInt;
            depthdesc.Width             = WindowWidth;
            depthdesc.Height            = WindowHeight;
            depthdesc.MipLevels         = 1;
            depthdesc.SampleDescription = new SampleDescription(1, 0);
            depthdesc.Usage             = ResourceUsage.Default;
            depthdesc.OptionFlags       = ResourceOptionFlags.None;
            depthdesc.CpuAccessFlags    = CpuAccessFlags.None;
            depthdesc.ArraySize         = 1;

            SharedTexture    = new Texture2D(D3DDevice, colordesc);
            DepthTexture     = new Texture2D(D3DDevice, depthdesc);
            SampleRenderView = new RenderTargetView(D3DDevice, SharedTexture);
            SampleDepthView  = new DepthStencilView(D3DDevice, DepthTexture);
            SampleEffect     = Effect.FromFile(D3DDevice, "MiniTri.fx", "fx_4_0");
            EffectTechnique technique = SampleEffect.GetTechniqueByIndex(0);;
            EffectPass      pass      = technique.GetPassByIndex(0);

            SampleLayout = new InputLayout(D3DDevice, pass.Description.Signature, new[] {
                new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0)
            });

            SampleStream = new DataStream(3 * 32, true, true);
            SampleStream.WriteRange(new[] {
                new Vector4(0.0f, 0.5f, 0.5f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new Vector4(0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(-0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f)
            });
            SampleStream.Position = 0;

            SampleVertices = new Buffer(D3DDevice, SampleStream, new BufferDescription()
            {
                BindFlags      = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags    = ResourceOptionFlags.None,
                SizeInBytes    = 3 * 32,
                Usage          = ResourceUsage.Default
            });

            D3DDevice.Flush();
        }
Exemplo n.º 13
0
        void DestroyD3D()
        {
            if (SampleVertices != null)
            {
                SampleVertices.Dispose();
                SampleVertices = null;
            }

            if (SampleLayout != null)
            {
                SampleLayout.Dispose();
                SampleLayout = null;
            }

            if (SampleEffect != null)
            {
                SampleEffect.Dispose();
                SampleEffect = null;
            }

            if (SampleRenderView != null)
            {
                SampleRenderView.Dispose();
                SampleRenderView = null;
            }

            if (SampleDepthView != null)
            {
                SampleDepthView.Dispose();
                SampleDepthView = null;
            }

            if (SampleStream != null)
            {
                SampleStream.Dispose();
                SampleStream = null;
            }

            if (SampleLayout != null)
            {
                SampleLayout.Dispose();
                SampleLayout = null;
            }

            if (SharedTexture != null)
            {
                SharedTexture.Dispose();
                SharedTexture = null;
            }

            if (DepthTexture != null)
            {
                DepthTexture.Dispose();
                DepthTexture = null;
            }

            if (D3DDevice != null)
            {
                D3DDevice.Dispose();
                D3DDevice = null;
            }
        }
Exemplo n.º 14
0
        public void InitializeDevice()
        {
            mForm = new Form { Width = mWidth, Height = mHeight };
            mForm.Closing += (sender, args) => IsClosing = true;

            using (var factory = new Factory())
            {
                Device = new Device(DriverType.Hardware, DeviceCreationFlags.BgraSupport, FeatureLevel.Level_10_0);

                mSwapChain = CreateSwapChain(factory);
            }

            using (var texture = Resource.FromSwapChain<Texture2D>(mSwapChain, 0))
            {
                mRenderTarget = new RenderTargetView(Device, texture);
            }

            var viewport = new Viewport
            {
                X = 0,
                Y = 0,
                Width = mWidth,
                Height = mHeight,
                MinZ = 0.0f,
                MaxZ = 1.0f
            };

            SetRasterizerState();
            CreateDepthBuffer();
            CreateStencilState();

            Device.Rasterizer.SetViewports(viewport);
            Device.OutputMerger.SetTargets(mDepthStencilView, mRenderTarget);
        }
Exemplo n.º 15
0
 /// <summary>
 /// Creates a device for wpf. 
 /// </summary>
 /// <param name="feature_level"></param>
 private void CreateDevice(FeatureLevel feature_level)
 {
     _device = new Device1(DriverType.Hardware, DeviceCreationFlags.Debug | DeviceCreationFlags.BgraSupport, feature_level);
 }
Exemplo n.º 16
0
        public void Dispose()
        {
            if (_depth_stencil_view != null && !_depth_stencil_view.Disposed)
            {
                _depth_stencil_view.Dispose();
                _depth_stencil_view = null;
            }

            if (_depth_buffer != null && !_depth_buffer.Disposed)
            {
                _depth_buffer.Dispose();
                _depth_buffer = null;
            }

            if (_render_target != null && !_render_target.Disposed)
            {
                _render_target.Dispose();
                _render_target = null;
            }

            if (_swapchain != null && !_swapchain.Disposed)
            {
                _swapchain.Dispose();
                _swapchain = null;
            }

            if (_device != null && !_device.Disposed)
            {
                _device.Dispose();
                _device = null;
            }
        }