Example #1
0
bool SpannerQRgbAttribute::merge(void*& parent, void* children[], bool postRead) const {
    if (postRead) {
        for (int i = 0; i < MERGE_COUNT; i++) {
            if (qAlpha(decodeInline<QRgb>(children[i])) != 0) {
                return false;
            }
        }
        return true;
    }
    QRgb parentValue = decodeInline<QRgb>(parent);
    int totalAlpha = qAlpha(parentValue) * Attribute::MERGE_COUNT;
    int totalRed = qRed(parentValue) * totalAlpha;
    int totalGreen = qGreen(parentValue) * totalAlpha;
    int totalBlue = qBlue(parentValue) * totalAlpha;
    bool allChildrenTransparent = true;
    for (int i = 0; i < Attribute::MERGE_COUNT; i++) {
        QRgb value = decodeInline<QRgb>(children[i]);
        int alpha = qAlpha(value);
        totalRed += qRed(value) * alpha;
        totalGreen += qGreen(value) * alpha;
        totalBlue += qBlue(value) * alpha;
        totalAlpha += alpha;
        allChildrenTransparent &= (alpha == 0);
    }
    if (totalAlpha == 0) {
        parent = encodeInline(QRgb());
    } else {
        parent = encodeInline(qRgba(totalRed / totalAlpha, totalGreen / totalAlpha,
            totalBlue / totalAlpha, totalAlpha / MERGE_COUNT));
    }
    return allChildrenTransparent;
} 
Example #2
0
void* QRgbAttribute::createFromVariant(const QVariant& value) const {
    switch (value.userType()) {
        case QMetaType::QColor:
            return encodeInline(value.value<QColor>().rgba());
        
        default:
            return encodeInline((QRgb)value.toUInt());
    } 
}
Example #3
0
void* QRgbAttribute::mix(void* first, void* second, float alpha) const {
    QRgb firstValue = decodeInline<QRgb>(first);
    QRgb secondValue = decodeInline<QRgb>(second);
    return encodeInline(qRgba(
        glm::mix((float)qRed(firstValue), (float)qRed(secondValue), alpha),
        glm::mix((float)qGreen(firstValue), (float)qGreen(secondValue), alpha),
        glm::mix((float)qBlue(firstValue), (float)qBlue(secondValue), alpha),
        glm::mix((float)qAlpha(firstValue), (float)qAlpha(secondValue), alpha)));
}
Example #4
0
void* QRgbAttribute::blend(void* source, void* dest) const {
    QRgb sourceValue = decodeInline<QRgb>(source);
    QRgb destValue = decodeInline<QRgb>(dest);    
    float alpha = qAlpha(sourceValue) / EIGHT_BIT_MAXIMUM;
    return encodeInline(qRgba(
        glm::mix((float)qRed(destValue), (float)qRed(sourceValue), alpha),
        glm::mix((float)qGreen(destValue), (float)qGreen(sourceValue), alpha),
        glm::mix((float)qBlue(destValue), (float)qBlue(sourceValue), alpha),
        glm::mix((float)qAlpha(destValue), (float)qAlpha(sourceValue), alpha)));
}
Example #5
0
bool PackedNormalAttribute::merge(void*& parent, void* children[], bool postRead) const {
    QRgb firstValue = decodeInline<QRgb>(children[0]);
    glm::vec3 total = unpackNormal(firstValue) * (float)qAlpha(firstValue);
    bool allChildrenEqual = true;
    for (int i = 1; i < Attribute::MERGE_COUNT; i++) {
        QRgb value = decodeInline<QRgb>(children[i]);
        total += unpackNormal(value) * (float)qAlpha(value);
        allChildrenEqual &= (firstValue == value);
    }
    float length = glm::length(total);
    parent = encodeInline(length < EPSILON ? QRgb() : packNormal(total / length));
    return allChildrenEqual;
}
Example #6
0
bool QRgbAttribute::merge(void*& parent, void* children[], bool postRead) const {
    QRgb firstValue = decodeInline<QRgb>(children[0]);
    int totalAlpha = qAlpha(firstValue);
    int totalRed = qRed(firstValue) * totalAlpha;
    int totalGreen = qGreen(firstValue) * totalAlpha;
    int totalBlue = qBlue(firstValue) * totalAlpha;
    bool allChildrenEqual = true;
    for (int i = 1; i < Attribute::MERGE_COUNT; i++) {
        QRgb value = decodeInline<QRgb>(children[i]);
        int alpha = qAlpha(value);
        totalRed += qRed(value) * alpha;
        totalGreen += qGreen(value) * alpha;
        totalBlue += qBlue(value) * alpha;
        totalAlpha += alpha;
        allChildrenEqual &= (firstValue == value);
    }
    if (totalAlpha == 0) {
        parent = encodeInline(QRgb());
    } else {
        parent = encodeInline(qRgba(totalRed / totalAlpha, totalGreen / totalAlpha,
            totalBlue / totalAlpha, totalAlpha / MERGE_COUNT));
    }
    return allChildrenEqual;
} 
bool QRgbAttribute::merge(void*& parent, void* children[]) const {
    QRgb firstValue = decodeInline<QRgb>(children[0]);
    int totalRed = qRed(firstValue);
    int totalGreen = qGreen(firstValue);
    int totalBlue = qBlue(firstValue);
    int totalAlpha = qAlpha(firstValue);
    bool allChildrenEqual = true;
    for (int i = 1; i < Attribute::MERGE_COUNT; i++) {
        QRgb value = decodeInline<QRgb>(children[i]);
        totalRed += qRed(value);
        totalGreen += qGreen(value);
        totalBlue += qBlue(value);
        totalAlpha += qAlpha(value);
        allChildrenEqual &= (firstValue == value);
    }
    parent = encodeInline(qRgba(totalRed / MERGE_COUNT, totalGreen / MERGE_COUNT,
        totalBlue / MERGE_COUNT, totalAlpha / MERGE_COUNT));
    return allChildrenEqual;
} 
Example #8
0
void MetavoxelSystem::init() {
    if (!_program.isLinked()) {
        switchToResourcesParentIfRequired();
        _program.addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/metavoxel_point.vert");
        _program.link();
       
        _pointScaleLocation = _program.uniformLocation("pointScale");
    }
    
    AttributeRegistry::getInstance()->configureScriptEngine(&_scriptEngine);
    
    QFile scriptFile("resources/scripts/sphere.js");
    scriptFile.open(QIODevice::ReadOnly);
    QScriptValue guideFunction = _scriptEngine.evaluate(QTextStream(&scriptFile).readAll());
    _data.setAttributeValue(MetavoxelPath(), AttributeValue(AttributeRegistry::getInstance()->getGuideAttribute(),
        encodeInline(PolymorphicDataPointer(new ScriptedMetavoxelGuide(guideFunction)))));
    
    _buffer.setUsagePattern(QOpenGLBuffer::DynamicDraw);
    _buffer.create();
}
Example #9
0
bool SpannerPackedNormalAttribute::merge(void*& parent, void* children[], bool postRead) const {
    if (postRead) {
        for (int i = 0; i < MERGE_COUNT; i++) {
            if (qAlpha(decodeInline<QRgb>(children[i])) != 0) {
                return false;
            }
        }
        return true;
    }
    QRgb parentValue = decodeInline<QRgb>(parent);
    glm::vec3 total = unpackNormal(parentValue) * (float)(qAlpha(parentValue) * Attribute::MERGE_COUNT);
    bool allChildrenTransparent = true;
    for (int i = 0; i < Attribute::MERGE_COUNT; i++) {
        QRgb value = decodeInline<QRgb>(children[i]);
        int alpha = qAlpha(value);
        total += unpackNormal(value) * (float)alpha;
        allChildrenTransparent &= (alpha == 0);
    }
    float length = glm::length(total);
    parent = encodeInline(length < EPSILON ? QRgb() : packNormal(total / length));
    return allChildrenTransparent;
}
Example #10
0
void* QRgbAttribute::createFromScript(const QScriptValue& value, QScriptEngine* engine) const {
    return encodeInline((QRgb)value.toUInt32());
}
Example #11
0
void* PackedNormalAttribute::blend(void* source, void* dest) const {
    QRgb sourceValue = decodeInline<QRgb>(source);
    QRgb destValue = decodeInline<QRgb>(dest);    
    float alpha = qAlpha(sourceValue) / EIGHT_BIT_MAXIMUM;
    return encodeInline(packNormal(glm::normalize(glm::mix(unpackNormal(destValue), unpackNormal(sourceValue), alpha))));
}
Example #12
0
void* PackedNormalAttribute::mix(void* first, void* second, float alpha) const {
    glm::vec3 firstNormal = unpackNormal(decodeInline<QRgb>(first));
    glm::vec3 secondNormal = unpackNormal(decodeInline<QRgb>(second));
    return encodeInline(packNormal(glm::normalize(glm::mix(firstNormal, secondNormal, alpha))));
}
Example #13
0
void* SharedObjectAttribute::createFromVariant(const QVariant& value) const {
    return create(encodeInline(value.value<SharedObjectPointer>()));
}