Ejemplo n.º 1
0
 /// <summary>Initializes a new instance of the <see cref="DisplayMode"/> class.</summary>
 /// <param name="pixelFormat">The pixel format.</param>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="refreshRate">The refresh rate.</param>
 public DisplayMode(Format pixelFormat, int width, int height, Rational refreshRate)
 {
     this.pixelFormat = pixelFormat;
     this.width = width;
     this.height = height;
     this.refreshRate = refreshRate;
 }
Ejemplo n.º 2
0
 public DisplayMode(Format pixelFormat, int width, int height, Rational refreshRate)
 {
     this.pixelFormat = pixelFormat;
     this.width       = width;
     this.height      = height;
     this.refreshRate = refreshRate;
 }
Ejemplo n.º 3
0
 internal DepthStencilBuffer(GraphicsDevice device, Direct3D11.Texture2D texture, DepthFormat depthFormat)
     : base(device, texture)
 {
     DepthFormat = depthFormat;
     DefaultViewFormat = ComputeViewFormat(DepthFormat, out HasStencil);
     Initialize(Resource);
     HasReadOnlyView = InitializeViewsDelayed(out ReadOnlyView);
 }
Ejemplo n.º 4
0
 internal DepthStencilBuffer(GraphicsDevice device, Texture2DDescription description2D, DepthFormat depthFormat)
     : base(device, description2D)
 {
     DepthFormat = depthFormat;
     DefaultViewFormat = ComputeViewFormat(DepthFormat, out HasStencil);
     Initialize(Resource);
     HasReadOnlyView = InitializeViewsDelayed(out ReadOnlyView);
 }
Ejemplo n.º 5
0
 internal DepthStencilBuffer(GraphicsDevice device, Texture2DDescription description2D, DepthFormat depthFormat)
     : base(device, description2D)
 {
     DepthFormat       = depthFormat;
     DefaultViewFormat = ComputeViewFormat(DepthFormat, out HasStencil);
     Initialize(Resource);
     HasReadOnlyView = InitializeViewsDelayed(out ReadOnlyView);
 }
Ejemplo n.º 6
0
 internal DepthStencilBuffer(GraphicsDevice device, Direct3D11.Texture2D texture, DepthFormat depthFormat)
     : base(device, texture)
 {
     DepthFormat       = depthFormat;
     DefaultViewFormat = ComputeViewFormat(DepthFormat, out HasStencil);
     Initialize(Resource);
     HasReadOnlyView = InitializeViewsDelayed(out ReadOnlyView);
 }
Ejemplo n.º 7
0
 internal DepthStencilBuffer(Direct3D11.Device device, Direct3D11.Texture2D texture, DepthFormat depthFormat)
     : base(device, texture)
 {
     DepthFormat       = depthFormat;
     DefaultViewFormat = ComputeViewFormat(DepthFormat, out HasStencil);
     Initialize(Resource);
     HasReadOnlyView  = InitializeViewsDelayed();
     DepthStencilView = new DepthStencilViewSelector(this);
 }
Ejemplo n.º 8
0
 public static ResourceDescription Texture1D(DXGI.Format format,
                                             long width,
                                             short arraySize           = 1,
                                             short mipLevels           = 0,
                                             ResourceOptionFlags flags = ResourceOptionFlags.None,
                                             TextureLayout layout      = TextureLayout.Unknown,
                                             long alignment            = 0)
 {
     return(new ResourceDescription(ResourceDimension.Texture1D, alignment, width, 1, arraySize, mipLevels, format, 1, 0, layout, flags));
 }
Ejemplo n.º 9
0
 public static ResourceDescription Texture3D(DXGI.Format format,
                                             long width,
                                             int height,
                                             short depth,
                                             short mipLevels      = 0,
                                             ResourceFlags flags  = ResourceFlags.None,
                                             TextureLayout layout = TextureLayout.Unknown,
                                             long alignment       = 0)
 {
     return(new ResourceDescription(ResourceDimension.Texture1D, alignment, width, height, depth, mipLevels, format, 1, 0, layout, flags));
 }
Ejemplo n.º 10
0
 private void PushElement(string name, DXGI.Format type, int typeSize, int count)
 {
     m_Elements.Add(new Element
     {
         Name     = name,
         Type     = type,
         TypeSize = typeSize,
         Offset   = m_Size,
         Count    = count
     });
     m_Size += typeSize * count;
 }
Ejemplo n.º 11
0
 public static ResourceDescription Texture2D(DXGI.Format format,
                                             long width,
                                             int height,
                                             short arraySize           = 1,
                                             short mipLevels           = 0,
                                             int sampleCount           = 1,
                                             int sampleQuality         = 0,
                                             ResourceOptionFlags flags = ResourceOptionFlags.None,
                                             TextureLayout layout      = TextureLayout.Unknown,
                                             long alignment            = 0)
 {
     return(new ResourceDescription(ResourceDimension.Texture1D, alignment, width, height, arraySize, mipLevels, format, sampleCount, sampleQuality, layout, flags));
 }
Ejemplo n.º 12
0
        private int CalculateRankForFormat(DXGI.Format format)
        {
            if (format == PreferredBackBufferFormat)
            {
                return(0);
            }

            if (CalculateFormatSize(format) == CalculateFormatSize(PreferredBackBufferFormat))
            {
                return(1);
            }

            return(int.MaxValue);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Resizes the current presenter, by resizing the back buffer and the depth stencil buffer.
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        public virtual void Resize(int width, int height, DXGI.Format format)
        {
            if (DepthStencilBuffer != null)
            {
                RemoveAndDispose(ref depthStencilBuffer);
            }

            Description.BackBufferWidth  = width;
            Description.BackBufferHeight = height;
            Description.BackBufferFormat = format;

            DefaultViewport = new ViewportF(0, 0, Description.BackBufferWidth, Description.BackBufferHeight);

            CreateDepthStencilBuffer();
        }
Ejemplo n.º 14
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, 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         = (int)FormatHelper.SizeOfInBytes(this.format);
            this.isStrictRowStride = (pixelSize * width) == rowStride;
        }
Ejemplo n.º 15
0
        private int CalculateFormatSize(DXGI.Format format)
        {
            switch (format)
            {
            case DXGI.Format.R8G8B8A8_UNorm:
            case DXGI.Format.R8G8B8A8_UNorm_SRgb:
            case DXGI.Format.B8G8R8A8_UNorm:
            case DXGI.Format.B8G8R8A8_UNorm_SRgb:
            case DXGI.Format.R10G10B10A2_UNorm:
                return(32);

            case DXGI.Format.B5G6R5_UNorm:
            case DXGI.Format.B5G5R5A1_UNorm:
                return(16);
            }

            return(0);
        }
Ejemplo n.º 16
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);
        }
Ejemplo n.º 17
0
        private static DepthFormat ComputeViewFormat(DXGI.Format format)
        {
            switch (format)
            {
            case SharpDX.DXGI.Format.D16_UNorm:
            case DXGI.Format.R16_Float:
            case DXGI.Format.R16_Typeless:
                return(DepthFormat.Depth16);

            case SharpDX.DXGI.Format.D32_Float:
            case DXGI.Format.R32_Float:
            case DXGI.Format.R32_Typeless:
                return(DepthFormat.Depth32);

            case SharpDX.DXGI.Format.D24_UNorm_S8_UInt:
            case SharpDX.DXGI.Format.R24_UNorm_X8_Typeless:
                return(DepthFormat.Depth24Stencil8);

            case SharpDX.DXGI.Format.D32_Float_S8X24_UInt:
            case SharpDX.DXGI.Format.R32_Float_X8X24_Typeless:
                return(DepthFormat.Depth32Stencil8X24);
            }
            throw new InvalidOperationException(string.Format("Unsupported DXGI.FORMAT [{0}] for depth buffer", format));
        }
Ejemplo n.º 18
0
 public Surface(Device2 device, int width, int height, DXGI.Format format, DXGI.AlphaMode alphaMode)
     : base(IntPtr.Zero)
 {
     device.CreateSurface(width, height, format, alphaMode, this);
 }
Ejemplo n.º 19
0
 public VirtualSurface(Device device, int initialWidth, int initialHeight, DXGI.Format format, DXGI.AlphaMode alphaMode) : base(IntPtr.Zero)
 {
     device.CreateVirtualSurface(initialWidth, initialHeight, format, alphaMode, this);
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Gets a specific <see cref="ShaderResourceView" /> from this texture.
 /// </summary>
 /// <param name="viewFormat">The view format.</param>
 /// <param name="viewType">Type of the view.</param>
 /// <param name="arrayOrDepthSlice">The array or depth slice.</param>
 /// <param name="mipIndex">Index of the mip.</param>
 /// <returns>An <see cref="ShaderResourceView" /></returns>
 public TextureView this[DXGI.Format viewFormat, ViewType viewType, int arrayOrDepthSlice, int mipIndex] {
     get { return(this.texture.GetShaderResourceView(viewFormat, viewType, arrayOrDepthSlice, mipIndex)); }
 }
Ejemplo n.º 21
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);
        }
Ejemplo n.º 22
0
 public VirtualSurface(SurfaceFactory factory, int initialWidth, int initialHeight, DXGI.Format format, DXGI.AlphaMode alphaMode)
     : base(IntPtr.Zero)
 {
     factory.CreateVirtualSurface(initialWidth, initialHeight, format, alphaMode, this);
 }