From 0a62edafec35b5291d3e1db377482cc64e7ebd95 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sun, 12 Apr 2020 21:20:52 -0400 Subject: [PATCH] now trying a mix of `gl`, `glium`, `glfw` --- Cargo.lock | 232 +++++------------------------ Cargo.toml | 4 +- src/graphics_gl.rs | 354 ++++++++++++++++++++++++++++++++++++++++++++ src/graphics_grr.rs | 27 ++-- src/main.rs | 10 +- 5 files changed, 414 insertions(+), 213 deletions(-) create mode 100644 src/graphics_gl.rs diff --git a/Cargo.lock b/Cargo.lock index 53d7e7f771..0568436afa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -166,15 +166,6 @@ name = "cfg-if" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "cgl" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "gleam 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "cgl" version = "0.3.2" @@ -227,17 +218,11 @@ dependencies = [ ] [[package]] -name = "cocoa" -version = "0.18.5" +name = "cmake" +version = "0.1.42" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "block 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", - "core-graphics 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)", - "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", - "objc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -482,6 +467,14 @@ dependencies = [ "lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "gl" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "gl_generator 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "gl_generator" version = "0.10.0" @@ -513,11 +506,26 @@ dependencies = [ ] [[package]] -name = "gleam" -version = "0.6.19" +name = "glfw" +version = "0.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "gl_generator 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "glfw-sys 3.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "objc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "raw-window-handle 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "glfw-sys" +version = "3.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cmake 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -540,31 +548,6 @@ name = "glob" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "glutin" -version = "0.21.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "android_glue 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "cgl 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "cocoa 0.18.5 (registry+https://github.com/rust-lang/crates.io-index)", - "core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", - "core-graphics 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)", - "glutin_egl_sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "glutin_emscripten_sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "glutin_gles2_sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "glutin_glx_sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "glutin_wgl_sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libloading 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "objc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "osmesa-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-client 0.21.13 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winit 0.19.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "glutin" version = "0.24.0" @@ -1042,16 +1025,6 @@ dependencies = [ "shared_library 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "parking_lot" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "lock_api 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot_core 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "parking_lot" version = "0.10.0" @@ -1061,20 +1034,6 @@ dependencies = [ "parking_lot_core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "parking_lot_core" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "parking_lot_core" version = "0.7.0" @@ -1245,14 +1204,6 @@ name = "rustc-hash" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "rusttype" version = "0.7.9" @@ -1322,35 +1273,11 @@ name = "slab" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "smallvec" -version = "0.6.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "smallvec" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "smithay-client-toolkit" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "andrew 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "dlib 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "nix 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-client 0.21.13 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-commons 0.21.13 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-protocols 0.21.13 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "smithay-client-toolkit" version = "0.6.6" @@ -1381,8 +1308,10 @@ dependencies = [ "enum_primitive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "genmesh 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "gfx 0.18.2 (registry+https://github.com/rust-lang/crates.io-index)", + "gl 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", + "glfw 0.37.0 (registry+https://github.com/rust-lang/crates.io-index)", "glium 0.27.0 (registry+https://github.com/rust-lang/crates.io-index)", - "glutin 0.21.2 (registry+https://github.com/rust-lang/crates.io-index)", + "glutin 0.24.0 (registry+https://github.com/rust-lang/crates.io-index)", "grr 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "image 0.23.2 (registry+https://github.com/rust-lang/crates.io-index)", "k4a-sys 0.2.0", @@ -1480,20 +1409,6 @@ dependencies = [ "winapi-util 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "wayland-client" -version = "0.21.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "downcast-rs 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", - "nix 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-commons 0.21.13 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-scanner 0.21.13 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-sys 0.21.13 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "wayland-client" version = "0.23.6" @@ -1510,15 +1425,6 @@ dependencies = [ "wayland-sys 0.23.6 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "wayland-commons" -version = "0.21.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "nix 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-sys 0.21.13 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "wayland-commons" version = "0.23.6" @@ -1528,18 +1434,6 @@ dependencies = [ "wayland-sys 0.23.6 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "wayland-protocols" -version = "0.21.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-client 0.21.13 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-commons 0.21.13 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-scanner 0.21.13 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-sys 0.21.13 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "wayland-protocols" version = "0.23.6" @@ -1551,16 +1445,6 @@ dependencies = [ "wayland-scanner 0.23.6 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "wayland-scanner" -version = "0.21.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", - "xml-rs 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "wayland-scanner" version = "0.23.6" @@ -1571,15 +1455,6 @@ dependencies = [ "xml-rs 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "wayland-sys" -version = "0.21.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "dlib 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "wayland-sys" version = "0.23.6" @@ -1634,30 +1509,6 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "winit" -version = "0.19.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "android_glue 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "backtrace 0.3.46 (registry+https://github.com/rust-lang/crates.io-index)", - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "cocoa 0.18.5 (registry+https://github.com/rust-lang/crates.io-index)", - "core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", - "core-graphics 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "objc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "raw-window-handle 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "smithay-client-toolkit 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-client 0.21.13 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "x11-dl 2.18.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "winit" version = "0.22.0" @@ -1738,13 +1589,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)" = "95e28fa049fda1c330bcf9d723be7663a899c4679724b34c81e9f5a326aab8cd" "checksum cexpr 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "fce5b5fb86b0c57c20c834c1b412fd09c77c8a59b9473f86272709e78874cd1d" "checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" -"checksum cgl 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "55e7ec0b74fe5897894cbc207092c577e87c52f8a59e8ca8d97ef37551f60a49" "checksum cgl 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0ced0551234e87afee12411d535648dd89d2e7f34c78b753395567aff3d447ff" "checksum cgmath 0.16.1 (registry+https://github.com/rust-lang/crates.io-index)" = "64a4b57c8f4e3a2e9ac07e0f6abc9c24b6fc9e1b54c3478cfb598f3d0023e51c" "checksum clang-sys 0.28.1 (registry+https://github.com/rust-lang/crates.io-index)" = "81de550971c976f176130da4b2978d3b524eaa0fd9ac31f3ceb5ae1231fb4853" "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -"checksum cocoa 0.18.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1706996401131526e36b3b49f0c4d912639ce110996f3ca144d78946727bce54" +"checksum cmake 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "81fb25b677f8bf1eb325017cb6bb8452f87969db0fedb4f757b297bee78a7c62" "checksum cocoa 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f29f7768b2d1be17b96158e3285951d366b40211320fb30826a76cb7a0da6400" "checksum color_quant 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0dbbb57365263e881e805dc77d94697c9118fd94d8da011240555aa7b23445bd" "checksum core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "25b9e03f145fd4f2bf705e07b900cd41fc636598fe5dc452fd0db1441c3f496d" @@ -1774,13 +1624,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum gfx 0.18.2 (registry+https://github.com/rust-lang/crates.io-index)" = "01de46f9508a5c259aef105f0bff760ceddca832ea9c87ce03d1923e22ee155b" "checksum gfx_core 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "75fbddaef2e12b4995900539d7209d947b988a3d87ee8737484d049b526e5441" "checksum gif 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)" = "471d90201b3b223f3451cd4ad53e34295f16a1df17b1edf3736d47761c3981af" +"checksum gl 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a94edab108827d67608095e269cf862e60d920f144a5026d3dbcfd8b877fb404" "checksum gl_generator 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a0ffaf173cf76c73a73e080366bf556b4776ece104b06961766ff11449f38604" "checksum gl_generator 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ca98bbde17256e02d17336a6bdb5a50f7d0ccacee502e191d3e3d0ec2f96f84a" "checksum gl_generator 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a95dfc23a2b4a9a2f5ab41d194f8bfda3cabec42af4e39f08c339eb2a0c124d" -"checksum gleam 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)" = "cae10d7c99d0e77b4766e850a60898a17c1abaf01075531f1066f03dc7dc5fc5" +"checksum glfw 0.37.0 (registry+https://github.com/rust-lang/crates.io-index)" = "36ed2a51f1e1c5722b7a3724fc146cbfe27297584a4fbb2797ce487f62bb0320" +"checksum glfw-sys 3.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0b567b13b593ec58ea912b2658ee6230ffe20a069fa5b771800acc69bb3a157e" "checksum glium 0.27.0 (registry+https://github.com/rust-lang/crates.io-index)" = "030bb23a12fac7e589b002c5e131e89348df88f91b56e3f3dbc4249527eeebf9" "checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" -"checksum glutin 0.21.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5371b35b309dace06be1b81b5f6adb1c9de578b7dbe1e74bf7e4ef762cf6febd" "checksum glutin 0.24.0 (registry+https://github.com/rust-lang/crates.io-index)" = "611023dea5047f3e9047aecb9e361852dcfd0881129daf5d110106ca2b14f3f3" "checksum glutin_egl_sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "772edef3b28b8ad41e4ea202748e65eefe8e5ffd1f4535f1219793dbb20b3d4c" "checksum glutin_emscripten_sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "80de4146df76e8a6c32b03007bc764ff3249dcaeb4f675d68a06caf1bac363f1" @@ -1835,8 +1686,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum ordered-float 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "18869315e81473c951eb56ad5558bbc56978562d3ecfb87abb7a1e944cea4518" "checksum osmesa-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "88cfece6e95d2e717e0872a7f53a8684712ad13822a7979bc760b9c77ec0013b" "checksum parking_lot 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "92e98c49ab0b7ce5b222f2cc9193fc4efe11c6d0bd4f648e374684a6857b1cfc" -"checksum parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252" -"checksum parking_lot_core 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b876b1b9e7ac6e1a74a6da34d25c42e17e8862aa409cbbbdcfc8d86c6f3bc62b" "checksum parking_lot_core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7582838484df45743c8434fbff785e8edf260c28748353d44bc0da32e0ceabf1" "checksum peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" "checksum percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" @@ -1859,7 +1708,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum regex-syntax 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)" = "7fe5bd57d1d7414c6b5ed48563a2c855d995ff777729dcd91c369ec7fea395ae" "checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" "checksum rustc-hash 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" -"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum rusttype 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)" = "310942406a39981bed7e12b09182a221a29e0990f3e7e0c971f131922ed135d5" "checksum rusttype 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "14a911032fb5791ccbeec9f28fdcb9bf0983b81f227bafdfd227c658d0731c8a" "checksum same-file 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" @@ -1870,9 +1718,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum shared_library 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5a9e7e0f2bfae24d8a5b5a66c5b257a83c7412304311512a0c054cd5e619da11" "checksum shlex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" -"checksum smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6" "checksum smallvec 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5c2fb2ec9bcd216a5b0d0ccf31ab17b5ed1d627960edff65bbe95d3ce221cefc" -"checksum smithay-client-toolkit 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2ccb8c57049b2a34d2cc2b203fa785020ba0129d31920ef0d317430adaf748fa" "checksum smithay-client-toolkit 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "421c8dc7acf5cb205b88160f8b4cc2c5cfabe210e43b2f80f009f4c1ef910f1d" "checksum stb_truetype 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f77b6b07e862c66a9f3e62a07588fee67cd90a9135a2b942409f195507b4fb51" "checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" @@ -1889,15 +1735,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum walkdir 2.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d" -"checksum wayland-client 0.21.13 (registry+https://github.com/rust-lang/crates.io-index)" = "49963e5f9eeaf637bfcd1b9f0701c99fd5cd05225eb51035550d4272806f2713" "checksum wayland-client 0.23.6 (registry+https://github.com/rust-lang/crates.io-index)" = "af1080ebe0efabcf12aef2132152f616038f2d7dcbbccf7b2d8c5270fe14bcda" -"checksum wayland-commons 0.21.13 (registry+https://github.com/rust-lang/crates.io-index)" = "40c08896768b667e1df195d88a62a53a2d1351a1ed96188be79c196b35bb32ec" "checksum wayland-commons 0.23.6 (registry+https://github.com/rust-lang/crates.io-index)" = "bb66b0d1a27c39bbce712b6372131c6e25149f03ffb0cd017cf8f7de8d66dbdb" -"checksum wayland-protocols 0.21.13 (registry+https://github.com/rust-lang/crates.io-index)" = "4afde2ea2a428eee6d7d2c8584fdbe8b82eee8b6c353e129a434cd6e07f42145" "checksum wayland-protocols 0.23.6 (registry+https://github.com/rust-lang/crates.io-index)" = "6cc286643656742777d55dc8e70d144fa4699e426ca8e9d4ef454f4bf15ffcf9" -"checksum wayland-scanner 0.21.13 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3828c568714507315ee425a9529edc4a4aa9901409e373e9e0027e7622b79e" "checksum wayland-scanner 0.23.6 (registry+https://github.com/rust-lang/crates.io-index)" = "93b02247366f395b9258054f964fe293ddd019c3237afba9be2ccbe9e1651c3d" -"checksum wayland-sys 0.21.13 (registry+https://github.com/rust-lang/crates.io-index)" = "520ab0fd578017a0ee2206623ba9ef4afe5e8f23ca7b42f6acfba2f4e66b1628" "checksum wayland-sys 0.23.6 (registry+https://github.com/rust-lang/crates.io-index)" = "d94e89a86e6d6d7c7c9b19ebf48a03afaac4af6bc22ae570e9a24124b75358f4" "checksum which 3.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d011071ae14a2f6671d0b74080ae0cd8ebf3a6f8c9589a2cd45f23126fe29724" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" @@ -1906,7 +1747,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-util 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "fa515c5163a99cc82bab70fd3bfdd36d827be85de63737b40fcef2ce084a436e" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -"checksum winit 0.19.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1e96eb4bb472fa43e718e8fa4aef82f86cd9deac9483a1e1529230babdb394a8" "checksum winit 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e9092b71b48ad6a0d98835a786308d10760cc09369d02e4a166608327f1f26" "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" "checksum x11-dl 2.18.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2bf981e3a5b3301209754218f962052d4d9ee97e478f4d26d4a6eced34c1fef8" diff --git a/Cargo.toml b/Cargo.toml index 5a4da7f348..8a9fe72672 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,8 +12,10 @@ path = "src/main.rs" enum_primitive = "0.1.1" # c wrapper ergonomics genmesh = "0.6.0" # for glium example gfx = "0.18.2" # another high level OpenGL / multi-API abstraction? +gl = "0.14.0" # this looks like bare bones OpenGL +glfw = "0.37.0" # GL framework - windows, contexts, devices glium="0.27.0" # high-level OpenGL abstraction (*not* vanilla OpenGL) -glutin = "0.21" # used by glium example code +glutin = "0.24.0" # used by glium example code grr = "0.7.0" # purports to be low-level OpenGL image = "0.23.2" k4a-sys = { path = "/home/bt/dev/3rd/k4a-sys" } # k4a-sys = "0.2.0" diff --git a/src/graphics_gl.rs b/src/graphics_gl.rs new file mode 100644 index 0000000000..1c371038b9 --- /dev/null +++ b/src/graphics_gl.rs @@ -0,0 +1,354 @@ +use std::ffi::CString; +use std::mem; +use std::os::raw::c_void; +use std::path::Path; +use std::ptr; +use std::str; +use std::sync::mpsc::Receiver; + +use gl; +use gl::types::*; +use glfw::{Action, Context, Key}; +use glutin; +use image::{GenericImage, GenericImageView}; +use glutin::event::{Event, WindowEvent}; +use glutin::event_loop::{ControlFlow, EventLoop}; +use glutin::window::WindowBuilder; +use glutin::ContextBuilder; + +//use shader::Shader; + +// Vertex data +static VERTEX_DATA: [GLfloat; 6] = [0.0, 0.5, 0.5, -0.5, -0.5, -0.5]; + +// Shader sources +static VS_SRC: &'static str = " +#version 150 +in vec2 position; +void main() { + gl_Position = vec4(position, 0.0, 1.0); +}"; + +static FS_SRC: &'static str = " +#version 150 +out vec4 out_color; +void main() { + out_color = vec4(1.0, 1.0, 1.0, 1.0); +}"; + +fn compile_shader(src: &str, ty: GLenum) -> GLuint { + let shader; + unsafe { + shader = gl::CreateShader(ty); + // Attempt to compile the shader + let c_str = CString::new(src.as_bytes()).unwrap(); + gl::ShaderSource(shader, 1, &c_str.as_ptr(), ptr::null()); + gl::CompileShader(shader); + + // Get the compile status + let mut status = gl::FALSE as GLint; + gl::GetShaderiv(shader, gl::COMPILE_STATUS, &mut status); + + // Fail on error + if status != (gl::TRUE as GLint) { + let mut len = 0; + gl::GetShaderiv(shader, gl::INFO_LOG_LENGTH, &mut len); + let mut buf = Vec::with_capacity(len as usize); + buf.set_len((len as usize) - 1); // subtract 1 to skip the trailing null character + gl::GetShaderInfoLog( + shader, + len, + ptr::null_mut(), + buf.as_mut_ptr() as *mut GLchar, + ); + panic!( + "{}", + str::from_utf8(&buf) + .ok() + .expect("ShaderInfoLog not valid utf8") + ); + } + } + shader +} + +fn link_program(vs: GLuint, fs: GLuint) -> GLuint { + unsafe { + let program = gl::CreateProgram(); + gl::AttachShader(program, vs); + gl::AttachShader(program, fs); + gl::LinkProgram(program); + // Get the link status + let mut status = gl::FALSE as GLint; + gl::GetProgramiv(program, gl::LINK_STATUS, &mut status); + + // Fail on error + if status != (gl::TRUE as GLint) { + let mut len: GLint = 0; + gl::GetProgramiv(program, gl::INFO_LOG_LENGTH, &mut len); + let mut buf = Vec::with_capacity(len as usize); + buf.set_len((len as usize) - 1); // subtract 1 to skip the trailing null character + gl::GetProgramInfoLog( + program, + len, + ptr::null_mut(), + buf.as_mut_ptr() as *mut GLchar, + ); + panic!( + "{}", + str::from_utf8(&buf) + .ok() + .expect("ProgramInfoLog not valid utf8") + ); + } + program + } +} + + + +pub fn run() { + /*//noinspection RsBorrowChecker + let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap(); + + glfw.window_hint(glfw::WindowHint::ContextVersion(3, 3)); + glfw.window_hint(glfw::WindowHint::OpenGlProfile(glfw::OpenGlProfileHint::Core)); + + let (mut window, events) = glfw + .create_window(800, 600, "Hello this is window", glfw::WindowMode::Windowed) + .expect("Failed to create GLFW window."); + + window.set_key_polling(true); + window.make_current(); + window.set_framebuffer_size_polling(true); + + while !window.should_close() { + glfw.poll_events(); + for (_, event) in glfw::flush_messages(&events) { + handle_window_event(&mut window, event); + } + }*/ + + let event_loop = EventLoop::new(); + let window = WindowBuilder::new(); + let gl_window = ContextBuilder::new() + .build_windowed(window, &event_loop) + .unwrap(); + + // It is essential to make the context current before calling `gl::load_with`. + let gl_window = unsafe { gl_window.make_current() }.unwrap(); + + // Load the OpenGL function pointers + gl::load_with(|symbol| gl_window.get_proc_address(symbol)); + + // Create GLSL shaders + let vs = compile_shader(VS_SRC, gl::VERTEX_SHADER); + let fs = compile_shader(FS_SRC, gl::FRAGMENT_SHADER); + let program = link_program(vs, fs); + + let mut vao = 0; + let mut vbo = 0; + + unsafe { + // Create Vertex Array Object + gl::GenVertexArrays(1, &mut vao); + gl::BindVertexArray(vao); + + // Create a Vertex Buffer Object and copy the vertex data to it + gl::GenBuffers(1, &mut vbo); + gl::BindBuffer(gl::ARRAY_BUFFER, vbo); + gl::BufferData( + gl::ARRAY_BUFFER, + (VERTEX_DATA.len() * mem::size_of::()) as GLsizeiptr, + mem::transmute(&VERTEX_DATA[0]), + gl::STATIC_DRAW, + ); + + // Use shader program + gl::UseProgram(program); + gl::BindFragDataLocation(program, 0, CString::new("out_color").unwrap().as_ptr()); + + // Specify the layout of the vertex data + let pos_attr = gl::GetAttribLocation(program, CString::new("position").unwrap().as_ptr()); + gl::EnableVertexAttribArray(pos_attr as GLuint); + gl::VertexAttribPointer( + pos_attr as GLuint, + 2, + gl::FLOAT, + gl::FALSE as GLboolean, + 0, + ptr::null(), + ); + } + + event_loop.run(move |event, _, control_flow| { + *control_flow = ControlFlow::Wait; + match event { + Event::LoopDestroyed => return, + Event::WindowEvent { event, .. } => match event { + WindowEvent::CloseRequested => { + // Cleanup + unsafe { + gl::DeleteProgram(program); + gl::DeleteShader(fs); + gl::DeleteShader(vs); + gl::DeleteBuffers(1, &vbo); + gl::DeleteVertexArrays(1, &vao); + } + *control_flow = ControlFlow::Exit + }, + _ => (), + }, + Event::RedrawRequested(_) => { + unsafe { + // Clear the screen to black + gl::ClearColor(0.3, 0.3, 0.3, 1.0); + gl::Clear(gl::COLOR_BUFFER_BIT); + // Draw a triangle from the 3 vertices + gl::DrawArrays(gl::TRIANGLES, 0, 3); + } + gl_window.swap_buffers().unwrap(); + }, + _ => (), + } + }); + + /*gl::load_with(|symbol| window.get_proc_address(symbol) as *const _); + + let (ourShader, VBO, VAO, EBO, texture) = unsafe { + // build and compile our shader program + // ------------------------------------ + let ourShader = Shader::new( + "src/_1_getting_started/shaders/4.1.texture.vs", + "src/_1_getting_started/shaders/4.1.texture.fs"); + + // set up vertex data (and buffer(s)) and configure vertex attributes + // ------------------------------------------------------------------ + // HINT: type annotation is crucial since default for float literals is f64 + let vertices: [f32; 32] = [ + // positions // colors // texture coords + 0.5, 0.5, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, // top right + 0.5, -0.5, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, // bottom right + -0.5, -0.5, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, // bottom left + -0.5, 0.5, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0 // top left + ]; + let indices = [ + 0, 1, 3, // first Triangle + 1, 2, 3 // second Triangle + ]; + let (mut VBO, mut VAO, mut EBO) = (0, 0, 0); + gl::GenVertexArrays(1, &mut VAO); + gl::GenBuffers(1, &mut VBO); + gl::GenBuffers(1, &mut EBO); + + gl::BindVertexArray(VAO); + + gl::BindBuffer(gl::ARRAY_BUFFER, VBO); + gl::BufferData(gl::ARRAY_BUFFER, + (vertices.len() * mem::size_of::()) as GLsizeiptr, + &vertices[0] as *const f32 as *const c_void, + gl::STATIC_DRAW); + + gl::BindBuffer(gl::ELEMENT_ARRAY_BUFFER, EBO); + gl::BufferData(gl::ELEMENT_ARRAY_BUFFER, + (indices.len() * mem::size_of::()) as GLsizeiptr, + &indices[0] as *const i32 as *const c_void, + gl::STATIC_DRAW); + + let stride = 8 * mem::size_of::() as GLsizei; + // position attribute + gl::VertexAttribPointer(0, 3, gl::FLOAT, gl::FALSE, stride, ptr::null()); + gl::EnableVertexAttribArray(0); + // color attribute + gl::VertexAttribPointer(1, 3, gl::FLOAT, gl::FALSE, stride, (3 * mem::size_of::()) as *const c_void); + gl::EnableVertexAttribArray(1); + // texture coord attribute + gl::VertexAttribPointer(2, 2, gl::FLOAT, gl::FALSE, stride, (6 * mem::size_of::()) as *const c_void); + gl::EnableVertexAttribArray(2); + + // load and create a texture + // ------------------------- + let mut texture = 0; + gl::GenTextures(1, &mut texture); + gl::BindTexture(gl::TEXTURE_2D, texture); // all upcoming GL_TEXTURE_2D operations now have effect on this texture object + // set the texture wrapping parameters + gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_WRAP_S, gl::REPEAT as i32); // set texture wrapping to gl::REPEAT (default wrapping method) + gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_WRAP_T, gl::REPEAT as i32); + // set texture filtering parameters + gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::LINEAR as i32); + gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::LINEAR as i32); + // load image, create texture and generate mipmaps + let img = image::open(&Path::new("resources/textures/container.jpg")).expect("Failed to load texture"); + let data = img.raw_pixels(); + gl::TexImage2D(gl::TEXTURE_2D, + 0, + gl::RGB as i32, + img.width as i32, + img.height as i32, + 0, + gl::RGB, + gl::UNSIGNED_BYTE, + &data[0] as *const u8 as *const c_void); + gl::GenerateMipmap(gl::TEXTURE_2D); + + (ourShader, VBO, VAO, EBO, texture) + }; + + // render loop + // ----------- + while !window.should_close() { + // events + // ----- + process_events(&mut window, &events); + + // render + // ------ + unsafe { + gl::ClearColor(0.2, 0.3, 0.3, 1.0); + gl::Clear(gl::COLOR_BUFFER_BIT); + + // bind Texture + gl::BindTexture(gl::TEXTURE_2D, texture); + + // render container + ourShader.useProgram(); + gl::BindVertexArray(VAO); + gl::DrawElements(gl::TRIANGLES, 6, gl::UNSIGNED_INT, ptr::null()); + } + + // glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.) + // ------------------------------------------------------------------------------- + window.swap_buffers(); + glfw.poll_events(); + } + + // optional: de-allocate all resources once they've outlived their purpose: + // ------------------------------------------------------------------------ + unsafe { + gl::DeleteVertexArrays(1, &VAO); + gl::DeleteBuffers(1, &VBO); + gl::DeleteBuffers(1, &EBO); + }*/ +} + +// NOTE: not the same version as in common.rs! +fn process_events(window: &mut glfw::Window, events: &Receiver<(f64, glfw::WindowEvent)>) { + for (_, event) in glfw::flush_messages(events) { + match event { + glfw::WindowEvent::FramebufferSize(width, height) => { + // make sure the viewport matches the new window dimensions; note that width and + // height will be significantly larger than specified on retina displays. + unsafe { gl::Viewport(0, 0, width, height) } + } + glfw::WindowEvent::Key(Key::Escape, _, Action::Press, _) => window.set_should_close(true), + _ => {} + } + } +} + +fn handle_window_event(window: &mut glfw::Window, event: glfw::WindowEvent) { + match event { + glfw::WindowEvent::Key(Key::Escape, _, Action::Press, _) => window.set_should_close(true), + _ => {} + } +} \ No newline at end of file diff --git a/src/graphics_grr.rs b/src/graphics_grr.rs index 936362c302..41488da910 100644 --- a/src/graphics_grr.rs +++ b/src/graphics_grr.rs @@ -1,4 +1,5 @@ use glutin::dpi::LogicalSize; +use glutin::dpi::PhysicalSize; use grr; use std::path::Path; @@ -37,10 +38,10 @@ const INDICES: [u16; 6] = [0, 1, 2, 2, 3, 0]; pub fn run(capture_provider: Arc) -> grr::Result<()> { unsafe { - let mut events_loop = glutin::EventsLoop::new(); - let wb = glutin::WindowBuilder::new() + let mut events_loop = glutin::event_loop::EventLoop::new(); + let wb = glutin::window::WindowBuilder::new() .with_title("grr - Texture") - .with_dimensions(LogicalSize { + .with_inner_size(LogicalSize { width: 1024.0, height: 768.0, }); @@ -53,10 +54,10 @@ pub fn run(capture_provider: Arc) -> grr::Result<()> { .make_current() .unwrap(); - let LogicalSize { + let PhysicalSize { width: mut w, height: mut h, - } = window.window().get_inner_size().unwrap(); + } = window.window().inner_size(); //window().get_inner_size().unwrap(); let grr = grr::Device::new( |symbol| window.get_proc_address(symbol) as *const _, @@ -185,14 +186,14 @@ pub fn run(capture_provider: Arc) -> grr::Result<()> { let mut running = true; while running { - events_loop.poll_events(|event| match event { - glutin::Event::WindowEvent { event, .. } => match event { - glutin::WindowEvent::CloseRequested => running = false, - glutin::WindowEvent::Resized(size) => { - w = size.width; - h = size.height; - let dpi_factor = window.window().get_hidpi_factor(); - window.resize(size.to_physical(dpi_factor)); + events_loop.run(move |event, _, _| match event { + glutin::event::Event::WindowEvent { event, .. } => match event { + glutin::event::WindowEvent::CloseRequested => running = false, + glutin::event::WindowEvent::Resized(size) => { + //w = size.width; + //h = size.height; + //let dpi_factor = window.window().get_hidpi_factor(); + //window.resize(size.to_physical(dpi_factor)); } _ => (), }, diff --git a/src/main.rs b/src/main.rs index e7d28e737d..f850c2eca1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,10 @@ #![allow(warnings)] #[macro_use] extern crate enum_primitive; -extern crate genmesh; #[macro_use] extern crate glium; +extern crate genmesh; +extern crate gl; +extern crate glfw; extern crate glutin; extern crate grr; extern crate image; @@ -52,10 +54,11 @@ use k4a_sys_wrapper::Image; use sensor_control::{capture_thread_to_texture, grab_single_frame, CaptureProvider, capture_thread}; pub mod conversion; +pub mod graphics_gl; pub mod graphics_glium; pub mod graphics_grr; -pub mod old_k4a_wrapper; pub mod k4a_sys_wrapper; +pub mod old_k4a_wrapper; pub mod sensor_control; pub fn main() { @@ -64,6 +67,7 @@ pub fn main() { thread::spawn(move || capture_thread(capture_provider)); - graphics_grr::run(capture_provider2).unwrap(); + //graphics_grr::run(capture_provider2).unwrap(); //graphics_glium::run_glium(); + graphics_gl::run(); }