Texture filter neartest by default

This commit is contained in:
Maddy Thorson 2021-02-02 18:31:22 -08:00
parent e359824c4d
commit 05c79b296e
2 changed files with 16 additions and 8 deletions

View File

@ -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;

View File

@ -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);
}