Ejemplo n.º 1
0
        public WindowsMixedRealityGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters)
            : base(device, presentationParameters)
        {
            holographicSpace = HolographicSpace.CreateForCoreWindow(CoreWindow.GetForCurrentThread());
            CoreWindow.GetForCurrentThread().Activate();

            Device3         d3DDevice        = device.NativeDevice.QueryInterface <Device3>();
            IDirect3DDevice d3DInteropDevice = null;

            // Acquire the DXGI interface for the Direct3D device.
            using (var dxgiDevice = d3DDevice.QueryInterface <SharpDX.DXGI.Device3>())
            {
                // Wrap the native device using a WinRT interop object.
                uint hr = CreateDirect3D11DeviceFromDXGIDevice(dxgiDevice.NativePointer, out IntPtr pUnknown);

                if (hr == 0)
                {
                    d3DInteropDevice = Marshal.GetObjectForIUnknown(pUnknown) as IDirect3DDevice;
                    Marshal.Release(pUnknown);
                }
            }

            holographicSpace.SetDirect3D11Device(d3DInteropDevice);

            BeginDraw(null);
            ResizeDepthStencilBuffer(backBuffer.Width, backBuffer.Height, 0);

            // Set a dummy back buffer as we use a seperate one for each eye.
            BackBuffer = Texture.New(GraphicsDevice, backBuffer.Description, null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates the depth stencil buffer.
        /// </summary>
        protected virtual void CreateDepthStencilBuffer()
        {
            // If no depth stencil buffer, just return
            if (Description.DepthStencilFormat == PixelFormat.None)
            {
                return;
            }

            // Creates the depth stencil buffer.
            var flags = TextureFlags.DepthStencil;

            if (GraphicsDevice.Features.CurrentProfile >= GraphicsProfile.Level_10_0 && Description.MultisampleCount == MultisampleCount.None)
            {
                flags |= TextureFlags.ShaderResource;
            }

            // Create texture description
            var depthTextureDescription = TextureDescription.New2D(Description.BackBufferWidth, Description.BackBufferHeight, Description.DepthStencilFormat, flags);

            depthTextureDescription.MultisampleCount = Description.MultisampleCount;

            var depthTexture = Texture.New(GraphicsDevice, depthTextureDescription);

            DepthStencilBuffer = depthTexture.DisposeBy(this);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a texture from an image file data (png, dds, ...).
        /// </summary>
        /// <param name="graphicsDevice">The graphics device in which to create the texture</param>
        /// <param name="data">The image file data</param>
        /// <returns>The texture</returns>
        public static Texture FromFileData(GraphicsDevice graphicsDevice, byte[] data)
        {
            Texture result;

            var loadAsSRgb = graphicsDevice.ColorSpace == ColorSpace.Linear;

            using (var imageStream = new MemoryStream(data))
            {
                using (var image = Image.Load(imageStream, loadAsSRgb))
                {
                    result = Texture.New(graphicsDevice, image);
                }
            }

            result.Reload = (graphicsResource, services) =>
            {
                using (var imageStream = new MemoryStream(data))
                {
                    using (var image = Image.Load(imageStream, loadAsSRgb))
                    {
                        ((Texture)graphicsResource).Recreate(image.ToDataBox());
                    }
                }
            };

            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a new texture that can be used as a ShaderResource from an existing depth texture.
        /// </summary>
        /// <returns></returns>
        public static Texture CreateDepthTextureCompatible(this Texture texture)
        {
            if (!texture.IsDepthStencil)
            {
                throw new NotSupportedException("This texture is not a valid depth stencil texture");
            }

            var description = texture.Description;

            description.Format = Texture.ComputeShaderResourceFormatFromDepthFormat(description.Format); // TODO: review this
            if (description.Format == PixelFormat.None)
            {
                throw new NotSupportedException("This depth stencil format is not supported");
            }

            description.Flags = TextureFlags.ShaderResource;
            return(Texture.New(texture.GraphicsDevice, description));
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Creates a texture for output.
 /// </summary>
 /// <param name="description">The description.</param>
 /// <param name="viewFormat">The pixel format seen by the shader</param>
 /// <returns>Texture.</returns>
 protected virtual Texture CreateTexture(TextureDescription description, PixelFormat viewFormat)
 {
     return(Texture.New(GraphicsDevice, description));
 }