diff --git a/cocos/game/director.ts b/cocos/game/director.ts index efa8f7163f6..038a4a0f916 100644 --- a/cocos/game/director.ts +++ b/cocos/game/director.ts @@ -809,7 +809,7 @@ export class Director extends EventTarget { * @en Build custom render pipeline * @zh 构建自定义渲染管线 */ - private buildRenderPipeline (): void { + public buildRenderPipeline (): void { if (!this._root) { return; } @@ -831,11 +831,6 @@ export class Director extends EventTarget { // 2. cclegacy.rendering is available // 3. The root node is created and uses custom pipeline if (macro.CUSTOM_PIPELINE_NAME !== '' && cclegacy.rendering && this._root && this._root.usesCustomPipeline) { - this.on( - DirectorEvent.BEFORE_RENDER, - this.buildRenderPipeline, - this, - ); this.on( DirectorEvent.BEFORE_SCENE_LAUNCH, cclegacy.rendering.forceResizeAllWindows, diff --git a/cocos/rendering/custom/web-pipeline.ts b/cocos/rendering/custom/web-pipeline.ts index 8f0472aea82..338491cb96d 100644 --- a/cocos/rendering/custom/web-pipeline.ts +++ b/cocos/rendering/custom/web-pipeline.ts @@ -1516,7 +1516,8 @@ export class WebPipeline implements BasicPipeline { ); } beginFrame (): void { - // noop + const director: Director = cclegacy.director; + director.buildRenderPipeline(); } update (camera: Camera): void { // noop diff --git a/cocos/root.jsb.ts b/cocos/root.jsb.ts index 95f388bb2cd..c35e8f1d10e 100644 --- a/cocos/root.jsb.ts +++ b/cocos/root.jsb.ts @@ -118,6 +118,11 @@ rootProto.createModel = function (ModelCtor) { return model; }; +jsb.buildRenderPipeline = function () { + const director = cclegacy.director; + director.buildRenderPipeline(); +} + rootProto.destroyModel = function (m) { const p = this._modelPools.get(m.constructor); if (p) { diff --git a/native/cocos/renderer/pipeline/custom/NativePipeline.cpp b/native/cocos/renderer/pipeline/custom/NativePipeline.cpp index 94af3b5659e..877a0270735 100644 --- a/native/cocos/renderer/pipeline/custom/NativePipeline.cpp +++ b/native/cocos/renderer/pipeline/custom/NativePipeline.cpp @@ -39,6 +39,7 @@ #include "cocos/scene/ReflectionProbeManager.h" #include "cocos/scene/RenderScene.h" #include "cocos/scene/RenderWindow.h" +#include "bindings/jswrapper/SeApi.h" #if CC_USE_DEBUG_RENDERER #include "profiler/DebugRenderer.h" @@ -1310,6 +1311,19 @@ void buildLayoutGraphNodeBuffer( } } +se::Value buildRPVal; +void buildRenderPipeline() { + if (buildRPVal.isUndefined()) { + auto global = se::ScriptEngine::getInstance()->getGlobalObject(); + se::Value jsbVal; + if(global->getProperty("jsb", &jsbVal) && jsbVal.isObject()) { + jsbVal.toObject()->getProperty("buildRenderPipeline", &buildRPVal); + } + } + se::ValueArray args; + buildRPVal.toObject()->call(args, nullptr); +} + } // namespace // NOLINTNEXTLINE @@ -1491,7 +1505,7 @@ void NativePipeline::render(const ccstd::vector &cameras) { std::ignore = cameras; const auto *sceneData = pipelineSceneData.get(); auto *commandBuffer = device->getCommandBuffer(); - + buildRenderPipeline(); executeRenderGraph(renderGraph); }