Example #1
0
        private IEnumerator TexturesSetPrepare()
        {
            foreach (CircleSizes size in Enum.GetValues(typeof(CircleSizes)))
            {
                foreach (CircleColors color in Enum.GetValues(typeof(CircleColors)))
                {
                    var     key     = new TextureKey(size, color);
                    Texture texture = null;

                    yield return(StartCoroutine(CreateTexture(key, (t) =>
                    {
                        texture = t;
                    })));

                    if (!texturesCache.ContainsKey(key))
                    {
                        texturesCache.Add(key, texture);
                    }
                    else
                    {
                        Destroy(texture);
                        texture = null;
                    }
                }
            }
            yield return(null);

            if (onSetIsReady != null)
            {
                onSetIsReady();
            }
        }
Example #2
0
        private IEnumerator CreateTexture(TextureKey key, Action <Texture> callback)
        {
            var sizeValue = GameModel.SIZE_BASE * (int)key.size;
            var texture   = new Texture2D(sizeValue, sizeValue, TextureFormat.ARGB32, false)
            {
                filterMode = FilterMode.Trilinear,
                anisoLevel = 20
            };

            Color32[] gradient    = null;
            var       colorFiller = new GradientColorGenerator(() =>
            {
                gradient = new Color32[sizeValue * sizeValue];

                for (int i = 0; i < sizeValue; i++)
                {
                    for (int j = 0; j < sizeValue; j++)
                    {
                        gradient[j + i * sizeValue] = Color32.Lerp(GetColorValue(key.color), GradientColor, (float)j / (sizeValue / 1.8f));
                    }
                }
            });

            yield return(colorFiller.WaitForColorFill());

            texture.SetPixels32(gradient, 0);
            texture.Apply(false, true);

            callback(texture);
        }
 protected override void UnloadTextureCore(TextureKey textureKey)
 {
     if (_textures.ContainsKey(textureKey))
     {
         _textures[textureKey].Dispose();
         _textures.Remove(textureKey);
     }
 }
 protected override void LoadTextureCore(TextureKey textureKey)
 {
     if (!_textures.ContainsKey(textureKey))
     {
         var textureString = TextureLookupTable[textureKey];
         var texture       = _contentManager.Load <Texture2D>(textureString);
         _textures.Add(textureKey, texture);
     }
 }
        protected override Texture2D GetTextureCore(TextureKey textureKey)
        {
            if (!_textures.ContainsKey(textureKey))
            {
                LoadTexture(textureKey);
            }

            return(_textures[textureKey]);
        }
Example #6
0
        /// <summary>
        /// Reads shader specialization state that has been serialized.
        /// </summary>
        /// <param name="dataReader">Data reader</param>
        /// <returns>Shader specialization state</returns>
        public static ShaderSpecializationState Read(ref BinarySerializer dataReader)
        {
            ShaderSpecializationState specState = new ShaderSpecializationState();

            dataReader.Read(ref specState._queriedState);
            dataReader.Read(ref specState._compute);

            if (specState._compute)
            {
                dataReader.ReadWithMagicAndSize(ref specState.ComputeState, ComsMagic);
            }
            else
            {
                dataReader.ReadWithMagicAndSize(ref specState.GraphicsState, GfxsMagic);
            }

            dataReader.Read(ref specState._constantBufferUsePerStage);

            int constantBufferUsePerStageMask = specState._constantBufferUsePerStage;

            while (constantBufferUsePerStageMask != 0)
            {
                int index = BitOperations.TrailingZeroCount(constantBufferUsePerStageMask);
                dataReader.Read(ref specState.ConstantBufferUse[index]);
                constantBufferUsePerStageMask &= ~(1 << index);
            }

            if (specState._queriedState.HasFlag(QueriedStateFlags.TransformFeedback))
            {
                ushort tfCount = 0;
                dataReader.Read(ref tfCount);
                specState.TransformFeedbackDescriptors = new TransformFeedbackDescriptor[tfCount];

                for (int index = 0; index < tfCount; index++)
                {
                    dataReader.ReadWithMagicAndSize(ref specState.TransformFeedbackDescriptors[index], TfbdMagic);
                }
            }

            ushort count = 0;

            dataReader.Read(ref count);

            for (int index = 0; index < count; index++)
            {
                TextureKey textureKey = default;
                Box <TextureSpecializationState> textureState = new Box <TextureSpecializationState>();

                dataReader.ReadWithMagicAndSize(ref textureKey, TexkMagic);
                dataReader.ReadWithMagicAndSize(ref textureState.Value, TexsMagic);

                specState._textureSpecialization[textureKey] = textureState;
            }

            return(specState);
        }
Example #7
0
        /// <summary>
        /// Gets texture specialization state for a given texture, or create a new one if not present.
        /// </summary>
        /// <param name="stageIndex">Shader stage where the texture is used</param>
        /// <param name="handle">Offset in words of the texture handle on the texture buffer</param>
        /// <param name="cbufSlot">Slot of the texture buffer constant buffer</param>
        /// <returns>Texture specialization state</returns>
        private Box <TextureSpecializationState> GetOrCreateTextureSpecState(int stageIndex, int handle, int cbufSlot)
        {
            TextureKey key = new TextureKey(stageIndex, handle, cbufSlot);

            if (!_textureSpecialization.TryGetValue(key, out Box <TextureSpecializationState> state))
            {
                _textureSpecialization.Add(key, state = new Box <TextureSpecializationState>());
            }

            return(state);
        }
Example #8
0
        /// <summary>
        /// Gets texture specialization state for a given texture.
        /// </summary>
        /// <param name="stageIndex">Shader stage where the texture is used</param>
        /// <param name="handle">Offset in words of the texture handle on the texture buffer</param>
        /// <param name="cbufSlot">Slot of the texture buffer constant buffer</param>
        /// <returns>Texture specialization state</returns>
        private Box <TextureSpecializationState> GetTextureSpecState(int stageIndex, int handle, int cbufSlot)
        {
            TextureKey key = new TextureKey(stageIndex, handle, cbufSlot);

            if (_textureSpecialization.TryGetValue(key, out Box <TextureSpecializationState> state))
            {
                return(state);
            }

            return(null);
        }
Example #9
0
        private Texture2D GetReplacementBuildingTexture(string textureName)
        {
            foreach (var pack in ActivePacks)
            {
                var key = new TextureKey(pack.Path, textureName);

                if (_replacementBuildingTextures.TryGetValue(key, out var replacementTexture))
                {
                    return(replacementTexture);
                }

                replacementTexture = pack.GetBuildingTexture(textureName);
                if (replacementTexture != null)
                {
                    // Set correct name and add to cache
                    replacementTexture.name           = TextureNames.ReplacedTexturePrefix + textureName;
                    _replacementBuildingTextures[key] = replacementTexture;

                    return(replacementTexture);
                }
            }

            return(null);
        }
Example #10
0
 protected abstract void UnloadTextureCore(TextureKey textureKey);
Example #11
0
 public Texture2D GetTexture(TextureKey textureKey)
 => ResourceGateway.GetTexture(textureKey);
Example #12
0
 public void UnloadTexture(TextureKey textureKey)
 => UnloadTexture(textureKey);
Example #13
0
 protected abstract Texture2D GetTextureCore(TextureKey textureKey);
Example #14
0
 public Texture2D GetTexture(TextureKey textureKey)
 => GetTextureCore(textureKey);
Example #15
0
 public void LoadTexture(TextureKey textureKey)
 => LoadTextureCore(textureKey);
Example #16
0
 public void UnloadTexture(TextureKey key)
 {
     textures.Remove(key);
 }
Example #17
0
        public void LoadTexture(string filename, TextureKey key)
        {
            Texture2D texture = _contentManager.Load <Texture2D>(filename);

            textures.Add(key, texture);
        }
Example #18
0
        public Texture GetTexture(CircleSizes size, CircleColors color)
        {
            var key = new TextureKey(size, color);

            return(texturesCache.ContainsKey(key) ? texturesCache[key] : null);
        }
Example #19
0
 public Texture2D GetTexture(TextureKey key)
 {
     return(textures[key]);
 }
Example #20
0
 public void LoadTexture(TextureKey textureKey)
 => ResourceGateway.LoadTexture(textureKey);
Example #21
0
        /// <summary>
        /// Checks if the recorded state matches the current GPU state.
        /// </summary>
        /// <param name="channel">GPU channel</param>
        /// <param name="poolState">Texture pool state</param>
        /// <param name="isCompute">Indicates whenever the check is requested by the 3D or compute engine</param>
        /// <returns>True if the state matches, false otherwise</returns>
        private bool Matches(GpuChannel channel, GpuChannelPoolState poolState, bool isCompute)
        {
            int constantBufferUsePerStageMask = _constantBufferUsePerStage;

            while (constantBufferUsePerStageMask != 0)
            {
                int index = BitOperations.TrailingZeroCount(constantBufferUsePerStageMask);

                uint useMask = isCompute
                    ? channel.BufferManager.GetComputeUniformBufferUseMask()
                    : channel.BufferManager.GetGraphicsUniformBufferUseMask(index);

                if (ConstantBufferUse[index] != useMask)
                {
                    return(false);
                }

                constantBufferUsePerStageMask &= ~(1 << index);
            }

            foreach (var kv in _textureSpecialization)
            {
                TextureKey textureKey = kv.Key;

                (int textureBufferIndex, int samplerBufferIndex) = TextureHandle.UnpackSlots(textureKey.CbufSlot, poolState.TextureBufferIndex);

                ulong textureCbAddress;
                ulong samplerCbAddress;

                if (isCompute)
                {
                    textureCbAddress = channel.BufferManager.GetComputeUniformBufferAddress(textureBufferIndex);
                    samplerCbAddress = channel.BufferManager.GetComputeUniformBufferAddress(samplerBufferIndex);
                }
                else
                {
                    textureCbAddress = channel.BufferManager.GetGraphicsUniformBufferAddress(textureKey.StageIndex, textureBufferIndex);
                    samplerCbAddress = channel.BufferManager.GetGraphicsUniformBufferAddress(textureKey.StageIndex, samplerBufferIndex);
                }

                if (!channel.MemoryManager.Physical.IsMapped(textureCbAddress) || !channel.MemoryManager.Physical.IsMapped(samplerCbAddress))
                {
                    continue;
                }

                Image.TextureDescriptor descriptor;

                if (isCompute)
                {
                    descriptor = channel.TextureManager.GetComputeTextureDescriptor(
                        poolState.TexturePoolGpuVa,
                        poolState.TextureBufferIndex,
                        poolState.TexturePoolMaximumId,
                        textureKey.Handle,
                        textureKey.CbufSlot);
                }
                else
                {
                    descriptor = channel.TextureManager.GetGraphicsTextureDescriptor(
                        poolState.TexturePoolGpuVa,
                        poolState.TextureBufferIndex,
                        poolState.TexturePoolMaximumId,
                        textureKey.StageIndex,
                        textureKey.Handle,
                        textureKey.CbufSlot);
                }

                Box <TextureSpecializationState> specializationState = kv.Value;

                if (specializationState.Value.QueriedFlags.HasFlag(QueriedTextureStateFlags.CoordNormalized) &&
                    specializationState.Value.CoordNormalized != descriptor.UnpackTextureCoordNormalized())
                {
                    return(false);
                }
            }

            return(true);
        }
        public void Deserialize(Stream input)
        {
            this.Version = input.ReadValueU32();
            if (this.Version < 2 || this.Version > 6)
            {
                throw new FormatException();
            }

            List <ResourceKey> keyTable = null;

            if (this.Version >= 3)
            {
                keyTable = new List <ResourceKey>();

                long keyTableOffset   = input.ReadValueU32();
                long originalPosition = input.Position;
                long keyTableSize     = input.ReadValueU32();

                input.Seek(originalPosition + keyTableOffset, SeekOrigin.Begin);

                var count = input.ReadValueU32();
                for (uint i = 0; i < count; i++)
                {
                    keyTable.Add(input.ReadResourceKeyTGI());
                }

                input.Seek(originalPosition + 4, SeekOrigin.Begin);
            }

            this.ShaderKeys.Clear();
            {
                var count = input.ReadValueU32();
                for (uint i = 0; i < count; i++)
                {
                    var shaderKey = new ShaderKey();
                    shaderKey.Deserialize(input);
                    this.ShaderKeys.Add(shaderKey);
                }
            }

            if (this.Version >= 3)
            {
                this.SkinRamp    = keyTable[input.ReadValueS32()];
                this.ScatterRamp = keyTable[input.ReadValueS32()];
            }
            else
            {
                this.SkinRamp    = input.ReadResourceKeyIGT();
                this.ScatterRamp = input.ReadResourceKeyIGT();
            }

            this.TextureKeys.Clear();
            {
                var count = input.ReadValueU32();
                for (int i = 0; i < count; i++)
                {
                    var textureKey = new TextureKey();
                    textureKey.Deserialize(input, this.Version, keyTable);
                    this.TextureKeys.Add(textureKey);
                }
            }
        }
Example #23
0
 public void UnloadTexture(TextureKey textureKey)
 => ResourceGateway.UnloadTexture(textureKey);
Example #24
0
        public void applyFacadeImageHowSandblast(IDictionary <Facade, string> facades)
        {
            KD.SDK.Catalog catalog = _appli.Catalog;

            catalog.SessionId = _appli.StartSessionFromCallParams(iParamsBlock);
            if (catalog.FileLoad(StringResources.getCatalogsPath() + "\\@tx_pal.cat", ""))
            {
                String project = _scene.SceneGetInfo(SceneEnum.SceneInfo.NAME);
                //MessageBox.Show("isLoad=" + catalog.IsLoaded() + " " + catalog.GetInfo(CatalogEnum.InfoId.FILENAME));
                int n = catalog.TableGetLinesNb(CatalogEnum.TableId.TEXTURES, 0);

                int textureIndex = 0;
                int TextureKey;

                Random rand = new Random();
                //MessageBox.Show(facades.Count.ToString());
                string strWidth;
                int    oldWidth, newWidth;
                foreach (KeyValuePair <Facade, string> item in facades)
                {
                    //MessageBox.Show(item.Key.getTextureId().ToString());
                    if (item.Key.getTextureId() != -1)
                    {
                        textureIndex = catalog.TableGetLineRankFromCode(CatalogEnum.TableId.TEXTURES, 0, 0, item.Key.getTextureId().ToString(), false);
                        TextureKey   = item.Key.getTextureId();
                        // MessageBox.Show("texture index = " + textureIndex);
                    }
                    else
                    {
                        catalog.TableAddLines(CatalogEnum.TableId.TEXTURES, 0, 1);
                        textureIndex = n++;
                        TextureKey   = textureIndex + 1;
                        while (catalog.TableGetLineRankFromCode(CatalogEnum.TableId.TEXTURES, 0, 0, TextureKey.ToString(), false) != -1)
                        {
                            //MessageBox.Show("key: " + TextureKey + " alreadyExist\n"+ catalog.TableGetLineRankFromCode(CatalogEnum.TableId.TEXTURES, 0, 0, TextureKey.ToString(), false));
                            TextureKey++;
                        }
                        item.Key.setTextureId(TextureKey);
                    }
                    strWidth = catalog.TableGetLineInfo(CatalogEnum.TableId.TEXTURES, 0, textureIndex, 11);
                    Int32.TryParse(strWidth, out oldWidth);
                    if (oldWidth != item.Key.width)
                    {
                        newWidth = item.Key.width;
                    }
                    else
                    {
                        newWidth = oldWidth + 1;
                    }
                    //MessageBox.Show("edit "+ textureIndex + " line, with "+ TextureKey + " kod");
                    catalog.TableSetLineInfo(CatalogEnum.TableId.TEXTURES, 0, textureIndex, 0, TextureKey.ToString());
                    catalog.TableSetLineInfo(CatalogEnum.TableId.TEXTURES, 0, textureIndex, 1, project + item.Key.getNumber() + rand.Next(1, 10));
                    catalog.TableSetLineInfo(CatalogEnum.TableId.TEXTURES, 0, textureIndex, 3, StringResources.getImageDirectoryName() + "\\gray.jpg");

                    catalog.TableSetLineInfo(CatalogEnum.TableId.TEXTURES, 0, textureIndex, 4, "0");
                    catalog.TableSetLineInfo(CatalogEnum.TableId.TEXTURES, 0, textureIndex, 5, "0");

                    catalog.TableSetLineInfo(CatalogEnum.TableId.TEXTURES, 0, textureIndex, 10, item.Value);
                    catalog.TableSetLineInfo(CatalogEnum.TableId.TEXTURES, 0, textureIndex, 11, newWidth.ToString());
                    catalog.TableSetLineInfo(CatalogEnum.TableId.TEXTURES, 0, textureIndex, 12, item.Key.height.ToString());
                    catalog.TableSetLineInfo(CatalogEnum.TableId.TEXTURES, 0, textureIndex, 13, "0");
                    catalog.TableSetLineInfo(CatalogEnum.TableId.TEXTURES, 0, textureIndex, 15, "1");
                    catalog.TableSetLineInfo(CatalogEnum.TableId.TEXTURES, 0, textureIndex, 16, "1");

                    //catalog.FileSave(StringResources.getCatalogsPath() + "\\@tx_pal.cat");
                    //MessageBox.Show(catalog.TableGetLine(CatalogEnum.TableId.TEXTURES, 0, textureIndex));
                    //n++;
                    //nextTextureKey++;
                }
                if (catalog.FileSave(StringResources.getCatalogsPath() + "\\@tx_pal.cat"))
                {
                    //MessageBox.Show("File Saved");
                }
                else
                {
                    MessageBox.Show("File dont saved");
                }
                registerTextures(facades.Keys);
                updateGraphics();

                //MessageBox.Show(count.ToString());
                //catalog.TableSetLineInfo(CatalogEnum.TableId.TEXTURES, 0, n, 0, (n+1).ToString());
                //catalog.TableSetLineInfo(CatalogEnum.TableId.TEXTURES, 0, n, 1, "New Texture");
                //catalog.TableSetLineInfo(CatalogEnum.TableId.TEXTURES, 0, n, 3, "images\\new.jpg");
                //catalog.TableSetLineInfo(CatalogEnum.TableId.TEXTURES, 0, n, 4, "1521");
                //catalog.TableSetLineInfo(CatalogEnum.TableId.TEXTURES, 0, n, 5, "651");
                //catalog.FileSave("C:\\InSitu\\Catalogs\\@tx_pal.cat");
                //n++;


                //for (int i = 0; i < n; i++)
                //{
                //    MessageBox.Show(catalog.TableGetLine(CatalogEnum.TableId.TEXTURES, 0, i));
                //}
            }
            else
            {
                MessageBox.Show("SomethingWrong");
            }
        }