mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added Instances construct
This commit is contained in:
32
voxygen/src/render/instances.rs
Normal file
32
voxygen/src/render/instances.rs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
use super::{gfx_backend, RenderError};
|
||||||
|
use gfx::{
|
||||||
|
self,
|
||||||
|
buffer::Role,
|
||||||
|
memory::{Bind, Usage},
|
||||||
|
Factory,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Represents a mesh that has been sent to the GPU.
|
||||||
|
pub struct Instances<T: Copy + gfx::traits::Pod> {
|
||||||
|
pub ibuf: gfx::handle::Buffer<gfx_backend::Resources, T>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: Copy + gfx::traits::Pod> Instances<T> {
|
||||||
|
pub fn new(factory: &mut gfx_backend::Factory, len: usize) -> Result<Self, RenderError> {
|
||||||
|
Ok(Self {
|
||||||
|
ibuf: factory
|
||||||
|
.create_buffer(len, Role::Vertex, Usage::Data, Bind::TRANSFER_DST)
|
||||||
|
.map_err(|err| RenderError::BufferCreationError(err))?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update(
|
||||||
|
&mut self,
|
||||||
|
encoder: &mut gfx::Encoder<gfx_backend::Resources, gfx_backend::CommandBuffer>,
|
||||||
|
instances: &[T],
|
||||||
|
) -> Result<(), RenderError> {
|
||||||
|
encoder
|
||||||
|
.update_buffer(&self.ibuf, instances, 0)
|
||||||
|
.map_err(|err| RenderError::UpdateError(err))
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
pub mod consts;
|
pub mod consts;
|
||||||
|
pub mod instances;
|
||||||
pub mod mesh;
|
pub mod mesh;
|
||||||
pub mod model;
|
pub mod model;
|
||||||
pub mod pipelines;
|
pub mod pipelines;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use super::{
|
use super::{
|
||||||
consts::Consts,
|
consts::Consts,
|
||||||
gfx_backend,
|
gfx_backend,
|
||||||
|
instances::Instances,
|
||||||
mesh::Mesh,
|
mesh::Mesh,
|
||||||
model::{DynamicModel, Model},
|
model::{DynamicModel, Model},
|
||||||
pipelines::{figure, fluid, postprocess, skybox, sprite, terrain, ui, Globals, Light},
|
pipelines::{figure, fluid, postprocess, skybox, sprite, terrain, ui, Globals, Light},
|
||||||
@ -435,6 +436,28 @@ impl Renderer {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Queue the rendering of the provided terrain chunk model in the upcoming frame.
|
||||||
|
pub fn render_sprites(
|
||||||
|
&mut self,
|
||||||
|
model: &Model<sprite::SpritePipeline>,
|
||||||
|
globals: &Consts<Globals>,
|
||||||
|
instances: &Instances<sprite::Instance>,
|
||||||
|
lights: &Consts<Light>,
|
||||||
|
) {
|
||||||
|
self.encoder.draw(
|
||||||
|
&model.slice,
|
||||||
|
&self.sprite_pipeline.pso,
|
||||||
|
&sprite::pipe::Data {
|
||||||
|
vbuf: model.vbuf.clone(),
|
||||||
|
ibuf: instances.ibuf.clone(),
|
||||||
|
globals: globals.buf.clone(),
|
||||||
|
lights: lights.buf.clone(),
|
||||||
|
tgt_color: self.tgt_color_view.clone(),
|
||||||
|
tgt_depth: self.tgt_depth_view.clone(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// Queue the rendering of the provided UI element in the upcoming frame.
|
/// Queue the rendering of the provided UI element in the upcoming frame.
|
||||||
pub fn render_ui_element(
|
pub fn render_ui_element(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
Reference in New Issue
Block a user