diff --git a/src/Occlusion/RenderList.cpp b/src/Occlusion/RenderList.cpp index 30b5b67d..50f45d11 100644 --- a/src/Occlusion/RenderList.cpp +++ b/src/Occlusion/RenderList.cpp @@ -67,7 +67,7 @@ void RenderList::render(GraphicsInterface *graphicsWrapper, const std::shared_pt //now render all of the meshes for (auto renderListIterator = this->getIterator(); !renderListIterator.isEnd(); ++renderListIterator) { - if (renderProgram->isMaterialRequired()) { + if (renderProgram->isMaterialRequired() && renderListIterator.isMaterialChanged()) { const auto& material = renderListIterator.getMaterial(); //activate textures if(material->hasDiffuseMap()) { @@ -90,7 +90,6 @@ void RenderList::render(GraphicsInterface *graphicsWrapper, const std::shared_pt } } - if (renderListIterator.get().indices.empty()) { std::cerr << "Empty meshInfo" << std::endl; continue; diff --git a/src/Occlusion/RenderList.h b/src/Occlusion/RenderList.h index 72c272c4..38dcf5b1 100644 --- a/src/Occlusion/RenderList.h +++ b/src/Occlusion/RenderList.h @@ -80,18 +80,18 @@ class RenderList { public: class RenderListIterator { const RenderList& renderList; - bool end; std::multimap>::reverse_iterator materialPriorityIt; mutable PerMaterialRenderInformation::perMaterialIterator* perMaterialIterator = nullptr; - + bool end; + bool materialChanged = true; public: /** * Provides an iterator that automatically iterates through materials and meshes, using depth information as ordering. * Using this iterator is prone to iterator invalidation. Thats why we don't remove items while any of these are on the fly. */ - explicit RenderListIterator(const RenderList& renderList) : renderList(renderList), end(false) - , materialPriorityIt(renderList.materialRenderPriorityMap.rbegin()) { + explicit RenderListIterator(const RenderList& renderList) : renderList(renderList), materialPriorityIt(renderList.materialRenderPriorityMap.rbegin()) + , end(false) { if (materialPriorityIt == renderList.materialRenderPriorityMap.rend()) { end = true; } else { @@ -112,6 +112,7 @@ class RenderList { } if (!perMaterialIterator->isEnd()) { ++(*perMaterialIterator); + materialChanged = false; } if (perMaterialIterator->isEnd()) { //so this material is done. move to next material @@ -122,6 +123,7 @@ class RenderList { } delete perMaterialIterator; perMaterialIterator = new PerMaterialRenderInformation::perMaterialIterator(renderList.perMaterialMeshMap.at(materialPriorityIt->second)); + materialChanged = true; } return *this; } @@ -136,6 +138,10 @@ class RenderList { const std::shared_ptr& getMesh() const { return perMaterialIterator->getMesh(); } + + bool isMaterialChanged() const { + return materialChanged; + } }; private: std::unordered_map, PerMaterialRenderInformation> perMaterialMeshMap; //Each mesh has its own render information