Skip to content

Commit

Permalink
Unify shared GPU settings
Browse files Browse the repository at this point in the history
These were done every render, but it is all same now.
Set it up once.
  • Loading branch information
enginmanap committed Dec 8, 2024
1 parent e43d2d9 commit 52c556b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/API/Graphics/GraphicsProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ GraphicsProgram::GraphicsProgram(AssetManager* assetManager, const std::string&
if(materialRequired) {
setSamplersAndUBOs();
}
graphicsWrapper->attachModelUBO(getID());
graphicsWrapper->attachModelIndicesUBO(getID());
}

GraphicsProgram::GraphicsProgram(AssetManager* assetManager, const std::string& vertexShader, const std::string& geometryShader, const std::string& fragmentShader, bool isMaterialUsed) :
Expand All @@ -27,7 +29,8 @@ GraphicsProgram::GraphicsProgram(AssetManager* assetManager, const std::string&
if(materialRequired) {
setSamplersAndUBOs();
}

graphicsWrapper->attachModelUBO(getID());
graphicsWrapper->attachModelIndicesUBO(getID());
}

GraphicsProgram::~GraphicsProgram() {
Expand Down Expand Up @@ -76,9 +79,6 @@ void GraphicsProgram::setSamplersAndUBOs() {
if (!setUniform("pre_shadowPoint", graphicsWrapper->getMaxTextureImageUnits() - 2)) {
std::cerr << "Uniform \"pre_shadowPoint\" could not be set for " << this->getProgramName() << std::endl;
}

graphicsWrapper->attachModelUBO(getID());
graphicsWrapper->attachModelIndicesUBO(getID());
}

bool GraphicsProgram::addPresetValue(const std::string& uniformName, const std::string& value) {
Expand Down
6 changes: 1 addition & 5 deletions src/GameObjects/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ void Model::activateTexturesOnly(std::shared_ptr<const Material>material) {
}

void Model::renderWithProgram(std::shared_ptr<GraphicsProgram> program, uint32_t lodLevel) {
graphicsWrapper->attachModelUBO(program->getID());
for (auto iter = meshMetaData.begin(); iter != meshMetaData.end(); ++iter) {

if (animated) {
Expand All @@ -187,17 +186,14 @@ void Model::renderWithProgram(std::shared_ptr<GraphicsProgram> program, uint32_t
program->setUniform("isAnimated", false);
}
if(program->IsMaterialRequired()) {
graphicsWrapper->attachMaterialUBO(program->getID());
this->activateTexturesOnly((*iter)->material);
}
graphicsWrapper->render(program->getID(), (*iter)->mesh->getVao(), (*iter)->mesh->getEbo(), (*iter)->mesh->getTriangleCount()[lodLevel] * 3);
}
}

void Model::renderWithProgramInstanced(const std::vector<glm::uvec4> &modelIndices, GraphicsProgram &program, uint32_t lodLevel) {

graphicsWrapper->attachModelUBO(program.getID());
graphicsWrapper->attachModelIndicesUBO(program.getID());

for (auto iter = meshMetaData.begin(); iter != meshMetaData.end(); ++iter) {
if (animated) {
//set all of the bones to unitTransform for testing
Expand Down

0 comments on commit 52c556b

Please sign in to comment.