1 // SPDX-FileCopyrightText: Copyright 2014 Emil Velikov
2 // SPDX-License-Identifier: BSD-2-Clause
7 #include "wcore_error.h"
9 #include "win_platform.h"
11 #include "wgl_config.h"
12 #include "wgl_context.h"
13 #include "wgl_display.h"
14 #include "wgl_platform.h"
15 #include "wgl_window.h"
17 static const struct wcore_platform_vtbl wgl_platform_vtbl
;
19 const char* wfl_class_name
= "waffle";
22 wgl_platform_destroy(struct wcore_platform
*wc_self
)
24 struct wgl_platform
*self
= wgl_platform(wc_self
);
28 ok
= UnregisterClass(self
->class_name
, GetModuleHandle(NULL
));
30 win_platform_teardown(wc_self
);
36 wgl_platform_register_class(const char* class_name
)
41 memset(&wc
, 0, sizeof(wc
));
42 wc
.style
= CS_OWNDC
| CS_HREDRAW
| CS_VREDRAW
;
43 // XXX: Use a non-default window_proc ?
44 wc
.lpfnWndProc
= DefWindowProc
;
45 wc
.hIcon
= LoadIcon(NULL
, IDI_APPLICATION
);
46 wc
.hInstance
= GetModuleHandle(NULL
);
47 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
48 wc
.hbrBackground
= (HBRUSH
) (COLOR_BTNFACE
+ 1);;
49 wc
.lpszClassName
= class_name
;
51 ok
= !!RegisterClass(&wc
);
54 int error
= GetLastError();
57 wcore_errorf(WAFFLE_ERROR_UNKNOWN
,
58 "RegisterClass() failed: %d",
66 struct wcore_platform
*
67 wgl_platform_create(void)
69 struct wgl_platform
*self
;
71 self
= wcore_calloc(sizeof(*self
));
75 wcore_platform_init(&self
->wcore
);
76 win_platform_init(&self
->wcore
);
78 if (!wgl_platform_register_class(wfl_class_name
))
81 self
->class_name
= wfl_class_name
;
83 self
->wcore
.vtbl
= &wgl_platform_vtbl
;
87 wgl_platform_destroy(&self
->wcore
);
92 wgl_make_current(struct wcore_platform
*wc_self
,
93 struct wcore_display
*wc_dpy
,
94 struct wcore_window
*wc_window
,
95 struct wcore_context
*wc_ctx
)
97 HDC hDC
= wc_window
? wgl_window(wc_window
)->hDC
: NULL
;
98 HGLRC hglrc
= wc_ctx
? wgl_context(wc_ctx
)->hglrc
: NULL
;
100 return wglMakeCurrent(hDC
, hglrc
);
104 wgl_get_proc_address(struct wcore_platform
*wc_self
, const char *name
)
106 return wglGetProcAddress(name
);
109 static const struct wcore_platform_vtbl wgl_platform_vtbl
= {
110 .destroy
= wgl_platform_destroy
,
112 .make_current
= wgl_make_current
,
113 .get_proc_address
= wgl_get_proc_address
,
114 .dl_can_open
= win_platform_can_dlopen
,
115 .dl_sym
= win_platform_dlsym
,
118 .connect
= wgl_display_connect
,
119 .destroy
= wgl_display_destroy
,
120 .supports_context_api
= wgl_display_supports_context_api
,
125 .choose
= wgl_config_choose
,
126 .destroy
= wgl_config_destroy
,
131 .create
= wgl_context_create
,
132 .destroy
= wgl_context_destroy
,
137 .create
= wgl_window_create
,
138 .destroy
= wgl_window_destroy
,
139 .show
= wgl_window_show
,
140 .resize
= wgl_window_resize
,
141 .swap_buffers
= wgl_window_swap_buffers
,