From caf421144a43f6d4fb70f9e21256af61bbc32054 Mon Sep 17 00:00:00 2001 From: Mike Welsh Date: Sat, 2 May 2020 08:18:45 -0700 Subject: [PATCH] webgl: Don't change wrapping mode in WebGL1 --- Cargo.lock | 32 ++++++++++++++++---------------- render/webgl/src/lib.rs | 23 ++++++++++++++++++++++- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 70014462e..e857983ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1826,22 +1826,6 @@ dependencies = [ "ruffle_core 0.1.0", ] -[[package]] -name = "ruffle_render_wgpu" -version = "0.1.0" -dependencies = [ - "bytemuck 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "image 0.23.4 (registry+https://github.com/rust-lang/crates.io-index)", - "jpeg-decoder 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "lyon 0.15.8 (registry+https://github.com/rust-lang/crates.io-index)", - "raw-window-handle 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "ruffle_core 0.1.0", - "wgpu 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "wgpu-native 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "ruffle_render_webgl" version = "0.1.0" @@ -1858,6 +1842,22 @@ dependencies = [ "web-sys 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ruffle_render_wgpu" +version = "0.1.0" +dependencies = [ + "bytemuck 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "image 0.23.4 (registry+https://github.com/rust-lang/crates.io-index)", + "jpeg-decoder 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "lyon 0.15.8 (registry+https://github.com/rust-lang/crates.io-index)", + "raw-window-handle 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "ruffle_core 0.1.0", + "wgpu 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "wgpu-native 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "ruffle_scanner" version = "0.1.0" diff --git a/render/webgl/src/lib.rs b/render/webgl/src/lib.rs index 4847307e9..feea9b767 100644 --- a/render/webgl/src/lib.rs +++ b/render/webgl/src/lib.rs @@ -670,6 +670,16 @@ impl RenderBackend for WebGlRenderBackend { ) .warn_on_error(); + // You must set the texture parameters for non-power-of-2 textures to function in WebGL. + self.gl + .tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_WRAP_S, Gl::CLAMP_TO_EDGE as i32); + self.gl + .tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_WRAP_T, Gl::CLAMP_TO_EDGE as i32); + self.gl + .tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_MIN_FILTER, Gl::LINEAR as i32); + self.gl + .tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_MAG_FILTER, Gl::LINEAR as i32); + let handle = BitmapHandle(self.textures.len()); self.textures.push(( id, @@ -713,6 +723,16 @@ impl RenderBackend for WebGlRenderBackend { ) .warn_on_error(); + // You must set the texture parameters for non-power-of-2 textures to function in WebGL. + self.gl + .tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_WRAP_S, Gl::CLAMP_TO_EDGE as i32); + self.gl + .tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_WRAP_T, Gl::CLAMP_TO_EDGE as i32); + self.gl + .tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_MIN_FILTER, Gl::LINEAR as i32); + self.gl + .tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_MAG_FILTER, Gl::LINEAR as i32); + let handle = BitmapHandle(self.textures.len()); self.textures.push(( id, @@ -1053,7 +1073,8 @@ impl RenderBackend for WebGlRenderBackend { .tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_MAG_FILTER, filter); self.gl .tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_MIN_FILTER, filter); - let wrap = if bitmap.is_repeating { + // On WebGL1, you are unable to change the wrapping parameter causes non-power-of-2 textures. + let wrap = if self.gl2.is_some() && bitmap.is_repeating { Gl::MIRRORED_REPEAT as i32 } else { Gl::CLAMP_TO_EDGE as i32