opengl dynamic libraries questions

7 views
Skip to first unread message

Ondrej Certik

unread,
Aug 13, 2009, 10:47:31 PM8/13/09
to hpfem
Hi,

I discovered, that if I create 2 .so libraries:

A.so
B.so

both A and B dynamically link with opengl (libGL.so). I dynamically
load both libraries at runtime using python (import A), I create an
opengl context in the library A (e.g. by calling it's function). Then
I can modify this context using opengl commands, as long as they are
executed using A.so, then I can save the result (offscreen) to an
image. Everything works.

Now if I want to modify the same context by a function implemented in
B.so, it just doesn't work. From what I discovered so far, it seems it
doesn't touch the context at all.

The context is created by the functions OSMesaCreateContextExt() and
OSMesaMakeCurrent(), assuming it changes some global variable in the
libGL.so library, is it possible that the libGL.so is in fact loaded
twice? E.g. once through A.so and second time through B.so? That would
explain my experience so far.

Is there any way to fix this? Or do I need to make sure that all my
calls are from within one .so library.

I thought that a dynamic library is loaded only once per program, but
maybe python loads again and again. Is there some way to check how
many times a dynamic library is loaded?

Ondrej

Ondrej Certik

unread,
Aug 13, 2009, 11:08:14 PM8/13/09
to hpfem

The following lines "fix" it:

import ctypes
import sys
sys.setdlopenflags(sys.getdlopenflags() | ctypes.RTLD_GLOBAL)

it sets the RTLD_GLOBAL flag to dlopen, then all the dynamic libs
share symbols and opengl works as expected.

Uff, this caused me exactly 3 hours of debugging. Well, I am a bit
more clever now at least.

Could some C guru on this list clarify, if the above is a correct
understanding of what is happening? :)


Ondrej

Reply all
Reply to author
Forward
0 new messages