Allow binding to arbitrary textures.

PiperOrigin-RevId: 836625847
Change-Id: If02ea708f49bdfd9be5be7d9a273340ba2f082f0
This commit is contained in:
Haroon Qureshi
2025-11-25 05:25:14 -08:00
committed by Copybara-Service
parent 589e013d9b
commit f28bcc4346
2 changed files with 9 additions and 4 deletions
@@ -165,9 +165,10 @@ bool GuiView::PrepareRenderable() {
clip_height = height;
}
const intptr_t tex_id = reinterpret_cast<intptr_t>(command.GetTexID());
mjrRect clip_rect{clip_left, clip_bottom, clip_width, clip_height};
builder.material(drawable_index,
GetMaterialInstance(drawable_index, clip_rect));
GetMaterialInstance(drawable_index, clip_rect, tex_id));
builder.geometry(drawable_index, kTriangles, buffer.vertex_buffer,
buffer.index_buffer, index_offset,
command.ElemCount);
@@ -186,11 +187,14 @@ bool GuiView::PrepareRenderable() {
}
filament::MaterialInstance* GuiView::GetMaterialInstance(int index,
mjrRect rect) {
mjrRect rect,
intptr_t texture_id) {
while (index >= instances_.size()) {
const filament::Texture* texture = object_mgr_->GetFont(texture_id);
filament::TextureSampler sampler;
filament::MaterialInstance* instance = material_->createInstance();
instance->setParameter("glyph", object_mgr_->GetFont(0), sampler);
instance->setParameter("glyph", texture, sampler);
instances_.push_back(instance);
}
@@ -49,7 +49,8 @@ class GuiView {
private:
// Returns the filament::MaterialInstance configured to draw into the given
// scissor rect.
filament::MaterialInstance* GetMaterialInstance(int index, mjrRect rect);
filament::MaterialInstance* GetMaterialInstance(int index, mjrRect rect,
intptr_t texture_id);
// Clears the filament::Scene of the UX renderable and releases all buffers.
void ResetRenderable();