/// <summary> /// Creates a cached texture for the specifed texture, using the specified path /// as a lookup key. /// </summary> public int CreateCachedTexture(BLP texture, string texturePath, TextureWrapMode textureWrapMode = TextureWrapMode.Repeat) { if (texture == null) { throw new ArgumentNullException(nameof(texture)); } int textureID = GL.GenTexture(); if (texture.GetCompressionType() == TextureCompressionType.DXTC) { try { LoadDXTTexture(textureID, texture); } catch (GraphicsErrorException gex) { Log.Warn($"GraphicsErrorException in CreateCachedTexture (failed to create DXT texture): {gex.Message}\n" + "The texture will be loaded as a bitmap instead."); } finally { // Load a fallback bitmap instead using (Bitmap mipZero = texture.GetMipMap(0)) { LoadBitmapTexture(textureID, mipZero); } } } else { using (Bitmap mipZero = texture.GetMipMap(0)) { LoadBitmapTexture(textureID, mipZero); } } // Use linear mipmapped filtering GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)textureWrapMode); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)textureWrapMode); int maximalMipLevel = texture.GetMipMapCount() == 0 ? 0 : texture.GetMipMapCount() - 1; GL.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureMaxLevel, ref maximalMipLevel); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureBaseLevel, 0); this.GLTextureCache.Add(texturePath.ConvertPathSeparatorsToCurrentNativeSeparator().ToUpperInvariant(), textureID); return(textureID); }
/// <summary> /// Exports the mipmaps in the image. /// </summary> public void RunExport() { var imageFilename = IOPath.GetFileNameWithoutExtension ( _exportTarget.FilePath.ConvertPathSeparatorsToCurrentNativeSeparator() ); string exportPath; if (_config.KeepFileDirectoryStructure) { exportPath = IOPath.Combine ( _exportDirectoryFileChooserButton.Filename, _exportTarget.FilePath.ConvertPathSeparatorsToCurrentNativeSeparator().Replace(".blp", string.Empty) ); } else { exportPath = IOPath.Combine ( _exportDirectoryFileChooserButton.Filename, imageFilename ); } var i = 0; _mipLevelListStore.Foreach ( (model, path, iter) => { var shouldExport = (bool)_mipLevelListStore.GetValue(iter, 0); if (shouldExport) { var formatExtension = GetFileExtensionFromImageFormat ( (ImageFormat)_exportFormatComboBox.Active ); Directory.CreateDirectory(Directory.GetParent(exportPath).FullName); var fullExportPath = $"{exportPath}_{i}.{formatExtension}"; using (var fs = File.OpenWrite(fullExportPath)) { _image.GetMipMap((uint)i).Save ( fs, GetImageEncoderFromFormat((ImageFormat)_exportFormatComboBox.Active) ); } } ++i; return(false); } ); }
/// <summary> /// Exports the mipmaps in the image. /// </summary> public void RunExport() { string ImageFilename = System.IO.Path.GetFileNameWithoutExtension(ExtensionMethods.ConvertPathSeparatorsToCurrentNativeSeparator(ExportTarget.ItemPath)); string ExportPath = ""; if (Config.GetShouldKeepFileDirectoryStructure()) { ExportPath = $"{ExportDirectoryFileChooserButton.Filename}{System.IO.Path.DirectorySeparatorChar}{ExtensionMethods.ConvertPathSeparatorsToCurrentNativeSeparator(ExportTarget.ItemPath).Replace(".blp", "")}"; } else { ExportPath = $"{ExportDirectoryFileChooserButton.Filename}{System.IO.Path.DirectorySeparatorChar}{ImageFilename}"; } int i = 0; MipLevelListStore.Foreach(delegate(ITreeModel model, TreePath path, TreeIter iter) { bool bShouldExport = (bool)MipLevelListStore.GetValue(iter, 0); if (bShouldExport) { string formatExtension = GetFileExtensionFromImageFormat((ImageFormat)ExportFormatComboBox.Active); System.IO.Directory.CreateDirectory(System.IO.Directory.GetParent(ExportPath).FullName); string fullExportPath = $"{ExportPath}_{i}.{formatExtension}"; Image.GetMipMap((uint)i).Save(fullExportPath, GetSystemImageFormatFromImageFormat((ImageFormat)ExportFormatComboBox.Active)); } ++i; return(false); }); }