Visual Computing Library  devel
Loading...
Searching...
No Matches
primitive_lines.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_BGFX_PRIMITIVES_LINES_PRIMITIVE_LINES_H
24#define VCL_BGFX_PRIMITIVES_LINES_PRIMITIVE_LINES_H
25
26#include <vclib/bgfx/buffers.h>
27#include <vclib/bgfx/context.h>
28
29#include <variant>
30
31namespace vcl::detail {
32
33// Note: copy constructor and assignment are not allowed (because of bgfx
34// handles). Move constructor and assignment are allowed.
35class PrimitiveLines
36{
37 bgfx::ProgramHandle mLinesPH =
39 .programManager()
40 .getProgram<VertFragProgram::PRIMITIVE_LINES>();
41
42 enum Ownership { OWNED = 0, NOT_OWNED = 1 };
43
44 // true if the buffers are created and managed internally
45 // by default, all variants are owned (first element of the variant)
46 bool mOwnsBuffers = true;
47
48 std::variant<VertexBuffer, const VertexBuffer*> mVertexCoords;
49 std::variant<VertexBuffer, const VertexBuffer*> mVertexNormals;
50 std::variant<VertexBuffer, const VertexBuffer*> mVertexColors;
51 std::variant<IndexBuffer, const IndexBuffer*> mLineColors;
52
53 std::variant<IndexBuffer, const IndexBuffer*> mIndices;
54
55public:
56 PrimitiveLines() = default;
57
58 PrimitiveLines(
59 const std::vector<float>& vertCoords,
60 const std::vector<float>& vertNormals = std::vector<float>(),
61 const std::vector<uint>& vertColors = std::vector<uint>(),
62 const std::vector<uint>& lineColors = std::vector<uint>());
63
64 PrimitiveLines(
65 const std::vector<float>& vertCoords,
66 const std::vector<uint>& lineIndices,
67 const std::vector<float>& vertNormals = std::vector<float>(),
68 const std::vector<uint>& vertColors = std::vector<uint>(),
69 const std::vector<uint>& lineColors = std::vector<uint>());
70
71 PrimitiveLines(
72 const uint pointsSize,
73 const VertexBuffer& vertexCoords,
74 const VertexBuffer& vertexNormals = VertexBuffer(),
75 const VertexBuffer& vertexColors = VertexBuffer(),
76 const IndexBuffer& lineColors = IndexBuffer());
77
78 PrimitiveLines(
79 const uint pointsSize,
80 const VertexBuffer& vertexCoords,
81 const IndexBuffer& lineIndices,
82 const VertexBuffer& vertexNormals = VertexBuffer(),
83 const VertexBuffer& vertexColors = VertexBuffer(),
84 const IndexBuffer& lineColors = IndexBuffer());
85
86 void swap(PrimitiveLines& other);
87
88 friend void swap(PrimitiveLines& a, PrimitiveLines& b) { a.swap(b); }
89
90 void setPoints(
91 const std::vector<float>& vertCoords,
92 const std::vector<float>& vertNormals,
93 const std::vector<uint>& vertColors,
94 const std::vector<uint>& lineColors);
95
96 void setPoints(
97 const std::vector<float>& vertCoords,
98 const std::vector<uint>& lineIndices,
99 const std::vector<float>& vertNormals,
100 const std::vector<uint>& vertColors,
101 const std::vector<uint>& lineColors);
102
103 void setPoints(
104 const uint pointsSize,
105 const VertexBuffer& vertexCoords,
106 const VertexBuffer& vertexNormals = VertexBuffer(),
107 const VertexBuffer& vertexColors = VertexBuffer(),
108 const IndexBuffer& lineColors = IndexBuffer());
109
110 void setPoints(
111 const uint pointsSize,
112 const VertexBuffer& vertexCoords,
113 const IndexBuffer& lineIndices,
114 const VertexBuffer& vertexNormals = VertexBuffer(),
115 const VertexBuffer& vertexColors = VertexBuffer(),
116 const IndexBuffer& lineColors = IndexBuffer());
117
118 void draw(uint viewId) const;
119
120private:
121 void reinitBuffers(Ownership owned);
122
123 void setPoints(
124 bool setLineIndices,
125 const std::vector<float>& vertCoords,
126 const std::vector<uint>& lineIndices,
127 const std::vector<float>& vertNormals,
128 const std::vector<uint>& vertColors,
129 const std::vector<uint>& lineColors);
130};
131
132} // namespace vcl::detail
133
134#endif // VCL_BGFX_PRIMITIVES_LINES_PRIMITIVE_LINES_H
static Context & instance(void *windowHandle=nullptr, void *displayHandle=nullptr)
Return the context instance.
Definition context.cpp:371