private void CheckColorTexture() { if (_tex2DColorImage1 == null) { Texture2DDescription description = new Texture2DDescription() { Width = RoomAliveToolkit.Kinect2Calibration.colorImageWidth, Height = RoomAliveToolkit.Kinect2Calibration.colorImageHeight, MipLevels = 1, ArraySize = 1, Format = SharpDX.DXGI.Format.B8G8R8A8_UNorm, Usage = ResourceUsage.Dynamic, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.Write, SampleDescription = new SharpDX.DXGI.SampleDescription(count: 1, quality: 0) }; _tex2DColorImage1 = SharpDX.Toolkit.Graphics.Texture2D.New(GraphicsDevice, description); _tex2DColorImage2 = SharpDX.Toolkit.Graphics.Texture2D.New(GraphicsDevice, description); } }
private void CheckDepthTexture() { if (depthImageTexture == null) { var depthImageTextureDesc = new Texture2DDescription() { Width = RoomAliveToolkit.Kinect2Calibration.depthImageWidth, Height = RoomAliveToolkit.Kinect2Calibration.depthImageHeight, MipLevels = 1, ArraySize = 1, Format = SharpDX.DXGI.Format.R16_UInt, SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0), Usage = ResourceUsage.Dynamic, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.Write, }; depthImageTexture = new SharpDX.Direct3D11.Texture2D(GraphicsDevice, depthImageTextureDesc); // Create toolkit texture that wraps the DX Texture _uintDepthImage1 = SharpDX.Toolkit.Graphics.Texture2D.New(GraphicsDevice, depthImageTexture); _uintDepthImage2 = SharpDX.Toolkit.Graphics.Texture2D.New(GraphicsDevice, depthImageTexture); } }
internal RenderTargetViewSelector(Texture texture) { this.texture = texture; }
protected override void LoadContent() { _spriteBatch = ToDisposeContent(new SpriteBatch(GraphicsDevice)); _depthRectangle = new Rectangle(0, 0, RoomAliveToolkit.Kinect2Calibration.depthImageWidth, RoomAliveToolkit.Kinect2Calibration.depthImageHeight); int depthWidth = RoomAliveToolkit.Kinect2Calibration.depthImageWidth; int depthHeight = RoomAliveToolkit.Kinect2Calibration.depthImageHeight; _roomAliveEffect = Content.Load <Effect>("Holographic"); _fromUintEffect = Content.Load <Effect>("FromUint"); _gaussianEffect = Content.Load <Effect>("BilateralFilter"); _colorSamplerState = ToDisposeContent(SharpDX.Toolkit.Graphics.SamplerState.New(this.GraphicsDevice, new SamplerStateDescription() { Filter = Filter.MinMagMipLinear, AddressU = TextureAddressMode.Border, AddressV = TextureAddressMode.Border, AddressW = TextureAddressMode.Border, BorderColor = new SharpDX.Color4(0.5f, 0.5f, 0.5f, 1.0f), ComparisonFunction = Comparison.Never, MaximumAnisotropy = 16, MipLodBias = 0, MinimumLod = -float.MaxValue, MaximumLod = float.MaxValue })); List <VertexPosition> vertices = new List <VertexPosition>(); List <int> indices = new List <int>(); // vertex buffer if (_camera.calibration != null) { var table = _camera.calibration.ComputeDepthFrameToCameraSpaceTable(); for (int i = 0; i < depthHeight; i++) { for (int j = 0; j < depthWidth; j++) { var point = table[RoomAliveToolkit.Kinect2Calibration.depthImageWidth * i + j]; vertices.Add(new VertexPosition(new SharpDX.Vector4(point.X, point.Y, j, i))); } } for (int i = 0; i < depthHeight - 1; i++) { for (int j = 0; j < depthWidth - 1; j++) { int baseIndex = depthWidth * i + j; indices.Add(baseIndex); indices.Add(baseIndex + depthWidth + 1); indices.Add(baseIndex + 1); indices.Add(baseIndex); indices.Add(baseIndex + depthWidth); indices.Add(baseIndex + depthWidth + 1); } } _vertexArray = vertices.ToArray(); _indexArray = indices.ToArray(); // build the plane geometry of the specified size and subdivision segments _geometry = ToDisposeContent(new GeometricPrimitive <VertexPosition>(GraphicsDevice, _vertexArray, _indexArray, true)); } else { Console.WriteLine("Camera '{0}' is missing calibration", _camera.name); Visible = false; Enabled = false; } if (!string.IsNullOrEmpty(_colorImageFilePath)) { _tex2DColorImage1 = SharpDX.Toolkit.Graphics.Texture2D.Load(GraphicsDevice, _colorImageFilePath, TextureFlags.ShaderResource, ResourceUsage.Dynamic); _tex2DColorImage2 = SharpDX.Toolkit.Graphics.Texture2D.Load(GraphicsDevice, _colorImageFilePath, TextureFlags.ShaderResource, ResourceUsage.Dynamic); } _imagingFactory = new SharpDX.WIC.ImagingFactory(); if (!string.IsNullOrEmpty(_depthImageFilePath)) { var depthImage = new RoomAliveToolkit.ShortImage(RoomAliveToolkit.Kinect2Calibration.depthImageWidth, RoomAliveToolkit.Kinect2Calibration.depthImageHeight); RoomAliveToolkit.ProjectorCameraEnsemble.LoadFromTiff(_imagingFactory, depthImage, _depthImageFilePath); UpdateDepthImage(this.GraphicsDevice, depthImage.DataIntPtr); } var floatDepthImageTextureDesc = new Texture2DDescription() { Width = depthWidth, Height = depthHeight, MipLevels = 1, ArraySize = 1, Format = SharpDX.DXGI.Format.R32_Float, SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0), Usage = ResourceUsage.Default, BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, }; _floatDepthImageFinal = ToDisposeContent(RenderTarget2D.New(GraphicsDevice, floatDepthImageTextureDesc)); _floatDepthImageSubpass = ToDisposeContent(RenderTarget2D.New(GraphicsDevice, floatDepthImageTextureDesc)); base.LoadContent(); }
internal unsafe void Initialize(ImageDescription description, IntPtr dataPointer, int offset, GCHandle?handle, bool bufferIsDisposable, PitchFlags pitchFlags = PitchFlags.None) { if (!FormatHelper.IsValid(description.Format) || FormatHelper.IsVideo(description.Format)) { throw new InvalidOperationException("Unsupported DXGI Format"); } this.handle = handle; switch (description.Dimension) { case TextureDimension.Texture1D: if (description.Width <= 0 || description.Height != 1 || description.Depth != 1 || description.ArraySize == 0) { throw new InvalidOperationException("Invalid Width/Height/Depth/ArraySize for Image 1D"); } // Check that miplevels are fine description.MipLevels = Texture.CalculateMipLevels(description.Width, 1, description.MipLevels); break; case TextureDimension.Texture2D: case TextureDimension.TextureCube: if (description.Width <= 0 || description.Height <= 0 || description.Depth != 1 || description.ArraySize == 0) { throw new InvalidOperationException("Invalid Width/Height/Depth/ArraySize for Image 2D"); } if (description.Dimension == TextureDimension.TextureCube) { if ((description.ArraySize % 6) != 0) { throw new InvalidOperationException("TextureCube must have an arraysize = 6"); } } // Check that miplevels are fine description.MipLevels = Texture.CalculateMipLevels(description.Width, description.Height, description.MipLevels); break; case TextureDimension.Texture3D: if (description.Width <= 0 || description.Height <= 0 || description.Depth <= 0 || description.ArraySize != 1) { throw new InvalidOperationException("Invalid Width/Height/Depth/ArraySize for Image 3D"); } // Check that miplevels are fine description.MipLevels = Texture.CalculateMipLevels(description.Width, description.Height, description.Depth, description.MipLevels); break; } // Calculate mipmaps int pixelBufferCount; this.mipMapToZIndex = CalculateImageArray(description, pitchFlags, out pixelBufferCount, out totalSizeInBytes); this.mipmapDescriptions = CalculateMipMapDescription(description, pitchFlags); zBufferCountPerArraySlice = this.mipMapToZIndex[this.mipMapToZIndex.Count - 1]; // Allocate all pixel buffers pixelBuffers = new PixelBuffer[pixelBufferCount]; pixelBufferArray = new PixelBufferArray(this); // Setup all pointers // only release buffer that is not pinned and is asked to be disposed. this.bufferIsDisposable = !handle.HasValue && bufferIsDisposable; this.buffer = dataPointer; if (dataPointer == IntPtr.Zero) { buffer = Utilities.AllocateMemory(totalSizeInBytes); offset = 0; this.bufferIsDisposable = true; } SetupImageArray((IntPtr)((byte *)buffer + offset), totalSizeInBytes, description, pitchFlags, pixelBuffers); Description = description; // PreCompute databoxes dataBoxArray = ComputeDataBox(); }