summaryrefslogtreecommitdiff
path: root/avmedia/source
diff options
context:
space:
mode:
authorZolnai Tamás <tamas.zolnai@collabora.com>2014-04-20 10:27:13 +0200
committerZolnai Tamás <tamas.zolnai@collabora.com>2014-04-20 10:27:24 +0200
commitc1baaddd8feac01fb2da48c140d4a96c201d7213 (patch)
tree7867b2cabed2557ebc07642ef16a33f47d7aa06a /avmedia/source
parent0db1e713bde4b16604c2f564fdc785ba0b467242 (diff)
avmediaogl: load all needed files into buffers for gltf rendering
Change-Id: I00fe209f3b0061dd67240eb1a490fb62530ffb55
Diffstat (limited to 'avmedia/source')
-rw-r--r--avmedia/source/opengl/oglplayer.cxx62
-rw-r--r--avmedia/source/opengl/oglplayer.hxx2
2 files changed, 64 insertions, 0 deletions
diff --git a/avmedia/source/opengl/oglplayer.cxx b/avmedia/source/opengl/oglplayer.cxx
index a59573521a93..d0ffde395229 100644
--- a/avmedia/source/opengl/oglplayer.cxx
+++ b/avmedia/source/opengl/oglplayer.cxx
@@ -12,6 +12,11 @@
#include "oglwindow.hxx"
#include <cppuhelper/supportsservice.hxx>
+#include <tools/stream.hxx>
+#include <vcl/graph.hxx>
+#include <vcl/graphicfilter.hxx>
+#include <tools/urlobj.hxx>
+#include <vcl/opengl/OpenGLHelper.hxx>
using namespace com::sun::star;
@@ -26,9 +31,66 @@ OGLPlayer::~OGLPlayer()
{
}
+static bool lcl_LoadFile( glTFFile* io_pFile, const OUString& rURL)
+{
+ SvFileStream aStream( rURL, STREAM_READ );
+ if( !aStream.IsOpen() )
+ return false;
+
+ const sal_Int64 nBytes = aStream.remainingSize();
+ char* pBuffer = new char[nBytes];
+ aStream.Read( pBuffer, nBytes );
+ aStream.Close();
+
+ io_pFile->buffer = pBuffer;
+ io_pFile->size = nBytes;
+
+ return true;
+}
+
bool OGLPlayer::create( const OUString& rURL )
{
m_sURL = rURL;
+
+ // Load *.json file and init renderer
+ glTFFile aJsonFile;
+ aJsonFile.type = GLTF_JSON;
+ OString sFileName = OUStringToOString(m_sURL.copy(m_sURL.lastIndexOf("/")+1),RTL_TEXTENCODING_UTF8);
+ aJsonFile.filename = (char*)sFileName.getStr();
+ if( !lcl_LoadFile(&aJsonFile, m_sURL) )
+ return false;
+
+ m_pHandle = gltf_renderer_init(&aJsonFile);
+
+ if( !m_pHandle || !m_pHandle->files )
+ return false;
+
+ // Load external resources
+ for( size_t i = 0; i < m_pHandle->size; ++i )
+ {
+ glTFFile* pFile = m_pHandle->files[i];
+ if( pFile && pFile->filename )
+ {
+ const OUString sFilesURL = m_sURL.copy(0,m_sURL.lastIndexOf("/")+1) +
+ OStringToOUString(OString(pFile->filename),RTL_TEXTENCODING_UTF8);
+ if( pFile->type == GLTF_IMAGE )
+ {
+ // Load images as bitmaps
+ GraphicFilter aFilter;
+ Graphic aGraphic;
+ aFilter.ImportGraphic(aGraphic, INetURLObject(sFilesURL));
+ const BitmapEx aBitmapEx = aGraphic.GetBitmapEx();
+ pFile->buffer = (char*)OpenGLHelper::ConvertBitmapExToRGBABuffer(aBitmapEx);
+ pFile->imagewidth = aBitmapEx.GetSizePixel().Width();
+ pFile->imageheight = aBitmapEx.GetSizePixel().Height();
+ }
+ else if( pFile->type == GLTF_BINARY || pFile->type == GLTF_GLSL )
+ {
+ if( !lcl_LoadFile(pFile, sFilesURL) )
+ return false;
+ }
+ }
+ }
return true;
}
diff --git a/avmedia/source/opengl/oglplayer.hxx b/avmedia/source/opengl/oglplayer.hxx
index 50a9190b930b..cf8ac2cdb222 100644
--- a/avmedia/source/opengl/oglplayer.hxx
+++ b/avmedia/source/opengl/oglplayer.hxx
@@ -14,6 +14,7 @@
#include <cppuhelper/basemutex.hxx>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/media/XPlayer.hpp>
+#include <libgltf.h>
namespace avmedia { namespace ogl {
@@ -54,6 +55,7 @@ public:
private:
OUString m_sURL;
+ glTFHandle* m_pHandle;
};
} // namespace ogl