Panda3D
 All Classes Functions Variables Enumerations
osMesaGraphicsStateGuardian.cxx
00001 // Filename: osMesaGraphicsStateGuardian.cxx
00002 // Created by:  drose (09Feb04)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "osMesaGraphicsStateGuardian.h"
00016 
00017 TypeHandle OSMesaGraphicsStateGuardian::_type_handle;
00018 
00019 ////////////////////////////////////////////////////////////////////
00020 //     Function: OSMesaGraphicsStateGuardian::Constructor
00021 //       Access: Public
00022 //  Description:
00023 ////////////////////////////////////////////////////////////////////
00024 OSMesaGraphicsStateGuardian::
00025 OSMesaGraphicsStateGuardian(GraphicsEngine *engine, GraphicsPipe *pipe,
00026                             OSMesaGraphicsStateGuardian *share_with) : 
00027   MesaGraphicsStateGuardian(engine, pipe)
00028 {
00029   OSMesaContext share_context = NULL;
00030   if (share_with != (OSMesaGraphicsStateGuardian *)NULL) {
00031     share_context = share_with->_context;
00032     _prepared_objects = share_with->get_prepared_objects();
00033   }
00034 
00035   _context = OSMesaCreateContext(OSMESA_RGBA, share_context);
00036 
00037   // OSMesa is never hardware-accelerated.
00038   _is_hardware = false;
00039 }
00040 
00041 ////////////////////////////////////////////////////////////////////
00042 //     Function: OSMesaGraphicsStateGuardian::Destructor
00043 //       Access: Public
00044 //  Description:
00045 ////////////////////////////////////////////////////////////////////
00046 OSMesaGraphicsStateGuardian::
00047 ~OSMesaGraphicsStateGuardian() {
00048   if (_context != (OSMesaContext)NULL) {
00049     OSMesaDestroyContext(_context);
00050     _context = (OSMesaContext)NULL;
00051   }
00052 }
00053 
00054 ////////////////////////////////////////////////////////////////////
00055 //     Function: OSMesaGraphicsStateGuardian::do_get_extension_func
00056 //       Access: Public, Virtual
00057 //  Description: Returns the pointer to the GL extension function with
00058 //               the indicated name.  It is the responsibility of the
00059 //               caller to ensure that the required extension is
00060 //               defined in the OpenGL runtime prior to calling this;
00061 //               it is an error to call this for a function that is
00062 //               not defined.
00063 ////////////////////////////////////////////////////////////////////
00064 void *OSMesaGraphicsStateGuardian::
00065 do_get_extension_func(const char *prefix, const char *name) {
00066 #if (OSMESA_MAJOR_VERSION == 4 && OSMESA_MINOR_VERSION >= 1) || OSMESA_MAJOR_VERSION > 4
00067   // If we've got at least OSMesa version 4.1, then we can use
00068   // OSMesaGetProcAddress.
00069 
00070   // We ignore the prefix and always use "gl", since that's what Mesa
00071   // does (even if we compile with name mangling enabled to rename the
00072   // Mesa functions to "mgl", they're still stored as "gl" in the
00073   // OSMesaGetProcAddress() lookup table.
00074   string fullname = string("gl") + string(name);
00075   void *ptr = (void *)OSMesaGetProcAddress(fullname.c_str());
00076   if (mesadisplay_cat.is_debug()) {
00077     mesadisplay_cat.debug()
00078       << "Looking for function " << fullname << ": " << ptr << "\n";
00079   }
00080   if (ptr == (void *)NULL) {
00081     // Well, try for the more accurate name.
00082     fullname = string(prefix) + string(name);
00083     ptr = (void *)OSMesaGetProcAddress(fullname.c_str());
00084     if (mesadisplay_cat.is_debug()) {
00085       mesadisplay_cat.debug()
00086         << "Looking for function " << fullname << ": " << ptr << "\n";
00087     }
00088   }
00089 
00090   return ptr;
00091 
00092 #else
00093   if (mesadisplay_cat.is_debug()) {
00094     mesadisplay_cat.debug()
00095       << "Couldn't look up extension function: compiled with Mesa version "
00096       << OSMESA_MAJOR_VERSION << "." << OSMESA_MINOR_VERSION << "\n";
00097   }
00098   
00099   // Otherwise, too bad.  No extension functions for you.  We could
00100   // try to write code that would dig around in the system interface
00101   // (using dlopen(), for instance) to find the extension functions,
00102   // but why should we have to do that?  Just go get the latest Mesa,
00103   // for goodness sakes!
00104   return NULL;
00105 #endif
00106 }
 All Classes Functions Variables Enumerations