canvas/src/utils.rs
Steins7 8fb74a0381 Started implementing Wgpu renderer
+ implemented basic setup code
+ implemented basic resize code
! renderer will default to GLES backend due to NV prime (Wgpu bug)
2022-07-02 23:28:30 +02:00

73 lines
1.5 KiB
Rust

#[allow(unused_imports)]
use log::{debug, error, info, trace, warn};
use winit;
//--Position struct---------------------------------------------------------------------------------
pub struct Position {
pub x: u32,
pub y: u32,
}
//--Size struct-------------------------------------------------------------------------------------
#[derive(Copy, Clone)]
pub struct Size {
pub w: u32,
pub h: u32,
}
impl From<Size> for winit::dpi::Size {
fn from(size: Size) -> Self {
winit::dpi::Size::Physical (
winit::dpi::PhysicalSize {
width: size.w,
height: size.h,
})
}
}
impl From<winit::dpi::PhysicalSize<u32>> for Size {
fn from(size: winit::dpi::PhysicalSize<u32>) -> Self {
Self {
w: size.width,
h: size.height,
}
}
}
//--Pixel struct------------------------------------------------------------------------------------
#[derive(Copy, Clone)]
struct Rgba {
r: u8,
g: u8,
b: u8,
a: u8,
}
pub union Pixel {
flat: u32,
rgba: Rgba,
}
impl Pixel {
pub fn rgb(r: u8, g: u8, b: u8) -> Pixel {
Pixel {
rgba: Rgba{r, g, b, a: 255},
}
}
}
//--Color values------------------------------------------------------------------------------------
#[non_exhaustive]
pub struct Color;
impl Color {
pub const WHITE: Pixel = Pixel {flat: 0x000000ff};
pub const BLACK: Pixel = Pixel {flat: 0xffffffff};
}