diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index de3f57c22b..710b64dde6 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -519,8 +519,6 @@ cocos_source_files( cocos/renderer/pipeline/RenderStage.h cocos/renderer/pipeline/RenderView.cpp cocos/renderer/pipeline/RenderView.h - cocos/renderer/pipeline/RenderWindow.cpp - cocos/renderer/pipeline/RenderWindow.h cocos/renderer/pipeline/PlanarShadowQueue.cpp cocos/renderer/pipeline/PlanarShadowQueue.h cocos/renderer/pipeline/ShadowMapBatchedQueue.cpp diff --git a/native/cocos/renderer/pipeline/RenderView.cpp b/native/cocos/renderer/pipeline/RenderView.cpp index aa0924e2b5..b5e2843ecc 100644 --- a/native/cocos/renderer/pipeline/RenderView.cpp +++ b/native/cocos/renderer/pipeline/RenderView.cpp @@ -1,7 +1,70 @@ #include "RenderView.h" +#include "Define.h" +#include "RenderFlow.h" +#include "RenderPipeline.h" +#include "helper/SharedMemory.h" namespace cc { namespace pipeline { +RenderView::RenderView(uint cameraID) +: _camera(GET_CAMERA(cameraID)) { + const auto root = GET_ROOT(0); //TODO coulsonwang + _pipeline = GET_PIPELINE(root->pipelineID); +} + +RenderView::~RenderView() { + destroy(); +} + +bool RenderView::initialize(const RenderViewInfo &info) { + _name = info.name; + _priority = info.priority; + setExecuteFlows(info.flows); + + return true; +} + +void RenderView::destroy() { + _window = nullptr; + _priority = 0; +} + +void RenderView::setExecuteFlows(const vector &flows) { + _flows.clear(); + + const auto pipelineFlows = _pipeline->getFlows(); + if (flows.size() == 1 && flows[0] == "UIFlow") { + for (auto flow : pipelineFlows) { + if (flow->getName() == "UIFlow") { + _flows.emplace_back(flow); + break; + } + } + return; + } + for (auto flow : pipelineFlows) { + if (static_cast(flow->getTag()) == RenderFlowTag::SCENE || + std::find(flows.begin(), flows.end(), flow->getName()) != flows.end()) { + _flows.emplace_back(flow); + } + } +} + +void RenderView::setWindow(uint windowID) { + _window = GET_WINDOW(windowID); +} + +void RenderView::onGlobalPipelineStateChanged() { + const auto pipelineFlows = _pipeline->getFlows(); + for (auto &flow : _flows) { + for (auto pipelineFlow : pipelineFlows) { + if (pipelineFlow->getName() == flow->getName()) { + flow = pipelineFlow; + break; + } + } + } +} } // namespace pipeline } // namespace cc diff --git a/native/cocos/renderer/pipeline/RenderView.h b/native/cocos/renderer/pipeline/RenderView.h index 6cab3f423d..3a36ec62cf 100644 --- a/native/cocos/renderer/pipeline/RenderView.h +++ b/native/cocos/renderer/pipeline/RenderView.h @@ -6,29 +6,35 @@ namespace cc { namespace pipeline { struct Camera; class RenderFlow; -class RenderWindow; +struct RenderWindow; +class RenderPipeline; struct CC_DLL RenderViewInfo { - //TODO + uint cameraID = 0; + String name; + uint priority = 0; + vector flows; }; class CC_DLL RenderView : public Object { public: - RenderView(Camera *camera); - ~RenderView() = default; + RenderView(uint cameraID); + virtual ~RenderView(); void destroy(); - void enable(bool value); bool initialize(const RenderViewInfo &info); - void setExecuteFlows(const RenderFlowList &flows); - void setPriority(); + void setExecuteFlows(const vector &flows); + void setWindow(uint windowID); + void onGlobalPipelineStateChanged(); CC_INLINE const String &getName() const { return _name; } CC_INLINE uint getPriority() const { return _priority; } + CC_INLINE void setPriority(uint value) { _priority = value; } CC_INLINE uint getVisibility() const { return _visibility; } CC_INLINE void setVisibility(uint value) { _visibility = value; } CC_INLINE Camera *getCamera() const { return _camera; } CC_INLINE bool isEnabled() const { return _isEnabled; } + CC_INLINE void enable(bool value) { _isEnabled = value; } CC_INLINE const RenderFlowList &getFlows() const { return _flows; } CC_INLINE RenderWindow *getWindow() const { return _window; } @@ -43,6 +49,8 @@ private: String _name; Camera *_camera = nullptr; RenderWindow *_window = nullptr; + RenderPipeline *_pipeline = nullptr; + uint _priority = 0; uint _visibility = CAMERA_DEFAULT_MASK; bool _isEnabled = false; diff --git a/native/cocos/renderer/pipeline/RenderWindow.cpp b/native/cocos/renderer/pipeline/RenderWindow.cpp deleted file mode 100644 index 7f2f449358..0000000000 --- a/native/cocos/renderer/pipeline/RenderWindow.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "RenderWindow.h" - -namespace cc { -namespace pipeline { - -} // namespace pipeline -} // namespace cc diff --git a/native/cocos/renderer/pipeline/RenderWindow.h b/native/cocos/renderer/pipeline/RenderWindow.h deleted file mode 100644 index 372d455df7..0000000000 --- a/native/cocos/renderer/pipeline/RenderWindow.h +++ /dev/null @@ -1,60 +0,0 @@ -#pragma once - -#include "core/CoreStd.h" - -namespace cc { -class Root; - -namespace pipeline { - -struct CC_DLL RenderWindowInfo { - String titile; - uint left = 0; - uint top = 0; - uint width = 0; - uint height = 0; - gfx::RenderPassInfo *renderPassInfo = nullptr; - bool isOffscreen = false; -}; - -class CC_DLL RenderWindow : public Object { -public: - static void registerCreateFunc(Root *root); - - bool initialize(const RenderWindowInfo &info); - void destroy(); - void resize(uint width, uint height); - - CC_INLINE uint getWidth() const { return _width; } - CC_INLINE uint geiHeight() const { return _height; } - CC_INLINE bool isOffscreen() const { return _isOffscreen; } - CC_INLINE gfx::RenderPass *getRenderPass() const { return _renderPass; } - CC_INLINE const gfx::TextureList &getColorTextures() const { return _colorTexs; } - CC_INLINE gfx::Texture *getDepthStencilTexture() const { return _depthStencilTex; } - CC_INLINE gfx::Framebuffer *getFramebuffer() const { return _frameBuffer; } - CC_INLINE bool hasOnScreenAttachments() const { return _hasOnScreenAttachments; } - CC_INLINE bool hasOffScreenAttachments() const { return _hasOffScreenAttachments; } - -private: - RenderWindow() = default; - RenderWindow(Root *root); - -private: - String title; - gfx::TextureList _colorTexs; - gfx::Texture *_depthStencilTex = nullptr; - gfx::Framebuffer *_frameBuffer = nullptr; - gfx::RenderPass *_renderPass = nullptr; - Root *_root = nullptr; - uint _width = 0; - uint _height = 0; - uint _top = 0; - uint _nativeWidth = 0; - uint _nativeHeight = 0; - bool _isOffscreen = false; - bool _hasOffScreenAttachments = false; - bool _hasOnScreenAttachments = false; -}; - -} // namespace pipeline -} // namespace cc diff --git a/native/cocos/renderer/pipeline/forward/ForwardPipeline.cpp b/native/cocos/renderer/pipeline/forward/ForwardPipeline.cpp index c5eb68ae03..e8ed987595 100644 --- a/native/cocos/renderer/pipeline/forward/ForwardPipeline.cpp +++ b/native/cocos/renderer/pipeline/forward/ForwardPipeline.cpp @@ -1,6 +1,5 @@ #include "ForwardPipeline.h" #include "../RenderView.h" -#include "../RenderWindow.h" #include "../helper/SharedMemory.h" #include "../shadow/ShadowFlow.h" #include "../ui/UIFlow.h" @@ -187,7 +186,7 @@ void ForwardPipeline::updateUBO(RenderView *view) { TO_VEC3(uboGlobalView, camera->position, UBOGlobal::CAMERA_POS_OFFSET); auto projectionSignY = _device->getScreenSpaceSignY(); - if (view->getWindow()->hasOffScreenAttachments()) { + if (view->getWindow()->hasOffScreenAttachments) { projectionSignY *= _device->getUVSpaceSignY(); // need flipping if drawing on render targets } uboGlobalView[UBOGlobal::CAMERA_POS_OFFSET + 3] = projectionSignY; diff --git a/native/cocos/renderer/pipeline/forward/ForwardStage.cpp b/native/cocos/renderer/pipeline/forward/ForwardStage.cpp index 3082c3c65d..b06cd1a831 100644 --- a/native/cocos/renderer/pipeline/forward/ForwardStage.cpp +++ b/native/cocos/renderer/pipeline/forward/ForwardStage.cpp @@ -7,7 +7,6 @@ #include "../RenderInstancedQueue.h" #include "../RenderQueue.h" #include "../RenderView.h" -#include "../RenderWindow.h" #include "../helper/SharedMemory.h" #include "ForwardPipeline.h" #include "gfx/GFXCommandBuffer.h" @@ -167,7 +166,7 @@ void ForwardStage::render(RenderView *view) { _clearColors[0].a = camera->clearColor.a; - auto framebuffer = view->getWindow()->getFramebuffer(); + auto framebuffer = GET_FRAMEBUFFER(view->getWindow()->framebufferID); const auto &colorTextures = framebuffer->getColorTextures(); auto renderPass = colorTextures.size() ? framebuffer->getRenderPass() : pipeline->getOrCreateRenderPass(static_cast(camera->clearFlag)); diff --git a/native/cocos/renderer/pipeline/helper/SharedMemory.h b/native/cocos/renderer/pipeline/helper/SharedMemory.h index a185b23645..73ffc8f6ae 100644 --- a/native/cocos/renderer/pipeline/helper/SharedMemory.h +++ b/native/cocos/renderer/pipeline/helper/SharedMemory.h @@ -12,6 +12,7 @@ namespace pipeline { struct RenderingSubMesh; struct FlatBuffer; struct PlanarShadow; +class RenderPipeline; struct CC_DLL ModelView { uint32_t subModelsID = 0; //array pool @@ -222,6 +223,8 @@ struct CC_DLL Root { float cumulativeTime = 0; float frameTime = 0; + uint32_t pipelineID = 0; + const static se::PoolType type = se::PoolType::ROOT; }; @@ -231,6 +234,12 @@ struct CC_DLL Director { const static se::PoolType type = se::PoolType::UNKNOWN; }; +struct CC_DLL RenderWindow { + uint32_t framebufferID = 0; + uint32_t hasOnScreenAttachments = 0; + uint32_t hasOffScreenAttachments = 0; +}; + //Get buffer pool data #define GET_SUBMODEL(index) (SharedMemory::get(index)) #define GET_PASS(index) (SharedMemory::get(index)) @@ -264,6 +273,9 @@ struct CC_DLL Director { #define GET_DEPTH_STENCIL_STATE(index) (static_cast(0)) #define GET_BLEND_STATE(index) (static_cast(0)) #define GET_BINDING_LAYOUT(index) (static_cast(0)) +#define GET_PIPELINE(index) (static_cast(0)) +#define GET_WINDOW(index) (static_cast(0)) +#define GET_FRAMEBUFFER(index) (static_cast(0)) //Get array pool data #define GET_MODEL_ARRAY(index) (static_cast(0)) diff --git a/native/cocos/renderer/pipeline/ui/UIStage.cpp b/native/cocos/renderer/pipeline/ui/UIStage.cpp index a677568f99..bf2bf618f7 100644 --- a/native/cocos/renderer/pipeline/ui/UIStage.cpp +++ b/native/cocos/renderer/pipeline/ui/UIStage.cpp @@ -2,7 +2,6 @@ #include "../Define.h" #include "../RenderQueue.h" #include "../RenderView.h" -#include "../RenderWindow.h" #include "../forward/ForwardPipeline.h" #include "../helper/SharedMemory.h" #include "gfx/GFXCommandBuffer.h" @@ -79,7 +78,7 @@ void UIStage::render(RenderView *view) { auto &commandBuffers = pipeline->getCommandBuffers(); auto cmdBuff = commandBuffers[0]; - auto framebuffer = view->getWindow()->getFramebuffer(); + auto framebuffer = GET_FRAMEBUFFER(view->getWindow()->framebufferID); auto renderPass = framebuffer->getColorTextures().size() ? framebuffer->getRenderPass() : pipeline->getOrCreateRenderPass(static_cast(camera->clearFlag)); cmdBuff->begin();