예제 #1
0
        private uint PackTileInAtlas(uint layerIdx, uint tx, uint ty)
        {
            var tileIndex = tx + (ty * _mlmask.Layers[layerIdx].WidthInTiles0);

            if (_mlmask.Layers[layerIdx].Tiles[Convert.ToInt32(tileIndex)].AtlasInPosition == uint.MaxValue)
            {
                BlockCompressLocalTile(ref _mlmask.Layers[layerIdx], tileIndex);

                var recursiveHash = FNV1A.FnvHashInitial;
                for (uint y = 0; y < _mlmask.AtlasTileSize / 4; y++)
                {
                    for (uint x = 0; x < _mlmask.AtlasTileSize / 4; x++)
                    {
                        var compressedBlock = _mlmask.Layers[layerIdx].Tiles[Convert.ToInt32(tileIndex)].AtlasBlockCompressed[x + (y * _mlmask.AtlasTileSize / 4)];
                        var color32         = new float[16];
                        D3DX.D3DXDecodeBC4U(ref color32, compressedBlock);
                        var color8 = new byte[16];
                        for (uint i = 0; i < 16; ++i)
                        {
                            color8[i] = Convert.ToByte(color32[i] * 255.0f);
                        }

                        recursiveHash = FNV1A.HashReadOnlySpan(color8, recursiveHash);
                    }
                }

                var atlasView = new TileView();
                if (!_mlmask.AtlasTiles.TryGetValue(recursiveHash, out atlasView))
                {
                    var atlasTile = new TileView
                    {
                        AtlasInPosition = _mlmask.AtlasTilesCount++,
                        LayerIndex      = layerIdx,
                        LayerTileIndex  = tileIndex
                    };

                    atlasView = atlasTile;
                    _mlmask.AtlasTiles.Add(recursiveHash, atlasTile);
                }

                var z = _mlmask.Layers[layerIdx].Tiles[Convert.ToInt32(tileIndex)];
                z.AtlasInPosition = atlasView.AtlasInPosition;
                _mlmask.Layers[layerIdx].Tiles[Convert.ToInt32(tileIndex)] = z;
            }

            return(_mlmask.Layers[layerIdx].Tiles[Convert.ToInt32(tileIndex)].AtlasInPosition);
        }
예제 #2
0
        uint PackTileInAtlas(uint layerIdx, uint tx, uint ty)
        {
            uint tileIndex = (tx + ty * mlmask.layers[layerIdx]._widthInTiles0);

            if (mlmask.layers[layerIdx].tiles[Convert.ToInt32(tileIndex)]._atlasInPosition == uint.MaxValue)
            {
                BlockCompressLocalTile(ref mlmask.layers[layerIdx], tileIndex);

                UInt64 recursiveHash = FNV1A.FnvHashInitial;
                for (uint y = 0; y < mlmask._atlasTileSize / 4; y++)
                {
                    for (uint x = 0; x < mlmask._atlasTileSize / 4; x++)
                    {
                        UInt64  compressedBlock = mlmask.layers[layerIdx].tiles[Convert.ToInt32(tileIndex)]._atlasBlockCompressed[x + y * mlmask._atlasTileSize / 4];
                        float[] color32         = new float[16];
                        D3DX.D3DXDecodeBC4U(ref color32, compressedBlock);
                        Byte[] color8 = new Byte[16];
                        for (uint i = 0; i < 16; ++i)
                        {
                            color8[i] = Convert.ToByte(color32[i] * 255.0f);
                        }

                        recursiveHash = FNV1A.HashReadOnlySpan(color8, recursiveHash);
                    }
                }

                TileView atlasView = new TileView();
                if (!mlmask._atlasTiles.TryGetValue(recursiveHash, out atlasView))
                {
                    TileView atlasTile = new TileView();
                    atlasTile._atlasInPosition = mlmask._atlasTilesCount++;
                    atlasTile._layerIndex      = layerIdx;
                    atlasTile._layerTileIndex  = tileIndex;

                    atlasView = atlasTile;
                    mlmask._atlasTiles.Add(recursiveHash, atlasTile);
                }

                var z = mlmask.layers[layerIdx].tiles[Convert.ToInt32(tileIndex)];
                z._atlasInPosition = atlasView._atlasInPosition;
                mlmask.layers[layerIdx].tiles[Convert.ToInt32(tileIndex)] = z;
            }

            return(mlmask.layers[layerIdx].tiles[Convert.ToInt32(tileIndex)]._atlasInPosition);
        }