diff --git a/SMCode/SM.OGL/Mesh/GenericMesh.cs b/SMCode/SM.OGL/Mesh/GenericMesh.cs index cadd423..96e4b76 100644 --- a/SMCode/SM.OGL/Mesh/GenericMesh.cs +++ b/SMCode/SM.OGL/Mesh/GenericMesh.cs @@ -103,6 +103,29 @@ namespace SM.OGL.Mesh GL.BindVertexArray(0); } + /// + /// This updates the parts of the mesh, that needs updating. + /// + public void Update() + { + if (!WasCompiled) + { + Compile(); + return; + } + + GL.BindVertexArray(_id); + + UpdateBoundingBox(); + + foreach(var attrib in Attributes) + { + if (attrib.ConnectedVBO == null || !attrib.ConnectedVBO.Active || !attrib.ConnectedVBO.CanBeUpdated) continue; + attrib.ConnectedVBO.Update(); + } + + } + /// public override void Dispose() { diff --git a/SMCode/SM.OGL/Mesh/VBO.cs b/SMCode/SM.OGL/Mesh/VBO.cs index 738bb60..1fee8cc 100644 --- a/SMCode/SM.OGL/Mesh/VBO.cs +++ b/SMCode/SM.OGL/Mesh/VBO.cs @@ -1,5 +1,6 @@ #region usings +using System; using System.Collections.Generic; using OpenTK; using OpenTK.Graphics; @@ -14,6 +15,11 @@ namespace SM.OGL.Mesh /// public class VBO : List { + /// + /// The ID for the buffer. + /// + public int BufferID { get; private set; } + /// /// Specifies the expected usage pattern of the data store. /// @@ -51,6 +57,11 @@ namespace SM.OGL.Mesh /// public VertexAttribPointerType PointerType; + /// + /// If true it can be updated, otherwise it will get ignored, when the mesh gets updated. + /// + public bool CanBeUpdated = false; + /// /// Generates a VBO for inserting mesh data. /// @@ -91,12 +102,18 @@ namespace SM.OGL.Mesh Normalised = normalised; } + public void Add(float x) + { + CanBeUpdated = true; + } + /// /// Adds two values to the VBO. /// public void Add(float x, float y) { AddRange(new[] {x, y}); + CanBeUpdated = true; } /// @@ -105,6 +122,7 @@ namespace SM.OGL.Mesh public void Add(float x, float y, float z) { AddRange(new[] {x, y, z}); + CanBeUpdated = true; } /// @@ -113,6 +131,7 @@ namespace SM.OGL.Mesh public void Add(float x, float y, float z, float w) { AddRange(new[] {x, y, z, w}); + CanBeUpdated = true; } /// @@ -205,13 +224,23 @@ namespace SM.OGL.Mesh var data = ToArray(); - var buffer = GL.GenBuffer(); - GL.BindBuffer(BufferTarget.ArrayBuffer, buffer); + BufferID = GL.GenBuffer(); + GL.BindBuffer(BufferTarget.ArrayBuffer, BufferID); GL.BufferData(BufferTarget.ArrayBuffer, data.Length * sizeof(float), data, BufferUsageHint); GL.VertexAttribPointer(attribID, PointerSize, PointerType, Normalised, PointerStride, PointerOffset); GL.EnableVertexAttribArray(attribID); GL.BindBuffer(BufferTarget.ArrayBuffer, 0); + + CanBeUpdated = false; + } + + internal void Update() + { + var data = ToArray(); + + GL.BindBuffer(BufferTarget.ArrayBuffer, BufferID); + GL.BufferSubData(BufferTarget.ArrayBuffer, IntPtr.Zero, data.Length * sizeof(float), data); } } } \ No newline at end of file diff --git a/SM_TEST/Program.cs b/SM_TEST/Program.cs index e0e3412..6feb15a 100644 --- a/SM_TEST/Program.cs +++ b/SM_TEST/Program.cs @@ -4,9 +4,12 @@ using OpenTK; using OpenTK.Graphics; using OpenTK.Input; using SM.Base; +using SM.Base.Time; using SM.Base.Window; using SM2D; +using SM2D.Controls; using SM2D.Drawing; +using SM2D.Object; using SM2D.Pipelines; using SM2D.Scene; using Font = SM.Base.Drawing.Text.Font; @@ -19,6 +22,7 @@ namespace SM_TEST static Scene scene; private static Font font; private static GLWindow window; + private static PolyLine line; static void Main(string[] args) { window = new GLWindow(); @@ -26,15 +30,14 @@ namespace SM_TEST window.SetRenderPipeline(new TestRenderPipeline()); window.SetScene(scene = new Scene()); - scene.Objects.Add(new DrawObject2D()); - scene.Objects.Add(new DrawObject2D() + + line = new PolyLine(new Vector2[] { Vector2.Zero, Vector2.One }, PolyLineType.Connected); + var display = new DrawObject2D() { - Transform = - { - Position = new SM.Base.Types.CVector2(20,20), - ZIndex = new SM.Base.Types.CVector1(1) - } - }); + Mesh = line + }; + display.Transform.Size.Set(1); + scene.Objects.Add(display); window.UpdateFrame += WindowOnUpdateFrame; window.Run(); @@ -44,13 +47,10 @@ namespace SM_TEST private static void WindowOnUpdateFrame(object sender, FrameEventArgs e) { - if (SM.Base.Controls.Keyboard.IsDown(Key.F, true)) - { - window.WindowFlags = WindowFlags.ExclusiveFullscreen; - window.ChangeFullscreenResolution(DisplayDevice.Default.SelectResolution(1280,720, DisplayDevice.Default.BitsPerPixel, DisplayDevice.Default.RefreshRate)); - } - if (SM.Base.Controls.Keyboard.IsDown(Key.W, true)) window.WindowFlags = WindowFlags.Window; - if (SM.Base.Controls.Keyboard.IsDown(Key.B, true)) window.WindowFlags = WindowFlags.BorderlessWindow; + + line.Vertex.RemoveRange(3, 3); + line.Vertex.Add(Mouse2D.InWorld(window.ViewportCamera as Camera), 0); + line.Update(); } diff --git a/SM_TEST/TestRenderPipeline.cs b/SM_TEST/TestRenderPipeline.cs index 117db39..9e3d3c3 100644 --- a/SM_TEST/TestRenderPipeline.cs +++ b/SM_TEST/TestRenderPipeline.cs @@ -20,7 +20,7 @@ namespace SM_TEST Framebuffers.Add(_postBuffer); _bloom = new BloomEffect(_postBuffer, hdr: true, .5f) { - Threshold = .8f, + Threshold = .5f, };