I create two thread and two HGLRC,Them can share list and texture(because I use wglShareLists.
Thread1 for draw the created model and have priority THREAD_PRIORITY_NORMAL
Thread2 for create the next model and have priority THREAD_PRIORITY_BELOW_NORMAL
When Thread2 finish a creating model job,Thread2 will change the model that thread1 draw,so thread1 will draw the new model
The problem is:
Sometimes,when thread2 put texture data to graphic card or get texture data from graphic card or remove some texture data,thead1 will block in some gl function for a moment,like glClear ,glViewport and so on…
I think maybe the GPU or pipeline are too busy,so
The first method I try is:
I use CCriticalSection to synchronization the two thread in order to prevent the two thread send command at the same time.
However It does not work,thread1 also block in some gl funtion sometimes.
The second method I try is:
I think that maybe there are many command reside in the command queue,When queue is full,the next command will waiting for a moment to let graphic card run these command.
So besides the first method,I add glFinish everywhere to make sure the command before call glFinish will send to graphic card then the next command will be sent after calling glFinish.
However It does not work,thread1 also block in some gl funtion sometimes.
The second method I try is:
I doubt glFinish do nothing,so I replace glFinish by the code below:
glFlush();
GLuint querie;
glGenQueriesARB(1,&querie);
glBeginQueryARB(GL_SAMPLES_PASSED_ARB,querie);
glEndQueryARB(GL_SAMPLES_PASSED_ARB);
GLint available=1;
glGetQueryObjectivARB(querie,GL_QUERY_RESULT_AVAILABLE_ARB,&available);
while (!available)
{
Sleep(1);
glGetQueryObjectivARB(querie,GL_QUERY_RESULT_AVAILABLE_ARB,&available);
}
However It does not work,thread1 also block in some gl funtion sometimes.But it is better than before,the times of block are fewer and the time of block is shorter.
Another situation is that ATI chip is more seriously than nVidia chip.
The situation of block always happen in ATI chip no matter the level of chip
The situation of block seldom happen in high level nVidia chip,even if it happened,the time of block is very short.It usually happened in low level nVidia chip.
The problem have confused me for three month.
I have tried many mothods,but …
Can anyone help me ?