mirror of
https://github.com/MaddyThorson/StrawberryBF.git
synced 2025-01-31 07:48:27 +08:00
Texture filter neartest by default
This commit is contained in:
parent
e359824c4d
commit
05c79b296e
@ -8,8 +8,8 @@ namespace Strawberry.SDL2
|
|||||||
{
|
{
|
||||||
public int TransformMatrixLocation { get; private set; }
|
public int TransformMatrixLocation { get; private set; }
|
||||||
public int TextureMatrixLocation { get; private set; }
|
public int TextureMatrixLocation { get; private set; }
|
||||||
public bool TexturesEnableLinearFilter = false;
|
public Texture.Filters TextureFilter = .Nearest;
|
||||||
public bool TexturesEnableEdgeClamping = false;
|
public bool TextureClamping = false;
|
||||||
|
|
||||||
private SDL.Window* window;
|
private SDL.Window* window;
|
||||||
private SDL.Surface* screen;
|
private SDL.Surface* screen;
|
||||||
@ -180,7 +180,7 @@ namespace Strawberry.SDL2
|
|||||||
Debug.Assert(surface != null, "Could not load from path.");
|
Debug.Assert(surface != null, "Could not load from path.");
|
||||||
Debug.Assert(surface.format.bytesPerPixel == 4, "Surface format incorrect.");
|
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);
|
SDL.FreeSurface(surface);
|
||||||
|
|
||||||
return tex;
|
return tex;
|
||||||
|
@ -2,13 +2,15 @@ namespace Strawberry
|
|||||||
{
|
{
|
||||||
public class Texture
|
public class Texture
|
||||||
{
|
{
|
||||||
|
public enum Filters { Nearest, Linear }
|
||||||
|
|
||||||
public uint32 Handle { get; private set; }
|
public uint32 Handle { get; private set; }
|
||||||
public int Width { get; private set; }
|
public int Width { get; private set; }
|
||||||
public int Height { get; private set; }
|
public int Height { get; private set; }
|
||||||
|
|
||||||
private static int32 OGLMajorV = -1;
|
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;
|
Width = width;
|
||||||
Height = height;
|
Height = height;
|
||||||
@ -19,14 +21,20 @@ namespace Strawberry
|
|||||||
GL.glGenTextures(1, &Handle);
|
GL.glGenTextures(1, &Handle);
|
||||||
GL.glBindTexture(GL.GL_TEXTURE_2D, Handle);
|
GL.glBindTexture(GL.GL_TEXTURE_2D, Handle);
|
||||||
|
|
||||||
// (OPTIONAL) Set linear Mipmaps
|
// Set Filter
|
||||||
if (indLinear) {
|
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_MAG_FILTER, GL.GL_LINEAR);
|
||||||
GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_LINEAR);
|
GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_LINEAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
// (OPTIONAL) Apply edge clamping
|
// Edge Clamp
|
||||||
if (indClamp) {
|
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_S, GL.GL_CLAMP_TO_EDGE);
|
||||||
GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);
|
GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user