private static void AddTextureNative(TextureNativeStruct_0001 tnStruct) { ShaderResourceView texture; try { texture = Program.MainForm.renderer.device.LoadTextureFromRenderWareNative(tnStruct); } catch { return; } DisposeTexture(tnStruct.textureName); Textures[tnStruct.textureName] = texture; }
private static void AddTextureNative(TextureNativeStruct_0001 tnStruct, SharpRenderer renderer) { if (Textures.ContainsKey(tnStruct.textureName)) { if (Textures[tnStruct.textureName] != null) { if (!Textures[tnStruct.textureName].IsDisposed) { Textures[tnStruct.textureName].Dispose(); } } Textures[tnStruct.textureName] = renderer.Device.LoadTextureFromRenderWareNative(tnStruct); } else { Textures.Add(tnStruct.textureName, renderer.Device.LoadTextureFromRenderWareNative(tnStruct)); } }
public static ShaderResourceView LoadTextureFromRenderWareNative(this SharpDevice device, TextureNativeStruct_0001 tnStruct) { Format format = Format.Unknown; if (tnStruct.compression == 0) { //if ((tnStruct.rasterFormatFlags & TextureRasterFormat.RASTER_C1555) != 0) // format = Format.B5G5R5A1_UNorm; //if ((tnStruct.rasterFormatFlags & TextureRasterFormat.RASTER_C4444) != 0) // format = Format.B4G4R4A4_UNorm; //else if ((tnStruct.rasterFormatFlags & TextureRasterFormat.RASTER_C555) != 0) // format = Format.B5G5R5A1_UNorm; if ((tnStruct.rasterFormatFlags & (TextureRasterFormat)0x0F00) == TextureRasterFormat.RASTER_C565) { format = Format.B5G6R5_UNorm; } if ((tnStruct.rasterFormatFlags & (TextureRasterFormat)0x0F00) == TextureRasterFormat.RASTER_C8888) { format = Format.B8G8R8A8_UNorm; } if ((tnStruct.rasterFormatFlags & (TextureRasterFormat)0x0F00) == TextureRasterFormat.RASTER_C888) { format = Format.B8G8R8A8_UNorm; } //else if ((tnStruct.rasterFormatFlags & TextureRasterFormat.RASTER_D16) != 0) // format = Format.D16_UNorm; //else if ((tnStruct.rasterFormatFlags & TextureRasterFormat.RASTER_D24) != 0) // format = Format.D24_UNorm_S8_UInt; //else if ((tnStruct.rasterFormatFlags & TextureRasterFormat.RASTER_D32) != 0) // format = Format.D32_Float; //else if ((tnStruct.rasterFormatFlags & TextureRasterFormat.RASTER_PAL4) != 0) // format = Format.P8; //else if ((tnStruct.rasterFormatFlags & TextureRasterFormat.RASTER_PAL8) != 0) // format = Format.P8; } else if (tnStruct.compression == 1) { format = Format.BC1_UNorm; } else { return(null); } if (format == Format.Unknown) { throw new Exception(tnStruct.textureName); } MipMapEntry[] mipMaps; if ((tnStruct.rasterFormatFlags & TextureRasterFormat.RASTER_PAL4) != 0 | (tnStruct.rasterFormatFlags & TextureRasterFormat.RASTER_PAL8) != 0) { mipMaps = ConvertFromPalette(tnStruct.mipMaps, tnStruct.mipMapCount, tnStruct.rasterFormatFlags, tnStruct.palette); if (tnStruct.platformType == 5) { format = Format.R8G8B8A8_UNorm; } } else { mipMaps = tnStruct.mipMaps; } DataRectangle[] dataRectangles = FillInitData(mipMaps, tnStruct.width, tnStruct.height, tnStruct.bitDepth, tnStruct.mipMapCount, format); Texture2D buffer = null; while (buffer == null) { try { buffer = new Texture2D(device.Device, new Texture2DDescription() { MipLevels = tnStruct.mipMapCount, Format = format, Width = tnStruct.width, Height = tnStruct.height, ArraySize = 1, BindFlags = BindFlags.ShaderResource, Usage = ResourceUsage.Default, SampleDescription = new SampleDescription(1, 0), OptionFlags = ResourceOptionFlags.None, }, dataRectangles); } catch { } } ShaderResourceView resourceView = new ShaderResourceView(device.Device, buffer); buffer.Dispose(); return(resourceView); }