fix RenderView and RenderWindow

This commit is contained in:
coulsonwang
2020-08-19 17:07:53 +08:00
parent e547b86402
commit 728ffb4aa0
9 changed files with 93 additions and 82 deletions
-2
View File
@@ -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
@@ -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<String> &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<RenderFlowTag>(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
+15 -7
View File
@@ -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<String> 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<String> &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;
@@ -1,7 +0,0 @@
#include "RenderWindow.h"
namespace cc {
namespace pipeline {
} // namespace pipeline
} // namespace cc
@@ -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
@@ -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;
@@ -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<gfx::ClearFlagBit>(camera->clearFlag));
@@ -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<SubModelView>(index))
#define GET_PASS(index) (SharedMemory::get<PassView>(index))
@@ -264,6 +273,9 @@ struct CC_DLL Director {
#define GET_DEPTH_STENCIL_STATE(index) (static_cast<gfx::DepthStencilState *>(0))
#define GET_BLEND_STATE(index) (static_cast<gfx::BlendState *>(0))
#define GET_BINDING_LAYOUT(index) (static_cast<gfx::BindingLayout *>(0))
#define GET_PIPELINE(index) (static_cast<RenderPipeline *>(0))
#define GET_WINDOW(index) (static_cast<RenderWindow *>(0))
#define GET_FRAMEBUFFER(index) (static_cast<gfx::Framebuffer *>(0))
//Get array pool data
#define GET_MODEL_ARRAY(index) (static_cast<uint32_t *>(0))
@@ -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<gfx::ClearFlags>(camera->clearFlag));
cmdBuff->begin();