summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Barrett <tom@tombarrett.xyz>2020-03-04 01:26:52 -0600
committerTom Barrett <tom@tombarrett.xyz>2020-03-04 01:26:52 -0600
commitaf5e8f365478f62bc5108217317e70a6ee1accf4 (patch)
treeecb72e11f3dded73eca3e46c50442008e4290c3f
parente79499cd864dc64017316ef4512991df68837576 (diff)
workable viewport structure
-rw-r--r--Cargo.lock18
-rw-r--r--Cargo.toml2
-rw-r--r--src/main.rs29
-rw-r--r--src/n1ck.rs94
-rw-r--r--src/tom.rs86
-rw-r--r--src/vertex.rs17
6 files changed, 182 insertions, 64 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 95ba3be..fedb451 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -159,6 +159,15 @@ dependencies = [
]
[[package]]
+name = "revision2020"
+version = "0.1.0"
+dependencies = [
+ "luminance 0.39.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "luminance-derive 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "luminance-glfw 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "semver"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -187,15 +196,6 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
-name = "working-title"
-version = "0.1.0"
-dependencies = [
- "luminance 0.39.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "luminance-derive 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "luminance-glfw 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
name = "xml-rs"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 503e7e8..034b691 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,5 +1,5 @@
[package]
-name = "working-title"
+name = "revision2020"
version = "0.1.0"
authors = ["Tom Barrett <tom@tombarrett.xyz>"]
edition = "2018"
diff --git a/src/main.rs b/src/main.rs
index 917bd64..b3c2e05 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,14 +1,16 @@
pub mod constants;
+pub mod n1ck;
pub mod tom;
+pub mod vertex;
use luminance::context::GraphicsContext;
use luminance::pipeline::{PipelineState, Viewport};
-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 tom::{Tom, VertexSemantics};
+
+use n1ck::N1ck;
+use tom::Tom;
+use vertex::VertexSemantics;
fn gen_viewports() -> Vec<Viewport> {
let mut viewports = Vec::new();
@@ -45,7 +47,7 @@ fn gen_viewports() -> Vec<Viewport> {
}
fn main() {
- let mut surface = GlfwSurface::new(
+ let surface = GlfwSurface::new(
WindowDim::Windowed(constants::WIDTH, constants::HEIGHT),
"revision2020",
WindowOpt::default(),
@@ -57,7 +59,9 @@ fn main() {
.unwrap()
.ignore_warnings();
- let mut tom = Tom::new();
+ let (mut tom, surface) = Tom::new(surface);
+ let (mut n1ck, mut surface) = N1ck::new(surface);
+
let viewports = gen_viewports();
let mut run = true;
@@ -67,10 +71,11 @@ fn main() {
run = false;
}
}
- let back_buffer = surface.back_buffer().unwrap();
- tom.update();
+ surface = tom.update(surface);
+ surface = n1ck.update(surface);
+ let back_buffer = surface.back_buffer().unwrap();
let mut pipeline_state = PipelineState::default();
surface
.pipeline_builder()
@@ -81,9 +86,13 @@ fn main() {
pipeline_state = pipeline_state.enable_clear_color(false);
if i == 0 {
- tom.draw();
+ surface = tom.draw(surface, &back_buffer, &program, &pipeline_state);
} else if i == 1 {
- // lowman.draw()
+ surface = n1ck.draw(surface, &back_buffer, &program, &pipeline_state);
+ } else if i == 2 {
+ surface = tom.draw(surface, &back_buffer, &program, &pipeline_state);
+ } else if i == 3 {
+ surface = n1ck.draw(surface, &back_buffer, &program, &pipeline_state);
}
}
diff --git a/src/n1ck.rs b/src/n1ck.rs
new file mode 100644
index 0000000..db77278
--- /dev/null
+++ b/src/n1ck.rs
@@ -0,0 +1,94 @@
+use luminance::context::GraphicsContext;
+use luminance::framebuffer::Framebuffer;
+use luminance::pipeline::PipelineState;
+use luminance::render_state::RenderState;
+use luminance::shader::program::Program;
+use luminance::tess::{Mode, Tess, TessBuilder, TessSliceIndex};
+use luminance::texture::Dim2;
+
+use crate::vertex::{Vertex, VertexPosition, VertexRGB, VertexSemantics};
+
+fn gen_vertices() -> Vec<Vertex> {
+ let mut vertices: Vec<Vertex> = Vec::new();
+
+ vertices.push(Vertex {
+ position: VertexPosition::new([-0.5, -0.5]),
+ color: VertexRGB::new([255, 0, 0]),
+ });
+ vertices.push(Vertex {
+ position: VertexPosition::new([0.5, -0.5]),
+ color: VertexRGB::new([0, 255, 0]),
+ });
+ vertices.push(Vertex {
+ position: VertexPosition::new([0.0, 0.5]),
+ color: VertexRGB::new([0, 0, 255]),
+ });
+
+ vertices
+}
+
+fn alter_vertices(vertices: &mut Vec<Vertex>) {
+ for vertex in vertices {
+ if vertex.color[1] < 255 {
+ vertex.color[1] += 1;
+ }
+ }
+}
+
+pub struct N1ck {
+ vertices: Vec<Vertex>,
+ tessalation: Tess,
+}
+
+impl N1ck {
+ pub fn new<T: GraphicsContext>(mut surface: T) -> (N1ck, T) {
+ let vertices = gen_vertices();
+ let tessalation = TessBuilder::new(&mut surface)
+ .add_vertices(&vertices)
+ .set_mode(Mode::Triangle)
+ .build()
+ .unwrap();
+
+ (
+ N1ck {
+ vertices,
+ tessalation,
+ },
+ surface,
+ )
+ }
+
+ pub fn update<T: GraphicsContext>(&mut self, mut surface: T) -> T {
+ alter_vertices(&mut self.vertices);
+
+ self.tessalation = TessBuilder::new(&mut surface)
+ .add_vertices(&self.vertices)
+ .set_mode(Mode::Triangle)
+ .build()
+ .unwrap();
+
+ surface
+ }
+
+ pub fn draw<T: GraphicsContext>(
+ &self,
+ mut surface: T,
+ back_buffer: &Framebuffer<Dim2, (), ()>,
+ program: &Program<VertexSemantics, (), ()>,
+ 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(self.tessalation.slice(..));
+ });
+ });
+ },
+ );
+
+ surface
+ }
+}
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<Vertex> {
let mut vertices: Vec<Vertex> = Vec::new();
@@ -43,54 +29,66 @@ fn gen_vertices() -> Vec<Vertex> {
fn alter_vertices(vertices: &mut Vec<Vertex>) {
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<Vertex>,
- //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<T: GraphicsContext>(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<T: GraphicsContext>(&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<T: GraphicsContext>(
+ &self,
+ mut surface: T,
+ back_buffer: &Framebuffer<Dim2, (), ()>,
+ program: &Program<VertexSemantics, (), ()>,
+ 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
}
}
diff --git a/src/vertex.rs b/src/vertex.rs
new file mode 100644
index 0000000..2030218
--- /dev/null
+++ b/src/vertex.rs
@@ -0,0 +1,17 @@
+use luminance_derive::{Semantics, Vertex};
+
+#[derive(Vertex)]
+#[vertex(sem = "VertexSemantics")]
+pub struct Vertex {
+ pub position: VertexPosition,
+ #[vertex(normalized = "true")]
+ pub 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,
+}