Important: Please read the Qt Code of Conduct -

How pass an array from qml to opengl Shader

  • Hello Everyone,

    I'm trying to paint a polygon on a map, using QML + Opengl.
    I can paint everything I want but, using QML, I don't find any solutions to pass an array of colors as a propriety of my Shaders: the array is correctly initialized in my app, but there is no way to pass it to opengl program.

    In "square.vert" I tried to define something like:
    attribute float sArray[ELEMENT]; // sArray is the proprity correctly defined in qml container

    Can anyone help me? Is there another way to pass a int[] o float[] to openGl scripts?

    Thanks in advance,


    ShaderEffect {
        width: parent.width
        height: width
        blending: true
        property vector2d u_viewport_resolution : Qt.vector2d(width*1.0, height*1.0)
        **property variant qmlArray: externArray**
        property bool quant: true
        property int cellColor: externcellColor
        fragmentShader: "qrc:/clutter.frag"
    function vector_initialize()
        var colorIndex = 0;
        for (var i = 0; i < 11520; ++i ) {
            externArray[i]= 3.;//colorIndex;
            colorIndex = colorIndex +1;
            if (colorIndex == 5 )
                colorIndex = 0;