workaround segfault in compiler on macos-clang-intel
[LibreOffice.git] / include / vcl / opengl / OpenGLContext.hxx
blob8cb5faa30d92fa4aee1b1a9bf9450fe3052b825b
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/.
8 */
10 #pragma once
12 #include <vcl/dllapi.h>
13 #include <vcl/sysdata.hxx>
14 #include <vcl/vclptr.hxx>
15 #include <rtl/ref.hxx>
17 class Point;
18 class Size;
19 class SystemChildWindow;
20 namespace vcl { class Window; }
22 /// Holds the information of our new child window
23 struct VCL_DLLPUBLIC GLWindow
25 unsigned int Width;
26 unsigned int Height;
27 bool bMultiSampleSupported;
29 GLWindow()
30 : Width(0)
31 , Height(0)
32 , bMultiSampleSupported(false)
36 virtual bool Synchronize(bool bOnoff) const;
38 virtual ~GLWindow();
41 class VCL_DLLPUBLIC OpenGLContext
43 friend class OpenGLTests;
44 protected:
45 OpenGLContext();
46 public:
47 static rtl::Reference<OpenGLContext> Create();
48 virtual ~OpenGLContext();
50 // Avoid implicitly defined copy constructors/assignments for the DLLPUBLIC class (they may
51 // require forward-declared classes used internally to be defined in places using OpenGLContext)
52 OpenGLContext(const OpenGLContext&) = delete;
53 OpenGLContext(OpenGLContext&&) = delete;
54 OpenGLContext& operator=(const OpenGLContext&) = delete;
55 OpenGLContext& operator=(OpenGLContext&&) = delete;
57 void acquire() { mnRefCount++; }
58 void release() { if ( --mnRefCount == 0 ) delete this; }
59 void dispose();
61 void requestLegacyContext();
63 bool init(vcl::Window* pParent);
65 void reset();
67 /// Is this GL context the current context ?
68 virtual bool isCurrent();
69 /// Is any GL context the current context ?
70 virtual bool isAnyCurrent();
71 /// release bound resources from the current context
72 static void clearCurrent();
73 /// release contexts etc. before (potentially) allowing another thread run.
74 SAL_DLLPRIVATE static void prepareForYield();
75 /// Is there a current GL context ?
76 SAL_DLLPRIVATE static bool hasCurrent();
78 /// make this GL context current - so it is implicit in subsequent GL calls
79 SAL_DLLPRIVATE virtual void makeCurrent();
80 /// Put this GL context to the end of the context list.
81 void registerAsCurrent();
82 /// reset the GL context so this context is not implicit in subsequent GL calls.
83 SAL_DLLPRIVATE virtual void resetCurrent();
84 /// unbind the GL_FRAMEBUFFER to its default state, needed for gtk3
85 virtual void restoreDefaultFramebuffer();
86 SAL_DLLPRIVATE virtual void swapBuffers();
87 virtual void sync();
88 void show();
90 void setWinPosAndSize(const Point &rPos, const Size& rSize);
91 virtual const GLWindow& getOpenGLWindow() const = 0;
93 SystemChildWindow* getChildWindow();
94 SAL_DLLPRIVATE const SystemChildWindow* getChildWindow() const;
96 bool isInitialized() const
98 return mbInitialized;
101 virtual SystemWindowData generateWinData(vcl::Window* pParent, bool bRequestLegacyContext);
103 private:
104 SAL_DLLPRIVATE virtual void initWindow();
105 SAL_DLLPRIVATE virtual void destroyCurrentContext();
106 virtual void adjustToNewSize();
108 protected:
109 bool InitGL();
110 static void InitGLDebugging();
111 static void InitChildWindow(SystemChildWindow *pChildWindow);
112 static void BuffersSwapped();
113 virtual GLWindow& getModifiableOpenGLWindow() = 0;
114 SAL_DLLPRIVATE virtual bool ImplInit();
116 VclPtr<vcl::Window> m_xWindow;
117 VclPtr<vcl::Window> mpWindow; //points to m_pWindow or the parent window, don't delete it
118 VclPtr<SystemChildWindow> m_pChildWindow;
119 bool mbInitialized;
120 int mnRefCount;
121 bool mbRequestLegacyContext;
123 public:
125 // Don't hold references to ourselves:
126 OpenGLContext *mpPrevContext;
127 OpenGLContext *mpNextContext;
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */