diff options
author | Markus Mohrhard <markus.mohrhard@collabora.co.uk> | 2014-08-08 05:28:02 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2014-08-08 09:24:00 +0200 |
commit | 396fa3b663efb2f0b125c6328732263133590b3f (patch) | |
tree | 0a6e91f613cb35c94b30fd7ce14e713948516d73 /canvas | |
parent | fix variable name (diff) | |
download | core-396fa3b663efb2f0b125c6328732263133590b3f.tar.gz core-396fa3b663efb2f0b125c6328732263133590b3f.zip |
reimplement custom sprite rendering with FBO
Change-Id: I8d7a54fac61a3072d4f34615e71e37c70dec4e50
Diffstat (limited to 'canvas')
-rw-r--r-- | canvas/source/opengl/ogl_buffercontext.hxx | 9 | ||||
-rw-r--r-- | canvas/source/opengl/ogl_canvascustomsprite.cxx | 7 | ||||
-rw-r--r-- | canvas/source/opengl/ogl_spritedevicehelper.cxx | 30 |
3 files changed, 33 insertions, 13 deletions
diff --git a/canvas/source/opengl/ogl_buffercontext.hxx b/canvas/source/opengl/ogl_buffercontext.hxx index 7d85e9a3791d..a99446b7ad2c 100644 --- a/canvas/source/opengl/ogl_buffercontext.hxx +++ b/canvas/source/opengl/ogl_buffercontext.hxx @@ -10,20 +10,25 @@ #ifndef INCLUDED_CANVAS_SOURCE_OPENGL_OGL_BUFFERCONTEXT_HXX #define INCLUDED_CANVAS_SOURCE_OPENGL_OGL_BUFFERCONTEXT_HXX +#include <GL/glew.h> + #include <sal/config.h> #include <boost/shared_ptr.hpp> + namespace oglcanvas { struct IBufferContext { virtual ~IBufferContext() {} - /// start render to buffer. changes gl current context + /// start render to buffer. changes current framebuffer virtual bool startBufferRendering() = 0; - /// end render to buffer. switches to window context, and selects rendered texture + /// end render to buffer. switches to default framebuffer virtual bool endBufferRendering() = 0; + + virtual GLuint getTextureId() = 0; }; typedef ::boost::shared_ptr<IBufferContext> IBufferContextSharedPtr; diff --git a/canvas/source/opengl/ogl_canvascustomsprite.cxx b/canvas/source/opengl/ogl_canvascustomsprite.cxx index 86cbac6902dd..2f2853e78543 100644 --- a/canvas/source/opengl/ogl_canvascustomsprite.cxx +++ b/canvas/source/opengl/ogl_canvascustomsprite.cxx @@ -159,9 +159,8 @@ namespace oglcanvas // composite that to screen // TODO(P3): buffer texture - // TODO: moggi: reimplement as FBO with rendering to texture - pBufferContext = NULL; - // pBufferContext->startBufferRendering(); + pBufferContext = maCanvasHelper.getDeviceHelper()->createBufferContext(aSpriteSizePixel); + pBufferContext->startBufferRendering(); } // this ends up in pBufferContext, if that one's "current" @@ -174,6 +173,8 @@ namespace oglcanvas // screen now. Calls below switches us back to window // context, and binds to generated, dynamic texture pBufferContext->endBufferRendering(); + GLuint nTexture = pBufferContext->getTextureId(); + glBindTexture(GL_TEXTURE_2D, nTexture); glEnable(GL_TEXTURE_2D); glTexParameteri(GL_TEXTURE_2D, diff --git a/canvas/source/opengl/ogl_spritedevicehelper.cxx b/canvas/source/opengl/ogl_spritedevicehelper.cxx index cd29f37f5352..3f6b53482aed 100644 --- a/canvas/source/opengl/ogl_spritedevicehelper.cxx +++ b/canvas/source/opengl/ogl_spritedevicehelper.cxx @@ -537,21 +537,29 @@ namespace oglcanvas namespace { - /* - * TODO: mogg: reimplement through FBO with texture as backend class BufferContextImpl : public IBufferContext { ::basegfx::B2IVector maSize; const SpriteDeviceHelper& mrDeviceHelper; + GLuint mnFrambufferId; + GLuint mnDepthId; + GLuint mnTextureId; virtual bool startBufferRendering() SAL_OVERRIDE { - return false; + glBindFramebuffer(GL_FRAMEBUFFER, mnFrambufferId); + return true; } virtual bool endBufferRendering() SAL_OVERRIDE { - return false; + glBindFramebuffer(GL_FRAMEBUFFER, 0); + return true; + } + + virtual GLuint getTextureId() SAL_OVERRIDE + { + return mnTextureId; } public: @@ -559,20 +567,26 @@ namespace oglcanvas const ::basegfx::B2IVector& rSize) : maSize(rSize), mrDeviceHelper(rDeviceHelper), - mnTexture(0) + mnFrambufferId(0), + mnDepthId(0), + mnTextureId(0) { + OpenGLHelper::createFramebuffer(maSize.getX(), maSize.getY(), mnFrambufferId, + mnDepthId, mnTextureId, false); } virtual ~BufferContextImpl() { + glDeleteTextures(1, &mnTextureId); + glDeleteRenderbuffers(1, &mnDepthId); + glDeleteFramebuffers(1, &mnFrambufferId); } }; - */ } - IBufferContextSharedPtr SpriteDeviceHelper::createBufferContext(const ::basegfx::B2IVector& ) const + IBufferContextSharedPtr SpriteDeviceHelper::createBufferContext(const ::basegfx::B2IVector& rSize) const { - return NULL; + return IBufferContextSharedPtr(new BufferContextImpl(*this, rSize)); } TextureCache& SpriteDeviceHelper::getTextureCache() const |