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)));
#include <GL/gl.h>
+#include <qmath.h>
+
static int
sizeForType(int glType)
{
return sizeof(GLint);
case GL_UNSIGNED_INT:
return sizeof(GLuint);
+ case GL_DOUBLE:
+ return sizeof(GLdouble);
default:
return sizeof(GLint);
}
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)
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;
}
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";
}