Skip to content

Commit b35e537

Browse files
committed
#5972 Track UI texture changes
1 parent 2a75b42 commit b35e537

2 files changed

Lines changed: 39 additions & 11 deletions

File tree

indra/llrender/lluiimage.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,17 @@ S32 LLUIImage::getHeight() const
7777

7878
buffer_data_list_t* LLUIImage::findDisplayList(S32 x, S32 y, S32 width, S32 height, const LLColor4& color, bool solid_color) const
7979
{
80+
LLImageGL* gl_image = mImage->getGLTexture();
81+
if (!gl_image)
82+
{
83+
return nullptr;
84+
}
85+
8086
LLVector3 ui_translation = gGL.getUITranslation();
8187
LLVector3 ui_scale = gGL.getUIScale();
88+
LLGLuint tex_name = gl_image->getTexName();
8289

83-
auto key = PackedKey::create(x, y, width, height, color, solid_color, ui_translation, ui_scale);
90+
auto key = PackedKey::create(x, y, width, height, color, solid_color, ui_translation, ui_scale, tex_name);
8491

8592
auto it = mDisplayLists.find(key);
8693
if (it != mDisplayLists.end())
@@ -94,9 +101,23 @@ buffer_data_list_t* LLUIImage::findDisplayList(S32 x, S32 y, S32 width, S32 heig
94101
buffer_data_list_t* LLUIImage::genDisplayList(S32 x, S32 y, S32 width, S32 height, const LLColor4& color, bool solid_color) const
95102
{
96103
LL_PROFILE_ZONE_SCOPED;
104+
105+
LLImageGL* gl_image = mImage->getGLTexture();
106+
if (!gl_image)
107+
{
108+
// Don't cache when texture hasn't been created yet
109+
// draw just aborts in this case, so don't draw either.
110+
return nullptr;
111+
}
112+
97113
LLVector3 ui_translation = gGL.getUITranslation();
98114
LLVector3 ui_scale = gGL.getUIScale();
99-
auto key = PackedKey::create(x, y, width, height, color, solid_color, ui_translation, ui_scale);
115+
116+
// Get the GL texture name - this uniquely identifies the current texture state
117+
// including discard level changes, texture recreation, etc.
118+
LLGLuint tex_name = gl_image->getTexName();
119+
120+
auto key = PackedKey::create(x, y, width, height, color, solid_color, ui_translation, ui_scale, tex_name);
100121

101122
CachedDisplayList cached;
102123
cached.last_used = std::chrono::steady_clock::now();

indra/llrender/lluiimage.h

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,34 +127,38 @@ class LLUIImage : public LLRefCount
127127
// Packed key for identifying unique display list configurations
128128
struct PackedKey
129129
{
130-
uint64_t position; // x and y coordinates
131-
uint64_t color_flags; // RGBA color + solid_color flag
132-
uint64_t dimensions; // width and height
133-
uint64_t translate; // UI offset
134-
uint64_t scale; // UI scale
130+
uint64_t position; // x and y coordinates (32 bits each)
131+
uint64_t color_flags; // RGBA color (8 bits each) + solid_color flag (1 bit)
132+
uint64_t dimensions; // width and height (32 bits each)
133+
uint64_t translate; // UI translation (32 bits each for X and Y)
134+
uint64_t scale; // UI scale (32 bits each for X and Y)
135+
uint64_t tex_name; // OpenGL texture name (32 bits) + padding
135136

136137
constexpr bool operator==(const PackedKey& other) const
137138
{
138139
return position == other.position &&
139140
color_flags == other.color_flags &&
140141
dimensions == other.dimensions &&
141142
translate == other.translate &&
142-
scale == other.scale;
143+
scale == other.scale &&
144+
tex_name == other.tex_name;
143145
}
144146

145147
struct Hash
146148
{
147149
std::size_t operator()(const PackedKey& key) const
148150
{
149151
return static_cast<std::size_t>(key.position ^ key.color_flags ^
150-
key.dimensions ^ key.translate ^ key.scale);
152+
key.dimensions ^ key.translate ^
153+
key.scale ^ key.tex_name);
151154
}
152155
};
153156

154157
// Static factory function to create PackedKey from parameters
155158
static constexpr PackedKey create(S32 x, S32 y, S32 width, S32 height,
156159
const LLColor4& color, bool solid_color,
157-
const LLVector3& translate, const LLVector3& scale)
160+
const LLVector3& translate, const LLVector3& scale,
161+
LLGLuint texture_name)
158162
{
159163
auto float_to_u8 = [](F32 f) -> uint8_t {
160164
return static_cast<uint8_t>(llclamp(f * 255.0f, 0.0f, 255.0f));
@@ -187,7 +191,10 @@ class LLUIImage : public LLRefCount
187191
uint64_t scl = (static_cast<uint64_t>(float_to_bits(scale.mV[VX])) << 32) |
188192
static_cast<uint64_t>(float_to_bits(scale.mV[VY]));
189193

190-
return PackedKey{ pos, col, dim, trns, scl };
194+
// Store full 32-bit texture name in lower 32 bits (upper 32 bits unused/zero)
195+
uint64_t tex = static_cast<uint64_t>(texture_name);
196+
197+
return PackedKey{ pos, col, dim, trns, scl, tex };
191198
}
192199
};
193200

0 commit comments

Comments
 (0)