Kaydet (Commit) 652e3d2d authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl

save texture to file as a PNG image

Change-Id: I5605b80f95d89599efe58cf65e1ce3f3581d401f
üst 8657e379
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include <GL/glew.h> #include <GL/glew.h>
#include <vcl/dllapi.h> #include <vcl/dllapi.h>
#include <vcl/salgtype.hxx> #include <vcl/salgtype.hxx>
#include <rtl/ustring.hxx>
#include <tools/gen.hxx> #include <tools/gen.hxx>
class ImplOpenGLTexture class ImplOpenGLTexture
...@@ -71,6 +71,8 @@ public: ...@@ -71,6 +71,8 @@ public:
void Unbind(); void Unbind();
void Read( GLenum nFormat, GLenum nType, sal_uInt8* pData ); void Read( GLenum nFormat, GLenum nType, sal_uInt8* pData );
void SaveToFile(const OUString& rFileName);
GLenum GetFilter() const; GLenum GetFilter() const;
void SetFilter( GLenum nFilter ); void SetFilter( GLenum nFilter );
......
...@@ -23,7 +23,8 @@ ...@@ -23,7 +23,8 @@
#include "svdata.hxx" #include "svdata.hxx"
#include "vcl/salbtype.hxx" #include <vcl/salbtype.hxx>
#include <vcl/pngwrite.hxx>
#include "opengl/framebuffer.hxx" #include "opengl/framebuffer.hxx"
#include "opengl/texture.hxx" #include "opengl/texture.hxx"
...@@ -262,6 +263,26 @@ void OpenGLTexture::Unbind() ...@@ -262,6 +263,26 @@ void OpenGLTexture::Unbind()
CHECK_GL_ERROR(); CHECK_GL_ERROR();
} }
void OpenGLTexture::SaveToFile(const OUString& rFileName)
{
std::vector<sal_uInt8> pBuffer(GetWidth() * GetHeight() * 4);
Read(GL_BGRA, GL_UNSIGNED_BYTE, pBuffer.data());
BitmapEx aBitmap = OpenGLHelper::ConvertBGRABufferToBitmapEx(pBuffer.data(), GetWidth(), GetHeight());
try
{
vcl::PNGWriter aWriter(aBitmap);
SvFileStream sOutput(rFileName, StreamMode::WRITE);
aWriter.Write(sOutput);
sOutput.Close();
}
catch (...)
{
SAL_WARN("vcl.opengl", "Error writing png to " << rFileName);
}
CHECK_GL_ERROR();
}
void OpenGLTexture::Read( GLenum nFormat, GLenum nType, sal_uInt8* pData ) void OpenGLTexture::Read( GLenum nFormat, GLenum nType, sal_uInt8* pData )
{ {
if( mpImpl == NULL ) if( mpImpl == NULL )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment