[Libreoffice-commits] core.git: Branch 'feature/use-ogl-context-in-canvas' - 3 commits - canvas/source include/vcl vcl/source
Markus Mohrhard
markus.mohrhard at collabora.co.uk
Thu Aug 7 20:55:17 PDT 2014
canvas/source/opengl/ogl_buffercontext.hxx | 9 ++++--
canvas/source/opengl/ogl_canvascustomsprite.cxx | 7 ++--
canvas/source/opengl/ogl_spritedevicehelper.cxx | 30 +++++++++++++++------
include/vcl/opengl/OpenGLHelper.hxx | 6 ++--
vcl/source/opengl/OpenGLHelper.cxx | 34 ++++++++++++++++++------
5 files changed, 63 insertions(+), 23 deletions(-)
New commits:
commit 062d9c7b8af0557398f399af0a4d4709b0c7d304
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date: Fri Aug 8 05:28:02 2014 +0200
reimplement custom sprite rendering with FBO
Change-Id: I8d7a54fac61a3072d4f34615e71e37c70dec4e50
diff --git a/canvas/source/opengl/ogl_buffercontext.hxx b/canvas/source/opengl/ogl_buffercontext.hxx
index 7d85e9a..a99446b 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 86cbac6..2f2853e 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 cd29f37..3f6b534 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
commit 89bc7be3ac9862bf1bd763226f56b6fee723a7cf
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date: Fri Aug 8 05:05:11 2014 +0200
fix variable name
Change-Id: I1cfd6d59e5569177d8ad23245435073d30fe1374
diff --git a/include/vcl/opengl/OpenGLHelper.hxx b/include/vcl/opengl/OpenGLHelper.hxx
index 0134697..52093c2 100644
--- a/include/vcl/opengl/OpenGLHelper.hxx
+++ b/include/vcl/opengl/OpenGLHelper.hxx
@@ -34,7 +34,7 @@ public:
* This also affects whether to free with glDeleteRenderbuffers or glDeleteTextures
*/
static void createFramebuffer(long nWidth, long nHeight, GLuint& nFramebufferId,
- GLuint& nRenderbufferTextId, GLuint& nRenderbufferColorId, bool bRenderbuffer = true);
+ GLuint& nRenderbufferDepthId, GLuint& nRenderbufferColorId, bool bRenderbuffer = true);
// Get OpenGL version (needs a context)
static float getGLVersion();
commit d24fd018c90c6517f88ecce3ed4f40fa47528ca7
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date: Fri Aug 8 04:52:38 2014 +0200
add possibility to generate FBO with texture
The caller is responsible to delete the buffers. Depending on bRenderbuffer either with glDeleteRenderbuffers or with glDeleteTextures.
Change-Id: I5ccbd49862c381abf04e812765cced485a083f89
diff --git a/include/vcl/opengl/OpenGLHelper.hxx b/include/vcl/opengl/OpenGLHelper.hxx
index f80d34b..0134697 100644
--- a/include/vcl/opengl/OpenGLHelper.hxx
+++ b/include/vcl/opengl/OpenGLHelper.hxx
@@ -30,9 +30,11 @@ public:
/**
* The caller is responsible for deleting the buffer objects identified by
* nFramebufferId, nRenderbufferDepthId and nRenderbufferColorId
+ * @param bRenderbuffer true => off-screen rendering, false => rendering to texture
+ * This also affects whether to free with glDeleteRenderbuffers or glDeleteTextures
*/
- static void createFramebuffer(long nWidth, long nHeight,
- GLuint& nFramebufferId, GLuint& nRenderbufferTextId, GLuint& nRenderbufferColorId);
+ static void createFramebuffer(long nWidth, long nHeight, GLuint& nFramebufferId,
+ GLuint& nRenderbufferTextId, GLuint& nRenderbufferColorId, bool bRenderbuffer = true);
// Get OpenGL version (needs a context)
static float getGLVersion();
diff --git a/vcl/source/opengl/OpenGLHelper.cxx b/vcl/source/opengl/OpenGLHelper.cxx
index a34ad75..d58b537 100644
--- a/vcl/source/opengl/OpenGLHelper.cxx
+++ b/vcl/source/opengl/OpenGLHelper.cxx
@@ -275,8 +275,8 @@ std::ostream& operator<<(std::ostream& rStrm, const glm::mat4& rMatrix)
return rStrm;
}
-void OpenGLHelper::createFramebuffer(long nWidth, long nHeight,
- GLuint& nFramebufferId, GLuint& nRenderbufferDepthId, GLuint& nRenderbufferColorId)
+void OpenGLHelper::createFramebuffer(long nWidth, long nHeight, GLuint& nFramebufferId,
+ GLuint& nRenderbufferDepthId, GLuint& nRenderbufferColorId, bool bRenderbuffer)
{
// create a renderbuffer for depth attachment
glGenRenderbuffers(1, &nRenderbufferDepthId);
@@ -284,13 +284,31 @@ void OpenGLHelper::createFramebuffer(long nWidth, long nHeight,
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, nWidth, nHeight);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
- // create a renderbuffer for color attachment
- glGenRenderbuffers(1, &nRenderbufferColorId);
- glBindRenderbuffer(GL_RENDERBUFFER, nRenderbufferColorId);
- glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, nWidth, nHeight);
- glBindRenderbuffer(GL_RENDERBUFFER, 0);
+ if(bRenderbuffer)
+ {
+ // create a renderbuffer for color attachment
+ glGenRenderbuffers(1, &nRenderbufferColorId);
+ glBindRenderbuffer(GL_RENDERBUFFER, nRenderbufferColorId);
+ glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, nWidth, nHeight);
+ glBindRenderbuffer(GL_RENDERBUFFER, 0);
+ }
+ else
+ {
+ glGenTextures(1, &nRenderbufferColorId);
+ glBindTexture(GL_TEXTURE_2D, nRenderbufferColorId);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, nWidth, nHeight, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, 0);
+ glBindTexture(GL_TEXTURE_2D, 0);
+
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+ GL_TEXTURE_2D, nRenderbufferColorId, 0);
+ }
- // create a framebuffer object and attach renderbuffer and texture
+ // create a framebuffer object and attach renderbuffer
glGenFramebuffers(1, &nFramebufferId);
glCheckFramebufferStatus(GL_FRAMEBUFFER);
glBindFramebuffer(GL_FRAMEBUFFER, nFramebufferId);
More information about the Libreoffice-commits
mailing list