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