void Start() { m_LookupTexture = new Texture2D(TableSize, TableSize, TextureFormat.RGBA32, false); m_LookupTexture.filterMode = FilterMode.Point; m_LookupTexture.wrapMode = TextureWrapMode.Clamp; m_RootPageNode = new TableNode(MaxMipLevel, 0, 0, TableSize, TableSize); m_Loader = (FileLoader)GetComponent(typeof(FileLoader)); m_tileTexture = (TiledTexture)GetComponent(typeof(TiledTexture)); m_tileTexture.OnTileUpdateComplete += InvalidatePage; m_Loader.OnLoadCompleteEvent += OnLoadTextureFinished; ((FeedBackCamera)GetComponent(typeof(FeedBackCamera))).readTextureAction += ProcessFeedback; Shader.SetGlobalVector( "_VTFeedbackParam", new Vector4(TableSize, TableSize * m_tileTexture.TileSize, // virtualTexture's 1d dimension MaxMipLevel, 0.0f)); Shader.SetGlobalTexture( "_VTLookupTex", m_LookupTexture); Shader.SetGlobalVector( "_VTPageParam", new Vector4( TableSize, 1.0f / TableSize, MaxMipLevel, 0)); }
public static IAsyncOperation <StandardLayout> LoadFromFileAsync(CanvasCase canvasCase, StorageFile file) { var task1 = Task <StandardLayout> .Run(async() => { var stream = await file.OpenReadAsync(); DataReader reader = new DataReader(stream); await reader.LoadAsync((uint)stream.Size); reader.ReadInt32(); //header Guid readedGuid = reader.ReadGuid(); int count = reader.ReadInt32(); byte[] oData = new byte[count * 8]; byte[] bData = new byte[count * 1024]; reader.ReadBytes(oData); reader.ReadBytes(bData); TiledTexture tTex = new TiledTexture(canvasCase.DeviceResources, bData, oData); StandardLayout loadedLayout = new StandardLayout(tTex); loadedLayout.PaintingTexture = canvasCase.PaintingTexture; loadedLayout.PaintingTextureTemp = canvasCase.PaintingTextureTemp; loadedLayout.saved = true; loadedLayout.guid = readedGuid; return(loadedLayout); }); return(task1.AsAsyncOperation()); }
public StandardLayout(RenderTexture Data) { tiledTexture = new TiledTexture(Data); for (int i = 0; i < BlendMode.c_parameterCount; i++) { Parameters[i] = new DCParameter(); } }
public StandardLayout(TiledTexture loadedData) { tiledTexture = loadedData; for (int i = 0; i < BlendMode.c_parameterCount; i++) { Parameters[i] = new DCParameter(); } }
public void Deactivate() { if (!activated) { return; } activated = false; tiledTexture?.Dispose(); tiledTexture = new TiledTexture(PaintingTexture); }
static byte[] header = { 0x44, 0x43, 0x4c, 0x46 };//DCLF public static async Task SaveToFileAsync(this StandardLayout layout, StorageFile file) { var stream = await file.OpenAsync(FileAccessMode.ReadWrite); int count; TiledTexture tex0 = null; if (layout is StandardLayout standardLayout) { if (standardLayout.activated) { tex0 = new TiledTexture(standardLayout.PaintingTexture); count = tex0.tilesCount; } else if (standardLayout.tiledTexture != null) { tex0 = new TiledTexture(standardLayout.tiledTexture); count = tex0.tilesCount; } else { count = 0; } DataWriter dataWriter = new DataWriter(stream); dataWriter.WriteBytes(header); dataWriter.WriteGuid(layout.guid); dataWriter.WriteInt32(count); if (count != 0) { byte[] oData = new byte[count * 8]; byte[] bData = new byte[count * 1024]; tex0.BlocksData.GetData(bData); tex0.BlocksOffsetsData.GetData(oData); if (!standardLayout.activated) { tex0.Dispose(); //此时为临时创建的TiledTexture } dataWriter.WriteBytes(oData); dataWriter.WriteBytes(bData); } await dataWriter.StoreAsync(); layout.saved = true; dataWriter.Dispose(); stream.Dispose(); } }
internal void RegisterTiledTexture(String key, TiledTexture texture, TextureCachePolicy cachePolicy) { if(String.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(); if(texture == null) throw new ArgumentNullException(); if(TiledTextures.ContainsKey(key)) throw new ArgumentException("Attempt to register duplicate key."); TiledTextures.Add(key, texture); CachePolicies.Add(key, cachePolicy); Users.Add(key, new List<DrawableBase>()); }
public void Blend(TiledTexture source, RenderTexture target, RenderTexture[] refs, ConstantBuffer parametersData) { if (source.tilesCount == 0) { return; } csBlend[1].SetBuffer(source.BlocksData, 0); csBlend[1].SetBuffer(source.BlocksOffsetsData, 1); for (int i = 0; i < c_refCount; i++) { if (refs[i] != null) { csBlend[1].SetTexture(refs[0], 2 + i); } } csBlend[1].SetUAVTexture(target, 0); csBlend[1].SetConstantBuffer(parametersData, 0); csBlend[1].Dispatch(1, 1, (source.tilesCount + 15) / 16); }
internal void AddUser(String key, TiledTexture user) { if(String.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(); if(user == null) throw new ArgumentNullException(); if(!Users.ContainsKey(key)) throw new ArgumentException("Attempt to add a user to an unknown key."); if(Users[key] == null) Users[key] = new List<TiledTexture>(); if(Users[key].Contains(user)) throw new ArgumentException("Attempt to register a duplicate user."); Users[key].Add(user); }
public void Blend(TiledTexture source, RenderTexture target, List <Vector2Int> part, RenderTexture[] refs, ConstantBuffer parametersData) { if (part == null || part.Count == 0 || source.tilesCount == 0) { return; } hParts.Clear(); for (int i = 0; i < part.Count; i++) { //if (source.TilesStatus.TryGetValue(part[i], out int tIndex)) //{ // hParts.Add(tIndex); //} int tIndex = source.TilesStatus[part[i]]; if (tIndex != -1) { hParts.Add(tIndex); } } if (hParts.Count == 0) { return; } int z = (hParts.Count + 15) / 16; ComputeBuffer buf_Index = new ComputeBuffer(source.deviceResources, hParts.Count, 4, hParts.ToArray()); csBlend[3].SetBuffer(source.BlocksData, 0); csBlend[3].SetBuffer(buf_Index, 1); csBlend[3].SetBuffer(source.BlocksOffsetsData, 2); for (int i = 0; i < c_refCount; i++) { if (refs[i] != null) { csBlend[3].SetTexture(refs[0], 3 + i); } } csBlend[3].SetUAVTexture(target, 0); csBlend[3].SetConstantBuffer(parametersData, 0); csBlend[3].Dispatch(1, 1, z); buf_Index.Dispose(); }
public void Blend3Indicate(TiledTexture source, RenderTexture target, List <int> indicate, RenderTexture[] refs, ConstantBuffer parametersData) { if (indicate == null || indicate.Count == 0 || source.tilesCount == 0) { return; } int z = (indicate.Count + 15) / 16; ComputeBuffer buf_Index = new ComputeBuffer(source.deviceResources, indicate.Count, 4, indicate.ToArray()); csBlend[3].SetBuffer(source.BlocksData, 0); csBlend[3].SetBuffer(buf_Index, 1); csBlend[3].SetBuffer(source.BlocksOffsetsData, 2); for (int i = 0; i < c_refCount; i++) { if (refs[i] != null) { csBlend[3].SetTexture(refs[0], 3 + i); } } csBlend[3].SetUAVTexture(target, 0); csBlend[3].SetConstantBuffer(parametersData, 0); csBlend[3].Dispatch(1, 1, z); buf_Index.Dispose(); }
public StandardLayout(StandardLayout standardLayout) { if (standardLayout.activated) { tiledTexture = new TiledTexture(standardLayout.PaintingTexture); } else if (standardLayout.tiledTexture != null) { tiledTexture = new TiledTexture(standardLayout.tiledTexture); } PaintingTexture = standardLayout.PaintingTexture; PaintingTextureTemp = standardLayout.PaintingTextureTemp; for (int i = 0; i < BlendMode.c_parameterCount; i++) { Parameters[i] = new DCParameter(); Parameters[i].Value = standardLayout.Parameters[i].Value; } BlendMode = standardLayout.BlendMode; Alpha = standardLayout.Alpha; RenderBufferNum = standardLayout.RenderBufferNum; RefBufferNum = standardLayout.RefBufferNum; guid = Guid.NewGuid(); }
public void ReplaceTiles(TiledTexture tt, out TiledTexture before) { if (activated) { before = new TiledTexture(PaintingTexture, tt.TilesList); tt.UnzipToTexture(PaintingTexture); } else if (tiledTexture != null && tiledTexture.tilesCount > 0) { PaintingTextureTemp.Clear(); tiledTexture.UnzipToTexture(PaintingTextureTemp); before = new TiledTexture(PaintingTextureTemp, tt.TilesList); tt.UnzipToTexture(PaintingTextureTemp); tiledTexture?.Dispose(); tiledTexture = new TiledTexture(PaintingTextureTemp); } else { PaintingTextureTemp.Clear(); before = new TiledTexture(PaintingTextureTemp, tt.TilesList); tiledTexture = new TiledTexture(tt); } }
public CMD_TileReplace(StandardLayout host, TiledTexture undoData, CanvasCase canvasCase) { Host = host; Data = undoData; this.canvasCase = canvasCase; }
public GridIndex(TiledTexture tiledTexture, Int32 columns = DefaultColumns, Int32 rows = DefaultRows, String name = DefaultName) : base(name, tiledTexture) { BuildKeyList(columns, rows); }
private void CleanupTiledTextures() { TiledTexture[] cleanup = new TiledTexture[TiledTextures.Values.Count]; TiledTextures.Values.CopyTo(cleanup, 0); foreach(TiledTexture t in cleanup) t.Dispose(); TiledTextures.Clear(); TiledTextures = null; }
private void CleanupTexture() { TextureColumnIndex.Dispose(); TextureColumnIndex = null; TiledFontTexture.Dispose(); TiledFontTexture = null; }
private void BuildTexture() { Texture2dPlus FontTexture = DrawEngine2d.Textures.CreateTexture(TextureKey, TextureWidth, TextureHeight, PixelFormat.Luminance, TextureCachePolicy.KeepAlways); FontTexture.SetPixels(0, TexturePixels, PixelFormat.Luminance); FontTexture.SetFilter(TextureFilterMode.Nearest, TextureFilterMode.Nearest, TextureFilterMode.Nearest); TiledFontTexture = DrawEngine2d.TiledTextures.CreateTiledTexture(TextureKey, FontTexture, TextureCachePolicy.KeepAlways); TextureColumnIndex = TiledFontTexture.CreateColumnIndex(MaxTextureCharCapacity); FontTexture = null; }
internal void RemoveUser(String key, TiledTexture user) { if(String.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(); if(user == null) throw new ArgumentNullException(); if(!Users.ContainsKey(key)) throw new ArgumentException("Attempt to remove a user from an unknown key."); if(Users[key] == null) throw new ArgumentException("Attempt to remove an unknown user."); if(!Users[key].Contains(user)) throw new ArgumentException("Attempt to remove an unknown user."); Users[key].Remove(user); //Let the cache policy decide what to do. ApplyCachePolicyForRemovalOfUser(key); }
private void OnInitComplete() { if(TextureVariableName.EndsWith(ShaderTexture.VariableTextureSuffix)) TextureVariableName = TextureVariableName.Substring(0, TextureVariableName.Length - ShaderTexture.VariableTextureSuffix.Length); texture = new TiledTexture(engine.D3DDevice.Device, WidthOfTiles, WidthOfTiles, WidthInTiles, WidthInTiles, SlimDX.DXGI.Format.R32_Float); texture.BindToEffect(effect, TextureVariableName); string locationVarName = TextureVariableName + "Location"; locationVar = effect.GetVariableByName(locationVarName).AsVector(); locationVar.Set(new Vector2()); InitTerrainAtStartingLongLat(); }
public ColumnIndex(TiledTexture tiledTexture, Int32 columns = DefaultColumns, String name = DefaultName) : base(name, tiledTexture) { BuildKeyList(columns); }