OpenGL & Multiprocessing

Does anyone have sample code using Multiprocessing threads with OpenGL, such as for a physics simulation? Or in general are their other resources available on multiprocessing other than Apple’s documentation?

I have tried to call opengl api to an preemptive tread in macos but it doesn’t work.

Well, I’ve seen starter code in the Mac-OpenGL mailing list archives, but it’s still missing the part connecting the physics calculations (done in an MPTask) and the OpenGL drawing.
How can I communicate between my OpenGL drawing routines and the MPTask which is updating the positions and velocities or whatever in the simulation?


The mailing list archive is down, I bookmarked this link and pasted the code I got below:^12@.ee93db1

(first code snippet)

MPTaskID physicsTask;
MPQueueID physicsQueue;
OSStatus err;

err = MPCreateQueue(&queue);
// Handle error
err = MPCreateTask ((TaskProc)&CalculationTask, thePhysicsWorld,
0, queue, 0, 0, 0, &task);
// Handle error

glutMainLoop(); // You may want to change this bit. :-p

err = MPTerminateTask(task, noErr);

(2nd snippet)

SStatus PhysicsCalculationTask(PhysicsWorld *inWorld)
AbsoluteTime currentTime, lastTime;
Scalar dTime, step;

 lastTime = UpTime();
 for (; [img][/img]
   (void) MPWaitOnSemaphore 

(gSomeSemaphoreThatNeverHappens,gYourDelay); //ignore error since it
will be a timeout err

    // or MPDelayUntil(AbsoluteTime *expirationTime);

     lastTime = cTime;
     step = 0.0;
     while ((step + kPhysicsDelay) < dTime)
         // Smooth out any timing bumps
         step += kPhysicsDelay;
     inWorld->Iterate(dTime - step);

 return noErr;


In my engine, i’d like to do physic calculation and object transformation in a preemptive task.
These use of semaphore, in code snippet is good.
Only one things:
The semaphore must be “open” when all the world ( sky, ground, terrain , object) is draw.
You know that only calculation of physich and transformation (by your personal routin for alter transfor matrix) can be in preemptive task, we mu use another way to draw the object.
Al object in my engine are subclass of one named _3DObejct, this is an abstract class.
I have a dinamic list where the element are funcion pointer to a draw function of all object, remember all are _3DObject subclass.
So in null event i run the list and exe all drawing function.
This appen only when calculation tread are finish do calculate all object.
_3DObject class have tow base metod draw( called in nullEvent as i said) and calculate() this metod is calle in preemptive thread .
In this thread i have another list where all element are pointer to calculate() metod of all object.

I hope this i useful for you.
Ask what you want.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.