initial work on screen text

Screen text is positioned in screen coordinates and therefore in 2D.
This means it will not move with the camera.

Change-Id: I3cf2e8859871ebc8034396b4c2d6f1ff9fe5d9f6
This commit is contained in:
Markus Mohrhard 2014-05-26 00:27:22 +02:00 committed by Markus Mohrhard
parent f9d9aceb1c
commit 36943e981b
9 changed files with 217 additions and 0 deletions

View File

@ -22,6 +22,8 @@ $(eval $(call gb_Package_add_files,chart2_opengl_shader,$(LIBO_BIN_FOLDER)/openg
symbolVertexShader.glsl \
textFragmentShader.glsl \
textVertexShader.glsl \
screenTextFragmentShader.glsl \
screenTextVertexShader.glsl \
shape3DFragmentShader.glsl \
shape3DVertexShader.glsl \
renderTextureVertexShader.glsl \

View File

@ -0,0 +1,17 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
varying vec2 vTexCoord;
uniform sampler2D TextTex;
void main()
{
gl_FragColor = vec4(texture2D(TextTex, vTexCoord).rgba);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -0,0 +1,19 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
attribute vec3 vPosition;
attribute vec2 texCoord;
varying vec2 vTexCoord;
void main()
{
gl_Position = vec4(vPosition, 1);
vTexCoord = texCoord;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -186,6 +186,12 @@ void GL3DBarChart::create3DShapes(const boost::ptr_vector<VDataSeries>& rDataSer
pAxis->setPosition(aBegin, aEnd);
pAxis->setLineColor(COL_BLUE);
// test for information
maShapes.push_back(new opengl3D::ScreenText(mpRenderer.get(), *mpTextCache,
"I'm really nice text", 0));
opengl3D::ScreenText* pScreenText = static_cast<opengl3D::ScreenText*>(&maShapes.back());
pScreenText->setPosition(glm::vec2(-1.0f, 0.9f), glm::vec2(-0.6f, 0.75f));
// Chart background.
maShapes.push_back(new opengl3D::Rectangle(mpRenderer.get(), nId++));
opengl3D::Rectangle* pRect = static_cast<opengl3D::Rectangle*>(&maShapes.back());

View File

@ -91,6 +91,20 @@ private:
glm::vec3 maBottomRight;
};
class ScreenText : public Renderable3DObject
{
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);
private:
const BitmapEx& mrText;
glm::vec2 maTopLeft;
glm::vec2 maBottomRight;
};
class Rectangle : public Renderable3DObject
{
public:

View File

@ -87,6 +87,15 @@ private:
* numbering counter clockwise
*/
sal_Int8 mnCornerId;
struct BarInformation
{
double nVal;
OUString aSeriesName;
};
std::map<sal_uInt32, BarInformation> maBarMap;
};
}

View File

@ -162,6 +162,7 @@ public:
void SetSize(const Size& rSize);
void SetCameraInfo(glm::vec3 pos, glm::vec3 direction, glm::vec3 up);
void CreateTextTexture(const BitmapEx& rBitmapEx, glm::vec3 vTopLeft,glm::vec3 vTopRight, glm::vec3 vBottomRight, glm::vec3 vBottomLeft, sal_uInt32 nUniqueId);
void CreateScreenTextTexture(const BitmapEx& rBitmapEx, glm::vec2 vTopLeft, glm::vec2 vBottomRight, sal_uInt32 nUniqueId);
void ProcessUnrenderedShape();
void SetPickingMode(bool bPickingMode);
@ -178,6 +179,7 @@ private:
void RenderExtrude3DObject();
//add for text
void RenderTextShape();
void RenderScreenTextShape();
void RenderExtrudeSurface(const Extrude3DInfo& extrude3D);
void RenderExtrudeTopSurface(const Extrude3DInfo& extrude3D);
void RenderExtrudeMiddleSurface(const Extrude3DInfo& extrude3D);
@ -206,6 +208,7 @@ private:
void ReleasePolygonShapes();
void ReleaseExtrude3DShapes();
void ReleaseTextShapes();
void ReleaseScreenTextShapes();
private:
struct ShaderResources
@ -226,6 +229,12 @@ private:
GLint m_TextTexCoordID;
GLint m_TextTexID;
// ScreenTextProID
GLint m_ScreenTextProID;
GLint m_ScreenTextVertexID;
GLint m_ScreenTextTexCoordID;
GLint m_ScreenTextTexID;
// CommonProID
GLint m_CommonProID;
GLint m_2DVertexID;
@ -251,6 +260,10 @@ private:
, m_TextVertexID(0)
, m_TextTexCoordID(0)
, m_TextTexID(0)
, m_ScreenTextProID(0)
, m_ScreenTextVertexID(0)
, m_ScreenTextTexCoordID(0)
, m_ScreenTextTexID(0)
, m_CommonProID(0)
, m_2DVertexID(0)
, m_2DColorID(0)
@ -267,6 +280,7 @@ private:
glDeleteProgram(m_CommonProID);
glDeleteProgram(m_RenderProID);
glDeleteProgram(m_TextProID);
glDeleteProgram(m_ScreenTextProID);
glDeleteProgram(m_3DProID);
}
@ -353,6 +367,7 @@ private:
GLuint m_BoundBoxNormal;
// add for text
std::vector <TextInfo> m_TextInfoList;
std::vector <TextInfo> m_ScreenTextInfoList;
GLuint m_TextTexCoordBuf;
std::vector<glm::vec3> m_Vertices;

View File

@ -115,6 +115,23 @@ void Text::setPosition(const glm::vec3& rTopLeft, const glm::vec3& rTopRight, co
maBottomRight = rBottomRight;
}
ScreenText::ScreenText(OpenGL3DRenderer* pRenderer, TextCache& rTextCache, const OUString& rStr, sal_uInt32 nId):
Renderable3DObject(pRenderer, nId),
mrText(rTextCache.getText(rStr))
{
}
void ScreenText::setPosition(const glm::vec2& rTopLeft, const glm::vec2& rBottomRight)
{
maTopLeft = rTopLeft;
maBottomRight = rBottomRight;
}
void ScreenText::render()
{
mpRenderer->CreateScreenTextTexture(mrText, maTopLeft, maBottomRight, mnUniqueId);
}
Rectangle::Rectangle(OpenGL3DRenderer* pRenderer, sal_uInt32 nId):
Renderable3DObject(pRenderer, nId)
{

View File

@ -123,6 +123,11 @@ void OpenGL3DRenderer::ShaderResources::LoadShaders()
m_TextTexCoordID = glGetAttribLocation(m_TextProID, "texCoord");
m_TextTexID = glGetUniformLocation(m_TextProID, "TextTex");
m_ScreenTextProID = OpenGLHelper::LoadShaders("screenTextVertexShader", "screenTextFragmentShader");
m_ScreenTextVertexID = glGetAttribLocation(m_ScreenTextProID, "vPosition");
m_ScreenTextTexCoordID = glGetAttribLocation(m_ScreenTextProID, "texCoord");
m_ScreenTextTexID = glGetUniformLocation(m_ScreenTextProID, "TextTex");
m_CommonProID = OpenGLHelper::LoadShaders("commonVertexShader", "commonFragmentShader");
m_MatrixID = glGetUniformLocation(m_CommonProID, "MVP");
m_2DVertexID = glGetAttribLocation(m_CommonProID, "vPosition");
@ -1349,6 +1354,50 @@ void OpenGL3DRenderer::RenderExtrude3DObject()
glDisable(GL_CULL_FACE);
}
void OpenGL3DRenderer::CreateScreenTextTexture(const BitmapEx& rBitmapEx, glm::vec2 vTopLeft, glm::vec2 vBottomRight, sal_uInt32 nUniqueId)
{
long bmpWidth = rBitmapEx.GetSizePixel().Width();
long bmpHeight = rBitmapEx.GetSizePixel().Height();
boost::scoped_array<sal_uInt8> bitmapBuf(OpenGLHelper::ConvertBitmapExToRGBABuffer(rBitmapEx));
TextInfo aTextInfo;
aTextInfo.id = getColorAsVector(nUniqueId);
aTextInfo.vertex[0] = vTopLeft.x;
aTextInfo.vertex[1] = vTopLeft.y;
aTextInfo.vertex[2] = 0;
aTextInfo.vertex[3] = vBottomRight.x;
aTextInfo.vertex[4] = vTopLeft.y;
aTextInfo.vertex[5] = 0;
aTextInfo.vertex[9] = vTopLeft.x;
aTextInfo.vertex[10] = vBottomRight.y;
aTextInfo.vertex[11] = 0;
aTextInfo.vertex[6] = vBottomRight.x;
aTextInfo.vertex[7] = vBottomRight.y;
aTextInfo.vertex[8] = 0;
CHECK_GL_ERROR();
glGenTextures(1, &aTextInfo.texture);
CHECK_GL_ERROR();
glBindTexture(GL_TEXTURE_2D, aTextInfo.texture);
CHECK_GL_ERROR();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
CHECK_GL_ERROR();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
CHECK_GL_ERROR();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
CHECK_GL_ERROR();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
CHECK_GL_ERROR();
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bmpWidth, bmpHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, bitmapBuf.get());
CHECK_GL_ERROR();
glBindTexture(GL_TEXTURE_2D, 0);
CHECK_GL_ERROR();
m_ScreenTextInfoList.push_back(aTextInfo);
}
void OpenGL3DRenderer::CreateTextTexture(const BitmapEx& rBitmapEx, glm::vec3 vTopLeft,glm::vec3 vTopRight, glm::vec3 vBottomRight, glm::vec3 vBottomLeft, sal_uInt32 nUniqueId)
{
long bmpWidth = rBitmapEx.GetSizePixel().Width();
@ -1403,6 +1452,72 @@ void OpenGL3DRenderer::ReleaseTextShapes()
m_TextInfoList.clear();
}
void OpenGL3DRenderer::ReleaseScreenTextShapes()
{
for (size_t i = 0; i < m_ScreenTextInfoList.size(); i++)
{
TextInfo &textInfo = m_ScreenTextInfoList[i];
glDeleteTextures(1, &textInfo.texture);
}
m_ScreenTextInfoList.clear();
}
void OpenGL3DRenderer::RenderScreenTextShape()
{
CHECK_GL_ERROR();
for (size_t i = 0; i < m_ScreenTextInfoList.size(); i++)
{
TextInfo &textInfo = m_ScreenTextInfoList[i];
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);
glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer);
glVertexAttribPointer(
maResources.m_ScreenTextVertexID,
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);
//tex coord
CHECK_GL_ERROR();
glEnableVertexAttribArray(maResources.m_ScreenTextTexCoordID);
glBindBuffer(GL_ARRAY_BUFFER, m_TextTexCoordBuf);
glVertexAttribPointer(
maResources.m_ScreenTextTexCoordID,
2, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);
//texture
CHECK_GL_ERROR();
glBindTexture(GL_TEXTURE_2D, textInfo.texture);
CHECK_GL_ERROR();
glUniform1i(maResources.m_ScreenTextTexID, 0);
CHECK_GL_ERROR();
//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);
}
CHECK_GL_ERROR();
}
void OpenGL3DRenderer::RenderTextShape()
{
CHECK_GL_ERROR();
@ -1484,6 +1599,8 @@ void OpenGL3DRenderer::ProcessUnrenderedShape()
RenderExtrude3DObject();
//render text
RenderTextShape();
// render screen text
RenderScreenTextShape();
ReleaseShapes();
#if DEBUG_FBO
OUString aFileName = OUString("D://shaderout_") + OUString::number(m_iWidth) + "_" + OUString::number(m_iHeight) + ".png";
@ -1525,6 +1642,7 @@ void OpenGL3DRenderer::ReleaseShapes()
ReleasePolygonShapes();
ReleaseExtrude3DShapes();
ReleaseTextShapes();
ReleaseScreenTextShapes();
}
}