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

2011-07-31 Thread Chia-I Wu
On Sat, Jul 16, 2011 at 5:19 AM, Paul Gotzel paul.got...@gmail.com wrote:
 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?
I am not familiar with OSMesa, but when both GL and OSMesa live in the
same address space, there are two copies of glapi (the dispatch table
and etc.).  In your example, it may happen that dynOSMesaMakeCurrent
updates OSMesa's copy of glapi, but glGetIntegerv uses GL's copy of
glapi.  But when both libraries are linked at compile time,
dynOSMesaMakeCurrent and glGetIntegerv may happen to use the same copy
of glapi.


 Thanks,
 Paul

 On Fri, Jul 15, 2011 at 3:45 PM, Patrick Baggett baggett.patr...@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.got...@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@lists.freedesktop.org
 http://lists.freedesktop.org/mailman/listinfo/mesa-dev




 ___
 mesa-dev mailing list
 mesa-dev@lists.freedesktop.org
 http://lists.freedesktop.org/mailman/listinfo/mesa-dev





-- 
o...@lunarg.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org

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

2011-07-15 Thread Paul Gotzel
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@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


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

2011-07-15 Thread Patrick Baggett
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.got...@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@lists.freedesktop.org
 http://lists.freedesktop.org/mailman/listinfo/mesa-dev


___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


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

2011-07-15 Thread Paul Gotzel
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.patr...@gmail.comwrote:

 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.got...@gmail.comwrote:

 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@lists.freedesktop.org
 http://lists.freedesktop.org/mailman/listinfo/mesa-dev



___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev