Play-/Source/ui_qt/GSH_OpenGLQt.cpp

54 lines
1 KiB
C++
Raw Normal View History

#include "GSH_OpenGLQt.h"
#include <QWindow>
#include <QOpenGLContext>
CGSH_OpenGLQt::CGSH_OpenGLQt(QWindow* renderWindow)
2018-04-30 21:01:23 +01:00
: m_renderWindow(renderWindow)
{
}
CGSH_OpenGLQt::~CGSH_OpenGLQt()
{
}
CGSH_OpenGL::FactoryFunction CGSH_OpenGLQt::GetFactoryFunction(QWindow* renderWindow)
{
2018-04-30 21:01:23 +01:00
return [renderWindow]() { return new CGSH_OpenGLQt(renderWindow); };
}
void CGSH_OpenGLQt::InitializeImpl()
{
2018-04-30 21:01:23 +01:00
m_context = new QOpenGLContext();
m_context->setFormat(m_renderWindow->requestedFormat());
2018-04-30 21:01:23 +01:00
bool succeeded = m_context->create();
Q_ASSERT(succeeded);
2018-04-30 21:01:23 +01:00
succeeded = m_context->makeCurrent(m_renderWindow);
Q_ASSERT(succeeded);
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
2018-04-30 21:01:23 +01:00
CGSH_OpenGL::InitializeImpl();
}
void CGSH_OpenGLQt::ReleaseImpl()
{
CGSH_OpenGL::ReleaseImpl();
delete m_context;
}
void CGSH_OpenGLQt::PresentBackbuffer()
{
2018-04-30 21:01:23 +01:00
if(m_renderWindow->isExposed())
{
m_context->swapBuffers(m_renderWindow);
m_context->makeCurrent(m_renderWindow);
}
}