From 4bb5b4f01c1b38fce9f1a11346de5bd4ee3c6fd4 Mon Sep 17 00:00:00 2001 From: Alex Wilson Date: Wed, 14 Dec 2011 16:10:15 +1000 Subject: [PATCH] Add lineWidth property to QSGGeometry Allows users to set a line width when using drawingModes GL_LINES, GL_LINE_LOOP etc. Only calls glLineWidth on these drawingModes, and does it just before the glDrawElements/glDrawArrays. Change-Id: I2af583970b2acf0ddb59025a454caa75a8ddbd4f Reviewed-by: Gunnar Sletta --- src/quick/scenegraph/coreapi/qsggeometry.cpp | 25 +++++++++++++++++++++++++ src/quick/scenegraph/coreapi/qsggeometry.h | 5 +++++ src/quick/scenegraph/coreapi/qsgrenderer.cpp | 4 ++++ 3 files changed, 34 insertions(+), 0 deletions(-) diff --git a/src/quick/scenegraph/coreapi/qsggeometry.cpp b/src/quick/scenegraph/coreapi/qsggeometry.cpp index 8661c9a..b747bb9 100644 --- a/src/quick/scenegraph/coreapi/qsggeometry.cpp +++ b/src/quick/scenegraph/coreapi/qsggeometry.cpp @@ -138,6 +138,7 @@ QSGGeometry::QSGGeometry(const QSGGeometry::AttributeSet &attributes, , m_owns_data(false) , m_index_usage_pattern(AlwaysUploadPattern) , m_vertex_usage_pattern(AlwaysUploadPattern) + , m_line_width(1.0) { Q_ASSERT(m_attributes.count > 0); Q_ASSERT(m_attributes.stride > 0); @@ -253,6 +254,30 @@ void QSGGeometry::setDrawingMode(GLenum mode) } /*! + Gets the current line width to be used for this geometry. This property only + applies where the drawingMode is GL_LINES or a related value. + + The default value is 1.0 + + \sa setLineWidth(), drawingMode() +*/ +float QSGGeometry::lineWidth() const +{ + return m_line_width; +} + +/*! + Sets the line width to be used for this geometry. This property only applies + where the drawingMode is GL_LINES or a related value. + + \sa lineWidth(), drawingMode() +*/ +void QSGGeometry::setLineWidth(float w) +{ + m_line_width = w; +} + +/*! \fn int QSGGeometry::drawingMode() const Returns the drawing mode of this geometry. diff --git a/src/quick/scenegraph/coreapi/qsggeometry.h b/src/quick/scenegraph/coreapi/qsggeometry.h index aea6f0b..85f4881 100644 --- a/src/quick/scenegraph/coreapi/qsggeometry.h +++ b/src/quick/scenegraph/coreapi/qsggeometry.h @@ -160,6 +160,9 @@ public: void markIndexDataDirty(); void markVertexDataDirty(); + float lineWidth() const; + void setLineWidth(float w); + private: friend class QSGGeometryData; @@ -181,6 +184,8 @@ private: uint m_reserved_bits : 27; float m_prealloc[16]; + + float m_line_width; }; inline uint *QSGGeometry::indexDataAsUInt() diff --git a/src/quick/scenegraph/coreapi/qsgrenderer.cpp b/src/quick/scenegraph/coreapi/qsgrenderer.cpp index 1b4f5da..a7aac5f 100644 --- a/src/quick/scenegraph/coreapi/qsgrenderer.cpp +++ b/src/quick/scenegraph/coreapi/qsgrenderer.cpp @@ -701,6 +701,10 @@ void QSGRenderer::draw(const QSGMaterialShader *shader, const QSGGeometry *g) indexData = g->indexData(); } + // Set the line width if applicable + if (g->drawingMode() == GL_LINES || g->drawingMode() == GL_LINE_STRIP || g->drawingMode() == GL_LINE_LOOP) { + glLineWidth(g->lineWidth()); + } // draw the stuff... if (g->indexCount()) { -- 1.7.2.5