Multi-platform .NET bindings to the Ultralight project.

fix pointer being passed to clip

add dpi awareness

simplify demo html

+104 -66
+5 -5
SilkNetSandbox/Program.OnLoad.cs
··· 32 32 33 33 //Vertex data, uploaded to the VBO. 34 34 ReadOnlySpan<float> vertices = stackalloc float[] { 35 - //X Y Z 36 - 0.5f, 0.5f, 0f, 37 - 0.5f, -0.5f, 0f, 38 - -0.5f, -0.5f, 0f, 39 - -0.5f, 0.5f, 0.5f 35 + //X Y Z 36 + 1f, 1f, 0f, 37 + 1f, -1f, 0f, 38 + -1f, -1f, 0f, 39 + -1f, 1f, 1f 40 40 }; 41 41 var pVertices = Unsafe.AsPointer(ref Unsafe.AsRef(vertices.GetPinnableReference())); 42 42 var verticesSize = vertices.Length * sizeof(float);
+14 -11
SilkNetSandbox/Program.OnRender.cs
··· 1 1 using System; 2 2 using System.Collections.Generic; 3 3 using System.Diagnostics; 4 + using System.Numerics; 4 5 using System.Runtime.CompilerServices; 5 6 using System.Runtime.InteropServices; 6 7 using Silk.NET.OpenGLES; ··· 15 16 private static unsafe void OnRender(double delta) //Method needs to be unsafe due to draw elements. 16 17 { 17 18 if (_haveRendered++ < 2) { 18 - Debugger.Break(); 19 + //Debugger.Break(); 19 20 //Bind the primary framebuffer, quad geometry and shader. 20 21 var wndSize = _wnd.Size; 21 22 var wndWidth = (uint) wndSize.Width; ··· 24 25 _gl.BindFramebuffer(FramebufferTarget.Framebuffer, 0); 25 26 _gl.BindFramebuffer(FramebufferTarget.ReadFramebuffer, 0); 26 27 _gl.BindFramebuffer(FramebufferTarget.DrawFramebuffer, 0); 27 - _gl.ClearColor(0.5f, 0.5f, 0.5f, 0); 28 + _gl.ClearColor(0, 0, 0, 0); 28 29 _gl.Clear((uint) ClearBufferMask.ColorBufferBit); 29 30 return; 30 31 } ··· 105 106 state.ViewportHeight, 106 107 1 107 108 ); 108 - var txf = Ultralight.ApplyProjection( 109 + var txf = 110 + Ultralight.ApplyProjection( 109 111 state.Transform, 110 112 state.ViewportWidth, 111 113 state.ViewportWidth, 112 - true 114 + false 113 115 ); 114 116 _gl.UniformMatrix4( 115 117 _gl.GetUniformLocation(pg, "Transform"), 1, false, ··· 129 131 ); 130 132 _gl.UniformMatrix4( 131 133 _gl.GetUniformLocation(pg, "Clip"), 8, false, 132 - (float*) Unsafe.AsPointer(ref Unsafe.AsRef(state)) 134 + (float*) Unsafe.AsPointer(ref Unsafe.AsRef(state.Clip)) 133 135 ); 134 136 135 137 CheckGl(); ··· 148 150 CheckGl(); 149 151 } 150 152 else { 151 - Console.WriteLine($"Texture1 Invalid: {texIndex1 + 1}"); 153 + //Console.WriteLine($"Texture1 Invalid: {texIndex1 + 1}"); 152 154 _gl.ActiveTexture(TextureUnit.Texture0); 153 155 _gl.BindTexture(GLEnum.Texture2D, 0); 154 156 } ··· 161 163 CheckGl(); 162 164 } 163 165 else { 164 - Console.WriteLine($"Texture2 Invalid: {texIndex2 + 1}"); 166 + //Console.WriteLine($"Texture2 Invalid: {texIndex2 + 1}"); 165 167 _gl.ActiveTexture(TextureUnit.Texture1); 166 168 _gl.BindTexture(GLEnum.Texture2D, 0); 167 169 } ··· 174 176 CheckGl(); 175 177 } 176 178 else { 177 - Console.WriteLine($"Texture3 Invalid: {texIndex3 + 1}"); 179 + //Console.WriteLine($"Texture3 Invalid: {texIndex3 + 1}"); 178 180 _gl.ActiveTexture(TextureUnit.Texture2); 179 181 _gl.BindTexture(GLEnum.Texture2D, 0); 180 182 } ··· 223 225 var wndWidth = (uint) wndSize.Width; 224 226 var wndHeight = (uint) wndSize.Height; 225 227 226 - var rbEntry = RenderBufferEntries[0]; 228 + //var rbEntry = RenderBufferEntries[0]; 227 229 //var rb = rbEntry.FrameBuffer; 228 230 var texEntry = TextureEntries[0]; //rbEntry.TextureEntry; 229 231 var tex = texEntry.Texure; ··· 236 238 //_gl.BindFramebuffer(FramebufferTarget.ReadFramebuffer, rb); 237 239 //_gl.ReadBuffer(ReadBufferMode.ColorAttachment0); 238 240 _gl.BindFramebuffer(FramebufferTarget.DrawFramebuffer, 0); 239 - _gl.ClearColor(0.5f, 0.5f, 0.5f, 0); 241 + _gl.ClearColor(0, 0, 0, 0); 240 242 _gl.Clear((uint) ClearBufferMask.ColorBufferBit); 241 243 /* 242 244 _gl.BlitFramebuffer( ··· 258 260 CheckGl(); 259 261 260 262 //Draw the geometry. 261 - _gl.DrawElements(PrimitiveType.Triangles, (uint) _indicesSize, DrawElementsType.UnsignedInt, null); 263 + _gl.DrawElements(PrimitiveType.Triangles, 264 + (uint) _indicesSize, DrawElementsType.UnsignedInt, null); 262 265 //*/ 263 266 } 264 267 }
+11
SilkNetSandbox/Program.cs
··· 19 19 20 20 partial class Program { 21 21 22 + static Program() 23 + { 24 + // ReSharper disable once InvertIf 25 + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) 26 + { 27 + Windows.User32.SetProcessDPIAware(); 28 + Windows.User32.SetProcessDpiAwarenessContext(Windows.User32.DpiAwarenessContext.PerMonitorAwareV2); 29 + Windows.ShCore.SetProcessDpiAwareness(Windows.ShCore.ProcessDpiAwareness.PerMonitorDpiAware); 30 + } 31 + } 32 + 22 33 private static IWindow _wnd; 23 34 24 35 private static GL _gl;
+27
SilkNetSandbox/Windows/ShCore.cs
··· 1 + using System; 2 + using System.Runtime.InteropServices; 3 + 4 + namespace Windows 5 + { 6 + 7 + internal static class ShCore 8 + { 9 + 10 + [DllImport("ShCore", SetLastError = true)] 11 + internal static extern bool SetProcessDpiAwareness(ProcessDpiAwareness awareness); 12 + 13 + [Flags] 14 + internal enum ProcessDpiAwareness 15 + { 16 + 17 + DpiUnaware = 0, 18 + 19 + SystemDpiAware = 1, 20 + 21 + PerMonitorDpiAware = 2 22 + 23 + } 24 + 25 + } 26 + 27 + }
+33
SilkNetSandbox/Windows/User32.cs
··· 1 + using System; 2 + using System.Runtime.InteropServices; 3 + 4 + namespace Windows 5 + { 6 + 7 + internal static class User32 8 + { 9 + 10 + [DllImport("user32", SetLastError = true)] 11 + internal static extern bool SetProcessDpiAwarenessContext(DpiAwarenessContext dpiFlag); 12 + 13 + [DllImport("user32", SetLastError = true)] 14 + internal static extern bool SetProcessDPIAware(); 15 + 16 + [Flags] 17 + internal enum DpiAwarenessContext 18 + { 19 + 20 + Unaware = 16, 21 + 22 + SystemAware = 17, 23 + 24 + PerMonitorAware = 18, 25 + 26 + PerMonitorAwareV2 = 34 27 + 28 + } 29 + 30 + 31 + } 32 + 33 + }
+12 -47
SilkNetSandbox/assets/index.html
··· 1 1 <html lang="en"> 2 2 <head> 3 - <style type="text/css"> 4 - body { 5 - margin: 0; 6 - padding: 0; 7 - overflow: hidden; 8 - color: black; 9 - font-family: Roboto, sans-serif; 10 - background: linear-gradient(-45deg, #acb4ff, #f5d4e2); 11 - display: flex; 12 - justify-content: center; 13 - align-items: center; 14 - align-content: center; 15 - font-size: 42pt; 16 - } 17 - 18 - main { 19 - text-align: center; 20 - border-radius: 25px; 21 - background: linear-gradient(-45deg, #e5eaf9, #f9eaf6); 22 - box-shadow: 0 7px 18px -6px #8f8ae1; 23 - max-width: 80vw; 24 - } 25 - 26 - h1 { 27 - display: inline-block; 28 - padding: 0; 29 - margin: .5rem; 30 - font-size: 1.2em; 31 - } 32 - 33 - p { 34 - display: inline-block; 35 - background: white; 36 - padding: .4em; 37 - margin: 10px; 38 - border-radius: 25px; 39 - } 3 + <title>UltralightSharp Demo</title> 4 + <style> 5 + div { 6 + width:1px; 7 + height:1px; 8 + display:inline-block; 9 + line-height: 0; 10 + padding: 0; 11 + margin: 0; 12 + border: none; 13 + } 40 14 </style> 41 - <title>UltralightSharp Demo</title> 42 15 </head> 43 - <body> 44 - <main> 45 - <h1>UltralightSharp Demo</h1> 46 - <p> 47 - Multiplatform<br> 48 - <b>C&sharp;</b> Bindings! 49 - </p> 50 - </main> 51 - </body> 16 + <body style="margin:0"><div style="background:#2cf"></div><div style="background:#fc2"></div><br/><div style="background:#cf2"></div><div style="background:#2fc"></div></body> 52 17 </html>
+1 -2
SilkNetSandbox/embedded/basic.frag.glsl
··· 10 10 11 11 void main() 12 12 { 13 - oColor = vec4(fUv.x,fUv.y,1,1); 14 - oColor = mix(texture(iTex, fUv), oColor, .1); 13 + oColor = texture(iTex, fUv); 15 14 }
+1 -1
SilkNetSandbox/embedded/basic.vert.glsl
··· 8 8 void main() 9 9 { 10 10 gl_Position = vec4(vPos.x, vPos.y, vPos.z, 1.0); 11 - fUv = vPos.xy + vec2(1,1); 11 + fUv = vPos.xy + vec2(0.5,0.5); 12 12 }