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

Glow backend #210

Merged
merged 96 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
1a16b73
Use Glow
asny Mar 11, 2022
7755184
Fix some errors
asny Mar 11, 2022
ba2e2e8
More fixes
asny Mar 12, 2022
1bc6523
...
asny Mar 12, 2022
3a3f3d9
Program done
asny Mar 12, 2022
1fcc1c1
Context takes an Rc to a glow context
asny Mar 12, 2022
27806cd
uniform done
asny Mar 12, 2022
88d8468
render target done
asny Mar 12, 2022
f96414a
Fix headless
asny Mar 13, 2022
81717f7
Texture
asny Mar 13, 2022
39c0bc4
Uniform buffer
asny Mar 13, 2022
c48daed
Screen
asny Mar 13, 2022
67d765b
DataType
asny Mar 13, 2022
e463a68
Almost working
asny Mar 13, 2022
aa8a018
unsafe
asny Mar 13, 2022
c44e937
is_max
asny Mar 13, 2022
b83cc7f
unsafe
asny Mar 13, 2022
f4d16c9
to and from byte slice functions
asny Mar 13, 2022
60ae3a4
Unsafe (compiling)
asny Mar 13, 2022
9fbf524
Fix warnings
asny Mar 13, 2022
04652d9
Do not use camera uniform buffer in Mesh
asny Mar 13, 2022
adb869f
Fix uniform buffer location
asny Mar 13, 2022
cc0c3ee
Gl error check
asny Mar 14, 2022
c7d3dd6
Use draw error
asny Mar 14, 2022
43ec228
Error check on context
asny Mar 14, 2022
b34a4a4
Error check on buffer fill
asny Mar 14, 2022
8956a9b
Bind vertex array and set seamless texture cube at context creation
asny Mar 14, 2022
97e6651
Avoid ogl and wgl
asny Mar 14, 2022
43858a7
Fix viewProjection
asny Mar 14, 2022
d97136d
Fix instanced mesh
asny Mar 14, 2022
4b5a972
Do not use indices in mandelbrot example
asny Mar 14, 2022
989152e
Fix warning
asny Mar 14, 2022
9fb9b5e
Fix docs
asny Mar 14, 2022
57693b8
Remove debug feature
asny Mar 14, 2022
26f888f
Use glow context on web
asny Mar 14, 2022
280ead3
Web is working
asny Mar 14, 2022
f3b6f51
More checks
asny Mar 14, 2022
36c70fc
Framebuffer checks
asny Mar 14, 2022
ed3f680
core::context module
asny Mar 15, 2022
bea2f17
glow::Context as GlContext
asny Mar 15, 2022
3093a57
context module reexport glow
asny Mar 16, 2022
eb7c779
Avoid GlContext name
asny Mar 16, 2022
280b0d3
Docs
asny Mar 16, 2022
420d195
Replace glow with crate::context internally
asny Mar 16, 2022
1620c6a
Docs
asny Mar 16, 2022
e1abed1
pub use HasContext in core::Context
asny Mar 17, 2022
20c953a
Docs
asny Mar 17, 2022
d6073ef
Use TextureDataType to determine the texture format
asny Mar 17, 2022
64abcb1
Derive format from TextureDataType
asny Mar 17, 2022
36b8ee5
Remove unused CopyDestination
asny Mar 17, 2022
d72e474
Avoid generic parameter for textures, only at construction
asny Mar 17, 2022
d34c56a
Fixes
asny Mar 17, 2022
364520d
More fixes
asny Mar 18, 2022
ba55c7a
Clean-up
asny Mar 18, 2022
cd54907
Fix hdr
asny Mar 18, 2022
10e7169
impl UniformDataType for Color
asny Mar 18, 2022
8a7acd4
Fix examples
asny Mar 18, 2022
18e761c
Avoid buffer generic parameter
asny Mar 18, 2022
1d6ea12
Avoid generics on ElementBuffer
asny Mar 18, 2022
cded186
CpuElementBuffer
asny Mar 18, 2022
3267321
to_mut_byte_slice
asny Mar 18, 2022
fbfb40d
Moved to/from byte slice functionality out of internal
asny Mar 18, 2022
ca254a1
Merge uniform data type extensions into data type
asny Mar 19, 2022
9a04035
More primitive data types supported for UniformDataType
asny Mar 19, 2022
269eb49
Avoid default method in DataType
asny Mar 19, 2022
34f9176
Use array instead of vec for texture data
asny Mar 19, 2022
9f8e888
More data types for buffer/uniform
asny Mar 19, 2022
e77f0e9
Fix depth material
asny Mar 19, 2022
594d490
Fix vec3 uniform
asny Mar 20, 2022
d010ffc
Fix emissive and fog
asny Mar 20, 2022
2d3b3d9
Fix web
asny Mar 20, 2022
8c7be38
Fix volume parsing
asny Mar 20, 2022
caac075
Add volume example
asny Mar 20, 2022
3e784ec
Bump version
asny Mar 20, 2022
d9140a0
texture read other formats than RGBA
asny Mar 21, 2022
a983099
Save pixels/read color takes/returns Vec<[u8; 4]>
asny Mar 21, 2022
7223628
Fix reading other formats than RGBA on web
asny Mar 21, 2022
96e38dd
Move and rename internal function
asny Mar 21, 2022
2f8217a
RenderTarget read_color
asny Mar 21, 2022
f8cae11
Docs
asny Mar 21, 2022
3a89aab
Error check after read
asny Mar 21, 2022
b8ad53c
Move data type definitions to data_type.rs
asny Mar 21, 2022
d9ecfc4
RenderTarget::screen
asny Mar 21, 2022
3be5c7e
render target read_depth
asny Mar 21, 2022
4a3e494
Picking target texture is one float
asny Mar 21, 2022
dbc0533
PrimitiveDataType impl Default
asny Mar 21, 2022
771622f
Check byte length when filling texture
asny Mar 21, 2022
f50cf04
Remove ogl and wgl
asny Mar 21, 2022
2eb9f4a
Docs
asny Mar 21, 2022
0e03975
Docs
asny Mar 21, 2022
90ea4a8
More docs
asny Mar 21, 2022
8c8f858
CpuElementBuffer -> Indices
asny Mar 21, 2022
3297c83
Panic if format and generic data type doesn't match for deprecated co…
asny Mar 21, 2022
26b6ba3
Minor clean-up
asny Mar 21, 2022
eeb262a
Minor clean-up
asny Mar 21, 2022
3978972
Move
asny Mar 21, 2022
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "three-d"
version = "0.10.0" # Remember to update example links
version = "0.11.0" # Remember to update example links
authors = ["Asger Nyman Christiansen <asgernyman@gmail.com>"]
edition = "2021"
description = "2D/3D renderer - makes it simple to draw stuff across platforms (including web)"
Expand All @@ -23,9 +23,9 @@ egui-gui = ["egui"] # Additional GUI features
image-io = ["image"] # Additional image functionality, for example loading an image to a texture
obj-io = ["wavefront_obj", "image-io"]
gltf-io = ["gltf", "image-io"]
debug = [] # Prints OpenGL debug information (only available when NOT building for the wasm32 architecture)

[dependencies]
glow = "0.11"
log = "0.4"
cgmath = "0.18"
half = {version="1.8", features=["std", "num-traits", "zerocopy", "serde"]}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![Logo](https://asny.github.io/three-d/0.10/logo.png)
![Logo](https://asny.github.io/three-d/0.11/logo.png)

# `three-d`

Expand Down Expand Up @@ -39,7 +39,7 @@ The crate consist of three main modules for drawing, `context`, `core` and `rend

### [Examples](https://github.com/asny/three-d/tree/master/examples)

![PBR example](https://asny.github.io/three-d/0.10/pbr.png)
![PBR example](https://asny.github.io/three-d/0.11/pbr.png)

Several examples covering most features can be found in the [examples folder](https://github.com/asny/three-d/tree/master/examples).

Expand Down
26 changes: 0 additions & 26 deletions build.rs

This file was deleted.

4 changes: 4 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ This is the recomended starting point for a gentle introduction to `three-d`.

![Forest example](https://asny.github.io/three-d/0.11/forest.png)

## Volume [[code](https://github.com/asny/three-d/tree/master/examples/volume/src/main.rs)] [[demo](https://asny.github.io/three-d/0.11/volume.html)]

![Volume example](https://asny.github.io/three-d/0.11/volume.png)

## Normals [[code](https://github.com/asny/three-d/tree/master/examples/normals/src/main.rs)] [[demo](https://asny.github.io/three-d/0.11/normals.html)]

![Normals example](https://asny.github.io/three-d/0.11/normals.png)
Expand Down
2 changes: 1 addition & 1 deletion examples/environment/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub async fn run(screenshot: Option<std::path::PathBuf>) {
.unwrap();
let skybox = Skybox::new_with_texture(
&context,
TextureCubeMap::<f16>::new_from_equirectangular(
TextureCubeMap::new_from_equirectangular::<Vector3<f16>>(
&context,
&loaded.hdr_image("chinese_garden_4k").unwrap(),
)
Expand Down
2 changes: 1 addition & 1 deletion examples/fireworks/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub fn run(screenshot: Option<std::path::PathBuf>) {
* explosion_direction,
});
}
particles.update(&data);
particles.update(&data).unwrap();
}

Screen::write(&context, ClearState::color(0.0, 0.0, 0.0, 1.0), || {
Expand Down
3 changes: 1 addition & 2 deletions examples/headless/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn main() {
.unwrap();

// Create a color texture to render into
let mut texture = Texture2D::<u8>::new_empty(
let mut texture = Texture2D::new_empty::<[u8; 4]>(
&context,
viewport.width,
viewport.height,
Expand All @@ -48,7 +48,6 @@ fn main() {
None,
Wrapping::ClampToEdge,
Wrapping::ClampToEdge,
Format::RGBA,
)
.unwrap();

Expand Down
8 changes: 5 additions & 3 deletions examples/logo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ pub async fn run(screenshot: Option<std::path::PathBuf>) {
)
.await
.unwrap();
let environment_map =
TextureCubeMap::<f32>::new_from_equirectangular(&context, &loaded.hdr_image("").unwrap())
.unwrap();
let environment_map = TextureCubeMap::new_from_equirectangular::<Vector3<f16>>(
&context,
&loaded.hdr_image("").unwrap(),
)
.unwrap();
let light = AmbientLight {
environment: Some(Environment::new(&context, &environment_map).unwrap()),
..Default::default()
Expand Down
17 changes: 8 additions & 9 deletions examples/mandelbrot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,17 @@ pub fn run(screenshot: Option<std::path::PathBuf>) {
)
.unwrap();

let indices = vec![0u8, 1, 2, 2, 3, 0];
let positions = vec![
vec3(-2.0, -2.0, 0.0),
vec3(2.0, -2.0, 0.0),
vec3(2.0, 2.0, 0.0),
vec3(-2.0, 2.0, 0.0),
];
let mut mesh = Model::new_with_material(
&context,
&CpuMesh {
indices: Some(Indices::U8(indices)),
positions: Positions::F32(positions),
positions: Positions::F32(vec![
vec3(-2.0, -2.0, 0.0),
vec3(2.0, -2.0, 0.0),
vec3(2.0, 2.0, 0.0),
vec3(2.0, 2.0, 0.0),
vec3(-2.0, 2.0, 0.0),
vec3(-2.0, -2.0, 0.0),
]),
..Default::default()
},
MandelbrotMaterial {},
Expand Down
70 changes: 3 additions & 67 deletions src/context.rs
Original file line number Diff line number Diff line change
@@ -1,71 +1,7 @@
#![allow(missing_docs)]

//!
//! Low-level graphics abstraction layer which maps one-to-one with the OpenGL graphics API on desktop
//! and WebGL2 bindings provided by the [web-sys](https://rustwasm.github.io/wasm-bindgen/api/web_sys/) crate on web.
//! Low-level graphics abstraction layer which maps one-to-one with the OpenGL graphics API on native
//! and WebGL2 graphics API on web. This is just a re-export of the [glow](https://crates.io/crates/glow) crate.
//! Use this if you want to have complete control of a feature but be aware that there are no safety checks.
//!

// GL
#[cfg(not(target_arch = "wasm32"))]
mod ogl;

#[doc(inline)]
#[cfg(not(target_arch = "wasm32"))]
pub use ogl::*;

// WEBGL
#[cfg(target_arch = "wasm32")]
mod wgl2;

#[doc(inline)]
#[cfg(target_arch = "wasm32")]
pub use wgl2::*;

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum ShaderType {
Vertex,
Fragment,
}

#[derive(Copy, Clone, Eq, PartialEq, Hash)]
pub enum DataType {
HalfFloat,
Float,
Byte,
UnsignedByte,
Short,
UnsignedShort,
Int,
UnsignedInt,
}

impl DataType {
fn byte_size(&self) -> u32 {
match self {
DataType::HalfFloat => 2,
DataType::Float => std::mem::size_of::<f32>() as u32,
DataType::UnsignedByte => std::mem::size_of::<u8>() as u32,
DataType::UnsignedShort => std::mem::size_of::<u16>() as u32,
DataType::UnsignedInt => std::mem::size_of::<u32>() as u32,
DataType::Byte => std::mem::size_of::<i8>() as u32,
DataType::Short => std::mem::size_of::<i16>() as u32,
DataType::Int => std::mem::size_of::<i32>() as u32,
}
}
}

impl DataType {
fn to_const(&self) -> u32 {
match self {
DataType::Float => consts::FLOAT,
DataType::HalfFloat => consts::HALF_FLOAT,
DataType::Byte => consts::BYTE,
DataType::UnsignedByte => consts::UNSIGNED_BYTE,
DataType::Short => consts::SHORT,
DataType::UnsignedShort => consts::UNSIGNED_SHORT,
DataType::Int => consts::INT,
DataType::UnsignedInt => consts::UNSIGNED_INT,
}
}
}
pub use glow::*;
Loading