nss: upgrade to release 3.73
[LibreOffice.git] / vcl / inc / opengl / VertexUtils.hxx
blob9589d0e85775c956b6ac6f6630a199b30e60dde7
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::vertex
23 template<GLenum TYPE>
24 inline void addRectangle(std::vector<GLfloat>& rVertices, GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2);
26 template<>
27 inline void addRectangle<GL_TRIANGLES>(std::vector<GLfloat>& rVertices, GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
29 rVertices.insert(rVertices.end(), {
30 x1, y1, x2, y1, x1, y2,
31 x1, y2, x2, y1, x2, y2
32 });
35 template<>
36 inline void addRectangle<GL_TRIANGLE_FAN>(std::vector<GLfloat>& rVertices, GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
38 rVertices.insert(rVertices.end(), {
39 x1, y2, x1, y1,
40 x2, y1, x2, y2
41 });
44 inline void createColor(Color nColor, GLfloat fTransparency, GLubyte& nR, GLubyte& nG, GLubyte& nB, GLubyte& nA)
46 nR = nColor.GetRed();
47 nG = nColor.GetGreen();
48 nB = nColor.GetBlue();
49 nA = (1.0f - fTransparency) * 255.0f;
52 template<GLenum TYPE>
53 inline void addQuadColors(std::vector<GLubyte>& rColors, Color nColor, GLfloat fTransparency);
55 template<>
56 inline void addQuadColors<GL_TRIANGLES>(std::vector<GLubyte>& rColors, Color nColor, GLfloat fTransparency)
58 GLubyte nR, nG, nB, nA;
59 createColor(nColor, fTransparency, nR, nG, nB, nA);
61 rColors.insert(rColors.end(), {
62 nR, nG, nB, nA,
63 nR, nG, nB, nA,
64 nR, nG, nB, nA,
65 nR, nG, nB, nA,
66 nR, nG, nB, nA,
67 nR, nG, nB, nA,
68 });
71 inline void addLineSegmentVertices(std::vector<GLfloat>& rVertices, std::vector<GLfloat>& rExtrusionVectors,
72 glm::vec2 prevPoint, glm::vec2 prevExtrusionVector, GLfloat prevLength,
73 glm::vec2 currPoint, glm::vec2 currExtrusionVector, GLfloat currLength)
75 rVertices.insert(rVertices.end(), {
76 prevPoint.x, prevPoint.y,
77 prevPoint.x, prevPoint.y,
78 currPoint.x, currPoint.y,
79 currPoint.x, currPoint.y,
80 prevPoint.x, prevPoint.y,
81 currPoint.x, currPoint.y,
82 });
84 rExtrusionVectors.insert(rExtrusionVectors.end(), {
85 -prevExtrusionVector.x, -prevExtrusionVector.y, -prevLength,
86 prevExtrusionVector.x, prevExtrusionVector.y, prevLength,
87 -currExtrusionVector.x, -currExtrusionVector.y, -currLength,
88 -currExtrusionVector.x, -currExtrusionVector.y, -currLength,
89 prevExtrusionVector.x, prevExtrusionVector.y, prevLength,
90 currExtrusionVector.x, currExtrusionVector.y, currLength,
91 });
94 inline glm::vec2 normalize(const glm::vec2& vector)
96 if (glm::length(vector) > 0.0)
97 return glm::normalize(vector);
98 return vector;
101 inline glm::vec2 perpendicular(const glm::vec2& vector)
103 return glm::vec2(-vector.y, vector.x);
106 inline float lineVectorAngle(const glm::vec2& previous, const glm::vec2& next)
108 float angle = std::atan2(previous.x * next.y - previous.y * next.x,
109 previous.x * next.x + previous.y * next.y);
111 return F_PI - std::fabs(angle);
114 } // end vcl::vertex
116 #endif // INCLUDED_VCL_INC_OPENGL_VERTEXUTILS_H
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */