bump product version to 6.4.0.3
[LibreOffice.git] / vcl / qt5 / Qt5OpenGLContext.cxx
bloba33f7abde2f5a49f72dd08405359a024ea1470a6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <Qt5OpenGLContext.hxx>
22 #include <vcl/sysdata.hxx>
23 #include <opengl/zone.hxx>
24 #include <sal/log.hxx>
26 #include <window.h>
28 #include <Qt5Object.hxx>
30 #include <QtGui/QOpenGLContext>
31 #include <QtGui/QWindow>
33 bool Qt5OpenGLContext::g_bAnyCurrent = false;
35 void Qt5OpenGLContext::swapBuffers()
37 OpenGLZone aZone;
39 if (m_pContext && m_pWindow && m_pWindow->isExposed())
41 m_pContext->swapBuffers(m_pWindow);
44 BuffersSwapped();
47 void Qt5OpenGLContext::resetCurrent()
49 clearCurrent();
51 OpenGLZone aZone;
53 if (m_pContext)
55 m_pContext->doneCurrent();
56 g_bAnyCurrent = false;
60 bool Qt5OpenGLContext::isCurrent()
62 OpenGLZone aZone;
63 return g_bAnyCurrent && (QOpenGLContext::currentContext() == m_pContext);
66 bool Qt5OpenGLContext::isAnyCurrent()
68 OpenGLZone aZone;
69 return g_bAnyCurrent && (QOpenGLContext::currentContext() != nullptr);
72 bool Qt5OpenGLContext::ImplInit()
74 if (!m_pWindow)
76 SAL_WARN("vcl.opengl.qt5", "failed to create window");
77 return false;
80 m_pWindow->setSurfaceType(QSurface::OpenGLSurface);
81 m_pWindow->create();
83 m_pContext = new QOpenGLContext(m_pWindow);
84 if (!m_pContext->create())
86 SAL_WARN("vcl.opengl.qt5", "failed to create context");
87 return false;
90 m_pContext->makeCurrent(m_pWindow);
91 g_bAnyCurrent = true;
93 bool bRet = InitGL();
94 InitGLDebugging();
96 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
98 registerAsCurrent();
100 return bRet;
103 void Qt5OpenGLContext::makeCurrent()
105 if (isCurrent())
106 return;
108 OpenGLZone aZone;
110 clearCurrent();
112 if (m_pContext && m_pWindow)
114 m_pContext->makeCurrent(m_pWindow);
115 g_bAnyCurrent = true;
118 registerAsCurrent();
121 void Qt5OpenGLContext::destroyCurrentContext()
123 OpenGLZone aZone;
125 if (m_pContext)
127 m_pContext->doneCurrent();
128 g_bAnyCurrent = false;
131 if (glGetError() != GL_NO_ERROR)
133 SAL_WARN("vcl.opengl.qt5", "glError: " << glGetError());
137 void Qt5OpenGLContext::initWindow()
139 if (!m_pChildWindow)
141 SystemWindowData winData = generateWinData(mpWindow, mbRequestLegacyContext);
142 m_pChildWindow = VclPtr<SystemChildWindow>::Create(mpWindow, 0, &winData, false);
145 if (m_pChildWindow)
147 InitChildWindow(m_pChildWindow.get());
150 m_pWindow
151 = static_cast<Qt5Object*>(m_pChildWindow->ImplGetWindowImpl()->mpSysObj)->windowHandle();