From 6ab750aa0b3b3d5be8c8f3a6388faea9149c5765 Mon Sep 17 00:00:00 2001
From: Sven Gothel
Date: Wed, 15 Mar 2023 03:31:49 +0100
Subject: opengl/util/glsl/Shader*: Mark classes and fields final, rename
dump{Shader->}Source(), refine string output.
---
.../com/jogamp/opengl/util/glsl/ShaderCode.java | 38 +++++++++++++---------
.../com/jogamp/opengl/util/glsl/ShaderProgram.java | 21 +++++++++---
.../com/jogamp/opengl/util/glsl/ShaderState.java | 2 +-
.../com/jogamp/opengl/util/glsl/ShaderUtil.java | 2 +-
4 files changed, 41 insertions(+), 22 deletions(-)
(limited to 'src/jogl/classes')
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.
*
*/
-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: {@value}
*/
@@ -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");
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=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 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 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 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)}.
*
*/
-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];
--
cgit v1.2.3