Exemplo n.º 1
0
        public InfoText(Device device)
        {
            this.device = device;
            outputMerger = device.OutputMerger;

            font = new Font(device, 20, 0, FontWeight.Normal, 0, false, FontCharacterSet.Default,
              FontPrecision.Default, FontQuality.ClearTypeNatural, FontPitchAndFamily.DontCare, "tahoma");

            renderTexture = new Texture2D(device, new Texture2DDescription()
            {
                ArraySize = 1,
                BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = Format.R8G8B8A8_UNorm,
                Height = rect.Height,
                Width = rect.Width,
                MipLevels = 1,
                OptionFlags = ResourceOptionFlags.None,
                SampleDescription = new SampleDescription(1, 0),
                Usage = ResourceUsage.Default
            });
            renderTextureView = new RenderTargetView(device, renderTexture);
            renderViews = new[] { renderTextureView };

            OverlayBufferRes = new ShaderResourceView(device, renderTexture, new ShaderResourceViewDescription()
            {
                Format = Format.R8G8B8A8_UNorm,
                Dimension = ShaderResourceViewDimension.Texture2D,
                Texture2D = new ShaderResourceViewDescription.Texture2DResource()
                {
                    MipLevels = 1,
                    MostDetailedMip = 0
                }
            });
        }
Exemplo n.º 2
0
        public void Render(Canvas canvas, Device2D device2D)
        {
            Contract.Requires(canvas != null);
            Contract.Requires(device2D != null);

            IntPtr sharedHandle = canvas.GetDeviceHandle(device2D);

            if(sharedHandle != _SharedHandle)
            {
                _SharedMutex.SafeDispose();
                _DependentView.SafeDispose();
                _SharedTexture.SafeDispose();

                _SharedMutex = null;
                _DependentView = null;
                _SharedTexture = null;

                if(sharedHandle != IntPtr.Zero)
                {
                    _SharedTexture = _Device3D.OpenSharedResource<Texture2D>(sharedHandle);

                    _SharedMutex = _SharedTexture.QueryInterface<KeyedMutex>();

                    _DependentView = new ShaderResourceView(_Device3D, _SharedTexture);

                    _SharedHandle = sharedHandle;
                }
            }

            if(_SharedMutex != null)
            {
                _SharedMutex.AcquireSync();

                try
                {
                    if(_SharedTexture != null)
                    {
                        var textureVariable = _Effect.GetVariableByName("tex2D");

                        Contract.Assert(textureVariable != null);

                        var shaderResource = textureVariable.AsShaderResource();

                        Contract.Assert(shaderResource != null);

                        shaderResource.SetResource(_DependentView);

                        _EffectPass.Apply();

                        _Device3D.Draw(_VertexCount, 0);
                    }
                }
                finally
                {
                    _SharedMutex.ReleaseSync();
                }
            }
        }
Exemplo n.º 3
0
		private void BindTextureFor1DColorProviders()
		{
			_descriptionTextureFor1DColorProvider = new Texture1DDescription()
			{
				ArraySize = 1,
				BindFlags = BindFlags.ShaderResource,
				CpuAccessFlags = CpuAccessFlags.Write,
				Format = Format.R32G32B32A32_Float,
				MipLevels = 1,
				OptionFlags = ResourceOptionFlags.None,
				Usage = ResourceUsage.Dynamic,
				Width = 1024
			};

			_textureFor1DColorProvider = new Texture1D(_hostDevice, _descriptionTextureFor1DColorProvider);

			var _textureFor1DColorMeshTextureView = new ShaderResourceView(_hostDevice, _textureFor1DColorProvider);

			var shaderResourceObj = this._lightingEffect.GetVariableByName("ColorGradient1DTexture");
			EffectShaderResourceVariable shaderResource = shaderResourceObj.AsShaderResource();
			shaderResource.SetResource(_textureFor1DColorMeshTextureView);
		}
Exemplo n.º 4
0
        void CreateBuffers()
        {
            DisposeBuffers();

            // New RenderTargetView from the backbuffer
            using (var bb = Texture2D.FromSwapChain<Texture2D>(_swapChain, 0))
            {
                renderView = new RenderTargetView(_device, bb);
                renderViews[0] = renderView;
            }

            Texture2DDescription gBufferDesc = new Texture2DDescription()
            {
                ArraySize = 1,
                BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = Format.R8G8B8A8_UNorm,
                Width = _width,
                Height = _height,
                MipLevels = 1,
                OptionFlags = ResourceOptionFlags.None,
                SampleDescription = new SampleDescription(1, 0),
                Usage = ResourceUsage.Default
            };

            gBufferLight = new Texture2D(_device, gBufferDesc);
            gBufferLightView = new RenderTargetView(_device, gBufferLight);

            gBufferNormal = new Texture2D(_device, gBufferDesc);
            gBufferNormalView = new RenderTargetView(_device, gBufferNormal);

            gBufferDiffuse = new Texture2D(_device, gBufferDesc);
            gBufferDiffuseView = new RenderTargetView(_device, gBufferDiffuse);

            gBufferViews = new RenderTargetView[] { gBufferLightView, gBufferNormalView, gBufferDiffuseView };

            ShaderResourceViewDescription gBufferResourceDesc = new ShaderResourceViewDescription()
            {
                Format = Format.R8G8B8A8_UNorm,
                Dimension = ShaderResourceViewDimension.Texture2D,
                Texture2D = new ShaderResourceViewDescription.Texture2DResource()
                {
                    MipLevels = 1,
                    MostDetailedMip = 0
                }
            };
            lightBufferRes = new ShaderResourceView(_device, gBufferLight, gBufferResourceDesc);
            normalBufferRes = new ShaderResourceView(_device, gBufferNormal, gBufferResourceDesc);
            diffuseBufferRes = new ShaderResourceView(_device, gBufferDiffuse, gBufferResourceDesc);

            Texture2DDescription depthDesc = new Texture2DDescription()
            {
                ArraySize = 1,
                BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = Format.R32_Typeless,
                Width = _width,
                Height = _height,
                MipLevels = 1,
                OptionFlags = ResourceOptionFlags.None,
                SampleDescription = new SampleDescription(1, 0),
                Usage = ResourceUsage.Default
            };

            DepthStencilViewDescription depthViewDesc = new DepthStencilViewDescription()
            {
                Dimension = DepthStencilViewDimension.Texture2D,
                Format = Format.D32_Float,
            };

            ShaderResourceViewDescription resourceDesc = new ShaderResourceViewDescription()
            {
                Format = Format.R32_Float,
                Dimension = ShaderResourceViewDimension.Texture2D,
                Texture2D = new ShaderResourceViewDescription.Texture2DResource()
                {
                    MipLevels = 1,
                    MostDetailedMip = 0
                }
            };

            depthTexture = new Texture2D(_device, depthDesc);
            depthView = new DepthStencilView(_device, depthTexture, depthViewDesc);
            depthRes = new ShaderResourceView(_device, depthTexture, resourceDesc);

            lightDepthTexture = new Texture2D(_device, depthDesc);
            lightDepthView = new DepthStencilView(_device, lightDepthTexture, depthViewDesc);
            lightDepthRes = new ShaderResourceView(_device, lightDepthTexture, resourceDesc);

            lightBufferVar = effect2.GetVariableByName("lightBuffer").AsShaderResource();
            normalBufferVar = effect2.GetVariableByName("normalBuffer").AsShaderResource();
            diffuseBufferVar = effect2.GetVariableByName("diffuseBuffer").AsShaderResource();
            depthMapVar = effect2.GetVariableByName("depthMap").AsShaderResource();
            lightDepthMapVar = effect2.GetVariableByName("lightDepthMap").AsShaderResource();

            _device.Rasterizer.SetViewports(new Viewport(0, 0, _width, _height));
        }
Exemplo n.º 5
0
		private void CreateAndBindTargets(int sizeX, int sizeY)
		{
			_d3dImageSource.SetRenderTargetDX10(null);

			Disposer.RemoveAndDispose(ref this._renderTargetView);
			Disposer.RemoveAndDispose(ref this._renderTargetIntermediateView);
			Disposer.RemoveAndDispose(ref this._renderTargetIntermediateShaderResourceView);
			Disposer.RemoveAndDispose(ref this._depthStencilView);
			Disposer.RemoveAndDispose(ref this._renderTarget);
			Disposer.RemoveAndDispose(ref this._renderTargetIntermediate);
			Disposer.RemoveAndDispose(ref this._depthStencil);
			Disposer.RemoveAndDispose(ref this._gammaCorrector);

			if (sizeX >= 2 && sizeY >= 2)
			{
				Texture2DDescription colordesc = new Texture2DDescription
				{
					BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
					Format = Format.B8G8R8A8_UNorm,
					Width = sizeX,
					Height = sizeY,
					MipLevels = 1,
					SampleDescription = new SampleDescription(1, 0),
					Usage = ResourceUsage.Default,
					OptionFlags = ResourceOptionFlags.Shared,
					CpuAccessFlags = CpuAccessFlags.None,
					ArraySize = 1
				};

				Texture2DDescription renderTextureDescriptionForD3D9 = new Texture2DDescription
				{
					BindFlags = BindFlags.None,
					Format = Format.B8G8R8A8_UNorm,
					Width = sizeX,
					Height = sizeY,
					MipLevels = 1,
					SampleDescription = new SampleDescription(1, 0),
					Usage = ResourceUsage.Staging,
					OptionFlags = ResourceOptionFlags.Shared,
					CpuAccessFlags = CpuAccessFlags.Read,
					ArraySize = 1
				};

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

				this._renderTarget = new Texture2D(this._device, colordesc);
				this._renderTargetIntermediate = new Texture2D(this._device, colordesc);
				this._depthStencil = new Texture2D(this._device, depthdesc);
				this._renderTargetIntermediateView = new RenderTargetView(this._device, this._renderTargetIntermediate);
				this._renderTargetIntermediateShaderResourceView = new ShaderResourceView(this._device, this._renderTargetIntermediate);
				this._renderTargetView = new RenderTargetView(this._device, this._renderTarget);
				this._depthStencilView = new DepthStencilView(this._device, this._depthStencil);
				this._gammaCorrector = new D3D10GammaCorrector(_device, "Altaxo.CompiledShaders.Effects.GammaCorrector.cso");

				this._d3dImageSource.SetRenderTargetDX10(this._renderTarget);
			}
		}
Exemplo n.º 6
0
 /// <summary>	
 /// Get an array of shader resources.	
 /// </summary>	
 /// <param name="offset">The zero-based array index to get the first interface. </param>
 /// <param name="count">The number of elements in the array. </param>
 /// <returns>Returns an array of shader-resource-view interfaces. See <see cref="SharpDX.Direct3D10.ShaderResourceView"/>. </returns>
 /// <unmanaged>HRESULT ID3D10EffectShaderResourceVariable::GetResourceArray([Out] ID3D10ShaderResourceView** ppResources,[None] int Offset,[None] int Count)</unmanaged>
 public SharpDX.Direct3D10.ShaderResourceView[] GetResourceArray(int offset, int count)
 {
     ShaderResourceView[] temp = new ShaderResourceView[count];
     GetResourceArray(temp, offset, count);
     return temp;
 }        
Exemplo n.º 7
0
        void videoPanelViewModel_VideoOpened(Object sender, EventArgs e)
        {

            for (int i = 0; i < nrTextures; i++)
            {
                Disposer.RemoveAndDispose(ref this.yuvTexture[i]);
                Disposer.RemoveAndDispose(ref this.textureView[i]);
            }
                                
            if (videoPlayerViewModel.DecodedVideoFormat == VideoLib.VideoPlayer.DecodedVideoFormat.YUV420P)
            {               
                int width = videoPlayerViewModel.Width;
                int height = videoPlayerViewModel.Height;

                yuvTexture[0] = createTexture(width, height, Format.R8_UNorm);
                yuvTexture[1] = createTexture(width / 2, height / 2, Format.R8_UNorm);
                yuvTexture[2] = createTexture(width / 2, height / 2, Format.R8_UNorm);

                nrTextures = 3;
            }
            else
            {                
                yuvTexture[0] = createTexture(videoPlayerViewModel.Width, videoPlayerViewModel.Height, Format.B8G8R8A8_UNorm);

                nrTextures = 1;
            }

            Device device = Host.Device;

            for (int i = 0; i < nrTextures; i++)
            {
                ShaderResourceViewDescription desc = new ShaderResourceViewDescription();
                desc.Format = yuvTexture[i].Description.Format;
                desc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D;
                desc.Texture2D.MipLevels = yuvTexture[i].Description.MipLevels;
                desc.Texture2D.MostDetailedMip = yuvTexture[i].Description.MipLevels - 1;

                textureView[i] = new ShaderResourceView(device, yuvTexture[i], desc);

            }
  
            viewport = setupViewport(videoPlayerViewModel.Width, videoPlayerViewModel.Height);
           
            device.Flush();

            DPFCanvas canvas = (DPFCanvas)Host;
            canvas.StartRendering();
             
        }
Exemplo n.º 8
0
 /// <summary>
 /// Get an array of shader resources.
 /// </summary>
 /// <param name="offset">The zero-based array index to get the first interface. </param>
 /// <param name="count">The number of elements in the array. </param>
 /// <returns>Returns an array of shader-resource-view interfaces. See <see cref="SharpDX.Direct3D10.ShaderResourceView"/>. </returns>
 /// <unmanaged>HRESULT ID3D10EffectShaderResourceVariable::GetResourceArray([Out] ID3D10ShaderResourceView** ppResources,[None] int Offset,[None] int Count)</unmanaged>
 public SharpDX.Direct3D10.ShaderResourceView[] GetResourceArray(int offset, int count)
 {
     ShaderResourceView[] temp = new ShaderResourceView[count];
     GetResourceArray(temp, offset, count);
     return(temp);
 }