ported all pipelines

This commit is contained in:
Capucho 2020-08-24 22:17:40 +01:00 committed by Imbris
parent 9370ffad33
commit 5f9c5b83d7
14 changed files with 606 additions and 478 deletions

View File

@ -41,13 +41,8 @@ common-state = {package = "veloren-common-state", path = "../common/state"}
anim = {package = "veloren-voxygen-anim", path = "anim"} anim = {package = "veloren-voxygen-anim", path = "anim"}
# Graphics # Graphics
gfx = "0.18.2"
gfx_device_gl = {version = "0.16.2", optional = true}
gfx_gl = {version = "0.6.1", optional = true}
glutin = "0.26.0"
old_school_gfx_glutin_ext = "0.26"
winit = {version = "0.24.0", features = ["serde"]} winit = {version = "0.24.0", features = ["serde"]}
wgpu = "0.6.0" wgpu = {git="https://github.com/gfx-rs/wgpu-rs.git"}
zerocopy = "0.3.0" zerocopy = "0.3.0"
# Ui # Ui

View File

@ -15,34 +15,25 @@ pub use self::{
error::RenderError, error::RenderError,
instances::Instances, instances::Instances,
mesh::{Mesh, Quad, Tri}, mesh::{Mesh, Quad, Tri},
model::{DynamicModel, Model}, model::{Model, SubModel},
pipelines::{ pipelines::{
clouds::{create_mesh as create_clouds_mesh, CloudsPipeline, Locals as CloudsLocals}, clouds::{create_mesh as create_clouds_mesh, Locals as CloudsLocals},
figure::{ figure::{BoneData as FigureBoneData, BoneMeshes, FigureModel, Locals as FigureLocals},
BoneData as FigureBoneData, BoneMeshes, FigureModel, FigurePipeline, lod_terrain::LodData,
Locals as FigureLocals, particle::Instance as ParticleInstance,
}, postprocess::create_mesh as create_pp_mesh,
fluid::FluidPipeline, shadow::Locals as ShadowLocals,
lod_terrain::{Locals as LodTerrainLocals, LodData, LodTerrainPipeline}, skybox::create_mesh as create_skybox_mesh,
particle::{Instance as ParticleInstance, ParticlePipeline}, sprite::{Instance as SpriteInstance, Locals as SpriteLocals},
postprocess::{ terrain::Locals as TerrainLocals,
create_mesh as create_pp_mesh, Locals as PostProcessLocals, PostProcessPipeline,
},
shadow::{Locals as ShadowLocals, ShadowPipeline},
skybox::{create_mesh as create_skybox_mesh, Locals as SkyboxLocals, SkyboxPipeline},
sprite::{Instance as SpriteInstance, Locals as SpriteLocals, SpritePipeline},
terrain::{Locals as TerrainLocals, TerrainPipeline},
ui::{ ui::{
create_quad as create_ui_quad, create_quad as create_ui_quad,
create_quad_vert_gradient as create_ui_quad_vert_gradient, create_tri as create_ui_tri, create_quad_vert_gradient as create_ui_quad_vert_gradient, create_tri as create_ui_tri,
Locals as UiLocals, Mode as UiMode, UiPipeline, Locals as UiLocals, Mode as UiMode,
}, },
GlobalModel, Globals, Light, Shadow, GlobalModel, Globals, Light, Shadow,
}, },
renderer::{ renderer::{ColLightInfo, Renderer},
ColLightFmt, ColLightInfo, LodAltFmt, LodColorFmt, LodTextureFmt, Renderer,
ShadowDepthStencilFmt, TgtColorFmt, TgtDepthStencilFmt, WinColorFmt, WinDepthFmt,
},
texture::Texture, texture::Texture,
}; };
pub use wgpu::{AddressMode, FilterMode}; pub use wgpu::{AddressMode, FilterMode};

View File

@ -1,4 +1,7 @@
use super::super::{Mesh, Model, TerrainPipeline}; use super::{
super::{Mesh, Model},
terrain::Vertex,
};
use crate::mesh::greedy::GreedyMesh; use crate::mesh::greedy::GreedyMesh;
use vek::*; use vek::*;
use zerocopy::AsBytes; use zerocopy::AsBytes;
@ -119,7 +122,7 @@ impl FigureLayout {
} }
pub struct FigureModel { pub struct FigureModel {
pub opaque: Model<TerrainPipeline>, pub opaque: Model<Vertex>,
/* TODO: Consider using mipmaps instead of storing multiple texture atlases for different /* TODO: Consider using mipmaps instead of storing multiple texture atlases for different
* LOD levels. */ * LOD levels. */
} }
@ -136,7 +139,7 @@ impl FigureModel {
} }
} }
pub type BoneMeshes = (Mesh<TerrainPipeline>, anim::vek::Aabb<f32>); pub type BoneMeshes = (Mesh<Vertex>, anim::vek::Aabb<f32>);
//gfx_defines! { //gfx_defines! {
// constant Locals { // constant Locals {

View File

@ -1,13 +1,6 @@
use super::super::TerrainLocals;
use vek::*; use vek::*;
use zerocopy::AsBytes; use zerocopy::AsBytes;
#[repr(C)]
#[derive(Copy, Clone, Debug, AsBytes)]
struct Vertex {
pos_norm: u32,
}
// gfx_defines! { // gfx_defines! {
// vertex Vertex { // vertex Vertex {
// pos_norm: u32 = "v_pos_norm", // pos_norm: u32 = "v_pos_norm",
@ -43,6 +36,12 @@ struct Vertex {
// (StencilOp::Keep,StencilOp::Keep,StencilOp::Keep))), } // (StencilOp::Keep,StencilOp::Keep,StencilOp::Keep))), }
// } // }
#[repr(C)]
#[derive(Copy, Clone, Debug, AsBytes)]
pub struct Vertex {
pos_norm: u32,
}
impl Vertex { impl Vertex {
#[allow(clippy::identity_op)] // TODO: Pending review in #587 #[allow(clippy::identity_op)] // TODO: Pending review in #587
#[allow(clippy::into_iter_on_ref)] // TODO: Pending review in #587 #[allow(clippy::into_iter_on_ref)] // TODO: Pending review in #587

View File

@ -1,19 +1,7 @@
use super::{ use super::super::{Renderer, Texture};
super::{
LodAltFmt, LodColorFmt, LodTextureFmt, Pipeline, Renderer, Texture, TgtColorFmt,
TgtDepthStencilFmt,
},
Globals,
};
use vek::*; use vek::*;
use zerocopy::AsBytes; use zerocopy::AsBytes;
#[repr(C)]
#[derive(Copy, Clone, Debug, AsBytes)]
struct Vertex {
pos: [f32; 2],
}
// gfx_defines! { // gfx_defines! {
// vertex Vertex { // vertex Vertex {
// pos: [f32; 2] = "v_pos", // pos: [f32; 2] = "v_pos",
@ -42,6 +30,12 @@ struct Vertex {
// (StencilOp::Keep,StencilOp::Keep,StencilOp::Keep))), } // (StencilOp::Keep,StencilOp::Keep,StencilOp::Keep))), }
// } // }
#[repr(C)]
#[derive(Copy, Clone, Debug, AsBytes)]
pub struct Vertex {
pos: [f32; 2],
}
impl Vertex { impl Vertex {
pub fn new(pos: Vec2<f32>) -> Self { pub fn new(pos: Vec2<f32>) -> Self {
Self { Self {
@ -51,9 +45,9 @@ impl Vertex {
} }
pub struct LodData { pub struct LodData {
pub map: Texture<LodColorFmt>, pub map: Texture,
pub alt: Texture<LodAltFmt>, pub alt: Texture,
pub horizon: Texture<LodTextureFmt>, pub horizon: Texture,
pub tgt_detail: u32, pub tgt_detail: u32,
} }
@ -65,48 +59,100 @@ impl LodData {
lod_alt: &[u32], lod_alt: &[u32],
lod_horizon: &[u32], lod_horizon: &[u32],
tgt_detail: u32, tgt_detail: u32,
border_color: gfx::texture::PackedColor, //border_color: gfx::texture::PackedColor,
) -> Self { ) -> Self {
let kind = gfx::texture::Kind::D2(map_size.x, map_size.y, gfx::texture::AaMode::Single); let mut texture_info = wgpu::TextureDescriptor {
let info = gfx::texture::SamplerInfo::new( label: None,
gfx::texture::FilterMethod::Bilinear, size: wgpu::Extent3d {
gfx::texture::WrapMode::Border, width: map_size.x,
height: map_size.y,
depth: 1,
},
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8UnormSrgb,
usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::COPY_DST,
};
let sampler_info = wgpu::SamplerDescriptor {
label: None,
address_mode_u: wgpu::AddressMode::ClampToEdge,
address_mode_v: wgpu::AddressMode::ClampToEdge,
address_mode_w: wgpu::AddressMode::ClampToEdge,
mag_filter: wgpu::FilterMode::Linear,
min_filter: wgpu::FilterMode::Linear,
mipmap_filter: wgpu::FilterMode::Nearest,
border_color: Some(wgpu::SamplerBorderColor::TransparentBlack),
..Default::default()
};
let map = renderer.create_texture_with_data_raw(
&texture_info,
&sampler_info,
map_size.x * 4,
[map_size.x, map_size.y],
lod_base.as_bytes(),
); );
texture_info = wgpu::TextureFormat::Rg16Uint;
let alt = renderer.create_texture_with_data_raw(
&texture_info,
&sampler_info,
map_size.x * 4,
[map_size.x, map_size.y],
lod_base.as_bytes(),
);
texture_info = wgpu::TextureFormat::Rgba8Unorm;
let horizon = renderer.create_texture_with_data_raw(
&texture_info,
&sampler_info,
map_size.x * 4,
[map_size.x, map_size.y],
lod_base.as_bytes(),
);
Self { Self {
map: renderer map,
.create_texture_immutable_raw( alt,
kind, horizon,
gfx::texture::Mipmap::Provided,
&[gfx::memory::cast_slice(lod_base)],
SamplerInfo {
border: border_color,
..info
},
)
.expect("Failed to generate map texture"),
alt: renderer
.create_texture_immutable_raw(
kind,
gfx::texture::Mipmap::Provided,
&[gfx::memory::cast_slice(lod_alt)],
SamplerInfo {
border: [0.0, 0.0, 0.0, 0.0].into(),
..info
},
)
.expect("Failed to generate alt texture"),
horizon: renderer
.create_texture_immutable_raw(
kind,
gfx::texture::Mipmap::Provided,
&[gfx::memory::cast_slice(lod_horizon)],
SamplerInfo {
border: [1.0, 0.0, 1.0, 0.0].into(),
..info
},
)
.expect("Failed to generate horizon texture"),
tgt_detail, tgt_detail,
} }
// Self {
// map: renderer
// .create_texture_immutable_raw(
// kind,
// gfx::texture::Mipmap::Provided,
// &[gfx::memory::cast_slice(lod_base)],
// SamplerInfo {
// border: border_color,
// ..info
// },
// )
// .expect("Failed to generate map texture"),
// alt: renderer
// .create_texture_immutable_raw(
// kind,
// gfx::texture::Mipmap::Provided,
// &[gfx::memory::cast_slice(lod_alt)],
// SamplerInfo {
// border: [0.0, 0.0, 0.0, 0.0].into(),
// ..info
// },
// )
// .expect("Failed to generate alt texture"),
// horizon: renderer
// .create_texture_immutable_raw(
// kind,
// gfx::texture::Mipmap::Provided,
// &[gfx::memory::cast_slice(lod_horizon)],
// SamplerInfo {
// border: [1.0, 0.0, 1.0, 0.0].into(),
// ..info
// },
// )
// .expect("Failed to generate horizon texture"),
// tgt_detail,
// }
} }
} }

View File

@ -1,79 +1,87 @@
use super::{
super::{Pipeline, TgtColorFmt, TgtDepthStencilFmt},
shadow, Globals, Light, Shadow,
};
use gfx::{
self, gfx_defines, gfx_impl_struct_meta, gfx_pipeline, gfx_pipeline_inner,
gfx_vertex_struct_meta, state::ColorMask,
};
use vek::*; use vek::*;
use zerocopy::AsBytes;
gfx_defines! { // gfx_defines! {
vertex Vertex { // vertex Vertex {
pos: [f32; 3] = "v_pos", // pos: [f32; 3] = "v_pos",
// ____BBBBBBBBGGGGGGGGRRRRRRRR // // ____BBBBBBBBGGGGGGGGRRRRRRRR
// col: u32 = "v_col", // // col: u32 = "v_col",
// ...AANNN // // ...AANNN
// A = AO // // A = AO
// N = Normal // // N = Normal
norm_ao: u32 = "v_norm_ao", // norm_ao: u32 = "v_norm_ao",
} // }
//
// vertex Instance {
// // created_at time, so we can calculate time relativity, needed for
// relative animation. // can save 32 bits per instance, for particles
// that are not relatively animated. inst_time: f32 = "inst_time",
//
// // The lifespan in seconds of the particle
// inst_lifespan: f32 = "inst_lifespan",
//
// // a seed value for randomness
// // can save 32 bits per instance, for particles that don't need
// randomness/uniqueness. inst_entropy: f32 = "inst_entropy",
//
// // modes should probably be seperate shaders, as a part of scaling
// and optimisation efforts. // can save 32 bits per instance, and have
// cleaner tailor made code. inst_mode: i32 = "inst_mode",
//
// // A direction for particles to move in
// inst_dir: [f32; 3] = "inst_dir",
//
// // a triangle is: f32 x 3 x 3 x 1 = 288 bits
// // a quad is: f32 x 3 x 3 x 2 = 576 bits
// // a cube is: f32 x 3 x 3 x 12 = 3456 bits
// // this vec is: f32 x 3 x 1 x 1 = 96 bits (per instance!)
// // consider using a throw-away mesh and
// // positioning the vertex vertices instead,
// // if we have:
// // - a triangle mesh, and 3 or more instances.
// // - a quad mesh, and 6 or more instances.
// // - a cube mesh, and 36 or more instances.
// inst_pos: [f32; 3] = "inst_pos",
// }
//
// pipeline pipe {
// vbuf: gfx::VertexBuffer<Vertex> = (),
// ibuf: gfx::InstanceBuffer<Instance> = (),
//
// globals: gfx::ConstantBuffer<Globals> = "u_globals",
// lights: gfx::ConstantBuffer<Light> = "u_lights",
// shadows: gfx::ConstantBuffer<Shadow> = "u_shadows",
//
// point_shadow_maps: gfx::TextureSampler<f32> = "t_point_shadow_maps",
// directed_shadow_maps: gfx::TextureSampler<f32> =
// "t_directed_shadow_maps",
//
// alt: gfx::TextureSampler<[f32; 2]> = "t_alt",
// horizon: gfx::TextureSampler<[f32; 4]> = "t_horizon",
//
// noise: gfx::TextureSampler<f32> = "t_noise",
//
// // Shadow stuff
// light_shadows: gfx::ConstantBuffer<shadow::Locals> =
// "u_light_shadows",
//
// tgt_color: gfx::BlendTarget<TgtColorFmt> = ("tgt_color",
// ColorMask::all(), gfx::preset::blend::ALPHA), tgt_depth_stencil:
// gfx::DepthTarget<TgtDepthStencilFmt> = gfx::preset::depth::LESS_EQUAL_WRITE,
// // tgt_depth_stencil: gfx::DepthStencilTarget<TgtDepthStencilFmt> =
// (gfx::preset::depth::LESS_EQUAL_WRITE,Stencil::new(Comparison::Always,0xff,
// (StencilOp::Keep,StencilOp::Keep,StencilOp::Keep))), }
vertex Instance { #[repr(C)]
// created_at time, so we can calculate time relativity, needed for relative animation. #[derive(Copy, Clone, Debug, AsBytes)]
// can save 32 bits per instance, for particles that are not relatively animated. pub struct Vertex {
inst_time: f32 = "inst_time", pos: [f32; 3],
// ____BBBBBBBBGGGGGGGGRRRRRRRR
// The lifespan in seconds of the particle // col: u32 = "v_col",
inst_lifespan: f32 = "inst_lifespan", // ...AANNN
// A = AO
// a seed value for randomness // N = Normal
// can save 32 bits per instance, for particles that don't need randomness/uniqueness. norm_ao: u32,
inst_entropy: f32 = "inst_entropy",
// modes should probably be seperate shaders, as a part of scaling and optimisation efforts.
// can save 32 bits per instance, and have cleaner tailor made code.
inst_mode: i32 = "inst_mode",
// A direction for particles to move in
inst_dir: [f32; 3] = "inst_dir",
// a triangle is: f32 x 3 x 3 x 1 = 288 bits
// a quad is: f32 x 3 x 3 x 2 = 576 bits
// a cube is: f32 x 3 x 3 x 12 = 3456 bits
// this vec is: f32 x 3 x 1 x 1 = 96 bits (per instance!)
// consider using a throw-away mesh and
// positioning the vertex vertices instead,
// if we have:
// - a triangle mesh, and 3 or more instances.
// - a quad mesh, and 6 or more instances.
// - a cube mesh, and 36 or more instances.
inst_pos: [f32; 3] = "inst_pos",
}
pipeline pipe {
vbuf: gfx::VertexBuffer<Vertex> = (),
ibuf: gfx::InstanceBuffer<Instance> = (),
globals: gfx::ConstantBuffer<Globals> = "u_globals",
lights: gfx::ConstantBuffer<Light> = "u_lights",
shadows: gfx::ConstantBuffer<Shadow> = "u_shadows",
point_shadow_maps: gfx::TextureSampler<f32> = "t_point_shadow_maps",
directed_shadow_maps: gfx::TextureSampler<f32> = "t_directed_shadow_maps",
alt: gfx::TextureSampler<[f32; 2]> = "t_alt",
horizon: gfx::TextureSampler<[f32; 4]> = "t_horizon",
noise: gfx::TextureSampler<f32> = "t_noise",
// Shadow stuff
light_shadows: gfx::ConstantBuffer<shadow::Locals> = "u_light_shadows",
tgt_color: gfx::BlendTarget<TgtColorFmt> = ("tgt_color", ColorMask::all(), gfx::preset::blend::ALPHA),
tgt_depth_stencil: gfx::DepthTarget<TgtDepthStencilFmt> = gfx::preset::depth::LESS_EQUAL_WRITE,
// tgt_depth_stencil: gfx::DepthStencilTarget<TgtDepthStencilFmt> = (gfx::preset::depth::LESS_EQUAL_WRITE,Stencil::new(Comparison::Always,0xff,(StencilOp::Keep,StencilOp::Keep,StencilOp::Keep))),
}
} }
impl Vertex { impl Vertex {
@ -128,6 +136,40 @@ impl ParticleMode {
pub fn into_uint(self) -> u32 { self as u32 } pub fn into_uint(self) -> u32 { self as u32 }
} }
#[repr(C)]
#[derive(Copy, Clone, Debug, AsBytes)]
pub struct Instance {
// created_at time, so we can calculate time relativity, needed for relative animation.
// can save 32 bits per instance, for particles that are not relatively animated.
inst_time: f32,
// The lifespan in seconds of the particle
inst_lifespan: f32,
// a seed value for randomness
// can save 32 bits per instance, for particles that don't need randomness/uniqueness.
inst_entropy: f32,
// modes should probably be seperate shaders, as a part of scaling and optimisation efforts.
// can save 32 bits per instance, and have cleaner tailor made code.
inst_mode: i32,
// A direction for particles to move in
inst_dir: [f32; 3],
// a triangle is: f32 x 3 x 3 x 1 = 288 bits
// a quad is: f32 x 3 x 3 x 2 = 576 bits
// a cube is: f32 x 3 x 3 x 12 = 3456 bits
// this vec is: f32 x 3 x 1 x 1 = 96 bits (per instance!)
// consider using a throw-away mesh and
// positioning the vertex verticies instead,
// if we have:
// - a triangle mesh, and 3 or more instances.
// - a quad mesh, and 6 or more instances.
// - a cube mesh, and 36 or more instances.
inst_pos: [f32; 3],
}
impl Instance { impl Instance {
pub fn new( pub fn new(
inst_time: f64, inst_time: f64,
@ -168,9 +210,3 @@ impl Instance {
impl Default for Instance { impl Default for Instance {
fn default() -> Self { Self::new(0.0, 0.0, ParticleMode::CampfireSmoke, Vec3::zero()) } fn default() -> Self { Self::new(0.0, 0.0, ParticleMode::CampfireSmoke, Vec3::zero()) }
} }
pub struct ParticlePipeline;
impl Pipeline for ParticlePipeline {
type Vertex = Vertex;
}

View File

@ -1,40 +1,43 @@
use super::{ use super::super::{Mesh, Tri};
super::{Mesh, Pipeline, TgtColorFmt, TgtDepthStencilFmt, Tri, WinColorFmt},
Globals,
};
use gfx::{
self, gfx_constant_struct_meta, gfx_defines, gfx_impl_struct_meta, gfx_pipeline,
gfx_pipeline_inner, gfx_vertex_struct_meta,
};
use vek::*; use vek::*;
use zerocopy::AsBytes;
gfx_defines! { // gfx_defines! {
vertex Vertex { // vertex Vertex {
pos: [f32; 2] = "v_pos", // pos: [f32; 2] = "v_pos",
} // }
//
// constant Locals {
// proj_mat_inv: [[f32; 4]; 4] = "proj_mat_inv",
// view_mat_inv: [[f32; 4]; 4] = "view_mat_inv",
// }
//
// pipeline pipe {
// vbuf: gfx::VertexBuffer<Vertex> = (),
//
// locals: gfx::ConstantBuffer<Locals> = "u_locals",
// globals: gfx::ConstantBuffer<Globals> = "u_globals",
//
// map: gfx::TextureSampler<[f32; 4]> = "t_map",
// alt: gfx::TextureSampler<[f32; 2]> = "t_alt",
// horizon: gfx::TextureSampler<[f32; 4]> = "t_horizon",
//
// color_sampler: gfx::TextureSampler<<TgtColorFmt as
// gfx::format::Formatted>::View> = "src_color", depth_sampler:
// gfx::TextureSampler<<TgtDepthStencilFmt as gfx::format::Formatted>::View> =
// "src_depth",
//
// noise: gfx::TextureSampler<f32> = "t_noise",
//
// tgt_color: gfx::RenderTarget<WinColorFmt> = "tgt_color",
// }
// }
constant Locals { #[repr(C)]
proj_mat_inv: [[f32; 4]; 4] = "proj_mat_inv", #[derive(Copy, Clone, Debug, AsBytes)]
view_mat_inv: [[f32; 4]; 4] = "view_mat_inv", pub struct Locals {
} proj_mat_inv: [[f32; 4]; 4],
view_mat_inv: [[f32; 4]; 4],
pipeline pipe {
vbuf: gfx::VertexBuffer<Vertex> = (),
locals: gfx::ConstantBuffer<Locals> = "u_locals",
globals: gfx::ConstantBuffer<Globals> = "u_globals",
map: gfx::TextureSampler<[f32; 4]> = "t_map",
alt: gfx::TextureSampler<[f32; 2]> = "t_alt",
horizon: gfx::TextureSampler<[f32; 4]> = "t_horizon",
color_sampler: gfx::TextureSampler<<TgtColorFmt as gfx::format::Formatted>::View> = "src_color",
depth_sampler: gfx::TextureSampler<<TgtDepthStencilFmt as gfx::format::Formatted>::View> = "src_depth",
noise: gfx::TextureSampler<f32> = "t_noise",
tgt_color: gfx::RenderTarget<WinColorFmt> = "tgt_color",
}
} }
impl Default for Locals { impl Default for Locals {
@ -50,13 +53,13 @@ impl Locals {
} }
} }
pub struct PostProcessPipeline; #[repr(C)]
#[derive(Copy, Clone, Debug, AsBytes)]
impl Pipeline for PostProcessPipeline { pub struct Vertex {
type Vertex = Vertex; pub pos: [f32; 2],
} }
pub fn create_mesh() -> Mesh<PostProcessPipeline> { pub fn create_mesh() -> Mesh<Vertex> {
let mut mesh = Mesh::new(); let mut mesh = Mesh::new();
#[rustfmt::skip] #[rustfmt::skip]

View File

@ -1,54 +1,52 @@
use super::{ use super::super::{ColLightInfo, Renderer, Texture};
super::{
ColLightFmt, ColLightInfo, Pipeline, RenderError, Renderer, ShadowDepthStencilFmt,
TerrainLocals, Texture,
},
figure, terrain, Globals,
};
use gfx::{
self, gfx_constant_struct_meta, gfx_defines, gfx_impl_struct_meta, gfx_pipeline,
gfx_pipeline_inner,
};
use vek::*; use vek::*;
use zerocopy::AsBytes;
gfx_defines! { // gfx_defines! {
constant Locals { // constant Locals {
shadow_matrices: [[f32; 4]; 4] = "shadowMatrices", // shadow_matrices: [[f32; 4]; 4] = "shadowMatrices",
texture_mats: [[f32; 4]; 4] = "texture_mat", // texture_mats: [[f32; 4]; 4] = "texture_mat",
} // }
pipeline pipe { // pipeline pipe {
// Terrain vertex stuff // // Terrain vertex stuff
vbuf: gfx::VertexBuffer<terrain::Vertex> = (), // vbuf: gfx::VertexBuffer<terrain::Vertex> = (),
locals: gfx::ConstantBuffer<TerrainLocals> = "u_locals", // locals: gfx::ConstantBuffer<TerrainLocals> = "u_locals",
globals: gfx::ConstantBuffer<Globals> = "u_globals", // globals: gfx::ConstantBuffer<Globals> = "u_globals",
// Shadow stuff // // Shadow stuff
light_shadows: gfx::ConstantBuffer<Locals> = "u_light_shadows", // light_shadows: gfx::ConstantBuffer<Locals> = "u_light_shadows",
tgt_depth_stencil: gfx::DepthTarget<ShadowDepthStencilFmt> = gfx::state::Depth { // tgt_depth_stencil: gfx::DepthTarget<ShadowDepthStencilFmt> =
fun: gfx::state::Comparison::Less, // gfx::state::Depth { fun: gfx::state::Comparison::Less,
write: true, // write: true,
}, // },
} // }
pipeline figure_pipe { // pipeline figure_pipe {
// Terrain vertex stuff // // Terrain vertex stuff
vbuf: gfx::VertexBuffer<terrain::Vertex> = (), // vbuf: gfx::VertexBuffer<terrain::Vertex> = (),
locals: gfx::ConstantBuffer<figure::Locals> = "u_locals", // locals: gfx::ConstantBuffer<figure::Locals> = "u_locals",
bones: gfx::ConstantBuffer<figure::BoneData> = "u_bones", // bones: gfx::ConstantBuffer<figure::BoneData> = "u_bones",
globals: gfx::ConstantBuffer<Globals> = "u_globals", // globals: gfx::ConstantBuffer<Globals> = "u_globals",
// Shadow stuff // // Shadow stuff
light_shadows: gfx::ConstantBuffer<Locals> = "u_light_shadows", // light_shadows: gfx::ConstantBuffer<Locals> = "u_light_shadows",
tgt_depth_stencil: gfx::DepthTarget<ShadowDepthStencilFmt> = gfx::state::Depth { // tgt_depth_stencil: gfx::DepthTarget<ShadowDepthStencilFmt> =
fun: gfx::state::Comparison::Less, // gfx::state::Depth { fun: gfx::state::Comparison::Less,
write: true, // write: true,
}, // },
} // }
// }
#[repr(C)]
#[derive(Copy, Clone, Debug, AsBytes)]
pub struct Locals {
shadow_matrices: [[f32; 4]; 4],
texture_mats: [[f32; 4]; 4],
} }
impl Locals { impl Locals {
@ -62,29 +60,41 @@ impl Locals {
pub fn default() -> Self { Self::new(Mat4::identity(), Mat4::identity()) } pub fn default() -> Self { Self::new(Mat4::identity(), Mat4::identity()) }
} }
pub struct ShadowPipeline; pub fn create_col_lights(
renderer: &mut Renderer,
(col_lights, col_lights_size): &ColLightInfo,
) -> Texture {
let mut texture_info = wgpu::TextureDescriptor {
label: None,
size: wgpu::Extent3d {
width: col_lights_size.x,
height: col_lights_size.y,
depth: 1,
},
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8UnormSrgb,
usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::COPY_DST,
};
impl ShadowPipeline { let sampler_info = wgpu::SamplerDescriptor {
pub fn create_col_lights( label: None,
renderer: &mut Renderer, address_mode_u: wgpu::AddressMode::ClampToEdge,
(col_lights, col_lights_size): &ColLightInfo, address_mode_v: wgpu::AddressMode::ClampToEdge,
) -> Result<Texture<ColLightFmt>, RenderError> { address_mode_w: wgpu::AddressMode::ClampToEdge,
renderer.create_texture_immutable_raw( mag_filter: wgpu::FilterMode::Linear,
gfx::texture::Kind::D2( min_filter: wgpu::FilterMode::Linear,
col_lights_size.x, mipmap_filter: wgpu::FilterMode::Nearest,
col_lights_size.y, border_color: Some(wgpu::SamplerBorderColor::TransparentBlack),
gfx::texture::AaMode::Single, ..Default::default()
), };
gfx::texture::Mipmap::Provided,
&[col_lights],
gfx::texture::SamplerInfo::new(
gfx::texture::FilterMethod::Bilinear,
gfx::texture::WrapMode::Clamp,
),
)
}
}
impl Pipeline for ShadowPipeline { renderer.create_texture_with_data_raw(
type Vertex = terrain::Vertex; &texture_info,
&sampler_info,
col_lights_size.x * 4,
[col_lights_size.x, col_lights_size.y],
col_lights.as_bytes(),
)
} }

View File

@ -1,49 +1,41 @@
use super::{ use super::super::{Mesh, Quad};
super::{Mesh, Pipeline, Quad, TgtColorFmt, TgtDepthStencilFmt}, use zerocopy::AsBytes;
Globals,
};
use gfx::{
self, gfx_constant_struct_meta, gfx_defines, gfx_impl_struct_meta, gfx_pipeline,
gfx_pipeline_inner, gfx_vertex_struct_meta,
};
gfx_defines! { // gfx_defines! {
vertex Vertex { // vertex Vertex {
pos: [f32; 3] = "v_pos", // pos: [f32; 3] = "v_pos",
} // }
constant Locals { // constant Locals {
nul: [f32; 4] = "nul", // nul: [f32; 4] = "nul",
} // }
pipeline pipe { // pipeline pipe {
vbuf: gfx::VertexBuffer<Vertex> = (), // vbuf: gfx::VertexBuffer<Vertex> = (),
locals: gfx::ConstantBuffer<Locals> = "u_locals", // locals: gfx::ConstantBuffer<Locals> = "u_locals",
globals: gfx::ConstantBuffer<Globals> = "u_globals", // globals: gfx::ConstantBuffer<Globals> = "u_globals",
alt: gfx::TextureSampler<[f32; 2]> = "t_alt", // alt: gfx::TextureSampler<[f32; 2]> = "t_alt",
horizon: gfx::TextureSampler<[f32; 4]> = "t_horizon", // horizon: gfx::TextureSampler<[f32; 4]> = "t_horizon",
noise: gfx::TextureSampler<f32> = "t_noise", // noise: gfx::TextureSampler<f32> = "t_noise",
tgt_color: gfx::RenderTarget<TgtColorFmt> = "tgt_color", // tgt_color: gfx::RenderTarget<TgtColorFmt> = "tgt_color",
tgt_depth_stencil: gfx::DepthTarget<TgtDepthStencilFmt> = gfx::preset::depth::LESS_EQUAL_TEST, // tgt_depth_stencil: gfx::DepthTarget<TgtDepthStencilFmt> =
// tgt_depth_stencil: gfx::DepthStencilTarget<TgtDepthStencilFmt> = (gfx::preset::depth::LESS_EQUAL_WRITE,Stencil::new(Comparison::Always,0xff,(StencilOp::Keep,StencilOp::Keep,StencilOp::Keep))), // gfx::preset::depth::LESS_EQUAL_TEST, // tgt_depth_stencil:
} // gfx::DepthStencilTarget<TgtDepthStencilFmt> =
// (gfx::preset::depth::LESS_EQUAL_WRITE,Stencil::new(Comparison::Always,0xff,
// (StencilOp::Keep,StencilOp::Keep,StencilOp::Keep))), }
// }
#[repr(C)]
#[derive(Copy, Clone, Debug, AsBytes)]
pub struct Vertex {
pub pos: [f32; 3],
} }
impl Locals { pub fn create_mesh() -> Mesh<Vertex> {
pub fn default() -> Self { Self { nul: [0.0; 4] } }
}
pub struct SkyboxPipeline;
impl Pipeline for SkyboxPipeline {
type Vertex = Vertex;
}
pub fn create_mesh() -> Mesh<SkyboxPipeline> {
let mut mesh = Mesh::new(); let mut mesh = Mesh::new();
// -x // -x

View File

@ -1,75 +1,86 @@
use super::{
super::{Pipeline, TgtColorFmt, TgtDepthStencilFmt},
shadow, terrain, Globals, Light, Shadow,
};
use core::fmt; use core::fmt;
use gfx::{
self, gfx_constant_struct_meta, gfx_defines, gfx_impl_struct_meta, gfx_pipeline,
gfx_pipeline_inner, gfx_vertex_struct_meta, state::ColorMask,
};
use vek::*; use vek::*;
use zerocopy::AsBytes;
gfx_defines! { // gfx_defines! {
vertex Vertex { // vertex Vertex {
pos: [f32; 3] = "v_pos", // pos: [f32; 3] = "v_pos",
// Because we try to restrict terrain sprite data to a 128×128 block // // Because we try to restrict terrain sprite data to a 128×128 block
// we need an offset into the texture atlas. // // we need an offset into the texture atlas.
atlas_pos: u32 = "v_atlas_pos", // atlas_pos: u32 = "v_atlas_pos",
// ____BBBBBBBBGGGGGGGGRRRRRRRR // // ____BBBBBBBBGGGGGGGGRRRRRRRR
// col: u32 = "v_col", // // col: u32 = "v_col",
// ...AANNN // // ...AANNN
// A = AO // // A = AO
// N = Normal // // N = Normal
norm_ao: u32 = "v_norm_ao", // norm_ao: u32 = "v_norm_ao",
} // }
//
// constant Locals {
// // Each matrix performs rotatation, translation, and scaling,
// relative to the sprite // origin, for all sprite instances. The
// matrix will be in an array indexed by the // sprite instance's
// orientation (0 through 7). mat: [[f32; 4]; 4] = "mat",
// wind_sway: [f32; 4] = "wind_sway",
// offs: [f32; 4] = "offs",
// }
//
// vertex/*constant*/ Instance {
// // Terrain block position and orientation
// pos_ori: u32 = "inst_pos_ori",
// inst_mat0: [f32; 4] = "inst_mat0",
// inst_mat1: [f32; 4] = "inst_mat1",
// inst_mat2: [f32; 4] = "inst_mat2",
// inst_mat3: [f32; 4] = "inst_mat3",
// inst_light: [f32; 4] = "inst_light",
// inst_wind_sway: f32 = "inst_wind_sway",
// }
//
// pipeline pipe {
// vbuf: gfx::VertexBuffer<Vertex> = (),
// ibuf: gfx::InstanceBuffer<Instance> = (),
// col_lights: gfx::TextureSampler<[f32; 4]> = "t_col_light",
//
// locals: gfx::ConstantBuffer<Locals> = "u_locals",
// // A sprite instance is a cross between a sprite and a terrain chunk.
// terrain_locals: gfx::ConstantBuffer<terrain::Locals> =
// "u_terrain_locals", globals: gfx::ConstantBuffer<Globals> =
// "u_globals", lights: gfx::ConstantBuffer<Light> = "u_lights",
// shadows: gfx::ConstantBuffer<Shadow> = "u_shadows",
//
// point_shadow_maps: gfx::TextureSampler<f32> = "t_point_shadow_maps",
// directed_shadow_maps: gfx::TextureSampler<f32> =
// "t_directed_shadow_maps",
//
// alt: gfx::TextureSampler<[f32; 2]> = "t_alt",
// horizon: gfx::TextureSampler<[f32; 4]> = "t_horizon",
//
// noise: gfx::TextureSampler<f32> = "t_noise",
//
// // Shadow stuff
// light_shadows: gfx::ConstantBuffer<shadow::Locals> =
// "u_light_shadows",
//
// tgt_color: gfx::BlendTarget<TgtColorFmt> = ("tgt_color",
// ColorMask::all(), gfx::preset::blend::ALPHA), tgt_depth_stencil:
// gfx::DepthTarget<TgtDepthStencilFmt> = gfx::preset::depth::LESS_EQUAL_WRITE,
// // tgt_depth_stencil: gfx::DepthStencilTarget<TgtDepthStencilFmt> =
// (gfx::preset::depth::LESS_EQUAL_WRITE,Stencil::new(Comparison::Always,0xff,
// (StencilOp::Keep,StencilOp::Keep,StencilOp::Keep))), }
constant Locals { #[repr(C)]
// Each matrix performs rotatation, translation, and scaling, relative to the sprite #[derive(Copy, Clone, Debug, AsBytes)]
// origin, for all sprite instances. The matrix will be in an array indexed by the pub struct Vertex {
// sprite instance's orientation (0 through 7). pos: [f32; 3],
mat: [[f32; 4]; 4] = "mat", // Because we try to restrict terrain sprite data to a 128×128 block
wind_sway: [f32; 4] = "wind_sway", // we need an offset into the texture atlas.
offs: [f32; 4] = "offs", atlas_pos: u32,
} // ____BBBBBBBBGGGGGGGGRRRRRRRR
// col: u32 = "v_col",
vertex/*constant*/ Instance { // ...AANNN
// Terrain block position and orientation // A = AO
pos_ori: u32 = "inst_pos_ori", // N = Normal
inst_mat0: [f32; 4] = "inst_mat0", norm_ao: u32,
inst_mat1: [f32; 4] = "inst_mat1",
inst_mat2: [f32; 4] = "inst_mat2",
inst_mat3: [f32; 4] = "inst_mat3",
inst_light: [f32; 4] = "inst_light",
inst_wind_sway: f32 = "inst_wind_sway",
}
pipeline pipe {
vbuf: gfx::VertexBuffer<Vertex> = (),
ibuf: gfx::InstanceBuffer<Instance> = (),
col_lights: gfx::TextureSampler<[f32; 4]> = "t_col_light",
locals: gfx::ConstantBuffer<Locals> = "u_locals",
// A sprite instance is a cross between a sprite and a terrain chunk.
terrain_locals: gfx::ConstantBuffer<terrain::Locals> = "u_terrain_locals",
globals: gfx::ConstantBuffer<Globals> = "u_globals",
lights: gfx::ConstantBuffer<Light> = "u_lights",
shadows: gfx::ConstantBuffer<Shadow> = "u_shadows",
point_shadow_maps: gfx::TextureSampler<f32> = "t_point_shadow_maps",
directed_shadow_maps: gfx::TextureSampler<f32> = "t_directed_shadow_maps",
alt: gfx::TextureSampler<[f32; 2]> = "t_alt",
horizon: gfx::TextureSampler<[f32; 4]> = "t_horizon",
noise: gfx::TextureSampler<f32> = "t_noise",
// Shadow stuff
light_shadows: gfx::ConstantBuffer<shadow::Locals> = "u_light_shadows",
tgt_color: gfx::BlendTarget<TgtColorFmt> = ("tgt_color", ColorMask::all(), gfx::preset::blend::ALPHA),
tgt_depth_stencil: gfx::DepthTarget<TgtDepthStencilFmt> = gfx::preset::depth::LESS_EQUAL_WRITE,
// tgt_depth_stencil: gfx::DepthStencilTarget<TgtDepthStencilFmt> = (gfx::preset::depth::LESS_EQUAL_WRITE,Stencil::new(Comparison::Always,0xff,(StencilOp::Keep,StencilOp::Keep,StencilOp::Keep))),
}
} }
impl fmt::Display for Vertex { impl fmt::Display for Vertex {
@ -114,6 +125,18 @@ impl Vertex {
} }
} }
#[repr(C)]
#[derive(Copy, Clone, Debug, AsBytes)]
pub struct Instance {
pos_ori: u32,
inst_mat0: [f32; 4],
inst_mat1: [f32; 4],
inst_mat2: [f32; 4],
inst_mat3: [f32; 4],
inst_light: [f32; 4],
inst_wind_sway: f32,
}
impl Instance { impl Instance {
pub fn new( pub fn new(
mat: Mat4<f32>, mat: Mat4<f32>,
@ -145,6 +168,17 @@ impl Default for Instance {
fn default() -> Self { Self::new(Mat4::identity(), 0.0, Vec3::zero(), 0, 1.0, 0.0) } fn default() -> Self { Self::new(Mat4::identity(), 0.0, Vec3::zero(), 0, 1.0, 0.0) }
} }
#[repr(C)]
#[derive(Copy, Clone, Debug, AsBytes)]
pub struct Locals {
// Each matrix performs rotatation, translation, and scaling, relative to the sprite
// origin, for all sprite instances. The matrix will be in an array indexed by the
// sprite instance's orientation (0 through 7).
mat: [[f32; 4]; 4],
wind_sway: [f32; 4],
offs: [f32; 4],
}
impl Default for Locals { impl Default for Locals {
fn default() -> Self { Self::new(Mat4::identity(), Vec3::one(), Vec3::zero(), 0.0) } fn default() -> Self { Self::new(Mat4::identity(), Vec3::one(), Vec3::zero(), 0.0) }
} }
@ -158,9 +192,3 @@ impl Locals {
} }
} }
} }
pub struct SpritePipeline;
impl Pipeline for SpritePipeline {
type Vertex = Vertex;
}

View File

@ -1,49 +1,53 @@
use super::{
super::{ColLightFmt, Pipeline, TgtColorFmt, TgtDepthStencilFmt},
shadow, Globals, Light, Shadow,
};
use gfx::{
self, gfx_constant_struct_meta, gfx_defines, gfx_impl_struct_meta, gfx_pipeline,
gfx_pipeline_inner, gfx_vertex_struct_meta,
};
use vek::*; use vek::*;
use zerocopy::AsBytes;
gfx_defines! { // gfx_defines! {
vertex Vertex { // vertex Vertex {
pos_norm: u32 = "v_pos_norm", // pos_norm: u32 = "v_pos_norm",
atlas_pos: u32 = "v_atlas_pos", // atlas_pos: u32 = "v_atlas_pos",
} // }
constant Locals { // constant Locals {
model_offs: [f32; 3] = "model_offs", // model_offs: [f32; 3] = "model_offs",
load_time: f32 = "load_time", // load_time: f32 = "load_time",
atlas_offs: [i32; 4] = "atlas_offs", // atlas_offs: [i32; 4] = "atlas_offs",
} // }
pipeline pipe { // pipeline pipe {
vbuf: gfx::VertexBuffer<Vertex> = (), // vbuf: gfx::VertexBuffer<Vertex> = (),
col_lights: gfx::TextureSampler<[f32; 4]> = "t_col_light", // col_lights: gfx::TextureSampler<[f32; 4]> = "t_col_light",
locals: gfx::ConstantBuffer<Locals> = "u_locals", // locals: gfx::ConstantBuffer<Locals> = "u_locals",
globals: gfx::ConstantBuffer<Globals> = "u_globals", // globals: gfx::ConstantBuffer<Globals> = "u_globals",
lights: gfx::ConstantBuffer<Light> = "u_lights", // lights: gfx::ConstantBuffer<Light> = "u_lights",
shadows: gfx::ConstantBuffer<Shadow> = "u_shadows", // shadows: gfx::ConstantBuffer<Shadow> = "u_shadows",
point_shadow_maps: gfx::TextureSampler<f32> = "t_point_shadow_maps", // point_shadow_maps: gfx::TextureSampler<f32> = "t_point_shadow_maps",
directed_shadow_maps: gfx::TextureSampler<f32> = "t_directed_shadow_maps", // directed_shadow_maps: gfx::TextureSampler<f32> =
// "t_directed_shadow_maps",
alt: gfx::TextureSampler<[f32; 2]> = "t_alt", // alt: gfx::TextureSampler<[f32; 2]> = "t_alt",
horizon: gfx::TextureSampler<[f32; 4]> = "t_horizon", // horizon: gfx::TextureSampler<[f32; 4]> = "t_horizon",
noise: gfx::TextureSampler<f32> = "t_noise", // noise: gfx::TextureSampler<f32> = "t_noise",
// Shadow stuff // // Shadow stuff
light_shadows: gfx::ConstantBuffer<shadow::Locals> = "u_light_shadows", // light_shadows: gfx::ConstantBuffer<shadow::Locals> =
// "u_light_shadows",
tgt_color: gfx::RenderTarget<TgtColorFmt> = "tgt_color", // tgt_color: gfx::RenderTarget<TgtColorFmt> = "tgt_color",
tgt_depth_stencil: gfx::DepthTarget<TgtDepthStencilFmt> = gfx::preset::depth::LESS_EQUAL_WRITE, // tgt_depth_stencil: gfx::DepthTarget<TgtDepthStencilFmt> =
// tgt_depth_stencil: gfx::DepthStencilTarget<TgtDepthStencilFmt> = (gfx::preset::depth::LESS_EQUAL_WRITE,Stencil::new(Comparison::Always,0xff,(StencilOp::Keep,StencilOp::Keep,StencilOp::Keep))), // gfx::preset::depth::LESS_EQUAL_WRITE, // tgt_depth_stencil:
} // gfx::DepthStencilTarget<TgtDepthStencilFmt> =
// (gfx::preset::depth::LESS_EQUAL_WRITE,Stencil::new(Comparison::Always,0xff,
// (StencilOp::Keep,StencilOp::Keep,StencilOp::Keep))), }
// }
#[repr(C)]
#[derive(Copy, Clone, Debug, AsBytes)]
pub struct Vertex {
pos_norm: u32,
atlas_pos: u32,
} }
impl Vertex { impl Vertex {
@ -104,8 +108,7 @@ impl Vertex {
// 0 to 31 // 0 to 31
glow: u8, glow: u8,
col: Rgb<u8>, col: Rgb<u8>,
) -> <<ColLightFmt as gfx::format::Formatted>::Surface as gfx::format::SurfaceTyped>::DataType ) -> [u8; 4] {
{
//[col.r, col.g, col.b, light] //[col.r, col.g, col.b, light]
// It would be nice for this to be cleaner, but we want to squeeze 5 fields into // It would be nice for this to be cleaner, but we want to squeeze 5 fields into
// 4. We can do this because both `light` and `glow` go from 0 to 31, // 4. We can do this because both `light` and `glow` go from 0 to 31,
@ -141,8 +144,7 @@ impl Vertex {
glowy: bool, glowy: bool,
shiny: bool, shiny: bool,
col: Rgb<u8>, col: Rgb<u8>,
) -> <<ColLightFmt as gfx::format::Formatted>::Surface as gfx::format::SurfaceTyped>::DataType ) -> [u8; 4] {
{
let attr = 0 | ((glowy as u8) << 0) | ((shiny as u8) << 1); let attr = 0 | ((glowy as u8) << 0) | ((shiny as u8) << 1);
[ [
(light.min(31) << 3) | ((col.r >> 1) & 0b111), (light.min(31) << 3) | ((col.r >> 1) & 0b111),
@ -151,6 +153,19 @@ impl Vertex {
col.g, // Green is lucky, it remains unscathed col.g, // Green is lucky, it remains unscathed
] ]
} }
/// Set the bone_idx for an existing figure vertex.
pub fn set_bone_idx(&mut self, bone_idx: u8) {
self.pos_norm = (self.pos_norm & !(0xF << 27)) | ((bone_idx as u32 & 0xF) << 27);
}
}
#[repr(C)]
#[derive(Copy, Clone, Debug, AsBytes)]
pub struct Locals {
model_offs: [f32; 3],
load_time: f32,
atlas_offs: [i32; 4],
} }
impl Locals { impl Locals {
@ -162,9 +177,3 @@ impl Locals {
} }
} }
} }
pub struct TerrainPipeline;
impl Pipeline for TerrainPipeline {
type Vertex = Vertex;
}

View File

@ -1,41 +1,48 @@
use super::super::{Globals, Pipeline, Quad, Tri, WinColorFmt, WinDepthFmt}; use super::super::{Quad, Tri};
use gfx::{
self, gfx_constant_struct_meta, gfx_defines, gfx_impl_struct_meta, gfx_pipeline,
gfx_pipeline_inner, gfx_vertex_struct_meta,
};
use vek::*; use vek::*;
use zerocopy::AsBytes;
gfx_defines! { // gfx_defines! {
vertex Vertex { // vertex Vertex {
pos: [f32; 2] = "v_pos", // pos: [f32; 2] = "v_pos",
uv: [f32; 2] = "v_uv", // uv: [f32; 2] = "v_uv",
color: [f32; 4] = "v_color", // color: [f32; 4] = "v_color",
center: [f32; 2] = "v_center", // center: [f32; 2] = "v_center",
mode: u32 = "v_mode", // mode: u32 = "v_mode",
} // }
constant Locals { // constant Locals {
pos: [f32; 4] = "w_pos", // pos: [f32; 4] = "w_pos",
} // }
pipeline pipe { // pipeline pipe {
vbuf: gfx::VertexBuffer<Vertex> = (), // vbuf: gfx::VertexBuffer<Vertex> = (),
locals: gfx::ConstantBuffer<Locals> = "u_locals", // locals: gfx::ConstantBuffer<Locals> = "u_locals",
globals: gfx::ConstantBuffer<Globals> = "u_globals", // globals: gfx::ConstantBuffer<Globals> = "u_globals",
tex: gfx::TextureSampler<[f32; 4]> = "u_tex", // tex: gfx::TextureSampler<[f32; 4]> = "u_tex",
scissor: gfx::Scissor = (), // scissor: gfx::Scissor = (),
tgt_color: gfx::BlendTarget<WinColorFmt> = ("tgt_color", gfx::state::ColorMask::all(), gfx::preset::blend::ALPHA), // tgt_color: gfx::BlendTarget<WinColorFmt> = ("tgt_color",
tgt_depth: gfx::DepthTarget<WinDepthFmt> = gfx::preset::depth::LESS_EQUAL_TEST, // gfx::state::ColorMask::all(), gfx::preset::blend::ALPHA), tgt_depth:
} // gfx::DepthTarget<WinDepthFmt> = gfx::preset::depth::LESS_EQUAL_TEST, }
// }
#[repr(C)]
#[derive(Copy, Clone, Debug, AsBytes)]
pub struct Vertex {
pos: [f32; 2],
uv: [f32; 2],
color: [f32; 4],
center: [f32; 2],
mode: u32,
} }
pub struct UiPipeline; #[repr(C)]
#[derive(Copy, Clone, Debug, AsBytes)]
impl Pipeline for UiPipeline { pub struct Locals {
type Vertex = Vertex; pos: [f32; 4],
} }
impl From<Vec4<f32>> for Locals { impl From<Vec4<f32>> for Locals {
@ -92,7 +99,7 @@ pub fn create_quad(
uv_rect: Aabr<f32>, uv_rect: Aabr<f32>,
color: Rgba<f32>, color: Rgba<f32>,
mode: Mode, mode: Mode,
) -> Quad<UiPipeline> { ) -> Quad<Vertex> {
create_quad_vert_gradient(rect, uv_rect, color, color, mode) create_quad_vert_gradient(rect, uv_rect, color, color, mode)
} }
@ -103,7 +110,7 @@ pub fn create_quad_vert_gradient(
top_color: Rgba<f32>, top_color: Rgba<f32>,
bottom_color: Rgba<f32>, bottom_color: Rgba<f32>,
mode: Mode, mode: Mode,
) -> Quad<UiPipeline> { ) -> Quad<Vertex> {
let top_color = top_color.into_array(); let top_color = top_color.into_array();
let bottom_color = bottom_color.into_array(); let bottom_color = bottom_color.into_array();
@ -152,7 +159,7 @@ pub fn create_tri(
uv_tri: [[f32; 2]; 3], uv_tri: [[f32; 2]; 3],
color: Rgba<f32>, color: Rgba<f32>,
mode: Mode, mode: Mode,
) -> Tri<UiPipeline> { ) -> Tri<Vertex> {
let center = [0.0, 0.0]; let center = [0.0, 0.0];
let mode_val = mode.value(); let mode_val = mode.value();
let v = |pos, uv| Vertex { let v = |pos, uv| Vertex {

View File

@ -84,12 +84,9 @@ use vek::*;
// gfx_backend::Resources, // gfx_backend::Resources,
// <ColLightFmt as gfx::format::Formatted>::View, // <ColLightFmt as gfx::format::Formatted>::View,
// >; // >;
// /// A type representing data that can be converted to an immutable texture /// A type representing data that can be converted to an immutable texture map
// map /// of ColLight data (used for texture atlases created during greedy /// of ColLight data (used for texture atlases created during greedy meshing).
// meshing). pub type ColLightInfo = ( pub type ColLightInfo = (Vec<[u8; 4]>, Vec2<u16>);
// Vec<<<ColLightFmt as gfx::format::Formatted>::Surface as
// gfx::format::SurfaceTyped>::DataType>, Vec2<u16>,
// );
/// Load from a GLSL file. /// Load from a GLSL file.
pub struct Glsl(String); pub struct Glsl(String);
@ -309,7 +306,7 @@ impl Renderer {
.request_device( .request_device(
wgpu::DeviceDescriptor { wgpu::DeviceDescriptor {
// TODO // TODO
features: Features::DEPTH_CLAMPING, features: Features::DEPTH_CLAMPING | Features::ADDRESS_MODE_CLAMP_TO_BORDER,
limits: Limits::default(), limits: Limits::default(),
shader_validation: true, shader_validation: true,
}, },
@ -1034,12 +1031,18 @@ impl Renderer {
texture_info: wgpu::TextureDescriptor, texture_info: wgpu::TextureDescriptor,
sampler_info: wgpu::SamplerDescriptor, sampler_info: wgpu::SamplerDescriptor,
bytes_per_row: u32, bytes_per_row: u32,
size: [u16; 2],
data: &[u8], data: &[u8],
) -> Texture { ) -> Texture {
let tex = Texture::new_raw(&self.device, texture_info, sampler_info); let tex = Texture::new_raw(&self.device, texture_info, sampler_info);
tex.update(&self.device, &self.queue, [0; 2], size, data, bytes_per_row); tex.update(
&self.device,
&self.queue,
[0; 2],
[texture_info.size.x, texture_info.size.y],
data,
bytes_per_row,
);
tex tex
} }
@ -1054,28 +1057,34 @@ impl Renderer {
} }
/// Create a new texture from the provided image. /// Create a new texture from the provided image.
///
/// Currently only supports Rgba8Srgb
pub fn create_texture( pub fn create_texture(
&mut self, &mut self,
image: &image::DynamicImage, image: &image::DynamicImage,
filter_method: Option<FilterMode>, filter_method: Option<FilterMode>,
addresse_mode: Option<AddressMode>, address_mode: Option<AddressMode>,
) -> Texture { ) -> Texture {
Texture::new( Texture::new(
&self.device, &self.device,
&self.queue, &self.queue,
image, image,
filter_method, filter_method,
addresse_mode, address_mode,
) )
} }
/// Create a new dynamic texture (gfx::memory::Usage::Dynamic) with the /// Create a new dynamic texture with the
/// specified dimensions. /// specified dimensions.
///
/// Currently only supports Rgba8Srgb
pub fn create_dynamic_texture(&mut self, dims: Vec2<u16>) -> Texture { pub fn create_dynamic_texture(&mut self, dims: Vec2<u16>) -> Texture {
Texture::new_dynamic(&mut self.factory, dims.x, dims.y) Texture::new_dynamic(&mut self.factory, dims.x, dims.y)
} }
/// Update a texture with the provided offset, size, and data. /// Update a texture with the provided offset, size, and data.
///
/// Currently only supports Rgba8Srgb
pub fn update_texture( pub fn update_texture(
&mut self, &mut self,
texture: &Texture, /* <T> */ texture: &Texture, /* <T> */

View File

@ -15,7 +15,7 @@ impl Texture {
queue: &wgpu::Queue, queue: &wgpu::Queue,
image: &DynamicImage, image: &DynamicImage,
filter_method: Option<wgpu::FilterMode>, filter_method: Option<wgpu::FilterMode>,
addresse_mode: Option<wgpu::AddressMode>, address_mode: Option<wgpu::AddressMode>,
) -> Result<Self, RenderError> { ) -> Result<Self, RenderError> {
// TODO: Actualy handle images that aren't in rgba format properly. // TODO: Actualy handle images that aren't in rgba format properly.
let buffer = image.as_flat_samples_u8().ok_or_else(|| { let buffer = image.as_flat_samples_u8().ok_or_else(|| {
@ -64,9 +64,9 @@ impl Texture {
let sampler_info = wgpu::SamplerDescriptor { let sampler_info = wgpu::SamplerDescriptor {
label: None, label: None,
address_mode_u: addresse_mode.unwrap_or(wgpu::AddressMode::ClampToEdge), address_mode_u: address_mode.unwrap_or(wgpu::AddressMode::ClampToEdge),
address_mode_v: addresse_mode.unwrap_or(wgpu::AddressMode::ClampToEdge), address_mode_v: address_mode.unwrap_or(wgpu::AddressMode::ClampToEdge),
address_mode_w: addresse_mode.unwrap_or(wgpu::AddressMode::ClampToEdge), address_mode_w: address_mode.unwrap_or(wgpu::AddressMode::ClampToEdge),
mag_filter: filter_method.unwrap_or(wgpu::FilterMode::Nearest), mag_filter: filter_method.unwrap_or(wgpu::FilterMode::Nearest),
min_filter: filter_method.unwrap_or(wgpu::FilterMode::Nearest), min_filter: filter_method.unwrap_or(wgpu::FilterMode::Nearest),
mipmap_filter: wgpu::FilterMode::Nearest, mipmap_filter: wgpu::FilterMode::Nearest,