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