/// <summary>
 /// Inherited from <see cref="RwNode"/>. Writes the data beyond the header.
 /// </summary>
 /// <param name="writer">The <see cref="BinaryWriter"/> to write the data with.</param>
 protected internal override void WriteBody(BinaryWriter writer)
 {
     writer.Write(Width);
     writer.Write(Height);
     writer.Write(Depth);
     writer.Write((uint)Format);
     writer.Write(Tex0Register.GetBytes());
     writer.Write(Tex1Register.GetBytes());
     writer.Write(MipTBP1Register.GetBytes());
     writer.Write(MipTBP2Register.GetBytes());
     writer.Write(TexelDataLength);
     writer.Write(PaletteDataLength);
     writer.Write(GpuAlignedLength);
     writer.Write(RwSkyMipMapValueNode.SKY_MIPMAP_VALUE);
 }
 /// <summary>
 /// Initializer only to be called in <see cref="RwNodeFactory"/>.
 /// </summary>
 internal RwRasterInfoStructNode(RwNodeFactory.RwNodeHeader header, BinaryReader reader)
     : base(header)
 {
     Width             = reader.ReadInt32();
     Height            = reader.ReadInt32();
     Depth             = reader.ReadInt32();
     Format            = (RwRasterFormats)reader.ReadUInt32();
     Tex0Register      = new Tex0Register(reader);
     Tex1Register      = new Tex1Register(reader);
     MipTBP1Register   = new MipTbpRegister(reader);
     MipTBP2Register   = new MipTbpRegister(reader);
     TexelDataLength   = reader.ReadUInt32();
     PaletteDataLength = reader.ReadUInt32();
     GpuAlignedLength  = reader.ReadUInt32();
     uint skyMipMapValue = reader.ReadUInt32();
 }
Beispiel #3
0
        /// <summary>
        /// Sets the appropriate raster info values based on the width, height and pixel format of the texture.
        /// </summary>
        /// <param name="width">Width of the texture.</param>
        /// <param name="height">Height of the texture.</param>
        /// <param name="pixelFormat">PS2 pixel format of the given texture data.</param>
        private void CreateRasterInfo(int width, int height, PS2PixelFormat pixelFormat)
        {
            _width = width;
            _height = height;
            _depth = PS2PixelFormatHelper.GetPixelFormatDepth(pixelFormat);
            _rasterFormat = GetRasterFormatFromDepth(_depth);

            _tex0 = new Tex0Register(pixelFormat, width, height);
            _tex1 = new Tex1Register(); // default settings

            int texSize = width * height;
            if (texSize < 16384) // because yes
            {
                _tex1.MaxMipLevel = 7;
                _tex1.MipMinFilter = PS2FilterMode.None;

                if (texSize <= 4096)
                {
                    _tex1.MipMaxFilter = PS2FilterMode.None;
                }
                else
                {
                    _tex1.MipMaxFilter = PS2FilterMode.Nearest;
                }
            }

            _mip1 = new MipTBPRegister(); // default settings
            _mip2 = new MipTBPRegister(); // default settings

            _texelDataLength = (uint)PS2PixelFormatHelper.GetTexelDataSize(pixelFormat, width, height);

            // Add image header size to the length if there is one
            if (_rasterFormat.HasFlagUnchecked(RWRasterFormats.HasHeaders))
                _texelDataLength += PS2StandardImageHeader.Size;

            _paletteDataLength = 0; // set to 0 if there's no palette present

            // division by 2 might only apply for 8 bit..
            int transferWidth = width / 2;
            int transferHeight = height / 2;
            _gpuAlignedLength = (uint)(transferWidth * transferHeight);

            // Calculate the palette data length for indexed textures
            if (_depth == 4 || _depth == 8)
            {
                int numColors = 256;

                if (_depth == 4)
                {
                    numColors = 16;
                }

                _paletteDataLength = (uint)(numColors * 4);

                // division by 4 might only apply for 8 bit..
                _gpuAlignedLength += _paletteDataLength / 4;

                // Add image header size to the length if there is one
                if (_rasterFormat.HasFlagUnchecked(RWRasterFormats.HasHeaders))
                    _paletteDataLength += PS2StandardImageHeader.Size;
            }

            // align to pages of 2048
            _gpuAlignedLength = (uint)AlignmentHelper.Align(_gpuAlignedLength, 2048);
        }
        /// <summary>
        /// Sets the appropriate rasterStructNode info values based on the width, height and pixel format of the texture.
        /// </summary>
        /// <param name="width">Width of the texture.</param>
        /// <param name="height">Height of the texture.</param>
        /// <param name="pixelFormat">PS2 pixel format of the given texture data.</param>
        private void CreateRasterInfo(int width, int height, PS2PixelFormat pixelFormat)
        {
            Width  = width;
            Height = height;
            Depth  = PS2PixelFormatHelper.GetPixelFormatDepth(pixelFormat);
            Format = GetRasterFormatFromDepth(Depth);

            Tex0Register = new Tex0Register(pixelFormat, width, height);
            Tex1Register = new Tex1Register(); // default settings

            int texSize = width * height;

            if (texSize < 16384) // because yes
            {
                Tex1Register.MaxMipLevel  = 7;
                Tex1Register.MipMinFilter = PS2FilterMode.None;

                if (texSize <= 4096)
                {
                    Tex1Register.MipMaxFilter = PS2FilterMode.None;
                }
                else
                {
                    Tex1Register.MipMaxFilter = PS2FilterMode.Nearest;
                }
            }

            MipTBP1Register = new MipTbpRegister(); // default settings
            MipTBP2Register = new MipTbpRegister(); // default settings

            TexelDataLength = (uint)PS2PixelFormatHelper.GetTexelDataSize(pixelFormat, width, height);

            // Add image header size to the length if there is one
            if (Format.HasFlagUnchecked(RwRasterFormats.HasHeaders))
            {
                TexelDataLength += PS2StandardImageHeader.Size;
            }

            PaletteDataLength = 0; // set to 0 if there's no palette present

            // division by 2 might only apply for 8 bit..
            int transferWidth  = width / 2;
            int transferHeight = height / 2;

            GpuAlignedLength = (uint)(transferWidth * transferHeight);

            // Calculate the palette data length for indexed textures
            if (Depth == 4 || Depth == 8)
            {
                int numColors = 256;

                if (Depth == 4)
                {
                    numColors = 16;
                }

                PaletteDataLength = (uint)(numColors * 4);

                // division by 4 might only apply for 8 bit..
                GpuAlignedLength += PaletteDataLength / 4;

                // Add image header size to the length if there is one
                if (Format.HasFlagUnchecked(RwRasterFormats.HasHeaders))
                {
                    PaletteDataLength += PS2StandardImageHeader.Size;
                }
            }

            // align to pages of 2048
            GpuAlignedLength = (uint)AlignmentHelper.Align(GpuAlignedLength, 2048);
        }
Beispiel #5
0
 /// <summary>
 /// Initializer only to be called in <see cref="RWNodeFactory"/>.
 /// </summary>
 internal RWRasterInfo(RWNodeFactory.RWNodeInfo header, BinaryReader reader)
     : base(header)
 {
     _width = reader.ReadInt32();
     _height = reader.ReadInt32();
     _depth = reader.ReadInt32();
     _rasterFormat = (RWRasterFormats)reader.ReadUInt32();
     _tex0 = new Tex0Register(reader);
     _tex1 = new Tex1Register(reader);
     _mip1 = new MipTBPRegister(reader);
     _mip2 = new MipTBPRegister(reader);
     _texelDataLength = reader.ReadUInt32();
     _paletteDataLength = reader.ReadUInt32();
     _gpuAlignedLength = reader.ReadUInt32();
     uint skyMipMapValue = reader.ReadUInt32();
 }