From af5e8f365478f62bc5108217317e70a6ee1accf4 Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Wed, 4 Mar 2020 01:26:52 -0600 Subject: workable viewport structure --- src/tom.rs | 86 ++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 42 insertions(+), 44 deletions(-) (limited to 'src/tom.rs') diff --git a/src/tom.rs b/src/tom.rs index d1daa0a..dfdc846 100644 --- a/src/tom.rs +++ b/src/tom.rs @@ -1,26 +1,12 @@ use luminance::context::GraphicsContext; -use luminance::pipeline::{PipelineState, Viewport}; +use luminance::framebuffer::Framebuffer; +use luminance::pipeline::PipelineState; use luminance::render_state::RenderState; use luminance::shader::program::Program; -use luminance::tess::{Mode, TessBuilder, TessSliceIndex}; -use luminance_derive::{Semantics, Vertex}; -use luminance_glfw::{GlfwSurface, Surface, WindowDim, WindowEvent, WindowOpt}; +use luminance::tess::{Mode, Tess, TessBuilder, TessSliceIndex}; +use luminance::texture::Dim2; -#[derive(Vertex)] -#[vertex(sem = "VertexSemantics")] -pub struct Vertex { - position: VertexPosition, - #[vertex(normalized = "true")] - color: VertexRGB, -} - -#[derive(Copy, Clone, Debug, Semantics)] -pub enum VertexSemantics { - #[sem(name = "position", repr = "[f32; 2]", wrapper = "VertexPosition")] - Position, - #[sem(name = "color", repr = "[u8; 3]", wrapper = "VertexRGB")] - Color, -} +use crate::vertex::{Vertex, VertexPosition, VertexRGB, VertexSemantics}; fn gen_vertices() -> Vec { let mut vertices: Vec = Vec::new(); @@ -43,54 +29,66 @@ fn gen_vertices() -> Vec { fn alter_vertices(vertices: &mut Vec) { for vertex in vertices { - vertex.position[0] += 0.01; - if vertex.color[1] < 255 { - vertex.color[1] += 1; + if vertex.color[0] < 255 { + vertex.color[0] += 1; } } } pub struct Tom { vertices: Vec, - //tessalation: Tess, + tessalation: Tess, } impl Tom { - pub fn new() -> Tom { - let mut vertices = gen_vertices(); - //let tessalation = TessBuilder::new(&mut surface) - // .add_vertices(&vertices) - // .set_mode(Mode::Triangle) - // .build() - // .unwrap(); - Tom { - vertices, - // tessalation, - } + pub fn new(mut surface: T) -> (Tom, T) { + let vertices = gen_vertices(); + let tessalation = TessBuilder::new(&mut surface) + .add_vertices(&vertices) + .set_mode(Mode::Triangle) + .build() + .unwrap(); + + ( + Tom { + vertices, + tessalation, + }, + surface, + ) } - pub fn update(&mut self) { + pub fn update(&mut self, mut surface: T) -> T { alter_vertices(&mut self.vertices); - //let tessalation = TessBuilder::new(&mut surface) - // .add_vertices(&self.vertices) - // .set_mode(Mode::Triangle) - // .build() - // .unwrap(); + + self.tessalation = TessBuilder::new(&mut surface) + .add_vertices(&self.vertices) + .set_mode(Mode::Triangle) + .build() + .unwrap(); + + surface } - pub fn draw(&self) { - /* + pub fn draw( + &self, + mut surface: T, + back_buffer: &Framebuffer, + program: &Program, + pipeline_state: &PipelineState, + ) -> T { surface.pipeline_builder().pipeline( &back_buffer, &pipeline_state, |_pipeline, mut shd_gate| { shd_gate.shade(&program, |_, mut rdr_gate| { rdr_gate.render(&RenderState::default(), |mut tess_gate| { - //tess_gate.render(triangle.slice(..)); + tess_gate.render(self.tessalation.slice(..)); }); }); }, ); - */ + + surface } } -- cgit v1.2.3