pub mod batch;
pub mod blend;
pub mod capabilities;
pub mod error;
pub mod format;
pub mod material;
pub mod occlusion;
pub mod resource;
pub mod scissor;
pub mod sync;
pub use batch::{Batch, BatchDraw, ClipRole, ClipState, Vertex};
pub use blend::{BlendFactor, BlendFactors, BlendMode};
pub use capabilities::{
Capabilities, Capability, DmaBufSupport, SampleCounts, SyncSupport, Withheld,
};
pub use error::{Error, Result};
pub use format::{Extent2D, FormatModifierSet, Fourcc, Modifier, PixelFormat};
#[derive(Debug, Clone)]
pub struct RuntimeProgram {
pub spirv: Vec<u32>,
pub glsl_es: String,
}
pub use material::{
ColorFilter, ColorForm, Gamma, Material, MaterialVariant, Sampling, Stop, TileMode,
MATERIAL_FLOATS, MAX_EFFECT_TEXTURES, MAX_STOPS, MORPHOLOGY_TAPS, RUNTIME_FLOATS,
};
pub use resource::{
mip_levels_for, BufferDescriptor, BufferUsage, TextureDescriptor, TextureUsage,
};
pub use scissor::Scissor;
pub use sync::{HalFence, FRAME_WAIT_TIMEOUT};
#[cfg(unix)]
pub use resource::{DmaBufPlane, ExternalImageDesc};
pub trait Hal: 'static {
type Context: HalContext<Hal = Self>;
type Texture: HalTexture;
type Fence: HalFence;
const NAME: &'static str;
}
pub trait HalTexture {
fn extent(&self) -> Extent2D;
fn format(&self) -> PixelFormat;
}
pub trait HalContext {
type Hal: Hal;
fn capabilities(&self) -> &Capabilities;
fn create_texture(&mut self, desc: &TextureDescriptor) -> Result<<Self::Hal as Hal>::Texture>;
fn destroy_texture(&mut self, texture: <Self::Hal as Hal>::Texture);
fn register_program(&mut self, program: &RuntimeProgram) -> Result<u32>;
fn submit_batch(
&mut self,
target: &mut <Self::Hal as Hal>::Texture,
batch: &Batch,
pass: PassDescriptor,
) -> Result<()> {
self.submit_batch_textured(target, batch, pass, &[])
}
fn submit_batch_textured(
&mut self,
target: &mut <Self::Hal as Hal>::Texture,
batch: &Batch,
pass: PassDescriptor,
textures: &[&<Self::Hal as Hal>::Texture],
) -> Result<()>;
fn read_texture(&mut self, texture: &mut <Self::Hal as Hal>::Texture) -> Result<Vec<u8>>;
fn write_texture(
&mut self,
texture: &mut <Self::Hal as Hal>::Texture,
pixels: &[u8],
) -> Result<()>;
fn create_exportable_texture(
&mut self,
_extent: Extent2D,
_format: PixelFormat,
_modifiers: &[Modifier],
) -> Result<<Self::Hal as Hal>::Texture> {
Err(Error::Unsupported("allocating exportable images"))
}
#[cfg(unix)]
fn export_texture(
&mut self,
_texture: &<Self::Hal as Hal>::Texture,
) -> Result<ExternalImageDesc> {
Err(Error::Unsupported("dma-buf export"))
}
fn submit_batch_deferred(
&mut self,
target: &mut <Self::Hal as Hal>::Texture,
batch: &Batch,
pass: PassDescriptor,
) -> Result<<Self::Hal as Hal>::Fence> {
self.submit_batch_deferred_textured(target, batch, pass, &[])
}
fn submit_batch_deferred_textured(
&mut self,
_target: &mut <Self::Hal as Hal>::Texture,
_batch: &Batch,
_pass: PassDescriptor,
_textures: &[&<Self::Hal as Hal>::Texture],
) -> Result<<Self::Hal as Hal>::Fence> {
Err(Error::Unsupported("deferred submission"))
}
fn retire_fence(&mut self, _fence: <Self::Hal as Hal>::Fence) {}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct PassDescriptor {
pub clear: Option<[f32; 4]>,
pub samples: u32,
pub viewport: Option<PassViewport>,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct PassViewport {
pub offset: [f32; 2],
pub extent: Extent2D,
}
impl Default for PassDescriptor {
fn default() -> Self {
Self {
clear: None,
samples: 1,
viewport: None,
}
}
}
impl PassDescriptor {
pub fn clear(color: [f32; 4]) -> Self {
Self {
clear: Some(color),
samples: 1,
viewport: None,
}
}
pub fn with_viewport(mut self, viewport: PassViewport) -> Self {
self.viewport = Some(viewport);
self
}
pub fn preserve() -> Self {
Self::default()
}
pub fn with_samples(mut self, samples: u32) -> Self {
self.samples = samples;
self
}
pub fn is_multisampled(&self) -> bool {
self.samples > 1
}
}