Detailed Description
The QLogicalVertex class references QGeometryData at a single vertex.
QLogicalVertex instances are a convenience class for use with QGeometryData. A QLogicalVertex simply references through to the data in a QGeometryData for a particular vertex, providing accessors to fetch position, texture coordinates, and other values.
Create a QLogicalVertex referring to a particular QGeometryData instance:
QGeometryData data;
data.appendVertex(QVector3D(1, 2, 3));
QLogicalVertex lv(data, 0);
This is inexpensive and no new storage is allocated for the actual data, just the reference and index.
With logical vertices instances referencing large QGeometryData instances, avoid modifying the instance:
lv.setVertex(3, 2, 1);
Create a QLogicalVertex with its own QGeometryData internally:
QLogicalVertex lv;
lv.setVertex(1, 2, 3);
Assign an instance of QLogicalVertex:
QLogicalVertex lv2;
lv2 = data.logicalVertexAt(0);
Although lv2 gets its own internal QGeometryData which is then immediately thrown away by the assignment, because of lazy initialization in QGeometryData the cost is negligible.
Use the fields() and hasField() functions to determine if a particular field is present in the vertex. Accessing non-existent data will cause an assert in debug mode (from the underlying QArray), and give undefined behaviour in release mode.
Member Function Documentation
QLogicalVertex::QLogicalVertex()
Constructs a new invalid QLogicalVertex which has no data.
QLogicalVertex::QLogicalVertex(QGeometryData data, int index)
Constructs a new QLogicalVertex referencing the data at index. Note that if this QLogicalVertex is modified, by calling vertex() or setNormal() for example, then a copy-on-write for data will be triggered.
QLogicalVertex::QLogicalVertex(const QVector3D & a)
Constructs a new QLogicalVertex with a vertex set to a.
QLogicalVertex::QLogicalVertex(const QVector3D & a, const QVector3D & n)
Constructs a new QLogicalVertex with a vertex set to a, and normal set to n.
QLogicalVertex::QLogicalVertex(const QVector3D & a, const QVector3D & n, const QVector2D & t)
Constructs a new QLogicalVertex with its vertex value set to a, normal set to n, and texture set to t. By default n is the null QVector3D, and t is the InvalidTexCoord. If n is null then hasType(QLogicalVertex::Normal) will return false. Likewise if t is the InvalidTexCoord then hasType(QLogicalVertex::Texture) will return false.
QLogicalVertex::QLogicalVertex(const QVector3D & a, QColor4ub color)
Constructs a new QLogicalVertex with its vertex value set to a, color value set to color.
QLogicalVertex::~QLogicalVertex()
Destroys this QLogicalVertex reclaiming any resources.
QVariant QLogicalVertex::attribute(QGL::VertexAttribute field = QGL::CustomVertex0) const
Returns the attribute value for field. The field defaults to QGL::CustomVertex0.
See also setAttribute().
Returns the element type for the attribute field.
const QColor4ub & QLogicalVertex::color() const
Returns a const reference to the color value for this vertex.
See also setColor().
QColor4ub & QLogicalVertex::colorRef()
Returns a modifiable reference to the color value for this vertex.
QGeometryData QLogicalVertex::data() const
Returns a copy of the QGeometryData underlying this vertex. Note that the copy is not expensive in terms of performance due to implicit sharing unless the copy is modified (causing a copy-on-write).
See also QLogicalVertex::index().
quint32 QLogicalVertex::fields() const
Returns a bit-mask of the fields in this logical vertex. Test the fields like this:
if (vertex.fields() & QGL::fieldMask(QGL::TextureCoord0))
tex = vertex.texCoord();
See also QGeometryData::fields().
float & QLogicalVertex::floatAttribute(QGL::VertexAttribute field = QGL::CustomVertex0)
Returns a modifiable reference to the attribute at field, which must be a float. The field defaults to QGL::CustomVertex0.
float QLogicalVertex::floatAttribute(QGL::VertexAttribute field = QGL::CustomVertex0) const
Returns the attribute at field. The field defaults to QGL::CustomVertex0. The attribute must be a float value.
bool QLogicalVertex::hasField(QGL::VertexAttribute type) const
Returns true if this vertex has data field type, and false otherwise.
In general check to see if a logical vertex has a particular field type before attempting to access it. In debug mode accessing a non-existent field will cause an assert; but in release mode the behaviour is undefined.
int QLogicalVertex::index() const
Returns the index at which this logical vertex's data is located in its associated QGeometryData; or -1 if this vertex is null.
bool QLogicalVertex::isNull() const
Returns true if this vertex is null.
See also QLogicalVertex().
const QVector3D & QLogicalVertex::normal() const
Returns a const reference to the normal value for this vertex.
See also setNormal().
QVector3D & QLogicalVertex::normal()
Returns a modifiable reference to the normal value for this vertex.
void QLogicalVertex::setAttribute(float value, QGL::VertexAttribute field)
Sets the float attribute value at field. The field defaults to QGL::CustomVertex0.
See also attribute().
void QLogicalVertex::setAttribute(const QVector2D & v, QGL::VertexAttribute field = QGL::CustomVertex0)
Sets the QVector2D attribute v at field. The field defaults to QGL::CustomVertex0.
void QLogicalVertex::setAttribute(const QVector3D & v, QGL::VertexAttribute field = QGL::CustomVertex0)
Sets the QVector3D attribute v at field. The field defaults to QGL::CustomVertex0.
void QLogicalVertex::setColor(const QColor4ub & c)
Sets the color value for this vertex to c.
See also color().
void QLogicalVertex::setNormal(const QVector3D & n)
Sets the normal value for this vertex to n.
See also normal().
void QLogicalVertex::setTexCoord(const QVector2D & t, QGL::VertexAttribute field = QGL::TextureCoord0)
Sets the texture coordinate at field for this vertex to t. The field defaults to QGL::TextureCoord0.
See also texCoord().
void QLogicalVertex::setVertex(const QVector3D & v)
Sets the vertex value for this vertex to v.
See also vertex().
const QVector2D & QLogicalVertex::texCoord(QGL::VertexAttribute field = QGL::TextureCoord0) const
Returns a copy of the texture coordinate value at field for this vertex. The field defaults to QGL::TextureCoord0.
See also setTexCoord().
QVector2D & QLogicalVertex::texCoordRef(QGL::VertexAttribute field = QGL::TextureCoord0)
Returns a modifiable reference to the texture coordinate for this vertex. The field defaults to QGL::TextureCoord0.
QVector2D & QLogicalVertex::vector2DAttribute(QGL::VertexAttribute field = QGL::CustomVertex0)
Returns a modifiable reference to the attribute at field, which must be a QVector2D. The field defaults to QGL::CustomVertex0.
QVector2D QLogicalVertex::vector2DAttribute(QGL::VertexAttribute field = QGL::CustomVertex0) const
Returns the attribute at field. The field defaults to QGL::CustomVertex0. The attribute must be a QVector2D value.
QVector3D & QLogicalVertex::vector3DAttribute(QGL::VertexAttribute field = QGL::CustomVertex0)
Returns a modifiable reference to the attribute at field, which must be a QVector3D. The field defaults to QGL::CustomVertex0.
QVector3D QLogicalVertex::vector3DAttribute(QGL::VertexAttribute field = QGL::CustomVertex0) const
Returns the attribute at field. The field defaults to QGL::CustomVertex0. The attribute must be a QVector3D value.
const QVector3D & QLogicalVertex::vertex() const
Returns a const reference to the vertex value for this vertex.
See also setVertex().
QVector3D & QLogicalVertex::vertex()
Returns a modifiable reference to the vertex value.
QLogicalVertex::operator QVector3D()
Returns a copy of the vertex value, by casting as a QVector3D. This allows passing of a QLogicalVertex to functions that expect a QVector3D.
bool QLogicalVertex::operator==(const QLogicalVertex & rhs) const
Returns true if rhs has exactly the same fields as this logical vertex, and each of those are equal to the corresponding field of the rhs.
If either are null, then false is returned.