Multi-platform .NET bindings to the Ultralight project.
at master 2.4 kB view raw
1using Silk.NET.OpenGLES; 2 3partial class Program { 4 5 private static bool _useBlitting = false; 6 7 private static double _scaleX = 1; 8 9 private static double _scaleY = 1; 10 11 private static unsafe void OnRender(double delta) //Method needs to be unsafe due to draw elements. 12 { 13 // ReSharper disable once ConditionIsAlwaysTrueOrFalse 14 if (_gl == null) 15 return; 16 17 _ulRenderer.Render(); 18 _gpuDriverSite.Render(_snView); 19 20 { 21 var wndSize = _snView.Size; 22 var wndWidth = (uint) wndSize.Width; 23 var wndHeight = (uint) wndSize.Height; 24 var width = (uint) (_scaleX * wndWidth); 25 var height = (uint) (_scaleY * wndHeight); 26 27 _gl.BindFramebuffer(FramebufferTarget.Framebuffer, 0); 28 _gl.Viewport(0, 0, width, height); 29 _gl.ClearColor(0, 0, 0, 0); 30 _gl.Clear((uint) ClearBufferMask.ColorBufferBit); 31 32 _gpuDriverSite.TryGetFrameBufferAndTexture(_ulView, out var rb, out var tex, out var texWidth, out var texHeight); 33 34 if (_useBlitting) { 35 // /* 36 //_gl.Disable(EnableCap.FramebufferSrgb); 37 _gl.Disable(EnableCap.ScissorTest); 38 _gl.Disable(EnableCap.Blend); 39 //Bind the primary framebuffer, quad geometry and shader. 40 _gl.BindFramebuffer(FramebufferTarget.ReadFramebuffer, rb); 41 _gl.ReadBuffer(ReadBufferMode.ColorAttachment0); 42 _gl.BindFramebuffer(FramebufferTarget.DrawFramebuffer, 0); 43 //_gl.ClearColor(0, 0, 0, 0); 44 //_gl.Clear((uint) ClearBufferMask.ColorBufferBit); 45 46 _gl.BlitFramebuffer( 47 0, 0, (int) texWidth, (int) texHeight, 48 0, 0, (int) width, (int) height, 49 (uint) AttribMask.ColorBufferBit, 50 BlitFramebufferFilter.Linear); 51 } 52 else { 53 //_gl.Disable(EnableCap.FramebufferSrgb); 54 _gl.Disable(EnableCap.ScissorTest); 55 _gl.Disable(EnableCap.Blend); 56 //Bind the primary framebuffer, quad geometry and shader. 57 _gl.BindVertexArray(_qva); 58 _gl.UseProgram(_qpg); 59 _gl.ActiveTexture(TextureUnit.Texture0); 60 _gl.BindTexture(TextureTarget.Texture2D, tex); 61 _gl.Uniform1(_gl.GetUniformLocation(_qpg, "iTex"), 0); 62 CheckGl(); 63 64 //Draw the quad. 65 _gl.DrawElements(PrimitiveType.Triangles, 66 (uint) _quadIndices.Length, DrawElementsType.UnsignedInt, null); 67 } 68 } 69 } 70 71}