Skip to content

Commit

Permalink
Merge pull request tainicom#17 from tainicom/Tilemap
Browse files Browse the repository at this point in the history
Tilemap
  • Loading branch information
nkast authored Nov 24, 2022
2 parents 144ba0b + 2c4f905 commit f479df6
Show file tree
Hide file tree
Showing 91 changed files with 3,568 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Aether.Extras.PORTABLE.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AnimationImporters.PORTABLE
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aether.Atlas.PORTABLE", "Atlas\Aether.Atlas.PORTABLE.csproj", "{E5907795-BC19-4CAA-9909-9F7145E1BB0D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aether.Tilemap.PORTABLE", "Tilemap\Aether.Tilemap.PORTABLE.csproj", "{94963AFA-FAC3-42A0-A2B2-4DA3A7F604D8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Aether.Shaders", "Aether.Shaders", "{0193DE8C-8B7A-43F6-A30B-E65EC387B2C4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aether.Shaders.Tilemap.PORTABLE", "Shaders\Tilemap\Aether.Shaders.Tilemap.PORTABLE.csproj", "{CA1564C9-D4A6-4454-A6B6-7B4E907DF8C0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -47,6 +53,14 @@ Global
{E5907795-BC19-4CAA-9909-9F7145E1BB0D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E5907795-BC19-4CAA-9909-9F7145E1BB0D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E5907795-BC19-4CAA-9909-9F7145E1BB0D}.Release|Any CPU.Build.0 = Release|Any CPU
{94963AFA-FAC3-42A0-A2B2-4DA3A7F604D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{94963AFA-FAC3-42A0-A2B2-4DA3A7F604D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{94963AFA-FAC3-42A0-A2B2-4DA3A7F604D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{94963AFA-FAC3-42A0-A2B2-4DA3A7F604D8}.Release|Any CPU.Build.0 = Release|Any CPU
{CA1564C9-D4A6-4454-A6B6-7B4E907DF8C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CA1564C9-D4A6-4454-A6B6-7B4E907DF8C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CA1564C9-D4A6-4454-A6B6-7B4E907DF8C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CA1564C9-D4A6-4454-A6B6-7B4E907DF8C0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -55,5 +69,9 @@ Global
{C3218A39-5491-44BF-B820-754832E318DB} = {717F89BC-8423-4E7C-A834-460CFD62B1E3}
{0A079394-D331-433A-94DF-AA25B6522279} = {717F89BC-8423-4E7C-A834-460CFD62B1E3}
{962D579A-91F7-4FAB-940A-423E04B8465E} = {717F89BC-8423-4E7C-A834-460CFD62B1E3}
{CA1564C9-D4A6-4454-A6B6-7B4E907DF8C0} = {0193DE8C-8B7A-43F6-A30B-E65EC387B2C4}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CC734668-3E0E-4826-90C3-55064F0473DB}
EndGlobalSection
EndGlobal
20 changes: 20 additions & 0 deletions Aether.Extras.WINDOWS.MG.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aether.Graphics.WINDOWS.MG"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AnimationImporters.WINDOWS.MG", "Content.Pipeline\AnimationImporters\AnimationImporters.WINDOWS.MG.csproj", "{D9A47306-DEE0-4410-BC2C-BA8FFCE682A3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TilemapImporter.WINDOWS.MG", "Content.Pipeline\TilemapImporters\TilemapImporter.WINDOWS.MG.csproj", "{9B0F9C6B-3C43-472D-B0C1-91E11A9FDE89}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aether.Animation.WINDOWS.MG", "Animation\Aether.Animation.WINDOWS.MG.csproj", "{F08D6D4C-60FB-4543-8D81-594080EB8051}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Aether.Shaders", "Aether.Shaders", "{13D47E11-4A7C-49C8-942E-2543E9C0098A}"
Expand All @@ -29,10 +31,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aether.Atlas.WINDOWS.MG", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aether.Shaders.InfiniteGrid.WINDOWS.MG", "Shaders\InfiniteGrid\Aether.Shaders.InfiniteGrid.WINDOWS.MG.csproj", "{08296A2E-BECF-4DB9-A518-8A613D07B80E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aether.Shaders.Tilemap.WINDOWS.MG", "Shaders\Tilemap\Aether.Shaders.Tilemap.WINDOWS.MG.csproj", "{6721CD07-0880-4154-85AF-EBE6043EF178}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SLMCImporter.WINDOWS.MG", "Content.Pipeline\SLMCImporter\SLMCImporter.WINDOWS.MG.csproj", "{C9FA924B-DA91-4641-8B7D-CBC09E5560AE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VoxelImporters.WINDOWS.MG", "Content.Pipeline\VoxelImporters\VoxelImporters.WINDOWS.MG.csproj", "{AA15CF95-0AF2-4346-9465-CB6EDBE22ED9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aether.Tilemap.WINDOWS.MG", "Tilemap\Aether.Tilemap.WINDOWS.MG.csproj", "{7BD9F460-F3F9-40A0-B298-066EA975C06C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -59,6 +65,10 @@ Global
{D9A47306-DEE0-4410-BC2C-BA8FFCE682A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D9A47306-DEE0-4410-BC2C-BA8FFCE682A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D9A47306-DEE0-4410-BC2C-BA8FFCE682A3}.Release|Any CPU.Build.0 = Release|Any CPU
{9B0F9C6B-3C43-472D-B0C1-91E11A9FDE89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9B0F9C6B-3C43-472D-B0C1-91E11A9FDE89}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9B0F9C6B-3C43-472D-B0C1-91E11A9FDE89}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9B0F9C6B-3C43-472D-B0C1-91E11A9FDE89}.Release|Any CPU.Build.0 = Release|Any CPU
{F08D6D4C-60FB-4543-8D81-594080EB8051}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F08D6D4C-60FB-4543-8D81-594080EB8051}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F08D6D4C-60FB-4543-8D81-594080EB8051}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -83,6 +93,10 @@ Global
{08296A2E-BECF-4DB9-A518-8A613D07B80E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{08296A2E-BECF-4DB9-A518-8A613D07B80E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{08296A2E-BECF-4DB9-A518-8A613D07B80E}.Release|Any CPU.Build.0 = Release|Any CPU
{6721CD07-0880-4154-85AF-EBE6043EF178}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6721CD07-0880-4154-85AF-EBE6043EF178}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6721CD07-0880-4154-85AF-EBE6043EF178}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6721CD07-0880-4154-85AF-EBE6043EF178}.Release|Any CPU.Build.0 = Release|Any CPU
{C9FA924B-DA91-4641-8B7D-CBC09E5560AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C9FA924B-DA91-4641-8B7D-CBC09E5560AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C9FA924B-DA91-4641-8B7D-CBC09E5560AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -91,6 +105,10 @@ Global
{AA15CF95-0AF2-4346-9465-CB6EDBE22ED9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AA15CF95-0AF2-4346-9465-CB6EDBE22ED9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AA15CF95-0AF2-4346-9465-CB6EDBE22ED9}.Release|Any CPU.Build.0 = Release|Any CPU
{7BD9F460-F3F9-40A0-B298-066EA975C06C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7BD9F460-F3F9-40A0-B298-066EA975C06C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7BD9F460-F3F9-40A0-B298-066EA975C06C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7BD9F460-F3F9-40A0-B298-066EA975C06C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -100,10 +118,12 @@ Global
{48E4029A-115C-4DC2-AF3A-0AB94F36BFC0} = {A921886B-C6F7-4FF8-8668-EC20004C464A}
{400DC7B2-739D-4156-916D-2F2E1920310D} = {A921886B-C6F7-4FF8-8668-EC20004C464A}
{D9A47306-DEE0-4410-BC2C-BA8FFCE682A3} = {A921886B-C6F7-4FF8-8668-EC20004C464A}
{9B0F9C6B-3C43-472D-B0C1-91E11A9FDE89} = {A921886B-C6F7-4FF8-8668-EC20004C464A}
{FBBDE2BA-F9F3-4041-8584-2C912C235E26} = {13D47E11-4A7C-49C8-942E-2543E9C0098A}
{96105100-20DB-4187-9BCA-0A20AC9F1298} = {13D47E11-4A7C-49C8-942E-2543E9C0098A}
{E710FBEA-8C75-405D-B6B4-CFC82CB48FB5} = {A921886B-C6F7-4FF8-8668-EC20004C464A}
{08296A2E-BECF-4DB9-A518-8A613D07B80E} = {13D47E11-4A7C-49C8-942E-2543E9C0098A}
{6721CD07-0880-4154-85AF-EBE6043EF178} = {13D47E11-4A7C-49C8-942E-2543E9C0098A}
{C9FA924B-DA91-4641-8B7D-CBC09E5560AE} = {A921886B-C6F7-4FF8-8668-EC20004C464A}
{AA15CF95-0AF2-4346-9465-CB6EDBE22ED9} = {A921886B-C6F7-4FF8-8668-EC20004C464A}
EndGlobalSection
Expand Down
22 changes: 22 additions & 0 deletions Aether.Extras.WINDOWS.XNA.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Aether.Content.Pipeline", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AnimationImporters.WINDOWS.XNA", "Content.Pipeline\AnimationImporters\AnimationImporters.WINDOWS.XNA.csproj", "{E22F02E7-6799-4C14-B9B3-B461D6E9AB6E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TilemapImporter.WINDOWS.XNA", "Content.Pipeline\TilemapImporters\TilemapImporter.WINDOWS.XNA.csproj", "{B5FAF2D1-7164-4956-9474-0F4B19706DE8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aether.Animation.WINDOWS.XNA", "Animation\Aether.Animation.WINDOWS.XNA.csproj", "{1BD2DBC0-D366-42F7-9369-F566CCD01C03}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Aether.Shaders", "Aether.Shaders", "{EFC7A27C-C20B-4BE7-8B3A-2B109991D704}"
Expand All @@ -23,10 +25,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aether.Atlas.WINDOWS.XNA",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aether.Shaders.InfiniteGrid.WINDOWS.XNA", "Shaders\InfiniteGrid\Aether.Shaders.InfiniteGrid.WINDOWS.XNA.csproj", "{908EC8FF-B0ED-478A-B486-702E578AF64A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aether.Shaders.Tilemap.WINDOWS.XNA", "Shaders\Tilemap\Aether.Shaders.Tilemap.WINDOWS.XNA.csproj", "{AB2B4C7E-0FCA-4CFE-8837-E3E3374249F6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SLMCImporter.WINDOWS.XNA", "Content.Pipeline\SLMCImporter\SLMCImporter.WINDOWS.XNA.csproj", "{497B1130-EB63-4057-BC40-F60D6FFA50CA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VoxelImporters.WINDOWS.XNA", "Content.Pipeline\VoxelImporters\VoxelImporters.WINDOWS.XNA.csproj", "{0690782F-0000-0000-0000-000000000000}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aether.Tilemap.WINDOWS.XNA", "Tilemap\Aether.Tilemap.WINDOWS.XNA.csproj", "{746551BA-FB64-43B0-8479-0506B930D3E5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Expand Down Expand Up @@ -69,14 +75,28 @@ Global
{908EC8FF-B0ED-478A-B486-702E578AF64A}.Debug|x86.Build.0 = Debug|x86
{908EC8FF-B0ED-478A-B486-702E578AF64A}.Release|x86.ActiveCfg = Release|x86
{908EC8FF-B0ED-478A-B486-702E578AF64A}.Release|x86.Build.0 = Release|x86
{AB2B4C7E-0FCA-4CFE-8837-E3E3374249F6}.Debug|x86.ActiveCfg = Debug|x86
{AB2B4C7E-0FCA-4CFE-8837-E3E3374249F6}.Debug|x86.Build.0 = Debug|x86
{AB2B4C7E-0FCA-4CFE-8837-E3E3374249F6}.Release|x86.ActiveCfg = Release|x86
{AB2B4C7E-0FCA-4CFE-8837-E3E3374249F6}.Release|x86.Build.0 = Release|x86
{497B1130-EB63-4057-BC40-F60D6FFA50CA}.Debug|x86.ActiveCfg = Debug|x86
{497B1130-EB63-4057-BC40-F60D6FFA50CA}.Debug|x86.Build.0 = Debug|x86
{497B1130-EB63-4057-BC40-F60D6FFA50CA}.Release|x86.ActiveCfg = Release|x86
{497B1130-EB63-4057-BC40-F60D6FFA50CA}.Release|x86.Build.0 = Release|x86
{B5FAF2D1-7164-4956-9474-0F4B19706DE8}.Debug|x86.ActiveCfg = Debug|x86
{B5FAF2D1-7164-4956-9474-0F4B19706DE8}.Debug|x86.Build.0 = Debug|x86
{B5FAF2D1-7164-4956-9474-0F4B19706DE8}.Release|x86.ActiveCfg = Release|x86
{B5FAF2D1-7164-4956-9474-0F4B19706DE8}.Release|x86.Build.0 = Release|x86
{0690782F-0000-0000-0000-000000000000}.Debug|x86.ActiveCfg = Debug|x86
{0690782F-0000-0000-0000-000000000000}.Debug|x86.Build.0 = Debug|x86
{0690782F-0000-0000-0000-000000000000}.Release|x86.ActiveCfg = Release|x86
{0690782F-0000-0000-0000-000000000000}.Release|x86.Build.0 = Release|x86
{746551BA-FB64-43B0-8479-0506B930D3E5}.Debug|x86.ActiveCfg = Debug|x86
{746551BA-FB64-43B0-8479-0506B930D3E5}.Debug|x86.Build.0 = Debug|x86
{746551BA-FB64-43B0-8479-0506B930D3E5}.Release|x86.ActiveCfg = Release|x86
{746551BA-FB64-43B0-8479-0506B930D3E5}.Release|x86.Build.0 = Release|x86


EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -86,9 +106,11 @@ Global
{E22F02E7-6799-4C14-B9B3-B461D6E9AB6E} = {F6B6E505-6037-49E4-9060-8B29A7B99BC1}
{90E6017D-198B-4470-BF9B-8B8791C295CC} = {F6B6E505-6037-49E4-9060-8B29A7B99BC1}
{497B1130-EB63-4057-BC40-F60D6FFA50CA} = {F6B6E505-6037-49E4-9060-8B29A7B99BC1}
{B5FAF2D1-7164-4956-9474-0F4B19706DE8} = {F6B6E505-6037-49E4-9060-8B29A7B99BC1}
{0690782F-0000-0000-0000-000000000000} = {F6B6E505-6037-49E4-9060-8B29A7B99BC1}
{89E0198E-7298-411A-B5C1-61F2754A3F80} = {EFC7A27C-C20B-4BE7-8B3A-2B109991D704}
{B82B862D-C728-4A10-8A56-65D688E022C8} = {EFC7A27C-C20B-4BE7-8B3A-2B109991D704}
{908EC8FF-B0ED-478A-B486-702E578AF64A} = {EFC7A27C-C20B-4BE7-8B3A-2B109991D704}
{AB2B4C7E-0FCA-4CFE-8837-E3E3374249F6} = {EFC7A27C-C20B-4BE7-8B3A-2B109991D704}
EndGlobalSection
EndGlobal
174 changes: 174 additions & 0 deletions Content.Pipeline/TilemapImporters/Processors/TilePacker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
#region License
// Copyright 2021 Kastellanos Nikolaos
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#endregion

using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;

namespace tainicom.Aether.Content.Pipeline
{
internal static class TilePacker
{
internal static IList<TileContent> ArrangeGlyphs(IList<TileContent> sourceTiles,
int tileWidth, int tileHeight,
bool requirePOT, bool requireSquare)
{
// copy tiles to destTiles
var destTiles = new List<TileContent>();
for (int i = 0; i < sourceTiles.Count; i++)
{
var srcTile = sourceTiles[i];
var dstTile = new TileContent(srcTile);
destTiles.Add(dstTile);
}

for (int i = 0; i < destTiles.Count; i++)
{
var dstTile = destTiles[i];
dstTile.DstBounds.Width = tileWidth;
dstTile.DstBounds.Height = tileHeight;
}

// Sort so the largest glyphs get arranged first.
destTiles.Sort(CompareTileSizes);

// Work out how big the output bitmap should be.
int outputWidth = EstimateOutputWidth(destTiles);
outputWidth = MakeValidTextureSize(outputWidth, requirePOT);
int outputHeight = 0;

// Choose positions for each glyph, one at a time.
for (int i = 0; i < destTiles.Count; i++)
{
PositionGlyph(destTiles, i, outputWidth);
outputHeight = Math.Max(outputHeight, destTiles[i].DstBounds.Y + destTiles[i].DstBounds.Height);
}

// Create the merged output bitmap.
outputHeight = MakeValidTextureSize(outputHeight, requirePOT);
if (requireSquare)
{
outputHeight = Math.Max(outputWidth, outputHeight);
outputWidth = outputHeight;
}

return destTiles;

}

static void PositionGlyph(List<TileContent> glyphs, int index, int outputWidth)
{
int x = 0;
int y = 0;

while (true)
{
// Is this position free for us to use?
int intersects = FindIntersectingTile(glyphs, index, x, y);

if (intersects < 0)
{
glyphs[index].DstBounds.X = x;
glyphs[index].DstBounds.Y = y;
return;
}

// Skip past the existing glyph that we collided with.
x = glyphs[intersects].DstBounds.X + glyphs[intersects].DstBounds.Width;

// If we ran out of room to move to the right, try the next line down instead.
//if (x + glyphs[index].SrcBounds.Width > outputWidth)
if (x + glyphs[index].DstBounds.Width > outputWidth)
{
x = 0;
y++;
}
}
}

// Checks if a proposed glyph position collides with anything that we already arranged.
static int FindIntersectingTile(List<TileContent> glyphs, int index, int x, int y)
{
var bounds = glyphs[index].DstBounds;

for (int i = 0; i < index; i++)
{
var other = glyphs[i].DstBounds;

if (other.X >= x + bounds.Width)
continue;
if (other.X + other.Width <= x)
continue;
if (other.Y >= y + bounds.Height)
continue;
if (other.Y + other.Height <= y)
continue;

return i;
}

return -1;
}

static int CompareTileSizes(TileContent a, TileContent b)
{
var res = b.DstBounds.Height.CompareTo(a.DstBounds.Height);
if (res == 0)
res = b.DstBounds.Width.CompareTo(a.DstBounds.Width);
return res;
}

static int EstimateOutputWidth(IList<TileContent> sourceGlyphs)
{
int maxWidth = 0;
int totalSize = 0;

foreach (var sourceGlyph in sourceGlyphs)
{
maxWidth = Math.Max(maxWidth, sourceGlyph.DstBounds.Width);
totalSize += sourceGlyph.DstBounds.Width * sourceGlyph.DstBounds.Height;
}

int width = Math.Max((int)Math.Sqrt(totalSize), maxWidth);
return width;
}

// Rounds a value up to the next larger valid texture size.
static int MakeValidTextureSize(int value, bool requirePowerOfTwo)
{
// In case we want to compress the texture, make sure the size is a multiple of 4.
const int blockSize = 4;

if (requirePowerOfTwo)
{
// Round up to a power of two.
int powerOfTwo = blockSize;

while (powerOfTwo < value)
powerOfTwo <<= 1;

return powerOfTwo;
}
else
{
// Round up to the specified block size.
return (value + blockSize - 1) & ~(blockSize - 1);
}
}
}

}

Loading

0 comments on commit f479df6

Please sign in to comment.