Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OgreGLSLExtSupport.cpp

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004     (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://ogre.sourceforge.net/
00006 
00007 Copyright © 2000-2002 The OGRE Team
00008 Also see acknowledgements in Readme.html
00009 
00010 This program is free software; you can redistribute it and/or modify it under
00011 the terms of the GNU Lesser General Public License as published by the Free Software
00012 Foundation; either version 2 of the License, or (at your option) any later
00013 version.
00014 
00015 This program is distributed in the hope that it will be useful, but WITHOUT
00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public License along with
00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00022 http://www.gnu.org/copyleft/lesser.txt.
00023 -----------------------------------------------------------------------------
00024 */
00025 
00026 #include "OgreLogManager.h"
00027 #include "OgreGLSLExtSupport.h"
00028 #include "OgreGLSupport.h"
00029 
00030 namespace Ogre
00031 {
00032     //
00033     // OpenGL Shading Language entry points
00034     //
00035     PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB_ptr = NULL;
00036     PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB_ptr = NULL;
00037     PFNGLDELETEOBJECTARBPROC glDeleteObjectARB_ptr = NULL;
00038     PFNGLDETACHOBJECTARBPROC glDetachObjectARB_ptr = NULL;
00039     PFNGLATTACHOBJECTARBPROC glAttachObjectARB_ptr = NULL;
00040 
00041     PFNGLSHADERSOURCEARBPROC glShaderSourceARB_ptr = NULL;
00042     PFNGLCOMPILESHADERARBPROC glCompileShaderARB_ptr = NULL;
00043     PFNGLLINKPROGRAMARBPROC glLinkProgramARB_ptr = NULL;
00044     PFNGLGETINFOLOGARBPROC glGetInfoLogARB_ptr = NULL;
00045     PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB_ptr = NULL;
00046 
00047     PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB_ptr = NULL;
00048     PFNGLGETOBJECTPARAMETERFVARBPROC glGetObjectParameterfvARB_ptr = NULL;
00049     PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB_ptr = NULL;
00050     PFNGLGETATTRIBLOCATIONARBPROC glGetAttribLocationARB_ptr = NULL;
00051     PFNGLGETACTIVEUNIFORMARBPROC glGetActiveUniformARB_ptr = NULL;
00052 
00053     PFNGLBINDATTRIBLOCATIONARBPROC glBindAttribLocationARB_ptr = NULL;
00054 
00055     PFNGLUNIFORM1FARBPROC glUniform1fARB_ptr = NULL;
00056     PFNGLUNIFORM2FARBPROC glUniform2fARB_ptr = NULL;
00057     PFNGLUNIFORM3FARBPROC glUniform3fARB_ptr = NULL;
00058     PFNGLUNIFORM4FARBPROC glUniform4fARB_ptr = NULL;
00059 
00060     PFNGLUNIFORM1IARBPROC glUniform1iARB_ptr = NULL;
00061     PFNGLUNIFORM2IARBPROC glUniform2iARB_ptr = NULL;
00062     PFNGLUNIFORM3IARBPROC glUniform3iARB_ptr = NULL;
00063     PFNGLUNIFORM4IARBPROC glUniform4iARB_ptr = NULL;
00064 
00065     PFNGLUNIFORM1FVARBPROC glUniform1fvARB_ptr = NULL;
00066     PFNGLUNIFORM2FVARBPROC glUniform2fvARB_ptr = NULL;
00067     PFNGLUNIFORM3FVARBPROC glUniform3fvARB_ptr = NULL;
00068     PFNGLUNIFORM4FVARBPROC glUniform4fvARB_ptr = NULL;
00069 
00070     PFNGLUNIFORM1IVARBPROC glUniform1ivARB_ptr = NULL;
00071     PFNGLUNIFORM2IVARBPROC glUniform2ivARB_ptr = NULL;
00072     PFNGLUNIFORM3IVARBPROC glUniform3ivARB_ptr = NULL;
00073     PFNGLUNIFORM4IVARBPROC glUniform4ivARB_ptr = NULL;
00074 
00075     PFNGLVERTEXATTRIB4FVARBPROC glVertexAttrib4fvARB_ptr = NULL;
00076     PFNGLVERTEXATTRIB3FVARBPROC glVertexAttrib3fvARB_ptr = NULL;
00077     PFNGLVERTEXATTRIB2FVARBPROC glVertexAttrib2fvARB_ptr = NULL;
00078     PFNGLVERTEXATTRIB1FVARBPROC glVertexAttrib1fvARB_ptr = NULL;
00079     PFNGLVERTEXATTRIB4FARBPROC glVertexAttrib4fARB_ptr = NULL;
00080     PFNGLVERTEXATTRIB3FARBPROC glVertexAttrib3fARB_ptr = NULL;
00081     PFNGLVERTEXATTRIB2FARBPROC glVertexAttrib2fARB_ptr = NULL;
00082     PFNGLVERTEXATTRIB1FARBPROC glVertexAttrib1fARB_ptr = NULL;
00083 
00084 
00085     //-----------------------------------------------------------------------------
00086     bool InitGLShaderLanguageExtensions( GLSupport& glSupport )
00087     {
00088         static bool init = false;
00089 
00090         // check that this has not been done before -- only need to get proc addresses once
00091         if (!init)
00092         {
00093 
00094             glCreateProgramObjectARB_ptr  = (PFNGLCREATEPROGRAMOBJECTARBPROC) glSupport.getProcAddress( "glCreateProgramObjectARB" );
00095             glCreateShaderObjectARB_ptr   = (PFNGLCREATESHADEROBJECTARBPROC) glSupport.getProcAddress( "glCreateShaderObjectARB" );
00096             glDeleteObjectARB_ptr         = (PFNGLDELETEOBJECTARBPROC) glSupport.getProcAddress( "glDeleteObjectARB" );
00097             glDetachObjectARB_ptr         = (PFNGLDETACHOBJECTARBPROC) glSupport.getProcAddress( "glDetachObjectARB" );
00098             glAttachObjectARB_ptr         = (PFNGLATTACHOBJECTARBPROC) glSupport.getProcAddress( "glAttachObjectARB" );
00099             glShaderSourceARB_ptr         = (PFNGLSHADERSOURCEARBPROC) glSupport.getProcAddress( "glShaderSourceARB" );
00100             glCompileShaderARB_ptr        = (PFNGLCOMPILESHADERARBPROC) glSupport.getProcAddress( "glCompileShaderARB" );
00101             glLinkProgramARB_ptr          = (PFNGLLINKPROGRAMARBPROC) glSupport.getProcAddress( "glLinkProgramARB" );
00102             glGetInfoLogARB_ptr           = (PFNGLGETINFOLOGARBPROC) glSupport.getProcAddress( "glGetInfoLogARB" );
00103             glUseProgramObjectARB_ptr     = (PFNGLUSEPROGRAMOBJECTARBPROC) glSupport.getProcAddress( "glUseProgramObjectARB" );
00104             glGetObjectParameterivARB_ptr = (PFNGLGETOBJECTPARAMETERIVARBPROC) glSupport.getProcAddress( "glGetObjectParameterivARB" );
00105             glGetObjectParameterfvARB_ptr = (PFNGLGETOBJECTPARAMETERFVARBPROC) glSupport.getProcAddress( "glGetObjectParameterfvARB" );
00106             glGetUniformLocationARB_ptr   = (PFNGLGETUNIFORMLOCATIONARBPROC) glSupport.getProcAddress( "glGetUniformLocationARB" );
00107             glGetActiveUniformARB_ptr     = (PFNGLGETACTIVEUNIFORMARBPROC) glSupport.getProcAddress( "glGetActiveUniformARB" );
00108             glGetAttribLocationARB_ptr    = (PFNGLGETATTRIBLOCATIONARBPROC) glSupport.getProcAddress( "glGetAttribLocationARB" );
00109             glBindAttribLocationARB_ptr   = (PFNGLBINDATTRIBLOCATIONARBPROC) glSupport.getProcAddress( "glBindAttribLocationARB" );
00110 
00111             glUniform1fARB_ptr            = (PFNGLUNIFORM1FARBPROC) glSupport.getProcAddress( "glUniform1fARB" );
00112             glUniform2fARB_ptr            = (PFNGLUNIFORM2FARBPROC) glSupport.getProcAddress( "glUniform2fARB" );
00113             glUniform3fARB_ptr            = (PFNGLUNIFORM3FARBPROC) glSupport.getProcAddress( "glUniform3fARB" );
00114             glUniform4fARB_ptr            = (PFNGLUNIFORM4FARBPROC) glSupport.getProcAddress( "glUniform4fARB" );
00115             glUniform1iARB_ptr            = (PFNGLUNIFORM1IARBPROC) glSupport.getProcAddress( "glUniform1iARB" );
00116             glUniform2iARB_ptr            = (PFNGLUNIFORM2IARBPROC) glSupport.getProcAddress( "glUniform2iARB" );
00117             glUniform3iARB_ptr            = (PFNGLUNIFORM3IARBPROC) glSupport.getProcAddress( "glUniform3iARB" );
00118             glUniform4iARB_ptr            = (PFNGLUNIFORM4IARBPROC) glSupport.getProcAddress( "glUniform4iARB" );
00119             glUniform1fvARB_ptr           = (PFNGLUNIFORM1FVARBPROC) glSupport.getProcAddress( "glUniform1fvARB" );
00120             glUniform2fvARB_ptr           = (PFNGLUNIFORM2FVARBPROC) glSupport.getProcAddress( "glUniform2fvARB" );
00121             glUniform3fvARB_ptr           = (PFNGLUNIFORM3FVARBPROC) glSupport.getProcAddress( "glUniform3fvARB" );
00122             glUniform4fvARB_ptr           = (PFNGLUNIFORM4FVARBPROC) glSupport.getProcAddress( "glUniform4fvARB" );
00123             glUniform1ivARB_ptr           = (PFNGLUNIFORM1IVARBPROC) glSupport.getProcAddress( "glUniform1ivARB" );
00124             glUniform2ivARB_ptr           = (PFNGLUNIFORM2IVARBPROC) glSupport.getProcAddress( "glUniform2ivARB" );
00125             glUniform3ivARB_ptr           = (PFNGLUNIFORM3IVARBPROC) glSupport.getProcAddress( "glUniform3ivARB" );
00126             glUniform4ivARB_ptr           = (PFNGLUNIFORM4IVARBPROC) glSupport.getProcAddress( "glUniform4ivARB" );
00127 
00128             glVertexAttrib4fvARB_ptr      = (PFNGLVERTEXATTRIB4FVARBPROC) glSupport.getProcAddress( "glVertexAttrib4fvARB" );
00129             glVertexAttrib3fvARB_ptr      = (PFNGLVERTEXATTRIB3FVARBPROC) glSupport.getProcAddress( "glVertexAttrib3fvARB" );
00130             glVertexAttrib2fvARB_ptr      = (PFNGLVERTEXATTRIB2FVARBPROC) glSupport.getProcAddress( "glVertexAttrib2fvARB" );
00131             glVertexAttrib1fvARB_ptr      = (PFNGLVERTEXATTRIB1FVARBPROC) glSupport.getProcAddress( "glVertexAttrib1fvARB" );
00132             glVertexAttrib4fARB_ptr       = (PFNGLVERTEXATTRIB4FARBPROC) glSupport.getProcAddress( "glVertexAttrib4fARB" );
00133             glVertexAttrib3fARB_ptr       = (PFNGLVERTEXATTRIB3FARBPROC) glSupport.getProcAddress( "glVertexAttrib3fARB" );
00134             glVertexAttrib2fARB_ptr       = (PFNGLVERTEXATTRIB2FARBPROC) glSupport.getProcAddress( "glVertexAttrib2fARB" );
00135             glVertexAttrib1fARB_ptr       = (PFNGLVERTEXATTRIB1FARBPROC) glSupport.getProcAddress( "glVertexAttrib1fARB" );
00136 
00137             init = true;
00138         }
00139 
00140         return init;
00141 
00142     }
00143 
00144     //-----------------------------------------------------------------------------
00145     void checkForGLSLError(const String& ogreMethod, const String& errorTextPrefix, const GLhandleARB obj, const bool forceInfoLog, const bool forceException)
00146     {
00147         GLenum glErr;
00148         bool errorsFound = false;
00149         String msg = errorTextPrefix;
00150 
00151         // get all the GL errors
00152         glErr = glGetError();
00153         while (glErr != GL_NO_ERROR)
00154         {
00155             msg += "\n" + String((char*)gluErrorString(glErr)); 
00156             glErr = glGetError();
00157             errorsFound = true;
00158         }
00159 
00160 
00161         // if errors were found then put them in the Log and raise and exception
00162         if (errorsFound || forceInfoLog)
00163         {
00164             // if shader or program object then get the log message and send to the log manager
00165             msg += logObjectInfo( msg, obj );
00166 
00167             if (forceException) 
00168             {
00169                 Except(Exception::ERR_INTERNAL_ERROR, msg, ogreMethod);
00170             }
00171         }
00172     }
00173 
00174     //-----------------------------------------------------------------------------
00175     String logObjectInfo(const String& msg, const GLhandleARB obj)
00176     {
00177         String logMessage = msg;
00178 
00179         if (obj > 0)
00180         {
00181             int infologLength = 0;
00182 
00183             glGetObjectParameterivARB_ptr(obj, GL_OBJECT_INFO_LOG_LENGTH_ARB, &infologLength);
00184 
00185             if (infologLength > 0)
00186             {
00187                 int charsWritten  = 0;
00188 
00189                 GLcharARB * infoLog = new GLcharARB[infologLength];
00190 
00191                 glGetInfoLogARB_ptr(obj, infologLength, &charsWritten, infoLog);
00192                 logMessage += String(infoLog) + "\n";
00193                 LogManager::getSingleton().logMessage(logMessage);
00194 
00195                 delete [] infoLog;
00196             }
00197         }
00198 
00199         return logMessage;
00200 
00201     }
00202 
00203 
00204 } // namespace Ogre

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:26 2004