public static void Release() { if (Irradiance != null) { Irradiance.Release(); Irradiance = null; } if (Prefiltered != null) { Prefiltered.Release(); Prefiltered = null; } }
public static async Task Load() { int index = selectedIndex; if (index < 0) { index = 0; } if (index > available.Count - 1) { index = available.Count - 1; } if (index >= 0 && index < available.Count) { string f = available[index]; string iradpath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Hdri", f, "irradiance.dds"); string prefpath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Hdri", f, "prefiltered.dds"); try { DDSImage rad = await DDSReader.DDSReader.ReadImageAsync(iradpath); DDSImage pre = await DDSReader.DDSReader.ReadImageAsync(prefpath); App.Current.Dispatcher.Invoke(() => { Collection <DDSMipMap> mips = (Collection <DDSMipMap>)rad.Frames; if (mips.Count > 0) { var mip = mips[0]; byte[] data = mip.MipmapData[0]; if (Irradiance != null) { Irradiance.Release(); } Irradiance = new GLTextuer2D(PixelInternalFormat.Rgb16f); Irradiance.Bind(); Irradiance.SetData(data, PixelFormat.Rgb, (int)mip.Width, (int)mip.Height); Irradiance.SetFilter((int)TextureMinFilter.Linear, (int)TextureMagFilter.Linear); Irradiance.SetWrap((int)TextureWrapMode.ClampToEdge); GLTextuer2D.Unbind(); } mips = (Collection <DDSMipMap>)pre.Frames; if (mips.Count > 0) { if (Prefiltered != null) { Prefiltered.Release(); } Prefiltered = new GLTextuer2D(PixelInternalFormat.Rgb16f); Prefiltered.Bind(); Prefiltered.SetMaxMipLevel(4); for (int i = 0; i < mips.Count; ++i) { var mip = mips[i]; byte[] data = mip.MipmapData[0]; Prefiltered.SetData(data, PixelFormat.Rgb, (int)mip.Width, (int)mip.Height, i); } Prefiltered.SetFilter((int)TextureMinFilter.LinearMipmapLinear, (int)TextureMagFilter.Linear); Prefiltered.SetWrap((int)TextureWrapMode.ClampToEdge); GLTextuer2D.Unbind(); } if (OnHdriLoaded != null) { OnHdriLoaded.Invoke(Irradiance, Prefiltered); } }); } catch (Exception e) { Log.Error(e); } } }