Skip to content

Commit 656d357

Browse files
authored
Merge pull request #86 from imakris/windows-egl-gl-platform
Add Windows EGL+GL platform and refresh headers
2 parents f27017e + f131e16 commit 656d357

80 files changed

Lines changed: 125209 additions & 20795 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/main.yaml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ jobs:
2929
# This will install XQuartz, which provides the missing X11 headers.
3030
run: brew install --cask xquartz
3131

32+
- name: Setup MSYS2 (Windows)
33+
if: runner.os == 'Windows'
34+
uses: msys2/setup-msys2@v2
35+
with:
36+
update: false
37+
install: mingw-w64-x86_64-gcc
38+
39+
- name: Install pytest
40+
run: python -m pip install pytest
41+
3242
- name: Configure CMake
3343
shell: bash
3444
# We need to provide a hint to CMake to find the X11 package from XQuartz
@@ -40,4 +50,15 @@ jobs:
4050
fi
4151
4252
- name: Build with CMake
43-
run: cmake --build build --config Release
53+
run: cmake --build build --config Release
54+
55+
- name: Run build smoke tests (Linux)
56+
if: runner.os == 'Linux'
57+
run: python -m pytest tests/test_build.py
58+
59+
- name: Run build smoke tests (Windows)
60+
if: runner.os == 'Windows'
61+
env:
62+
CC: C:\msys64\mingw64\bin\gcc.exe
63+
CXX: C:\msys64\mingw64\bin\g++.exe
64+
run: python -m pytest tests/test_build.py

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ install(TARGETS glatter
5959
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
6060
)
6161
install(DIRECTORY include/glatter DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
62+
install(DIRECTORY include/KHR include/EGL include/GLES include/GLES2 include/GLES3
63+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
64+
)
6265

6366
# --- Simple Integration Test ---
6467
add_executable(glatter-test tests/main.cpp)
@@ -70,4 +73,4 @@ target_link_libraries(glatter-test PRIVATE glatter)
7073
if(GLATTER_BUILD_INTERNAL_TESTS)
7174
enable_testing()
7275
add_subdirectory(tests/cmake)
73-
endif()
76+
endif()

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ void setup_scene() {
5757
```
5858
For header-only usage, include `<glatter/glatter_solo.h>`. This tiny wrapper defines
5959
`GLATTER_HEADER_ONLY` and includes the main header.
60+
Note: On MinGW/Windows, header-only mode requires C++17 (inline variables) to
61+
avoid multiple-definition linker errors.
6062

6163
### 2) Compiled C translation unit (C or C++)
6264

example/glatter/wglgears.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
349349
* Create an RGB, double-buffered window.
350350
* Return the window and context handles.
351351
*/
352-
static void make_window(LPCSTR name, int x, int y, int width, int height) {
352+
static void make_window(LPCWSTR name, int x, int y, int width, int height) {
353353
GLuint PixelFormat;
354354
WNDCLASS wc;
355355
DWORD dwExStyle, dwStyle;
@@ -480,7 +480,7 @@ main(int argc, char *argv[])
480480
}
481481

482482

483-
make_window("wglgears", 0, 0, 300, 300);
483+
make_window(L"wglgears", 0, 0, 300, 300);
484484
reshape(300, 300);
485485

486486
wglSwapIntervalEXT(0);

include/EGL/eglplatform.h

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
#ifndef __eglplatform_h_
2+
#define __eglplatform_h_
3+
4+
/*
5+
** Copyright 2007-2020 The Khronos Group Inc.
6+
** SPDX-License-Identifier: Apache-2.0
7+
*/
8+
9+
/* Platform-specific types and definitions for egl.h
10+
*
11+
* Adopters may modify khrplatform.h and this file to suit their platform.
12+
* You are encouraged to submit all modifications to the Khronos group so that
13+
* they can be included in future versions of this file. Please submit changes
14+
* by filing an issue or pull request on the public Khronos EGL Registry, at
15+
* https://www.github.com/KhronosGroup/EGL-Registry/
16+
*/
17+
18+
#include <KHR/khrplatform.h>
19+
20+
/* Macros used in EGL function prototype declarations.
21+
*
22+
* EGL functions should be prototyped as:
23+
*
24+
* EGLAPI return-type EGLAPIENTRY eglFunction(arguments);
25+
* typedef return-type (EXPAPIENTRYP PFNEGLFUNCTIONPROC) (arguments);
26+
*
27+
* KHRONOS_APICALL and KHRONOS_APIENTRY are defined in KHR/khrplatform.h
28+
*/
29+
30+
#ifndef EGLAPI
31+
#define EGLAPI KHRONOS_APICALL
32+
#endif
33+
34+
#ifndef EGLAPIENTRY
35+
#define EGLAPIENTRY KHRONOS_APIENTRY
36+
#endif
37+
#define EGLAPIENTRYP EGLAPIENTRY*
38+
39+
/* The types NativeDisplayType, NativeWindowType, and NativePixmapType
40+
* are aliases of window-system-dependent types, such as X Display * or
41+
* Windows Device Context. They must be defined in platform-specific
42+
* code below. The EGL-prefixed versions of Native*Type are the same
43+
* types, renamed in EGL 1.3 so all types in the API start with "EGL".
44+
*
45+
* Khronos STRONGLY RECOMMENDS that you use the default definitions
46+
* provided below, since these changes affect both binary and source
47+
* portability of applications using EGL running on different EGL
48+
* implementations.
49+
*/
50+
51+
#if defined(EGL_NO_PLATFORM_SPECIFIC_TYPES)
52+
53+
typedef void *EGLNativeDisplayType;
54+
typedef void *EGLNativePixmapType;
55+
typedef void *EGLNativeWindowType;
56+
57+
#elif defined(_WIN32) || defined(__VC32__) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) /* Win32 and WinCE */
58+
#ifndef WIN32_LEAN_AND_MEAN
59+
#define WIN32_LEAN_AND_MEAN 1
60+
#endif
61+
#include <windows.h>
62+
63+
typedef HDC EGLNativeDisplayType;
64+
typedef HBITMAP EGLNativePixmapType;
65+
typedef HWND EGLNativeWindowType;
66+
67+
#elif defined(__QNX__)
68+
69+
typedef khronos_uintptr_t EGLNativeDisplayType;
70+
typedef struct _screen_pixmap* EGLNativePixmapType; /* screen_pixmap_t */
71+
typedef struct _screen_window* EGLNativeWindowType; /* screen_window_t */
72+
73+
#elif defined(__EMSCRIPTEN__)
74+
75+
typedef int EGLNativeDisplayType;
76+
typedef int EGLNativePixmapType;
77+
typedef int EGLNativeWindowType;
78+
79+
#elif defined(__WINSCW__) || defined(__SYMBIAN32__) /* Symbian */
80+
81+
typedef int EGLNativeDisplayType;
82+
typedef void *EGLNativePixmapType;
83+
typedef void *EGLNativeWindowType;
84+
85+
#elif defined(WL_EGL_PLATFORM)
86+
87+
typedef struct wl_display *EGLNativeDisplayType;
88+
typedef struct wl_egl_pixmap *EGLNativePixmapType;
89+
typedef struct wl_egl_window *EGLNativeWindowType;
90+
91+
#elif defined(__GBM__)
92+
93+
typedef struct gbm_device *EGLNativeDisplayType;
94+
typedef struct gbm_bo *EGLNativePixmapType;
95+
typedef void *EGLNativeWindowType;
96+
97+
#elif defined(__ANDROID__) || defined(ANDROID)
98+
99+
struct ANativeWindow;
100+
struct egl_native_pixmap_t;
101+
102+
typedef void* EGLNativeDisplayType;
103+
typedef struct egl_native_pixmap_t* EGLNativePixmapType;
104+
typedef struct ANativeWindow* EGLNativeWindowType;
105+
106+
#elif defined(USE_OZONE)
107+
108+
typedef intptr_t EGLNativeDisplayType;
109+
typedef intptr_t EGLNativePixmapType;
110+
typedef intptr_t EGLNativeWindowType;
111+
112+
#elif defined(USE_X11)
113+
114+
/* X11 (tentative) */
115+
#include <X11/Xlib.h>
116+
#include <X11/Xutil.h>
117+
118+
typedef Display *EGLNativeDisplayType;
119+
typedef Pixmap EGLNativePixmapType;
120+
typedef Window EGLNativeWindowType;
121+
122+
#elif defined(__unix__)
123+
124+
typedef void *EGLNativeDisplayType;
125+
typedef khronos_uintptr_t EGLNativePixmapType;
126+
typedef khronos_uintptr_t EGLNativeWindowType;
127+
128+
#elif defined(__APPLE__)
129+
130+
typedef int EGLNativeDisplayType;
131+
typedef void *EGLNativePixmapType;
132+
typedef void *EGLNativeWindowType;
133+
134+
#elif defined(__HAIKU__)
135+
136+
#include <kernel/image.h>
137+
138+
typedef void *EGLNativeDisplayType;
139+
typedef khronos_uintptr_t EGLNativePixmapType;
140+
typedef khronos_uintptr_t EGLNativeWindowType;
141+
142+
#elif defined(__Fuchsia__)
143+
144+
typedef void *EGLNativeDisplayType;
145+
typedef khronos_uintptr_t EGLNativePixmapType;
146+
typedef khronos_uintptr_t EGLNativeWindowType;
147+
148+
#else
149+
#error "Platform not recognized"
150+
#endif
151+
152+
/* EGL 1.2 types, renamed for consistency in EGL 1.3 */
153+
typedef EGLNativeDisplayType NativeDisplayType;
154+
typedef EGLNativePixmapType NativePixmapType;
155+
typedef EGLNativeWindowType NativeWindowType;
156+
157+
158+
/* Define EGLint. This must be a signed integral type large enough to contain
159+
* all legal attribute names and values passed into and out of EGL, whether
160+
* their type is boolean, bitmask, enumerant (symbolic constant), integer,
161+
* handle, or other. While in general a 32-bit integer will suffice, if
162+
* handles are 64 bit types, then EGLint should be defined as a signed 64-bit
163+
* integer type.
164+
*/
165+
typedef khronos_int32_t EGLint;
166+
167+
168+
/* C++ / C typecast macros for special EGL handle values */
169+
#if defined(__cplusplus)
170+
#define EGL_CAST(type, value) (static_cast<type>(value))
171+
#else
172+
#define EGL_CAST(type, value) ((type) (value))
173+
#endif
174+
175+
#endif /* __eglplatform_h */

include/GLES/glplatform.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifndef __glplatform_h_
2+
#define __glplatform_h_
3+
4+
/*
5+
** Copyright 2017-2020 The Khronos Group Inc.
6+
** SPDX-License-Identifier: Apache-2.0
7+
*/
8+
9+
/* Platform-specific types and definitions for OpenGL ES 1.X gl.h
10+
*
11+
* Adopters may modify khrplatform.h and this file to suit their platform.
12+
* Please contribute modifications back to Khronos as pull requests on the
13+
* public github repository:
14+
* https://github.com/KhronosGroup/OpenGL-Registry
15+
*/
16+
17+
#include <KHR/khrplatform.h>
18+
19+
#ifndef GL_API
20+
#define GL_API KHRONOS_APICALL
21+
#endif
22+
23+
#ifndef GL_APIENTRY
24+
#define GL_APIENTRY KHRONOS_APIENTRY
25+
#endif
26+
27+
#endif /* __glplatform_h_ */

include/GLES2/gl2platform.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifndef __gl2platform_h_
2+
#define __gl2platform_h_
3+
4+
/*
5+
** Copyright 2017-2020 The Khronos Group Inc.
6+
** SPDX-License-Identifier: Apache-2.0
7+
*/
8+
9+
/* Platform-specific types and definitions for OpenGL ES 2.X gl2.h
10+
*
11+
* Adopters may modify khrplatform.h and this file to suit their platform.
12+
* Please contribute modifications back to Khronos as pull requests on the
13+
* public github repository:
14+
* https://github.com/KhronosGroup/OpenGL-Registry
15+
*/
16+
17+
#include <KHR/khrplatform.h>
18+
19+
#ifndef GL_APICALL
20+
#define GL_APICALL KHRONOS_APICALL
21+
#endif
22+
23+
#ifndef GL_APIENTRY
24+
#define GL_APIENTRY KHRONOS_APIENTRY
25+
#endif
26+
27+
#endif /* __gl2platform_h_ */

include/GLES3/gl3platform.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifndef __gl3platform_h_
2+
#define __gl3platform_h_
3+
4+
/*
5+
** Copyright 2017-2020 The Khronos Group Inc.
6+
** SPDX-License-Identifier: Apache-2.0
7+
*/
8+
9+
/* Platform-specific types and definitions for OpenGL ES 3.X gl3.h
10+
*
11+
* Adopters may modify khrplatform.h and this file to suit their platform.
12+
* Please contribute modifications back to Khronos as pull requests on the
13+
* public github repository:
14+
* https://github.com/KhronosGroup/OpenGL-Registry
15+
*/
16+
17+
#include <KHR/khrplatform.h>
18+
19+
#ifndef GL_APICALL
20+
#define GL_APICALL KHRONOS_APICALL
21+
#endif
22+
23+
#ifndef GL_APIENTRY
24+
#define GL_APIENTRY KHRONOS_APIENTRY
25+
#endif
26+
27+
#endif /* __gl3platform_h_ */

0 commit comments

Comments
 (0)