功能向RenderPipe集中
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@ class RenderPipe;
|
||||
class Renderable;
|
||||
typedef std::shared_ptr<Renderable> RenderablePtr;
|
||||
typedef std::shared_ptr<const Renderable> RenderableConstPtr;
|
||||
typedef std::vector<RenderableConstPtr> RenderableArray;
|
||||
|
||||
class VertexShaderInterface;
|
||||
|
||||
|
||||
@@ -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<RenderableConstPtr> m_queue;
|
||||
UniformBuffer m_uniformBuffer;
|
||||
RenderableArray m_renderableQueue;
|
||||
|
||||
public:
|
||||
RenderPipe();
|
||||
|
||||
@@ -22,7 +22,7 @@ public:
|
||||
typedef std::vector<Node> NodeArray;
|
||||
|
||||
public:
|
||||
void process(const RenderPipe& renderQueue);
|
||||
void process(const RenderableArray& renderableArray);
|
||||
|
||||
public:
|
||||
NodeArray m_nodes;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ public:
|
||||
public:
|
||||
SceneNodePtr newSceneNode(const std::string& name);
|
||||
SceneNodePtr getRootSceneNode() const;
|
||||
void buildRenderableQueue(RenderPipe& pipe) const;
|
||||
|
||||
public:
|
||||
template<typename ComponentType>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ SceneComponent::~SceneComponent()
|
||||
|
||||
}
|
||||
|
||||
void SceneComponent::render(const fMatrix4& transParent, RenderPipe& queue) const
|
||||
void SceneComponent::buildRenderableQueue(const fMatrix4& transParent, RenderPipe& pipe) const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -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<RenderableEntity>(primitivePtr, transParent);
|
||||
queue.pushRenderable(renderable);
|
||||
pipe.pushRenderable(renderable);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user