Kaydet (Commit) 20e4e65b authored tarafından Markus Mohrhard's avatar Markus Mohrhard Kaydeden (comit) Markus Mohrhard

add a text cache to improve rendering performance

Change-Id: I5b3fbe9476f0eafed4524f57aa7bf65dfd029c1d
üst 4f8d9775
......@@ -30,7 +30,8 @@ GL3DBarChart::GL3DBarChart(
mpRenderer(new opengl3D::OpenGL3DRenderer()),
mrWindow(rWindow),
mpCamera(NULL),
mbValidContext(true)
mbValidContext(true),
mpTextCache(new opengl3D::TextCache())
{
Size aSize = mrWindow.GetSizePixel();
mpRenderer->SetSize(aSize);
......@@ -101,7 +102,8 @@ void GL3DBarChart::create3DShapes(const boost::ptr_vector<VDataSeries>& rDataSer
if(!aSeriesName.isEmpty())
{
maShapes.push_back(new opengl3D::Text(mpRenderer.get(), aSeriesName, nId++));
maShapes.push_back(new opengl3D::Text(mpRenderer.get(),
*mpTextCache, aSeriesName, nId++));
opengl3D::Text* p = static_cast<opengl3D::Text*>(&maShapes.back());
glm::vec3 aTopLeft, aTopRight, aBottomRight;
aTopLeft.x = -nBarDistanceY;
......@@ -181,7 +183,8 @@ void GL3DBarChart::create3DShapes(const boost::ptr_vector<VDataSeries>& rDataSer
float nXPos = i * (nBarSizeX + nBarDistanceX);
maShapes.push_back(new opengl3D::Text(mpRenderer.get(), aCats[i], nId++));
maShapes.push_back(new opengl3D::Text(mpRenderer.get(), *mpTextCache,
aCats[i], nId++));
opengl3D::Text* p = static_cast<opengl3D::Text*>(&maShapes.back());
aTopLeft.x = nXPos + TEXT_HEIGHT;
aTopLeft.y = nYPos + calculateTextWidth(aCats[i]) + 0.5 * nBarDistanceY;
......@@ -193,7 +196,8 @@ void GL3DBarChart::create3DShapes(const boost::ptr_vector<VDataSeries>& rDataSer
// create shapes on other side as well
maShapes.push_back(new opengl3D::Text(mpRenderer.get(), aCats[i], nId++));
maShapes.push_back(new opengl3D::Text(mpRenderer.get(), *mpTextCache,
aCats[i], nId++));
p = static_cast<opengl3D::Text*>(&maShapes.back());
aTopLeft.x = nXPos + TEXT_HEIGHT;
aTopLeft.y = - 0.5 * nBarDistanceY;
......
......@@ -14,10 +14,22 @@
#include <vcl/opengl/OpenGLContext.hxx>
#include "GL3DRenderer.hxx"
#include <boost/ptr_container/ptr_map.hpp>
namespace chart {
namespace opengl3D {
class TextCache
{
public:
const BitmapEx& getText(OUString rText);
private:
typedef boost::ptr_map<OUString, BitmapEx> TextCacheType;
TextCacheType maTextCache;
};
class Renderable3DObject
{
public:
......@@ -65,7 +77,7 @@ private:
class Text : public Renderable3DObject
{
public:
Text(OpenGL3DRenderer* pRenderer, const OUString& rStr, sal_uInt32 nId);
Text(OpenGL3DRenderer* pRenderer, TextCache& rTextCache, const OUString& rStr, sal_uInt32 nId);
virtual void render() SAL_OVERRIDE;
Size getSize() const;
......@@ -73,7 +85,7 @@ public:
void setPosition(const glm::vec3& rTopLeft, const glm::vec3& rTopRight, const glm::vec3& rBottomRight);
private:
BitmapEx maText;
const BitmapEx& mrText;
glm::vec3 maTopLeft;
glm::vec3 maTopRight;
glm::vec3 maBottomRight;
......
......@@ -26,6 +26,7 @@ namespace opengl3D {
class Renderable3DObject;
class OpenGL3DRenderer;
class TextCache;
class Camera;
}
......@@ -58,6 +59,8 @@ private:
opengl3D::Camera* mpCamera;
bool mbValidContext;
boost::scoped_ptr<opengl3D::TextCache> mpTextCache;
};
}
......
......@@ -68,10 +68,12 @@ void Line::setLineColor(const Color& rColor)
maLineColor = rColor;
}
Text::Text(OpenGL3DRenderer* pRenderer, const OUString& rStr, sal_uInt32 nId):
Renderable3DObject(pRenderer, nId)
const BitmapEx& TextCache::getText(OUString rText)
{
// Convert OUString to BitmapEx.
TextCacheType::const_iterator itr = maTextCache.find(rText);
if(itr != maTextCache.end())
return *itr->second;
VirtualDevice aDevice(*Application::GetDefaultDevice(), 0, 0);
Font aFont = aDevice.GetFont();
aFont.SetSize(Size(0, 96));
......@@ -79,27 +81,35 @@ Text::Text(OpenGL3DRenderer* pRenderer, const OUString& rStr, sal_uInt32 nId):
::Rectangle aRect;
aDevice.SetFont(aFont);
aDevice.Erase();
aDevice.GetTextBoundRect(aRect, rStr);
aDevice.GetTextBoundRect(aRect, rText);
Size aSize = aRect.GetSize();
aSize.Width() += 5;
aSize.Height() *= 1.6;
aDevice.SetOutputSizePixel(aSize);
aDevice.SetBackground(Wallpaper(COL_TRANSPARENT));
aDevice.DrawText(Point(0,0), rStr);
aDevice.DrawText(Point(0,0), rText);
maText = BitmapEx(aDevice.GetBitmapEx(Point(0,0), aSize));
BitmapEx* pText = new BitmapEx(aDevice.GetBitmapEx(Point(0,0), aSize));
maTextCache.insert(rText, pText);
return *pText;
}
Text::Text(OpenGL3DRenderer* pRenderer, TextCache& rTextCache, const OUString& rStr, sal_uInt32 nId):
Renderable3DObject(pRenderer, nId),
mrText(rTextCache.getText(rStr))
{
}
void Text::render()
{
glm::vec3 dir2 = maTopRight - maTopLeft;
glm::vec3 bottomLeft = maBottomRight - dir2;
mpRenderer->CreateTextTexture(maText, maTopLeft, maTopRight, maBottomRight, bottomLeft, mnUniqueId);
mpRenderer->CreateTextTexture(mrText, maTopLeft, maTopRight, maBottomRight, bottomLeft, mnUniqueId);
}
Size Text::getSize() const
{
return maText.GetSizePixel();
return mrText.GetSizePixel();
}
void Text::setPosition(const glm::vec3& rTopLeft, const glm::vec3& rTopRight, const glm::vec3& rBottomRight)
......
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