diff --git a/src/common/rendering/hwrenderer/data/hw_levelmesh.cpp b/src/common/rendering/hwrenderer/data/hw_levelmesh.cpp index d51a7112d..f17c14965 100644 --- a/src/common/rendering/hwrenderer/data/hw_levelmesh.cpp +++ b/src/common/rendering/hwrenderer/data/hw_levelmesh.cpp @@ -56,21 +56,23 @@ void LevelMesh::AddEmptyMesh() // Default empty mesh (we can't make it completely empty since vulkan doesn't like that) float minval = -100001.0f; float maxval = -100000.0f; - ginfo.Vertices[0] = { minval, minval, minval }; - ginfo.Vertices[1] = { maxval, minval, minval }; - ginfo.Vertices[2] = { maxval, maxval, minval }; - ginfo.Vertices[3] = { minval, minval, minval }; - ginfo.Vertices[4] = { minval, maxval, minval }; - ginfo.Vertices[5] = { maxval, maxval, minval }; - ginfo.Vertices[6] = { minval, minval, maxval }; - ginfo.Vertices[7] = { maxval, minval, maxval }; - ginfo.Vertices[8] = { maxval, maxval, maxval }; - ginfo.Vertices[9] = { minval, minval, maxval }; - ginfo.Vertices[10] = { minval, maxval, maxval }; - ginfo.Vertices[11] = { maxval, maxval, maxval }; + auto vertices = GetVertices(ginfo); + vertices[0] = { minval, minval, minval }; + vertices[1] = { maxval, minval, minval }; + vertices[2] = { maxval, maxval, minval }; + vertices[3] = { minval, minval, minval }; + vertices[4] = { minval, maxval, minval }; + vertices[5] = { maxval, maxval, minval }; + vertices[6] = { minval, minval, maxval }; + vertices[7] = { maxval, minval, maxval }; + vertices[8] = { maxval, maxval, maxval }; + vertices[9] = { minval, minval, maxval }; + vertices[10] = { minval, maxval, maxval }; + vertices[11] = { maxval, maxval, maxval }; + auto indexes = GetIndexes(ginfo); for (int i = 0; i < 3 * 4; i++) - ginfo.Indexes[i] = i; + indexes[i] = i; Mesh.IndexCount = ginfo.IndexCount; diff --git a/src/common/rendering/hwrenderer/data/hw_levelmesh.h b/src/common/rendering/hwrenderer/data/hw_levelmesh.h index 5b8c4121a..dc482a9b9 100644 --- a/src/common/rendering/hwrenderer/data/hw_levelmesh.h +++ b/src/common/rendering/hwrenderer/data/hw_levelmesh.h @@ -20,9 +20,6 @@ struct LevelMeshTileStats; struct GeometryAllocInfo { - FFlatVertex* Vertices = nullptr; - int* UniformIndexes = nullptr; - uint32_t* Indexes = nullptr; int VertexStart = 0; int VertexCount = 0; int IndexStart = 0; @@ -31,29 +28,23 @@ struct GeometryAllocInfo struct UniformsAllocInfo { - SurfaceUniforms* Uniforms = nullptr; - SurfaceLightUniforms* LightUniforms = nullptr; - FMaterialState* Materials = nullptr; int Start = 0; int Count = 0; }; struct SurfaceAllocInfo { - LevelMeshSurface* Surface = nullptr; int Index = 0; int Count = 0; }; struct LightAllocInfo { - LevelMeshLight* Light = nullptr; int Index = 0; }; struct LightListAllocInfo { - int32_t* List = nullptr; int Start = 0; int Count = 0; }; @@ -100,7 +91,6 @@ public: LevelMesh(); virtual ~LevelMesh() = default; - virtual void FullRefresh() {}; LevelMeshSurface* Trace(const FVector3& start, FVector3 direction, float maxDist); @@ -124,6 +114,19 @@ public: LightListAllocInfo AllocLightList(int count); int AllocTile(const LightmapTile& tile); + LevelMeshSurface* GetSurface(const SurfaceAllocInfo& info) { return &Mesh.Surfaces[info.Index]; } + + FFlatVertex* GetVertices(const GeometryAllocInfo& info) { return &Mesh.Vertices[info.VertexStart]; } + int* GetUniformIndexes(const GeometryAllocInfo& info) { return &Mesh.UniformIndexes[info.VertexStart]; } + uint32_t* GetIndexes(const GeometryAllocInfo& info) { return &Mesh.Indexes[info.IndexStart]; } + + SurfaceUniforms* GetUniforms(const UniformsAllocInfo& info) { return &Mesh.Uniforms[info.Start]; } + SurfaceLightUniforms* GetLightUniforms(const UniformsAllocInfo& info) { return &Mesh.LightUniforms[info.Start]; } + FMaterialState* GetMaterials(const UniformsAllocInfo& info) { return &Mesh.Materials[info.Start]; } + + LevelMeshLight* GetLight(const LightAllocInfo& info) { return &Mesh.Lights[info.Index]; } + int32_t* GetLightList(const LightListAllocInfo& info) { return &Mesh.LightIndexes[info.Start]; } + void FreeGeometry(int vertexStart, int vertexCount, int indexStart, int indexCount); void FreeUniforms(int start, int count); void FreeSurface(unsigned int surfaceIndex, int count = 1); @@ -253,9 +256,6 @@ inline GeometryAllocInfo LevelMesh::AllocGeometry(int vertexCount, int indexCoun I_FatalError("Could not find space in level mesh index buffer"); } info.IndexCount = indexCount; - info.Vertices = &Mesh.Vertices[info.VertexStart]; - info.UniformIndexes = &Mesh.UniformIndexes[info.VertexStart]; - info.Indexes = &Mesh.Indexes[info.IndexStart]; UploadRanges.Vertex.Add(info.VertexStart, info.VertexCount); UploadRanges.UniformIndexes.Add(info.VertexStart, info.VertexCount); @@ -282,9 +282,6 @@ inline UniformsAllocInfo LevelMesh::AllocUniforms(int count) I_FatalError("Could not find space in level mesh uniform buffer"); } info.Count = count; - info.Uniforms = &Mesh.Uniforms[info.Start]; - info.LightUniforms = &Mesh.LightUniforms[info.Start]; - info.Materials = &Mesh.Materials[info.Start]; UploadRanges.Uniforms.Add(info.Start, info.Count); UploadRanges.LightUniforms.Add(info.Start, info.Count); @@ -305,7 +302,6 @@ inline LightListAllocInfo LevelMesh::AllocLightList(int count) I_FatalError("Could not find space in level mesh light index buffer"); } info.Count = count; - info.List = &Mesh.LightIndexes[info.Start]; UploadRanges.LightIndex.Add(info.Start, info.Count); return info; } @@ -322,7 +318,6 @@ inline LightAllocInfo LevelMesh::AllocLight() if (info.Index == -1) I_FatalError("Could not find space in level mesh light buffer"); } - info.Light = &Mesh.Lights[info.Index]; UploadRanges.Light.Add(info.Index, 1); return info; } @@ -339,7 +334,6 @@ inline SurfaceAllocInfo LevelMesh::AllocSurface(int count) if (info.Index == -1) I_FatalError("Could not find space in level mesh surface buffer"); } - info.Surface = &Mesh.Surfaces[info.Index]; info.Count = count; UploadRanges.Surface.Add(info.Index, info.Count); return info; diff --git a/src/rendering/hwrenderer/doom_levelmesh.cpp b/src/rendering/hwrenderer/doom_levelmesh.cpp index d80c3602f..9c76b9697 100644 --- a/src/rendering/hwrenderer/doom_levelmesh.cpp +++ b/src/rendering/hwrenderer/doom_levelmesh.cpp @@ -376,9 +376,13 @@ void DoomLevelMesh::CreateModelSurfaces(AActor* thing, FSpriteModelFrame* modelf UniformsAllocInfo uinfo = AllocUniforms(numUniforms); SurfaceAllocInfo sinfo = AllocSurface(numUniforms); // Note: this is not a typo. We currently only create a SurfaceInfo for each apply state. - SurfaceUniforms* curUniforms = uinfo.Uniforms; - SurfaceLightUniforms* curLightUniforms = uinfo.LightUniforms; - FMaterialState* curMaterial = uinfo.Materials; + SurfaceUniforms* curUniforms = GetUniforms(uinfo); + SurfaceLightUniforms* curLightUniforms = GetLightUniforms(uinfo); + FMaterialState* curMaterial = GetMaterials(uinfo); + + auto indexes = GetIndexes(ginfo); + auto vertices = GetVertices(ginfo); + auto uniformIndexes = GetUniformIndexes(ginfo); int pipelineID = 0; int uniformsIndex = uinfo.Start; @@ -399,7 +403,7 @@ void DoomLevelMesh::CreateModelSurfaces(AActor* thing, FSpriteModelFrame* modelf int numVertices = command.Count / 3 * 3; for (int i = 0; i < numVertices; i++) { - *(ginfo.Indexes++) = vertIndex + i; + *(indexes++) = vertIndex + i; } for (int i = command.Start, end = command.Start + numVertices; i < end; i++) { @@ -412,8 +416,8 @@ void DoomLevelMesh::CreateModelSurfaces(AActor* thing, FSpriteModelFrame* modelf vertOut.u = vertIn.u; vertOut.v = vertIn.v; vertOut.lindex = -1.0f; - *(ginfo.Vertices++) = vertOut; - *(ginfo.UniformIndexes++) = uniformsIndex; + *(vertices++) = vertOut; + *(uniformIndexes++) = uniformsIndex; } vertIndex += numVertices; } @@ -426,7 +430,7 @@ void DoomLevelMesh::CreateModelSurfaces(AActor* thing, FSpriteModelFrame* modelf int numVertices = command.Count / 3 * 3; for (int i = 0; i < numVertices; i++) { - *(ginfo.Indexes++) = vertIndex + i; + *(indexes++) = vertIndex + i; } for (int i = command.Start, end = command.Start + numVertices; i < end; i++) { @@ -439,8 +443,8 @@ void DoomLevelMesh::CreateModelSurfaces(AActor* thing, FSpriteModelFrame* modelf vertOut.u = vertIn.u; vertOut.v = vertIn.v; vertOut.lindex = -1.0f; - *(ginfo.Vertices++) = vertOut; - *(ginfo.UniformIndexes++) = uniformsIndex; + *(vertices++) = vertOut; + *(uniformIndexes++) = uniformsIndex; } vertIndex += numVertices; } @@ -454,28 +458,28 @@ void DoomLevelMesh::CreateModelSurfaces(AActor* thing, FSpriteModelFrame* modelf curLightUniforms->uLightLevel = applyState.surfaceUniforms.uLightLevel; curLightUniforms++; - sinfo.Surface->PipelineID = pipelineID; - sinfo.Surface->SectorGroup = thing->Sector ? sectorGroup[thing->Sector->Index()] : 0; - sinfo.Surface->Alpha = float(thing->Alpha); - sinfo.Surface->MeshLocation.StartVertIndex = ginfo.VertexStart; - sinfo.Surface->MeshLocation.StartElementIndex = ginfo.IndexStart; - sinfo.Surface->MeshLocation.NumVerts = ginfo.VertexCount; - sinfo.Surface->MeshLocation.NumElements = ginfo.IndexCount; - sinfo.Surface->Plane = FVector4(0.0f, 0.0f, 0.0f, 0.0f); - sinfo.Surface->Texture = TexMan.GetGameTexture(skyflatnum); // To do: how to get a FGameTexture from a material? - sinfo.Surface->PortalIndex = 0; - sinfo.Surface->IsSky = false; - sinfo.Surface->Bounds = GetBoundsFromSurface(*sinfo.Surface); - sinfo.Surface->LightList.Pos = 0; // To do: how to manage the light list for baked models? - sinfo.Surface->LightList.Count = 0; - sinfo.Surface->LightmapTileIndex = -1; // To do: create tiles for the model surfaces? Current SurfaceInfo is too big for this + auto surface = GetSurface(sinfo); + surface->PipelineID = pipelineID; + surface->SectorGroup = thing->Sector ? sectorGroup[thing->Sector->Index()] : 0; + surface->Alpha = float(thing->Alpha); + surface->MeshLocation.StartVertIndex = ginfo.VertexStart; + surface->MeshLocation.StartElementIndex = ginfo.IndexStart; + surface->MeshLocation.NumVerts = ginfo.VertexCount; + surface->MeshLocation.NumElements = ginfo.IndexCount; + surface->Plane = FVector4(0.0f, 0.0f, 0.0f, 0.0f); + surface->Texture = TexMan.GetGameTexture(skyflatnum); // To do: how to get a FGameTexture from a material? + surface->PortalIndex = 0; + surface->IsSky = false; + surface->Bounds = GetBoundsFromSurface(*surface); + surface->LightList.Pos = 0; // To do: how to manage the light list for baked models? + surface->LightList.Count = 0; + surface->LightmapTileIndex = -1; // To do: create tiles for the model surfaces? Current SurfaceInfo is too big for this for (int i = ginfo.IndexStart / 3, end = (ginfo.IndexStart + ginfo.IndexCount) / 3; i < end; i++) Mesh.SurfaceIndexes[i] = sinfo.Index; - if (DoomSurfaceInfos.size() <= (size_t)sinfo.Index) - DoomSurfaceInfos.resize(sinfo.Index + 1); - DoomSurfaceInfos[sinfo.Index].Type = ST_NONE; // Maybe add ST_MODEL? + auto doomsurface = GetDoomSurface(sinfo); + doomsurface->Type = ST_NONE; // Maybe add ST_MODEL? uniformsIndex++; } @@ -721,7 +725,7 @@ int DoomLevelMesh::GetLightIndex(FDynamicLight* light, int portalgroup) LightAllocInfo info = AllocLight(); - CopyToMeshLight(light, *info.Light, portalgroup); + CopyToMeshLight(light, *GetLight(info), portalgroup); light->levelmesh[index].index = info.Index + 1; light->levelmesh[index].portalgroup = portalgroup; @@ -1202,6 +1206,7 @@ LightListAllocInfo DoomLevelMesh::CreateLightList(FLightNode* node, int portalgr } LightListAllocInfo info = AllocLightList(lightcount); + int32_t* lightList = GetLightList(info); int i = 0; cur = node; while (cur) @@ -1212,7 +1217,7 @@ LightListAllocInfo DoomLevelMesh::CreateLightList(FLightNode* node, int portalgr int lightindex = GetLightIndex(light, portalgroup); if (lightindex >= 0) { - info.List[i++] = lightindex; + lightList[i++] = lightindex; } } cur = cur->nextLight; @@ -1421,17 +1426,18 @@ void DoomLevelMesh::SetSideLights(FLevelLocals& doomMap, unsigned int sideIndex) for (UniformsAllocInfo& uinfo : Sides[sideIndex].Uniforms) { + auto lightUniforms = GetLightUniforms(uinfo); for (int i = 0, count = uinfo.Count; i < count; i++) { // To do: calculate this correctly (see HWDrawInfo::SetColor) - // uinfo.LightUniforms[i].uVertexColor - // uinfo.LightUniforms[i].uDesaturationFactor - if (uinfo.LightUniforms[i].uLightLevel >= 0.0f) + // lightUniforms[i].uVertexColor + // lightUniforms[i].uDesaturationFactor + if (lightUniforms[i].uLightLevel >= 0.0f) { - uinfo.LightUniforms[i].uLightLevel = clamp(doomMap.sides[sideIndex].sector->lightlevel * (1.0f / 255.0f), 0.0f, 1.0f); + lightUniforms[i].uLightLevel = clamp(doomMap.sides[sideIndex].sector->lightlevel * (1.0f / 255.0f), 0.0f, 1.0f); } - SetColor(uinfo.LightUniforms[i], &doomMap, lightmode, lightlevel, rel, fullbrightScene, Colormap, absalpha); + SetColor(lightUniforms[i], &doomMap, lightmode, lightlevel, rel, fullbrightScene, Colormap, absalpha); } UploadRanges.LightUniforms.Add(uinfo.Start, uinfo.Count); } @@ -1455,9 +1461,10 @@ void DoomLevelMesh::SetFlatLights(FLevelLocals& doomMap, unsigned int sectorInde for (UniformsAllocInfo& uinfo : Flats[sectorIndex].Uniforms) { + auto lightUniforms = GetLightUniforms(uinfo); for (int i = 0, count = uinfo.Count; i < count; i++) { - SetColor(uinfo.LightUniforms[i], &doomMap, lightmode, lightlevel, rel, fullbrightScene, Colormap, alpha); + SetColor(lightUniforms[i], &doomMap, lightmode, lightlevel, rel, fullbrightScene, Colormap, alpha); } UploadRanges.LightUniforms.Add(uinfo.Start, uinfo.Count); } @@ -1512,9 +1519,13 @@ void DoomLevelMesh::CreateWallSurface(side_t* side, HWWallDispatcher& disp, Mesh UniformsAllocInfo uinfo = AllocUniforms(numUniforms); SurfaceAllocInfo sinfo = AllocSurface(); - SurfaceUniforms* curUniforms = uinfo.Uniforms; - SurfaceLightUniforms* curLightUniforms = uinfo.LightUniforms; - FMaterialState* curMaterial = uinfo.Materials; + SurfaceUniforms* curUniforms = GetUniforms(uinfo); + SurfaceLightUniforms* curLightUniforms = GetLightUniforms(uinfo); + FMaterialState* curMaterial = GetMaterials(uinfo); + + auto indexes = GetIndexes(ginfo); + auto vertices = GetVertices(ginfo); + auto uniformIndexes = GetUniformIndexes(ginfo); int pipelineID = 0; int uniformsIndex = uinfo.Start; @@ -1531,15 +1542,15 @@ void DoomLevelMesh::CreateWallSurface(side_t* side, HWWallDispatcher& disp, Mesh { for (int i = 2, count = command.Count; i < count; i++) { - *(ginfo.Indexes++) = vertIndex; - *(ginfo.Indexes++) = vertIndex + i - 1; - *(ginfo.Indexes++) = vertIndex + i; + *(indexes++) = vertIndex; + *(indexes++) = vertIndex + i - 1; + *(indexes++) = vertIndex + i; } for (int i = command.Start, end = command.Start + command.Count; i < end; i++) { - *(ginfo.Vertices++) = state.mVertices[i]; - *(ginfo.UniformIndexes++) = uniformsIndex; + *(vertices++) = state.mVertices[i]; + *(uniformIndexes++) = uniformsIndex; } vertIndex += command.Count; } @@ -1574,10 +1585,7 @@ void DoomLevelMesh::CreateWallSurface(side_t* side, HWWallDispatcher& disp, Mesh sampleDimension = side->textures[side_t::bottom].LightmapSampleDistance; } - if (DoomSurfaceInfos.size() <= (size_t)sinfo.Index) - DoomSurfaceInfos.resize(sinfo.Index + 1); - - DoomSurfaceInfo& info = DoomSurfaceInfos[sinfo.Index]; + DoomSurfaceInfo& info = *GetDoomSurface(sinfo); info.Type = wallpart.LevelMeshInfo.Type; info.ControlSector = wallpart.LevelMeshInfo.ControlSector; info.TypeIndex = side->Index(); @@ -1586,29 +1594,30 @@ void DoomLevelMesh::CreateWallSurface(side_t* side, HWWallDispatcher& disp, Mesh info.NextSurface = Sides[sideIndex].FirstSurface; Sides[sideIndex].FirstSurface = sinfo.Index; - sinfo.Surface->PipelineID = pipelineID; - sinfo.Surface->SectorGroup = sectorGroup[side->sector->Index()]; - sinfo.Surface->Alpha = float(side->linedef->alpha); - sinfo.Surface->MeshLocation.StartVertIndex = ginfo.VertexStart; - sinfo.Surface->MeshLocation.StartElementIndex = ginfo.IndexStart; - sinfo.Surface->MeshLocation.NumVerts = ginfo.VertexCount; - sinfo.Surface->MeshLocation.NumElements = ginfo.IndexCount; - sinfo.Surface->Plane = FVector4(N.X, N.Y, 0.0f, v1 | N); - sinfo.Surface->Texture = wallpart.texture; - sinfo.Surface->PortalIndex = (drawType == LevelMeshDrawType::Portal) ? linePortals[side->linedef->Index()] : 0; - sinfo.Surface->IsSky = (drawType == LevelMeshDrawType::Portal) ? (wallpart.portaltype == PORTALTYPE_SKY || wallpart.portaltype == PORTALTYPE_SKYBOX || wallpart.portaltype == PORTALTYPE_HORIZON) : false; - sinfo.Surface->Bounds = GetBoundsFromSurface(*sinfo.Surface); - sinfo.Surface->LightList.Pos = lightlist.Start; - sinfo.Surface->LightList.Count = lightlist.Count; + auto surface = GetSurface(sinfo); + surface->PipelineID = pipelineID; + surface->SectorGroup = sectorGroup[side->sector->Index()]; + surface->Alpha = float(side->linedef->alpha); + surface->MeshLocation.StartVertIndex = ginfo.VertexStart; + surface->MeshLocation.StartElementIndex = ginfo.IndexStart; + surface->MeshLocation.NumVerts = ginfo.VertexCount; + surface->MeshLocation.NumElements = ginfo.IndexCount; + surface->Plane = FVector4(N.X, N.Y, 0.0f, v1 | N); + surface->Texture = wallpart.texture; + surface->PortalIndex = (drawType == LevelMeshDrawType::Portal) ? linePortals[side->linedef->Index()] : 0; + surface->IsSky = (drawType == LevelMeshDrawType::Portal) ? (wallpart.portaltype == PORTALTYPE_SKY || wallpart.portaltype == PORTALTYPE_SKYBOX || wallpart.portaltype == PORTALTYPE_HORIZON) : false; + surface->Bounds = GetBoundsFromSurface(*surface); + surface->LightList.Pos = lightlist.Start; + surface->LightList.Count = lightlist.Count; - if (disp.Level->lightmaps && !sinfo.Surface->IsSky) + if (disp.Level->lightmaps && !surface->IsSky) { - sinfo.Surface->LightmapTileIndex = AddSurfaceToTile(info, *sinfo.Surface, sampleDimension, !!(side->sector->Flags & SECF_LM_DYNAMIC)); + surface->LightmapTileIndex = AddSurfaceToTile(info, *surface, sampleDimension, !!(side->sector->Flags & SECF_LM_DYNAMIC)); Lightmap.AddedSurfaces.Push(sinfo.Index); } else { - sinfo.Surface->LightmapTileIndex = -1; + surface->LightmapTileIndex = -1; } SetSideLightmap(sinfo.Index); @@ -1766,12 +1775,13 @@ void DoomLevelMesh::CreateFlatSurface(HWFlatDispatcher& disp, MeshBuilder& state int* surfaceIndexes = &Mesh.SurfaceIndexes[ginfo.IndexStart / 3]; - *uinfo.Uniforms = *uniforms; - *uinfo.Materials = *material; + *GetUniforms(uinfo) = *uniforms; + *GetMaterials(uinfo) = *material; - uinfo.LightUniforms->uVertexColor = uniforms->uVertexColor; - uinfo.LightUniforms->uDesaturationFactor = uniforms->uDesaturationFactor; - uinfo.LightUniforms->uLightLevel = uniforms->uLightLevel; + auto lightUniforms = GetLightUniforms(uinfo); + lightUniforms->uVertexColor = uniforms->uVertexColor; + lightUniforms->uDesaturationFactor = uniforms->uDesaturationFactor; + lightUniforms->uLightLevel = uniforms->uLightLevel; int uniformsIndex = uinfo.Start; int vertIndex = ginfo.VertexStart; @@ -1816,6 +1826,10 @@ void DoomLevelMesh::CreateFlatSurface(HWFlatDispatcher& disp, MeshBuilder& state float skyZ = flatpart.ceiling ? 32768.0f : -32768.0f; bool useSkyZ = (drawType == LevelMeshDrawType::Portal && flatpart.plane.texture == skyflatnum); + FFlatVertex* vertices = GetVertices(ginfo); + int* uniformIndexes = GetUniformIndexes(ginfo); + uint32_t* indexes = GetIndexes(ginfo); + for (subsector_t* sub : flatpart.section->subsectors) { if (sub->numlines < 3) @@ -1843,8 +1857,8 @@ void DoomLevelMesh::CreateFlatSurface(HWFlatDispatcher& disp, MeshBuilder& state ffv.lv = 0.0f; ffv.lindex = -1.0f; - *(ginfo.Vertices++) = ffv; - *(ginfo.UniformIndexes++) = uniformsIndex; + *(vertices++) = ffv; + *(uniformIndexes++) = uniformsIndex; } SurfaceAllocInfo sinfo = AllocSurface(); @@ -1853,9 +1867,9 @@ void DoomLevelMesh::CreateFlatSurface(HWFlatDispatcher& disp, MeshBuilder& state { for (int i = 2, count = sub->numlines; i < count; i++) { - *(ginfo.Indexes++) = startVertIndex; - *(ginfo.Indexes++) = startVertIndex + i - 1; - *(ginfo.Indexes++) = startVertIndex + i; + *(indexes++) = startVertIndex; + *(indexes++) = startVertIndex + i - 1; + *(indexes++) = startVertIndex + i; *(surfaceIndexes++) = sinfo.Index; } } @@ -1863,9 +1877,9 @@ void DoomLevelMesh::CreateFlatSurface(HWFlatDispatcher& disp, MeshBuilder& state { for (int i = 2, count = sub->numlines; i < count; i++) { - *(ginfo.Indexes++) = startVertIndex + i; - *(ginfo.Indexes++) = startVertIndex + i - 1; - *(ginfo.Indexes++) = startVertIndex; + *(indexes++) = startVertIndex + i; + *(indexes++) = startVertIndex + i - 1; + *(indexes++) = startVertIndex; *(surfaceIndexes++) = sinfo.Index; } } @@ -1895,11 +1909,8 @@ void DoomLevelMesh::CreateFlatSurface(HWFlatDispatcher& disp, MeshBuilder& state info.NextSurface = Flats[sectorIndex].FirstSurface; Flats[sectorIndex].FirstSurface = sinfo.Index; - *sinfo.Surface = surf; - - if (DoomSurfaceInfos.size() <= (size_t)sinfo.Index) - DoomSurfaceInfos.resize(sinfo.Index + 1); - DoomSurfaceInfos[sinfo.Index] = info; + *GetSurface(sinfo) = surf; + *GetDoomSurface(sinfo) = info; for (int i = ginfo.IndexStart / 3, end = (ginfo.IndexStart + ginfo.IndexCount) / 3; i < end; i++) Mesh.SurfaceIndexes[i] = sinfo.Index; diff --git a/src/rendering/hwrenderer/doom_levelmesh.h b/src/rendering/hwrenderer/doom_levelmesh.h index cf15a47f5..13b547438 100644 --- a/src/rendering/hwrenderer/doom_levelmesh.h +++ b/src/rendering/hwrenderer/doom_levelmesh.h @@ -257,6 +257,14 @@ private: void BuildSideVisibilityLists(FLevelLocals& doomMap); void BuildSubsectorVisibilityLists(FLevelLocals& doomMap); + DoomSurfaceInfo* GetDoomSurface(const SurfaceAllocInfo& sinfo) + { + size_t i = (size_t)sinfo.Index; + if (DoomSurfaceInfos.size() <= i) + DoomSurfaceInfos.resize(i + 1); + return &DoomSurfaceInfos[i]; + } + TArray DoomSurfaceInfos; TArray Sides;