From 9c4afed302d41df3217fb6e409782ce2f4c53f78 Mon Sep 17 00:00:00 2001 From: Determinant Date: Wed, 15 Nov 2017 10:35:04 -0500 Subject: use unsafe texture feature --- Cargo.toml | 7 ++++--- src/main.rs | 12 ++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9718582..8954ae9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,8 @@ [package] name = "runes" version = "0.1.0" -authors = ["Determinant "] +authors = ["Determinant "] -[dependencies] -sdl2 = "0.31" +[dependencies.sdl2] +version = "0.31" +features = ["unsafe_textures"] diff --git a/src/main.rs b/src/main.rs index c894e02..9220694 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,7 +63,7 @@ struct SDLWindow { canvas: RefCell, events: RefCell, frame_buffer: UnsafeCell<[u8; FB_SIZE]>, - texture_creator: sdl2::render::TextureCreator, + texture: UnsafeCell } impl SDLWindow { @@ -84,7 +84,8 @@ impl SDLWindow { canvas: RefCell::new(canvas), events: RefCell::new(sdl_context.event_pump().unwrap()), frame_buffer: UnsafeCell::new([0; FB_SIZE]), - texture_creator, + texture: UnsafeCell::new(texture_creator.create_texture_streaming( + PixelFormatEnum::RGB24, WIN_WIDTH, WIN_HEIGHT).unwrap()) } } @@ -130,12 +131,11 @@ impl ppu::Screen for SDLWindow { fn render(&self) { let mut canvas = self.canvas.borrow_mut(); let fb = unsafe{&*self.frame_buffer.get()}; - let mut texture = self.texture_creator.create_texture_streaming( - PixelFormatEnum::RGB24, WIN_WIDTH, WIN_HEIGHT).unwrap(); - texture.update(Rect::new(0, 0, WIN_WIDTH, WIN_HEIGHT), fb, FB_PITCH).unwrap(); + let texture = unsafe{&mut *self.texture.get()}; + texture.update(None, fb, FB_PITCH).unwrap(); canvas.copy(&texture, None, Some(Rect::new(0, 0, WIN_WIDTH, WIN_HEIGHT))).unwrap(); canvas.present(); - canvas.set_draw_color(Color::RGB(128, 128, 128)); + //canvas.set_draw_color(Color::RGB(128, 128, 128)); canvas.clear(); } } -- cgit v1.2.3-70-g09d2