| 1 |
/****************************************************************************** |
| 2 |
This source file is part of the Avogadro project. |
| 3 |
This source code is released under the 3-Clause BSD License, (see "LICENSE"). |
| 4 |
******************************************************************************/ |
| 5 |
|
| 6 |
#ifndef AVOGADRO_RENDERING_DASHEDLINEGEOMETRY_H |
| 7 |
#define AVOGADRO_RENDERING_DASHEDLINEGEOMETRY_H |
| 8 |
|
| 9 |
#include "drawable.h" |
| 10 |
|
| 11 |
#include <avogadro/core/array.h> |
| 12 |
|
| 13 |
namespace Avogadro { |
| 14 |
namespace Rendering { |
| 15 |
|
| 16 |
/** |
| 17 |
* @class DashedLineGeometry DashedLinegeometry.h |
| 18 |
* <avogadro/rendering/dashedlinegeometry.h> |
| 19 |
* @brief The DashedLineGeometry class is used to store sets of dashed lines. |
| 20 |
*/ |
| 21 |
|
| 22 |
class AVOGADRORENDERING_EXPORT DashedLineGeometry : public Drawable |
| 23 |
{ |
| 24 |
public: |
| 25 |
struct PackedVertex |
| 26 |
{ // 16 bytes total: |
| 27 |
Vector3f vertex; // 12 bytes |
| 28 |
Vector4ub color; // 4 bytes |
| 29 |
|
| 30 |
PackedVertex(const Vector3f& v, const Vector4ub& c) : vertex(v), color(c) {} |
| 31 |
static int vertexOffset() { return 0; } |
| 32 |
static int colorOffset() { return static_cast<int>(sizeof(Vector3f)); } |
| 33 |
}; |
| 34 |
|
| 35 |
DashedLineGeometry(); |
| 36 |
DashedLineGeometry(const DashedLineGeometry& other); |
| 37 |
~DashedLineGeometry() override; |
| 38 |
|
| 39 |
DashedLineGeometry& operator=(DashedLineGeometry); |
| 40 |
friend void swap(DashedLineGeometry& lhs, DashedLineGeometry& rhs); |
| 41 |
|
| 42 |
/** |
| 43 |
* Accept a visit from our friendly visitor. |
| 44 |
*/ |
| 45 |
void accept(Visitor&) override; |
| 46 |
|
| 47 |
/** |
| 48 |
* @brief Render the line strips. |
| 49 |
* @param camera The current camera to be used for rendering. |
| 50 |
*/ |
| 51 |
void render(const Camera& camera) override; |
| 52 |
|
| 53 |
/** |
| 54 |
* Clear the contents of the node. |
| 55 |
*/ |
| 56 |
void clear() override; |
| 57 |
|
| 58 |
/** |
| 59 |
* Add a complete line strip to the object. |
| 60 |
* @param vertices The 3D vertices which will be connected to form the line |
| 61 |
* strip. |
| 62 |
* @param color Vertex color. If not specified, use the current color() and |
| 63 |
* opacity(). If the 3 component color is set, the current opacity() is used. |
| 64 |
* @param lineWidth The width of the line strip. |
| 65 |
* @note All arrays must be the same length, or this function call will fail, |
| 66 |
* returning InvalidIndex. |
| 67 |
* @return The index of the first vertex added by this call. |
| 68 |
* @{ |
| 69 |
*/ |
| 70 |
size_t addDashedLine(const Vector3f& start, const Vector3f& end, |
| 71 |
const Vector4ub& color, int dashCount); |
| 72 |
size_t addDashedLine(const Vector3f& start, const Vector3f& end, |
| 73 |
const Vector3ub& color, int dashCount); |
| 74 |
size_t addDashedLine(const Vector3f& start, const Vector3f& end, |
| 75 |
int dashCount); |
| 76 |
/** @} */ |
| 77 |
|
| 78 |
/** |
| 79 |
* The default color of the lines. This is used to set the color of new |
| 80 |
* vertices when no explicit vertex color is specified. |
| 81 |
* @{ |
| 82 |
*/ |
| 83 |
void setColor(const Vector3ub& c) { m_color = c; } |
| 84 |
Vector3ub color() const { return m_color; } |
| 85 |
/** @} */ |
| 86 |
|
| 87 |
/** |
| 88 |
* The default opacity of the lines. This is used when either no explicit |
| 89 |
* vertex color is specified, or a three component color is used. |
| 90 |
* @{ |
| 91 |
*/ |
| 92 |
void setOpacity(unsigned char opacity_) { m_opacity = opacity_; } |
| 93 |
unsigned char opacity() const { return m_opacity; } |
| 94 |
/** @} */ |
| 95 |
|
| 96 |
/** |
| 97 |
* The line width used for all of the lines. |
| 98 |
* @{ |
| 99 |
*/ |
| 100 |
void setLineWidth(unsigned char lineWidth_) { m_lineWidth = lineWidth_; } |
| 101 |
unsigned char lineWidth() const { return m_lineWidth; } |
| 102 |
/** @} */ |
| 103 |
|
| 104 |
private: |
| 105 |
/** |
| 106 |
* @brief Update the VBOs, IBOs etc ready for rendering. |
| 107 |
*/ |
| 108 |
void update(); |
| 109 |
|
| 110 |
Core::Array<PackedVertex> m_vertices; |
| 111 |
float m_lineWidth; |
| 112 |
int m_lineCount; |
| 113 |
|
| 114 |
Vector3ub m_color; |
| 115 |
unsigned char m_opacity; |
| 116 |
|
| 117 |
bool m_dirty; |
| 118 |
|
| 119 |
class Private; |
| 120 |
Private* d; |
| 121 |
}; |
| 122 |
|
| 123 |
inline DashedLineGeometry& DashedLineGeometry::operator=( |
| 124 |
DashedLineGeometry other) |
| 125 |
{ |
| 126 |
using std::swap; |
| 127 |
swap(*this, other); |
| 128 |
return *this; |
| 129 |
} |
| 130 |
|
| 131 |
inline void swap(DashedLineGeometry& lhs, DashedLineGeometry& rhs) |
| 132 |
{ |
| 133 |
using std::swap; |
| 134 |
swap(static_cast<Drawable&>(lhs), static_cast<Drawable&>(rhs)); |
| 135 |
swap(lhs.m_vertices, rhs.m_vertices); |
| 136 |
swap(lhs.m_color, rhs.m_color); |
| 137 |
swap(lhs.m_opacity, rhs.m_opacity); |
| 138 |
lhs.m_dirty = rhs.m_dirty = true; |
| 139 |
} |
| 140 |
|
| 141 |
} // End namespace Rendering |
| 142 |
} // End namespace Avogadro |
| 143 |
|
| 144 |
#endif // AVOGADRO_RENDERING_DASHEDLINEGEOMETRY_H |