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 --- src/main.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src') 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