summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2014-02-03 18:06:20 +0100
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2014-02-03 18:28:04 +0100
commit27c1d4f2c4f55b67499d73fa7452a9a14a2aa948 (patch)
treed51bae39b3a2bdcdd01de4e943cd332a53a6399c
parentb13185adbab4c18dbd691cf78083545b2874f2e8 (diff)
working symbol rendering based on point sprites
This approach ahs several advantages compared to the old approach. There is no UNO involved anymore and we have a perfect shape defined by a mathematical formula. No need for anti-aliasing or complex calculations on the CPU. Change-Id: I5018eae516de3368037c4c293d937de66f38568d
-rw-r--r--chart2/opengl/symbolFragmentShader.glsl61
-rw-r--r--chart2/opengl/symbolVertexShader.glsl3
-rwxr-xr-xchart2/source/view/main/OpenGLRender.cxx52
-rwxr-xr-xchart2/source/view/main/OpenGLRender.hxx1
4 files changed, 94 insertions, 23 deletions
diff --git a/chart2/opengl/symbolFragmentShader.glsl b/chart2/opengl/symbolFragmentShader.glsl
index a84d83cfba48..2837f958af29 100644
--- a/chart2/opengl/symbolFragmentShader.glsl
+++ b/chart2/opengl/symbolFragmentShader.glsl
@@ -6,17 +6,70 @@
* 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/.
*/
-#
+
#version 120
varying vec4 fragmentColor;
+uniform int shape;
void main()
{
vec2 p = gl_PointCoord * 2.0 - vec2(1.0); // (0,0) in the center
- if (abs(p.x) < abs(p.y))
- discard;
-
+ if(shape == 0)
+ {
+ }
+ else if(shape == 1) //diamon
+ {
+ if (abs(p.x) + abs(p.y) > 1)
+ discard;
+ }
+ else if(shape == 2) // arrow
+ {
+ if(p.y < 0 && (abs(p.x) + abs(p.y)) > 1)
+ discard;
+ else if(p.y > 0 && abs(p.x) > 0.5)
+ discard;
+ }
+ else if(shape == 3) //arrow up
+ {
+ if(p.y > 0 && (abs(p.x) + abs(p.y)) > 1)
+ discard;
+ else if(p.y < 0 && abs(p.x) > 0.5)
+ discard;
+ }
+ else if(shape == 4)
+ {
+ if(p.x > 0 && (abs(p.x) + abs(p.y)) > 1)
+ discard;
+ else if(p.x < 0 && abs(p.y) > 0.5)
+ discard;
+ }
+ else if(shape == 5)
+ {
+ if(p.x < 0 && (abs(p.x) + abs(p.y)) > 1)
+ discard;
+ else if(p.x > 0 && abs(p.y) > 0.5)
+ discard;
+ }
+ else if(shape == 6)
+ {
+ if(abs(p.x) < abs(p.y))
+ discard;
+ }
+ else if(shape == 7)
+ {
+ if(abs(p.y) < abs(p.x))
+ discard;
+ }
+ else if(shape == 8)
+ {
+ if(dot(p.x, p.y) > 1)
+ discard;
+ }
+ else if(shape == 9)
+ {
+ }
+
gl_FragColor = fragmentColor;
}
diff --git a/chart2/opengl/symbolVertexShader.glsl b/chart2/opengl/symbolVertexShader.glsl
index e1bbec9bc202..3cf9f41ef21b 100644
--- a/chart2/opengl/symbolVertexShader.glsl
+++ b/chart2/opengl/symbolVertexShader.glsl
@@ -16,9 +16,8 @@ varying vec4 fragmentColor;
void main()
{
- gl_Position = MVP * vec4(vPosition, 1);
+ gl_Position = MVP * vec4(vPosition, 1);
fragmentColor = vColor;
- gl_PointSize = 10.0;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/view/main/OpenGLRender.cxx b/chart2/source/view/main/OpenGLRender.cxx
index 29c5d353ec93..d4349a6cdaad 100755
--- a/chart2/source/view/main/OpenGLRender.cxx
+++ b/chart2/source/view/main/OpenGLRender.cxx
@@ -297,8 +297,9 @@ int OpenGLRender::InitOpenGL(GLWindow aWindow)
m_SymbolProID = LoadShaders("symbolVertexShader", "symbolFragmentShader");
m_SymbolVertexID = glGetAttribLocation(m_SymbolProID, "vPosition");
- m_SymbolMatrixID = glGetAttribLocation(m_SymbolProID, "MVP");
- m_SymbolColorID = glGetAttribLocation(m_SymbolProID, "vColor");
+ m_SymbolMatrixID = glGetUniformLocation(m_SymbolProID, "MVP");
+ m_SymbolColorID = glGetUniformLocation(m_SymbolProID, "vColor");
+ m_SymbolShapeID = glGetUniformLocation(m_SymbolProID, "shape");
CHECK_GL_ERROR();
@@ -1204,11 +1205,13 @@ int OpenGLRender::RenderRectangleShape(bool bBorder, bool bFill)
{
//move the circle to the pos, and scale using the xScale and Y scale
RectanglePointList &pointList = m_RectangleShapePointList.front();
- PosVecf3 trans = {0, 0, 0};
- PosVecf3 angle = {0.0f, 0.0f, 0.0f};
- PosVecf3 scale = {1, 1, 1.0f};
- MoveModelf(trans, angle, scale);
- m_MVP = m_Projection * m_View * m_Model;
+ {
+ PosVecf3 trans = {0, 0, 0};
+ PosVecf3 angle = {0.0f, 0.0f, 0.0f};
+ PosVecf3 scale = {1, 1, 1.0f};
+ MoveModelf(trans, angle, scale);
+ m_MVP = m_Projection * m_View * m_Model;
+ }
//render to fbo
//fill vertex buffer
@@ -1251,6 +1254,17 @@ int OpenGLRender::RenderRectangleShape(bool bBorder, bool bFill)
}
if(bBorder)
{
+ if(bFill)
+ {
+ PosVecf3 trans = {0.0, 0.0, Z_STEP };
+ PosVecf3 angle = {0.0f, 0.0f, 0.0f};
+ PosVecf3 scale = {1, 1, 1.0f};
+ MoveModelf(trans, angle, scale);
+ m_MVP = m_Projection * m_View * m_Model;
+
+ m_fZStep += Z_STEP;
+ glUniformMatrix4fv(m_BackgroundMatrixID, 1, GL_FALSE, &m_MVP[0][0]);
+ }
SetBackGroundColor(COL_BLACK, COL_BLACK);
glBindBuffer(GL_ARRAY_BUFFER, m_ColorBuffer);
@@ -1649,31 +1663,36 @@ int OpenGLRender::RenderPieSegment2DShape(float fSize, float fPosX, float fPosY)
return 0;
}
-int OpenGLRender::RenderSymbol2DShape(float x, float y, float width, float height, sal_Int32)
+int OpenGLRender::RenderSymbol2DShape(float x, float y, float , float , sal_Int32 nSymbol)
{
CHECK_GL_ERROR();
- glDisable(GL_POINT_SMOOTH);
- glDisable(GL_MULTISAMPLE);
- glPointSize(10.f);
+ glPointSize(20.f);
CHECK_GL_ERROR();
- PosVecf3 trans = {x/OPENGL_SCALE_VALUE, y/OPENGL_SCALE_VALUE, m_fZStep};
+ PosVecf3 trans = {0.0, 0.0, 0.0};
PosVecf3 angle = {0.0f, 0.0f, 0.0f};
- PosVecf3 scale = {width/OPENGL_SCALE_VALUE, height/OPENGL_SCALE_VALUE, 1.0f};
+ PosVecf3 scale = {1.0, 1.0, 1.0f};
MoveModelf(trans, angle, scale);
m_MVP = m_Projection * m_View * m_Model;
- float aPos[3] = { 0.f, 0.f, 0.f };
+ float aPos[3] = { x/OPENGL_SCALE_VALUE, y/OPENGL_SCALE_VALUE, m_fZStep };
//fill vertex buffer
glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer);
+ CHECK_GL_ERROR();
glBufferData(GL_ARRAY_BUFFER, 3 * sizeof(float), aPos, GL_STATIC_DRAW);
CHECK_GL_ERROR();
// Use our shader
glUseProgram(m_SymbolProID);
+ CHECK_GL_ERROR();
+
glUniform4fv(m_SymbolColorID, 1, &m_2DColor[0]);
+ glUniform1i(m_SymbolShapeID, nSymbol);
+ CHECK_GL_ERROR();
+
glUniformMatrix4fv(m_SymbolMatrixID, 1, GL_FALSE, &m_MVP[0][0]);
+ CHECK_GL_ERROR();
// 1rst attribute buffer : vertices
glEnableVertexAttribArray(m_SymbolVertexID);
glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer);
@@ -1685,12 +1704,11 @@ int OpenGLRender::RenderSymbol2DShape(float x, float y, float width, float heigh
0, // stride
(void*)0 // array buffer offset
);
- glDrawArrays(GL_POINTS, 0, 1); // 12*3 indices starting at 0 -> 12 triangles
+ glDrawArrays(GL_POINTS, 0, 1);
glDisableVertexAttribArray(m_SymbolVertexID);
+ CHECK_GL_ERROR();
glUseProgram(0);
- glEnable(GL_MULTISAMPLE);
- glEnable(GL_POINT_SMOOTH);
m_fZStep += Z_STEP;
CHECK_GL_ERROR();
diff --git a/chart2/source/view/main/OpenGLRender.hxx b/chart2/source/view/main/OpenGLRender.hxx
index e741595904d1..03364e27426e 100755
--- a/chart2/source/view/main/OpenGLRender.hxx
+++ b/chart2/source/view/main/OpenGLRender.hxx
@@ -294,6 +294,7 @@ private:
GLuint m_SymbolVertexID;
GLuint m_SymbolMatrixID;
GLuint m_SymbolColorID;
+ GLuint m_SymbolShapeID;
#if DEBUG_POSITIONING
GLuint m_DebugProID;