Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed add stage item #1897

Merged
merged 2 commits into from Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cocos/renderer/memop/RecyclePool.hpp
Expand Up @@ -59,7 +59,7 @@ class RecyclePool
_data.clear();
}

const T* getData(size_t index) const
T* getData(size_t index) const
{
if (index >= _count)
{
Expand Down
13 changes: 6 additions & 7 deletions cocos/renderer/renderer/BaseRenderer.cpp
Expand Up @@ -159,9 +159,11 @@ void BaseRenderer::render(const View& view, const Scene* scene)
// dispatch draw items to different stage
_stageInfos->reset();
StageItem stageItem;
std::vector<StageItem> stageItems;
for (const auto& stage : view.stages)
{
StageInfo* stageInfo = _stageInfos->add();
stageInfo->stage = stage;
stageInfo->items.clear();
for (size_t i = 0, len = _drawItems->getLength(); i < len; i++)
{
const DrawItem* item = _drawItems->getData(i);
Expand All @@ -177,24 +179,21 @@ void BaseRenderer::render(const View& view, const Scene* scene)
stageItem.uniforms = item->uniforms;
stageItem.definesKeyHash = item->definesKeyHash;

stageItems.push_back(stageItem);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

每个 stage 应该用单独的 std::vector

stageInfo->items.push_back(stageItem);
}
}
StageInfo* stageInfo = _stageInfos->add();
stageInfo->stage = stage;
stageInfo->items = &stageItems;
}

// render stages
std::unordered_map<std::string, const StageCallback>::iterator foundIter;
for (size_t i = 0, len = _stageInfos->getLength(); i < len; i++)
{
const StageInfo* stageInfo = _stageInfos->getData(i);
StageInfo* stageInfo = _stageInfos->getData(i);
foundIter = _stage2fn.find(stageInfo->stage);
if (_stage2fn.end() != foundIter)
{
auto& fn = foundIter->second;
fn(view, *stageInfo->items);
fn(view, stageInfo->items);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion cocos/renderer/renderer/BaseRenderer.h
Expand Up @@ -110,7 +110,8 @@ class BaseRenderer : public Ref

struct StageInfo
{
std::vector<StageItem>* items;
public:
std::vector<StageItem> items;
std::string stage = "";
};

Expand All @@ -128,6 +129,7 @@ class BaseRenderer : public Ref
RecyclePool<DrawItem>* _drawItems = nullptr;
RecyclePool<StageInfo>* _stageInfos = nullptr;
RecyclePool<View>* _views = nullptr;
RecyclePool<StageItem>* _stageItems = nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

貌似没看到有用这个_stageItems的地方,是用在了其他地方了么?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

多余的,漏删了


cocos2d::Mat4* _tmpMat4 = nullptr;

Expand Down