diff options
author | Caolán McNamara <caolanm@redhat.com> | 2016-05-20 09:41:18 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2016-05-21 10:04:15 +0100 |
commit | b8d163f4334424e78290eae49713e6ba2405b30f (patch) | |
tree | 55e78506accb6fe4dbbc1ecb918e4ccc2f510254 /vcl/osx/salobj.cxx | |
parent | da03b62bb4d44ad1410a4dff15f97bacd55fb99b (diff) |
Split OpenGLContext up into SalInstance specific classes
which, at least theoretically, allows there to be vclplug
specific ones. i.e. a gtk3 specific one which doesn't
assume gtk3 is running under X
Change-Id: I6c007a87abbd3049b6fffc70d349e3b7ac445eec
Diffstat (limited to 'vcl/osx/salobj.cxx')
-rw-r--r-- | vcl/osx/salobj.cxx | 109 |
1 files changed, 108 insertions, 1 deletions
diff --git a/vcl/osx/salobj.cxx b/vcl/osx/salobj.cxx index 87edbfa9a1ed..6bbb43aa51a8 100644 --- a/vcl/osx/salobj.cxx +++ b/vcl/osx/salobj.cxx @@ -18,10 +18,15 @@ */ #include <string.h> +#include <vcl/opengl/OpenGLContext.hxx> +#include <vcl/opengl/OpenGLHelper.hxx> +#include <opengl/zone.hxx> #include "osx/saldata.hxx" -#include "osx/salobj.h" #include "osx/salframe.h" +#include "osx/salinst.h" +#include "osx/salobj.h" + #include <AppKit/NSOpenGLView.h> AquaSalObject::AquaSalObject( AquaSalFrame* pFrame, SystemWindowData* pWindowData ) : @@ -226,4 +231,106 @@ const SystemEnvData* AquaSalObject::GetSystemData() const return &maSysData; } +class AquaOpenGLContext : public OpenGLContext +{ +public: + virtual bool initWindow() override; +private: + NSOpenGLView* getOpenGLView(); + virtual bool ImplInit() override; + virtual SystemWindowData generateWinData(vcl::Window* pParent, bool bRequestLegacyContext) override; + virtual void makeCurrent() override; + virtual void destroyCurrentContext() override; + virtual void resetCurrent() override; + virtual void swapBuffers() override; +}; + +void AquaOpenGLContext::resetCurrent() +{ + clearCurrent(); + + OpenGLZone aZone; + + (void) this; // loplugin:staticmethods + [NSOpenGLContext clearCurrentContext]; +} + +void AquaOpenGLContext::makeCurrent() +{ + if (isCurrent()) + return; + + OpenGLZone aZone; + + clearCurrent(); + + NSOpenGLView* pView = getOpenGLView(); + [[pView openGLContext] makeCurrentContext]; + + registerAsCurrent(); +} + +void AquaOpenGLContext::swapBuffers() +{ + OpenGLZone aZone; + + NSOpenGLView* pView = getOpenGLView(); + [[pView openGLContext] flushBuffer]; + + BuffersSwapped(); +} + +SystemWindowData AquaOpenGLContext::generateWinData(vcl::Window* /*pParent*/, bool bRequestLegacyContext) +{ + SystemWindowData aWinData; + aWinData.bOpenGL = true; + aWinData.bLegacy = bRequestLegacyContext; + aWinData.nSize = sizeof(aWinData); + return aWinData; +} + +void AquaOpenGLContext::destroyCurrentContext() +{ + [NSOpenGLContext clearCurrentContext]; +} + +bool AquaOpenGLContext::initWindow() +{ + if( !m_pChildWindow ) + { + SystemWindowData winData = generateWinData(mpWindow, mbRequestLegacyContext); + m_pChildWindow = VclPtr<SystemChildWindow>::Create(mpWindow, 0, &winData, false); + } + + if (m_pChildWindow) + { + InitChildWindow(m_pChildWindow.get()); + } + + return true; +} + +bool AquaOpenGLContext::ImplInit() +{ + OpenGLZone aZone; + + VCL_GL_INFO("OpenGLContext::ImplInit----start"); + NSOpenGLView* pView = getOpenGLView(); + [[pView openGLContext] makeCurrentContext]; + + bool bRet = InitGLEW(); + InitGLEWDebugging(); + return bRet; +} + +NSOpenGLView* AquaOpenGLContext::getOpenGLView() +{ + return reinterpret_cast<NSOpenGLView*>(m_pChildWindow->GetSystemData()->mpNSView); +} + +OpenGLContext* AquaSalInstance::CreateOpenGLContext() +{ + return new AquaOpenGLContext; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |