Skip to content
Open
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
12 changes: 6 additions & 6 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ jobs:
run: sudo apt update && sudo apt install libudev-dev
- name: Clippy
run: cargo clippy -- -D warnings
- name: Featureless clipppy
run: cargo clippy --no-default-features -- -D warnings
- name: Clippy with std
run: cargo clippy --features std -- -D warnings

web-check:
runs-on: macOS-latest
Expand All @@ -62,7 +62,7 @@ jobs:
rust-version: ${{ matrix.rust }}
targets: wasm32-unknown-unknown
- uses: actions/checkout@master
- name: Check stdweb
run: cargo install cargo-web && cargo web check --features stdweb
- name: Clippy
run: cargo check --target wasm32-unknown-unknown --features web-sys
- name: Check web
run: cargo check --target wasm32-unknown-unknown
- name: Check web std
run: cargo check --target wasm32-unknown-unknown --features std
12 changes: 8 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ repository = "https://github.com/ryanisaacg/golem"
readme = "README.md"

[features]
stdweb = ["glow/stdweb"]
web-sys = ["glow/web-sys"]
std = []

[dependencies]
bytemuck = "1"
glow = { version = "0.4.0", default-features = false }
log = "0.4"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
glow = { version = "0.6.0", default-features = false }

[target.'cfg(target_arch = "wasm32")'.dependencies]
glow = { version = "0.6.0", default-features = false, features = ["web-sys"] }
web-sys = { version = "0.3", features = ["WebGlRenderingContext"] }

[dev-dependencies]
blinds = { version = "0.1.0", default-features = false, features = ["gl"] }
blinds = { version = "0.2.0", default-features = false }
nalgebra-glm = "0.7.0"
22 changes: 11 additions & 11 deletions examples/3d_scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ use golem::{
};
use nalgebra_glm as glm;

async fn app(
window: Window,
ctx: golem::glow::Context,
mut events: EventStream,
) -> Result<(), GolemError> {
let ctx = &Context::from_glow(ctx)?;
async fn app(window: Window, mut events: EventStream) -> Result<(), GolemError> {
// On desktop and web, we have to load the context slightly differently
#[cfg(not(target_arch = "wasm32"))]
let ctx = Context::from_loader_function(|addr| window.get_proc_address(addr))?;
#[cfg(target_arch = "wasm32")]
let ctx = Context::from_webgl_context(window.webgl_context())?;

// A cube
#[rustfmt::skip]
Expand All @@ -39,7 +39,7 @@ async fn app(
];

let mut shader = ShaderProgram::new(
ctx,
&ctx,
ShaderDescription {
vertex_input: &[Attribute::new("vert_position", AttributeType::Vector(D3))],
fragment_input: &[],
Expand All @@ -58,8 +58,8 @@ async fn app(
},
)?;

let mut vb = VertexBuffer::new(ctx)?;
let mut eb = ElementBuffer::new(ctx)?;
let mut vb = VertexBuffer::new(&ctx)?;
let mut eb = ElementBuffer::new(&ctx)?;
vb.set_data(&vertices);
eb.set_data(&indices);
ctx.clear();
Expand Down Expand Up @@ -152,7 +152,7 @@ async fn app(
}

fn main() {
run_gl(Settings::default(), |window, gfx, events| async move {
app(window, gfx, events).await.unwrap()
run(Settings::default(), |window, events| async move {
app(window, events).await.unwrap()
});
}
22 changes: 11 additions & 11 deletions examples/blend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use golem::{
UniformType, UniformValue, VertexBuffer,
};

async fn app(
window: Window,
ctx: golem::glow::Context,
mut events: EventStream,
) -> Result<(), GolemError> {
let ctx = &Context::from_glow(ctx)?;
async fn app(window: Window, mut events: EventStream) -> Result<(), GolemError> {
// On desktop and web, we have to load the context slightly differently
#[cfg(not(target_arch = "wasm32"))]
let ctx = Context::from_loader_function(|addr| window.get_proc_address(addr))?;
#[cfg(target_arch = "wasm32")]
let ctx = Context::from_webgl_context(window.webgl_context())?;

#[rustfmt::skip]
let vertices = [
Expand All @@ -25,7 +25,7 @@ async fn app(
let indices = [0, 1, 2, 2, 3, 0];

let mut shader = ShaderProgram::new(
ctx,
&ctx,
ShaderDescription {
vertex_input: &[Attribute::new("vert_position", AttributeType::Vector(D2))],
fragment_input: &[],
Expand All @@ -42,8 +42,8 @@ async fn app(
},
)?;

let mut vb = VertexBuffer::new(ctx)?;
let mut eb = ElementBuffer::new(ctx)?;
let mut vb = VertexBuffer::new(&ctx)?;
let mut eb = ElementBuffer::new(&ctx)?;
vb.set_data(&vertices);
eb.set_data(&indices);
ctx.clear();
Expand Down Expand Up @@ -71,7 +71,7 @@ async fn app(
}

fn main() {
run_gl(Settings::default(), |window, gfx, events| async move {
app(window, gfx, events).await.unwrap()
run(Settings::default(), |window, events| async move {
app(window, events).await.unwrap()
});
}
22 changes: 11 additions & 11 deletions examples/depth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use golem::{
UniformType, UniformValue, VertexBuffer,
};

async fn app(
window: Window,
ctx: golem::glow::Context,
mut events: EventStream,
) -> Result<(), GolemError> {
let ctx = &Context::from_glow(ctx)?;
async fn app(window: Window, mut events: EventStream) -> Result<(), GolemError> {
// On desktop and web, we have to load the context slightly differently
#[cfg(not(target_arch = "wasm32"))]
let ctx = Context::from_loader_function(|addr| window.get_proc_address(addr))?;
#[cfg(target_arch = "wasm32")]
let ctx = Context::from_webgl_context(window.webgl_context())?;

#[rustfmt::skip]
let triangle_1 = [
Expand All @@ -29,7 +29,7 @@ async fn app(
let indices = [0, 1, 2];

let mut shader = ShaderProgram::new(
ctx,
&ctx,
ShaderDescription {
vertex_input: &[Attribute::new("vert_position", AttributeType::Vector(D3))],
fragment_input: &[],
Expand All @@ -46,8 +46,8 @@ async fn app(
},
)?;

let mut vb = VertexBuffer::new(ctx)?;
let mut eb = ElementBuffer::new(ctx)?;
let mut vb = VertexBuffer::new(&ctx)?;
let mut eb = ElementBuffer::new(&ctx)?;
eb.set_data(&indices);
ctx.clear();
ctx.set_depth_test_mode(Some(DepthTestMode {
Expand Down Expand Up @@ -78,7 +78,7 @@ async fn app(
}

fn main() {
run_gl(Settings::default(), |window, gfx, events| async move {
app(window, gfx, events).await.unwrap()
run(Settings::default(), |window, events| async move {
app(window, events).await.unwrap()
});
}
22 changes: 11 additions & 11 deletions examples/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use golem::{
ElementBuffer, GeometryMode, GolemError, ShaderDescription, ShaderProgram, VertexBuffer,
};

async fn app(
window: Window,
ctx: golem::glow::Context,
mut events: EventStream,
) -> Result<(), GolemError> {
let ctx = &Context::from_glow(ctx)?;
async fn app(window: Window, mut events: EventStream) -> Result<(), GolemError> {
// On desktop and web, we have to load the context slightly differently
#[cfg(not(target_arch = "wasm32"))]
let ctx = Context::from_loader_function(|addr| window.get_proc_address(addr))?;
#[cfg(target_arch = "wasm32")]
let ctx = Context::from_webgl_context(window.webgl_context())?;

#[rustfmt::skip]
let vertices = [
Expand All @@ -23,7 +23,7 @@ async fn app(
let indices = [0, 1, 1, 2, 2, 3, 3, 0];

let mut shader = ShaderProgram::new(
ctx,
&ctx,
ShaderDescription {
vertex_input: &[
Attribute::new("vert_position", AttributeType::Vector(D2)),
Expand All @@ -41,8 +41,8 @@ async fn app(
},
)?;

let mut vb = VertexBuffer::new(ctx)?;
let mut eb = ElementBuffer::new(ctx)?;
let mut vb = VertexBuffer::new(&ctx)?;
let mut eb = ElementBuffer::new(&ctx)?;
vb.set_data(&vertices);
eb.set_data(&indices);
shader.bind();
Expand All @@ -59,7 +59,7 @@ async fn app(
}

fn main() {
run_gl(Settings::default(), |window, gfx, events| async move {
app(window, gfx, events).await.unwrap()
run(Settings::default(), |window, events| async move {
app(window, events).await.unwrap()
});
}
23 changes: 11 additions & 12 deletions examples/hello-triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ use golem::{
};

// The application loop, powered by the blinds crate
async fn app(
window: Window,
ctx: golem::glow::Context,
mut events: EventStream,
) -> Result<(), GolemError> {
// Create a context from 'glow', GL On Whatever
let ctx = &Context::from_glow(ctx)?;
async fn app(window: Window, mut events: EventStream) -> Result<(), GolemError> {
// On desktop and web, we have to load the context slightly differently
#[cfg(not(target_arch = "wasm32"))]
let ctx = Context::from_loader_function(|addr| window.get_proc_address(addr))?;
#[cfg(target_arch = "wasm32")]
let ctx = Context::from_webgl_context(window.webgl_context())?;

#[rustfmt::skip]
// This is the data that represents the triangle
Expand Down Expand Up @@ -42,7 +41,7 @@ async fn app(
// The input to the shader program is fed to the vertex_input, so your vertex data's format
// needs to match what you define in vertex_input
let mut shader = ShaderProgram::new(
ctx,
&ctx,
ShaderDescription {
// Take in to the shader a position (as a vector with 2 components) and a color (as a
// vector with 4 components). This is the same format as 'vertices' above
Expand Down Expand Up @@ -72,8 +71,8 @@ async fn app(
)?;

// Create buffer objects, which we use to transfer data from the CPU to the GPU
let mut vb = VertexBuffer::new(ctx)?;
let mut eb = ElementBuffer::new(ctx)?;
let mut vb = VertexBuffer::new(&ctx)?;
let mut eb = ElementBuffer::new(&ctx)?;
// Set the data of the buffer to be our vertices and indices from earlier
vb.set_data(&vertices);
eb.set_data(&indices);
Expand All @@ -98,7 +97,7 @@ async fn app(

// Run our application!
fn main() {
run_gl(Settings::default(), |window, gfx, events| async move {
app(window, gfx, events).await.unwrap()
run(Settings::default(), |window, events| async move {
app(window, events).await.unwrap()
});
}
22 changes: 11 additions & 11 deletions examples/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use golem::{
VertexBuffer,
};

async fn app(
window: Window,
ctx: golem::glow::Context,
mut events: EventStream,
) -> Result<(), GolemError> {
let ctx = &Context::from_glow(ctx)?;
async fn app(window: Window, mut events: EventStream) -> Result<(), GolemError> {
// On desktop and web, we have to load the context slightly differently
#[cfg(not(target_arch = "wasm32"))]
let ctx = Context::from_loader_function(|addr| window.get_proc_address(addr))?;
#[cfg(target_arch = "wasm32")]
let ctx = Context::from_webgl_context(window.webgl_context())?;

#[rustfmt::skip]
let image = [
Expand All @@ -36,7 +36,7 @@ async fn app(
let indices = [0, 1, 2, 2, 3, 0];

let mut shader = ShaderProgram::new(
ctx,
&ctx,
ShaderDescription {
vertex_input: &[
Attribute::new("vert_position", AttributeType::Vector(D2)),
Expand All @@ -54,8 +54,8 @@ async fn app(
},
)?;

let mut vb = VertexBuffer::new(ctx)?;
let mut eb = ElementBuffer::new(ctx)?;
let mut vb = VertexBuffer::new(&ctx)?;
let mut eb = ElementBuffer::new(&ctx)?;
vb.set_data(&vertices);
eb.set_data(&indices);
shader.bind();
Expand All @@ -76,7 +76,7 @@ async fn app(
}

fn main() {
run_gl(Settings::default(), |window, gfx, events| async move {
app(window, gfx, events).await.unwrap()
run(Settings::default(), |window, events| async move {
app(window, events).await.unwrap()
});
}
Loading