Added sprite pipeline

This commit is contained in:
Joshua Barretto 2019-08-19 18:01:23 +01:00
parent 08e982fa7c
commit e2082088c8
4 changed files with 91 additions and 1 deletions

View File

@ -18,6 +18,7 @@ pub use self::{
create_mesh as create_pp_mesh, Locals as PostProcessLocals, PostProcessPipeline,
},
skybox::{create_mesh as create_skybox_mesh, Locals as SkyboxLocals, SkyboxPipeline},
sprite::{Instance as SpriteInstance, SpritePipeline},
terrain::{Locals as TerrainLocals, TerrainPipeline},
ui::{
create_quad as create_ui_quad, create_tri as create_ui_tri, Locals as UiLocals,

View File

@ -2,6 +2,7 @@ pub mod figure;
pub mod fluid;
pub mod postprocess;
pub mod skybox;
pub mod sprite;
pub mod terrain;
pub mod ui;

View File

@ -0,0 +1,69 @@
use super::{
super::{Pipeline, TgtColorFmt, TgtDepthFmt},
Globals, Light,
};
use gfx::{
self,
// Macros
gfx_defines,
gfx_impl_struct_meta,
gfx_pipeline,
gfx_pipeline_inner,
gfx_vertex_struct_meta,
};
use vek::*;
gfx_defines! {
vertex Vertex {
pos: [f32; 3] = "v_pos",
norm: [f32; 3] = "v_norm",
col: [f32; 3] = "v_col",
}
vertex Instance {
inst_pos: [f32; 3] = "inst_pos",
inst_col: [f32; 4] = "inst_col",
}
pipeline pipe {
vbuf: gfx::VertexBuffer<Vertex> = (),
ibuf: gfx::InstanceBuffer<Instance> = (),
globals: gfx::ConstantBuffer<Globals> = "u_globals",
lights: gfx::ConstantBuffer<Light> = "u_lights",
tgt_color: gfx::RenderTarget<TgtColorFmt> = "tgt_color",
tgt_depth: gfx::DepthTarget<TgtDepthFmt> = gfx::preset::depth::LESS_EQUAL_WRITE,
}
}
impl Vertex {
pub fn new(pos: Vec3<f32>, norm: Vec3<f32>, col: Rgb<f32>) -> Self {
Self {
pos: pos.into_array(),
col: col.into_array(),
norm: norm.into_array(),
}
}
}
impl Instance {
pub fn new(inst_pos: Vec3<f32>, col: Rgba<f32>) -> Self {
Self {
inst_pos: inst_pos.into_array(),
inst_col: col.into_array(),
}
}
}
impl Default for Instance {
fn default() -> Self {
Self::new(Vec3::zero(), Rgba::broadcast(1.0))
}
}
pub struct SpritePipeline;
impl Pipeline for SpritePipeline {
type Vertex = Vertex;
}

View File

@ -3,7 +3,7 @@ use super::{
gfx_backend,
mesh::Mesh,
model::{DynamicModel, Model},
pipelines::{figure, fluid, postprocess, skybox, terrain, ui, Globals, Light},
pipelines::{figure, fluid, postprocess, skybox, sprite, terrain, ui, Globals, Light},
texture::Texture,
Pipeline, RenderError,
};
@ -65,6 +65,7 @@ pub struct Renderer {
figure_pipeline: GfxPipeline<figure::pipe::Init<'static>>,
terrain_pipeline: GfxPipeline<terrain::pipe::Init<'static>>,
fluid_pipeline: GfxPipeline<fluid::pipe::Init<'static>>,
sprite_pipeline: GfxPipeline<sprite::pipe::Init<'static>>,
ui_pipeline: GfxPipeline<ui::pipe::Init<'static>>,
postprocess_pipeline: GfxPipeline<postprocess::pipe::Init<'static>>,
@ -86,6 +87,7 @@ impl Renderer {
figure_pipeline,
terrain_pipeline,
fluid_pipeline,
sprite_pipeline,
ui_pipeline,
postprocess_pipeline,
) = create_pipelines(&mut factory, &mut shader_reload_indicator)?;
@ -114,6 +116,7 @@ impl Renderer {
figure_pipeline,
terrain_pipeline,
fluid_pipeline,
sprite_pipeline,
ui_pipeline,
postprocess_pipeline,
@ -201,6 +204,7 @@ impl Renderer {
figure_pipeline,
terrain_pipeline,
fluid_pipeline,
sprite_pipeline,
ui_pipeline,
postprocess_pipeline,
)) => {
@ -208,6 +212,7 @@ impl Renderer {
self.figure_pipeline = figure_pipeline;
self.terrain_pipeline = terrain_pipeline;
self.fluid_pipeline = fluid_pipeline;
self.sprite_pipeline = sprite_pipeline;
self.ui_pipeline = ui_pipeline;
self.postprocess_pipeline = postprocess_pipeline;
}
@ -495,6 +500,7 @@ fn create_pipelines(
GfxPipeline<figure::pipe::Init<'static>>,
GfxPipeline<terrain::pipe::Init<'static>>,
GfxPipeline<fluid::pipe::Init<'static>>,
GfxPipeline<sprite::pipe::Init<'static>>,
GfxPipeline<ui::pipe::Init<'static>>,
GfxPipeline<postprocess::pipe::Init<'static>>,
),
@ -571,6 +577,18 @@ fn create_pipelines(
gfx::state::CullFace::Nothing,
)?;
// Construct a pipeline for rendering sprites
let sprite_pipeline = create_pipeline(
factory,
sprite::pipe::new(),
&assets::load_watched::<String>("voxygen.shaders.sprite-vert", shader_reload_indicator)
.unwrap(),
&assets::load_watched::<String>("voxygen.shaders.sprite-frag", shader_reload_indicator)
.unwrap(),
&include_ctx,
gfx::state::CullFace::Back,
)?;
// Construct a pipeline for rendering UI elements
let ui_pipeline = create_pipeline(
factory,
@ -606,6 +624,7 @@ fn create_pipelines(
figure_pipeline,
terrain_pipeline,
fluid_pipeline,
sprite_pipeline,
ui_pipeline,
postprocess_pipeline,
))