Kaydet (Commit) 05ecb52d authored tarafından weigao's avatar weigao Kaydeden (comit) Markus Mohrhard

add position control to screen text

Change-Id: I6bf340acb3aa50f2ce534b10d5be32c4615b0688
üst 692878e3
......@@ -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;
......
......@@ -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
......
......@@ -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);
......
......@@ -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);
}
......
......@@ -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,16 +1870,37 @@ 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
......@@ -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()
......
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