1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4     (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 
29 #include "OgreException.h"
30 #include "OgreLogManager.h"
31 #include "OgreGLSLExtSupport.h"
32 
33 namespace Ogre
34 {
35     namespace GLSL
36     {
37 
38     //-----------------------------------------------------------------------------
reportGLSLError(GLenum glErr,const String & ogreMethod,const String & errorTextPrefix,const GLhandleARB obj,const bool forceInfoLog,const bool forceException)39     void reportGLSLError(GLenum glErr, const String& ogreMethod, const String& errorTextPrefix, const GLhandleARB obj, const bool forceInfoLog, const bool forceException)
40     {
41         bool errorsFound = false;
42         String msg = errorTextPrefix;
43 
44         // get all the GL errors
45         while (glErr != GL_NO_ERROR)
46         {
47             msg += glErrorToString(glErr);
48             glErr = glGetError();
49             errorsFound = true;
50         }
51 
52 
53         // if errors were found then put them in the Log and raise and exception
54         if (errorsFound || forceInfoLog)
55         {
56             // if shader or program object then get the log message and send to the log manager
57             msg += logObjectInfo( msg, obj );
58 
59             if (forceException)
60             {
61                 OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, msg, ogreMethod);
62             }
63         }
64     }
65 
logObjectInfo(const String & msg,GLuint obj)66     String logObjectInfo(const String& msg, GLuint obj)
67     {
68         String logMessage = getObjectInfo(obj);
69 
70         if (logMessage.empty())
71             return msg;
72 
73         logMessage = msg + "\n" + logMessage;
74 
75         LogManager::getSingleton().logMessage(LML_CRITICAL, logMessage);
76 
77         return logMessage;
78     }
79 
80     //-----------------------------------------------------------------------------
getObjectInfo(GLuint obj)81     String getObjectInfo(GLuint obj)
82     {
83         String logMessage;
84 
85         if (obj > 0)
86         {
87             GLint infologLength = 0;
88 
89             if(glIsProgram(obj))
90                 glValidateProgram(obj);
91 
92             glGetObjectParameterivARB(obj, GL_OBJECT_INFO_LOG_LENGTH_ARB, &infologLength);
93 
94             if (infologLength > 0)
95             {
96                 GLint charsWritten  = 0;
97 
98                 GLcharARB * infoLog = new GLcharARB[infologLength];
99 
100                 glGetInfoLogARB(obj, infologLength, &charsWritten, infoLog);
101                 logMessage = String(infoLog);
102 
103                 delete [] infoLog;
104             }
105         }
106 
107         return logMessage;
108 
109     }
110 
111     } // namespace GLSL
112 } // namespace Ogre
113