diff --git a/src/common/rendering/hwrenderer/data/hw_levelmesh.h b/src/common/rendering/hwrenderer/data/hw_levelmesh.h index d7986549d..aa80574aa 100644 --- a/src/common/rendering/hwrenderer/data/hw_levelmesh.h +++ b/src/common/rendering/hwrenderer/data/hw_levelmesh.h @@ -43,7 +43,6 @@ struct LevelMeshSurface unsigned int startVertIndex; unsigned int startUvIndex; FVector4 plane; - void* controlSector; // type is sector_t bool bSky; // Lightmap UV information in pixel size @@ -167,7 +166,8 @@ public: std::unique_ptr Collision; - TArray Surfaces; + virtual LevelMeshSurface* GetSurface(int index) { return nullptr; } + virtual int GetSurfaceCount() { return 0; } TArray SmoothingGroups; // TODO fill TArray Portals; // TODO fill diff --git a/src/common/rendering/vulkan/accelstructs/vk_lightmap.cpp b/src/common/rendering/vulkan/accelstructs/vk_lightmap.cpp index 9d4cefa14..6b9a7d273 100644 --- a/src/common/rendering/vulkan/accelstructs/vk_lightmap.cpp +++ b/src/common/rendering/vulkan/accelstructs/vk_lightmap.cpp @@ -102,9 +102,9 @@ void VkLightmap::RenderAtlasImage(size_t pageIndex) }; beginPass(); - for (unsigned int i = 0; i < mesh->Surfaces.Size(); i++) + for (int i = 0, count = mesh->GetSurfaceCount(); i < count; i++) { - LevelMeshSurface* targetSurface = &mesh->Surfaces[i]; + LevelMeshSurface* targetSurface = mesh->GetSurface(i); if (targetSurface->lightmapperAtlasPage != pageIndex) continue; @@ -203,9 +203,9 @@ void VkLightmap::CreateAtlasImages() const int spacing = 3; // Note: the spacing is here to avoid that the resolve sampler finds data from other surface tiles RectPacker packer(atlasImageSize, atlasImageSize, RectPacker::Spacing(spacing)); - for (unsigned int i = 0; i < mesh->Surfaces.Size(); i++) + for (int i = 0, count = mesh->GetSurfaceCount(); i < count; i++) { - LevelMeshSurface* surface = &mesh->Surfaces[i]; + LevelMeshSurface* surface = mesh->GetSurface(i); auto result = packer.insert(surface->texWidth + 2, surface->texHeight + 2); surface->lightmapperAtlasX = result.pos.x + 1; @@ -312,9 +312,9 @@ void VkLightmap::DownloadAtlasImage(size_t pageIndex) hvec4* pixels = (hvec4*)atlasImages[pageIndex].Transfer->Map(0, atlasImageSize * atlasImageSize * sizeof(hvec4)); - for (unsigned int i = 0; i < mesh->Surfaces.Size(); i++) + for (int i = 0, count = mesh->GetSurfaceCount(); i < count; i++) { - LevelMeshSurface* surface = &mesh->Surfaces[i]; + LevelMeshSurface* surface = mesh->GetSurface(i); if (surface->lightmapperAtlasPage != pageIndex) continue; diff --git a/src/common/rendering/vulkan/accelstructs/vk_raytrace.cpp b/src/common/rendering/vulkan/accelstructs/vk_raytrace.cpp index 004748519..53f67b85c 100644 --- a/src/common/rendering/vulkan/accelstructs/vk_raytrace.cpp +++ b/src/common/rendering/vulkan/accelstructs/vk_raytrace.cpp @@ -115,13 +115,15 @@ void VkRaytrace::CreateBuffers() } TArray surfaceInfo; - for (auto& surface : Mesh->Surfaces) + for (int i = 0, count = Mesh->GetSurfaceCount(); i < count; i++) { + LevelMeshSurface* surface = Mesh->GetSurface(i); + SurfaceInfo info; - info.Normal = surface.plane.XYZ(); + info.Normal = surface->plane.XYZ(); info.PortalIndex = 0; - info.SamplingDistance = (float)surface.sampleDimension; - info.Sky = surface.bSky; + info.SamplingDistance = (float)surface->sampleDimension; + info.Sky = surface->bSky; surfaceInfo.Push(info); } diff --git a/src/common/rendering/vulkan/vk_renderdevice.cpp b/src/common/rendering/vulkan/vk_renderdevice.cpp index c4af486de..34388651f 100644 --- a/src/common/rendering/vulkan/vk_renderdevice.cpp +++ b/src/common/rendering/vulkan/vk_renderdevice.cpp @@ -535,7 +535,7 @@ void VulkanRenderDevice::SetLevelMesh(LevelMesh* mesh) mRaytrace->SetLevelMesh(mesh); static LevelMesh* lastMesh = nullptr; // Temp hack; Since this function is called every frame we only want to do this once - if (lastMesh != mesh && mesh->Surfaces.Size() > 0) + if (lastMesh != mesh && mesh->GetSurfaceCount() > 0) { lastMesh = mesh; @@ -559,23 +559,25 @@ void VulkanRenderDevice::SetLevelMesh(LevelMesh* mesh) TArray LMTextureData; LMTextureData.Resize(mesh->LMTextureSize * mesh->LMTextureSize * mesh->LMTextureCount * 3); - for (auto& surface : mesh->Surfaces) + for (int i = 0, count = mesh->GetSurfaceCount(); i < count; i++) { - uint16_t* currentTexture = LMTextureData.Data() + (mesh->LMTextureSize * mesh->LMTextureSize * 3) * surface.atlasPageIndex; + LevelMeshSurface* surface = mesh->GetSurface(i); - FVector3* colorSamples = surface.texPixels.data(); + uint16_t* currentTexture = LMTextureData.Data() + (mesh->LMTextureSize * mesh->LMTextureSize * 3) * surface->atlasPageIndex; + + FVector3* colorSamples = surface->texPixels.data(); // store results to lightmap texture - for (int i = 0; i < surface.texHeight; i++) + for (int i = 0; i < surface->texHeight; i++) { - for (int j = 0; j < surface.texWidth; j++) + for (int j = 0; j < surface->texWidth; j++) { // get texture offset - int offs = ((mesh->LMTextureSize * (i + surface.atlasY)) + surface.atlasX) * 3; + int offs = ((mesh->LMTextureSize * (i + surface->atlasY)) + surface->atlasX) * 3; // convert RGB to bytes - currentTexture[offs + j * 3 + 0] = floatToHalf(clamp(colorSamples[i * surface.texWidth + j].X, 0.0f, 65000.0f)); - currentTexture[offs + j * 3 + 1] = floatToHalf(clamp(colorSamples[i * surface.texWidth + j].Y, 0.0f, 65000.0f)); - currentTexture[offs + j * 3 + 2] = floatToHalf(clamp(colorSamples[i * surface.texWidth + j].Z, 0.0f, 65000.0f)); + currentTexture[offs + j * 3 + 0] = floatToHalf(clamp(colorSamples[i * surface->texWidth + j].X, 0.0f, 65000.0f)); + currentTexture[offs + j * 3 + 1] = floatToHalf(clamp(colorSamples[i * surface->texWidth + j].Y, 0.0f, 65000.0f)); + currentTexture[offs + j * 3 + 2] = floatToHalf(clamp(colorSamples[i * surface->texWidth + j].Z, 0.0f, 65000.0f)); } } } diff --git a/src/rendering/hwrenderer/doom_levelmesh.cpp b/src/rendering/hwrenderer/doom_levelmesh.cpp index 775ee8879..838ef414b 100644 --- a/src/rendering/hwrenderer/doom_levelmesh.cpp +++ b/src/rendering/hwrenderer/doom_levelmesh.cpp @@ -230,7 +230,7 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side) // line_horizont consumes everything if (side->linedef->special == Line_Horizon && front != back) { - LevelMeshSurface surf; + DoomLevelMeshSurface surf; surf.type = ST_MIDDLESIDE; surf.typeIndex = typeIndex; surf.bSky = front->GetTexture(sector_t::floor) == skyflatnum || front->GetTexture(sector_t::ceiling) == skyflatnum; @@ -276,7 +276,7 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side) if (bothSides) continue; - LevelMeshSurface surf; + DoomLevelMeshSurface surf; surf.type = ST_MIDDLESIDE; surf.typeIndex = typeIndex; surf.controlSector = xfloor->model; @@ -318,7 +318,7 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side) { if (IsBottomSideVisible(side)) { - LevelMeshSurface surf; + DoomLevelMeshSurface surf; FVector3 verts[4]; verts[0].X = verts[2].X = v1.X; @@ -356,7 +356,7 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side) bool bSky = IsTopSideSky(front, back, side); if (bSky || IsTopSideVisible(side)) { - LevelMeshSurface surf; + DoomLevelMeshSurface surf; FVector3 verts[4]; verts[0].X = verts[2].X = v1.X; @@ -392,7 +392,7 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side) // middle seg if (back == nullptr) { - LevelMeshSurface surf; + DoomLevelMeshSurface surf; surf.bSky = false; FVector3 verts[4]; @@ -424,7 +424,7 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side) void DoomLevelMesh::CreateFloorSurface(FLevelLocals &doomMap, subsector_t *sub, sector_t *sector, int typeIndex, bool is3DFloor) { - LevelMeshSurface surf; + DoomLevelMeshSurface surf; surf.bSky = IsSkySector(sector, sector_t::floor); secplane_t plane; @@ -463,7 +463,7 @@ void DoomLevelMesh::CreateFloorSurface(FLevelLocals &doomMap, subsector_t *sub, void DoomLevelMesh::CreateCeilingSurface(FLevelLocals &doomMap, subsector_t *sub, sector_t *sector, int typeIndex, bool is3DFloor) { - LevelMeshSurface surf; + DoomLevelMeshSurface surf; surf.bSky = IsSkySector(sector, sector_t::ceiling); secplane_t plane; diff --git a/src/rendering/hwrenderer/doom_levelmesh.h b/src/rendering/hwrenderer/doom_levelmesh.h index 263073e92..862e3c469 100644 --- a/src/rendering/hwrenderer/doom_levelmesh.h +++ b/src/rendering/hwrenderer/doom_levelmesh.h @@ -12,6 +12,11 @@ typedef dp::rect_pack::RectPacker RectPacker; struct FLevelLocals; +struct DoomLevelMeshSurface : public LevelMeshSurface +{ + sector_t* controlSector; +}; + class DoomLevelMesh : public LevelMesh { public: @@ -28,6 +33,11 @@ public: return Surfaces[surfaceIndex].bSky; } + LevelMeshSurface* GetSurface(int index) override { return &Surfaces[index]; } + int GetSurfaceCount() override { return Surfaces.Size(); } + + TArray Surfaces; + TArray LightmapUvs; static_assert(alignof(FVector2) == alignof(float[2]) && sizeof(FVector2) == sizeof(float) * 2);