message: Improvements to viewer texture baking
  Fix an OpenGL error after baking textures in the viewer.
  Apply a constant maximum resolution to baked textures.
  Minor clarifications to baking logic.
diff: @@ -39,7 +39,7 @@ const int IRRADIANCE_MAP_WIDTH = 256;
  const int IRRADIANCE_MAP_HEIGHT = 128;
  const int MIN_TEXTURE_RES = 256;
  -int MAX_TEXTURE_RES = 4096;
  +const int MAX_TEXTURE_RES = 8192;
  const int DEFAULT_TEXTURE_RES = 1024;
  const std::string DIR_LIGHT_NODE_CATEGORY = "directional_light";
  @@ -241,7 +241,6 @@ Viewer::Viewer(const std::string& materialFilename,
  #endif
  _imageHandler = mx::GLTextureHandler::create(imageLoader);
  _imageHandler->setSearchPath(_searchPath);
  - glGetIntegerv(GL_MAX_TEXTURE_SIZE, &MAX_TEXTURE_RES);
  // Initialize user interfaces.
  createLoadMeshInterface(_window, "Load Mesh");
  @@ -1671,22 +1670,23 @@ mx::ImagePtr Viewer::renderWedge()
  void Viewer::bakeTextures()
  {
  MaterialPtr material = getSelectedMaterial();
  - mx::FileSearchPath searchPath = _searchPath;
  mx::DocumentPtr doc = material->getDocument();
  if (!doc)
  {
  return;
  }
  +
  + // Create a unique image handler for baking.
  mx::FilePath documentFilename = doc->getSourceUri();
  + mx::FileSearchPath searchPath = _searchPath;
  searchPath.append(documentFilename.getParentPath());
  - mx::ValuePtr udimSetValue = doc->getGeomPropValue("udimset");
  - mx::Image::BaseType baseType = (_bakeHdr)? mx::Image::BaseType::FLOAT : mx::Image::BaseType::UINT8;
  mx::ImageHandlerPtr imageHandler = mx::GLTextureHandler::create(mx::StbImageLoader::create());
  imageHandler->setSearchPath(searchPath);
  - // if material has udims
  + // Compute material and UDIM lists.
  std::vector<MaterialPtr> materialsToBake;
  std::vector<std::string> udimSet;
  + mx::ValuePtr udimSetValue = doc->getGeomPropValue("udimset");
  if (!material->getUdim().empty() && udimSetValue && _materials.size() > 1)
  {
  materialsToBake = _materials;
  @@ -1697,12 +1697,18 @@ void Viewer::bakeTextures()
  materialsToBake.push_back(material);
  udimSet.push_back("");
  }
  +
  + {
  + // Construct a texture baker.
  + mx::Image::BaseType baseType = _bakeHdr ? mx::Image::BaseType::FLOAT : mx::Image::BaseType::UINT8;
  mx::TextureBakerPtr baker = mx::TextureBaker::create(_bakeTextureRes, _bakeTextureRes, baseType);
  +
  + // Bake each material in the list.
  for (MaterialPtr mat : materialsToBake)
  - {
  - if (mat->getElement()->getCategory() == "shaderref")
  {
  mx::ShaderRefPtr shaderRef = mat->getElement()->asA<mx::ShaderRef>();
  + if (shaderRef)
  + {
  mx::StringResolverPtr resolver = mx::StringResolver::create();
  resolver->setUdimString(mat->getUdim());
  imageHandler->setFilenameResolver(resolver);
  @@ -1722,12 +1728,15 @@ void Viewer::bakeTextures()
  new ng::MessageDialog(this, ng::MessageDialog::Type::Warning, "Failed to bake textures", e.what());
  }
  }
  -
  + }
  }
  + // Restore state for scene rendering.
  glfwMakeContextCurrent(mGLFWWindow);
  glfwGetFramebufferSize(mGLFWWindow, &mFBSize[0], &mFBSize[1]);
  glViewport(0, 0, mFBSize[0], mFBSize[1]);
  + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
  + glDrawBuffer(GL_BACK);
  }
  void Viewer::drawContents()
  