From 31fb6d7e432c91b72d636be2107405c7b30fc736 Mon Sep 17 00:00:00 2001 From: JacobTech Date: Fri, 29 Mar 2024 10:54:51 -0400 Subject: [PATCH] FIX AMD location issue --- GraphicsManager/GraphicsManager.csproj | 4 +- GraphicsManager/Objects/Core/Shader.cs | 7 +++ GraphicsManager/Objects/Core/Texture.cs | 18 +++++-- GraphicsManager/Objects/Label.cs | 50 +++++++++----------- GraphicsManager/Objects/RainbowLabel.cs | 16 ++++++- GraphicsManager/Resources/Shaders/Label.frag | 2 +- GraphicsManager/Window.cs | 5 +- 7 files changed, 63 insertions(+), 39 deletions(-) diff --git a/GraphicsManager/GraphicsManager.csproj b/GraphicsManager/GraphicsManager.csproj index 4079dab..3299491 100644 --- a/GraphicsManager/GraphicsManager.csproj +++ b/GraphicsManager/GraphicsManager.csproj @@ -10,7 +10,7 @@ False https://git.jacobtech.com/JacobTech.com/GraphicsManager git - 1.0.8-alpha82 + 1.0.8-alpha99 @@ -34,7 +34,7 @@ - + diff --git a/GraphicsManager/Objects/Core/Shader.cs b/GraphicsManager/Objects/Core/Shader.cs index 1547a2a..120269d 100755 --- a/GraphicsManager/Objects/Core/Shader.cs +++ b/GraphicsManager/Objects/Core/Shader.cs @@ -109,6 +109,13 @@ public class Shader : IDisposable GL.Uniform1(location, value); } + + public void SetInt(string name) + { + int location = GL.GetUniformLocation(Handle, name); + + GL.Uniform1(location, location); + } public Shader Clone() { diff --git a/GraphicsManager/Objects/Core/Texture.cs b/GraphicsManager/Objects/Core/Texture.cs index 4574fa1..0c8df56 100755 --- a/GraphicsManager/Objects/Core/Texture.cs +++ b/GraphicsManager/Objects/Core/Texture.cs @@ -204,7 +204,7 @@ public class Texture private static Dictionary BadChars = new(); - internal static Texture TextureForChar(IGLFWGraphicsContext con, FontInteraction l, char charter) + internal static Texture TextureForChar(IGLFWGraphicsContext con, FontInteraction l, char charter, Shader s) { try { @@ -229,9 +229,21 @@ public class Texture GlyphSlot glyph = l.CurrentFonts[i].Face.Glyph; FTBitmap bitmap = glyph.Bitmap; Texture t = new(); - t.Unit = TextureUnit.Texture9; + t.Unit = (s.GetUniformLocation("u_texture") switch + { + 0 => TextureUnit.Texture0, + 1 => TextureUnit.Texture1, + 2 => TextureUnit.Texture2, + 3 => TextureUnit.Texture3, + 4 => TextureUnit.Texture4, + 5 => TextureUnit.Texture5, + 6 => TextureUnit.Texture6, + 7 => TextureUnit.Texture7, + 8 => TextureUnit.Texture8, + 9 => TextureUnit.Texture9, + }); GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1); - GL.ActiveTexture(TextureUnit.Texture9); + GL.ActiveTexture(t.Unit); t.handel = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, t.handel); GL.TexImage2D(TextureTarget.Texture2D, 0, diff --git a/GraphicsManager/Objects/Label.cs b/GraphicsManager/Objects/Label.cs index aae8ec1..88a29a4 100755 --- a/GraphicsManager/Objects/Label.cs +++ b/GraphicsManager/Objects/Label.cs @@ -8,15 +8,12 @@ using OpenTK.Windowing.Common; using OpenTK.Windowing.Common.Input; using OpenTK.Windowing.Desktop; using OpenTK.Windowing.GraphicsLibraryFramework; -using SharpFont; -using Encoding = SharpFont.Encoding; namespace GraphicsManager.Objects; public class Label : ILabel { public static readonly Dictionary DefaultTextShader = new(); - //public static readonly Font DefaultFont = Core.Font.MakeFontFromSystem(); public Label(FontFamily fontFamily) { @@ -35,7 +32,7 @@ public class Label : ILabel public Vector2 LocationAsFloat { get { return laf; } } public Vector2 SizeAsFloat { get { return saf; } } - private char? pc = null; + private char? pc; public char? PasswordChar { get => pc; @@ -72,8 +69,8 @@ public class Label : ILabel public int VBO { get; private set; } public Vector2 DIR { get; set; } = new Vector2(1f, 0f); - public int TrueHeight = 0; - public int PostiveTrueHeight = 0; + public int TrueHeight; + public int PostiveTrueHeight; public Vector2i GetSizeOfChar(int Index) { @@ -103,6 +100,7 @@ public class Label : ILabel return new((int)addx, (int)addy); } + public string Text { get => text; @@ -176,8 +174,7 @@ public class Label : ILabel public float Scale { get; set; } = 1.0f; public Color4 Color { get; set; } = new Color4(255, 255, 255, 255); public Vector2i Distance { get; set; } - private Vector3i loc_ = new(); - private int maxy = 0, maxx = 0; + private Vector3i loc_; public Vector3i Location { get @@ -190,7 +187,6 @@ public class Label : ILabel if (Window is null || Parent is null) return; if (Window.CanControleUpdate && Loaded) { - // = Parent.GetParentRelLocPoint() + new Vector2i(Location.X, Parent.Size.Y - (loc_.Y + Size.Y)); Parent!.TryDraw(); if (!Window.Context.IsCurrent) Window.Context.MakeCurrent(); } @@ -227,7 +223,6 @@ public class Label : ILabel Loaded = false; Visible = false; } - public Vector2i ScissorLocation { get; private set; } public void Draw(int x, int y, int ww, int hh) { @@ -236,7 +231,7 @@ public class Label : ILabel if (!Window!.Context.IsCurrent) Window.Context.MakeCurrent(); Shader.Use(); GL.Enable(EnableCap.Blend); - GL.Uniform4(2, Color); + GL.Uniform4(Shader.GetUniformLocation("textColor"), Color); Matrix4 projectionM = Matrix4.CreateOrthographicOffCenter(0, Window!.Size.X, Window!.Size.Y, 0, -1.0f, 1.0f); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); GL.BlendFunc(0, BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); @@ -250,7 +245,19 @@ public class Label : ILabel float char_x = 0.0f; GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1); - GL.ActiveTexture(TextureUnit.Texture9); + GL.ActiveTexture((Shader.GetUniformLocation("u_texture") switch + { + 0 => TextureUnit.Texture0, + 1 => TextureUnit.Texture1, + 2 => TextureUnit.Texture2, + 3 => TextureUnit.Texture3, + 4 => TextureUnit.Texture4, + 5 => TextureUnit.Texture5, + 6 => TextureUnit.Texture6, + 7 => TextureUnit.Texture7, + 8 => TextureUnit.Texture8, + 9 => TextureUnit.Texture9, + })); float hhh = 0f; for (int i = 0; i < Text.Length; i++) @@ -263,7 +270,7 @@ public class Label : ILabel bool n = (c == '\n'); if (!_characters[Window!.Context][Font].ContainsKey(c) && !n) { - Texture f = Texture.TextureForChar(Window!.Context, Font, c); + Texture f = Texture.TextureForChar(Window!.Context, Font, c, Shader); } int maxx = 0; @@ -349,19 +356,6 @@ public class Label : ILabel GlobalBuffers[win.Context] = new(VBO, VAO, tup.Item3 + 1); - -/* - VBO = GL.GenBuffer(); - GL.BindBuffer(BufferTarget.ArrayBuffer, VBO); - GL.BufferData(BufferTarget.ArrayBuffer, 4 * 6 * 4, vquad, BufferUsageHint.StaticDraw); - - VAO = GL.GenVertexArray(); - GL.BindVertexArray(VAO); - GL.EnableVertexAttribArray(0); - GL.VertexAttribPointer(0, 2, VertexAttribPointerType.Float, false, 4 * 4, 0); - GL.EnableVertexAttribArray(1); - GL.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, 4 * 4, 2 * 4); -*/ GL.BindBuffer(BufferTarget.ArrayBuffer, 0); GL.BindVertexArray(0); @@ -382,7 +376,7 @@ public class Label : ILabel public MouseCursor HoverMouse { get; set; } = MouseCursor.Default; - private bool mi = false; + private bool mi; public bool MouseInside { @@ -410,5 +404,5 @@ public class Label : ILabel public event Func? MouseLeave; public object? Tag { get; set; } = null; - public bool Loaded { get; private set; } = false; + public bool Loaded { get; private set; } } diff --git a/GraphicsManager/Objects/RainbowLabel.cs b/GraphicsManager/Objects/RainbowLabel.cs index a51fd6b..f6b2167 100755 --- a/GraphicsManager/Objects/RainbowLabel.cs +++ b/GraphicsManager/Objects/RainbowLabel.cs @@ -241,7 +241,19 @@ public class RainbowLabel : ILabel float char_x = 0.0f; GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1); - GL.ActiveTexture(TextureUnit.Texture9); + GL.ActiveTexture((Shader.GetUniformLocation("u_texture") switch + { + 0 => TextureUnit.Texture0, + 1 => TextureUnit.Texture1, + 2 => TextureUnit.Texture2, + 3 => TextureUnit.Texture3, + 4 => TextureUnit.Texture4, + 5 => TextureUnit.Texture5, + 6 => TextureUnit.Texture6, + 7 => TextureUnit.Texture7, + 8 => TextureUnit.Texture8, + 9 => TextureUnit.Texture9, + })); float hhh = 0f; for (int i = 0; i < Text.Length; i++) @@ -256,7 +268,7 @@ public class RainbowLabel : ILabel bool n = (c == '\n'); if (!Label._characters[Window!.Context][Font].ContainsKey(c) && !n) { - Texture f = Texture.TextureForChar(Window!.Context, Font, c); + Texture f = Texture.TextureForChar(Window!.Context, Font, c, Shader); } int maxx = 0; diff --git a/GraphicsManager/Resources/Shaders/Label.frag b/GraphicsManager/Resources/Shaders/Label.frag index 6c28bfa..66142a2 100755 --- a/GraphicsManager/Resources/Shaders/Label.frag +++ b/GraphicsManager/Resources/Shaders/Label.frag @@ -12,5 +12,5 @@ void main() { vec2 uv = vUV.xy; float text = texture(u_texture, uv).r; - fragColor = vec4(textColor.r*text, textColor.g*text, textColor.b*text, textColor.a*text); + fragColor = textColor*text; } \ No newline at end of file diff --git a/GraphicsManager/Window.cs b/GraphicsManager/Window.cs index 42cee06..82d3669 100755 --- a/GraphicsManager/Window.cs +++ b/GraphicsManager/Window.cs @@ -62,7 +62,7 @@ public class Window : NativeWindow , IWindow { Rectangle.DefaultAlphaTextureShader.Add(Context, new("AlphaChannelTexture", true, Texture:true)); Rectangle.DefaultAlphaTextureShader[Context].Use(); - Rectangle.DefaultAlphaTextureShader[Context].SetInt("bob", 0); + Rectangle.DefaultAlphaTextureShader[Context].SetInt("bob", 0); Rectangle.DefaultAlphaTextureShader[Context].SetInt("smith", 1); } @@ -70,8 +70,7 @@ public class Window : NativeWindow , IWindow { Label.DefaultTextShader.Add(Context, new("Label", true)); Label.DefaultTextShader[Context].Use(); - Label.DefaultTextShader[Context].SetInt("u_texture", 9); - Label.DefaultTextShader[Context].SetInt("textColor", 2); + Label.DefaultTextShader[Context].SetInt("u_texture", Label.DefaultTextShader[Context].GetUniformLocation("u_texture")); } if (!Label._characters.ContainsKey(Context)) Label._characters.Add(Context, new()); last = WindowState;