summaryrefslogtreecommitdiff
path: root/vcl/inc/opengl
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2016-05-29 12:37:41 +0900
committerTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2016-06-08 11:39:22 +0900
commit344dc6939c45552dc162ea8b3f892e2ae4998d64 (patch)
treec7cb883e535ec3df4b2b0cdff9b5e104a68c954d /vcl/inc/opengl
parentd0ec6c7b72f5826b9645c997b03d6f032b4f72f7 (diff)
opengl: batch drawing of pixel, line, rect draw calls
Change-Id: Ib1619fa476f488c5315411b1ad4d1b7464c70c69
Diffstat (limited to 'vcl/inc/opengl')
-rw-r--r--vcl/inc/opengl/RenderList.hxx98
-rw-r--r--vcl/inc/opengl/VertexUtils.hxx38
-rw-r--r--vcl/inc/opengl/program.hxx6
-rw-r--r--vcl/inc/opengl/texture.hxx6
4 files changed, 147 insertions, 1 deletions
diff --git a/vcl/inc/opengl/RenderList.hxx b/vcl/inc/opengl/RenderList.hxx
new file mode 100644
index 000000000000..0ba977a232a9
--- /dev/null
+++ b/vcl/inc/opengl/RenderList.hxx
@@ -0,0 +1,98 @@
+/* -*- 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 <glm/glm.hpp>
+
+#include <vcl/opengl/OpenGLHelper.hxx>
+#include <vcl/salgtype.hxx>
+#include <basegfx/range/b2drange.hxx>
+
+struct RenderParameters
+{
+ std::vector<GLfloat> maVertices;
+ std::vector<GLfloat> maExtrusionVectors;
+ std::vector<glm::vec4> maColors;
+};
+
+struct RenderEntry
+{
+ RenderParameters maTriangleParameters;
+ RenderParameters maLineParameters;
+ RenderParameters maLineAAParameters;
+
+ bool hasTriangles()
+ {
+ return !maTriangleParameters.maVertices.empty();
+ }
+
+ bool hasLines()
+ {
+ return !maLineParameters.maVertices.empty();
+ }
+
+ bool hasLinesAA()
+ {
+ return !maLineAAParameters.maVertices.empty();
+ }
+};
+
+class RenderList
+{
+private:
+ basegfx::B2DRange maOverlapTrackingRectangle;
+ std::vector<RenderEntry> maRenderEntries;
+
+ void checkOverlapping(const basegfx::B2DRange& rDrawRectangle)
+ {
+ if (maRenderEntries.empty() || maOverlapTrackingRectangle.overlaps(rDrawRectangle))
+ {
+ maRenderEntries.resize(maRenderEntries.size() + 1);
+ maOverlapTrackingRectangle = rDrawRectangle;
+ }
+ else
+ {
+ maOverlapTrackingRectangle.expand(rDrawRectangle);
+ }
+ }
+
+public:
+
+ RenderList() = default;
+
+ bool empty()
+ {
+ return maRenderEntries.empty();
+ }
+
+ void clear()
+ {
+ maRenderEntries.clear();
+ maOverlapTrackingRectangle.reset();
+ }
+
+ std::vector<RenderEntry>& getEntries()
+ {
+ return maRenderEntries;
+ }
+
+ void addDrawPixel(long nX, long nY, const SalColor& rColor);
+
+ void addDrawRectangle(long nX, long nY, long nWidth, long nHeight,
+ const SalColor& rLineColor, const SalColor& rFillColor);
+
+ void addDrawLine(long nX1, long nY1, long nX2, long nY2, const SalColor& rLineColor, bool bUseAA);
+};
+
+#endif // INCLUDED_VCL_INC_OPENGL_RENDERLIST_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/opengl/VertexUtils.hxx b/vcl/inc/opengl/VertexUtils.hxx
index becc62ba229e..c64340b4a5e4 100644
--- a/vcl/inc/opengl/VertexUtils.hxx
+++ b/vcl/inc/opengl/VertexUtils.hxx
@@ -39,6 +39,44 @@ inline void addRectangle<GL_TRIANGLE_FAN>(std::vector<GLfloat>& rVertices, GLflo
});
}
+inline glm::vec4 createGLColor(const SalColor& rColor, GLfloat rTransparency)
+{
+ return glm::vec4(SALCOLOR_RED(rColor) / 255.0f,
+ SALCOLOR_GREEN(rColor) / 255.0f,
+ SALCOLOR_BLUE(rColor) / 255.0f,
+ 1.0f - rTransparency);
+}
+
+template<GLenum TYPE>
+inline void addQuadColors(std::vector<glm::vec4>& rColors, const SalColor& rColor, GLfloat rTransparency);
+
+template<>
+inline void addQuadColors<GL_TRIANGLES>(std::vector<glm::vec4>& rColors, const SalColor& rColor, GLfloat rTransparency)
+{
+ glm::vec4 color = createGLColor(rColor, rTransparency);
+
+ rColors.insert(rColors.end(), {
+ color, color, color,
+ color, color, color
+ });
+}
+
+template<GLenum TYPE>
+inline void addQuadEmptyExtrusionVectors(std::vector<GLfloat>& rExtrusions);
+
+template<>
+inline void addQuadEmptyExtrusionVectors<GL_TRIANGLES>(std::vector<GLfloat>& rExtrusions)
+{
+ rExtrusions.insert(rExtrusions.end(), {
+ 0.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 0.0f,
+ });
+}
+
inline void addLineVertex(std::vector<GLfloat>& rVertices, std::vector<GLfloat>& rExtrusionVectors, glm::vec2 point, glm::vec2 extrusionVector, float length)
{
rVertices.push_back(point.x);
diff --git a/vcl/inc/opengl/program.hxx b/vcl/inc/opengl/program.hxx
index 3c194d887ba9..c737c1250aaa 100644
--- a/vcl/inc/opengl/program.hxx
+++ b/vcl/inc/opengl/program.hxx
@@ -22,6 +22,7 @@
#include <tools/color.hxx>
#include <opengl/texture.hxx>
+#include <glm/glm.hpp>
#include <unordered_map>
typedef std::unordered_map< OString, GLuint, OStringHash > UniformCache;
@@ -52,7 +53,9 @@ private:
GLuint mnTexCoordAttrib;
GLuint mnAlphaCoordAttrib;
GLuint mnMaskCoordAttrib;
- GLuint mnNormalAttrib;
+ GLuint mnExtrusionVectorsAttrib;
+ GLuint mnVertexColorsAttrib;
+
TextureList maTextures;
bool mbBlending;
@@ -79,6 +82,7 @@ public:
void SetAlphaCoord( const GLvoid* pData );
void SetMaskCoord(const GLvoid* pData);
void SetExtrusionVectors(const GLvoid* pData);
+ void SetVertexColors(std::vector<glm::vec4>& rColorVector);
void SetUniform1f( const OString& rName, GLfloat v1 );
void SetUniform2f( const OString& rName, GLfloat v1, GLfloat v2 );
diff --git a/vcl/inc/opengl/texture.hxx b/vcl/inc/opengl/texture.hxx
index 5b4ccffd6149..e120c080ffa1 100644
--- a/vcl/inc/opengl/texture.hxx
+++ b/vcl/inc/opengl/texture.hxx
@@ -78,6 +78,8 @@ private:
ImplOpenGLTexture* mpImpl;
int mnSlotNumber;
+ inline bool GetTextureRect(const SalTwoRect& rPosAry, bool bInverted, GLfloat& x1, GLfloat& x2, GLfloat& y1, GLfloat& y2) const;
+
public:
OpenGLTexture();
OpenGLTexture(ImplOpenGLTexture* pImpl, Rectangle aRectangle, int nSlotNumber);
@@ -124,6 +126,10 @@ template<> void OpenGLTexture::FillCoords<GL_TRIANGLES>(
std::vector<GLfloat>& aCoord, const SalTwoRect& rPosAry, bool bInverted)
const;
+template<> void OpenGLTexture::FillCoords<GL_TRIANGLE_FAN>(
+ std::vector<GLfloat>& aCoord, const SalTwoRect& rPosAry, bool bInverted)
+ const;
+
#endif // INCLUDED_VCL_INC_OPENGL_TEXTURE_H
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */