Skip to content

Commit 6d15c03

Browse files
committed
feat(model): replace generateDrawCommands with direct submesh handling in ForwardRenderer
1 parent 2d37081 commit 6d15c03

3 files changed

Lines changed: 16 additions & 20 deletions

File tree

src/common/model/model.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,6 @@
1111
#include "texture/texture-utils.hpp"
1212

1313
namespace our {
14-
void Model::generateDrawCommands(std::vector<RenderCommand>& modelCommands,
15-
std::vector<RenderCommand>& transparentCommands,
16-
const glm::mat4& modelMatrix) const {
17-
for (const auto& submesh : submeshes) {
18-
RenderCommand cmd;
19-
cmd.localToWorld = modelMatrix * submesh->transform;
20-
cmd.center = glm::vec3(cmd.localToWorld * glm::vec4(0, 0, 0, 1));
21-
cmd.mesh = submesh->mesh;
22-
cmd.material = submesh->material;
23-
if (submesh->material->transparent) {
24-
transparentCommands.push_back(cmd);
25-
} else {
26-
modelCommands.push_back(cmd);
27-
}
28-
}
29-
}
3014

3115
void Model::loadFromFile(const std::string& path) {
3216
std::cout << "Loading model from file: " << path << std::endl;

src/common/model/model.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ namespace our {
3434
Model(const std::string& name) {
3535
this->name = name;
3636
};
37-
void generateDrawCommands(std::vector<RenderCommand>& modelCommands,
38-
std::vector<RenderCommand>& transparentCommands, const glm::mat4& modelMatrix) const;
37+
std::vector<MeshRendererComponent*>& getSubmeshes() {
38+
return submeshes;
39+
}
3940
Mesh* getCombinedMesh() const {
4041
return combinedMesh;
4142
}

src/common/systems/forward-renderer.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,19 @@ namespace our {
169169
}
170170

171171
if (auto modelRenderer = entity->getComponent<ModelRendererComponent>(); modelRenderer) {
172-
glm::mat4 localToWorld = modelRenderer->getOwner()->getLocalToWorldMatrix();
173-
modelRenderer->model->generateDrawCommands(opaqueCommands, transparentCommands, localToWorld);
172+
glm::mat4 modelMatrix = modelRenderer->getOwner()->getLocalToWorldMatrix();
173+
for (MeshRendererComponent* submesh : modelRenderer->model->getSubmeshes()) {
174+
RenderCommand command;
175+
command.localToWorld = modelMatrix * submesh->transform;
176+
command.center = glm::vec3(command.localToWorld * glm::vec4(0, 0, 0, 1));
177+
command.mesh = submesh->mesh;
178+
command.material = submesh->material;
179+
if (command.material->transparent) {
180+
transparentCommands.push_back(command);
181+
} else {
182+
opaqueCommands.push_back(command);
183+
}
184+
}
174185
}
175186
}
176187

0 commit comments

Comments
 (0)