void Shader::setParameter(const std::string& name, const Texture& texture) { if (m_shaderProgram) { ensureGlContext(); // Find the location of the variable in the shader int location = glGetUniformLocationARB(m_shaderProgram, name.c_str()); if (location == -1) { err() << "Texture \"" << name << "\" not found in shader" << std::endl; return; } // Store the location -> texture mapping TextureTable::iterator it = m_textures.find(location); if (it == m_textures.end()) { // New entry, make sure there are enough texture units static const GLint maxUnits = getMaxTextureUnits(); if (m_textures.size() + 1 >= static_cast<std::size_t>(maxUnits)) { err() << "Impossible to use texture \"" << name << "\" for shader: all available texture units are used" << std::endl; return; } m_textures[location] = &texture; } else { // Location already used, just replace the texture it->second = &texture; } } }
void Shader::setParameter(const std::string &name, const Texture &texture) { if (mShaderProgram) { ensureGLContext(); GLint location = getParamLocation(name); if (location != -1) { TextureTable::iterator it = mTextures.find(location); if (it == mTextures.end()) { GLint maxUnits = getMaxTextureUnits(); if (mTextures.size() + 1 >= staticCast_t(maxUnits)) { std::cerr << "Imposible to use texture \"" << name << "\" for shader, all available texture units are used.\n"; return; } mTextures[location] = &texture; } else { it->second = &texture; } } } }