gamnit: move `pixelated=` up to `Texture`
authorAlexis Laferrière <alexis.laf@xymus.net>
Sat, 10 Jun 2017 18:39:45 +0000 (14:39 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Wed, 14 Jun 2017 13:36:37 +0000 (09:36 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/gamnit/textures.nit

index 271e688..fabed02 100644 (file)
@@ -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