]> git.cworth.org Git - apitrace/commitdiff
Incorporate Jose's patch and make vertexdatainterpreter work.
authorZack Rusin <zack@kde.org>
Thu, 7 Apr 2011 23:09:28 +0000 (19:09 -0400)
committerZack Rusin <zack@kde.org>
Thu, 7 Apr 2011 23:09:28 +0000 (19:09 -0400)
gui/mainwindow.cpp
gui/ui/mainwindow.ui
gui/vertexdatainterpreter.cpp

index e02dbd8ac7633f420cd6bf0f0af276d69a143f03..380ef8a132a679fc5cdcbc2f4b100dcef7ed2b3f 100644 (file)
@@ -57,7 +57,7 @@ MainWindow::MainWindow()
 
     connect(m_ui.vertexInterpretButton, SIGNAL(clicked()),
             m_vdataInterpreter, SLOT(interpretData()));
-    connect(m_ui.vertexTypeCB, SIGNAL(activated(const QString&)),
+    connect(m_ui.vertexTypeCB, SIGNAL(currentIndexChanged(const QString&)),
             m_vdataInterpreter, SLOT(setTypeFromString(const QString&)));
     connect(m_ui.vertexStrideSB, SIGNAL(valueChanged(int)),
             m_vdataInterpreter, SLOT(setStride(int)));
index 6c7e25e5e667b81b55d005702b4fadbedd1ee074..d0d14264c71869ebc495b97f7a861beb736b88c2 100644 (file)
            <string>GL_FLOAT</string>
           </property>
          </item>
+         <item>
+          <property name="text">
+           <string>GL_DOUBLE</string>
+          </property>
+         </item>
         </widget>
        </item>
        <item row="1" column="0">
        </item>
        <item row="2" column="1">
         <widget class="QSpinBox" name="vertexComponentsSB">
+         <property name="minimum">
+          <number>1</number>
+         </property>
          <property name="maximum">
           <number>256</number>
          </property>
index e00466b18bea56ab15c2ac764328a3f76fad402c..7e3616e35b517f079270a9dcc3b33e3ac28151d2 100644 (file)
@@ -7,6 +7,8 @@
 
 #include <GL/gl.h>
 
+#include <qmath.h>
+
 static int
 sizeForType(int glType)
 {
@@ -25,6 +27,8 @@ sizeForType(int glType)
         return sizeof(GLint);
     case GL_UNSIGNED_INT:
         return sizeof(GLuint);
+    case GL_DOUBLE:
+        return sizeof(GLdouble);
     default:
         return sizeof(GLint);
     }
@@ -41,35 +45,39 @@ convertData(const QByteArray &dataArray,
 
     const char *data = dataArray.constData();
     int typeSize = sizeForType(type);
-    int sizePerAttribute = typeSize;
+    int elementSize = numComponents * typeSize;
+
+    if (!stride)
+        stride = elementSize;
 
-    if (stride)
-        sizePerAttribute = stride;
+    int numElements = dataArray.size() / stride;
 
-    int numElements = dataArray.size() / sizePerAttribute;
+    if ((numElements % numComponents) != 0) {
+        int temp = qFloor(dataArray.size() / (float)stride);
+        int fullElemSize = temp * stride;
+        if (fullElemSize + numComponents * typeSize <= dataArray.size()){
+            /* num full elements plus the part of the buffer in which we fit */
+            numElements = temp + 1;
+        } else {
+            numElements = temp;
+        }
+    }
 
 #if 0
     qDebug() << "numElements = "<<numElements;
-    qDebug() << "sizePerAttribute = "<<sizePerAttribute;
+    qDebug() << "elementSize = "<<elementSize;
     qDebug() << "stride = "<<stride;
     qDebug() << "numComponents = "<<numComponents;
+    qDebug() << "typeSize = "<<typeSize;
 #endif
 
-    if (numElements * sizePerAttribute > dataArray.size()) {
-        qDebug()<<"Vertex data too large for the given binary data";
-        return strings;
-    }
-    if ((numElements % numComponents) != 0) {
-        qDebug()<<"Bad stride for the given vertex data";
-        return strings;
-    }
 
-    for (int i = 0; i < numElements; i += numComponents) {
-        QString vectorString = QString::fromLatin1("%1) [").arg(i / numComponents);
+    for (int i = 0; i < numElements; ++i) {
+        QString vectorString = QString::fromLatin1("%1) [").arg(i);
         for (int j = 0; j < numComponents; ++j) {
-            int idx = i + j;
+            int offset = i*stride + j*typeSize;
             const T *elementPtr =
-                (const T*)(data + idx * sizePerAttribute);
+                (const T*)(data + offset);
             T elem = *elementPtr;
             vectorString += QString::number(elem);
             if ((j + 1) < numComponents)
@@ -172,6 +180,9 @@ void VertexDataInterpreter::interpretData()
     case GL_UNSIGNED_INT:
         lst = convertData<int>(m_data, m_type, m_stride, m_components);
         break;
+    case GL_DOUBLE:
+        lst = convertData<double>(m_data, m_type, m_stride, m_components);
+        break;
     default:
         qDebug()<<"unkown gltype = "<<m_type;
     }
@@ -196,6 +207,8 @@ void VertexDataInterpreter::setTypeFromString(const QString &str)
         setType(GL_BYTE);
     } else if (str == QLatin1String("GL_UNSIGNED_BYTE")) {
         setType(GL_UNSIGNED_BYTE);
+    } else if (str == QLatin1String("GL_DOUBLE")) {
+        setType(GL_DOUBLE);
     } else {
         qDebug()<<"unknown vertex data type";
     }