Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Very basic yage-gl crate + cleanup #8

Merged
merged 4 commits into from
Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 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,23 +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" }

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 = "../../" }
18 changes: 7 additions & 11 deletions examples/native-glutin/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
mod support;

use glutin::GlContext;

use yage::some_non_wasm_function;
use yage::gltf::load_gltf;
use yage::gl::GL;
use yage::gl::glenum;

// TODO!!: This is just the (slighly adapted) glutin window example and doesn't even use yage
fn main() {

dbg!(some_non_wasm_function());
load_gltf("Box.glb");

let mut events_loop = glutin::EventsLoop::new();
let window = glutin::WindowBuilder::new().with_title("A fantastic window!");
let context = glutin::ContextBuilder::new();
Expand All @@ -20,7 +13,10 @@ fn main() {

println!("Pixel format of the window's GL context: {:?}", gl_window.get_pixel_format());

support::load(&gl_window.context());
gl::load_with(|ptr| gl_window.context().get_proc_address(ptr) as *const _);

let gl = GL::new();
gl.clear_color(0.0, 1.0, 0.0, 1.0);

let mut running = true;
while running {
Expand All @@ -40,7 +36,7 @@ fn main() {
}
});

support::draw_frame([1.0, 0.5, 0.7, 1.0]);
gl.clear(glenum::BufferBit::Color);
let _ = gl_window.swap_buffers();
}
}
96 changes: 0 additions & 96 deletions examples/native-glutin/src/support.rs

This file was deleted.

3 changes: 2 additions & 1 deletion examples/rust-webpack/crate/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[package]
authors = ["The RustWasm Developers"]
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"
name = "rust-webpack"
readme = "./README.md"
repository = "https://github.com/bwasty/yage"
edition = "2018"
version = "0.1.0"

[lib]
Expand Down
28 changes: 27 additions & 1 deletion examples/rust-webpack/crate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +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 @@ -27,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 @@ -42,6 +67,7 @@ pub fn run() -> Result<(), JsValue> {
let body: &web_sys::Node = body.as_ref();
body.append_child(&p)?;

let _ = yage::start();
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
Loading