Ejemplo n.º 1
0
        public static byte[] ReadTexture(IMemory Memory, GalImage Image, long Position)
        {
            MemoryManager CpuMemory;

            if (Memory is NvGpuVmm Vmm)
            {
                CpuMemory = Vmm.Memory;
            }
            else
            {
                CpuMemory = (MemoryManager)Memory;
            }

            ISwizzle Swizzle = TextureHelper.GetSwizzle(Image);

            ImageDescriptor Desc = GetImageDescriptor(Image.Format);

            (int Width, int Height) = GetImageSizeInBlocks(Image);

            int BytesPerPixel = Desc.BytesPerPixel;

            //Note: Each row of the texture needs to be aligned to 4 bytes.
            int Pitch = (Width * BytesPerPixel + 3) & ~3;

            byte[] Data = new byte[Height * Pitch];

            for (int Y = 0; Y < Height; Y++)
            {
                int OutOffs = Y * Pitch;

                for (int X = 0; X < Width; X++)
                {
                    long Offset = (uint)Swizzle.GetSwizzleOffset(X, Y);

                    CpuMemory.ReadBytes(Position + Offset, Data, OutOffs, BytesPerPixel);

                    OutOffs += BytesPerPixel;
                }
            }

            return(Data);
        }
Ejemplo n.º 2
0
        public static byte[] ReadTexture(IAMemory Memory, GalImage Image, long Position)
        {
            AMemory CpuMemory;

            if (Memory is NvGpuVmm Vmm)
            {
                CpuMemory = Vmm.Memory;
            }
            else
            {
                CpuMemory = (AMemory)Memory;
            }

            ISwizzle Swizzle = TextureHelper.GetSwizzle(Image);

            ImageDescriptor Desc = GetImageDescriptor(Image.Format);

            (int Width, int Height) = GetImageSizeInBlocks(Image);

            int BytesPerPixel = Desc.BytesPerPixel;

            int OutOffs = 0;

            byte[] Data = new byte[Width * Height * BytesPerPixel];

            for (int Y = 0; Y < Height; Y++)
            {
                for (int X = 0; X < Width; X++)
                {
                    long Offset = (uint)Swizzle.GetSwizzleOffset(X, Y);

                    CpuMemory.ReadBytes(Position + Offset, Data, OutOffs, BytesPerPixel);

                    OutOffs += BytesPerPixel;
                }
            }

            return(Data);
        }
Ejemplo n.º 3
0
 protected override void Destroy()
 {
     CpuMemory.Dispose();
 }