Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added shader validation code

  • Loading branch information...
commit 22c5a2ed8522bcc14f29cbe36290653eff8123cf 1 parent 8b93578
Ali Helmy authored September 24, 2011
30  LessonOne/src/com/onehandstand/lwjgltutorial/lessonone/ShaderTriangle.java
@@ -5,7 +5,10 @@
5 5
 import java.io.BufferedReader;
6 6
 import java.io.FileReader;
7 7
 import java.io.IOException;
  8
+import java.nio.ByteBuffer;
  9
+import java.nio.IntBuffer;
8 10
 
  11
+import org.lwjgl.BufferUtils;
9 12
 import org.lwjgl.opengl.ARBFragmentShader;
10 13
 import org.lwjgl.opengl.ARBVertexShader;
11 14
 import static org.lwjgl.opengl.GL11.*;
@@ -15,6 +18,7 @@
15 18
 	private int shader, vertexShader, fragmentShader;
16 19
 	private boolean useShaders;
17 20
 	
  21
+	public static boolean verboseValidityCheck=false;
18 22
 	private static final String SHADERS_ROOT_PATH="shaders";
19 23
 	
20 24
 	public ShaderTriangle() {
@@ -59,6 +63,7 @@ public void draw() {
59 63
 		glVertex2f(0.0f, 0.8f);
60 64
 		glVertex2f(-0.8f, -0.8f);
61 65
 		glVertex2f(0.8f, -0.8f);
  66
+		glEnd();
62 67
 		
63 68
 		//free up use of shader program
64 69
 		glUseProgramObjectARB(0);
@@ -107,9 +112,28 @@ private String readInShaderCodeFromShaderFile(String pathToShaderFile) {
107 112
 		}
108 113
 	}
109 114
 
110  
-	private boolean isShaderValid(int shader) {
111  
-		// TODO implement shader validation
112  
-		return true;
  115
+	private boolean isShaderValid(int shaderToCheck) {
  116
+		IntBuffer iVal = BufferUtils.createIntBuffer(1);
  117
+		glGetObjectParameterARB(shaderToCheck, GL_OBJECT_INFO_LOG_LENGTH_ARB, iVal);
  118
+		int length = iVal.get();
  119
+		boolean isValid = length>1;
  120
+		
  121
+		if (isValid && verboseValidityCheck) {
  122
+			printShaderLogInfo(shaderToCheck, iVal, length);
  123
+		}
  124
+		
  125
+		return isValid;
  126
+	}
  127
+
  128
+	private void printShaderLogInfo(int shaderToCheck, IntBuffer iVal,
  129
+			int length) {
  130
+		ByteBuffer infoLog = BufferUtils.createByteBuffer(length);
  131
+		iVal.flip();
  132
+		glGetInfoLogARB(shaderToCheck, iVal, infoLog);
  133
+		byte[] infoBytes = new byte[length];
  134
+		infoLog.get(infoBytes);
  135
+		String out = new String(infoBytes);
  136
+		System.out.println("Info log:\n"+out);
113 137
 	}
114 138
 	
115 139
 }

0 notes on commit 22c5a2e

Please sign in to comment.
Something went wrong with that request. Please try again.