clean-up LightData

remove unused code and fields, make it a value-object.

Change-Id: I52e611a1d64061c89a8ed82017a5da04f1880836
This commit is contained in:
Mathias Agopian
2018-08-06 15:16:27 -07:00
committed by Romain Guy
parent 94c3623c1c
commit ac24fc3e30
4 changed files with 31 additions and 47 deletions

View File

@@ -18,10 +18,9 @@
#include "details/Engine.h"
#include <private/filament/UibGenerator.h>
#include <filament/EngineEnums.h>
#include <utils/architecture.h>
#include <utils/Panic.h>
#include <private/filament/UibGenerator.h>
namespace filament {
@@ -30,24 +29,28 @@ using namespace driver;
namespace details {
LightData::LightData(FEngine& engine) noexcept
: mEngine(engine),
mLightUib(UibGenerator::getLightsUib()),
mLightsUb(mLightUib)
{
DriverApi& driverApi = mEngine.getDriverApi();
mLightUbh = driverApi.createUniformBuffer(mLightUib.getSize());
: mLightsUb(UibGenerator::getLightsUib()) {
DriverApi& driverApi = engine.getDriverApi();
mLightUbh = driverApi.createUniformBuffer(mLightsUb.getSize());
driverApi.bindUniforms(BindingPoints::LIGHTS, mLightUbh);
}
LightData::~LightData() noexcept = default;
void LightData::terminate() {
DriverApi& driverApi = mEngine.getDriverApi();
void LightData::terminate(FEngine& engine) {
DriverApi& driverApi = engine.getDriverApi();
driverApi.destroyUniformBuffer(mLightUbh);
}
void LightData::commitSlow() noexcept {
DriverApi& driverApi = mEngine.getDriverApi();
void LightData::commit(FEngine& engine) noexcept {
if (UTILS_UNLIKELY(mLightsUb.isDirty())) {
commitSlow(engine);
}
engine.getDriverApi().bindUniforms(BindingPoints::LIGHTS, mLightUbh);
}
void LightData::commitSlow(FEngine& engine) noexcept {
DriverApi& driverApi = engine.getDriverApi();
driverApi.updateUniformBuffer(mLightUbh, UniformBuffer(mLightsUb));
mLightsUb.clean();
}

View File

@@ -41,9 +41,9 @@ namespace details {
// ------------------------------------------------------------------------------------------------
FScene::FScene(FEngine& engine) :
mEngine(engine) {
mGpuLightData = std::make_unique<LightData>(engine);
mIndirectLight = engine.getDefaultIndirectLight();
mEngine(engine),
mIndirectLight(engine.getDefaultIndirectLight()),
mGpuLightData(engine) {
}
FScene::~FScene() noexcept = default;
@@ -164,12 +164,13 @@ void FScene::updateUBOs(utils::Range<uint32_t> visibleRenderables) const noexcep
}
void FScene::terminate(FEngine& engine) {
mGpuLightData->terminate(); // free-up the lights buffer
// free-up the lights buffer
mGpuLightData.terminate(engine);
}
void FScene::prepareLights(const CameraInfo& camera) noexcept {
FLightManager& lcm = mEngine.getLightManager();
LightData* const gpuLightData = mGpuLightData.get();
LightData& gpuLightData = mGpuLightData;
FScene::LightSoa& lightData = getLightData();
/*
@@ -213,7 +214,7 @@ void FScene::prepareLights(const CameraInfo& camera) noexcept {
auto const* UTILS_RESTRICT instances = lightData.data<FScene::LIGHT_INSTANCE>();
for (size_t i = DIRECTIONAL_LIGHTS_COUNT, c = lightData.size(); i < c; ++i) {
LightData::LightIndex gpuIndex = LightData::LightIndex(i - DIRECTIONAL_LIGHTS_COUNT);
LightData::LightParameters& lp = gpuLightData->getLightParameters(gpuIndex);
LightData::LightParameters& lp = gpuLightData.getLightParameters(gpuIndex);
auto li = instances[i];
lp.positionFalloff = { positions[i].xyz, lcm.getSquaredFalloffInv(li) };
lp.colorIntensity = { lcm.getColor(li), lcm.getIntensity(li) };
@@ -221,8 +222,8 @@ void FScene::prepareLights(const CameraInfo& camera) noexcept {
lp.spotScaleOffset.xy = { lcm.getSpotParams(li).scaleOffset };
}
gpuLightData->invalidate(0, lightData.size());
gpuLightData->commit();
gpuLightData.invalidate(0, lightData.size());
gpuLightData.commit(mEngine);
}
void FScene::addEntity(Entity entity) {

View File

@@ -17,23 +17,11 @@
#ifndef TNT_FILAMENT_DETAILS_LIGHTDATA_H
#define TNT_FILAMENT_DETAILS_LIGHTDATA_H
#include "details/Engine.h"
#include <filament/EngineEnums.h>
#include <filament/LightManager.h>
#include <private/filament/UibGenerator.h>
#include <driver/Handle.h>
#include <driver/UniformBuffer.h>
#include <utils/compiler.h>
#include <math/vec4.h>
#include <bitset>
namespace filament {
namespace details {
@@ -52,15 +40,9 @@ public:
explicit LightData(FEngine& engine) noexcept;
void commit() noexcept {
if (UTILS_UNLIKELY(mLightsUb.isDirty())) {
commitSlow();
}
mEngine.getDriverApi().bindUniforms(BindingPoints::LIGHTS, mLightUbh);
}
void terminate();
void commit(FEngine& engine) noexcept;
void terminate(FEngine& engine);
LightData(LightData const& rhs) = delete;
LightData(LightData&& rhs) = delete;
@@ -68,7 +50,7 @@ public:
LightData& operator=(LightData&& rhs) = delete;
~LightData() noexcept;
LightParameters& getLightParameters(LightIndex h) {
LightParameters& getLightParameters(LightIndex h) noexcept {
// This assumes the layout of the LightsUniforms uniform buffer
// it is defined in UibGenerator.cpp
LightParameters* lights = (LightParameters *)mLightsUb.getBuffer();
@@ -80,10 +62,7 @@ public:
}
private:
void commitSlow() noexcept;
FEngine& mEngine;
UniformInterfaceBlock& mLightUib;
void commitSlow(FEngine& engine) noexcept;
Handle<HwUniformBuffer> mLightUbh;
mutable UniformBuffer mLightsUb;
};

View File

@@ -23,6 +23,7 @@
#include "components/TransformManager.h"
#include "details/Culler.h"
#include "details/LightData.h"
#include <filament/Box.h>
#include <filament/Scene.h>
@@ -161,7 +162,7 @@ private:
FEngine& mEngine;
FSkybox const* mSkybox = nullptr;
FIndirectLight const* mIndirectLight = nullptr;
std::unique_ptr<LightData> mGpuLightData;
LightData mGpuLightData;
// list of Entities in the scene. We use a robin_set<> so we can do efficient removes
// (a vector<> could work, but removes would be O(n)). robin_set<> iterates almost as