soul searching on the whole Sprite/Texture thing. It seems like SFML encourages batches of Textures to be loaded vs a constant stream of new Textures like this application will be producing. So, methinks it's time to venture out into some vulkan 2d graphics libraries

This commit is contained in:
2019-07-08 23:47:15 -07:00
parent cc5b2a346e
commit 807597ebaf
3 changed files with 589 additions and 26 deletions

View File

@@ -40,6 +40,7 @@ use vulkano::pipeline::ComputePipeline;
use vulkano::sync::GpuFuture;
use shaderc::CompileOptions;
use shade_runner::CompileError;
use crate::workpiece::{WorkpieceLoader, Workpiece};
mod slider;
mod timer;
@@ -47,14 +48,62 @@ mod input;
mod vkprocessor;
mod util;
mod button;
mod workpiece;
/*
What next?
Second sprite for rendering paths at x10 or so resolution
color bucketing
Textures and Sprites cannot live in the same struct as there is no way for a sprite to own
its texture and become a single object (rust self-referencing structs)
I want to pull out the textures into their own managing struct instead
But I want to be able to modify the texture after I give it to a sprite which is an issue
So if I place all the textures in a single container and then let a sprite borrow that container
I will no longer be able to modify any of the textures
I have to pass in the textures to the sprite individually so they don't get borrow poisoned
It seems like I can put the textures in a struct as long as I pass the struct.texture explicitly
So at first glance it seems like we need to
+ create a texture
+ assign that texture to a sprite
And any time we want to update the texture. We need to delete the sprite
So I'm kinda coming to the conclusion here that rust SFML is not made for
frequent updates to the screen...
Let's take a look at how easy it would be to replace SFML...
e.g
*/
/// ```
/// struct Thing<'a> {
/// field1: Option<&'a mut Thing<'a>>
/// }
///
/// fn main() {
/// let mut thing1 = Thing { field1: None };
/// let mut thing2 = Thing { field1: None };
///
/// thing1.field1 = Some(&mut thing2);
/// thing1.field1 = Some(&mut thing2); <-- Second mutable borrow error
/// }
/// ```
// What next?
// Second sprite for rendering paths at x10 or so resolution
// color bucketing
fn main() {
let font = Font::from_file("resources/fonts/sansation.ttf").unwrap();
let instance = Instance::new(None, &InstanceExtensions::none(), None).unwrap();
@@ -76,11 +125,19 @@ fn main() {
let mut input = Input::new();
let xy = processor.xy;
let mut bg_texture = Texture::new(xy.0, xy.1).unwrap();
bg_texture.update_from_pixels(processor.read_image().as_slice(), xy.0, xy.1, 0, 0);
let mut background_sprite = Sprite::with_texture(&bg_texture);
background_sprite.set_position((0., 0.));
let mut workpieceloader = WorkpieceLoader::new(String::from("resources/images/funky-bird.jpg"));
workpieceloader.load_first_stage(processor.read_image());
let mut workpiece = Workpiece::new();
workpiece.render_sprite.set_texture(&mut workpieceloader.first_stage_texture, false);
// workpiece.render_sprite.set_texture(&mut workpieceloader.swatch_texture, false);
// workpiece.render_sprite.set_texture(&mut workpieceloader.vec.get(0).unwrap(), false);
workpiece.render_sprite.set_texture(&mut workpieceloader.vec.get(0).unwrap(), false);
workpiece.render_sprite = Sprite::new();
workpieceloader.first_stage_texture.set_smooth(false);
let mut slider = Slider::new(Vector2f::new(40.0, 40.0), None, &font);
@@ -127,9 +184,9 @@ fn main() {
},
Event::MouseWheelScrolled { wheel, delta, x, y } => {
if delta > 0.0 {
background_sprite.set_scale(background_sprite.get_scale()*Vector2f::new(1.1,1.1));
workpiece.render_sprite.set_scale(workpiece.render_sprite.get_scale()*Vector2f::new(1.1,1.1));
} else {
background_sprite.set_scale(background_sprite.get_scale()*Vector2f::new(0.9,0.9));
workpiece.render_sprite.set_scale(workpiece.render_sprite.get_scale()*Vector2f::new(0.9,0.9));
}
},
_ => {}
@@ -141,8 +198,8 @@ fn main() {
if input.is_mousebutton_held(Button::Middle) {
let delta = mouse_xy - mouse::desktop_position();
mouse_xy = mouse::desktop_position();
background_sprite.set_position(
background_sprite.position() - Vector2f::new(delta.x as f32, delta.y as f32)
workpiece.render_sprite.set_position(
workpiece.render_sprite.position() - Vector2f::new(delta.x as f32, delta.y as f32)
);
}
@@ -160,7 +217,7 @@ fn main() {
window.clear(&Color::BLACK);
window.draw(&background_sprite);
window.draw(&workpiece.render_sprite);
window.draw(&slider);