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)
This commit is contained in:
parent
b38344077f
commit
60d90a32ad
|
@ -5,7 +5,6 @@ using System.Numerics;
|
|||
|
||||
namespace BizHawk.Bizware.BizwareGL
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
|||
/// </summary>
|
||||
BitmapBuffer ResolveTexture2d(Texture2d texture);
|
||||
|
||||
void SetMinFilter(Texture2d texture, TextureMinFilter minFilter);
|
||||
|
||||
void SetMagFilter(Texture2d texture, TextureMagFilter magFilter);
|
||||
|
||||
/// <summary>
|
||||
/// creates a vertex layout resource
|
||||
/// </summary>
|
||||
|
@ -138,10 +133,12 @@ namespace BizHawk.Bizware.BizwareGL
|
|||
Texture2d WrapGLTexture2d(IntPtr glTexId, int width, int height);
|
||||
|
||||
/// <summary>
|
||||
/// 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)
|
||||
/// </summary>
|
||||
void SetTextureWrapMode(Texture2d tex, bool clamp);
|
||||
/// <param name="texture"></param>
|
||||
/// <param name="linear"></param>
|
||||
public void SetTextureFilter(Texture2d texture, bool linear);
|
||||
|
||||
/// <summary>
|
||||
/// Loads the texture with new data. This isn't supposed to be especially versatile, it just blasts a bitmap buffer into the texture
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
|
@ -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,
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue