LibreOffice Module vcl (master)  1
RenderList.hxx
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 
11 #ifndef INCLUDED_VCL_INC_OPENGL_RENDERLIST_H
12 #define INCLUDED_VCL_INC_OPENGL_RENDERLIST_H
13 
14 #include <unordered_map>
15 
16 #include <glm/glm.hpp>
17 
18 #include <vcl/salgtype.hxx>
21 
22 #include <opengl/texture.hxx>
23 
24 #include <com/sun/star/drawing/LineCap.hpp>
25 
26 struct Vertex
27 {
28  glm::vec2 position;
29  glm::vec4 color;
30  glm::vec4 lineData;
31 };
32 
33 static_assert(sizeof(Vertex) == (2*4 + 4*4 + 4*4), "Vertex struct has wrong size/alignment");
34 
35 
37 {
38  std::vector<Vertex> maVertices;
39  std::vector<GLuint> maIndices;
40 };
41 
43 {
44  std::vector<GLfloat> maVertices;
45  std::vector<GLfloat> maTextureCoords;
46  std::vector<GLubyte> maColors;
48 };
49 
51 {
53 
56 
57  std::unordered_map<GLuint, RenderTextureParameters> maTextureParametersMap;
58 
59  bool hasTriangles() const
60  {
61  return !maTriangleParameters.maVertices.empty();
62  }
63 
64  bool hasLines() const
65  {
66  return !maLineParameters.maVertices.empty();
67  }
68 
69  bool hasTextures() const
70  {
71  return !maTextureParametersMap.empty();
72  }
73 };
74 
76 {
77 private:
78  std::vector<RenderEntry> maRenderEntries;
79  std::vector<basegfx::B2DRange> maRectangles;
80 
81  bool doesOverlap(const basegfx::B2DRange& rDrawRectangle)
82  {
83  if (!maRenderEntries.back().maOverlapTrackingRectangle.overlaps(rDrawRectangle))
84  return false;
85 
86  for (const basegfx::B2DRange& rRectangle : maRectangles)
87  {
88  if (rRectangle.overlaps(rDrawRectangle))
89  return true;
90  }
91  return false;
92  }
93 
94  void checkOverlapping(const basegfx::B2DRange& rDrawRectangle)
95  {
96  if (maRenderEntries.empty() || doesOverlap(rDrawRectangle))
97  {
98  maRenderEntries.emplace_back();
99  maRenderEntries.back().maOverlapTrackingRectangle = rDrawRectangle;
100 
101  maRectangles.clear();
102  maRectangles.reserve(30);
103  maRectangles.push_back(rDrawRectangle);
104  }
105  else
106  {
107  maRenderEntries.back().maOverlapTrackingRectangle.expand(rDrawRectangle);
108 
109  if (maRectangles.size() < 30)
110  {
111  maRectangles.push_back(rDrawRectangle);
112  }
113  else
114  {
115  basegfx::B2DRange aTempRectangle(maRectangles[0]);
116  aTempRectangle.expand(rDrawRectangle);
117  double minArea = aTempRectangle.getWidth() * aTempRectangle.getHeight();
118  size_t index = 0;
119 
120  double area;
121  for (size_t i = 1; i < maRectangles.size(); ++i)
122  {
123  aTempRectangle = maRectangles[i];
124  aTempRectangle.expand(rDrawRectangle);
125  area = aTempRectangle.getWidth() * aTempRectangle.getHeight();
126  if (area < minArea)
127  index = i;
128  }
129  maRectangles[index].expand(rDrawRectangle);
130  }
131  }
132  }
133 
134 public:
135 
136  RenderList() = default;
137 
138  bool empty()
139  {
140  return maRenderEntries.empty();
141  }
142 
143  void clear()
144  {
145  maRenderEntries.clear();
146  }
147 
148  std::vector<RenderEntry>& getEntries()
149  {
150  return maRenderEntries;
151  }
152 
153  void addDrawTextureWithMaskColor(OpenGLTexture const & rTexture, Color nColor, const SalTwoRect& r2Rect);
154 
155  void addDrawPixel(long nX, long nY, Color nColor);
156 
157  void addDrawRectangle(long nX, long nY, long nWidth, long nHeight, double fTransparency,
158  Color nLineColor, Color nFillColor);
159 
160  void addDrawLine(long nX1, long nY1, long nX2, long nY2, Color nLineColor, bool bUseAA);
161 
162  void addDrawPolyPolygon(const basegfx::B2DPolyPolygon& rPolyPolygon, double fTransparency,
163  Color nLineColor, Color nFillColor, bool bUseAA);
164 
165  void addDrawPolyLine(const basegfx::B2DPolygon& rPolygon, double fTransparency,
166  const basegfx::B2DVector& rLineWidth, basegfx::B2DLineJoin eLineJoin,
167  css::drawing::LineCap eLineCap, double fMiterMinimumAngle,
168  Color nLineColor, bool bUseAA);
169 };
170 
171 #endif // INCLUDED_VCL_INC_OPENGL_RENDERLIST_H
172 
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unordered_map< GLuint, RenderTextureParameters > maTextureParametersMap
Definition: RenderList.hxx:57
void expand(const B2DTuple &rTuple)
std::vector< GLfloat > maTextureCoords
Definition: RenderList.hxx:45
double getHeight() const
bool empty()
Definition: RenderList.hxx:138
bool doesOverlap(const basegfx::B2DRange &rDrawRectangle)
Definition: RenderList.hxx:81
void clear()
Definition: RenderList.hxx:143
bool hasTriangles() const
Definition: RenderList.hxx:59
bool hasTextures() const
Definition: RenderList.hxx:69
std::vector< Vertex > maVertices
Definition: RenderList.hxx:38
glm::vec3 position
double getWidth() const
basegfx::B2DRange maOverlapTrackingRectangle
Definition: RenderList.hxx:52
std::vector< GLuint > maIndices
Definition: RenderList.hxx:39
void addDrawTextureWithMaskColor(OpenGLTexture const &rTexture, Color nColor, const SalTwoRect &r2Rect)
std::vector< RenderEntry > & getEntries()
Definition: RenderList.hxx:148
int i
void checkOverlapping(const basegfx::B2DRange &rDrawRectangle)
Definition: RenderList.hxx:94
tuple index
void addDrawPolyLine(const basegfx::B2DPolygon &rPolygon, double fTransparency, const basegfx::B2DVector &rLineWidth, basegfx::B2DLineJoin eLineJoin, css::drawing::LineCap eLineCap, double fMiterMinimumAngle, Color nLineColor, bool bUseAA)
std::vector< basegfx::B2DRange > maRectangles
Definition: RenderList.hxx:79
void addDrawLine(long nX1, long nY1, long nX2, long nY2, Color nLineColor, bool bUseAA)
RenderParameters maLineParameters
Definition: RenderList.hxx:55
bool hasLines() const
Definition: RenderList.hxx:64
RenderParameters maTriangleParameters
Definition: RenderList.hxx:54
OpenGLTexture maTexture
Definition: RenderList.hxx:47
void addDrawRectangle(long nX, long nY, long nWidth, long nHeight, double fTransparency, Color nLineColor, Color nFillColor)
void addDrawPixel(long nX, long nY, Color nColor)
void addDrawPolyPolygon(const basegfx::B2DPolyPolygon &rPolyPolygon, double fTransparency, Color nLineColor, Color nFillColor, bool bUseAA)
std::vector< GLubyte > maColors
Definition: RenderList.hxx:46
std::vector< GLfloat > maVertices
Definition: RenderList.hxx:44
RenderList()=default
std::vector< RenderEntry > maRenderEntries
Definition: RenderList.hxx:78