From 169f4a60fee62e7742c33596c1494901d9ba8df9 Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
Date: Sun, 8 May 2011 05:32:52 +0200
Subject: JOGL/ShaderCode: Dump proper GLSL source w/ line numbers if GLSLCode
 debug prop is set

---
 .../com/jogamp/opengl/util/glsl/ShaderCode.java    | 28 ++++++++++++++++------
 1 file changed, 21 insertions(+), 7 deletions(-)

(limited to 'src/jogl/classes/com/jogamp/opengl')

diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java
index c6a52a33e..ad17dd288 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java
@@ -67,7 +67,7 @@ public class ShaderCode {
 
         if(DEBUG_CODE) {
             System.out.println("Created: "+toString());
-            dumpShaderSource(System.out);
+            // dumpShaderSource(System.out); // already done in readShaderSource
         }
     }
 
@@ -282,14 +282,18 @@ public class ShaderCode {
         }
     }
 
-    public static void readShaderSource(Class context, URL url, StringBuffer result) {
+    private static int readShaderSource(Class context, URL url, StringBuffer result, int lineno) {
         try {
             if(DEBUG_CODE) {
-                System.err.println("ShaderCode.readShaderSource<0>: "+url);
+                System.err.printf("%3d: // %s\n", lineno, url);
             }
             BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
             String line = null;
             while ((line = reader.readLine()) != null) {
+                lineno++;
+                if(DEBUG_CODE) {
+                    System.err.printf("%3d: %s\n", lineno, line);
+                }
                 if (line.startsWith("#include ")) {
                     String includeFile = line.substring(9).trim();
                     URL nextURL = null;
@@ -307,10 +311,7 @@ public class ShaderCode {
                         // Fail
                         throw new FileNotFoundException("Can't find include file " + includeFile);
                     }
-                    if(DEBUG_CODE) {
-                        System.err.println("ShaderCode.readShaderSource<I>: "+url+" + "+includeFile+" := "+nextURL);
-                    }                    
-                    readShaderSource(context, nextURL, result);
+                    lineno = readShaderSource(context, nextURL, result, lineno);
                 } else {
                     result.append(line + "\n");
                 }
@@ -318,6 +319,19 @@ public class ShaderCode {
         } catch (IOException e) {
             throw new RuntimeException(e);
         }
+        return lineno;
+    }
+    
+    public static void readShaderSource(Class context, URL url, StringBuffer result) {
+        if(DEBUG_CODE) {
+            System.err.println();
+            System.err.println("// -----------------------------------------------------------");
+        }
+        readShaderSource(context, url, result, 0);
+        if(DEBUG_CODE) {
+            System.err.println("// -----------------------------------------------------------");
+            System.err.println();
+        }
     }
 
     public static String readShaderSource(Class context, String path) {
-- 
cgit v1.2.3