载入中...
搜索中...
未找到
FractureDepth.cpp
浏览该文件的文档.
1#include <algorithm>
2#include <exception>
3#include <functional>
4#include <glm/mat4x4.hpp>
5#include "graphics/Graphics.h"
8namespace eve::physics {
12eve::Result<void> GeometryCollectionRenderer::registerDepthContribution() {
13 if (depthRegistration_) return eve::Result<void>::success();
14 // The legacy GBuffer hook has process lifetime. Install exactly one dispatcher;
15 // it owns no renderer, mesh or Graphics. Expired weak leases are pruned on
16 // registration and dispatch, so repeated scenes do not accumulate callbacks.
17 static std::vector<std::weak_ptr<DepthRegistration>> registrations;
18 static bool installed = false;
19 try {
20 auto candidate = std::make_shared<DepthRegistration>();
21 candidate->drawer = [this](graphics::Graphics& target, const graphics::Camera3D::Data& camera,
22 const glm::mat4& vp, float) {
23 if (!submitted_ || &target != meshOwner_) return;
24 for (const auto& batch : fragmentBatches_) {
25 if (!batch.mesh) continue;
26 auto color = batch.interior ? std::array<float, 4>{interiorR_, interiorG_, interiorB_, interiorA_}
27 : std::array<float, 4>{exteriorR_, exteriorG_, exteriorB_, exteriorA_};
28 if (!batch.interior)
29 if (auto found = groupColors_.find(batch.groupId); found != groupColors_.end())
30 color = found->second;
31 target.drawMeshGBuffer(batch.mesh, vp, glm::mat4(1.f), camera.nearZ, camera.farZ, nullptr, color[0],
32 color[1], color[2], 0.f, 0.f, .85f, 0.f);
33 }
34 };
35 if (!installed) {
38 const glm::mat4& vp, float aspect) {
39 std::erase_if(registrations, [](const auto& weak) { return weak.expired(); });
40 for (const auto& weak : registrations)
41 if (auto live = weak.lock()) live->drawer(target, camera, vp, aspect);
42 });
43 installed = true;
44 }
45 std::erase_if(registrations, [](const auto& weak) { return weak.expired(); });
46 registrations.push_back(candidate);
47 depthRegistration_ = std::move(candidate);
49 } catch (const std::exception& error) {
52 }
53}
54} // namespace eve::physics
LogicalId target
std::vector< std::unique_ptr< ScriptClimbingEventSink > > live
float camera[2]
std::string error
Definition Package.cpp:174
bool found
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
static void addGBufferExtraDrawer(GBufferExtraDrawer drawer)
Adds g buffer extra drawer.
std::function< void(Graphics &gfx, const Camera3D::Data &cam, const glm::mat4 &viewProj, float aspect)> GBufferExtraDrawer
Register a callback that fills the G-buffer (depth/normal/albedo) for geometry outside the Renderable...
Optional physics backend for vehicle mobility and body attach.
Definition Climbing.h:36
graphics::RenderSystem3D::GBufferExtraDrawer drawer
glm::vec4 color