PDA

View Full Version : OpenGL & Multiprocessing



07-04-2000, 06:47 AM
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?

Claudio
07-05-2000, 12:15 AM
I have tried to call opengl api to an preemptive tread in macos but it doesn't work.

07-05-2000, 06:54 PM
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?

-Doug

The mailing list archive is down, I bookmarked this link and pasted the code I got below: http://webx.lists.apple.com/?13@64.XU6wa5bTjYi^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 (; http://www.opengl.org/discussion_boards/ubb/wink.gif
*****{
*******(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
*************inWorld->Iterate(kPhysicsDelay);
*************step += kPhysicsDelay;
*********}
********
*********inWorld->Iterate(dTime - step);
*****}
****
*****return noErr;
}

Claudio
07-05-2000, 10:30 PM
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.