Line data Source code
1 :
2 : /* Copyright (c) 2014-2015, Daniel Nachbaur <danielnachbaur@gmail.com>
3 : * Juan Hernando <jhernando@fi.upm.es>
4 : * Stefan.Eilemann@epfl.ch
5 : *
6 : * This library is free software; you can redistribute it and/or modify it under
7 : * the terms of the GNU Lesser General Public License version 2.1 as published
8 : * by the Free Software Foundation.
9 : *
10 : * This library is distributed in the hope that it will be useful, but WITHOUT
11 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 : * details.
14 : *
15 : * You should have received a copy of the GNU Lesser General Public License
16 : * along with this library; if not, write to the Free Software Foundation, Inc.,
17 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 : */
19 :
20 : #include "window.h"
21 : #include "windowImpl.h"
22 : #include "windowEvent.h"
23 :
24 : #include "shareContextWindow.h"
25 :
26 : namespace eq
27 : {
28 : namespace qt
29 : {
30 : namespace
31 : {
32 0 : QOpenGLContext* _getShareContext( const WindowSettings& settings )
33 : {
34 0 : const SystemWindow* shareWindow = settings.getSharedContextWindow();
35 0 : const Window* window = dynamic_cast< const Window* >( shareWindow );
36 0 : if( window )
37 : // This only works if configInit has already been called in the window
38 0 : return window->getContext();
39 :
40 : const ShareContextWindow* dummyWindow =
41 0 : dynamic_cast< const ShareContextWindow* >( shareWindow );
42 0 : return dummyWindow ? dummyWindow->getContext() : 0;
43 : }
44 : }
45 :
46 0 : detail::Window* Window::createImpl( const WindowSettings& settings,
47 : QScreen* screen, QThread* thread )
48 : {
49 0 : QOpenGLContext* shareContext = _getShareContext( settings );
50 :
51 0 : const int32_t drawable = getAttribute( IATTR_HINT_DRAWABLE );
52 0 : detail::Window* window = 0;
53 0 : if( drawable == eq::WINDOW )
54 0 : window = new detail::QWindowWrapper( settings, screen, shareContext );
55 : else
56 : window = new detail::QOffscreenSurfaceWrapper( settings, screen,
57 0 : shareContext );
58 :
59 0 : if( thread )
60 0 : window->getContext()->moveToThread( thread );
61 0 : return window;
62 : }
63 :
64 0 : Window::Window( NotifierInterface& parent_, const WindowSettings& settings,
65 : detail::Window* impl )
66 : : WindowIF( parent_, settings )
67 0 : , _impl( impl )
68 : {
69 0 : }
70 :
71 0 : Window::~Window()
72 : {
73 0 : destroyImpl( _impl );
74 0 : }
75 :
76 0 : bool Window::configInit()
77 : {
78 0 : if( !_impl->configInit( *this ))
79 0 : return false;
80 :
81 0 : makeCurrent();
82 0 : initGLEW();
83 :
84 : const int32_t drawable =
85 0 : getIAttribute( WindowSettings::IATTR_HINT_DRAWABLE );
86 : // pbuffer is deprecated in Qt, use FBO instead
87 0 : if( drawable == FBO || drawable == PBUFFER )
88 0 : return configInitFBO();
89 0 : return true;
90 : }
91 :
92 0 : void Window::configExit()
93 : {
94 0 : configExitFBO();
95 0 : makeCurrent();
96 0 : exitGLEW();
97 0 : _impl->doneCurrent();
98 0 : _impl->configExit();
99 0 : }
100 :
101 0 : QOpenGLContext* Window::getContext() const
102 : {
103 0 : return _impl->getContext();
104 : }
105 :
106 0 : void Window::makeCurrent( const bool cache LB_UNUSED ) const
107 : {
108 : // Qt (at least on Windows) complains about call to non-current context
109 : // while swapBuffers()
110 : #ifndef _MSC_VER
111 0 : if( cache && isCurrent( ))
112 0 : return;
113 : #endif
114 :
115 0 : _impl->makeCurrent(); // Make real GL context current first
116 0 : WindowIF::makeCurrent(); // Validate FBO binding and caching state
117 : }
118 :
119 0 : void Window::doneCurrent() const
120 : {
121 0 : if( !isCurrent( ))
122 0 : return;
123 :
124 0 : _impl->doneCurrent();
125 0 : WindowIF::doneCurrent();
126 : }
127 :
128 0 : void Window::swapBuffers()
129 : {
130 0 : _impl->swapBuffers();
131 0 : }
132 :
133 0 : void Window::joinNVSwapBarrier( const uint32_t /*group*/,
134 : const uint32_t /*barrier*/ )
135 : {
136 0 : }
137 :
138 0 : void Window::leaveNVSwapBarrier()
139 : {
140 0 : }
141 :
142 0 : bool Window::processEvent( const WindowEvent& event_ )
143 : {
144 : // Resizing the FBO if needed
145 0 : if( getFrameBufferObject() &&
146 0 : event_.eq::Event::type == eq::Event::WINDOW_RESIZE )
147 : {
148 0 : getFrameBufferObject()->resize( event_.resize.w, event_.resize.h );
149 : }
150 0 : return SystemWindow::processEvent( event_ );
151 : }
152 :
153 0 : QObject* Window::getEventProcessor()
154 : {
155 0 : return _impl->getEventProcessor();
156 : }
157 :
158 0 : void Window::moveContextToThread( QThread* thread_ )
159 : {
160 0 : _impl->getContext()->moveToThread( thread_ );
161 0 : }
162 :
163 : }
164 42 : }
|