Skip to content

Commit

Permalink
Only change textures if material changes
Browse files Browse the repository at this point in the history
There is already a check on OpenGL backend for this,
but I am not sure if all backends can/will have it.
  • Loading branch information
enginmanap committed Dec 28, 2024
1 parent 3a64995 commit b97944b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/Occlusion/RenderList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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;
Expand Down
14 changes: 10 additions & 4 deletions src/Occlusion/RenderList.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,18 @@ class RenderList {
public:
class RenderListIterator {
const RenderList& renderList;
bool end;
std::multimap<float, std::shared_ptr<const Material>>::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 {
Expand All @@ -112,6 +112,7 @@ class RenderList {
}
if (!perMaterialIterator->isEnd()) {
++(*perMaterialIterator);
materialChanged = false;
}
if (perMaterialIterator->isEnd()) {
//so this material is done. move to next material
Expand All @@ -122,6 +123,7 @@ class RenderList {
}
delete perMaterialIterator;
perMaterialIterator = new PerMaterialRenderInformation::perMaterialIterator(renderList.perMaterialMeshMap.at(materialPriorityIt->second));
materialChanged = true;
}
return *this;
}
Expand All @@ -136,6 +138,10 @@ class RenderList {
const std::shared_ptr<MeshAsset>& getMesh() const {
return perMaterialIterator->getMesh();
}

bool isMaterialChanged() const {
return materialChanged;
}
};
private:
std::unordered_map<std::shared_ptr<const Material>, PerMaterialRenderInformation> perMaterialMeshMap; //Each mesh has its own render information
Expand Down

0 comments on commit b97944b

Please sign in to comment.