mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-02-16 17:21:10 +00:00
WIP refactoring of surface gathering
This commit is contained in:
parent
f78739196f
commit
f279fa69f4
2 changed files with 52 additions and 23 deletions
|
@ -10,6 +10,8 @@
|
|||
#include "hw_viewpointuniforms.h"
|
||||
#include "hw_cvars.h"
|
||||
|
||||
#include <atomic>
|
||||
|
||||
EXTERN_CVAR(Int, lm_max_updates);
|
||||
|
||||
struct FColormap;
|
||||
|
@ -260,13 +262,17 @@ protected:
|
|||
|
||||
EPassType mPassType = NORMAL_PASS;
|
||||
|
||||
TArray<int> mActiveLightmapSurfaces;
|
||||
std::atomic<unsigned> mActiveLightmapSurfaceBufferIndex;
|
||||
TArray<int> mActiveLightmapSurfacesBuffer;
|
||||
public:
|
||||
|
||||
uint64_t firstFrame = 0;
|
||||
|
||||
void Reset()
|
||||
{
|
||||
mActiveLightmapSurfaceBufferIndex = { 0 };
|
||||
mActiveLightmapSurfacesBuffer.Resize(lm_max_updates);
|
||||
|
||||
mTextureEnabled = true;
|
||||
mBrightmapEnabled = mGradientEnabled = mFogEnabled = mGlowEnabled = false;
|
||||
mFogColor = 0xffffffff;
|
||||
|
@ -735,18 +741,31 @@ public:
|
|||
|
||||
inline void PushVisibleSurface(int surfaceIndex, LevelMeshSurface* surface)
|
||||
{
|
||||
if(surface->needsUpdate && mActiveLightmapSurfaces.Size() < unsigned(lm_max_updates) && mActiveLightmapSurfaces.Find(surfaceIndex) >= mActiveLightmapSurfaces.Size()) // yikes, how awful
|
||||
mActiveLightmapSurfaces.Push(surfaceIndex);
|
||||
if (surface->needsUpdate) // TODO atomic?
|
||||
{
|
||||
int index = mActiveLightmapSurfaceBufferIndex.fetch_add(1);
|
||||
if (index < mActiveLightmapSurfacesBuffer.Size())
|
||||
{
|
||||
mActiveLightmapSurfacesBuffer[index] = surfaceIndex;
|
||||
surface->needsUpdate = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline auto& GetVisibleSurfaceList()
|
||||
{
|
||||
return mActiveLightmapSurfaces;
|
||||
return mActiveLightmapSurfacesBuffer;
|
||||
}
|
||||
|
||||
inline unsigned GetVisibleSurfaceListCount() const
|
||||
{
|
||||
return mActiveLightmapSurfaceBufferIndex;
|
||||
}
|
||||
|
||||
inline void ClearVisibleSurfaceList()
|
||||
{
|
||||
mActiveLightmapSurfaces.Clear();
|
||||
mActiveLightmapSurfacesBuffer.Resize(lm_max_updates);
|
||||
mActiveLightmapSurfaceBufferIndex = 0;
|
||||
}
|
||||
|
||||
// API-dependent render interface
|
||||
|
|
|
@ -97,6 +97,33 @@ void CollectLights(FLevelLocals* Level)
|
|||
}
|
||||
}
|
||||
|
||||
void UpdateLightmaps(DFrameBuffer* screen, FRenderState& RenderState)
|
||||
{
|
||||
|
||||
// Lightmapping stuff
|
||||
auto& list = RenderState.GetVisibleSurfaceList();
|
||||
auto size = RenderState.GetVisibleSurfaceListCount();
|
||||
|
||||
list.Resize(min(list.Size(), unsigned(size)));
|
||||
|
||||
if (size < lm_background_updates)
|
||||
{
|
||||
int index = 0;
|
||||
for (auto& e : level.levelMesh->Surfaces)
|
||||
{
|
||||
if (e.needsUpdate)
|
||||
{
|
||||
list.Push(index);
|
||||
|
||||
if (list.Size() >= lm_background_updates)
|
||||
break;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
}
|
||||
|
||||
screen->UpdateLightmaps(list);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
|
@ -199,24 +226,7 @@ sector_t* RenderViewpoint(FRenderViewpoint& mainvp, AActor* camera, IntRect* bou
|
|||
screen->NextEye(eyeCount);
|
||||
}
|
||||
|
||||
auto& list = RenderState.GetVisibleSurfaceList();
|
||||
if (list.Size() < lm_background_updates)
|
||||
{
|
||||
int index = 0;
|
||||
for (auto& e : level.levelMesh->Surfaces)
|
||||
{
|
||||
if (e.needsUpdate)
|
||||
{
|
||||
list.Push(index);
|
||||
|
||||
if(list.Size() >= lm_background_updates)
|
||||
break;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
}
|
||||
|
||||
screen->UpdateLightmaps(list);
|
||||
UpdateLightmaps(screen, RenderState);
|
||||
|
||||
return mainvp.sector;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue