[Mesa-dev] is it possible to dynamic load OSMesa?

Paul Gotzel paul.gotzel at gmail.com
Fri Jul 15 13:19:05 PDT 2011


Patrick,

Good thought but it doesn't work.  I don't understand why adding -lOSMesa to
the following makes everything work.

gcc -I../../include -g -O2 -Wall -Wmissing-prototypes -std=c99 -ffast-math
-fvisibility=hidden -fno-strict-aliasing -g  -fPIC   -D_GNU_SOURCE
-DPTHREADS -DDEBUG -DHAVE_POSIX_MEMALIGN -DUSE_XSHM  osdemo.c -L../../lib
-lGL -o osdemo

There must be some other initialization I need to call to get things to work
but I don't understand enough of the details of Mesa to know what is
missing.  I've stepped through the mesa context initialization and I cannot
see what is different between the two runs.  The odd thing is that
everything seems to work but then I end up what I believe is an empty gl
dispatch table.  This is the first time I've looked this so I'm not really
sure what to expect.  Any ideas of where to look in the Mesa code?

Thanks,
Paul

On Fri, Jul 15, 2011 at 3:45 PM, Patrick Baggett
<baggett.patrick at gmail.com>wrote:

> If libOSMesa.so is separate library, then isn't libGL.so too? You're
> calling glGetIntegerv() from libGL.so but not from libOSMesa.so -- try doing
> dlsym("glGetIntegerv") and removing libGL.so from the link line.
>
> Patrick
>
> On Fri, Jul 15, 2011 at 2:41 PM, Paul Gotzel <paul.gotzel at gmail.com>wrote:
>
>> Hello,
>>
>> I've downloaded the latest 7.10.3 and I need to be able to dynamically
>> load OSMesa.  Is this possible?  I've tried to use dlopen and dlsym to load
>> the functions and all the OSMesa calls return success but when I make the gl
>> calls I get:
>>
>> GL User Error: glGetIntegerv called without a rendering context
>> GL User Error: glGetIntegerv called without a rendering context
>> GL User Error: glGetIntegerv called without a rendering context
>>
>> Any help would be appreciated.
>>
>> Thanks,
>> Paul
>>
>> My sample program is as follows.  I compile it with the same flags as the
>> rest of the demo programs without linking to OSMesa.
>>
>> static void *
>> loadOSMesa()
>> {
>>   return dlopen("libOSMesa.so", RTLD_DEEPBIND | RTLD_NOW | RTLD_GLOBAL);
>> }
>>
>> static OSMesaContext
>> dynOSMesaCreateContext()
>> {
>>   typedef OSMesaContext (*CreateContextProto)( GLenum , GLint , GLint ,
>> GLint , OSMesaContext );
>>   static void *createPfunc = NULL;
>>   CreateContextProto createContext;
>>   if (createPfunc == NULL)
>>   {
>>     void *handle = loadOSMesa();
>>     if (handle)
>>     {
>>       createPfunc = dlsym(handle, "OSMesaCreateContextExt");
>>     }
>>   }
>>
>>   if (createPfunc)
>>   {
>>     createContext = (CreateContextProto)(createPfunc);
>>     return (*createContext)(GL_RGBA, 16, 0, 0, NULL);
>>   }
>>   return 0;
>> }
>>
>> static GLboolean
>> dynOSMesaMakeCurrent(OSMesaContext cid, void * win, GLenum type, GLsizei
>> w, GLsizei h)
>> {
>>   typedef GLboolean (*MakeCurrentProto)(OSMesaContext, void *, GLenum,
>> GLsizei, GLsizei);
>>   static void *currentPfunc = NULL;
>>   MakeCurrentProto makeCurrent;
>>   if (currentPfunc == NULL)
>>   {
>>     void *handle = loadOSMesa();
>>     if (handle)
>>     {
>>       currentPfunc = dlsym(handle, "OSMesaMakeCurrent");
>>     }
>>   }
>>   if (currentPfunc)
>>   {
>>     makeCurrent = (MakeCurrentProto)(currentPfunc);
>>     return (*makeCurrent)(cid, win, type, w, h);
>>   }
>>   return GL_FALSE;
>> }
>>
>> int
>> main(int argc, char *argv[])
>> {
>>    OSMesaContext ctx;
>>    void *buffer;
>>
>>    ctx = dynOSMesaCreateContext();
>>    if (!ctx) {
>>       printf("OSMesaCreateContext failed!\n");
>>       return 0;
>>    }
>>
>>    int Width = 100;
>>    int Height = 100;
>>
>>    /* Allocate the image buffer */
>>    buffer = malloc( Width * Height * 4 * sizeof(GLubyte) );
>>    if (!buffer) {
>>       printf("Alloc image buffer failed!\n");
>>       return 0;
>>    }
>>
>>    /* Bind the buffer to the context and make it current */
>>    if (!dynOSMesaMakeCurrent( ctx, buffer, GL_UNSIGNED_BYTE, Width, Height
>> )) {
>>       printf("OSMesaMakeCurrent failed!\n");
>>       return 0;
>>    }
>>
>>
>>    {
>>       int z, s, a;
>>       glGetIntegerv(GL_DEPTH_BITS, &z);
>>       glGetIntegerv(GL_STENCIL_BITS, &s);
>>       glGetIntegerv(GL_ACCUM_RED_BITS, &a);
>>       printf("Depth=%d Stencil=%d Accum=%d\n", z, s, a);
>>    }
>>
>>    return 0;
>> }
>>
>>
>> _______________________________________________
>> mesa-dev mailing list
>> mesa-dev at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20110715/dd45eb8a/attachment.html>


More information about the mesa-dev mailing list