Skip to content

Commit

Permalink
[Render/RenderSystem] Moved the camera info sending to the render system
Browse files Browse the repository at this point in the history
- They previously were in the system but have been moved in the render graph when it appeared; this barely made sense as the render system is needed for this anyway

- Removed RenderSystem::sendCameraMatrices()
  - This has long been unused as camera info are sent independently, and should never have been public anyway
  • Loading branch information
Razakhel committed Mar 22, 2024
1 parent 1d128a8 commit a4bde34
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 40 deletions.
2 changes: 1 addition & 1 deletion include/RaZ/Render/RenderSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class RenderSystem final : public System {
#endif
void resizeViewport(unsigned int width, unsigned int height);
bool update(const FrameTimeInfo& timeInfo) override;
void sendCameraMatrices() const;
/// Updates all lights referenced by the RenderSystem, sending their data to the GPU.
void updateLights() const;
void updateShaders() const;
Expand All @@ -82,6 +81,7 @@ class RenderSystem final : public System {
private:
void initialize();
void initialize(unsigned int sceneWidth, unsigned int sceneHeight);
void sendCameraInfo() const;
void sendViewMatrix(const Mat4f& viewMat) const { m_cameraUbo.sendData(viewMat, 0); }
void sendInverseViewMatrix(const Mat4f& invViewMat) const { m_cameraUbo.sendData(invViewMat, sizeof(Mat4f)); }
void sendProjectionMatrix(const Mat4f& projMat) const { m_cameraUbo.sendData(projMat, sizeof(Mat4f) * 2); }
Expand Down
24 changes: 0 additions & 24 deletions src/RaZ/Render/RenderGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,30 +75,6 @@ void RenderGraph::executeGeometryPass(RenderSystem& renderSystem) const {
if (!geometryFramebuffer.isEmpty())
geometryFramebuffer.bind();

auto& camera = renderSystem.m_cameraEntity->getComponent<Camera>();
auto& camTransform = renderSystem.m_cameraEntity->getComponent<Transform>();

renderSystem.m_cameraUbo.bind();

if (camTransform.hasUpdated()) {
if (camera.getCameraType() == CameraType::LOOK_AT)
camera.computeLookAt(camTransform.getPosition());
else
camera.computeViewMatrix(camTransform);

camera.computeInverseViewMatrix();

renderSystem.sendViewMatrix(camera.getViewMatrix());
renderSystem.sendInverseViewMatrix(camera.getInverseViewMatrix());
renderSystem.sendCameraPosition(camTransform.getPosition());

camTransform.setUpdated(false);
}

renderSystem.sendProjectionMatrix(camera.getProjectionMatrix());
renderSystem.sendInverseProjectionMatrix(camera.getInverseProjectionMatrix());
renderSystem.sendViewProjectionMatrix(camera.getProjectionMatrix() * camera.getViewMatrix());

if (renderSystem.hasCubemap())
renderSystem.getCubemap().draw();

Expand Down
46 changes: 32 additions & 14 deletions src/RaZ/Render/RenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ bool RenderSystem::update(const FrameTimeInfo& timeInfo) {
m_timeUbo.sendData(timeInfo.deltaTime, 0);
m_timeUbo.sendData(timeInfo.globalTime, sizeof(float));

sendCameraInfo();

m_renderGraph.execute(*this);

#if defined(RAZ_CONFIG_DEBUG) && !defined(SKIP_RENDERER_ERRORS)
Expand All @@ -66,20 +68,6 @@ bool RenderSystem::update(const FrameTimeInfo& timeInfo) {
return true;
}

void RenderSystem::sendCameraMatrices() const {
assert("Error: A camera must be given to a RenderSystem to send its matrices." && (m_cameraEntity != nullptr));

const auto& camera = m_cameraEntity->getComponent<Camera>();

m_cameraUbo.bind();
sendViewMatrix(camera.getViewMatrix());
sendInverseViewMatrix(camera.getInverseViewMatrix());
sendProjectionMatrix(camera.getProjectionMatrix());
sendInverseProjectionMatrix(camera.getInverseProjectionMatrix());
sendViewProjectionMatrix(camera.getProjectionMatrix() * camera.getViewMatrix());
sendCameraPosition(m_cameraEntity->getComponent<Transform>().getPosition());
}

void RenderSystem::updateLights() const {
ZoneScopedN("RenderSystem::updateLights");

Expand Down Expand Up @@ -252,4 +240,34 @@ void RenderSystem::updateLight(const Entity& entity, unsigned int lightIndex) co
m_lightsUbo.sendData(light.getAngle().value, static_cast<unsigned int>(dataStride + sizeof(Vec4f) * 3 + sizeof(float)));
}

void RenderSystem::sendCameraInfo() const {
assert("Error: A camera must be given to a RenderSystem to send its info." && (m_cameraEntity != nullptr));

ZoneScopedN("RenderSystem::sendCameraInfo");

auto& camera = m_cameraEntity->getComponent<Camera>();
auto& camTransform = m_cameraEntity->getComponent<Transform>();

m_cameraUbo.bind();

if (camTransform.hasUpdated()) {
if (camera.getCameraType() == CameraType::LOOK_AT)
camera.computeLookAt(camTransform.getPosition());
else
camera.computeViewMatrix(camTransform);

camera.computeInverseViewMatrix();

sendViewMatrix(camera.getViewMatrix());
sendInverseViewMatrix(camera.getInverseViewMatrix());
sendCameraPosition(camTransform.getPosition());

camTransform.setUpdated(false);
}

sendProjectionMatrix(camera.getProjectionMatrix());
sendInverseProjectionMatrix(camera.getInverseProjectionMatrix());
sendViewProjectionMatrix(camera.getProjectionMatrix() * camera.getViewMatrix());
}

} // namespace Raz
1 change: 0 additions & 1 deletion src/RaZ/Script/LuaRenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ void LuaWrapper::registerRenderSystemTypes() {
uint8_t>(&RenderSystem::createWindow));
#endif
renderSystem["resizeViewport"] = &RenderSystem::resizeViewport;
renderSystem["sendCameraMatrices"] = &RenderSystem::sendCameraMatrices;
renderSystem["updateLights"] = &RenderSystem::updateLights;
renderSystem["updateShaders"] = &RenderSystem::updateShaders;
renderSystem["updateMaterials"] = sol::overload([] (const RenderSystem& r) { r.updateMaterials(); },
Expand Down

0 comments on commit a4bde34

Please sign in to comment.