Ejemplo n.º 1
0
        private CTextureSurface(ICDevice device, ResourceDimension dimension, Texture2DDescription description, SubresourceData[] initialData, Action<CTextureSurface> onRelease)
            : base(device, dimension, description, t => onRelease((CTextureSurface)t))
        {
            CreateNative();

            if (initialData != null)
                throw new NotSupportedException("Initial newData is not supported for render target and depth-stencil resources by D3D9 implementation of Beholder");
        }
Ejemplo n.º 2
0
        protected CTexture(ICDevice device, ResourceDimension dimension, Texture2DDescription description, Action<CTexture> onDispose)
        {
            this.device = device;
            this.dimension = dimension;
            this.desc = description;
            this.onDispose = onDispose;

            if (desc.BindFlags.HasFlag(BindFlags.RenderTarget))
                rtvs = new List<CRenderTargetView>();
            if (desc.BindFlags.HasFlag(BindFlags.DepthStencil))
                dsvs = new List<CDepthStencilView>();
            if (desc.BindFlags.HasFlag(BindFlags.ShaderResource))
                srvs = new List<CShaderResourceView>();
        }
Ejemplo n.º 3
0
        public SwapChainSurfaces(ICDevice device, int width, int height, ref SwapChainDescription implicitSwapChainDescription)
        {
            this.device = device;

            var glContext = device.GetCurrentContext();

            texture2DDescription = new Texture2DDescription
            {
                ArraySize = 1,
                ExtraFlags = ExtraFlags.None,
                Usage = Usage.Default,
                MipLevels = 1,
                MiscFlags = MiscFlags.None
            };

            OnReset(glContext, width, height, ref implicitSwapChainDescription);
        }
Ejemplo n.º 4
0
 void ITexture2D.GetDescription(out Texture2DDescription texture2DDesc)
 {
     texture2DDesc = desc;
 }
Ejemplo n.º 5
0
        public unsafe ITexture2D Load(string fileName)
        {
            ITexture2D result;
            var bitmap = new Bitmap(fileName);

            var data = new byte[bitmap.Width * bitmap.Height * 4 * 2];
            var mipPointers = new IntPtr[GetMipCount(bitmap.Width, bitmap.Height)];

            fixed (byte* pData = data)
            {
                mipPointers[0] = (IntPtr)pData;

                var bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
                {
                    var dst = pData;
                    var src = (byte*)bitmapData.Scan0;

                    if (bgra)
                    {
                        for (int y = 0; y < bitmap.Height; y++)
                        {
                            for (int x = 0; x < bitmap.Width; x++)
                            {
                                dst[0] = src[0];
                                dst[1] = src[1];
                                dst[2] = src[2];
                                dst[3] = 255;

                                src += 3;
                                dst += 4;
                            }
                        }
                    }
                    else
                    {
                        for (int y = 0; y < bitmap.Height; y++)
                        {
                            for (int x = 0; x < bitmap.Width; x++)
                            {
                                dst[0] = src[2];
                                dst[1] = src[1];
                                dst[2] = src[0];
                                dst[3] = 255;

                                src += 3;
                                dst += 4;
                            }
                        }
                    }

                    int mipWidth = bitmap.Width;
                    int mipHeight = bitmap.Height;

                    for (int level = 1; level < mipPointers.Length; level++)
                    {
                        mipPointers[level] = (IntPtr)dst;
                        src = (byte*)mipPointers[level - 1];

                        int srcRowSpan = mipWidth * 4;

                        mipWidth = Math.Max(mipWidth / 2, 1);
                        mipHeight = Math.Max(mipHeight / 2, 1);

                        for (int y = 0; y < mipHeight; y++)
                        {
                            for (int x = 0; x < mipWidth; x++)
                            {
                                for (int i = 0; i < 3; i++)
                                {
                                    float tl = SrgbToLinear(src[i] / 255f);
                                    float tr = SrgbToLinear(src[i + 4] / 255f);
                                    float bl = SrgbToLinear(src[i + srcRowSpan] / 255f);
                                    float br = SrgbToLinear(src[i + 4 + srcRowSpan] / 255f);

                                    dst[i] = (byte)(LinearToSrgb((tl + tr + bl + br) / 4f) * 255.9999f);
                                }

                                dst[3] = 255;

                                src += 8;
                                dst += 4;
                            }

                            src += srcRowSpan;
                        }
                    }
                }
                bitmap.UnlockBits(bitmapData);

                var desc = new Texture2DDescription
                {
                    Width = bitmap.Width,
                    Height = bitmap.Height,
                    ArraySize = 1,
                    MipLevels = mipPointers.Length,
                    FormatID = formatId,
                    Sampling = Sampling.NoMultisampling,
                    BindFlags = BindFlags.ShaderResource,
                    Usage = Usage.Immutable
                };

                result = device.Create.Texture2D(desc, mipPointers.Select(x => new SubresourceData(x, 1)).ToArray());
            }
            return result;
        }
Ejemplo n.º 6
0
 public CTextureSurface(ICDevice device, Texture2DDescription description, SubresourceData[] initialData, Action<CTextureSurface> onRelease)
     : this(device, ResourceDimension.Texture2D, description, initialData, onRelease)
 {
 }