Skip to content

Commit

Permalink
webgl2_renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
mrk-its committed Oct 12, 2020
1 parent 0c4ef21 commit 89c04ca
Show file tree
Hide file tree
Showing 36 changed files with 1,988 additions and 150 deletions.
16 changes: 15 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ default = [
"mp3",
"x11",
]

web = [
"bevy_webgl2",
"bevy_winit",
"render",
"bevy_sprite",
"png",
"bevy_text",
"bevy_ui",
]

profiler = ["bevy_ecs/profiler", "bevy_diagnostic/profiler"]
wgpu_trace = ["bevy_wgpu/trace"]

Expand Down Expand Up @@ -80,18 +91,21 @@ bevy_sprite = { path = "crates/bevy_sprite", optional = true, version = "0.2.1"
bevy_text = { path = "crates/bevy_text", optional = true, version = "0.2.1" }
bevy_ui = { path = "crates/bevy_ui", optional = true, version = "0.2.1" }
bevy_wgpu = { path = "crates/bevy_wgpu", optional = true, version = "0.2.1" }
bevy_webgl2 = { path = "crates/bevy_webgl2", optional = true, version = "0.2.1" }
bevy_winit = { path = "crates/bevy_winit", optional = true, version = "0.2.1" }
bevy_gilrs = { path = "crates/bevy_gilrs", optional = true, version = "0.2.1" }
log = { version = "0.4", features = ["release_max_level_info"] }

[dev-dependencies]
rand = "0.7.3"
serde = { version = "1", features = ["derive"] }
log = "0.4"
ron = "0.6"
anyhow = "1.0"
env_logger = "0.7"
console_error_panic_hook = "0.1.6"

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
console_error_panic_hook = "0.1.6"
console_log = { version = "0.2", features = ["color"] }

[[example]]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion crates/bevy_asset/src/asset_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl AssetServer {

#[cfg(target_arch = "wasm32")]
fn get_root_path(&self) -> Result<PathBuf, AssetServerError> {
Ok(PathBuf::from("/"))
Ok(PathBuf::from("."))
}

// TODO: add type checking here. people shouldn't be able to request a Handle<Texture> for a Mesh asset
Expand Down
6 changes: 4 additions & 2 deletions crates/bevy_render/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ bevy_window = { path = "../bevy_window", version = "0.2.1" }
bevy_utils = { path = "../bevy_utils", version = "0.2.1" }

# rendering
spirv-reflect = "0.2.3"
image = { version = "0.23", default-features = false }

# misc
Expand All @@ -45,7 +44,10 @@ hex = "0.4.2"
hexasphere = "1.0.0"
parking_lot = "0.11.0"

[target.'cfg(not(target_os = "ios"))'.dependencies]
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
spirv-reflect = "0.2.3"

[target.'cfg(all(not(target_os = "ios"), not(target_arch = "wasm32")))'.dependencies]
bevy-glsl-to-spirv = "0.1.7"

[target.'cfg(target_os = "ios")'.dependencies]
Expand Down
1 change: 0 additions & 1 deletion crates/bevy_render/src/mesh/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::{
},
render_graph::{CommandQueue, Node, SystemNode},
renderer::{BufferInfo, BufferUsage, RenderResourceContext, RenderResourceId},
render_graph::{CommandQueue, Node, SystemNode},
};
use bevy_app::prelude::{EventReader, Events};
use bevy_asset::{AssetEvent, Assets, Handle};
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_render/src/pipeline/pipeline_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ impl PipelineCompiler {

let specialized_pipeline_handle = pipelines.add(specialized_descriptor);
render_resource_context.create_render_pipeline(
source_pipeline,
specialized_pipeline_handle,
pipelines.get(&specialized_pipeline_handle).unwrap(),
&shaders,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/pipeline/render_pipelines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub fn draw_render_pipelines_system(
.set_bind_groups_from_bindings(
&mut draw,
&mut [
&mut render_pipelines.bindings,
&mut render_pipelines.bindings, // memory leak!
&mut render_resource_bindings,
],
)
Expand Down
66 changes: 35 additions & 31 deletions crates/bevy_render/src/pipeline/vertex_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,40 +35,44 @@ pub enum VertexFormat {
}

impl VertexFormat {
pub fn get_size(&self) -> u64 {
pub fn get_sizes(&self) -> (i32, i32) {
match *self {
VertexFormat::Uchar2 => 2,
VertexFormat::Uchar4 => 4,
VertexFormat::Char2 => 2,
VertexFormat::Char4 => 4,
VertexFormat::Uchar2Norm => 2,
VertexFormat::Uchar4Norm => 4,
VertexFormat::Char2Norm => 2,
VertexFormat::Char4Norm => 4,
VertexFormat::Ushort2 => 2 * 2,
VertexFormat::Ushort4 => 2 * 4,
VertexFormat::Short2 => 2 * 2,
VertexFormat::Short4 => 2 * 4,
VertexFormat::Ushort2Norm => 2 * 2,
VertexFormat::Ushort4Norm => 2 * 4,
VertexFormat::Short2Norm => 2 * 2,
VertexFormat::Short4Norm => 2 * 4,
VertexFormat::Half2 => 2 * 2,
VertexFormat::Half4 => 2 * 4,
VertexFormat::Float => 4,
VertexFormat::Float2 => 4 * 2,
VertexFormat::Float3 => 4 * 3,
VertexFormat::Float4 => 4 * 4,
VertexFormat::Uint => 4,
VertexFormat::Uint2 => 4 * 2,
VertexFormat::Uint3 => 4 * 3,
VertexFormat::Uint4 => 4 * 4,
VertexFormat::Int => 4,
VertexFormat::Int2 => 4 * 2,
VertexFormat::Int3 => 4 * 3,
VertexFormat::Int4 => 4 * 4,
VertexFormat::Uchar2 => (1, 2),
VertexFormat::Uchar4 => (1, 4),
VertexFormat::Char2 => (1, 2),
VertexFormat::Char4 => (1, 4),
VertexFormat::Uchar2Norm => (1, 2),
VertexFormat::Uchar4Norm => (1, 4),
VertexFormat::Char2Norm => (1, 2),
VertexFormat::Char4Norm => (1, 4),
VertexFormat::Ushort2 => (2, 2),
VertexFormat::Ushort4 => (2, 4),
VertexFormat::Short2 => (2, 2),
VertexFormat::Short4 => (2, 4),
VertexFormat::Ushort2Norm => (2, 2),
VertexFormat::Ushort4Norm => (2, 4),
VertexFormat::Short2Norm => (2, 2),
VertexFormat::Short4Norm => (2, 4),
VertexFormat::Half2 => (2, 2),
VertexFormat::Half4 => (2, 4),
VertexFormat::Float => (4, 1),
VertexFormat::Float2 => (4, 2),
VertexFormat::Float3 => (4, 3),
VertexFormat::Float4 => (4, 4),
VertexFormat::Uint => (4, 1),
VertexFormat::Uint2 => (4, 2),
VertexFormat::Uint3 => (4, 3),
VertexFormat::Uint4 => (4, 4),
VertexFormat::Int => (4, 1),
VertexFormat::Int2 => (4, 2),
VertexFormat::Int3 => (4, 3),
VertexFormat::Int4 => (4, 4),
}
}
pub fn get_size(&self) -> u64 {
let (component_size, components) = self.get_sizes();
return (component_size * components) as u64;
}
}

pub trait AsVertexFormats {
Expand Down
Loading

0 comments on commit 89c04ca

Please sign in to comment.