1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
use bytes::Bytes;
use crate::engine::d2::{
asset::AssetFormat,
display::{Graphics, Texture},
util::Value,
};
/// Functions related to the device's renderer.
pub trait RendererSystem {
/// The type of this renderer.
fn render_type(&self) -> RendererType;
/// The maximum width and height of a Texture on this renderer, in pixels. Guaranteed to be at
/// least 1024.
fn max_texture_size(&self) -> i32;
/// Whether the renderer currently has a GPU context. In some renderers the
/// GPU and all its resources may be destroyed at any time by the system. On renderers that don't
/// need to worry about reclaiming GPU resources (Canvas) this is always true.
/// *
/// When this becomes false, all Textures and Graphics objects are destroyed and become invalid.
/// When it returns to true, apps should reload its textures.
fn has_gpu(&self) -> Value<bool>;
/// Creates a new blank texture, initialized to transparent black.
/// *
/// @param width The width of the texture, in pixels.
/// @param height The height of the texture, in pixels.
/// *
/// @returns The new texture, or None if the GPU context is currently unavailable.
fn create_texture(&self, width: i32, height: i32) -> Box<dyn Texture>;
// /// Creates a new texture from native image data. Normally you should use
// /// `System::loadAssetPack()` to load textures, but this can be useful for working with external
// /// code that deals with native images.
// /// *
// /// @param image The platform-specific image data.
// /// *
// /// @returns The new texture, or None if the GPU context is currently unavailable.
// fn createTextureFromImage(&self, image: NativeImage) -> Box<dyn Texture>;
// fn createBuffer (&self, size: i32) ->Buffer;
// fn createShader (&self, glsl :String) ->Shader;
fn graphics(&self) -> Box<dyn Graphics>;
/// The compressed texture formats supported by this renderer.
fn compressed_texture_formats(&self) -> Vec<AssetFormat>;
fn create_compressed_texture(&self, format: AssetFormat, data: Bytes) -> Box<dyn Texture>;
/// Notifies the renderer that things are about to be drawn.
fn will_render(&self);
/// Notifies the renderer that drawing the frame is complete.
fn did_render(&self);
}
pub enum RendererType {
GLES,
WebGL,
Canvas,
}