Kaydet (Commit) d18ad8a7 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl

opengl: shader based polyline rendering - fixes tdf#97137 for OGL

Adds native opengl polyline rendering to draw polylines, line joins
and line caps as triangle strips. The vertex shader allows for the
dynamic line width by calculating the correct vertex posiitons,
and the fragment shader is used for anti-aliasing.

Change-Id: If7982c828cae1fae59c57194c8ac77e5ad7f1d26
üst 9c6b6c6c
......@@ -779,6 +779,35 @@ namespace basegfx
namespace tools
{
B2DPolygon polygonSubdivide(const B2DPolygon& rCandidate, double fMaxAllowedAngle, double fMaxPartOfEdge)
{
if(fMaxAllowedAngle > F_PI2)
{
fMaxAllowedAngle = F_PI2;
}
else if(fMaxAllowedAngle < 0.01 * F_PI2)
{
fMaxAllowedAngle = 0.01 * F_PI2;
}
if(fMaxPartOfEdge > 1.0)
{
fMaxPartOfEdge = 1.0;
}
else if(fMaxPartOfEdge < 0.01)
{
fMaxPartOfEdge = 0.01;
}
B2DPolygon aCandidate(rCandidate);
const double fMaxCos(cos(fMaxAllowedAngle));
aCandidate.removeDoublePoints();
aCandidate = subdivideToSimple(aCandidate, fMaxCos * fMaxCos, fMaxPartOfEdge * fMaxPartOfEdge);
return aCandidate;
}
B2DPolyPolygon createAreaGeometry(
const B2DPolygon& rCandidate,
double fHalfLineWidth,
......
......@@ -137,6 +137,12 @@ namespace basegfx
double fMaxAllowedAngle = (12.5 * F_PI180),
double fMaxPartOfEdge = 0.4,
double fMiterMinimumAngle = (15.0 * F_PI180));
BASEGFX_DLLPUBLIC B2DPolygon polygonSubdivide(
const B2DPolygon& rCandidate,
double fMaxAllowedAngle = (12.5 * F_PI180),
double fMaxPartOfEdge = 0.4);
} // end of namespace tools
} // end of namespace basegfx
......
......@@ -21,6 +21,8 @@ $(eval $(call gb_Package_add_files,vcl_opengl_shader,$(LIBO_ETC_FOLDER)/opengl,\
invert50FragmentShader.glsl \
convolutionFragmentShader.glsl \
linearGradientFragmentShader.glsl \
lineFragmentShader.glsl \
lineVertexShader.glsl \
maskFragmentShader.glsl \
maskedTextureVertexShader.glsl \
maskedTextureFragmentShader.glsl \
......
......@@ -37,6 +37,7 @@ private:
GLuint mnTexCoordAttrib;
GLuint mnAlphaCoordAttrib;
GLuint mnMaskCoordAttrib;
GLuint mnNormalAttrib;
TextureList maTextures;
bool mbBlending;
......@@ -59,6 +60,7 @@ public:
void SetTextureCoord( const GLvoid* pData );
void SetAlphaCoord( const GLvoid* pData );
void SetMaskCoord(const GLvoid* pData);
void SetExtrusionVectors(const GLvoid* pData);
void SetUniform1f( const OString& rName, GLfloat v1 );
void SetUniform2f( const OString& rName, GLfloat v1, GLfloat v2 );
......@@ -80,7 +82,7 @@ public:
bool DrawTexture( const OpenGLTexture& rTexture );
protected:
void SetVertexAttrib( GLuint& rAttrib, const OString& rName, const GLvoid* pData );
void SetVertexAttrib( GLuint& rAttrib, const OString& rName, const GLvoid* pData, GLint nSize = 2 );
GLuint GetUniformLocation( const OString& rName );
};
......
......@@ -113,6 +113,7 @@ public:
bool UseSolid( SalColor nColor );
bool UseSolidAA( SalColor nColor, double fTransparency );
bool UseSolidAA( SalColor nColor );
bool UseLine(SalColor nColor, double fTransparency, GLfloat fLineWidth, bool bUseAA);
bool UseInvert50();
bool UseInvert(SalInvert nFlags);
......@@ -127,6 +128,9 @@ public:
void DrawRect( long nX, long nY, long nWidth, long nHeight );
void DrawRect( const Rectangle& rRect );
void DrawPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry );
void DrawLineSegment(float x1, float y1, float x2, float y2);
void DrawLineCap(float x1, float y1, float x2, float y2, css::drawing::LineCap eLineCap, float fLineWidth);
void DrawPolyLine( const basegfx::B2DPolygon& rPolygon, float fLineWidth, basegfx::B2DLineJoin eLineJoin, css::drawing::LineCap eLineCap);
void DrawPolyPolygon( const basegfx::B2DPolyPolygon& rPolyPolygon, bool blockAA = false );
void DrawRegionBand( const RegionBand& rRegion );
void DrawTextureRect( OpenGLTexture& rTexture, const SalTwoRect& rPosAry, bool bInverted = false );
......
This diff is collapsed.
/* -*- 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 float fade_factor; // 0->1 fade factor used for AA
uniform vec4 color;
uniform float line_width;
uniform float feather;
void main()
{
float start = (line_width / 2.0) - feather; // where we start to apply alpha
float end = (line_width / 2.0) + feather; // where we end to apply alpha
// Calculate the multiplier so we can transform the 0->1 fade factor
// to take feather and line width into account.
float multiplied = 1.0 / (1.0 - (start / end));
float dist = (1.0 - abs(fade_factor)) * multiplied;
float alpha = clamp(dist, 0.0, 1.0);
// modify the alpha chanel only
vec4 result_color = color;
result_color.a = result_color.a * alpha;
gl_FragColor = result_color;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- 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 vec2 position;
attribute vec4 extrusion_vectors;
varying float fade_factor; // fade factor for anti-aliasing
uniform float line_width;
uniform float feather; // width where we fade the line
uniform mat4 mvp;
void main()
{
vec2 extrusion_vector = extrusion_vectors.xy;
// miter factor to additionaly lenghten the distance of vertex (needed for miter)
// if 1.0 - miter_factor has no effect
float miter_factor = 1.0f / abs(extrusion_vectors.z);
// fade factor is always -1.0 or 1.0 -> we transport that info together with length
fade_factor = sign(extrusion_vectors.z);
float rendered_thickness = (line_width + feather * 2.0) * miter_factor;
// lengthen the vertex in directon of the extrusion vector by line width.
vec4 position = vec4(position + (extrusion_vector * (rendered_thickness / 2.0) ), 0.0, 1.0);
gl_Position = mvp * position;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -22,6 +22,7 @@ OpenGLProgram::OpenGLProgram() :
mnTexCoordAttrib( SAL_MAX_UINT32 ),
mnAlphaCoordAttrib( SAL_MAX_UINT32 ),
mnMaskCoordAttrib( SAL_MAX_UINT32 ),
mnNormalAttrib( SAL_MAX_UINT32 ),
mbBlending( false ),
mfLastWidth(0.0),
mfLastHeight(0.0),
......@@ -100,7 +101,7 @@ bool OpenGLProgram::Clean()
return true;
}
void OpenGLProgram::SetVertexAttrib( GLuint& rAttrib, const OString& rName, const GLvoid* pData )
void OpenGLProgram::SetVertexAttrib( GLuint& rAttrib, const OString& rName, const GLvoid* pData, GLint nSize )
{
if( rAttrib == SAL_MAX_UINT32 )
{
......@@ -113,7 +114,7 @@ void OpenGLProgram::SetVertexAttrib( GLuint& rAttrib, const OString& rName, cons
CHECK_GL_ERROR();
mnEnabledAttribs |= ( 1 << rAttrib );
}
glVertexAttribPointer( rAttrib, 2, GL_FLOAT, GL_FALSE, 0, pData );
glVertexAttribPointer( rAttrib, nSize, GL_FLOAT, GL_FALSE, 0, pData );
CHECK_GL_ERROR();
}
......@@ -137,6 +138,11 @@ void OpenGLProgram::SetMaskCoord(const GLvoid* pData)
SetVertexAttrib(mnMaskCoordAttrib, "mask_coord_in", pData);
}
void OpenGLProgram::SetExtrusionVectors(const GLvoid* pData)
{
SetVertexAttrib(mnNormalAttrib, "extrusion_vectors", pData, 3);
}
GLuint OpenGLProgram::GetUniformLocation( const OString& rName )
{
auto it = maUniformLocations.find( rName );
......
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