From 659308eb2afb21dca32b2949e69e7017d2691152 Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Tue, 29 Jul 2014 11:24:55 +1000 Subject: [PATCH] Set filter mode on tile textures to nearest when page scale is one, and linear otherwise. --- rendergl.rs | 17 +++++++++++++++-- texturegl.rs | 18 +++++++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/rendergl.rs b/rendergl.rs index adc181e..a3f23d0 100755 --- a/rendergl.rs +++ b/rendergl.rs @@ -11,7 +11,7 @@ use color::Color; use layers::Layer; use layers; use scene::Scene; -use texturegl::{Flip, NoFlip, VerticalFlip}; +use texturegl::{Flip, Linear, Nearest, NoFlip, VerticalFlip}; use texturegl::{Texture, TextureTarget2D, TextureTargetRectangle}; use tiling::Tile; use platform::surface::NativeCompositingGraphicsContext; @@ -415,6 +415,18 @@ pub fn bind_and_render_quad(render_context: RenderContext, use_program(program_id); active_texture(TEXTURE0); + + // FIXME: This should technically check that the transform + // matrix only contains scale in these components. + let has_scale = transform.m11 as uint != texture.size.width || + transform.m22 as uint != texture.size.height; + let filter_mode = if has_scale { + Linear + } else { + Nearest + }; + texture.set_filter_mode(filter_mode); + let _bound_texture = texture.bind(); // Set the projection matrix. @@ -530,7 +542,8 @@ impl Render for Tile { } } -pub fn render_scene(root_layer: Rc>, render_context: RenderContext, scene: &Scene) { +pub fn render_scene(root_layer: Rc>, render_context: RenderContext, + scene: &Scene) { // Set the viewport. viewport(0 as GLint, 0 as GLint, scene.size.width as GLsizei, scene.size.height as GLsizei); diff --git a/texturegl.rs b/texturegl.rs index 8acacdc..03e3ee1 100644 --- a/texturegl.rs +++ b/texturegl.rs @@ -12,7 +12,7 @@ use layers::LayerBuffer; use geom::size::Size2D; -use opengles::gl2::{BGRA, CLAMP_TO_EDGE, GLenum, GLint, GLsizei, GLuint, LINEAR, RGB, RGBA}; +use opengles::gl2::{BGRA, CLAMP_TO_EDGE, GLenum, GLint, GLsizei, GLuint, LINEAR, NEAREST, RGB, RGBA}; use opengles::gl2::{TEXTURE_MAG_FILTER, TEXTURE_MIN_FILTER, TEXTURE_2D, TEXTURE_RECTANGLE_ARB}; use opengles::gl2::{TEXTURE_WRAP_S, TEXTURE_WRAP_T, UNSIGNED_BYTE, UNSIGNED_INT_8_8_8_8_REV}; use opengles::gl2; @@ -23,6 +23,11 @@ pub enum Format { RGB24Format } +pub enum FilterMode { + Nearest, + Linear +} + /// Image data used when uploading to a texture. pub struct TextureImageData<'a> { size: Size2D, @@ -175,6 +180,17 @@ impl Texture { gl2::tex_parameter_i(self.target.as_gl_target(), TEXTURE_WRAP_T, CLAMP_TO_EDGE as GLint); } + /// Sets the filter mode for this texture. + pub fn set_filter_mode(&self, mode: FilterMode) { + let _bound_texture = self.bind(); + let gl_mode = match mode { + Nearest => NEAREST, + Linear => LINEAR, + } as GLint; + gl2::tex_parameter_i(self.target.as_gl_target(), TEXTURE_MAG_FILTER, gl_mode); + gl2::tex_parameter_i(self.target.as_gl_target(), TEXTURE_MIN_FILTER, gl_mode); + } + /// Binds the texture to the current context. pub fn bind(&self) -> BoundTexture { gl2::bind_texture(self.target.as_gl_target(), self.id);