mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-23 17:43:08 -05:00
Simplify terrain atlas code
This commit is contained in:
parent
b7c712fc03
commit
6f27061871
22 changed files with 175 additions and 180 deletions
|
@ -45,8 +45,8 @@ namespace ClassicalSharp {
|
|||
}
|
||||
|
||||
public void DrawBatch(BlockID block, float size, float x, float y) {
|
||||
drawer.elementsPerAtlas1D = TerrainAtlas1D.elementsPerAtlas1D;
|
||||
drawer.invVerElementSize = TerrainAtlas1D.invElementSize;
|
||||
drawer.tilesPerAtlas1D = TerrainAtlas1D.TilesPerAtlas;
|
||||
drawer.invVerTileSize = TerrainAtlas1D.invTileSize;
|
||||
|
||||
bool bright = BlockInfo.FullBright[block];
|
||||
if (BlockInfo.Draw[block] == DrawType.Gas) return;
|
||||
|
@ -94,7 +94,7 @@ namespace ClassicalSharp {
|
|||
|
||||
int GetTex(BlockID block, int side) {
|
||||
int texLoc = BlockInfo.GetTextureLoc(block, side);
|
||||
texIndex = texLoc / TerrainAtlas1D.elementsPerAtlas1D;
|
||||
texIndex = texLoc / TerrainAtlas1D.TilesPerAtlas;
|
||||
|
||||
if (lastTexIndex != texIndex) Flush();
|
||||
return texLoc;
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace ClassicalSharp.Gui.Screens {
|
|||
}
|
||||
|
||||
void RenderTerrain() {
|
||||
int elementsPerAtlas = TerrainAtlas1D.elementsPerAtlas1D;
|
||||
int elementsPerAtlas = TerrainAtlas1D.TilesPerAtlas;
|
||||
for (int i = 0; i < TerrainAtlas2D.TilesPerRow * TerrainAtlas2D.RowsCount;) {
|
||||
int index = 0, texIdx = i / elementsPerAtlas, ignored;
|
||||
|
||||
|
@ -91,7 +91,7 @@ namespace ClassicalSharp.Gui.Screens {
|
|||
}
|
||||
idAtlas.tex.Y += (short)tileSize;
|
||||
|
||||
if ((y % 4) != 3) continue;
|
||||
if ((y % 4) != 3) continue;
|
||||
game.Graphics.BindTexture(idAtlas.tex.ID);
|
||||
game.Graphics.UpdateDynamicVb_IndexedTris(dynamicVb, vertices, index);
|
||||
index = 0;
|
||||
|
|
|
@ -103,8 +103,8 @@ namespace ClassicalSharp.Model {
|
|||
SpriteXQuad(true, false);
|
||||
SpriteXQuad(true, true);
|
||||
} else {
|
||||
drawer.elementsPerAtlas1D = TerrainAtlas1D.elementsPerAtlas1D;
|
||||
drawer.invVerElementSize = TerrainAtlas1D.invElementSize;
|
||||
drawer.tilesPerAtlas1D = TerrainAtlas1D.TilesPerAtlas;
|
||||
drawer.invVerTileSize = TerrainAtlas1D.invTileSize;
|
||||
|
||||
drawer.minBB = BlockInfo.MinBB[block]; drawer.minBB.Y = 1 - drawer.minBB.Y;
|
||||
drawer.maxBB = BlockInfo.MaxBB[block]; drawer.maxBB.Y = 1 - drawer.maxBB.Y;
|
||||
|
@ -128,7 +128,7 @@ namespace ClassicalSharp.Model {
|
|||
|
||||
int GetTex(int side) {
|
||||
int texLoc = BlockInfo.GetTextureLoc(block, side);
|
||||
texIndex = texLoc / TerrainAtlas1D.elementsPerAtlas1D;
|
||||
texIndex = texLoc / TerrainAtlas1D.TilesPerAtlas;
|
||||
|
||||
if (lastTexIndex != texIndex) Flush();
|
||||
return texLoc;
|
||||
|
|
|
@ -68,7 +68,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||
}
|
||||
if (LostContext) throw new InvalidOperationException("Cannot create texture when context lost");
|
||||
|
||||
if (!bmp.IsLocked) bmp.LockBits();
|
||||
if (!bmp.IsLocked) bmp.LockBits();
|
||||
int texId = CreateTexture(bmp.Width, bmp.Height, bmp.Scan0, managedPool, mipmaps);
|
||||
bmp.UnlockBits();
|
||||
return texId;
|
||||
|
|
|
@ -124,13 +124,13 @@ namespace ClassicalSharp {
|
|||
|
||||
void DrawLeftFace(int count) {
|
||||
int texId = BlockInfo.textures[curBlock * Side.Sides + Side.Left];
|
||||
int i = texId / elementsPerAtlas1D;
|
||||
float vOrigin = (texId % elementsPerAtlas1D) * invVerElementSize;
|
||||
int i = texId / tilesPerAtlas1D;
|
||||
float vOrigin = (texId % tilesPerAtlas1D) * invVerTileSize;
|
||||
int offset = (lightFlags >> Side.Left) & 1;
|
||||
|
||||
float u1 = minBB.Z, u2 = (count - 1) + maxBB.Z * 15.99f/16f;
|
||||
float v1 = vOrigin + maxBB.Y * invVerElementSize;
|
||||
float v2 = vOrigin + minBB.Y * invVerElementSize * 15.99f/16f;
|
||||
float v1 = vOrigin + maxBB.Y * invVerTileSize;
|
||||
float v2 = vOrigin + minBB.Y * invVerTileSize * 15.99f/16f;
|
||||
DrawInfo part = isTranslucent ? translucentParts[i] : normalParts[i];
|
||||
|
||||
int F = bitFlags[cIndex];
|
||||
|
@ -166,13 +166,13 @@ namespace ClassicalSharp {
|
|||
|
||||
void DrawRightFace(int count) {
|
||||
int texId = BlockInfo.textures[curBlock * Side.Sides + Side.Right];
|
||||
int i = texId / elementsPerAtlas1D;
|
||||
float vOrigin = (texId % elementsPerAtlas1D) * invVerElementSize;
|
||||
int i = texId / tilesPerAtlas1D;
|
||||
float vOrigin = (texId % tilesPerAtlas1D) * invVerTileSize;
|
||||
int offset = (lightFlags >> Side.Right) & 1;
|
||||
|
||||
float u1 = (count - minBB.Z), u2 = (1 - maxBB.Z) * 15.99f/16f;
|
||||
float v1 = vOrigin + maxBB.Y * invVerElementSize;
|
||||
float v2 = vOrigin + minBB.Y * invVerElementSize * 15.99f/16f;
|
||||
float v1 = vOrigin + maxBB.Y * invVerTileSize;
|
||||
float v2 = vOrigin + minBB.Y * invVerTileSize * 15.99f/16f;
|
||||
DrawInfo part = isTranslucent ? translucentParts[i] : normalParts[i];
|
||||
|
||||
int F = bitFlags[cIndex];
|
||||
|
@ -208,13 +208,13 @@ namespace ClassicalSharp {
|
|||
|
||||
void DrawFrontFace(int count) {
|
||||
int texId = BlockInfo.textures[curBlock * Side.Sides + Side.Front];
|
||||
int i = texId / elementsPerAtlas1D;
|
||||
float vOrigin = (texId % elementsPerAtlas1D) * invVerElementSize;
|
||||
int i = texId / tilesPerAtlas1D;
|
||||
float vOrigin = (texId % tilesPerAtlas1D) * invVerTileSize;
|
||||
int offset = (lightFlags >> Side.Front) & 1;
|
||||
|
||||
float u1 = (count - minBB.X), u2 = (1 - maxBB.X) * 15.99f/16f;
|
||||
float v1 = vOrigin + maxBB.Y * invVerElementSize;
|
||||
float v2 = vOrigin + minBB.Y * invVerElementSize * 15.99f/16f;
|
||||
float v1 = vOrigin + maxBB.Y * invVerTileSize;
|
||||
float v2 = vOrigin + minBB.Y * invVerTileSize * 15.99f/16f;
|
||||
DrawInfo part = isTranslucent ? translucentParts[i] : normalParts[i];
|
||||
|
||||
int F = bitFlags[cIndex];
|
||||
|
@ -250,13 +250,13 @@ namespace ClassicalSharp {
|
|||
|
||||
void DrawBackFace(int count) {
|
||||
int texId = BlockInfo.textures[curBlock * Side.Sides + Side.Back];
|
||||
int i = texId / elementsPerAtlas1D;
|
||||
float vOrigin = (texId % elementsPerAtlas1D) * invVerElementSize;
|
||||
int i = texId / tilesPerAtlas1D;
|
||||
float vOrigin = (texId % tilesPerAtlas1D) * invVerTileSize;
|
||||
int offset = (lightFlags >> Side.Back) & 1;
|
||||
|
||||
float u1 = minBB.X, u2 = (count - 1) + maxBB.X * 15.99f/16f;
|
||||
float v1 = vOrigin + maxBB.Y * invVerElementSize;
|
||||
float v2 = vOrigin + minBB.Y * invVerElementSize * 15.99f/16f;
|
||||
float v1 = vOrigin + maxBB.Y * invVerTileSize;
|
||||
float v2 = vOrigin + minBB.Y * invVerTileSize * 15.99f/16f;
|
||||
DrawInfo part = isTranslucent ? translucentParts[i] : normalParts[i];
|
||||
|
||||
int F = bitFlags[cIndex];
|
||||
|
@ -292,13 +292,13 @@ namespace ClassicalSharp {
|
|||
|
||||
void DrawBottomFace(int count) {
|
||||
int texId = BlockInfo.textures[curBlock * Side.Sides + Side.Bottom];
|
||||
int i = texId / elementsPerAtlas1D;
|
||||
float vOrigin = (texId % elementsPerAtlas1D) * invVerElementSize;
|
||||
int i = texId / tilesPerAtlas1D;
|
||||
float vOrigin = (texId % tilesPerAtlas1D) * invVerTileSize;
|
||||
int offset = (lightFlags >> Side.Bottom) & 1;
|
||||
|
||||
float u1 = minBB.X, u2 = (count - 1) + maxBB.X * 15.99f/16f;
|
||||
float v1 = vOrigin + minBB.Z * invVerElementSize;
|
||||
float v2 = vOrigin + maxBB.Z * invVerElementSize * 15.99f/16f;
|
||||
float v1 = vOrigin + minBB.Z * invVerTileSize;
|
||||
float v2 = vOrigin + maxBB.Z * invVerTileSize * 15.99f/16f;
|
||||
DrawInfo part = isTranslucent ? translucentParts[i] : normalParts[i];
|
||||
|
||||
int F = bitFlags[cIndex];
|
||||
|
@ -334,13 +334,13 @@ namespace ClassicalSharp {
|
|||
|
||||
void DrawTopFace(int count) {
|
||||
int texId = BlockInfo.textures[curBlock * Side.Sides + Side.Top];
|
||||
int i = texId / elementsPerAtlas1D;
|
||||
float vOrigin = (texId % elementsPerAtlas1D) * invVerElementSize;
|
||||
int i = texId / tilesPerAtlas1D;
|
||||
float vOrigin = (texId % tilesPerAtlas1D) * invVerTileSize;
|
||||
int offset = (lightFlags >> Side.Top) & 1;
|
||||
|
||||
float u1 = minBB.X, u2 = (count - 1) + maxBB.X * 15.99f/16f;
|
||||
float v1 = vOrigin + minBB.Z * invVerElementSize;
|
||||
float v2 = vOrigin + maxBB.Z * invVerElementSize * 15.99f/16f;
|
||||
float v1 = vOrigin + minBB.Z * invVerTileSize;
|
||||
float v2 = vOrigin + maxBB.Z * invVerTileSize * 15.99f/16f;
|
||||
DrawInfo part = isTranslucent ? translucentParts[i] : normalParts[i];
|
||||
|
||||
int F = bitFlags[cIndex];
|
||||
|
|
|
@ -8,8 +8,8 @@ namespace ClassicalSharp {
|
|||
/// <summary> Draws the vertices for a cuboid region. </summary>
|
||||
public sealed class CuboidDrawer {
|
||||
|
||||
public int elementsPerAtlas1D;
|
||||
public float invVerElementSize;
|
||||
public int tilesPerAtlas1D;
|
||||
public float invVerTileSize;
|
||||
|
||||
/// <summary> Whether a colour tinting effect should be applied to all faces. </summary>
|
||||
public bool Tinted;
|
||||
|
@ -23,10 +23,10 @@ namespace ClassicalSharp {
|
|||
|
||||
/// <summary> Draws the left face of the given cuboid region. </summary>
|
||||
public void Left(int count, int col, int texLoc, VertexP3fT2fC4b[] vertices, ref int index) {
|
||||
float vOrigin = (texLoc % elementsPerAtlas1D) * invVerElementSize;
|
||||
float vOrigin = (texLoc % tilesPerAtlas1D) * invVerTileSize;
|
||||
float u1 = minBB.Z, u2 = (count - 1) + maxBB.Z * 15.99f/16f;
|
||||
float v1 = vOrigin + maxBB.Y * invVerElementSize;
|
||||
float v2 = vOrigin + minBB.Y * invVerElementSize * 15.99f/16f;
|
||||
float v1 = vOrigin + maxBB.Y * invVerTileSize;
|
||||
float v2 = vOrigin + minBB.Y * invVerTileSize * 15.99f/16f;
|
||||
if (Tinted) col = TintBlock(col);
|
||||
|
||||
VertexP3fT2fC4b v; v.X = x1; v.Colour = col;
|
||||
|
@ -38,10 +38,10 @@ namespace ClassicalSharp {
|
|||
|
||||
/// <summary> Draws the right face of the given cuboid region. </summary>
|
||||
public void Right(int count, int col, int texLoc, VertexP3fT2fC4b[] vertices, ref int index) {
|
||||
float vOrigin = (texLoc % elementsPerAtlas1D) * invVerElementSize;
|
||||
float vOrigin = (texLoc % tilesPerAtlas1D) * invVerTileSize;
|
||||
float u1 = (count - minBB.Z), u2 = (1 - maxBB.Z) * 15.99f/16f;
|
||||
float v1 = vOrigin + maxBB.Y * invVerElementSize;
|
||||
float v2 = vOrigin + minBB.Y * invVerElementSize * 15.99f/16f;
|
||||
float v1 = vOrigin + maxBB.Y * invVerTileSize;
|
||||
float v2 = vOrigin + minBB.Y * invVerTileSize * 15.99f/16f;
|
||||
if (Tinted) col = TintBlock(col);
|
||||
|
||||
VertexP3fT2fC4b v; v.X = x2; v.Colour = col;
|
||||
|
@ -53,10 +53,10 @@ namespace ClassicalSharp {
|
|||
|
||||
/// <summary> Draws the front face of the given cuboid region. </summary>
|
||||
public void Front(int count, int col, int texLoc, VertexP3fT2fC4b[] vertices, ref int index) {
|
||||
float vOrigin = (texLoc % elementsPerAtlas1D) * invVerElementSize;
|
||||
float vOrigin = (texLoc % tilesPerAtlas1D) * invVerTileSize;
|
||||
float u1 = (count - minBB.X), u2 = (1 - maxBB.X) * 15.99f/16f;
|
||||
float v1 = vOrigin + maxBB.Y * invVerElementSize;
|
||||
float v2 = vOrigin + minBB.Y * invVerElementSize * 15.99f/16f;
|
||||
float v1 = vOrigin + maxBB.Y * invVerTileSize;
|
||||
float v2 = vOrigin + minBB.Y * invVerTileSize * 15.99f/16f;
|
||||
if (Tinted) col = TintBlock(col);
|
||||
|
||||
VertexP3fT2fC4b v; v.Z = z1; v.Colour = col;
|
||||
|
@ -68,10 +68,10 @@ namespace ClassicalSharp {
|
|||
|
||||
/// <summary> Draws the back face of the given cuboid region. </summary>
|
||||
public void Back(int count, int col, int texLoc, VertexP3fT2fC4b[] vertices, ref int index) {
|
||||
float vOrigin = (texLoc % elementsPerAtlas1D) * invVerElementSize;
|
||||
float vOrigin = (texLoc % tilesPerAtlas1D) * invVerTileSize;
|
||||
float u1 = minBB.X, u2 = (count - 1) + maxBB.X * 15.99f/16f;
|
||||
float v1 = vOrigin + maxBB.Y * invVerElementSize;
|
||||
float v2 = vOrigin + minBB.Y * invVerElementSize * 15.99f/16f;
|
||||
float v1 = vOrigin + maxBB.Y * invVerTileSize;
|
||||
float v2 = vOrigin + minBB.Y * invVerTileSize * 15.99f/16f;
|
||||
if (Tinted) col = TintBlock(col);
|
||||
|
||||
VertexP3fT2fC4b v; v.Z = z2; v.Colour = col;
|
||||
|
@ -83,10 +83,10 @@ namespace ClassicalSharp {
|
|||
|
||||
/// <summary> Draws the bottom face of the given cuboid region. </summary>
|
||||
public void Bottom(int count, int col, int texLoc, VertexP3fT2fC4b[] vertices, ref int index) {
|
||||
float vOrigin = (texLoc % elementsPerAtlas1D) * invVerElementSize;
|
||||
float vOrigin = (texLoc % tilesPerAtlas1D) * invVerTileSize;
|
||||
float u1 = minBB.X, u2 = (count - 1) + maxBB.X * 15.99f/16f;
|
||||
float v1 = vOrigin + minBB.Z * invVerElementSize;
|
||||
float v2 = vOrigin + maxBB.Z * invVerElementSize * 15.99f/16f;
|
||||
float v1 = vOrigin + minBB.Z * invVerTileSize;
|
||||
float v2 = vOrigin + maxBB.Z * invVerTileSize * 15.99f/16f;
|
||||
if (Tinted) col = TintBlock(col);
|
||||
|
||||
VertexP3fT2fC4b v; v.Y = y1; v.Colour = col;
|
||||
|
@ -98,10 +98,10 @@ namespace ClassicalSharp {
|
|||
|
||||
/// <summary> Draws the top face of the given cuboid region. </summary>
|
||||
public void Top(int count, int col, int texLoc, VertexP3fT2fC4b[] vertices, ref int index) {
|
||||
float vOrigin = (texLoc % elementsPerAtlas1D) * invVerElementSize;
|
||||
float vOrigin = (texLoc % tilesPerAtlas1D) * invVerTileSize;
|
||||
float u1 = minBB.X, u2 = (count - 1) + maxBB.X * 15.99f/16f;
|
||||
float v1 = vOrigin + minBB.Z * invVerElementSize;
|
||||
float v2 = vOrigin + maxBB.Z * invVerElementSize * 15.99f/16f;
|
||||
float v1 = vOrigin + minBB.Z * invVerTileSize;
|
||||
float v2 = vOrigin + maxBB.Z * invVerTileSize * 15.99f/16f;
|
||||
if (Tinted) col = TintBlock(col);
|
||||
|
||||
VertexP3fT2fC4b v; v.Y = y2; v.Colour = col;
|
||||
|
|
|
@ -91,8 +91,8 @@ namespace ClassicalSharp {
|
|||
|
||||
protected override void PreStretchTiles(int x1, int y1, int z1) {
|
||||
base.PreStretchTiles(x1, y1, z1);
|
||||
drawer.invVerElementSize = invVerElementSize;
|
||||
drawer.elementsPerAtlas1D = elementsPerAtlas1D;
|
||||
drawer.invVerTileSize = invVerTileSize;
|
||||
drawer.tilesPerAtlas1D = tilesPerAtlas1D;
|
||||
}
|
||||
|
||||
protected override void RenderTile(int index) {
|
||||
|
@ -126,7 +126,7 @@ namespace ClassicalSharp {
|
|||
|
||||
if (leftCount != 0) {
|
||||
int texLoc = BlockInfo.textures[curBlock * Side.Sides + Side.Left];
|
||||
int i = texLoc / elementsPerAtlas1D;
|
||||
int i = texLoc / tilesPerAtlas1D;
|
||||
int offset = (lightFlags >> Side.Left) & 1;
|
||||
|
||||
DrawInfo part = isTranslucent ? translucentParts[i] : normalParts[i];
|
||||
|
@ -137,7 +137,7 @@ namespace ClassicalSharp {
|
|||
|
||||
if (rightCount != 0) {
|
||||
int texLoc = BlockInfo.textures[curBlock * Side.Sides + Side.Right];
|
||||
int i = texLoc / elementsPerAtlas1D;
|
||||
int i = texLoc / tilesPerAtlas1D;
|
||||
int offset = (lightFlags >> Side.Right) & 1;
|
||||
|
||||
DrawInfo part = isTranslucent ? translucentParts[i] : normalParts[i];
|
||||
|
@ -148,7 +148,7 @@ namespace ClassicalSharp {
|
|||
|
||||
if (frontCount != 0) {
|
||||
int texLoc = BlockInfo.textures[curBlock * Side.Sides + Side.Front];
|
||||
int i = texLoc / elementsPerAtlas1D;
|
||||
int i = texLoc / tilesPerAtlas1D;
|
||||
int offset = (lightFlags >> Side.Front) & 1;
|
||||
|
||||
DrawInfo part = isTranslucent ? translucentParts[i] : normalParts[i];
|
||||
|
@ -159,7 +159,7 @@ namespace ClassicalSharp {
|
|||
|
||||
if (backCount != 0) {
|
||||
int texLoc = BlockInfo.textures[curBlock * Side.Sides + Side.Back];
|
||||
int i = texLoc / elementsPerAtlas1D;
|
||||
int i = texLoc / tilesPerAtlas1D;
|
||||
int offset = (lightFlags >> Side.Back) & 1;
|
||||
|
||||
DrawInfo part = isTranslucent ? translucentParts[i] : normalParts[i];
|
||||
|
@ -170,7 +170,7 @@ namespace ClassicalSharp {
|
|||
|
||||
if (bottomCount != 0) {
|
||||
int texLoc = BlockInfo.textures[curBlock * Side.Sides + Side.Bottom];
|
||||
int i = texLoc / elementsPerAtlas1D;
|
||||
int i = texLoc / tilesPerAtlas1D;
|
||||
int offset = (lightFlags >> Side.Bottom) & 1;
|
||||
|
||||
DrawInfo part = isTranslucent ? translucentParts[i] : normalParts[i];
|
||||
|
@ -180,7 +180,7 @@ namespace ClassicalSharp {
|
|||
|
||||
if (topCount != 0) {
|
||||
int texLoc = BlockInfo.textures[curBlock * Side.Sides + Side.Top];
|
||||
int i = texLoc / elementsPerAtlas1D;
|
||||
int i = texLoc / tilesPerAtlas1D;
|
||||
int offset = (lightFlags >> Side.Top) & 1;
|
||||
|
||||
DrawInfo part = isTranslucent ? translucentParts[i] : normalParts[i];
|
||||
|
|
|
@ -13,8 +13,8 @@ namespace ClassicalSharp {
|
|||
protected DrawInfo[] normalParts, translucentParts;
|
||||
protected int arraysCount = 0;
|
||||
protected bool fullBright, tinted;
|
||||
protected float invVerElementSize;
|
||||
protected int elementsPerAtlas1D;
|
||||
protected float invVerTileSize;
|
||||
protected int tilesPerAtlas1D;
|
||||
|
||||
void TerrainAtlasChanged(object sender, EventArgs e) {
|
||||
int newArraysCount = TerrainAtlas1D.TexIds.Length;
|
||||
|
@ -73,8 +73,8 @@ namespace ClassicalSharp {
|
|||
protected abstract void RenderTile(int index);
|
||||
|
||||
protected virtual void PreStretchTiles(int x1, int y1, int z1) {
|
||||
invVerElementSize = TerrainAtlas1D.invElementSize;
|
||||
elementsPerAtlas1D = TerrainAtlas1D.elementsPerAtlas1D;
|
||||
invVerTileSize = TerrainAtlas1D.invTileSize;
|
||||
tilesPerAtlas1D = TerrainAtlas1D.TilesPerAtlas;
|
||||
arraysCount = TerrainAtlas1D.TexIds.Length;
|
||||
|
||||
if (normalParts == null) {
|
||||
|
@ -114,13 +114,13 @@ namespace ClassicalSharp {
|
|||
static JavaRandom spriteRng = new JavaRandom(0);
|
||||
protected virtual void DrawSprite(int count) {
|
||||
int texId = BlockInfo.textures[curBlock * Side.Sides + Side.Right];
|
||||
int i = texId / elementsPerAtlas1D;
|
||||
float vOrigin = (texId % elementsPerAtlas1D) * invVerElementSize;
|
||||
int i = texId / tilesPerAtlas1D;
|
||||
float vOrigin = (texId % tilesPerAtlas1D) * invVerTileSize;
|
||||
|
||||
float x1 = X + 2.50f/16, y1 = Y, z1 = Z + 2.50f/16;
|
||||
float x2 = X + 13.5f/16, y2 = Y + 1, z2 = Z + 13.5f/16;
|
||||
const float u1 = 0, u2 = 15.99f/16f;
|
||||
float v1 = vOrigin, v2 = vOrigin + invVerElementSize * 15.99f/16f;
|
||||
float v1 = vOrigin, v2 = vOrigin + invVerTileSize * 15.99f/16f;
|
||||
|
||||
byte offsetType = BlockInfo.SpriteOffset[curBlock];
|
||||
if (offsetType >= 6 && offsetType <= 7) {
|
||||
|
|
|
@ -170,7 +170,7 @@ namespace ClassicalSharp.Particles {
|
|||
Vector3 worldPos = new Vector3(position.X, position.Y, position.Z);
|
||||
int texLoc = BlockInfo.GetTextureLoc(block, Side.Left), texIndex = 0;
|
||||
TextureRec baseRec = TerrainAtlas1D.GetTexRec(texLoc, 1, out texIndex);
|
||||
float uScale = (1/16f), vScale = (1/16f) * TerrainAtlas1D.invElementSize;
|
||||
float uScale = (1/16f), vScale = (1/16f) * TerrainAtlas1D.invTileSize;
|
||||
|
||||
Vector3 minBB = BlockInfo.MinBB[block];
|
||||
Vector3 maxBB = BlockInfo.MaxBB[block];
|
||||
|
|
|
@ -119,12 +119,12 @@ namespace ClassicalSharp.Renderers {
|
|||
renderer.normalPartsCount = new int[TerrainAtlas1D.TexIds.Length];
|
||||
renderer.translucentPartsCount = new int[TerrainAtlas1D.TexIds.Length];
|
||||
} else {
|
||||
bool refreshRequired = elementsPerBitmap != TerrainAtlas1D.elementsPerBitmap;
|
||||
bool refreshRequired = elementsPerBitmap != TerrainAtlas1D.TilesPerAtlas;
|
||||
if (refreshRequired) Refresh();
|
||||
}
|
||||
|
||||
renderer._1DUsed = TerrainAtlas1D.UsedAtlasesCount();
|
||||
elementsPerBitmap = TerrainAtlas1D.elementsPerBitmap;
|
||||
elementsPerBitmap = TerrainAtlas1D.TilesPerAtlas;
|
||||
ResetUsedFlags();
|
||||
}
|
||||
|
||||
|
|
|
@ -55,11 +55,11 @@ namespace ClassicalSharp.Textures {
|
|||
/// <summary> Runs through all animations and if necessary updates the terrain atlas. </summary>
|
||||
public void Tick(ScheduledTask task) {
|
||||
if (useLavaAnim) {
|
||||
int size = Math.Min(TerrainAtlas2D.ElemSize, 64);
|
||||
int size = Math.Min(TerrainAtlas2D.TileSize, 64);
|
||||
DrawAnimation(null, 30, size);
|
||||
}
|
||||
if (useWaterAnim) {
|
||||
int size = Math.Min(TerrainAtlas2D.ElemSize, 64);
|
||||
int size = Math.Min(TerrainAtlas2D.TileSize, 64);
|
||||
DrawAnimation(null, 14, size);
|
||||
}
|
||||
|
||||
|
@ -169,7 +169,7 @@ namespace ClassicalSharp.Textures {
|
|||
data.FrameY, 0, 0, animsBuffer, animPart, size);
|
||||
}
|
||||
|
||||
int y = rowNum * TerrainAtlas2D.ElemSize;
|
||||
int y = rowNum * TerrainAtlas2D.TileSize;
|
||||
game.Graphics.UpdateTexturePart(TerrainAtlas1D.TexIds[index], 0, y, animPart, game.Graphics.Mipmaps);
|
||||
}
|
||||
|
||||
|
@ -209,7 +209,7 @@ namespace ClassicalSharp.Textures {
|
|||
const string terrainFormat = "&cAnimation frames for tile ({0}, {1}) are bigger than the size of a tile in terrain.png";
|
||||
void ValidateAnimations() {
|
||||
validated = true;
|
||||
int elemSize = TerrainAtlas2D.ElemSize;
|
||||
int elemSize = TerrainAtlas2D.TileSize;
|
||||
for (int i = animations.Count - 1; i >= 0; i--) {
|
||||
AnimationData a = animations[i];
|
||||
if (a.FrameSize > elemSize) {
|
||||
|
|
|
@ -10,45 +10,42 @@ namespace ClassicalSharp.Textures {
|
|||
|
||||
/// <summary> Represents a 2D packed texture atlas that has been converted into an array of 1D atlases. </summary>
|
||||
public static class TerrainAtlas1D {
|
||||
|
||||
public static int elementsPerAtlas1D;
|
||||
public static int elementsPerBitmap;
|
||||
public static float invElementSize;
|
||||
public static int TilesPerAtlas;
|
||||
public static float invTileSize;
|
||||
public static int[] TexIds;
|
||||
internal static Game game;
|
||||
|
||||
public static TextureRec GetTexRec(int texLoc, int uCount, out int index) {
|
||||
index = texLoc / elementsPerAtlas1D;
|
||||
int y = texLoc % elementsPerAtlas1D;
|
||||
index = texLoc / TilesPerAtlas;
|
||||
int y = texLoc % TilesPerAtlas;
|
||||
// Adjust coords to be slightly inside - fixes issues with AMD/ATI cards.
|
||||
return new TextureRec(0, y * invElementSize, (uCount - 1) + 15.99f/16f, (15.99f/16f) * invElementSize);
|
||||
return new TextureRec(0, y * invTileSize, (uCount - 1) + 15.99f/16f, (15.99f/16f) * invTileSize);
|
||||
}
|
||||
|
||||
/// <summary> Returns the index of the 1D texture within the array of 1D textures
|
||||
/// containing the given texture id. </summary>
|
||||
public static int Get1DIndex(int texLoc) { return texLoc / elementsPerAtlas1D; }
|
||||
public static int Get1DIndex(int texLoc) { return texLoc / TilesPerAtlas; }
|
||||
|
||||
/// <summary> Returns the index of the given texture id within a 1D texture. </summary>
|
||||
public static int Get1DRowId(int texLoc) { return texLoc % elementsPerAtlas1D; }
|
||||
public static int Get1DRowId(int texLoc) { return texLoc % TilesPerAtlas; }
|
||||
|
||||
public static void UpdateState() {
|
||||
int elemSize = TerrainAtlas2D.ElemSize;
|
||||
int maxVerticalSize = Math.Min(4096, game.Graphics.MaxTextureDimensions);
|
||||
int elementsPerFullAtlas = maxVerticalSize / elemSize;
|
||||
const int totalElements = TerrainAtlas2D.RowsCount * TerrainAtlas2D.TilesPerRow;
|
||||
int tileSize = TerrainAtlas2D.TileSize;
|
||||
int maxAtlasHeight = Math.Min(4096, game.Graphics.MaxTextureDimensions);
|
||||
int maxTilesPerAtlas = maxAtlasHeight / tileSize;
|
||||
const int maxTiles = TerrainAtlas2D.RowsCount * TerrainAtlas2D.TilesPerRow;
|
||||
|
||||
int atlasesCount = Utils.CeilDiv(totalElements, elementsPerFullAtlas);
|
||||
elementsPerAtlas1D = Math.Min(elementsPerFullAtlas, totalElements);
|
||||
int atlas1DHeight = Utils.NextPowerOf2(elementsPerAtlas1D * elemSize);
|
||||
TilesPerAtlas = Math.Min(maxTilesPerAtlas, maxTiles);
|
||||
int atlasesCount = Utils.CeilDiv(maxTiles, TilesPerAtlas);
|
||||
int atlasHeight = TilesPerAtlas * tileSize;
|
||||
|
||||
Convert2DTo1D(atlasesCount, atlas1DHeight);
|
||||
elementsPerBitmap = atlas1DHeight / elemSize;
|
||||
invElementSize = 1f / elementsPerBitmap;
|
||||
invTileSize = 1f / TilesPerAtlas;
|
||||
Convert2DTo1D(atlasesCount, atlasHeight);
|
||||
}
|
||||
|
||||
static void Convert2DTo1D(int atlasesCount, int atlas1DHeight) {
|
||||
TexIds = new int[atlasesCount];
|
||||
Utils.LogDebug("Loaded new atlas: {0} bmps, {1} per bmp", atlasesCount, elementsPerAtlas1D);
|
||||
Utils.LogDebug("Loaded new atlas: {0} bmps, {1} per bmp", atlasesCount, TilesPerAtlas);
|
||||
int index = 0;
|
||||
|
||||
using (FastBitmap atlas = new FastBitmap(TerrainAtlas2D.Atlas, true, true)) {
|
||||
|
@ -58,13 +55,16 @@ namespace ClassicalSharp.Textures {
|
|||
}
|
||||
|
||||
static void Make1DTexture(int i, FastBitmap atlas, int atlas1DHeight, ref int index) {
|
||||
int elemSize = TerrainAtlas2D.ElemSize;
|
||||
using (Bitmap atlas1d = Platform.CreateBmp(elemSize, atlas1DHeight))
|
||||
int tileSize = TerrainAtlas2D.TileSize;
|
||||
using (Bitmap atlas1d = Platform.CreateBmp(tileSize, atlas1DHeight))
|
||||
using (FastBitmap dst = new FastBitmap(atlas1d, true, false))
|
||||
{
|
||||
for (int index1D = 0; index1D < elementsPerAtlas1D; index1D++) {
|
||||
FastBitmap.MovePortion((index & 0x0F) * elemSize, (index >> 4) * elemSize,
|
||||
0, index1D * elemSize, atlas, dst, elemSize);
|
||||
for (int index1D = 0; index1D < TilesPerAtlas; index1D++) {
|
||||
int atlasX = (index % TerrainAtlas2D.TilesPerRow) * tileSize;
|
||||
int atlasY = (index / TerrainAtlas2D.TilesPerRow) * tileSize;
|
||||
|
||||
FastBitmap.MovePortion(atlasX, atlasY,
|
||||
0, index1D * tileSize, atlas, dst, tileSize);
|
||||
index++;
|
||||
}
|
||||
TexIds[i] = game.Graphics.CreateTexture(dst, true, game.Graphics.Mipmaps);
|
||||
|
|
|
@ -13,19 +13,19 @@ namespace ClassicalSharp {
|
|||
|
||||
public const int TilesPerRow = 16, RowsCount = 16;
|
||||
public static Bitmap Atlas;
|
||||
public static int ElemSize;
|
||||
public static int TileSize;
|
||||
internal static Game game;
|
||||
|
||||
/// <summary> Updates the underlying atlas bitmap, fields, and texture. </summary>
|
||||
public static void UpdateState(Bitmap bmp) {
|
||||
Atlas = bmp;
|
||||
ElemSize = bmp.Width / TilesPerRow;
|
||||
TileSize = bmp.Width / TilesPerRow;
|
||||
BlockInfo.RecalculateSpriteBB();
|
||||
}
|
||||
|
||||
/// <summary> Creates a new texture that contains the tile at the specified index. </summary>
|
||||
public static int LoadTextureElement(int index) {
|
||||
int size = ElemSize;
|
||||
int size = TileSize;
|
||||
using (FastBitmap atlas = new FastBitmap(Atlas, true, true))
|
||||
using (Bitmap bmp = Platform.CreateBmp(size, size))
|
||||
using (FastBitmap dst = new FastBitmap(bmp, true, false))
|
||||
|
|
|
@ -214,7 +214,7 @@ void Animations_Draw(AnimationData* data, Int32 texId, Int32 size) {
|
|||
Bitmap_CopyBlock(x, data->FrameY, 0, 0, &anims_bmp, &animPart, size);
|
||||
}
|
||||
|
||||
Int32 y = rowNum * Atlas2D_ElementSize;
|
||||
Int32 y = rowNum * Atlas2D_TileSize;
|
||||
Gfx_UpdateTexturePart(Atlas1D_TexIds[index], 0, y, &animPart, Gfx_Mipmaps);
|
||||
if (size > ANIMS_FAST_SIZE) Platform_MemFree(&ptr);
|
||||
}
|
||||
|
@ -259,7 +259,7 @@ void Animations_Validate(void) {
|
|||
Int32 maxX = data.FrameX + data.FrameSize * data.StatesCount;
|
||||
String_Clear(&msg);
|
||||
|
||||
if (data.FrameSize > Atlas2D_ElementSize) {
|
||||
if (data.FrameSize > Atlas2D_TileSize) {
|
||||
String_Format2(&msg, "&cAnimation frames for tile (%b, %b) are bigger than the size of a tile in terrain.png", &data.TileX, &data.TileY);
|
||||
} else if (maxX > anims_bmp.Width || maxY > anims_bmp.Height) {
|
||||
String_Format2(&msg, "&cSome of the animation frames for tile (%b, %b) are at coordinates outside animations.png", &data.TileX, &data.TileY);
|
||||
|
@ -279,11 +279,11 @@ void Animations_Validate(void) {
|
|||
|
||||
void Animations_Tick(ScheduledTask* task) {
|
||||
if (anims_useLavaAnim) {
|
||||
Int32 size = min(Atlas2D_ElementSize, 64);
|
||||
Int32 size = min(Atlas2D_TileSize, 64);
|
||||
Animations_Draw(NULL, 30, size);
|
||||
}
|
||||
if (anims_useWaterAnim) {
|
||||
Int32 size = min(Atlas2D_ElementSize, 64);
|
||||
Int32 size = min(Atlas2D_TileSize, 64);
|
||||
Animations_Draw(NULL, 14, size);
|
||||
}
|
||||
if (anims_count == 0) return;
|
||||
|
|
|
@ -317,7 +317,7 @@ Real32 Block_GetSpriteBB_RightX(Int32 size, Int32 tileX, Int32 tileY, Bitmap* bm
|
|||
|
||||
void Block_RecalculateBB(BlockID block) {
|
||||
Bitmap* bmp = &Atlas2D_Bitmap;
|
||||
Int32 elemSize = Atlas2D_ElementSize;
|
||||
Int32 elemSize = Atlas2D_TileSize;
|
||||
TextureLoc texLoc = Block_GetTexLoc(block, FACE_XMAX);
|
||||
Int32 texX = texLoc & 0x0F, texY = texLoc >> 4;
|
||||
|
||||
|
|
|
@ -380,14 +380,14 @@ Random spriteRng;
|
|||
void Builder_DrawSprite(Int32 count) {
|
||||
TextureLoc texLoc = Block_GetTexLoc(Builder_Block, FACE_XMAX);
|
||||
Int32 i = Atlas1D_Index(texLoc);
|
||||
Real32 vOrigin = Atlas1D_RowId(texLoc) * Atlas1D_InvElementSize;
|
||||
Real32 vOrigin = Atlas1D_RowId(texLoc) * Atlas1D_InvTileSize;
|
||||
Real32 X = (Real32)Builder_X, Y = (Real32)Builder_Y, Z = (Real32)Builder_Z;
|
||||
|
||||
#define u1 0.0f
|
||||
#define u2 UV2_Scale
|
||||
Real32 x1 = (Real32)X + 2.50f / 16.0f, y1 = (Real32)Y, z1 = (Real32)Z + 2.50f / 16.0f;
|
||||
Real32 x2 = (Real32)X + 13.5f / 16.0f, y2 = (Real32)Y + 1.0f, z2 = (Real32)Z + 13.5f / 16.0f;
|
||||
Real32 v1 = vOrigin, v2 = vOrigin + Atlas1D_InvElementSize * UV2_Scale;
|
||||
Real32 v1 = vOrigin, v2 = vOrigin + Atlas1D_InvTileSize * UV2_Scale;
|
||||
|
||||
UInt8 offsetType = Block_SpriteOffset[Builder_Block];
|
||||
if (offsetType >= 6 && offsetType <= 7) {
|
||||
|
|
|
@ -49,12 +49,12 @@ void ChunkUpdater_EnvVariableChanged(void* obj, Int32 envVar) {
|
|||
|
||||
void ChunkUpdater_TerrainAtlasChanged(void* obj) {
|
||||
if (MapRenderer_1DUsedCount) {
|
||||
bool refreshRequired = cu_elementsPerBitmap != Atlas1D_ElementsPerBitmap;
|
||||
bool refreshRequired = cu_elementsPerBitmap != Atlas1D_TilesPerAtlas;
|
||||
if (refreshRequired) ChunkUpdater_Refresh();
|
||||
}
|
||||
|
||||
MapRenderer_1DUsedCount = Atlas1D_UsedAtlasesCount();
|
||||
cu_elementsPerBitmap = Atlas1D_ElementsPerBitmap;
|
||||
cu_elementsPerBitmap = Atlas1D_TilesPerAtlas;
|
||||
ChunkUpdater_ResetPartFlags();
|
||||
}
|
||||
|
||||
|
|
|
@ -12,11 +12,11 @@ col.B = (UInt8)(col.B * Drawer_TintColour.B / 255);\
|
|||
|
||||
|
||||
void Drawer_XMin(Int32 count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b** vertices) {
|
||||
Real32 vOrigin = Atlas1D_RowId(texLoc) * Atlas1D_InvElementSize;
|
||||
Real32 vOrigin = Atlas1D_RowId(texLoc) * Atlas1D_InvTileSize;
|
||||
Real32 u1 = Drawer_MinBB.Z;
|
||||
Real32 u2 = (count - 1) + Drawer_MaxBB.Z * UV2_Scale;
|
||||
Real32 v1 = vOrigin + Drawer_MaxBB.Y * Atlas1D_InvElementSize;
|
||||
Real32 v2 = vOrigin + Drawer_MinBB.Y * Atlas1D_InvElementSize * UV2_Scale;
|
||||
Real32 v1 = vOrigin + Drawer_MaxBB.Y * Atlas1D_InvTileSize;
|
||||
Real32 v2 = vOrigin + Drawer_MinBB.Y * Atlas1D_InvTileSize * UV2_Scale;
|
||||
ApplyTint;
|
||||
|
||||
VertexP3fT2fC4b* ptr = *vertices;
|
||||
|
@ -29,11 +29,11 @@ void Drawer_XMin(Int32 count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b*
|
|||
}
|
||||
|
||||
void Drawer_XMax(Int32 count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b** vertices) {
|
||||
Real32 vOrigin = Atlas1D_RowId(texLoc) * Atlas1D_InvElementSize;
|
||||
Real32 vOrigin = Atlas1D_RowId(texLoc) * Atlas1D_InvTileSize;
|
||||
Real32 u1 = (count - Drawer_MinBB.Z);
|
||||
Real32 u2 = (1 - Drawer_MaxBB.Z) * UV2_Scale;
|
||||
Real32 v1 = vOrigin + Drawer_MaxBB.Y * Atlas1D_InvElementSize;
|
||||
Real32 v2 = vOrigin + Drawer_MinBB.Y * Atlas1D_InvElementSize * UV2_Scale;
|
||||
Real32 v1 = vOrigin + Drawer_MaxBB.Y * Atlas1D_InvTileSize;
|
||||
Real32 v2 = vOrigin + Drawer_MinBB.Y * Atlas1D_InvTileSize * UV2_Scale;
|
||||
ApplyTint;
|
||||
|
||||
VertexP3fT2fC4b* ptr = *vertices;
|
||||
|
@ -46,11 +46,11 @@ void Drawer_XMax(Int32 count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b*
|
|||
}
|
||||
|
||||
void Drawer_ZMin(Int32 count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b** vertices) {
|
||||
Real32 vOrigin = Atlas1D_RowId(texLoc) * Atlas1D_InvElementSize;
|
||||
Real32 vOrigin = Atlas1D_RowId(texLoc) * Atlas1D_InvTileSize;
|
||||
Real32 u1 = (count - Drawer_MinBB.X);
|
||||
Real32 u2 = (1 - Drawer_MaxBB.X) * UV2_Scale;
|
||||
Real32 v1 = vOrigin + Drawer_MaxBB.Y * Atlas1D_InvElementSize;
|
||||
Real32 v2 = vOrigin + Drawer_MinBB.Y * Atlas1D_InvElementSize * UV2_Scale;
|
||||
Real32 v1 = vOrigin + Drawer_MaxBB.Y * Atlas1D_InvTileSize;
|
||||
Real32 v2 = vOrigin + Drawer_MinBB.Y * Atlas1D_InvTileSize * UV2_Scale;
|
||||
ApplyTint;
|
||||
|
||||
VertexP3fT2fC4b* ptr = *vertices;
|
||||
|
@ -63,11 +63,11 @@ void Drawer_ZMin(Int32 count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b*
|
|||
}
|
||||
|
||||
void Drawer_ZMax(Int32 count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b** vertices) {
|
||||
Real32 vOrigin = Atlas1D_RowId(texLoc) * Atlas1D_InvElementSize;
|
||||
Real32 vOrigin = Atlas1D_RowId(texLoc) * Atlas1D_InvTileSize;
|
||||
Real32 u1 = Drawer_MinBB.X;
|
||||
Real32 u2 = (count - 1) + Drawer_MaxBB.X * UV2_Scale;
|
||||
Real32 v1 = vOrigin + Drawer_MaxBB.Y * Atlas1D_InvElementSize;
|
||||
Real32 v2 = vOrigin + Drawer_MinBB.Y * Atlas1D_InvElementSize * UV2_Scale;
|
||||
Real32 v1 = vOrigin + Drawer_MaxBB.Y * Atlas1D_InvTileSize;
|
||||
Real32 v2 = vOrigin + Drawer_MinBB.Y * Atlas1D_InvTileSize * UV2_Scale;
|
||||
ApplyTint;
|
||||
|
||||
VertexP3fT2fC4b* ptr = *vertices;
|
||||
|
@ -80,11 +80,11 @@ void Drawer_ZMax(Int32 count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b*
|
|||
}
|
||||
|
||||
void Drawer_YMin(Int32 count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b** vertices) {
|
||||
Real32 vOrigin = Atlas1D_RowId(texLoc) * Atlas1D_InvElementSize;
|
||||
Real32 vOrigin = Atlas1D_RowId(texLoc) * Atlas1D_InvTileSize;
|
||||
Real32 u1 = Drawer_MinBB.X;
|
||||
Real32 u2 = (count - 1) + Drawer_MaxBB.X * UV2_Scale;
|
||||
Real32 v1 = vOrigin + Drawer_MinBB.Z * Atlas1D_InvElementSize;
|
||||
Real32 v2 = vOrigin + Drawer_MaxBB.Z * Atlas1D_InvElementSize * UV2_Scale;
|
||||
Real32 v1 = vOrigin + Drawer_MinBB.Z * Atlas1D_InvTileSize;
|
||||
Real32 v2 = vOrigin + Drawer_MaxBB.Z * Atlas1D_InvTileSize * UV2_Scale;
|
||||
ApplyTint;
|
||||
|
||||
VertexP3fT2fC4b* ptr = *vertices;
|
||||
|
@ -97,11 +97,11 @@ void Drawer_YMin(Int32 count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b*
|
|||
}
|
||||
|
||||
void Drawer_YMax(Int32 count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b** vertices) {
|
||||
Real32 vOrigin = Atlas1D_RowId(texLoc) * Atlas1D_InvElementSize;
|
||||
Real32 vOrigin = Atlas1D_RowId(texLoc) * Atlas1D_InvTileSize;
|
||||
Real32 u1 = Drawer_MinBB.X;
|
||||
Real32 u2 = (count - 1) + Drawer_MaxBB.X * UV2_Scale;
|
||||
Real32 v1 = vOrigin + Drawer_MinBB.Z * Atlas1D_InvElementSize;
|
||||
Real32 v2 = vOrigin + Drawer_MaxBB.Z * Atlas1D_InvElementSize * UV2_Scale;
|
||||
Real32 v1 = vOrigin + Drawer_MinBB.Z * Atlas1D_InvTileSize;
|
||||
Real32 v2 = vOrigin + Drawer_MaxBB.Z * Atlas1D_InvTileSize * UV2_Scale;
|
||||
ApplyTint;
|
||||
|
||||
VertexP3fT2fC4b* ptr = *vertices;
|
||||
|
|
|
@ -2988,7 +2988,7 @@ void Overlay_MakeLabels(MenuScreen* screen, TextWidget* labels, STRING_PURE Stri
|
|||
/*########################################################################################################################*
|
||||
*------------------------------------------------------TexIdsOverlay------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
#define TEXID_OVERLAY_VERTICES_COUNT (ATLAS2D_ELEMENTS_PER_ROW * ATLAS2D_ROWS_COUNT * 4)
|
||||
#define TEXID_OVERLAY_VERTICES_COUNT (ATLAS2D_TILES_PER_ROW * ATLAS2D_ROWS_COUNT * 4)
|
||||
GuiElementVTABLE TexIdsOverlay_VTABLE;
|
||||
TexIdsOverlay TexIdsOverlay_Instance;
|
||||
void TexIdsOverlay_ContextLost(void* obj) {
|
||||
|
@ -3010,7 +3010,7 @@ void TexIdsOverlay_ContextRecreated(void* obj) {
|
|||
size = (size / 8) * 8;
|
||||
Math_Clamp(size, 8, 40);
|
||||
|
||||
screen->XOffset = Gui_CalcPos(ANCHOR_CENTRE, 0, size * ATLAS2D_ELEMENTS_PER_ROW, Game_Width);
|
||||
screen->XOffset = Gui_CalcPos(ANCHOR_CENTRE, 0, size * ATLAS2D_TILES_PER_ROW, Game_Width);
|
||||
screen->YOffset = Gui_CalcPos(ANCHOR_CENTRE, 0, size * ATLAS2D_ROWS_COUNT, Game_Height);
|
||||
screen->TileSize = size;
|
||||
|
||||
|
@ -3022,15 +3022,15 @@ void TexIdsOverlay_ContextRecreated(void* obj) {
|
|||
|
||||
void TexIdsOverlay_RenderTerrain(TexIdsOverlay* screen) {
|
||||
VertexP3fT2fC4b vertices[TEXID_OVERLAY_VERTICES_COUNT];
|
||||
Int32 elemsPerAtlas = Atlas1D_ElementsPerAtlas, i;
|
||||
for (i = 0; i < ATLAS2D_ELEMENTS_PER_ROW * ATLAS2D_ROWS_COUNT;) {
|
||||
Int32 elemsPerAtlas = Atlas1D_TilesPerAtlas, i;
|
||||
for (i = 0; i < ATLAS2D_TILES_PER_ROW * ATLAS2D_ROWS_COUNT;) {
|
||||
VertexP3fT2fC4b* ptr = vertices;
|
||||
Int32 j, ignored, size = screen->TileSize;
|
||||
|
||||
for (j = 0; j < elemsPerAtlas; j++) {
|
||||
TextureRec rec = Atlas1D_TexRec(i + j, 1, &ignored);
|
||||
Int32 x = (i + j) % ATLAS2D_ELEMENTS_PER_ROW;
|
||||
Int32 y = (i + j) / ATLAS2D_ELEMENTS_PER_ROW;
|
||||
Int32 x = (i + j) % ATLAS2D_TILES_PER_ROW;
|
||||
Int32 y = (i + j) / ATLAS2D_TILES_PER_ROW;
|
||||
|
||||
Texture tex = Texture_FromRec(NULL, screen->XOffset + x * size,
|
||||
screen->YOffset + y * size, size, size, rec);
|
||||
|
@ -3053,9 +3053,9 @@ void TexIdsOverlay_RenderTextOverlay(TexIdsOverlay* screen) {
|
|||
TextAtlas* idAtlas = &screen->IdAtlas;
|
||||
idAtlas->Tex.Y = (screen->YOffset + (size - idAtlas->Tex.Height));
|
||||
for (y = 0; y < ATLAS2D_ROWS_COUNT; y++) {
|
||||
for (x = 0; x < ATLAS2D_ELEMENTS_PER_ROW; x++) {
|
||||
for (x = 0; x < ATLAS2D_TILES_PER_ROW; x++) {
|
||||
idAtlas->CurX = screen->XOffset + size * x + 3; /* offset text by 3 pixels */
|
||||
Int32 id = x + y * ATLAS2D_ELEMENTS_PER_ROW;
|
||||
Int32 id = x + y * ATLAS2D_TILES_PER_ROW;
|
||||
TextAtlas_AddInt(idAtlas, id, &ptr);
|
||||
}
|
||||
idAtlas->Tex.Y += size;
|
||||
|
|
|
@ -364,7 +364,7 @@ void Particles_BreakBlockEffect(Vector3I coords, BlockID oldBlock, BlockID block
|
|||
TextureLoc texLoc = Block_GetTexLoc(block, FACE_XMIN);
|
||||
Int32 texIndex;
|
||||
TextureRec baseRec = Atlas1D_TexRec(texLoc, 1, &texIndex);
|
||||
Real32 uScale = (1.0f / 16.0f), vScale = (1.0f / 16.0f) * Atlas1D_InvElementSize;
|
||||
Real32 uScale = (1.0f / 16.0f), vScale = (1.0f / 16.0f) * Atlas1D_InvTileSize;
|
||||
|
||||
Vector3 minBB = Block_MinBB[block];
|
||||
Vector3 maxBB = Block_MaxBB[block];
|
||||
|
|
|
@ -8,33 +8,32 @@
|
|||
|
||||
void Atlas2D_UpdateState(Bitmap* bmp) {
|
||||
Atlas2D_Bitmap = *bmp;
|
||||
Atlas2D_ElementSize = bmp->Width / ATLAS2D_ELEMENTS_PER_ROW;
|
||||
Atlas2D_TileSize = bmp->Width / ATLAS2D_TILES_PER_ROW;
|
||||
Block_RecalculateSpriteBB();
|
||||
}
|
||||
|
||||
GfxResourceID Atlas2D_LoadTextureElement_Raw(TextureLoc texLoc, Bitmap* element) {
|
||||
Int32 size = Atlas2D_ElementSize;
|
||||
Int32 x = texLoc % ATLAS2D_ELEMENTS_PER_ROW, y = texLoc / ATLAS2D_ELEMENTS_PER_ROW;
|
||||
Bitmap_CopyBlock(x * size, y * size, 0, 0,
|
||||
&Atlas2D_Bitmap, element, size);
|
||||
Int32 size = Atlas2D_TileSize;
|
||||
Int32 x = texLoc % ATLAS2D_TILES_PER_ROW, y = texLoc / ATLAS2D_TILES_PER_ROW;
|
||||
Bitmap_CopyBlock(x * size, y * size, 0, 0, &Atlas2D_Bitmap, element, size);
|
||||
|
||||
return Gfx_CreateTexture(element, false, Gfx_Mipmaps);
|
||||
}
|
||||
|
||||
GfxResourceID Atlas2D_LoadTextureElement(TextureLoc texLoc) {
|
||||
Int32 size = Atlas2D_ElementSize;
|
||||
Bitmap element;
|
||||
Int32 size = Atlas2D_TileSize;
|
||||
Bitmap tile;
|
||||
|
||||
/* Try to allocate bitmap on stack if possible */
|
||||
if (size > 64) {
|
||||
Bitmap_Allocate(&element, size, size);
|
||||
GfxResourceID texId = Atlas2D_LoadTextureElement_Raw(texLoc, &element);
|
||||
Platform_MemFree(&element.Scan0);
|
||||
Bitmap_Allocate(&tile, size, size);
|
||||
GfxResourceID texId = Atlas2D_LoadTextureElement_Raw(texLoc, &tile);
|
||||
Platform_MemFree(&tile.Scan0);
|
||||
return texId;
|
||||
} else {
|
||||
UInt8 scan0[Bitmap_DataSize(64, 64)];
|
||||
Bitmap_Create(&element, size, size, scan0);
|
||||
return Atlas2D_LoadTextureElement_Raw(texLoc, &element);
|
||||
Bitmap_Create(&tile, size, size, scan0);
|
||||
return Atlas2D_LoadTextureElement_Raw(texLoc, &tile);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,24 +49,24 @@ TextureRec Atlas1D_TexRec(TextureLoc texLoc, Int32 uCount, Int32* index) {
|
|||
/* Adjust coords to be slightly inside - fixes issues with AMD/ATI cards. */
|
||||
TextureRec rec;
|
||||
rec.U1 = 0.0f;
|
||||
rec.V1 = y * Atlas1D_InvElementSize;
|
||||
rec.V1 = y * Atlas1D_InvTileSize;
|
||||
rec.U2 = (uCount - 1) + UV2_Scale;
|
||||
rec.V2 = rec.V1 + UV2_Scale * Atlas1D_InvElementSize;
|
||||
rec.V2 = rec.V1 + UV2_Scale * Atlas1D_InvTileSize;
|
||||
return rec;
|
||||
}
|
||||
|
||||
void Atlas1D_Make1DTexture(Int32 i, Int32 atlas1DHeight, Int32* index) {
|
||||
Int32 elemSize = Atlas2D_ElementSize;
|
||||
Int32 tileSize = Atlas2D_TileSize;
|
||||
Bitmap atlas1D;
|
||||
Bitmap_Allocate(&atlas1D, elemSize, atlas1DHeight);
|
||||
Bitmap_Allocate(&atlas1D, tileSize, atlas1DHeight);
|
||||
|
||||
Int32 index1D;
|
||||
for (index1D = 0; index1D < Atlas1D_ElementsPerAtlas; index1D++) {
|
||||
Int32 atlasX = (*index & 0x0F) * elemSize;
|
||||
Int32 atlasY = (*index >> 4) * elemSize;
|
||||
for (index1D = 0; index1D < Atlas1D_TilesPerAtlas; index1D++) {
|
||||
Int32 atlasX = (*index % ATLAS2D_TILES_PER_ROW) * tileSize;
|
||||
Int32 atlasY = (*index / ATLAS2D_TILES_PER_ROW) * tileSize;
|
||||
|
||||
Bitmap_CopyBlock(atlasX, atlasY, 0, index1D * elemSize,
|
||||
&Atlas2D_Bitmap, &atlas1D, elemSize);
|
||||
Bitmap_CopyBlock(atlasX, atlasY, 0, index1D * tileSize,
|
||||
&Atlas2D_Bitmap, &atlas1D, tileSize);
|
||||
(*index)++;
|
||||
}
|
||||
|
||||
|
@ -77,7 +76,7 @@ void Atlas1D_Make1DTexture(Int32 i, Int32 atlas1DHeight, Int32* index) {
|
|||
|
||||
void Atlas1D_Convert2DTo1D(Int32 atlasesCount, Int32 atlas1DHeight) {
|
||||
Atlas1D_Count = atlasesCount;
|
||||
Platform_Log2("Loaded new atlas: %i bmps, %i per bmp", &atlasesCount, &Atlas1D_ElementsPerAtlas);
|
||||
Platform_Log2("Loaded new atlas: %i bmps, %i per bmp", &atlasesCount, &Atlas1D_TilesPerAtlas);
|
||||
|
||||
Int32 index = 0, i;
|
||||
for (i = 0; i < atlasesCount; i++) {
|
||||
|
@ -86,17 +85,16 @@ void Atlas1D_Convert2DTo1D(Int32 atlasesCount, Int32 atlas1DHeight) {
|
|||
}
|
||||
|
||||
void Atlas1D_UpdateState(void) {
|
||||
Int32 maxVerticalSize = min(4096, Gfx_MaxTextureDimensions);
|
||||
Int32 elementsPerFullAtlas = maxVerticalSize / Atlas2D_ElementSize;
|
||||
Int32 totalElements = ATLAS2D_ROWS_COUNT * ATLAS2D_ELEMENTS_PER_ROW;
|
||||
Int32 maxAtlasHeight = min(4096, Gfx_MaxTextureDimensions);
|
||||
Int32 maxTilesPerAtlas = maxAtlasHeight / Atlas2D_TileSize;
|
||||
Int32 maxTiles = ATLAS2D_ROWS_COUNT * ATLAS2D_TILES_PER_ROW;
|
||||
|
||||
Int32 atlasesCount = Math_CeilDiv(totalElements, elementsPerFullAtlas);
|
||||
Atlas1D_ElementsPerAtlas = min(elementsPerFullAtlas, totalElements);
|
||||
Int32 atlas1DHeight = Math_NextPowOf2(Atlas1D_ElementsPerAtlas * Atlas2D_ElementSize);
|
||||
Atlas1D_TilesPerAtlas = min(maxTilesPerAtlas, maxTiles);
|
||||
Int32 atlasesCount = Math_CeilDiv(maxTiles, Atlas1D_TilesPerAtlas);
|
||||
Int32 atlasHeight = Atlas1D_TilesPerAtlas * Atlas2D_TileSize;
|
||||
|
||||
Atlas1D_Convert2DTo1D(atlasesCount, atlas1DHeight);
|
||||
Atlas1D_ElementsPerBitmap = atlas1DHeight / Atlas2D_ElementSize;
|
||||
Atlas1D_InvElementSize = 1.0f / Atlas1D_ElementsPerBitmap;
|
||||
Atlas1D_InvTileSize = 1.0f / Atlas1D_TilesPerAtlas;
|
||||
Atlas1D_Convert2DTo1D(atlasesCount, atlasHeight);
|
||||
}
|
||||
|
||||
Int32 Atlas1D_UsedAtlasesCount(void) {
|
||||
|
|
|
@ -6,25 +6,22 @@
|
|||
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
||||
*/
|
||||
|
||||
#define ATLAS2D_ELEMENTS_PER_ROW 16
|
||||
#define ATLAS2D_TILES_PER_ROW 16
|
||||
#define ATLAS2D_ROWS_COUNT 16
|
||||
|
||||
Bitmap Atlas2D_Bitmap;
|
||||
Int32 Atlas2D_ElementSize;
|
||||
Int32 Atlas2D_TileSize;
|
||||
void Atlas2D_UpdateState(Bitmap* bmp);
|
||||
/* Creates a native texture that contains the tile at the specified index. */
|
||||
GfxResourceID Atlas2D_LoadTextureElement(TextureLoc texLoc);
|
||||
void Atlas2D_Free(void);
|
||||
|
||||
/* The theoretical largest number of 1D atlases that a 2D atlas can be broken down into. */
|
||||
#define ATLAS1D_MAX_ATLASES_COUNT (ATLAS2D_ELEMENTS_PER_ROW * ATLAS2D_ROWS_COUNT)
|
||||
#define ATLAS1D_MAX_ATLASES_COUNT (ATLAS2D_TILES_PER_ROW * ATLAS2D_ROWS_COUNT)
|
||||
/* The number of elements each 1D atlas contains. */
|
||||
Int32 Atlas1D_ElementsPerAtlas;
|
||||
/* The number of elements in each adjusted 1D atlas.
|
||||
(in the case only 1 1D atlas used, and is resized vertically to be a power of two) */
|
||||
Int32 Atlas1D_ElementsPerBitmap;
|
||||
Int32 Atlas1D_TilesPerAtlas;
|
||||
/* Size of a texture coord V for an element in a 1D atlas. */
|
||||
Real32 Atlas1D_InvElementSize;
|
||||
Real32 Atlas1D_InvTileSize;
|
||||
/* Native texture ID for each 1D atlas. */
|
||||
GfxResourceID Atlas1D_TexIds[ATLAS1D_MAX_ATLASES_COUNT];
|
||||
/* Number of 1D atlases that actually have textures / are used. */
|
||||
|
@ -32,9 +29,9 @@ Int32 Atlas1D_Count;
|
|||
/* Retrieves the 1D texture rectangle and 1D atlas index of the given texture. */
|
||||
TextureRec Atlas1D_TexRec(TextureLoc texLoc, Int32 uCount, Int32* index);
|
||||
/* Returns the index of the 1D atlas within the array of 1D atlases that contains the given texture id.*/
|
||||
#define Atlas1D_Index(texLoc) ((texLoc) / Atlas1D_ElementsPerAtlas)
|
||||
#define Atlas1D_Index(texLoc) ((texLoc) / Atlas1D_TilesPerAtlas)
|
||||
/* Returns the index of the given texture id within a 1D atlas. */
|
||||
#define Atlas1D_RowId(texLoc) ((texLoc) % Atlas1D_ElementsPerAtlas)
|
||||
#define Atlas1D_RowId(texLoc) ((texLoc) % Atlas1D_TilesPerAtlas)
|
||||
|
||||
/* Updates variables and native textures for the 1D atlas array. */
|
||||
void Atlas1D_UpdateState(void);
|
||||
|
|
Loading…
Add table
Reference in a new issue