aboutsummaryrefslogtreecommitdiffstats
path: root/src/declarative/scenegraph/coreapi
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/scenegraph/coreapi')
-rw-r--r--src/declarative/scenegraph/coreapi/qsgdefaultrenderer.cpp5
-rw-r--r--src/declarative/scenegraph/coreapi/qsggeometry.cpp113
-rw-r--r--src/declarative/scenegraph/coreapi/qsggeometry.h31
-rw-r--r--src/declarative/scenegraph/coreapi/qsggeometry_p.h32
-rw-r--r--src/declarative/scenegraph/coreapi/qsgmaterial.cpp16
-rw-r--r--src/declarative/scenegraph/coreapi/qsgmaterial.h8
-rw-r--r--src/declarative/scenegraph/coreapi/qsgnode.cpp2
-rw-r--r--src/declarative/scenegraph/coreapi/qsgrenderer.cpp201
-rw-r--r--src/declarative/scenegraph/coreapi/qsgrenderer_p.h30
9 files changed, 367 insertions, 71 deletions
diff --git a/src/declarative/scenegraph/coreapi/qsgdefaultrenderer.cpp b/src/declarative/scenegraph/coreapi/qsgdefaultrenderer.cpp
index 382ac37d2c..ce05e76969 100644
--- a/src/declarative/scenegraph/coreapi/qsgdefaultrenderer.cpp
+++ b/src/declarative/scenegraph/coreapi/qsgdefaultrenderer.cpp
@@ -46,7 +46,7 @@
#include "qsgmaterial.h"
#include <QtCore/qvarlengtharray.h>
-#include <QtGui/qapplication.h>
+#include <QtWidgets/qapplication.h>
#include <QtCore/qpair.h>
#include <QtCore/QElapsedTimer>
@@ -510,8 +510,7 @@ void QSGDefaultRenderer::renderNodes(const QDataBuffer<QSGGeometryNode *> &list)
//glDepthRange((geomNode->renderOrder() + 0.1) * scale, (geomNode->renderOrder() + 0.9) * scale);
const QSGGeometry *g = geomNode->geometry();
- bindGeometry(program, g);
- draw(geomNode);
+ draw(program, g);
#ifdef RENDERER_DEBUG
geometryNodesDrawn++;
diff --git a/src/declarative/scenegraph/coreapi/qsggeometry.cpp b/src/declarative/scenegraph/coreapi/qsggeometry.cpp
index 71b5cb63f1..6b622afd8d 100644
--- a/src/declarative/scenegraph/coreapi/qsggeometry.cpp
+++ b/src/declarative/scenegraph/coreapi/qsggeometry.cpp
@@ -40,6 +40,7 @@
****************************************************************************/
#include "qsggeometry.h"
+#include "qsggeometry_p.h"
QT_BEGIN_NAMESPACE
@@ -122,7 +123,10 @@ QSGGeometry::QSGGeometry(const QSGGeometry::AttributeSet &attributes,
, m_attributes(attributes)
, m_data(0)
, m_index_data_offset(-1)
+ , m_server_data(0)
, m_owns_data(false)
+ , m_index_usage_pattern(AlwaysUploadPattern)
+ , m_vertex_usage_pattern(AlwaysUploadPattern)
{
Q_ASSERT(m_attributes.count > 0);
Q_ASSERT(m_attributes.stride > 0);
@@ -136,6 +140,9 @@ QSGGeometry::~QSGGeometry()
{
if (m_owns_data)
qFree(m_data);
+
+ if (m_server_data)
+ delete m_server_data;
}
/*!
@@ -250,6 +257,15 @@ void QSGGeometry::allocate(int vertexCount, int indexCount)
m_owns_data = true;
}
+ // If we have associated vbo data we could potentially crash later if
+ // the old buffers are used with the new vertex and index count, so we force
+ // an update in the renderer in that case. This is really the users responsibility
+ // but it is cheap for us to enforce this, so why not...
+ if (m_server_data) {
+ markIndexDataDirty();
+ markVertexDataDirty();
+ }
+
}
/*!
@@ -307,4 +323,101 @@ void QSGGeometry::updateTexturedRectGeometry(QSGGeometry *g, const QRectF &rect,
v[3].ty = textureRect.bottom();
}
+
+
+/*!
+ \enum QSGGeometry::DataPattern
+
+ The DataPattern enum is used to specify the use pattern for the vertex
+ and index data in a geometry object.
+
+ \value AlwaysUploadPattern The data is always uploaded. This means that
+ the user does not need to explicitly mark index and vertex data as
+ dirty after changing it. This is the default.
+
+ \value DynamicPattern The data is modified repeatedly and drawn many times.
+ This is a hint that may provide better performance. When set
+ the user must make sure to mark the data as dirty after changing it.
+
+ \value StaticPattern The data is modified once and drawn many times. This is
+ a hint that may provide better performance. When set the user must make sure
+ to mark the data as dirty after changing it.
+ */
+
+
+/*!
+ \fn QSGGeometry::DataPattern QSGGeometry::indexDataPattern() const
+
+ Returns the usage pattern for indices in this geometry. The default
+ pattern is AlwaysUploadPattern.
+ */
+
+/*!
+ Sets the usage pattern for indices to \a p.
+
+ The default is AlwaysUploadPattern. When set to anything other than
+ the default, the user must call markIndexDataDirty() after changing
+ the index data.
+ */
+
+void QSGGeometry::setIndexDataPattern(DataPattern p)
+{
+ m_index_usage_pattern = p;
+}
+
+
+
+
+/*!
+ \fn QSGGeometry::DataPattern QSGGeometry::vertexDataPattern() const
+
+ Returns the usage pattern for vertices in this geometry. The default
+ pattern is AlwaysUploadPattern.
+ */
+
+/*!
+ Sets the usage pattern for vertices to \a p.
+
+ The default is AlwaysUploadPattern. When set to anything other than
+ the default, the user must call markVertexDataDirty() after changing
+ the vertex data.
+ */
+
+void QSGGeometry::setVertexDataPattern(DataPattern p)
+{
+ m_vertex_usage_pattern = p;
+}
+
+
+
+
+/*!
+ Mark that the vertices in this geometry has changed and must be uploaded
+ again.
+
+ This function only has an effect when the usage pattern for vertices is
+ StaticData and the renderer that renders this geometry uploads the geometry
+ into Vertex Buffer Objects (VBOs).
+ */
+void QSGGeometry::markIndexDataDirty()
+{
+ m_dirty_index_data = true;
+}
+
+
+
+/*!
+ Mark that the vertices in this geometry has changed and must be uploaded
+ again.
+
+ This function only has an effect when the usage pattern for vertices is
+ StaticData and the renderer that renders this geometry uploads the geometry
+ into Vertex Buffer Objects (VBOs).
+ */
+void QSGGeometry::markVertexDataDirty()
+{
+ m_dirty_vertex_data = true;
+}
+
+
QT_END_NAMESPACE
diff --git a/src/declarative/scenegraph/coreapi/qsggeometry.h b/src/declarative/scenegraph/coreapi/qsggeometry.h
index 432503085d..107cabc506 100644
--- a/src/declarative/scenegraph/coreapi/qsggeometry.h
+++ b/src/declarative/scenegraph/coreapi/qsggeometry.h
@@ -42,7 +42,8 @@
#ifndef QSGGEOMETRY_H
#define QSGGEOMETRY_H
-#include <QtOpenGL/qgl.h>
+#include <QtGui/qopengl.h>
+#include <QRectF>
QT_BEGIN_HEADER
@@ -50,6 +51,8 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
+class QSGGeometryData;
+
class Q_DECLARATIVE_EXPORT QSGGeometry
{
public:
@@ -92,6 +95,13 @@ public:
static const AttributeSet &defaultAttributes_TexturedPoint2D();
static const AttributeSet &defaultAttributes_ColoredPoint2D();
+ enum DataPattern {
+ AlwaysUploadPattern = 0,
+ StreamPattern = 1,
+ DynamicPattern = 2,
+ StaticPattern = 3
+ };
+
QSGGeometry(const QSGGeometry::AttributeSet &attribs,
int vertexCount,
int indexCount = 0,
@@ -134,7 +144,18 @@ public:
static void updateRectGeometry(QSGGeometry *g, const QRectF &rect);
static void updateTexturedRectGeometry(QSGGeometry *g, const QRectF &rect, const QRectF &sourceRect);
+ void setIndexDataPattern(DataPattern p);
+ DataPattern indexDataPattern() const { return (DataPattern) m_index_usage_pattern; }
+
+ void setVertexDataPattern(DataPattern p);
+ DataPattern vertexDataPattern() const { return (DataPattern) m_vertex_usage_pattern; }
+
+ void markIndexDataDirty();
+ void markVertexDataDirty();
+
private:
+ friend class QSGGeometryData;
+
int m_drawing_mode;
int m_vertex_count;
int m_index_count;
@@ -143,10 +164,14 @@ private:
void *m_data;
int m_index_data_offset;
- void *m_reserved_pointer;
+ QSGGeometryData *m_server_data;
uint m_owns_data : 1;
- uint m_reserved_bits : 31;
+ uint m_index_usage_pattern : 2;
+ uint m_vertex_usage_pattern : 2;
+ uint m_dirty_index_data : 1;
+ uint m_dirty_vertex_data : 1;
+ uint m_reserved_bits : 27;
float m_prealloc[16];
};
diff --git a/src/declarative/scenegraph/coreapi/qsggeometry_p.h b/src/declarative/scenegraph/coreapi/qsggeometry_p.h
new file mode 100644
index 0000000000..2fba155000
--- /dev/null
+++ b/src/declarative/scenegraph/coreapi/qsggeometry_p.h
@@ -0,0 +1,32 @@
+#ifndef QSGGEOMETRY_P_H
+#define QSGGEOMETRY_P_H
+
+#include "qsggeometry.h"
+
+QT_BEGIN_NAMESPACE
+
+class QSGGeometryData
+{
+public:
+ virtual ~QSGGeometryData() {}
+
+ static inline QSGGeometryData *data(const QSGGeometry *g) {
+ return g->m_server_data;
+ }
+
+ static inline void install(const QSGGeometry *g, QSGGeometryData *data) {
+ Q_ASSERT(!g->m_server_data);
+ const_cast<QSGGeometry *>(g)->m_server_data = data;
+ }
+
+ static bool inline hasDirtyVertexData(const QSGGeometry *g) { return g->m_dirty_vertex_data; }
+ static void inline clearDirtyVertexData(const QSGGeometry *g) { const_cast<QSGGeometry *>(g)->m_dirty_vertex_data = false; }
+
+ static bool inline hasDirtyIndexData(const QSGGeometry *g) { return g->m_dirty_vertex_data; }
+ static void inline clearDirtyIndexData(const QSGGeometry *g) { const_cast<QSGGeometry *>(g)->m_dirty_index_data = false; }
+
+};
+
+QT_END_NAMESPACE
+
+#endif // QSGGEOMETRY_P_H
diff --git a/src/declarative/scenegraph/coreapi/qsgmaterial.cpp b/src/declarative/scenegraph/coreapi/qsgmaterial.cpp
index ca172d6f49..65ce9eec93 100644
--- a/src/declarative/scenegraph/coreapi/qsgmaterial.cpp
+++ b/src/declarative/scenegraph/coreapi/qsgmaterial.cpp
@@ -51,7 +51,7 @@ QT_BEGIN_NAMESPACE
The QSGMaterial and QSGMaterialShader form a tight relationship. For one
scene graph (including nested graphs), there is one unique QSGMaterialShader
- instance which encapsulates the QGLShaderProgram the scene graph uses
+ instance which encapsulates the QOpenGLShaderProgram the scene graph uses
to render that material, such as a shader to flat coloring of geometry.
Each QSGGeometryNode can have a unique QSGMaterial containing the
how the shader should be configured when drawing that node, such as
@@ -152,7 +152,7 @@ QSGMaterialShader::QSGMaterialShader()
/*!
- \fn QGLShaderProgram *QSGMaterialShader::program() const
+ \fn QOpenGLShaderProgram *QSGMaterialShader::program() const
Returns the shader program used by this QSGMaterialShader.
*/
@@ -228,7 +228,7 @@ void QSGMaterialShader::updateState(const RenderState &state, QSGMaterial *newMa
/*!
This function is called when the shader is initialized to compile the
- actual QGLShaderProgram. Do not call it explicitely.
+ actual QOpenGLShaderProgram. Do not call it explicitely.
The default implementation will extract the vertexShader() and
fragmentShader() and bind the names returned from attributeNames()
@@ -239,8 +239,8 @@ void QSGMaterialShader::compile()
{
Q_ASSERT_X(!m_program.isLinked(), "QSGSMaterialShader::compile()", "Compile called multiple times!");
- program()->addShaderFromSourceCode(QGLShader::Vertex, vertexShader());
- program()->addShaderFromSourceCode(QGLShader::Fragment, fragmentShader());
+ program()->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShader());
+ program()->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShader());
char const *const *attr = attributeNames();
#ifndef QT_NO_DEBUG
@@ -385,10 +385,10 @@ QRect QSGMaterialShader::RenderState::deviceRect() const
/*!
- Returns the QGLContext that is being used for rendering
+ Returns the QOpenGLContext that is being used for rendering
*/
-const QGLContext *QSGMaterialShader::RenderState::context() const
+QOpenGLContext *QSGMaterialShader::RenderState::context() const
{
return static_cast<const QSGRenderer *>(m_data)->glContext();
}
@@ -417,7 +417,7 @@ static void qt_print_material_count()
The QSGMaterial and QSGMaterialShader subclasses form a tight relationship. For
one scene graph (including nested graphs), there is one unique QSGMaterialShader
- instance which encapsulates the QGLShaderProgram the scene graph uses
+ instance which encapsulates the QOpenGLShaderProgram the scene graph uses
to render that material, such as a shader to flat coloring of geometry.
Each QSGGeometryNode can have a unique QSGMaterial containing the
how the shader should be configured when drawing that node, such as
diff --git a/src/declarative/scenegraph/coreapi/qsgmaterial.h b/src/declarative/scenegraph/coreapi/qsgmaterial.h
index 7c6935899e..084219bfba 100644
--- a/src/declarative/scenegraph/coreapi/qsgmaterial.h
+++ b/src/declarative/scenegraph/coreapi/qsgmaterial.h
@@ -42,7 +42,7 @@
#ifndef MATERIAL_H
#define MATERIAL_H
-#include <qglshaderprogram.h>
+#include <qopenglshaderprogram.h>
QT_BEGIN_HEADER
@@ -75,7 +75,7 @@ public:
QRect viewportRect() const;
QRect deviceRect() const;
- const QGLContext *context() const;
+ QOpenGLContext *context() const;
private:
friend class QSGRenderer;
@@ -91,7 +91,7 @@ public:
virtual void updateState(const RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial);
virtual char const *const *attributeNames() const = 0; // Array must end with null.
- inline QGLShaderProgram *program() { return &m_program; }
+ inline QOpenGLShaderProgram *program() { return &m_program; }
protected:
@@ -104,7 +104,7 @@ protected:
virtual const char *fragmentShader() const = 0;
private:
- QGLShaderProgram m_program;
+ QOpenGLShaderProgram m_program;
void *m_reserved;
};
diff --git a/src/declarative/scenegraph/coreapi/qsgnode.cpp b/src/declarative/scenegraph/coreapi/qsgnode.cpp
index bff289b332..95afbb51ab 100644
--- a/src/declarative/scenegraph/coreapi/qsgnode.cpp
+++ b/src/declarative/scenegraph/coreapi/qsgnode.cpp
@@ -1264,8 +1264,6 @@ void QSGNodeDumper::dump(QSGNode *n)
void QSGNodeDumper::visitNode(QSGNode *n)
{
- if (n->isSubtreeBlocked())
- return;
qDebug() << QString(m_indent * 2, QLatin1Char(' ')) << n;
QSGNodeVisitor::visitNode(n);
}
diff --git a/src/declarative/scenegraph/coreapi/qsgrenderer.cpp b/src/declarative/scenegraph/coreapi/qsgrenderer.cpp
index 67575597ff..607c5b5b1f 100644
--- a/src/declarative/scenegraph/coreapi/qsgrenderer.cpp
+++ b/src/declarative/scenegraph/coreapi/qsgrenderer.cpp
@@ -43,12 +43,13 @@
#include "qsgnode.h"
#include "qsgmaterial.h"
#include "qsgnodeupdater_p.h"
+#include "qsggeometry_p.h"
#include "private/qsgadaptationlayer_p.h"
-#include <QGLShaderProgram>
-#include <qglframebufferobject.h>
-#include <QtGui/qapplication.h>
+#include <QOpenGLShaderProgram>
+#include <qopenglframebufferobject.h>
+#include <QtWidgets/qapplication.h>
#include <qdatetime.h>
@@ -80,7 +81,7 @@ void QSGBindable::reactivate() const
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
}
-QSGBindableFbo::QSGBindableFbo(QGLFramebufferObject *fbo) : m_fbo(fbo)
+QSGBindableFbo::QSGBindableFbo(QOpenGLFramebufferObject *fbo) : m_fbo(fbo)
{
}
@@ -130,6 +131,8 @@ QSGRenderer::QSGRenderer(QSGContext *context)
, m_changed_emitted(false)
, m_mirrored(false)
, m_is_rendering(false)
+ , m_vertex_buffer_bound(false)
+ , m_index_buffer_bound(false)
{
initializeGLFunctions();
}
@@ -206,7 +209,7 @@ void QSGRenderer::renderScene()
class B : public QSGBindable
{
public:
- void bind() const { QGLFramebufferObject::bindDefault(); }
+ void bind() const { QOpenGLFramebufferObject::bindDefault(); }
} b;
renderScene(b);
}
@@ -254,6 +257,16 @@ void QSGRenderer::renderScene(const QSGBindable &bindable)
m_changed_emitted = false;
m_bindable = 0;
+ if (m_vertex_buffer_bound) {
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ m_vertex_buffer_bound = false;
+ }
+
+ if (m_index_buffer_bound) {
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+ m_index_buffer_bound = false;
+ }
+
#ifdef QSG_RENDERER_TIMING
printf(" - Breakdown of frametime: preprocess=%d, updates=%d, binding=%d, render=%d, total=%d\n",
preprocessTime,
@@ -441,13 +454,13 @@ QSGRenderer::ClipType QSGRenderer::updateStencilClip(const QSGClipNode *clip)
} else {
if (!stencilEnabled) {
if (!m_clip_program.isLinked()) {
- m_clip_program.addShaderFromSourceCode(QGLShader::Vertex,
+ m_clip_program.addShaderFromSourceCode(QOpenGLShader::Vertex,
"attribute highp vec4 vCoord; \n"
"uniform highp mat4 matrix; \n"
"void main() { \n"
" gl_Position = matrix * vCoord; \n"
"}");
- m_clip_program.addShaderFromSourceCode(QGLShader::Fragment,
+ m_clip_program.addShaderFromSourceCode(QOpenGLShader::Fragment,
"void main() { \n"
" gl_FragColor = vec4(0.81, 0.83, 0.12, 1.0); \n" // Trolltech green ftw!
"}");
@@ -473,14 +486,17 @@ QSGRenderer::ClipType QSGRenderer::updateStencilClip(const QSGClipNode *clip)
glStencilFunc(GL_EQUAL, clipDepth, 0xff); // stencil test, ref, test mask
glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); // stencil fail, z fail, z pass
- const QSGGeometry *geometry = clip->geometry();
- Q_ASSERT(geometry->attributeCount() > 0);
- const QSGGeometry::Attribute *a = geometry->attributes();
-
- glVertexAttribPointer(0, a->tupleSize, a->type, GL_FALSE, geometry->stride(), geometry->vertexData());
+ const QSGGeometry *g = clip->geometry();
+ Q_ASSERT(g->attributeCount() > 0);
+ const QSGGeometry::Attribute *a = g->attributes();
+ glVertexAttribPointer(0, a->tupleSize, a->type, GL_FALSE, g->stride(), g->vertexData());
m_clip_program.setUniformValue(m_clip_matrix_id, m);
- draw(clip);
+ if (g->indexCount()) {
+ glDrawElements(g->drawingMode(), g->indexCount(), g->indexType(), g->indexData());
+ } else {
+ glDrawArrays(g->drawingMode(), 0, g->vertexCount());
+ }
++clipDepth;
}
@@ -507,25 +523,6 @@ QSGRenderer::ClipType QSGRenderer::updateStencilClip(const QSGClipNode *clip)
}
-/*!
- Issues the GL draw call for \a geometryNode.
-
- The function assumes that attributes have been bound and set up prior
- to making this call.
-
- \internal
- */
-
-void QSGRenderer::draw(const QSGBasicGeometryNode *node)
-{
- const QSGGeometry *g = node->geometry();
- if (g->indexCount()) {
- glDrawElements(g->drawingMode(), g->indexCount(), g->indexType(), g->indexData());
- } else {
- glDrawArrays(g->drawingMode(), 0, g->vertexCount());
- }
-}
-
static inline int size_of_type(GLenum type)
{
@@ -542,19 +539,102 @@ static inline int size_of_type(GLenum type)
4,
sizeof(double)
};
+ Q_ASSERT(type >= GL_BYTE && type <= 0x140A); // the value of GL_DOUBLE
return sizes[type - GL_BYTE];
}
+
+class QSGRendererVBOGeometryData : public QSGGeometryData
+{
+public:
+ QSGRendererVBOGeometryData()
+ : vertexBuffer(0)
+ , indexBuffer(0)
+ {
+ }
+
+ ~QSGRendererVBOGeometryData()
+ {
+ QOpenGLFunctions *func = QOpenGLContext::currentContext()->functions();
+ if (vertexBuffer)
+ func->glDeleteBuffers(1, &vertexBuffer);
+ if (indexBuffer)
+ func->glDeleteBuffers(1, &indexBuffer);
+ }
+
+ GLuint vertexBuffer;
+ GLuint indexBuffer;
+
+ static QSGRendererVBOGeometryData *get(const QSGGeometry *g) {
+ QSGRendererVBOGeometryData *gd = static_cast<QSGRendererVBOGeometryData *>(QSGGeometryData::data(g));
+ if (!gd) {
+ gd = new QSGRendererVBOGeometryData;
+ QSGGeometryData::install(g, gd);
+ }
+ return gd;
+ }
+
+};
+
+static inline GLenum qt_drawTypeForPattern(QSGGeometry::DataPattern p)
+{
+ Q_ASSERT(p > 0 && p <= 3);
+ static GLenum drawTypes[] = { 0,
+ GL_STREAM_DRAW,
+ GL_DYNAMIC_DRAW,
+ GL_STATIC_DRAW
+ };
+ return drawTypes[p];
+}
+
+
/*!
- Convenience function to set up and bind the vertex data in \a g to the
- required attribute positions defined in \a material.
+ Issues the GL draw call for the geometry \a g using the material \a shader.
+
+ The function assumes that attributes have been bound and set up prior
+ to making this call.
\internal
*/
-void QSGRenderer::bindGeometry(QSGMaterialShader *material, const QSGGeometry *g)
+void QSGRenderer::draw(const QSGMaterialShader *shader, const QSGGeometry *g)
{
- char const *const *attrNames = material->attributeNames();
+ // ### remove before final release...
+ static bool use_vbo = !QApplication::arguments().contains("--no-vbo");
+
+ const void *vertexData;
+ int vertexByteSize = g->vertexCount() * g->stride();
+ if (use_vbo && g->vertexDataPattern() != QSGGeometry::AlwaysUploadPattern && vertexByteSize > 1024) {
+
+ // The base pointer for a VBO is 0
+ vertexData = 0;
+
+ bool updateData = QSGGeometryData::hasDirtyVertexData(g);
+ QSGRendererVBOGeometryData *gd = QSGRendererVBOGeometryData::get(g);
+ if (!gd->vertexBuffer) {
+ glGenBuffers(1, &gd->vertexBuffer);
+ updateData = true;
+ }
+
+ glBindBuffer(GL_ARRAY_BUFFER, gd->vertexBuffer);
+ m_vertex_buffer_bound = true;
+
+ if (updateData) {
+ glBufferData(GL_ARRAY_BUFFER, vertexByteSize, g->vertexData(),
+ qt_drawTypeForPattern(g->vertexDataPattern()));
+ QSGGeometryData::clearDirtyVertexData(g);
+ }
+
+ } else {
+ if (m_vertex_buffer_bound) {
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ m_vertex_buffer_bound = false;
+ }
+ vertexData = g->vertexData();
+ }
+
+ // Bind the vertices to attributes...
+ char const *const *attrNames = shader->attributeNames();
int offset = 0;
for (int j = 0; attrNames[j]; ++j) {
if (!*attrNames[j])
@@ -562,15 +642,62 @@ void QSGRenderer::bindGeometry(QSGMaterialShader *material, const QSGGeometry *g
Q_ASSERT_X(j < g->attributeCount(), "QSGRenderer::bindGeometry()", "Geometry lacks attribute required by material");
const QSGGeometry::Attribute &a = g->attributes()[j];
Q_ASSERT_X(j == a.position, "QSGRenderer::bindGeometry()", "Geometry does not have continuous attribute positions");
+
#if defined(QT_OPENGL_ES_2)
GLboolean normalize = a.type != GL_FLOAT;
#else
GLboolean normalize = a.type != GL_FLOAT && a.type != GL_DOUBLE;
#endif
- glVertexAttribPointer(a.position, a.tupleSize, a.type, normalize, g->stride(), (char *) g->vertexData() + offset);
+ glVertexAttribPointer(a.position, a.tupleSize, a.type, normalize, g->stride(), (char *) vertexData + offset);
offset += a.tupleSize * size_of_type(a.type);
}
+
+ // Set up the indices...
+ const void *indexData;
+ if (use_vbo && g->indexDataPattern() != QSGGeometry::AlwaysUploadPattern && g->indexCount() > 512) {
+
+ // Base pointer for a VBO is 0
+ indexData = 0;
+
+ bool updateData = QSGGeometryData::hasDirtyIndexData(g);
+ QSGRendererVBOGeometryData *gd = QSGRendererVBOGeometryData::get(g);
+ if (!gd->indexBuffer) {
+ glGenBuffers(1, &gd->indexBuffer);
+ updateData = true;
+ }
+
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gd->indexBuffer);
+ m_index_buffer_bound = true;
+
+ if (updateData) {
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER,
+ g->indexCount() * (g->indexType() == GL_UNSIGNED_SHORT ? 2 : 4),
+ g->indexData(),
+ qt_drawTypeForPattern(g->indexDataPattern()));
+ QSGGeometryData::clearDirtyIndexData(g);
+ }
+
+ } else {
+ if (m_index_buffer_bound) {
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+ m_index_buffer_bound = false;
+ }
+ indexData = g->indexData();
+ }
+
+
+ // draw the stuff...
+ if (g->indexCount()) {
+ glDrawElements(g->drawingMode(), g->indexCount(), g->indexType(), indexData);
+ } else {
+ glDrawArrays(g->drawingMode(), 0, g->vertexCount());
+ }
+
+ // We leave buffers bound for now... They will be reset by bind on next draw() or
+ // set back to 0 if next draw is not using VBOs
+
}
+
QT_END_NAMESPACE
diff --git a/src/declarative/scenegraph/coreapi/qsgrenderer_p.h b/src/declarative/scenegraph/coreapi/qsgrenderer_p.h
index 3fdcf06a08..eed6483cdb 100644
--- a/src/declarative/scenegraph/coreapi/qsgrenderer_p.h
+++ b/src/declarative/scenegraph/coreapi/qsgrenderer_p.h
@@ -45,8 +45,9 @@
#include <qset.h>
#include <qhash.h>
-#include <qglfunctions.h>
-#include <qglshaderprogram.h>
+#include <qcolor.h>
+#include <qopenglfunctions.h>
+#include <qopenglshaderprogram.h>
#include "qsgnode.h"
#include "qsgmaterial.h"
@@ -62,13 +63,12 @@ QT_MODULE(Declarative)
class QSGMaterialShader;
struct QSGMaterialType;
-class QGLFramebufferObject;
+class QOpenGLFramebufferObject;
class TextureReference;
class QSGBindable;
class QSGNodeUpdater;
-
-class Q_DECLARATIVE_EXPORT QSGRenderer : public QObject, public QGLFunctions
+class Q_DECLARATIVE_EXPORT QSGRenderer : public QObject, public QOpenGLFunctions
{
Q_OBJECT
public:
@@ -116,7 +116,7 @@ public:
void setClearColor(const QColor &color);
QColor clearColor() const { return m_clear_color; }
- const QGLContext *glContext() const { Q_ASSERT(m_context); return m_context->glContext(); }
+ QOpenGLContext *glContext() const { Q_ASSERT(m_context); return m_context->glContext(); }
QSGContext *context();
@@ -137,8 +137,7 @@ signals:
void sceneGraphChanged(); // Add, remove, ChangeFlags changes...
protected:
- void draw(const QSGBasicGeometryNode *geometry);
- void bindGeometry(QSGMaterialShader *material, const QSGGeometry *g);
+ void draw(const QSGMaterialShader *material, const QSGGeometry *g);
virtual void render() = 0;
QSGRenderer::ClipType updateStencilClip(const QSGClipNode *clip);
@@ -169,14 +168,17 @@ private:
QSet<QSGNode *> m_nodes_to_preprocess;
QMatrix4x4 m_projection_matrix;
- QGLShaderProgram m_clip_program;
+ QOpenGLShaderProgram m_clip_program;
int m_clip_matrix_id;
const QSGBindable *m_bindable;
- bool m_changed_emitted : 1;
- bool m_mirrored : 1;
- bool m_is_rendering : 1;
+ uint m_changed_emitted : 1;
+ uint m_mirrored : 1;
+ uint m_is_rendering : 1;
+
+ uint m_vertex_buffer_bound : 1;
+ uint m_index_buffer_bound : 1;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QSGRenderer::ClearMode)
@@ -193,10 +195,10 @@ public:
class QSGBindableFbo : public QSGBindable
{
public:
- QSGBindableFbo(QGLFramebufferObject *fbo);
+ QSGBindableFbo(QOpenGLFramebufferObject *fbo);
virtual void bind() const;
private:
- QGLFramebufferObject *m_fbo;
+ QOpenGLFramebufferObject *m_fbo;
};