summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Barrett <tom@tombarrett.xyz>2020-03-03 08:19:43 -0600
committerTom Barrett <tom@tombarrett.xyz>2020-03-03 08:19:43 -0600
commitfebf1af1eca928aa212fd3ba2be6f1f1baa46e3f (patch)
treec5a6d42104c3748e94299178bcccfe11c14cb460
parent930579481957454e81c09da1391ec0019607c360 (diff)
every pipeline builder call clears the buffer, so only the last viewport is shown
-rw-r--r--src/constants.rs2
-rw-r--r--src/main.rs75
2 files changed, 60 insertions, 17 deletions
diff --git a/src/constants.rs b/src/constants.rs
new file mode 100644
index 0000000..4f87ae4
--- /dev/null
+++ b/src/constants.rs
@@ -0,0 +1,2 @@
+pub const WIDTH: u32 = 640;
+pub const HEIGHT: u32 = 480;
diff --git a/src/main.rs b/src/main.rs
index bf607eb..07d3857 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,5 +1,6 @@
+pub mod constants;
use luminance::context::GraphicsContext;
-use luminance::pipeline::PipelineState;
+use luminance::pipeline::{PipelineState, Viewport};
use luminance::render_state::RenderState;
use luminance::shader::program::Program;
use luminance::tess::{Mode, TessBuilder, TessSliceIndex};
@@ -50,10 +51,47 @@ fn alter_vertices(vertices: &mut Vec<Vertex>) {
}
}
+fn gen_viewports() -> Vec<Viewport> {
+ let mut viewports = Vec::new();
+
+ viewports.push(Viewport::Specific {
+ x: 0,
+ y: 0,
+ width: constants::WIDTH / 2,
+ height: constants::HEIGHT / 2,
+ });
+
+ viewports.push(Viewport::Specific {
+ x: 0,
+ y: constants::WIDTH / 2,
+ width: constants::WIDTH / 2,
+ height: constants::HEIGHT / 2,
+ });
+
+ viewports.push(Viewport::Specific {
+ x: constants::WIDTH / 2,
+ y: 0,
+ width: constants::WIDTH / 2,
+ height: constants::HEIGHT / 2,
+ });
+
+ viewports.push(Viewport::Specific {
+ x: constants::WIDTH / 2,
+ y: constants::HEIGHT / 2,
+ width: constants::WIDTH / 2,
+ height: constants::HEIGHT / 2,
+ });
+
+ viewports
+}
+
fn main() {
- let mut surface =
- GlfwSurface::new(WindowDim::Windowed(500, 500), "art", WindowOpt::default()).unwrap();
- //GlfwSurface::new(WindowDim::Fullscreen, "art", WindowOpt::default()).unwrap();
+ let mut surface = GlfwSurface::new(
+ WindowDim::Windowed(constants::WIDTH, constants::HEIGHT),
+ "art",
+ WindowOpt::default(),
+ )
+ .unwrap();
let program: Program<VertexSemantics, (), ()> =
Program::from_strings(None, include_str!("vs.glsl"), None, include_str!("fs.glsl"))
@@ -61,18 +99,16 @@ fn main() {
.ignore_warnings();
let mut vertices = gen_vertices();
+ let viewports = gen_viewports();
let mut run = true;
-
while run {
for event in surface.poll_events() {
if let WindowEvent::Close = event {
run = false;
}
}
-
let back_buffer = surface.back_buffer().unwrap();
-
alter_vertices(&mut vertices);
let triangle = TessBuilder::new(&mut surface)
@@ -81,17 +117,22 @@ fn main() {
.build()
.unwrap();
- surface.pipeline_builder().pipeline(
- &back_buffer,
- &PipelineState::default(),
- |_pipeline, mut shd_gate| {
- shd_gate.shade(&program, |_, mut rdr_gate| {
- rdr_gate.render(&RenderState::default(), |mut tess_gate| {
- tess_gate.render(triangle.slice(..));
+ let mut pipeline_state = PipelineState::default();
+ for viewport in viewports.iter() {
+ pipeline_state = pipeline_state.set_viewport(*viewport);
+
+ 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(..));
+ });
});
- });
- },
- );
+ },
+ );
+ }
surface.swap_buffers();
}