textureReloadRequest.cxx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * PANDA 3D SOFTWARE
  3. * Copyright (c) Carnegie Mellon University. All rights reserved.
  4. *
  5. * All use of this software is subject to the terms of the revised BSD
  6. * license. You should have received a copy of this license along
  7. * with this source code in a file named "LICENSE."
  8. *
  9. * @file textureReloadRequest.cxx
  10. * @author drose
  11. * @date 2008-08-12
  12. */
  13. #include "textureReloadRequest.h"
  14. #include "textureContext.h"
  15. TypeHandle TextureReloadRequest::_type_handle;
  16. /**
  17. * Performs the task: that is, loads the one model.
  18. */
  19. AsyncTask::DoneStatus TextureReloadRequest::
  20. do_task() {
  21. // Don't reload the texture if it doesn't need it.
  22. if (!_texture->was_image_modified(_pgo) &&
  23. (_allow_compressed ? _texture->has_ram_image() : _texture->has_uncompressed_ram_image())) {
  24. return DS_done;
  25. }
  26. double delay = async_load_delay;
  27. if (delay != 0.0) {
  28. Thread::sleep(delay);
  29. if (!_texture->was_image_modified(_pgo) &&
  30. (_allow_compressed ? _texture->has_ram_image() : _texture->has_uncompressed_ram_image())) {
  31. return DS_done;
  32. }
  33. }
  34. if (_allow_compressed) {
  35. _texture->get_ram_image();
  36. } else {
  37. _texture->get_uncompressed_ram_image();
  38. }
  39. // Now that we've loaded the texture, we should ensure it actually gets
  40. // prepared--even if it's no longer visible in the frame--or it may become a
  41. // kind of a leak (if the texture is never rendered again on this GSG, we'll
  42. // just end up carrying the texture memory in RAM forever, instead of dumping
  43. // it as soon as it gets prepared).
  44. _pgo->enqueue_texture(_texture);
  45. // Don't continue the task; we're done.
  46. return DS_done;
  47. }