Change textures from interface to abstract class.
This commit is contained in:
parent
e731e8af49
commit
4b2271dd29
@ -40,7 +40,7 @@ namespace Quik.FreeType
|
||||
return FT.GetCharIndex(_face, (ulong)character) != 0;
|
||||
}
|
||||
|
||||
public override void GetCharacter(int character, out IQuikTexture texture, out QuikGlyph glyph)
|
||||
public override void GetCharacter(int character, out QuikTexture texture, out QuikGlyph glyph)
|
||||
{
|
||||
GlyphEntry entry;
|
||||
|
||||
@ -102,7 +102,7 @@ namespace Quik.FreeType
|
||||
|
||||
private class Atlas : IDisposable
|
||||
{
|
||||
public IQuikTexture Texture;
|
||||
public QuikTexture Texture;
|
||||
|
||||
private QuikVec2 _pointer = new QuikVec2();
|
||||
private float _verticalAdvance = 0;
|
||||
|
@ -3,17 +3,21 @@ using OpenTK.Graphics.OpenGL4;
|
||||
|
||||
namespace Quik.OpenTK
|
||||
{
|
||||
public class OpenGLTexture : IQuikTexture
|
||||
public class OpenGLTexture : QuikTexture
|
||||
{
|
||||
public int TextureId { get; private set; }
|
||||
private OpenGLTextureManager Manager { get; }
|
||||
|
||||
private int _width;
|
||||
private int _height;
|
||||
private bool _mipmaps;
|
||||
|
||||
internal OpenGLTexture(OpenGLTextureManager manager, QuikImageFormat format, QuikVec2 size, bool mipmaps)
|
||||
{
|
||||
Manager = manager;
|
||||
Mipmaps = mipmaps;
|
||||
Width = (int)size.X;
|
||||
Height = (int)size.Y;
|
||||
_mipmaps = mipmaps;
|
||||
_width = (int)size.X;
|
||||
_height = (int)size.Y;
|
||||
|
||||
TextureId = GL.GenTexture();
|
||||
|
||||
@ -40,11 +44,11 @@ namespace Quik.OpenTK
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Equals(IQuikTexture other) =>
|
||||
public override bool Equals(QuikTexture other) =>
|
||||
other is OpenGLTexture && ((OpenGLTexture)other).TextureId == TextureId;
|
||||
|
||||
private bool _isDisposed = false;
|
||||
private void Dispose(bool disposing)
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (_isDisposed) return;
|
||||
Manager?.Reclaim(this);
|
||||
@ -52,17 +56,14 @@ namespace Quik.OpenTK
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose() => Dispose(true);
|
||||
public override int Width => _width;
|
||||
/// <inheritdoc />
|
||||
public override int Height => _height;
|
||||
/// <inheritdoc />
|
||||
public override bool Mipmaps => _mipmaps;
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Width { get; }
|
||||
/// <inheritdoc />
|
||||
public int Height { get; }
|
||||
/// <inheritdoc />
|
||||
public bool Mipmaps { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Image(IntPtr data, QuikImageFormat format, QuikVec2 size, int level, int alignment = 4)
|
||||
public override void Image(IntPtr data, QuikImageFormat format, QuikVec2 size, int level, int alignment = 4)
|
||||
{
|
||||
GL.BindTexture(TextureTarget.Texture2D, TextureId);
|
||||
GL.PixelStore(PixelStoreParameter.UnpackAlignment, alignment);
|
||||
@ -70,7 +71,7 @@ namespace Quik.OpenTK
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SubImage(IntPtr data, QuikImageFormat format, QuikRectangle location, int level, int alignment = 4)
|
||||
public override void SubImage(IntPtr data, QuikImageFormat format, QuikRectangle location, int level, int alignment = 4)
|
||||
{
|
||||
GL.BindTexture(TextureTarget.Texture2D, TextureId);
|
||||
GL.PixelStore(PixelStoreParameter.UnpackAlignment, alignment);
|
||||
@ -87,7 +88,7 @@ namespace Quik.OpenTK
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void GenerateMipMaps()
|
||||
public override void GenerateMipMaps()
|
||||
{
|
||||
GL.BindTexture(TextureTarget.Texture2D, TextureId);
|
||||
GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
|
||||
|
@ -9,7 +9,7 @@ namespace Quik.OpenTK
|
||||
|
||||
private List<int> _reclaimList = new List<int>();
|
||||
|
||||
public IQuikTexture CreateTexture(QuikVec2 size, bool mipmaps, QuikImageFormat format)
|
||||
public QuikTexture CreateTexture(QuikVec2 size, bool mipmaps, QuikImageFormat format)
|
||||
{
|
||||
return new OpenGLTexture(this, format, size, mipmaps);
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ namespace Quik.CommandQueue
|
||||
}
|
||||
}
|
||||
|
||||
public void Image(IQuikTexture texture, in QuikRectangle rectangle)
|
||||
public void Image(QuikTexture texture, in QuikRectangle rectangle)
|
||||
{
|
||||
Enqueue(Command.Image);
|
||||
Enqueue((Frame)(int)ImageCommandFlags.Single);
|
||||
@ -207,7 +207,7 @@ namespace Quik.CommandQueue
|
||||
Enqueue(rectangle);
|
||||
}
|
||||
|
||||
public void Image(IQuikTexture texture, in QuikRectangle rectangle, in QuikRectangle uv)
|
||||
public void Image(QuikTexture texture, in QuikRectangle rectangle, in QuikRectangle uv)
|
||||
{
|
||||
Enqueue(Command.Image);
|
||||
Enqueue((Frame)(int)(ImageCommandFlags.Single | ImageCommandFlags.UVs));
|
||||
@ -216,7 +216,7 @@ namespace Quik.CommandQueue
|
||||
Enqueue(uv);
|
||||
}
|
||||
|
||||
public void Image(IQuikTexture texture, QuikRectangle[] rectangles, bool interleavedUV = false)
|
||||
public void Image(QuikTexture texture, QuikRectangle[] rectangles, bool interleavedUV = false)
|
||||
{
|
||||
ImageCommandFlags flags = interleavedUV ? ImageCommandFlags.UVs : ImageCommandFlags.None;
|
||||
|
||||
@ -230,7 +230,7 @@ namespace Quik.CommandQueue
|
||||
}
|
||||
}
|
||||
|
||||
public void Image(IQuikTexture texture, QuikRectangle[] rectangles, QuikRectangle[] uvs)
|
||||
public void Image(QuikTexture texture, QuikRectangle[] rectangles, QuikRectangle[] uvs)
|
||||
{
|
||||
int count = Math.Min(rectangles.Length, uvs.Length);
|
||||
Enqueue(Command.Image);
|
||||
|
@ -5,22 +5,28 @@ namespace Quik
|
||||
/// <summary>
|
||||
/// Interface for texture instances.
|
||||
/// </summary>
|
||||
public interface IQuikTexture : IEquatable<IQuikTexture>, IDisposable
|
||||
public abstract class QuikTexture : IEquatable<QuikTexture>, IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Width of the texture.
|
||||
/// </summary>
|
||||
int Width { get; }
|
||||
public abstract int Width { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Height of the texture.
|
||||
/// </summary>
|
||||
int Height { get; }
|
||||
public abstract int Height { get; }
|
||||
|
||||
/// <summary>
|
||||
/// True if the texture can have mipmaps.
|
||||
/// </summary>
|
||||
bool Mipmaps { get; }
|
||||
public abstract bool Mipmaps { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether this texture contains a signed distance field.
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public bool SignedDistanceField { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Upload texture data.
|
||||
@ -30,7 +36,7 @@ namespace Quik
|
||||
/// <param name="size">Size of the texture data.</param>
|
||||
/// <param name="level">Mip level.</param>
|
||||
/// <param name="alignment">Pixel alignment. Expected to be 1, 2, 4, or 8.</param>
|
||||
void Image(IntPtr data, QuikImageFormat format, QuikVec2 size, int level, int alignment = 4);
|
||||
public abstract void Image(IntPtr data, QuikImageFormat format, QuikVec2 size, int level, int alignment = 4);
|
||||
|
||||
/// <summary>
|
||||
/// Upload texture data.
|
||||
@ -40,11 +46,19 @@ namespace Quik
|
||||
/// <param name="location">Location of the data in the texture.</param>
|
||||
/// <param name="level">Mip level.</param>
|
||||
/// <param name="alignment">Pixel alignment. Expected to be 1, 2, 4, or 8.</param>
|
||||
void SubImage(IntPtr data, QuikImageFormat format, QuikRectangle location, int level, int alignment = 4);
|
||||
public abstract void SubImage(IntPtr data, QuikImageFormat format, QuikRectangle location, int level, int alignment = 4);
|
||||
|
||||
/// <summary>
|
||||
/// Generate the mip maps for the texture.
|
||||
/// </summary>
|
||||
void GenerateMipMaps();
|
||||
public abstract void GenerateMipMaps();
|
||||
|
||||
public virtual bool Equals(QuikTexture other)
|
||||
{
|
||||
return base.Equals(other);
|
||||
}
|
||||
|
||||
public void Dispose() => Dispose(true);
|
||||
protected virtual void Dispose(bool isDisposing) { }
|
||||
}
|
||||
}
|
@ -21,7 +21,7 @@ namespace Quik
|
||||
/// All parameters are hints. If there is a situation where the texture does not
|
||||
/// have mip levels, or format cannot be specified, ignore these parameters.
|
||||
/// </remarks>
|
||||
IQuikTexture CreateTexture(QuikVec2 size, bool mipmaps, QuikImageFormat format);
|
||||
QuikTexture CreateTexture(QuikVec2 size, bool mipmaps, QuikImageFormat format);
|
||||
|
||||
/// <summary>
|
||||
/// A function called on context clear. (useful for discarding old textures)
|
||||
|
@ -108,9 +108,9 @@ namespace Quik
|
||||
set => this["list-marker-position"] = value;
|
||||
}
|
||||
|
||||
public IQuikTexture ListMarkerImage
|
||||
public QuikTexture ListMarkerImage
|
||||
{
|
||||
get => (IQuikTexture)this["list-marker-image"];
|
||||
get => (QuikTexture)this["list-marker-image"];
|
||||
set => this["list-marker-image"] = value;
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,6 @@ namespace Quik.Typography
|
||||
public abstract float Descender { get; }
|
||||
|
||||
public abstract bool HasCharacter(int character);
|
||||
public abstract void GetCharacter(int character, out IQuikTexture texture, out QuikGlyph glyph);
|
||||
public abstract void GetCharacter(int character, out QuikTexture texture, out QuikGlyph glyph);
|
||||
}
|
||||
}
|
@ -280,7 +280,7 @@ namespace Quik.Typography
|
||||
for (int i = block.Text.Length - 1; i >= 0; i--)
|
||||
{
|
||||
char chr = block.Text[i];
|
||||
block.Font.GetCharacter(chr, out IQuikTexture texture, out QuikGlyph metrics);
|
||||
block.Font.GetCharacter(chr, out QuikTexture texture, out QuikGlyph metrics);
|
||||
group.Add(
|
||||
new TypesetCharacter(
|
||||
chr,
|
||||
@ -301,7 +301,7 @@ namespace Quik.Typography
|
||||
for (int i = 0; i < block.Text.Length; i++)
|
||||
{
|
||||
char chr = block.Text[i];
|
||||
block.Font.GetCharacter(chr, out IQuikTexture texture, out QuikGlyph metrics);
|
||||
block.Font.GetCharacter(chr, out QuikTexture texture, out QuikGlyph metrics);
|
||||
group.Add(
|
||||
new TypesetCharacter(
|
||||
chr,
|
||||
@ -352,13 +352,13 @@ namespace Quik.Typography
|
||||
public struct TypesetCharacter
|
||||
{
|
||||
public int Character;
|
||||
public IQuikTexture Texture;
|
||||
public QuikTexture Texture;
|
||||
public QuikRectangle Position;
|
||||
public QuikRectangle UV;
|
||||
|
||||
public TypesetCharacter(
|
||||
int chr,
|
||||
IQuikTexture texture,
|
||||
QuikTexture texture,
|
||||
in QuikRectangle position,
|
||||
in QuikRectangle uv)
|
||||
{
|
||||
|
@ -1411,7 +1411,7 @@ namespace Quik.VertexGenerator
|
||||
|
||||
private void RenderCharacter(QuikCommandPutChar chr)
|
||||
{
|
||||
Context.DefaultFont.GetCharacter(chr.Character, out IQuikTexture texture, out QuikGlyph metrics);
|
||||
Context.DefaultFont.GetCharacter(chr.Character, out QuikTexture texture, out QuikGlyph metrics);
|
||||
|
||||
QuikVertex a, b, c, d;
|
||||
a = b = c = d = new QuikVertex() {Color = new QuikColor(0xffffffff)};
|
||||
@ -1445,14 +1445,14 @@ namespace Quik.VertexGenerator
|
||||
QuikFont font = Context.DefaultFont;
|
||||
QuikVertex vertex = new QuikVertex() {Color = new QuikColor(0x000000ff)};
|
||||
QuikVec2 pointer = text.Position;
|
||||
IQuikTexture texture = null;
|
||||
QuikTexture texture = null;
|
||||
|
||||
for (int i = 0; i < text.Text.Length; i++)
|
||||
{
|
||||
int chr = text.Text[i];
|
||||
QuikGlyph metrics;
|
||||
|
||||
IQuikTexture ntex;
|
||||
QuikTexture ntex;
|
||||
font.GetCharacter(chr, out ntex, out metrics);
|
||||
|
||||
if (ntex != texture && texture != null)
|
||||
@ -1502,7 +1502,7 @@ namespace Quik.VertexGenerator
|
||||
short startElement = (short)_elementBufferPointer;
|
||||
TypesetGroup group = text.Group;
|
||||
QuikVertex vertex = new QuikVertex() { Color = new QuikColor(0x000000ff) };
|
||||
IQuikTexture texture = null;
|
||||
QuikTexture texture = null;
|
||||
|
||||
group.SortBy(TypesetGroup.SortByTexture);
|
||||
foreach (TypesetCharacter chr in group)
|
||||
@ -1569,6 +1569,6 @@ namespace Quik.VertexGenerator
|
||||
public short Count;
|
||||
public QuikRectangle Bounds;
|
||||
public bool ClearStencil;
|
||||
public IQuikTexture Texture;
|
||||
public QuikTexture Texture;
|
||||
}
|
||||
}
|
@ -20,7 +20,7 @@ namespace QuikTestApplication
|
||||
public static byte[] TextureData { get; private set; } = Array.Empty<byte>();
|
||||
public static QuikVec2 TextureSize { get; private set; }
|
||||
|
||||
public IQuikTexture Texture { get; }
|
||||
public QuikTexture Texture { get; }
|
||||
|
||||
public override float Ascender => throw new NotImplementedException();
|
||||
|
||||
@ -113,7 +113,7 @@ namespace QuikTestApplication
|
||||
return _characters.Contains((char) character);
|
||||
}
|
||||
|
||||
public override void GetCharacter(int character, out IQuikTexture texture, out QuikGlyph glyph)
|
||||
public override void GetCharacter(int character, out QuikTexture texture, out QuikGlyph glyph)
|
||||
{
|
||||
if (!_glyphs.TryGetValue(character, out glyph))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user