Files
phy/egui/load/trait.TextureLoader.html
Orion Kindel 0ce894e6b0 doc
2025-03-18 10:30:23 -05:00

54 lines
11 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="A `TextureLoader` uploads a `ColorImage` to the GPU, returning a `SizedTexture`."><title>TextureLoader in egui::load - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="egui" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.0 (9fc6b4312 2025-01-07)" data-channel="1.84.0" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../egui/index.html">egui</a><span class="version">0.30.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Texture<wbr>Loader</a></h2><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.byte_size" title="byte_size">byte_size</a></li><li><a href="#tymethod.forget" title="forget">forget</a></li><li><a href="#tymethod.forget_all" title="forget_all">forget_all</a></li><li><a href="#tymethod.id" title="id">id</a></li><li><a href="#tymethod.load" title="load">load</a></li></ul><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.end_pass" title="end_pass">end_pass</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In egui::<wbr>load</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">egui</a>::<wbr><a href="index.html">load</a></span><h1>Trait <span class="trait">TextureLoader</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/egui/load.rs.html#487-536">Source</a> </span></div><pre class="rust item-decl"><code>pub trait TextureLoader {
// Required methods
fn <a href="#tymethod.id" class="fn">id</a>(&amp;self) -&gt; &amp;<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.str.html">str</a>;
<span class="item-spacer"></span> fn <a href="#tymethod.load" class="fn">load</a>(
&amp;self,
ctx: &amp;<a class="struct" href="../struct.Context.html" title="struct egui::Context">Context</a>,
uri: &amp;<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.str.html">str</a>,
texture_options: <a class="struct" href="../struct.TextureOptions.html" title="struct egui::TextureOptions">TextureOptions</a>,
size_hint: <a class="enum" href="enum.SizeHint.html" title="enum egui::load::SizeHint">SizeHint</a>,
) -&gt; <a class="type" href="type.TextureLoadResult.html" title="type egui::load::TextureLoadResult">TextureLoadResult</a>;
<span class="item-spacer"></span> fn <a href="#tymethod.forget" class="fn">forget</a>(&amp;self, uri: &amp;<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.str.html">str</a>);
<span class="item-spacer"></span> fn <a href="#tymethod.forget_all" class="fn">forget_all</a>(&amp;self);
<span class="item-spacer"></span> fn <a href="#tymethod.byte_size" class="fn">byte_size</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a>;
// Provided method
fn <a href="#method.end_pass" class="fn">end_pass</a>(&amp;self, frame_index: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a>) { ... }
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A <code>TextureLoader</code> uploads a <a href="../struct.ColorImage.html" title="struct egui::ColorImage"><code>ColorImage</code></a> to the GPU, returning a <a href="struct.SizedTexture.html" title="struct egui::load::SizedTexture"><code>SizedTexture</code></a>.</p>
<p><code>egui</code> comes with an implementation that uses <a href="../struct.Context.html#method.load_texture" title="method egui::Context::load_texture"><code>Context::load_texture</code></a>,
which just asks the egui backend to upload the image to the GPU.</p>
<p>You can implement this trait if you do your own uploading of images to the GPU.
For instance, you can use this to refer to textures in a game engine that egui
doesnt otherwise know about.</p>
<p>Implementations are expected to cache each combination of <code>(URI, TextureOptions)</code>.</p>
</div></details><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.id" class="method"><a class="src rightside" href="../../src/egui/load.rs.html#494">Source</a><h4 class="code-header">fn <a href="#tymethod.id" class="fn">id</a>(&amp;self) -&gt; &amp;<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.str.html">str</a></h4></section></summary><div class="docblock"><p>Unique ID of this loader.</p>
<p>To reduce the chance of collisions, include <code>module_path!()</code> as part of this ID.</p>
<p>For example: <code>concat!(module_path!(), "::MyLoader")</code>
for <code>my_crate::my_loader::MyLoader</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.load" class="method"><a class="src rightside" href="../../src/egui/load.rs.html#508-514">Source</a><h4 class="code-header">fn <a href="#tymethod.load" class="fn">load</a>(
&amp;self,
ctx: &amp;<a class="struct" href="../struct.Context.html" title="struct egui::Context">Context</a>,
uri: &amp;<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.str.html">str</a>,
texture_options: <a class="struct" href="../struct.TextureOptions.html" title="struct egui::TextureOptions">TextureOptions</a>,
size_hint: <a class="enum" href="enum.SizeHint.html" title="enum egui::load::SizeHint">SizeHint</a>,
) -&gt; <a class="type" href="type.TextureLoadResult.html" title="type egui::load::TextureLoadResult">TextureLoadResult</a></h4></section></summary><div class="docblock"><p>Try loading the texture from the given uri.</p>
<p>Implementations should call <code>ctx.request_repaint</code> to wake up the ui
once the texture is ready.</p>
<p>The implementation should cache any result, so that calling this
is immediate-mode safe.</p>
<h5 id="errors"><a class="doc-anchor" href="#errors">§</a>Errors</h5>
<p>This may fail with:</p>
<ul>
<li><a href="enum.LoadError.html#variant.NotSupported" title="variant egui::load::LoadError::NotSupported"><code>LoadError::NotSupported</code></a> if the loader does not support loading <code>uri</code>.</li>
<li><a href="enum.LoadError.html#variant.Loading" title="variant egui::load::LoadError::Loading"><code>LoadError::Loading</code></a> if the loading process failed.</li>
</ul>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.forget" class="method"><a class="src rightside" href="../../src/egui/load.rs.html#520">Source</a><h4 class="code-header">fn <a href="#tymethod.forget" class="fn">forget</a>(&amp;self, uri: &amp;<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.str.html">str</a>)</h4></section></summary><div class="docblock"><p>Forget the given <code>uri</code>.</p>
<p>If <code>uri</code> is cached, it should be evicted from cache,
so that it may be fully reloaded.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.forget_all" class="method"><a class="src rightside" href="../../src/egui/load.rs.html#526">Source</a><h4 class="code-header">fn <a href="#tymethod.forget_all" class="fn">forget_all</a>(&amp;self)</h4></section></summary><div class="docblock"><p>Forget all URIs ever given to this loader.</p>
<p>If the loader caches any URIs, the entire cache should be cleared,
so that all of them may be fully reloaded.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.byte_size" class="method"><a class="src rightside" href="../../src/egui/load.rs.html#535">Source</a><h4 class="code-header">fn <a href="#tymethod.byte_size" class="fn">byte_size</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a></h4></section></summary><div class="docblock"><p>If the loader caches any data, this should return the size of that cache.</p>
</div></details></div><h2 id="provided-methods" class="section-header">Provided Methods<a href="#provided-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="method.end_pass" class="method"><a class="src rightside" href="../../src/egui/load.rs.html#530-532">Source</a><h4 class="code-header">fn <a href="#method.end_pass" class="fn">end_pass</a>(&amp;self, frame_index: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a>)</h4></section></summary><div class="docblock"><p>Implementations may use this to perform work at the end of a pass,
such as evicting unused entries from a cache.</p>
</div></details></div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-TextureLoader-for-DefaultTextureLoader" class="impl"><a class="src rightside" href="../../src/egui/load/texture_loader.rs.html#11-74">Source</a><a href="#impl-TextureLoader-for-DefaultTextureLoader" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.TextureLoader.html" title="trait egui::load::TextureLoader">TextureLoader</a> for <a class="struct" href="struct.DefaultTextureLoader.html" title="struct egui::load::DefaultTextureLoader">DefaultTextureLoader</a></h3></section></div><script src="../../trait.impl/egui/load/trait.TextureLoader.js" async></script></section></div></main></body></html>