private void WriteToTexture(Rectangle rect, IntPtr buffer, int stride, EX9.Texture texture)
        {
            // TODO: Do not lock entire surface.
            var dataRect = texture.LockRectangle(0, rect, LockFlags.None);

            try
            {
                var dataStream = dataRect.Data;
                if (rect.Width == FWidth && rect.Height == FHeight && dataRect.Pitch == stride)
                {
                    dataStream.WriteRange(buffer, FHeight * dataRect.Pitch);
                }
                else
                {
                    var offset = stride * rect.Y + 4 * rect.X;
                    var source = buffer + offset;
                    for (int y = 0; y < rect.Height; y++)
                    {
                        dataStream.Position = y * dataRect.Pitch;
                        dataStream.WriteRange(source + y * stride, rect.Width * 4);
                    }
                }
            }
            finally
            {
                texture.UnlockRectangle(0);
            }
        }
Exemple #2
0
        private void WriteToTexture(Rectangle rect, IntPtr buffer, int stride, EX9.Texture texture)
        {
            // Rect needs to be inside of Width/Height
            rect = Rectangle.Intersect(new Rectangle(0, 0, FSize.Width, FSize.Height), rect);
            if (rect == Rectangle.Empty)
            {
                return;
            }
            var dataRect = texture.LockRectangle(0, rect, LockFlags.None);

            try
            {
                var dataStream = dataRect.Data;
                if (rect.Width == FSize.Width && rect.Height == FSize.Height && dataRect.Pitch == stride)
                {
                    dataStream.WriteRange(buffer, FSize.Height * dataRect.Pitch);
                }
                else
                {
                    var offset = stride * rect.Y + 4 * rect.X;
                    var source = buffer + offset;
                    for (int y = 0; y < rect.Height; y++)
                    {
                        dataStream.Position = y * dataRect.Pitch;
                        dataStream.WriteRange(source + y * stride, rect.Width * 4);
                    }
                }
            }
            finally
            {
                texture.UnlockRectangle(0);
            }
        }
        public void LoadTextureData(Texture2d tex, BitmapBuffer bmp)
        {
            sdi.BitmapData bmp_data = bmp.LockBits();
            d3d9.Texture   dtex     = tex.Opaque as d3d9.Texture;
            var            dr       = dtex.LockRectangle(0, LockFlags.None);

            //TODO - do we need to handle odd sizes, weird pitches here?
            dr.Data.WriteRange(bmp_data.Scan0, bmp.Width * bmp.Height);
            dtex.UnlockRectangle(0);
            bmp.UnlockBits(bmp_data);
        }
Exemple #4
0
        public unsafe BitmapBuffer ResolveTexture2d(Texture2d tex)
        {
            //TODO - lazy create and cache resolving target in RT
            var target = new d3d9.Texture(dev, tex.IntWidth, tex.IntHeight, 1, d3d9.Usage.None, d3d9.Format.A8R8G8B8, d3d9.Pool.SystemMemory);
            var tw     = tex.Opaque as TextureWrapper;

            dev.GetRenderTargetData(tw.Texture.GetSurfaceLevel(0), target.GetSurfaceLevel(0));
            var dr = target.LockRectangle(0, LockFlags.ReadOnly);

            if (dr.Pitch != tex.IntWidth * 4)
            {
                throw new InvalidOperationException();
            }
            int[] pixels = new int[tex.IntWidth * tex.IntHeight];
            dr.Data.ReadRange(pixels, 0, tex.IntWidth * tex.IntHeight);
            var bb = new BitmapBuffer(tex.IntWidth, tex.IntHeight, pixels);

            target.UnlockRectangle(0);
            target.Dispose();             //buffer churn warning
            return(bb);
        }
Exemple #5
0
		public unsafe BitmapBuffer ResolveTexture2d(Texture2d tex)
		{
			//TODO - lazy create and cache resolving target in RT
			var target = new d3d9.Texture(dev, tex.IntWidth, tex.IntHeight, 1, d3d9.Usage.None, d3d9.Format.A8R8G8B8, d3d9.Pool.SystemMemory);
			var tw = tex.Opaque as TextureWrapper;
			dev.GetRenderTargetData(tw.Texture.GetSurfaceLevel(0), target.GetSurfaceLevel(0));
			var dr = target.LockRectangle(0, LockFlags.ReadOnly);
			if (dr.Pitch != tex.IntWidth * 4) throw new InvalidOperationException();
			int[] pixels = new int[tex.IntWidth * tex.IntHeight];
			dr.Data.ReadRange(pixels, 0, tex.IntWidth * tex.IntHeight);
			var bb = new BitmapBuffer(tex.IntWidth, tex.IntHeight, pixels);
			target.UnlockRectangle(0);
			target.Dispose(); //buffer churn warning
			return bb;
		}