PDA

View Full Version : qt and gl/cl inerop



giugio
24th December 2012, 12:17
hеllo.
I'm trying to use an interop with opengl and opencl in qt.
this is my code:


GLuint id = 0;
glGenBuffers(1, &id);
glBindBuffer(GL_ARRAY_BUFFER, id);
glBufferData(GL_ARRAY_BUFFER, lSize, NULL, GL_STATIC_DRAW);

int err;
cl::BufferGL buff;
buff= cl::BufferGL(context, CL_MEM_WRITE_ONLY, id, &err);

glBindBuffer(GL_ARRAY_BUFFER, 0);
vertexBufferObject = id;

I get always the same error:
-60: CL_INVALID_GL_OBJECT.
i omitted the construction of the gl/cl context code, but I'm was try this without qt and all works fine.
When i use the code in qt i get the error.
What can be?
the threads and contexts that are used in qt?
How i can resolve?
But I wish understand and use my own library, rather than use an already done library .
thanks.

amleto
24th December 2012, 13:41
show your COMPLETE & COMPILABLE example that works, and then show your COMPLETE & COMPILABLE example that doesn't work.

Please explain how this is a qt question.

giugio
25th December 2012, 15:37
thanks.
but I must gain some information, before post my code:
I'm trying to work with
http://doc.qt.digia.com/opencl-snapshot/qclcontextgl.html.
I not understand the
supportsObjectSharing
and the


/*!
Constructs a new OpenCL context object that is suitable for use
with OpenGL objects.
*/
QCLContextGL::QCLContextGL()
: QCLContext(), d_ptr(new QCLContextGLPrivate())
{
}

in the qclcontextgl.cpp line:81.
1)I'm not understand what is a 1)context and what is a 2)contextprivate.
Is related to multithreading?
where i can found documentation on this arg?
thanks.

amleto
25th December 2012, 19:25
1 - http://www.dyn-lab.com/articles/cl-gl.html

2 - you don't need to worry about it - it is the qt implementation. It wont be thread related.

giugio
25th December 2012, 20:42
this is my qglwidget constructor for try to create interoperability:
i use this lib :http://doc.qt.digia.com/opencl-snapshot/qclcontextgl.html



CTest::CTest(HINSTANCE hPrevInstance, int nShowCmd)
{
m_hPrevInstance = hPrevInstance;
m_nShowCmd = nShowCmd;
CApplication::m_Draw = bind(&CTest::Draw, this);
CApplication::m_Create = bind(&CTest::CreateInit, this);

setMouseTracking(true);
m_pTimer = new QTimer(this);
connect(m_pTimer, SIGNAL(timeout()), this , SLOT(OnIdleOpenGl()) );
makeCurrent();
context.create();

vert = NULL;
if (!vert) {
vert = new QGLBuffer(QGLBuffer::VertexBuffer);
vert->setUsagePattern(QGLBuffer::DynamicDraw);
if (!vert->create()) {
delete vert;
vert = 0;

}
}
if (vert) {
vert->bind();
vert->allocate(sizeof(GLfloat) * 4 * 4);
if (!vert->map(QGLBuffer::WriteOnly)) {
// No point using a vertex buffer if we cannot map it.
vert->unmap();
vert->release();
delete vert;
vert = 0;
} else {
vert->unmap();
vert->release();
}

}
QCLBuffer BBB;
if (context.supportsObjectSharing()) {
BBB = context.createGLBuffer(vert,QCLMemoryObject::Write Only);
}

m_pTimer->setInterval( 3 );
m_pTimer->start();
}

but this:
context.supportsObjectSharing()
return false
and this if i remove the test:
BBB = context.createGLBuffer(vert,QCLMemoryObject::Write Only);
return a void openclbuffer.

thanks

amleto
25th December 2012, 22:26
looks like your conext should acquire() the qclbuffer

giugio
26th December 2012, 00:13
in the bezierpatch demo of the library all work fine, but i'm not understand why!

giugio
26th December 2012, 18:32
how i can understand the thread related problematics in qt and opengl?
thanks.

amleto
26th December 2012, 20:31
what thread 'problematics'?