diff options
| -rw-r--r-- | indra/llrender/lluiimage.cpp | 25 | ||||
| -rw-r--r-- | indra/llrender/lluiimage.h | 25 |
2 files changed, 39 insertions, 11 deletions
diff --git a/indra/llrender/lluiimage.cpp b/indra/llrender/lluiimage.cpp index 85754209a4..d0b6bcbf66 100644 --- a/indra/llrender/lluiimage.cpp +++ b/indra/llrender/lluiimage.cpp @@ -77,10 +77,17 @@ S32 LLUIImage::getHeight() const buffer_data_list_t* LLUIImage::findDisplayList(S32 x, S32 y, S32 width, S32 height, const LLColor4& color, bool solid_color) const { + LLImageGL* gl_image = mImage->getGLTexture(); + if (!gl_image) + { + return nullptr; + } + LLVector3 ui_translation = gGL.getUITranslation(); LLVector3 ui_scale = gGL.getUIScale(); + LLGLuint tex_name = gl_image->getTexName(); - auto key = PackedKey::create(x, y, width, height, color, solid_color, ui_translation, ui_scale); + auto key = PackedKey::create(x, y, width, height, color, solid_color, ui_translation, ui_scale, tex_name); auto it = mDisplayLists.find(key); if (it != mDisplayLists.end()) @@ -94,9 +101,23 @@ buffer_data_list_t* LLUIImage::findDisplayList(S32 x, S32 y, S32 width, S32 heig buffer_data_list_t* LLUIImage::genDisplayList(S32 x, S32 y, S32 width, S32 height, const LLColor4& color, bool solid_color) const { LL_PROFILE_ZONE_SCOPED; + + LLImageGL* gl_image = mImage->getGLTexture(); + if (!gl_image) + { + // Don't cache when texture hasn't been created yet + // draw just aborts in this case, so don't draw either. + return nullptr; + } + LLVector3 ui_translation = gGL.getUITranslation(); LLVector3 ui_scale = gGL.getUIScale(); - auto key = PackedKey::create(x, y, width, height, color, solid_color, ui_translation, ui_scale); + + // Get the GL texture name - this uniquely identifies the current texture state + // including discard level changes, texture recreation, etc. + LLGLuint tex_name = gl_image->getTexName(); + + auto key = PackedKey::create(x, y, width, height, color, solid_color, ui_translation, ui_scale, tex_name); CachedDisplayList cached; cached.last_used = std::chrono::steady_clock::now(); diff --git a/indra/llrender/lluiimage.h b/indra/llrender/lluiimage.h index 6f33c31bfe..0998ac17b4 100644 --- a/indra/llrender/lluiimage.h +++ b/indra/llrender/lluiimage.h @@ -127,11 +127,12 @@ protected: // Packed key for identifying unique display list configurations struct PackedKey { - uint64_t position; // x and y coordinates - uint64_t color_flags; // RGBA color + solid_color flag - uint64_t dimensions; // width and height - uint64_t translate; // UI offset - uint64_t scale; // UI scale + uint64_t position; // x and y coordinates (32 bits each) + uint64_t color_flags; // RGBA color (8 bits each) + solid_color flag (1 bit) + uint64_t dimensions; // width and height (32 bits each) + uint64_t translate; // UI translation (32 bits each for X and Y) + uint64_t scale; // UI scale (32 bits each for X and Y) + uint64_t tex_name; // OpenGL texture name (32 bits) + padding constexpr bool operator==(const PackedKey& other) const { @@ -139,7 +140,8 @@ protected: color_flags == other.color_flags && dimensions == other.dimensions && translate == other.translate && - scale == other.scale; + scale == other.scale && + tex_name == other.tex_name; } struct Hash @@ -147,14 +149,16 @@ protected: std::size_t operator()(const PackedKey& key) const { return static_cast<std::size_t>(key.position ^ key.color_flags ^ - key.dimensions ^ key.translate ^ key.scale); + key.dimensions ^ key.translate ^ + key.scale ^ key.tex_name); } }; // Static factory function to create PackedKey from parameters static constexpr PackedKey create(S32 x, S32 y, S32 width, S32 height, const LLColor4& color, bool solid_color, - const LLVector3& translate, const LLVector3& scale) + const LLVector3& translate, const LLVector3& scale, + LLGLuint texture_name) { auto float_to_u8 = [](F32 f) -> uint8_t { return static_cast<uint8_t>(llclamp(f * 255.0f, 0.0f, 255.0f)); @@ -187,7 +191,10 @@ protected: uint64_t scl = (static_cast<uint64_t>(float_to_bits(scale.mV[VX])) << 32) | static_cast<uint64_t>(float_to_bits(scale.mV[VY])); - return PackedKey{ pos, col, dim, trns, scl }; + // Store full 32-bit texture name in lower 32 bits (upper 32 bits unused/zero) + uint64_t tex = static_cast<uint64_t>(texture_name); + + return PackedKey{ pos, col, dim, trns, scl, tex }; } }; |
