using System.Numerics; using System.Runtime.InteropServices; using Vortice.D3DCompiler; using Vortice.Direct3D; using Vortice.Direct3D11; using Vortice.DXGI; using XFEEDToolBox.Core.Rendering; namespace XFEEDToolBox.Rendering; internal sealed partial class GalaxyGraphics { private ID3D11PixelShader zonesPs=null!; private ID3D11Buffer zonesConstants=null!; private ID3D11Texture2D? zoneIdTexture,zoneBoundaryTexture; private ID3D11ShaderResourceView? zoneIds,zoneBoundaries; private Task? zoneRasterTask; internal bool ShowGalacticZonesPlane {get;set;} internal bool GalacticZonesPlaneReady=>zoneIds is not null&&zoneBoundaries is not null; internal bool GalacticZonesPlaneDrawn {get;private set;} private void InitializeGalacticZones(string shader) { zonesPs=device.CreatePixelShader(Compiler.CompileFromFile(shader,"PSGalacticZones","ps_5_0").Span); zonesConstants=device.CreateBuffer(48,BindFlags.ConstantBuffer); } private bool PrepareGalacticZones() { if(GalacticZonesPlaneReady)return true; if(zoneRasterTask is null) { zoneRasterTask=Task.Run(()=>GalaxyZoneRaster.Create(GalaxyOriginalZones.Reference)); _=zoneRasterTask.ContinueWith(task=>App.MainWindow.DispatcherQueue.TryEnqueue(()=> { if(disposed)return; if(task.IsFaulted)App.Runtime.Log("银河区域",task.Exception!.GetBaseException().Message); ResourcesChanged?.Invoke(); }),TaskScheduler.Default); return false; } if(!zoneRasterTask.IsCompletedSuccessfully)return false; var raster=zoneRasterTask.Result;var pins=new GCHandle[raster.BoundaryMips.Length+1]; try { pins[0]=GCHandle.Alloc(raster.Ids,GCHandleType.Pinned); zoneIdTexture=device.CreateTexture2D(new Texture2DDescription{Width=(uint)raster.Map.Width,Height=(uint)raster.Map.Height,MipLevels=1,ArraySize=1, Format=Format.R8_UInt,SampleDescription=new(1,0),Usage=ResourceUsage.Immutable,BindFlags=BindFlags.ShaderResource}, [new SubresourceData(pins[0].AddrOfPinnedObject(),(uint)raster.Map.Width,0)]); var mipData=new SubresourceData[raster.BoundaryMips.Length]; for(var index=0;index