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"}
# 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"]}
wgpu = "0.6.0"
wgpu = {git="https://github.com/gfx-rs/wgpu-rs.git"}
zerocopy = "0.3.0"
# Ui

View File

@ -15,34 +15,25 @@ pub use self::{
error::RenderError,
instances::Instances,
mesh::{Mesh, Quad, Tri},
model::{DynamicModel, Model},
model::{Model, SubModel},
pipelines::{
clouds::{create_mesh as create_clouds_mesh, CloudsPipeline, Locals as CloudsLocals},
figure::{
BoneData as FigureBoneData, BoneMeshes, FigureModel, FigurePipeline,
Locals as FigureLocals,
},
fluid::FluidPipeline,
lod_terrain::{Locals as LodTerrainLocals, LodData, LodTerrainPipeline},
particle::{Instance as ParticleInstance, ParticlePipeline},
postprocess::{
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},
clouds::{create_mesh as create_clouds_mesh, Locals as CloudsLocals},
figure::{BoneData as FigureBoneData, BoneMeshes, FigureModel, Locals as FigureLocals},
lod_terrain::LodData,
particle::Instance as ParticleInstance,
postprocess::create_mesh as create_pp_mesh,
shadow::Locals as ShadowLocals,
skybox::create_mesh as create_skybox_mesh,
sprite::{Instance as SpriteInstance, Locals as SpriteLocals},
terrain::Locals as TerrainLocals,
ui::{
create_quad as create_ui_quad,
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,
},
renderer::{
ColLightFmt, ColLightInfo, LodAltFmt, LodColorFmt, LodTextureFmt, Renderer,
ShadowDepthStencilFmt, TgtColorFmt, TgtDepthStencilFmt, WinColorFmt, WinDepthFmt,
},
renderer::{ColLightInfo, Renderer},
texture::Texture,
};
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 vek::*;
use zerocopy::AsBytes;
@ -119,7 +122,7 @@ impl FigureLayout {
}
pub struct FigureModel {
pub opaque: Model<TerrainPipeline>,
pub opaque: Model<Vertex>,
/* TODO: Consider using mipmaps instead of storing multiple texture atlases for different
* 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! {
// constant Locals {

View File

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

View File

@ -1,19 +1,7 @@
use super::{
super::{
LodAltFmt, LodColorFmt, LodTextureFmt, Pipeline, Renderer, Texture, TgtColorFmt,
TgtDepthStencilFmt,
},
Globals,
};
use super::super::{Renderer, Texture};
use vek::*;
use zerocopy::AsBytes;
#[repr(C)]
#[derive(Copy, Clone, Debug, AsBytes)]
struct Vertex {
pos: [f32; 2],
}
// gfx_defines! {
// vertex Vertex {
// pos: [f32; 2] = "v_pos",
@ -42,6 +30,12 @@ struct Vertex {
// (StencilOp::Keep,StencilOp::Keep,StencilOp::Keep))), }
// }
#[repr(C)]
#[derive(Copy, Clone, Debug, AsBytes)]
pub struct Vertex {
pos: [f32; 2],
}
impl Vertex {
pub fn new(pos: Vec2<f32>) -> Self {
Self {
@ -51,9 +45,9 @@ impl Vertex {
}
pub struct LodData {
pub map: Texture<LodColorFmt>,
pub alt: Texture<LodAltFmt>,
pub horizon: Texture<LodTextureFmt>,
pub map: Texture,
pub alt: Texture,
pub horizon: Texture,
pub tgt_detail: u32,
}
@ -65,48 +59,100 @@ impl LodData {
lod_alt: &[u32],
lod_horizon: &[u32],
tgt_detail: u32,
border_color: gfx::texture::PackedColor,
//border_color: gfx::texture::PackedColor,
) -> Self {
let kind = gfx::texture::Kind::D2(map_size.x, map_size.y, gfx::texture::AaMode::Single);
let info = gfx::texture::SamplerInfo::new(
gfx::texture::FilterMethod::Bilinear,
gfx::texture::WrapMode::Border,
let mut texture_info = wgpu::TextureDescriptor {
label: None,
size: wgpu::Extent3d {
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 {
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"),
map,
alt,
horizon,
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 zerocopy::AsBytes;
gfx_defines! {
vertex Vertex {
pos: [f32; 3] = "v_pos",
// gfx_defines! {
// vertex Vertex {
// pos: [f32; 3] = "v_pos",
// // ____BBBBBBBBGGGGGGGGRRRRRRRR
// // col: u32 = "v_col",
// // ...AANNN
// // A = AO
// // N = Normal
// 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))), }
#[repr(C)]
#[derive(Copy, Clone, Debug, AsBytes)]
pub struct Vertex {
pos: [f32; 3],
// ____BBBBBBBBGGGGGGGGRRRRRRRR
// col: u32 = "v_col",
// ...AANNN
// A = AO
// N = Normal
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))),
}
norm_ao: u32,
}
impl Vertex {
@ -128,6 +136,40 @@ impl ParticleMode {
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 {
pub fn new(
inst_time: f64,
@ -168,9 +210,3 @@ impl Instance {
impl Default for Instance {
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::{
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 super::super::{Mesh, Tri};
use vek::*;
use zerocopy::AsBytes;
gfx_defines! {
vertex Vertex {
pos: [f32; 2] = "v_pos",
}
// gfx_defines! {
// vertex Vertex {
// 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 {
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",
}
#[repr(C)]
#[derive(Copy, Clone, Debug, AsBytes)]
pub struct Locals {
proj_mat_inv: [[f32; 4]; 4],
view_mat_inv: [[f32; 4]; 4],
}
impl Default for Locals {
@ -50,13 +53,13 @@ impl Locals {
}
}
pub struct PostProcessPipeline;
impl Pipeline for PostProcessPipeline {
type Vertex = Vertex;
#[repr(C)]
#[derive(Copy, Clone, Debug, AsBytes)]
pub struct Vertex {
pub pos: [f32; 2],
}
pub fn create_mesh() -> Mesh<PostProcessPipeline> {
pub fn create_mesh() -> Mesh<Vertex> {
let mut mesh = Mesh::new();
#[rustfmt::skip]

View File

@ -1,54 +1,52 @@
use super::{
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 super::super::{ColLightInfo, Renderer, Texture};
use vek::*;
use zerocopy::AsBytes;
gfx_defines! {
constant Locals {
shadow_matrices: [[f32; 4]; 4] = "shadowMatrices",
texture_mats: [[f32; 4]; 4] = "texture_mat",
}
// gfx_defines! {
// constant Locals {
// shadow_matrices: [[f32; 4]; 4] = "shadowMatrices",
// texture_mats: [[f32; 4]; 4] = "texture_mat",
// }
pipeline pipe {
// Terrain vertex stuff
vbuf: gfx::VertexBuffer<terrain::Vertex> = (),
// pipeline pipe {
// // Terrain vertex stuff
// vbuf: gfx::VertexBuffer<terrain::Vertex> = (),
locals: gfx::ConstantBuffer<TerrainLocals> = "u_locals",
globals: gfx::ConstantBuffer<Globals> = "u_globals",
// locals: gfx::ConstantBuffer<TerrainLocals> = "u_locals",
// globals: gfx::ConstantBuffer<Globals> = "u_globals",
// Shadow stuff
light_shadows: gfx::ConstantBuffer<Locals> = "u_light_shadows",
// // Shadow stuff
// light_shadows: gfx::ConstantBuffer<Locals> = "u_light_shadows",
tgt_depth_stencil: gfx::DepthTarget<ShadowDepthStencilFmt> = gfx::state::Depth {
fun: gfx::state::Comparison::Less,
write: true,
},
}
// tgt_depth_stencil: gfx::DepthTarget<ShadowDepthStencilFmt> =
// gfx::state::Depth { fun: gfx::state::Comparison::Less,
// write: true,
// },
// }
pipeline figure_pipe {
// Terrain vertex stuff
vbuf: gfx::VertexBuffer<terrain::Vertex> = (),
// pipeline figure_pipe {
// // Terrain vertex stuff
// vbuf: gfx::VertexBuffer<terrain::Vertex> = (),
locals: gfx::ConstantBuffer<figure::Locals> = "u_locals",
bones: gfx::ConstantBuffer<figure::BoneData> = "u_bones",
globals: gfx::ConstantBuffer<Globals> = "u_globals",
// locals: gfx::ConstantBuffer<figure::Locals> = "u_locals",
// bones: gfx::ConstantBuffer<figure::BoneData> = "u_bones",
// globals: gfx::ConstantBuffer<Globals> = "u_globals",
// Shadow stuff
light_shadows: gfx::ConstantBuffer<Locals> = "u_light_shadows",
// // Shadow stuff
// light_shadows: gfx::ConstantBuffer<Locals> = "u_light_shadows",
tgt_depth_stencil: gfx::DepthTarget<ShadowDepthStencilFmt> = gfx::state::Depth {
fun: gfx::state::Comparison::Less,
write: true,
},
}
// tgt_depth_stencil: gfx::DepthTarget<ShadowDepthStencilFmt> =
// gfx::state::Depth { fun: gfx::state::Comparison::Less,
// write: true,
// },
// }
// }
#[repr(C)]
#[derive(Copy, Clone, Debug, AsBytes)]
pub struct Locals {
shadow_matrices: [[f32; 4]; 4],
texture_mats: [[f32; 4]; 4],
}
impl Locals {
@ -62,29 +60,41 @@ impl Locals {
pub fn default() -> Self { Self::new(Mat4::identity(), Mat4::identity()) }
}
pub struct ShadowPipeline;
impl ShadowPipeline {
pub fn create_col_lights(
pub fn create_col_lights(
renderer: &mut Renderer,
(col_lights, col_lights_size): &ColLightInfo,
) -> Result<Texture<ColLightFmt>, RenderError> {
renderer.create_texture_immutable_raw(
gfx::texture::Kind::D2(
col_lights_size.x,
col_lights_size.y,
gfx::texture::AaMode::Single,
),
gfx::texture::Mipmap::Provided,
&[col_lights],
gfx::texture::SamplerInfo::new(
gfx::texture::FilterMethod::Bilinear,
gfx::texture::WrapMode::Clamp,
),
)
}
}
) -> 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 Pipeline for ShadowPipeline {
type Vertex = terrain::Vertex;
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()
};
renderer.create_texture_with_data_raw(
&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::{
super::{Mesh, Pipeline, Quad, TgtColorFmt, TgtDepthStencilFmt},
Globals,
};
use gfx::{
self, gfx_constant_struct_meta, gfx_defines, gfx_impl_struct_meta, gfx_pipeline,
gfx_pipeline_inner, gfx_vertex_struct_meta,
};
use super::super::{Mesh, Quad};
use zerocopy::AsBytes;
gfx_defines! {
vertex Vertex {
pos: [f32; 3] = "v_pos",
}
// gfx_defines! {
// vertex Vertex {
// pos: [f32; 3] = "v_pos",
// }
constant Locals {
nul: [f32; 4] = "nul",
}
// constant Locals {
// nul: [f32; 4] = "nul",
// }
pipeline pipe {
vbuf: gfx::VertexBuffer<Vertex> = (),
// pipeline pipe {
// vbuf: gfx::VertexBuffer<Vertex> = (),
locals: gfx::ConstantBuffer<Locals> = "u_locals",
globals: gfx::ConstantBuffer<Globals> = "u_globals",
// locals: gfx::ConstantBuffer<Locals> = "u_locals",
// globals: gfx::ConstantBuffer<Globals> = "u_globals",
alt: gfx::TextureSampler<[f32; 2]> = "t_alt",
horizon: gfx::TextureSampler<[f32; 4]> = "t_horizon",
// alt: gfx::TextureSampler<[f32; 2]> = "t_alt",
// 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_depth_stencil: gfx::DepthTarget<TgtDepthStencilFmt> = 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))),
}
// tgt_color: gfx::RenderTarget<TgtColorFmt> = "tgt_color",
// tgt_depth_stencil: gfx::DepthTarget<TgtDepthStencilFmt> =
// 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 default() -> Self { Self { nul: [0.0; 4] } }
}
pub struct SkyboxPipeline;
impl Pipeline for SkyboxPipeline {
type Vertex = Vertex;
}
pub fn create_mesh() -> Mesh<SkyboxPipeline> {
pub fn create_mesh() -> Mesh<Vertex> {
let mut mesh = Mesh::new();
// -x

View File

@ -1,75 +1,86 @@
use super::{
super::{Pipeline, TgtColorFmt, TgtDepthStencilFmt},
shadow, terrain, Globals, Light, Shadow,
};
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 zerocopy::AsBytes;
gfx_defines! {
vertex Vertex {
pos: [f32; 3] = "v_pos",
// gfx_defines! {
// vertex Vertex {
// pos: [f32; 3] = "v_pos",
// // Because we try to restrict terrain sprite data to a 128×128 block
// // we need an offset into the texture atlas.
// atlas_pos: u32 = "v_atlas_pos",
// // ____BBBBBBBBGGGGGGGGRRRRRRRR
// // col: u32 = "v_col",
// // ...AANNN
// // A = AO
// // N = Normal
// 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))), }
#[repr(C)]
#[derive(Copy, Clone, Debug, AsBytes)]
pub struct Vertex {
pos: [f32; 3],
// Because we try to restrict terrain sprite data to a 128×128 block
// we need an offset into the texture atlas.
atlas_pos: u32 = "v_atlas_pos",
atlas_pos: u32,
// ____BBBBBBBBGGGGGGGGRRRRRRRR
// col: u32 = "v_col",
// ...AANNN
// A = AO
// N = Normal
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))),
}
norm_ao: u32,
}
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 {
pub fn new(
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) }
}
#[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 {
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 zerocopy::AsBytes;
gfx_defines! {
vertex Vertex {
pos_norm: u32 = "v_pos_norm",
atlas_pos: u32 = "v_atlas_pos",
}
// gfx_defines! {
// vertex Vertex {
// pos_norm: u32 = "v_pos_norm",
// atlas_pos: u32 = "v_atlas_pos",
// }
constant Locals {
model_offs: [f32; 3] = "model_offs",
load_time: f32 = "load_time",
atlas_offs: [i32; 4] = "atlas_offs",
}
// constant Locals {
// model_offs: [f32; 3] = "model_offs",
// load_time: f32 = "load_time",
// atlas_offs: [i32; 4] = "atlas_offs",
// }
pipeline pipe {
vbuf: gfx::VertexBuffer<Vertex> = (),
col_lights: gfx::TextureSampler<[f32; 4]> = "t_col_light",
// pipeline pipe {
// vbuf: gfx::VertexBuffer<Vertex> = (),
// col_lights: gfx::TextureSampler<[f32; 4]> = "t_col_light",
locals: gfx::ConstantBuffer<Locals> = "u_locals",
globals: gfx::ConstantBuffer<Globals> = "u_globals",
lights: gfx::ConstantBuffer<Light> = "u_lights",
shadows: gfx::ConstantBuffer<Shadow> = "u_shadows",
// locals: gfx::ConstantBuffer<Locals> = "u_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",
// 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",
// alt: gfx::TextureSampler<[f32; 2]> = "t_alt",
// horizon: gfx::TextureSampler<[f32; 4]> = "t_horizon",
noise: gfx::TextureSampler<f32> = "t_noise",
// noise: gfx::TextureSampler<f32> = "t_noise",
// Shadow stuff
light_shadows: gfx::ConstantBuffer<shadow::Locals> = "u_light_shadows",
// // Shadow stuff
// light_shadows: gfx::ConstantBuffer<shadow::Locals> =
// "u_light_shadows",
tgt_color: gfx::RenderTarget<TgtColorFmt> = "tgt_color",
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))),
}
// tgt_color: gfx::RenderTarget<TgtColorFmt> = "tgt_color",
// 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))), }
// }
#[repr(C)]
#[derive(Copy, Clone, Debug, AsBytes)]
pub struct Vertex {
pos_norm: u32,
atlas_pos: u32,
}
impl Vertex {
@ -104,8 +108,7 @@ impl Vertex {
// 0 to 31
glow: u8,
col: Rgb<u8>,
) -> <<ColLightFmt as gfx::format::Formatted>::Surface as gfx::format::SurfaceTyped>::DataType
{
) -> [u8; 4] {
//[col.r, col.g, col.b, light]
// 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,
@ -141,8 +144,7 @@ impl Vertex {
glowy: bool,
shiny: bool,
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);
[
(light.min(31) << 3) | ((col.r >> 1) & 0b111),
@ -151,6 +153,19 @@ impl Vertex {
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 {
@ -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 gfx::{
self, gfx_constant_struct_meta, gfx_defines, gfx_impl_struct_meta, gfx_pipeline,
gfx_pipeline_inner, gfx_vertex_struct_meta,
};
use super::super::{Quad, Tri};
use vek::*;
use zerocopy::AsBytes;
gfx_defines! {
vertex Vertex {
pos: [f32; 2] = "v_pos",
uv: [f32; 2] = "v_uv",
color: [f32; 4] = "v_color",
center: [f32; 2] = "v_center",
mode: u32 = "v_mode",
}
// gfx_defines! {
// vertex Vertex {
// pos: [f32; 2] = "v_pos",
// uv: [f32; 2] = "v_uv",
// color: [f32; 4] = "v_color",
// center: [f32; 2] = "v_center",
// mode: u32 = "v_mode",
// }
constant Locals {
pos: [f32; 4] = "w_pos",
}
// constant Locals {
// pos: [f32; 4] = "w_pos",
// }
pipeline pipe {
vbuf: gfx::VertexBuffer<Vertex> = (),
// pipeline pipe {
// vbuf: gfx::VertexBuffer<Vertex> = (),
locals: gfx::ConstantBuffer<Locals> = "u_locals",
globals: gfx::ConstantBuffer<Globals> = "u_globals",
tex: gfx::TextureSampler<[f32; 4]> = "u_tex",
// locals: gfx::ConstantBuffer<Locals> = "u_locals",
// globals: gfx::ConstantBuffer<Globals> = "u_globals",
// 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_depth: gfx::DepthTarget<WinDepthFmt> = gfx::preset::depth::LESS_EQUAL_TEST,
}
// tgt_color: gfx::BlendTarget<WinColorFmt> = ("tgt_color",
// 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;
impl Pipeline for UiPipeline {
type Vertex = Vertex;
#[repr(C)]
#[derive(Copy, Clone, Debug, AsBytes)]
pub struct Locals {
pos: [f32; 4],
}
impl From<Vec4<f32>> for Locals {
@ -92,7 +99,7 @@ pub fn create_quad(
uv_rect: Aabr<f32>,
color: Rgba<f32>,
mode: Mode,
) -> Quad<UiPipeline> {
) -> Quad<Vertex> {
create_quad_vert_gradient(rect, uv_rect, color, color, mode)
}
@ -103,7 +110,7 @@ pub fn create_quad_vert_gradient(
top_color: Rgba<f32>,
bottom_color: Rgba<f32>,
mode: Mode,
) -> Quad<UiPipeline> {
) -> Quad<Vertex> {
let top_color = top_color.into_array();
let bottom_color = bottom_color.into_array();
@ -152,7 +159,7 @@ pub fn create_tri(
uv_tri: [[f32; 2]; 3],
color: Rgba<f32>,
mode: Mode,
) -> Tri<UiPipeline> {
) -> Tri<Vertex> {
let center = [0.0, 0.0];
let mode_val = mode.value();
let v = |pos, uv| Vertex {

View File

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

View File

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