Skip to content

Commit 522ff1c

Browse files
haroonqcopybara-github
authored andcommitted
Allow ImGui uploaded images to be resized or destroyed.
PiperOrigin-RevId: 846354598 Change-Id: I86882813ab607945fffc763122248e167be856a8
1 parent b5b654f commit 522ff1c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/experimental/filament/filament/gui_view.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,24 @@ uintptr_t GuiView::UploadImage(uintptr_t tex_id, const uint8_t* pixels,
125125
mju_error("Texture not found: %lu", tex_id);
126126
}
127127
texture = iter->second;
128+
129+
if (pixels == nullptr) {
130+
// A nullptr implies that the user wants to destroy the texture.
131+
engine->destroy(texture);
132+
textures_.erase(tex_id);
133+
return 0;
134+
} else if (texture->getWidth() != width || texture->getHeight() != height) {
135+
// Recreate the texture if the dimensions have changed.
136+
engine->destroy(texture);
137+
texture = filament::Texture::Builder()
138+
.width(width)
139+
.height(height)
140+
.levels(1)
141+
.format(internal_format)
142+
.sampler(filament::Texture::Sampler::SAMPLER_2D)
143+
.build(*engine);
144+
textures_[tex_id] = texture;
145+
}
128146
}
129147

130148
// Create a copy of the image to pass it to filament as we don't know the

0 commit comments

Comments
 (0)