llfetchedgltfmaterial.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /**
  2. * @file llfetchedgltfmaterial.h
  3. *
  4. * $LicenseInfo:firstyear=2022&license=viewergpl$
  5. *
  6. * Copyright (c) 2022, Linden Research, Inc.
  7. *
  8. * Second Life Viewer Source Code
  9. * The source code in this file ("Source Code") is provided by Linden Lab
  10. * to you under the terms of the GNU General Public License, version 2.0
  11. * ("GPL"), unless you have obtained a separate licensing agreement
  12. * ("Other License"), formally executed by you and Linden Lab. Terms of
  13. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  14. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  15. *
  16. * There are special exceptions to the terms and conditions of the GPL as
  17. * it is applied to this Source Code. View the full text of the exception
  18. * in the file doc/FLOSS-exception.txt in this software distribution, or
  19. * online at
  20. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  21. *
  22. * By copying, modifying or distributing this software, you acknowledge
  23. * that you have read and understood your obligations described above,
  24. * and agree to abide by those obligations.
  25. *
  26. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  27. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  28. * COMPLETENESS OR PERFORMANCE.
  29. * $/LicenseInfo$
  30. */
  31. #ifndef LL_LLFETCHEDGLTFMATERIAL_H
  32. #define LL_LLFETCHEDGLTFMATERIAL_H
  33. #include <functional>
  34. #include "hbfastset.h"
  35. #include "llgltfmaterial.h"
  36. #include "llpointer.h"
  37. class LLViewerTexture;
  38. class LLViewerFetchedTexture;
  39. class LLFetchedGLTFMaterial : public LLGLTFMaterial
  40. {
  41. friend class LLGLTFMaterialList;
  42. protected:
  43. LOG_CLASS(LLFetchedGLTFMaterial);
  44. public:
  45. LL_INLINE LLFetchedGLTFMaterial()
  46. : mExpectedFlushTime(0.f),
  47. mActive(true),
  48. mFetching(false),
  49. mFetchSuccess(false)
  50. {
  51. }
  52. LLFetchedGLTFMaterial& operator=(const LLFetchedGLTFMaterial& rhs);
  53. bool operator==(const LLGLTFMaterial& rhs) const = delete;
  54. LLFetchedGLTFMaterial* asFetched() override { return this; }
  55. void onMaterialComplete(std::function<void()> mat_complete_callback);
  56. // Bind this material for rendering. media_texp is an optional media
  57. // texture that may override the base color texture.
  58. void bind(LLViewerTexture* media_texp, F32 vsize);
  59. LL_INLINE bool isFetching() const { return mFetching; }
  60. LL_INLINE bool isLoaded() const { return !mFetching && mFetchSuccess; }
  61. void addTextureEntry(LLTextureEntry* tep) override;
  62. void removeTextureEntry(LLTextureEntry* tep) override;
  63. bool replaceLocalTexture(const LLUUID& tracking_id, const LLUUID& old_id,
  64. const LLUUID& new_id) override;
  65. void updateTextureTracking() override;
  66. typedef fast_hset<LLTextureEntry*> te_list_t;
  67. LL_INLINE const te_list_t& getTexEntries() const
  68. {
  69. return mTextureEntries;
  70. }
  71. // Handy methods to easily setup a material preview. HB
  72. LLViewerTexture* getPreview();
  73. LL_INLINE void clearPreview() { mPreview = NULL; }
  74. protected:
  75. // Lifetime management
  76. LL_INLINE void materialBegin() { mFetching = true; }
  77. void materialComplete(bool success);
  78. public:
  79. // Textures used for fetching/rendering
  80. LLPointer<LLViewerFetchedTexture> mBaseColorTexture;
  81. LLPointer<LLViewerFetchedTexture> mNormalTexture;
  82. LLPointer<LLViewerFetchedTexture> mMetallicRoughnessTexture;
  83. LLPointer<LLViewerFetchedTexture> mEmissiveTexture;
  84. protected:
  85. te_list_t mTextureEntries;
  86. LLPointer<LLViewerTexture> mPreview;
  87. // Lifetime management
  88. std::vector<std::function<void()> > mCompleteCallbacks;
  89. F32 mExpectedFlushTime;
  90. bool mActive;
  91. bool mFetching;
  92. bool mFetchSuccess;
  93. };
  94. // Used in the llgltf library, to create and bind a fetched material. HB
  95. extern LLGLTFMaterial* create_fetch_material();
  96. extern void bind_fetched_material(LLGLTFMaterial* matp);
  97. // For the new implementation of the llgltf library (WIP).
  98. extern LLGLTexture* gl_texture_from_fetched(const LLUUID& id);
  99. extern LLGLTexture* gl_texture_from_local_file(const std::string& filename);
  100. extern LLGLTexture* gl_texture_from_memory(U8* datap, S32 size,
  101. const std::string& mime_type);
  102. #endif // LL_LLFETCHEDGLTFMATERIAL_H