F - fullscreen, ESC - exit
This commit is contained in:
+30
-4
@@ -18,8 +18,8 @@ import (
|
|||||||
const (
|
const (
|
||||||
APP_NAME = "MXL Player"
|
APP_NAME = "MXL Player"
|
||||||
APP_VER = "0.0.1"
|
APP_VER = "0.0.1"
|
||||||
WIN_WIDTH int32 = 1920
|
WIN_WIDTH int32 = 1280
|
||||||
WIN_HEIGHT int32 = 1080
|
WIN_HEIGHT int32 = 720
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -28,6 +28,8 @@ const (
|
|||||||
windowResizable uint64 = 0x0000000000000020
|
windowResizable uint64 = 0x0000000000000020
|
||||||
|
|
||||||
sdlEventQuit uint32 = 0x100
|
sdlEventQuit uint32 = 0x100
|
||||||
|
sdlEventWindowResized uint32 = 0x206
|
||||||
|
sdlEventPixelSizeChanged uint32 = 0x207
|
||||||
sdlEventKeyDown uint32 = 0x300
|
sdlEventKeyDown uint32 = 0x300
|
||||||
keyEscape uint32 = 0x1B
|
keyEscape uint32 = 0x1B
|
||||||
)
|
)
|
||||||
@@ -42,6 +44,7 @@ var (
|
|||||||
sdlVulkanCreateSurface func(window, instance, allocator uintptr, surface *uint64) bool
|
sdlVulkanCreateSurface func(window, instance, allocator uintptr, surface *uint64) bool
|
||||||
sdlPollEvent func(event unsafe.Pointer) bool
|
sdlPollEvent func(event unsafe.Pointer) bool
|
||||||
sdlGetWindowSizeInPixels func(window uintptr, w, h *int32) bool
|
sdlGetWindowSizeInPixels func(window uintptr, w, h *int32) bool
|
||||||
|
sdlSetWindowFullscreen func(windows uintptr, fullscreen bool) bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func sdlError() string { return cstr(sdlGetError()) }
|
func sdlError() string { return cstr(sdlGetError()) }
|
||||||
@@ -65,6 +68,7 @@ func loadSDLMissing() error {
|
|||||||
purego.RegisterLibFunc(&sdlVulkanCreateSurface, h, "SDL_Vulkan_CreateSurface")
|
purego.RegisterLibFunc(&sdlVulkanCreateSurface, h, "SDL_Vulkan_CreateSurface")
|
||||||
purego.RegisterLibFunc(&sdlPollEvent, h, "SDL_PollEvent")
|
purego.RegisterLibFunc(&sdlPollEvent, h, "SDL_PollEvent")
|
||||||
purego.RegisterLibFunc(&sdlGetWindowSizeInPixels, h, "SDL_GetWindowSizeInPixels")
|
purego.RegisterLibFunc(&sdlGetWindowSizeInPixels, h, "SDL_GetWindowSizeInPixels")
|
||||||
|
purego.RegisterLibFunc(&sdlSetWindowFullscreen, h, "SDL_SetWindowFullscreen")
|
||||||
sdlLoaded = true
|
sdlLoaded = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -454,7 +458,7 @@ func main() {
|
|||||||
|
|
||||||
// Reader goroutine: stages V210 bytes into the staging buffer.
|
// Reader goroutine: stages V210 bytes into the staging buffer.
|
||||||
// Single-flight handshake: it only writes staging after the render thread
|
// 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())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
grant := make(chan struct{})
|
grant := make(chan struct{})
|
||||||
@@ -494,17 +498,39 @@ func main() {
|
|||||||
|
|
||||||
// Core Loop
|
// Core Loop
|
||||||
running := true
|
running := true
|
||||||
|
resized := false
|
||||||
|
fullscreen := false
|
||||||
for running {
|
for running {
|
||||||
var event [128]byte
|
var event [128]byte
|
||||||
for sdlPollEvent(unsafe.Pointer(&event[0])) {
|
for sdlPollEvent(unsafe.Pointer(&event[0])) {
|
||||||
eventType := *(*uint32)(unsafe.Pointer(&event[0]))
|
eventType := *(*uint32)(unsafe.Pointer(&event[0]))
|
||||||
if eventType == sdlEventQuit {
|
switch eventType {
|
||||||
|
case sdlEventQuit:
|
||||||
running = false
|
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 {
|
if !running {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
if resized {
|
||||||
|
if err := recreateSwapChain(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
resized = false
|
||||||
|
}
|
||||||
// Acquire the next swapchain image
|
// Acquire the next swapchain image
|
||||||
imageIndex, r := vkDevice.AcquireNextImage(vkSwapchain, imageAvailable, ^uint64(0))
|
imageIndex, r := vkDevice.AcquireNextImage(vkSwapchain, imageAvailable, ^uint64(0))
|
||||||
if r == vk.ErrorOutOfDateKHR || r == vk.SuboptimalKHR {
|
if r == vk.ErrorOutOfDateKHR || r == vk.SuboptimalKHR {
|
||||||
|
|||||||
Reference in New Issue
Block a user