Permalink
Browse files

added shader validation code

  • Loading branch information...
alihelmy committed Sep 24, 2011
1 parent 8b93578 commit 22c5a2ed8522bcc14f29cbe36290653eff8123cf
Showing with 27 additions and 3 deletions.
  1. +27 −3 LessonOne/src/com/onehandstand/lwjgltutorial/lessonone/ShaderTriangle.java
@@ -5,7 +5,10 @@
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.IntBuffer;
+import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.ARBFragmentShader;
import org.lwjgl.opengl.ARBVertexShader;
import static org.lwjgl.opengl.GL11.*;
@@ -15,6 +18,7 @@
private int shader, vertexShader, fragmentShader;
private boolean useShaders;
+ public static boolean verboseValidityCheck=false;
private static final String SHADERS_ROOT_PATH="shaders";
public ShaderTriangle() {
@@ -59,6 +63,7 @@ public void draw() {
glVertex2f(0.0f, 0.8f);
glVertex2f(-0.8f, -0.8f);
glVertex2f(0.8f, -0.8f);
+ glEnd();
//free up use of shader program
glUseProgramObjectARB(0);
@@ -107,9 +112,28 @@ private String readInShaderCodeFromShaderFile(String pathToShaderFile) {
}
}
- private boolean isShaderValid(int shader) {
- // TODO implement shader validation
- return true;
+ private boolean isShaderValid(int shaderToCheck) {
+ IntBuffer iVal = BufferUtils.createIntBuffer(1);
+ glGetObjectParameterARB(shaderToCheck, GL_OBJECT_INFO_LOG_LENGTH_ARB, iVal);
+ int length = iVal.get();
+ boolean isValid = length>1;
+
+ if (isValid && verboseValidityCheck) {
+ printShaderLogInfo(shaderToCheck, iVal, length);
+ }
+
+ return isValid;
+ }
+
+ private void printShaderLogInfo(int shaderToCheck, IntBuffer iVal,
+ int length) {
+ ByteBuffer infoLog = BufferUtils.createByteBuffer(length);
+ iVal.flip();
+ glGetInfoLogARB(shaderToCheck, iVal, infoLog);
+ byte[] infoBytes = new byte[length];
+ infoLog.get(infoBytes);
+ String out = new String(infoBytes);
+ System.out.println("Info log:\n"+out);
}
}

0 comments on commit 22c5a2e

Please sign in to comment.