From 60d90a32ad2c11cbce3e12fe3e5fe9f13c0f54f6 Mon Sep 17 00:00:00 2001
From: CasualPokePlayer <50538166+CasualPokePlayer@users.noreply.github.com>
Date: Tue, 14 May 2024 17:28:49 -0700
Subject: [PATCH] Remove ability to specify texture wrap mode (never was ever
used besides the default clamping); merge specifying min/mag filters into one
function (with only linear/nearest neighbor options)
---
src/BizHawk.Bizware.BizwareGL/IGL.cs | 13 ++---
src/BizHawk.Bizware.BizwareGL/RetroShader.cs | 2 -
src/BizHawk.Bizware.BizwareGL/Texture2d.cs | 16 +-----
.../enums/TextureMagFilter.cs | 18 -------
.../enums/TextureMinFilter.cs | 20 --------
.../D3D11/IGL_D3D11.cs | 16 +-----
.../GDIPlus/GDIPlusTexture.cs | 5 +-
.../GDIPlus/IGL_GDIPlus.cs | 11 +---
.../OpenGL/IGL_OpenGL.cs | 51 +++++++------------
.../Renderers/GDIPlusGuiRenderer.cs | 13 +----
10 files changed, 32 insertions(+), 133 deletions(-)
delete mode 100644 src/BizHawk.Bizware.BizwareGL/enums/TextureMagFilter.cs
delete mode 100644 src/BizHawk.Bizware.BizwareGL/enums/TextureMinFilter.cs
diff --git a/src/BizHawk.Bizware.BizwareGL/IGL.cs b/src/BizHawk.Bizware.BizwareGL/IGL.cs
index af9c191aa9..39a3c12c71 100644
--- a/src/BizHawk.Bizware.BizwareGL/IGL.cs
+++ b/src/BizHawk.Bizware.BizwareGL/IGL.cs
@@ -5,7 +5,6 @@ using System.Numerics;
namespace BizHawk.Bizware.BizwareGL
{
-
///
/// This is a wrapper over OpenGL and direct3d to give a uniform interface
/// TODO - This really needs to be split up into an internal and a user interface. so many of the functions are made to support the smart wrappers
@@ -106,10 +105,6 @@ namespace BizHawk.Bizware.BizwareGL
///
BitmapBuffer ResolveTexture2d(Texture2d texture);
- void SetMinFilter(Texture2d texture, TextureMinFilter minFilter);
-
- void SetMagFilter(Texture2d texture, TextureMagFilter magFilter);
-
///
/// creates a vertex layout resource
///
@@ -138,10 +133,12 @@ namespace BizHawk.Bizware.BizwareGL
Texture2d WrapGLTexture2d(IntPtr glTexId, int width, int height);
///
- /// Sets the clamp mode (for both uv) for the Texture2d.
- /// The default is clamped=true.
+ /// Sets the texture's filtering mode
+ /// The default is linear = false (i.e. nearest neighbor)
///
- void SetTextureWrapMode(Texture2d tex, bool clamp);
+ ///
+ ///
+ public void SetTextureFilter(Texture2d texture, bool linear);
///
/// Loads the texture with new data. This isn't supposed to be especially versatile, it just blasts a bitmap buffer into the texture
diff --git a/src/BizHawk.Bizware.BizwareGL/RetroShader.cs b/src/BizHawk.Bizware.BizwareGL/RetroShader.cs
index 2f3417b3b8..003b1c617a 100644
--- a/src/BizHawk.Bizware.BizwareGL/RetroShader.cs
+++ b/src/BizHawk.Bizware.BizwareGL/RetroShader.cs
@@ -93,8 +93,6 @@ namespace BizHawk.Bizware.BizwareGL
var mat = Matrix4x4.Transpose(Modelview * Projection);
Pipeline["modelViewProj"].Set(mat, true);
- Owner.SetTextureWrapMode(tex, true);
-
sampler0.Set(tex);
Owner.SetViewport(OutputSize);
diff --git a/src/BizHawk.Bizware.BizwareGL/Texture2d.cs b/src/BizHawk.Bizware.BizwareGL/Texture2d.cs
index 3040ce0a10..b52680018b 100644
--- a/src/BizHawk.Bizware.BizwareGL/Texture2d.cs
+++ b/src/BizHawk.Bizware.BizwareGL/Texture2d.cs
@@ -40,21 +40,9 @@ namespace BizHawk.Bizware.BizwareGL
{
}
- public void SetMinFilter(TextureMinFilter minFilter) => Owner.SetMinFilter(this, minFilter);
+ public void SetFilterLinear() => Owner.SetTextureFilter(this, true);
- public void SetMagFilter(TextureMagFilter magFilter) => Owner.SetMagFilter(this, magFilter);
-
- public void SetFilterLinear()
- {
- SetMinFilter(TextureMinFilter.Linear);
- SetMagFilter(TextureMagFilter.Linear);
- }
-
- public void SetFilterNearest()
- {
- SetMinFilter(TextureMinFilter.Nearest);
- SetMagFilter(TextureMagFilter.Nearest);
- }
+ public void SetFilterNearest() => Owner.SetTextureFilter(this, false);
public IGL Owner { get; }
public object Opaque { get; private set; }
diff --git a/src/BizHawk.Bizware.BizwareGL/enums/TextureMagFilter.cs b/src/BizHawk.Bizware.BizwareGL/enums/TextureMagFilter.cs
deleted file mode 100644
index 73ddfedc61..0000000000
--- a/src/BizHawk.Bizware.BizwareGL/enums/TextureMagFilter.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-namespace BizHawk.Bizware.BizwareGL
-{
- public enum TextureMagFilter
- {
- Nearest = 0x2600,
- Linear = 0x2601,
- LinearDetailSgis = 0x8097,
- LinearDetailAlphaSgis = 0x8098,
- LinearDetailColorSgis = 0x8099,
- LinearSharpenSgis = 0x80AD,
- LinearSharpenAlphaSgis = 0x80AE,
- LinearSharpenColorSgis = 0x80AF,
- Filter4Sgis = 0x8146,
- PixelTexGenQCeilingSgix = 0x8184,
- PixelTexGenQRoundSgix = 0x8185,
- PixelTexGenQFloorSgix = 0x8186,
- }
-}
diff --git a/src/BizHawk.Bizware.BizwareGL/enums/TextureMinFilter.cs b/src/BizHawk.Bizware.BizwareGL/enums/TextureMinFilter.cs
deleted file mode 100644
index 749a9f238e..0000000000
--- a/src/BizHawk.Bizware.BizwareGL/enums/TextureMinFilter.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-namespace BizHawk.Bizware.BizwareGL
-{
- public enum TextureMinFilter
- {
- Nearest = 0x2600,
- Linear = 0x2601,
- NearestMipmapNearest = 0x2700,
- LinearMipmapNearest = 0x2701,
- NearestMipmapLinear = 0x2702,
- LinearMipmapLinear = 0x2703,
- Filter4Sgis = 0x8146,
- LinearClipmapLinearSgix = 0x8170,
- PixelTexGenQCeilingSgix = 0x8184,
- PixelTexGenQRoundSgix = 0x8185,
- PixelTexGenQFloorSgix = 0x8186,
- NearestClipmapNearestSgix = 0x844D,
- NearestClipmapLinearSgix = 0x844E,
- LinearClipmapNearestSgix = 0x844F,
- }
-}
diff --git a/src/BizHawk.Bizware.Graphics/D3D11/IGL_D3D11.cs b/src/BizHawk.Bizware.Graphics/D3D11/IGL_D3D11.cs
index 869218720a..09c732adb9 100644
--- a/src/BizHawk.Bizware.Graphics/D3D11/IGL_D3D11.cs
+++ b/src/BizHawk.Bizware.Graphics/D3D11/IGL_D3D11.cs
@@ -968,22 +968,10 @@ namespace BizHawk.Bizware.Graphics
}
}
- // TODO: Remove this, we only use clamp ever anyways
- public void SetTextureWrapMode(Texture2d tex, bool clamp)
- {
- }
-
- // TODO: Merge these to one call (for Linear / Nearest)
- public void SetMinFilter(Texture2d texture, TextureMinFilter minFilter)
+ public void SetTextureFilter(Texture2d texture, bool linear)
{
var tw = (TextureWrapper)texture.Opaque;
- tw.LinearFiltering = minFilter == TextureMinFilter.Linear;
- }
-
- public void SetMagFilter(Texture2d texture, TextureMagFilter magFilter)
- {
- var tw = (TextureWrapper)texture.Opaque;
- tw.LinearFiltering = magFilter == TextureMagFilter.Linear;
+ tw.LinearFiltering = linear;
}
public Texture2d LoadTexture(Bitmap bitmap)
diff --git a/src/BizHawk.Bizware.Graphics/GDIPlus/GDIPlusTexture.cs b/src/BizHawk.Bizware.Graphics/GDIPlus/GDIPlusTexture.cs
index d0726fdb49..ada84602b2 100644
--- a/src/BizHawk.Bizware.Graphics/GDIPlus/GDIPlusTexture.cs
+++ b/src/BizHawk.Bizware.Graphics/GDIPlus/GDIPlusTexture.cs
@@ -1,15 +1,12 @@
using System;
using System.Drawing;
-using BizHawk.Bizware.BizwareGL;
-
namespace BizHawk.Bizware.Graphics
{
public class GDIPlusTexture : IDisposable
{
public Bitmap SDBitmap;
- public TextureMinFilter MinFilter = TextureMinFilter.Nearest;
- public TextureMagFilter MagFilter = TextureMagFilter.Nearest;
+ public bool LinearFiltering;
public void Dispose()
{
diff --git a/src/BizHawk.Bizware.Graphics/GDIPlus/IGL_GDIPlus.cs b/src/BizHawk.Bizware.Graphics/GDIPlus/IGL_GDIPlus.cs
index 12672eebc8..94598e05b0 100644
--- a/src/BizHawk.Bizware.Graphics/GDIPlus/IGL_GDIPlus.cs
+++ b/src/BizHawk.Bizware.Graphics/GDIPlus/IGL_GDIPlus.cs
@@ -68,10 +68,6 @@ namespace BizHawk.Bizware.Graphics
{
}
- public void SetTextureWrapMode(Texture2d tex, bool clamp)
- {
- }
-
public void Draw(IntPtr data, int count)
{
}
@@ -117,11 +113,8 @@ namespace BizHawk.Bizware.Graphics
{
}
- public void SetMinFilter(Texture2d texture, TextureMinFilter minFilter)
- => ((GDIPlusTexture) texture.Opaque).MinFilter = minFilter;
-
- public void SetMagFilter(Texture2d texture, TextureMagFilter magFilter)
- => ((GDIPlusTexture) texture.Opaque).MagFilter = magFilter;
+ public void SetTextureFilter(Texture2d texture, bool linear)
+ => ((GDIPlusTexture) texture.Opaque).LinearFiltering = linear;
public Texture2d LoadTexture(Bitmap bitmap)
{
diff --git a/src/BizHawk.Bizware.Graphics/OpenGL/IGL_OpenGL.cs b/src/BizHawk.Bizware.Graphics/OpenGL/IGL_OpenGL.cs
index 2432d2ca59..8f3cafd973 100644
--- a/src/BizHawk.Bizware.Graphics/OpenGL/IGL_OpenGL.cs
+++ b/src/BizHawk.Bizware.Graphics/OpenGL/IGL_OpenGL.cs
@@ -21,9 +21,6 @@ using Silk.NET.OpenGL.Legacy;
using BizShader = BizHawk.Bizware.BizwareGL.Shader;
-using BizTextureMagFilter = BizHawk.Bizware.BizwareGL.TextureMagFilter;
-using BizTextureMinFilter = BizHawk.Bizware.BizwareGL.TextureMinFilter;
-
using GLVertexAttribPointerType = Silk.NET.OpenGL.Legacy.VertexAttribPointerType;
namespace BizHawk.Bizware.Graphics
@@ -316,15 +313,6 @@ namespace BizHawk.Bizware.Graphics
GL.BindTexture(TextureTarget.Texture2D, (uint)tex.Opaque);
}
- public void SetTextureWrapMode(Texture2d tex, bool clamp)
- {
- BindTexture2d(tex);
-
- var mode = clamp ? TextureWrapMode.ClampToEdge : TextureWrapMode.Repeat;
- GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)mode);
- GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)mode);
- }
-
private void LegacyBindArrayData(VertexLayout vertexLayout, IntPtr pData)
{
// DEPRECATED CRAP USED, NEEDED FOR ANCIENT SHADERS
@@ -496,16 +484,11 @@ namespace BizHawk.Bizware.Graphics
GL.BindTexture(TextureTarget.Texture2D, (uint)tex.Opaque);
}
- public void SetMinFilter(Texture2d texture, BizTextureMinFilter minFilter)
+ public void SetTextureFilter(Texture2d texture, bool linear)
{
BindTexture2d(texture);
- GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)minFilter);
- }
-
- public void SetMagFilter(Texture2d texture, BizTextureMagFilter magFilter)
- {
- BindTexture2d(texture);
- GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)magFilter);
+ GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)(linear ? TextureMinFilter.Linear : TextureMinFilter.Nearest));
+ GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)(linear ? TextureMagFilter.Linear : TextureMagFilter.Nearest));
}
public Texture2d LoadTexture(Bitmap bitmap)
@@ -520,16 +503,26 @@ namespace BizHawk.Bizware.Graphics
return LoadTexture(bmp);
}
- public Texture2d CreateTexture(int width, int height)
+ private uint GenTexture()
{
var id = GL.GenTexture();
+ // sensible defaults
+ GL.BindTexture(TextureTarget.Texture2D, id);
+ GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
+ GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
+ GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
+ GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
+ return id;
+ }
+
+ public Texture2d CreateTexture(int width, int height)
+ {
+ var id = GenTexture();
return new(this, id, width, height);
}
public Texture2d WrapGLTexture2d(IntPtr glTexId, int width, int height)
- {
- return new(this, (uint)glTexId.ToInt32(), width, height) { IsUpsideDown = true };
- }
+ => new(this, (uint)glTexId.ToInt32(), width, height) { IsUpsideDown = true };
public unsafe void LoadTextureData(Texture2d tex, BitmapBuffer bmp)
{
@@ -555,13 +548,10 @@ namespace BizHawk.Bizware.Graphics
public unsafe RenderTarget CreateRenderTarget(int w, int h)
{
// create a texture for it
- var texId = GL.GenTexture();
+ var texId = GenTexture();
var tex = new Texture2d(this, texId, w, h);
- GL.BindTexture(TextureTarget.Texture2D, texId);
GL.TexImage2D(TextureTarget.Texture2D, 0, InternalFormat.Rgba8, (uint)w, (uint)h, 0, PixelFormat.Bgra, PixelType.UnsignedByte, null);
- tex.SetMagFilter(BizTextureMagFilter.Nearest);
- tex.SetMinFilter(BizTextureMinFilter.Nearest);
// create the FBO
var fbId = GL.GenFramebuffer();
@@ -600,7 +590,7 @@ namespace BizHawk.Bizware.Graphics
public unsafe Texture2d LoadTexture(BitmapBuffer bmp)
{
Texture2d ret;
- var id = GL.GenTexture();
+ var id = GenTexture();
try
{
ret = new(this, id, bmp.Width, bmp.Height);
@@ -615,9 +605,6 @@ namespace BizHawk.Bizware.Graphics
throw;
}
- // set default filtering... its safest to do this always
- ret.SetFilterNearest();
-
return ret;
}
diff --git a/src/BizHawk.Bizware.Graphics/Renderers/GDIPlusGuiRenderer.cs b/src/BizHawk.Bizware.Graphics/Renderers/GDIPlusGuiRenderer.cs
index 25d0fa66e2..03bab3a8db 100644
--- a/src/BizHawk.Bizware.Graphics/Renderers/GDIPlusGuiRenderer.cs
+++ b/src/BizHawk.Bizware.Graphics/Renderers/GDIPlusGuiRenderer.cs
@@ -214,19 +214,8 @@ namespace BizHawk.Bizware.Graphics
private static void PrepDraw(SDGraphics g, Texture2d tex)
{
var tw = (GDIPlusTexture)tex.Opaque;
-
// TODO - we can support bicubic for the final presentation...
- if ((int)tw.MagFilter != (int)tw.MinFilter)
- {
- throw new InvalidOperationException($"{nameof(tw)}.{nameof(tw.MagFilter)} != {nameof(tw)}.{nameof(tw.MinFilter)}");
- }
-
- g.InterpolationMode = tw.MagFilter switch
- {
- TextureMagFilter.Linear => InterpolationMode.Bilinear,
- TextureMagFilter.Nearest => InterpolationMode.NearestNeighbor,
- _ => g.InterpolationMode
- };
+ g.InterpolationMode = tw.LinearFiltering ? InterpolationMode.Bilinear : InterpolationMode.NearestNeighbor;
}
private void SetupMatrix(SDGraphics g)