1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <QtOpenGLContext.hxx>
24 #include <vcl/sysdata.hxx>
25 #include <opengl/zone.hxx>
26 #include <sal/log.hxx>
30 #include <QtObject.hxx>
32 #include <QtGui/QOpenGLContext>
33 #include <QtGui/QWindow>
35 bool QtOpenGLContext::g_bAnyCurrent
= false;
37 void QtOpenGLContext::swapBuffers()
41 if (m_pContext
&& m_pWindow
&& m_pWindow
->isExposed())
43 m_pContext
->swapBuffers(m_pWindow
);
49 void QtOpenGLContext::resetCurrent()
57 m_pContext
->doneCurrent();
58 g_bAnyCurrent
= false;
62 bool QtOpenGLContext::isCurrent()
65 return g_bAnyCurrent
&& (QOpenGLContext::currentContext() == m_pContext
);
68 bool QtOpenGLContext::isAnyCurrent()
71 return g_bAnyCurrent
&& (QOpenGLContext::currentContext() != nullptr);
74 bool QtOpenGLContext::ImplInit()
78 SAL_WARN("vcl.opengl.qt", "failed to create window");
82 m_pWindow
->setSurfaceType(QSurface::OpenGLSurface
);
85 m_pContext
= new QOpenGLContext(m_pWindow
);
86 if (!m_pContext
->create())
88 SAL_WARN("vcl.opengl.qt", "failed to create context");
92 m_pContext
->makeCurrent(m_pWindow
);
98 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
);
105 void QtOpenGLContext::makeCurrent()
114 if (m_pContext
&& m_pWindow
)
116 m_pContext
->makeCurrent(m_pWindow
);
117 g_bAnyCurrent
= true;
123 void QtOpenGLContext::destroyCurrentContext()
129 m_pContext
->doneCurrent();
130 g_bAnyCurrent
= false;
133 if (glGetError() != GL_NO_ERROR
)
135 SAL_WARN("vcl.opengl.qt", "glError: " << glGetError());
139 void QtOpenGLContext::initWindow()
143 SystemWindowData winData
= generateWinData(mpWindow
, mbRequestLegacyContext
);
144 m_pChildWindow
= VclPtr
<SystemChildWindow
>::Create(mpWindow
, 0, &winData
, false);
149 InitChildWindow(m_pChildWindow
.get());
153 = static_cast<QtObject
*>(m_pChildWindow
->ImplGetWindowImpl()->mpSysObj
)->windowHandle();