summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/graph
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-03-15 03:26:30 +0100
committerSven Gothel <[email protected]>2023-03-15 03:26:30 +0100
commitc01a4ad712cfa2d1f8746daf161d9052c8acfccd (patch)
tree4f8a033905d0ffc63329f44726a9ea88c0b2977f /src/jogl/classes/com/jogamp/graph
parent00dbacc5af3531af50e77a02d534dc11e08de10f (diff)
Fix ShaderProgram ownership bug, introduced in commit 67a723477ecd818fbc5859fe20ee536a3b4efae5 (reverting and clarifying)
All Graph ShaderPrograms used are owned by RegionRenderer, not RenderState nor [GL]Region*, hence [GL]Region* shall only nullify the resources but not destroy the shader currently in use. One RegionRenderer maybe used for multuple Regions.
Diffstat (limited to 'src/jogl/classes/com/jogamp/graph')
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java11
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java32
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java28
3 files changed, 36 insertions, 35 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
index a86060fab..c8e9a0113 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
@@ -179,7 +179,6 @@ public abstract class GLRegion extends Region {
*/
protected abstract void updateImpl(final GL2ES2 gl);
- protected abstract void clearShaderImpl(final GL2ES2 gl);
protected abstract void destroyImpl(final GL2ES2 gl);
protected abstract void clearImpl(final GL2ES2 gl);
@@ -212,16 +211,14 @@ public abstract class GLRegion extends Region {
return this;
}
- /** Deletes all {@link ShaderProgram}s and nullifies its references. */
- public final void clearShader(final GL2ES2 gl) {
- clearShaderImpl(gl);
- }
-
/**
* Delete and clear the associated OGL objects.
+ * <p>
+ * The {@link ShaderProgram}s references are nullified but not {@link ShaderProgram#destroy(GL2ES2) destroyed}
+ * as they are owned by {@link RegionRenderer}.
+ * </p>
*/
public final void destroy(final GL2ES2 gl) {
- clearShaderImpl(gl);
clear(gl);
destroyImpl(gl);
}
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java
index 9fef381f4..54deb9e4b 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java
@@ -50,10 +50,15 @@ import com.jogamp.graph.curve.Region;
/**
* OpenGL {@link Region} renderer
- * <p>
- * All OpenGL related operations regarding {@link Region}s
- * are passed through an instance of this class.
- * </p>
+ *
+ * All {@link Region} rendering operations utilize a RegionRenderer.
+ *
+ * The RegionRenderer owns its {@link RenderState}, a composition.
+ *
+ * The RegionRenderer manages and own all used {@link ShaderProgram}s, a composition.
+ *
+ * At its {@link #destroy(GL2ES2) destruction}, all {@link ShaderProgram}s and its {@link RenderState}
+ * will be destroyed and released.
*/
public class RegionRenderer {
protected static final boolean DEBUG = Region.DEBUG;
@@ -223,9 +228,12 @@ public class RegionRenderer {
initialized = true;
}
- /** Deletes all {@link ShaderProgram}s and nullifies its references. */
- public final void clearShader(final GL2ES2 gl) {
+ /** Deletes all {@link ShaderProgram}s and nullifies its references including {@link RenderState#destroy(GL2ES2)}. */
+ public final void destroy(final GL2ES2 gl) {
if(!initialized){
+ if(DEBUG_INSTANCE) {
+ System.err.println("TextRenderer: Not initialized!");
+ }
return;
}
for(final Iterator<IntObjectHashMap.Entry> i = shaderPrograms.iterator(); i.hasNext(); ) {
@@ -233,17 +241,7 @@ public class RegionRenderer {
sp.destroy(gl);
}
shaderPrograms.clear();
- rs.destroy(gl);
- }
-
- public final void destroy(final GL2ES2 gl) {
- if(!initialized){
- if(DEBUG_INSTANCE) {
- System.err.println("TextRenderer: Not initialized!");
- }
- return;
- }
- clearShader(gl);
+ rs.destroy();
initialized = false;
}
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java
index 407f40b68..3f7e3f81d 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java
@@ -199,14 +199,20 @@ public class RenderState {
}
public final int id() { return id; }
+
+ /** Return the current {@link ShaderProgram} */
public final ShaderProgram getShaderProgram() { return sp; }
+
+ /** Return whether the current {@link ShaderProgram} is {@link ShaderProgram#inUse() in use}. */
public final boolean isShaderProgramInUse() { return null != sp ? sp.inUse() : false; }
/**
- * Set a {@link ShaderProgram} and enable it. If the given {@link ShaderProgram} is new,
- * method returns true, otherwise false.
+ * Sets the current {@link ShaderProgram} and enables it.
+ *
+ * If the given {@link ShaderProgram} is not {@link #getShaderProgram() the current}, method returns true, otherwise false.
+ *
* @param gl
- * @param spNext
+ * @param spNext the next current {@link ShaderProgram} to be set and enabled
* @return true if a new shader program is being used and hence external uniform-data and -location,
* as well as the attribute-location must be updated, otherwise false.
*/
@@ -263,7 +269,8 @@ public class RenderState {
if( updateLocation || 0 > data.getLocation() ) {
final boolean ok = 0 <= data.setLocation(gl, sp.program());
if( throwOnError && !ok ) {
- throw new GLException("Could not locate "+data);
+ sp.dumpSource(System.err);
+ throw new GLException("Could not locate "+data.getName()+" in "+sp+", "+data);
}
return ok;
} else {
@@ -285,7 +292,8 @@ public class RenderState {
if( updateLocation ) {
updateData = 0 <= data.setLocation(gl, sp.program());
if( throwOnError && !updateData ) {
- throw new GLException("Could not locate "+data);
+ sp.dumpSource(System.err);
+ throw new GLException("Could not locate "+data.getName()+" in "+sp+", "+data);
}
}
if( updateData ){
@@ -306,7 +314,8 @@ public class RenderState {
if( updateLocation || 0 > data.getLocation() ) {
final boolean ok = 0 <= data.setLocation(gl, sp.program());
if( throwOnError && !ok ) {
- throw new GLException("Could not locate "+data);
+ sp.dumpSource(System.err);
+ throw new GLException("Could not locate "+data.getName()+" in "+sp+", "+data);
}
return ok;
} else {
@@ -326,13 +335,10 @@ public class RenderState {
}
/**
- * Issues {@link ShaderProgram#destroy(GL2ES2)} and nullifies reference.
+ * Only nullifies {@link ShaderProgram} reference owned by {@link RegionRenderer}.
*/
public void destroy(final GL2ES2 gl) {
- if( null != sp ) {
- sp.destroy(gl);
- sp = null;
- }
+ sp = null; // owned by RegionRenderer
}
public final RenderState attachTo(final GL2ES2 gl) {