Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VertexElement" /> struct.
        /// </summary>
        /// <param name="semanticName">Name of the semantic.</param>
        /// <param name="semanticIndex">Index of the semantic.</param>
        /// <param name="format">The format.</param>
        /// <param name="alignedByteOffset">The aligned byte offset.</param>
        public VertexElement(string semanticName, int semanticIndex, Format format, int alignedByteOffset = AppendAligned) : this()
        {
            if (semanticName == null)
            {
                throw new ArgumentNullException("semanticName");
            }

            // All semantics will be upper case.
            semanticName = semanticName.ToUpperInvariant();

            var match = MatchSemanticIndex.Match(semanticName);

            if (match.Success)
            {
                throw new ArgumentException("Semantic name cannot a semantic index when using constructor with explicit semantic index. Use implicit semantic index constructor.");
            }

            // Convert to singleton string in order to speed up things.
            this.semanticName      = (SingletonString)semanticName;
            this.semanticIndex     = semanticIndex;
            this.format            = format;
            this.alignedByteOffset = alignedByteOffset;

            // Precalculate hashcode
            hashCode = ComputeHashCode();
        }
Example #2
0
 /// <summary>
 /// Makes Typless format from UNorm or SRgb
 /// </summary>
 /// <param name="format"></param>
 /// <returns></returns>
 internal protected DXGI.Format MakeTypeless(DXGI.Format format)
 {
     if (format == DXGI.Format.B8G8R8A8_UNorm)
     {
         return(DXGI.Format.B8G8R8A8_Typeless);
     }
     if (format == DXGI.Format.R8G8B8A8_UNorm)
     {
         return(DXGI.Format.R8G8B8A8_Typeless);
     }
     if (format == DXGI.Format.B8G8R8X8_UNorm)
     {
         return(DXGI.Format.B8G8R8X8_Typeless);
     }
     if (format == DXGI.Format.BC1_UNorm)
     {
         return(DXGI.Format.BC1_Typeless);
     }
     if (format == DXGI.Format.BC2_UNorm)
     {
         return(DXGI.Format.BC2_Typeless);
     }
     if (format == DXGI.Format.BC3_UNorm)
     {
         return(DXGI.Format.BC3_Typeless);
     }
     if (format == DXGI.Format.BC7_UNorm)
     {
         return(DXGI.Format.BC7_Typeless);
     }
     if (format == DXGI.Format.B8G8R8A8_UNorm_SRgb)
     {
         return(DXGI.Format.B8G8R8A8_Typeless);
     }
     if (format == DXGI.Format.R8G8B8A8_UNorm_SRgb)
     {
         return(DXGI.Format.R8G8B8A8_Typeless);
     }
     if (format == DXGI.Format.B8G8R8X8_UNorm_SRgb)
     {
         return(DXGI.Format.B8G8R8X8_Typeless);
     }
     if (format == DXGI.Format.BC1_UNorm_SRgb)
     {
         return(DXGI.Format.BC1_Typeless);
     }
     if (format == DXGI.Format.BC2_UNorm_SRgb)
     {
         return(DXGI.Format.BC2_Typeless);
     }
     if (format == DXGI.Format.BC3_UNorm_SRgb)
     {
         return(DXGI.Format.BC3_Typeless);
     }
     if (format == DXGI.Format.BC7_UNorm_SRgb)
     {
         return(DXGI.Format.BC7_Typeless);
     }
     return(format);
 }
Example #3
0
        private Texture2D CaptureTexture(DeviceContext deviceContext,
                                         Texture2D source, out Texture2DDescription desc)
        {
            Device d3dDevice = deviceContext.Device;
            // debug: i got it!
            //D3D11.Texture2D texture = source.QueryInterface<D3D11.Texture2D>();
            Texture2D staging = null;

            desc = source.Description;

            if (desc.SampleDescription.Count > 1)
            {
                desc.SampleDescription.Count   = 1;
                desc.SampleDescription.Quality = 0;

                Texture2D temp = new Texture2D(d3dDevice, desc);

                DXGI.Format fmt = EnsureNotTypeless(desc.Format);

                FormatSupport support = d3dDevice.CheckFormatSupport(fmt);

                if ((support & FormatSupport.MultisampleResolve) == 0)
                {
                    return(null);
                }

                for (int item = 0; item < desc.ArraySize; ++item)
                {
                    for (int level = 0; level < desc.MipLevels; ++level)
                    {
                        int index = Resource.CalculateSubResourceIndex(level, item, desc.MipLevels);
                        deviceContext.ResolveSubresource(temp, index, source, index, fmt);
                    }
                }

                desc.BindFlags      = 0;
                desc.OptionFlags   &= ResourceOptionFlags.TextureCube;
                desc.CpuAccessFlags = CpuAccessFlags.Read;
                desc.Usage          = ResourceUsage.Staging;

                staging = new Texture2D(d3dDevice, desc);
                deviceContext.CopyResource(temp, staging);
            }
            else if (desc.Usage == ResourceUsage.Staging &&
                     desc.CpuAccessFlags == CpuAccessFlags.Read)
            {
                staging = source;
            }
            else
            {
                desc.BindFlags      = 0;
                desc.OptionFlags   &= ResourceOptionFlags.TextureCube;
                desc.CpuAccessFlags = CpuAccessFlags.Read;
                desc.Usage          = ResourceUsage.Staging;
                staging             = new Texture2D(d3dDevice, desc);
                deviceContext.CopyResource(source, staging);
            }

            return(staging);
        }
Example #4
0
        internal static void ComputePitch(DXGI.Format fmt, int width, int height, out int rowPitch, out int slicePitch, out int widthCount, out int heightCount, PitchFlags flags = PitchFlags.None)
        {
            widthCount  = width;
            heightCount = height;

            if (DXGI.FormatHelper.IsCompressed(fmt))
            {
                int bpb = (fmt == DXGI.Format.BC1_Typeless ||
                           fmt == DXGI.Format.BC1_UNorm ||
                           fmt == DXGI.Format.BC1_UNorm_SRgb ||
                           fmt == DXGI.Format.BC4_Typeless ||
                           fmt == DXGI.Format.BC4_UNorm ||
                           fmt == DXGI.Format.BC4_SNorm) ? 8 : 16;
                widthCount  = Math.Max(1, (width + 3) / 4);
                heightCount = Math.Max(1, (height + 3) / 4);
                rowPitch    = widthCount * bpb;

                slicePitch = rowPitch * heightCount;
            }
            else if (DXGI.FormatHelper.IsPacked(fmt))
            {
                rowPitch = ((width + 1) >> 1) * 4;

                slicePitch = rowPitch * height;
            }
            else
            {
                int bpp;

                if ((flags & PitchFlags.Bpp24) != 0)
                {
                    bpp = 24;
                }
                else if ((flags & PitchFlags.Bpp16) != 0)
                {
                    bpp = 16;
                }
                else if ((flags & PitchFlags.Bpp8) != 0)
                {
                    bpp = 8;
                }
                else
                {
                    bpp = DXGI.FormatHelper.SizeOfInBits(fmt);
                }

                if ((flags & PitchFlags.LegacyDword) != 0)
                {
                    // Special computation for some incorrectly created DDS files based on
                    // legacy DirectDraw assumptions about pitch alignment
                    rowPitch   = ((width * bpp + 31) / 32) * sizeof(int);
                    slicePitch = rowPitch * height;
                }
                else
                {
                    rowPitch   = (width * bpp + 7) / 8;
                    slicePitch = rowPitch * height;
                }
            }
        }
Example #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VertexElement" /> struct.
        /// </summary>
        /// <param name="semanticName">Name of the semantic.</param>
        /// <param name="format">The format.</param>
        /// <remarks>
        /// If the semantic name contains a postfix number, this number will be used as a semantic index.
        /// </remarks>
        public VertexElement(string semanticName, Format format) : this()
        {
            if (semanticName == null)
            {
                throw new ArgumentNullException("semanticName");
            }

            // All semantics will be upper case.
            semanticName = semanticName.ToUpperInvariant();

            var match = MatchSemanticIndex.Match(semanticName);

            if (match.Success)
            {
                // Convert to singleton string in order to speed up things.
                this.semanticName = (SingletonString)match.Groups[1].Value;
                semanticIndex     = int.Parse(match.Groups[2].Value);
            }
            else
            {
                this.semanticName = (SingletonString)semanticName;
            }

            this.format       = format;
            alignedByteOffset = AppendAligned;

            // Precalculate hashcode
            hashCode = ComputeHashCode();
        }
Example #6
0
        public static SharpDX.DXGI.Format GetDXGIFormat(TextureFormat fmt)
        {
            SharpDX.DXGI.Format format = SharpDX.DXGI.Format.Unknown;
            switch (fmt)
            {
            // compressed
            case TextureFormat.D3DFMT_DXT1: format = SharpDX.DXGI.Format.BC1_UNorm; break;

            case TextureFormat.D3DFMT_DXT3: format = SharpDX.DXGI.Format.BC2_UNorm; break;

            case TextureFormat.D3DFMT_DXT5: format = SharpDX.DXGI.Format.BC3_UNorm; break;

            case TextureFormat.D3DFMT_ATI1: format = SharpDX.DXGI.Format.BC4_UNorm; break;

            case TextureFormat.D3DFMT_ATI2: format = SharpDX.DXGI.Format.BC5_UNorm; break;

            case TextureFormat.D3DFMT_BC7: format = SharpDX.DXGI.Format.BC7_UNorm; break;

            // uncompressed
            case TextureFormat.D3DFMT_A1R5G5B5: format = SharpDX.DXGI.Format.B5G5R5A1_UNorm; break;

            case TextureFormat.D3DFMT_A8: format = SharpDX.DXGI.Format.A8_UNorm; break;

            case TextureFormat.D3DFMT_A8B8G8R8: format = SharpDX.DXGI.Format.R8G8B8A8_UNorm; break;

            case TextureFormat.D3DFMT_L8: format = SharpDX.DXGI.Format.R8_UNorm; break;

            case TextureFormat.D3DFMT_A8R8G8B8: format = SharpDX.DXGI.Format.B8G8R8A8_UNorm; break;
            }
            return(format);
        }
Example #7
0
        public ImageFormat(SharpDX.DXGI.Format format)
        {
            DxgiFormat = format;
            switch (format)
            {
            case Format.R32G32B32A32_Float:
                GliFormat = GliFormat.RGBA32_SFLOAT;
                PixelSize = 4 * 4;
                break;

            case Format.R8G8B8A8_UNorm_SRgb:
                GliFormat = GliFormat.RGBA8_SRGB;
                PixelSize = 4;
                break;

            case Format.R8G8B8A8_UNorm:
                GliFormat = GliFormat.RGBA8_UNORM;
                PixelSize = 4;
                break;

            case Format.R8G8B8A8_SNorm:
                GliFormat = GliFormat.RGBA8_SNORM;
                PixelSize = 4;
                break;

            default:
                Debug.Assert(false);
                break;
            }
        }
Example #8
0
        public ImageFormat(GliFormat format)
        {
            GliFormat = format;
            switch (format)
            {
            case GliFormat.RGBA32_SFLOAT:
                DxgiFormat = Format.R32G32B32A32_Float;
                break;

            case GliFormat.RGBA8_SRGB:
                DxgiFormat = Format.R8G8B8A8_UNorm_SRgb;
                break;

            case GliFormat.RGBA8_UNORM:
                DxgiFormat = Format.R8G8B8A8_UNorm;
                break;

            case GliFormat.RGBA8_SNORM:
                DxgiFormat = Format.R8G8B8A8_SNorm;
                break;

            default:
                Debug.Assert(false);
                break;
            }
        }
Example #9
0
        /// <summary>
        /// Renders this GeometryResource.
        /// </summary>
        /// <param name="renderState">Current render state.</param>
        public void Render(RenderState renderState)
        {
            D3D11.DeviceContext deviceContext     = renderState.Device.DeviceImmediateContextD3D11;
            DXGI.Format         indexBufferFormat = renderState.Device.SupportsOnly16BitIndexBuffer ? DXGI.Format.R16_UInt : DXGI.Format.R32_UInt;

            int lastVertexBufferID = -1;
            int lastIndexBufferID  = -1;

            for (int loop = 0; loop < m_loadedStructures.Length; loop++)
            {
                LoadedStructureInfo structureToDraw = m_loadedStructures[loop];

                // Apply VertexBuffer
                if (lastVertexBufferID != structureToDraw.VertexBufferID)
                {
                    lastVertexBufferID = structureToDraw.VertexBufferID;
                    deviceContext.InputAssembler.InputLayout = structureToDraw.InputLayout;
                    deviceContext.InputAssembler.SetVertexBuffers(0, new D3D11.VertexBufferBinding(structureToDraw.VertexBuffer, structureToDraw.SizePerVertex, 0));
                }

                // Apply IndexBuffer
                if (lastIndexBufferID != structureToDraw.IndexBufferID)
                {
                    deviceContext.InputAssembler.SetIndexBuffer(structureToDraw.IndexBuffer, indexBufferFormat, 0);
                }

                // Apply material
                renderState.ApplyMaterial(structureToDraw.Material);
                D3D11.InputLayout newInputLayout = null;
                if (renderState.ForcedMaterial != null)
                {
                    newInputLayout = renderState.ForcedMaterial.GenerateInputLayout(
                        renderState.Device,
                        StandardVertex.InputElements,
                        MaterialApplyInstancingMode.SingleObject);
                    deviceContext.InputAssembler.InputLayout = newInputLayout;
                }
                try
                {
                    // Draw current rener block
                    deviceContext.DrawIndexed(
                        structureToDraw.IndexCount,
                        structureToDraw.StartIndex,
                        0);
                }
                finally
                {
                    if (newInputLayout != null)
                    {
                        deviceContext.InputAssembler.InputLayout = null;
                        GraphicsHelper.SafeDispose(ref newInputLayout);
                    }
                }
            }
        }
Example #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TextureUploader"/> class.
        /// </summary>
        /// <param name="device">The device on which the texture was created.</param>
        /// <param name="texture">The texture which is to be uploaded to system memory.</param>
        internal TextureUploader(EngineDevice device, D3D11.Texture2D texture)
        {
            var textureDesc = texture.Description;

            m_device         = device;
            m_texture        = texture;
            m_width          = textureDesc.Width;
            m_height         = textureDesc.Height;
            m_format         = textureDesc.Format;
            m_isMultisampled = (textureDesc.SampleDescription.Count > 1) || (textureDesc.SampleDescription.Quality > 0);
        }
        public static Format ToDirect3D9(DXGI.Format format)
        {
            switch (format)
            {
            case DXGI.Format.R8G8B8A8_UNorm:
                return(Format.A8R8G8B8);

            case DXGI.Format.B5G6R5_UNorm:
                return(Format.R5G6B5);

            case DXGI.Format.B5G5R5A1_UNorm:
                return(Format.A1R5G5B5);

            case DXGI.Format.A8_UNorm:
                return(Format.A8);

            case DXGI.Format.R10G10B10A2_UNorm:
                return(Format.A2B10G10R10);

            case DXGI.Format.B8G8R8A8_UNorm:
                return(Format.A8B8G8R8);

            case DXGI.Format.R16G16_UNorm:
                return(Format.G16R16);

            case DXGI.Format.R16G16B16A16_UNorm:
                return(Format.A16B16G16R16);

            case DXGI.Format.R16_Float:
                return(Format.R16F);

            case DXGI.Format.R16G16_Float:
                return(Format.G16R16F);

            case DXGI.Format.R16G16B16A16_Float:
                return(Format.A16B16G16R16F);

            case DXGI.Format.R32_Float:
                return(Format.R32F);

            case DXGI.Format.R32G32_Float:
                return(Format.G32R32F);

            case DXGI.Format.R32G32B32A32_Float:
                return(Format.A32B32G32R32F);
            }

            return(Format.Unknown);
        }
Example #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PixelBuffer" /> struct.
        /// </summary>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="format">The format.</param>
        /// <param name="rowStride">The row pitch.</param>
        /// <param name="bufferStride">The slice pitch.</param>
        /// <param name="dataPointer">The pixels.</param>
        public PixelBuffer(int width, int height, DXGI.Format format, int rowStride, int bufferStride, IntPtr dataPointer)
        {
            if (dataPointer == IntPtr.Zero)
            {
                throw new ArgumentException("Pointer cannot be equal to IntPtr.Zero", "dataPointer");
            }

            this.width             = width;
            this.height            = height;
            this.format            = format;
            this.rowStride         = rowStride;
            this.bufferStride      = bufferStride;
            this.dataPointer       = dataPointer;
            this.pixelSize         = DXGI.FormatHelper.SizeOfInBytes(this.format);
            this.isStrictRowStride = (pixelSize * width) == rowStride;
        }
Example #13
0
        private DXGI.Format EnsureNotTypeless(DXGI.Format format)
        {
            switch (format)
            {
            case DXGI.Format.R32G32B32A32_Typeless: return(DXGI.Format.R32G32B32A32_Float);

            case DXGI.Format.R32G32B32_Typeless: return(DXGI.Format.R32G32B32_Float);

            case DXGI.Format.R16G16B16A16_Typeless: return(DXGI.Format.R16G16B16A16_UNorm);

            case DXGI.Format.R32G32_Typeless: return(DXGI.Format.R32G32_Float);

            case DXGI.Format.R10G10B10A2_Typeless: return(DXGI.Format.R10G10B10A2_UNorm);

            case DXGI.Format.R8G8B8A8_Typeless: return(DXGI.Format.R8G8B8A8_UNorm);

            case DXGI.Format.R16G16_Typeless: return(DXGI.Format.R16G16_UNorm);

            case DXGI.Format.R32_Typeless: return(DXGI.Format.R32_Float);

            case DXGI.Format.R8G8_Typeless: return(DXGI.Format.R8G8_UNorm);

            case DXGI.Format.R16_Typeless: return(DXGI.Format.R16_UNorm);

            case DXGI.Format.R8_Typeless: return(DXGI.Format.R8_UNorm);

            case DXGI.Format.BC1_Typeless: return(DXGI.Format.BC1_UNorm);

            case DXGI.Format.BC2_Typeless: return(DXGI.Format.BC2_UNorm);

            case DXGI.Format.BC3_Typeless: return(DXGI.Format.BC3_UNorm);

            case DXGI.Format.BC4_Typeless: return(DXGI.Format.BC4_UNorm);

            case DXGI.Format.BC5_Typeless: return(DXGI.Format.BC5_UNorm);

            case DXGI.Format.B8G8R8A8_Typeless: return(DXGI.Format.B8G8R8A8_UNorm);

            case DXGI.Format.B8G8R8X8_Typeless: return(DXGI.Format.B8G8R8X8_UNorm);

            case DXGI.Format.BC7_Typeless: return(DXGI.Format.BC7_UNorm);

            default: return(format);
            }
        }
Example #14
0
		/// <summary>
		/// Makes Typless format from UNorm or SRgb
		/// </summary>
		/// <param name="format"></param>
		/// <returns></returns>
		internal protected DXGI.Format MakeTypeless ( DXGI.Format format )
		{
			if (format==DXGI.Format.B8G8R8A8_UNorm) return DXGI.Format.B8G8R8A8_Typeless;
			if (format==DXGI.Format.R8G8B8A8_UNorm) return DXGI.Format.R8G8B8A8_Typeless;
			if (format==DXGI.Format.B8G8R8X8_UNorm) return DXGI.Format.B8G8R8X8_Typeless;
			if (format==DXGI.Format.BC1_UNorm) return DXGI.Format.BC1_Typeless;
			if (format==DXGI.Format.BC2_UNorm) return DXGI.Format.BC2_Typeless;
			if (format==DXGI.Format.BC3_UNorm) return DXGI.Format.BC3_Typeless;
			if (format==DXGI.Format.BC7_UNorm) return DXGI.Format.BC7_Typeless;
			if (format==DXGI.Format.B8G8R8A8_UNorm_SRgb) return DXGI.Format.B8G8R8A8_Typeless;
			if (format==DXGI.Format.R8G8B8A8_UNorm_SRgb) return DXGI.Format.R8G8B8A8_Typeless;
			if (format==DXGI.Format.B8G8R8X8_UNorm_SRgb) return DXGI.Format.B8G8R8X8_Typeless;
			if (format==DXGI.Format.BC1_UNorm_SRgb) return DXGI.Format.BC1_Typeless;
			if (format==DXGI.Format.BC2_UNorm_SRgb) return DXGI.Format.BC2_Typeless;
			if (format==DXGI.Format.BC3_UNorm_SRgb) return DXGI.Format.BC3_Typeless;
			if (format==DXGI.Format.BC7_UNorm_SRgb) return DXGI.Format.BC7_Typeless;
			return format;
		}
        public static int GetColorBits(DXGI.Format format)
        {
            switch (format)
            {
            case DXGI.Format.R32G32B32A32_Float:
            case DXGI.Format.R32G32B32A32_SInt:
            case DXGI.Format.R32G32B32A32_Typeless:
            case DXGI.Format.R32G32B32A32_UInt:
            case DXGI.Format.R32G32B32_Float:
            case DXGI.Format.R32G32B32_SInt:
            case DXGI.Format.R32G32B32_Typeless:
            case DXGI.Format.R32G32B32_UInt:
                return(32);

            case DXGI.Format.R16G16B16A16_Float:
            case DXGI.Format.R16G16B16A16_SInt:
            case DXGI.Format.R16G16B16A16_SNorm:
            case DXGI.Format.R16G16B16A16_Typeless:
            case DXGI.Format.R16G16B16A16_UInt:
            case DXGI.Format.R16G16B16A16_UNorm:
                return(16);

            case DXGI.Format.R10G10B10A2_Typeless:
            case DXGI.Format.R10G10B10A2_UInt:
            case DXGI.Format.R10G10B10A2_UNorm:
                return(10);

            case DXGI.Format.R8G8B8A8_SInt:
            case DXGI.Format.R8G8B8A8_SNorm:
            case DXGI.Format.R8G8B8A8_Typeless:
            case DXGI.Format.R8G8B8A8_UInt:
            case DXGI.Format.R8G8B8A8_UNorm:
            case DXGI.Format.R8G8B8A8_UNorm_SRgb:
                return(8);

            case DXGI.Format.B5G5R5A1_UNorm:
            case DXGI.Format.B5G6R5_UNorm:
                return(5);

            default:
                return(0);
            }
        }
Example #16
0
        public override void Init(IntPtr display, IntPtr window, uint samples, bool vsync, bool sRGB)
        {
            _display = display;
            _window  = window;

            System.Console.WriteLine("Creating D3D12 render context");

            CreateDevice();
            CreateCommandQueue();
            CreateSwapChain(window, vsync);

            _format     = sRGB ? SharpDX.DXGI.Format.R8G8B8A8_UNorm_SRgb : SharpDX.DXGI.Format.R8G8B8A8_UNorm;
            _sampleDesc = GetSampleDescription(samples);
            samples     = (uint)_sampleDesc.Count;

            CreateHeaps();
            CreateBuffers();
            CreateCommandList();

            _device = new RenderDeviceD3D12(_dev.NativePointer, _fence.NativePointer, (int)_format, (int)SharpDX.DXGI.Format.D24_UNorm_S8_UInt,
                                            _sampleDesc.Count, sRGB);
        }
Example #17
0
        /// <summary>
        /// Converts a <see cref="SharpDX.DXGI.Format"/> to a a WIC <see cref="WIC.PixelFormat"/>.
        /// </summary>
        /// <param name="format">A <see cref="SharpDX.DXGI.Format"/></param>
        /// <param name="guid">A WIC <see cref="WIC.PixelFormat"/> Guid.</param>
        /// <returns>True if conversion succeed, false otherwise.</returns>
        private static bool ToWIC(DXGI.Format format, out Guid guid)
        {
            for (int i = 0; i < WICToDXGIFormats.Length; ++i)
            {
                if (WICToDXGIFormats[i].Format == format)
                {
                    guid = WICToDXGIFormats[i].WIC;
                    return(true);
                }
            }

            // Special cases
            switch (format)
            {
            case SharpDX.DXGI.Format.R8G8B8A8_UNorm_SRgb:
                guid = SharpDX.WIC.PixelFormat.Format32bppRGBA;
                return(true);

            case SharpDX.DXGI.Format.D32_Float:
                guid = SharpDX.WIC.PixelFormat.Format32bppGrayFloat;
                return(true);

            case SharpDX.DXGI.Format.D16_UNorm:
                guid = SharpDX.WIC.PixelFormat.Format16bppGray;
                return(true);

            case SharpDX.DXGI.Format.B8G8R8A8_UNorm_SRgb:
                guid = SharpDX.WIC.PixelFormat.Format32bppBGRA;
                return(true);

            case SharpDX.DXGI.Format.B8G8R8X8_UNorm_SRgb:
                guid = SharpDX.WIC.PixelFormat.Format32bppBGR;
                return(true);
            }

            guid = Guid.Empty;
            return(false);
        }
        /// <summary>
        /// Gets the maximum MSAA sample count for a particular <see cref="PixelFormat" />.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="pixelFormat">The pixelFormat.</param>
        /// <returns>The maximum multisample count for this pixel pixelFormat</returns>
        private static MSAALevel GetMaximumMSAASampleCount(SharpDX.Direct3D11.Device device, SharpDX.DXGI.Format pixelFormat)
        {
            int maxCount = 1;

            for (int i = 1; i <= 8; i *= 2)
            {
                if (device.CheckMultisampleQualityLevels(pixelFormat, i) != 0)
                {
                    maxCount = i;
                }
            }
            return((MSAALevel)maxCount);
        }
Example #19
0
        public void Setup(OperatorPart outputOpPart, double startTime = 0, double endTime = 184, double frameRate   = 30, double width                = 1920, double height = 1080,
                          string fileExtension = "png", bool skipExistingFiles            = false, string directory = "output", string filenameFormat = "[T]", SharpDX.DXGI.Format imageFormat = Format.R8G8B8A8_UNorm)
        {
            try
            {
                Dispose();

                _outputOpPart      = outputOpPart;
                _directory         = directory;
                _fileNameFormat    = filenameFormat;
                _startTime         = startTime;
                _endTime           = endTime;
                _frameRate         = frameRate;
                _width             = (int)width;
                _height            = (int)height;
                _samples           = 2;
                _fileExtension     = fileExtension.ToLower();
                _skipExistingFiles = skipExistingFiles;

                _defaultContext = new OperatorPartContext(0.0f);
                _defaultContext.Variables.Add("Screensize.Width", _width);
                _defaultContext.Variables.Add("Screensize.Height", _height);
                _defaultContext.Variables.Add("AspectRatio", (float)_width / _height);
                _defaultContext.Variables.Add("Samples", _samples);
                _defaultContext.Variables.Add("FullScreen", 0.0f);
                _defaultContext.Variables.Add("LoopMode", 0.0f);
                _defaultContext.ImageBufferFormat = imageFormat;

                _frameTime = 1.0 / _frameRate;

                Directory.CreateDirectory(_directory);

                _renderer = new DefaultRenderer();

                _texture = ShaderResourceView.FromFile(D3DDevice.Device, "./assets-common/image/white.png");


                _renderTargetResource = null;
                ResourceManager.ValidateRenderTargetResource(ref _renderTargetResource, _outputOpPart, D3DDevice.Device, _width, _height, imageFormat);
                _renderTargetView = new RenderTargetView(D3DDevice.Device, _renderTargetResource.Texture);

                _renderDepthResource = null;
                ResourceManager.ValidateDepthStencilResource(ref _renderDepthResource, _outputOpPart, D3DDevice.Device, _width, _height);
                var depthViewDesc = new DepthStencilViewDescription();
                depthViewDesc.Format    = Format.D32_Float;
                depthViewDesc.Dimension = DepthStencilViewDimension.Texture2D;

                _renderTargetDepthView = new DepthStencilView(D3DDevice.Device, _renderDepthResource.Texture, depthViewDesc);

                _gpuSyncer = new BlockingGpuSyncer(D3DDevice.Device);

                D3DDevice.Device.ImmediateContext.OutputMerger.SetTargets(_renderTargetDepthView, _renderTargetView);
                _viewport = new ViewportF(0, 0, _width, _height, 0.0f, 1.0f);
                D3DDevice.Device.ImmediateContext.Rasterizer.SetViewport(_viewport);


                var timeAccessorCollector = new OperatorPart.CollectOpPartFunctionsOfType <OperatorPartTraits.ITimeAccessor>();
                _outputOpPart.TraverseWithFunction(timeAccessorCollector, null);
                _timeAccessorOpPartFunctions = new List <OperatorPart.Function>();
                foreach (var opPartFunction in timeAccessorCollector.CollectedOpPartFunctions)
                {
                    _timeAccessorOpPartFunctions.Add(opPartFunction as OperatorPart.Function);
                }
                _currentTime = _startTime;
            }
            catch (Exception e)
            {
                Logger.Error("Failed to setup image-sequence {0}", e.Message);
            }
        }
        /// <summary>
        /// creates a thumbnail for one image layer/mipmap
        /// </summary>
        /// <param name="size">maximum width/height of the thumbnail</param>
        /// <param name="texture">source texture</param>
        /// <param name="dstFormat">destination texture format</param>
        /// <param name="layer">source layer</param>
        /// <returns>texture with width, height smaller or equal to size. One layer and one mipmap</returns>
        public TextureArray2D CreateThumbnail(int size, ITexture texture,
                                              SharpDX.DXGI.Format dstFormat, int layer, ScalingModel scaling)
        {
            Debug.Assert(ImageFormat.IsSupported(dstFormat));
            Debug.Assert(ImageFormat.IsSupported(texture.Format));

            // determine dimensions of output texture
            var width  = 0;
            var height = 0;

            if (texture.Size.Width > texture.Size.Height)
            {
                width  = size;
                height = (texture.Size.Height * size) / texture.Size.Width;
            }
            else
            {
                height = size;
                width  = (texture.Size.Width * size) / texture.Size.Height;
            }
            Debug.Assert(width <= size);
            Debug.Assert(height <= size);

            var res = new TextureArray2D(LayerMipmapCount.One, new Size3(width, height), dstFormat, false);

            // compute which mipmap has the closest fit
            var mipmap   = 0;
            var curWidth = texture.Size.Width;

            while (curWidth >= width)
            {
                ++mipmap;
                curWidth /= 2;
            }
            // mipmap just jumped over the optimal size
            mipmap = Math.Max(0, mipmap - 1);

            var      dev    = Device.Get();
            ITexture tmpTex = null;

            if (texture.NumMipmaps < mipmap + 1)
            {
                // generate new texture with mipmaps
                tmpTex = texture.CloneWithMipmaps(mipmap + 1);

                scaling.WriteMipmaps(tmpTex);
                dev.Pixel.SetShaderResource(0, tmpTex.GetSrView(new LayerMipmapSlice(layer, mipmap)));
            }
            else
            {
                dev.Pixel.SetShaderResource(0, texture.GetSrView(new LayerMipmapSlice(layer, mipmap)));
            }

            quad.Bind(false);
            if (texture.Is3D)
            {
                dev.Pixel.Set(convert3D.Pixel);
            }
            else
            {
                dev.Pixel.Set(convert2D.Pixel);
            }

            dev.Pixel.SetSampler(0, sampler);

            dev.OutputMerger.SetRenderTargets(res.GetRtView(LayerMipmapSlice.Mip0));
            dev.SetViewScissors(width, height);
            dev.DrawFullscreenTriangle(1);

            // remove bindings
            dev.Pixel.SetShaderResource(0, null);
            dev.OutputMerger.SetRenderTargets((RenderTargetView)null);
            quad.Unbind();

            tmpTex?.Dispose();

            return(res);
        }
Example #21
0
        /// <summary>
        /// for unit testing purposes. Converts naked srv to TextureArray2D
        /// </summary>
        internal Texture3D ConvertFromRaw3D(SharpDX.Direct3D11.ShaderResourceView srv, Size3 size, SharpDX.DXGI.Format dstFormat, bool isInteger)
        {
            var res = new Texture3D(1, size, dstFormat, false);

            var dev = DirectX.Device.Get();

            quad.Bind(true);
            if (isInteger)
            {
                if (convert3DInt == null)
                {
                    convert3DInt = new DirectX.Shader(DirectX.Shader.Type.Pixel, GetSource(new ShaderBuilder3D("int4")), "ConvertInt");
                }
                dev.Pixel.Set(convert3DInt.Pixel);
            }
            else
            {
                dev.Pixel.Set(convert3D.Pixel);
            }

            dev.Pixel.SetShaderResource(0, srv);

            cbuffer.SetData(new LayerLevelOffsetData
            {
                Layer      = 0,
                Level      = 0,
                Xoffset    = 0,
                Yoffset    = 0,
                Multiplier = 1.0f,
                UseOverlay = 0,
                Scale      = 1
            });

            dev.Pixel.SetConstantBuffer(0, cbuffer.Handle);
            dev.OutputMerger.SetRenderTargets(res.GetRtView(LayerMipmapSlice.Mip0));
            dev.SetViewScissors(size.Width, size.Height);
            dev.DrawFullscreenTriangle(size.Depth);

            // remove bindings
            dev.Pixel.SetShaderResource(0, null);
            dev.OutputMerger.SetRenderTargets((RenderTargetView)null);
            quad.Unbind();

            return(res);
        }
        // if texture cannot be loaded, it will be used byte pattern to generate substition texture
        public IFileArrayTexture CreateFromFiles(string resourceName, string[] inputFiles, MyFileTextureEnum type, byte[] bytePatternFor4x4, Format formatBytePattern, bool autoDisposeOnUnload)
        {
            MyFileArrayTexture array;
            m_fileTextureArrays.AllocateOrCreate(out array);
            array.Load(resourceName, inputFiles, type, bytePatternFor4x4, formatBytePattern);

            if (m_isDeviceInit)
                array.OnDeviceInit();

            if (autoDisposeOnUnload)
                m_texturesOnAutoDisposal.Add(array);

            return array;
        }
Example #23
0
 public WICTranslate(Guid wic, DXGI.Format format)
 {
     this.WIC    = wic;
     this.Format = format;
 }
Example #24
0
 /// <summary>
 /// Copy a multisampled resource into a non-multisampled resource. This API is most useful when re-using the resulting render target of one render pass as an input to a second render pass.
 /// </summary>
 /// <remarks>
 /// Both the source and destination resources must be the same {{resource type}} and have the same dimensions. The source and destination must have compatible formats. There are three scenarios for this:  ScenarioRequirements Source and destination are prestructured and typedBoth the source and destination must have identical formats and that format must be specified in the Format parameter. One resource is prestructured and typed and the other is prestructured and typelessThe typed resource must have a format that is compatible with the typeless resource (i.e. the typed resource is DXGI_FORMAT_R32_FLOAT and the typeless resource is DXGI_FORMAT_R32_TYPELESS). The format of the typed resource must be specified in the Format parameter. Source and destination are prestructured and typelessBoth the source and destination must have the same typeless format (i.e. both must have DXGI_FORMAT_R32_TYPELESS), and the Format parameter must specify a format that is compatible with the source and destination (i.e. if both are DXGI_FORMAT_R32_TYPELESS then DXGI_FORMAT_R32_FLOAT or DXGI_FORMAT_R32_UINT could be specified in the Format parameter).  ?
 /// </remarks>
 /// <param name="source">Source resource. Must be multisampled. </param>
 /// <param name="sourceSubresource">The source subresource of the source resource. </param>
 /// <param name="destination">Destination resource. Must be a created with the <see cref="SharpDX.Direct3D10.ResourceUsage.Default"/> flag and be single-sampled. See <see cref="SharpDX.Direct3D10.Resource"/>. </param>
 /// <param name="destinationSubresource">A zero-based index, that identifies the destination subresource. See {{D3D10CalcSubresource}} for more details. </param>
 /// <param name="format">that indicates how the multisampled resource will be resolved to a single-sampled resource. See remarks. </param>
 /// <unmanaged>void ID3D10Device::ResolveSubresource([In] ID3D10Resource* pDstResource,[In] int DstSubresource,[In] ID3D10Resource* pSrcResource,[In] int SrcSubresource,[In] DXGI_FORMAT Format)</unmanaged>
 public void ResolveSubresource(SharpDX.Direct3D10.Resource source, int sourceSubresource, SharpDX.Direct3D10.Resource destination, int destinationSubresource, SharpDX.DXGI.Format format)
 {
     ResolveSubresource_(destination, destinationSubresource, source, sourceSubresource, format);
 }
Example #25
0
        public static Guid PixelFormatFromFormat(SharpDX.DXGI.Format format)
        {
            switch (format)
            {
            case SharpDX.DXGI.Format.R32G32B32A32_Typeless:
            case SharpDX.DXGI.Format.R32G32B32A32_Float:
                return(SharpDX.WIC.PixelFormat.Format128bppRGBAFloat);

            case SharpDX.DXGI.Format.R32G32B32A32_UInt:
            case SharpDX.DXGI.Format.R32G32B32A32_SInt:
                return(SharpDX.WIC.PixelFormat.Format128bppRGBAFixedPoint);

            case SharpDX.DXGI.Format.R32G32B32_Typeless:
            case SharpDX.DXGI.Format.R32G32B32_Float:
                return(SharpDX.WIC.PixelFormat.Format96bppRGBFloat);

            case SharpDX.DXGI.Format.R32G32B32_UInt:
            case SharpDX.DXGI.Format.R32G32B32_SInt:
                return(SharpDX.WIC.PixelFormat.Format96bppRGBFixedPoint);

            case SharpDX.DXGI.Format.R16G16B16A16_Typeless:
            case SharpDX.DXGI.Format.R16G16B16A16_Float:
            case SharpDX.DXGI.Format.R16G16B16A16_UNorm:
            case SharpDX.DXGI.Format.R16G16B16A16_UInt:
            case SharpDX.DXGI.Format.R16G16B16A16_SNorm:
            case SharpDX.DXGI.Format.R16G16B16A16_SInt:
                return(SharpDX.WIC.PixelFormat.Format64bppRGBA);

            case SharpDX.DXGI.Format.R32G32_Typeless:
            case SharpDX.DXGI.Format.R32G32_Float:
            case SharpDX.DXGI.Format.R32G32_UInt:
            case SharpDX.DXGI.Format.R32G32_SInt:
            case SharpDX.DXGI.Format.R32G8X24_Typeless:
            case SharpDX.DXGI.Format.D32_Float_S8X24_UInt:
            case SharpDX.DXGI.Format.R32_Float_X8X24_Typeless:
            case SharpDX.DXGI.Format.X32_Typeless_G8X24_UInt:
                return(Guid.Empty);

            case SharpDX.DXGI.Format.R10G10B10A2_Typeless:
            case SharpDX.DXGI.Format.R10G10B10A2_UNorm:
            case SharpDX.DXGI.Format.R10G10B10A2_UInt:
                return(SharpDX.WIC.PixelFormat.Format32bppRGBA1010102);

            case SharpDX.DXGI.Format.R11G11B10_Float:
                return(Guid.Empty);

            case SharpDX.DXGI.Format.R8G8B8A8_Typeless:
            case SharpDX.DXGI.Format.R8G8B8A8_UNorm:
            case SharpDX.DXGI.Format.R8G8B8A8_UNorm_SRgb:
            case SharpDX.DXGI.Format.R8G8B8A8_UInt:
            case SharpDX.DXGI.Format.R8G8B8A8_SNorm:
            case SharpDX.DXGI.Format.R8G8B8A8_SInt:
                return(SharpDX.WIC.PixelFormat.Format32bppRGBA);

            case SharpDX.DXGI.Format.R16G16_Typeless:
            case SharpDX.DXGI.Format.R16G16_Float:
            case SharpDX.DXGI.Format.R16G16_UNorm:
            case SharpDX.DXGI.Format.R16G16_UInt:
            case SharpDX.DXGI.Format.R16G16_SNorm:
            case SharpDX.DXGI.Format.R16G16_SInt:
                return(Guid.Empty);

            case SharpDX.DXGI.Format.R32_Typeless:
            case SharpDX.DXGI.Format.D32_Float:
            case SharpDX.DXGI.Format.R32_Float:
            case SharpDX.DXGI.Format.R32_UInt:
            case SharpDX.DXGI.Format.R32_SInt:
                return(Guid.Empty);

            case SharpDX.DXGI.Format.R24G8_Typeless:
            case SharpDX.DXGI.Format.D24_UNorm_S8_UInt:
            case SharpDX.DXGI.Format.R24_UNorm_X8_Typeless:
                return(SharpDX.WIC.PixelFormat.Format32bppGrayFloat);

            case SharpDX.DXGI.Format.X24_Typeless_G8_UInt:
            case SharpDX.DXGI.Format.R9G9B9E5_Sharedexp:
            case SharpDX.DXGI.Format.R8G8_B8G8_UNorm:
            case SharpDX.DXGI.Format.G8R8_G8B8_UNorm:
                return(Guid.Empty);

            case SharpDX.DXGI.Format.B8G8R8A8_UNorm:
            case SharpDX.DXGI.Format.B8G8R8X8_UNorm:
                return(SharpDX.WIC.PixelFormat.Format32bppBGRA);

            case SharpDX.DXGI.Format.R10G10B10_Xr_Bias_A2_UNorm:
                return(SharpDX.WIC.PixelFormat.Format32bppBGR101010);

            case SharpDX.DXGI.Format.B8G8R8A8_Typeless:
            case SharpDX.DXGI.Format.B8G8R8A8_UNorm_SRgb:
            case SharpDX.DXGI.Format.B8G8R8X8_Typeless:
            case SharpDX.DXGI.Format.B8G8R8X8_UNorm_SRgb:
                return(SharpDX.WIC.PixelFormat.Format32bppBGRA);

            case SharpDX.DXGI.Format.R8G8_Typeless:
            case SharpDX.DXGI.Format.R8G8_UNorm:
            case SharpDX.DXGI.Format.R8G8_UInt:
            case SharpDX.DXGI.Format.R8G8_SNorm:
            case SharpDX.DXGI.Format.R8G8_SInt:
                return(Guid.Empty);

            case SharpDX.DXGI.Format.R16_Typeless:
            case SharpDX.DXGI.Format.R16_Float:
            case SharpDX.DXGI.Format.D16_UNorm:
            case SharpDX.DXGI.Format.R16_UNorm:
            case SharpDX.DXGI.Format.R16_SNorm:
                return(SharpDX.WIC.PixelFormat.Format16bppGrayHalf);

            case SharpDX.DXGI.Format.R16_UInt:
            case SharpDX.DXGI.Format.R16_SInt:
                return(SharpDX.WIC.PixelFormat.Format16bppGrayFixedPoint);

            case SharpDX.DXGI.Format.B5G6R5_UNorm:
                return(SharpDX.WIC.PixelFormat.Format16bppBGR565);

            case SharpDX.DXGI.Format.B5G5R5A1_UNorm:
                return(SharpDX.WIC.PixelFormat.Format16bppBGRA5551);

            case SharpDX.DXGI.Format.B4G4R4A4_UNorm:
                return(Guid.Empty);

            case SharpDX.DXGI.Format.R8_Typeless:
            case SharpDX.DXGI.Format.R8_UNorm:
            case SharpDX.DXGI.Format.R8_UInt:
            case SharpDX.DXGI.Format.R8_SNorm:
            case SharpDX.DXGI.Format.R8_SInt:
                return(SharpDX.WIC.PixelFormat.Format8bppGray);

            case SharpDX.DXGI.Format.A8_UNorm:
                return(SharpDX.WIC.PixelFormat.Format8bppAlpha);

            case SharpDX.DXGI.Format.R1_UNorm:
                return(SharpDX.WIC.PixelFormat.Format1bppIndexed);

            default:
                return(Guid.Empty);
            }
        }
Example #26
0
 /// <summary>
 /// converts the texture into another format and performs cropping if requested
 /// </summary>
 /// <param name="texture">source texture</param>
 /// <param name="dstFormat">destination format</param>
 /// <param name="scaling">required for regenerating mipmaps after cropping</param>
 /// <param name="mipmap">mipmap to export, -1 for all mipmaps</param>
 /// <param name="layer">layer to export, -1 for all layers</param>
 /// <param name="multiplier">rgb channels will be multiplied by this value</param>
 public ITexture Convert(ITexture texture, SharpDX.DXGI.Format dstFormat, ScalingModel scaling, int mipmap = -1, int layer = -1, float multiplier = 1.0f)
 {
     return(Convert(texture, dstFormat, new LayerMipmapRange(layer, mipmap), multiplier, false, Size3.Zero, Size3.Zero, Size3.Zero, scaling, null));
 }
Example #27
0
            public void Load(string resourceName, string[] filePaths, MyFileTextureEnum type, byte[] bytePattern, Format formatBytePattern)
            {
                m_resourceName = resourceName;

                if (m_listSubresourceFilenames == null)
                {
                    m_objectsPoolOfStringLists.AllocateOrCreate(out m_listSubresourceFilenames);
                }
                m_listSubresourceFilenames.Clear();
                foreach (string path in filePaths)
                {
                    m_listSubresourceFilenames.Add(path);
                }
                m_type = type;

                ISrvBindable tex = MyManagers.FileTextures.GetTexture(filePaths[0], type);

                m_size        = tex.Size;
                TextureFormat = Format.Unknown;
                m_recoverySystem.UseBytePattern    = true;
                m_recoverySystem.FormatBytePattern = formatBytePattern;
                m_recoverySystem.BytePattern       = bytePattern;
            }
Example #28
0
        // if texture cannot be loaded, it will be used byte pattern to generate substition texture
        public IFileArrayTexture CreateFromFiles(string resourceName, string[] inputFiles, MyFileTextureEnum type, byte[] bytePatternFor4x4, Format formatBytePattern, bool autoDisposeOnUnload)
        {
            MyFileArrayTexture array;

            m_fileTextureArrays.AllocateOrCreate(out array);
            array.Load(resourceName, inputFiles, type, bytePatternFor4x4, formatBytePattern);

            if (m_isDeviceInit)
            {
                array.OnDeviceInit();
            }

            if (autoDisposeOnUnload)
            {
                m_texturesOnAutoDisposal.Add(array);
            }

            return(array);
        }
Example #29
0
        //-------------------------------------------------------------------------------------
        // Returns the DXGI format and optionally the WIC pixel Guid to convert to
        //-------------------------------------------------------------------------------------
        private static DXGI.Format DetermineFormat(Guid pixelFormat, WICFlags flags, out Guid pixelFormatOut)
        {
            DXGI.Format format = ToDXGI(pixelFormat);
            pixelFormatOut = Guid.Empty;

            if (format == DXGI.Format.Unknown)
            {
                for (int i = 0; i < WICConvertTable.Length; ++i)
                {
                    if (WICConvertTable[i].source == pixelFormat)
                    {
                        pixelFormatOut = WICConvertTable[i].target;

                        format = ToDXGI(WICConvertTable[i].target);
                        Debug.Assert(format != DXGI.Format.Unknown);
                        break;
                    }
                }
            }

            // Handle special cases based on flags
            switch (format)
            {
            case DXGI.Format.B8G8R8A8_UNorm:     // BGRA
            case DXGI.Format.B8G8R8X8_UNorm:     // BGRX
                if ((flags & WICFlags.ForceRgb) != 0)
                {
                    format         = DXGI.Format.R8G8B8A8_UNorm;
                    pixelFormatOut = WIC.PixelFormat.Format32bppRGBA;
                }
                break;

            case DXGI.Format.R10G10B10_Xr_Bias_A2_UNorm:
                if ((flags & WICFlags.NoX2Bias) != 0)
                {
                    format         = DXGI.Format.R10G10B10A2_UNorm;
                    pixelFormatOut = WIC.PixelFormat.Format32bppRGBA1010102;
                }
                break;

            case DXGI.Format.B5G5R5A1_UNorm:
            case DXGI.Format.B5G6R5_UNorm:
                if ((flags & WICFlags.No16Bpp) != 0)
                {
                    format         = DXGI.Format.R8G8B8A8_UNorm;
                    pixelFormatOut = WIC.PixelFormat.Format32bppRGBA;
                }
                break;

            case DXGI.Format.R1_UNorm:
                if ((flags & WICFlags.FlagsAllowMono) == 0)
                {
                    // By default we want to promote a black & white to greyscale since R1 is not a generally supported D3D format
                    format         = DXGI.Format.R8_UNorm;
                    pixelFormatOut = WIC.PixelFormat.Format8bppGray;
                }
                break;
            }

            return(format);
        }
Example #30
0
        /// <summary>
        /// converts the texture into another format and performs cropping if requested
        /// </summary>
        /// <param name="texture">source texture</param>
        /// <param name="dstFormat">destination format</param>
        /// <param name="srcLm">layer/mipmap to export</param>
        /// <param name="multiplier">rgb channels will be multiplied by this value</param>
        /// <param name="crop">indicates if the image should be cropped, only works with 1 mipmap to export</param>
        /// <param name="offset">if crop: offset in source image</param>
        /// <param name="size">if crop: size of the destination image</param>
        /// <param name="align">if nonzero: texture width will be aligned to this (rounded down)</param>
        /// <param name="scaling">required for regenerating mipmaps after cropping.</param>
        /// <param name="overlay">overlay</param>
        /// <param name="scale">scales the destination image by this factor</param>
        /// <returns></returns>
        public ITexture Convert(ITexture texture, SharpDX.DXGI.Format dstFormat, LayerMipmapRange srcLm, float multiplier, bool crop,
                                Size3 offset, Size3 size, Size3 align, ScalingModel scaling, ITexture overlay = null, int scale = 1)
        {
            Debug.Assert(ImageFormat.IsSupported(dstFormat));
            Debug.Assert(ImageFormat.IsSupported(texture.Format));
            Debug.Assert(overlay == null || texture.HasSameDimensions(overlay));
            Debug.Assert(scale >= 1);

            // set width, height mipmap
            int nMipmaps = srcLm.IsSingleMipmap ? 1: texture.NumMipmaps;
            int nLayer   = srcLm.IsSingleLayer ? 1 : texture.NumLayers;

            // set correct width, height, offsets
            if (!crop)
            {
                size   = texture.Size.GetMip(srcLm.FirstMipmap);
                offset = Size3.Zero;
            }

            if (scale != 1)
            {
                size.X *= scale;
                size.Y *= scale;
                if (texture.Is3D)
                {
                    size.Z *= scale;
                }
                offset.X *= scale;
                offset.Y *= scale;
                if (texture.Is3D)
                {
                    offset.Z *= scale;
                }
            }

            // adjust alignments
            for (int i = 0; i < 3; ++i)
            {
                if (align[i] != 0)
                {
                    if (size[i] % align[i] != 0)
                    {
                        if (size[i] < align[i])
                        {
                            throw new Exception($"image needs to be aligned to {align[i]} but one axis is only {size[i]}. Axis should be at least {align[i]}");
                        }

                        crop = true;
                        var remainder = size[i] % align[i];
                        offset[i] = offset[i] + remainder / 2;
                        size[i]   = size[i] - remainder;
                    }
                }
            }

            bool recomputeMips = nMipmaps > 1 && (crop || scale != 1);

            if (recomputeMips)
            {
                // number of mipmaps might have changed
                nMipmaps      = size.MaxMipLevels;
                recomputeMips = nMipmaps > 1;
            }

            var res = texture.Create(new LayerMipmapCount(nLayer, nMipmaps), size, dstFormat, false);

            var dev = DirectX.Device.Get();

            quad.Bind(texture.Is3D);
            if (texture.Is3D)
            {
                dev.Pixel.Set(convert3D.Pixel);
            }
            else
            {
                dev.Pixel.Set(convert2D.Pixel);
            }

            dev.Pixel.SetShaderResource(0, texture.View);
            if (overlay != null)
            {
                dev.Pixel.SetShaderResource(1, overlay.View);
            }
            else
            {
                dev.Pixel.SetShaderResource(1, null);
            }

            foreach (var dstLm in res.LayerMipmap.Range)
            {
                cbuffer.SetData(new LayerLevelOffsetData
                {
                    Layer      = dstLm.Layer + srcLm.FirstLayer + offset.Z,
                    Level      = dstLm.Mipmap + srcLm.FirstMipmap,
                    Xoffset    = offset.X,
                    Yoffset    = offset.Y,
                    Multiplier = multiplier,
                    UseOverlay = overlay != null ? 1 : 0,
                    Scale      = scale
                });

                var dim = res.Size.GetMip(dstLm.Mipmap);
                dev.Pixel.SetConstantBuffer(0, cbuffer.Handle);
                dev.OutputMerger.SetRenderTargets(res.GetRtView(dstLm));
                dev.SetViewScissors(dim.Width, dim.Height);
                dev.DrawFullscreenTriangle(dim.Depth);

                if (recomputeMips && dstLm.Mipmap > 0)
                {
                    break;                                    // only write most detailed mipmap
                }
            }

            // remove bindings
            dev.Pixel.SetShaderResource(0, null);
            dev.Pixel.SetShaderResource(1, null);
            dev.OutputMerger.SetRenderTargets((RenderTargetView)null);
            quad.Unbind();

            if (recomputeMips)
            {
                scaling.WriteMipmaps(res);
            }

            return(res);
        }
 /// <summary>
 /// Gets the <see cref="FeaturesPerFormat" /> for the specified <see cref="SharpDX.DXGI.Format" />.
 /// </summary>
 /// <param name="dxgiFormat">The DXGI format.</param>
 /// <returns>Features for the specific format.</returns>
 public                                     FeaturesPerFormat this[SharpDX.DXGI.Format dxgiFormat]
 {
     get { return(this.mapFeaturesPerFormat[(int)dxgiFormat]); }
 }
            public void Load(string resourceName, string[] filePaths, MyFileTextureEnum type, byte[] bytePattern, Format formatBytePattern)
            {
                m_resourceName = resourceName;

                if (m_listSubresourceFilenames == null)
                    m_objectsPoolOfStringLists.AllocateOrCreate(out m_listSubresourceFilenames);
                m_listSubresourceFilenames.Clear();
                foreach (string path in filePaths)
                    m_listSubresourceFilenames.Add(path);
                m_type = type;

                ISrvBindable tex = MyManagers.FileTextures.GetTexture(filePaths[0], type);
                m_size = tex.Size;
                TextureFormat = Format.Unknown;
                m_recoverySystem.UseBytePattern = true;
                m_recoverySystem.FormatBytePattern = formatBytePattern;
                m_recoverySystem.BytePattern = bytePattern;
            }