Expand description
Image loading traits and texture cache integration for crate::renderer::RaylibRender.
Path-based images from cotis-defaults implement RaylibLoadableImage and
GenericCompatibleImage. Custom Image element data
can integrate by implementing these traits and using RaylibRender::translate_generic_image to
populate the renderer cache.
§Custom image extension
ⓘ
use std::sync::Arc;
use cotis_raylib::drawables::RaylibDrawContext;
use cotis_raylib::raylib_images::{GenericCompatibleImage, RaylibLoadableImage};
use cotis_raylib::renderer::RaylibRender;
use raylib::prelude::Texture2D;
struct MyImage { path: String }
impl RaylibLoadableImage for MyImage {
fn get_filename(&self) -> &str { &self.path }
}
impl GenericCompatibleImage for MyImage {
fn load_texture(&self, _ctx: &mut RaylibDrawContext<'_, '_>) {}
fn get_texture(&self, ctx: &RaylibDrawContext<'_, '_>) -> Arc<Texture2D> {
ctx.image_cache.expect("cache required").get(&self.path).unwrap().clone()
}
}
// Preload before drawing:
// render.translate_generic_image(&my_image);Traits§
- Generic
Compatible Image - Two-phase image draw: optional per-frame setup, then texture lookup from cache.
- Raylib
Loadable Image - Path-based image data that can be loaded into the renderer texture cache.
- Texture2D
Holder - Abstraction over owned and borrowed raylib textures.