From 9a0e6d75248e068a6aeca4d79de395d5bd054763 Mon Sep 17 00:00:00 2001 From: thejinchao Date: Mon, 25 Aug 2025 23:12:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=90=91RenderPipe=E9=9B=86?= =?UTF-8?q?=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/console/ui/ui_main.cpp | 13 ++++++---- source/core/include/dvc_pre_declare.h | 1 + source/core/include/pipe/dvc_render_pipe.h | 22 +++++++++------- source/core/include/pipe/dvc_render_step_IA.h | 2 +- .../scene/component/dvc_camera_component.h | 2 +- .../include/scene/component/dvc_component.h | 2 +- .../scene/component/dvc_light_component.h | 2 +- .../scene/component/dvc_mesh_component.h | 2 +- source/core/include/scene/dvc_scene.h | 1 + source/core/include/scene/dvc_scene_node.h | 2 +- source/core/source/pipe/dvc_render_pipe.cpp | 26 +++---------------- .../core/source/pipe/dvc_render_step_IA.cpp | 6 ++--- .../scene/component/dvc_camera_component.cpp | 2 +- .../source/scene/component/dvc_component.cpp | 2 +- .../scene/component/dvc_light_component.cpp | 2 +- .../scene/component/dvc_mesh_component.cpp | 6 ++--- source/core/source/scene/dvc_scene.cpp | 5 ++++ source/core/source/scene/dvc_scene_node.cpp | 6 ++--- 18 files changed, 50 insertions(+), 54 deletions(-) diff --git a/source/console/ui/ui_main.cpp b/source/console/ui/ui_main.cpp index ab42ff0..efc8d42 100644 --- a/source/console/ui/ui_main.cpp +++ b/source/console/ui/ui_main.cpp @@ -101,7 +101,9 @@ void drawMainUI() ImGui::Combo("AntiAliasing", (int*)(&g_aaTech), aaItem, IM_ARRAYSIZE(aaItem)); if (ImGui::Button("Render")) { - davinci::UniformBuffer uniformBuffer; + davinci::RenderPipe pipe; + + davinci::UniformBuffer& uniformBuffer = pipe.getUniformBuffer(); uniformBuffer.updateStandardAttribute(g_scene); //find Light node @@ -111,13 +113,14 @@ void drawMainUI() uniformBuffer.setAttribute("light0:position", lightNode->getWorldPosition()); } - davinci::RenderPipe queue; - queue.build(g_scene); + pipe.setAntiAliasingTech(g_aaTech); + + g_scene.buildRenderableQueue(pipe); g_renderTarget.clear(); - queue.process(g_aaTech, uniformBuffer, g_renderTarget); + pipe.process(g_renderTarget); - //davinci_utils::dump_render_target("d:\\rendertarget", g_renderTarget); + davinci_utils::dump_render_target("d:\\rendertarget", g_renderTarget); } ImGui::End(); diff --git a/source/core/include/dvc_pre_declare.h b/source/core/include/dvc_pre_declare.h index c796115..917a7ec 100644 --- a/source/core/include/dvc_pre_declare.h +++ b/source/core/include/dvc_pre_declare.h @@ -65,6 +65,7 @@ class RenderPipe; class Renderable; typedef std::shared_ptr RenderablePtr; typedef std::shared_ptr RenderableConstPtr; +typedef std::vector RenderableArray; class VertexShaderInterface; diff --git a/source/core/include/pipe/dvc_render_pipe.h b/source/core/include/pipe/dvc_render_pipe.h index 7aa8c91..80e298f 100644 --- a/source/core/include/pipe/dvc_render_pipe.h +++ b/source/core/include/pipe/dvc_render_pipe.h @@ -2,6 +2,7 @@ #include "dvc_config.h" #include "scene/dvc_scene.h" +#include "device/dvc_uniform_buffer.h" #include "device/dvc_render_target.h" DV_CORE_BEGIN_NAMESPACE @@ -9,20 +10,23 @@ DV_CORE_BEGIN_NAMESPACE class DV_CORE_API RenderPipe { public: + UniformBuffer& getUniformBuffer() { + return m_uniformBuffer; + } + AntiAliasingTech getAntiAliasingTech() const { + return m_aaTech; + } + void setAntiAliasingTech(AntiAliasingTech aaTech) { + m_aaTech = aaTech; + } void pushRenderable(RenderableConstPtr renderable); - size_t getRenderableCounts() const { - return m_queue.size(); - } - RenderableConstPtr getRenderable(size_t index) const; - - void build(const Scene& scene); - - void process(AntiAliasingTech aaTech, UniformBuffer& uniformBuffer, RenderTarget& renderTarget); + void process(RenderTarget& renderTarget); protected: AntiAliasingTech m_aaTech; - std::vector m_queue; + UniformBuffer m_uniformBuffer; + RenderableArray m_renderableQueue; public: RenderPipe(); diff --git a/source/core/include/pipe/dvc_render_step_IA.h b/source/core/include/pipe/dvc_render_step_IA.h index 7610ee2..2b7d28e 100644 --- a/source/core/include/pipe/dvc_render_step_IA.h +++ b/source/core/include/pipe/dvc_render_step_IA.h @@ -22,7 +22,7 @@ public: typedef std::vector NodeArray; public: - void process(const RenderPipe& renderQueue); + void process(const RenderableArray& renderableArray); public: NodeArray m_nodes; diff --git a/source/core/include/scene/component/dvc_camera_component.h b/source/core/include/scene/component/dvc_camera_component.h index 103ff0e..deadc47 100644 --- a/source/core/include/scene/component/dvc_camera_component.h +++ b/source/core/include/scene/component/dvc_camera_component.h @@ -18,7 +18,7 @@ public: }; public: virtual const std::string& getTypeName() const { return typeName(); } - virtual void render(const fMatrix4& transParent, RenderPipe& queue) const; + virtual void buildRenderableQueue(const fMatrix4& transParent, RenderPipe& pipe) const; fVector3 getEye(void) const; fVector3 getLookat(void) const; diff --git a/source/core/include/scene/component/dvc_component.h b/source/core/include/scene/component/dvc_component.h index 5560fb8..2c13b02 100644 --- a/source/core/include/scene/component/dvc_component.h +++ b/source/core/include/scene/component/dvc_component.h @@ -9,7 +9,7 @@ class DV_CORE_API SceneComponent { public: virtual const std::string& getTypeName() const = 0; - virtual void render(const fMatrix4& transParent, RenderPipe& queue) const; + virtual void buildRenderableQueue(const fMatrix4& transParent, RenderPipe& pipe) const; protected: SceneNodePtr m_owner; diff --git a/source/core/include/scene/component/dvc_light_component.h b/source/core/include/scene/component/dvc_light_component.h index 6fa77cb..3121147 100644 --- a/source/core/include/scene/component/dvc_light_component.h +++ b/source/core/include/scene/component/dvc_light_component.h @@ -27,7 +27,7 @@ public: }; public: virtual const std::string& getTypeName() const { return typeName(); } - virtual void render(const fMatrix4& transParent, RenderPipe& queue) const; + virtual void buildRenderableQueue(const fMatrix4& transParent, RenderPipe& pipe) const; void setLightDefine(const LightDefine& lightDefine); protected: diff --git a/source/core/include/scene/component/dvc_mesh_component.h b/source/core/include/scene/component/dvc_mesh_component.h index 7a33681..9a2eeb4 100644 --- a/source/core/include/scene/component/dvc_mesh_component.h +++ b/source/core/include/scene/component/dvc_mesh_component.h @@ -9,7 +9,7 @@ class DV_CORE_API MeshComponent : public SceneComponent { public: virtual const std::string& getTypeName() const { return typeName(); } - virtual void render(const fMatrix4& transParent, RenderPipe& queue) const; + virtual void buildRenderableQueue(const fMatrix4& transParent, RenderPipe& pipe) const; void setMesh(MeshConstPtr mesh); diff --git a/source/core/include/scene/dvc_scene.h b/source/core/include/scene/dvc_scene.h index 5c9e40b..7131aad 100644 --- a/source/core/include/scene/dvc_scene.h +++ b/source/core/include/scene/dvc_scene.h @@ -40,6 +40,7 @@ public: public: SceneNodePtr newSceneNode(const std::string& name); SceneNodePtr getRootSceneNode() const; + void buildRenderableQueue(RenderPipe& pipe) const; public: template diff --git a/source/core/include/scene/dvc_scene_node.h b/source/core/include/scene/dvc_scene_node.h index a89aa40..22c2fc5 100644 --- a/source/core/include/scene/dvc_scene_node.h +++ b/source/core/include/scene/dvc_scene_node.h @@ -55,7 +55,7 @@ public: } public: - void buildRenderQueue(const fMatrix4& transParent, RenderPipe& queue); + void buildRenderableQueue(const fMatrix4& transParent, RenderPipe& pipe); protected: std::string m_name; diff --git a/source/core/source/pipe/dvc_render_pipe.cpp b/source/core/source/pipe/dvc_render_pipe.cpp index 860e764..c79a97e 100644 --- a/source/core/source/pipe/dvc_render_pipe.cpp +++ b/source/core/source/pipe/dvc_render_pipe.cpp @@ -20,36 +20,18 @@ RenderPipe::~RenderPipe() void RenderPipe::pushRenderable(RenderableConstPtr renderable) { - m_queue.push_back(renderable); + m_renderableQueue.push_back(renderable); } -RenderableConstPtr RenderPipe::getRenderable(size_t index) const +void RenderPipe::process(RenderTarget& renderTarget) { - assert(index < m_queue.size()); - if (index < m_queue.size()) - { - return m_queue[index]; - } - return nullptr; -} - -void RenderPipe::build(const Scene& scene) -{ - //Build render queue - scene.getRootSceneNode()->buildRenderQueue(fMatrix4::IDENTITY, *this); -} - -void RenderPipe::process(AntiAliasingTech aaTech, UniformBuffer& uniformBuffer, RenderTarget& renderTarget) -{ - m_aaTech = aaTech; - //Assembere input InputAssemberStep IA; - IA.process(*this); + IA.process(m_renderableQueue); //Vertex shader VertexShaderStep VS; - VS.process(uniformBuffer, IA.m_nodes); + VS.process(m_uniformBuffer, IA.m_nodes); //Pixel shader PixelShaderStep PS; diff --git a/source/core/source/pipe/dvc_render_step_IA.cpp b/source/core/source/pipe/dvc_render_step_IA.cpp index 3585545..e33d23d 100644 --- a/source/core/source/pipe/dvc_render_step_IA.cpp +++ b/source/core/source/pipe/dvc_render_step_IA.cpp @@ -3,12 +3,12 @@ DV_CORE_BEGIN_NAMESPACE -void InputAssemberStep::process(const RenderPipe& renderQueue) +void InputAssemberStep::process(const RenderableArray& renderableArray) { - size_t counts = renderQueue.getRenderableCounts(); + size_t counts = renderableArray.size(); for (size_t i = 0; i < counts; i++) { - RenderableConstPtr renderable = renderQueue.getRenderable(i); + RenderableConstPtr renderable = renderableArray[i]; if (renderable) { Node node; diff --git a/source/core/source/scene/component/dvc_camera_component.cpp b/source/core/source/scene/component/dvc_camera_component.cpp index 2fb50b1..d85d792 100644 --- a/source/core/source/scene/component/dvc_camera_component.cpp +++ b/source/core/source/scene/component/dvc_camera_component.cpp @@ -51,7 +51,7 @@ void CameraComponent::setCameraDefine(const CameraComponent::CameraDefine& camer m_viewProjMatrix = matProj * matView; } -void CameraComponent::render(const fMatrix4& transParent, RenderPipe& queue) const +void CameraComponent::buildRenderableQueue(const fMatrix4& transParent, RenderPipe& pipe) const { } diff --git a/source/core/source/scene/component/dvc_component.cpp b/source/core/source/scene/component/dvc_component.cpp index b3ca646..b0cecca 100644 --- a/source/core/source/scene/component/dvc_component.cpp +++ b/source/core/source/scene/component/dvc_component.cpp @@ -13,7 +13,7 @@ SceneComponent::~SceneComponent() } -void SceneComponent::render(const fMatrix4& transParent, RenderPipe& queue) const +void SceneComponent::buildRenderableQueue(const fMatrix4& transParent, RenderPipe& pipe) const { } diff --git a/source/core/source/scene/component/dvc_light_component.cpp b/source/core/source/scene/component/dvc_light_component.cpp index d19e704..7675e45 100644 --- a/source/core/source/scene/component/dvc_light_component.cpp +++ b/source/core/source/scene/component/dvc_light_component.cpp @@ -24,7 +24,7 @@ void LightComponent::setLightDefine(const LightDefine& lightDefine) m_define = lightDefine; } -void LightComponent::render(const fMatrix4& transParent, RenderPipe& queue) const +void LightComponent::buildRenderableQueue(const fMatrix4& transParent, RenderPipe& pipe) const { } diff --git a/source/core/source/scene/component/dvc_mesh_component.cpp b/source/core/source/scene/component/dvc_mesh_component.cpp index afeb275..e5fbd3b 100644 --- a/source/core/source/scene/component/dvc_mesh_component.cpp +++ b/source/core/source/scene/component/dvc_mesh_component.cpp @@ -27,9 +27,9 @@ void MeshComponent::setMesh(MeshConstPtr mesh) m_mesh = mesh; } -void MeshComponent::render(const fMatrix4& transParent, RenderPipe& queue) const +void MeshComponent::buildRenderableQueue(const fMatrix4& transParent, RenderPipe& pipe) const { - SceneComponent::render(transParent, queue); + SceneComponent::buildRenderableQueue(transParent, pipe); int32_t primitiveCounts = m_mesh->getPrimitiveCounts(); for (int32_t i = 0; i < primitiveCounts; i++) @@ -37,7 +37,7 @@ void MeshComponent::render(const fMatrix4& transParent, RenderPipe& queue) const Mesh::PrimitiveConstPtr primitivePtr = m_mesh->getPrimitive(i); RenderablePtr renderable = std::make_shared(primitivePtr, transParent); - queue.pushRenderable(renderable); + pipe.pushRenderable(renderable); } } diff --git a/source/core/source/scene/dvc_scene.cpp b/source/core/source/scene/dvc_scene.cpp index 6f05f31..3bbe388 100644 --- a/source/core/source/scene/dvc_scene.cpp +++ b/source/core/source/scene/dvc_scene.cpp @@ -120,4 +120,9 @@ SceneNodePtr Scene::getRootSceneNode(void) const return m_rootSceneNode; } +void Scene::buildRenderableQueue(RenderPipe& pipe) const +{ + getRootSceneNode()->buildRenderableQueue(fMatrix4::IDENTITY, pipe); +} + DV_CORE_END_NAMESPACE diff --git a/source/core/source/scene/dvc_scene_node.cpp b/source/core/source/scene/dvc_scene_node.cpp index 92610e4..8b2593e 100644 --- a/source/core/source/scene/dvc_scene_node.cpp +++ b/source/core/source/scene/dvc_scene_node.cpp @@ -89,18 +89,18 @@ SceneComponentConstPtr SceneNode::getComponent(size_t index) const return m_componentArray[index]; } -void SceneNode::buildRenderQueue(const fMatrix4& transParent, RenderPipe& queue) +void SceneNode::buildRenderableQueue(const fMatrix4& transParent, RenderPipe& pipe) { fMatrix4 transform = m_transform * transParent; for (auto component : m_componentArray) { - component->render(transform, queue); + component->buildRenderableQueue(transform, pipe); } for (auto child : m_childen) { - child->buildRenderQueue(transform, queue); + child->buildRenderableQueue(transform, pipe); } }