Commit 4621b57d authored by robbycerantola's avatar robbycerantola

render portion or full window very fast, but without transparency

parent 183f9576
......@@ -3,7 +3,7 @@ extern crate time;
use orbclient::{Color, Window, Renderer, EventOption};
const TIMES:i32 = 100;
const TIMES:i32 = 10;
fn main() {
//let (width, height) = orbclient::get_display_size().unwrap();
......@@ -21,6 +21,7 @@ fn main() {
let data = vec![Color::rgba(100,200,10,20);412500];
let data2 = vec![Color::rgba(200,100,10,20);412500];
let data3 = vec![Color::rgba(10,100,200,20);800];
let data4 = vec![Color::rgba(10,100,200,20);480000];
//draw image benchmarking
println!("Benchmarking implementations to draw an image on window:");
......@@ -36,7 +37,7 @@ fn main() {
t = time::now();
for _i in 0..TIMES {
window.image_fast(140,240,750,550, &data2[..]);
window.image_fast(40,40,750,550, &data2[..]);
}
t2 = time::now();
let dt2 = (t2-t)/TIMES;
......@@ -48,12 +49,22 @@ fn main() {
t = time::now();
for _i in 0..TIMES {
window.image(0,0,800,1, &data3[..]);
window.image(0,0,800,10, &data3[..]);
}
t2 = time::now();
let dt3 = (t2-t)/TIMES;
println!("image wrapper {:?}",dt3);
println!("Overwrite window!");
t = time::now();
for _i in 0..TIMES {
window.image_over(80, &data4[..380000]);
}
t2 = time::now();
let dt4 = (t2-t)/TIMES;
println!("window blit {:?}",dt4);
window.sync();
'events: loop {
......
......@@ -59,9 +59,7 @@ fn main() {
window.char(200, 200, '═', Color::rgb(0, 0, 0));
window.char(208, 200, '═', Color::rgb(0, 0, 0));
// testing for non existent x,y position : does not panic but returns Color(0,0,0,0)
let _non_existent_pixel = window.getpixel(width as i32 +10,height as i32 +10);
......
......@@ -316,6 +316,16 @@ pub trait Renderer {
}
}
///Display an image overwriting a portion of window starting at given line : very quick!!
fn image_over (&mut self, start: i32, image_data: &[Color]) {
let start = start as usize * self.width() as usize;
let stop = start + image_data.len();
let window_data = self.data_mut();
if image_data.len() + start > window_data.len() {return};
window_data[start..stop].copy_from_slice(image_data);
}
// Speed improved, but image has to be all inside of window boundary
fn image_fast (&mut self, start_x: i32, start_y: i32, w: u32, h: u32, image_data: &[Color]) {
let window_w = self.width() as usize;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment