From aa111d34e54cee28af4bb44485c8da94a7ce5cff Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sun, 17 Nov 2019 22:41:00 +0000 Subject: [PATCH] Added clouds --- assets/voxygen/shaders/figure-frag.glsl | 2 +- assets/voxygen/shaders/fluid-frag.glsl | 6 +- assets/voxygen/shaders/include/sky.glsl | 101 ++++++++++++++++++++--- assets/voxygen/shaders/skybox-frag.glsl | 2 +- assets/voxygen/shaders/sprite-frag.glsl | 2 +- assets/voxygen/shaders/terrain-frag.glsl | 2 +- assets/voxygen/texture/noise.png | 3 + voxygen/src/render/pipelines/figure.rs | 2 + voxygen/src/render/pipelines/fluid.rs | 1 + voxygen/src/render/pipelines/skybox.rs | 2 + voxygen/src/render/pipelines/sprite.rs | 2 + voxygen/src/render/pipelines/terrain.rs | 2 + voxygen/src/render/renderer.rs | 33 +++++--- voxygen/src/render/texture.rs | 44 +++++----- voxygen/src/scene/terrain.rs | 2 +- voxygen/src/ui/cache.rs | 6 +- voxygen/src/ui/graphic/mod.rs | 13 +-- 17 files changed, 161 insertions(+), 64 deletions(-) create mode 100644 assets/voxygen/texture/noise.png diff --git a/assets/voxygen/shaders/figure-frag.glsl b/assets/voxygen/shaders/figure-frag.glsl index 06156e2cf2..88d757817e 100644 --- a/assets/voxygen/shaders/figure-frag.glsl +++ b/assets/voxygen/shaders/figure-frag.glsl @@ -39,7 +39,7 @@ void main() { vec3 surf_color = illuminate(srgb_to_linear(model_col.rgb * f_col), light, diffuse_light, ambient_light); float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x); - vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, true); + vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, f_pos, true); vec3 color = mix(surf_color, fog_color, fog_level); tgt_color = vec4(color, 1.0); diff --git a/assets/voxygen/shaders/fluid-frag.glsl b/assets/voxygen/shaders/fluid-frag.glsl index 2d4f3bae7b..276cd7ccef 100644 --- a/assets/voxygen/shaders/fluid-frag.glsl +++ b/assets/voxygen/shaders/fluid-frag.glsl @@ -50,7 +50,7 @@ float wave_height(vec3 pos) { 0.0 ); - return pow(abs(height), 0.5) * sign(height) * 3.0; + return pow(abs(height), 0.5) * sign(height) * 1.5; } void main() { @@ -113,13 +113,13 @@ void main() { vec3 surf_color = illuminate(srgb_to_linear(f_col), light, diffuse_light, ambient_light); float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x); - vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, true); + vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, f_pos, true); vec3 reflect_ray_dir = reflect(cam_to_frag, norm); // Hack to prevent the reflection ray dipping below the horizon and creating weird blue spots in the water reflect_ray_dir.z = max(reflect_ray_dir.z, 0.05); - vec3 reflect_color = get_sky_color(reflect_ray_dir, time_of_day.x, false) * f_light; + vec3 reflect_color = get_sky_color(reflect_ray_dir, time_of_day.x, f_pos, false) * f_light; // 0 = 100% reflection, 1 = translucent water float passthrough = pow(dot(faceforward(f_norm, f_norm, cam_to_frag), -cam_to_frag), 0.5); diff --git a/assets/voxygen/shaders/include/sky.glsl b/assets/voxygen/shaders/include/sky.glsl index d60345f962..2cefc6ab16 100644 --- a/assets/voxygen/shaders/include/sky.glsl +++ b/assets/voxygen/shaders/include/sky.glsl @@ -1,5 +1,7 @@ #include +uniform sampler2D t_noise; + const float PI = 3.141592; const vec3 SKY_DAY_TOP = vec3(0.1, 0.2, 0.9); @@ -43,6 +45,22 @@ float get_moon_brightness(vec3 moon_dir) { return max(-moon_dir.z + 0.6, 0.0) * 0.07; } +vec3 get_sun_color(vec3 sun_dir) { + return mix( + mix( + DUSK_LIGHT, + NIGHT_LIGHT, + max(sun_dir.z, 0) + ), + DAY_LIGHT, + max(-sun_dir.z, 0) + ); +} + +vec3 get_moon_color(vec3 moon_dir) { + return vec3(0.15, 0.15, 1.5); +} + void get_sun_diffuse(vec3 norm, float time_of_day, out vec3 light, out vec3 diffuse_light, out vec3 ambient_light, float diffusion) { const float SUN_AMBIANCE = 0.1; @@ -54,17 +72,9 @@ void get_sun_diffuse(vec3 norm, float time_of_day, out vec3 light, out vec3 diff // clamp() changed to max() as sun_dir.z is produced from a cos() function and therefore never greater than 1 - vec3 sun_color = mix( - mix( - DUSK_LIGHT, - NIGHT_LIGHT, - max(sun_dir.z, 0) - ), - DAY_LIGHT, - max(-sun_dir.z, 0) - ); + vec3 sun_color = get_sun_color(sun_dir); - vec3 moon_color = vec3(0.1, 0.1, 1) * 1.5; + vec3 moon_color = get_moon_color(moon_dir); vec3 sun_chroma = sun_color * sun_light; vec3 moon_chroma = moon_color * moon_light; @@ -104,7 +114,70 @@ float is_star_at(vec3 dir) { return 0.0; } -vec3 get_sky_color(vec3 dir, float time_of_day, bool with_stars) { +vec3 pos_at_height(vec3 dir, float height) { + float dist = height / dir.z; + return dir * dist; +} + +const float CLOUD_AVG_HEIGHT = 1500.0; +const float CLOUD_HEIGHT_MIN = CLOUD_AVG_HEIGHT - 100.0; +const float CLOUD_HEIGHT_MAX = CLOUD_AVG_HEIGHT + 100.0; +const float CLOUD_THRESHOLD = 0.3; +const float CLOUD_SCALE = 1.0; +const float CLOUD_DENSITY = 50.0; + +float spow(float x, float e) { + return sign(x) * pow(abs(x), e); +} + +vec4 cloud_at(vec3 pos) { + float hdist = distance(pos.xy, cam_pos.xy) / 100000.0; + if (hdist > 1.0) { // Maximum cloud distance + return vec4(0.0); + } + + float value = ( + 0.0 + + texture(t_noise, pos.xy / CLOUD_SCALE * 0.0003 - tick.x * 0.01).x + + texture(t_noise, pos.xy / CLOUD_SCALE * 0.0009 + tick.x * 0.03).x * 0.5 + + texture(t_noise, pos.xy / CLOUD_SCALE * 0.0025 - tick.x * 0.05).x * 0.25 + ) / 2.75; + + float density = max((value - CLOUD_THRESHOLD) - abs(pos.z - CLOUD_AVG_HEIGHT) / 2000.0, 0.0) * CLOUD_DENSITY; + + vec3 color = vec3(1.0) * (1.0 - pow(max(CLOUD_AVG_HEIGHT - pos.z, 0.0), 0.25) / 2.5); + + return vec4(color, density / max((hdist - 0.7) * 100.0, 1.0)); +} + +vec4 get_cloud_color(vec3 dir, float time_of_day, float max_dist) { + float mind = (CLOUD_HEIGHT_MIN - cam_pos.z) / dir.z; + float maxd = (CLOUD_HEIGHT_MAX - cam_pos.z) / dir.z; + + float start = max(min(mind, maxd), 0.0); + float delta = abs(mind - maxd); + + if (delta <= 0.0) { + return vec4(0); + } + + vec3 cloud_col = vec3(1); + float passthrough = 1.0; + const float INCR = 0.05; + for (float d = 0.0; d < 1.0; d += INCR) { + float dist = start + d * delta; + vec3 pos = cam_pos.xyz + dir * dist; + vec4 sample = cloud_at(pos); + if (dist < max_dist) { + passthrough *= (1.0 - sample.a * INCR); + cloud_col = mix(cloud_col, sample.rgb, passthrough * sample.a * INCR); + } + } + + return vec4(cloud_col, 1.0 - passthrough / (1.0 + delta * 0.0003)); +} + +vec3 get_sky_color(vec3 dir, float time_of_day, vec3 f_pos, bool with_stars) { // Sky color vec3 sun_dir = get_sun_dir(time_of_day); vec3 moon_dir = get_moon_dir(time_of_day); @@ -179,7 +252,11 @@ vec3 get_sky_color(vec3 dir, float time_of_day, bool with_stars) { vec3 moon_surf = pow(max(dot(dir, -moon_dir) - 0.001, 0.0), 3000.0) * MOON_SURF_COLOR; vec3 moon_light = clamp(moon_halo + moon_surf, vec3(0), vec3(clamp(dir.z * 3.0, 0, 1))); - return sky_color + sun_light + moon_light; + // Clouds + vec4 clouds = get_cloud_color(dir, time_of_day, distance(cam_pos.xyz, f_pos)); + clouds.rgb *= get_sun_brightness(sun_dir) * get_sun_color(sun_dir) + get_moon_brightness(moon_dir) * get_moon_color(moon_dir); + + return mix(sky_color + sun_light + moon_light, clouds.rgb, clouds.a); } float fog(vec3 f_pos, vec3 focus_pos, uint medium) { diff --git a/assets/voxygen/shaders/skybox-frag.glsl b/assets/voxygen/shaders/skybox-frag.glsl index 9277816577..ac5624aea9 100644 --- a/assets/voxygen/shaders/skybox-frag.glsl +++ b/assets/voxygen/shaders/skybox-frag.glsl @@ -13,5 +13,5 @@ uniform u_locals { out vec4 tgt_color; void main() { - tgt_color = vec4(get_sky_color(normalize(f_pos), time_of_day.x, true), 1.0); + tgt_color = vec4(get_sky_color(normalize(f_pos), time_of_day.x, vec3(100000), true), 1.0); } diff --git a/assets/voxygen/shaders/sprite-frag.glsl b/assets/voxygen/shaders/sprite-frag.glsl index d243cb5368..50add1e0d7 100644 --- a/assets/voxygen/shaders/sprite-frag.glsl +++ b/assets/voxygen/shaders/sprite-frag.glsl @@ -27,7 +27,7 @@ void main() { vec3 surf_color = illuminate(f_col, light, diffuse_light, ambient_light); float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x); - vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, true); + vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, f_pos, true); vec3 color = mix(surf_color, fog_color, fog_level); tgt_color = vec4(color, 1.0 - clamp((distance(focus_pos.xy, f_pos.xy) - (RENDER_DIST - FADE_DIST)) / FADE_DIST, 0, 1)); diff --git a/assets/voxygen/shaders/terrain-frag.glsl b/assets/voxygen/shaders/terrain-frag.glsl index 7727afe185..6067dbfee7 100644 --- a/assets/voxygen/shaders/terrain-frag.glsl +++ b/assets/voxygen/shaders/terrain-frag.glsl @@ -40,7 +40,7 @@ void main() { vec3 surf_color = illuminate(srgb_to_linear(f_col), light, diffuse_light, ambient_light); float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x); - vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, true); + vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, f_pos, true); vec3 color = mix(surf_color, fog_color, fog_level); tgt_color = vec4(color, 1.0); diff --git a/assets/voxygen/texture/noise.png b/assets/voxygen/texture/noise.png new file mode 100644 index 0000000000..faef1bed6b --- /dev/null +++ b/assets/voxygen/texture/noise.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9c41eb6e06bf9fc61135ab9009bf81a6eaf55f34101d698032650188187670d4 +size 9532 diff --git a/voxygen/src/render/pipelines/figure.rs b/voxygen/src/render/pipelines/figure.rs index 246d294c2f..2a01f1e841 100644 --- a/voxygen/src/render/pipelines/figure.rs +++ b/voxygen/src/render/pipelines/figure.rs @@ -40,6 +40,8 @@ gfx_defines! { lights: gfx::ConstantBuffer = "u_lights", shadows: gfx::ConstantBuffer = "u_shadows", + noise: gfx::TextureSampler = "t_noise", + tgt_color: gfx::RenderTarget = "tgt_color", tgt_depth: gfx::DepthTarget = gfx::preset::depth::LESS_EQUAL_WRITE, } diff --git a/voxygen/src/render/pipelines/fluid.rs b/voxygen/src/render/pipelines/fluid.rs index e387437da1..67264323ad 100644 --- a/voxygen/src/render/pipelines/fluid.rs +++ b/voxygen/src/render/pipelines/fluid.rs @@ -29,6 +29,7 @@ gfx_defines! { lights: gfx::ConstantBuffer = "u_lights", shadows: gfx::ConstantBuffer = "u_shadows", + noise: gfx::TextureSampler = "t_noise", waves: gfx::TextureSampler<[f32; 4]> = "t_waves", tgt_color: gfx::BlendTarget = ("tgt_color", ColorMask::all(), gfx::preset::blend::ALPHA), diff --git a/voxygen/src/render/pipelines/skybox.rs b/voxygen/src/render/pipelines/skybox.rs index 35aed1d861..06446c0468 100644 --- a/voxygen/src/render/pipelines/skybox.rs +++ b/voxygen/src/render/pipelines/skybox.rs @@ -28,6 +28,8 @@ gfx_defines! { locals: gfx::ConstantBuffer = "u_locals", globals: gfx::ConstantBuffer = "u_globals", + noise: gfx::TextureSampler = "t_noise", + tgt_color: gfx::RenderTarget = "tgt_color", tgt_depth: gfx::DepthTarget = gfx::preset::depth::PASS_TEST, } diff --git a/voxygen/src/render/pipelines/sprite.rs b/voxygen/src/render/pipelines/sprite.rs index be80c49afd..9dcfef88c9 100644 --- a/voxygen/src/render/pipelines/sprite.rs +++ b/voxygen/src/render/pipelines/sprite.rs @@ -38,6 +38,8 @@ gfx_defines! { lights: gfx::ConstantBuffer = "u_lights", shadows: gfx::ConstantBuffer = "u_shadows", + noise: gfx::TextureSampler = "t_noise", + tgt_color: gfx::BlendTarget = ("tgt_color", ColorMask::all(), gfx::preset::blend::ALPHA), tgt_depth: gfx::DepthTarget = gfx::preset::depth::LESS_EQUAL_WRITE, } diff --git a/voxygen/src/render/pipelines/terrain.rs b/voxygen/src/render/pipelines/terrain.rs index cb264261e2..073185630e 100644 --- a/voxygen/src/render/pipelines/terrain.rs +++ b/voxygen/src/render/pipelines/terrain.rs @@ -34,6 +34,8 @@ gfx_defines! { lights: gfx::ConstantBuffer = "u_lights", shadows: gfx::ConstantBuffer = "u_shadows", + noise: gfx::TextureSampler = "t_noise", + tgt_color: gfx::RenderTarget = "tgt_color", tgt_depth: gfx::DepthTarget = gfx::preset::depth::LESS_EQUAL_WRITE, } diff --git a/voxygen/src/render/renderer.rs b/voxygen/src/render/renderer.rs index 94c2330915..7097be53cd 100644 --- a/voxygen/src/render/renderer.rs +++ b/voxygen/src/render/renderer.rs @@ -72,6 +72,8 @@ pub struct Renderer { shader_reload_indicator: ReloadIndicator, + noise_tex: Texture<(gfx::format::R8, gfx::format::Unorm)>, + aa_mode: AaMode, } @@ -102,6 +104,13 @@ impl Renderer { let sampler = factory.create_sampler_linear(); + let noise_tex = Texture::new( + &mut factory, + &assets::load_expect("voxygen.texture.noise"), + Some(gfx::texture::FilterMethod::Trilinear), + Some(gfx::texture::WrapMode::Tile), + )?; + Ok(Self { device, encoder: factory.create_command_buffer().into(), @@ -126,6 +135,8 @@ impl Renderer { shader_reload_indicator, + noise_tex, + aa_mode, }) } @@ -351,27 +362,24 @@ impl Renderer { } /// Create a new texture from the provided image. - pub fn create_texture( + pub fn create_texture( &mut self, image: &image::DynamicImage, filter_method: Option, wrap_mode: Option, - ) -> Result, RenderError> { + ) -> Result { Texture::new(&mut self.factory, image, filter_method, wrap_mode) } /// Create a new dynamic texture (gfx::memory::Usage::Dynamic) with the specified dimensions. - pub fn create_dynamic_texture( - &mut self, - dims: Vec2, - ) -> Result, RenderError> { + pub fn create_dynamic_texture(&mut self, dims: Vec2) -> Result { Texture::new_dynamic(&mut self.factory, dims.x, dims.y) } /// Update a texture with the provided offset, size, and data. - pub fn update_texture( + pub fn update_texture( &mut self, - texture: &Texture

, + texture: &Texture, offset: [u16; 2], size: [u16; 2], data: &[[u8; 4]], @@ -444,6 +452,7 @@ impl Renderer { vbuf: model.vbuf.clone(), locals: locals.buf.clone(), globals: globals.buf.clone(), + noise: (self.noise_tex.srv.clone(), self.noise_tex.sampler.clone()), tgt_color: self.tgt_color_view.clone(), tgt_depth: self.tgt_depth_view.clone(), }, @@ -476,6 +485,7 @@ impl Renderer { bones: bones.buf.clone(), lights: lights.buf.clone(), shadows: shadows.buf.clone(), + noise: (self.noise_tex.srv.clone(), self.noise_tex.sampler.clone()), tgt_color: self.tgt_color_view.clone(), tgt_depth: self.tgt_depth_view.clone(), }, @@ -506,6 +516,7 @@ impl Renderer { globals: globals.buf.clone(), lights: lights.buf.clone(), shadows: shadows.buf.clone(), + noise: (self.noise_tex.srv.clone(), self.noise_tex.sampler.clone()), tgt_color: self.tgt_color_view.clone(), tgt_depth: self.tgt_depth_view.clone(), }, @@ -520,7 +531,7 @@ impl Renderer { locals: &Consts, lights: &Consts, shadows: &Consts, - waves: &Texture, + waves: &Texture, ) { self.encoder.draw( &gfx::Slice { @@ -537,6 +548,7 @@ impl Renderer { globals: globals.buf.clone(), lights: lights.buf.clone(), shadows: shadows.buf.clone(), + noise: (self.noise_tex.srv.clone(), self.noise_tex.sampler.clone()), waves: (waves.srv.clone(), waves.sampler.clone()), tgt_color: self.tgt_color_view.clone(), tgt_depth: self.tgt_depth_view.clone(), @@ -568,6 +580,7 @@ impl Renderer { globals: globals.buf.clone(), lights: lights.buf.clone(), shadows: shadows.buf.clone(), + noise: (self.noise_tex.srv.clone(), self.noise_tex.sampler.clone()), tgt_color: self.tgt_color_view.clone(), tgt_depth: self.tgt_depth_view.clone(), }, @@ -578,7 +591,7 @@ impl Renderer { pub fn render_ui_element( &mut self, model: &Model, - tex: &Texture, + tex: &Texture, scissor: Aabr, globals: &Consts, locals: &Consts, diff --git a/voxygen/src/render/texture.rs b/voxygen/src/render/texture.rs index 66d0af88c4..08fa7ac69b 100644 --- a/voxygen/src/render/texture.rs +++ b/voxygen/src/render/texture.rs @@ -1,26 +1,32 @@ -use super::{gfx_backend, Pipeline, RenderError}; +use super::{gfx_backend, RenderError}; use gfx::{self, traits::Factory}; use image::{DynamicImage, GenericImageView}; use std::marker::PhantomData; use vek::Vec2; -type ShaderFormat = (gfx::format::R8_G8_B8_A8, gfx::format::Srgb); +type DefaultShaderFormat = (gfx::format::R8_G8_B8_A8, gfx::format::Srgb); /// Represents an image that has been uploaded to the GPU. -pub struct Texture { - pub tex: gfx::handle::Texture< - gfx_backend::Resources, - ::Surface, - >, +pub struct Texture +where + F::Surface: gfx::format::TextureSurface, + F::Channel: gfx::format::TextureChannel, + ::DataType: Copy, +{ + pub tex: gfx::handle::Texture::Surface>, pub srv: gfx::handle::ShaderResourceView< gfx_backend::Resources, - ::View, + ::View, >, pub sampler: gfx::handle::Sampler, - _phantom: PhantomData

, } -impl Texture

{ +impl Texture +where + F::Surface: gfx::format::TextureSurface, + F::Channel: gfx::format::TextureChannel, + ::DataType: Copy, +{ pub fn new( factory: &mut gfx_backend::Factory, image: &DynamicImage, @@ -28,14 +34,14 @@ impl Texture

{ wrap_mode: Option, ) -> Result { let (tex, srv) = factory - .create_texture_immutable_u8::( + .create_texture_immutable_u8::( gfx::texture::Kind::D2( image.width() as u16, image.height() as u16, gfx::texture::AaMode::Single, ), gfx::texture::Mipmap::Provided, - &[&image.to_rgba().into_raw()], + &[&image.raw_pixels()], ) .map_err(|err| RenderError::CombinedError(err))?; @@ -46,7 +52,6 @@ impl Texture

{ filter_method.unwrap_or(gfx::texture::FilterMethod::Scale), wrap_mode.unwrap_or(gfx::texture::WrapMode::Clamp), )), - _phantom: PhantomData, }) } @@ -64,16 +69,12 @@ impl Texture

{ 1 as gfx::texture::Level, gfx::memory::Bind::SHADER_RESOURCE, gfx::memory::Usage::Dynamic, - Some(<::Channel as gfx::format::ChannelTyped>::get_channel_type()), + Some(<::Channel as gfx::format::ChannelTyped>::get_channel_type()), ) .map_err(|err| RenderError::CombinedError(gfx::CombinedError::Texture(err)))?; let srv = factory - .view_texture_as_shader_resource::( - &tex, - (0, 0), - gfx::format::Swizzle::new(), - ) + .view_texture_as_shader_resource::(&tex, (0, 0), gfx::format::Swizzle::new()) .map_err(|err| RenderError::CombinedError(gfx::CombinedError::Resource(err)))?; Ok(Self { @@ -83,7 +84,6 @@ impl Texture

{ gfx::texture::FilterMethod::Scale, gfx::texture::WrapMode::Clamp, )), - _phantom: PhantomData, }) } @@ -93,7 +93,7 @@ impl Texture

{ encoder: &mut gfx::Encoder, offset: [u16; 2], size: [u16; 2], - data: &[[u8; 4]], + data: &[::DataType], ) -> Result<(), RenderError> { let info = gfx::texture::ImageInfoCommon { xoffset: offset[0], @@ -106,7 +106,7 @@ impl Texture

{ mipmap: 0, }; encoder - .update_texture::<::Surface, ShaderFormat>( + .update_texture::<::Surface, F>( &self.tex, None, info, data, ) .map_err(|err| RenderError::TexUpdateError(err)) diff --git a/voxygen/src/scene/terrain.rs b/voxygen/src/scene/terrain.rs index 3a7c93f6bf..382859b60e 100644 --- a/voxygen/src/scene/terrain.rs +++ b/voxygen/src/scene/terrain.rs @@ -212,7 +212,7 @@ pub struct Terrain { // GPU data sprite_models: HashMap<(BlockKind, usize), Model>, - waves: Texture, + waves: Texture, phantom: PhantomData, } diff --git a/voxygen/src/ui/cache.rs b/voxygen/src/ui/cache.rs index 51727c39e2..36604f2bfb 100644 --- a/voxygen/src/ui/cache.rs +++ b/voxygen/src/ui/cache.rs @@ -14,7 +14,7 @@ const POSITION_TOLERANCE: f32 = 0.1; pub struct Cache { glyph_cache: GlyphCache<'static>, - glyph_cache_tex: Texture, + glyph_cache_tex: Texture, graphic_cache: GraphicCache, } @@ -38,10 +38,10 @@ impl Cache { graphic_cache: GraphicCache::new(renderer), }) } - pub fn glyph_cache_tex(&self) -> &Texture { + pub fn glyph_cache_tex(&self) -> &Texture { &self.glyph_cache_tex } - pub fn glyph_cache_mut_and_tex(&mut self) -> (&mut GlyphCache<'static>, &Texture) { + pub fn glyph_cache_mut_and_tex(&mut self) -> (&mut GlyphCache<'static>, &Texture) { (&mut self.glyph_cache, &self.glyph_cache_tex) } pub fn graphic_cache(&self) -> &GraphicCache { diff --git a/voxygen/src/ui/graphic/mod.rs b/voxygen/src/ui/graphic/mod.rs index 7bdb59c3db..8fba234e68 100644 --- a/voxygen/src/ui/graphic/mod.rs +++ b/voxygen/src/ui/graphic/mod.rs @@ -84,7 +84,7 @@ pub struct GraphicCache { // Atlases with the index of their texture in the textures vec atlases: Vec<(SimpleAtlasAllocator, usize)>, - textures: Vec>, + textures: Vec, // Stores the location of graphics rendered at a particular resolution and cached on the cpu cache_map: HashMap, } @@ -131,7 +131,7 @@ impl GraphicCache { self.graphic_map.get(&id) } /// Used to aquire textures for rendering - pub fn get_tex(&self, id: TexId) -> &Texture { + pub fn get_tex(&self, id: TexId) -> &Texture { self.textures.get(id.0).expect("Invalid TexId used") } pub fn clear_cache(&mut self, renderer: &mut Renderer) { @@ -302,7 +302,7 @@ fn draw_graphic(graphic_map: &GraphicMap, graphic_id: Id, dims: Vec2) -> Op } } -fn create_atlas_texture(renderer: &mut Renderer) -> (SimpleAtlasAllocator, Texture) { +fn create_atlas_texture(renderer: &mut Renderer) -> (SimpleAtlasAllocator, Texture) { let (w, h) = renderer.get_resolution().into_tuple(); let max_texture_size = renderer.max_texture_size(); @@ -326,12 +326,7 @@ fn aabr_from_alloc_rect(rect: guillotiere::Rectangle) -> Aabr { } } -fn upload_image( - renderer: &mut Renderer, - aabr: Aabr, - tex: &Texture, - image: &RgbaImage, -) { +fn upload_image(renderer: &mut Renderer, aabr: Aabr, tex: &Texture, image: &RgbaImage) { let offset = aabr.min.into_array(); let size = aabr.size().into_array(); if let Err(err) = renderer.update_texture(