Cogs.Core
GLContext.h
1#pragma once
2
3#ifdef COGS_EGL
4 #ifndef __EMSCRIPTEN__
5 #define EGL_EGL_PROTOTYPES 0
6 #endif
7 #include <EGL/egl.h>
8 #include <EGL/eglext.h>
9 #undef Always
10 #undef None
11#endif // of COGS_EGL
12
13
14#ifdef __linux__
15#include <X11/Xlib.h>
16#include <X11/Xutil.h>
17#undef Always
18#undef None
19#endif
20
21#ifdef COGS_GLX
22#include <GL/glx.h>
23#include <GL/glxext.h>
24#endif // of COGS_GLX
25
26#ifdef COGS_WGL
27#include <KHR/khrplatform.h>
28#include <GL/glcorearb.h>
29#include <GL/wgl.h>
30#include <GL/wglext.h>
31#endif // of COGS_WGL
32
33#include <stdint.h>
34
35#if defined( __APPLE__ )
36 #if defined __OBJC__
37 @class NSOpenGLContext;
38 typedef NSOpenGLContext* NSContextPtr;
39 #else
40 typedef struct NSOpenGLContext* NSContextPtr;
41 #endif
42#endif
43
44namespace Cogs {
45
46 struct WindowData;
47 struct GraphicsDeviceSettings;
48
50 {
51#ifdef _WIN32
52 typedef HDC NativeDisplay;
53#elif defined(COGS_GLX)
54 typedef Display* NativeDisplay;
55#elif defined(COGS_EGL)
56 typedef EGLNativeDisplayType NativeDisplay;
57#else
58 typedef void* NativeDisplay;
59#endif
60
61 enum struct Platform
62 {
63 None,
64 ES3,
65 GL
66 };
67 Platform platform = Platform::None;
68
69 };
70 bool setUpGLDebugging(const char* contextName, GLContextBase::Platform platform);
71
72#ifdef _WIN32
73 struct GLContext : GLContextBase
74 {
75 ~GLContext() { destroy(); }
76
77 bool create(NativeDisplay display, WindowData* windowData, GLContext* shareContext, const GraphicsDeviceSettings* settings, Platform desiredPlatform, bool debug);
78 bool makeCurrent();
79 void swapBuffers(uint32_t syncInterval, uint32_t presentFlags);
80 void destroy();
81
82 HDC hdc = nullptr;
83 HGLRC context = nullptr;
84 HWND headlessHwnd = nullptr; // Dummy window for headless contexts, null otherwise.
85 };
86#endif
87
88#ifdef __APPLE__
89struct GLContext : GLContextBase
90{
91 GLContext(NSContextPtr c = nullptr) : context(c) {}
92 ~GLContext() { destroy(); }
93
94 bool create(NativeDisplay display, WindowData* windowData, GLContext* shareContext, const GraphicsDeviceSettings* settings, Platform desiredPlatform, bool debug);
95 bool makeCurrent();
96 void swapBuffers(uint32_t syncInterval, uint32_t presentFlags);
97 void destroy();
98
99 NSContextPtr context;
100};
101#endif
102
103#ifdef COGS_GLX
104
105 struct GLContext : GLContextBase
106 {
107 ~GLContext() { destroy(); }
108
109 bool create(NativeDisplay display, WindowData* windowData, GLContext* shareContext, const GraphicsDeviceSettings* settings, Platform desiredPlatform, bool debug);
110 bool makeCurrent();
111 void swapBuffers(uint32_t syncInterval, uint32_t presentFlags);
112 void destroy();
113
114 static GLXFBConfig getFBConfig(NativeDisplay display, int requestedSampleCount);
115 static XVisualInfo* getVisualInfo(Display* display, GLXFBConfig fbConfig);
116
117 Display* dpy = nullptr;
118 Window win = 0;
119 GLXContext glc = nullptr;
120 static GLXFBConfig fbConfig;
121
122 bool ownWindow = false;
123 bool ownContext = false;
124 };
125 bool getGLXFuncPointers();
126#endif
127
128#ifdef COGS_EGL
129 struct GLContext : GLContextBase
130 {
131 ~GLContext() { destroy(); }
132
133 EGLDisplay eglDisplay = nullptr;
134 EGLContext eglContext = nullptr;
135 EGLSurface eglSurface = nullptr;
136 bool ownContext = false;
137 bool ownDisplay = false;
138
139 bool create(NativeDisplay display, WindowData* windowData, GLContext* shareContext, const GraphicsDeviceSettings* settings, Platform desiredPlatform, bool debug);
140 bool makeCurrent();
141 void swapBuffers(uint32_t syncInterval, uint32_t presentFlags);
142 void destroy();
143 };
144#endif // of COGS_EGL
145
146 bool getGLFuncPointers();
147 bool getGLES3FuncPointers(GLContextBase::Platform platform);
148
149}
Contains all Cogs related functionality.
Definition: FieldSetter.h:23