swap out remaining wgpu references
This commit is contained in:
parent
7342f96174
commit
64b897016c
@ -5,7 +5,7 @@ use crate::render::{
|
|||||||
},
|
},
|
||||||
render_graph::RenderGraphBuilder,
|
render_graph::RenderGraphBuilder,
|
||||||
render_resource::{resource_name, resource_providers::FrameTextureResourceProvider},
|
render_resource::{resource_name, resource_providers::FrameTextureResourceProvider},
|
||||||
texture::{TextureDescriptor, TextureDimension},
|
texture::{Extent3d, TextureDescriptor, TextureDimension, TextureFormat, TextureUsage},
|
||||||
Color,
|
Color,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ impl ForwardPassBuilder for RenderGraphBuilder {
|
|||||||
self.add_resource_provider(FrameTextureResourceProvider::new(
|
self.add_resource_provider(FrameTextureResourceProvider::new(
|
||||||
resource_name::texture::DEPTH,
|
resource_name::texture::DEPTH,
|
||||||
TextureDescriptor {
|
TextureDescriptor {
|
||||||
size: wgpu::Extent3d {
|
size: Extent3d {
|
||||||
depth: 1,
|
depth: 1,
|
||||||
width: 1,
|
width: 1,
|
||||||
height: 1,
|
height: 1,
|
||||||
@ -27,8 +27,8 @@ impl ForwardPassBuilder for RenderGraphBuilder {
|
|||||||
mip_level_count: 1,
|
mip_level_count: 1,
|
||||||
sample_count: 1,
|
sample_count: 1,
|
||||||
dimension: TextureDimension::D2,
|
dimension: TextureDimension::D2,
|
||||||
format: wgpu::TextureFormat::Depth32Float,
|
format: TextureFormat::Depth32Float,
|
||||||
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
|
usage: TextureUsage::OUTPUT_ATTACHMENT,
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
.add_pass(
|
.add_pass(
|
||||||
|
@ -4,6 +4,7 @@ mod pipeline;
|
|||||||
mod pipeline_layout;
|
mod pipeline_layout;
|
||||||
pub mod pipelines;
|
pub mod pipelines;
|
||||||
mod vertex_buffer_descriptor;
|
mod vertex_buffer_descriptor;
|
||||||
|
pub mod state_descriptors;
|
||||||
|
|
||||||
pub use bind_group::*;
|
pub use bind_group::*;
|
||||||
pub use binding::*;
|
pub use binding::*;
|
||||||
|
@ -1,9 +1,17 @@
|
|||||||
use super::{BindGroup, PipelineLayout, VertexBufferDescriptor};
|
use super::{
|
||||||
|
state_descriptors::{
|
||||||
|
BlendDescriptor, ColorStateDescriptor, ColorWrite, CompareFunction, CullMode,
|
||||||
|
DepthStencilStateDescriptor, FrontFace, PrimitiveTopology, RasterizationStateDescriptor,
|
||||||
|
StencilStateFaceDescriptor, IndexFormat,
|
||||||
|
},
|
||||||
|
BindGroup, PipelineLayout, VertexBufferDescriptor,
|
||||||
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
asset::{AssetStorage, Handle},
|
asset::{AssetStorage, Handle},
|
||||||
render::{
|
render::{
|
||||||
render_resource::resource_name,
|
render_resource::resource_name,
|
||||||
shader::{Shader, ShaderStages},
|
shader::{Shader, ShaderStages},
|
||||||
|
texture::TextureFormat,
|
||||||
Vertex,
|
Vertex,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -20,19 +28,19 @@ pub struct PipelineDescriptor {
|
|||||||
pub draw_targets: Vec<String>,
|
pub draw_targets: Vec<String>,
|
||||||
pub layout: PipelineLayoutType,
|
pub layout: PipelineLayoutType,
|
||||||
pub shader_stages: ShaderStages,
|
pub shader_stages: ShaderStages,
|
||||||
pub rasterization_state: Option<wgpu::RasterizationStateDescriptor>,
|
pub rasterization_state: Option<RasterizationStateDescriptor>,
|
||||||
|
|
||||||
/// The primitive topology used to interpret vertices.
|
/// The primitive topology used to interpret vertices.
|
||||||
pub primitive_topology: wgpu::PrimitiveTopology,
|
pub primitive_topology: PrimitiveTopology,
|
||||||
|
|
||||||
/// The effect of draw calls on the color aspect of the output target.
|
/// The effect of draw calls on the color aspect of the output target.
|
||||||
pub color_states: Vec<wgpu::ColorStateDescriptor>,
|
pub color_states: Vec<ColorStateDescriptor>,
|
||||||
|
|
||||||
/// The effect of draw calls on the depth and stencil aspects of the output target, if any.
|
/// The effect of draw calls on the depth and stencil aspects of the output target, if any.
|
||||||
pub depth_stencil_state: Option<wgpu::DepthStencilStateDescriptor>,
|
pub depth_stencil_state: Option<DepthStencilStateDescriptor>,
|
||||||
|
|
||||||
/// The format of any index buffers used with this pipeline.
|
/// The format of any index buffers used with this pipeline.
|
||||||
pub index_format: wgpu::IndexFormat,
|
pub index_format: IndexFormat,
|
||||||
|
|
||||||
/// The format of any vertex buffers used with this pipeline.
|
/// The format of any vertex buffers used with this pipeline.
|
||||||
pub vertex_buffer_descriptors: Vec<VertexBufferDescriptor>,
|
pub vertex_buffer_descriptors: Vec<VertexBufferDescriptor>,
|
||||||
@ -61,15 +69,15 @@ impl PipelineDescriptor {
|
|||||||
draw_targets: Vec::new(),
|
draw_targets: Vec::new(),
|
||||||
shader_stages: ShaderStages::new(vertex_shader),
|
shader_stages: ShaderStages::new(vertex_shader),
|
||||||
vertex_buffer_descriptors: Vec::new(),
|
vertex_buffer_descriptors: Vec::new(),
|
||||||
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
|
rasterization_state: Some(RasterizationStateDescriptor {
|
||||||
front_face: wgpu::FrontFace::Ccw,
|
front_face: FrontFace::Ccw,
|
||||||
cull_mode: wgpu::CullMode::Back,
|
cull_mode: CullMode::Back,
|
||||||
depth_bias: 0,
|
depth_bias: 0,
|
||||||
depth_bias_slope_scale: 0.0,
|
depth_bias_slope_scale: 0.0,
|
||||||
depth_bias_clamp: 0.0,
|
depth_bias_clamp: 0.0,
|
||||||
}),
|
}),
|
||||||
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
primitive_topology: PrimitiveTopology::TriangleList,
|
||||||
index_format: wgpu::IndexFormat::Uint16,
|
index_format: IndexFormat::Uint16,
|
||||||
sample_count: 1,
|
sample_count: 1,
|
||||||
sample_mask: !0,
|
sample_mask: !0,
|
||||||
alpha_to_coverage_enabled: false,
|
alpha_to_coverage_enabled: false,
|
||||||
@ -107,7 +115,11 @@ pub struct PipelineBuilder<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> PipelineBuilder<'a> {
|
impl<'a> PipelineBuilder<'a> {
|
||||||
pub fn new(name: &str, shader_storage: &'a mut AssetStorage<Shader>, vertex_shader: Shader) -> Self {
|
pub fn new(
|
||||||
|
name: &str,
|
||||||
|
shader_storage: &'a mut AssetStorage<Shader>,
|
||||||
|
vertex_shader: Shader,
|
||||||
|
) -> Self {
|
||||||
let vertex_shader_handle = shader_storage.add(vertex_shader);
|
let vertex_shader_handle = shader_storage.add(vertex_shader);
|
||||||
PipelineBuilder {
|
PipelineBuilder {
|
||||||
pipeline: PipelineDescriptor::new(Some(name), vertex_shader_handle),
|
pipeline: PipelineDescriptor::new(Some(name), vertex_shader_handle),
|
||||||
@ -125,14 +137,14 @@ impl<'a> PipelineBuilder<'a> {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_color_state(mut self, color_state_descriptor: wgpu::ColorStateDescriptor) -> Self {
|
pub fn add_color_state(mut self, color_state_descriptor: ColorStateDescriptor) -> Self {
|
||||||
self.pipeline.color_states.push(color_state_descriptor);
|
self.pipeline.color_states.push(color_state_descriptor);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_depth_stencil_state(
|
pub fn with_depth_stencil_state(
|
||||||
mut self,
|
mut self,
|
||||||
depth_stencil_state: wgpu::DepthStencilStateDescriptor,
|
depth_stencil_state: DepthStencilStateDescriptor,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
if let Some(_) = self.pipeline.depth_stencil_state {
|
if let Some(_) = self.pipeline.depth_stencil_state {
|
||||||
panic!("Depth stencil state has already been set");
|
panic!("Depth stencil state has already been set");
|
||||||
@ -163,7 +175,7 @@ impl<'a> PipelineBuilder<'a> {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_index_format(mut self, index_format: wgpu::IndexFormat) -> Self {
|
pub fn with_index_format(mut self, index_format: IndexFormat) -> Self {
|
||||||
self.pipeline.index_format = index_format;
|
self.pipeline.index_format = index_format;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@ -175,13 +187,13 @@ impl<'a> PipelineBuilder<'a> {
|
|||||||
|
|
||||||
pub fn with_rasterization_state(
|
pub fn with_rasterization_state(
|
||||||
mut self,
|
mut self,
|
||||||
rasterization_state: wgpu::RasterizationStateDescriptor,
|
rasterization_state: RasterizationStateDescriptor,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.pipeline.rasterization_state = Some(rasterization_state);
|
self.pipeline.rasterization_state = Some(rasterization_state);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_primitive_topology(mut self, primitive_topology: wgpu::PrimitiveTopology) -> Self {
|
pub fn with_primitive_topology(mut self, primitive_topology: PrimitiveTopology) -> Self {
|
||||||
self.pipeline.primitive_topology = primitive_topology;
|
self.pipeline.primitive_topology = primitive_topology;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@ -202,20 +214,20 @@ impl<'a> PipelineBuilder<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_standard_config(self) -> Self {
|
pub fn with_standard_config(self) -> Self {
|
||||||
self.with_depth_stencil_state(wgpu::DepthStencilStateDescriptor {
|
self.with_depth_stencil_state(DepthStencilStateDescriptor {
|
||||||
format: wgpu::TextureFormat::Depth32Float,
|
format: TextureFormat::Depth32Float,
|
||||||
depth_write_enabled: true,
|
depth_write_enabled: true,
|
||||||
depth_compare: wgpu::CompareFunction::Less,
|
depth_compare: CompareFunction::Less,
|
||||||
stencil_front: wgpu::StencilStateFaceDescriptor::IGNORE,
|
stencil_front: StencilStateFaceDescriptor::IGNORE,
|
||||||
stencil_back: wgpu::StencilStateFaceDescriptor::IGNORE,
|
stencil_back: StencilStateFaceDescriptor::IGNORE,
|
||||||
stencil_read_mask: 0,
|
stencil_read_mask: 0,
|
||||||
stencil_write_mask: 0,
|
stencil_write_mask: 0,
|
||||||
})
|
})
|
||||||
.add_color_state(wgpu::ColorStateDescriptor {
|
.add_color_state(ColorStateDescriptor {
|
||||||
format: wgpu::TextureFormat::Bgra8UnormSrgb,
|
format: TextureFormat::Bgra8UnormSrgb,
|
||||||
color_blend: wgpu::BlendDescriptor::REPLACE,
|
color_blend: BlendDescriptor::REPLACE,
|
||||||
alpha_blend: wgpu::BlendDescriptor::REPLACE,
|
alpha_blend: BlendDescriptor::REPLACE,
|
||||||
write_mask: wgpu::ColorWrite::ALL,
|
write_mask: ColorWrite::ALL,
|
||||||
})
|
})
|
||||||
.add_vertex_buffer_descriptor(Vertex::get_vertex_buffer_descriptor())
|
.add_vertex_buffer_descriptor(Vertex::get_vertex_buffer_descriptor())
|
||||||
.add_draw_target(resource_name::draw_target::ASSIGNED_MESHES)
|
.add_draw_target(resource_name::draw_target::ASSIGNED_MESHES)
|
||||||
|
@ -1,10 +1,18 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
asset::AssetStorage,
|
asset::AssetStorage,
|
||||||
render::{
|
render::{
|
||||||
pipeline::PipelineDescriptor,
|
pipeline::{
|
||||||
|
state_descriptors::{
|
||||||
|
BlendDescriptor, BlendFactor, BlendOperation, ColorStateDescriptor, ColorWrite,
|
||||||
|
CompareFunction, CullMode, DepthStencilStateDescriptor, FrontFace,
|
||||||
|
RasterizationStateDescriptor, StencilStateFaceDescriptor,
|
||||||
|
},
|
||||||
|
PipelineDescriptor,
|
||||||
|
},
|
||||||
render_graph::RenderGraphBuilder,
|
render_graph::RenderGraphBuilder,
|
||||||
render_resource::resource_name,
|
render_resource::resource_name,
|
||||||
shader::{Shader, ShaderStage},
|
shader::{Shader, ShaderStage},
|
||||||
|
texture::TextureFormat,
|
||||||
Vertex,
|
Vertex,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -33,35 +41,35 @@ impl ForwardPipelineBuilder for RenderGraphBuilder {
|
|||||||
ShaderStage::Fragment,
|
ShaderStage::Fragment,
|
||||||
include_str!("forward.frag"),
|
include_str!("forward.frag"),
|
||||||
))
|
))
|
||||||
.with_rasterization_state(wgpu::RasterizationStateDescriptor {
|
.with_rasterization_state(RasterizationStateDescriptor {
|
||||||
front_face: wgpu::FrontFace::Ccw,
|
front_face: FrontFace::Ccw,
|
||||||
cull_mode: wgpu::CullMode::Back,
|
cull_mode: CullMode::Back,
|
||||||
depth_bias: 0,
|
depth_bias: 0,
|
||||||
depth_bias_slope_scale: 0.0,
|
depth_bias_slope_scale: 0.0,
|
||||||
depth_bias_clamp: 0.0,
|
depth_bias_clamp: 0.0,
|
||||||
})
|
})
|
||||||
.with_depth_stencil_state(wgpu::DepthStencilStateDescriptor {
|
.with_depth_stencil_state(DepthStencilStateDescriptor {
|
||||||
format: wgpu::TextureFormat::Depth32Float,
|
format: TextureFormat::Depth32Float,
|
||||||
depth_write_enabled: true,
|
depth_write_enabled: true,
|
||||||
depth_compare: wgpu::CompareFunction::Less,
|
depth_compare: CompareFunction::Less,
|
||||||
stencil_front: wgpu::StencilStateFaceDescriptor::IGNORE,
|
stencil_front: StencilStateFaceDescriptor::IGNORE,
|
||||||
stencil_back: wgpu::StencilStateFaceDescriptor::IGNORE,
|
stencil_back: StencilStateFaceDescriptor::IGNORE,
|
||||||
stencil_read_mask: 0,
|
stencil_read_mask: 0,
|
||||||
stencil_write_mask: 0,
|
stencil_write_mask: 0,
|
||||||
})
|
})
|
||||||
.add_color_state(wgpu::ColorStateDescriptor {
|
.add_color_state(ColorStateDescriptor {
|
||||||
format: wgpu::TextureFormat::Bgra8UnormSrgb,
|
format: TextureFormat::Bgra8UnormSrgb,
|
||||||
color_blend: wgpu::BlendDescriptor {
|
color_blend: BlendDescriptor {
|
||||||
src_factor: wgpu::BlendFactor::SrcAlpha,
|
src_factor: BlendFactor::SrcAlpha,
|
||||||
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
dst_factor: BlendFactor::OneMinusSrcAlpha,
|
||||||
operation: wgpu::BlendOperation::Add,
|
operation: BlendOperation::Add,
|
||||||
},
|
},
|
||||||
alpha_blend: wgpu::BlendDescriptor {
|
alpha_blend: BlendDescriptor {
|
||||||
src_factor: wgpu::BlendFactor::One,
|
src_factor: BlendFactor::One,
|
||||||
dst_factor: wgpu::BlendFactor::One,
|
dst_factor: BlendFactor::One,
|
||||||
operation: wgpu::BlendOperation::Add,
|
operation: BlendOperation::Add,
|
||||||
},
|
},
|
||||||
write_mask: wgpu::ColorWrite::ALL,
|
write_mask: ColorWrite::ALL,
|
||||||
})
|
})
|
||||||
.add_vertex_buffer_descriptor(Vertex::get_vertex_buffer_descriptor())
|
.add_vertex_buffer_descriptor(Vertex::get_vertex_buffer_descriptor())
|
||||||
.add_draw_target(resource_name::draw_target::ASSIGNED_MESHES)
|
.add_draw_target(resource_name::draw_target::ASSIGNED_MESHES)
|
||||||
|
@ -1,10 +1,18 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
asset::AssetStorage,
|
asset::AssetStorage,
|
||||||
render::{
|
render::{
|
||||||
pipeline::PipelineDescriptor,
|
pipeline::{
|
||||||
|
state_descriptors::{
|
||||||
|
BlendDescriptor, ColorStateDescriptor, ColorWrite, CompareFunction, CullMode,
|
||||||
|
DepthStencilStateDescriptor, FrontFace, RasterizationStateDescriptor,
|
||||||
|
StencilStateFaceDescriptor,
|
||||||
|
},
|
||||||
|
PipelineDescriptor,
|
||||||
|
},
|
||||||
render_graph::RenderGraphBuilder,
|
render_graph::RenderGraphBuilder,
|
||||||
render_resource::resource_name,
|
render_resource::resource_name,
|
||||||
shader::{Shader, ShaderStage},
|
shader::{Shader, ShaderStage},
|
||||||
|
texture::TextureFormat,
|
||||||
Vertex,
|
Vertex,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -34,27 +42,27 @@ impl ForwardFlatPipelineBuilder for RenderGraphBuilder {
|
|||||||
ShaderStage::Fragment,
|
ShaderStage::Fragment,
|
||||||
include_str!("forward_flat.frag"),
|
include_str!("forward_flat.frag"),
|
||||||
))
|
))
|
||||||
.with_rasterization_state(wgpu::RasterizationStateDescriptor {
|
.with_rasterization_state(RasterizationStateDescriptor {
|
||||||
front_face: wgpu::FrontFace::Ccw,
|
front_face: FrontFace::Ccw,
|
||||||
cull_mode: wgpu::CullMode::Back,
|
cull_mode: CullMode::Back,
|
||||||
depth_bias: 0,
|
depth_bias: 0,
|
||||||
depth_bias_slope_scale: 0.0,
|
depth_bias_slope_scale: 0.0,
|
||||||
depth_bias_clamp: 0.0,
|
depth_bias_clamp: 0.0,
|
||||||
})
|
})
|
||||||
.with_depth_stencil_state(wgpu::DepthStencilStateDescriptor {
|
.with_depth_stencil_state(DepthStencilStateDescriptor {
|
||||||
format: wgpu::TextureFormat::Depth32Float,
|
format: TextureFormat::Depth32Float,
|
||||||
depth_write_enabled: true,
|
depth_write_enabled: true,
|
||||||
depth_compare: wgpu::CompareFunction::Less,
|
depth_compare: CompareFunction::Less,
|
||||||
stencil_front: wgpu::StencilStateFaceDescriptor::IGNORE,
|
stencil_front: StencilStateFaceDescriptor::IGNORE,
|
||||||
stencil_back: wgpu::StencilStateFaceDescriptor::IGNORE,
|
stencil_back: StencilStateFaceDescriptor::IGNORE,
|
||||||
stencil_read_mask: 0,
|
stencil_read_mask: 0,
|
||||||
stencil_write_mask: 0,
|
stencil_write_mask: 0,
|
||||||
})
|
})
|
||||||
.add_color_state(wgpu::ColorStateDescriptor {
|
.add_color_state(ColorStateDescriptor {
|
||||||
format: wgpu::TextureFormat::Bgra8UnormSrgb,
|
format: TextureFormat::Bgra8UnormSrgb,
|
||||||
color_blend: wgpu::BlendDescriptor::REPLACE,
|
color_blend: BlendDescriptor::REPLACE,
|
||||||
alpha_blend: wgpu::BlendDescriptor::REPLACE,
|
alpha_blend: BlendDescriptor::REPLACE,
|
||||||
write_mask: wgpu::ColorWrite::ALL,
|
write_mask: ColorWrite::ALL,
|
||||||
})
|
})
|
||||||
.add_vertex_buffer_descriptor(Vertex::get_vertex_buffer_descriptor())
|
.add_vertex_buffer_descriptor(Vertex::get_vertex_buffer_descriptor())
|
||||||
.add_draw_target(resource_name::draw_target::MESHES)
|
.add_draw_target(resource_name::draw_target::MESHES)
|
||||||
|
@ -2,12 +2,18 @@ use crate::{
|
|||||||
asset::AssetStorage,
|
asset::AssetStorage,
|
||||||
render::{
|
render::{
|
||||||
pipeline::{
|
pipeline::{
|
||||||
|
state_descriptors::{
|
||||||
|
BlendDescriptor, BlendFactor, BlendOperation, ColorStateDescriptor, ColorWrite,
|
||||||
|
CompareFunction, CullMode, DepthStencilStateDescriptor, FrontFace,
|
||||||
|
RasterizationStateDescriptor, StencilStateFaceDescriptor,
|
||||||
|
},
|
||||||
InputStepMode, PipelineDescriptor, VertexAttributeDescriptor, VertexBufferDescriptor,
|
InputStepMode, PipelineDescriptor, VertexAttributeDescriptor, VertexBufferDescriptor,
|
||||||
VertexFormat,
|
VertexFormat,
|
||||||
},
|
},
|
||||||
render_graph::RenderGraphBuilder,
|
render_graph::RenderGraphBuilder,
|
||||||
render_resource::{resource_name, resource_providers::RectData},
|
render_resource::{resource_name, resource_providers::RectData},
|
||||||
shader::{Shader, ShaderStage},
|
shader::{Shader, ShaderStage},
|
||||||
|
texture::TextureFormat,
|
||||||
Vertex,
|
Vertex,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -36,35 +42,35 @@ impl UiPipelineBuilder for RenderGraphBuilder {
|
|||||||
ShaderStage::Fragment,
|
ShaderStage::Fragment,
|
||||||
include_str!("ui.frag"),
|
include_str!("ui.frag"),
|
||||||
))
|
))
|
||||||
.with_rasterization_state(wgpu::RasterizationStateDescriptor {
|
.with_rasterization_state(RasterizationStateDescriptor {
|
||||||
front_face: wgpu::FrontFace::Ccw,
|
front_face: FrontFace::Ccw,
|
||||||
cull_mode: wgpu::CullMode::None,
|
cull_mode: CullMode::None,
|
||||||
depth_bias: 0,
|
depth_bias: 0,
|
||||||
depth_bias_slope_scale: 0.0,
|
depth_bias_slope_scale: 0.0,
|
||||||
depth_bias_clamp: 0.0,
|
depth_bias_clamp: 0.0,
|
||||||
})
|
})
|
||||||
.with_depth_stencil_state(wgpu::DepthStencilStateDescriptor {
|
.with_depth_stencil_state(DepthStencilStateDescriptor {
|
||||||
format: wgpu::TextureFormat::Depth32Float,
|
format: TextureFormat::Depth32Float,
|
||||||
depth_write_enabled: false,
|
depth_write_enabled: false,
|
||||||
depth_compare: wgpu::CompareFunction::Always,
|
depth_compare: CompareFunction::Always,
|
||||||
stencil_front: wgpu::StencilStateFaceDescriptor::IGNORE,
|
stencil_front: StencilStateFaceDescriptor::IGNORE,
|
||||||
stencil_back: wgpu::StencilStateFaceDescriptor::IGNORE,
|
stencil_back: StencilStateFaceDescriptor::IGNORE,
|
||||||
stencil_read_mask: 0,
|
stencil_read_mask: 0,
|
||||||
stencil_write_mask: 0,
|
stencil_write_mask: 0,
|
||||||
})
|
})
|
||||||
.add_color_state(wgpu::ColorStateDescriptor {
|
.add_color_state(ColorStateDescriptor {
|
||||||
format: wgpu::TextureFormat::Bgra8UnormSrgb,
|
format: TextureFormat::Bgra8UnormSrgb,
|
||||||
color_blend: wgpu::BlendDescriptor {
|
color_blend: BlendDescriptor {
|
||||||
src_factor: wgpu::BlendFactor::SrcAlpha,
|
src_factor: BlendFactor::SrcAlpha,
|
||||||
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
dst_factor: BlendFactor::OneMinusSrcAlpha,
|
||||||
operation: wgpu::BlendOperation::Add,
|
operation: BlendOperation::Add,
|
||||||
},
|
},
|
||||||
alpha_blend: wgpu::BlendDescriptor {
|
alpha_blend: BlendDescriptor {
|
||||||
src_factor: wgpu::BlendFactor::One,
|
src_factor: BlendFactor::One,
|
||||||
dst_factor: wgpu::BlendFactor::One,
|
dst_factor: BlendFactor::One,
|
||||||
operation: wgpu::BlendOperation::Add,
|
operation: BlendOperation::Add,
|
||||||
},
|
},
|
||||||
write_mask: wgpu::ColorWrite::ALL,
|
write_mask: ColorWrite::ALL,
|
||||||
})
|
})
|
||||||
.add_vertex_buffer_descriptor(Vertex::get_vertex_buffer_descriptor())
|
.add_vertex_buffer_descriptor(Vertex::get_vertex_buffer_descriptor())
|
||||||
.add_vertex_buffer_descriptor(VertexBufferDescriptor {
|
.add_vertex_buffer_descriptor(VertexBufferDescriptor {
|
||||||
|
174
src/render/pipeline/state_descriptors.rs
Normal file
174
src/render/pipeline/state_descriptors.rs
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
use crate::render::texture::TextureFormat;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct DepthStencilStateDescriptor {
|
||||||
|
pub format: TextureFormat,
|
||||||
|
pub depth_write_enabled: bool,
|
||||||
|
pub depth_compare: CompareFunction,
|
||||||
|
pub stencil_front: StencilStateFaceDescriptor,
|
||||||
|
pub stencil_back: StencilStateFaceDescriptor,
|
||||||
|
pub stencil_read_mask: u32,
|
||||||
|
pub stencil_write_mask: u32,
|
||||||
|
}
|
||||||
|
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||||
|
pub enum StencilOperation {
|
||||||
|
Keep = 0,
|
||||||
|
Zero = 1,
|
||||||
|
Replace = 2,
|
||||||
|
Invert = 3,
|
||||||
|
IncrementClamp = 4,
|
||||||
|
DecrementClamp = 5,
|
||||||
|
IncrementWrap = 6,
|
||||||
|
DecrementWrap = 7,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
pub struct StencilStateFaceDescriptor {
|
||||||
|
pub compare: CompareFunction,
|
||||||
|
pub fail_op: StencilOperation,
|
||||||
|
pub depth_fail_op: StencilOperation,
|
||||||
|
pub pass_op: StencilOperation,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl StencilStateFaceDescriptor {
|
||||||
|
pub const IGNORE: Self = StencilStateFaceDescriptor {
|
||||||
|
compare: CompareFunction::Always,
|
||||||
|
fail_op: StencilOperation::Keep,
|
||||||
|
depth_fail_op: StencilOperation::Keep,
|
||||||
|
pass_op: StencilOperation::Keep,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||||
|
pub enum CompareFunction {
|
||||||
|
Never = 0,
|
||||||
|
Less = 1,
|
||||||
|
Equal = 2,
|
||||||
|
LessEqual = 3,
|
||||||
|
Greater = 4,
|
||||||
|
NotEqual = 5,
|
||||||
|
GreaterEqual = 6,
|
||||||
|
Always = 7,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||||
|
pub enum PrimitiveTopology {
|
||||||
|
PointList = 0,
|
||||||
|
LineList = 1,
|
||||||
|
LineStrip = 2,
|
||||||
|
TriangleList = 3,
|
||||||
|
TriangleStrip = 4,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||||
|
pub enum FrontFace {
|
||||||
|
Ccw = 0,
|
||||||
|
Cw = 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for FrontFace {
|
||||||
|
fn default() -> Self {
|
||||||
|
FrontFace::Ccw
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||||
|
pub enum CullMode {
|
||||||
|
None = 0,
|
||||||
|
Front = 1,
|
||||||
|
Back = 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for CullMode {
|
||||||
|
fn default() -> Self {
|
||||||
|
CullMode::None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default)]
|
||||||
|
pub struct RasterizationStateDescriptor {
|
||||||
|
pub front_face: FrontFace,
|
||||||
|
pub cull_mode: CullMode,
|
||||||
|
pub depth_bias: i32,
|
||||||
|
pub depth_bias_slope_scale: f32,
|
||||||
|
pub depth_bias_clamp: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct ColorStateDescriptor {
|
||||||
|
pub format: TextureFormat,
|
||||||
|
pub alpha_blend: BlendDescriptor,
|
||||||
|
pub color_blend: BlendDescriptor,
|
||||||
|
pub write_mask: ColorWrite,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
pub struct BlendDescriptor {
|
||||||
|
pub src_factor: BlendFactor,
|
||||||
|
pub dst_factor: BlendFactor,
|
||||||
|
pub operation: BlendOperation,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BlendDescriptor {
|
||||||
|
pub const REPLACE: Self = BlendDescriptor {
|
||||||
|
src_factor: BlendFactor::One,
|
||||||
|
dst_factor: BlendFactor::Zero,
|
||||||
|
operation: BlendOperation::Add,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
bitflags::bitflags! {
|
||||||
|
#[repr(transparent)]
|
||||||
|
pub struct ColorWrite: u32 {
|
||||||
|
const RED = 1;
|
||||||
|
const GREEN = 2;
|
||||||
|
const BLUE = 4;
|
||||||
|
const ALPHA = 8;
|
||||||
|
const COLOR = 7;
|
||||||
|
const ALL = 15;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for ColorWrite {
|
||||||
|
fn default() -> Self {
|
||||||
|
ColorWrite::ALL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||||
|
pub enum BlendFactor {
|
||||||
|
Zero = 0,
|
||||||
|
One = 1,
|
||||||
|
SrcColor = 2,
|
||||||
|
OneMinusSrcColor = 3,
|
||||||
|
SrcAlpha = 4,
|
||||||
|
OneMinusSrcAlpha = 5,
|
||||||
|
DstColor = 6,
|
||||||
|
OneMinusDstColor = 7,
|
||||||
|
DstAlpha = 8,
|
||||||
|
OneMinusDstAlpha = 9,
|
||||||
|
SrcAlphaSaturated = 10,
|
||||||
|
BlendColor = 11,
|
||||||
|
OneMinusBlendColor = 12,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||||
|
pub enum BlendOperation {
|
||||||
|
Add = 0,
|
||||||
|
Subtract = 1,
|
||||||
|
ReverseSubtract = 2,
|
||||||
|
Min = 3,
|
||||||
|
Max = 4,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for BlendOperation {
|
||||||
|
fn default() -> Self {
|
||||||
|
BlendOperation::Add
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||||
|
pub enum IndexFormat {
|
||||||
|
Uint16 = 0,
|
||||||
|
Uint32 = 1,
|
||||||
|
}
|
@ -1,15 +1,15 @@
|
|||||||
|
use crate::render::render_resource::BufferUsage;
|
||||||
|
|
||||||
pub enum ResourceInfo {
|
pub enum ResourceInfo {
|
||||||
Buffer {
|
Buffer {
|
||||||
size: u64,
|
size: u64,
|
||||||
buffer_usage: wgpu::BufferUsage,
|
buffer_usage: BufferUsage,
|
||||||
// pub layout: Option<
|
|
||||||
},
|
},
|
||||||
InstanceBuffer {
|
InstanceBuffer {
|
||||||
size: usize,
|
size: usize,
|
||||||
count: usize,
|
count: usize,
|
||||||
buffer_usage: wgpu::BufferUsage,
|
buffer_usage: BufferUsage,
|
||||||
mesh_id: usize,
|
mesh_id: usize,
|
||||||
// pub layout: Option<
|
|
||||||
},
|
},
|
||||||
Texture,
|
Texture,
|
||||||
Sampler,
|
Sampler,
|
||||||
|
@ -42,7 +42,7 @@ impl ResourceProvider for LightResourceProvider {
|
|||||||
) {
|
) {
|
||||||
let light_uniform_size = (std::mem::size_of::<LightCount>()
|
let light_uniform_size = (std::mem::size_of::<LightCount>()
|
||||||
+ self.max_lights * std::mem::size_of::<LightRaw>())
|
+ self.max_lights * std::mem::size_of::<LightRaw>())
|
||||||
as wgpu::BufferAddress;
|
as u64;
|
||||||
|
|
||||||
let buffer = renderer.create_buffer(
|
let buffer = renderer.create_buffer(
|
||||||
light_uniform_size,
|
light_uniform_size,
|
||||||
@ -102,7 +102,7 @@ impl ResourceProvider for LightResourceProvider {
|
|||||||
0,
|
0,
|
||||||
self.light_buffer.unwrap(),
|
self.light_buffer.unwrap(),
|
||||||
0,
|
0,
|
||||||
light_count_size as wgpu::BufferAddress,
|
light_count_size as u64,
|
||||||
);
|
);
|
||||||
|
|
||||||
renderer.copy_buffer_to_buffer(
|
renderer.copy_buffer_to_buffer(
|
||||||
@ -110,7 +110,7 @@ impl ResourceProvider for LightResourceProvider {
|
|||||||
0,
|
0,
|
||||||
self.light_buffer.unwrap(),
|
self.light_buffer.unwrap(),
|
||||||
light_count_size as u64,
|
light_count_size as u64,
|
||||||
total_size as wgpu::BufferAddress,
|
total_size as u64,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ use std::{
|
|||||||
marker::PhantomData,
|
marker::PhantomData,
|
||||||
ops::Deref,
|
ops::Deref,
|
||||||
};
|
};
|
||||||
|
pub const BIND_BUFFER_ALIGNMENT: u64 = 256;
|
||||||
pub struct UniformResourceProvider<T>
|
pub struct UniformResourceProvider<T>
|
||||||
where
|
where
|
||||||
T: AsUniforms + Send + Sync,
|
T: AsUniforms + Send + Sync,
|
||||||
@ -150,7 +150,7 @@ where
|
|||||||
|
|
||||||
// allocate enough space for twice as many entities as there are currently;
|
// allocate enough space for twice as many entities as there are currently;
|
||||||
let capacity = count * 2;
|
let capacity = count * 2;
|
||||||
let size = wgpu::BIND_BUFFER_ALIGNMENT * capacity;
|
let size = BIND_BUFFER_ALIGNMENT * capacity;
|
||||||
let created_resource =
|
let created_resource =
|
||||||
renderer.create_buffer(size, BufferUsage::COPY_DST | BufferUsage::UNIFORM);
|
renderer.create_buffer(size, BufferUsage::COPY_DST | BufferUsage::UNIFORM);
|
||||||
|
|
||||||
@ -169,10 +169,10 @@ where
|
|||||||
let resource = resource.unwrap();
|
let resource = resource.unwrap();
|
||||||
let size = {
|
let size = {
|
||||||
let info = renderer.get_dynamic_uniform_buffer_info(resource).unwrap();
|
let info = renderer.get_dynamic_uniform_buffer_info(resource).unwrap();
|
||||||
wgpu::BIND_BUFFER_ALIGNMENT * info.count
|
BIND_BUFFER_ALIGNMENT * info.count
|
||||||
};
|
};
|
||||||
|
|
||||||
let alignment = wgpu::BIND_BUFFER_ALIGNMENT as usize;
|
let alignment = BIND_BUFFER_ALIGNMENT as usize;
|
||||||
let mut offset = 0usize;
|
let mut offset = 0usize;
|
||||||
let info = renderer
|
let info = renderer
|
||||||
.get_dynamic_uniform_buffer_info_mut(resource)
|
.get_dynamic_uniform_buffer_info_mut(resource)
|
||||||
@ -193,7 +193,7 @@ where
|
|||||||
size as usize,
|
size as usize,
|
||||||
BufferUsage::COPY_SRC,
|
BufferUsage::COPY_SRC,
|
||||||
&mut |mapped| {
|
&mut |mapped| {
|
||||||
let alignment = wgpu::BIND_BUFFER_ALIGNMENT as usize;
|
let alignment = BIND_BUFFER_ALIGNMENT as usize;
|
||||||
let mut offset = 0usize;
|
let mut offset = 0usize;
|
||||||
for (entity, (uniforms, _renderable)) in query.iter_entities(world) {
|
for (entity, (uniforms, _renderable)) in query.iter_entities(world) {
|
||||||
if !entities.contains(&entity) {
|
if !entities.contains(&entity) {
|
||||||
|
@ -167,6 +167,12 @@ impl WgpuRenderer {
|
|||||||
.map(|v| v.into())
|
.map(|v| v.into())
|
||||||
.collect::<Vec<OwnedWgpuVertexBufferDescriptor>>();
|
.collect::<Vec<OwnedWgpuVertexBufferDescriptor>>();
|
||||||
|
|
||||||
|
let color_states = pipeline_descriptor
|
||||||
|
.color_states
|
||||||
|
.iter()
|
||||||
|
.map(|c| c.into())
|
||||||
|
.collect::<Vec<wgpu::ColorStateDescriptor>>();
|
||||||
|
|
||||||
let mut render_pipeline_descriptor = wgpu::RenderPipelineDescriptor {
|
let mut render_pipeline_descriptor = wgpu::RenderPipelineDescriptor {
|
||||||
layout: &pipeline_layout,
|
layout: &pipeline_layout,
|
||||||
vertex_stage: wgpu::ProgrammableStageDescriptor {
|
vertex_stage: wgpu::ProgrammableStageDescriptor {
|
||||||
@ -180,11 +186,17 @@ impl WgpuRenderer {
|
|||||||
}),
|
}),
|
||||||
None => None,
|
None => None,
|
||||||
},
|
},
|
||||||
rasterization_state: pipeline_descriptor.rasterization_state.clone(),
|
rasterization_state: pipeline_descriptor
|
||||||
primitive_topology: pipeline_descriptor.primitive_topology,
|
.rasterization_state
|
||||||
color_states: &pipeline_descriptor.color_states,
|
.as_ref()
|
||||||
depth_stencil_state: pipeline_descriptor.depth_stencil_state.clone(),
|
.map(|r| r.into()),
|
||||||
index_format: pipeline_descriptor.index_format,
|
primitive_topology: pipeline_descriptor.primitive_topology.into(),
|
||||||
|
color_states: &color_states,
|
||||||
|
depth_stencil_state: pipeline_descriptor
|
||||||
|
.depth_stencil_state
|
||||||
|
.as_ref()
|
||||||
|
.map(|d| d.into()),
|
||||||
|
index_format: pipeline_descriptor.index_format.into(),
|
||||||
vertex_buffers: &owned_vertex_buffer_descriptors
|
vertex_buffers: &owned_vertex_buffer_descriptors
|
||||||
.iter()
|
.iter()
|
||||||
.map(|v| v.into())
|
.map(|v| v.into())
|
||||||
|
@ -2,7 +2,7 @@ use crate::{
|
|||||||
legion::prelude::*,
|
legion::prelude::*,
|
||||||
render::{
|
render::{
|
||||||
pipeline::{BindGroup, BindType},
|
pipeline::{BindGroup, BindType},
|
||||||
render_resource::{RenderResource, RenderResources, ResourceInfo},
|
render_resource::{BufferUsage, RenderResource, RenderResources, ResourceInfo},
|
||||||
shader::DynamicUniformBufferInfo,
|
shader::DynamicUniformBufferInfo,
|
||||||
texture::{SamplerDescriptor, TextureDescriptor},
|
texture::{SamplerDescriptor, TextureDescriptor},
|
||||||
},
|
},
|
||||||
@ -72,7 +72,7 @@ impl WgpuResources {
|
|||||||
let resource = self.create_buffer(
|
let resource = self.create_buffer(
|
||||||
device,
|
device,
|
||||||
size,
|
size,
|
||||||
wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST,
|
BufferUsage::UNIFORM | BufferUsage::COPY_DST,
|
||||||
);
|
);
|
||||||
|
|
||||||
self.render_resources
|
self.render_resources
|
||||||
@ -216,11 +216,11 @@ impl WgpuResources {
|
|||||||
&mut self,
|
&mut self,
|
||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
size: u64,
|
size: u64,
|
||||||
buffer_usage: wgpu::BufferUsage,
|
buffer_usage: BufferUsage,
|
||||||
) -> RenderResource {
|
) -> RenderResource {
|
||||||
let buffer = device.create_buffer(&wgpu::BufferDescriptor {
|
let buffer = device.create_buffer(&wgpu::BufferDescriptor {
|
||||||
size,
|
size,
|
||||||
usage: buffer_usage,
|
usage: buffer_usage.into(),
|
||||||
});
|
});
|
||||||
|
|
||||||
let resource = self.render_resources.get_next_resource();
|
let resource = self.render_resources.get_next_resource();
|
||||||
@ -234,10 +234,10 @@ impl WgpuResources {
|
|||||||
&mut self,
|
&mut self,
|
||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
buffer_usage: wgpu::BufferUsage,
|
buffer_usage: BufferUsage,
|
||||||
) -> RenderResource {
|
) -> RenderResource {
|
||||||
let resource = self.render_resources.get_next_resource();
|
let resource = self.render_resources.get_next_resource();
|
||||||
let buffer = device.create_buffer_with_data(data, buffer_usage);
|
let buffer = device.create_buffer_with_data(data, buffer_usage.into());
|
||||||
self.add_resource_info(
|
self.add_resource_info(
|
||||||
resource,
|
resource,
|
||||||
ResourceInfo::Buffer {
|
ResourceInfo::Buffer {
|
||||||
@ -256,11 +256,11 @@ impl WgpuResources {
|
|||||||
mesh_id: usize,
|
mesh_id: usize,
|
||||||
size: usize,
|
size: usize,
|
||||||
count: usize,
|
count: usize,
|
||||||
buffer_usage: wgpu::BufferUsage,
|
buffer_usage: BufferUsage,
|
||||||
) -> RenderResource {
|
) -> RenderResource {
|
||||||
let buffer = device.create_buffer(&wgpu::BufferDescriptor {
|
let buffer = device.create_buffer(&wgpu::BufferDescriptor {
|
||||||
size: (size * count) as u64,
|
size: (size * count) as u64,
|
||||||
usage: buffer_usage,
|
usage: buffer_usage.into(),
|
||||||
});
|
});
|
||||||
|
|
||||||
let resource = self.render_resources.get_next_resource();
|
let resource = self.render_resources.get_next_resource();
|
||||||
@ -285,9 +285,9 @@ impl WgpuResources {
|
|||||||
data: &[u8],
|
data: &[u8],
|
||||||
size: usize,
|
size: usize,
|
||||||
count: usize,
|
count: usize,
|
||||||
buffer_usage: wgpu::BufferUsage,
|
buffer_usage: BufferUsage,
|
||||||
) -> RenderResource {
|
) -> RenderResource {
|
||||||
let buffer = device.create_buffer_with_data(data, buffer_usage);
|
let buffer = device.create_buffer_with_data(data, buffer_usage.into());
|
||||||
let resource = self.render_resources.get_next_resource();
|
let resource = self.render_resources.get_next_resource();
|
||||||
|
|
||||||
self.add_resource_info(
|
self.add_resource_info(
|
||||||
@ -317,10 +317,10 @@ impl WgpuResources {
|
|||||||
&mut self,
|
&mut self,
|
||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
size: usize,
|
size: usize,
|
||||||
buffer_usage: wgpu::BufferUsage,
|
buffer_usage: BufferUsage,
|
||||||
setup_data: &mut dyn FnMut(&mut [u8]),
|
setup_data: &mut dyn FnMut(&mut [u8]),
|
||||||
) -> RenderResource {
|
) -> RenderResource {
|
||||||
let mut mapped = device.create_buffer_mapped(size, buffer_usage);
|
let mut mapped = device.create_buffer_mapped(size, buffer_usage.into());
|
||||||
setup_data(&mut mapped.data);
|
setup_data(&mut mapped.data);
|
||||||
let buffer = mapped.finish();
|
let buffer = mapped.finish();
|
||||||
|
|
||||||
|
@ -3,9 +3,20 @@ use crate::{
|
|||||||
render::{
|
render::{
|
||||||
pass::{LoadOp, StoreOp},
|
pass::{LoadOp, StoreOp},
|
||||||
pipeline::{
|
pipeline::{
|
||||||
InputStepMode, VertexAttributeDescriptor, VertexBufferDescriptor, VertexFormat, BindType
|
state_descriptors::{
|
||||||
|
BlendDescriptor, BlendFactor, BlendOperation, ColorStateDescriptor, ColorWrite,
|
||||||
|
CompareFunction, CullMode, DepthStencilStateDescriptor, FrontFace, IndexFormat,
|
||||||
|
PrimitiveTopology, RasterizationStateDescriptor, StencilOperation,
|
||||||
|
StencilStateFaceDescriptor,
|
||||||
|
},
|
||||||
|
BindType, InputStepMode, VertexAttributeDescriptor, VertexBufferDescriptor,
|
||||||
|
VertexFormat,
|
||||||
},
|
},
|
||||||
render_resource::BufferUsage,
|
render_resource::BufferUsage,
|
||||||
|
texture::{
|
||||||
|
AddressMode, Extent3d, SamplerDescriptor, TextureDescriptor, TextureDimension,
|
||||||
|
TextureFormat, TextureUsage, TextureViewDimension, FilterMode,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -157,3 +168,308 @@ impl From<&BindType> for wgpu::BindingType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Extent3d> for wgpu::Extent3d {
|
||||||
|
fn from(val: Extent3d) -> Self {
|
||||||
|
wgpu::Extent3d {
|
||||||
|
depth: val.depth,
|
||||||
|
height: val.height,
|
||||||
|
width: val.width,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<TextureDescriptor> for wgpu::TextureDescriptor {
|
||||||
|
fn from(texture_descriptor: TextureDescriptor) -> Self {
|
||||||
|
wgpu::TextureDescriptor {
|
||||||
|
size: texture_descriptor.size.into(),
|
||||||
|
array_layer_count: texture_descriptor.array_layer_count,
|
||||||
|
mip_level_count: texture_descriptor.mip_level_count,
|
||||||
|
sample_count: texture_descriptor.sample_count,
|
||||||
|
dimension: texture_descriptor.dimension.into(),
|
||||||
|
format: texture_descriptor.format.into(),
|
||||||
|
usage: texture_descriptor.usage.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<TextureViewDimension> for wgpu::TextureViewDimension {
|
||||||
|
fn from(dimension: TextureViewDimension) -> Self {
|
||||||
|
match dimension {
|
||||||
|
TextureViewDimension::D1 => wgpu::TextureViewDimension::D1,
|
||||||
|
TextureViewDimension::D2 => wgpu::TextureViewDimension::D2,
|
||||||
|
TextureViewDimension::D2Array => wgpu::TextureViewDimension::D2Array,
|
||||||
|
TextureViewDimension::Cube => wgpu::TextureViewDimension::Cube,
|
||||||
|
TextureViewDimension::CubeArray => wgpu::TextureViewDimension::CubeArray,
|
||||||
|
TextureViewDimension::D3 => wgpu::TextureViewDimension::D3,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<TextureDimension> for wgpu::TextureDimension {
|
||||||
|
fn from(dimension: TextureDimension) -> Self {
|
||||||
|
match dimension {
|
||||||
|
TextureDimension::D1 => wgpu::TextureDimension::D1,
|
||||||
|
TextureDimension::D2 => wgpu::TextureDimension::D2,
|
||||||
|
TextureDimension::D3 => wgpu::TextureDimension::D3,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<TextureFormat> for wgpu::TextureFormat {
|
||||||
|
fn from(val: TextureFormat) -> Self {
|
||||||
|
match val {
|
||||||
|
TextureFormat::R8Unorm => wgpu::TextureFormat::R8Unorm,
|
||||||
|
TextureFormat::R8Snorm => wgpu::TextureFormat::R8Snorm,
|
||||||
|
TextureFormat::R8Uint => wgpu::TextureFormat::R8Uint,
|
||||||
|
TextureFormat::R8Sint => wgpu::TextureFormat::R8Sint,
|
||||||
|
TextureFormat::R16Unorm => wgpu::TextureFormat::R16Unorm,
|
||||||
|
TextureFormat::R16Snorm => wgpu::TextureFormat::R16Snorm,
|
||||||
|
TextureFormat::R16Uint => wgpu::TextureFormat::R16Uint,
|
||||||
|
TextureFormat::R16Sint => wgpu::TextureFormat::R16Sint,
|
||||||
|
TextureFormat::R16Float => wgpu::TextureFormat::R16Float,
|
||||||
|
TextureFormat::Rg8Unorm => wgpu::TextureFormat::Rg8Unorm,
|
||||||
|
TextureFormat::Rg8Snorm => wgpu::TextureFormat::Rg8Snorm,
|
||||||
|
TextureFormat::Rg8Uint => wgpu::TextureFormat::Rg8Uint,
|
||||||
|
TextureFormat::Rg8Sint => wgpu::TextureFormat::Rg8Sint,
|
||||||
|
TextureFormat::R32Uint => wgpu::TextureFormat::R32Uint,
|
||||||
|
TextureFormat::R32Sint => wgpu::TextureFormat::R32Sint,
|
||||||
|
TextureFormat::R32Float => wgpu::TextureFormat::R32Float,
|
||||||
|
TextureFormat::Rg16Unorm => wgpu::TextureFormat::Rg16Unorm,
|
||||||
|
TextureFormat::Rg16Snorm => wgpu::TextureFormat::Rg16Snorm,
|
||||||
|
TextureFormat::Rg16Uint => wgpu::TextureFormat::Rg16Uint,
|
||||||
|
TextureFormat::Rg16Sint => wgpu::TextureFormat::Rg16Sint,
|
||||||
|
TextureFormat::Rg16Float => wgpu::TextureFormat::Rg16Float,
|
||||||
|
TextureFormat::Rgba8Unorm => wgpu::TextureFormat::Rgba8Unorm,
|
||||||
|
TextureFormat::Rgba8UnormSrgb => wgpu::TextureFormat::Rgba8UnormSrgb,
|
||||||
|
TextureFormat::Rgba8Snorm => wgpu::TextureFormat::Rgba8Snorm,
|
||||||
|
TextureFormat::Rgba8Uint => wgpu::TextureFormat::Rgba8Uint,
|
||||||
|
TextureFormat::Rgba8Sint => wgpu::TextureFormat::Rgba8Sint,
|
||||||
|
TextureFormat::Bgra8Unorm => wgpu::TextureFormat::Bgra8Unorm,
|
||||||
|
TextureFormat::Bgra8UnormSrgb => wgpu::TextureFormat::Bgra8UnormSrgb,
|
||||||
|
TextureFormat::Rgb10a2Unorm => wgpu::TextureFormat::Rgb10a2Unorm,
|
||||||
|
TextureFormat::Rg11b10Float => wgpu::TextureFormat::Rg11b10Float,
|
||||||
|
TextureFormat::Rg32Uint => wgpu::TextureFormat::Rg32Uint,
|
||||||
|
TextureFormat::Rg32Sint => wgpu::TextureFormat::Rg32Sint,
|
||||||
|
TextureFormat::Rg32Float => wgpu::TextureFormat::Rg32Float,
|
||||||
|
TextureFormat::Rgba16Unorm => wgpu::TextureFormat::Rgba16Unorm,
|
||||||
|
TextureFormat::Rgba16Snorm => wgpu::TextureFormat::Rgba16Snorm,
|
||||||
|
TextureFormat::Rgba16Uint => wgpu::TextureFormat::Rgba16Uint,
|
||||||
|
TextureFormat::Rgba16Sint => wgpu::TextureFormat::Rgba16Sint,
|
||||||
|
TextureFormat::Rgba16Float => wgpu::TextureFormat::Rgba16Float,
|
||||||
|
TextureFormat::Rgba32Uint => wgpu::TextureFormat::Rgba32Uint,
|
||||||
|
TextureFormat::Rgba32Sint => wgpu::TextureFormat::Rgba32Sint,
|
||||||
|
TextureFormat::Rgba32Float => wgpu::TextureFormat::Rgba32Float,
|
||||||
|
TextureFormat::Depth32Float => wgpu::TextureFormat::Depth32Float,
|
||||||
|
TextureFormat::Depth24Plus => wgpu::TextureFormat::Depth24Plus,
|
||||||
|
TextureFormat::Depth24PlusStencil8 => wgpu::TextureFormat::Depth24PlusStencil8,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<TextureUsage> for wgpu::TextureUsage {
|
||||||
|
fn from(val: TextureUsage) -> Self {
|
||||||
|
wgpu::TextureUsage::from_bits(val.bits()).unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&DepthStencilStateDescriptor> for wgpu::DepthStencilStateDescriptor {
|
||||||
|
fn from(val: &DepthStencilStateDescriptor) -> Self {
|
||||||
|
wgpu::DepthStencilStateDescriptor {
|
||||||
|
depth_compare: val.depth_compare.into(),
|
||||||
|
depth_write_enabled: val.depth_write_enabled,
|
||||||
|
format: val.format.into(),
|
||||||
|
stencil_back: (&val.stencil_back).into(),
|
||||||
|
stencil_front: (&val.stencil_front).into(),
|
||||||
|
stencil_read_mask: val.stencil_read_mask,
|
||||||
|
stencil_write_mask: val.stencil_write_mask,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&StencilStateFaceDescriptor> for wgpu::StencilStateFaceDescriptor {
|
||||||
|
fn from(val: &StencilStateFaceDescriptor) -> Self {
|
||||||
|
wgpu::StencilStateFaceDescriptor {
|
||||||
|
compare: val.compare.into(),
|
||||||
|
depth_fail_op: val.depth_fail_op.into(),
|
||||||
|
fail_op: val.fail_op.into(),
|
||||||
|
pass_op: val.pass_op.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<CompareFunction> for wgpu::CompareFunction {
|
||||||
|
fn from(val: CompareFunction) -> Self {
|
||||||
|
match val {
|
||||||
|
CompareFunction::Never => wgpu::CompareFunction::Never,
|
||||||
|
CompareFunction::Less => wgpu::CompareFunction::Less,
|
||||||
|
CompareFunction::Equal => wgpu::CompareFunction::Equal,
|
||||||
|
CompareFunction::LessEqual => wgpu::CompareFunction::LessEqual,
|
||||||
|
CompareFunction::Greater => wgpu::CompareFunction::Greater,
|
||||||
|
CompareFunction::NotEqual => wgpu::CompareFunction::NotEqual,
|
||||||
|
CompareFunction::GreaterEqual => wgpu::CompareFunction::GreaterEqual,
|
||||||
|
CompareFunction::Always => wgpu::CompareFunction::Always,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<StencilOperation> for wgpu::StencilOperation {
|
||||||
|
fn from(val: StencilOperation) -> Self {
|
||||||
|
match val {
|
||||||
|
StencilOperation::Keep => wgpu::StencilOperation::Keep,
|
||||||
|
StencilOperation::Zero => wgpu::StencilOperation::Zero,
|
||||||
|
StencilOperation::Replace => wgpu::StencilOperation::Replace,
|
||||||
|
StencilOperation::Invert => wgpu::StencilOperation::Invert,
|
||||||
|
StencilOperation::IncrementClamp => wgpu::StencilOperation::IncrementClamp,
|
||||||
|
StencilOperation::DecrementClamp => wgpu::StencilOperation::DecrementClamp,
|
||||||
|
StencilOperation::IncrementWrap => wgpu::StencilOperation::IncrementWrap,
|
||||||
|
StencilOperation::DecrementWrap => wgpu::StencilOperation::DecrementWrap,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<PrimitiveTopology> for wgpu::PrimitiveTopology {
|
||||||
|
fn from(val: PrimitiveTopology) -> Self {
|
||||||
|
match val {
|
||||||
|
PrimitiveTopology::PointList => wgpu::PrimitiveTopology::PointList,
|
||||||
|
PrimitiveTopology::LineList => wgpu::PrimitiveTopology::LineList,
|
||||||
|
PrimitiveTopology::LineStrip => wgpu::PrimitiveTopology::LineStrip,
|
||||||
|
PrimitiveTopology::TriangleList => wgpu::PrimitiveTopology::TriangleList,
|
||||||
|
PrimitiveTopology::TriangleStrip => wgpu::PrimitiveTopology::TriangleStrip,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<FrontFace> for wgpu::FrontFace {
|
||||||
|
fn from(val: FrontFace) -> Self {
|
||||||
|
match val {
|
||||||
|
FrontFace::Ccw => wgpu::FrontFace::Ccw,
|
||||||
|
FrontFace::Cw => wgpu::FrontFace::Cw,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<CullMode> for wgpu::CullMode {
|
||||||
|
fn from(val: CullMode) -> Self {
|
||||||
|
match val {
|
||||||
|
CullMode::None => wgpu::CullMode::None,
|
||||||
|
CullMode::Front => wgpu::CullMode::Front,
|
||||||
|
CullMode::Back => wgpu::CullMode::Back,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&RasterizationStateDescriptor> for wgpu::RasterizationStateDescriptor {
|
||||||
|
fn from(val: &RasterizationStateDescriptor) -> Self {
|
||||||
|
wgpu::RasterizationStateDescriptor {
|
||||||
|
front_face: val.front_face.into(),
|
||||||
|
cull_mode: val.cull_mode.into(),
|
||||||
|
depth_bias: val.depth_bias,
|
||||||
|
depth_bias_slope_scale: val.depth_bias_slope_scale,
|
||||||
|
depth_bias_clamp: val.depth_bias_clamp,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&ColorStateDescriptor> for wgpu::ColorStateDescriptor {
|
||||||
|
fn from(val: &ColorStateDescriptor) -> Self {
|
||||||
|
wgpu::ColorStateDescriptor {
|
||||||
|
format: val.format.into(),
|
||||||
|
alpha_blend: (&val.alpha_blend).into(),
|
||||||
|
color_blend: (&val.color_blend).into(),
|
||||||
|
write_mask: val.write_mask.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ColorWrite> for wgpu::ColorWrite {
|
||||||
|
fn from(val: ColorWrite) -> Self {
|
||||||
|
wgpu::ColorWrite::from_bits(val.bits()).unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&BlendDescriptor> for wgpu::BlendDescriptor {
|
||||||
|
fn from(val: &BlendDescriptor) -> Self {
|
||||||
|
wgpu::BlendDescriptor {
|
||||||
|
src_factor: val.src_factor.into(),
|
||||||
|
dst_factor: val.dst_factor.into(),
|
||||||
|
operation: val.operation.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<BlendFactor> for wgpu::BlendFactor {
|
||||||
|
fn from(val: BlendFactor) -> Self {
|
||||||
|
match val {
|
||||||
|
BlendFactor::Zero => wgpu::BlendFactor::Zero,
|
||||||
|
BlendFactor::One => wgpu::BlendFactor::One,
|
||||||
|
BlendFactor::SrcColor => wgpu::BlendFactor::SrcColor,
|
||||||
|
BlendFactor::OneMinusSrcColor => wgpu::BlendFactor::OneMinusSrcColor,
|
||||||
|
BlendFactor::SrcAlpha => wgpu::BlendFactor::SrcAlpha,
|
||||||
|
BlendFactor::OneMinusSrcAlpha => wgpu::BlendFactor::OneMinusSrcAlpha,
|
||||||
|
BlendFactor::DstColor => wgpu::BlendFactor::DstColor,
|
||||||
|
BlendFactor::OneMinusDstColor => wgpu::BlendFactor::OneMinusDstColor,
|
||||||
|
BlendFactor::DstAlpha => wgpu::BlendFactor::DstAlpha,
|
||||||
|
BlendFactor::OneMinusDstAlpha => wgpu::BlendFactor::OneMinusDstAlpha,
|
||||||
|
BlendFactor::SrcAlphaSaturated => wgpu::BlendFactor::SrcAlphaSaturated,
|
||||||
|
BlendFactor::BlendColor => wgpu::BlendFactor::BlendColor,
|
||||||
|
BlendFactor::OneMinusBlendColor => wgpu::BlendFactor::OneMinusBlendColor,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<BlendOperation> for wgpu::BlendOperation {
|
||||||
|
fn from(val: BlendOperation) -> Self {
|
||||||
|
match val {
|
||||||
|
BlendOperation::Add => wgpu::BlendOperation::Add,
|
||||||
|
BlendOperation::Subtract => wgpu::BlendOperation::Subtract,
|
||||||
|
BlendOperation::ReverseSubtract => wgpu::BlendOperation::ReverseSubtract,
|
||||||
|
BlendOperation::Min => wgpu::BlendOperation::Min,
|
||||||
|
BlendOperation::Max => wgpu::BlendOperation::Max,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<IndexFormat> for wgpu::IndexFormat {
|
||||||
|
fn from(val: IndexFormat) -> Self {
|
||||||
|
match val {
|
||||||
|
IndexFormat::Uint16 => wgpu::IndexFormat::Uint16,
|
||||||
|
IndexFormat::Uint32 => wgpu::IndexFormat::Uint32,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<SamplerDescriptor> for wgpu::SamplerDescriptor {
|
||||||
|
fn from(sampler_descriptor: SamplerDescriptor) -> Self {
|
||||||
|
wgpu::SamplerDescriptor {
|
||||||
|
address_mode_u: sampler_descriptor.address_mode_u.into(),
|
||||||
|
address_mode_v: sampler_descriptor.address_mode_v.into(),
|
||||||
|
address_mode_w: sampler_descriptor.address_mode_w.into(),
|
||||||
|
mag_filter: sampler_descriptor.mag_filter.into(),
|
||||||
|
min_filter: sampler_descriptor.min_filter.into(),
|
||||||
|
mipmap_filter: sampler_descriptor.mipmap_filter.into(),
|
||||||
|
lod_min_clamp: sampler_descriptor.lod_min_clamp,
|
||||||
|
lod_max_clamp: sampler_descriptor.lod_max_clamp,
|
||||||
|
compare_function: sampler_descriptor.compare_function.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<AddressMode> for wgpu::AddressMode {
|
||||||
|
fn from(val: AddressMode) -> Self {
|
||||||
|
match val {
|
||||||
|
AddressMode::ClampToEdge => wgpu::AddressMode::ClampToEdge,
|
||||||
|
AddressMode::Repeat => wgpu::AddressMode::Repeat,
|
||||||
|
AddressMode::MirrorRepeat => wgpu::AddressMode::MirrorRepeat,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<FilterMode> for wgpu::FilterMode {
|
||||||
|
fn from(val: FilterMode) -> Self {
|
||||||
|
match val {
|
||||||
|
FilterMode::Nearest => wgpu::FilterMode::Nearest,
|
||||||
|
FilterMode::Linear => wgpu::FilterMode::Linear,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,46 +1,55 @@
|
|||||||
use crate::asset::Texture;
|
use crate::{asset::Texture, render::pipeline::state_descriptors::CompareFunction};
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct SamplerDescriptor {
|
pub struct SamplerDescriptor {
|
||||||
pub address_mode_u: wgpu::AddressMode,
|
pub address_mode_u: AddressMode,
|
||||||
pub address_mode_v: wgpu::AddressMode,
|
pub address_mode_v: AddressMode,
|
||||||
pub address_mode_w: wgpu::AddressMode,
|
pub address_mode_w: AddressMode,
|
||||||
pub mag_filter: wgpu::FilterMode,
|
pub mag_filter: FilterMode,
|
||||||
pub min_filter: wgpu::FilterMode,
|
pub min_filter: FilterMode,
|
||||||
pub mipmap_filter: wgpu::FilterMode,
|
pub mipmap_filter: FilterMode,
|
||||||
pub lod_min_clamp: f32,
|
pub lod_min_clamp: f32,
|
||||||
pub lod_max_clamp: f32,
|
pub lod_max_clamp: f32,
|
||||||
pub compare_function: wgpu::CompareFunction,
|
pub compare_function: CompareFunction,
|
||||||
}
|
|
||||||
|
|
||||||
impl From<SamplerDescriptor> for wgpu::SamplerDescriptor {
|
|
||||||
fn from(sampler_descriptor: SamplerDescriptor) -> Self {
|
|
||||||
wgpu::SamplerDescriptor {
|
|
||||||
address_mode_u: sampler_descriptor.address_mode_u,
|
|
||||||
address_mode_v: sampler_descriptor.address_mode_v,
|
|
||||||
address_mode_w: sampler_descriptor.address_mode_w,
|
|
||||||
mag_filter: sampler_descriptor.mag_filter,
|
|
||||||
min_filter: sampler_descriptor.min_filter,
|
|
||||||
mipmap_filter: sampler_descriptor.mipmap_filter,
|
|
||||||
lod_min_clamp: sampler_descriptor.lod_min_clamp,
|
|
||||||
lod_max_clamp: sampler_descriptor.lod_max_clamp,
|
|
||||||
compare_function: sampler_descriptor.compare_function,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&Texture> for SamplerDescriptor {
|
impl From<&Texture> for SamplerDescriptor {
|
||||||
fn from(_texture: &Texture) -> Self {
|
fn from(_texture: &Texture) -> Self {
|
||||||
SamplerDescriptor {
|
SamplerDescriptor {
|
||||||
address_mode_u: wgpu::AddressMode::ClampToEdge,
|
address_mode_u: AddressMode::ClampToEdge,
|
||||||
address_mode_v: wgpu::AddressMode::ClampToEdge,
|
address_mode_v: AddressMode::ClampToEdge,
|
||||||
address_mode_w: wgpu::AddressMode::ClampToEdge,
|
address_mode_w: AddressMode::ClampToEdge,
|
||||||
mag_filter: wgpu::FilterMode::Nearest,
|
mag_filter: FilterMode::Nearest,
|
||||||
min_filter: wgpu::FilterMode::Linear,
|
min_filter: FilterMode::Linear,
|
||||||
mipmap_filter: wgpu::FilterMode::Nearest,
|
mipmap_filter: FilterMode::Nearest,
|
||||||
lod_min_clamp: -100.0,
|
lod_min_clamp: -100.0,
|
||||||
lod_max_clamp: 100.0,
|
lod_max_clamp: 100.0,
|
||||||
compare_function: wgpu::CompareFunction::Always,
|
compare_function: CompareFunction::Always,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||||
|
pub enum AddressMode {
|
||||||
|
ClampToEdge = 0,
|
||||||
|
Repeat = 1,
|
||||||
|
MirrorRepeat = 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for AddressMode {
|
||||||
|
fn default() -> Self {
|
||||||
|
AddressMode::ClampToEdge
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||||
|
pub enum FilterMode {
|
||||||
|
Nearest = 0,
|
||||||
|
Linear = 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for FilterMode {
|
||||||
|
fn default() -> Self {
|
||||||
|
FilterMode::Nearest
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
use super::TextureDimension;
|
use super::{Extent3d, TextureDimension, TextureFormat};
|
||||||
use crate::asset::Texture;
|
use crate::{asset::Texture, render::texture::TextureUsage};
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct TextureDescriptor {
|
pub struct TextureDescriptor {
|
||||||
pub size: wgpu::Extent3d,
|
pub size: Extent3d,
|
||||||
pub array_layer_count: u32,
|
pub array_layer_count: u32,
|
||||||
pub mip_level_count: u32,
|
pub mip_level_count: u32,
|
||||||
pub sample_count: u32,
|
pub sample_count: u32,
|
||||||
pub dimension: TextureDimension,
|
pub dimension: TextureDimension,
|
||||||
pub format: wgpu::TextureFormat,
|
pub format: TextureFormat,
|
||||||
pub usage: wgpu::TextureUsage,
|
pub usage: TextureUsage,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&Texture> for TextureDescriptor {
|
impl From<&Texture> for TextureDescriptor {
|
||||||
fn from(texture: &Texture) -> Self {
|
fn from(texture: &Texture) -> Self {
|
||||||
TextureDescriptor {
|
TextureDescriptor {
|
||||||
size: wgpu::Extent3d {
|
size: Extent3d {
|
||||||
height: texture.height as u32,
|
height: texture.height as u32,
|
||||||
width: texture.width as u32,
|
width: texture.width as u32,
|
||||||
depth: 1,
|
depth: 1,
|
||||||
@ -24,22 +24,8 @@ impl From<&Texture> for TextureDescriptor {
|
|||||||
mip_level_count: 1,
|
mip_level_count: 1,
|
||||||
sample_count: 1,
|
sample_count: 1,
|
||||||
dimension: TextureDimension::D2,
|
dimension: TextureDimension::D2,
|
||||||
format: wgpu::TextureFormat::Rgba8UnormSrgb,
|
format: TextureFormat::Rgba8UnormSrgb,
|
||||||
usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::COPY_DST,
|
usage: TextureUsage::SAMPLED | TextureUsage::COPY_DST,
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<TextureDescriptor> for wgpu::TextureDescriptor {
|
|
||||||
fn from(texture_descriptor: TextureDescriptor) -> Self {
|
|
||||||
wgpu::TextureDescriptor {
|
|
||||||
size: texture_descriptor.size,
|
|
||||||
array_layer_count: texture_descriptor.array_layer_count,
|
|
||||||
mip_level_count: texture_descriptor.mip_level_count,
|
|
||||||
sample_count: texture_descriptor.sample_count,
|
|
||||||
dimension: texture_descriptor.dimension.into(),
|
|
||||||
format: texture_descriptor.format,
|
|
||||||
usage: texture_descriptor.usage,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
// NOTE: These are currently just copies of the wgpu types, but they might change in the future
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
|
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
|
||||||
pub enum TextureViewDimension {
|
pub enum TextureViewDimension {
|
||||||
D1,
|
D1,
|
||||||
@ -8,18 +10,6 @@ pub enum TextureViewDimension {
|
|||||||
D3,
|
D3,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<TextureViewDimension> for wgpu::TextureViewDimension {
|
|
||||||
fn from(dimension: TextureViewDimension) -> Self {
|
|
||||||
match dimension {
|
|
||||||
TextureViewDimension::D1 => wgpu::TextureViewDimension::D1,
|
|
||||||
TextureViewDimension::D2 => wgpu::TextureViewDimension::D2,
|
|
||||||
TextureViewDimension::D2Array => wgpu::TextureViewDimension::D2Array,
|
|
||||||
TextureViewDimension::Cube => wgpu::TextureViewDimension::Cube,
|
|
||||||
TextureViewDimension::CubeArray => wgpu::TextureViewDimension::CubeArray,
|
|
||||||
TextureViewDimension::D3 => wgpu::TextureViewDimension::D3,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Hash)]
|
#[derive(Copy, Clone, Debug, Hash)]
|
||||||
pub enum TextureDimension {
|
pub enum TextureDimension {
|
||||||
@ -28,12 +18,92 @@ pub enum TextureDimension {
|
|||||||
D3,
|
D3,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<TextureDimension> for wgpu::TextureDimension {
|
#[derive(Clone, Copy, Debug)]
|
||||||
fn from(dimension: TextureDimension) -> Self {
|
pub struct Extent3d {
|
||||||
match dimension {
|
pub width: u32,
|
||||||
TextureDimension::D1 => wgpu::TextureDimension::D1,
|
pub height: u32,
|
||||||
TextureDimension::D2 => wgpu::TextureDimension::D2,
|
pub depth: u32,
|
||||||
TextureDimension::D3 => wgpu::TextureDimension::D3,
|
}
|
||||||
}
|
|
||||||
|
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||||
|
pub enum TextureFormat {
|
||||||
|
// Normal 8 bit formats
|
||||||
|
R8Unorm = 0,
|
||||||
|
R8Snorm = 1,
|
||||||
|
R8Uint = 2,
|
||||||
|
R8Sint = 3,
|
||||||
|
|
||||||
|
// Normal 16 bit formats
|
||||||
|
R16Unorm = 4,
|
||||||
|
R16Snorm = 5,
|
||||||
|
R16Uint = 6,
|
||||||
|
R16Sint = 7,
|
||||||
|
R16Float = 8,
|
||||||
|
|
||||||
|
Rg8Unorm = 9,
|
||||||
|
Rg8Snorm = 10,
|
||||||
|
Rg8Uint = 11,
|
||||||
|
Rg8Sint = 12,
|
||||||
|
|
||||||
|
// Normal 32 bit formats
|
||||||
|
R32Uint = 13,
|
||||||
|
R32Sint = 14,
|
||||||
|
R32Float = 15,
|
||||||
|
Rg16Unorm = 16,
|
||||||
|
Rg16Snorm = 17,
|
||||||
|
Rg16Uint = 18,
|
||||||
|
Rg16Sint = 19,
|
||||||
|
Rg16Float = 20,
|
||||||
|
Rgba8Unorm = 21,
|
||||||
|
Rgba8UnormSrgb = 22,
|
||||||
|
Rgba8Snorm = 23,
|
||||||
|
Rgba8Uint = 24,
|
||||||
|
Rgba8Sint = 25,
|
||||||
|
Bgra8Unorm = 26,
|
||||||
|
Bgra8UnormSrgb = 27,
|
||||||
|
|
||||||
|
// Packed 32 bit formats
|
||||||
|
Rgb10a2Unorm = 28,
|
||||||
|
Rg11b10Float = 29,
|
||||||
|
|
||||||
|
// Normal 64 bit formats
|
||||||
|
Rg32Uint = 30,
|
||||||
|
Rg32Sint = 31,
|
||||||
|
Rg32Float = 32,
|
||||||
|
Rgba16Unorm = 33,
|
||||||
|
Rgba16Snorm = 34,
|
||||||
|
Rgba16Uint = 35,
|
||||||
|
Rgba16Sint = 36,
|
||||||
|
Rgba16Float = 37,
|
||||||
|
|
||||||
|
// Normal 128 bit formats
|
||||||
|
Rgba32Uint = 38,
|
||||||
|
Rgba32Sint = 39,
|
||||||
|
Rgba32Float = 40,
|
||||||
|
|
||||||
|
// Depth and stencil formats
|
||||||
|
Depth32Float = 41,
|
||||||
|
Depth24Plus = 42,
|
||||||
|
Depth24PlusStencil8 = 43,
|
||||||
|
}
|
||||||
|
|
||||||
|
bitflags::bitflags! {
|
||||||
|
#[repr(transparent)]
|
||||||
|
pub struct TextureUsage: u32 {
|
||||||
|
const COPY_SRC = 1;
|
||||||
|
const COPY_DST = 2;
|
||||||
|
const SAMPLED = 4;
|
||||||
|
const STORAGE = 8;
|
||||||
|
const OUTPUT_ATTACHMENT = 16;
|
||||||
|
const NONE = 0;
|
||||||
|
/// The combination of all read-only usages.
|
||||||
|
const READ_ALL = Self::COPY_SRC.bits | Self::SAMPLED.bits;
|
||||||
|
/// The combination of all write-only and read-write usages.
|
||||||
|
const WRITE_ALL = Self::COPY_DST.bits | Self::STORAGE.bits | Self::OUTPUT_ATTACHMENT.bits;
|
||||||
|
/// The combination of all usages that the are guaranteed to be be ordered by the hardware.
|
||||||
|
/// If a usage is not ordered, then even if it doesn't change between draw calls, there
|
||||||
|
/// still need to be pipeline barriers inserted for synchronization.
|
||||||
|
const ORDERED = Self::READ_ALL.bits | Self::OUTPUT_ATTACHMENT.bits;
|
||||||
|
const UNINITIALIZED = 0xFFFF;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user