diff options
Diffstat (limited to 'src/main/kotlin')
| -rw-r--r-- | src/main/kotlin/gui/EmulationOutputWindow.kt | 19 | ||||
| -rw-r--r-- | src/main/kotlin/gui/WindowContainer.kt | 51 |
2 files changed, 54 insertions, 16 deletions
diff --git a/src/main/kotlin/gui/EmulationOutputWindow.kt b/src/main/kotlin/gui/EmulationOutputWindow.kt index 14fe246..3f57d5a 100644 --- a/src/main/kotlin/gui/EmulationOutputWindow.kt +++ b/src/main/kotlin/gui/EmulationOutputWindow.kt @@ -1,15 +1,22 @@ package gui import glm_.vec2.Vec2 -import imgui.Cond -import imgui.ImGui +import imgui.* -fun paintEmulationOutputWindow() { +fun paintEmulationOutputWindow(frame: TextureID) { with(ImGui) { - setNextWindowSize(Vec2(640, 576), Cond.FirstUseEver) + + pushStyleVar(StyleVar.WindowPadding, Vec2(0)) + + setNextWindowSize(Vec2(640, 596), Cond.FirstUseEver) setNextWindowPos(Vec2(620, 10), Cond.FirstUseEver) - begin("Emulation output - 4x scale") - text("TODO - actually render something...") + + begin("Emulation output - 4x scale", flags_ = WindowFlag.NoScrollbar or WindowFlag.NoResize) + + image(frame, Vec2(640,576)) + end() + + popStyleVar() } }
\ No newline at end of file diff --git a/src/main/kotlin/gui/WindowContainer.kt b/src/main/kotlin/gui/WindowContainer.kt index 8dcd37b..60dc1e4 100644 --- a/src/main/kotlin/gui/WindowContainer.kt +++ b/src/main/kotlin/gui/WindowContainer.kt @@ -1,28 +1,36 @@ package gui +import GameBoy import cpu.Cpu +import gli_.Texture +import gli_.gli +import glm_.vec2.Vec2i import glm_.vec4.Vec4 import gln.checkError +import gln.texture.glDeleteTexture +import gln.texture.initTexture2d +import gpu.TestPatternGpu import imgui.Context import imgui.ImGui +import imgui.TextureID import imgui.destroy import imgui.impl.LwjglGL3 import org.lwjgl.opengl.GL11 +import org.lwjgl.opengl.GL30 import uno.glfw.GlfwWindow import uno.glfw.glfw +import java.awt.image.BufferedImage import java.io.File class WindowContainer { - var cpu: Cpu + val gameBoy: GameBoy init { glfw.init("3.2") - cpu = Cpu() - val file = File("src/main/resources/roms/boot-rom.gb") - val rom = file.readBytes() - cpu.loadRom(rom) - //cpu.run() + + gameBoy = GameBoy(Cpu(), TestPatternGpu()) + gameBoy.loadRom(File("src/main/resources/roms/boot-rom.gb")) } val window = GlfwWindow(1280, 720, "KGB - KotlinGameBoy").apply { @@ -53,12 +61,14 @@ class WindowContainer { LwjglGL3.newFrame() + val (texture, textureId) = createAndRegisterTexture(gameBoy.gpu.getFrame()) + with(ImGui) { paintDebugWindow() - paintEmulationOutputWindow() - paintCpuRegisterWindow(cpu.registers) - paintRunControlWindow(cpu) - paintRamDumpWindow(cpu.ram) + paintCpuRegisterWindow(gameBoy.cpu.registers) + paintRunControlWindow(gameBoy.cpu) + paintRamDumpWindow(gameBoy.cpu.ram) + paintEmulationOutputWindow(textureId) } gln.glViewport(window.framebufferSize) @@ -68,6 +78,27 @@ class WindowContainer { ImGui.render() LwjglGL3.renderDrawData(ImGui.drawData!!) + // TODO - render direct to framebuffer rather than creating and destroying texture each frame + disposeTexture(texture, textureId) + checkError("mainLoop") } + + private fun createAndRegisterTexture(frame: BufferedImage): Pair<Texture, TextureID> { + val texture = gli.createTexture(frame) + val textureId = initTexture2d { + minFilter = linear + magFilter = linear + GL30.glPixelStorei(GL30.GL_UNPACK_ROW_LENGTH, 0) + image(GL30.GL_RGB, Vec2i(640,576), GL30.GL_RGB, GL30.GL_UNSIGNED_BYTE, texture.data()) + } + + return Pair(texture, textureId) + } + + private fun disposeTexture(texture: Texture, textureID: TextureID) { + glDeleteTexture(textureID) + texture.dispose() + } + }
\ No newline at end of file |