Texture.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "../../Include/RmlUi/Core/Texture.h"
  2. #include "RenderManagerAccess.h"
  3. namespace Rml {
  4. Texture::Texture(RenderManager* render_manager, TextureFileIndex file_index) : render_manager(render_manager), file_index(file_index) {}
  5. Texture::Texture(RenderManager* render_manager, StableVectorIndex callback_index) : render_manager(render_manager), callback_index(callback_index) {}
  6. Vector2i Texture::GetDimensions() const
  7. {
  8. if (file_index != TextureFileIndex::Invalid)
  9. return RenderManagerAccess::GetDimensions(render_manager, file_index);
  10. if (callback_index != StableVectorIndex::Invalid)
  11. return RenderManagerAccess::GetDimensions(render_manager, callback_index);
  12. return {};
  13. }
  14. Texture::operator bool() const
  15. {
  16. return callback_index != StableVectorIndex::Invalid || file_index != TextureFileIndex::Invalid;
  17. }
  18. bool Texture::operator==(const Texture& other) const
  19. {
  20. return render_manager == other.render_manager && file_index == other.file_index && callback_index == other.callback_index;
  21. }
  22. TextureSource::TextureSource(String source, String document_path) : source(std::move(source)), document_path(std::move(document_path)) {}
  23. Texture TextureSource::GetTexture(RenderManager& render_manager) const
  24. {
  25. Texture& texture = textures[&render_manager];
  26. if (!texture)
  27. texture = render_manager.LoadTexture(source, document_path);
  28. return texture;
  29. }
  30. const String& TextureSource::GetSource() const
  31. {
  32. return source;
  33. }
  34. const String& TextureSource::GetDefinitionSource() const
  35. {
  36. return document_path;
  37. }
  38. } // namespace Rml