termin-materials intent¶
Дата: 2026-05-19
Статус: декларация о намерениях, не детальный migration checklist.
Обновление 2026-05-19:
- Создан первичный пакет
termin-materials. - В
termin-materialsвынесены C++shader_parser,glsl_preprocessorи Python bindingtermin.materials._materials_native. - В
termin-materialsвынесены Python bindingsTcRenderState,TcMaterialPhase,TcMaterialи material registry helpers. - Построение материала из
ShaderMultyPhaseProgrammвынесено в явный module-level APItermin.materials.create_material_from_parsed(...);TcMaterial.from_parsed(...)оставлен как legacy-forwarder. - Python shader-parser imports внутри
termin-appпереведены на canonicaltermin.materials. TcMaterialbinding больше не зависит от app-levelTextureHandle:set_textureиfrom_parsed(..., textures=...)принимаютTcTexture, а default white/normal texture lookup передается из app слоя черезdefault_white_texture/default_normal_texture.termin._native.renderпока сохраняет исторический export material/shader типов через импортtermin.materials._materials_native; это совместимость существующего пути, не новый owner.- App-level GLSL fallback loader через
ResourceManagerостается вtermin.visualization.render.glsl_preprocessor, потому что это не core material/shader-format логика.
Зачем¶
Текущая граница вокруг material/shader runtime размазана:
- низкоуровневые
tc_material*структуры иTcMaterialhandle лежат вtermin-graphics; - Python bindings
TcMaterial,TcMaterialPhase,TcRenderStateпока живут вtermin-app; - shader parser, GLSL preprocessor/include bank и material UBO synthesis тоже остаются в
termin-app; - render components и visualization импортируют material API через
termin._native.render; - concrete render passes пока смешаны с app/render runtime.
termin-graphics не должен становиться владельцем всей material-семантики. Его ответственность ближе к GPU/device/backend/texture/shader registry primitives. Материал же завязан на наш shader format, phases, render state, uniforms/textures, include/preprocessor rules и layout synthesis. Это отдельный домен.
Цель: выделить material/shader-format слой в самостоятельную библиотеку, условно termin-materials.
Целевая форма слоев¶
termin-graphics
GPU/device/backend/runtime primitives
texture registry and TcTexture
low-level shader registry and TcShader
tgfx2 handles/context/device
termin-materials
TcRenderState
TcMaterialPhase
TcMaterial
material registry API
.shader parser and phase model
GLSL preprocessor/include bank
material UBO layout synthesis
helpers for building material phases from shader sources
termin-render
frame graph
render pipeline contracts
render targets
render engine
pass execution interfaces
termin-passes
concrete pass implementations over termin-render + termin-materials
postprocess passes
scene/material/depth/id/shadow passes, split further if dependencies demand it
termin-components-render
CameraComponent
LightComponent
MeshRenderer and drawable scene components
component bindings over scene + render + materials
termin-materials is not a pass library. Concrete passes should not be moved into it.
Boundary Rules¶
termin-graphics should not know about:
.shaderfile syntax;- material phases as authoring/runtime concept;
- engine include bank;
- material UBO synthesis rules;
- editor/resource-manager fallback behavior.
termin-materials may depend on:
termin-base;termin-graphics;- possibly
termin-inspect, if kind registration is moved there intentionally; - possibly
termin-renderonly if a concrete need appears, but this should be treated with suspicion.
termin-render may depend on material C ABI/types only where pass execution contracts need them. It should not own shader-format parsing or material authoring logic.
termin-passes may depend on:
termin-render;termin-materials;- component libraries required by specific passes.
If pass dependencies become too broad, split pass packages by responsibility instead of pushing everything into termin-render.
Migration Direction¶
Do not add new compatibility wrappers. When a domain moves, replace imports with the canonical path and remove the old binding/module owner where feasible. Existing historical re-exports can be removed later as a separate cleanup step.
Preferred staged migration:
- Create
termin-materialsCMake/Python package. Done: initial package exists. - Move shader-format code from
termin-appintotermin-materials: Partially done for parser/preprocessor. - shader parser;
- GLSL preprocessor;
- include bank;
- material UBO layout synthesis.
- Move Python bindings for material API into
termin-materials: TcRenderState; Done.TcMaterialPhase; Done.TcMaterial; Done.- material registry info functions. Done.
- Replace Python imports from
termin._native.renderto the new canonical material package. - Keep app/resource-manager conveniences outside the core material binding:
- default white/normal texture lookup;
- resource-manager based material resolution;
- editor-only inspection widgets.
- Decide whether the low-level C material storage moves out of
termin-graphics: - short term:
termin-materialscan own the high-level API while using C storage still exported bytermin-graphics; - long term: move
tc_material.h,tc_material_registry.h, andtgfx_material_handle.hppintotermin-materialsif dependency graph allows it cleanly. - After material ownership is clean, revisit concrete render passes and create
termin-passes.
Open Questions¶
- Should
TcShaderstay intermin-graphics, or should shader registry move together with materials? - Should material kind registration live in
termin-materialsor in an inspect integration package? - Should
TcMaterial.from_parsedbe removed entirely after downstream call sites migrate? It is now only a compatibility forwarder tocreate_material_from_parsed. - How much of existing app-level
TextureHandlecompatibility should survive after material extraction? - Do scene/material/depth/id/shadow passes belong in one
termin-passespackage, or should scene-dependent passes be separated from pure postprocess passes?
Current Smells To Watch¶
termin-components-renderstill includes app directories in CMake. This is a migration debt and should be removed.termin._native.renderstill exports material types and many concrete passes.create_material_from_parsedstill does a lot in one function: phase creation, shader feature propagation, material UBO layout upload, default uniform application, texture defaults, and color overrides. The ownership is clearer now, but the implementation should eventually be split into smaller internal helpers.termin-renderis already broad enough; avoid solving pass ownership by adding more concrete pass code there.