cid#1607171 Data race condition
[LibreOffice.git] / canvas / source / opengl / ogl_canvastools.cxx
blob57aa686072b0b5f47c7b11d31da3da3ad3787f74
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <sal/config.h>
12 #include <epoxy/gl.h>
14 #include <basegfx/matrix/b2dhommatrix.hxx>
15 #include <basegfx/polygon/b2dpolygontriangulator.hxx>
16 #include <basegfx/polygon/b2dpolypolygon.hxx>
17 #include <basegfx/utils/tools.hxx>
18 #include <com/sun/star/rendering/ARGBColor.hpp>
20 #include "ogl_canvastools.hxx"
22 using namespace ::com::sun::star;
24 namespace oglcanvas
26 /// triangulates polygon before
27 void renderComplexPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly )
29 ::basegfx::B2DPolyPolygon aPolyPoly(rPolyPoly);
30 if( aPolyPoly.areControlPointsUsed() )
31 aPolyPoly = rPolyPoly.getDefaultAdaptiveSubdivision();
32 const ::basegfx::B2DRange aBounds(aPolyPoly.getB2DRange());
33 const double nWidth=aBounds.getWidth();
34 const double nHeight=aBounds.getHeight();
35 const ::basegfx::triangulator::B2DTriangleVector rTriangulatedPolygon(
36 ::basegfx::triangulator::triangulate(aPolyPoly));
38 for( auto const& rTriangulatedPolygonItem : rTriangulatedPolygon )
40 const::basegfx::triangulator::B2DTriangle& rCandidate(rTriangulatedPolygonItem);
41 glTexCoord2f(
42 rCandidate.getA().getX()/nWidth,
43 rCandidate.getA().getY()/nHeight);
44 glVertex2d(
45 rCandidate.getA().getX(),
46 rCandidate.getA().getY());
48 glTexCoord2f(
49 rCandidate.getB().getX()/nWidth,
50 rCandidate.getB().getY()/nHeight);
51 glVertex2d(
52 rCandidate.getB().getX(),
53 rCandidate.getB().getY());
55 glTexCoord2f(
56 rCandidate.getC().getX()/nWidth,
57 rCandidate.getC().getY()/nHeight);
58 glVertex2d(
59 rCandidate.getC().getX(),
60 rCandidate.getC().getY());
64 /** only use this for line polygons.
66 better not leave triangulation to OpenGL. also, ignores texturing
68 void renderPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly )
70 ::basegfx::B2DPolyPolygon aPolyPoly(rPolyPoly);
71 if( aPolyPoly.areControlPointsUsed() )
72 aPolyPoly = rPolyPoly.getDefaultAdaptiveSubdivision();
74 for( sal_uInt32 i=0; i<aPolyPoly.count(); i++ )
76 glBegin(GL_LINE_STRIP);
78 const ::basegfx::B2DPolygon& rPolygon( aPolyPoly.getB2DPolygon(i) );
80 const sal_uInt32 nPts=rPolygon.count();
81 const sal_uInt32 nExtPts=nPts + int(rPolygon.isClosed());
82 for( sal_uInt32 j=0; j<nExtPts; j++ )
84 const ::basegfx::B2DPoint& rPt( rPolygon.getB2DPoint( j % nPts ) );
85 glVertex2d(rPt.getX(), rPt.getY());
88 glEnd();
92 void setupState( const ::basegfx::B2DHomMatrix& rTransform,
93 GLenum eSrcBlend,
94 GLenum eDstBlend,
95 const rendering::ARGBColor& rColor )
97 double aGLTransform[] =
99 rTransform.get(0,0), rTransform.get(1,0), 0, 0,
100 rTransform.get(0,1), rTransform.get(1,1), 0, 0,
101 0, 0, 1, 0,
102 rTransform.get(0,2), rTransform.get(1,2), 0, 1
104 glMultMatrixd(aGLTransform);
106 glEnable(GL_BLEND);
107 glBlendFunc(eSrcBlend, eDstBlend);
109 glColor4d(rColor.Red,
110 rColor.Green,
111 rColor.Blue,
112 rColor.Alpha);
114 // GL 1.2:
115 // glBlendEquation( GLenum mode );
116 // glBlendColor( GLclampf red, GLclampf green,GLclampf blue, GLclampf alpha );
117 // glConvolutionFilter1D
118 // glConvolutionFilter2D
119 // glSeparableFilter2D
122 void renderOSD( const std::vector<double>& rNumbers, double scale )
124 double y=4.0;
125 basegfx::B2DHomMatrix aTmp;
126 basegfx::B2DHomMatrix aScaleShear;
127 aScaleShear.shearX(-0.1);
128 aScaleShear.scale(scale,scale);
130 for(double rNumber : rNumbers)
132 aTmp.identity();
133 aTmp.translate(0,y);
134 y += 1.2*scale;
136 basegfx::B2DPolyPolygon aPoly=
137 basegfx::utils::number2PolyPolygon(rNumber,10,3);
139 aTmp=aTmp*aScaleShear;
140 aPoly.transform(aTmp);
142 glColor4f(0,1,0,1);
143 renderPolyPolygon(aPoly);
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */