From 864925df25940b0ca016f02187a7c39c1ea3bf1a Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sun, 1 Oct 2023 12:52:23 +0200 Subject: [PATCH] More clean up --- src/rendering/hwrenderer/doom_levelmesh.cpp | 41 +++++++++------------ src/rendering/hwrenderer/doom_levelmesh.h | 1 - 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/rendering/hwrenderer/doom_levelmesh.cpp b/src/rendering/hwrenderer/doom_levelmesh.cpp index 7e1f617e3..8f5fb5f9b 100644 --- a/src/rendering/hwrenderer/doom_levelmesh.cpp +++ b/src/rendering/hwrenderer/doom_levelmesh.cpp @@ -1309,34 +1309,29 @@ void DoomLevelSubmesh::PackLightmapAtlas() for (LevelMeshSurface* surf : sortedSurfaces) { - FinishSurface(LMTextureSize, LMTextureSize, packer, *surf); + int sampleWidth = surf->AtlasTile.Width; + int sampleHeight = surf->AtlasTile.Height; + + auto result = packer.insert(sampleWidth, sampleHeight); + int x = result.pos.x, y = result.pos.y; + + surf->AtlasTile.X = x; + surf->AtlasTile.Y = y; + surf->AtlasTile.ArrayIndex = (int)result.pageIndex; + + // calculate final texture coordinates + for (int i = 0; i < (int)surf->numVerts; i++) + { + auto& u = LightmapUvs[surf->startUvIndex + i].X; + auto& v = LightmapUvs[surf->startUvIndex + i].Y; + u = (u + x) / (float)LMTextureSize; + v = (v + y) / (float)LMTextureSize; + } } LMTextureCount = (int)packer.getNumPages(); } -void DoomLevelSubmesh::FinishSurface(int lightmapTextureWidth, int lightmapTextureHeight, RectPacker& packer, LevelMeshSurface& surface) -{ - int sampleWidth = surface.AtlasTile.Width; - int sampleHeight = surface.AtlasTile.Height; - - auto result = packer.insert(sampleWidth, sampleHeight); - int x = result.pos.x, y = result.pos.y; - surface.AtlasTile.ArrayIndex = (int)result.pageIndex; - - // calculate final texture coordinates - for (int i = 0; i < (int)surface.numVerts; i++) - { - auto& u = LightmapUvs[surface.startUvIndex + i].X; - auto& v = LightmapUvs[surface.startUvIndex + i].Y; - u = (u + x) / (float)lightmapTextureWidth; - v = (v + y) / (float)lightmapTextureHeight; - } - - surface.AtlasTile.X = x; - surface.AtlasTile.Y = y; -} - BBox DoomLevelSubmesh::GetBoundsFromSurface(const LevelMeshSurface& surface) const { constexpr float M_INFINITY = 1e30f; // TODO cleanup diff --git a/src/rendering/hwrenderer/doom_levelmesh.h b/src/rendering/hwrenderer/doom_levelmesh.h index a2955114a..cf1a3d410 100644 --- a/src/rendering/hwrenderer/doom_levelmesh.h +++ b/src/rendering/hwrenderer/doom_levelmesh.h @@ -115,7 +115,6 @@ private: inline int AllocUvs(int amount) { return LightmapUvs.Reserve(amount); } void BuildSurfaceParams(int lightMapTextureWidth, int lightMapTextureHeight, LevelMeshSurface& surface); - void FinishSurface(int lightmapTextureWidth, int lightmapTextureHeight, RectPacker& packer, LevelMeshSurface& surface); static bool IsDegenerate(const FVector3& v0, const FVector3& v1, const FVector3& v2);