summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/opengl/util
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-03-15 03:31:49 +0100
committerSven Gothel <[email protected]>2023-03-15 03:31:49 +0100
commit6ab750aa0b3b3d5be8c8f3a6388faea9149c5765 (patch)
tree227510fc8caaf50595ab6c07daa5352fa88a5ee6 /src/jogl/classes/com/jogamp/opengl/util
parentc01a4ad712cfa2d1f8746daf161d9052c8acfccd (diff)
opengl/util/glsl/Shader*: Mark classes and fields final, rename dump{Shader->}Source(), refine string output.
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/util')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java38
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java21
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java2
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderUtil.java2
4 files changed, 41 insertions, 22 deletions
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 532db3a7a..163e00c7a 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java
@@ -72,7 +72,7 @@ import com.jogamp.common.util.VersionNumber;
* was added since 2.2.1.
* </p>
*/
-public class ShaderCode {
+public final class ShaderCode {
public static final boolean DEBUG_CODE = Debug.isPropertyDefined("jogl.debug.GLSLCode", true);
/** Unique resource suffix for {@link GL2ES2#GL_VERTEX_SHADER} in source code: <code>{@value}</code> */
@@ -815,7 +815,7 @@ public class ShaderCode {
if(null!=shaderSource) {
if(DEBUG_CODE) {
System.err.println("ShaderCode.compile:");
- dumpShaderSource(System.err);
+ dumpSource(System.err);
}
valid=ShaderUtil.createAndCompileShader(gl, shader, shaderType,
shaderSource, verboseOut);
@@ -859,7 +859,7 @@ public class ShaderCode {
}
@Override
public String toString() {
- final StringBuilder buf = new StringBuilder("ShaderCode[id="+id+", type="+shaderTypeStr()+", valid="+valid+", shader: ");
+ final StringBuilder buf = new StringBuilder("ShaderCode[id="+id()+", type="+shaderTypeStr()+", valid="+valid+", "+shader.remaining()+"/"+shader.capacity()+" shader: ");
for(int i=0; i<shader.remaining(); i++) {
buf.append(" "+shader.get(i));
}
@@ -871,15 +871,20 @@ public class ShaderCode {
return buf.toString();
}
- public void dumpShaderSource(final PrintStream out) {
+ public void dumpSource(final PrintStream out) {
if(null==shaderSource) {
out.println("<no shader source>");
return;
}
final int sourceCount = shaderSource.length;
- final int shaderCount = (null!=shader)?shader.capacity():0;
+ final int shaderCount = shader.capacity();
+ out.println();
+ out.print("ShaderCode[id="+id()+", type="+shaderTypeStr()+", valid="+valid+", "+shader.remaining()+"/"+shaderCount+" shader: ");
+ if( 0 == shaderCount ) {
+ out.println("none]");
+ }
for(int i=0; i<shaderCount; i++) {
- out.println("");
+ out.println();
out.println("Shader #"+i+"/"+shaderCount+" name "+shader.get(i));
out.println("--------------------------------------------------------------");
if(i>=sourceCount) {
@@ -902,6 +907,7 @@ public class ShaderCode {
}
out.println("--------------------------------------------------------------");
}
+ out.println("]");
}
/**
@@ -922,7 +928,7 @@ public class ShaderCode {
if(null==shaderSource) {
throw new IllegalStateException("no shader source");
}
- final int shaderCount = (null!=shader)?shader.capacity():0;
+ final int shaderCount = shader.capacity();
if(0>shaderIdx || shaderIdx>=shaderCount) {
throw new IndexOutOfBoundsException("shaderIdx not within shader bounds [0.."+(shaderCount-1)+"]: "+shaderIdx);
}
@@ -1027,7 +1033,7 @@ public class ShaderCode {
if(null==shaderSource) {
throw new IllegalStateException("no shader source");
}
- final int shaderCount = (null!=shader)?shader.capacity():0;
+ final int shaderCount = shader.capacity();
if(0>shaderIdx || shaderIdx>=shaderCount) {
throw new IndexOutOfBoundsException("shaderIdx not within shader bounds [0.."+(shaderCount-1)+"]: "+shaderIdx);
}
@@ -1437,18 +1443,18 @@ public class ShaderCode {
// Internals only below this point
//
- protected CharSequence[][] shaderSource = null;
- protected Buffer shaderBinary = null;
- protected int shaderBinaryFormat = -1;
- protected IntBuffer shader = null;
- protected int shaderType = -1;
- protected int id = -1;
+ private CharSequence[][] shaderSource;
+ private Buffer shaderBinary;
+ private int shaderBinaryFormat = -1;
+ private final IntBuffer shader;
+ private int shaderType = -1;
+ private int id = -1;
- protected boolean valid=false;
+ private boolean valid=false;
private static synchronized int getNextID() {
return nextID++;
}
- protected static int nextID = 1;
+ private static int nextID = 1;
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java
index 63455ba51..82486a213 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java
@@ -36,7 +36,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.io.PrintStream;
-public class ShaderProgram {
+public final class ShaderProgram {
public ShaderProgram() {
id = getNextID();
@@ -282,9 +282,13 @@ public class ShaderProgram {
sb = new StringBuilder();
}
sb.append("ShaderProgram[id=").append(id);
- sb.append(", linked="+programLinked+", inUse="+programInUse+", program: "+shaderProgram+",");
- for(final Iterator<ShaderCode> iter=allShaderCode.iterator(); iter.hasNext(); ) {
- sb.append(Platform.getNewline()).append(" ").append(iter.next());
+ sb.append(", linked="+programLinked+", inUse="+programInUse+", program: "+shaderProgram+", "+allShaderCode.size()+" code: ");
+ if( 0 < allShaderCode.size() ) {
+ for(final Iterator<ShaderCode> iter=allShaderCode.iterator(); iter.hasNext(); ) {
+ sb.append(Platform.getNewline()).append(" ").append(iter.next());
+ }
+ } else {
+ sb.append("none");
}
sb.append("]");
return sb;
@@ -316,6 +320,15 @@ public class ShaderProgram {
programInUse = false;
}
+ public void dumpSource(final PrintStream out) {
+ out.println();
+ out.println(toString());
+ for(final Iterator<ShaderCode> iter=allShaderCode.iterator(); iter.hasNext(); ) {
+ iter.next().dumpSource(out);
+ }
+ out.println();
+ }
+
private boolean programLinked = false;
private boolean programInUse = false;
private int shaderProgram = 0; // non zero is valid!
diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java
index e06f7be00..f13c2f743 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java
@@ -57,7 +57,7 @@ import com.jogamp.opengl.util.GLArrayDataEditable;
* and can be retrieved via {@link #getShaderState(GL)}.
* </p>
*/
-public class ShaderState {
+public final class ShaderState {
public static final boolean DEBUG;
static {
diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderUtil.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderUtil.java
index 165a5167a..5ad1d49d9 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderUtil.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderUtil.java
@@ -42,7 +42,7 @@ import com.jogamp.opengl.*;
import com.jogamp.common.nio.Buffers;
import com.jogamp.opengl.GLExtensions;
-public class ShaderUtil {
+public final class ShaderUtil {
public static String getShaderInfoLog(final GL _gl, final int shaderObj) {
final GL2ES2 gl = _gl.getGL2ES2();
final int[] infoLogLength=new int[1];