LibreOffice Module vcl (master)  1
OpenGLContext.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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  */
9 
10 #ifndef INCLUDED_VCL_OPENGL_OPENGLCONTEXT_HXX
11 #define INCLUDED_VCL_OPENGL_OPENGLCONTEXT_HXX
12 
13 #include <epoxy/gl.h>
14 
15 #include <vcl/dllapi.h>
16 #include <vcl/syschild.hxx>
17 #include <rtl/ref.hxx>
18 
19 #include <memory>
20 #include <unordered_map>
21 
22 class OpenGLFramebuffer;
23 class OpenGLProgram;
24 class OpenGLTexture;
25 class RenderState;
26 
29 {
30  unsigned int Width;
31  unsigned int Height;
33 
35  : Width(0)
36  , Height(0)
37  , bMultiSampleSupported(false)
38  {
39  }
40 
41  virtual bool Synchronize(bool bOnoff) const;
42 
43  virtual ~GLWindow();
44 };
45 
47 {
49 
51  : mbLimitedShaderRegisters(false)
52  {}
53 };
54 
56 {
57  friend class OpenGLTests;
58 protected:
59  OpenGLContext();
60 public:
62  virtual ~OpenGLContext();
63  void acquire() { mnRefCount++; }
64  void release() { if ( --mnRefCount == 0 ) delete this; }
65  void dispose();
66 
67  void requestLegacyContext();
68 
69  bool init(vcl::Window* pParent);
70 
71  void reset();
72 
73  // use these methods right after setting a context to make sure drawing happens
74  // in the right FBO (default one is for onscreen painting)
75  void BindFramebuffer( OpenGLFramebuffer* pFramebuffer );
76  void AcquireDefaultFramebuffer();
77  OpenGLFramebuffer* AcquireFramebuffer( const OpenGLTexture& rTexture );
78  static void ReleaseFramebuffer( OpenGLFramebuffer* pFramebuffer );
79  void UnbindTextureFromFramebuffers( GLuint nTexture );
80  static bool IsTextureAttachedAnywhere( GLuint nTexture );
81 
82  void ReleaseFramebuffer( const OpenGLTexture& rTexture );
83  void ReleaseFramebuffers();
84 
85  // retrieve a program from the cache or compile/link it
86  OpenGLProgram* GetProgram( const OUString& rVertexShader, const OUString& rFragmentShader, const OString& preamble = "" );
87  OpenGLProgram* UseProgram( const OUString& rVertexShader, const OUString& rFragmentShader, const OString& preamble = "" );
88 
90  {
91  return *mpRenderState;
92  }
93 
95  {
96  return maOpenGLCapabilitySwitch;
97  }
98 
100  virtual bool isCurrent();
102  virtual bool isAnyCurrent();
104  static void clearCurrent();
106  static void prepareForYield();
108  static bool hasCurrent();
109 
111  static void makeVCLCurrent();
113  static rtl::Reference<OpenGLContext> getVCLContext(bool bMakeIfNecessary = true);
115  virtual void makeCurrent();
117  void registerAsCurrent();
119  virtual void resetCurrent();
121  virtual void restoreDefaultFramebuffer();
122  virtual void swapBuffers();
123  virtual void sync();
124  void show();
125 
126  void setWinPosAndSize(const Point &rPos, const Size& rSize);
127  virtual const GLWindow& getOpenGLWindow() const = 0;
128 
129  SystemChildWindow* getChildWindow();
130  const SystemChildWindow* getChildWindow() const;
131 
132  bool isInitialized() const
133  {
134  return mbInitialized;
135  }
136 
138  void setVCLOnly() { mbVCLOnly = true; }
139  bool isVCLOnly() const { return mbVCLOnly; }
140 
141  virtual SystemWindowData generateWinData(vcl::Window* pParent, bool bRequestLegacyContext);
142 
143 private:
144  virtual void initWindow();
145  virtual void destroyCurrentContext();
146  virtual void adjustToNewSize();
147 
148 protected:
149  bool InitGL();
150  static void InitGLDebugging();
151  static void InitChildWindow(SystemChildWindow *pChildWindow);
152  static void BuffersSwapped();
153  virtual GLWindow& getModifiableOpenGLWindow() = 0;
154  virtual bool ImplInit();
155 
157  VclPtr<vcl::Window> mpWindow; //points to m_pWindow or the parent window, don't delete it
162  bool mbVCLOnly;
163 
168 
170 
171 private:
172  typedef std::unordered_map< OString, std::shared_ptr<OpenGLProgram> > ProgramCollection;
173  ProgramCollection maPrograms;
175 
176  std::unique_ptr<RenderState> mpRenderState;
177 
178 public:
180 
181  // Don't hold references to ourselves:
184 };
185 
186 #endif
187 
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< RenderState > mpRenderState
bool bMultiSampleSupported
RenderState & state()
OpenGLContext * mpNextContext
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
vcl::Region maClipRegion
unsigned int Height
bool mbInitialized
std::unordered_map< OString, std::shared_ptr< OpenGLProgram > > ProgramCollection
bool mbRequestLegacyContext
bool isInitialized() const
OpenGLProgram * mpCurrentProgram
OpenGLFramebuffer * mpCurrentFramebuffer
Holds the information of our new child window.
OpenGLFramebuffer * mpLastFramebuffer
OpenGLCapabilitySwitch maOpenGLCapabilitySwitch
bool isVCLOnly() const
ProgramCollection maPrograms
OpenGLContext * mpPrevContext
void setVCLOnly()
VCL promiscuously re-uses its own contexts:
unsigned int Width
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
VclPtr< vcl::Window > m_xWindow
OpenGLCapabilitySwitch & getOpenGLCapabilitySwitch()
FILE * init(int, char **)
VclPtr< SystemChildWindow > m_pChildWindow
OpenGLFramebuffer * mpFirstFramebuffer
void dispose()
VclPtr< vcl::Window > mpWindow