示例#1
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);
        }
示例#2
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();
 }