summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@collabora.co.uk>2014-08-08 05:28:02 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2014-08-08 05:46:17 +0200
commit062d9c7b8af0557398f399af0a4d4709b0c7d304 (patch)
tree4b941ae818793ec6c78d0f38aa640b006154618c
parent89bc7be3ac9862bf1bd763226f56b6fee723a7cf (diff)
reimplement custom sprite rendering with FBOfeature/use-ogl-context-in-canvas
Change-Id: I8d7a54fac61a3072d4f34615e71e37c70dec4e50
-rw-r--r--canvas/source/opengl/ogl_buffercontext.hxx9
-rw-r--r--canvas/source/opengl/ogl_canvascustomsprite.cxx7
-rw-r--r--canvas/source/opengl/ogl_spritedevicehelper.cxx30
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