From f68f84e8d95a0a03c4a6d8e5df581981d0a00dd4 Mon Sep 17 00:00:00 2001 From: Zlixine Date: Mon, 30 Oct 2017 02:10:15 +0200 Subject: [PATCH] Much faster mesh rendering with c++11 std::to_string Easier, Faster, More beautiful! What do you want more. --- includes/learnopengl/mesh.h | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/includes/learnopengl/mesh.h b/includes/learnopengl/mesh.h index 7841f8e..4d2aea7 100644 --- a/includes/learnopengl/mesh.h +++ b/includes/learnopengl/mesh.h @@ -68,19 +68,18 @@ public: { glActiveTexture(GL_TEXTURE0 + i); // active proper texture unit before binding // retrieve texture number (the N in diffuse_textureN) - stringstream ss; string number; string name = textures[i].type; if(name == "texture_diffuse") - ss << diffuseNr++; // transfer unsigned int to stream - else if(name == "texture_specular") - ss << specularNr++; // transfer unsigned int to stream + number = std::to_string(diffuseNr++); + else if(name == "texture_specular") + number = std::to_string(specularNr++); // transfer unsigned int to stream else if(name == "texture_normal") - ss << normalNr++; // transfer unsigned int to stream + number = std::to_string(normalNr++); // transfer unsigned int to stream else if(name == "texture_height") - ss << heightNr++; // transfer unsigned int to stream - number = ss.str(); - // now set the sampler to the correct texture unit + number = std::to_string(heightNr++); // transfer unsigned int to stream + + // now set the sampler to the correct texture unit glUniform1i(glGetUniformLocation(shader.ID, (name + number).c_str()), i); // and finally bind the texture glBindTexture(GL_TEXTURE_2D, textures[i].id); @@ -139,4 +138,4 @@ private: glBindVertexArray(0); } }; -#endif \ No newline at end of file +#endif