mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-22 11:58:21 -06:00
wip chunk rendering
This commit is contained in:
parent
096db79b12
commit
3cfd6448cc
44
src/game.rs
44
src/game.rs
|
@ -65,12 +65,6 @@ pub fn run() {
|
|||
//=======================
|
||||
|
||||
let mut last_render = Instant::now();
|
||||
|
||||
let sampler_nearest = glium::uniforms::SamplerBehavior {
|
||||
minify_filter: MinifySamplerFilter::Nearest,
|
||||
magnify_filter: MagnifySamplerFilter::Nearest,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
event_loop.run(move |event, _, control_flow| {
|
||||
*control_flow = ControlFlow::Poll;
|
||||
|
@ -130,23 +124,27 @@ pub fn run() {
|
|||
let view = state.camera.view_matrix();
|
||||
|
||||
//Draw example triangle
|
||||
target.draw(
|
||||
&vertex_buffer,
|
||||
glium::index::NoIndices(glium::index::PrimitiveType::TrianglesList),
|
||||
&programs.chunk,
|
||||
&uniform! {
|
||||
model: [
|
||||
[1., 0., 0., 0.],
|
||||
[0., 1., 0., 0.],
|
||||
[0., 0., 1., 0.],
|
||||
[0., 0., 0., 1.0_f32]
|
||||
],
|
||||
view: view,
|
||||
perspective: perspective,
|
||||
tex: Sampler(&assets.textures.block_atlas, sampler_nearest)
|
||||
},
|
||||
&Default::default()
|
||||
).unwrap();
|
||||
|
||||
//Draw chunks
|
||||
state.world.render(&mut target, &programs, &assets, perspective, view);
|
||||
|
||||
// target.draw(
|
||||
// &vertex_buffer,
|
||||
// glium::index::NoIndices(glium::index::PrimitiveType::TrianglesList),
|
||||
// &programs.chunk,
|
||||
// &uniform! {
|
||||
// model: [
|
||||
// [1., 0., 0., 0.],
|
||||
// [0., 1., 0., 0.],
|
||||
// [0., 0., 1., 0.],
|
||||
// [0., 0., 0., 1.0_f32]
|
||||
// ],
|
||||
// view: view,
|
||||
// perspective: perspective,
|
||||
// tex: Sampler(&assets.textures.block_atlas, sampler_nearest)
|
||||
// },
|
||||
// &Default::default()
|
||||
// ).unwrap();
|
||||
|
||||
//Finish drawing
|
||||
target.finish().unwrap();
|
||||
|
|
|
@ -1,7 +1,17 @@
|
|||
use glam::{Vec2, IVec2};
|
||||
use glium::Display;
|
||||
use glium::{
|
||||
Display, Frame, Surface, uniform,
|
||||
uniforms::{
|
||||
Sampler, SamplerBehavior,
|
||||
MinifySamplerFilter, MagnifySamplerFilter,
|
||||
}
|
||||
};
|
||||
use hashbrown::HashMap;
|
||||
use crate::game::options::GameOptions;
|
||||
use crate::game::{
|
||||
options::GameOptions,
|
||||
shaders::Programs,
|
||||
assets::Assets
|
||||
};
|
||||
|
||||
mod chunk;
|
||||
mod thread;
|
||||
|
@ -33,6 +43,41 @@ impl World {
|
|||
thread: WorldThreading::new(),
|
||||
}
|
||||
}
|
||||
pub fn render(
|
||||
&self,
|
||||
target: &mut Frame,
|
||||
programs: &Programs,
|
||||
assets: &Assets,
|
||||
perspective: [[f32; 4]; 4],
|
||||
view: [[f32; 4]; 4]
|
||||
) {
|
||||
let sampler = SamplerBehavior {
|
||||
minify_filter: MinifySamplerFilter::Nearest,
|
||||
magnify_filter: MagnifySamplerFilter::Nearest,
|
||||
..Default::default()
|
||||
};
|
||||
for (&position, chunk) in &self.chunks {
|
||||
if let Some((_, vertex, index)) = &chunk.mesh {
|
||||
target.draw(
|
||||
vertex,
|
||||
index,
|
||||
&programs.chunk,
|
||||
&uniform! {
|
||||
model: [
|
||||
[1., 0., 0., 0.],
|
||||
[0., 1., 0., 0.],
|
||||
[0., 0., 1., 0.],
|
||||
[(position.x * CHUNK_SIZE as i32) as f32, 0., (position.y * CHUNK_SIZE as i32) as f32, 1.0_f32]
|
||||
],
|
||||
view: view,
|
||||
persperctive: perspective,
|
||||
tex: Sampler(&assets.textures.block_atlas, sampler)
|
||||
},
|
||||
&Default::default()
|
||||
).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn update_loaded_chunks(&mut self, around_position: Vec2, options: &GameOptions, display: &Display) {
|
||||
let render_dist = options.render_distance as i32 + 1;
|
||||
let inside_chunk = (around_position / CHUNK_SIZE as f32).as_ivec2();
|
||||
|
|
|
@ -3,7 +3,13 @@ use crate::game::world::chunk::ChunkData;
|
|||
use crate::game::shaders::chunk::Vertex as ChunkVertex;
|
||||
|
||||
pub fn generate_mesh(position: IVec2, chunk_data: ChunkData, neighbors: [ChunkData; 4]) -> (Vec<ChunkVertex>, Vec<u16>) {
|
||||
let vertex = Vec::new();
|
||||
let index = Vec::new();
|
||||
let mut vertex = Vec::new();
|
||||
let mut index = Vec::new();
|
||||
vertex.push(ChunkVertex { position: [-0.5, -0.5, 0.], uv: [0., 0.], normal: [0., 1., 0.] });
|
||||
vertex.push(ChunkVertex { position: [ 0.0, 0.5, 0.], uv: [0., 1.], normal: [0., 1., 0.] });
|
||||
vertex.push(ChunkVertex { position: [ 0.5, -0.5, 0.], uv: [1., 1.], normal: [0., 1., 0.] });
|
||||
index.push(0);
|
||||
index.push(1);
|
||||
index.push(2);
|
||||
(vertex, index)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue