LibreOffice Module canvas (master) 1
ogl_canvastools.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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 */
9
10#include <sal/config.h>
11
12#include <epoxy/gl.h>
13
18#include <com/sun/star/rendering/ARGBColor.hpp>
19
20#include "ogl_canvastools.hxx"
21
22using namespace ::com::sun::star;
23
24namespace oglcanvas
25{
27 void renderComplexPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly )
28 {
29 ::basegfx::B2DPolyPolygon aPolyPoly(rPolyPoly);
30 if( aPolyPoly.areControlPointsUsed() )
31 aPolyPoly = rPolyPoly.getDefaultAdaptiveSubdivision();
32 const ::basegfx::B2DRange& rBounds(aPolyPoly.getB2DRange());
33 const double nWidth=rBounds.getWidth();
34 const double nHeight=rBounds.getHeight();
35 const ::basegfx::triangulator::B2DTriangleVector rTriangulatedPolygon(
36 ::basegfx::triangulator::triangulate(aPolyPoly));
37
38 for( auto const& rTriangulatedPolygonItem : rTriangulatedPolygon )
39 {
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());
47
48 glTexCoord2f(
49 rCandidate.getB().getX()/nWidth,
50 rCandidate.getB().getY()/nHeight);
51 glVertex2d(
52 rCandidate.getB().getX(),
53 rCandidate.getB().getY());
54
55 glTexCoord2f(
56 rCandidate.getC().getX()/nWidth,
57 rCandidate.getC().getY()/nHeight);
58 glVertex2d(
59 rCandidate.getC().getX(),
60 rCandidate.getC().getY());
61 }
62 }
63
68 void renderPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly )
69 {
70 ::basegfx::B2DPolyPolygon aPolyPoly(rPolyPoly);
71 if( aPolyPoly.areControlPointsUsed() )
72 aPolyPoly = rPolyPoly.getDefaultAdaptiveSubdivision();
73
74 for( sal_uInt32 i=0; i<aPolyPoly.count(); i++ )
75 {
76 glBegin(GL_LINE_STRIP);
77
78 const ::basegfx::B2DPolygon& rPolygon( aPolyPoly.getB2DPolygon(i) );
79
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++ )
83 {
84 const ::basegfx::B2DPoint& rPt( rPolygon.getB2DPoint( j % nPts ) );
85 glVertex2d(rPt.getX(), rPt.getY());
86 }
87
88 glEnd();
89 }
90 }
91
92 void setupState( const ::basegfx::B2DHomMatrix& rTransform,
93 GLenum eSrcBlend,
94 GLenum eDstBlend,
95 const rendering::ARGBColor& rColor )
96 {
97 double aGLTransform[] =
98 {
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
103 };
104 glMultMatrixd(aGLTransform);
105
106 glEnable(GL_BLEND);
107 glBlendFunc(eSrcBlend, eDstBlend);
108
109 glColor4d(rColor.Red,
110 rColor.Green,
111 rColor.Blue,
112 rColor.Alpha);
113
114 // GL 1.2:
115 // glBlendEquation( GLenum mode );
116 // glBlendColor( GLclampf red, GLclampf green,GLclampf blue, GLclampf alpha );
117 // glConvolutionFilter1D
118 // glConvolutionFilter2D
119 // glSeparableFilter2D
120 }
121
122 void renderOSD( const std::vector<double>& rNumbers, double scale )
123 {
124 double y=4.0;
126 basegfx::B2DHomMatrix aScaleShear;
127 aScaleShear.shearX(-0.1);
128 aScaleShear.scale(scale,scale);
129
130 for(double rNumber : rNumbers)
131 {
132 aTmp.identity();
133 aTmp.translate(0,y);
134 y += 1.2*scale;
135
138
139 aTmp=aTmp*aScaleShear;
140 aPoly.transform(aTmp);
141
142 glColor4f(0,1,0,1);
143 renderPolyPolygon(aPoly);
144 }
145 }
146}
147
148/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void shearX(double fSx)
void translate(double fX, double fY)
void scale(double fX, double fY)
B2DPolygon const & getB2DPolygon(sal_uInt32 nIndex) const
void transform(const basegfx::B2DHomMatrix &rMatrix)
B2DRange getB2DRange() const
bool areControlPointsUsed() const
sal_uInt32 count() const
B2DPolyPolygon getDefaultAdaptiveSubdivision() const
float y
Definition: dx_9rm.cxx:190
B2DPolyPolygon number2PolyPolygon(double fVal, sal_Int32 nTotalDigits, sal_Int32 nDecPlaces, bool bLitSegments=true)
int i
void renderComplexPolyPolygon(const ::basegfx::B2DPolyPolygon &rPolyPoly)
triangulates polygon before
void renderOSD(const std::vector< double > &rNumbers, double scale)
void setupState(const ::basegfx::B2DHomMatrix &rTransform, GLenum eSrcBlend, GLenum eDstBlend, const rendering::ARGBColor &rColor)
void renderPolyPolygon(const ::basegfx::B2DPolyPolygon &rPolyPoly)
only use this for line polygons.
sal_Int32 scale
const wchar_t *typedef int(__stdcall *DllNativeUnregProc)(int