From 52c556b4a6814ccaeb40979d5733833f57cc7e28 Mon Sep 17 00:00:00 2001 From: Engin Manap Date: Sun, 8 Dec 2024 14:39:53 +0100 Subject: [PATCH] Unify shared GPU settings These were done every render, but it is all same now. Set it up once. --- src/API/Graphics/GraphicsProgram.cpp | 8 ++++---- src/GameObjects/Model.cpp | 6 +----- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/API/Graphics/GraphicsProgram.cpp b/src/API/Graphics/GraphicsProgram.cpp index 554e9be4..819e6f65 100644 --- a/src/API/Graphics/GraphicsProgram.cpp +++ b/src/API/Graphics/GraphicsProgram.cpp @@ -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) : @@ -27,7 +29,8 @@ GraphicsProgram::GraphicsProgram(AssetManager* assetManager, const std::string& if(materialRequired) { setSamplersAndUBOs(); } - + graphicsWrapper->attachModelUBO(getID()); + graphicsWrapper->attachModelIndicesUBO(getID()); } GraphicsProgram::~GraphicsProgram() { @@ -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) { diff --git a/src/GameObjects/Model.cpp b/src/GameObjects/Model.cpp index e4ab28f0..d9315bcb 100644 --- a/src/GameObjects/Model.cpp +++ b/src/GameObjects/Model.cpp @@ -176,7 +176,6 @@ void Model::activateTexturesOnly(std::shared_ptrmaterial) { } void Model::renderWithProgram(std::shared_ptr program, uint32_t lodLevel) { - graphicsWrapper->attachModelUBO(program->getID()); for (auto iter = meshMetaData.begin(); iter != meshMetaData.end(); ++iter) { if (animated) { @@ -187,7 +186,7 @@ void Model::renderWithProgram(std::shared_ptr 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); } @@ -195,9 +194,6 @@ void Model::renderWithProgram(std::shared_ptr program, uint32_t void Model::renderWithProgramInstanced(const std::vector &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