summaryrefslogtreecommitdiff
path: root/avmedia
diff options
context:
space:
mode:
authorZolnai Tamás <tamas.zolnai@collabora.com>2014-06-25 15:19:41 +0200
committerZolnai Tamás <zolnaitamas2000@gmail.com>2014-06-25 13:22:29 +0000
commit6403f2b59b4c83e0899012e5ca0ddd705784350c (patch)
treeccc8080f9b4ba808f2fec310aedd15703c41170b /avmedia
parent076e4afc61b216e34959bd4e3701f1fa19972d5c (diff)
Update libgltf: new build system and various fixes
Building: - The new tarball has reasonable build system so build libgltf as external package instead of compiling source files directly. - Freetype dependancy is removed Improvements comes with the new libgltf - Can rotate the models too (orbit mode) - Two camera handling mode: walkthrough and orbit (press M to change). - gltf_animation_set_time() works - FPS can be displayed without freetype (press F) Additional notes: - There were some bugs/regressions which are fixed during the integration (see patches). - License files are uddated now. - libgltf building is enabled only on those platforms on which gltf support actually works (windows and linux) Change-Id: Ia6c9c4da53a9b4fedba0d73aa5791489f8ad424b Reviewed-on: https://gerrit.libreoffice.org/9895 Reviewed-by: Zolnai Tamás <zolnaitamas2000@gmail.com> Tested-by: Zolnai Tamás <zolnaitamas2000@gmail.com>
Diffstat (limited to 'avmedia')
-rw-r--r--avmedia/Library_avmedia.mk1
-rw-r--r--avmedia/Library_avmediaogl.mk9
-rw-r--r--avmedia/source/opengl/oglplayer.cxx25
-rw-r--r--avmedia/source/opengl/oglplayer.hxx1
-rw-r--r--avmedia/source/opengl/oglwindow.cxx70
-rw-r--r--avmedia/source/opengl/oglwindow.hxx1
6 files changed, 69 insertions, 38 deletions
diff --git a/avmedia/Library_avmedia.mk b/avmedia/Library_avmedia.mk
index 63e9067ec38c..184c66c7d201 100644
--- a/avmedia/Library_avmedia.mk
+++ b/avmedia/Library_avmedia.mk
@@ -27,7 +27,6 @@ $(eval $(call gb_Library_use_externals,avmedia,\
boost_headers \
glew \
mesa_headers \
- zlib \
))
$(eval $(call gb_Library_use_libraries,avmedia,\
diff --git a/avmedia/Library_avmediaogl.mk b/avmedia/Library_avmediaogl.mk
index afa52ca006d4..3bbebe885b97 100644
--- a/avmedia/Library_avmediaogl.mk
+++ b/avmedia/Library_avmediaogl.mk
@@ -16,11 +16,9 @@ $(eval $(call gb_Library_use_sdk_api,avmediaogl))
$(eval $(call gb_Library_use_externals,avmediaogl, \
boost_headers \
libgltf \
+ glew \
glm_headers \
mesa_headers \
- glew \
- zlib \
- freetype \
))
$(eval $(call gb_Library_use_libraries,avmediaogl,\
@@ -50,8 +48,6 @@ $(eval $(call gb_Library_add_exception_objects,avmediaogl,\
ifeq ($(strip $(OS)),WNT)
$(eval $(call gb_Library_use_system_win32_libs,avmediaogl,\
opengl32 \
- gdi32 \
- glu32 \
))
else ifeq ($(OS),MACOSX)
$(eval $(call gb_Library_use_system_darwin_frameworks,avmediaogl,\
@@ -59,10 +55,7 @@ $(eval $(call gb_Library_use_system_darwin_frameworks,avmediaogl,\
))
else ifeq ($(OS),LINUX)
$(eval $(call gb_Library_add_libs,avmediaogl,\
- -ldl \
-lGL \
- -lGLU \
- -lX11 \
))
endif
diff --git a/avmedia/source/opengl/oglplayer.cxx b/avmedia/source/opengl/oglplayer.cxx
index 35ae14008ab1..30c26419182f 100644
--- a/avmedia/source/opengl/oglplayer.cxx
+++ b/avmedia/source/opengl/oglplayer.cxx
@@ -28,6 +28,7 @@ OGLPlayer::OGLPlayer()
: Player_BASE(m_aMutex)
, m_pHandle(NULL)
, m_pOGLWindow(NULL)
+ , m_bIsRendering(false)
{
}
@@ -141,8 +142,14 @@ void SAL_CALL OGLPlayer::start() throw ( uno::RuntimeException, std::exception )
{
osl::MutexGuard aGuard(m_aMutex);
assert(m_pHandle);
+
+ // gltf_animation_start play animation from the time 0.0,
+ // but OGLPlayer::start used as play from that time where it was stopped before
+ double fTime = gltf_animation_get_time(m_pHandle);
gltf_animation_start(m_pHandle);
+ gltf_animation_set_time(m_pHandle, fTime);
m_aTimer.Start();
+ m_bIsRendering = true;
}
void SAL_CALL OGLPlayer::stop() throw ( uno::RuntimeException, std::exception )
@@ -151,13 +158,19 @@ void SAL_CALL OGLPlayer::stop() throw ( uno::RuntimeException, std::exception )
assert(m_pHandle);
m_aTimer.Stop();
gltf_animation_stop(m_pHandle);
+ m_bIsRendering = false;
}
sal_Bool SAL_CALL OGLPlayer::isPlaying() throw ( uno::RuntimeException, std::exception )
{
osl::MutexGuard aGuard(m_aMutex);
assert(m_pHandle);
- return (sal_Bool)gltf_animation_is_playing(m_pHandle);
+ // Here isPlaying means model is rendered in the window and
+ // able to interact with the user (e.g. moving camera)
+ if( getDuration() > 0.0 )
+ return gltf_animation_is_playing(m_pHandle);
+ else
+ return m_bIsRendering;
}
double SAL_CALL OGLPlayer::getDuration() throw ( uno::RuntimeException, std::exception )
@@ -169,18 +182,16 @@ double SAL_CALL OGLPlayer::getDuration() throw ( uno::RuntimeException, std::exc
void SAL_CALL OGLPlayer::setMediaTime( double fTime ) throw ( uno::RuntimeException, std::exception )
{
- // TODO: doesn't work, but cause problem in playing
osl::MutexGuard aGuard(m_aMutex);
assert(m_pHandle);
- (void) fTime;
- //gltf_animation_set_time(m_pHandle, fTime);
+ gltf_animation_set_time(m_pHandle, fTime);
}
double SAL_CALL OGLPlayer::getMediaTime() throw ( ::com::sun::star::uno::RuntimeException, std::exception )
{
osl::MutexGuard aGuard(m_aMutex);
assert(m_pHandle);
- return 0.0; //gltf_animation_get_time(m_pHandle);
+ return gltf_animation_get_time(m_pHandle);
}
void SAL_CALL OGLPlayer::setPlaybackLoop( sal_Bool bSet ) throw ( uno::RuntimeException, std::exception )
@@ -264,6 +275,9 @@ uno::Reference< media::XPlayerWindow > SAL_CALL OGLPlayer::createPlayerWindow( c
SAL_WARN("avmedia.opengl", "Error occured while parsing *.json file! Error code: " << nRet);
return uno::Reference< media::XPlayerWindow >();
}
+ // The background color is white by default, but we need to separate the
+ // OpenGL window from the main window so set background color to grey
+ glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
m_pOGLWindow = new OGLWindow(*m_pHandle, m_aContext, *pChildWindow->GetParent());
return uno::Reference< media::XPlayerWindow >( m_pOGLWindow );
}
@@ -291,6 +305,7 @@ uno::Reference< media::XFrameGrabber > SAL_CALL OGLPlayer::createFrameGrabber()
SAL_WARN("avmedia.opengl", "Error occured while parsing *.json file! Error code: " << nRet);
return uno::Reference< media::XFrameGrabber >();
}
+ glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
OGLFrameGrabber *pFrameGrabber = new OGLFrameGrabber( *m_pHandle );
return uno::Reference< media::XFrameGrabber >( pFrameGrabber );
}
diff --git a/avmedia/source/opengl/oglplayer.hxx b/avmedia/source/opengl/oglplayer.hxx
index 42476fc916a4..e25dfd321285 100644
--- a/avmedia/source/opengl/oglplayer.hxx
+++ b/avmedia/source/opengl/oglplayer.hxx
@@ -64,6 +64,7 @@ private:
OpenGLContext m_aContext;
AutoTimer m_aTimer;
OGLWindow* m_pOGLWindow;
+ bool m_bIsRendering;
};
} // namespace ogl
diff --git a/avmedia/source/opengl/oglwindow.cxx b/avmedia/source/opengl/oglwindow.cxx
index aa29f4b8ea0b..5d85d6286444 100644
--- a/avmedia/source/opengl/oglwindow.cxx
+++ b/avmedia/source/opengl/oglwindow.cxx
@@ -20,6 +20,7 @@ OGLWindow::OGLWindow( glTFHandle& rHandle, OpenGLContext& rContext, Window& rEve
, m_rEventHandler( rEventHandlerParent )
, m_bVisible ( false )
, m_aLastMousePos(Point())
+ , m_bIsOrbitMode( false )
{
}
@@ -249,33 +250,36 @@ IMPL_LINK(OGLWindow, CameraHandler, VclWindowEvent*, pEvent)
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) );
+ glm::vec3 vMup = glm::cross(vView-vEye,glm::vec3(1.0f,0.0f,0.0f) );
vMup = glm::normalize(vMup);
vMup *= 25.0f;
- if(nCode == KEY_Q)vMoveBy += vMove*(0.0005f*fModelSize);
- if(nCode == KEY_E)vMoveBy -= vMove*(0.0005f*fModelSize);
- if(nCode == KEY_A)vMoveBy -= vStrafe*(0.0005f*fModelSize);
- if(nCode == KEY_D)vMoveBy += vStrafe*(0.0005f*fModelSize);
- if(nCode == KEY_W)vMoveBy -= vMup*(0.0005f*fModelSize);
- if(nCode == KEY_S)vMoveBy += vMup*(0.0005f*fModelSize);
+ if(nCode == KEY_W)vMoveBy += vMove*(0.005f*fModelSize);
+ if(nCode == KEY_S)vMoveBy -= vMove*(0.005f*fModelSize);
+ if( !m_bIsOrbitMode )
+ {
+ if(nCode == KEY_A)vMoveBy -= vStrafe*(0.005f*fModelSize);
+ if(nCode == KEY_D)vMoveBy += vStrafe*(0.005f*fModelSize);
+ }
}
gltf_renderer_move_camera(&m_rHandle, vMoveBy.x, vMoveBy.y, vMoveBy.z, 0.0);
}
- }
- }
- // TODO: Clean this mess up after libgltf gets a working camera handling
- else if( pEvent->GetId() == VCLEVENT_WINDOW_KEYUP )
- {
- KeyEvent* pKeyEvt = (KeyEvent*)pEvent->GetData();
- if(pKeyEvt)
- {
- const sal_uInt16 nCode = pKeyEvt->GetKeyCode().GetCode();
- if (nCode == KEY_Q || nCode == KEY_E ||
- nCode == KEY_A || nCode == KEY_D ||
- nCode == KEY_W || nCode == KEY_S )
+ else if(nCode == KEY_M)
{
- gltf_renderer_move_camera(&m_rHandle, 0.0, 0.0, 0.0, 0.0);
+ if(m_bIsOrbitMode)
+ {
+ gltf_orbit_view_stop(&m_rHandle);
+ m_bIsOrbitMode = false;
+ }
+ else
+ {
+ gltf_orbit_mode_start(&m_rHandle);
+ m_bIsOrbitMode = true;
+ }
+ }
+ else if(nCode == KEY_F)
+ {
+ gltf_render_FPS_enable(&m_rHandle);
}
}
}
@@ -303,14 +307,32 @@ IMPL_LINK(OGLWindow, CameraHandler, VclWindowEvent*, pEvent)
else
fSensitivity = 540.0 / fSensitivity;
- long nDeltaX = m_aLastMousePos.X()-aCurPos.X();
- long nDeltaY = aCurPos.Y()-m_aLastMousePos.Y();
- // TODO: It seems this method just moves the camera but not rotate it.
- gltf_renderer_rotate_camera(&m_rHandle, (float)nDeltaX*fSensitivity, (float)nDeltaY*fSensitivity, 0.0, 0.0);
+ long nDeltaX = m_aLastMousePos.X()-aCurPos.X();
+ long nDeltaY = m_aLastMousePos.Y()-aCurPos.Y();
+ if( m_bIsOrbitMode )
+ {
+ fSensitivity *= 5;
+ gltf_renderer_rotate_model(&m_rHandle, (float)nDeltaX*fSensitivity, (float)nDeltaY*fSensitivity, 0.0);
+ }
+ else
+ {
+ // Filter out too small deltas to avoid rewrite rotation parameter with 0
+ // before rotation is done
+ if( nDeltaX != 0 || nDeltaY != 0 )
+ gltf_renderer_rotate_camera(&m_rHandle, (float)nDeltaX*fSensitivity, (float)nDeltaY*fSensitivity, 0.0);
+ }
m_aLastMousePos = aCurPos;
}
}
+ else if( pEvent->GetId() == VCLEVENT_WINDOW_MOUSEBUTTONUP )
+ {
+ MouseEvent* pMouseEvt = (MouseEvent*)pEvent->GetData();
+ if(pMouseEvt && pMouseEvt->IsLeft() && pMouseEvt->GetClicks() == 1)
+ {
+ gltf_renderer_stop_rotate_model(&m_rHandle);
+ }
+ }
return 0;
}
diff --git a/avmedia/source/opengl/oglwindow.hxx b/avmedia/source/opengl/oglwindow.hxx
index 9ea073745990..b4b1390b67ae 100644
--- a/avmedia/source/opengl/oglwindow.hxx
+++ b/avmedia/source/opengl/oglwindow.hxx
@@ -70,6 +70,7 @@ private:
Window& m_rEventHandler;
bool m_bVisible;
Point m_aLastMousePos;
+ bool m_bIsOrbitMode;
};
} // namespace ogl