1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #ifndef INCLUDED_CHART2_SOURCE_VIEW_INC_GL3DBARCHART_HXX
11 #define INCLUDED_CHART2_SOURCE_VIEW_INC_GL3DBARCHART_HXX
13 #include "GL3DPlotterBase.hxx"
18 #include "VDataSeries.hxx"
20 #include <glm/glm.hpp>
22 #include <vcl/timer.hxx>
23 #include <vcl/idle.hxx>
24 #include <vcl/openglwin.hxx>
26 #include <rtl/ref.hxx>
27 #include <salhelper/thread.hxx>
28 #include <osl/conditn.hxx>
32 class ExplicitCategoriesProvider
;
36 class Renderable3DObject
;
37 class OpenGL3DRenderer
;
47 EVENT_MOVE_TO_DEFAULT
,
54 EVENT_SELECTBAR_UPDEDATE
58 class RenderOneFrameThread
;
59 class RenderAnimationThread
;
61 class GL3DBarChart
: public GL3DPlotterBase
, public IRenderer
63 friend class RenderThread
;
64 friend class RenderOneFrameThread
;
65 friend class RenderAnimationThread
;
66 friend class RenderBenchMarkThread
;
69 const css::uno::Reference
<css::chart2::XChartType
>& xChartType
,
70 OpenGLWindow
* pContext
);
72 virtual ~GL3DBarChart() override
;
74 virtual void create3DShapes(const std::vector
<std::unique_ptr
<VDataSeries
>>& rDataSeries
,
75 ExplicitCategoriesProvider
& rCatProvider
) override
;
77 virtual void render() override
;
79 /// Render one frame of the 3D bar chart.
82 virtual void update() override
;
84 /// Draw to the framebuffer context, and provide the ID of the bar that the user has clicked.
85 sal_uInt32
barIdAtPosition(const Point
& rPos
);
86 virtual void clickedAt(const Point
& rPos
, sal_uInt16 nButtons
) override
;
88 virtual void mouseDragMove(const Point
& rStartPos
, const Point
& rEndPos
, sal_uInt16 nButtons
) override
;
89 virtual void scroll(long nDelta
) override
;
90 virtual void contextDestroyed() override
;
92 void setOpenGLWindow(OpenGLWindow
* pWindow
);
96 void spawnRenderThread(RenderThread
*pThread
);
97 void joinRenderThread();
100 glm::vec3
getCornerPosition(sal_Int8 nCornerId
);
101 void updateScreenText();
102 void updateRenderFPS();
103 void updateDataUpdateFPS();
104 DECL_LINK(UpdateTimerHdl
, Timer
*, void);
105 static int calcTimeInterval(TimeValue
const &startTime
, TimeValue
const &endTime
);
106 float addScreenTextShape(OUString
&nStr
, const glm::vec2
& rLeftOrRightTop
, float nTextHeight
, bool bLeftTopFlag
,
107 const glm::vec4
& rColor
,
108 const glm::vec3
& rPos
= glm::vec3(0.0f
, 0.0f
, 0.0f
),
109 sal_uInt32 nEvent
= 0);
110 void recordBarHistory(sal_uInt32 nBarID
, float nVal
);
111 void updateClickEvent();
112 void calcDistance(std::vector
<sal_uInt32
> &vectorNearest
);
113 static float calcScrollDistance(const glm::mat4
&mvp
, const glm::vec3
& rPos
);
114 void initDistanceHeap(std::vector
<sal_uInt32
> &vectorNearest
);
115 void keepHeap(std::vector
<sal_uInt32
> &vectorNearest
, int index
);
116 static void swapVector(int i
, int j
, std::vector
<sal_uInt32
> &vectorNearest
);
117 void getNearestBars(std::vector
<sal_uInt32
> &vectorNearest
);
119 void processAutoFly(sal_uInt32 nId
, Color nColor
);
120 void getNeighborBarID(sal_uInt32 nSelectBarId
, sal_uInt32
*pNeighborBarId
);
121 void addMovementScreenText(sal_uInt32 nBarId
);
122 css::uno::Reference
<css::chart2::XChartType
> mxChartType
;
123 std::vector
<std::unique_ptr
<opengl3D::Renderable3DObject
> > maShapes
;
125 std::unique_ptr
<opengl3D::OpenGL3DRenderer
> mpRenderer
;
126 VclPtr
<OpenGLWindow
> mpWindow
;
128 opengl3D::Camera
* mpCamera
;
131 std::unique_ptr
<opengl3D::TextCache
> mpTextCache
;
133 glm::vec3 maCameraPosition
;
134 glm::vec3 maCameraDirection
;
136 glm::vec3 maDefaultCameraPosition
;
137 glm::vec3 maDefaultCameraDirection
;
143 * 0 = corner at (0,0,0);
144 * numbering counter clockwise
148 std::vector
<OUString
> maCategories
;
149 std::vector
<OUString
> maSeriesNames
;
150 struct BarInformation
155 BarInformation(const glm::vec3
& rPos
, float nVal
);
158 std::map
<sal_uInt32
, const BarInformation
> maBarMap
;
159 bool mbNeedsNewRender
;
163 rtl::Reference
<RenderThread
> mpRenderThread
;
165 ::osl::Condition maClickCond
;
166 RenderEventType maRenderEvent
;
167 RenderEventType maPreRenderEvent
;
168 sal_uInt32 mnSelectBarId
;
169 sal_uInt32 mnPreSelectBarId
;
171 sal_uInt32 miScrollRate
;
174 bool mbScreenTextNewRender
;
175 std::vector
<std::unique_ptr
<opengl3D::Renderable3DObject
>> maScreenTextShapes
;
177 OUString maDataUpdateFPS
;
178 sal_uInt32 miFrameCount
;
179 sal_uInt32 miDataUpdateCounter
;
180 TimeValue maFPSRenderStartTime
;
181 TimeValue maFPSRenderEndTime
;
182 TimeValue maDataUpdateStartTime
;
183 TimeValue maDataUpdateEndTime
;
184 std::map
<sal_uInt32
, std::deque
<float> > maBarHistory
;
185 std::vector
<sal_uInt32
> maVectorNearest
;
186 std::map
<sal_uInt32
, float> maDistanceMap
;
187 std::map
<sal_uInt32
, Color
> maBarColorMap
;
189 bool mbBenchMarkMode
;
190 sal_uInt32 mnHistoryCounter
;
191 sal_uInt32 mnBarsInRow
;
193 sal_Int32 mnUpdateBarId
;
195 // these form a pair:
196 // main thread sets condition 1 and waits until it can take the mutex
197 // render thread checks condition 1 before taking the mutex and waits in case it
198 // is set until condition 2 is set
200 // only necessary for the benchmark mode
201 osl::Condition maCond1
;
202 osl::Condition maCond2
;
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */