AGENT SKILL

Filament 对象生命周期管理

filament-lifetime

确保 Filament 对象创建与销毁生命周期的正确性。在初始化渲染管线或分配/释放 GPU 缓冲区和实体(entity)时使用此技能。

使用场景C++ 开发
License 许可
Apache-2.0
所属仓库
google/filament
最近更新
2026-11-14
Stars
★ 2.1w
Forks
2.3k

01 前言 Front Matter

name
filament-lifetime
description
Enforce correct Filament object creation and destruction lifecycles. Use this skill when initializing rendering pipelines or allocating/deallocating GPU buffers and entities.

03 SKILL.md 正文

Filament object creation and destruction lifecycles

Filament manages its own native allocations. To prevent segmentation faults and memory leaks, follow these rules:

1. ECS Entities & Components

Getting the Entity Manager

  • Preferred Method: Retrieve the EntityManager directly from the Engine instance: utils::EntityManager& em = engine->getEntityManager();
  • Alternative (Avoid if engine is available): Only use the global singleton if the Engine pointer is inaccessible: utils::EntityManager& em = utils::EntityManager::get();

Entities

  • Create: Create Entity IDs using the entity manager: utils::Entity entity = engine->getEntityManager().create();
  • Destroy: Free the Entity ID from the entity manager: engine->getEntityManager().destroy(entity);

Components

  • Create: Attach components to an existing entity using manager builders:
    • Renderables/Lights: Use RenderableManager::Builder or LightManager::Builder on the entity:
      RenderableManager::Builder(1)
          .geometry(0, RenderableManager::PrimitiveType::TRIANGLES, vb, ib)
          .material(0, matInstance)
          .build(*engine, entity);
      
    • Cameras: Attach a Camera component to the entity: Camera* camera = engine->createCamera(entity);
  • Destroy (CRITICAL):
    1. To clean up the entire entity: First, destroy all Filament-managed components on the entity: engine->destroy(entity); Second, free the Entity ID: engine->getEntityManager().destroy(entity);
      // Correct Entity Cleanup
      engine->destroy(myEntity);
      engine->getEntityManager().destroy(myEntity);
      
    2. To remove a single component from the entity: You can destroy specific components individually without deleting the entity:
      • Cameras: engine->destroyCameraComponent(entity);
      • Transforms: engine->getTransformManager().destroy(entity);
      • Renderables: engine->getRenderableManager().destroy(entity);

2. Engine-Managed Native Objects

Native GPU objects are created using the Engine factory or nested Builder patterns.

  • NO delete: Never call standard C++ delete on pointers returned by Engine.
  • Direct Factories: Instantiated directly from the Engine instance.
    • Objects: View, Scene, Renderer, SwapChain.
    • Pattern:
      View* view = engine->createView();
      // ...
      engine->destroy(view);
      
  • Builder Pattern: Instantiated using a nested Builder class, passing the engine instance to build(*engine).
    • Objects: VertexBuffer, IndexBuffer, Texture, Material, IndirectLight, Skybox, RenderTarget.
    • Pattern:
      VertexBuffer* vb = VertexBuffer::Builder()
          .vertexCount(count)
          .bufferCount(1)
          .attribute(VertexAttribute::POSITION, 0, VertexBuffer::AttributeType::FLOAT3)
          .build(*engine);
      // ...
      engine->destroy(vb);
      

04 同仓库更多 Skills

google
google/filament

Filament 数学运算与坐标变换

filament-math

确保 Filament 代码中数学原语和命名约定的正确性。在执行坐标变换、向量运算或投影设置时使用此技能。

软件开发工程师C++ 开发
★ 2.1w
google
google/filament

Git 提交 cherry-pick 与回填

cherry-pick

将某个提交 cherry-pick 到另一个分支并创建 PR。当用户要求将某个提交或 PR cherry-pick 或回填(backport)到发布分支时使用。

软件开发工程师代码仓库协作管理
★ 2.1w
google
google/filament

C++ 代码验证流程

verification-protocols

修改 C++ 源文件或头文件后需执行的标准验证流程。使用此技能格式化 include 语句、构建引擎并运行核心测试。

软件开发工程师C++ 开发
★ 2.1w
google
google/filament

C++ 预处理保护规范检查

preprocessor-guard-hygiene

在 C++ 中强制实施预处理保护(preprocessor guard)规则以及依赖宏的包含卫生规范。在修改条件导入或预处理指令时使用此技能。

软件开发工程师C++ 开发
★ 2.1w
google
google/filament

C++ 头文件自包含检查

header-self-containment

强制实施严格的头文件自包含规范,确保每个头文件都能独立编译。在创建或修改 C++ 头文件时使用此技能。

软件开发工程师C++ 开发
★ 2.1w
google
google/filament

Filament 桌面端测试

filament-desktop-testing

在桌面平台执行 Filament 的单元测试和性能基准测试。使用此技能在本地运行并筛选测试或基准测试。

测试工程师测试与质量保障
★ 2.1w