[Libreoffice-commits] core.git: 10 commits - chart2/opengl chart2/source
Markus Mohrhard
markus.mohrhard at collabora.co.uk
Tue Aug 12 21:30:25 PDT 2014
chart2/opengl/screenTextFragmentShader.glsl | 3
chart2/source/view/charttypes/GL3DBarChart.cxx | 386 ++++++++++++++++++++-----
chart2/source/view/inc/3DChartObjects.hxx | 3
chart2/source/view/inc/GL3DBarChart.hxx | 32 +-
chart2/source/view/inc/GL3DRenderer.hxx | 10
chart2/source/view/main/3DChartObjects.cxx | 5
chart2/source/view/main/GL3DRenderer.cxx | 78 ++++-
7 files changed, 424 insertions(+), 93 deletions(-)
New commits:
commit 0da2a52dc13e594c9196de9b28cd12c6800001b9
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date: Wed Aug 13 06:14:30 2014 +0200
use references where possible
Change-Id: Ie629d3d8b6d3048a0b34bb80f27eba6044d7f695
diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx
index 0d5dd13..0299b92 100644
--- a/chart2/source/view/charttypes/GL3DBarChart.cxx
+++ b/chart2/source/view/charttypes/GL3DBarChart.cxx
@@ -928,11 +928,11 @@ void GL3DBarChart::contextDestroyed()
mbValidContext = false;
}
-void GL3DBarChart::addScreenTextShape(OUString &nStr, glm::vec2 rLeftTop, float nTextHeight, glm::vec3 rPos, sal_uInt32 nEvent)
+void GL3DBarChart::addScreenTextShape(OUString &nStr, glm::vec2 rLeftTop, float nTextHeight, const glm::vec3& rPos, sal_uInt32 nEvent)
{
maScreenTextShapes.push_back(new opengl3D::ScreenText(mpRenderer.get(), *mpTextCache, nStr, nEvent));
- opengl3D::TextCacheItem aTextCache = mpTextCache->getText(nStr);
- float nRectWidth = (float)aTextCache.maSize.Width() / (float)aTextCache.maSize.Height() * 0.05;
+ const opengl3D::TextCacheItem& rTextCache = mpTextCache->getText(nStr);
+ float nRectWidth = (float)rTextCache.maSize.Width() / (float)rTextCache.maSize.Height() * 0.05;
opengl3D::ScreenText* pScreenText = static_cast<opengl3D::ScreenText*>(&maScreenTextShapes.back());
pScreenText->setPosition(rLeftTop, glm::vec2(rLeftTop.x + nRectWidth, rLeftTop.y - nTextHeight), rPos);
}
@@ -1018,8 +1018,8 @@ void GL3DBarChart::updateClickEvent()
{
aBarValue = OUString("Value: ") + OUString::number(*it);
maScreenTextShapes.push_back(new opengl3D::ScreenText(mpRenderer.get(), *mpTextCache, aBarValue, CALC_POS_EVENT_ID));
- opengl3D::TextCacheItem aTextCache = mpTextCache->getText(aBarValue);
- float nRectWidth = (float)aTextCache.maSize.Width() / (float)aTextCache.maSize.Height() * 0.03;
+ const opengl3D::TextCacheItem& rTextCache = mpTextCache->getText(aBarValue);
+ float nRectWidth = (float)rTextCache.maSize.Width() / (float)rTextCache.maSize.Height() * 0.03;
std::map<sal_uInt32, const BarInformation>::const_iterator itr = maBarMap.find(mSelectBarId);
const BarInformation& rBarInfo = itr->second;
glm::vec3 aTextPos = glm::vec3(rBarInfo.maPos.x + BAR_SIZE_X / 2.0f,
@@ -1038,9 +1038,9 @@ void GL3DBarChart::updateClickEvent()
}
}
-float GL3DBarChart::calcScrollDistance(glm::mat4& rMVP, glm::vec3 aPos)
+float GL3DBarChart::calcScrollDistance(const glm::mat4& rMVP, const glm::vec3& rPos)
{
- glm::vec4 aScreenPos = rMVP * glm::vec4(aPos, 1.0);
+ glm::vec4 aScreenPos = rMVP * glm::vec4(rPos, 1.0);
glm::vec3 aActualPos = glm::vec3(aScreenPos.x / aScreenPos.w, aScreenPos.y / aScreenPos.w, 0.0);
return glm::length(aActualPos);
}
@@ -1159,8 +1159,8 @@ void GL3DBarChart::updateScroll()
{
OUString aBarValue = OUString("Value: ") + OUString::number(aBarInfoList[i].mnVal);
maScreenTextShapes.push_back(new opengl3D::ScreenText(mpRenderer.get(), *mpTextCache, aBarValue, CALC_POS_EVENT_ID));
- opengl3D::TextCacheItem aTextCache = mpTextCache->getText(aBarValue);
- float nRectWidth = (float)aTextCache.maSize.Width() / (float)aTextCache.maSize.Height() * 0.03;
+ const opengl3D::TextCacheItem& rTextCache = mpTextCache->getText(aBarValue);
+ float nRectWidth = (float)rTextCache.maSize.Width() / (float)rTextCache.maSize.Height() * 0.03;
glm::vec3 aTextPos = glm::vec3(aBarInfoList[i].maPos.x + BAR_SIZE_X / 2.0f,
aBarInfoList[i].maPos.y + BAR_SIZE_Y / 2.0f,
aBarInfoList[i].maPos.z);
diff --git a/chart2/source/view/inc/GL3DBarChart.hxx b/chart2/source/view/inc/GL3DBarChart.hxx
index f50895f..3f8ea1d 100644
--- a/chart2/source/view/inc/GL3DBarChart.hxx
+++ b/chart2/source/view/inc/GL3DBarChart.hxx
@@ -90,11 +90,11 @@ private:
void updateDataUpdateFPS();
DECL_LINK(updateTimer, void*);
int calcTimeInterval(TimeValue &startTime, TimeValue &endTime);
- void addScreenTextShape(OUString &nStr, glm::vec2 rLeftTop, float nTextHeight, glm::vec3 rPos = glm::vec3(0.0f, 0.0f, 0.0f), sal_uInt32 nEvent = 0);
+ void addScreenTextShape(OUString &nStr, glm::vec2 rLeftTop, float nTextHeight, const glm::vec3& rPos = glm::vec3(0.0f, 0.0f, 0.0f), sal_uInt32 nEvent = 0);
void recordBarHistory(sal_uInt32 &nBarID, float &nVal);
void updateClickEvent();
void calcDistance(std::vector<sal_uInt32> &vectorNearest);
- float calcScrollDistance(glm::mat4 &mvp, glm::vec3 pos);
+ float calcScrollDistance(const glm::mat4 &mvp, const glm::vec3& rPos);
void initDistanceHeap(std::vector<sal_uInt32> &vectorNearest);
void keepHeap(std::vector<sal_uInt32> &vectorNearest, int index);
void swapVector(int i, int j, std::vector<sal_uInt32> &vectorNearest);
commit 80fe3e318b6ca4f179dc82a35078888533480afa
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date: Wed Aug 13 06:07:58 2014 +0200
consistent variable naming
Change-Id: I81012a46abd6182c04f1939b6451b18fbbdec646
diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx
index 924c6d2..0d5dd13 100644
--- a/chart2/source/view/charttypes/GL3DBarChart.cxx
+++ b/chart2/source/view/charttypes/GL3DBarChart.cxx
@@ -324,8 +324,8 @@ void RenderBenchMarkThread::ProcessClickFlyBack()
if (!mbNeedFlyBack)
return;
osl_getSystemTime(&maClickFlyBackEndTime);
- int aDeltaMs = mpChart->calcTimeInterval(maClickFlyBackStartTime, maClickFlyBackEndTime);
- if(aDeltaMs >= 10000)
+ int nDeltaMs = mpChart->calcTimeInterval(maClickFlyBackStartTime, maClickFlyBackEndTime);
+ if(nDeltaMs >= 10000)
{
mpChart->maRenderEvent = EVENT_MOVE_TO_DEFAULT;
}
@@ -647,10 +647,10 @@ void GL3DBarChart::create3DShapes(const boost::ptr_vector<VDataSeries>& rDataSer
mnCornerId = 0;
mbCameraInit = true;
float pi = 3.1415926f;
- float angleX = -pi / 6.5f;
- float angleZ = -pi / 8.0f;
- glm::mat4 maDefaultRotateMatrix = glm::eulerAngleYXZ(0.0f, angleX, angleZ);
- maDefaultCameraPosition = glm::vec3(maDefaultRotateMatrix * glm::vec4(maDefaultCameraPosition, 1.0f));
+ float nAngleX = -pi / 6.5f;
+ float nAngleZ = -pi / 8.0f;
+ glm::mat4 aDefaultRotateMatrix = glm::eulerAngleYXZ(0.0f, nAngleX, nAngleZ);
+ maDefaultCameraPosition = glm::vec3(aDefaultRotateMatrix * glm::vec4(maDefaultCameraPosition, 1.0f));
maCameraPosition = maDefaultCameraPosition;
maCameraDirection = maDefaultCameraDirection;
mpCamera->setPosition(maCameraPosition);
@@ -690,7 +690,6 @@ void GL3DBarChart::update()
mpRenderThread = rtl::Reference<RenderThread>(new RenderOneFrameThread(this));
mrWindow.getContext().resetCurrent();
mpRenderThread->launch();
-
}
namespace {
@@ -791,21 +790,21 @@ void GL3DBarChart::clickedAt(const Point& rPos, sal_uInt16 nButtons)
return;
const BarInformation& rBarInfo = itr->second;
- glm::vec3 textPos = glm::vec3(rBarInfo.maPos.x + BAR_SIZE_X / 2.0f,
+ glm::vec3 aTextPos = glm::vec3(rBarInfo.maPos.x + BAR_SIZE_X / 2.0f,
rBarInfo.maPos.y + BAR_SIZE_Y / 2.0f,
rBarInfo.maPos.z);
maShapes.push_back(new opengl3D::ScreenText(mpRenderer.get(), *mpTextCache,
OUString("Value: ") + OUString::number(rBarInfo.mnVal), CALC_POS_EVENT_ID));
opengl3D::ScreenText* pScreenText = static_cast<opengl3D::ScreenText*>(&maShapes.back());
- pScreenText->setPosition(glm::vec2(-0.9f, 0.9f), glm::vec2(-0.6f, 0.8f), textPos);
+ pScreenText->setPosition(glm::vec2(-0.9f, 0.9f), glm::vec2(-0.6f, 0.8f), aTextPos);
pScreenText->render();
- glm::vec3 maTargetPosition = rBarInfo.maPos;
- maTargetPosition.z += 240;
- maTargetPosition.y += BAR_SIZE_Y / 2.0f;
+ glm::vec3 aTargetPosition = rBarInfo.maPos;
+ aTargetPosition.z += 240;
+ aTargetPosition.y += BAR_SIZE_Y / 2.0f;
Size aSize = mrWindow.GetSizePixel();
mrWindow.getContext().setWinSize(aSize);
- mpRenderThread = rtl::Reference<RenderThread>(new RenderAnimationThread(this, maCameraPosition, maTargetPosition, STEPS));
+ mpRenderThread = rtl::Reference<RenderThread>(new RenderAnimationThread(this, maCameraPosition, aTargetPosition, STEPS));
mrWindow.getContext().resetCurrent();
mpRenderThread->launch();
@@ -830,16 +829,16 @@ void GL3DBarChart::render()
void GL3DBarChart::mouseDragMove(const Point& rStartPos, const Point& rEndPos, sal_uInt16 )
{
- long direction = rEndPos.X() - rStartPos.X();
+ long nDirection = rEndPos.X() - rStartPos.X();
osl::MutexGuard aGuard(maMutex);
if ((maRenderEvent == EVENT_NONE) || (maRenderEvent == EVENT_SHOW_SCROLL))
- maRenderEvent = direction > 0 ? EVENT_DRAG_RIGHT : EVENT_DRAG_LEFT;
- if(direction < 0)
+ maRenderEvent = nDirection > 0 ? EVENT_DRAG_RIGHT : EVENT_DRAG_LEFT;
+ if(nDirection < 0)
{
mnCornerId = (mnCornerId + 1) % 4;
moveToCorner();
}
- else if(direction > 0)
+ else if(nDirection > 0)
{
mnCornerId = mnCornerId - 1;
if(mnCornerId < 0)
@@ -932,20 +931,20 @@ void GL3DBarChart::contextDestroyed()
void GL3DBarChart::addScreenTextShape(OUString &nStr, glm::vec2 rLeftTop, float nTextHeight, glm::vec3 rPos, sal_uInt32 nEvent)
{
maScreenTextShapes.push_back(new opengl3D::ScreenText(mpRenderer.get(), *mpTextCache, nStr, nEvent));
- opengl3D::TextCacheItem tmpTextCache = mpTextCache->getText(nStr);
- float rectWidth = (float)tmpTextCache.maSize.Width() / (float)tmpTextCache.maSize.Height() * 0.05;
+ opengl3D::TextCacheItem aTextCache = mpTextCache->getText(nStr);
+ float nRectWidth = (float)aTextCache.maSize.Width() / (float)aTextCache.maSize.Height() * 0.05;
opengl3D::ScreenText* pScreenText = static_cast<opengl3D::ScreenText*>(&maScreenTextShapes.back());
- pScreenText->setPosition(rLeftTop, glm::vec2(rLeftTop.x + rectWidth, rLeftTop.y - nTextHeight), rPos);
+ pScreenText->setPosition(rLeftTop, glm::vec2(rLeftTop.x + nRectWidth, rLeftTop.y - nTextHeight), rPos);
}
void GL3DBarChart::updateRenderFPS()
{
- int aDeltaMs = calcTimeInterval(maFPSRenderStartTime, maFPSRenderEndTime);
- if(aDeltaMs >= FPS_TIME)
+ int nDeltaMs = calcTimeInterval(maFPSRenderStartTime, maFPSRenderEndTime);
+ if(nDeltaMs >= FPS_TIME)
{
osl_getSystemTime(&maFPSRenderEndTime);
- aDeltaMs = calcTimeInterval(maFPSRenderStartTime, maFPSRenderEndTime);
- int iFPS = miFrameCount * 1000 / aDeltaMs;
+ nDeltaMs = calcTimeInterval(maFPSRenderStartTime, maFPSRenderEndTime);
+ int iFPS = miFrameCount * 1000 / nDeltaMs;
maFPS = OUString("Render FPS: ") + OUString::number(iFPS);
miFrameCount = 0;
osl_getSystemTime(&maFPSRenderStartTime);
@@ -978,17 +977,17 @@ void GL3DBarChart::updateScreenText()
void GL3DBarChart::updateDataUpdateFPS()
{
- int aDeltaMs = calcTimeInterval(maDataUpdateStartTime, maDataUpdateEndTime);
- if(aDeltaMs >= DATAUPDATE_FPS_TIME)
+ int nDeltaMs = calcTimeInterval(maDataUpdateStartTime, maDataUpdateEndTime);
+ if(nDeltaMs >= DATAUPDATE_FPS_TIME)
{
- int iFPS = miDataUpdateCounter * 1000 / aDeltaMs;
+ int iFPS = miDataUpdateCounter * 1000 / nDeltaMs;
if (iFPS)
{
maDataUpdateFPS = OUString("Data Update FPS: ") + OUString::number(iFPS);
}
else
{
- float fFPS = (float)miDataUpdateCounter * 1000 / (float)aDeltaMs;
+ float fFPS = (float)miDataUpdateCounter * 1000 / (float)nDeltaMs;
maDataUpdateFPS = OUString("Data Update FPS: ") + OUString::number(fFPS);
}
miDataUpdateCounter = 0;
@@ -1000,125 +999,125 @@ void GL3DBarChart::updateDataUpdateFPS()
void GL3DBarChart::recordBarHistory(sal_uInt32 &nBarID, float &nVal)
{
- std::list<float> &alist = maBarHistory[nBarID];
- if(alist.size() == HISTORY_NUM)
- alist.pop_front();
- alist.push_back(nVal);
+ std::list<float>& aList = maBarHistory[nBarID];
+ if(aList.size() == HISTORY_NUM)
+ aList.pop_front();
+ aList.push_back(nVal);
}
void GL3DBarChart::updateClickEvent()
{
if (maRenderEvent == EVENT_CLICK)
{
- std::list<float> &alist = maBarHistory[mSelectBarId];
+ std::list<float>& aList = maBarHistory[mSelectBarId];
sal_uInt32 idex = 0;
- for (std::list<float>::iterator it = alist.begin();it != alist.end();it++)
+ for (std::list<float>::iterator it = aList.begin();it != aList.end();it++)
{
- OUString barValue;
- if (idex + 1 == alist.size())
+ OUString aBarValue;
+ if (idex + 1 == aList.size())
{
- barValue = OUString("Value: ") + OUString::number(*it);
- maScreenTextShapes.push_back(new opengl3D::ScreenText(mpRenderer.get(), *mpTextCache, barValue, CALC_POS_EVENT_ID));
- opengl3D::TextCacheItem tmpTextCache = mpTextCache->getText(barValue);
- float rectWidth = (float)tmpTextCache.maSize.Width() / (float)tmpTextCache.maSize.Height() * 0.03;
+ aBarValue = OUString("Value: ") + OUString::number(*it);
+ maScreenTextShapes.push_back(new opengl3D::ScreenText(mpRenderer.get(), *mpTextCache, aBarValue, CALC_POS_EVENT_ID));
+ opengl3D::TextCacheItem aTextCache = mpTextCache->getText(aBarValue);
+ float nRectWidth = (float)aTextCache.maSize.Width() / (float)aTextCache.maSize.Height() * 0.03;
std::map<sal_uInt32, const BarInformation>::const_iterator itr = maBarMap.find(mSelectBarId);
const BarInformation& rBarInfo = itr->second;
- glm::vec3 textPos = glm::vec3(rBarInfo.maPos.x + BAR_SIZE_X / 2.0f,
+ glm::vec3 aTextPos = glm::vec3(rBarInfo.maPos.x + BAR_SIZE_X / 2.0f,
rBarInfo.maPos.y + BAR_SIZE_Y / 2.0f,
rBarInfo.maPos.z);
opengl3D::ScreenText* pScreenText = static_cast<opengl3D::ScreenText*>(&maScreenTextShapes.back());
- pScreenText->setPosition(glm::vec2(-rectWidth / 2, 0.03f), glm::vec2(rectWidth / 2, -0.03f), textPos);
+ pScreenText->setPosition(glm::vec2(-nRectWidth / 2, 0.03f), glm::vec2(nRectWidth / 2, -0.03f), aTextPos);
}
else
{
- barValue = OUString("History_") + OUString::number(idex) + OUString(": ") + OUString::number(*it);
- addScreenTextShape(barValue, glm::vec2(0.65f, 0.99f - (idex * 0.1f)), 0.1f);
+ aBarValue = OUString("History_") + OUString::number(idex) + OUString(": ") + OUString::number(*it);
+ addScreenTextShape(aBarValue, glm::vec2(0.65f, 0.99f - (idex * 0.1f)), 0.1f);
}
idex++;
}
}
}
-float GL3DBarChart::calcScrollDistance(glm::mat4 &mvp, glm::vec3 pos)
+float GL3DBarChart::calcScrollDistance(glm::mat4& rMVP, glm::vec3 aPos)
{
- glm::vec4 screenPos = mvp * glm::vec4(pos, 1.0);
- glm::vec3 actualPos = glm::vec3(screenPos.x / screenPos.w, screenPos.y / screenPos.w, 0.0);
- return glm::length(actualPos);
+ glm::vec4 aScreenPos = rMVP * glm::vec4(aPos, 1.0);
+ glm::vec3 aActualPos = glm::vec3(aScreenPos.x / aScreenPos.w, aScreenPos.y / aScreenPos.w, 0.0);
+ return glm::length(aActualPos);
}
-void GL3DBarChart::calcDistance(std::vector<sal_uInt32> & vectorNearest)
+void GL3DBarChart::calcDistance(std::vector<sal_uInt32> & rVectorNearest)
{
int i =0;
- glm::mat4 projection = mpRenderer->GetProjectionMatrix();
- glm::mat4 view = mpRenderer->GetViewMatrix();
- glm::mat4 scale = mpRenderer->GetGlobalScaleMatrix();
- glm::mat4 mvp = projection * view * scale;
+ glm::mat4 aProjection = mpRenderer->GetProjectionMatrix();
+ glm::mat4 aView = mpRenderer->GetViewMatrix();
+ glm::mat4 aScale = mpRenderer->GetGlobalScaleMatrix();
+ glm::mat4 aMVP = aProjection * aView * aScale;
std::map<sal_uInt32, const BarInformation>::iterator it;
for(it= maBarMap.begin(); it!= maBarMap.end(); ++it)
{
sal_uInt32 nId = it->first;
if(i < SHOW_VALUE_COUNT)
{
- vectorNearest.push_back(nId);
+ rVectorNearest.push_back(nId);
i++;
}
- maDistanceMap[nId] = calcScrollDistance(mvp, glm::vec3(it->second.maPos.x + BAR_SIZE_X / 2.0f,
+ maDistanceMap[nId] = calcScrollDistance(aMVP, glm::vec3(it->second.maPos.x + BAR_SIZE_X / 2.0f,
it->second.maPos.y + BAR_SIZE_Y / 2.0f,
it->second.maPos.z));
}
}
-void GL3DBarChart::initDistanceHeap(std::vector<sal_uInt32> &vectorNearest)
+void GL3DBarChart::initDistanceHeap(std::vector<sal_uInt32> &rVectorNearest)
{
- for(int i= (vectorNearest.size()-2)/2; i>= 0; i--)
+ for(int i= (rVectorNearest.size()-2)/2; i>= 0; i--)
{
- keepHeap(vectorNearest, i);
+ keepHeap(rVectorNearest, i);
}
}
-void GL3DBarChart::keepHeap(std::vector<sal_uInt32> &vectorNearest, int index)
+void GL3DBarChart::keepHeap(std::vector<sal_uInt32> &rVectorNearest, int nIndex)
{
- size_t parentindex = index;
- while(parentindex < vectorNearest.size())
+ size_t nParentIndex = nIndex;
+ while(nParentIndex < rVectorNearest.size())
{
- size_t leftindex = parentindex * 2 + 1;
- size_t rightindex = leftindex +1;
- if(leftindex >= vectorNearest.size())
+ size_t nLeftIndex = nParentIndex * 2 + 1;
+ size_t nRightIndex = nLeftIndex +1;
+ if(nLeftIndex >= rVectorNearest.size())
break;
- size_t farthestindex = leftindex;
- float farthest = maDistanceMap[vectorNearest[leftindex]];
- if(rightindex < vectorNearest.size())
+ size_t nFarthestIndex = nLeftIndex;
+ float nFarthest = maDistanceMap[rVectorNearest[nLeftIndex]];
+ if(nRightIndex < rVectorNearest.size())
{
- float right = maDistanceMap[vectorNearest[rightindex]];
- if(right > farthest)
+ float nRight = maDistanceMap[rVectorNearest[nRightIndex]];
+ if(nRight > nFarthest)
{
- farthest = right;
- farthestindex = rightindex;
+ nFarthest = nRight;
+ nFarthestIndex = nRightIndex;
}
}
- float parent = maDistanceMap[vectorNearest[parentindex]];
- if(parent >= farthest)
+ float nParent = maDistanceMap[rVectorNearest[nParentIndex]];
+ if(nParent >= nFarthest)
break;
else
{
- swapVector(parentindex , farthestindex, vectorNearest);
- parentindex = farthestindex;
+ swapVector(nParentIndex , nFarthestIndex, rVectorNearest);
+ nParentIndex = nFarthestIndex;
}
}
}
-void GL3DBarChart::swapVector(int i, int j, std::vector<sal_uInt32> &vectorNearest)
+void GL3DBarChart::swapVector(int i, int j, std::vector<sal_uInt32> &rVectorNearest)
{
- sal_uInt32 tmp = vectorNearest[i];
- vectorNearest[i] = vectorNearest[j];
- vectorNearest[j] = tmp;
+ sal_uInt32 nTmp = rVectorNearest[i];
+ rVectorNearest[i] = rVectorNearest[j];
+ rVectorNearest[j] = nTmp;
}
-void GL3DBarChart::getNearestBars(std::vector<sal_uInt32> &vectorNearest)
+void GL3DBarChart::getNearestBars(std::vector<sal_uInt32> &rVectorNearest)
{
- calcDistance(vectorNearest);
- initDistanceHeap(vectorNearest);
+ calcDistance(rVectorNearest);
+ initDistanceHeap(rVectorNearest);
std::map<sal_uInt32, float>::iterator it;
int i = 0;
for(it= maDistanceMap.begin(); it!= maDistanceMap.end(); ++it)
@@ -1126,12 +1125,12 @@ void GL3DBarChart::getNearestBars(std::vector<sal_uInt32> &vectorNearest)
i++;
if(i <= SHOW_VALUE_COUNT)
continue;
- float distance = it->second;
- float Heaphead = maDistanceMap[vectorNearest[0]];
- if(distance < Heaphead)
+ float nDistance = it->second;
+ float nHeaphead = maDistanceMap[rVectorNearest[0]];
+ if(nDistance < nHeaphead)
{
- vectorNearest[0] = it->first;
- keepHeap(vectorNearest, 0);
+ rVectorNearest[0] = it->first;
+ keepHeap(rVectorNearest, 0);
}
}
}
@@ -1140,32 +1139,33 @@ void GL3DBarChart::updateScroll()
{
if ((maRenderEvent == EVENT_SCROLL) || (maRenderEvent == EVENT_SHOW_SCROLL))
{
- float minDistance = 0.0f;
- std::vector<BarInformation> barInfoList;
+ float fMinDistance = 0.0f;
+ std::vector<BarInformation> aBarInfoList;
for(size_t i= 0;i < maVectorNearest.size(); i++)
{
//get bar height position
std::map<sal_uInt32, const BarInformation>::const_iterator itr = maBarMap.find(maVectorNearest[i]);
const BarInformation& rBarInfo = itr->second;
- barInfoList.push_back(rBarInfo);
- glm::vec3 pos = rBarInfo.maPos;
- minDistance = (minDistance == 0.0f) ? glm::length(pos - maCameraPosition) :
- std::min(glm::length(pos - maCameraPosition), minDistance);
+ aBarInfoList.push_back(rBarInfo);
+ glm::vec3 aPos = rBarInfo.maPos;
+ fMinDistance = (fMinDistance == 0.0f) ? glm::length(aPos - maCameraPosition) :
+ std::min(glm::length(aPos - maCameraPosition), fMinDistance);
}
- if (minDistance <= SHOW_SCROLL_TEXT_DISTANCE)
+
+ if (fMinDistance <= SHOW_SCROLL_TEXT_DISTANCE)
{
//update scroll value
- for(size_t i = 0; i < barInfoList.size(); i++)
+ for(size_t i = 0; i < aBarInfoList.size(); i++)
{
- OUString barValue = OUString("Value: ") + OUString::number(barInfoList[i].mnVal);
- maScreenTextShapes.push_back(new opengl3D::ScreenText(mpRenderer.get(), *mpTextCache, barValue, CALC_POS_EVENT_ID));
- opengl3D::TextCacheItem tmpTextCache = mpTextCache->getText(barValue);
- float rectWidth = (float)tmpTextCache.maSize.Width() / (float)tmpTextCache.maSize.Height() * 0.03;
- glm::vec3 textPos = glm::vec3(barInfoList[i].maPos.x + BAR_SIZE_X / 2.0f,
- barInfoList[i].maPos.y + BAR_SIZE_Y / 2.0f,
- barInfoList[i].maPos.z);
+ OUString aBarValue = OUString("Value: ") + OUString::number(aBarInfoList[i].mnVal);
+ maScreenTextShapes.push_back(new opengl3D::ScreenText(mpRenderer.get(), *mpTextCache, aBarValue, CALC_POS_EVENT_ID));
+ opengl3D::TextCacheItem aTextCache = mpTextCache->getText(aBarValue);
+ float nRectWidth = (float)aTextCache.maSize.Width() / (float)aTextCache.maSize.Height() * 0.03;
+ glm::vec3 aTextPos = glm::vec3(aBarInfoList[i].maPos.x + BAR_SIZE_X / 2.0f,
+ aBarInfoList[i].maPos.y + BAR_SIZE_Y / 2.0f,
+ aBarInfoList[i].maPos.z);
opengl3D::ScreenText* pScreenText = static_cast<opengl3D::ScreenText*>(&maScreenTextShapes.back());
- pScreenText->setPosition(glm::vec2(-rectWidth / 2, 0.03f), glm::vec2(rectWidth / 2, -0.03f), textPos);
+ pScreenText->setPosition(glm::vec2(-nRectWidth / 2, 0.03f), glm::vec2(nRectWidth / 2, -0.03f), aTextPos);
}
}
}
commit db8c473cb73c6fc6aaf0e36e88e1b2ee000f4f6e
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date: Wed Aug 13 05:34:58 2014 +0200
fix warnings
Change-Id: Idced64d57ea850961d67e83e082b51dc9442cc0d
diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx
index 9893423..924c6d2 100644
--- a/chart2/source/view/charttypes/GL3DBarChart.cxx
+++ b/chart2/source/view/charttypes/GL3DBarChart.cxx
@@ -409,12 +409,12 @@ GL3DBarChart::GL3DBarChart(
maRenderEvent(EVENT_NONE),
mSelectBarId(0),
miScrollRate(0),
- miFrameCount(0),
- miDataUpdateCounter(0),
mbScrollFlg(false),
mbScreenTextNewRender(false),
maFPS(OUString("Render FPS: 0")),
- maDataUpdateFPS(OUString("Data Update FPS: 0"))
+ maDataUpdateFPS(OUString("Data Update FPS: 0")),
+ miFrameCount(0),
+ miDataUpdateCounter(0)
{
if (BENCH_MARK_MODE)
{
@@ -1062,7 +1062,6 @@ void GL3DBarChart::calcDistance(std::vector<sal_uInt32> & vectorNearest)
vectorNearest.push_back(nId);
i++;
}
- glm::vec3 distancePosition = it->second.maPos;
maDistanceMap[nId] = calcScrollDistance(mvp, glm::vec3(it->second.maPos.x + BAR_SIZE_X / 2.0f,
it->second.maPos.y + BAR_SIZE_Y / 2.0f,
it->second.maPos.z));
diff --git a/chart2/source/view/inc/GL3DBarChart.hxx b/chart2/source/view/inc/GL3DBarChart.hxx
index d8b8843..f50895f 100644
--- a/chart2/source/view/inc/GL3DBarChart.hxx
+++ b/chart2/source/view/inc/GL3DBarChart.hxx
@@ -50,7 +50,6 @@ enum RenderEventType
EVENT_DIE
};
-
class RenderThread;
class RenderOneFrameThread;
class RenderAnimationThread;
commit 0cb5939f72288d175f2977d4c832ab7ff1edbf18
Author: weigao <weigao at multicorewareinc.com>
Date: Sat Aug 9 20:33:08 2014 +0800
modify screen text color to blue
Change-Id: I80435a980550a2b74657442ef1b44ca8e3825a97
diff --git a/chart2/opengl/screenTextFragmentShader.glsl b/chart2/opengl/screenTextFragmentShader.glsl
index 7e2bd26..1354bf1 100644
--- a/chart2/opengl/screenTextFragmentShader.glsl
+++ b/chart2/opengl/screenTextFragmentShader.glsl
@@ -9,10 +9,11 @@
varying vec2 vTexCoord;
uniform sampler2D TextTex;
+uniform vec4 textColor;
void main()
{
vec3 color = texture2D(TextTex, vTexCoord).rgb;
- gl_FragColor = vec4(color, 1.0 - color.r);
+ gl_FragColor = vec4(textColor.rgb, 1.0 - color.r);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx
index 94ca993..1993a19 100644
--- a/chart2/source/view/inc/GL3DRenderer.hxx
+++ b/chart2/source/view/inc/GL3DRenderer.hxx
@@ -323,6 +323,7 @@ private:
GLint m_ScreenTextVertexID;
GLint m_ScreenTextTexCoordID;
GLint m_ScreenTextTexID;
+ GLint m_ScreenTextColorID;
// CommonProID
GLint m_CommonProID;
diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index 60b9f77..d31e5d1 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -190,6 +190,7 @@ OpenGL3DRenderer::ShaderResources::ShaderResources()
, m_ScreenTextVertexID(0)
, m_ScreenTextTexCoordID(0)
, m_ScreenTextTexID(0)
+ , m_ScreenTextColorID(0)
, m_CommonProID(0)
, m_2DVertexID(0)
, m_2DColorID(0)
@@ -305,6 +306,7 @@ void OpenGL3DRenderer::ShaderResources::LoadShaders()
m_ScreenTextVertexID = glGetAttribLocation(m_ScreenTextProID, "vPosition");
m_ScreenTextTexCoordID = glGetAttribLocation(m_ScreenTextProID, "texCoord");
m_ScreenTextTexID = glGetUniformLocation(m_ScreenTextProID, "TextTex");
+ m_ScreenTextColorID = glGetUniformLocation(m_ScreenTextProID, "textColor");
m_CommonProID = OpenGLHelper::LoadShaders("commonVertexShader", "commonFragmentShader");
m_MatrixID = glGetUniformLocation(m_CommonProID, "MVP");
@@ -1877,6 +1879,8 @@ void OpenGL3DRenderer::ReleaseScreenTextTexture()
void OpenGL3DRenderer::RenderScreenTextShape()
{
glUseProgram(maResources.m_ScreenTextProID);
+ glm::vec4 textColor = glm::vec4(0.0, 0.0, 1.0, 1.0);
+ glUniform4fv(maResources.m_ScreenTextColorID, 1, &textColor[0]);
CHECK_GL_ERROR();
for (size_t i = 0; i < m_ScreenTextInfoList.size(); i++)
{
commit b80cd0c555a203eae63d97fdd8d55a6f5364f875
Author: weigao <weigao at multicorewareinc.com>
Date: Sat Aug 9 20:18:07 2014 +0800
add scroll screen text
Change-Id: I619af23f2ea8df2878e2161e99626b09b947a31b
diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx
index 8af7001..9893423 100644
--- a/chart2/source/view/charttypes/GL3DBarChart.cxx
+++ b/chart2/source/view/charttypes/GL3DBarChart.cxx
@@ -24,13 +24,16 @@
#include <windows.h>
#endif
-#define BENCH_MARK_MODE false
-#define CLICK_EVENT_ID 1
+#define BENCH_MARK_MODE true
+#define CALC_POS_EVENT_ID 1
#define SHAPE_START_ID 10
#define DATA_UPDATE_TIME 15
#define FPS_TIME 500
#define DATAUPDATE_FPS_TIME 500
#define HISTORY_NUM 5
+#define SHOW_VALUE_COUNT 15
+#define SHOW_SCROLL_TEXT_DISTANCE 1000
+
using namespace com::sun::star;
@@ -313,7 +316,7 @@ void RenderBenchMarkThread::MoveToCorner()
void RenderBenchMarkThread::ProcessScroll()
{
//will add other process later
- mpChart->maRenderEvent = EVENT_NONE;
+ mpChart->maRenderEvent = EVENT_SHOW_SCROLL;
}
void RenderBenchMarkThread::ProcessClickFlyBack()
@@ -717,7 +720,7 @@ void GL3DBarChart::moveToDefault()
if(BENCH_MARK_MODE)
{
// add correct handling here!!
- if (maRenderEvent != EVENT_NONE)
+ if ((maRenderEvent != EVENT_NONE) && (maRenderEvent != EVENT_SHOW_SCROLL))
return;
{
@@ -758,7 +761,7 @@ void GL3DBarChart::clickedAt(const Point& rPos, sal_uInt16 nButtons)
if (BENCH_MARK_MODE)
{
// add correct handling here !!
- if (maRenderEvent != EVENT_NONE)
+ if ((maRenderEvent != EVENT_NONE) && (maRenderEvent != EVENT_SHOW_SCROLL))
return;
{
@@ -792,7 +795,7 @@ void GL3DBarChart::clickedAt(const Point& rPos, sal_uInt16 nButtons)
rBarInfo.maPos.y + BAR_SIZE_Y / 2.0f,
rBarInfo.maPos.z);
maShapes.push_back(new opengl3D::ScreenText(mpRenderer.get(), *mpTextCache,
- OUString("Value: ") + OUString::number(rBarInfo.mnVal), CLICK_EVENT_ID));
+ OUString("Value: ") + OUString::number(rBarInfo.mnVal), CALC_POS_EVENT_ID));
opengl3D::ScreenText* pScreenText = static_cast<opengl3D::ScreenText*>(&maShapes.back());
pScreenText->setPosition(glm::vec2(-0.9f, 0.9f), glm::vec2(-0.6f, 0.8f), textPos);
pScreenText->render();
@@ -829,7 +832,7 @@ void GL3DBarChart::mouseDragMove(const Point& rStartPos, const Point& rEndPos, s
{
long direction = rEndPos.X() - rStartPos.X();
osl::MutexGuard aGuard(maMutex);
- if (maRenderEvent == EVENT_NONE)
+ if ((maRenderEvent == EVENT_NONE) || (maRenderEvent == EVENT_SHOW_SCROLL))
maRenderEvent = direction > 0 ? EVENT_DRAG_RIGHT : EVENT_DRAG_LEFT;
if(direction < 0)
{
@@ -904,11 +907,17 @@ void GL3DBarChart::scroll(long nDelta)
{
{
osl::MutexGuard aGuard(maMutex);
+ if ((maRenderEvent != EVENT_NONE) && (maRenderEvent != EVENT_SHOW_SCROLL))
+ return;
glm::vec3 maDir = glm::normalize(maCameraPosition - maCameraDirection);
maCameraPosition -= (float((nDelta/10)) * maDir);
mpCamera->setPosition(maCameraPosition);
if(BENCH_MARK_MODE)
+ {
+ maVectorNearest.clear();
+ getNearestBars(maVectorNearest);
maRenderEvent = EVENT_SCROLL;
+ }
}
update();
@@ -963,6 +972,7 @@ void GL3DBarChart::updateScreenText()
updateRenderFPS();
updateDataUpdateFPS();
updateClickEvent();
+ updateScroll();
mbScreenTextNewRender = true;
}
@@ -1008,7 +1018,7 @@ void GL3DBarChart::updateClickEvent()
if (idex + 1 == alist.size())
{
barValue = OUString("Value: ") + OUString::number(*it);
- maScreenTextShapes.push_back(new opengl3D::ScreenText(mpRenderer.get(), *mpTextCache, barValue, CLICK_EVENT_ID));
+ maScreenTextShapes.push_back(new opengl3D::ScreenText(mpRenderer.get(), *mpTextCache, barValue, CALC_POS_EVENT_ID));
opengl3D::TextCacheItem tmpTextCache = mpTextCache->getText(barValue);
float rectWidth = (float)tmpTextCache.maSize.Width() / (float)tmpTextCache.maSize.Height() * 0.03;
std::map<sal_uInt32, const BarInformation>::const_iterator itr = maBarMap.find(mSelectBarId);
@@ -1029,6 +1039,139 @@ void GL3DBarChart::updateClickEvent()
}
}
+float GL3DBarChart::calcScrollDistance(glm::mat4 &mvp, glm::vec3 pos)
+{
+ glm::vec4 screenPos = mvp * glm::vec4(pos, 1.0);
+ glm::vec3 actualPos = glm::vec3(screenPos.x / screenPos.w, screenPos.y / screenPos.w, 0.0);
+ return glm::length(actualPos);
+}
+
+void GL3DBarChart::calcDistance(std::vector<sal_uInt32> & vectorNearest)
+{
+ int i =0;
+ glm::mat4 projection = mpRenderer->GetProjectionMatrix();
+ glm::mat4 view = mpRenderer->GetViewMatrix();
+ glm::mat4 scale = mpRenderer->GetGlobalScaleMatrix();
+ glm::mat4 mvp = projection * view * scale;
+ std::map<sal_uInt32, const BarInformation>::iterator it;
+ for(it= maBarMap.begin(); it!= maBarMap.end(); ++it)
+ {
+ sal_uInt32 nId = it->first;
+ if(i < SHOW_VALUE_COUNT)
+ {
+ vectorNearest.push_back(nId);
+ i++;
+ }
+ glm::vec3 distancePosition = it->second.maPos;
+ maDistanceMap[nId] = calcScrollDistance(mvp, glm::vec3(it->second.maPos.x + BAR_SIZE_X / 2.0f,
+ it->second.maPos.y + BAR_SIZE_Y / 2.0f,
+ it->second.maPos.z));
+ }
+}
+
+void GL3DBarChart::initDistanceHeap(std::vector<sal_uInt32> &vectorNearest)
+{
+ for(int i= (vectorNearest.size()-2)/2; i>= 0; i--)
+ {
+ keepHeap(vectorNearest, i);
+ }
+}
+
+void GL3DBarChart::keepHeap(std::vector<sal_uInt32> &vectorNearest, int index)
+{
+ size_t parentindex = index;
+ while(parentindex < vectorNearest.size())
+ {
+ size_t leftindex = parentindex * 2 + 1;
+ size_t rightindex = leftindex +1;
+ if(leftindex >= vectorNearest.size())
+ break;
+ size_t farthestindex = leftindex;
+ float farthest = maDistanceMap[vectorNearest[leftindex]];
+ if(rightindex < vectorNearest.size())
+ {
+ float right = maDistanceMap[vectorNearest[rightindex]];
+ if(right > farthest)
+ {
+ farthest = right;
+ farthestindex = rightindex;
+ }
+ }
+ float parent = maDistanceMap[vectorNearest[parentindex]];
+ if(parent >= farthest)
+ break;
+ else
+ {
+ swapVector(parentindex , farthestindex, vectorNearest);
+ parentindex = farthestindex;
+ }
+ }
+
+}
+
+void GL3DBarChart::swapVector(int i, int j, std::vector<sal_uInt32> &vectorNearest)
+{
+ sal_uInt32 tmp = vectorNearest[i];
+ vectorNearest[i] = vectorNearest[j];
+ vectorNearest[j] = tmp;
+}
+
+void GL3DBarChart::getNearestBars(std::vector<sal_uInt32> &vectorNearest)
+{
+ calcDistance(vectorNearest);
+ initDistanceHeap(vectorNearest);
+ std::map<sal_uInt32, float>::iterator it;
+ int i = 0;
+ for(it= maDistanceMap.begin(); it!= maDistanceMap.end(); ++it)
+ {
+ i++;
+ if(i <= SHOW_VALUE_COUNT)
+ continue;
+ float distance = it->second;
+ float Heaphead = maDistanceMap[vectorNearest[0]];
+ if(distance < Heaphead)
+ {
+ vectorNearest[0] = it->first;
+ keepHeap(vectorNearest, 0);
+ }
+ }
+}
+
+void GL3DBarChart::updateScroll()
+{
+ if ((maRenderEvent == EVENT_SCROLL) || (maRenderEvent == EVENT_SHOW_SCROLL))
+ {
+ float minDistance = 0.0f;
+ std::vector<BarInformation> barInfoList;
+ for(size_t i= 0;i < maVectorNearest.size(); i++)
+ {
+ //get bar height position
+ std::map<sal_uInt32, const BarInformation>::const_iterator itr = maBarMap.find(maVectorNearest[i]);
+ const BarInformation& rBarInfo = itr->second;
+ barInfoList.push_back(rBarInfo);
+ glm::vec3 pos = rBarInfo.maPos;
+ minDistance = (minDistance == 0.0f) ? glm::length(pos - maCameraPosition) :
+ std::min(glm::length(pos - maCameraPosition), minDistance);
+ }
+ if (minDistance <= SHOW_SCROLL_TEXT_DISTANCE)
+ {
+ //update scroll value
+ for(size_t i = 0; i < barInfoList.size(); i++)
+ {
+ OUString barValue = OUString("Value: ") + OUString::number(barInfoList[i].mnVal);
+ maScreenTextShapes.push_back(new opengl3D::ScreenText(mpRenderer.get(), *mpTextCache, barValue, CALC_POS_EVENT_ID));
+ opengl3D::TextCacheItem tmpTextCache = mpTextCache->getText(barValue);
+ float rectWidth = (float)tmpTextCache.maSize.Width() / (float)tmpTextCache.maSize.Height() * 0.03;
+ glm::vec3 textPos = glm::vec3(barInfoList[i].maPos.x + BAR_SIZE_X / 2.0f,
+ barInfoList[i].maPos.y + BAR_SIZE_Y / 2.0f,
+ barInfoList[i].maPos.z);
+ opengl3D::ScreenText* pScreenText = static_cast<opengl3D::ScreenText*>(&maScreenTextShapes.back());
+ pScreenText->setPosition(glm::vec2(-rectWidth / 2, 0.03f), glm::vec2(rectWidth / 2, -0.03f), textPos);
+ }
+ }
+ }
+}
+
IMPL_LINK_NOARG(GL3DBarChart, updateTimer)
{
maTimer.Stop();
diff --git a/chart2/source/view/inc/GL3DBarChart.hxx b/chart2/source/view/inc/GL3DBarChart.hxx
index 552a226..d8b8843 100644
--- a/chart2/source/view/inc/GL3DBarChart.hxx
+++ b/chart2/source/view/inc/GL3DBarChart.hxx
@@ -94,6 +94,13 @@ private:
void addScreenTextShape(OUString &nStr, glm::vec2 rLeftTop, float nTextHeight, glm::vec3 rPos = glm::vec3(0.0f, 0.0f, 0.0f), sal_uInt32 nEvent = 0);
void recordBarHistory(sal_uInt32 &nBarID, float &nVal);
void updateClickEvent();
+ void calcDistance(std::vector<sal_uInt32> &vectorNearest);
+ float calcScrollDistance(glm::mat4 &mvp, glm::vec3 pos);
+ void initDistanceHeap(std::vector<sal_uInt32> &vectorNearest);
+ void keepHeap(std::vector<sal_uInt32> &vectorNearest, int index);
+ void swapVector(int i, int j, std::vector<sal_uInt32> &vectorNearest);
+ void getNearestBars(std::vector<sal_uInt32> &vectorNearest);
+ void updateScroll();
css::uno::Reference<css::chart2::XChartType> mxChartType;
boost::ptr_vector<opengl3D::Renderable3DObject> maShapes;
@@ -159,6 +166,8 @@ private:
TimeValue maDataUpdateStartTime;
TimeValue maDataUpdateEndTime;
std::map<sal_uInt32, std::list<float>> maBarHistory;
+ std::vector<sal_uInt32> maVectorNearest;
+ std::map<sal_uInt32, float> maDistanceMap;
};
}
diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx
index 7c1c989..94ca993 100644
--- a/chart2/source/view/inc/GL3DRenderer.hxx
+++ b/chart2/source/view/inc/GL3DRenderer.hxx
@@ -216,6 +216,9 @@ public:
void SetScrollSpeed(float scrollSpeed);
void SetScrollDistance(float scrollDistance);
void SetSceneEdge(float minCoordX, float maxCoordX);
+ glm::mat4 GetProjectionMatrix();
+ glm::mat4 GetViewMatrix();
+ glm::mat4 GetGlobalScaleMatrix();
private:
void MoveModelf( const PosVecf3& trans, const PosVecf3& angle, const PosVecf3& scale);
diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index 02b03f8..60b9f77 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -1887,7 +1887,7 @@ void OpenGL3DRenderer::RenderScreenTextShape()
if (textInfo.uniqueId)
{
glm::vec3 worldPos = glm::vec3(m_ScrollMoveMatrix * m_GlobalScaleMatrix * glm::vec4(textInfo.pos, 1));
- if (worldPos.x < m_fMinCoordX)
+ if ((worldPos.x < m_fMinCoordX) || (worldPos.x > m_fMaxCoordX))
continue;
glm::vec4 pos = m_3DProjection * m_3DView * glm::vec4(worldPos, 1);
xTrans = pos.x / pos.w;
@@ -2372,6 +2372,21 @@ void OpenGL3DRenderer::CalcScrollMoveMatrix(bool bNewScene)
m_bUndrawFlag = m_fCurDistance >= m_fScrollDistance ? true : false;
}
+glm::mat4 OpenGL3DRenderer::GetProjectionMatrix()
+{
+ return m_3DProjection;
+}
+
+glm::mat4 OpenGL3DRenderer::GetViewMatrix()
+{
+ return m_3DView;
+}
+
+glm::mat4 OpenGL3DRenderer::GetGlobalScaleMatrix()
+{
+ return m_GlobalScaleMatrix;
+}
+
void OpenGL3DRenderer::RenderBatchBars(bool bNewScene)
{
if(bNewScene)
commit 916b1403de2f1c8062a8378d98d45ab195764700
Author: weigao <weigao at multicorewareinc.com>
Date: Sat Aug 9 18:19:33 2014 +0800
add click and history screen text
Change-Id: I7aba9fcc0a5ed96de722f9334476da6763221ab0
diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx
index cd95848..8af7001 100644
--- a/chart2/source/view/charttypes/GL3DBarChart.cxx
+++ b/chart2/source/view/charttypes/GL3DBarChart.cxx
@@ -28,6 +28,9 @@
#define CLICK_EVENT_ID 1
#define SHAPE_START_ID 10
#define DATA_UPDATE_TIME 15
+#define FPS_TIME 500
+#define DATAUPDATE_FPS_TIME 500
+#define HISTORY_NUM 5
using namespace com::sun::star;
@@ -541,7 +544,7 @@ void GL3DBarChart::create3DShapes(const boost::ptr_vector<VDataSeries>& rDataSer
maBarMap.insert(std::pair<sal_uInt32, BarInformation>(nId,
BarInformation(glm::vec3(nXPos, nYPos, float(nVal/nMaxVal)),
nVal, nIndex, nSeriesIndex)));
-
+ recordBarHistory(nId, nVal);
maShapes.push_back(new opengl3D::Bar(mpRenderer.get(), aBarPosition, nColor, nId));
nId += ID_STEP;
}
@@ -929,7 +932,7 @@ void GL3DBarChart::addScreenTextShape(OUString &nStr, glm::vec2 rLeftTop, float
void GL3DBarChart::updateRenderFPS()
{
int aDeltaMs = calcTimeInterval(maFPSRenderStartTime, maFPSRenderEndTime);
- if(aDeltaMs >= 500)
+ if(aDeltaMs >= FPS_TIME)
{
osl_getSystemTime(&maFPSRenderEndTime);
aDeltaMs = calcTimeInterval(maFPSRenderStartTime, maFPSRenderEndTime);
@@ -939,7 +942,7 @@ void GL3DBarChart::updateRenderFPS()
osl_getSystemTime(&maFPSRenderStartTime);
}
osl_getSystemTime(&maFPSRenderEndTime);
- addScreenTextShape(maFPS, glm::vec2(-0.99f, 0.99f), 0.1f, glm::vec3(0.0, 0.0, 0.0));
+ addScreenTextShape(maFPS, glm::vec2(-0.99f, 0.99f), 0.1f);
}
int GL3DBarChart::calcTimeInterval(TimeValue &startTime, TimeValue &endTime)
@@ -959,13 +962,14 @@ void GL3DBarChart::updateScreenText()
mpRenderer->ReleaseScreenTextShapes();
updateRenderFPS();
updateDataUpdateFPS();
+ updateClickEvent();
mbScreenTextNewRender = true;
}
void GL3DBarChart::updateDataUpdateFPS()
{
int aDeltaMs = calcTimeInterval(maDataUpdateStartTime, maDataUpdateEndTime);
- if(aDeltaMs >= 500)
+ if(aDeltaMs >= DATAUPDATE_FPS_TIME)
{
int iFPS = miDataUpdateCounter * 1000 / aDeltaMs;
if (iFPS)
@@ -981,7 +985,48 @@ void GL3DBarChart::updateDataUpdateFPS()
osl_getSystemTime(&maDataUpdateStartTime);
}
osl_getSystemTime(&maDataUpdateEndTime);
- addScreenTextShape(maDataUpdateFPS, glm::vec2(-0.69f, 0.99f), 0.1f, glm::vec3(0.0, 0.0, 0.0));
+ addScreenTextShape(maDataUpdateFPS, glm::vec2(-0.69f, 0.99f), 0.1f);
+}
+
+void GL3DBarChart::recordBarHistory(sal_uInt32 &nBarID, float &nVal)
+{
+ std::list<float> &alist = maBarHistory[nBarID];
+ if(alist.size() == HISTORY_NUM)
+ alist.pop_front();
+ alist.push_back(nVal);
+}
+
+void GL3DBarChart::updateClickEvent()
+{
+ if (maRenderEvent == EVENT_CLICK)
+ {
+ std::list<float> &alist = maBarHistory[mSelectBarId];
+ sal_uInt32 idex = 0;
+ for (std::list<float>::iterator it = alist.begin();it != alist.end();it++)
+ {
+ OUString barValue;
+ if (idex + 1 == alist.size())
+ {
+ barValue = OUString("Value: ") + OUString::number(*it);
+ maScreenTextShapes.push_back(new opengl3D::ScreenText(mpRenderer.get(), *mpTextCache, barValue, CLICK_EVENT_ID));
+ opengl3D::TextCacheItem tmpTextCache = mpTextCache->getText(barValue);
+ float rectWidth = (float)tmpTextCache.maSize.Width() / (float)tmpTextCache.maSize.Height() * 0.03;
+ std::map<sal_uInt32, const BarInformation>::const_iterator itr = maBarMap.find(mSelectBarId);
+ const BarInformation& rBarInfo = itr->second;
+ glm::vec3 textPos = glm::vec3(rBarInfo.maPos.x + BAR_SIZE_X / 2.0f,
+ rBarInfo.maPos.y + BAR_SIZE_Y / 2.0f,
+ rBarInfo.maPos.z);
+ opengl3D::ScreenText* pScreenText = static_cast<opengl3D::ScreenText*>(&maScreenTextShapes.back());
+ pScreenText->setPosition(glm::vec2(-rectWidth / 2, 0.03f), glm::vec2(rectWidth / 2, -0.03f), textPos);
+ }
+ else
+ {
+ barValue = OUString("History_") + OUString::number(idex) + OUString(": ") + OUString::number(*it);
+ addScreenTextShape(barValue, glm::vec2(0.65f, 0.99f - (idex * 0.1f)), 0.1f);
+ }
+ idex++;
+ }
+ }
}
IMPL_LINK_NOARG(GL3DBarChart, updateTimer)
@@ -992,7 +1037,6 @@ IMPL_LINK_NOARG(GL3DBarChart, updateTimer)
maTimer.Start();
return 0;
}
-
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/view/inc/GL3DBarChart.hxx b/chart2/source/view/inc/GL3DBarChart.hxx
index e0cdddd..552a226 100644
--- a/chart2/source/view/inc/GL3DBarChart.hxx
+++ b/chart2/source/view/inc/GL3DBarChart.hxx
@@ -91,7 +91,9 @@ private:
void updateDataUpdateFPS();
DECL_LINK(updateTimer, void*);
int calcTimeInterval(TimeValue &startTime, TimeValue &endTime);
- void addScreenTextShape(OUString &nStr, glm::vec2 rLeftTop, float nTextHeight, glm::vec3 rPos, sal_uInt32 nEvent = 0);
+ void addScreenTextShape(OUString &nStr, glm::vec2 rLeftTop, float nTextHeight, glm::vec3 rPos = glm::vec3(0.0f, 0.0f, 0.0f), sal_uInt32 nEvent = 0);
+ void recordBarHistory(sal_uInt32 &nBarID, float &nVal);
+ void updateClickEvent();
css::uno::Reference<css::chart2::XChartType> mxChartType;
boost::ptr_vector<opengl3D::Renderable3DObject> maShapes;
@@ -156,6 +158,7 @@ private:
TimeValue maFPSRenderEndTime;
TimeValue maDataUpdateStartTime;
TimeValue maDataUpdateEndTime;
+ std::map<sal_uInt32, std::list<float>> maBarHistory;
};
}
diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index 866a5cf..02b03f8 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -1880,7 +1880,7 @@ void OpenGL3DRenderer::RenderScreenTextShape()
CHECK_GL_ERROR();
for (size_t i = 0; i < m_ScreenTextInfoList.size(); i++)
{
- TextInfo &textInfo = m_ScreenTextInfoList[i];
+ TextInfo textInfo = m_ScreenTextInfoList[i];
//calc the postition and check whether it can be displayed
float xTrans = 0.0f;
float yTrans = 0.0f;
commit 7a91a493b24dd4a90dc375c71d23b5035169502c
Author: weigao <weigao at multicorewareinc.com>
Date: Sat Aug 9 14:30:36 2014 +0800
add data update text rendering
Change-Id: I022bb00b3704fd3e6bc00a625016716cc7092a99
diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx
index 70417c2..cd95848 100644
--- a/chart2/source/view/charttypes/GL3DBarChart.cxx
+++ b/chart2/source/view/charttypes/GL3DBarChart.cxx
@@ -404,9 +404,11 @@ GL3DBarChart::GL3DBarChart(
mSelectBarId(0),
miScrollRate(0),
miFrameCount(0),
+ miDataUpdateCounter(0),
mbScrollFlg(false),
mbScreenTextNewRender(false),
- maFPS(OUString("Render FPS: 0"))
+ maFPS(OUString("Render FPS: 0")),
+ maDataUpdateFPS(OUString("Data Update FPS: 0"))
{
if (BENCH_MARK_MODE)
{
@@ -423,8 +425,10 @@ GL3DBarChart::GL3DBarChart(
maTimer.SetTimeout(DATA_UPDATE_TIME);
maTimer.SetTimeoutHdl(LINK(this, GL3DBarChart, updateTimer));
maTimer.Start();
- osl_getSystemTime(&mafpsRenderStartTime);
- osl_getSystemTime(&mafpsRenderEndTime);
+ osl_getSystemTime(&maFPSRenderStartTime);
+ osl_getSystemTime(&maFPSRenderEndTime);
+ osl_getSystemTime(&maDataUpdateStartTime);
+ osl_getSystemTime(&maDataUpdateEndTime);
}
Size aSize = mrWindow.GetSizePixel();
mpRenderer->SetSize(aSize);
@@ -665,6 +669,7 @@ void GL3DBarChart::create3DShapes(const boost::ptr_vector<VDataSeries>& rDataSer
mrWindow.getContext().resetCurrent();
mpRenderThread->launch();
}
+ miDataUpdateCounter++;
mbNeedsNewRender = true;
}
@@ -912,9 +917,9 @@ void GL3DBarChart::contextDestroyed()
mbValidContext = false;
}
-void GL3DBarChart::addScreenTextShape(OUString &nStr, glm::vec2 rLeftTop, float nTextHeight, glm::vec3 rPos)
+void GL3DBarChart::addScreenTextShape(OUString &nStr, glm::vec2 rLeftTop, float nTextHeight, glm::vec3 rPos, sal_uInt32 nEvent)
{
- maScreenTextShapes.push_back(new opengl3D::ScreenText(mpRenderer.get(), *mpTextCache, nStr, 0));
+ maScreenTextShapes.push_back(new opengl3D::ScreenText(mpRenderer.get(), *mpTextCache, nStr, nEvent));
opengl3D::TextCacheItem tmpTextCache = mpTextCache->getText(nStr);
float rectWidth = (float)tmpTextCache.maSize.Width() / (float)tmpTextCache.maSize.Height() * 0.05;
opengl3D::ScreenText* pScreenText = static_cast<opengl3D::ScreenText*>(&maScreenTextShapes.back());
@@ -923,17 +928,17 @@ void GL3DBarChart::addScreenTextShape(OUString &nStr, glm::vec2 rLeftTop, float
void GL3DBarChart::updateRenderFPS()
{
- int aDeltaMs = calcTimeInterval(mafpsRenderStartTime, mafpsRenderEndTime);
+ int aDeltaMs = calcTimeInterval(maFPSRenderStartTime, maFPSRenderEndTime);
if(aDeltaMs >= 500)
{
- osl_getSystemTime(&mafpsRenderEndTime);
- aDeltaMs = calcTimeInterval(mafpsRenderStartTime, mafpsRenderEndTime);
+ osl_getSystemTime(&maFPSRenderEndTime);
+ aDeltaMs = calcTimeInterval(maFPSRenderStartTime, maFPSRenderEndTime);
int iFPS = miFrameCount * 1000 / aDeltaMs;
maFPS = OUString("Render FPS: ") + OUString::number(iFPS);
miFrameCount = 0;
- osl_getSystemTime(&mafpsRenderStartTime);
+ osl_getSystemTime(&maFPSRenderStartTime);
}
- osl_getSystemTime(&mafpsRenderEndTime);
+ osl_getSystemTime(&maFPSRenderEndTime);
addScreenTextShape(maFPS, glm::vec2(-0.99f, 0.99f), 0.1f, glm::vec3(0.0, 0.0, 0.0));
}
@@ -953,9 +958,32 @@ void GL3DBarChart::updateScreenText()
maScreenTextShapes.clear();
mpRenderer->ReleaseScreenTextShapes();
updateRenderFPS();
+ updateDataUpdateFPS();
mbScreenTextNewRender = true;
}
+void GL3DBarChart::updateDataUpdateFPS()
+{
+ int aDeltaMs = calcTimeInterval(maDataUpdateStartTime, maDataUpdateEndTime);
+ if(aDeltaMs >= 500)
+ {
+ int iFPS = miDataUpdateCounter * 1000 / aDeltaMs;
+ if (iFPS)
+ {
+ maDataUpdateFPS = OUString("Data Update FPS: ") + OUString::number(iFPS);
+ }
+ else
+ {
+ float fFPS = (float)miDataUpdateCounter * 1000 / (float)aDeltaMs;
+ maDataUpdateFPS = OUString("Data Update FPS: ") + OUString::number(fFPS);
+ }
+ miDataUpdateCounter = 0;
+ osl_getSystemTime(&maDataUpdateStartTime);
+ }
+ osl_getSystemTime(&maDataUpdateEndTime);
+ addScreenTextShape(maDataUpdateFPS, glm::vec2(-0.69f, 0.99f), 0.1f, glm::vec3(0.0, 0.0, 0.0));
+}
+
IMPL_LINK_NOARG(GL3DBarChart, updateTimer)
{
maTimer.Stop();
diff --git a/chart2/source/view/inc/GL3DBarChart.hxx b/chart2/source/view/inc/GL3DBarChart.hxx
index 88de9e0..e0cdddd 100644
--- a/chart2/source/view/inc/GL3DBarChart.hxx
+++ b/chart2/source/view/inc/GL3DBarChart.hxx
@@ -88,9 +88,10 @@ private:
void updateTimer();
void updateScreenText();
void updateRenderFPS();
+ void updateDataUpdateFPS();
DECL_LINK(updateTimer, void*);
int calcTimeInterval(TimeValue &startTime, TimeValue &endTime);
- void addScreenTextShape(OUString &nStr, glm::vec2 rLeftTop, float nTextHeight, glm::vec3 rPos);
+ void addScreenTextShape(OUString &nStr, glm::vec2 rLeftTop, float nTextHeight, glm::vec3 rPos, sal_uInt32 nEvent = 0);
css::uno::Reference<css::chart2::XChartType> mxChartType;
boost::ptr_vector<opengl3D::Renderable3DObject> maShapes;
@@ -148,9 +149,13 @@ private:
bool mbScreenTextNewRender;
boost::ptr_vector<opengl3D::Renderable3DObject> maScreenTextShapes;
OUString maFPS;
+ OUString maDataUpdateFPS;
sal_uInt32 miFrameCount;
- TimeValue mafpsRenderStartTime;
- TimeValue mafpsRenderEndTime;
+ sal_uInt32 miDataUpdateCounter;
+ TimeValue maFPSRenderStartTime;
+ TimeValue maFPSRenderEndTime;
+ TimeValue maDataUpdateStartTime;
+ TimeValue maDataUpdateEndTime;
};
}
commit 76fa54819b0445c9e6b85db2729540a07b4601ce
Author: weigao <weigao at multicorewareinc.com>
Date: Sat Aug 9 13:38:11 2014 +0800
add function of adding screen text shape
Change-Id: I0f40081a0855bc8e43a8d4761222bd351b5d6f0c
diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx
index 5328683..70417c2 100644
--- a/chart2/source/view/charttypes/GL3DBarChart.cxx
+++ b/chart2/source/view/charttypes/GL3DBarChart.cxx
@@ -912,6 +912,15 @@ void GL3DBarChart::contextDestroyed()
mbValidContext = false;
}
+void GL3DBarChart::addScreenTextShape(OUString &nStr, glm::vec2 rLeftTop, float nTextHeight, glm::vec3 rPos)
+{
+ maScreenTextShapes.push_back(new opengl3D::ScreenText(mpRenderer.get(), *mpTextCache, nStr, 0));
+ opengl3D::TextCacheItem tmpTextCache = mpTextCache->getText(nStr);
+ float rectWidth = (float)tmpTextCache.maSize.Width() / (float)tmpTextCache.maSize.Height() * 0.05;
+ opengl3D::ScreenText* pScreenText = static_cast<opengl3D::ScreenText*>(&maScreenTextShapes.back());
+ pScreenText->setPosition(rLeftTop, glm::vec2(rLeftTop.x + rectWidth, rLeftTop.y - nTextHeight), rPos);
+}
+
void GL3DBarChart::updateRenderFPS()
{
int aDeltaMs = calcTimeInterval(mafpsRenderStartTime, mafpsRenderEndTime);
@@ -925,11 +934,7 @@ void GL3DBarChart::updateRenderFPS()
osl_getSystemTime(&mafpsRenderStartTime);
}
osl_getSystemTime(&mafpsRenderEndTime);
- maScreenTextShapes.push_back(new opengl3D::ScreenText(mpRenderer.get(), *mpTextCache, maFPS, 0));
- opengl3D::TextCacheItem tmpTextCache = mpTextCache->getText(maFPS);
- float rectWidth = (float)tmpTextCache.maSize.Width() / (float)tmpTextCache.maSize.Height() * 0.05;
- opengl3D::ScreenText* pScreenText = static_cast<opengl3D::ScreenText*>(&maScreenTextShapes.back());
- pScreenText->setPosition(glm::vec2(-0.99f, 0.99f), glm::vec2(-0.99f + rectWidth, 0.89f));
+ addScreenTextShape(maFPS, glm::vec2(-0.99f, 0.99f), 0.1f, glm::vec3(0.0, 0.0, 0.0));
}
int GL3DBarChart::calcTimeInterval(TimeValue &startTime, TimeValue &endTime)
diff --git a/chart2/source/view/inc/GL3DBarChart.hxx b/chart2/source/view/inc/GL3DBarChart.hxx
index 2771260..88de9e0 100644
--- a/chart2/source/view/inc/GL3DBarChart.hxx
+++ b/chart2/source/view/inc/GL3DBarChart.hxx
@@ -90,6 +90,7 @@ private:
void updateRenderFPS();
DECL_LINK(updateTimer, void*);
int calcTimeInterval(TimeValue &startTime, TimeValue &endTime);
+ void addScreenTextShape(OUString &nStr, glm::vec2 rLeftTop, float nTextHeight, glm::vec3 rPos);
css::uno::Reference<css::chart2::XChartType> mxChartType;
boost::ptr_vector<opengl3D::Renderable3DObject> maShapes;
commit 212dfdbb92344cac86f8a511697b148ddd00678d
Author: weigao <weigao at multicorewareinc.com>
Date: Sat Aug 9 13:08:16 2014 +0800
add render fps rendering
Change-Id: Ic0c8c9a05079a4d4b715f90eccffb7c4ae8260c9
diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx
index b325ac8..5328683 100644
--- a/chart2/source/view/charttypes/GL3DBarChart.cxx
+++ b/chart2/source/view/charttypes/GL3DBarChart.cxx
@@ -27,6 +27,7 @@
#define BENCH_MARK_MODE false
#define CLICK_EVENT_ID 1
#define SHAPE_START_ID 10
+#define DATA_UPDATE_TIME 15
using namespace com::sun::star;
@@ -185,12 +186,7 @@ public:
, mbNeedFlyBack(false)
, mnStep(0)
, mnStepsTotal(0)
- , miFrameCount(0)
{
- osl_getSystemTime(&mafpsRenderStartTime);
- osl_getSystemTime(&mafpsRenderEndTime);
- osl_getSystemTime(&maScreenTextUpdateStartTime);
- osl_getSystemTime(&maScreenTextUpdateEndTime);
osl_getSystemTime(&maClickFlyBackStartTime);
osl_getSystemTime(&maClickFlyBackEndTime);
}
@@ -204,8 +200,6 @@ private:
void MoveToCorner();
void ProcessScroll();
void UpdateScreenText();
- void UpdateFPS();
- int CalcTimeInterval(TimeValue &startTime, TimeValue &endTime);
void ProcessClickFlyBack();
private:
glm::vec3 maStartPos;
@@ -216,13 +210,8 @@ private:
glm::vec3 maStepDirection;
size_t mnStep;
size_t mnStepsTotal;
- TimeValue mafpsRenderStartTime;
- TimeValue mafpsRenderEndTime;
- TimeValue maScreenTextUpdateStartTime;
- TimeValue maScreenTextUpdateEndTime;
TimeValue maClickFlyBackStartTime;
TimeValue maClickFlyBackEndTime;
- int miFrameCount;
OUString maFPS;
};
@@ -329,7 +318,7 @@ void RenderBenchMarkThread::ProcessClickFlyBack()
if (!mbNeedFlyBack)
return;
osl_getSystemTime(&maClickFlyBackEndTime);
- int aDeltaMs = CalcTimeInterval(maClickFlyBackStartTime, maClickFlyBackEndTime);
+ int aDeltaMs = mpChart->calcTimeInterval(maClickFlyBackStartTime, maClickFlyBackEndTime);
if(aDeltaMs >= 10000)
{
mpChart->maRenderEvent = EVENT_MOVE_TO_DEFAULT;
@@ -357,42 +346,18 @@ void RenderBenchMarkThread::ProcessMouseEvent()
}
}
-int RenderBenchMarkThread::CalcTimeInterval(TimeValue &startTime, TimeValue &endTime)
-{
- TimeValue aTime;
- aTime.Seconds = endTime.Seconds - startTime.Seconds - 1;
- aTime.Nanosec = 1000000000 + endTime.Nanosec - startTime.Nanosec;
- aTime.Seconds += aTime.Nanosec / 1000000000;
- aTime.Nanosec %= 1000000000;
- return aTime.Seconds * 1000+aTime.Nanosec / 1000000;
-}
-
-void RenderBenchMarkThread::UpdateFPS()
-{
- int aDeltaMs = CalcTimeInterval(mafpsRenderStartTime, mafpsRenderEndTime);
- if(aDeltaMs >= 500)
- {
- osl_getSystemTime(&mafpsRenderEndTime);
- aDeltaMs = CalcTimeInterval(mafpsRenderStartTime, mafpsRenderEndTime);
- int iFPS = miFrameCount * 1000 / aDeltaMs;
- maFPS = OUString("Render FPS: ") + OUString::number(iFPS);
- miFrameCount = 0;
- osl_getSystemTime(&mafpsRenderStartTime);
- }
- osl_getSystemTime(&mafpsRenderEndTime);
- //will add the fps render code here later
-}
-
void RenderBenchMarkThread::UpdateScreenText()
{
- int aDeltaMs = CalcTimeInterval(maScreenTextUpdateStartTime, maScreenTextUpdateEndTime);
- if (aDeltaMs >= 20)
+ if (mpChart->mbScreenTextNewRender)
{
- mpChart->mpRenderer->ReleaseScreenTextShapes();
- UpdateFPS();
- osl_getSystemTime(&maScreenTextUpdateStartTime);
+ mpChart->mpRenderer->ReleaseScreenTextTexture();
+ for(boost::ptr_vector<opengl3D::Renderable3DObject>::iterator itr = mpChart->maScreenTextShapes.begin(),
+ itrEnd = mpChart->maScreenTextShapes.end(); itr != itrEnd; ++itr)
+ {
+ itr->render();
+ }
+ mpChart->mbScreenTextNewRender = false;
}
- osl_getSystemTime(&maScreenTextUpdateEndTime);
}
void RenderBenchMarkThread::execute()
@@ -406,6 +371,7 @@ void RenderBenchMarkThread::execute()
UpdateScreenText();
ProcessMouseEvent();
renderFrame();
+ mpChart->miFrameCount++;
}
#ifdef WNT
Sleep(1);
@@ -415,7 +381,6 @@ void RenderBenchMarkThread::execute()
nTV.Nanosec = 1000000;
osl_waitThread(&nTV);
#endif
- miFrameCount++;
}
}
@@ -438,7 +403,10 @@ GL3DBarChart::GL3DBarChart(
maRenderEvent(EVENT_NONE),
mSelectBarId(0),
miScrollRate(0),
- mbScrollFlg(false)
+ miFrameCount(0),
+ mbScrollFlg(false),
+ mbScreenTextNewRender(false),
+ maFPS(OUString("Render FPS: 0"))
{
if (BENCH_MARK_MODE)
{
@@ -452,6 +420,11 @@ GL3DBarChart::GL3DBarChart(
mpRenderer->SetScroll();
}
}
+ maTimer.SetTimeout(DATA_UPDATE_TIME);
+ maTimer.SetTimeoutHdl(LINK(this, GL3DBarChart, updateTimer));
+ maTimer.Start();
+ osl_getSystemTime(&mafpsRenderStartTime);
+ osl_getSystemTime(&mafpsRenderEndTime);
}
Size aSize = mrWindow.GetSizePixel();
mpRenderer->SetSize(aSize);
@@ -939,6 +912,54 @@ void GL3DBarChart::contextDestroyed()
mbValidContext = false;
}
+void GL3DBarChart::updateRenderFPS()
+{
+ int aDeltaMs = calcTimeInterval(mafpsRenderStartTime, mafpsRenderEndTime);
+ if(aDeltaMs >= 500)
+ {
+ osl_getSystemTime(&mafpsRenderEndTime);
+ aDeltaMs = calcTimeInterval(mafpsRenderStartTime, mafpsRenderEndTime);
+ int iFPS = miFrameCount * 1000 / aDeltaMs;
+ maFPS = OUString("Render FPS: ") + OUString::number(iFPS);
+ miFrameCount = 0;
+ osl_getSystemTime(&mafpsRenderStartTime);
+ }
+ osl_getSystemTime(&mafpsRenderEndTime);
+ maScreenTextShapes.push_back(new opengl3D::ScreenText(mpRenderer.get(), *mpTextCache, maFPS, 0));
+ opengl3D::TextCacheItem tmpTextCache = mpTextCache->getText(maFPS);
+ float rectWidth = (float)tmpTextCache.maSize.Width() / (float)tmpTextCache.maSize.Height() * 0.05;
+ opengl3D::ScreenText* pScreenText = static_cast<opengl3D::ScreenText*>(&maScreenTextShapes.back());
+ pScreenText->setPosition(glm::vec2(-0.99f, 0.99f), glm::vec2(-0.99f + rectWidth, 0.89f));
+}
+
+int GL3DBarChart::calcTimeInterval(TimeValue &startTime, TimeValue &endTime)
+{
+ TimeValue aTime;
+ aTime.Seconds = endTime.Seconds - startTime.Seconds - 1;
+ aTime.Nanosec = 1000000000 + endTime.Nanosec - startTime.Nanosec;
+ aTime.Seconds += aTime.Nanosec / 1000000000;
+ aTime.Nanosec %= 1000000000;
+ return aTime.Seconds * 1000+aTime.Nanosec / 1000000;
+}
+
+void GL3DBarChart::updateScreenText()
+{
+ osl::MutexGuard aGuard(maMutex);
+ maScreenTextShapes.clear();
+ mpRenderer->ReleaseScreenTextShapes();
+ updateRenderFPS();
+ mbScreenTextNewRender = true;
+}
+
+IMPL_LINK_NOARG(GL3DBarChart, updateTimer)
+{
+ maTimer.Stop();
+ updateScreenText();
+ maTimer.SetTimeout(DATA_UPDATE_TIME);
+ maTimer.Start();
+ return 0;
+}
+
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/view/inc/GL3DBarChart.hxx b/chart2/source/view/inc/GL3DBarChart.hxx
index 7b1e7b6..2771260 100644
--- a/chart2/source/view/inc/GL3DBarChart.hxx
+++ b/chart2/source/view/inc/GL3DBarChart.hxx
@@ -85,7 +85,11 @@ private:
void moveToCorner();
void moveToDefault();
glm::vec3 getCornerPosition(sal_Int8 nCornerId);
-
+ void updateTimer();
+ void updateScreenText();
+ void updateRenderFPS();
+ DECL_LINK(updateTimer, void*);
+ int calcTimeInterval(TimeValue &startTime, TimeValue &endTime);
css::uno::Reference<css::chart2::XChartType> mxChartType;
boost::ptr_vector<opengl3D::Renderable3DObject> maShapes;
@@ -139,6 +143,13 @@ private:
Point maClickPos;
sal_uInt32 miScrollRate;
bool mbScrollFlg;
+ Timer maTimer;
+ bool mbScreenTextNewRender;
+ boost::ptr_vector<opengl3D::Renderable3DObject> maScreenTextShapes;
+ OUString maFPS;
+ sal_uInt32 miFrameCount;
+ TimeValue mafpsRenderStartTime;
+ TimeValue mafpsRenderEndTime;
};
}
diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx
index 94a5f88..7c1c989 100644
--- a/chart2/source/view/inc/GL3DRenderer.hxx
+++ b/chart2/source/view/inc/GL3DRenderer.hxx
@@ -209,6 +209,7 @@ public:
void ReleaseShapes();
void ReleaseScreenTextShapes();
void ReleaseTextTexture();
+ void ReleaseScreenTextTexture();
void StartClick(sal_uInt32 &selectID);
void EndClick();
void SetScroll();
@@ -462,6 +463,7 @@ private:
float m_fLightPower[MAX_LIGHT_NUM];
//for 3.0 end
std::vector<GLuint> m_Texturelist;
+ std::vector<GLuint> m_ScreenTexturelist;
bool m_bHighLighting;
sal_uInt32 m_uiSelectID;
float m_fScrollSpeed;
diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index 295a8a7..866a5cf 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -1709,6 +1709,7 @@ void OpenGL3DRenderer::CreateScreenTextTexture(
glBindTexture(GL_TEXTURE_2D, 0);
CHECK_GL_ERROR();
m_ScreenTextInfoList.push_back(aTextInfo);
+ m_ScreenTexturelist.push_back(aTextInfo.texture);
}
void OpenGL3DRenderer::CreateTextTextureSingle(const boost::shared_array<sal_uInt8> &bitmapBuf,
@@ -1860,14 +1861,19 @@ void OpenGL3DRenderer::ReleaseTextTexture()
void OpenGL3DRenderer::ReleaseScreenTextShapes()
{
- for (size_t i = 0; i < m_ScreenTextInfoList.size(); i++)
+ m_ScreenTextInfoList.clear();
+}
+
+void OpenGL3DRenderer::ReleaseScreenTextTexture()
+{
+ for (size_t i = 0; i < m_ScreenTexturelist.size(); i++)
{
- TextInfo &textInfo = m_ScreenTextInfoList[i];
- glDeleteTextures(1, &textInfo.texture);
+ glDeleteTextures(1, &m_ScreenTexturelist[i]);
}
- m_ScreenTextInfoList.clear();
+ m_ScreenTexturelist.clear();
}
+
void OpenGL3DRenderer::RenderScreenTextShape()
{
glUseProgram(maResources.m_ScreenTextProID);
commit 05ecb52d2bc95dcaceb47df8f09b5bfbe924f9b7
Author: weigao <weigao at multicorewareinc.com>
Date: Fri Aug 8 18:35:25 2014 +0800
add position control to screen text
Change-Id: I6bf340acb3aa50f2ce534b10d5be32c4615b0688
diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx
index 3a39896..b325ac8 100644
--- a/chart2/source/view/charttypes/GL3DBarChart.cxx
+++ b/chart2/source/view/charttypes/GL3DBarChart.cxx
@@ -25,6 +25,8 @@
#endif
#define BENCH_MARK_MODE false
+#define CLICK_EVENT_ID 1
+#define SHAPE_START_ID 10
using namespace com::sun::star;
@@ -489,7 +491,7 @@ void GL3DBarChart::create3DShapes(const boost::ptr_vector<VDataSeries>& rDataSer
// Each series of data flows from left to right, and multiple series are
// stacked vertically along y axis.
- sal_uInt32 nId = 1;
+ sal_uInt32 nId = SHAPE_START_ID;
float nXEnd = 0.0;
float nYPos = 0.0;
@@ -805,11 +807,13 @@ void GL3DBarChart::clickedAt(const Point& rPos, sal_uInt16 nButtons)
return;
const BarInformation& rBarInfo = itr->second;
-
+ glm::vec3 textPos = glm::vec3(rBarInfo.maPos.x + BAR_SIZE_X / 2.0f,
+ rBarInfo.maPos.y + BAR_SIZE_Y / 2.0f,
+ rBarInfo.maPos.z);
maShapes.push_back(new opengl3D::ScreenText(mpRenderer.get(), *mpTextCache,
- OUString("Value: ") + OUString::number(rBarInfo.mnVal), 0));
+ OUString("Value: ") + OUString::number(rBarInfo.mnVal), CLICK_EVENT_ID));
opengl3D::ScreenText* pScreenText = static_cast<opengl3D::ScreenText*>(&maShapes.back());
- pScreenText->setPosition(glm::vec2(-0.9f, 0.9f), glm::vec2(-0.6f, 0.8f));
+ pScreenText->setPosition(glm::vec2(-0.9f, 0.9f), glm::vec2(-0.6f, 0.8f), textPos);
pScreenText->render();
glm::vec3 maTargetPosition = rBarInfo.maPos;
diff --git a/chart2/source/view/inc/3DChartObjects.hxx b/chart2/source/view/inc/3DChartObjects.hxx
index 54b04fd..9c8bb503 100644
--- a/chart2/source/view/inc/3DChartObjects.hxx
+++ b/chart2/source/view/inc/3DChartObjects.hxx
@@ -111,12 +111,13 @@ public:
ScreenText(OpenGL3DRenderer* pRenderer, TextCache& rTextCache, const OUString& rStr, sal_uInt32 nId);
virtual void render() SAL_OVERRIDE;
- void setPosition(const glm::vec2& rTopLeft, const glm::vec2& rBottomRight);
+ void setPosition(const glm::vec2& rTopLeft, const glm::vec2& rBottomRight, glm::vec3 r3DPos = glm::vec3(0.0, 0.0, 0.0));
private:
TextCacheItem maText;
glm::vec2 maTopLeft;
glm::vec2 maBottomRight;
+ glm::vec3 ma3DPos;
};
class Rectangle : public Renderable3DObject
diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx
index f4b4b67..94a5f88 100644
--- a/chart2/source/view/inc/GL3DRenderer.hxx
+++ b/chart2/source/view/inc/GL3DRenderer.hxx
@@ -138,8 +138,10 @@ struct PackedVertex{
struct TextInfo
{
glm::vec4 id;
+ sal_uInt32 uniqueId;
GLuint texture;
float vertex[12];
+ glm::vec3 pos;
};
struct TextureArrayInfo
@@ -197,7 +199,7 @@ public:
sal_uInt32 nUniqueId);
void CreateScreenTextTexture(const boost::shared_array<sal_uInt8> &bitmapBuf,
::Size maSizePixels, const glm::vec2& vTopLeft,
- const glm::vec2& vBottomRight, sal_uInt32 nUniqueId);
+ const glm::vec2& vBottomRight, glm::vec3 vPos, sal_uInt32 nUniqueId);
void ProcessUnrenderedShape(bool bNewScene);
void SetPickingMode(bool bPickingMode);
diff --git a/chart2/source/view/main/3DChartObjects.cxx b/chart2/source/view/main/3DChartObjects.cxx
index 9786c00..a045b48 100644
--- a/chart2/source/view/main/3DChartObjects.cxx
+++ b/chart2/source/view/main/3DChartObjects.cxx
@@ -134,16 +134,17 @@ ScreenText::ScreenText(OpenGL3DRenderer* pRenderer, TextCache& rTextCache, const
{
}
-void ScreenText::setPosition(const glm::vec2& rTopLeft, const glm::vec2& rBottomRight)
+void ScreenText::setPosition(const glm::vec2& rTopLeft, const glm::vec2& rBottomRight, glm::vec3 r3DPos)
{
maTopLeft = rTopLeft;
maBottomRight = rBottomRight;
+ ma3DPos = r3DPos;
}
void ScreenText::render()
{
mpRenderer->CreateScreenTextTexture(maText.maPixels, maText.maSize,
- maTopLeft, maBottomRight,
+ maTopLeft, maBottomRight, ma3DPos,
mnUniqueId);
}
diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index 48d7da7..295a8a7 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -1666,13 +1666,14 @@ void OpenGL3DRenderer::RenderExtrude3DObject()
void OpenGL3DRenderer::CreateScreenTextTexture(
const boost::shared_array<sal_uInt8> &bitmapBuf,
::Size maSizePixels, const glm::vec2& vTopLeft,
- const glm::vec2& vBottomRight, sal_uInt32 nUniqueId)
+ const glm::vec2& vBottomRight, glm::vec3 vPos, sal_uInt32 nUniqueId)
{
long bmpWidth = maSizePixels.Width();
long bmpHeight = maSizePixels.Height();
TextInfo aTextInfo;
aTextInfo.id = getColorAsVector(nUniqueId);
+ aTextInfo.uniqueId = nUniqueId;
aTextInfo.vertex[0] = vBottomRight.x;
aTextInfo.vertex[1] = vBottomRight.y;
aTextInfo.vertex[2] = 0;
@@ -1688,6 +1689,7 @@ void OpenGL3DRenderer::CreateScreenTextTexture(
aTextInfo.vertex[9] = vTopLeft.x;
aTextInfo.vertex[10] = vBottomRight.y;
aTextInfo.vertex[11] = 0;
+ aTextInfo.pos = vPos;
CHECK_GL_ERROR();
glGenTextures(1, &aTextInfo.texture);
@@ -1868,17 +1870,38 @@ void OpenGL3DRenderer::ReleaseScreenTextShapes()
void OpenGL3DRenderer::RenderScreenTextShape()
{
+ glUseProgram(maResources.m_ScreenTextProID);
CHECK_GL_ERROR();
for (size_t i = 0; i < m_ScreenTextInfoList.size(); i++)
{
TextInfo &textInfo = m_ScreenTextInfoList[i];
+ //calc the postition and check whether it can be displayed
+ float xTrans = 0.0f;
+ float yTrans = 0.0f;
+ if (textInfo.uniqueId)
+ {
+ glm::vec3 worldPos = glm::vec3(m_ScrollMoveMatrix * m_GlobalScaleMatrix * glm::vec4(textInfo.pos, 1));
+ if (worldPos.x < m_fMinCoordX)
+ continue;
+ glm::vec4 pos = m_3DProjection * m_3DView * glm::vec4(worldPos, 1);
+ xTrans = pos.x / pos.w;
+ yTrans = pos.y / pos.w;
+ for (int j = 0; j < 12; j++)
+ {
+ if (j % 3 == 0)
+ {
+ textInfo.vertex[j] += xTrans;
+ }
+ if (j % 3 == 1)
+ {
+ textInfo.vertex[j] += yTrans;
+ }
+ }
+ }
glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer);
CHECK_GL_ERROR();
glBufferData(GL_ARRAY_BUFFER, sizeof(textInfo.vertex), textInfo.vertex, GL_STATIC_DRAW);
CHECK_GL_ERROR();
- glUseProgram(maResources.m_ScreenTextProID);
-
- CHECK_GL_ERROR();
// 1rst attribute buffer : vertices
glEnableVertexAttribArray(maResources.m_ScreenTextVertexID);
@@ -1912,13 +1935,13 @@ void OpenGL3DRenderer::RenderScreenTextShape()
//TODO: moggi: get rid fo GL_QUADS
glDrawArrays(GL_QUADS, 0, 4);
CHECK_GL_ERROR();
- glDisableVertexAttribArray(maResources.m_ScreenTextTexCoordID);
- CHECK_GL_ERROR();
- glDisableVertexAttribArray(maResources.m_ScreenTextVertexID);
- CHECK_GL_ERROR();
- glBindTexture(GL_TEXTURE_2D, 0);
- glUseProgram(0);
}
+ glDisableVertexAttribArray(maResources.m_ScreenTextTexCoordID);
+ CHECK_GL_ERROR();
+ glDisableVertexAttribArray(maResources.m_ScreenTextVertexID);
+ CHECK_GL_ERROR();
+ glBindTexture(GL_TEXTURE_2D, 0);
+ glUseProgram(0);
CHECK_GL_ERROR();
}
void OpenGL3DRenderer::ReleaseTextShapesBatch()
More information about the Libreoffice-commits
mailing list