Hi all !
I'am developing quite a big app with a colleague, dealing with computer
graphics.
We have had quite a large workaround during the last days on the subject
of threads, looking in the mailing list archive, reading books, testing
and so on.
However, we still have major problems.
In this mail I first expose what we need to do.
I then discuss the propositions spl made in previous mails.
By the end, I give the general idea of what may be, perhaps, a solution
based on Xlib. However, we have not yet succeeded in implementing this
solution.
_________________
1) Aims and problems
Basically, we need to draw continuously a moving object in a glcanvas
which is inside one of the application's forms, with lots of other
objects (buttons, inputs, etc.).
The basic way would be to modify the event loop with something like :
while(1) {
fl_check_forms();
compute_object_movement(); // this is a very quick-to-compute function
activate_canvas();
draw_canvas(); // this is an expansive function
swap_buffer();
}
This is to slow, and stops the drawing when lots of user events have to
be computed.
___________________
2) spl previous advice
The solutions proposed by spl in
http://bob.usuhs.mil/mailserv/list-archives/xforms-archive/0304.html
and
http://bob.usuhs.mil/mailserv/list-archives/xforms-archive.2000/0359.html
work fine (no bug), but do not solve our problem.
In this solution, the main program has the following architecture :
main() {
XInitThreads();
fl_initialise();
create_forms();
fl_check_forms(); // display the forms
create_my_thread(MyThread): //pthread while ( 1 ) {
lock(); //pthread_mutex_lock
fl_check_forms();
unlock(); pthread_mutex_unlock
sleep_a_bit();
}
}
and here is the thread architecture :
MyThread(){
while(1) {
compute_object_movement(); // this is a very quick-to-compute
function
lock(); //pthread_mutex_lock
activate_canvas();
draw_canvas(); // this is an expansive function
swap_buffer();
unlock(); pthread_mutex_unlock
sleep_a_bit();
}
This does not seem to raise any error. However, it is not of interest in
our case because we want the user event part and the drawing part not to
interfere :
- the compute_object_movement() is very small (whereas the drawing
itself is expansive) ; the interest of using a thread is not in
compute_object_movement()
- we need to run fl_check_forms() and the drawing in parallel
___________________
2) elements for a solution reparenting a window (perhaps !)
Here is the architecture of the "solution" :
main {
XInitThreads();
fl_initialise();
create_forms(); // except the glcanvas
fl_check_forms(); // display the forms
create_my_thread(MyThread): //pthread
while ( 1 ) {
fl_check_forms();
}
}
and here is the thread architecture :
MyThread(){
create_a_glwindow() ; // without using Xforms
display_gl_window();
reparent_gl_window(); // reparent the GLwingow to the window of the
form it should appear in.
while(1) {
compute_object_movement(); // this is a very quick-to-compute
function draw_in_gl_window(); // this is an expansive
function
}
}
So... The idea would be to let the thread create its own window and so
on...
I am really not sure it would work but... The investigation we made
seems to give some results...
_____________
well.. that's almost all...
Do you think the "solution" makes sense ?
If so, perhaps you may give some help... Reparenting a window with Xlib
is not our preferred game ;-)
If not... would you have advice, other idea, etc ?
Thx for reading my poor english, and for help ;-)
Nicolas
_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuhs.mil or see
http://bob.usuhs.mil/mailserv/xforms.html
XForms Home Page: http://world.std.com/~xforms
List Archive: http://bob.usuhs.mil/mailserv/list-archives/
This archive was generated by hypermail 2b29 : Fri Feb 07 2003 - 14:58:28 EST