[Interest] How to pass data to\from GLSL compute shaders in Qt5?

Gleb "Crazy Sage" Igumnov crazy.sage at gmail.com
Thu Jan 19 07:05:45 CET 2017

Hello. I'm trying to port my program that is using GL compute shaders to Qt and I can't understand, what is correct way to work with buffers.
I initialize and use buffers with following code:

>    QOpenGLBuffer cull_ray_buffer;
>    QOpenGLBuffer cull_face_buffer;
>    QOpenGLBuffer cull_out_buffer;
>    if(!cull_ray_buffer.create())
>    {
>        qDebug()<<"Can't create cull ray buffer";
>        return false;
>    }
>    cull_ray_buffer.allocate(border_rays.size()*sizeof(QVector4D));//border_rays_ is QVector of QVector4D
>    if(!cull_face_buffer.create())
>    {
>        qDebug()<<"Can't create cull face buffer";
>        return false;
>    }
>    cull_face_buffer.allocate(faces_.data(), faces_.size()*sizeof(QVector4D));//faces_ is QVector of QVector4D
>    if(!cull_out_buffer.create())
>    {
>        qDebug()<<"Can't create cull out buffer";
>        return false;
>    }
>    cull_out_buffer.allocate(tmp_out.data(), tmp_out.size()*sizeof(int));//tmp_out_ is QVector of int
>    ogl->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, cull_ray_buffer.bufferId());//ogl is an instance of QOpenGLFunctions_4_4_Core
>    ogl->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, cull_face_buffer.bufferId());
>    ogl->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, cull_out_buffer.bufferId());

In my shader I have buffers declared like this:

>    layout(std430, binding=0) buffer rays{
>        vec4 r[];
>    };
>    layout(std430, binding=1) buffer faces{
>        vec4 f[];
>    };
>    layout(std430, binding=2) buffer outputs{
>        int o[];
>    };

I link shader before creating and binding buffers and then try to get output data by doing one of following things:

>    int* b = static_cast<int*>(cull_out_buffer.map(QOpenGLBuffer::ReadOnly));


>    cull_out_buffer.read(0,tmp_out.data(), tmp_out.size()*sizeof(int))

in first case I'm getting NULL pointer, in second - function returns false.
Also I'm not even sure that shader receives input data correctly (and I don't see any way to check it, because it is console gpu-computing project without any actual rendering).

Can  someone please explain to me, what is correct way of passing data
to compute shaders using QOpenGLBuffer (if there is any)?

With best regards,
 Gleb "Crazy Sage" Igumnov                          mailto:crazy.sage at gmail.com

Это сообщение проверено на вирусы антивирусом Avast.

More information about the Interest mailing list