F - fullscreen, ESC - exit

This commit is contained in:
Dmitry Sergeev
2026-08-22 15:20:06 +03:00
parent 84572fb88c
commit b03bfba5bd
+33 -7
View File
@@ -18,8 +18,8 @@ import (
const (
APP_NAME = "MXL Player"
APP_VER = "0.0.1"
WIN_WIDTH int32 = 1920
WIN_HEIGHT int32 = 1080
WIN_WIDTH int32 = 1280
WIN_HEIGHT int32 = 720
)
const (
@@ -27,9 +27,11 @@ const (
windowVulkan uint64 = 0x0000000010000000
windowResizable uint64 = 0x0000000000000020
sdlEventQuit uint32 = 0x100
sdlEventKeyDown uint32 = 0x300
keyEscape uint32 = 0x1B
sdlEventQuit uint32 = 0x100
sdlEventWindowResized uint32 = 0x206
sdlEventPixelSizeChanged uint32 = 0x207
sdlEventKeyDown uint32 = 0x300
keyEscape uint32 = 0x1B
)
var (
@@ -42,6 +44,7 @@ var (
sdlVulkanCreateSurface func(window, instance, allocator uintptr, surface *uint64) bool
sdlPollEvent func(event unsafe.Pointer) bool
sdlGetWindowSizeInPixels func(window uintptr, w, h *int32) bool
sdlSetWindowFullscreen func(windows uintptr, fullscreen bool) bool
)
func sdlError() string { return cstr(sdlGetError()) }
@@ -65,6 +68,7 @@ func loadSDLMissing() error {
purego.RegisterLibFunc(&sdlVulkanCreateSurface, h, "SDL_Vulkan_CreateSurface")
purego.RegisterLibFunc(&sdlPollEvent, h, "SDL_PollEvent")
purego.RegisterLibFunc(&sdlGetWindowSizeInPixels, h, "SDL_GetWindowSizeInPixels")
purego.RegisterLibFunc(&sdlSetWindowFullscreen, h, "SDL_SetWindowFullscreen")
sdlLoaded = true
return nil
}
@@ -454,7 +458,7 @@ func main() {
// Reader goroutine: stages V210 bytes into the staging buffer.
// Single-flight handshake: it only writes staging after the render thread
// grants permission (post-WaitFence), so the GPU is never reading it.
// grants permission (post-WaitFence), so the GPU is never reading it
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
grant := make(chan struct{})
@@ -494,17 +498,39 @@ func main() {
// Core Loop
running := true
resized := false
fullscreen := false
for running {
var event [128]byte
for sdlPollEvent(unsafe.Pointer(&event[0])) {
eventType := *(*uint32)(unsafe.Pointer(&event[0]))
if eventType == sdlEventQuit {
switch eventType {
case sdlEventQuit:
running = false
case sdlEventWindowResized, sdlEventPixelSizeChanged:
resized = true
case sdlEventKeyDown:
key := *(*int32)(unsafe.Pointer(&event[28]))
switch uint32(key) {
case keyEscape:
running = false
// f
case 0x66:
fullscreen = !fullscreen
sdlSetWindowFullscreen(windowHandler, fullscreen)
resized = true
}
}
}
if !running {
break
}
if resized {
if err := recreateSwapChain(); err != nil {
panic(err)
}
resized = false
}
// Acquire the next swapchain image
imageIndex, r := vkDevice.AcquireNextImage(vkSwapchain, imageAvailable, ^uint64(0))
if r == vk.ErrorOutOfDateKHR || r == vk.SuboptimalKHR {