2019-10-23 12:32:32 +01:00
|
|
|
#if !defined(GLES_COMPATIBILITY)
|
2016-06-28 05:12:38 +03:00
|
|
|
#include "GSH_OpenGLQt.h"
|
2019-10-23 12:32:32 +01:00
|
|
|
#endif
|
|
|
|
|
2020-02-02 19:44:10 +00:00
|
|
|
#include <QSurface>
|
2020-02-06 14:58:57 +00:00
|
|
|
#include <QWindow>
|
2016-06-28 05:12:38 +03:00
|
|
|
#include <QOpenGLContext>
|
|
|
|
|
2019-10-23 12:32:32 +01:00
|
|
|
#if defined(GLES_COMPATIBILITY)
|
|
|
|
#include "GSH_OpenGLQt.h"
|
|
|
|
#endif
|
|
|
|
|
2020-08-21 17:23:48 -04:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <CoreFoundation/CoreFoundation.h>
|
|
|
|
#endif
|
|
|
|
|
2020-02-02 19:44:10 +00:00
|
|
|
CGSH_OpenGLQt::CGSH_OpenGLQt(QSurface* renderSurface)
|
|
|
|
: m_renderSurface(renderSurface)
|
2016-06-28 05:12:38 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-02-02 19:44:10 +00:00
|
|
|
CGSH_OpenGL::FactoryFunction CGSH_OpenGLQt::GetFactoryFunction(QSurface* renderSurface)
|
2016-06-28 05:12:38 +03:00
|
|
|
{
|
2020-02-02 19:44:10 +00:00
|
|
|
return [renderSurface]() { return new CGSH_OpenGLQt(renderSurface); };
|
2016-06-28 05:12:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGSH_OpenGLQt::InitializeImpl()
|
|
|
|
{
|
2020-08-21 17:23:48 -04:00
|
|
|
#ifdef __APPLE__
|
|
|
|
//When building against macOS SDK 10.15+ and running on macOS 10.15+, the system will trigger an assert because we
|
|
|
|
//are not using NSOpenGLContext on the main thread. Disable this assert since it doesn't cause any problem if we do.
|
|
|
|
CFPreferencesSetAppValue(CFSTR("NSOpenGLContextSuppressThreadAssertions"), kCFBooleanTrue, kCFPreferencesCurrentApplication);
|
|
|
|
#endif
|
2020-08-30 12:03:43 -04:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
m_context = new QOpenGLContext();
|
2020-02-02 19:44:10 +00:00
|
|
|
m_context->setFormat(m_renderSurface->format());
|
2016-06-28 05:12:38 +03:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
bool succeeded = m_context->create();
|
|
|
|
Q_ASSERT(succeeded);
|
2016-06-28 05:12:38 +03:00
|
|
|
|
2020-02-02 19:44:10 +00:00
|
|
|
succeeded = m_context->makeCurrent(m_renderSurface);
|
2018-04-30 21:01:23 +01:00
|
|
|
Q_ASSERT(succeeded);
|
2016-06-28 05:12:38 +03:00
|
|
|
|
2019-07-05 15:50:33 +01:00
|
|
|
#ifdef USE_GLEW
|
2018-04-30 21:01:23 +01:00
|
|
|
glewExperimental = GL_TRUE;
|
|
|
|
auto result = glewInit();
|
|
|
|
Q_ASSERT(result == GLEW_OK);
|
2018-05-23 03:11:24 +03:00
|
|
|
#endif
|
2016-06-28 05:12:38 +03:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
CGSH_OpenGL::InitializeImpl();
|
2016-06-28 05:12:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGSH_OpenGLQt::ReleaseImpl()
|
|
|
|
{
|
|
|
|
CGSH_OpenGL::ReleaseImpl();
|
|
|
|
|
|
|
|
delete m_context;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGSH_OpenGLQt::PresentBackbuffer()
|
|
|
|
{
|
2020-02-06 14:58:57 +00:00
|
|
|
bool swapBuffer = true;
|
|
|
|
if(m_renderSurface->surfaceClass() == QSurface::Window)
|
|
|
|
{
|
|
|
|
swapBuffer = static_cast<QWindow*>(m_renderSurface)->isExposed();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(swapBuffer)
|
|
|
|
{
|
|
|
|
m_context->swapBuffers(m_renderSurface);
|
|
|
|
m_context->makeCurrent(m_renderSurface);
|
|
|
|
}
|
2016-06-28 05:12:38 +03:00
|
|
|
}
|