avmedia/source/opengl/oglframegrabber.cxx | 27 +---- avmedia/source/opengl/oglplayer.cxx | 41 +++---- avmedia/source/opengl/oglplayer.hxx | 1 chart2/source/view/main/OpenGLRender.cxx | 27 ----- external/libgltf/UnpackedTarball_libgltf.mk | 1 external/libgltf/patches/format_parameter_for_bitmap.patch | 68 +++++++++++++ include/vcl/opengl/OpenGLHelper.hxx | 1 vcl/source/opengl/OpenGLContext.cxx | 28 ----- vcl/source/opengl/OpenGLHelper.cxx | 29 +++++ 9 files changed, 125 insertions(+), 98 deletions(-)
New commits: commit 52b06dab6e53b7a25fd4d1dcebc3051afce4c5b4 Author: Zolnai Tamás <tamas.zol...@collabora.com> Date: Sun Apr 27 16:30:46 2014 +0200 OGLPlayer: use libgltf methods for playing 3D animation By now this methods are unimplemented inside libgltf. Change-Id: Ib7dfb1a053d11fc43fec26ec4f9195e7f64a8a74 diff --git a/avmedia/source/opengl/oglplayer.cxx b/avmedia/source/opengl/oglplayer.cxx index f6f8ab8..3200f16 100644 --- a/avmedia/source/opengl/oglplayer.cxx +++ b/avmedia/source/opengl/oglplayer.cxx @@ -24,12 +24,13 @@ namespace avmedia { namespace ogl { OGLPlayer::OGLPlayer() : Player_BASE(m_aMutex) - , m_bIsPlaying(false) { } OGLPlayer::~OGLPlayer() { + // Comment out while it causes segmentation fault + // gltf_renderer_release(m_pHandle); } static bool lcl_LoadFile( glTFFile* io_pFile, const OUString& rURL) @@ -98,42 +99,37 @@ bool OGLPlayer::create( const OUString& rURL ) void SAL_CALL OGLPlayer::start() throw ( uno::RuntimeException, std::exception ) { osl::MutexGuard aGuard(m_aMutex); - // TODO: Start playing of gltf model (see com::sun::star::media::XPlayer) - m_bIsPlaying = true; + gltf_animation_start(m_pHandle); } void SAL_CALL OGLPlayer::stop() throw ( uno::RuntimeException, std::exception ) { osl::MutexGuard aGuard(m_aMutex); - // TODO: Stop playing of gltf model (see com::sun::star::media::XPlayer) - m_bIsPlaying = false; + gltf_animation_stop(m_pHandle); } sal_Bool SAL_CALL OGLPlayer::isPlaying() throw ( uno::RuntimeException, std::exception ) { osl::MutexGuard aGuard(m_aMutex); - // TODO: Check whether gltf model is played by now (see com::sun::star::media::XPlayer) - return m_bIsPlaying; + return (sal_Bool)gltf_animation_is_playing(m_pHandle); } double SAL_CALL OGLPlayer::getDuration() throw ( uno::RuntimeException, std::exception ) { osl::MutexGuard aGuard(m_aMutex); - // TODO: Get gltf's duration (see com::sun::star::media::XPlayer) - return 0.0; + return gltf_animation_get_duration(m_pHandle); } -void SAL_CALL OGLPlayer::setMediaTime( double /*fTime*/ ) throw ( uno::RuntimeException, std::exception ) +void SAL_CALL OGLPlayer::setMediaTime( double fTime ) throw ( uno::RuntimeException, std::exception ) { osl::MutexGuard aGuard(m_aMutex); - // TODO: Set player to the specified point (see com::sun::star::media::XPlayer) + 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); - // TODO: Get player current time position (see com::sun::star::media::XPlayer) - return 0.0; + return gltf_animation_get_time(m_pHandle); } double SAL_CALL OGLPlayer::getRate() throw ( uno::RuntimeException, std::exception ) @@ -143,17 +139,16 @@ double SAL_CALL OGLPlayer::getRate() throw ( uno::RuntimeException, std::excepti return 1.0; } -void SAL_CALL OGLPlayer::setPlaybackLoop( sal_Bool /*bSet*/ ) throw ( uno::RuntimeException, std::exception ) +void SAL_CALL OGLPlayer::setPlaybackLoop( sal_Bool bSet ) throw ( uno::RuntimeException, std::exception ) { osl::MutexGuard aGuard(m_aMutex); - // TODO: Set the playes replay itself when it ends (see com::sun::star::media::XPlayer) + gltf_animation_set_looping(m_pHandle, (int)bSet); } sal_Bool SAL_CALL OGLPlayer::isPlaybackLoop() throw ( uno::RuntimeException, std::exception ) { osl::MutexGuard aGuard(m_aMutex); - // TODO: Check whether playing will restart after it ends (see com::sun::star::media::XPlayer) - return false; + return (sal_Bool)gltf_animation_get_looping(m_pHandle); } void SAL_CALL OGLPlayer::setVolumeDB( sal_Int16 /*nVolumDB*/ ) throw ( uno::RuntimeException, std::exception ) diff --git a/avmedia/source/opengl/oglplayer.hxx b/avmedia/source/opengl/oglplayer.hxx index a40b43d..1f1efce 100644 --- a/avmedia/source/opengl/oglplayer.hxx +++ b/avmedia/source/opengl/oglplayer.hxx @@ -58,7 +58,6 @@ private: OUString m_sURL; glTFHandle* m_pHandle; OpenGLContext m_aContext; - bool m_bIsPlaying; }; } // namespace ogl commit 79d75557100b696a02c3341f2e5277900cb3c4df Author: Zolnai Tamás <tamas.zol...@collabora.com> Date: Sun Apr 27 14:41:12 2014 +0200 OGLPlayer: no sound of OpenGL models Change-Id: I50277f315689006e6a824e61a6ba6929077b20a8 diff --git a/avmedia/source/opengl/oglplayer.cxx b/avmedia/source/opengl/oglplayer.cxx index 9d5f730..f6f8ab8 100644 --- a/avmedia/source/opengl/oglplayer.cxx +++ b/avmedia/source/opengl/oglplayer.cxx @@ -158,27 +158,23 @@ sal_Bool SAL_CALL OGLPlayer::isPlaybackLoop() throw ( uno::RuntimeException, std void SAL_CALL OGLPlayer::setVolumeDB( sal_Int16 /*nVolumDB*/ ) throw ( uno::RuntimeException, std::exception ) { - osl::MutexGuard aGuard(m_aMutex); - // TODO: Set audio volume (see com::sun::star::media::XPlayer) + // OpenGL models have no sound. } sal_Int16 SAL_CALL OGLPlayer::getVolumeDB() throw ( uno::RuntimeException, std::exception ) { - osl::MutexGuard aGuard(m_aMutex); - // TODO: Get audio volume (see com::sun::star::media::XPlayer) + // OpenGL models have no sound. return 0; } void SAL_CALL OGLPlayer::setMute( sal_Bool /*bSet*/ ) throw ( uno::RuntimeException, std::exception ) { - osl::MutexGuard aGuard(m_aMutex); - // TODO: Set volume to 0 (see com::sun::star::media::XPlayer) + // OpenGL models have no sound. } sal_Bool SAL_CALL OGLPlayer::isMute() throw ( uno::RuntimeException, std::exception ) { - osl::MutexGuard aGuard(m_aMutex); - // TODO: Get whether volume is set to 0 by setMute (see com::sun::star::media::XPlayer) + // OpenGL models have no sound. return false; } commit f0bd1c6980e52f212ed95820420acfd0bcdf3cca Author: Zolnai Tamás <tamas.zol...@collabora.com> Date: Sun Apr 27 14:17:05 2014 +0200 OGFrameGrabber: use a BGRA buffer Change-Id: Ie827ba98a6ff65d63eb61df1d90e18919de86395 diff --git a/avmedia/source/opengl/oglframegrabber.cxx b/avmedia/source/opengl/oglframegrabber.cxx index b2dcdc8..8b061e7 100644 --- a/avmedia/source/opengl/oglframegrabber.cxx +++ b/avmedia/source/opengl/oglframegrabber.cxx @@ -15,6 +15,10 @@ #include <vcl/salbtype.hxx> #include <vcl/bmpacc.hxx> +#include <vcl/opengl/OpenGLHelper.hxx> + +#include <boost/scoped_array.hpp> + using namespace com::sun::star; namespace avmedia { namespace ogl { @@ -32,26 +36,9 @@ OGLFrameGrabber::~OGLFrameGrabber() uno::Reference< css::graphic::XGraphic > SAL_CALL OGLFrameGrabber::grabFrame( double fMediaTime ) throw ( uno::RuntimeException, std::exception ) { - // TODO: libgltf should provide an RGBA buffer, not just an RGB one. See: OpenGLRender::GetAsBitmap(). - char* pBuffer = new char[m_pHandle->viewport.width * m_pHandle->viewport.height * 3]; - gltf_renderer_get_bitmap(m_pHandle, fMediaTime, pBuffer, m_pHandle->viewport.width, m_pHandle->viewport.height); - Bitmap aBitmap( Size(m_pHandle->viewport.width, m_pHandle->viewport.height), 24 ); - { - Bitmap::ScopedWriteAccess pWriteAccess( aBitmap ); - size_t nCurPos = 0; - for( int y = 0; y < m_pHandle->viewport.height; ++y) - { - Scanline pScan = pWriteAccess->GetScanline(y); - for( int x = 0; x < m_pHandle->viewport.width; ++x ) - { - *pScan++ = pBuffer[nCurPos]; - *pScan++ = pBuffer[nCurPos+1]; - *pScan++ = pBuffer[nCurPos+2]; - nCurPos += 3; - } - } - } - delete [] pBuffer; + boost::scoped_array<sal_uInt8> pBuffer(new sal_uInt8[m_pHandle->viewport.width * m_pHandle->viewport.height * 4]); + gltf_renderer_get_bitmap(m_pHandle, fMediaTime, (char*)pBuffer.get(), m_pHandle->viewport.width, m_pHandle->viewport.height, GL_BGRA); + BitmapEx aBitmap = OpenGLHelper::ConvertBGRABufferToBitmapEx(pBuffer.get(), m_pHandle->viewport.width, m_pHandle->viewport.height); return Graphic( aBitmap ).GetXGraphic(); } diff --git a/external/libgltf/UnpackedTarball_libgltf.mk b/external/libgltf/UnpackedTarball_libgltf.mk index dd28b67..6e6157d 100644 --- a/external/libgltf/UnpackedTarball_libgltf.mk +++ b/external/libgltf/UnpackedTarball_libgltf.mk @@ -26,6 +26,7 @@ $(eval $(call gb_UnpackedTarball_add_patches,libgltf,\ external/libgltf/patches/avoid_c++11.patch \ external/libgltf/patches/json_charbuffer_used_as_cstring.patch \ external/libgltf/patches/shader_charbuffer_used_as_cstring.patch \ + external/libgltf/patches/format_parameter_for_bitmap.patch \ )) # vim: set noet sw=4 ts=4: diff --git a/external/libgltf/patches/format_parameter_for_bitmap.patch b/external/libgltf/patches/format_parameter_for_bitmap.patch new file mode 100644 index 0000000..526e958 --- /dev/null +++ b/external/libgltf/patches/format_parameter_for_bitmap.patch @@ -0,0 +1,68 @@ +diff -ur libgltf.org/inc/libgltf.h libgltf/inc/libgltf.h +--- libgltf.org/inc/libgltf.h 2014-04-27 14:10:06.191988313 +0200 ++++ libgltf/inc/libgltf.h 2014-04-27 14:12:03.171983919 +0200 +@@ -47,7 +47,7 @@ + /** Get a bitmap of the screen in the given point in time. */ + extern "C" + void gltf_renderer_get_bitmap(glTFHandle *handle, double time, +- char* buffer, long width, long height); ++ char* buffer, long width, long height, GLenum format); + + /** Start playing the glTF animation to the current openGLcontext. */ + extern "C" +@@ -80,4 +80,4 @@ + /** Query where exactly the animation is, in seconds. */ + extern "C" + double gltf_animation_get_time(glTFHandle *handle); +-#endif +\ No newline at end of file ++#endif +diff -ur libgltf.org/src/libgltf.cpp libgltf/src/libgltf.cpp +--- libgltf.org/src/libgltf.cpp 2014-04-27 14:10:06.192988313 +0200 ++++ libgltf/src/libgltf.cpp 2014-04-27 14:12:06.648983788 +0200 +@@ -70,10 +70,10 @@ + + extern "C" + void gltf_renderer_get_bitmap(glTFHandle *handle, double time, +- char* buffer, long width, long height) ++ char* buffer, long width, long height, GLenum format) + { + class RenderScene* renderScene = (RenderScene*)handle->renderer; +- renderScene->renderToBuffer(&(handle->viewport), (unsigned char*)buffer); ++ renderScene->renderToBuffer(&(handle->viewport), (unsigned char*)buffer, format); + return; + } + +diff -ur libgltf.org/src/RenderScene.cpp libgltf/src/RenderScene.cpp +--- libgltf.org/src/RenderScene.cpp 2014-04-27 14:10:06.192988313 +0200 ++++ libgltf/src/RenderScene.cpp 2014-04-27 14:11:03.199986172 +0200 +@@ -630,7 +630,7 @@ + return pCamera; + } + +-void RenderScene::renderToBuffer(glTFViewport* pViewport, unsigned char * buffer) ++void RenderScene::renderToBuffer(glTFViewport* pViewport, unsigned char * buffer, GLenum format) + { + createRenderObj(pViewport->width, pViewport->height); + createTextureObj(pViewport->width, pViewport->height); +@@ -647,7 +647,7 @@ + GLenum fbResult = glCheckFramebufferStatus(GL_FRAMEBUFFER); + if( fbResult != GL_FRAMEBUFFER_COMPLETE ) + result = false; +- glReadPixels(0, 0, pViewport->width, pViewport->height, GL_BGR, ++ glReadPixels(0, 0, pViewport->width, pViewport->height, format, + GL_UNSIGNED_BYTE, buffer); + glBindFramebuffer(GL_FRAMEBUFFER, 0); + glDeleteFramebuffers(1, &mFBOID); +diff -ur libgltf.org/src/RenderScene.h libgltf/src/RenderScene.h +--- libgltf.org/src/RenderScene.h 2014-04-27 14:10:06.192988313 +0200 ++++ libgltf/src/RenderScene.h 2014-04-27 14:13:41.291980233 +0200 +@@ -91,7 +91,7 @@ + void render(void* lpParam); + void releaseRender(void* lpParam); + CPhysicalCamera* getCamera(); +- void renderToBuffer(glTFViewport* pViewpoit, unsigned char * buffer); ++ void renderToBuffer(glTFViewport* pViewpoit, unsigned char * buffer, GLenum format); + void renderRotateCamera(double horizontal, double vertical, + double planar, double time); + void renderMoveCamera(double x, double y, double z, double time); commit 99a034f91471b410d2437b6651be7ef10091549b Author: Zolnai Tamás <tamas.zol...@collabora.com> Date: Sun Apr 27 20:25:52 2014 +0200 OpenGLHelper: extract BGRA buffer -> BitmepEx conversion Change-Id: I71edb2768d24f0c6686a9c94333447a5acc498b4 diff --git a/chart2/source/view/main/OpenGLRender.cxx b/chart2/source/view/main/OpenGLRender.cxx index 79e408c..2301768 100644 --- a/chart2/source/view/main/OpenGLRender.cxx +++ b/chart2/source/view/main/OpenGLRender.cxx @@ -10,7 +10,6 @@ #include <GL/glew.h> #include <vector> #include "OpenGLRender.hxx" -#include <vcl/bmpacc.hxx> #include <vcl/graph.hxx> #include <com/sun/star/awt/XBitmap.hpp> #include <com/sun/star/beans/XPropertySet.hpp> @@ -200,31 +199,7 @@ BitmapEx OpenGLRender::GetAsBitmap() boost::scoped_array<sal_uInt8> buf(new sal_uInt8[m_iWidth * m_iHeight * 4]); glReadPixels(0, 0, m_iWidth, m_iHeight, GL_BGRA, GL_UNSIGNED_BYTE, buf.get()); - Bitmap aBitmap( Size(m_iWidth, m_iHeight), 24 ); - AlphaMask aAlpha( Size(m_iWidth, m_iHeight) ); - - { - Bitmap::ScopedWriteAccess pWriteAccess( aBitmap ); - AlphaMask::ScopedWriteAccess pAlphaWriteAccess( aAlpha ); - - size_t nCurPos = 0; - for( int y = 0; y < m_iHeight; ++y) - { - Scanline pScan = pWriteAccess->GetScanline(y); - Scanline pAlphaScan = pAlphaWriteAccess->GetScanline(y); - for( int x = 0; x < m_iWidth; ++x ) - { - *pScan++ = buf[nCurPos]; - *pScan++ = buf[nCurPos+1]; - *pScan++ = buf[nCurPos+2]; - - nCurPos += 3; - *pAlphaScan++ = static_cast<sal_uInt8>( 255 - buf[nCurPos++] ); - } - } - } - - BitmapEx aBmp(aBitmap, aAlpha); + BitmapEx aBmp = OpenGLHelper::ConvertBGRABufferToBitmapEx(buf.get(), m_iWidth, m_iHeight); #if DEBUG_PNG // debug PNG writing static int nIdx = 0; diff --git a/include/vcl/opengl/OpenGLHelper.hxx b/include/vcl/opengl/OpenGLHelper.hxx index 5551fc1..7fa7d84 100644 --- a/include/vcl/opengl/OpenGLHelper.hxx +++ b/include/vcl/opengl/OpenGLHelper.hxx @@ -22,6 +22,7 @@ public: static GLint LoadShaders(const OUString& rVertexShaderName, const OUString& rFragmentShaderName); static sal_uInt8* ConvertBitmapExToRGBABuffer(const BitmapEx& rBitmapEx); + static BitmapEx ConvertBGRABufferToBitmapEx(const sal_uInt8* const pBuffer, long nWidth, long nHeight); }; #endif diff --git a/vcl/source/opengl/OpenGLContext.cxx b/vcl/source/opengl/OpenGLContext.cxx index b8c963b..07b38d2 100644 --- a/vcl/source/opengl/OpenGLContext.cxx +++ b/vcl/source/opengl/OpenGLContext.cxx @@ -8,6 +8,7 @@ */ #include <vcl/opengl/OpenGLContext.hxx> +#include <vcl/opengl/OpenGLHelper.hxx> #include <vcl/syschild.hxx> #include <vcl/sysdata.hxx> @@ -15,7 +16,6 @@ #include <vcl/pngwrite.hxx> #include <vcl/bmpacc.hxx> #include <vcl/graph.hxx> -#include <vcl/bitmapex.hxx> using namespace com::sun::star; @@ -522,31 +522,7 @@ void OpenGLContext::renderToFile() boost::scoped_array<sal_uInt8> buf(new sal_uInt8[iWidth * iHeight * 4]); glReadPixels(0, 0, iWidth, iHeight, GL_BGRA, GL_UNSIGNED_BYTE, buf.get()); - Bitmap aBitmap( Size(iWidth, iHeight), 24 ); - AlphaMask aAlpha( Size(iWidth, iHeight) ); - - { - Bitmap::ScopedWriteAccess pWriteAccess( aBitmap ); - AlphaMask::ScopedWriteAccess pAlphaWriteAccess( aAlpha ); - - size_t nCurPos = 0; - for( int y = 0; y < iHeight; ++y) - { - Scanline pScan = pWriteAccess->GetScanline(y); - Scanline pAlphaScan = pAlphaWriteAccess->GetScanline(y); - for( int x = 0; x < iWidth; ++x ) - { - *pScan++ = buf[nCurPos]; - *pScan++ = buf[nCurPos+1]; - *pScan++ = buf[nCurPos+2]; - - nCurPos += 3; - *pAlphaScan++ = static_cast<sal_uInt8>( 255 - buf[nCurPos++] ); - } - } - } - - BitmapEx aBmp(aBitmap, aAlpha); + BitmapEx aBmp = OpenGLHelper::ConvertBGRABufferToBitmapEx(buf.get(), iWidth, iHeight); static int nIdx = 0; OUString aName = OUString( "file:///home/moggi/Documents/work/text" ) + OUString::number( nIdx++ ) + ".png"; try { diff --git a/vcl/source/opengl/OpenGLHelper.cxx b/vcl/source/opengl/OpenGLHelper.cxx index 35760f2..82b4a9a 100644 --- a/vcl/source/opengl/OpenGLHelper.cxx +++ b/vcl/source/opengl/OpenGLHelper.cxx @@ -168,4 +168,33 @@ sal_uInt8* OpenGLHelper::ConvertBitmapExToRGBABuffer(const BitmapEx& rBitmapEx) return pBitmapBuf; } +BitmapEx OpenGLHelper::ConvertBGRABufferToBitmapEx(const sal_uInt8* const pBuffer, long nWidth, long nHeight) +{ + assert(pBuffer); + Bitmap aBitmap( Size(nWidth, nHeight), 24 ); + AlphaMask aAlpha( Size(nWidth, nHeight) ); + + { + Bitmap::ScopedWriteAccess pWriteAccess( aBitmap ); + AlphaMask::ScopedWriteAccess pAlphaWriteAccess( aAlpha ); + + size_t nCurPos = 0; + for( int y = 0; y < nHeight; ++y) + { + Scanline pScan = pWriteAccess->GetScanline(y); + Scanline pAlphaScan = pAlphaWriteAccess->GetScanline(y); + for( int x = 0; x < nWidth; ++x ) + { + *pScan++ = pBuffer[nCurPos]; + *pScan++ = pBuffer[nCurPos+1]; + *pScan++ = pBuffer[nCurPos+2]; + + nCurPos += 3; + *pAlphaScan++ = static_cast<sal_uInt8>( 255 - pBuffer[nCurPos++] ); + } + } + } + return BitmapEx(aBitmap, aAlpha); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits