From 14f9b1e8445dfa319a1f41e57e98defbe047a51b Mon Sep 17 00:00:00 2001
From: Pasi Keranen <pasi.keranen@digia.com>
Date: Wed, 24 Sep 2014 10:55:14 +0300
Subject: [PATCH] Implemented vertexAttrib functions for VariantLists.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Change-Id: I319a9ca8838fe2f68182c2b42c64bd02b40d2280
Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Reviewed-by: Pasi Keränen <pasi.keranen@digia.com>
---
 src/context3d.cpp | 109 ++++++++++++++++++++++++++++++++++++++++++++++
 src/context3d_p.h |  10 ++---
 2 files changed, 114 insertions(+), 5 deletions(-)

diff --git a/src/context3d.cpp b/src/context3d.cpp
index 329cf59..6b4a9e6 100644
--- a/src/context3d.cpp
+++ b/src/context3d.cpp
@@ -4037,3 +4037,112 @@ void CanvasContext::stencilOpSeparate(glEnums face, glEnums fail, glEnums zfail,
                                 << ")";
     glStencilOpSeparate(GLenum(face), GLenum(fail), GLenum(zfail), GLenum(zpass));
 }
+
+
+/*!
+ * \qmlmethod void Context3D::vertexAttrib1fva(int indx, list<variant> values)
+ * Sets the array of float values given in \a values to the generic vertex attribute index
+ * specified by \a indx.
+ */
+/*!
+ * \internal
+ */
+void CanvasContext::vertexAttrib1fva(uint indx, QVariantList values)
+{
+    if (m_logAllCalls) qDebug() << "Context3D::" << __FUNCTION__
+                                << "(indx" << indx
+                                << ", values:" << values
+                                << ")";
+    if (!m_currentProgram)
+        return;
+
+    int size = values.count();
+    float *arrayData = new float[size];
+
+    ArrayUtils::fillFloatArrayFromVariantList(values, arrayData);
+
+    glVertexAttrib1fv(indx, arrayData);
+
+    delete arrayData;
+}
+
+/*!
+ * \qmlmethod void Context3D::vertexAttrib2fva(int indx, list<variant> values)
+ * Sets the array of float values given in \a values to the generic vertex attribute index
+ * specified by \a indx.
+ */
+/*!
+ * \internal
+ */
+void CanvasContext::vertexAttrib2fva(uint indx, QVariantList values)
+{
+    if (m_logAllCalls) qDebug() << "Context3D::" << __FUNCTION__
+                                << "(indx" << indx
+                                << ", values:" << values
+                                << ")";
+    if (!m_currentProgram)
+        return;
+
+    int size = values.count();
+    float *arrayData = new float[size];
+
+    ArrayUtils::fillFloatArrayFromVariantList(values, arrayData);
+
+    glVertexAttrib2fv(indx, arrayData);
+
+    delete arrayData;
+}
+
+/*!
+ * \qmlmethod void Context3D::vertexAttrib3fva(int indx, list<variant> values)
+ * Sets the array of float values given in \a values to the generic vertex attribute index
+ * specified by \a indx.
+ */
+/*!
+ * \internal
+ */
+void CanvasContext::vertexAttrib3fva(uint indx, QVariantList values)
+{
+    if (m_logAllCalls) qDebug() << "Context3D::" << __FUNCTION__
+                                << "(indx" << indx
+                                << ", values:" << values
+                                << ")";
+    if (!m_currentProgram)
+        return;
+
+    int size = values.count();
+    float *arrayData = new float[size];
+
+    ArrayUtils::fillFloatArrayFromVariantList(values, arrayData);
+
+    glVertexAttrib3fv(indx, arrayData);
+
+    delete arrayData;
+}
+
+/*!
+ * \qmlmethod void Context3D::vertexAttrib4fva(int indx, list<variant> values)
+ * Sets the array of float values given in \a values to the generic vertex attribute index
+ * specified by \a indx.
+ */
+/*!
+ * \internal
+ */
+void CanvasContext::vertexAttrib4fva(uint indx, QVariantList values)
+{
+    if (m_logAllCalls) qDebug() << "Context3D::" << __FUNCTION__
+                                << "(indx" << indx
+                                << ", values:" << values
+                                << ")";
+    if (!m_currentProgram)
+        return;
+
+    int size = values.count();
+    float *arrayData = new float[size];
+
+    ArrayUtils::fillFloatArrayFromVariantList(values, arrayData);
+
+    glVertexAttrib4fv(indx, arrayData);
+
+    delete arrayData;
+}
diff --git a/src/context3d_p.h b/src/context3d_p.h
index d4bbd58..facaff7 100644
--- a/src/context3d_p.h
+++ b/src/context3d_p.h
@@ -1162,6 +1162,11 @@ public:
     Q_INVOKABLE void stencilOp(glEnums fail, glEnums zfail, glEnums zpass);
     Q_INVOKABLE void stencilOpSeparate(glEnums face, glEnums fail, glEnums zfail, glEnums zpass);
 
+    Q_INVOKABLE void vertexAttrib1fva(uint indx, QVariantList values);
+    Q_INVOKABLE void vertexAttrib2fva(uint indx, QVariantList values);
+    Q_INVOKABLE void vertexAttrib3fva(uint indx, QVariantList values);
+    Q_INVOKABLE void vertexAttrib4fva(uint indx, QVariantList values);
+
 
     QString glEnumToString(glEnums value) const;
     float devicePixelRatio();
@@ -1181,11 +1186,6 @@ public:
     any getUniform(WebGLProgram program, WebGLUniformLocation? location);
     any getVertexAttrib(GLuint index, GLenum pname);
     GLsizeiptr getVertexAttribOffset(GLuint index, GLenum pname);
-
-     void vertexAttrib1fv(GLuint indx, sequence<GLfloat> values);
-     void vertexAttrib2fv(GLuint indx, sequence<GLfloat> values);
-     void vertexAttrib3fv(GLuint indx, sequence<GLfloat> values);
-     void vertexAttrib4fv(GLuint indx, sequence<GLfloat> values);
     */
 
     void setLogAllCalls(bool logCalls);
-- 
GitLab