PCMOpenGLExtensionLoader.cpp

Go to the documentation of this file.
00001 
00002 //
00003 // This source file is a part of ParCompMark
00004 // Parallel Compositing Benchmark Framework
00005 //
00006 // for latest info see http://parcompmark.sourceforge.net
00007 
00008 //
00009 // Copyright (C) 2006 IT2 ParCompMark Dev. Team
00010 // 
00011 // This program is free software; you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License
00013 // as published by the Free Software Foundation; either version 2
00014 // of the License, or (at your option) any later version.
00015 // 
00016 // This program is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 // GNU General Public License for more details.
00020 // 
00021 // You should have received a copy of the GNU General Public License
00022 // along with this program; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00024 
00025 //
00026 // Inner includes
00027 //
00028 
00029 #include "../include/PCMOpenGLExtensionLoader.h"
00030 
00031 //
00032 // Outer includes
00033 //
00034 
00035 #include <GL/glew.h>
00036 #include <GL/glx.h>
00037 #include <GL/glu.h>
00038 
00039 namespace ParCompMark
00040 {
00041 
00042   //
00043   // Class variables
00044   //
00045 
00046   OpenGLExtensionLoader::LoadingMode OpenGLExtensionLoader::mLoadingMode = DELAYED;
00047   std::list < std::string > OpenGLExtensionLoader::mExtensionsToLoad;
00048 
00049   //
00050   // Class methods
00051   //
00052 
00053   void OpenGLExtensionLoader::load(const std::list < std::string > &extensions)
00054   {
00055         switch (mLoadingMode)
00056         {
00057          case IMMEDIATE:
00058                 _init();
00059                 _load(extensions);
00060                 break;
00061                 case DELAYED:std::list < std::string > _extensions = extensions;
00062                 mExtensionsToLoad.splice(mExtensionsToLoad.end(), _extensions);
00063                 break;
00064         }
00065   }
00066 
00067  /*----------------------------------------------------------------------*/
00068 
00069   void OpenGLExtensionLoader::loadDelayed()
00070   {
00071         _init();
00072         _load(mExtensionsToLoad);
00073   }
00074 
00075  /*----------------------------------------------------------------------*/
00076 
00077   void OpenGLExtensionLoader::_load(const std::list < std::string > &extensions)
00078   {
00079         //loadOpenGLExtension should be called inside an OpenGL context 
00080 
00081         std::string currentExt;
00082 
00083         std::list < std::string > ext = extensions;
00084 
00085         for(; !ext.empty(); ext.pop_back())
00086         {
00087 
00088          //only for safety reasons
00089          currentExt = "";
00090 
00091          currentExt = ext.back();
00092 
00093          //check requested extensions
00094          if(!glewIsSupported(currentExt.c_str()))
00095                 Except(INTERNAL_ERROR, "OpenGLExtensionLoader::load()",
00096                    "OpenGL extension `" + currentExt + "\'is not supported.");
00097 
00098         }
00099   }
00100 
00101  /*----------------------------------------------------------------------*/
00102 
00103   void OpenGLExtensionLoader::_init()
00104   {
00105         //ensuring that all extensions with valid entry points will be exposed
00106         glewExperimental = GL_TRUE;
00107 
00108         // TODO: maybe one call is good
00109         GLenum err = glewInit();
00110 
00111         //check if everything is OK
00112         if(GLEW_OK != err)
00113          Except(INTERNAL_ERROR, "OpenGLExtensionLoader::load()",
00114                  std::string("Error during OpenGL extentension loading: ") +
00115                  std::string((const char *) glewGetErrorString(err)));
00116   }
00117 
00118  /*----------------------------------------------------------------------*/
00119 
00120 }