/// <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); }