From 90562ee84b9bf20df9434887bc29d6a54bd15fde Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 13 May 2023 18:18:01 +0900 Subject: [PATCH] internal/goglfw: enable to build for GOOS=darwin Updates #2546 --- internal/goglfw/cocoainit_darwin.go | 14 + internal/goglfw/cocoamonitor_darwin.go | 31 +++ internal/goglfw/cocoaplatform_darwin.go | 22 ++ internal/goglfw/cocoawindow_darwin.go | 242 ++++++++++++++++++ .../goglfw/{context_windows.go => context.go} | 2 + .../goglfw/{glfw3h_windows.go => glfw3h.go} | 2 + internal/goglfw/{init_windows.go => init.go} | 2 + .../goglfw/{input_windows.go => input.go} | 2 + .../{internal_windows.go => internal.go} | 2 + .../goglfw/{monitor_windows.go => monitor.go} | 2 + internal/goglfw/nsgl_darwin.go | 14 + internal/goglfw/posixthread_unix.go | 28 ++ internal/goglfw/wglcontext_windows.go | 23 ++ internal/goglfw/win32platform_windows.go | 23 -- .../goglfw/{window_windows.go => window.go} | 2 + 15 files changed, 388 insertions(+), 23 deletions(-) create mode 100644 internal/goglfw/cocoainit_darwin.go create mode 100644 internal/goglfw/cocoamonitor_darwin.go create mode 100644 internal/goglfw/cocoaplatform_darwin.go create mode 100644 internal/goglfw/cocoawindow_darwin.go rename internal/goglfw/{context_windows.go => context.go} (99%) rename internal/goglfw/{glfw3h_windows.go => glfw3h.go} (99%) rename internal/goglfw/{init_windows.go => init.go} (97%) rename internal/goglfw/{input_windows.go => input.go} (99%) rename internal/goglfw/{internal_windows.go => internal.go} (99%) rename internal/goglfw/{monitor_windows.go => monitor.go} (99%) create mode 100644 internal/goglfw/nsgl_darwin.go create mode 100644 internal/goglfw/posixthread_unix.go rename internal/goglfw/{window_windows.go => window.go} (99%) diff --git a/internal/goglfw/cocoainit_darwin.go b/internal/goglfw/cocoainit_darwin.go new file mode 100644 index 000000000..4b30a7800 --- /dev/null +++ b/internal/goglfw/cocoainit_darwin.go @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: Zlib +// SPDX-FileCopyrightText: 2002-2006 Marcus Geelnard +// SPDX-FileCopyrightText: 2006-2019 Camilla Löwy +// SPDX-FileCopyrightText: 2023 The Ebitengine Authors + +package goglfw + +func platformInit() error { + panic("goglfw: platformInit is not implemented yet") +} + +func platformTerminate() error { + panic("goglfw: platformTerminate is not implemented yet") +} diff --git a/internal/goglfw/cocoamonitor_darwin.go b/internal/goglfw/cocoamonitor_darwin.go new file mode 100644 index 000000000..e648b4951 --- /dev/null +++ b/internal/goglfw/cocoamonitor_darwin.go @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: Zlib +// SPDX-FileCopyrightText: 2002-2006 Marcus Geelnard +// SPDX-FileCopyrightText: 2006-2019 Camilla Löwy +// SPDX-FileCopyrightText: 2023 The Ebitengine Authors + +package goglfw + +func (m *Monitor) platformGetMonitorPos() (xpos, ypos int, ok bool) { + // cocoa_monitor.m:L450 + panic("goglfw: Monitor.platformGetMonitorPos is not implemented yet") +} + +func (m *Monitor) platformGetMonitorContentScale() (xscale, yscale float32, err error) { + // cocoa_monitor.m:L464 + panic("goglfw: Monitor.platformGetMonitorContentScale is not implemented yet") +} + +func (m *Monitor) platformGetMonitorWorkarea() (xpos, ypos, width, height int) { + // cocoa_monitor.m:L486 + panic("goglfw: Monitor.platformGetMonitorWorkarea is not implemented yet") +} + +func (m *Monitor) platformAppendVideoModes(monitors []*VidMode) ([]*VidMode, error) { + // cocoa_monitor.m:L512 + panic("goglfw: Monitor.platformAppendVideoModes is not implemented yet") +} + +func (m *Monitor) platformGetVideoMode() *VidMode { + // cocoa_monitor.m:L552 + panic("goglfw: Monitor.platformGetVideoMode is not implemented yet") +} diff --git a/internal/goglfw/cocoaplatform_darwin.go b/internal/goglfw/cocoaplatform_darwin.go new file mode 100644 index 000000000..e1c7179bf --- /dev/null +++ b/internal/goglfw/cocoaplatform_darwin.go @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: Zlib +// SPDX-FileCopyrightText: 2002-2006 Marcus Geelnard +// SPDX-FileCopyrightText: 2006-2019 Camilla Löwy +// SPDX-FileCopyrightText: 2023 The Ebitengine Authors + +package goglfw + +type platformWindowState struct { + // TODO: Implement this. +} + +type platformMonitorState struct { + // TODO: Implement this. +} + +type platformCursorState struct { + // TODO: Implement this. +} + +type platformLibraryWindowState struct { + // TODO: Implement this. +} diff --git a/internal/goglfw/cocoawindow_darwin.go b/internal/goglfw/cocoawindow_darwin.go new file mode 100644 index 000000000..9e0a1bf56 --- /dev/null +++ b/internal/goglfw/cocoawindow_darwin.go @@ -0,0 +1,242 @@ +// SPDX-License-Identifier: Zlib +// SPDX-FileCopyrightText: 2002-2006 Marcus Geelnard +// SPDX-FileCopyrightText: 2006-2019 Camilla Löwy +// SPDX-FileCopyrightText: 2023 The Ebitengine Authors + +package goglfw + +func (w *Window) platformCreateWindow(wndconfig *wndconfig, ctxconfig *ctxconfig, fbconfig *fbconfig) error { + // cocoa_window.m:L898 + panic("goglfw: Window.platformCreateWindow is not implemented yet") +} + +func (w *Window) platformDestroyWindow() error { + // cocoa_window.m:L968 + panic("goglfw: Window.platformDestroyWindow is not implemented yet") +} + +func (w *Window) platformSetWindowTitle(title string) error { + // cocoa_window.m:L999 + panic("goglfw: Window.platformSetWindowTitle is not implemented yet") +} + +func (w *Window) platformSetWindowIcon(images []*Image) error { + // cocoa_window.m:L1010 + panic("goglfw: Window.platformSetWindowIcon is not implemented yet") +} + +func (w *Window) platformGetWindowPos() (xpos, ypos int, err error) { + // cocoa_window.m:L1016 + panic("goglfw: Window.platformGetWindowPos is not implemented yet") +} + +func (w *Window) platformSetWindowPos(xpos, ypos int) error { + // cocoa_window.m:L1031 + panic("goglfw: Window.platformSetWindowPos is not implemented yet") +} + +func (w *Window) platformGetWindowSize() (width, height int, err error) { + // cocoa_window.m:L1043 + panic("goglfw: Window.platformGetWindowSize is not implemented yet") +} + +func (w *Window) platformSetWindowSize(width, height int) error { + // cocoa_window.m:L1057 + panic("goglfw: Window.platformSetWindowSize is not implemented yet") +} + +func (w *Window) platformSetWindowSizeLimits(minwidth, minheight, maxwidth, maxheight int) error { + // cocoa_window.m:L1079 + panic("goglfw: Window.platformSetWindowSizeLimits is not implemented yet") +} + +func (w *Window) platformSetWindowAspectRatio(numer, denom int) error { + // cocoa_window.m:L1098 + panic("goglfw: Window.platformSetWindowAspectRatio is not implemented yet") +} + +func (w *Window) platformGetFramebufferSize() (width, height int, err error) { + // cocoa_window.m:L1108 + panic("goglfw: Window.platformGetFramebufferSize is not implemented yet") +} + +func (w *Window) platformGetWindowFrameSize() (left, top, right, bottom int, err error) { + // cocoa_window.m:L1123 + panic("goglfw: Window.platformGetWindowFrameSize is not implemented yet") +} + +func (w *Window) platformGetWindowContentScale() (xscale, yscale float32, err error) { + // cocoa_window.m:L1146 + panic("goglfw: Window.platformGetWindowContentScale is not implemented yet") +} + +func (w *Window) platformIconifyWindow() { + // cocoa_window.m:L1162 + panic("goglfw: Window.platformIconifyWindow is not implemented yet") +} + +func (w *Window) platformRestoreWindow() { + // cocoa_window.m:L1169 + panic("goglfw: Window.platformRestoreWindow is not implemented yet") +} + +func (w *Window) platformMaximizeWindow() error { + // cocoa_window.m:L1179 + panic("goglfw: Window.platformMaximizeWindow is not implemented yet") +} + +func (w *Window) platformShowWindow() { + // cocoa_window.m:L1187 + panic("goglfw: Window.platformShowWindow is not implemented yet") +} + +func (w *Window) platformHideWindow() { + // cocoa_window.m:L1194 + panic("goglfw: Window.platformHideWindow is not implemented yet") +} + +func (w *Window) platformRequestWindowAttention() { + // cocoa_window.m:L1201 + panic("goglfw: Window.platformRequestWindowAttention is not implemented yet") +} + +func (w *Window) platformFocusWindow() error { + // cocoa_window.m:L1208 + panic("goglfw: Window.platformFocusWindow is not implemented yet") +} + +func (w *Window) platformSetWindowMonitor(monitor *Monitor, xpos, ypos, width, height, refreshRate int) error { + // cocoa_window.m:L1220 + panic("goglfw: Window.platformSetWindowMonitor is not implemented yet") +} + +func (w *Window) platformWindowFocused() bool { + // cocoa_window.m:L1348 + panic("goglfw: platformWindowFocused is not implemented yet") +} + +func (w *Window) platformWindowIconified() bool { + // cocoa_window.m:L1355 + panic("goglfw: Window.platformWindowIconified is not implemented yet") +} + +func (w *Window) platformWindowVisible() bool { + // cocoa_window.m:L1362 + panic("goglfw: Window.platformWindowVisible is not implemented yet") +} + +func (w *Window) platformWindowMaximized() bool { + // cocoa_window.m:L1369 + panic("goglfw: Window.platformWindowMaximized is not implemented yet") +} + +func (w *Window) platformWindowHovered() (bool, error) { + // cocoa_window.m:L1381 + panic("goglfw: Window.platformWindowHovered is not implemented yet") +} + +func (w *Window) platformFramebufferTransparent() bool { + // cocoa_window.m:L1399 + panic("goglfw: Window.platformFramebufferTransparent is not implemented yet") +} + +func (w *Window) platformSetWindowResizable(enabled bool) error { + // cocoa_window.m:L1406 + panic("goglfw: Window.platformSetWindowResizable is not implemented yet") +} + +func (w *Window) platformSetWindowDecorated(enabled bool) error { + // cocoa_window.m:L1430 + panic("goglfw: Window.platformSetWindowDecorated is not implemented yet") +} + +func (w *Window) platformSetWindowFloating(enabled bool) error { + // cocoa_window.m:L1452 + panic("goglfw: Window.platformSetWindowFloating is not implemented yet") +} + +func (w *Window) platformGetWindowOpacity() (float32, error) { + // cocoa_window.m:L1462 + panic("goglfw: Window.platformGetWindowOpacity is not implemented yet") +} + +func (w *Window) platformSetWindowOpacity(opacity float32) error { + // cocoa_window.m:L1469 + panic("goglfw: Window.platformSetWindowOpacity is not implemented yet") +} + +func (w *Window) platformSetRawMouseMotion(enabled bool) error { + return nil +} + +func platformRawMouseMotionSupported() bool { + return false +} + +func platformPollEvents() error { + // cocoa_window.m:L1485 + panic("goglfw: platformPollEvents is not implemented yet") +} + +func platformWaitEvents() error { + // cocoa_window.m:L1507 + panic("goglfw: platformWaitEvents is not implemented yet") +} + +func platformWaitEventsTimeout(timeout float64) error { + // cocoa_window.m:L1528 + panic("goglfw: platformWaitEventsTimeout is not implemented yet") +} + +func platformPostEmptyEvent() error { + // cocoa_window.m:L1548 + panic("goglfw: platformPostEmptyEvent is not implemented yet") +} + +func (w *Window) platformGetCursorPos() (xpos, ypos float64, err error) { + // cocoa_window.m:L1569 + panic("goglfw: Window.platformGetCursorPos is not implemented yet") +} + +func (w *Window) platformSetCursorPos(xpos, ypos float64) error { + // cocoa_window.m:L1585 + panic("goglfw: Window.platformSetCursorPos is not implemented yet") +} + +func (w *Window) platformSetCursorMode(mode int) error { + // cocoa_window.m:L1621 + panic("goglfw: Window.platformSetMode is not implemented yet") +} + +func platformGetScancodeName(scancode int) (string, error) { + // cocoa_window.m:L1629 + panic("goglfw: platformGetScancodeName is not implemented yet") +} + +func platformGetKeyScancode(key Key) int { + // cocoa_window.m:L1678 + panic("goglfw: platformGetKeyScancode is not implemented yet") +} + +func (c *Cursor) platformCreateStandardCursor(shape StandardCursor) error { + // cocoa_window.m:L1727 + panic("goglfw: Cursor.platformCreateStandardCursor is not implemented yet") +} + +func (c *Cursor) platformDestroyCursor() error { + // cocoa_window.m:L1757 + panic("goglfw: Cursor.platformDestroyCursor is not implemented yet") +} + +func (w *Window) platformSetCursor(cursor *Cursor) error { + // cocoa_window.m:L1765 + panic("goglfw: Window.platformSetCursor is not implemented yet") +} + +func platformSetClipboardString(str string) error { + panic("goglfw: platformSetClipboardString is not implemented") +} + +func platformGetClipboardString() (string, error) { + panic("goglfw: platformGetClipboardString is not implemented") +} diff --git a/internal/goglfw/context_windows.go b/internal/goglfw/context.go similarity index 99% rename from internal/goglfw/context_windows.go rename to internal/goglfw/context.go index 8e7c22ce4..d92c66a0d 100644 --- a/internal/goglfw/context_windows.go +++ b/internal/goglfw/context.go @@ -3,6 +3,8 @@ // SPDX-FileCopyrightText: 2006-2019 Camilla Löwy // SPDX-FileCopyrightText: 2022 The Ebitengine Authors +//go:build darwin || windows + package goglfw import ( diff --git a/internal/goglfw/glfw3h_windows.go b/internal/goglfw/glfw3h.go similarity index 99% rename from internal/goglfw/glfw3h_windows.go rename to internal/goglfw/glfw3h.go index 8fafaf3d4..5088a6221 100644 --- a/internal/goglfw/glfw3h_windows.go +++ b/internal/goglfw/glfw3h.go @@ -3,6 +3,8 @@ // SPDX-FileCopyrightText: 2006-2019 Camilla Löwy // SPDX-FileCopyrightText: 2022 The Ebitengine Authors +//go:build darwin || windows + package goglfw const ( diff --git a/internal/goglfw/init_windows.go b/internal/goglfw/init.go similarity index 97% rename from internal/goglfw/init_windows.go rename to internal/goglfw/init.go index 76208b3da..f2a5c11f5 100644 --- a/internal/goglfw/init_windows.go +++ b/internal/goglfw/init.go @@ -3,6 +3,8 @@ // SPDX-FileCopyrightText: 2006-2019 Camilla Löwy // SPDX-FileCopyrightText: 2022 The Ebitengine Authors +//go:build darwin || windows + package goglfw func terminate() error { diff --git a/internal/goglfw/input_windows.go b/internal/goglfw/input.go similarity index 99% rename from internal/goglfw/input_windows.go rename to internal/goglfw/input.go index c8e6ba388..d05b5b348 100644 --- a/internal/goglfw/input_windows.go +++ b/internal/goglfw/input.go @@ -3,6 +3,8 @@ // SPDX-FileCopyrightText: 2006-2019 Camilla Löwy // SPDX-FileCopyrightText: 2022 The Ebitengine Authors +//go:build darwin || windows + package goglfw import ( diff --git a/internal/goglfw/internal_windows.go b/internal/goglfw/internal.go similarity index 99% rename from internal/goglfw/internal_windows.go rename to internal/goglfw/internal.go index 0073dae60..fd05e9032 100644 --- a/internal/goglfw/internal_windows.go +++ b/internal/goglfw/internal.go @@ -3,6 +3,8 @@ // SPDX-FileCopyrightText: 2006-2019 Camilla Löwy // SPDX-FileCopyrightText: 2022 The Ebitengine Authors +//go:build darwin || windows + package goglfw import ( diff --git a/internal/goglfw/monitor_windows.go b/internal/goglfw/monitor.go similarity index 99% rename from internal/goglfw/monitor_windows.go rename to internal/goglfw/monitor.go index 44eff79cd..c3138bbfb 100644 --- a/internal/goglfw/monitor_windows.go +++ b/internal/goglfw/monitor.go @@ -3,6 +3,8 @@ // SPDX-FileCopyrightText: 2006-2019 Camilla Löwy // SPDX-FileCopyrightText: 2022 The Ebitengine Authors +//go:build darwin || windows + package goglfw import ( diff --git a/internal/goglfw/nsgl_darwin.go b/internal/goglfw/nsgl_darwin.go new file mode 100644 index 000000000..016f44b5f --- /dev/null +++ b/internal/goglfw/nsgl_darwin.go @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: Zlib +// SPDX-FileCopyrightText: 2002-2006 Marcus Geelnard +// SPDX-FileCopyrightText: 2006-2019 Camilla Löwy +// SPDX-FileCopyrightText: 2023 The Ebitengine Authors + +package goglfw + +type platformContextState struct { + // TODO: Implement this. +} + +type platformLibraryContextState struct { + // TODO: Implement this. +} diff --git a/internal/goglfw/posixthread_unix.go b/internal/goglfw/posixthread_unix.go new file mode 100644 index 000000000..bb45c2240 --- /dev/null +++ b/internal/goglfw/posixthread_unix.go @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: Zlib +// SPDX-FileCopyrightText: 2002-2006 Marcus Geelnard +// SPDX-FileCopyrightText: 2006-2019 Camilla Löwy +// SPDX-FileCopyrightText: 2023 The Ebitengine Authors + +//go:build darwin + +package goglfw + +type platformTLSState struct { + // TODO: Implement this. +} + +func (t *tls) create() error { + panic("goglfw: tls.create is not implemented yet") +} + +func (t *tls) destroy() error { + panic("goglfw: tls.destroy is not implemented yet") +} + +func (t *tls) get() (uintptr, error) { + panic("goglfw: tls.get is not implemented yet") +} + +func (t *tls) set(value uintptr) error { + panic("goglfw: tls.set is not implemented yet") +} diff --git a/internal/goglfw/wglcontext_windows.go b/internal/goglfw/wglcontext_windows.go index 4d913be05..591144732 100644 --- a/internal/goglfw/wglcontext_windows.go +++ b/internal/goglfw/wglcontext_windows.go @@ -17,6 +17,29 @@ import ( "github.com/hajimehoshi/ebiten/v2/internal/winver" ) +type platformContextState struct { + dc _HDC + handle _HGLRC + interval int +} + +type platformLibraryContextState struct { + inited bool + + EXT_swap_control bool + EXT_colorspace bool + ARB_multisample bool + ARB_framebuffer_sRGB bool + EXT_framebuffer_sRGB bool + ARB_pixel_format bool + ARB_create_context bool + ARB_create_context_profile bool + EXT_create_context_es2_profile bool + ARB_create_context_robustness bool + ARB_create_context_no_error bool + ARB_context_flush_control bool +} + func findPixelFormatAttribValue(attribs []int32, values []int32, attrib int32) int32 { for i := range attribs { if attribs[i] == attrib { diff --git a/internal/goglfw/win32platform_windows.go b/internal/goglfw/win32platform_windows.go index 3aeb763ab..c0da337e2 100644 --- a/internal/goglfw/win32platform_windows.go +++ b/internal/goglfw/win32platform_windows.go @@ -37,12 +37,6 @@ type platformWindowState struct { highSurrogate uint16 } -type platformContextState struct { - dc _HDC - handle _HGLRC - interval int -} - type platformMonitorState struct { handle _HMONITOR @@ -81,20 +75,3 @@ type platformLibraryWindowState struct { rawInput []byte mouseTrailSize uint32 } - -type platformLibraryContextState struct { - inited bool - - EXT_swap_control bool - EXT_colorspace bool - ARB_multisample bool - ARB_framebuffer_sRGB bool - EXT_framebuffer_sRGB bool - ARB_pixel_format bool - ARB_create_context bool - ARB_create_context_profile bool - EXT_create_context_es2_profile bool - ARB_create_context_robustness bool - ARB_create_context_no_error bool - ARB_context_flush_control bool -} diff --git a/internal/goglfw/window_windows.go b/internal/goglfw/window.go similarity index 99% rename from internal/goglfw/window_windows.go rename to internal/goglfw/window.go index bcc5e1f70..46b4ab6c9 100644 --- a/internal/goglfw/window_windows.go +++ b/internal/goglfw/window.go @@ -3,6 +3,8 @@ // SPDX-FileCopyrightText: 2006-2019 Camilla Löwy // SPDX-FileCopyrightText: 2022 The Ebitengine Authors +//go:build darwin || windows + package goglfw import (