avmedia/source/framework/modeltools.cxx | 12 ++-- avmedia/source/opengl/oglmanager.cxx | 1 avmedia/source/opengl/oglplayer.cxx | 46 +++++++++++---- avmedia/source/opengl/oglwindow.cxx | 87 ++++++++++++++++++++++++++++- avmedia/source/opengl/oglwindow.hxx | 7 ++ avmedia/source/viewer/mediawindow_impl.cxx | 20 +++--- avmedia/source/viewer/mediawindow_impl.hxx | 1 include/sal/log-areas.dox | 2 8 files changed, 145 insertions(+), 31 deletions(-)
New commits: commit bf703a7ef97008a19b7cd725acd98e3b86889283 Author: Zolnai Tamás <tamas.zol...@collabora.com> Date: Tue May 13 00:07:48 2014 +0200 glTF rendering: first try to move camera position SystemChildWindow can't handle events by its own that's why it's parent is used as an event handler. Mouse pointer specify the active model. This patch made for editing, in case of slideshow we have one less window. Change-Id: If8ac57176b9a0abab518f8d8a06a2a41177a4881 diff --git a/avmedia/source/opengl/oglplayer.cxx b/avmedia/source/opengl/oglplayer.cxx index f74162b..43b8a71 100644 --- a/avmedia/source/opengl/oglplayer.cxx +++ b/avmedia/source/opengl/oglplayer.cxx @@ -211,7 +211,7 @@ uno::Reference< media::XPlayerWindow > SAL_CALL OGLPlayer::createPlayerWindow( c m_pHandle->viewport.y = 0; m_pHandle->viewport.width = aSize.Width(); m_pHandle->viewport.height = aSize.Height(); - OGLWindow* pWindow = new OGLWindow(m_pHandle, &m_aContext); + OGLWindow* pWindow = new OGLWindow(m_pHandle, &m_aContext, pChildWindow); return uno::Reference< media::XPlayerWindow >( pWindow ); } diff --git a/avmedia/source/opengl/oglwindow.cxx b/avmedia/source/opengl/oglwindow.cxx index 3168874..35b1ab4 100644 --- a/avmedia/source/opengl/oglwindow.cxx +++ b/avmedia/source/opengl/oglwindow.cxx @@ -14,9 +14,10 @@ using namespace com::sun::star; namespace avmedia { namespace ogl { -OGLWindow::OGLWindow( glTFHandle* pHandle, OpenGLContext* pContext ) +OGLWindow::OGLWindow( glTFHandle* pHandle, OpenGLContext* pContext, SystemChildWindow* pChildWindow ) : m_pHandle( pHandle ) , m_pContext( pContext ) + , m_pEventHandler( pChildWindow->GetParent() ) , m_bVisible ( false ) , meZoomLevel( media::ZoomLevel_ORIGINAL ) { @@ -122,7 +123,17 @@ void SAL_CALL OGLWindow::setVisible( sal_Bool bSet ) throw (uno::RuntimeException, std::exception) { if( bSet && !m_bVisible ) + { update(); + m_pEventHandler->GetParent()->AddEventListener( LINK(this, OGLWindow, FocusGrabber)); + m_pEventHandler->AddEventListener( LINK(this, OGLWindow, CameraHandler)); + m_pEventHandler->GrabFocus(); + } + else if( !bSet ) + { + m_pEventHandler->GetParent()->RemoveEventListener( LINK(this, OGLWindow, FocusGrabber)); + m_pEventHandler->RemoveEventListener( LINK(this, OGLWindow, CameraHandler)); + } m_bVisible = bSet; } @@ -196,6 +207,80 @@ void SAL_CALL OGLWindow::removePaintListener( const uno::Reference< awt::XPaintL { } +IMPL_LINK(OGLWindow, FocusGrabber, VclWindowEvent*, pEvent) +{ + assert(m_pEventHandler); + if( pEvent->GetId() == VCLEVENT_WINDOW_MOUSEMOVE ) + { + MouseEvent* pMouseEvt = (MouseEvent*)pEvent->GetData(); + if(pMouseEvt) + { + const Point& rMousePos = pMouseEvt->GetPosPixel(); + const Rectangle aWinRect(m_pEventHandler->GetPosPixel(),m_pEventHandler->GetSizePixel()); + if( aWinRect.IsInside(rMousePos) ) + { + if ( !m_pEventHandler->HasFocus() ) + { + m_pEventHandler->GrabFocus(); + } + } + else if ( m_pEventHandler->HasFocus() ) + { + m_pEventHandler->GrabFocusToDocument(); + } + } + } + + return 0; +} + +IMPL_LINK(OGLWindow, CameraHandler, VclWindowEvent*, pEvent) +{ + if( pEvent->GetId() == VCLEVENT_WINDOW_KEYINPUT ) + { + KeyEvent* pKeyEvt = (KeyEvent*)pEvent->GetData(); + if(pKeyEvt) + { + sal_uInt16 nCode = pKeyEvt->GetKeyCode().GetCode(); + m_pContext->makeCurrent(); + + // Calculate movement + glm::vec3 vMoveBy; + { + glm::vec3 vEye; + glm::vec3 vView; + glm::vec3 vUp; + gltf_get_camera_pos(&vEye,&vView,&vUp); + float fModelSize =(float)gltf_get_model_size(); + + glm::vec3 vMove = vView-vEye; + vMove = glm::normalize(vMove); + vMove *= 25.0f; + glm::vec3 vStrafe = glm::cross(vView-vEye, vUp); + vStrafe = glm::normalize(vStrafe); + vStrafe *= 25.0f; + glm::vec3 vMup = glm::cross(vView-vEye,glm::vec3(1.f,0.f,0.f) ); + vMup = glm::normalize(vMup); + vMup *= 25.0f; + + if(nCode == KEY_Q)vMoveBy += vMove*(0.1f*fModelSize); + if(nCode == KEY_E)vMoveBy -= vMove*(0.1f*fModelSize); + if(nCode == KEY_A)vMoveBy -= vStrafe*(0.1f*fModelSize); + if(nCode == KEY_D)vMoveBy += vStrafe*(0.1f*fModelSize); + if(nCode == KEY_W)vMoveBy -= vMup*(0.1f*fModelSize); + if(nCode == KEY_S)vMoveBy += vMup*(0.1f*fModelSize); + } + + gltf_renderer_move_camera(vMoveBy.x,vMoveBy.y,vMoveBy.z,10.0); + gltf_prepare_renderer(m_pHandle); + gltf_renderer(m_pHandle); + gltf_complete_renderer(); + m_pContext->swapBuffers(); + } + } + return 0; +} + } // namespace ogl } // namespace avmedia diff --git a/avmedia/source/opengl/oglwindow.hxx b/avmedia/source/opengl/oglwindow.hxx index 95767c0..e7b0d3a 100644 --- a/avmedia/source/opengl/oglwindow.hxx +++ b/avmedia/source/opengl/oglwindow.hxx @@ -19,6 +19,7 @@ #include <libgltf.h> #include <vcl/opengl/OpenGLContext.hxx> +#include <vcl/syschild.hxx> namespace avmedia { namespace ogl { @@ -26,7 +27,7 @@ class OGLWindow : public ::cppu::WeakImplHelper2 < com::sun::star::media::XPlaye com::sun::star::lang::XServiceInfo > { public: - OGLWindow( glTFHandle* pHandle, OpenGLContext* pContext ); + OGLWindow( glTFHandle* pHandle, OpenGLContext* pContext, SystemChildWindow* pChildWindow ); virtual ~OGLWindow(); virtual void SAL_CALL update() throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; @@ -61,8 +62,12 @@ public: virtual void SAL_CALL removePaintListener( const com::sun::star::uno::Reference< com::sun::star::awt::XPaintListener >& xListener ) throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; private: + DECL_LINK( FocusGrabber, VclWindowEvent* ); + DECL_LINK( CameraHandler, VclWindowEvent* ); + glTFHandle* m_pHandle; OpenGLContext* m_pContext; + Window* m_pEventHandler; bool m_bVisible; com::sun::star::media::ZoomLevel meZoomLevel; }; diff --git a/avmedia/source/viewer/mediawindow_impl.cxx b/avmedia/source/viewer/mediawindow_impl.cxx index ab9d351..6ef8462 100644 --- a/avmedia/source/viewer/mediawindow_impl.cxx +++ b/avmedia/source/viewer/mediawindow_impl.cxx @@ -162,6 +162,7 @@ MediaWindowImpl::MediaWindowImpl( Window* pParent, MediaWindow* pMediaWindow, bo DragSourceHelper( this ), mpMediaWindow( pMediaWindow ), mpEvents( NULL ), + mbEventTransparent(true), mpMediaWindowControl( bInternalMediaControl ? new MediaWindowControl( this ) : NULL ), mpEmptyBmpEx( NULL ), mpAudioBmpEx( NULL ) @@ -505,6 +506,7 @@ void MediaWindowImpl::onURLChanged() { SystemWindowData aWinData = OpenGLContext::generateWinData(this); mpChildWindow.reset(new MediaChildWindow(this,&aWinData)); + mbEventTransparent = false; } if( !mpChildWindow ) return; @@ -715,7 +717,7 @@ void MediaWindowImpl::GetFocus() void MediaWindowImpl::MouseMove( const MouseEvent& rMEvt ) { - if( mpMediaWindow ) + if( mpMediaWindow && mbEventTransparent ) mpMediaWindow->MouseMove( rMEvt ); } @@ -723,7 +725,7 @@ void MediaWindowImpl::MouseMove( const MouseEvent& rMEvt ) void MediaWindowImpl::MouseButtonDown( const MouseEvent& rMEvt ) { - if( mpMediaWindow ) + if( mpMediaWindow && mbEventTransparent ) mpMediaWindow->MouseButtonDown( rMEvt ); } @@ -731,7 +733,7 @@ void MediaWindowImpl::MouseButtonDown( const MouseEvent& rMEvt ) void MediaWindowImpl::MouseButtonUp( const MouseEvent& rMEvt ) { - if( mpMediaWindow ) + if( mpMediaWindow && mbEventTransparent ) mpMediaWindow->MouseButtonUp( rMEvt ); } @@ -739,7 +741,7 @@ void MediaWindowImpl::MouseButtonUp( const MouseEvent& rMEvt ) void MediaWindowImpl::KeyInput( const KeyEvent& rKEvt ) { - if( mpMediaWindow ) + if( mpMediaWindow && mbEventTransparent ) mpMediaWindow->KeyInput( rKEvt ); } @@ -747,7 +749,7 @@ void MediaWindowImpl::KeyInput( const KeyEvent& rKEvt ) void MediaWindowImpl::KeyUp( const KeyEvent& rKEvt ) { - if( mpMediaWindow ) + if( mpMediaWindow && mbEventTransparent ) mpMediaWindow->KeyUp( rKEvt ); } @@ -755,7 +757,7 @@ void MediaWindowImpl::KeyUp( const KeyEvent& rKEvt ) void MediaWindowImpl::Command( const CommandEvent& rCEvt ) { - if( mpMediaWindow ) + if( mpMediaWindow && mbEventTransparent ) mpMediaWindow->Command( rCEvt ); } @@ -763,21 +765,21 @@ void MediaWindowImpl::Command( const CommandEvent& rCEvt ) sal_Int8 MediaWindowImpl::AcceptDrop( const AcceptDropEvent& rEvt ) { - return( mpMediaWindow ? mpMediaWindow->AcceptDrop( rEvt ) : 0 ); + return( mpMediaWindow && mbEventTransparent ? mpMediaWindow->AcceptDrop( rEvt ) : 0 ); } sal_Int8 MediaWindowImpl::ExecuteDrop( const ExecuteDropEvent& rEvt ) { - return( mpMediaWindow ? mpMediaWindow->ExecuteDrop( rEvt ) : 0 ); + return( mpMediaWindow && mbEventTransparent ? mpMediaWindow->ExecuteDrop( rEvt ) : 0 ); } void MediaWindowImpl::StartDrag( sal_Int8 nAction, const Point& rPosPixel ) { - if( mpMediaWindow ) + if( mpMediaWindow && mbEventTransparent ) mpMediaWindow->StartDrag( nAction, rPosPixel ); } diff --git a/avmedia/source/viewer/mediawindow_impl.hxx b/avmedia/source/viewer/mediawindow_impl.hxx index 906959d..a5e8215 100644 --- a/avmedia/source/viewer/mediawindow_impl.hxx +++ b/avmedia/source/viewer/mediawindow_impl.hxx @@ -174,6 +174,7 @@ namespace avmedia ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > mxEventsIf; MediaEventListenersImpl* mpEvents; + bool mbEventTransparent; boost::scoped_ptr<MediaChildWindow> mpChildWindow; MediaWindowControl* mpMediaWindowControl; BitmapEx* mpEmptyBmpEx; commit 01d3044d30283aec1b7a6908428691a6befe6783 Author: Zolnai Tamás <tamas.zol...@collabora.com> Date: Fri May 9 18:03:03 2014 +0200 More warnings related to glTF rendering Use avmedia.opengl to be more explicit. Change-Id: I07878c3648de2e4786bf8a5144ef0c1fbb5530f1 diff --git a/avmedia/source/framework/modeltools.cxx b/avmedia/source/framework/modeltools.cxx index c625fba..6dff44b 100644 --- a/avmedia/source/framework/modeltools.cxx +++ b/avmedia/source/framework/modeltools.cxx @@ -40,7 +40,7 @@ static void lcl_EmbedExternals(const OUString& rSourceURL, uno::Reference<embed: ::osl::FileBase::createTempFile(0, 0, &sTempFileURL); if (::osl::FileBase::E_None != aErr) { - SAL_WARN("avmedia.model", "cannot create temp file"); + SAL_WARN("avmedia.opengl", "Cannot create temp file"); return; } try @@ -53,7 +53,7 @@ static void lcl_EmbedExternals(const OUString& rSourceURL, uno::Reference<embed: } catch (uno::Exception const& e) { - SAL_WARN("avmedia.model", "exception: '" << e.Message << "'"); + SAL_WARN("avmedia.opengl", "Exception: '" << e.Message << "'"); return; } @@ -96,7 +96,7 @@ static void lcl_EmbedExternals(const OUString& rSourceURL, uno::Reference<embed: } catch ( boost::exception const& ) { - SAL_WARN("avmedia.model", "failed to parse json file"); + SAL_WARN("avmedia.opengl", "Exception while parsing *.json file"); return; } @@ -121,7 +121,7 @@ static void lcl_EmbedExternals(const OUString& rSourceURL, uno::Reference<embed: if (!aContent.openStream(xOutStream)) { - SAL_WARN("avmedia.model", "openStream to storage failed"); + SAL_WARN("avmedia.opengl", "openStream to storage failed"); return; } } @@ -164,7 +164,7 @@ bool Embed3DModel( const uno::Reference<frame::XModel>& xModel, if (!aSourceContent.openStream(xOutStream)) { - SAL_INFO("avmedia.model", "openStream to storage failed"); + SAL_WARN("avmedia.opengl", "openStream to storage failed"); return false; } @@ -189,7 +189,7 @@ bool Embed3DModel( const uno::Reference<frame::XModel>& xModel, } catch (uno::Exception const&) { - SAL_WARN("avmedia.model", "Exception while trying to embed model"); + SAL_WARN("avmedia.opengl", "Exception while trying to embed model"); } return false; } diff --git a/avmedia/source/opengl/oglmanager.cxx b/avmedia/source/opengl/oglmanager.cxx index f55553f..afd55ca 100644 --- a/avmedia/source/opengl/oglmanager.cxx +++ b/avmedia/source/opengl/oglmanager.cxx @@ -36,6 +36,7 @@ uno::Reference< media::XPlayer > SAL_CALL OGLManager::createPlayer( const OUStri else { delete pPlayer; + SAL_WARN("avmedia.opengl", "Can't creat player for OpenGL model: " + rURL); return uno::Reference< media::XPlayer >(); } } diff --git a/avmedia/source/opengl/oglplayer.cxx b/avmedia/source/opengl/oglplayer.cxx index 0bed52c..f74162b 100644 --- a/avmedia/source/opengl/oglplayer.cxx +++ b/avmedia/source/opengl/oglplayer.cxx @@ -61,12 +61,18 @@ bool OGLPlayer::create( const OUString& rURL ) OString sFileName = OUStringToOString(INetURLObject(m_sURL).GetLastName(),RTL_TEXTENCODING_UTF8); aJsonFile.filename = (char*)sFileName.getStr(); if( !lcl_LoadFile(&aJsonFile, m_sURL) ) + { + SAL_WARN("avmedia.opengl", "Can't load *.json file: " + sFileName); return false; + } m_pHandle = gltf_renderer_init(&aJsonFile); if( !m_pHandle || !m_pHandle->files ) + { + SAL_WARN("avmedia.opengl", "gltf_renderer_init returned an invalid glTFHandle"); return false; + } // Load external resources for( size_t i = 0; i < m_pHandle->size; ++i ) @@ -90,7 +96,10 @@ bool OGLPlayer::create( const OUString& rURL ) else if( pFile->type == GLTF_BINARY || pFile->type == GLTF_GLSL ) { if( !lcl_LoadFile(pFile, sFilesURL) ) + { + SAL_WARN("avmedia.opengl", "Can't load glTF file: " + sFilesURL); return false; + } } } } @@ -184,19 +193,24 @@ uno::Reference< media::XPlayerWindow > SAL_CALL OGLPlayer::createPlayerWindow( c { osl::MutexGuard aGuard( m_aMutex ); - if( rArguments.getLength() > 2 ) + assert( rArguments.getLength() >= 3 ); + + sal_IntPtr pIntPtr = 0; + rArguments[ 2 ] >>= pIntPtr; + SystemChildWindow *pChildWindow = reinterpret_cast< SystemChildWindow* >( pIntPtr ); + + if( !m_aContext.init(pChildWindow) ) { - sal_IntPtr pIntPtr = 0; - rArguments[ 2 ] >>= pIntPtr; - SystemChildWindow *pChildWindow = reinterpret_cast< SystemChildWindow* >( pIntPtr ); - m_aContext.init(pChildWindow); - Size aSize = pChildWindow->GetSizePixel(); - m_aContext.setWinSize(aSize); - m_pHandle->viewport.x = 0; - m_pHandle->viewport.y = 0; - m_pHandle->viewport.width = aSize.Width(); - m_pHandle->viewport.height = aSize.Height(); + SAL_WARN("avmedia.opengl", "Context initialization failed"); + return uno::Reference< media::XPlayerWindow >(); } + + Size aSize = pChildWindow->GetSizePixel(); + m_aContext.setWinSize(aSize); + m_pHandle->viewport.x = 0; + m_pHandle->viewport.y = 0; + m_pHandle->viewport.width = aSize.Width(); + m_pHandle->viewport.height = aSize.Height(); OGLWindow* pWindow = new OGLWindow(m_pHandle, &m_aContext); return uno::Reference< media::XPlayerWindow >( pWindow ); } @@ -205,7 +219,13 @@ uno::Reference< media::XFrameGrabber > SAL_CALL OGLPlayer::createFrameGrabber() throw ( uno::RuntimeException, std::exception ) { osl::MutexGuard aGuard(m_aMutex); - m_aContext.init(); + + if( !m_aContext.init() ) + { + SAL_WARN("avmedia.opengl", "Offscreen context initialization failed"); + return uno::Reference< media::XFrameGrabber >(); + } + m_pHandle->viewport.x = 0; m_pHandle->viewport.y = 0; m_pHandle->viewport.width = getPreferredPlayerWindowSize().Width; diff --git a/include/sal/log-areas.dox b/include/sal/log-areas.dox index 617cec8..6a28330 100644 --- a/include/sal/log-areas.dox +++ b/include/sal/log-areas.dox @@ -457,7 +457,7 @@ certain functionality. @section avmedia @li @c avmedia -@li @c avmedia.model - 3D models +@li @c avmedia.opengl - OpenGL models @section other
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits