1 #include "vertexdatainterpreter.h"
11 sizeForType(int glType)
15 return sizeof(GLfloat);
16 case GL_UNSIGNED_BYTE:
17 return sizeof(GLubyte);
19 return sizeof(GLbyte);
21 return sizeof(GLshort);
22 case GL_UNSIGNED_SHORT:
23 return sizeof(GLushort);
27 return sizeof(GLuint);
35 convertData(const QByteArray &dataArray,
42 const char *data = dataArray.constData();
43 int typeSize = sizeForType(type);
44 int sizePerAttribute = typeSize;
47 sizePerAttribute = stride;
49 int numElements = dataArray.size() / sizePerAttribute;
52 qDebug() << "numElements = "<<numElements;
53 qDebug() << "sizePerAttribute = "<<sizePerAttribute;
54 qDebug() << "stride = "<<stride;
55 qDebug() << "numComponents = "<<numComponents;
58 if (numElements * sizePerAttribute > dataArray.size()) {
59 qDebug()<<"Vertex data too large for the given binary data";
62 if ((numElements % numComponents) != 0) {
63 qDebug()<<"Bad stride for the given vertex data";
67 for (int i = 0; i < numElements; i += numComponents) {
68 QString vectorString = QString::fromLatin1("%1) [").arg(i / numComponents);
69 for (int j = 0; j < numComponents; ++j) {
72 (const T*)(data + idx * sizePerAttribute);
74 vectorString += QString::number(elem);
75 if ((j + 1) < numComponents)
76 vectorString += QLatin1String(", ");
79 strings += vectorString;
86 VertexDataInterpreter::VertexDataInterpreter(QObject *parent)
95 void VertexDataInterpreter::setData(const QByteArray &data)
99 m_listWidget->clear();
102 QByteArray VertexDataInterpreter::data() const
107 void VertexDataInterpreter::setType(int type)
112 int VertexDataInterpreter::type() const
117 void VertexDataInterpreter::setStride(int stride)
122 int VertexDataInterpreter::stride() const
127 void VertexDataInterpreter::setComponents(int num)
132 int VertexDataInterpreter::components() const
137 void VertexDataInterpreter::setListWidget(QListWidget *listWidget)
139 m_listWidget = listWidget;
142 void VertexDataInterpreter::interpretData()
147 m_listWidget->clear();
149 if (m_data.isEmpty() || !m_components)
155 lst = convertData<float>(m_data, m_type, m_stride, m_components);
157 case GL_UNSIGNED_BYTE:
158 lst = convertData<quint8>(m_data, m_type, m_stride, m_components);
161 lst = convertData<qint8>(m_data, m_type, m_stride, m_components);
164 lst = convertData<qint16>(m_data, m_type, m_stride, m_components);
166 case GL_UNSIGNED_SHORT:
167 lst = convertData<quint16>(m_data, m_type, m_stride, m_components);
170 lst = convertData<unsigned int>(m_data, m_type, m_stride, m_components);
172 case GL_UNSIGNED_INT:
173 lst = convertData<int>(m_data, m_type, m_stride, m_components);
176 qDebug()<<"unkown gltype = "<<m_type;
178 //qDebug()<<"list is "<<lst;
179 m_listWidget->addItems(lst);
183 void VertexDataInterpreter::setTypeFromString(const QString &str)
185 if (str == QLatin1String("GL_FLOAT")) {
187 } else if (str == QLatin1String("GL_INT")) {
189 } else if (str == QLatin1String("GL_UNSIGNED_INT")) {
190 setType(GL_UNSIGNED_INT);
191 } else if (str == QLatin1String("GL_SHORT")) {
193 } else if (str == QLatin1String("GL_UNSIGNED_SHORT")) {
194 setType(GL_UNSIGNED_SHORT);
195 } else if (str == QLatin1String("GL_BYTE")) {
197 } else if (str == QLatin1String("GL_UNSIGNED_BYTE")) {
198 setType(GL_UNSIGNED_BYTE);
200 qDebug()<<"unknown vertex data type";
204 #include "vertexdatainterpreter.moc"