I tried the makeCurrent but I got error.
As suggested by pcpower in irc (thanks), I have changed my code, and now instead of display lists I'm using Virtual Buffer Objects, with QGLBuffer. If my code is not threaded everything is working fine, but when I run threads, the buffers are created by threads (without error), but nothing is displayed - I think its because they have different contexts. Here's a sample of my code:
viewer.cpp:
@
Viewer::Viewer(QWidget *parent) : QGLViewer(parent) {}
void Viewer::draw()
{
for(int i=0; i<facesToDisplay; i++)
faces[i]->draw();
}
void Viewer::loadNeededFaces()
{
for(int i=0; i<totalFaces; i++)
{
if(faceIsNeeded(i))
QtConcurrent::run(this, &Viewer;::loadFace, i);
}
}
void Viewer::loadFace(int faceNumber)
{
Face* face = new Face(faceNumber);
face->createBuffer();
}
@
Face.cpp
@
void Face::createBuffer()
{
vertexBuffer = new QGLBuffer(QGLBuffer::VertexBuffer);
vertexBuffer->create();
vertexBuffer->bind();
vertexBuffer->setUsagePattern(QGLBuffer::StaticDraw);
vertexBuffer->allocate(vertexs, 3totalVerticessizeof(GLfloat));
}
void Face::draw()
{
vertexBuffer->bind())
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0));
glDrawElements(GL_LINE_STRIP, 5, GL_UNSIGNED_INT, 0);
glDrawArrays(GL_QUAD_STRIP, 0, totalVertices);
glDisableClientState(GL_VERTEX_ARRAY);
}
@
The idea is to have a main GUI thread (instance of Viewer) to display the visible faces, and forecast the faces that will needed soon, to preload them using working threads, so when the user rotates the object, the faces that will appear are already precalculated (and possible in the GPU), so the loading will be smooth.
The code isn't 100% correct, its just a sample of my code. Anyone can give me a hint on how to put that code working ? I think I need to get some context and then use makeCurrent. I have already tried to pass to the Face instance, a pointer to the Viewer, and then call the makeCurrent on that pointer, but with no success - "QGLContext::makeCurrent(): Failed."