add mipmaps and spcify wrap function on sampler

This commit is contained in:
griffi-gh 2023-01-22 22:31:16 +01:00
parent 5f06c85279
commit 8f1821a8f5
3 changed files with 10 additions and 6 deletions

View file

@ -1,5 +1,5 @@
use shipyard::{World, NonSendSync, UniqueView, Unique}; use shipyard::{World, NonSendSync, UniqueView, Unique};
use glium::{texture::SrgbTexture2dArray, Program}; use glium::{texture::{SrgbTexture2dArray, MipmapsOption}, Program};
use strum::EnumIter; use strum::EnumIter;
use crate::rendering::Renderer; use crate::rendering::Renderer;
@ -61,7 +61,8 @@ pub fn load_prefabs(world: &World) {
world.add_unique_non_send_sync(BlockTexturesPrefab( world.add_unique_non_send_sync(BlockTexturesPrefab(
load_texture2darray_prefab::<BlockTextures, _>( load_texture2darray_prefab::<BlockTextures, _>(
"./assets/blocks/".into(), "./assets/blocks/".into(),
&renderer.display &renderer.display,
MipmapsOption::AutoGeneratedMipmaps
) )
)); ));
world.add_unique_non_send_sync(ChunkShaderPrefab( world.add_unique_non_send_sync(ChunkShaderPrefab(

View file

@ -1,7 +1,7 @@
use strum::IntoEnumIterator; use strum::IntoEnumIterator;
use rayon::prelude::*; use rayon::prelude::*;
use std::{fs::File, path::PathBuf, io::BufReader}; use std::{fs::File, path::PathBuf, io::BufReader};
use glium::{texture::{SrgbTexture2dArray, RawImage2d}, backend::Facade}; use glium::{texture::{SrgbTexture2dArray, RawImage2d, MipmapsOption}, backend::Facade};
use super::AssetPaths; use super::AssetPaths;
pub fn load_texture2darray_prefab< pub fn load_texture2darray_prefab<
@ -9,7 +9,8 @@ pub fn load_texture2darray_prefab<
E: Facade E: Facade
>( >(
directory: PathBuf, directory: PathBuf,
facade: &E facade: &E,
mipmaps: MipmapsOption,
) -> SrgbTexture2dArray { ) -> SrgbTexture2dArray {
log::info!("↓↓↓ loading textures {} ↓↓↓", directory.as_os_str().to_str().unwrap()); log::info!("↓↓↓ loading textures {} ↓↓↓", directory.as_os_str().to_str().unwrap());
//Load raw images //Load raw images
@ -38,6 +39,6 @@ pub fn load_texture2darray_prefab<
}).collect(); }).collect();
log::info!("done loading texture files, uploading to the gpu"); log::info!("done loading texture files, uploading to the gpu");
//Upload images to the GPU //Upload images to the GPU
SrgbTexture2dArray::new(facade, raw_images) SrgbTexture2dArray::with_mipmaps(facade, raw_images, mipmaps)
.expect("Failed to upload texture array to GPU") .expect("Failed to upload texture array to GPU")
} }

View file

@ -6,7 +6,8 @@ use glium::{
Sampler, Sampler,
SamplerBehavior, SamplerBehavior,
MinifySamplerFilter, MinifySamplerFilter,
MagnifySamplerFilter MagnifySamplerFilter,
SamplerWrapFunction
}, },
draw_parameters::{ draw_parameters::{
Depth, Depth,
@ -89,6 +90,7 @@ pub fn draw_world(
minify_filter: MinifySamplerFilter::Linear, minify_filter: MinifySamplerFilter::Linear,
magnify_filter: MagnifySamplerFilter::Nearest, magnify_filter: MagnifySamplerFilter::Nearest,
max_anisotropy: 8, max_anisotropy: 8,
wrap_function: (SamplerWrapFunction::Clamp, SamplerWrapFunction::Clamp, SamplerWrapFunction::Clamp),
..Default::default() ..Default::default()
}); });
let view = camera.view_matrix.to_cols_array_2d(); let view = camera.view_matrix.to_cols_array_2d();