1 #include "vertexdatainterpreter.h"
26 return sizeof(double);
34 convertData(const QByteArray &dataArray,
42 int dataSize = dataArray.size() - startingOffset;
43 const char *data = dataArray.constData() + startingOffset;
44 int typeSize = sizeForType(type);
45 int elementSize = numComponents * typeSize;
50 int numElements = dataSize / stride;
52 if ((numElements % numComponents) != 0) {
53 int temp = qFloor(dataSize / (float)stride);
54 int fullElemSize = temp * stride;
55 if (fullElemSize + numComponents * typeSize <= dataSize) {
56 /* num full elements plus the part of the buffer in which we fit */
57 numElements = temp + 1;
64 qDebug() << "numElements = "<<numElements;
65 qDebug() << "elementSize = "<<elementSize;
66 qDebug() << "stride = "<<stride;
67 qDebug() << "numComponents = "<<numComponents;
68 qDebug() << "typeSize = "<<typeSize;
72 for (int i = 0; i < numElements; ++i) {
73 QString vectorString = QString::fromLatin1("%1) [").arg(i);
74 for (int j = 0; j < numComponents; ++j) {
75 int offset = i*stride + j*typeSize;
77 (const T*)(data + offset);
79 vectorString += QString::number(elem);
80 if ((j + 1) < numComponents)
81 vectorString += QLatin1String(", ");
84 strings += vectorString;
91 VertexDataInterpreter::VertexDataInterpreter(QObject *parent)
101 void VertexDataInterpreter::setData(const QByteArray &data)
105 m_listWidget->clear();
108 QByteArray VertexDataInterpreter::data() const
113 void VertexDataInterpreter::setType(int type)
118 int VertexDataInterpreter::type() const
123 void VertexDataInterpreter::setStride(int stride)
128 int VertexDataInterpreter::stride() const
133 void VertexDataInterpreter::setComponents(int num)
138 int VertexDataInterpreter::components() const
143 void VertexDataInterpreter::setListWidget(QListWidget *listWidget)
145 m_listWidget = listWidget;
148 void VertexDataInterpreter::interpretData()
153 m_listWidget->clear();
155 if (m_data.isEmpty() || !m_components)
161 lst = convertData<qint8>(m_data, m_type, m_stride, m_components,
165 lst = convertData<quint8>(m_data, m_type, m_stride, m_components,
169 lst = convertData<qint16>(m_data, m_type, m_stride, m_components,
173 lst = convertData<quint16>(m_data, m_type, m_stride, m_components,
177 lst = convertData<qint32>(m_data, m_type, m_stride, m_components,
181 lst = convertData<quint32>(m_data, m_type, m_stride, m_components,
185 lst = convertData<float>(m_data, m_type, m_stride, m_components,
189 lst = convertData<double>(m_data, m_type, m_stride, m_components,
193 qDebug()<<"unkown gltype = "<<m_type;
195 //qDebug()<<"list is "<<lst;
196 m_listWidget->addItems(lst);
200 void VertexDataInterpreter::setTypeFromString(const QString &str)
202 if (str == QLatin1String("GL_FLOAT")) {
204 } else if (str == QLatin1String("GL_INT")) {
206 } else if (str == QLatin1String("GL_UNSIGNED_INT")) {
208 } else if (str == QLatin1String("GL_SHORT")) {
210 } else if (str == QLatin1String("GL_UNSIGNED_SHORT")) {
212 } else if (str == QLatin1String("GL_BYTE")) {
214 } else if (str == QLatin1String("GL_UNSIGNED_BYTE")) {
216 } else if (str == QLatin1String("GL_DOUBLE")) {
219 qDebug()<<"unknown vertex data type";
223 int VertexDataInterpreter::startingOffset() const
225 return m_startingOffset;
228 void VertexDataInterpreter::setStartingOffset(int offset)
230 m_startingOffset = offset;
233 #include "vertexdatainterpreter.moc"