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

Paul Gotzel paul.gotzel at gmail.com
Fri Jul 15 12:41:02 PDT 2011


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;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20110715/4975b5b4/attachment.htm>


More information about the mesa-dev mailing list