Kaydet (Commit) 27c1d4f2 authored tarafından Markus Mohrhard's avatar Markus Mohrhard

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
üst b13185ad
...@@ -6,17 +6,70 @@ ...@@ -6,17 +6,70 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ */
#
#version 120 #version 120
varying vec4 fragmentColor; varying vec4 fragmentColor;
uniform int shape;
void main() void main()
{ {
vec2 p = gl_PointCoord * 2.0 - vec2(1.0); // (0,0) in the center vec2 p = gl_PointCoord * 2.0 - vec2(1.0); // (0,0) in the center
if (abs(p.x) < abs(p.y)) if(shape == 0)
discard; {
}
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; gl_FragColor = fragmentColor;
} }
......
...@@ -16,9 +16,8 @@ varying vec4 fragmentColor; ...@@ -16,9 +16,8 @@ varying vec4 fragmentColor;
void main() void main()
{ {
gl_Position = MVP * vec4(vPosition, 1); gl_Position = MVP * vec4(vPosition, 1);
fragmentColor = vColor; fragmentColor = vColor;
gl_PointSize = 10.0;
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -297,8 +297,9 @@ int OpenGLRender::InitOpenGL(GLWindow aWindow) ...@@ -297,8 +297,9 @@ int OpenGLRender::InitOpenGL(GLWindow aWindow)
m_SymbolProID = LoadShaders("symbolVertexShader", "symbolFragmentShader"); m_SymbolProID = LoadShaders("symbolVertexShader", "symbolFragmentShader");
m_SymbolVertexID = glGetAttribLocation(m_SymbolProID, "vPosition"); m_SymbolVertexID = glGetAttribLocation(m_SymbolProID, "vPosition");
m_SymbolMatrixID = glGetAttribLocation(m_SymbolProID, "MVP"); m_SymbolMatrixID = glGetUniformLocation(m_SymbolProID, "MVP");
m_SymbolColorID = glGetAttribLocation(m_SymbolProID, "vColor"); m_SymbolColorID = glGetUniformLocation(m_SymbolProID, "vColor");
m_SymbolShapeID = glGetUniformLocation(m_SymbolProID, "shape");
CHECK_GL_ERROR(); CHECK_GL_ERROR();
...@@ -1204,11 +1205,13 @@ int OpenGLRender::RenderRectangleShape(bool bBorder, bool bFill) ...@@ -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 //move the circle to the pos, and scale using the xScale and Y scale
RectanglePointList &pointList = m_RectangleShapePointList.front(); RectanglePointList &pointList = m_RectangleShapePointList.front();
PosVecf3 trans = {0, 0, 0}; {
PosVecf3 angle = {0.0f, 0.0f, 0.0f}; PosVecf3 trans = {0, 0, 0};
PosVecf3 scale = {1, 1, 1.0f}; PosVecf3 angle = {0.0f, 0.0f, 0.0f};
MoveModelf(trans, angle, scale); PosVecf3 scale = {1, 1, 1.0f};
m_MVP = m_Projection * m_View * m_Model; MoveModelf(trans, angle, scale);
m_MVP = m_Projection * m_View * m_Model;
}
//render to fbo //render to fbo
//fill vertex buffer //fill vertex buffer
...@@ -1251,6 +1254,17 @@ int OpenGLRender::RenderRectangleShape(bool bBorder, bool bFill) ...@@ -1251,6 +1254,17 @@ int OpenGLRender::RenderRectangleShape(bool bBorder, bool bFill)
} }
if(bBorder) 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); SetBackGroundColor(COL_BLACK, COL_BLACK);
glBindBuffer(GL_ARRAY_BUFFER, m_ColorBuffer); glBindBuffer(GL_ARRAY_BUFFER, m_ColorBuffer);
...@@ -1649,31 +1663,36 @@ int OpenGLRender::RenderPieSegment2DShape(float fSize, float fPosX, float fPosY) ...@@ -1649,31 +1663,36 @@ int OpenGLRender::RenderPieSegment2DShape(float fSize, float fPosX, float fPosY)
return 0; 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(); CHECK_GL_ERROR();
glDisable(GL_POINT_SMOOTH); glPointSize(20.f);
glDisable(GL_MULTISAMPLE);
glPointSize(10.f);
CHECK_GL_ERROR(); 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 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); MoveModelf(trans, angle, scale);
m_MVP = m_Projection * m_View * m_Model; 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 //fill vertex buffer
glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer);
CHECK_GL_ERROR();
glBufferData(GL_ARRAY_BUFFER, 3 * sizeof(float), aPos, GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, 3 * sizeof(float), aPos, GL_STATIC_DRAW);
CHECK_GL_ERROR(); CHECK_GL_ERROR();
// Use our shader // Use our shader
glUseProgram(m_SymbolProID); glUseProgram(m_SymbolProID);
CHECK_GL_ERROR();
glUniform4fv(m_SymbolColorID, 1, &m_2DColor[0]); glUniform4fv(m_SymbolColorID, 1, &m_2DColor[0]);
glUniform1i(m_SymbolShapeID, nSymbol);
CHECK_GL_ERROR();
glUniformMatrix4fv(m_SymbolMatrixID, 1, GL_FALSE, &m_MVP[0][0]); glUniformMatrix4fv(m_SymbolMatrixID, 1, GL_FALSE, &m_MVP[0][0]);
CHECK_GL_ERROR();
// 1rst attribute buffer : vertices // 1rst attribute buffer : vertices
glEnableVertexAttribArray(m_SymbolVertexID); glEnableVertexAttribArray(m_SymbolVertexID);
glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer);
...@@ -1685,12 +1704,11 @@ int OpenGLRender::RenderSymbol2DShape(float x, float y, float width, float heigh ...@@ -1685,12 +1704,11 @@ int OpenGLRender::RenderSymbol2DShape(float x, float y, float width, float heigh
0, // stride 0, // stride
(void*)0 // array buffer offset (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); glDisableVertexAttribArray(m_SymbolVertexID);
CHECK_GL_ERROR();
glUseProgram(0); glUseProgram(0);
glEnable(GL_MULTISAMPLE);
glEnable(GL_POINT_SMOOTH);
m_fZStep += Z_STEP; m_fZStep += Z_STEP;
CHECK_GL_ERROR(); CHECK_GL_ERROR();
......
...@@ -294,6 +294,7 @@ private: ...@@ -294,6 +294,7 @@ private:
GLuint m_SymbolVertexID; GLuint m_SymbolVertexID;
GLuint m_SymbolMatrixID; GLuint m_SymbolMatrixID;
GLuint m_SymbolColorID; GLuint m_SymbolColorID;
GLuint m_SymbolShapeID;
#if DEBUG_POSITIONING #if DEBUG_POSITIONING
GLuint m_DebugProID; GLuint m_DebugProID;
......
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