FIX AMD location issue

This commit is contained in:
JacobTech 2024-03-29 10:54:51 -04:00
parent 13dc6cb820
commit 31fb6d7e43
7 changed files with 63 additions and 39 deletions

View File

@ -10,7 +10,7 @@
<IncludeSymbols>False</IncludeSymbols> <IncludeSymbols>False</IncludeSymbols>
<RepositoryUrl>https://git.jacobtech.com/JacobTech.com/GraphicsManager</RepositoryUrl> <RepositoryUrl>https://git.jacobtech.com/JacobTech.com/GraphicsManager</RepositoryUrl>
<RepositoryType>git</RepositoryType> <RepositoryType>git</RepositoryType>
<Version>1.0.8-alpha82</Version> <Version>1.0.8-alpha99</Version>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
@ -34,7 +34,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="OpenTK" Version="4.7.1" /> <PackageReference Include="OpenTK" Version="4.7.1" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.3" /> <PackageReference Include="SixLabors.ImageSharp" Version="2.1.7" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta15" /> <PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta15" />
<PackageReference Include="SpaceWizards.SharpFont" Version="1.0.1" /> <PackageReference Include="SpaceWizards.SharpFont" Version="1.0.1" />
</ItemGroup> </ItemGroup>

View File

@ -110,6 +110,13 @@ public class Shader : IDisposable
GL.Uniform1(location, value); GL.Uniform1(location, value);
} }
public void SetInt(string name)
{
int location = GL.GetUniformLocation(Handle, name);
GL.Uniform1(location, location);
}
public Shader Clone() public Shader Clone()
{ {
return (Shader)MemberwiseClone(); return (Shader)MemberwiseClone();

View File

@ -204,7 +204,7 @@ public class Texture
private static Dictionary<FontInteraction, Texture> BadChars = new(); private static Dictionary<FontInteraction, Texture> 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 try
{ {
@ -229,9 +229,21 @@ public class Texture
GlyphSlot glyph = l.CurrentFonts[i].Face.Glyph; GlyphSlot glyph = l.CurrentFonts[i].Face.Glyph;
FTBitmap bitmap = glyph.Bitmap; FTBitmap bitmap = glyph.Bitmap;
Texture t = new(); 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.PixelStore(PixelStoreParameter.UnpackAlignment, 1);
GL.ActiveTexture(TextureUnit.Texture9); GL.ActiveTexture(t.Unit);
t.handel = GL.GenTexture(); t.handel = GL.GenTexture();
GL.BindTexture(TextureTarget.Texture2D, t.handel); GL.BindTexture(TextureTarget.Texture2D, t.handel);
GL.TexImage2D(TextureTarget.Texture2D, 0, GL.TexImage2D(TextureTarget.Texture2D, 0,

View File

@ -8,15 +8,12 @@ using OpenTK.Windowing.Common;
using OpenTK.Windowing.Common.Input; using OpenTK.Windowing.Common.Input;
using OpenTK.Windowing.Desktop; using OpenTK.Windowing.Desktop;
using OpenTK.Windowing.GraphicsLibraryFramework; using OpenTK.Windowing.GraphicsLibraryFramework;
using SharpFont;
using Encoding = SharpFont.Encoding;
namespace GraphicsManager.Objects; namespace GraphicsManager.Objects;
public class Label : ILabel public class Label : ILabel
{ {
public static readonly Dictionary<IGLFWGraphicsContext, Shader> DefaultTextShader = new(); public static readonly Dictionary<IGLFWGraphicsContext, Shader> DefaultTextShader = new();
//public static readonly Font DefaultFont = Core.Font.MakeFontFromSystem();
public Label(FontFamily fontFamily) public Label(FontFamily fontFamily)
{ {
@ -35,7 +32,7 @@ public class Label : ILabel
public Vector2 LocationAsFloat { get { return laf; } } public Vector2 LocationAsFloat { get { return laf; } }
public Vector2 SizeAsFloat { get { return saf; } } public Vector2 SizeAsFloat { get { return saf; } }
private char? pc = null; private char? pc;
public char? PasswordChar public char? PasswordChar
{ {
get => pc; get => pc;
@ -72,8 +69,8 @@ public class Label : ILabel
public int VBO { get; private set; } public int VBO { get; private set; }
public Vector2 DIR { get; set; } = new Vector2(1f, 0f); public Vector2 DIR { get; set; } = new Vector2(1f, 0f);
public int TrueHeight = 0; public int TrueHeight;
public int PostiveTrueHeight = 0; public int PostiveTrueHeight;
public Vector2i GetSizeOfChar(int Index) public Vector2i GetSizeOfChar(int Index)
{ {
@ -103,6 +100,7 @@ public class Label : ILabel
return new((int)addx, (int)addy); return new((int)addx, (int)addy);
} }
public string Text public string Text
{ {
get => text; get => text;
@ -176,8 +174,7 @@ public class Label : ILabel
public float Scale { get; set; } = 1.0f; public float Scale { get; set; } = 1.0f;
public Color4 Color { get; set; } = new Color4(255, 255, 255, 255); public Color4 Color { get; set; } = new Color4(255, 255, 255, 255);
public Vector2i Distance { get; set; } public Vector2i Distance { get; set; }
private Vector3i loc_ = new(); private Vector3i loc_;
private int maxy = 0, maxx = 0;
public Vector3i Location public Vector3i Location
{ {
get get
@ -190,7 +187,6 @@ public class Label : ILabel
if (Window is null || Parent is null) return; if (Window is null || Parent is null) return;
if (Window.CanControleUpdate && Loaded) if (Window.CanControleUpdate && Loaded)
{ {
// = Parent.GetParentRelLocPoint() + new Vector2i(Location.X, Parent.Size.Y - (loc_.Y + Size.Y));
Parent!.TryDraw(); Parent!.TryDraw();
if (!Window.Context.IsCurrent) Window.Context.MakeCurrent(); if (!Window.Context.IsCurrent) Window.Context.MakeCurrent();
} }
@ -227,7 +223,6 @@ public class Label : ILabel
Loaded = false; Loaded = false;
Visible = false; Visible = false;
} }
public Vector2i ScissorLocation { get; private set; }
public void Draw(int x, int y, int ww, int hh) 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(); if (!Window!.Context.IsCurrent) Window.Context.MakeCurrent();
Shader.Use(); Shader.Use();
GL.Enable(EnableCap.Blend); 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); Matrix4 projectionM = Matrix4.CreateOrthographicOffCenter(0, Window!.Size.X, Window!.Size.Y, 0, -1.0f, 1.0f);
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
GL.BlendFunc(0, BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.BlendFunc(0, BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
@ -250,7 +245,19 @@ public class Label : ILabel
float char_x = 0.0f; float char_x = 0.0f;
GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1); 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; float hhh = 0f;
for (int i = 0; i < Text.Length; i++) for (int i = 0; i < Text.Length; i++)
@ -263,7 +270,7 @@ public class Label : ILabel
bool n = (c == '\n'); bool n = (c == '\n');
if (!_characters[Window!.Context][Font].ContainsKey(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; int maxx = 0;
@ -349,19 +356,6 @@ public class Label : ILabel
GlobalBuffers[win.Context] = new(VBO, VAO, tup.Item3 + 1); 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.BindBuffer(BufferTarget.ArrayBuffer, 0);
GL.BindVertexArray(0); GL.BindVertexArray(0);
@ -382,7 +376,7 @@ public class Label : ILabel
public MouseCursor HoverMouse { get; set; } = MouseCursor.Default; public MouseCursor HoverMouse { get; set; } = MouseCursor.Default;
private bool mi = false; private bool mi;
public bool MouseInside public bool MouseInside
{ {
@ -410,5 +404,5 @@ public class Label : ILabel
public event Func<IRenderObject, Task>? MouseLeave; public event Func<IRenderObject, Task>? MouseLeave;
public object? Tag { get; set; } = null; public object? Tag { get; set; } = null;
public bool Loaded { get; private set; } = false; public bool Loaded { get; private set; }
} }

View File

@ -241,7 +241,19 @@ public class RainbowLabel : ILabel
float char_x = 0.0f; float char_x = 0.0f;
GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1); 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; float hhh = 0f;
for (int i = 0; i < Text.Length; i++) for (int i = 0; i < Text.Length; i++)
@ -256,7 +268,7 @@ public class RainbowLabel : ILabel
bool n = (c == '\n'); bool n = (c == '\n');
if (!Label._characters[Window!.Context][Font].ContainsKey(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; int maxx = 0;

View File

@ -12,5 +12,5 @@ void main()
{ {
vec2 uv = vUV.xy; vec2 uv = vUV.xy;
float text = texture(u_texture, uv).r; float text = texture(u_texture, uv).r;
fragColor = vec4(textColor.r*text, textColor.g*text, textColor.b*text, textColor.a*text); fragColor = textColor*text;
} }

View File

@ -70,8 +70,7 @@ public class Window : NativeWindow , IWindow
{ {
Label.DefaultTextShader.Add(Context, new("Label", true)); Label.DefaultTextShader.Add(Context, new("Label", true));
Label.DefaultTextShader[Context].Use(); Label.DefaultTextShader[Context].Use();
Label.DefaultTextShader[Context].SetInt("u_texture", 9); Label.DefaultTextShader[Context].SetInt("u_texture", Label.DefaultTextShader[Context].GetUniformLocation("u_texture"));
Label.DefaultTextShader[Context].SetInt("textColor", 2);
} }
if (!Label._characters.ContainsKey(Context)) Label._characters.Add(Context, new()); if (!Label._characters.ContainsKey(Context)) Label._characters.Add(Context, new());
last = WindowState; last = WindowState;