Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: delete buffers on stop
  • Loading branch information
JeremyMeissner committed Apr 11, 2022
commit ff1746ff1d34ccb6b120cc3e57e84c020eb3ac41
14 changes: 8 additions & 6 deletions FreeFrame/Components/Shapes/Shape.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using OpenTK.Graphics.OpenGL4;
using OpenTK.Graphics.OpenGL4;
using OpenTK.Windowing.Desktop;

namespace FreeFrame.Components.Shapes
Expand Down Expand Up @@ -92,7 +88,13 @@ public void Draw()
GL.BindVertexArray(_vertexArrayObject);
GL.DrawElements(PrimitiveType.Triangles, _indexCount, DrawElementsType.UnsignedInt, 0);
}

public void DeleteObjects()
{
GL.DeleteBuffer(_vertexBufferObject);
GL.DeleteBuffer(_indexBufferObject);
GL.DeleteVertexArray(_vertexArrayObject);
_shader.Delete();
}
/// <summary>
/// Should update the size and the position to the new Window size
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion FreeFrame/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ static void Main()
{
NativeWindowSettings nativeWindowSettings = new()
{
Size = new Vector2i(600, 600),
Size = new Vector2i(800, 600),
Title = "FreeFrame"
};
using Window window = new(GameWindowSettings.Default, nativeWindowSettings); // Create window context (GLFW, OpenGL)
Expand Down
3 changes: 2 additions & 1 deletion FreeFrame/Shader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public Shader(string uriVertexShader, string uriFragementShader)
}
public int GetUniformLocation(string uniform) => GL.GetUniformLocation(_program, uniform);
public void Use() => GL.UseProgram(_program);
~Shader() => GL.DeleteProgram(_program);
public void Delete() => GL.DeleteProgram(_program);
~Shader() => Delete();
}
}
27 changes: 12 additions & 15 deletions FreeFrame/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ protected override void OnRenderFrame(FrameEventArgs e)

if (_shapes != null)
{

_shapes[0].UpdateProperties();
_shapes[0].Draw();
}
Expand All @@ -91,12 +90,14 @@ protected override void OnUnload()
{
base.OnUnload();

Console.WriteLine("Program stops");

GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
GL.BindVertexArray(0);
GL.UseProgram(0);

// TODO: Delete the buffer in the Shape class
_shapes.ForEach(shape => shape.DeleteObjects());
}
public void ShowUI()
{
Expand All @@ -106,6 +107,7 @@ public void ShowUI()
ImGui.GetStyle().TabRounding = 0.0f;


// Parameters side
ImGui.Begin("Parameters", ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoTitleBar);
ImGui.SetWindowSize(new System.Numerics.Vector2(200, ClientSize.Y / 2));
ImGui.SetWindowPos(new System.Numerics.Vector2(ClientSize.X - ImGui.GetWindowWidth(), 0));
Expand All @@ -125,10 +127,9 @@ public void ShowUI()
ImGui.Text("Color");
ImGui.Spacing();
ImGui.ColorEdit4("Color", ref _ioColor);

ImGui.End();


// Tree view side
ImGui.Begin("Tree view", ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoTitleBar);
ImGui.SetWindowSize(new System.Numerics.Vector2(200, ClientSize.Y / 2));
ImGui.SetWindowPos(new System.Numerics.Vector2(ClientSize.X - ImGui.GetWindowWidth(), ClientSize.Y / 2));
Expand All @@ -140,24 +141,23 @@ public void ShowUI()
ImGui.Selectable("Rectangle");
ImGui.End();


// Animation side
ImGui.Begin("Animation", ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoTitleBar);
ImGui.SetWindowSize(new System.Numerics.Vector2(ClientSize.X / 2, 200));
ImGui.SetWindowPos(new System.Numerics.Vector2(0, ClientSize.Y - ImGui.GetWindowHeight()));
ImGui.Text("Animation");
ImGui.End();


// Timeline side
ImGui.Begin("Timeline", ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoTitleBar);
ImGui.SetWindowSize(new System.Numerics.Vector2(ClientSize.X / 2 - 200, 200));
ImGui.SetWindowPos(new System.Numerics.Vector2(ClientSize.X / 2, ClientSize.Y - ImGui.GetWindowHeight()));
ImGui.Text("Timeline");
ImGui.Spacing();
ImGui.SliderInt("(seconds)", ref _ioTimeline, 0, 60);

ImGui.End();


// Navbar side
ImGui.Begin("NavBar", ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.MenuBar);
ImGui.SetWindowSize(new System.Numerics.Vector2(ClientSize.X - 200, 0));
ImGui.SetWindowPos(new System.Numerics.Vector2(0, 0));
Expand All @@ -167,9 +167,7 @@ public void ShowUI()
if (ImGui.BeginMenu("File"))
{
if (ImGui.MenuItem("Open..", "Ctrl+O"))
{
_dialogFilePicker = true;
}
if (ImGui.BeginMenu("Save"))
{
if (ImGui.MenuItem("Save as PNG", "Ctrl+S"))
Expand Down Expand Up @@ -199,10 +197,10 @@ public void ShowUI()
ImGui.EndPopup();
}

// File picker dialog
if (_dialogFilePicker)
ImGui.OpenPopup("open-file");

if (ImGui.BeginPopupModal("open-file"))
if (ImGui.BeginPopupModal("open-file")) // ImGuiWindowFlags.AlwaysAutoResize
{
var picker = FilePicker.GetFilePicker(this, Path.Combine(Environment.CurrentDirectory, "Content/Atlases"), ".svg");
if (picker.Draw())
Expand All @@ -211,18 +209,17 @@ public void ShowUI()
_shapes.ForEach(shape => shape.GenerateObjects());
FilePicker.RemoveFilePicker(this);
if (compatibilityFlag)
{
_dialogCompatibility = true;
}

}
_dialogFilePicker = false;
ImGui.EndPopup();
}

// Compatibility alert
if (_dialogCompatibility)
ImGui.OpenPopup("Compatibility Problem");
if (ImGui.BeginPopupModal("Compatibility Problem"))
if (ImGui.BeginPopupModal("Compatibility Problem")) // ImGuiWindowFlags.AlwaysAutoResize
{
ImGui.Text("Some SVG elements are not compatible. Go to the list of compatible SVG elements");
ImGui.Separator();
Expand Down