From 05c79b296efeb8182f15b228d6c5c09cc5934e58 Mon Sep 17 00:00:00 2001 From: Maddy Thorson Date: Tue, 2 Feb 2021 18:31:22 -0800 Subject: [PATCH] Texture filter neartest by default --- src/PlatformLayer/SDL2/SDL2PlatformLayer.bf | 6 +++--- src/PlatformLayer/Texture.bf | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/PlatformLayer/SDL2/SDL2PlatformLayer.bf b/src/PlatformLayer/SDL2/SDL2PlatformLayer.bf index 94d3f63..45f7440 100644 --- a/src/PlatformLayer/SDL2/SDL2PlatformLayer.bf +++ b/src/PlatformLayer/SDL2/SDL2PlatformLayer.bf @@ -8,8 +8,8 @@ namespace Strawberry.SDL2 { public int TransformMatrixLocation { get; private set; } public int TextureMatrixLocation { get; private set; } - public bool TexturesEnableLinearFilter = false; - public bool TexturesEnableEdgeClamping = false; + public Texture.Filters TextureFilter = .Nearest; + public bool TextureClamping = false; private SDL.Window* window; private SDL.Surface* screen; @@ -180,7 +180,7 @@ namespace Strawberry.SDL2 Debug.Assert(surface != null, "Could not load from path."); Debug.Assert(surface.format.bytesPerPixel == 4, "Surface format incorrect."); - var tex = new Texture(surface.w, surface.h, (uint8*)surface.pixels, TexturesEnableLinearFilter, TexturesEnableEdgeClamping); + var tex = new Texture(surface.w, surface.h, (uint8*)surface.pixels, TextureFilter, TextureClamping); SDL.FreeSurface(surface); return tex; diff --git a/src/PlatformLayer/Texture.bf b/src/PlatformLayer/Texture.bf index fcc4ff5..a2327b3 100644 --- a/src/PlatformLayer/Texture.bf +++ b/src/PlatformLayer/Texture.bf @@ -2,13 +2,15 @@ namespace Strawberry { public class Texture { + public enum Filters { Nearest, Linear } + public uint32 Handle { get; private set; } public int Width { get; private set; } public int Height { get; private set; } private static int32 OGLMajorV = -1; - public this(int width, int height, uint8* pixels, bool indLinear, bool indClamp) + public this(int width, int height, uint8* pixels, Filters filter = .Nearest, bool clamp = false) { Width = width; Height = height; @@ -19,14 +21,20 @@ namespace Strawberry GL.glGenTextures(1, &Handle); GL.glBindTexture(GL.GL_TEXTURE_2D, Handle); - // (OPTIONAL) Set linear Mipmaps - if (indLinear) { + // Set Filter + switch (filter) + { + case .Nearest: + GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); + GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST_MIPMAP_NEAREST); + + case .Linear: GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_LINEAR); } - // (OPTIONAL) Apply edge clamping - if (indClamp) { + // Edge Clamp + if (clamp) { GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE); GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE); }