From b744cc907afba256459dd4546e5e1b8bfae898ef Mon Sep 17 00:00:00 2001
From: Benjamin Wasty <benny.wasty@gmail.com>
Date: Tue, 12 Mar 2019 21:56:35 +0100
Subject: [PATCH] refactor crates

---
 Cargo.toml                             | 21 ++++++-----
 README.md                              | 50 +++++---------------------
 examples/native-azul/Cargo.toml        |  2 +-
 examples/native-glutin/Cargo.toml      |  5 ++-
 examples/rust-webpack/crate/Cargo.toml |  2 +-
 examples/rust-webpack/crate/src/lib.rs | 26 +++++++++++++-
 examples/wasm-app/README.md            |  3 ++
 src/lib.rs                             | 35 +++---------------
 yage-app/Cargo.toml                    | 10 ------
 yage-app/README.md                     |  3 --
 yage-core/Cargo.toml                   |  2 +-
 yage-gl/Cargo.toml                     |  2 +-
 yage-gltf/Cargo.toml                   |  2 +-
 yage-glutin/Cargo.toml                 |  8 +++++
 yage-glutin/README.md                  |  1 +
 {yage-app => yage-glutin}/src/lib.rs   |  0
 yage-web/Cargo.toml                    |  7 ++++
 yage-web/README.md                     |  1 +
 yage-web/src/lib.rs                    |  0
 19 files changed, 75 insertions(+), 105 deletions(-)
 delete mode 100644 yage-app/Cargo.toml
 delete mode 100644 yage-app/README.md
 create mode 100644 yage-glutin/Cargo.toml
 create mode 100644 yage-glutin/README.md
 rename {yage-app => yage-glutin}/src/lib.rs (100%)
 create mode 100644 yage-web/Cargo.toml
 create mode 100644 yage-web/README.md
 create mode 100644 yage-web/src/lib.rs

diff --git a/Cargo.toml b/Cargo.toml
index 7c176d3..084b3f4 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -2,7 +2,7 @@
 name = "yage"
 version = "0.0.1"
 description = "Yet another graphics engine"
-authors = ["Benjamin Wasty <benny.wasty@gmail.com>"]
+authors = ["Benjamin Wasty <benjamin.wasty@cginternals.com>", "Stefan Buschmann <stefan.buschmann@cginternals.com>"]
 repository = "https://github.com/bwasty/yage"
 readme = "README.md"
 license = "MIT/Apache-2.0"
@@ -18,26 +18,25 @@ maintenance = { status = "experimental" }
 crate-type = ["cdylib", "rlib"]
 
 [features]
-wasm = ["web-sys", "js-sys", "console_error_panic_hook"]
-native = [] 
 gltf = ["yage-gltf"]
-# NOTE: to disable the default wasm feature, use `default-features = false`
-default = ["wasm", "gltf"]
+# NOTE: to disable the default gltf feature, use `default-features = false`
+default = ["gltf"]
 
 [workspace]
-members = ["yage-core", "yage-gl", "yage-app", "yage-gltf"]
+members = ["yage-core", "yage-gl", "yage-glutin", "yage-web", "yage-gltf"]
 exclude = ["examples/native-glutin", "examples/rust-webpack", "examples/native-azul"]
 
 [dependencies]
+cfg-if = "0.1.6"
+
 yage-core = { path = "yage-core", version = "0.0.1" }
 yage-gl = { path = "yage-gl", version = "0.0.1" }
-yage-app = { path = "yage-app", version = "0.0.1" }
 yage-gltf = { path = "yage-gltf", version = "0.0.1", optional = true }
+[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
+yage-glutin = { path = "yage-glutin", version = "0.0.1" }
+[target.'cfg(target_arch = "wasm32")'.dependencies]
+yage-web = { path = "yage-web", version = "0.0.1" }
 
-# TODO!!: TMP
-glenum = "0.1.1"
-
-cfg-if = "0.1.6"
 wasm-bindgen = "0.2.37"
 
 # The `console_error_panic_hook` crate provides better debugging of panics by
diff --git a/README.md b/README.md
index c69ed68..aa4e4fa 100644
--- a/README.md
+++ b/README.md
@@ -17,52 +17,20 @@ Very, very early. Currently it's mostly [wasm-pack-template](https://github.com/
 - [npm](https://www.npmjs.com/get-npm)
 
 ### Building
-- `wasm-pack build`
-
----
-
-_GENERATED PART OF README_
-
----
-
-# πŸ¦€πŸ•ΈοΈ `wasm-pack-template`
-
-A template for kick starting a Rust and WebAssembly project using
-[`wasm-pack`](https://github.com/rustwasm/wasm-pack).
-
-This template is designed for compiling Rust libraries into WebAssembly and
-publishing the resulting package to NPM.
-
-* Want to use the published NPM package in a Website? [Check out
-  `create-wasm-app`.](https://github.com/rustwasm/create-wasm-app)
-* Want to make a monorepo-style Website without publishing to NPM? Check out
-  [`rust-webpack-template`](https://github.com/rustwasm/rust-webpack-template)
-  and/or
-  [`rust-parcel-template`](https://github.com/rustwasm/rust-parcel-template).
-
-## πŸ”‹ Batteries Included
-
-* [`wasm-bindgen`](https://github.com/rustwasm/wasm-bindgen) for communicating
-  between WebAssembly and JavaScript.
-* [`console_error_panic_hook`](https://github.com/rustwasm/console_error_panic_hook)
-  for logging panic messages to the developer console.
-* [`wee_alloc`](https://github.com/rustwasm/wee_alloc), an allocator optimized
-  for small code size.
-
-### πŸ› οΈ Build with `wasm-pack build`
-
 ```
 wasm-pack build
 ```
 
-### πŸ”¬ Test in Headless Browsers with `wasm-pack test`
+### Examples
+* Native
+  - `cd examples/native-glutin`
+  - `cargo run`
+* Web
+  - `cd examples/rust-webpack`
+  - `npm install`
+  - `npm start`
 
+### Testing
 ```
 wasm-pack test --headless --firefox
 ```
-
-### 🎁 Publish to NPM with `wasm-pack publish`
-
-```
-wasm-pack publish
-```
diff --git a/examples/native-azul/Cargo.toml b/examples/native-azul/Cargo.toml
index cc0c24c..40c66dd 100644
--- a/examples/native-azul/Cargo.toml
+++ b/examples/native-azul/Cargo.toml
@@ -1,7 +1,7 @@
 [package]
 name = "native-azul"
 version = "0.0.1"
-authors = ["Benjamin Wasty <benny.wasty@gmail.com>"]
+authors = ["Benjamin Wasty <benjamin.wasty@cginternals.com>", "Stefan Buschmann <stefan.buschmann@cginternals.com>"]
 edition = "2018"
 
 [dependencies]
diff --git a/examples/native-glutin/Cargo.toml b/examples/native-glutin/Cargo.toml
index 3a84299..03ded84 100644
--- a/examples/native-glutin/Cargo.toml
+++ b/examples/native-glutin/Cargo.toml
@@ -1,11 +1,10 @@
 [package]
 name = "native-glutin"
 version = "0.0.1"
-authors = ["Benjamin Wasty <benny.wasty@gmail.com>"]
+authors = ["Benjamin Wasty <benjamin.wasty@cginternals.com>", "Stefan Buschmann <stefan.buschmann@cginternals.com>"]
 edition = "2018"
 
 [dependencies]
 glutin = "0.19.0"
 gl = "0.11.0"
-# wasm feature is default - exclude them for quicker compile
-yage = { path = "../../", features = ["native", "gltf"], default-features = false }
+yage = { path = "../../" }
diff --git a/examples/rust-webpack/crate/Cargo.toml b/examples/rust-webpack/crate/Cargo.toml
index c89118b..749ba1c 100644
--- a/examples/rust-webpack/crate/Cargo.toml
+++ b/examples/rust-webpack/crate/Cargo.toml
@@ -1,5 +1,5 @@
 [package]
-authors = []
+authors = ["Benjamin Wasty <benjamin.wasty@cginternals.com>", "Stefan Buschmann <stefan.buschmann@cginternals.com>"]
 categories = ["wasm"]
 description = "My super awesome Rust, WebAssembly, and Webpack project!"
 license = "Apache-2.0/MIT"
diff --git a/examples/rust-webpack/crate/src/lib.rs b/examples/rust-webpack/crate/src/lib.rs
index 1d41507..5c487ac 100644
--- a/examples/rust-webpack/crate/src/lib.rs
+++ b/examples/rust-webpack/crate/src/lib.rs
@@ -4,8 +4,12 @@ extern crate web_sys;
 extern crate wasm_bindgen;
 
 use wasm_bindgen::prelude::*;
+use wasm_bindgen::JsCast;
+
+use web_sys::WebGlRenderingContext;
 
 use yage::gl::GL;
+use yage::gl::glenum;
 
 cfg_if! {
     // When the `console_error_panic_hook` feature is enabled, we can call the
@@ -29,6 +33,25 @@ cfg_if! {
     }
 }
 
+fn setup_canvas() -> Result<(), JsValue> {
+    // TODO!!: most of this setup should go into yage-web
+    let document = web_sys::window().unwrap().document().unwrap();
+    let canvas = document.get_element_by_id("canvas").unwrap();
+    let canvas: web_sys::HtmlCanvasElement = canvas.dyn_into::<web_sys::HtmlCanvasElement>()?;
+
+    // TODO!: make it WebGL2
+    let context: WebGlRenderingContext = canvas
+        .get_context("webgl")?
+        .unwrap()
+        .dyn_into()?;
+
+    let gl = GL::from_webgl_context(context);
+    gl.clear_color(0.0, 1.0, 0.0, 1.0);
+    gl.clear(glenum::BufferBit::Color);
+
+    Ok(())
+}
+
 // Called by our JS entry point to run the example.
 #[wasm_bindgen]
 pub fn run() -> Result<(), JsValue> {
@@ -44,6 +67,7 @@ pub fn run() -> Result<(), JsValue> {
     let body: &web_sys::Node = body.as_ref();
     body.append_child(&p)?;
 
-    let _ = yage::start_new();
+    setup_canvas();
+
     Ok(())
 }
diff --git a/examples/wasm-app/README.md b/examples/wasm-app/README.md
index 42f4365..6c57538 100644
--- a/examples/wasm-app/README.md
+++ b/examples/wasm-app/README.md
@@ -1,3 +1,6 @@
+# THIS EXAMPLE DOES NOT WORK AT THE MOMENT
+Will be unmaintained until more of yage works/is implemented cleanly.
+
 # `wasm-app`
 
 Minimal example bootstrapped with [create-wasm-app](https://github.com/rustwasm/create-wasm-app).
diff --git a/src/lib.rs b/src/lib.rs
index 9c5c0e2..c829ff9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,6 +1,9 @@
 pub extern crate yage_core as core;
 pub extern crate yage_gl as gl;
-pub extern crate yage_app as app;
+#[cfg(not(target_arch = "wasm32"))]
+pub extern crate yage_glutin;
+#[cfg(target_arch = "wasm32")]
+pub extern crate yage_web as web;
 #[cfg(feature = "gltf")]
 pub extern crate yage_gltf as gltf;
 
@@ -8,16 +11,6 @@ mod utils;
 
 use cfg_if::cfg_if;
 
-#[cfg(feature = "wasm")]
-use wasm_bindgen::prelude::*;
-#[cfg(feature = "wasm")]
-use wasm_bindgen::JsCast;
-
-#[cfg(feature = "wasm")]
-use js_sys::WebAssembly;
-#[cfg(feature = "wasm")]
-use web_sys::{WebGlProgram, WebGlRenderingContext, WebGlShader};
-
 cfg_if! {
     // When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
     // allocator.
@@ -27,23 +20,3 @@ cfg_if! {
         static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
     }
 }
-
-#[cfg(feature = "wasm")]
-#[wasm_bindgen]
-pub fn start_new() -> Result<(), JsValue> {
-    let document = web_sys::window().unwrap().document().unwrap();
-    let canvas = document.get_element_by_id("canvas").unwrap();
-    let canvas: web_sys::HtmlCanvasElement = canvas.dyn_into::<web_sys::HtmlCanvasElement>()?;
-
-    // TODO!: make it WebGL2
-    let context: WebGlRenderingContext = canvas
-        .get_context("webgl")?
-        .unwrap()
-        .dyn_into()?;
-
-    let gl = gl::GL::from_webgl_context(context);
-    gl.clear_color(0.0, 1.0, 0.0, 1.0);
-    gl.clear(glenum::BufferBit::Color);
-
-    Ok(())
-}
diff --git a/yage-app/Cargo.toml b/yage-app/Cargo.toml
deleted file mode 100644
index badf931..0000000
--- a/yage-app/Cargo.toml
+++ /dev/null
@@ -1,10 +0,0 @@
-[package]
-name = "yage-app"
-version = "0.0.1"
-authors = ["Benjamin Wasty <benny.wasty@gmail.com>"]
-edition = "2018"
-
-[dependencies]
-
-[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
-glutin = "0.19.0"
diff --git a/yage-app/README.md b/yage-app/README.md
deleted file mode 100644
index 80de75c..0000000
--- a/yage-app/README.md
+++ /dev/null
@@ -1,3 +0,0 @@
-This crate should abstract over native window and event handling (glutin) and WebGL canvases in the browser. Potential inspiration: https://github.com/unrust/uni-app
-
-TODO: better name?
diff --git a/yage-core/Cargo.toml b/yage-core/Cargo.toml
index d1868b1..6132066 100644
--- a/yage-core/Cargo.toml
+++ b/yage-core/Cargo.toml
@@ -1,7 +1,7 @@
 [package]
 name = "yage-core"
 version = "0.0.1"
-authors = ["Benjamin Wasty <benny.wasty@gmail.com>"]
+authors = ["Benjamin Wasty <benjamin.wasty@cginternals.com>", "Stefan Buschmann <stefan.buschmann@cginternals.com>"]
 edition = "2018"
 
 [dependencies]
diff --git a/yage-gl/Cargo.toml b/yage-gl/Cargo.toml
index 03ade1d..b973795 100644
--- a/yage-gl/Cargo.toml
+++ b/yage-gl/Cargo.toml
@@ -1,7 +1,7 @@
 [package]
 name = "yage-gl"
 version = "0.0.1"
-authors = ["Benjamin Wasty <benny.wasty@gmail.com>"]
+authors = ["Benjamin Wasty <benjamin.wasty@cginternals.com>", "Stefan Buschmann <stefan.buschmann@cginternals.com>"]
 edition = "2018"
 
 [dependencies]
diff --git a/yage-gltf/Cargo.toml b/yage-gltf/Cargo.toml
index 8a4e21a..5beed24 100644
--- a/yage-gltf/Cargo.toml
+++ b/yage-gltf/Cargo.toml
@@ -1,7 +1,7 @@
 [package]
 name = "yage-gltf"
 version = "0.0.1"
-authors = ["Benjamin Wasty <benny.wasty@gmail.com>"]
+authors = ["Benjamin Wasty <benjamin.wasty@cginternals.com>", "Stefan Buschmann <stefan.buschmann@cginternals.com>"]
 edition = "2018"
 
 [dependencies]
diff --git a/yage-glutin/Cargo.toml b/yage-glutin/Cargo.toml
new file mode 100644
index 0000000..9c5add4
--- /dev/null
+++ b/yage-glutin/Cargo.toml
@@ -0,0 +1,8 @@
+[package]
+name = "yage-glutin"
+version = "0.0.1"
+authors = ["Benjamin Wasty <benjamin.wasty@cginternals.com>", "Stefan Buschmann <stefan.buschmann@cginternals.com>"]
+edition = "2018"
+
+[dependencies]
+glutin = "0.19.0"
diff --git a/yage-glutin/README.md b/yage-glutin/README.md
new file mode 100644
index 0000000..90c8ccc
--- /dev/null
+++ b/yage-glutin/README.md
@@ -0,0 +1 @@
+This crate should handle window, context, events loop (most of what is now in `examples/native-glutin/main.rs`)
diff --git a/yage-app/src/lib.rs b/yage-glutin/src/lib.rs
similarity index 100%
rename from yage-app/src/lib.rs
rename to yage-glutin/src/lib.rs
diff --git a/yage-web/Cargo.toml b/yage-web/Cargo.toml
new file mode 100644
index 0000000..92255de
--- /dev/null
+++ b/yage-web/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "yage-web"
+version = "0.0.1"
+authors = ["Benjamin Wasty <benjamin.wasty@cginternals.com>", "Stefan Buschmann <stefan.buschmann@cginternals.com>"]
+edition = "2018"
+
+[dependencies]
diff --git a/yage-web/README.md b/yage-web/README.md
new file mode 100644
index 0000000..e1fd4ff
--- /dev/null
+++ b/yage-web/README.md
@@ -0,0 +1 @@
+This crate should handle the WebGL context and be the web counterpart of yage-glutin.
diff --git a/yage-web/src/lib.rs b/yage-web/src/lib.rs
new file mode 100644
index 0000000..e69de29