From 9fcbbe7d57eb691aa785d30b4fdca012e4cfab97 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Tue, 29 Nov 2022 22:53:37 -0400 Subject: [PATCH] chore: cleanup OpenGL vertex array + buffers --- src/platform.zig | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/platform.zig b/src/platform.zig index 6f503d1..111a0b0 100644 --- a/src/platform.zig +++ b/src/platform.zig @@ -108,7 +108,7 @@ pub const Gui = struct { } // Returns the VAO ID since it's used in run() - fn generateBuffers() [3]c_uint { + fn generateBuffers() struct { c_uint, c_uint, c_uint } { var vao_id: c_uint = undefined; var vbo_id: c_uint = undefined; var ebo_id: c_uint = undefined; @@ -158,14 +158,21 @@ pub const Gui = struct { var quit = std.atomic.Atomic(bool).init(false); var tracker = FpsTracker.init(); + var buffer_ids = Self.generateBuffers(); + defer { + gl.deleteBuffers(1, &buffer_ids[2]); // EBO + gl.deleteBuffers(1, &buffer_ids[1]); // VBO + gl.deleteVertexArrays(1, &buffer_ids[0]); // VAO + } + + const vao_id = buffer_ids[0]; + _ = Self.generateTexture(cpu.bus.ppu.framebuf.get(.Renderer)); + const thread = try std.Thread.spawn(.{}, emu.run, .{ &quit, scheduler, cpu, &tracker }); defer thread.join(); var title_buf: [0x100]u8 = [_]u8{0} ** 0x100; - const vao_id = Self.generateBuffers()[0]; - _ = Self.generateTexture(cpu.bus.ppu.framebuf.get(.Renderer)); - emu_loop: while (true) { var event: SDL.SDL_Event = undefined; while (SDL.SDL_PollEvent(&event) != 0) {