summaryrefslogtreecommitdiffstats
path: root/vcl/inc/opengl/RenderList.hxx
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
commit940b4d1848e8c70ab7642901a68594e8016caffc (patch)
treeeb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /vcl/inc/opengl/RenderList.hxx
parentInitial commit. (diff)
downloadlibreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz
libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vcl/inc/opengl/RenderList.hxx')
-rw-r--r--vcl/inc/opengl/RenderList.hxx173
1 files changed, 173 insertions, 0 deletions
diff --git a/vcl/inc/opengl/RenderList.hxx b/vcl/inc/opengl/RenderList.hxx
new file mode 100644
index 000000000..213a2f43b
--- /dev/null
+++ b/vcl/inc/opengl/RenderList.hxx
@@ -0,0 +1,173 @@
+/* -*- 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/.
+ *
+ */
+
+#ifndef INCLUDED_VCL_INC_OPENGL_RENDERLIST_H
+#define INCLUDED_VCL_INC_OPENGL_RENDERLIST_H
+
+#include <unordered_map>
+
+#include <glm/glm.hpp>
+
+#include <vcl/salgtype.hxx>
+#include <basegfx/range/b2drange.hxx>
+#include <basegfx/polygon/b2dpolypolygon.hxx>
+
+#include <opengl/texture.hxx>
+
+#include <com/sun/star/drawing/LineCap.hpp>
+
+struct Vertex
+{
+ glm::vec2 position;
+ glm::vec4 color;
+ glm::vec4 lineData;
+};
+
+static_assert(sizeof(Vertex) == (2*4 + 4*4 + 4*4), "Vertex struct has wrong size/alignment");
+
+
+struct RenderParameters
+{
+ std::vector<Vertex> maVertices;
+ std::vector<GLuint> maIndices;
+};
+
+struct RenderTextureParameters
+{
+ std::vector<GLfloat> maVertices;
+ std::vector<GLfloat> maTextureCoords;
+ std::vector<GLubyte> maColors;
+ OpenGLTexture maTexture;
+};
+
+struct RenderEntry
+{
+ basegfx::B2DRange maOverlapTrackingRectangle;
+
+ RenderParameters maTriangleParameters;
+ RenderParameters maLineParameters;
+
+ std::unordered_map<GLuint, RenderTextureParameters> maTextureParametersMap;
+
+ bool hasTriangles() const
+ {
+ return !maTriangleParameters.maVertices.empty();
+ }
+
+ bool hasLines() const
+ {
+ return !maLineParameters.maVertices.empty();
+ }
+
+ bool hasTextures() const
+ {
+ return !maTextureParametersMap.empty();
+ }
+};
+
+class RenderList
+{
+private:
+ std::vector<RenderEntry> maRenderEntries;
+ std::vector<basegfx::B2DRange> maRectangles;
+
+ bool doesOverlap(const basegfx::B2DRange& rDrawRectangle)
+ {
+ if (!maRenderEntries.back().maOverlapTrackingRectangle.overlaps(rDrawRectangle))
+ return false;
+
+ for (const basegfx::B2DRange& rRectangle : maRectangles)
+ {
+ if (rRectangle.overlaps(rDrawRectangle))
+ return true;
+ }
+ return false;
+ }
+
+ void checkOverlapping(const basegfx::B2DRange& rDrawRectangle)
+ {
+ if (maRenderEntries.empty() || doesOverlap(rDrawRectangle))
+ {
+ maRenderEntries.emplace_back();
+ maRenderEntries.back().maOverlapTrackingRectangle = rDrawRectangle;
+
+ maRectangles.clear();
+ maRectangles.reserve(30);
+ maRectangles.push_back(rDrawRectangle);
+ }
+ else
+ {
+ maRenderEntries.back().maOverlapTrackingRectangle.expand(rDrawRectangle);
+
+ if (maRectangles.size() < 30)
+ {
+ maRectangles.push_back(rDrawRectangle);
+ }
+ else
+ {
+ basegfx::B2DRange aTempRectangle(maRectangles[0]);
+ aTempRectangle.expand(rDrawRectangle);
+ double minArea = aTempRectangle.getWidth() * aTempRectangle.getHeight();
+ size_t index = 0;
+
+ double area;
+ for (size_t i = 1; i < maRectangles.size(); ++i)
+ {
+ aTempRectangle = maRectangles[i];
+ aTempRectangle.expand(rDrawRectangle);
+ area = aTempRectangle.getWidth() * aTempRectangle.getHeight();
+ if (area < minArea)
+ index = i;
+ }
+ maRectangles[index].expand(rDrawRectangle);
+ }
+ }
+ }
+
+public:
+
+ RenderList() = default;
+
+ bool empty()
+ {
+ return maRenderEntries.empty();
+ }
+
+ void clear()
+ {
+ maRenderEntries.clear();
+ }
+
+ std::vector<RenderEntry>& getEntries()
+ {
+ return maRenderEntries;
+ }
+
+ VCL_DLLPUBLIC void addDrawTextureWithMaskColor(OpenGLTexture const & rTexture, Color nColor, const SalTwoRect& r2Rect);
+
+ void addDrawPixel(long nX, long nY, Color nColor);
+
+ void addDrawRectangle(long nX, long nY, long nWidth, long nHeight, double fTransparency,
+ Color nLineColor, Color nFillColor);
+
+ void addDrawLine(long nX1, long nY1, long nX2, long nY2, Color nLineColor, bool bUseAA);
+
+ void addDrawPolyPolygon(const basegfx::B2DPolyPolygon& rPolyPolygon, double fTransparency,
+ Color nLineColor, Color nFillColor, bool bUseAA);
+
+ void addDrawPolyLine(const basegfx::B2DPolygon& rPolygon, double fTransparency,
+ double fLineWidth, basegfx::B2DLineJoin eLineJoin,
+ css::drawing::LineCap eLineCap, double fMiterMinimumAngle,
+ Color nLineColor, bool bUseAA);
+};
+
+#endif // INCLUDED_VCL_INC_OPENGL_RENDERLIST_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */