1 #ifndef VVGL_GLContext_hpp 2 #define VVGL_GLContext_hpp 4 #include "VVGL_Defines.hpp" 8 #if defined(VVGL_SDK_MAC) 9 #pragma clang diagnostic push 10 #pragma clang diagnostic ignored "-W#warnings" 11 #import <OpenGL/OpenGL.h> 13 #import <OpenGL/glext.h> 14 #import <OpenGL/gl3.h> 15 #import <OpenGL/gl3ext.h> 16 #pragma clang diagnostic pop 17 #elif defined(VVGL_SDK_IOS) 20 #import <OpenGLES/ES3/glext.h> 23 #elif defined(VVGL_SDK_RPI) 27 #include <GLES2/gl2.h> 28 #include <GLES2/gl2ext.h> 30 #include <EGL/eglext.h> 31 #elif defined(VVGL_SDK_GLFW) 34 #include <GLFW/glfw3.h> 35 #elif defined(VVGL_SDK_QT) 38 #include "GLQtCtxWrapper.hpp" 43 #include "VVGL_Geom.hpp" 57 #if defined(VVGL_SDK_MAC) 62 uint32_t GLDisplayMaskForAllScreens();
67 CGLPixelFormatObj CreateDefaultPixelFormat();
72 CGLPixelFormatObj CreateCompatibilityGLPixelFormat();
77 CGLPixelFormatObj CreateGL3PixelFormat();
82 CGLPixelFormatObj CreateGL4PixelFormat();
83 #elif defined(VVGL_SDK_QT) 88 VVGL_EXPORT QSurfaceFormat CreateDefaultSurfaceFormat();
93 VVGL_EXPORT QSurfaceFormat CreateCompatibilityGLSurfaceFormat();
98 VVGL_EXPORT QSurfaceFormat CreateGL3SurfaceFormat();
103 VVGL_EXPORT QSurfaceFormat CreateGL4SurfaceFormat();
122 #if defined(VVGL_SDK_MAC) 123 CGLContextObj ctx =
nullptr;
124 CGLContextObj sharedCtx =
nullptr;
125 CGLPixelFormatObj pxlFmt =
nullptr;
126 #elif defined(VVGL_SDK_IOS) 128 #elif defined(VVGL_SDK_GLFW) 129 GLFWwindow *win =
nullptr;
130 bool initializedFuncs =
false;
131 #elif defined(VVGL_SDK_RPI) 132 EGLDisplay display = EGL_NO_DISPLAY;
133 EGLSurface winSurface = EGL_NO_SURFACE;
134 EGLContext sharedCtx = EGL_NO_CONTEXT;
135 bool ownsTheCtx =
false;
136 EGLContext ctx = EGL_NO_CONTEXT;
137 #elif defined(VVGL_SDK_QT) 138 GLQtCtxWrapper *ctx =
nullptr;
139 QSurfaceFormat sfcFmt = CreateDefaultSurfaceFormat();
140 bool initializedFuncs =
false;
144 std::string _renderer = std::string(
"");
149 #if defined(VVGL_SDK_MAC) 151 GLContext(
const CGLContextObj & inCtx,
const CGLContextObj & inShareCtx,
const CGLPixelFormatObj & inPxlFm=CreateDefaultPixelFormat());
153 GLContext(
const CGLContextObj & inShareCtx,
const CGLPixelFormatObj & inPxlFmt=CreateDefaultPixelFormat());
156 CGLContextObj contextObj() {
return ctx; }
158 CGLContextObj sharedContextObj() {
return sharedCtx; }
160 CGLPixelFormatObj pixelFormatObj() {
return pxlFmt; }
161 #elif defined(VVGL_SDK_IOS) 168 #elif defined(VVGL_SDK_GLFW) 170 #elif defined(VVGL_SDK_RPI) 172 GLContext(EGLDisplay inDisplay, EGLSurface inWinSurface, EGLContext inSharedCtx, EGLContext inCtx);
174 GLContext(EGLDisplay inDisplay, EGLSurface inWinSurface, EGLContext inSharedCtx);
175 #elif defined(VVGL_SDK_QT) 179 GLContext(QSurface * inTargetSurface, QOpenGLContext * inCtx,
bool inCreateCtx=
true, QSurfaceFormat inSfcFmt=CreateDefaultSurfaceFormat());
183 static QOpenGLContext * GetCurrentContext();
185 void setSurface(
const QSurface * inTargetSurface);
187 void moveToThread(QThread * inThread);
188 QOpenGLContext * context();
189 QObject * contextAsObject();
190 QThread * contextThread();
191 QVariant nativeHandle();
209 void calculateVersion();
224 void makeCurrentIfNotCurrent();
226 void makeCurrentIfNull();
230 #if defined(VVGL_SDK_MAC) 231 bool sameShareGroupAs(
const CGLContextObj & inCtx);
234 std::string getRenderer() {
return _renderer; }
237 friend ostream & operator<<(ostream & os,
const GLContext & n);
238 friend ostream & operator<<(ostream & os,
const GLContext * n);
245 #if defined(VVGL_SDK_MAC) 250 inline GLContextRef CreateGLContextRefUsing(
const CGLContextObj & inCtx,
const CGLContextObj & inShareCtx,
const CGLPixelFormatObj & inPxlFmt=CreateDefaultPixelFormat()) {
return make_shared<GLContext>(inCtx, inShareCtx, inPxlFmt); }
255 inline GLContextRef CreateNewGLContextRef(
const CGLContextObj & inShareCtx,
const CGLPixelFormatObj & inPxlFmt=CreateDefaultPixelFormat()) {
return make_shared<GLContext>(inShareCtx, inPxlFmt); }
256 #elif defined(VVGL_SDK_IOS) 261 inline GLContextRef CreateGLContextRefUsing(
const void * inEAGLContext) {
return make_shared<GLContext>(inEAGLContext); }
262 #elif defined(VVGL_SDK_GLFW) 267 inline GLContextRef CreateGLContextRefUsing(GLFWwindow * inWindow) {
return make_shared<GLContext>(inWindow); }
268 #elif defined(VVGL_SDK_RPI) 273 inline GLContextRef CreateGLContextRefUsing(EGLDisplay inDisplay, EGLSurface inWinSurface, EGLContext inSharedCtx, EGLContext inCtx) {
return make_shared<GLContext>(inDisplay, inWinSurface, inSharedCtx, inCtx); }
278 inline GLContextRef CreateNewGLContextRef(EGLDisplay inDisplay, EGLSurface inWinSurface, EGLContext inSharedCtx) {
return make_shared<GLContext>(inDisplay, inWinSurface, inSharedCtx); }
279 #elif defined(VVGL_SDK_QT) 287 inline GLContextRef CreateGLContextRefUsing(QSurface * inTargetSurface, QOpenGLContext * inCtx, QSurfaceFormat inSfcFmt=CreateDefaultSurfaceFormat()) {
return make_shared<GLContext>(inTargetSurface, inCtx,
false, inSfcFmt); }
295 inline GLContextRef CreateNewGLContextRef(QSurface * inTargetSurface, QOpenGLContext * inShareCtx, QSurfaceFormat inSfcFmt=CreateDefaultSurfaceFormat()) {
return make_shared<GLContext>(inTargetSurface, inShareCtx,
true, inSfcFmt); }
GLContextRef CreateGLContextRefUsing(QSurface *inTargetSurface, QOpenGLContext *inCtx, QSurfaceFormat inSfcFmt=CreateDefaultSurfaceFormat())
Doesn't create any GL resources, just makes a new GLContext instance using the passed resources...
Definition: GLContext.hpp:287
Definition: GLBuffer.hpp:13
GLContext is an attempt to make a platform/SDK-agnostic representation of an OpenGL context...
Definition: GLContext.hpp:119
GLContextRef CreateNewGLContextRef()
Creates a generic OpenGL context and GLContext instance using whatever the default settings are for t...
Definition: GLContext.hpp:301
GLContextRef CreateNewGLContextRef(QSurface *inTargetSurface, QOpenGLContext *inShareCtx, QSurfaceFormat inSfcFmt=CreateDefaultSurfaceFormat())
Creates a new OpenGL context and GLContext instance.
Definition: GLContext.hpp:295
GLVersion
This enum is used to describe the GL environment of a GL context, which is determined at runtime...
Definition: VVGL_Base.hpp:94
shared_ptr< GLContext > GLContextRef
A GLContextRef is a shared pointer around a GLContext.
Definition: VVGL_Base.hpp:60