23#ifndef VCL_BGFX_PRIMITIVES_LINES_H
24#define VCL_BGFX_PRIMITIVES_LINES_H
26#include <vclib/bgfx/primitives/lines/cpu_generated_lines.h>
27#include <vclib/bgfx/primitives/lines/primitive_lines.h>
28#include <vclib/bgfx/uniform.h>
30#include <vclib/base.h>
31#include <vclib/space/core.h>
58 enum class ColorToUse {
64 enum class ImplementationType {
80 float mThickness = 5.0f;
85 bool mShadingPerVertexCapability =
false;
86 bool mShadingPerVertex =
false;
88 BitSet8 mColorCapability = {
false,
false,
true};
89 ColorToUse mColorToUse = ColorToUse::GENERAL;
90 Color mGeneralColor = Color::ColorABGR::LightGray;
92 ImplementationType mType = ImplementationType::COUNT;
94 std::variant<detail::PrimitiveLines, detail::CPUGeneratedLines>
97 static inline Uniform sSettingUH;
112 Lines(ImplementationType type = ImplementationType::COUNT)
114 if (type == ImplementationType::COUNT)
116 setImplementationType(type);
157 ImplementationType type = ImplementationType::COUNT) :
205 ImplementationType type = ImplementationType::COUNT) :
242 ImplementationType type = ImplementationType::COUNT)
244 using enum ImplementationType;
245 using namespace detail;
249 setImplementationType(type);
253 std::get<PrimitiveLines>(mLinesImplementation)
258 std::get<CPUGeneratedLines>(mLinesImplementation)
297 ImplementationType type = ImplementationType::COUNT)
299 using enum ImplementationType;
300 using namespace detail;
304 setImplementationType(type);
308 std::get<PrimitiveLines>(mLinesImplementation)
318 std::get<CPUGeneratedLines>(mLinesImplementation)
394 if (!mShadingPerVertexCapability &&
perVertex) {
395 throw std::runtime_error(
396 "Lines::setShading(): shading per vertex not supported by the "
414 if (!mColorCapability[toUnderlying(color)]) {
415 throw std::runtime_error(
416 "Lines::setColorToUse(): color option not supported by the "
430 using enum ImplementationType;
431 using namespace detail;
433 bindSettingsUniform();
434 if (mType == PRIMITIVE)
435 std::get<PrimitiveLines>(mLinesImplementation).draw(viewId);
437 if (mType == CPU_GENERATED)
438 std::get<CPUGeneratedLines>(mLinesImplementation).draw(viewId);
452 using enum ImplementationType;
455 return CPU_GENERATED;
460 bool setImplementationType(ImplementationType type)
462 using enum ImplementationType;
471 mLinesImplementation = detail::PrimitiveLines();
476 mLinesImplementation = detail::CPUGeneratedLines();
480 default:
return false;
484 void updateShadingCapability(
const std::vector<float>& vertNormals)
486 mShadingPerVertexCapability = !vertNormals.empty();
487 if (!mShadingPerVertexCapability)
488 mShadingPerVertex =
false;
491 void updateColorCapability(
492 const std::vector<uint>& vertColors,
493 const std::vector<uint>& lineColors)
495 using enum ColorToUse;
497 mColorCapability[toUnderlying(PER_VERTEX)] = !vertColors.empty();
498 mColorCapability[toUnderlying(PER_EDGE)] = !lineColors.empty();
500 if (!mColorCapability[toUnderlying(mColorToUse)])
501 mColorToUse = GENERAL;
504 void bindSettingsUniform()
const
509 sSettingUH = Uniform(
"u_settings", bgfx::UniformType::Vec4);
513 static_cast<float>(mColorToUse),
514 std::bit_cast<float>(mGeneralColor.abgr()),
515 static_cast<float>(mShadingPerVertex)};
516 sSettingUH.
bind(data);
The Color class represents a 32 bit color.
Definition color.h:48
The Lines class provides an abstraction for rendering 3D lines with variable thickness and different ...
Definition lines.h:56
ImplementationType implementationType() const
Returns the current implementation type that is used to render the lines.
Definition lines.h:380
void setPoints(const std::vector< float > &vertCoords, const std::vector< uint > &lineIndices, const std::vector< float > &vertNormals, const std::vector< uint > &vertColors, const std::vector< uint > &lineColors, ImplementationType type=ImplementationType::COUNT)
Sets the points of the lines.
Definition lines.h:291
ColorToUse colorToUse() const
Returns the color that is used to render the lines.
Definition lines.h:356
void draw(uint viewId) const
Draws in the given view the lines with the current settings.
Definition lines.h:428
ImplementationType defaultImplementationType(bool cpuMemPointsProvided) const
Returns the default supported implementation type that can be used, depending on the capabilities of ...
Definition lines.h:449
Lines(const std::vector< float > &vertCoords, const std::vector< float > &vertNormals, const std::vector< uint > &vertColors, const std::vector< uint > &lineColors, float thickness=5.0f, bool shadingPerVertex=false, ColorToUse colorToUse=ColorToUse::GENERAL, ImplementationType type=ImplementationType::COUNT)
Creates a Lines object with given points and parameters.
Definition lines.h:149
Color & generalColor()
Returns a reference to the general color that is used to render the lines when colorToUse() is set to...
Definition lines.h:372
void setColorToUse(ColorToUse color)
Sets which color to use for rendering the lines.
Definition lines.h:412
Lines(const std::vector< float > &vertCoords, const std::vector< uint > &lineIndices, const std::vector< float > &vertNormals, const std::vector< uint > &vertColors, const std::vector< uint > &lineColors, float thickness=5.0f, bool shadingPerVertex=false, ColorToUse colorToUse=ColorToUse::GENERAL, ImplementationType type=ImplementationType::COUNT)
Creates a Lines object with given points and parameters.
Definition lines.h:196
Lines(ImplementationType type=ImplementationType::COUNT)
Creates a Lines object with default parameters and without points.
Definition lines.h:112
float thickness() const
Returns the thickness of the lines (in pixels).
Definition lines.h:336
float & thickness()
Returns a reference to the thickness of the lines (in pixels). This allows to modify the thickness di...
Definition lines.h:343
bool shadingPerVertex() const
Returns true if shading is computed per vertex using vertex normals, false if no shading is applied.
Definition lines.h:350
Color generalColor() const
Returns the general color that is used to render the lines when colorToUse() is set to ColorToUse::GE...
Definition lines.h:363
void setPoints(const std::vector< float > &vertCoords, const std::vector< float > &vertNormals, const std::vector< uint > &vertColors, const std::vector< uint > &lineColors, ImplementationType type=ImplementationType::COUNT)
Sets the points of the lines.
Definition lines.h:237
void setShading(bool perVertex)
Sets wether to use per vertex shading (using vertex normals) or not.
Definition lines.h:392
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:41