From: Alexis Laferrière Date: Sat, 10 Jun 2017 18:39:45 +0000 (-0400) Subject: gamnit: move `pixelated=` up to `Texture` X-Git-Url: http://nitlanguage.org gamnit: move `pixelated=` up to `Texture` Signed-off-by: Alexis Laferrière --- diff --git a/lib/gamnit/textures.nit b/lib/gamnit/textures.nit index 271e688..fabed02 100644 --- a/lib/gamnit/textures.nit +++ b/lib/gamnit/textures.nit @@ -96,6 +96,22 @@ abstract class Texture # Offset of the bottom border on `root` from 0.0 to 1.0 fun offset_bottom: Float do return 1.0 + + # Should this texture be drawn pixelated when magnified? otherwise it is interpolated + # + # This setting affects all the textures based on the same pixel data, or `root`. + # + # Must be set after a successful call to `load`. + fun pixelated=(pixelated: Bool) + do + if root.gl_texture == -1 then return + + # TODO do not modify `root` by using *sampler objects* in glesv3 + glBindTexture(gl_TEXTURE_2D, root.gl_texture) + + var param = if pixelated then gl_NEAREST else gl_LINEAR + glTexParameteri(gl_TEXTURE_2D, gl_TEXTURE_MAG_FILTER, param) + end end # Colorful small texture of 32x32 pixels by default @@ -228,18 +244,6 @@ class RootTexture cpixels.destroy end - # Set whether this texture should be pixelated when drawn, otherwise it is interpolated - fun pixelated=(pixelated: Bool) - do - # TODO this service could be made available in `Texture` when using - # the kind of texture wrapper of gles v2 or maybe 3 - - glBindTexture(gl_TEXTURE_2D, gl_texture) - - var param = if pixelated then gl_NEAREST else gl_LINEAR - glTexParameteri(gl_TEXTURE_2D, gl_TEXTURE_MAG_FILTER, param) - end - # Has this resource been deleted? var deleted = false