bump product version to 6.4.0.3
[LibreOffice.git] / vcl / inc / opengl / VertexUtils.hxx
blob910b8725a1e9416d7e8781b645de281b3b3996de
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
9 */
11 #ifndef INCLUDED_VCL_INC_OPENGL_VERTEXUTILS_H
12 #define INCLUDED_VCL_INC_OPENGL_VERTEXUTILS_H
14 #include <basegfx/numeric/ftools.hxx>
15 #include <epoxy/gl.h>
16 #include <glm/gtx/norm.hpp>
17 #include <tools/color.hxx>
18 #include <vector>
20 namespace vcl
22 namespace vertex
25 template<GLenum TYPE>
26 inline void addRectangle(std::vector<GLfloat>& rVertices, GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2);
28 template<>
29 inline void addRectangle<GL_TRIANGLES>(std::vector<GLfloat>& rVertices, GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
31 rVertices.insert(rVertices.end(), {
32 x1, y1, x2, y1, x1, y2,
33 x1, y2, x2, y1, x2, y2
34 });
37 template<>
38 inline void addRectangle<GL_TRIANGLE_FAN>(std::vector<GLfloat>& rVertices, GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
40 rVertices.insert(rVertices.end(), {
41 x1, y2, x1, y1,
42 x2, y1, x2, y2
43 });
46 inline void createColor(Color nColor, GLfloat fTransparency, GLubyte& nR, GLubyte& nG, GLubyte& nB, GLubyte& nA)
48 nR = nColor.GetRed();
49 nG = nColor.GetGreen();
50 nB = nColor.GetBlue();
51 nA = (1.0f - fTransparency) * 255.0f;
54 template<GLenum TYPE>
55 inline void addQuadColors(std::vector<GLubyte>& rColors, Color nColor, GLfloat fTransparency);
57 template<>
58 inline void addQuadColors<GL_TRIANGLES>(std::vector<GLubyte>& rColors, Color nColor, GLfloat fTransparency)
60 GLubyte nR, nG, nB, nA;
61 createColor(nColor, fTransparency, nR, nG, nB, nA);
63 rColors.insert(rColors.end(), {
64 nR, nG, nB, nA,
65 nR, nG, nB, nA,
66 nR, nG, nB, nA,
67 nR, nG, nB, nA,
68 nR, nG, nB, nA,
69 nR, nG, nB, nA,
70 });
73 inline void addLineSegmentVertices(std::vector<GLfloat>& rVertices, std::vector<GLfloat>& rExtrusionVectors,
74 glm::vec2 prevPoint, glm::vec2 prevExtrusionVector, GLfloat prevLength,
75 glm::vec2 currPoint, glm::vec2 currExtrusionVector, GLfloat currLength)
77 rVertices.insert(rVertices.end(), {
78 prevPoint.x, prevPoint.y,
79 prevPoint.x, prevPoint.y,
80 currPoint.x, currPoint.y,
81 currPoint.x, currPoint.y,
82 prevPoint.x, prevPoint.y,
83 currPoint.x, currPoint.y,
84 });
86 rExtrusionVectors.insert(rExtrusionVectors.end(), {
87 -prevExtrusionVector.x, -prevExtrusionVector.y, -prevLength,
88 prevExtrusionVector.x, prevExtrusionVector.y, prevLength,
89 -currExtrusionVector.x, -currExtrusionVector.y, -currLength,
90 -currExtrusionVector.x, -currExtrusionVector.y, -currLength,
91 prevExtrusionVector.x, prevExtrusionVector.y, prevLength,
92 currExtrusionVector.x, currExtrusionVector.y, currLength,
93 });
96 inline glm::vec2 normalize(const glm::vec2& vector)
98 if (glm::length(vector) > 0.0)
99 return glm::normalize(vector);
100 return vector;
103 inline glm::vec2 perpendicular(const glm::vec2& vector)
105 return glm::vec2(-vector.y, vector.x);
108 inline float lineVectorAngle(const glm::vec2& previous, const glm::vec2& next)
110 float angle = std::atan2(previous.x * next.y - previous.y * next.x,
111 previous.x * next.x + previous.y * next.y);
113 return F_PI - std::fabs(angle);
116 }} // end vcl::vertex
118 #endif // INCLUDED_VCL_INC_OPENGL_VERTEXUTILS_H
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */