mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 07:14:46 +00:00
Precursor to triangle in editor
This commit is contained in:
parent
931910532b
commit
05e13e9842
5 changed files with 99 additions and 7 deletions
15
Cargo.lock
generated
15
Cargo.lock
generated
|
@ -103,6 +103,16 @@ version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
|
checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bincode"
|
||||||
|
version = "1.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5753e2a71534719bf3f4e57006c3a4f0d2c672a4b676eec84161f763eca87dbf"
|
||||||
|
dependencies = [
|
||||||
|
"byteorder",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "1.2.1"
|
version = "1.2.1"
|
||||||
|
@ -1812,6 +1822,7 @@ dependencies = [
|
||||||
name = "roc_editor"
|
name = "roc_editor"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"bincode",
|
||||||
"bumpalo",
|
"bumpalo",
|
||||||
"gfx-backend-dx12",
|
"gfx-backend-dx12",
|
||||||
"gfx-backend-metal",
|
"gfx-backend-metal",
|
||||||
|
@ -1844,6 +1855,7 @@ dependencies = [
|
||||||
"roc_types",
|
"roc_types",
|
||||||
"roc_unify",
|
"roc_unify",
|
||||||
"roc_uniq",
|
"roc_uniq",
|
||||||
|
"serde",
|
||||||
"target-lexicon",
|
"target-lexicon",
|
||||||
"tokio",
|
"tokio",
|
||||||
"winit",
|
"winit",
|
||||||
|
@ -2183,6 +2195,9 @@ name = "serde"
|
||||||
version = "1.0.106"
|
version = "1.0.106"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "36df6ac6412072f67cf767ebbde4133a5b2e88e76dc6187fa7104cd16f783399"
|
checksum = "36df6ac6412072f67cf767ebbde4133a5b2e88e76dc6187fa7104cd16f783399"
|
||||||
|
dependencies = [
|
||||||
|
"serde_derive",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
|
|
|
@ -51,6 +51,9 @@ target-lexicon = "0.10"
|
||||||
winit = "0.22"
|
winit = "0.22"
|
||||||
image = "0.23"
|
image = "0.23"
|
||||||
gfx-hal = "0.5"
|
gfx-hal = "0.5"
|
||||||
|
glsl-to-spirv = "0.1"
|
||||||
|
bincode = "1.2"
|
||||||
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
|
||||||
[target.'cfg(target_os = "macos")'.dependencies.backend]
|
[target.'cfg(target_os = "macos")'.dependencies.backend]
|
||||||
package = "gfx-backend-metal"
|
package = "gfx-backend-metal"
|
||||||
|
@ -73,4 +76,3 @@ maplit = "1.0.1"
|
||||||
indoc = "0.3.3"
|
indoc = "0.3.3"
|
||||||
quickcheck = "0.8"
|
quickcheck = "0.8"
|
||||||
quickcheck_macros = "0.8"
|
quickcheck_macros = "0.8"
|
||||||
|
|
||||||
|
|
8
editor/shaders/triangle.frag
Normal file
8
editor/shaders/triangle.frag
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#version 450
|
||||||
|
#extension GL_ARB_separate_shader_objects : enable
|
||||||
|
|
||||||
|
layout(location = 0) out vec4 fragment_color;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
fragment_color = vec4(0.5, 0.5, 1.0, 1.0);
|
||||||
|
}
|
15
editor/shaders/triangle.vert
Normal file
15
editor/shaders/triangle.vert
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#version 450
|
||||||
|
#extension GL_ARB_separate_shader_objects : enable
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vec2 position;
|
||||||
|
if (gl_VertexIndex == 0) {
|
||||||
|
position = vec2(0.0, -0.5);
|
||||||
|
} else if (gl_VertexIndex == 1) {
|
||||||
|
position = vec2(-0.5, 0.5);
|
||||||
|
} else if (gl_VertexIndex == 2) {
|
||||||
|
position = vec2(0.5, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
gl_Position = vec4(position, 0.0, 1.0);
|
||||||
|
}
|
|
@ -1,4 +1,11 @@
|
||||||
|
use gfx_hal::{
|
||||||
|
device::Device,
|
||||||
|
window::{Extent2D, PresentationSurface, Surface},
|
||||||
|
Instance,
|
||||||
|
};
|
||||||
|
use glsl_to_spirv::ShaderType;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
use std::mem::ManuallyDrop;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
/// The editor is actually launched from the CLI if you pass it zero arguments,
|
/// The editor is actually launched from the CLI if you pass it zero arguments,
|
||||||
|
@ -18,10 +25,38 @@ use winit::{
|
||||||
};
|
};
|
||||||
|
|
||||||
fn run_event_loop() {
|
fn run_event_loop() {
|
||||||
|
// TODO do a better window size
|
||||||
|
const WINDOW_SIZE: [u32; 2] = [512, 512];
|
||||||
|
|
||||||
let event_loop = EventLoop::new();
|
let event_loop = EventLoop::new();
|
||||||
let window = WindowBuilder::new().build(&event_loop).unwrap();
|
|
||||||
|
let (logical_window_size, physical_window_size) = {
|
||||||
|
use winit::dpi::{LogicalSize, PhysicalSize};
|
||||||
|
|
||||||
|
let dpi = event_loop.primary_monitor().scale_factor();
|
||||||
|
let logical: LogicalSize<u32> = WINDOW_SIZE.into();
|
||||||
|
let physical: PhysicalSize<u32> = logical.to_physical(dpi);
|
||||||
|
|
||||||
|
(logical, physical)
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut surface_extent = Extent2D {
|
||||||
|
width: physical_window_size.width,
|
||||||
|
height: physical_window_size.height,
|
||||||
|
};
|
||||||
|
|
||||||
|
let window = WindowBuilder::new()
|
||||||
|
.with_title("roc")
|
||||||
|
.with_inner_size(logical_window_size)
|
||||||
|
.build(&event_loop)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let mut should_configure_swapchain = true;
|
||||||
|
|
||||||
event_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
|
use winit::event::{Event, WindowEvent};
|
||||||
|
use winit::event_loop::ControlFlow;
|
||||||
|
|
||||||
// TODO try ControlFlow::Poll and see if it affects input latency.
|
// TODO try ControlFlow::Poll and see if it affects input latency.
|
||||||
// Otherwise, this seems like a better default for minimizing idle
|
// Otherwise, this seems like a better default for minimizing idle
|
||||||
// CPU usage and battry drain. (Might want to switch to Poll whenever
|
// CPU usage and battry drain. (Might want to switch to Poll whenever
|
||||||
|
@ -30,12 +65,29 @@ fn run_event_loop() {
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
event: WindowEvent::CloseRequested,
|
event: window_event,
|
||||||
..
|
..
|
||||||
} => {
|
} => match window_event {
|
||||||
|
WindowEvent::CloseRequested => {
|
||||||
println!("✈️ Thank you for flying Roc Airlines!");
|
println!("✈️ Thank you for flying Roc Airlines!");
|
||||||
*control_flow = ControlFlow::Exit
|
*control_flow = ControlFlow::Exit
|
||||||
}
|
}
|
||||||
|
WindowEvent::Resized(dims) => {
|
||||||
|
surface_extent = Extent2D {
|
||||||
|
width: dims.width,
|
||||||
|
height: dims.height,
|
||||||
|
};
|
||||||
|
should_configure_swapchain = true;
|
||||||
|
}
|
||||||
|
WindowEvent::ScaleFactorChanged { new_inner_size, .. } => {
|
||||||
|
surface_extent = Extent2D {
|
||||||
|
width: new_inner_size.width,
|
||||||
|
height: new_inner_size.height,
|
||||||
|
};
|
||||||
|
should_configure_swapchain = true;
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
},
|
||||||
Event::MainEventsCleared => window.request_redraw(),
|
Event::MainEventsCleared => window.request_redraw(),
|
||||||
Event::RedrawRequested(_) => {
|
Event::RedrawRequested(_) => {
|
||||||
// TODO render the editor
|
// TODO render the editor
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue