Print line numbers with shader source. 69/17769/1
authorFrancisco Santos <f1.santos@samsung.com>
Thu, 27 Feb 2014 17:39:00 +0000 (17:39 +0000)
committerFrancisco Santos <f1.santos@samsung.com>
Mon, 10 Mar 2014 13:43:18 +0000 (13:43 +0000)
Change-Id: I9729b9bf75d5082e0a3be5a5a194e4afe0ede8c6
Signed-off-by: Francisco Santos <f1.santos@samsung.com>
dali/internal/render/shaders/program.cpp

index 6956d7e..a5633f6 100644 (file)
 // CLASS HEADER
 #include <dali/internal/render/shaders/program.h>
 
+// EXTERNAL INCLUDES
+#include <dali/public-api/common/vector-wrapper.h>
+#include <iomanip>
+
 // INTERNAL INCLUDES
 #include <dali/public-api/common/dali-common.h>
 #include <dali/public-api/common/constants.h>
 #include <dali/integration-api/debug.h>
 #include <dali/integration-api/shader-data.h>
 
+namespace
+{
+void LogWithLineNumbers( const char * source )
+{
+  unsigned int lineNumber = 0u;
+  const char *prev = source;
+  const char *ptr = prev;
+
+  while( true )
+  {
+    if(lineNumber > 200u)
+    {
+      break;
+    }
+    // seek the next end of line or end of text
+    while( *ptr!='\n' && *ptr != '\0' ) ++ptr;
+
+    std::string line( prev, ptr-prev );
+    Dali::Integration::Log::LogMessage(Dali::Integration::Log::DebugError, "%4d %s\n", lineNumber, line.c_str());
+
+    if( *ptr == '\0' )
+    {
+      break;
+    }
+    prev = ++ptr;
+    ++lineNumber;
+  }
+}
+
+} //namespace
+
 namespace Dali
 {
 
@@ -546,7 +581,9 @@ bool Program::CompileShader( GLenum shaderType, GLuint& shaderId, const char* sr
 
   if (compiled == GL_FALSE)
   {
-    DALI_LOG_ERROR("Failed to compiler shader \n%s\n", src);
+    DALI_LOG_ERROR("Failed to compile shader\n");
+    LogWithLineNumbers(src);
+
     std::vector< char > szLog;
     GLint nLength;
     mGlAbstraction.GetShaderiv( shaderId, GL_INFO_LOG_LENGTH, &nLength);