Beispiel #1
0
void QGLIndexBufferPrivate::append
    (const QGLIndexBufferPrivate *other, uint offset, int start)
{
    if (elementType == GL_UNSIGNED_SHORT &&
            other->elementType == GL_UNSIGNED_SHORT) {
        // Both buffers are ushort.
        const ushort *data = other->indexesShort.constData() + start;
        int count = other->indexesShort.count() - start;
        indexesShort.reserve(indexesShort.count() + count);
        indexCount += count;
        while (count-- > 0)
            indexesShort.append(ushort(*data++ + offset));
    } else if (elementType == GL_UNSIGNED_SHORT) {
        // Only first buffer is ushort: convert it to int first.
        const ushort *indexes = indexesShort.constData();
        int count = indexesShort.count();
        indexesInt.reserve(count + other->indexesInt.count());
        while (count-- > 0)
            indexesInt.append(*indexes++);
        indexesShort = QArray<ushort>();
        elementType = GL_UNSIGNED_INT;
        const uint *data = other->indexesInt.constData() + start;
        count = other->indexesInt.count() - start;
        indexCount += count;
        while (count-- > 0)
            indexesInt.append(*data++ + offset);
    } else if (other->elementType == GL_UNSIGNED_SHORT) {
        // Only second buffer is ushort.
        const ushort *data = other->indexesShort.constData() + start;
        int count = other->indexesShort.count() - start;
        indexesInt.reserve(indexesInt.count() + count);
        indexCount += count;
        while (count-- > 0)
            indexesInt.append(*data++ + offset);
    } else {
        // Neither buffer is ushort.
        const uint *data = other->indexesInt.constData() + start;
        int count = other->indexesInt.count() - start;
        indexesInt.reserve(indexesInt.count() + count);
        indexCount += count;
        while (count-- > 0)
            indexesInt.append(*data++ + offset);
    }
}
Beispiel #2
0
static QArray<ushort> qt_qarray_uint_to_ushort(const QArray<uint> &array)
{
    QArray<ushort> result;
    const uint *values = array.constData();
    int size = array.size();
    bool largeValue = false;
    result.reserve(size);
    while (size-- > 0) {
        uint value = *values++;
        if (ushort(value) != value)
            largeValue = true;
        result.append(ushort(value));
    }
    if (largeValue)
        qWarning("QGLIndexBuffer::setIndexes: large 32-bit value provided to a 16-bit only buffer");
    return result;
}