void Model::drawModel(GLSLProgram &shader) const { for (size_t i=0; i<materials_.size(); ++i) { if (materials_[i].map_Kd != "") { glUniform1f(shader("useTextureMap"), 1.0); //use texture GLint whichID[1]; glActiveTexture(GL_TEXTURE0); glGetIntegerv(GL_TEXTURE_BINDING_2D, whichID); if (whichID[0] != textures_[i]) { glBindTexture(GL_TEXTURE_2D, textures_[i]); } } else { glUniform1f(shader("useTextureMap"), 0.0); glUniform3fv(shader("materialKd"), 1 , glm::value_ptr(materials_[i].Kd)); if (shader.isActive(shader("materialKs"))) glUniform3fv(shader("materialKs"), 1 , glm::value_ptr(materials_[i].Ks)); if (shader.isActive(shader("materialKa"))) glUniform3fv(shader("materialKa"), 1 , glm::value_ptr(materials_[i].Ka)); if (shader.isActive(shader("materialNs"))) glUniform1f(shader("materialNs"), materials_[i].Ns); } if (materials_.size() == 1) glDrawElements(GL_TRIANGLES, indices_.size(), GL_UNSIGNED_SHORT, 0); else glDrawElements(GL_TRIANGLES, materials_[i].count, GL_UNSIGNED_SHORT, (const GLvoid*)(&indices_[materials_[i].offset])); } }
GLuint Model::getVAOForContext(GLSLProgram &shader, QGLContext *context){ if (!vaoHashContainer_.contains(context)) { glGenVertexArrays(1, &vaoID_); glBindVertexArray(vaoID_); shader.use(); glBindBuffer (GL_ARRAY_BUFFER, vboVerticesID_); glEnableVertexAttribArray(shader["vVertex"]); glVertexAttribPointer(shader["vVertex"], 3, GL_FLOAT, GL_FALSE,sizeof(Vertex),0); if (shader.isActive(shader["vNormal"])) { glEnableVertexAttribArray(shader["vNormal"]); glVertexAttribPointer(shader["vNormal"], 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)(offsetof(Vertex, normal)) ); } if (shader.isActive(shader["vUV"])) { glEnableVertexAttribArray(shader["vUV"]); glVertexAttribPointer(shader["vUV"], 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)(offsetof(Vertex, uv)) ); } if (materials_.size()==1) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndicesID_); glBindVertexArray(0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0); vaoHashContainer_.insert(context, vaoID_); shader.unUse(); } return vaoHashContainer_[context]; }