载入中...
搜索中...
未找到
EvpackStaticPrefab.cpp
浏览该文件的文档.
151PreparedStaticPrefabScene::PreparedStaticPrefabScene(std::unique_ptr<Impl> impl) : impl_(std::move(impl)) {}
157const std::vector<StaticPrefabScenePart>& PreparedStaticPrefabScene::parts() const noexcept { return impl_->parts; }
173 const std::shared_ptr<EvpackStaticPrefab>& owner, graphics::Graphics& graphics, PrefabRootPose rootPose) {
174 if (rootPose != PrefabRootPose::Authored && rootPose != PrefabRootPose::ReplaceTranslationRotation)
180 if (owner->impl_->draws.size() > 65536 || owner->impl_->resourcePins == std::numeric_limits<std::size_t>::max())
182 Diagnostic::error(DiagnosticCode::PreconditionViolation, "prefab scene preparation budget exceeded"));
184 std::make_unique<PreparedStaticPrefabScene::Impl>(PreparedStaticPrefabScene::Impl{owner, graphics})));
188 DiagnosticCode::Unsupported, "TVE prefab scene parts require the vegetation deformation adapter"));
190 material->setTint(draw.material.color.r, draw.material.color.g, draw.material.color.b, draw.material.color.a);
199 material->setBlendMode(draw.material.blend == graphics::BlendMode::Premultiplied ? "premultiplied"
205 if (!surface.ok()) return Result<std::unique_ptr<PreparedStaticPrefabScene>>::failure(surface.status());
207 const auto& local = rootPose == PrefabRootPose::Authored ? draw.transform : draw.placementTransform;
229 if (rootPose != PrefabRootPose::Authored && rootPose != PrefabRootPose::ReplaceTranslationRotation)
234 DiagnosticCode::NotFound, "prefab has no enabled renderer bounds", {}, {}, "asset.graphics.prefab"));
235 return Result<std::array<float, 6>>::success(rootPose == PrefabRootPose::Authored ? impl_->localBounds
274Result<std::vector<StaticPrefabGpuPart>> EvpackStaticPrefab::prepareGpuDriven(graphics::Graphics& gfx) {
277 DiagnosticCode::InvalidArgument, "prefab resources have been released", {}, {}, "asset.graphics.prefab"));
280 Diagnostic::error(DiagnosticCode::InvalidArgument, "prefab GPU-driven parts are already registered", {}, {},
289 DiagnosticCode::InvalidArgument, "transparent prefab Detail cannot use opaque GPU submission", {}, {},
306 !conventionalBinding(draw.material.surface.textures[std::size_t(graphics::PbrTextureSlot::Normal)]))
308 DiagnosticCode::InvalidArgument, "extended prefab material requires a GPU-driven PBR surface record",
311 material->setTint(draw.material.color.r, draw.material.color.g, draw.material.color.b, draw.material.color.a);
322 DiagnosticCode::InvalidArgument, "prefab material is unavailable to GPU-driven rendering", {}, {},
326 const auto releaseRegistered = [&gfx](const std::vector<std::unique_ptr<graphics::Material>>& owned,
338 std::copy(glm::value_ptr(draw.transform), glm::value_ptr(draw.transform) + 16, part.localTransform.begin());
341 if (part.meshId == graphics::kInvalidGpuDrivenSlot || part.materialId == graphics::kInvalidGpuDrivenSlot) {
345 Diagnostic::error(DiagnosticCode::InvalidArgument, "prefab GPU table registration failed", {}, {},
352 DiagnosticCode::InvalidArgument, "prefab has no enabled renderer", {}, {}, "asset.graphics.prefab"));
357Result<std::unique_ptr<EvpackStaticPrefab>> EvpackStaticPrefab::load(const asset::EvpackResourceReader& reader,
367 std::unique_ptr<EvpackStaticPrefab>(new EvpackStaticPrefab(std::make_unique<Impl>(Impl{meshes, images})));
403 if (frame.root && (std::fabs(world[3][0] - node.x) > 1e-4f || std::fabs(world[3][1] - node.y) > 1e-4f ||
418 if (!parameters) return Result<std::unique_ptr<EvpackStaticPrefab>>::failure(parameters.status());
434 Diagnostic::error(DiagnosticCode::InvalidArgument, "material references missing mesh UV channel",
454 parameters.value().surface.vegetationDetail.textures[role].texture = out->impl_->imageLeases.at(imageKey);
457 if (!validatedSurface) return Result<std::unique_ptr<EvpackStaticPrefab>>::failure(validatedSurface.status());
474Result<void> EvpackStaticPrefab::draw(graphics::Graphics& gfx, const std::array<float, 16>& transform,
478 DiagnosticCode::InvalidArgument, "prefab resources have been released", {}, {}, "asset.graphics.prefab"));
482 DiagnosticCode::InvalidArgument, "nonfinite instance transform", {}, {}, "asset.graphics.prefab"));
485 return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, "nonfinite camera view", {},
525 DiagnosticCode::InvalidArgument, "prefab resources have been released", {}, {}, "asset.graphics.prefab"));
529 DiagnosticCode::InvalidArgument, "nonfinite instance transform", {}, {}, "asset.graphics.prefab"));
533 DiagnosticCode::InvalidArgument, "nonfinite shadow view projection", {}, {}, "asset.graphics.prefab"));
EVEngine assertion entry point, backed by zeroerr.
#define EV_ASSERT(cond,...)
Assert an internal engine invariant (state that must always hold).
Definition Assert.h:37
Transactional graphics consumers for canonical runtime assets.
Transactional EVIMG runtime texture loading.
Runtime decoding of canonical scene templates.
JSON-free versioned runtime metadata codec.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.cpp:21
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
Immutable reader retaining an admitted pack by shared ownership.
Definition EvpackResourceReader.h:29
Result< PersistentId > buildId() const
Copy the deterministic build identity of the admitted immutable package.
Definition EvpackResourceReader.h:37
Owning static-prefab GPU leases and immutable draw transforms; no ECS or Scene mutation....
Definition EvpackStaticPrefab.h:91
static Result< std::unique_ptr< EvpackStaticPrefab > > load(const asset::EvpackResourceReader &reader, graphics::IMeshResourceFactory &meshes, graphics::IImageResourceFactory &images, const AssetRef &asset, const asset::EvpackCapabilities &capabilities)
Validate a template and stage its mesh, material and image dependencies; failures release staged uplo...
Definition EvpackStaticPrefab.cpp:357
std::size_t drawCount() const noexcept
Number of enabled static renderer bindings prepared for drawing.
Definition EvpackStaticPrefab.cpp:225
PersistentId sourceBuildId() const noexcept
Copy the admitted deterministic package build identity; constant-time, no IO or callbacks....
Definition EvpackStaticPrefab.cpp:227
Result< std::vector< StaticPrefabGpuPart > > prepareGpuDriven(graphics::Graphics &graphics)
Register every opaque or masked prefab draw in GPU-driven tables transactionally.
Definition EvpackStaticPrefab.cpp:274
friend class StaticPrefabResourcePin
Definition EvpackStaticPrefab.h:178
AssetRef sourceAsset() const
Copy the admitted source asset identity; immutable and valid after GPU release. @thread Any thread af...
Definition EvpackStaticPrefab.cpp:226
static Result< std::unique_ptr< PreparedStaticPrefabScene > > prepareScene(const std::shared_ptr< EvpackStaticPrefab > &owner, graphics::Graphics &graphics, PrefabRootPose rootPose=PrefabRootPose::Authored)
Prepare complete scene-renderer materials and local transforms while pinning loaded prefab resources.
Definition EvpackStaticPrefab.cpp:172
Result< void > release()
Invalidate draw packets and release all leases; failed releases remain owned for retry.
Definition EvpackStaticPrefab.cpp:238
static Result< std::unique_ptr< StaticPrefabResourcePin > > pinResources(const std::shared_ptr< EvpackStaticPrefab > &owner)
Retain loaded resources for an admitted version without creating renderer/material inputs.
Definition EvpackStaticPrefab.cpp:133
Result< std::array< float, 6 > > localBounds(PrefabRootPose rootPose=PrefabRootPose::Authored) const
Copy prefab-local min XYZ/max XYZ enclosing enabled renderer geometry and hierarchy transforms.
Definition EvpackStaticPrefab.cpp:228
EvpackStaticPrefab(const EvpackStaticPrefab &)=delete
Owning preparation lease pinning prefab GPU resources and complete scene materials....
Definition EvpackStaticPrefab.h:58
PreparedStaticPrefabScene(const PreparedStaticPrefabScene &)=delete
Result< void > release()
Release after all borrowed parts are unlinked; failed material cleanup retains state for retry.
Definition EvpackStaticPrefab.cpp:158
const std::vector< StaticPrefabScenePart > & parts() const noexcept
Borrow prepared renderer parts until release/destruction; no callbacks or per-frame lookup.
Definition EvpackStaticPrefab.cpp:157
~PreparedStaticPrefabScene()
Release material records and the prefab pin; reports cleanup errors to stderr on destruction.
Definition EvpackStaticPrefab.cpp:152
StaticPrefabResourcePin(const StaticPrefabResourcePin &)=delete
~StaticPrefabResourcePin()
Drop the pin; the final prefab owner may release GPU resources. @cost Fixed counter work; final-owner...
Definition EvpackStaticPrefab.cpp:129
Capability-aware scene-template/3 decoder with explicit scene-template/2 compatibility.
Definition EvpackSceneTemplateLoader.h:38
Result< LoadedSceneTemplate > load(const AssetRef &sceneTemplate, const asset::EvpackCapabilities &capabilities, const SceneTemplateLoadLimits &limits={}) const
Validate identities, hierarchy and finite TRS values before building a tree.
Definition EvpackSceneTemplateLoader.cpp:56
Definition Graphics.h:134
virtual void setMesh3DMaterial(float metallic, float roughness)=0
Metallic (0..1) and roughness (0..1) for the next default mesh draw.
virtual void drawMeshShadow(Mesh *mesh, const glm::mat4 &lightMVP, bool doubleSided=true)=0
Queue an opaque shadow caster.
virtual void drawMesh(Mesh *mesh, const glm::mat4 &model, Texture *texture, const Color &tint)=0
Draw one mesh with model matrix. Requires begin3DFrame() (or an open swapchain pass).
virtual void drawMeshShadowAlpha(Mesh *mesh, const glm::mat4 &lightMVP, Texture *albedo=nullptr, bool doubleSided=true, float lodWeight=1.f, bool lodFadeReverse=false, bool lodDither=false)=0
Shadow pass draw with alpha-cutout discard (card/billboard geometry such as sprite-stack slices): tra...
virtual Result< void > setMesh3DPbrSurface(const PbrSurface *surface)
Copy a validated extended surface for subsequent draws; null resets to legacy shading.
Definition Graphics.h:1253
virtual uint32_t gpuDrivenMeshRecord(Mesh *mesh)
GPU mesh-table slot for a mesh (kInvalidGpuDrivenSlot when not uploaded).
Definition Graphics.h:296
virtual bool gpuDrivenMaterialUsable(Material *material)
Whether a material can be shaded by the GPU-driven opaque path. Backends/drivers with descriptor-inde...
Definition Graphics.h:326
virtual void setMesh3DTexCellBomb(float cellScale, float strength, float rotAmount=1.f)=0
Texture cell bombing for the next default mesh draw (breaks tiling). cellScale: cells per UV unit (ty...
virtual void setMesh3DParallax(float scale, float minLayers=8.f, float maxLayers=32.f)=0
Parallax occlusion mapping for the next default mesh draw. scale: UV displacement strength (0=off)....
virtual void setMesh3DVirtualTexture(bool enabled, int pageCountX, int pageCountY, int atlasSlotsX, int atlasSlotsY, float borderFraction)=0
Configure page-table sampling for the next mesh draw.
virtual void setMesh3DSurface(SurfaceMode mode, BlendMode blend, bool depthWrite, bool doubleSided, float alphaCutoff, const std::string &alphaTechnique="cutoff")=0
Select pipeline state for subsequent mesh draws.
virtual uint32_t gpuDrivenMaterialRecord(Material *material)
GPU material-table slot for a material (lazily created).
Definition Graphics.h:302
virtual void setMesh3DShadowReceive(bool receive)=0
Per-draw: when false, shadow sampling is forced off for the next mesh draw.
virtual Result< void > gpuDrivenReleaseMaterialRecord(Material *material)
Release a lazily-created GPU material-table record.
Definition Graphics.h:314
virtual void setMesh3DNormalTexture(Texture *normal)=0
Optional normal map for the next drawMesh / drawMeshShader (nullptr = flat).
virtual void setMesh3DHeightTexture(Texture *height)=0
Optional height map for parallax (R channel; nullptr = flat / off).
Backend-owned RGBA8 texture upload and release operations.
Definition IImageResourceFactory.h:15
Backend-owned mesh upload and release operations.
Definition IMeshResourceFactory.h:15
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:15
Definition CookedMaterial.cpp:5
@ TangentXYZ
@ Inherit
@ Transparent
Result< void > validatePbrSurface(const PbrSurface &s)
Validate finite material factors and sampler enums without changing the input.
Definition PbrGpuUniform.cpp:124
constexpr uint32_t kInvalidGpuDrivenSlot
GPU-driven API surface without GLM layout records.
Definition GpuDrivenApi.h:17
@ InvalidArgument
@ NotFound
@ PreconditionViolation
@ Unsupported
@ Failed
PrefabRootPose
Immutable prefab placement convention shared by geometry bounds and renderer preparation....
Definition PrefabRootPose.h:11
@ ReplaceTranslationRotation
@ Authored
Definition Container.h:602
Actual runtime device capabilities used for variant selection.
Definition Evpack.h:92
graphics::Texture * image
Definition EvpackStaticPrefab.cpp:116
glm::mat4 transform
Definition EvpackStaticPrefab.cpp:113
glm::mat4 placementTransform
Definition EvpackStaticPrefab.cpp:114
bool receiveShadows
Definition EvpackStaticPrefab.cpp:119
graphics::Mesh * mesh
Definition EvpackStaticPrefab.cpp:115
MaterialData material
Definition EvpackStaticPrefab.cpp:117
bool castShadows
Definition EvpackStaticPrefab.cpp:118
std::map< std::string, graphics::Texture * > imageLeases
Definition EvpackStaticPrefab.cpp:111
std::map< std::string, graphics::Mesh * > meshLeases
Definition EvpackStaticPrefab.cpp:103
bool hasLocalBounds
Definition EvpackStaticPrefab.cpp:108
std::size_t resourcePins
Definition EvpackStaticPrefab.cpp:125
PersistentId sourceBuild
Definition EvpackStaticPrefab.cpp:110
bool released
Definition EvpackStaticPrefab.cpp:124
std::vector< std::unique_ptr< graphics::Material > > gpuMaterials
Definition EvpackStaticPrefab.cpp:122
std::optional< AssetRef > sourceAsset
Definition EvpackStaticPrefab.cpp:109
graphics::Graphics * gpuGraphics
Definition EvpackStaticPrefab.cpp:123
graphics::IImageResourceFactory & images
Definition EvpackStaticPrefab.cpp:101
graphics::IMeshResourceFactory & meshes
Definition EvpackStaticPrefab.cpp:100
std::map< std::string, std::vector< uint32_t > > meshUvSets
Definition EvpackStaticPrefab.cpp:104
std::array< float, 6 > localBounds
Definition EvpackStaticPrefab.cpp:106
std::map< std::string, std::array< float, 6 > > meshBounds
Definition EvpackStaticPrefab.cpp:105
std::array< float, 6 > placementBounds
Definition EvpackStaticPrefab.cpp:107
std::vector< Draw > draws
Definition EvpackStaticPrefab.cpp:121
std::shared_ptr< EvpackStaticPrefab > owner
Definition EvpackStaticPrefab.cpp:145
std::vector< std::unique_ptr< graphics::Material > > materials
Definition EvpackStaticPrefab.cpp:147
std::vector< StaticPrefabScenePart > parts
Definition EvpackStaticPrefab.cpp:148
graphics::Graphics & graphics
Definition EvpackStaticPrefab.cpp:146
One prefab renderer registered in backend GPU-driven tables.
Definition EvpackStaticPrefab.h:80
std::uint32_t meshId
Definition EvpackStaticPrefab.h:82
std::array< float, 16 > localTransform
Definition EvpackStaticPrefab.h:81
std::uint32_t materialId
Definition EvpackStaticPrefab.h:82
Renderer inputs borrowed from PreparedStaticPrefabScene until its release/destruction.
Definition EvpackStaticPrefab.h:48
graphics::Material * material
Definition EvpackStaticPrefab.h:51
graphics::Mesh * mesh
Definition EvpackStaticPrefab.h:50
bool receiveShadows
Definition EvpackStaticPrefab.h:52
std::array< float, 16 > localTransform
Definition EvpackStaticPrefab.h:49
bool castShadows
Definition EvpackStaticPrefab.h:52
One borrowed texture plus independently owned UV/sampler parameters. Texture is graphics-factory-owne...
Definition PbrSurface.h:39
Declarative scene-node description (build once / on dirty → flatten into SceneHost::Tree)....
Definition NodeDesc.h:19