载入中...
搜索中...
未找到
OceanHullMaskPublication.cpp
浏览该文件的文档.
1#include <bit>
2#include <exception>
5#include "graphics/Graphics.h"
6#include "graphics/Texture.h"
7
8namespace eve::fluids {
11 auto& state = *renderer_.impl_;
12 auto fail = [](DiagnosticCode code, const char* message) {
13 return Result<void>::failure(Diagnostic::error(code, message, "fluids.ocean.hull"));
14 };
15 if (state.lifetime.expired()) return fail(DiagnosticCode::StaleHandle, "Graphics retired");
16 if (frame_.size() == 0) {
17 state.hullPublished = false;
18 return Result<void>::success();
19 }
20 std::vector<std::uint8_t> pixels(4 * 545 * 4, 0);
21 auto put = [&](std::size_t scalar, float value) {
22 const auto bits = std::bit_cast<std::uint32_t>(value);
23 for (unsigned channel = 0; channel < 4; ++channel)
24 pixels[scalar * 4 + channel] = static_cast<std::uint8_t>((bits >> (8 * channel)) & 255U);
25 };
26 put(0, static_cast<float>(frame_.size()));
27 for (std::size_t row = 0; row < frame_.rows().size(); ++row)
28 for (unsigned col = 0; col < 4; ++col) put((row + 1) * 4 + col, frame_.rows()[row][col]);
29 const unsigned back = 1 - state.hullFront;
30 try {
31 if (!state.hullMask[back]) {
34 state.hullMask[back] = state.graphics->newTexture(4, 545, pixels.data(), info);
35 if (!state.hullMask[back]) return fail(DiagnosticCode::Unsupported, "Hull mask texture unavailable");
36 } else {
37 auto result = state.graphics->updateTextureRegion(state.hullMask[back], 0, 0, 4, 545, pixels);
38 if (!result) return result;
39 }
40 } catch (const std::exception& error) {
41 return fail(DiagnosticCode::Failed, error.what());
42 }
43 state.hullFront = back;
44 state.hullOrigin = frame_.origin();
45 state.hullPublished = true;
46 return Result<void>::success();
47}
48} // namespace eve::fluids
std::string message
DiagnosticCode code
Poco::JSON::Object::Ptr result
ssq::Object frame
std::string error
Definition Package.cpp:174
Object::Ptr value
uint8_t * pixels
float size
Definition TreeMesh.cpp:158
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
Immutable owning render-only union of convex dry volumes. No body handles, callbacks,...
glm::dvec3 origin() const
World origin subtracted before float projection.
unsigned size() const
Number of dry volumes; at most 32.
std::span< const glm::vec4 > rows() const
Borrow packed render-space halfspaces until frame destruction/move. Each volume has seventeen vec4 ro...
Borrowed mask upload; no frame or vessel pointer is retained after publication.
EVENGINE_API_DOMAINS Result< void > publish() const
Upload into the inactive texture and publish only on success; empty clears the mask.
EVENGINE_API_DOMAINS OceanHullMaskPublication hullMaskBuilder(const OceanHullMaskFrame &frame)
Borrow a mask frame for synchronous upload; keep frame and renderer alive until publish returns.
GLSL compute kernels for the GPU surface-flow solver.
Definition FluidTarget.h:12
DiagnosticCode
Stable machine-readable diagnostic codes.
Definition Diagnostic.h:47
Options for Graphics::newTexture / newCubemap. When generateMipmaps is true and sampler....
static TextureSampler nearest()
Nearest.
glm::uvec4 info