Skip to content

Commit

Permalink
refactor crates
Browse files Browse the repository at this point in the history
  • Loading branch information
bwasty committed Mar 12, 2019
1 parent 3519902 commit b744cc9
Show file tree
Hide file tree
Showing 19 changed files with 75 additions and 105 deletions.
21 changes: 10 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
50 changes: 9 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
2 changes: 1 addition & 1 deletion examples/native-azul/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
5 changes: 2 additions & 3 deletions examples/native-glutin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 = "../../" }
2 changes: 1 addition & 1 deletion examples/rust-webpack/crate/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
26 changes: 25 additions & 1 deletion examples/rust-webpack/crate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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> {
Expand All @@ -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(())
}
3 changes: 3 additions & 0 deletions examples/wasm-app/README.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
35 changes: 4 additions & 31 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
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;

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.
Expand All @@ -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(())
}
10 changes: 0 additions & 10 deletions yage-app/Cargo.toml

This file was deleted.

3 changes: 0 additions & 3 deletions yage-app/README.md

This file was deleted.

2 changes: 1 addition & 1 deletion yage-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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]
2 changes: 1 addition & 1 deletion yage-gl/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
2 changes: 1 addition & 1 deletion yage-gltf/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
8 changes: 8 additions & 0 deletions yage-glutin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions yage-glutin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This crate should handle window, context, events loop (most of what is now in `examples/native-glutin/main.rs`)
File renamed without changes.
7 changes: 7 additions & 0 deletions yage-web/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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]
1 change: 1 addition & 0 deletions yage-web/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This crate should handle the WebGL context and be the web counterpart of yage-glutin.
Empty file added yage-web/src/lib.rs
Empty file.

0 comments on commit b744cc9

Please sign in to comment.